LCOV - code coverage report
Current view: top level - gcc - tree-cfg.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 82.9 % 5126 4248
Test Date: 2026-06-20 15:32:29 Functions: 90.9 % 209 190
Legend: Lines:     hit not hit

            Line data    Source code
       1              : /* Control flow functions for trees.
       2              :    Copyright (C) 2001-2026 Free Software Foundation, Inc.
       3              :    Contributed by Diego Novillo <dnovillo@redhat.com>
       4              : 
       5              : This file is part of GCC.
       6              : 
       7              : GCC is free software; you can redistribute it and/or modify
       8              : it under the terms of the GNU General Public License as published by
       9              : the Free Software Foundation; either version 3, or (at your option)
      10              : any later version.
      11              : 
      12              : GCC is distributed in the hope that it will be useful,
      13              : but WITHOUT ANY WARRANTY; without even the implied warranty of
      14              : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      15              : GNU General Public License for more details.
      16              : 
      17              : You should have received a copy of the GNU General Public License
      18              : along with GCC; see the file COPYING3.  If not see
      19              : <http://www.gnu.org/licenses/>.  */
      20              : 
      21              : #include "config.h"
      22              : #include "system.h"
      23              : #include "coretypes.h"
      24              : #include "backend.h"
      25              : #include "target.h"
      26              : #include "rtl.h"
      27              : #include "tree.h"
      28              : #include "gimple.h"
      29              : #include "cfghooks.h"
      30              : #include "tree-pass.h"
      31              : #include "ssa.h"
      32              : #include "cgraph.h"
      33              : #include "gimple-pretty-print.h"
      34              : #include "diagnostic-core.h"
      35              : #include "fold-const.h"
      36              : #include "trans-mem.h"
      37              : #include "stor-layout.h"
      38              : #include "print-tree.h"
      39              : #include "cfganal.h"
      40              : #include "gimple-iterator.h"
      41              : #include "gimple-fold.h"
      42              : #include "tree-eh.h"
      43              : #include "gimplify-me.h"
      44              : #include "gimple-walk.h"
      45              : #include "tree-cfg.h"
      46              : #include "tree-ssa-loop-manip.h"
      47              : #include "tree-ssa-loop-niter.h"
      48              : #include "tree-into-ssa.h"
      49              : #include "tree-dfa.h"
      50              : #include "tree-ssa.h"
      51              : #include "except.h"
      52              : #include "cfgloop.h"
      53              : #include "tree-ssa-propagate.h"
      54              : #include "value-prof.h"
      55              : #include "tree-inline.h"
      56              : #include "tree-ssa-live.h"
      57              : #include "tree-ssa-dce.h"
      58              : #include "omp-general.h"
      59              : #include "omp-expand.h"
      60              : #include "tree-cfgcleanup.h"
      61              : #include "gimplify.h"
      62              : #include "attribs.h"
      63              : #include "selftest.h"
      64              : #include "opts.h"
      65              : #include "asan.h"
      66              : #include "profile.h"
      67              : #include "sreal.h"
      68              : #include "gcc-urlifier.h"
      69              : 
      70              : /* This file contains functions for building the Control Flow Graph (CFG)
      71              :    for a function tree.  */
      72              : 
      73              : /* Local declarations.  */
      74              : 
      75              : /* Initial capacity for the basic block array.  */
      76              : static const int initial_cfg_capacity = 20;
      77              : 
      78              : /* This hash table allows us to efficiently lookup all CASE_LABEL_EXPRs
      79              :    which use a particular edge.  The CASE_LABEL_EXPRs are chained together
      80              :    via their CASE_CHAIN field, which we clear after we're done with the
      81              :    hash table to prevent problems with duplication of GIMPLE_SWITCHes.
      82              : 
      83              :    Access to this list of CASE_LABEL_EXPRs allows us to efficiently
      84              :    update the case vector in response to edge redirections.
      85              : 
      86              :    Right now this table is set up and torn down at key points in the
      87              :    compilation process.  It would be nice if we could make the table
      88              :    more persistent.  The key is getting notification of changes to
      89              :    the CFG (particularly edge removal, creation and redirection).  */
      90              : 
      91              : static hash_map<edge, tree> *edge_to_cases;
      92              : 
      93              : /* If we record edge_to_cases, this bitmap will hold indexes
      94              :    of basic blocks that end in a GIMPLE_SWITCH which we touched
      95              :    due to edge manipulations.  */
      96              : 
      97              : static bitmap touched_switch_bbs;
      98              : 
      99              : /* OpenMP region idxs for blocks during cfg pass.  */
     100              : static vec<int> bb_to_omp_idx;
     101              : 
     102              : /* CFG statistics.  */
     103              : struct cfg_stats_d
     104              : {
     105              :   long num_merged_labels;
     106              : };
     107              : 
     108              : static struct cfg_stats_d cfg_stats;
     109              : 
     110              : /* Data to pass to replace_block_vars_by_duplicates_1.  */
     111              : struct replace_decls_d
     112              : {
     113              :   hash_map<tree, tree> *vars_map;
     114              :   tree to_context;
     115              : };
     116              : 
     117              : /* Basic blocks and flowgraphs.  */
     118              : static void make_blocks (gimple_seq);
     119              : 
     120              : /* Edges.  */
     121              : static void make_edges (void);
     122              : static void assign_discriminators (void);
     123              : static void make_cond_expr_edges (basic_block);
     124              : static void make_gimple_switch_edges (gswitch *, basic_block);
     125              : static bool make_goto_expr_edges (basic_block);
     126              : static void make_gimple_asm_edges (basic_block);
     127              : static edge gimple_redirect_edge_and_branch (edge, basic_block);
     128              : static edge gimple_try_redirect_by_replacing_jump (edge, basic_block);
     129              : 
     130              : /* Various helpers.  */
     131              : static inline bool stmt_starts_bb_p (gimple *, gimple *);
     132              : static bool gimple_verify_flow_info (void);
     133              : static void gimple_make_forwarder_block (edge);
     134              : static bool verify_gimple_transaction (gtransaction *);
     135              : static bool call_can_make_abnormal_goto (gimple *);
     136              : 
     137              : /* Flowgraph optimization and cleanup.  */
     138              : static void gimple_merge_blocks (basic_block, basic_block);
     139              : static bool gimple_can_merge_blocks_p (basic_block, basic_block);
     140              : static void remove_bb (basic_block);
     141              : static edge find_taken_edge_computed_goto (basic_block, tree);
     142              : static edge find_taken_edge_cond_expr (const gcond *, tree);
     143              : 
     144              : void
     145      3268316 : init_empty_tree_cfg_for_function (struct function *fn)
     146              : {
     147              :   /* Initialize the basic block array.  */
     148      3268316 :   init_flow (fn);
     149      3268316 :   profile_status_for_fn (fn) = PROFILE_ABSENT;
     150      3268316 :   n_basic_blocks_for_fn (fn) = NUM_FIXED_BLOCKS;
     151      3268316 :   last_basic_block_for_fn (fn) = NUM_FIXED_BLOCKS;
     152      3268316 :   vec_safe_grow_cleared (basic_block_info_for_fn (fn),
     153              :                          initial_cfg_capacity, true);
     154              : 
     155              :   /* Build a mapping of labels to their associated blocks.  */
     156      3268316 :   vec_safe_grow_cleared (label_to_block_map_for_fn (fn),
     157              :                          initial_cfg_capacity, true);
     158              : 
     159      3268316 :   SET_BASIC_BLOCK_FOR_FN (fn, ENTRY_BLOCK, ENTRY_BLOCK_PTR_FOR_FN (fn));
     160      3268316 :   SET_BASIC_BLOCK_FOR_FN (fn, EXIT_BLOCK, EXIT_BLOCK_PTR_FOR_FN (fn));
     161              : 
     162      3268316 :   ENTRY_BLOCK_PTR_FOR_FN (fn)->next_bb
     163      3268316 :     = EXIT_BLOCK_PTR_FOR_FN (fn);
     164      3268316 :   EXIT_BLOCK_PTR_FOR_FN (fn)->prev_bb
     165      3268316 :     = ENTRY_BLOCK_PTR_FOR_FN (fn);
     166      3268316 : }
     167              : 
     168              : void
     169      3183057 : init_empty_tree_cfg (void)
     170              : {
     171      3183057 :   init_empty_tree_cfg_for_function (cfun);
     172      3183057 : }
     173              : 
     174              : /*---------------------------------------------------------------------------
     175              :                               Create basic blocks
     176              : ---------------------------------------------------------------------------*/
     177              : 
     178              : /* Entry point to the CFG builder for trees.  SEQ is the sequence of
     179              :    statements to be added to the flowgraph.  */
     180              : 
     181              : static void
     182      2880210 : build_gimple_cfg (gimple_seq seq)
     183              : {
     184              :   /* Register specific gimple functions.  */
     185      2880210 :   gimple_register_cfg_hooks ();
     186              : 
     187      2880210 :   memset ((void *) &cfg_stats, 0, sizeof (cfg_stats));
     188              : 
     189      2880210 :   init_empty_tree_cfg ();
     190              : 
     191      2880210 :   make_blocks (seq);
     192              : 
     193              :   /* Make sure there is always at least one block, even if it's empty.  */
     194      2880210 :   if (n_basic_blocks_for_fn (cfun) == NUM_FIXED_BLOCKS)
     195            0 :     create_empty_bb (ENTRY_BLOCK_PTR_FOR_FN (cfun));
     196              : 
     197              :   /* Adjust the size of the array.  */
     198      2880210 :   if (basic_block_info_for_fn (cfun)->length ()
     199      2880210 :       < (size_t) n_basic_blocks_for_fn (cfun))
     200            0 :     vec_safe_grow_cleared (basic_block_info_for_fn (cfun),
     201              :                            n_basic_blocks_for_fn (cfun));
     202              : 
     203              :   /* To speed up statement iterator walks, we first purge dead labels.  */
     204      2880210 :   cleanup_dead_labels ();
     205              : 
     206              :   /* Group case nodes to reduce the number of edges.
     207              :      We do this after cleaning up dead labels because otherwise we miss
     208              :      a lot of obvious case merging opportunities.  */
     209      2880210 :   group_case_labels ();
     210              : 
     211              :   /* Create the edges of the flowgraph.  */
     212      2880210 :   make_edges ();
     213      2880210 :   assign_discriminators ();
     214      2880210 :   cleanup_dead_labels ();
     215      2880210 : }
     216              : 
     217              : /* Look for ANNOTATE calls with loop annotation kind in BB; if found, remove
     218              :    them and propagate the information to LOOP.  We assume that the annotations
     219              :    come immediately before the condition in BB, if any.  */
     220              : 
     221              : static void
     222      1549985 : replace_loop_annotate_in_block (basic_block bb, class loop *loop)
     223              : {
     224      1549985 :   gimple_stmt_iterator gsi = gsi_last_bb (bb);
     225      1549985 :   gimple *stmt = gsi_stmt (gsi);
     226              : 
     227      1549985 :   if (!(stmt && gimple_code (stmt) == GIMPLE_COND))
     228       574290 :     return;
     229              : 
     230       986671 :   for (gsi_prev_nondebug (&gsi); !gsi_end_p (gsi); gsi_prev (&gsi))
     231              :     {
     232       536473 :       stmt = gsi_stmt (gsi);
     233       536473 :       if (gimple_code (stmt) != GIMPLE_CALL)
     234              :         break;
     235        56223 :       if (!gimple_call_internal_p (stmt)
     236        56223 :           || gimple_call_internal_fn (stmt) != IFN_ANNOTATE)
     237              :         break;
     238              : 
     239         5488 :       switch ((annot_expr_kind) tree_to_shwi (gimple_call_arg (stmt, 1)))
     240              :         {
     241          352 :         case annot_expr_ivdep_kind:
     242          352 :           loop->safelen = INT_MAX;
     243          352 :           break;
     244         1997 :         case annot_expr_unroll_kind:
     245         1997 :           loop->unroll
     246         1997 :             = (unsigned short) tree_to_shwi (gimple_call_arg (stmt, 2));
     247         1997 :           cfun->has_unroll = true;
     248         1997 :           break;
     249         3072 :         case annot_expr_no_vector_kind:
     250         3072 :           loop->dont_vectorize = true;
     251         3072 :           break;
     252            3 :         case annot_expr_vector_kind:
     253            3 :           loop->force_vectorize = true;
     254            3 :           cfun->has_force_vectorize_loops = true;
     255            3 :           break;
     256            0 :         case annot_expr_parallel_kind:
     257            0 :           loop->can_be_parallel = true;
     258            0 :           loop->safelen = INT_MAX;
     259            0 :           break;
     260           64 :         case annot_expr_maybe_infinite_kind:
     261           64 :           loop->finite_p = false;
     262           64 :           break;
     263            0 :         default:
     264            0 :           gcc_unreachable ();
     265              :         }
     266              : 
     267         5488 :       stmt = gimple_build_assign (gimple_call_lhs (stmt),
     268              :                                   gimple_call_arg (stmt, 0));
     269         5488 :       gsi_replace (&gsi, stmt, true);
     270              :     }
     271              : }
     272              : 
     273              : /* Look for ANNOTATE calls with loop annotation kind; if found, remove
     274              :    them and propagate the information to the loop.  We assume that the
     275              :    annotations come immediately before the condition of the loop.  */
     276              : 
     277              : static void
     278      2880210 : replace_loop_annotate (void)
     279              : {
     280      2880210 :   basic_block bb;
     281      2880210 :   gimple_stmt_iterator gsi;
     282      2880210 :   gimple *stmt;
     283              : 
     284      9254727 :   for (auto loop : loops_list (cfun, 0))
     285              :     {
     286              :       /* Push the global flag_finite_loops state down to individual loops.  */
     287       614097 :       loop->finite_p = flag_finite_loops;
     288              : 
     289              :       /* Check all exit source blocks for annotations.  */
     290      3383342 :       for (auto e : get_loop_exit_edges (loop))
     291      2164082 :         replace_loop_annotate_in_block (e->src, loop);
     292      2880210 :     }
     293              : 
     294              :   /* Remove IFN_ANNOTATE.  Safeguard for the case loop->latch == NULL.  */
     295     20488167 :   FOR_EACH_BB_FN (bb, cfun)
     296              :     {
     297    167588856 :       for (gsi = gsi_last_bb (bb); !gsi_end_p (gsi); gsi_prev (&gsi))
     298              :         {
     299     66186471 :           stmt = gsi_stmt (gsi);
     300     66186471 :           if (gimple_code (stmt) != GIMPLE_CALL)
     301     55929371 :             continue;
     302     10257100 :           if (!gimple_call_internal_p (stmt)
     303     10257100 :               || gimple_call_internal_fn (stmt) != IFN_ANNOTATE)
     304     10257100 :             continue;
     305              : 
     306            0 :           switch ((annot_expr_kind) tree_to_shwi (gimple_call_arg (stmt, 1)))
     307              :             {
     308            0 :             case annot_expr_ivdep_kind:
     309            0 :             case annot_expr_unroll_kind:
     310            0 :             case annot_expr_no_vector_kind:
     311            0 :             case annot_expr_vector_kind:
     312            0 :             case annot_expr_parallel_kind:
     313            0 :             case annot_expr_maybe_infinite_kind:
     314            0 :               break;
     315            0 :             default:
     316            0 :               gcc_unreachable ();
     317              :             }
     318              : 
     319            0 :           warning_at (gimple_location (stmt), 0, "ignoring loop annotation");
     320            0 :           stmt = gimple_build_assign (gimple_call_lhs (stmt),
     321              :                                       gimple_call_arg (stmt, 0));
     322            0 :           gsi_replace (&gsi, stmt, true);
     323              :         }
     324              :     }
     325      2880210 : }
     326              : 
     327              : static unsigned int
     328      2880210 : execute_build_cfg (void)
     329              : {
     330      2880210 :   gimple_seq body = gimple_body (current_function_decl);
     331              : 
     332      2880210 :   build_gimple_cfg (body);
     333      2880210 :   gimple_set_body (current_function_decl, NULL);
     334      2880210 :   if (dump_file && (dump_flags & TDF_DETAILS))
     335              :     {
     336            2 :       fprintf (dump_file, "Scope blocks:\n");
     337            2 :       dump_scope_blocks (dump_file, dump_flags);
     338              :     }
     339      2880210 :   cleanup_tree_cfg ();
     340              : 
     341      2880210 :   bb_to_omp_idx.release ();
     342              : 
     343      2880210 :   loop_optimizer_init (AVOID_CFG_MODIFICATIONS);
     344      2880210 :   replace_loop_annotate ();
     345      2880210 :   return 0;
     346              : }
     347              : 
     348              : namespace {
     349              : 
     350              : const pass_data pass_data_build_cfg =
     351              : {
     352              :   GIMPLE_PASS, /* type */
     353              :   "cfg", /* name */
     354              :   OPTGROUP_NONE, /* optinfo_flags */
     355              :   TV_TREE_CFG, /* tv_id */
     356              :   PROP_gimple_leh, /* properties_required */
     357              :   ( PROP_cfg | PROP_loops ), /* properties_provided */
     358              :   0, /* properties_destroyed */
     359              :   0, /* todo_flags_start */
     360              :   0, /* todo_flags_finish */
     361              : };
     362              : 
     363              : class pass_build_cfg : public gimple_opt_pass
     364              : {
     365              : public:
     366       298844 :   pass_build_cfg (gcc::context *ctxt)
     367       597688 :     : gimple_opt_pass (pass_data_build_cfg, ctxt)
     368              :   {}
     369              : 
     370              :   /* opt_pass methods: */
     371      2880210 :   unsigned int execute (function *) final override
     372              :   {
     373      2880210 :     return execute_build_cfg ();
     374              :   }
     375              : 
     376              : }; // class pass_build_cfg
     377              : 
     378              : } // anon namespace
     379              : 
     380              : gimple_opt_pass *
     381       298844 : make_pass_build_cfg (gcc::context *ctxt)
     382              : {
     383       298844 :   return new pass_build_cfg (ctxt);
     384              : }
     385              : 
     386              : 
     387              : /* Return true if T is a computed goto.  */
     388              : 
     389              : bool
     390    639604581 : computed_goto_p (gimple *t)
     391              : {
     392    639604581 :   return (gimple_code (t) == GIMPLE_GOTO
     393    639604581 :           && TREE_CODE (gimple_goto_dest (t)) != LABEL_DECL);
     394              : }
     395              : 
     396              : /* Returns true if the sequence of statements STMTS only contains
     397              :    a call to __builtin_unreachable ().  */
     398              : 
     399              : bool
     400      3681486 : gimple_seq_unreachable_p (gimple_seq stmts)
     401              : {
     402      3681486 :   if (stmts == NULL
     403              :       /* Return false if -fsanitize=unreachable, we don't want to
     404              :          optimize away those calls, but rather turn them into
     405              :          __ubsan_handle_builtin_unreachable () or __builtin_trap ()
     406              :          later.  */
     407      3681486 :       || sanitize_flags_p (SANITIZE_UNREACHABLE))
     408         2703 :     return false;
     409              : 
     410      3678783 :   gimple_stmt_iterator gsi = gsi_last (stmts);
     411              : 
     412      3678783 :   if (!gimple_call_builtin_p (gsi_stmt (gsi), BUILT_IN_UNREACHABLE))
     413              :     return false;
     414              : 
     415      1089844 :   for (gsi_prev (&gsi); !gsi_end_p (gsi); gsi_prev (&gsi))
     416              :     {
     417         8503 :       gimple *stmt = gsi_stmt (gsi);
     418         8503 :       if (gimple_code (stmt) != GIMPLE_LABEL
     419         4176 :           && !is_gimple_debug (stmt)
     420         9592 :           && !gimple_clobber_p (stmt))
     421              :       return false;
     422              :     }
     423              :   return true;
     424              : }
     425              : 
     426              : /* Returns true for edge E where e->src ends with a GIMPLE_COND and
     427              :    the other edge points to a bb with just __builtin_unreachable ().
     428              :    I.e. return true for C->M edge in:
     429              :    <bb C>:
     430              :    ...
     431              :    if (something)
     432              :      goto <bb N>;
     433              :    else
     434              :      goto <bb M>;
     435              :    <bb N>:
     436              :    __builtin_unreachable ();
     437              :    <bb M>:  */
     438              : 
     439              : bool
     440     11939784 : assert_unreachable_fallthru_edge_p (edge e)
     441              : {
     442     11939784 :   basic_block pred_bb = e->src;
     443     23879568 :   if (safe_is_a <gcond *> (*gsi_last_bb (pred_bb)))
     444              :     {
     445     11939784 :       basic_block other_bb = EDGE_SUCC (pred_bb, 0)->dest;
     446     11939784 :       if (other_bb == e->dest)
     447      6316642 :         other_bb = EDGE_SUCC (pred_bb, 1)->dest;
     448     11939784 :       if (EDGE_COUNT (other_bb->succs) == 0)
     449      3686116 :         return gimple_seq_unreachable_p (bb_seq (other_bb));
     450              :     }
     451              :   return false;
     452              : }
     453              : 
     454              : 
     455              : /* Initialize GF_CALL_CTRL_ALTERING flag, which indicates the call
     456              :    could alter control flow except via eh. We initialize the flag at
     457              :    CFG build time and only ever clear it later.  */
     458              : 
     459              : static void
     460     10907104 : gimple_call_initialize_ctrl_altering (gimple *stmt)
     461              : {
     462     10907104 :   int flags = gimple_call_flags (stmt);
     463              : 
     464              :   /* A call alters control flow if it can make an abnormal goto.  */
     465     10907104 :   if (call_can_make_abnormal_goto (stmt)
     466              :       /* A call also alters control flow if it does not return.  */
     467     10899897 :       || flags & ECF_NORETURN
     468              :       /* TM ending statements have backedges out of the transaction.
     469              :          Return true so we split the basic block containing them.
     470              :          Note that the TM_BUILTIN test is merely an optimization.  */
     471      9277366 :       || ((flags & ECF_TM_BUILTIN)
     472          985 :           && is_tm_ending_fndecl (gimple_call_fndecl (stmt)))
     473              :       /* BUILT_IN_RETURN call is same as return statement.  */
     474      9276388 :       || gimple_call_builtin_p (stmt, BUILT_IN_RETURN)
     475              :       /* IFN_UNIQUE should be the last insn, to make checking for it
     476              :          as cheap as possible.  */
     477     20183492 :       || (gimple_call_internal_p (stmt)
     478       487209 :           && gimple_call_internal_unique_p (stmt)))
     479      1716509 :     gimple_call_set_ctrl_altering (stmt, true);
     480              :   else
     481      9190595 :     gimple_call_set_ctrl_altering (stmt, false);
     482     10907104 : }
     483              : 
     484              : 
     485              : /* Insert SEQ after BB and build a flowgraph.  */
     486              : 
     487              : static basic_block
     488      2932523 : make_blocks_1 (gimple_seq seq, basic_block bb)
     489              : {
     490      2932523 :   gimple_stmt_iterator i = gsi_start (seq);
     491      2932523 :   gimple *stmt = NULL;
     492      2932523 :   gimple *prev_stmt = NULL;
     493      2932523 :   bool start_new_block = true;
     494      2932523 :   bool first_stmt_of_seq = true;
     495              : 
     496     94055781 :   while (!gsi_end_p (i))
     497              :     {
     498              :       /* PREV_STMT should only be set to a debug stmt if the debug
     499              :          stmt is before nondebug stmts.  Once stmt reaches a nondebug
     500              :          nonlabel, prev_stmt will be set to it, so that
     501              :          stmt_starts_bb_p will know to start a new block if a label is
     502              :          found.  However, if stmt was a label after debug stmts only,
     503              :          keep the label in prev_stmt even if we find further debug
     504              :          stmts, for there may be other labels after them, and they
     505              :          should land in the same block.  */
     506     91123258 :       if (!prev_stmt || !stmt || !is_gimple_debug (stmt))
     507              :         prev_stmt = stmt;
     508     91123258 :       stmt = gsi_stmt (i);
     509              : 
     510     91123258 :       if (stmt && is_gimple_call (stmt))
     511     10907104 :         gimple_call_initialize_ctrl_altering (stmt);
     512              : 
     513              :       /* If the statement starts a new basic block or if we have determined
     514              :          in a previous pass that we need to create a new block for STMT, do
     515              :          so now.  */
     516     91123258 :       if (start_new_block || stmt_starts_bb_p (stmt, prev_stmt))
     517              :         {
     518     21698836 :           if (!first_stmt_of_seq)
     519     18766313 :             gsi_split_seq_before (&i, &seq);
     520     21698836 :           bb = create_basic_block (seq, bb);
     521     21698836 :           start_new_block = false;
     522     21698836 :           prev_stmt = NULL;
     523              :         }
     524              : 
     525              :       /* Now add STMT to BB and create the subgraphs for special statement
     526              :          codes.  */
     527     91123258 :       gimple_set_bb (stmt, bb);
     528              : 
     529              :       /* If STMT is a basic block terminator, set START_NEW_BLOCK for the
     530              :          next iteration.  */
     531     91123258 :       if (stmt_ends_bb_p (stmt))
     532              :         {
     533              :           /* If the stmt can make abnormal goto use a new temporary
     534              :              for the assignment to the LHS.  This makes sure the old value
     535              :              of the LHS is available on the abnormal edge.  Otherwise
     536              :              we will end up with overlapping life-ranges for abnormal
     537              :              SSA names.  */
     538     19760432 :           if (gimple_has_lhs (stmt)
     539      1613564 :               && stmt_can_make_abnormal_goto (stmt)
     540      3441753 :               && is_gimple_reg_type (TREE_TYPE (gimple_get_lhs (stmt))))
     541              :             {
     542         2494 :               tree lhs = gimple_get_lhs (stmt);
     543         2494 :               tree tmp = create_tmp_var (TREE_TYPE (lhs));
     544         2494 :               gimple *s = gimple_build_assign (lhs, tmp);
     545         2494 :               gimple_set_location (s, gimple_location (stmt));
     546         2494 :               gimple_set_block (s, gimple_block (stmt));
     547         2494 :               gimple_set_lhs (stmt, tmp);
     548         2494 :               gsi_insert_after (&i, s, GSI_SAME_STMT);
     549              :             }
     550              :           start_new_block = true;
     551              :         }
     552              : 
     553     91123258 :       gsi_next (&i);
     554     91123258 :       first_stmt_of_seq = false;
     555              :     }
     556      2932523 :   return bb;
     557              : }
     558              : 
     559              : /* Build a flowgraph for the sequence of stmts SEQ.  */
     560              : 
     561              : static void
     562      2880210 : make_blocks (gimple_seq seq)
     563              : {
     564              :   /* Look for debug markers right before labels, and move the debug
     565              :      stmts after the labels.  Accepting labels among debug markers
     566              :      adds no value, just complexity; if we wanted to annotate labels
     567              :      with view numbers (so sequencing among markers would matter) or
     568              :      somesuch, we're probably better off still moving the labels, but
     569              :      adding other debug annotations in their original positions or
     570              :      emitting nonbind or bind markers associated with the labels in
     571              :      the original position of the labels.
     572              : 
     573              :      Moving labels would probably be simpler, but we can't do that:
     574              :      moving labels assigns label ids to them, and doing so because of
     575              :      debug markers makes for -fcompare-debug and possibly even codegen
     576              :      differences.  So, we have to move the debug stmts instead.  To
     577              :      that end, we scan SEQ backwards, marking the position of the
     578              :      latest (earliest we find) label, and moving debug stmts that are
     579              :      not separated from it by nondebug nonlabel stmts after the
     580              :      label.  */
     581      2880210 :   if (MAY_HAVE_DEBUG_MARKER_STMTS)
     582              :     {
     583      1742859 :       gimple_stmt_iterator label = gsi_none ();
     584              : 
     585    100066540 :       for (gimple_stmt_iterator i = gsi_last (seq); !gsi_end_p (i); gsi_prev (&i))
     586              :         {
     587     48290411 :           gimple *stmt = gsi_stmt (i);
     588              : 
     589              :           /* If this is the first label we encounter (latest in SEQ)
     590              :              before nondebug stmts, record its position.  */
     591     48290411 :           if (is_a <glabel *> (stmt))
     592              :             {
     593      9091769 :               if (gsi_end_p (label))
     594      8448475 :                 label = i;
     595      9091769 :               continue;
     596              :             }
     597              : 
     598              :           /* Without a recorded label position to move debug stmts to,
     599              :              there's nothing to do.  */
     600     39198642 :           if (gsi_end_p (label))
     601     30732997 :             continue;
     602              : 
     603              :           /* Move the debug stmt at I after LABEL.  */
     604      8465645 :           if (is_gimple_debug (stmt))
     605              :             {
     606        22459 :               gcc_assert (gimple_debug_nonbind_marker_p (stmt));
     607              :               /* As STMT is removed, I advances to the stmt after
     608              :                  STMT, so the gsi_prev in the for "increment"
     609              :                  expression gets us to the stmt we're to visit after
     610              :                  STMT.  LABEL, however, would advance to the moved
     611              :                  stmt if we passed it to gsi_move_after, so pass it a
     612              :                  copy instead, so as to keep LABEL pointing to the
     613              :                  LABEL.  */
     614        22459 :               gimple_stmt_iterator copy = label;
     615        22459 :               gsi_move_after (&i, &copy);
     616        22459 :               continue;
     617        22459 :             }
     618              : 
     619              :           /* There aren't any (more?) debug stmts before label, so
     620              :              there isn't anything else to move after it.  */
     621              :           label = gsi_none ();
     622              :         }
     623              :     }
     624              : 
     625      2880210 :   make_blocks_1 (seq, ENTRY_BLOCK_PTR_FOR_FN (cfun));
     626      2880210 : }
     627              : 
     628              : /* Create and return a new empty basic block after bb AFTER.  */
     629              : 
     630              : static basic_block
     631     69773585 : create_bb (void *h, void *e, basic_block after)
     632              : {
     633     69773585 :   basic_block bb;
     634              : 
     635     69773585 :   gcc_assert (!e);
     636              : 
     637              :   /* Create and initialize a new basic block.  Since alloc_block uses
     638              :      GC allocation that clears memory to allocate a basic block, we do
     639              :      not have to clear the newly allocated basic block here.  */
     640     69773585 :   bb = alloc_block ();
     641              : 
     642     69773585 :   bb->index = last_basic_block_for_fn (cfun);
     643     69773585 :   bb->flags = BB_NEW;
     644     69773585 :   set_bb_seq (bb, h ? (gimple_seq) h : NULL);
     645              : 
     646              :   /* Add the new block to the linked list of blocks.  */
     647     69773585 :   link_block (bb, after);
     648              : 
     649              :   /* Grow the basic block array if needed.  */
     650     69773585 :   if ((size_t) last_basic_block_for_fn (cfun)
     651     69773585 :       == basic_block_info_for_fn (cfun)->length ())
     652     21188162 :     vec_safe_grow_cleared (basic_block_info_for_fn (cfun),
     653     21188162 :                            last_basic_block_for_fn (cfun) + 1);
     654              : 
     655              :   /* Add the newly created block to the array.  */
     656     69773585 :   SET_BASIC_BLOCK_FOR_FN (cfun, last_basic_block_for_fn (cfun), bb);
     657              : 
     658     69773585 :   n_basic_blocks_for_fn (cfun)++;
     659     69773585 :   last_basic_block_for_fn (cfun)++;
     660              : 
     661     69773585 :   return bb;
     662              : }
     663              : 
     664              : 
     665              : /*---------------------------------------------------------------------------
     666              :                                  Edge creation
     667              : ---------------------------------------------------------------------------*/
     668              : 
     669              : /* If basic block BB has an abnormal edge to a basic block
     670              :    containing IFN_ABNORMAL_DISPATCHER internal call, return
     671              :    that the dispatcher's basic block, otherwise return NULL.  */
     672              : 
     673              : basic_block
     674          662 : get_abnormal_succ_dispatcher (basic_block bb)
     675              : {
     676          662 :   edge e;
     677          662 :   edge_iterator ei;
     678              : 
     679         1405 :   FOR_EACH_EDGE (e, ei, bb->succs)
     680         1055 :     if ((e->flags & (EDGE_ABNORMAL | EDGE_EH)) == EDGE_ABNORMAL)
     681              :       {
     682          312 :         gimple_stmt_iterator gsi
     683          312 :           = gsi_start_nondebug_after_labels_bb (e->dest);
     684          312 :         gimple *g = gsi_stmt (gsi);
     685          312 :         if (g && gimple_call_internal_p (g, IFN_ABNORMAL_DISPATCHER))
     686          312 :           return e->dest;
     687              :       }
     688              :   return NULL;
     689              : }
     690              : 
     691              : /* Helper function for make_edges.  Create a basic block with
     692              :    with ABNORMAL_DISPATCHER internal call in it if needed, and
     693              :    create abnormal edges from BBS to it and from it to FOR_BB
     694              :    if COMPUTED_GOTO is false, otherwise factor the computed gotos.  */
     695              : 
     696              : static void
     697         5244 : handle_abnormal_edges (basic_block *dispatcher_bbs, basic_block for_bb,
     698              :                        auto_vec<basic_block> *bbs, bool computed_goto)
     699              : {
     700         5244 :   basic_block *dispatcher = dispatcher_bbs + (computed_goto ? 1 : 0);
     701         5244 :   unsigned int idx = 0;
     702         5244 :   basic_block bb;
     703         5244 :   bool inner = false;
     704              : 
     705         5244 :   if (!bb_to_omp_idx.is_empty ())
     706              :     {
     707           11 :       dispatcher = dispatcher_bbs + 2 * bb_to_omp_idx[for_bb->index];
     708           11 :       if (bb_to_omp_idx[for_bb->index] != 0)
     709            6 :         inner = true;
     710              :     }
     711              : 
     712              :   /* If the dispatcher has been created already, then there are basic
     713              :      blocks with abnormal edges to it, so just make a new edge to
     714              :      for_bb.  */
     715         5244 :   if (*dispatcher == NULL)
     716              :     {
     717              :       /* Check if there are any basic blocks that need to have
     718              :          abnormal edges to this dispatcher.  If there are none, return
     719              :          early.  */
     720         3454 :       if (bb_to_omp_idx.is_empty ())
     721              :         {
     722         3443 :           if (bbs->is_empty ())
     723         5244 :             return;
     724              :         }
     725              :       else
     726              :         {
     727           18 :           FOR_EACH_VEC_ELT (*bbs, idx, bb)
     728           18 :             if (bb_to_omp_idx[bb->index] == bb_to_omp_idx[for_bb->index])
     729              :               break;
     730           11 :           if (bb == NULL)
     731              :             return;
     732              :         }
     733              : 
     734              :       /* Create the dispatcher bb.  */
     735         2628 :       *dispatcher = create_basic_block (NULL, for_bb);
     736         2628 :       if (computed_goto)
     737              :         {
     738              :           /* Factor computed gotos into a common computed goto site.  Also
     739              :              record the location of that site so that we can un-factor the
     740              :              gotos after we have converted back to normal form.  */
     741          546 :           gimple_stmt_iterator gsi = gsi_start_bb (*dispatcher);
     742              : 
     743              :           /* Create the destination of the factored goto.  Each original
     744              :              computed goto will put its desired destination into this
     745              :              variable and jump to the label we create immediately below.  */
     746          546 :           tree var = create_tmp_var (ptr_type_node, "gotovar");
     747              : 
     748              :           /* Build a label for the new block which will contain the
     749              :              factored computed goto.  */
     750          546 :           tree factored_label_decl
     751          546 :             = create_artificial_label (UNKNOWN_LOCATION);
     752          546 :           gimple *factored_computed_goto_label
     753          546 :             = gimple_build_label (factored_label_decl);
     754          546 :           gsi_insert_after (&gsi, factored_computed_goto_label, GSI_NEW_STMT);
     755              : 
     756              :           /* Build our new computed goto.  */
     757          546 :           gimple *factored_computed_goto = gimple_build_goto (var);
     758          546 :           gsi_insert_after (&gsi, factored_computed_goto, GSI_NEW_STMT);
     759              : 
     760         2108 :           FOR_EACH_VEC_ELT (*bbs, idx, bb)
     761              :             {
     762         1016 :               if (!bb_to_omp_idx.is_empty ()
     763            0 :                   && bb_to_omp_idx[bb->index] != bb_to_omp_idx[for_bb->index])
     764            0 :                 continue;
     765              : 
     766         1016 :               gsi = gsi_last_bb (bb);
     767         1016 :               gimple *last = gsi_stmt (gsi);
     768              : 
     769         1016 :               gcc_assert (computed_goto_p (last));
     770              : 
     771              :               /* Copy the original computed goto's destination into VAR.  */
     772         1016 :               gimple *assignment
     773         1016 :                 = gimple_build_assign (var, gimple_goto_dest (last));
     774         1016 :               gsi_insert_before (&gsi, assignment, GSI_SAME_STMT);
     775              : 
     776         1016 :               edge e = make_edge (bb, *dispatcher, EDGE_FALLTHRU);
     777         1016 :               e->goto_locus = gimple_location (last);
     778         1016 :               gsi_remove (&gsi, true);
     779              :             }
     780              :         }
     781              :       else
     782              :         {
     783         2082 :           tree arg = inner ? boolean_true_node : boolean_false_node;
     784         2082 :           gcall *g = gimple_build_call_internal (IFN_ABNORMAL_DISPATCHER,
     785              :                                                  1, arg);
     786         2082 :           gimple_call_set_ctrl_altering (g, true);
     787         2082 :           gimple_stmt_iterator gsi = gsi_after_labels (*dispatcher);
     788         2082 :           gsi_insert_after (&gsi, g, GSI_NEW_STMT);
     789              : 
     790              :           /* Create predecessor edges of the dispatcher.  */
     791        13461 :           FOR_EACH_VEC_ELT (*bbs, idx, bb)
     792              :             {
     793         7215 :               if (!bb_to_omp_idx.is_empty ()
     794           44 :                   && bb_to_omp_idx[bb->index] != bb_to_omp_idx[for_bb->index])
     795           20 :                 continue;
     796         7195 :               make_edge (bb, *dispatcher, EDGE_ABNORMAL);
     797              :             }
     798              :         }
     799              :     }
     800              : 
     801         4418 :   make_edge (*dispatcher, for_bb, EDGE_ABNORMAL);
     802              : }
     803              : 
     804              : /* Creates outgoing edges for BB.  Returns 1 when it ends with an
     805              :    computed goto, returns 2 when it ends with a statement that
     806              :    might return to this function via an nonlocal goto, otherwise
     807              :    return 0.  Updates *PCUR_REGION with the OMP region this BB is in.  */
     808              : 
     809              : static int
     810     21698836 : make_edges_bb (basic_block bb, struct omp_region **pcur_region, int *pomp_index)
     811              : {
     812     21698836 :   gimple *last = *gsi_last_bb (bb);
     813     21698836 :   bool fallthru = false;
     814     21698836 :   int ret = 0;
     815              : 
     816     21698836 :   if (!last)
     817              :     return ret;
     818              : 
     819     21698836 :   switch (gimple_code (last))
     820              :     {
     821      6113173 :     case GIMPLE_GOTO:
     822      6113173 :       if (make_goto_expr_edges (bb))
     823     21698836 :         ret = 1;
     824              :       fallthru = false;
     825              :       break;
     826      2871098 :     case GIMPLE_RETURN:
     827      2871098 :       {
     828      2871098 :         edge e = make_edge (bb, EXIT_BLOCK_PTR_FOR_FN (cfun), 0);
     829      2871098 :         e->goto_locus = gimple_location (last);
     830      2871098 :         fallthru = false;
     831              :       }
     832      2871098 :       break;
     833      5464926 :     case GIMPLE_COND:
     834      5464926 :       make_cond_expr_edges (bb);
     835      5464926 :       fallthru = false;
     836      5464926 :       break;
     837        53044 :     case GIMPLE_SWITCH:
     838        53044 :       make_gimple_switch_edges (as_a <gswitch *> (last), bb);
     839        53044 :       fallthru = false;
     840        53044 :       break;
     841       867565 :     case GIMPLE_RESX:
     842       867565 :       make_eh_edge (last);
     843       867565 :       fallthru = false;
     844       867565 :       break;
     845        41776 :     case GIMPLE_EH_DISPATCH:
     846        41776 :       fallthru = make_eh_dispatch_edges (as_a <geh_dispatch *> (last));
     847        41776 :       break;
     848              : 
     849      3775956 :     case GIMPLE_CALL:
     850              :       /* If this function receives a nonlocal goto, then we need to
     851              :          make edges from this call site to all the nonlocal goto
     852              :          handlers.  */
     853      3775956 :       if (stmt_can_make_abnormal_goto (last))
     854         7207 :         ret = 2;
     855              : 
     856              :       /* If this statement has reachable exception handlers, then
     857              :          create abnormal edges to them.  */
     858      3775956 :       make_eh_edge (last);
     859              : 
     860              :       /* BUILTIN_RETURN is really a return statement.  */
     861      3775956 :       if (gimple_call_builtin_p (last, BUILT_IN_RETURN))
     862              :         {
     863          368 :           make_edge (bb, EXIT_BLOCK_PTR_FOR_FN (cfun), 0);
     864          368 :           fallthru = false;
     865              :         }
     866              :       /* Some calls are known not to return.  */
     867              :       else
     868      3775588 :         fallthru = !gimple_call_noreturn_p (last);
     869              :       break;
     870              : 
     871      2202542 :     case GIMPLE_ASSIGN:
     872              :       /* A GIMPLE_ASSIGN may throw internally and thus be considered
     873              :          control-altering.  */
     874      2202542 :       if (is_ctrl_altering_stmt (last))
     875       618538 :         make_eh_edge (last);
     876              :       fallthru = true;
     877              :       break;
     878              : 
     879         1565 :     case GIMPLE_ASM:
     880         1565 :       make_gimple_asm_edges (bb);
     881         1565 :       fallthru = true;
     882         1565 :       break;
     883              : 
     884       290176 :     CASE_GIMPLE_OMP:
     885       290176 :       fallthru = omp_make_gimple_edges (bb, pcur_region, pomp_index);
     886       290176 :       break;
     887              : 
     888          411 :     case GIMPLE_TRANSACTION:
     889          411 :       {
     890          411 :         gtransaction *txn = as_a <gtransaction *> (last);
     891          411 :         tree label1 = gimple_transaction_label_norm (txn);
     892          411 :         tree label2 = gimple_transaction_label_uninst (txn);
     893              : 
     894          411 :         if (label1)
     895          401 :           make_edge (bb, label_to_block (cfun, label1), EDGE_FALLTHRU);
     896          411 :         if (label2)
     897          397 :           make_edge (bb, label_to_block (cfun, label2),
     898          397 :                      EDGE_TM_UNINSTRUMENTED | (label1 ? 0 : EDGE_FALLTHRU));
     899              : 
     900          411 :         tree label3 = gimple_transaction_label_over (txn);
     901          411 :         if (gimple_transaction_subcode (txn)
     902              :             & (GTMA_HAVE_ABORT | GTMA_IS_OUTER))
     903           65 :           make_edge (bb, label_to_block (cfun, label3), EDGE_TM_ABORT);
     904              : 
     905              :         fallthru = false;
     906              :       }
     907              :       break;
     908              : 
     909        16604 :     default:
     910        16604 :       gcc_assert (!stmt_ends_bb_p (last));
     911              :       fallthru = true;
     912              :       break;
     913              :     }
     914              : 
     915     13366106 :   if (fallthru)
     916      4618913 :     make_edge (bb, bb->next_bb, EDGE_FALLTHRU);
     917              : 
     918              :   return ret;
     919              : }
     920              : 
     921              : /* Join all the blocks in the flowgraph.  */
     922              : 
     923              : static void
     924      2880210 : make_edges (void)
     925              : {
     926      2880210 :   basic_block bb;
     927      2880210 :   struct omp_region *cur_region = NULL;
     928      2880210 :   auto_vec<basic_block> ab_edge_goto;
     929      2880210 :   auto_vec<basic_block> ab_edge_call;
     930      2880210 :   int cur_omp_region_idx = 0;
     931              : 
     932              :   /* Create an edge from entry to the first block with executable
     933              :      statements in it.  */
     934      2880210 :   make_edge (ENTRY_BLOCK_PTR_FOR_FN (cfun),
     935      2880210 :              BASIC_BLOCK_FOR_FN (cfun, NUM_FIXED_BLOCKS),
     936              :              EDGE_FALLTHRU);
     937              : 
     938              :   /* Traverse the basic block array placing edges.  */
     939     24439592 :   FOR_EACH_BB_FN (bb, cfun)
     940              :     {
     941     21559382 :       int mer;
     942              : 
     943     21559382 :       if (!bb_to_omp_idx.is_empty ())
     944       726136 :         bb_to_omp_idx[bb->index] = cur_omp_region_idx;
     945              : 
     946     21559382 :       mer = make_edges_bb (bb, &cur_region, &cur_omp_region_idx);
     947     21559382 :       if (mer == 1)
     948         1117 :         ab_edge_goto.safe_push (bb);
     949     21558265 :       else if (mer == 2)
     950         7207 :         ab_edge_call.safe_push (bb);
     951              : 
     952     22095041 :       if (cur_region && bb_to_omp_idx.is_empty ())
     953        22250 :         bb_to_omp_idx.safe_grow_cleared (n_basic_blocks_for_fn (cfun), true);
     954              :     }
     955              : 
     956              :   /* Computed gotos are hell to deal with, especially if there are
     957              :      lots of them with a large number of destinations.  So we factor
     958              :      them to a common computed goto location before we build the
     959              :      edge list.  After we convert back to normal form, we will un-factor
     960              :      the computed gotos since factoring introduces an unwanted jump.
     961              :      For non-local gotos and abnormal edges from calls to calls that return
     962              :      twice or forced labels, factor the abnormal edges too, by having all
     963              :      abnormal edges from the calls go to a common artificial basic block
     964              :      with ABNORMAL_DISPATCHER internal call and abnormal edges from that
     965              :      basic block to all forced labels and calls returning twice.
     966              :      We do this per-OpenMP structured block, because those regions
     967              :      are guaranteed to be single entry single exit by the standard,
     968              :      so it is not allowed to enter or exit such regions abnormally this way,
     969              :      thus all computed gotos, non-local gotos and setjmp/longjmp calls
     970              :      must not transfer control across SESE region boundaries.  */
     971      2880210 :   if (!ab_edge_goto.is_empty () || !ab_edge_call.is_empty ())
     972              :     {
     973         2680 :       gimple_stmt_iterator gsi;
     974         2680 :       basic_block dispatcher_bb_array[2] = { NULL, NULL };
     975         2680 :       basic_block *dispatcher_bbs = dispatcher_bb_array;
     976         2680 :       int count = n_basic_blocks_for_fn (cfun);
     977              : 
     978         2680 :       if (!bb_to_omp_idx.is_empty ())
     979            9 :         dispatcher_bbs = XCNEWVEC (basic_block, 2 * count);
     980              : 
     981        31410 :       FOR_EACH_BB_FN (bb, cfun)
     982              :         {
     983        73092 :           for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
     984              :             {
     985        42618 :               glabel *label_stmt = dyn_cast <glabel *> (gsi_stmt (gsi));
     986        16111 :               tree target;
     987              : 
     988        16111 :               if (!label_stmt)
     989              :                 break;
     990              : 
     991        16111 :               target = gimple_label_label (label_stmt);
     992              : 
     993              :               /* Make an edge to every label block that has been marked as a
     994              :                  potential target for a computed goto or a non-local goto.  */
     995        16111 :               if (FORCED_LABEL (target))
     996         2411 :                 handle_abnormal_edges (dispatcher_bbs, bb, &ab_edge_goto,
     997              :                                        true);
     998        16111 :               if (DECL_NONLOCAL (target))
     999              :                 {
    1000          479 :                   handle_abnormal_edges (dispatcher_bbs, bb, &ab_edge_call,
    1001              :                                          false);
    1002          479 :                   break;
    1003              :                 }
    1004              :             }
    1005              : 
    1006        28730 :           if (!gsi_end_p (gsi) && is_gimple_debug (gsi_stmt (gsi)))
    1007         2316 :             gsi_next_nondebug (&gsi);
    1008        28730 :           if (!gsi_end_p (gsi))
    1009              :             {
    1010              :               /* Make an edge to every setjmp-like call.  */
    1011        26850 :               gimple *call_stmt = gsi_stmt (gsi);
    1012        26850 :               if (is_gimple_call (call_stmt)
    1013        26850 :                   && ((gimple_call_flags (call_stmt) & ECF_RETURNS_TWICE)
    1014         8226 :                       || gimple_call_builtin_p (call_stmt,
    1015              :                                                 BUILT_IN_SETJMP_RECEIVER)))
    1016         2354 :                 handle_abnormal_edges (dispatcher_bbs, bb, &ab_edge_call,
    1017              :                                        false);
    1018              :             }
    1019              :         }
    1020              : 
    1021         2689 :       if (!bb_to_omp_idx.is_empty ())
    1022            9 :         XDELETE (dispatcher_bbs);
    1023              :     }
    1024              : 
    1025      2880210 :   omp_free_regions ();
    1026      2880210 : }
    1027              : 
    1028              : /* Add SEQ after GSI.  Start new bb after GSI, and created further bbs as
    1029              :    needed.  Returns true if new bbs were created.
    1030              :    Note: This is transitional code, and should not be used for new code.  We
    1031              :    should be able to get rid of this by rewriting all target va-arg
    1032              :    gimplification hooks to use an interface gimple_build_cond_value as described
    1033              :    in https://gcc.gnu.org/ml/gcc-patches/2015-02/msg01194.html.  */
    1034              : 
    1035              : bool
    1036        52313 : gimple_find_sub_bbs (gimple_seq seq, gimple_stmt_iterator *gsi)
    1037              : {
    1038        52313 :   gimple *stmt = gsi_stmt (*gsi);
    1039        52313 :   basic_block bb = gimple_bb (stmt);
    1040        52313 :   basic_block lastbb, afterbb;
    1041        52313 :   int old_num_bbs = n_basic_blocks_for_fn (cfun);
    1042        52313 :   edge e;
    1043        52313 :   lastbb = make_blocks_1 (seq, bb);
    1044        52313 :   if (old_num_bbs == n_basic_blocks_for_fn (cfun))
    1045              :     return false;
    1046        52313 :   e = split_block (bb, stmt);
    1047              :   /* Move e->dest to come after the new basic blocks.  */
    1048        52313 :   afterbb = e->dest;
    1049        52313 :   unlink_block (afterbb);
    1050        52313 :   link_block (afterbb, lastbb);
    1051        52313 :   redirect_edge_succ (e, bb->next_bb);
    1052        52313 :   bb = bb->next_bb;
    1053       191767 :   while (bb != afterbb)
    1054              :     {
    1055       139454 :       struct omp_region *cur_region = NULL;
    1056       139454 :       profile_count cnt = profile_count::zero ();
    1057       139454 :       bool all = true;
    1058              : 
    1059       139454 :       int cur_omp_region_idx = 0;
    1060       139454 :       int mer = make_edges_bb (bb, &cur_region, &cur_omp_region_idx);
    1061       139454 :       gcc_assert (!mer && !cur_region);
    1062       139454 :       add_bb_to_loop (bb, afterbb->loop_father);
    1063              : 
    1064       139454 :       edge e;
    1065       139454 :       edge_iterator ei;
    1066       308214 :       FOR_EACH_EDGE (e, ei, bb->preds)
    1067              :         {
    1068       168760 :           if (e->count ().initialized_p ())
    1069        23337 :             cnt += e->count ();
    1070              :           else
    1071              :             all = false;
    1072              :         }
    1073       139454 :       tree_guess_outgoing_edge_probabilities (bb);
    1074       139454 :       if (all || profile_status_for_fn (cfun) == PROFILE_READ)
    1075        18730 :         bb->count = cnt;
    1076              : 
    1077       139454 :       bb = bb->next_bb;
    1078              :     }
    1079              :   return true;
    1080              : }
    1081              : 
    1082              : /* Auto-profile needs discriminator to distinguish statements with same line
    1083              :    number (file name is ignored) which are in different basic block.  This
    1084              :    map keeps track of current discriminator for a given line number.  */
    1085              : struct discrim_entry
    1086              : {
    1087              :   /* ID of basic block we saw line number last time.  */
    1088              :   unsigned int bb_id;
    1089              :   /* Discriminator we used.  */
    1090              :   unsigned int discrim;
    1091              : };
    1092              : 
    1093              : /* Return updated LOC with discriminator for use in basic block BB_ID.
    1094              :    MAP keeps track of current values.  */
    1095              : 
    1096              : location_t
    1097     73405599 : assign_discriminator (location_t loc, unsigned int bb_id,
    1098              :                       hash_map<int_hash <unsigned, -1U, -2U>,
    1099              :                                discrim_entry> &map)
    1100              : {
    1101     73405599 :   bool existed;
    1102     73405599 :   if ((unsigned) LOCATION_LINE (loc) >= -2U)
    1103              :     return loc;
    1104     73405597 :   discrim_entry &e
    1105     73405597 :     = map.get_or_insert ((unsigned) LOCATION_LINE (loc), &existed);
    1106     73405597 :   gcc_checking_assert (!has_discriminator (loc));
    1107     73405597 :   if (!existed)
    1108              :     {
    1109     13701695 :       e.bb_id = bb_id;
    1110     13701695 :       e.discrim = 0;
    1111     13701695 :       return loc;
    1112              :     }
    1113     59703902 :   if (e.bb_id != bb_id)
    1114              :     {
    1115     40032165 :       e.bb_id = bb_id;
    1116     40032165 :       e.discrim++;
    1117              :     }
    1118     59703902 :   if (e.discrim)
    1119     50599624 :     return location_with_discriminator (loc, e.discrim);
    1120              :   return loc;
    1121              : }
    1122              : 
    1123              : /* Assign discriminators to statement locations.  */
    1124              : 
    1125              : static void
    1126      2880210 : assign_discriminators (void)
    1127              : {
    1128      2880210 :   hash_map<int_hash <unsigned, -1U, -2U>, discrim_entry> map (13);
    1129      2880210 :   unsigned int bb_id = 0;
    1130      2880210 :   basic_block bb;
    1131     24442220 :   FOR_EACH_BB_FN (bb, cfun)
    1132              :     {
    1133     21562010 :       location_t prev_loc = UNKNOWN_LOCATION, prev_replacement = UNKNOWN_LOCATION;
    1134              :       /* Traverse the basic block, if two function calls within a basic block
    1135              :          are mapped to the same line, assign a new discriminator because a call
    1136              :          stmt could be a split point of a basic block.  */
    1137     43124020 :       for (gimple_stmt_iterator gsi = gsi_start_bb (bb);
    1138    103663744 :            !gsi_end_p (gsi); gsi_next (&gsi))
    1139              :         {
    1140     82101734 :           gimple *stmt = gsi_stmt (gsi);
    1141     82101734 :           location_t loc = gimple_location (stmt);
    1142     82101734 :           if (loc == UNKNOWN_LOCATION)
    1143      4360906 :             continue;
    1144     77740828 :           if (loc == prev_loc)
    1145     23326383 :             gimple_set_location (stmt, prev_replacement);
    1146              :           else
    1147              :             {
    1148     54414445 :               prev_loc = loc;
    1149     54414445 :               prev_replacement = assign_discriminator (loc, bb_id, map);
    1150    108828890 :               gimple_set_location (stmt, prev_replacement);
    1151              :             }
    1152              :           /* Break basic blocks after each call.  This is required so each
    1153              :              call site has unique discriminator.
    1154              :              More correctly, we can break after each statement that can possibly
    1155              :              terinate execution of the basic block, but for auto-profile this
    1156              :              precision is probably not useful.  */
    1157     77740828 :           if (gimple_code (stmt) == GIMPLE_CALL)
    1158              :             {
    1159     10905557 :               prev_loc = UNKNOWN_LOCATION;
    1160     10905557 :               bb_id++;
    1161              :             }
    1162              :         }
    1163              :       /* If basic block has multiple successors, consider every edge as a
    1164              :          separate block.  */
    1165     21562010 :       if (!single_succ_p (bb))
    1166      9685064 :         bb_id++;
    1167     89111258 :       for (edge e : bb->succs)
    1168              :         {
    1169     27924090 :           if (e->goto_locus != UNKNOWN_LOCATION)
    1170     18991154 :             e->goto_locus = assign_discriminator (e->goto_locus, bb_id, map);
    1171     27924090 :           for (gphi_iterator gpi = gsi_start_phis (bb);
    1172     27924090 :                !gsi_end_p (gpi); gsi_next (&gpi))
    1173              :             {
    1174            0 :               gphi *phi = gpi.phi ();
    1175            0 :               location_t phi_loc
    1176            0 :                 = gimple_phi_arg_location_from_edge (phi, e);
    1177            0 :               if (phi_loc == UNKNOWN_LOCATION)
    1178            0 :                 continue;
    1179            0 :               gimple_phi_arg_set_location
    1180            0 :                 (phi, e->dest_idx, assign_discriminator (phi_loc, bb_id, map));
    1181              :             }
    1182     27924090 :            bb_id++;
    1183              :         }
    1184     21562010 :       bb_id++;
    1185              :     }
    1186              : 
    1187      2880210 : }
    1188              : 
    1189              : /* Create the edges for a GIMPLE_COND starting at block BB.  */
    1190              : 
    1191              : static void
    1192      5464926 : make_cond_expr_edges (basic_block bb)
    1193              : {
    1194     10929852 :   gcond *entry = as_a <gcond *> (*gsi_last_bb (bb));
    1195      5464926 :   gimple *then_stmt, *else_stmt;
    1196      5464926 :   basic_block then_bb, else_bb;
    1197      5464926 :   tree then_label, else_label;
    1198      5464926 :   edge e;
    1199              : 
    1200      5464926 :   gcc_assert (entry);
    1201              : 
    1202              :   /* Entry basic blocks for each component.  */
    1203      5464926 :   then_label = gimple_cond_true_label (entry);
    1204      5464926 :   else_label = gimple_cond_false_label (entry);
    1205      5464926 :   then_bb = label_to_block (cfun, then_label);
    1206      5464926 :   else_bb = label_to_block (cfun, else_label);
    1207      5464926 :   then_stmt = first_stmt (then_bb);
    1208      5464926 :   else_stmt = first_stmt (else_bb);
    1209              : 
    1210      5464926 :   e = make_edge (bb, then_bb, EDGE_TRUE_VALUE);
    1211      5464926 :   e->goto_locus = gimple_location (then_stmt);
    1212      5464926 :   e = make_edge (bb, else_bb, EDGE_FALSE_VALUE);
    1213      5464926 :   if (e)
    1214      5459759 :     e->goto_locus = gimple_location (else_stmt);
    1215              : 
    1216              :   /* We do not need the labels anymore.  */
    1217      5464926 :   gimple_cond_set_true_label (entry, NULL_TREE);
    1218      5464926 :   gimple_cond_set_false_label (entry, NULL_TREE);
    1219      5464926 : }
    1220              : 
    1221              : 
    1222              : /* Called for each element in the hash table (P) as we delete the
    1223              :    edge to cases hash table.
    1224              : 
    1225              :    Clear all the CASE_CHAINs to prevent problems with copying of
    1226              :    SWITCH_EXPRs and structure sharing rules, then free the hash table
    1227              :    element.  */
    1228              : 
    1229              : bool
    1230      1023061 : edge_to_cases_cleanup (edge const &, tree const &value, void *)
    1231              : {
    1232      1023061 :   tree t, next;
    1233              : 
    1234      2202032 :   for (t = value; t; t = next)
    1235              :     {
    1236      1178971 :       next = CASE_CHAIN (t);
    1237      1178971 :       CASE_CHAIN (t) = NULL;
    1238              :     }
    1239              : 
    1240      1023061 :   return true;
    1241              : }
    1242              : 
    1243              : /* Start recording information mapping edges to case labels.  */
    1244              : 
    1245              : void
    1246     29416467 : start_recording_case_labels (void)
    1247              : {
    1248     29416467 :   gcc_assert (edge_to_cases == NULL);
    1249     29416467 :   edge_to_cases = new hash_map<edge, tree>;
    1250     29416467 :   touched_switch_bbs = BITMAP_ALLOC (NULL);
    1251     29416467 : }
    1252              : 
    1253              : /* Return nonzero if we are recording information for case labels.  */
    1254              : 
    1255              : static bool
    1256       367738 : recording_case_labels_p (void)
    1257              : {
    1258       367738 :   return (edge_to_cases != NULL);
    1259              : }
    1260              : 
    1261              : /* Stop recording information mapping edges to case labels and
    1262              :    remove any information we have recorded.  */
    1263              : void
    1264     29416467 : end_recording_case_labels (void)
    1265              : {
    1266     29416467 :   bitmap_iterator bi;
    1267     29416467 :   unsigned i;
    1268     30439528 :   edge_to_cases->traverse<void *, edge_to_cases_cleanup> (NULL);
    1269     58832934 :   delete edge_to_cases;
    1270     29416467 :   edge_to_cases = NULL;
    1271     29574390 :   EXECUTE_IF_SET_IN_BITMAP (touched_switch_bbs, 0, i, bi)
    1272              :     {
    1273       157923 :       basic_block bb = BASIC_BLOCK_FOR_FN (cfun, i);
    1274       157923 :       if (bb)
    1275              :         {
    1276       470401 :           if (gswitch *stmt = safe_dyn_cast <gswitch *> (*gsi_last_bb (bb)))
    1277       156027 :             group_case_labels_stmt (stmt);
    1278              :         }
    1279              :     }
    1280     29416467 :   BITMAP_FREE (touched_switch_bbs);
    1281     29416467 : }
    1282              : 
    1283              : /* If we are inside a {start,end}_recording_cases block, then return
    1284              :    a chain of CASE_LABEL_EXPRs from T which reference E.
    1285              : 
    1286              :    Otherwise return NULL.  */
    1287              : 
    1288              : tree
    1289       367738 : get_cases_for_edge (edge e, gswitch *t)
    1290              : {
    1291       367738 :   tree *slot;
    1292       367738 :   size_t i, n;
    1293              : 
    1294              :   /* If we are not recording cases, then we do not have CASE_LABEL_EXPR
    1295              :      chains available.  Return NULL so the caller can detect this case.  */
    1296       367738 :   if (!recording_case_labels_p ())
    1297              :     return NULL;
    1298              : 
    1299       321888 :   slot = edge_to_cases->get (e);
    1300       321888 :   if (slot)
    1301       164074 :     return *slot;
    1302              : 
    1303              :   /* If we did not find E in the hash table, then this must be the first
    1304              :      time we have been queried for information about E & T.  Add all the
    1305              :      elements from T to the hash table then perform the query again.  */
    1306              : 
    1307       157814 :   n = gimple_switch_num_labels (t);
    1308      1328210 :   for (i = 0; i < n; i++)
    1309              :     {
    1310      1170396 :       tree elt = gimple_switch_label (t, i);
    1311      1170396 :       tree lab = CASE_LABEL (elt);
    1312      1170396 :       basic_block label_bb = label_to_block (cfun, lab);
    1313      1170396 :       edge this_edge = find_edge (e->src, label_bb);
    1314              : 
    1315              :       /* Add it to the chain of CASE_LABEL_EXPRs referencing E, or create
    1316              :          a new chain.  */
    1317      1170396 :       tree &s = edge_to_cases->get_or_insert (this_edge);
    1318      1170396 :       CASE_CHAIN (elt) = s;
    1319      1170396 :       s = elt;
    1320              :     }
    1321              : 
    1322       157814 :   return *edge_to_cases->get (e);
    1323              : }
    1324              : 
    1325              : /* Create the edges for a GIMPLE_SWITCH starting at block BB.  */
    1326              : 
    1327              : static void
    1328        53044 : make_gimple_switch_edges (gswitch *entry, basic_block bb)
    1329              : {
    1330        53044 :   size_t i, n;
    1331              : 
    1332        53044 :   n = gimple_switch_num_labels (entry);
    1333              : 
    1334       371463 :   for (i = 0; i < n; ++i)
    1335              :     {
    1336       318419 :       basic_block label_bb = gimple_switch_label_bb (cfun, entry, i);
    1337       318419 :       make_edge (bb, label_bb, 0);
    1338              :     }
    1339        53044 : }
    1340              : 
    1341              : 
    1342              : /* Return the basic block holding label DEST.  */
    1343              : 
    1344              : basic_block
    1345    442410334 : label_to_block (struct function *ifun, tree dest)
    1346              : {
    1347    442410334 :   int uid = LABEL_DECL_UID (dest);
    1348              : 
    1349              :   /* We would die hard when faced by an undefined label.  Emit a label to
    1350              :      the very first basic block.  This will hopefully make even the dataflow
    1351              :      and undefined variable warnings quite right.  */
    1352    442410334 :   if (seen_error () && uid < 0)
    1353              :     {
    1354           97 :       gimple_stmt_iterator gsi =
    1355           97 :         gsi_start_bb (BASIC_BLOCK_FOR_FN (cfun, NUM_FIXED_BLOCKS));
    1356           97 :       gimple *stmt;
    1357              : 
    1358           97 :       stmt = gimple_build_label (dest);
    1359           97 :       gsi_insert_before (&gsi, stmt, GSI_NEW_STMT);
    1360           97 :       uid = LABEL_DECL_UID (dest);
    1361              :     }
    1362    442410334 :   if (vec_safe_length (ifun->cfg->x_label_to_block_map) <= (unsigned int) uid)
    1363              :     return NULL;
    1364    442410334 :   return (*ifun->cfg->x_label_to_block_map)[uid];
    1365              : }
    1366              : 
    1367              : /* Create edges for a goto statement at block BB.  Returns true
    1368              :    if abnormal edges should be created.  */
    1369              : 
    1370              : static bool
    1371      6113173 : make_goto_expr_edges (basic_block bb)
    1372              : {
    1373      6113173 :   gimple_stmt_iterator last = gsi_last_bb (bb);
    1374      6113173 :   gimple *goto_t = gsi_stmt (last);
    1375              : 
    1376              :   /* A simple GOTO creates normal edges.  */
    1377      6113173 :   if (simple_goto_p (goto_t))
    1378              :     {
    1379      6112056 :       tree dest = gimple_goto_dest (goto_t);
    1380      6112056 :       basic_block label_bb = label_to_block (cfun, dest);
    1381      6112056 :       edge e = make_edge (bb, label_bb, EDGE_FALLTHRU);
    1382      6112056 :       e->goto_locus = gimple_location (goto_t);
    1383      6112056 :       gsi_remove (&last, true);
    1384      6112056 :       return false;
    1385              :     }
    1386              : 
    1387              :   /* A computed GOTO creates abnormal edges.  */
    1388              :   return true;
    1389              : }
    1390              : 
    1391              : /* Create edges for an asm statement with labels at block BB.  */
    1392              : 
    1393              : static void
    1394         1565 : make_gimple_asm_edges (basic_block bb)
    1395              : {
    1396         3130 :   gasm *stmt = as_a <gasm *> (*gsi_last_bb (bb));
    1397         1565 :   int i, n = gimple_asm_nlabels (stmt);
    1398              : 
    1399         2441 :   for (i = 0; i < n; ++i)
    1400              :     {
    1401          876 :       tree label = TREE_VALUE (gimple_asm_label_op (stmt, i));
    1402          876 :       basic_block label_bb = label_to_block (cfun, label);
    1403          876 :       make_edge (bb, label_bb, 0);
    1404              :     }
    1405         1565 : }
    1406              : 
    1407              : /*---------------------------------------------------------------------------
    1408              :                                Flowgraph analysis
    1409              : ---------------------------------------------------------------------------*/
    1410              : 
    1411              : /* Cleanup useless labels in basic blocks.  This is something we wish
    1412              :    to do early because it allows us to group case labels before creating
    1413              :    the edges for the CFG, and it speeds up block statement iterators in
    1414              :    all passes later on.
    1415              :    We rerun this pass after CFG is created, to get rid of the labels that
    1416              :    are no longer referenced.  After then we do not run it any more, since
    1417              :    (almost) no new labels should be created.  */
    1418              : 
    1419              : /* A map from basic block index to the leading label of that block.  */
    1420              : struct label_record
    1421              : {
    1422              :   /* The label.  */
    1423              :   tree label;
    1424              : 
    1425              :   /* True if the label is referenced from somewhere.  */
    1426              :   bool used;
    1427              : };
    1428              : 
    1429              : /* Given LABEL return the first label in the same basic block.  */
    1430              : 
    1431              : static tree
    1432     20434366 : main_block_label (tree label, label_record *label_for_bb)
    1433              : {
    1434     20434366 :   basic_block bb = label_to_block (cfun, label);
    1435     20434366 :   tree main_label = label_for_bb[bb->index].label;
    1436              : 
    1437              :   /* label_to_block possibly inserted undefined label into the chain.  */
    1438     20434366 :   if (!main_label)
    1439              :     {
    1440           88 :       label_for_bb[bb->index].label = label;
    1441           88 :       main_label = label;
    1442              :     }
    1443              : 
    1444     20434366 :   label_for_bb[bb->index].used = true;
    1445     20434366 :   return main_label;
    1446              : }
    1447              : 
    1448              : /* Clean up redundant labels within the exception tree.  */
    1449              : 
    1450              : static void
    1451      7249564 : cleanup_dead_labels_eh (label_record *label_for_bb)
    1452              : {
    1453      7249564 :   eh_landing_pad lp;
    1454      7249564 :   eh_region r;
    1455      7249564 :   tree lab;
    1456      7249564 :   int i;
    1457              : 
    1458      7249564 :   if (cfun->eh == NULL)
    1459      7249564 :     return;
    1460              : 
    1461     10398753 :   for (i = 1; vec_safe_iterate (cfun->eh->lp_array, i, &lp); ++i)
    1462      3149189 :     if (lp && lp->post_landing_pad)
    1463              :       {
    1464      1930081 :         lab = main_block_label (lp->post_landing_pad, label_for_bb);
    1465      1930081 :         if (lab != lp->post_landing_pad)
    1466              :           {
    1467            0 :             EH_LANDING_PAD_NR (lp->post_landing_pad) = 0;
    1468            0 :             lp->post_landing_pad = lab;
    1469            0 :             EH_LANDING_PAD_NR (lab) = lp->index;
    1470              :           }
    1471              :       }
    1472              : 
    1473     12479510 :   FOR_ALL_EH_REGION (r)
    1474      5229946 :     switch (r->type)
    1475              :       {
    1476              :       case ERT_CLEANUP:
    1477              :       case ERT_MUST_NOT_THROW:
    1478              :         break;
    1479              : 
    1480       133486 :       case ERT_TRY:
    1481       133486 :         {
    1482       133486 :           eh_catch c;
    1483       266137 :           for (c = r->u.eh_try.first_catch; c ; c = c->next_catch)
    1484              :             {
    1485       132651 :               lab = c->label;
    1486       132651 :               if (lab)
    1487        88438 :                 c->label = main_block_label (lab, label_for_bb);
    1488              :             }
    1489              :         }
    1490              :         break;
    1491              : 
    1492         9550 :       case ERT_ALLOWED_EXCEPTIONS:
    1493         9550 :         lab = r->u.allowed.label;
    1494         9550 :         if (lab)
    1495          936 :           r->u.allowed.label = main_block_label (lab, label_for_bb);
    1496              :         break;
    1497              :       }
    1498              : }
    1499              : 
    1500              : 
    1501              : /* Cleanup redundant labels.  This is a three-step process:
    1502              :      1) Find the leading label for each block.
    1503              :      2) Redirect all references to labels to the leading labels.
    1504              :      3) Cleanup all useless labels.  */
    1505              : 
    1506              : void
    1507      7249564 : cleanup_dead_labels (void)
    1508              : {
    1509      7249564 :   basic_block bb;
    1510      7249564 :   label_record *label_for_bb = XCNEWVEC (struct label_record,
    1511              :                                          last_basic_block_for_fn (cfun));
    1512              : 
    1513              :   /* Find a suitable label for each block.  We use the first user-defined
    1514              :      label if there is one, or otherwise just the first label we see.  */
    1515     62740374 :   FOR_EACH_BB_FN (bb, cfun)
    1516              :     {
    1517     55490810 :       gimple_stmt_iterator i;
    1518              : 
    1519    145287612 :       for (i = gsi_start_bb (bb); !gsi_end_p (i); gsi_next (&i))
    1520              :         {
    1521     88512428 :           tree label;
    1522     89807051 :           glabel *label_stmt = dyn_cast <glabel *> (gsi_stmt (i));
    1523              : 
    1524     34316241 :           if (!label_stmt)
    1525              :             break;
    1526              : 
    1527     34316241 :           label = gimple_label_label (label_stmt);
    1528              : 
    1529              :           /* If we have not yet seen a label for the current block,
    1530              :              remember this one and see if there are more labels.  */
    1531     34316241 :           if (!label_for_bb[bb->index].label)
    1532              :             {
    1533     32080579 :               label_for_bb[bb->index].label = label;
    1534     32080579 :               continue;
    1535              :             }
    1536              : 
    1537              :           /* If we did see a label for the current block already, but it
    1538              :              is an artificially created label, replace it if the current
    1539              :              label is a user defined label.  */
    1540      2235662 :           if (!DECL_ARTIFICIAL (label)
    1541      2235662 :               && DECL_ARTIFICIAL (label_for_bb[bb->index].label))
    1542              :             {
    1543        10249 :               label_for_bb[bb->index].label = label;
    1544        10249 :               break;
    1545              :             }
    1546              :         }
    1547              :     }
    1548              : 
    1549              :   /* Now redirect all jumps/branches to the selected label.
    1550              :      First do so for each block ending in a control statement.  */
    1551     62740374 :   FOR_EACH_BB_FN (bb, cfun)
    1552              :     {
    1553     55490810 :       gimple *stmt = *gsi_last_bb (bb);
    1554     55490810 :       tree label, new_label;
    1555              : 
    1556     55490810 :       if (!stmt)
    1557       410929 :         continue;
    1558              : 
    1559     55079881 :       switch (gimple_code (stmt))
    1560              :         {
    1561     16484090 :         case GIMPLE_COND:
    1562     16484090 :           {
    1563     16484090 :             gcond *cond_stmt = as_a <gcond *> (stmt);
    1564     16484090 :             label = gimple_cond_true_label (cond_stmt);
    1565     16484090 :             if (label)
    1566              :               {
    1567      5435620 :                 new_label = main_block_label (label, label_for_bb);
    1568      5435620 :                 if (new_label != label)
    1569         9185 :                   gimple_cond_set_true_label (cond_stmt, new_label);
    1570              :               }
    1571              : 
    1572     16484090 :             label = gimple_cond_false_label (cond_stmt);
    1573     16484090 :             if (label)
    1574              :               {
    1575      5435620 :                 new_label = main_block_label (label, label_for_bb);
    1576      5435620 :                 if (new_label != label)
    1577       108604 :                   gimple_cond_set_false_label (cond_stmt, new_label);
    1578              :               }
    1579              :           }
    1580              :           break;
    1581              : 
    1582       113221 :         case GIMPLE_SWITCH:
    1583       113221 :           {
    1584       113221 :             gswitch *switch_stmt = as_a <gswitch *> (stmt);
    1585       113221 :             size_t i, n = gimple_switch_num_labels (switch_stmt);
    1586              : 
    1587              :             /* Replace all destination labels.  */
    1588      1568732 :             for (i = 0; i < n; ++i)
    1589              :               {
    1590      1455511 :                 tree case_label = gimple_switch_label (switch_stmt, i);
    1591      1455511 :                 label = CASE_LABEL (case_label);
    1592      1455511 :                 new_label = main_block_label (label, label_for_bb);
    1593      1455511 :                 if (new_label != label)
    1594       787076 :                   CASE_LABEL (case_label) = new_label;
    1595              :               }
    1596              :             break;
    1597              :           }
    1598              : 
    1599         5419 :         case GIMPLE_ASM:
    1600         5419 :           {
    1601         5419 :             gasm *asm_stmt = as_a <gasm *> (stmt);
    1602         5419 :             int i, n = gimple_asm_nlabels (asm_stmt);
    1603              : 
    1604         8027 :             for (i = 0; i < n; ++i)
    1605              :               {
    1606         2608 :                 tree cons = gimple_asm_label_op (asm_stmt, i);
    1607         2608 :                 tree label = main_block_label (TREE_VALUE (cons), label_for_bb);
    1608         2608 :                 TREE_VALUE (cons) = label;
    1609              :               }
    1610              :             break;
    1611              :           }
    1612              : 
    1613              :         /* We have to handle gotos until they're removed, and we don't
    1614              :            remove them until after we've created the CFG edges.  */
    1615      6085319 :         case GIMPLE_GOTO:
    1616      6085319 :           if (!computed_goto_p (stmt))
    1617              :             {
    1618      6083142 :               ggoto *goto_stmt = as_a <ggoto *> (stmt);
    1619      6083142 :               label = gimple_goto_dest (goto_stmt);
    1620      6083142 :               new_label = main_block_label (label, label_for_bb);
    1621      6083142 :               if (new_label != label)
    1622      1091050 :                 gimple_goto_set_dest (goto_stmt, new_label);
    1623              :             }
    1624              :           break;
    1625              : 
    1626          822 :         case GIMPLE_TRANSACTION:
    1627          822 :           {
    1628          822 :             gtransaction *txn = as_a <gtransaction *> (stmt);
    1629              : 
    1630          822 :             label = gimple_transaction_label_norm (txn);
    1631          822 :             if (label)
    1632              :               {
    1633          802 :                 new_label = main_block_label (label, label_for_bb);
    1634          802 :                 if (new_label != label)
    1635            0 :                   gimple_transaction_set_label_norm (txn, new_label);
    1636              :               }
    1637              : 
    1638          822 :             label = gimple_transaction_label_uninst (txn);
    1639          822 :             if (label)
    1640              :               {
    1641          794 :                 new_label = main_block_label (label, label_for_bb);
    1642          794 :                 if (new_label != label)
    1643            0 :                   gimple_transaction_set_label_uninst (txn, new_label);
    1644              :               }
    1645              : 
    1646          822 :             label = gimple_transaction_label_over (txn);
    1647          822 :             if (label)
    1648              :               {
    1649          814 :                 new_label = main_block_label (label, label_for_bb);
    1650          814 :                 if (new_label != label)
    1651            7 :                   gimple_transaction_set_label_over (txn, new_label);
    1652              :               }
    1653              :           }
    1654              :           break;
    1655              : 
    1656              :         default:
    1657              :           break;
    1658              :       }
    1659              :     }
    1660              : 
    1661              :   /* Do the same for the exception region tree labels.  */
    1662      7249564 :   cleanup_dead_labels_eh (label_for_bb);
    1663              : 
    1664              :   /* Finally, purge dead labels.  All user-defined labels and labels that
    1665              :      can be the target of non-local gotos and labels which have their
    1666              :      address taken are preserved.  */
    1667     62740374 :   FOR_EACH_BB_FN (bb, cfun)
    1668              :     {
    1669     55490810 :       gimple_stmt_iterator i;
    1670     55490810 :       tree label_for_this_bb = label_for_bb[bb->index].label;
    1671              : 
    1672     55490810 :       if (!label_for_this_bb)
    1673     23410143 :         continue;
    1674              : 
    1675              :       /* If the main label of the block is unused, we may still remove it.  */
    1676     32080667 :       if (!label_for_bb[bb->index].used)
    1677     15047972 :         label_for_this_bb = NULL;
    1678              : 
    1679     98477675 :       for (i = gsi_start_bb (bb); !gsi_end_p (i); )
    1680              :         {
    1681     65523041 :           tree label;
    1682     66397008 :           glabel *label_stmt = dyn_cast <glabel *> (gsi_stmt (i));
    1683              : 
    1684     34316341 :           if (!label_stmt)
    1685              :             break;
    1686              : 
    1687     34316341 :           label = gimple_label_label (label_stmt);
    1688              : 
    1689     34316341 :           if (label == label_for_this_bb
    1690     17283646 :               || !DECL_ARTIFICIAL (label)
    1691     16562462 :               || DECL_NONLOCAL (label)
    1692     50877341 :               || FORCED_LABEL (label))
    1693     17781941 :             gsi_next (&i);
    1694              :           else
    1695              :             {
    1696     16534400 :               gcc_checking_assert (EH_LANDING_PAD_NR (label) == 0);
    1697     16534400 :               gsi_remove (&i, true);
    1698              :             }
    1699              :         }
    1700              :     }
    1701              : 
    1702      7249564 :   free (label_for_bb);
    1703      7249564 : }
    1704              : 
    1705              : /* Scan the sorted vector of cases in STMT (a GIMPLE_SWITCH) and combine
    1706              :    the ones jumping to the same label.
    1707              :    Eg. three separate entries 1: 2: 3: become one entry 1..3:  */
    1708              : 
    1709              : bool
    1710       271568 : group_case_labels_stmt (gswitch *stmt)
    1711              : {
    1712       271568 :   int old_size = gimple_switch_num_labels (stmt);
    1713       271568 :   int i, next_index, new_size;
    1714       271568 :   basic_block default_bb = NULL;
    1715              : 
    1716       271568 :   default_bb = gimple_switch_default_bb (cfun, stmt);
    1717              : 
    1718              :   /* Look for possible opportunities to merge cases.  */
    1719       271568 :   new_size = i = 1;
    1720      2170309 :   while (i < old_size)
    1721              :     {
    1722      1627173 :       tree base_case, base_high;
    1723      1627173 :       basic_block base_bb;
    1724              : 
    1725      1627173 :       base_case = gimple_switch_label (stmt, i);
    1726              : 
    1727      1627173 :       gcc_assert (base_case);
    1728      1627173 :       base_bb = label_to_block (cfun, CASE_LABEL (base_case));
    1729              : 
    1730              :       /* Discard cases that have the same destination as the default case.  */
    1731      1633185 :       if (base_bb == NULL
    1732      1627173 :           || base_bb == default_bb)
    1733              :         {
    1734         6012 :           i++;
    1735         6012 :           continue;
    1736              :         }
    1737              : 
    1738      3242322 :       base_high = CASE_HIGH (base_case)
    1739      1621161 :           ? CASE_HIGH (base_case)
    1740      1538739 :           : CASE_LOW (base_case);
    1741      1621161 :       next_index = i + 1;
    1742              : 
    1743              :       /* Try to merge case labels.  Break out when we reach the end
    1744              :          of the label vector or when we cannot merge the next case
    1745              :          label with the current one.  */
    1746      2367555 :       while (next_index < old_size)
    1747              :         {
    1748      2097878 :           tree merge_case = gimple_switch_label (stmt, next_index);
    1749      2097878 :           basic_block merge_bb = label_to_block (cfun, CASE_LABEL (merge_case));
    1750      2097878 :           wide_int bhp1 = wi::to_wide (base_high) + 1;
    1751              : 
    1752              :           /* Merge the cases if they jump to the same place,
    1753              :              and their ranges are consecutive.  */
    1754      2097878 :           if (merge_bb == base_bb
    1755      2940339 :               && wi::to_wide (CASE_LOW (merge_case)) == bhp1)
    1756              :             {
    1757       746394 :               base_high
    1758      1492788 :                 = (CASE_HIGH (merge_case)
    1759       746394 :                    ? CASE_HIGH (merge_case) : CASE_LOW (merge_case));
    1760       746394 :               CASE_HIGH (base_case) = base_high;
    1761       746394 :               next_index++;
    1762              :             }
    1763              :           else
    1764              :             break;
    1765      2097878 :         }
    1766              : 
    1767      1621161 :       if (new_size < i)
    1768        66957 :         gimple_switch_set_label (stmt, new_size,
    1769              :                                  gimple_switch_label (stmt, i));
    1770      1621161 :       i = next_index;
    1771      1621161 :       new_size++;
    1772              :     }
    1773              : 
    1774       271568 :   gcc_assert (new_size <= old_size);
    1775              : 
    1776       271568 :   if (new_size < old_size)
    1777        19017 :     gimple_switch_set_num_labels (stmt, new_size);
    1778              : 
    1779       271568 :   return new_size < old_size;
    1780              : }
    1781              : 
    1782              : /* Look for blocks ending in a multiway branch (a GIMPLE_SWITCH),
    1783              :    and scan the sorted vector of cases.  Combine the ones jumping to the
    1784              :    same label.  */
    1785              : 
    1786              : bool
    1787      4369354 : group_case_labels (void)
    1788              : {
    1789      4369354 :   basic_block bb;
    1790      4369354 :   bool changed = false;
    1791              : 
    1792     38298154 :   FOR_EACH_BB_FN (bb, cfun)
    1793              :     {
    1794    101574338 :       if (gswitch *stmt = safe_dyn_cast <gswitch *> (*gsi_last_bb (bb)))
    1795        60177 :         changed |= group_case_labels_stmt (stmt);
    1796              :     }
    1797              : 
    1798      4369354 :   return changed;
    1799              : }
    1800              : 
    1801              : /* Checks whether we can merge block B into block A.  */
    1802              : 
    1803              : static bool
    1804    408759218 : gimple_can_merge_blocks_p (basic_block a, basic_block b)
    1805              : {
    1806    408759218 :   gimple *stmt;
    1807              : 
    1808    574762279 :   if (!single_succ_p (a))
    1809              :     return false;
    1810              : 
    1811    194336508 :   if (single_succ_edge (a)->flags & EDGE_COMPLEX)
    1812              :     return false;
    1813              : 
    1814    183481958 :   if (single_succ (a) != b)
    1815              :     return false;
    1816              : 
    1817    470432595 :   if (!single_pred_p (b))
    1818              :     return false;
    1819              : 
    1820     90006824 :   if (a == ENTRY_BLOCK_PTR_FOR_FN (cfun)
    1821     58585945 :       || b == EXIT_BLOCK_PTR_FOR_FN (cfun))
    1822              :     return false;
    1823              : 
    1824              :   /* If A ends by a statement causing exceptions or something similar, we
    1825              :      cannot merge the blocks.  */
    1826     32405811 :   stmt = *gsi_last_bb (a);
    1827     32405811 :   if (stmt && stmt_ends_bb_p (stmt))
    1828              :     return false;
    1829              : 
    1830              :   /* Examine the labels at the beginning of B.  */
    1831     61278601 :   for (gimple_stmt_iterator gsi = gsi_start_bb (b); !gsi_end_p (gsi);
    1832       190831 :        gsi_next (&gsi))
    1833              :     {
    1834     27241822 :       tree lab;
    1835     27241822 :       glabel *label_stmt = dyn_cast <glabel *> (gsi_stmt (gsi));
    1836      1855377 :       if (!label_stmt)
    1837              :         break;
    1838      1855377 :       lab = gimple_label_label (label_stmt);
    1839              : 
    1840              :       /* Do not remove user forced labels or for -O0 any user labels.  */
    1841      1911658 :       if (!DECL_ARTIFICIAL (lab) && (!optimize || FORCED_LABEL (lab)))
    1842    380425771 :         return false;
    1843              :     }
    1844              : 
    1845              :   /* Protect simple loop latches.  We only want to avoid merging
    1846              :      the latch with the loop header or with a block in another
    1847              :      loop in this case.  */
    1848     28879339 :   if (current_loops
    1849     26184383 :       && b->loop_father->latch == b
    1850       422295 :       && loops_state_satisfies_p (LOOPS_HAVE_SIMPLE_LATCHES)
    1851     28915768 :       && (b->loop_father->header == a
    1852        24622 :           || b->loop_father != a->loop_father))
    1853              :     return false;
    1854              : 
    1855              :   /* It must be possible to eliminate all phi nodes in B.  If ssa form
    1856              :      is not up-to-date and a name-mapping is registered, we cannot eliminate
    1857              :      any phis.  Symbols marked for renaming are never a problem though.  */
    1858     34512008 :   for (gphi_iterator gsi = gsi_start_phis (b); !gsi_end_p (gsi);
    1859      5644601 :        gsi_next (&gsi))
    1860              :     {
    1861      5644601 :       gphi *phi = gsi.phi ();
    1862              :       /* Technically only new names matter.  */
    1863      5644601 :       if (name_registered_for_update_p (PHI_RESULT (phi)))
    1864            0 :         return false;
    1865              :     }
    1866              : 
    1867              :   /* When not optimizing, don't merge if we'd lose goto_locus.  */
    1868     28867407 :   if (!optimize
    1869     28867407 :       && single_succ_edge (a)->goto_locus != UNKNOWN_LOCATION)
    1870              :     {
    1871       576884 :       location_t goto_locus = single_succ_edge (a)->goto_locus;
    1872       576884 :       gimple_stmt_iterator prev, next;
    1873       576884 :       prev = gsi_last_nondebug_bb (a);
    1874       576884 :       next = gsi_after_labels (b);
    1875       576884 :       if (!gsi_end_p (next) && is_gimple_debug (gsi_stmt (next)))
    1876            6 :         gsi_next_nondebug (&next);
    1877       576884 :       if ((gsi_end_p (prev)
    1878       431510 :            || gimple_location (gsi_stmt (prev)) != goto_locus)
    1879       965662 :           && (gsi_end_p (next)
    1880       486231 :               || gimple_location (gsi_stmt (next)) != goto_locus))
    1881       533960 :         return false;
    1882              :     }
    1883              : 
    1884              :   return true;
    1885              : }
    1886              : 
    1887              : /* Replaces all uses of NAME by VAL.  */
    1888              : 
    1889              : void
    1890      3838321 : replace_uses_by (tree name, tree val)
    1891              : {
    1892      3838321 :   imm_use_iterator imm_iter;
    1893      3838321 :   use_operand_p use;
    1894      3838321 :   gimple *stmt;
    1895      3838321 :   edge e;
    1896              : 
    1897     14629860 :   FOR_EACH_IMM_USE_STMT (stmt, imm_iter, name)
    1898              :     {
    1899              :       /* Mark the block if we change the last stmt in it.  */
    1900      6953218 :       if (cfgcleanup_altered_bbs
    1901      6953218 :           && stmt_ends_bb_p (stmt))
    1902       773004 :         bitmap_set_bit (cfgcleanup_altered_bbs, gimple_bb (stmt)->index);
    1903              : 
    1904     21248472 :       FOR_EACH_IMM_USE_ON_STMT (use, imm_iter)
    1905              :         {
    1906      7147627 :           replace_exp (use, val);
    1907              : 
    1908      7147627 :           if (gimple_code (stmt) == GIMPLE_PHI)
    1909              :             {
    1910      2407586 :               e = gimple_phi_arg_edge (as_a <gphi *> (stmt),
    1911      2407586 :                                        PHI_ARG_INDEX_FROM_USE (use));
    1912      2407586 :               if (e->flags & EDGE_ABNORMAL
    1913      2407586 :                   && !SSA_NAME_OCCURS_IN_ABNORMAL_PHI (val))
    1914              :                 {
    1915              :                   /* This can only occur for virtual operands, since
    1916              :                      for the real ones SSA_NAME_OCCURS_IN_ABNORMAL_PHI (name))
    1917              :                      would prevent replacement.  */
    1918            0 :                   gcc_checking_assert (virtual_operand_p (name));
    1919            0 :                   SSA_NAME_OCCURS_IN_ABNORMAL_PHI (val) = 1;
    1920              :                 }
    1921              :             }
    1922              :         }
    1923              : 
    1924      6953218 :       if (gimple_code (stmt) != GIMPLE_PHI)
    1925              :         {
    1926      4732373 :           gimple_stmt_iterator gsi = gsi_for_stmt (stmt);
    1927      4732373 :           gimple *orig_stmt = stmt;
    1928      4732373 :           size_t i;
    1929              : 
    1930              :           /* FIXME.  It shouldn't be required to keep TREE_CONSTANT
    1931              :              on ADDR_EXPRs up-to-date on GIMPLE.  Propagation will
    1932              :              only change sth from non-invariant to invariant, and only
    1933              :              when propagating constants.  */
    1934      4732373 :           if (is_gimple_min_invariant (val))
    1935      1615605 :             for (i = 0; i < gimple_num_ops (stmt); i++)
    1936              :               {
    1937      1173163 :                 tree op = gimple_op (stmt, i);
    1938              :                 /* Operands may be empty here.  For example, the labels
    1939              :                    of a GIMPLE_COND are nulled out following the creation
    1940              :                    of the corresponding CFG edges.  */
    1941      1173163 :                 if (op && TREE_CODE (op) == ADDR_EXPR)
    1942        60154 :                   recompute_tree_invariant_for_addr_expr (op);
    1943              :               }
    1944      4732373 :           update_stmt (stmt);
    1945              : 
    1946      4732373 :           if (fold_stmt (&gsi))
    1947              :             {
    1948       490723 :               stmt = gsi_stmt (gsi);
    1949       490723 :               update_stmt (stmt);
    1950              :             }
    1951              : 
    1952      4732373 :           if (maybe_clean_or_replace_eh_stmt (orig_stmt, stmt))
    1953          913 :             gimple_purge_dead_eh_edges (gimple_bb (stmt));
    1954              :         }
    1955      3838321 :     }
    1956              : 
    1957      3838321 :   gcc_checking_assert (has_zero_uses (name));
    1958              : 
    1959              :   /* Also update the trees stored in loop structures.  */
    1960      3838321 :   if (current_loops)
    1961              :     {
    1962    134681657 :       for (auto loop : loops_list (cfun, 0))
    1963    127005015 :           substitute_in_loop_info (loop, name, val);
    1964              :     }
    1965      3838321 : }
    1966              : 
    1967              : /* Merge block B into block A.  */
    1968              : 
    1969              : static void
    1970     16770583 : gimple_merge_blocks (basic_block a, basic_block b)
    1971              : {
    1972     16770583 :   gimple_stmt_iterator last, gsi;
    1973     16770583 :   gphi_iterator psi;
    1974              : 
    1975     16770583 :   if (dump_file)
    1976        19692 :     fprintf (dump_file, "Merging blocks %d and %d\n", a->index, b->index);
    1977              : 
    1978              :   /* Remove all single-valued PHI nodes from block B of the form
    1979              :      V_i = PHI <V_j> by propagating V_j to all the uses of V_i.  */
    1980     16770583 :   gsi = gsi_last_bb (a);
    1981     20527644 :   for (psi = gsi_start_phis (b); !gsi_end_p (psi); )
    1982              :     {
    1983      3757061 :       gimple *phi = gsi_stmt (psi);
    1984      3757061 :       tree def = gimple_phi_result (phi), use = gimple_phi_arg_def (phi, 0);
    1985      3757061 :       gimple *copy;
    1986      3757061 :       bool may_replace_uses = (virtual_operand_p (def)
    1987      3757061 :                                || may_propagate_copy (def, use));
    1988              : 
    1989              :       /* In case we maintain loop closed ssa form, do not propagate arguments
    1990              :          of loop exit phi nodes.  */
    1991      3757061 :       if (current_loops
    1992      3757061 :           && loops_state_satisfies_p (LOOP_CLOSED_SSA)
    1993       624707 :           && !virtual_operand_p (def)
    1994       458199 :           && TREE_CODE (use) == SSA_NAME
    1995      4101250 :           && a->loop_father != b->loop_father)
    1996              :         may_replace_uses = false;
    1997              : 
    1998      3756838 :       if (!may_replace_uses)
    1999              :         {
    2000         1016 :           gcc_assert (!virtual_operand_p (def));
    2001              : 
    2002              :           /* Note that just emitting the copies is fine -- there is no problem
    2003              :              with ordering of phi nodes.  This is because A is the single
    2004              :              predecessor of B, therefore results of the phi nodes cannot
    2005              :              appear as arguments of the phi nodes.  */
    2006          508 :           copy = gimple_build_assign (def, use);
    2007          508 :           gsi_insert_after (&gsi, copy, GSI_NEW_STMT);
    2008          508 :           remove_phi_node (&psi, false);
    2009              :         }
    2010              :       else
    2011              :         {
    2012              :           /* If we deal with a PHI for virtual operands, we can simply
    2013              :              propagate these without fussing with folding or updating
    2014              :              the stmt.  */
    2015      7513106 :           if (virtual_operand_p (def))
    2016              :             {
    2017      1452854 :               imm_use_iterator iter;
    2018      1452854 :               use_operand_p use_p;
    2019      1452854 :               gimple *stmt;
    2020              : 
    2021      5660710 :               FOR_EACH_IMM_USE_STMT (stmt, iter, def)
    2022      8296378 :                 FOR_EACH_IMM_USE_ON_STMT (use_p, iter)
    2023      2770688 :                   SET_USE (use_p, use);
    2024              : 
    2025      1452854 :               if (SSA_NAME_OCCURS_IN_ABNORMAL_PHI (def))
    2026          284 :                 SSA_NAME_OCCURS_IN_ABNORMAL_PHI (use) = 1;
    2027              :             }
    2028              :           else
    2029      2303699 :             replace_uses_by (def, use);
    2030              : 
    2031      3756553 :           remove_phi_node (&psi, true);
    2032              :         }
    2033              :     }
    2034              : 
    2035              :   /* Ensure that B follows A.  */
    2036     16770583 :   move_block_after (b, a);
    2037              : 
    2038     16770583 :   gcc_assert (single_succ_edge (a)->flags & EDGE_FALLTHRU);
    2039     33541166 :   gcc_assert (!*gsi_last_bb (a)
    2040              :               || !stmt_ends_bb_p (*gsi_last_bb (a)));
    2041              : 
    2042              :   /* Remove labels from B and set gimple_bb to A for other statements.  */
    2043    126595633 :   for (gsi = gsi_start_bb (b); !gsi_end_p (gsi);)
    2044              :     {
    2045     93054467 :       gimple *stmt = gsi_stmt (gsi);
    2046     93054467 :       if (glabel *label_stmt = dyn_cast <glabel *> (stmt))
    2047              :         {
    2048       111612 :           tree label = gimple_label_label (label_stmt);
    2049       111612 :           int lp_nr;
    2050              : 
    2051       111612 :           gsi_remove (&gsi, false);
    2052              : 
    2053              :           /* Now that we can thread computed gotos, we might have
    2054              :              a situation where we have a forced label in block B
    2055              :              However, the label at the start of block B might still be
    2056              :              used in other ways (think about the runtime checking for
    2057              :              Fortran assigned gotos).  So we cannot just delete the
    2058              :              label.  Instead we move the label to the start of block A.  */
    2059       111612 :           if (FORCED_LABEL (label))
    2060              :             {
    2061         5233 :               gimple_stmt_iterator dest_gsi = gsi_start_bb (a);
    2062         5233 :               tree first_label = NULL_TREE;
    2063         5233 :               if (!gsi_end_p (dest_gsi))
    2064         5215 :                 if (glabel *first_label_stmt
    2065         5215 :                     = dyn_cast <glabel *> (gsi_stmt (dest_gsi)))
    2066         4452 :                   first_label = gimple_label_label (first_label_stmt);
    2067         4452 :               if (first_label
    2068         4452 :                   && (DECL_NONLOCAL (first_label)
    2069         4452 :                       || EH_LANDING_PAD_NR (first_label) != 0))
    2070           12 :                 gsi_insert_after (&dest_gsi, stmt, GSI_NEW_STMT);
    2071              :               else
    2072         5221 :                 gsi_insert_before (&dest_gsi, stmt, GSI_NEW_STMT);
    2073              :             }
    2074              :           /* Other user labels keep around in a form of a debug stmt.  */
    2075       106379 :           else if (!DECL_ARTIFICIAL (label) && MAY_HAVE_DEBUG_BIND_STMTS)
    2076              :             {
    2077         9055 :               gimple *dbg = gimple_build_debug_bind (label,
    2078              :                                                      integer_zero_node,
    2079              :                                                      stmt);
    2080         9055 :               gimple_debug_bind_reset_value (dbg);
    2081         9055 :               gsi_insert_before (&gsi, dbg, GSI_SAME_STMT);
    2082              :             }
    2083              : 
    2084       111612 :           lp_nr = EH_LANDING_PAD_NR (label);
    2085       111612 :           if (lp_nr)
    2086              :             {
    2087         8114 :               eh_landing_pad lp = get_eh_landing_pad_from_number (lp_nr);
    2088         8114 :               lp->post_landing_pad = NULL;
    2089              :             }
    2090              :         }
    2091              :       else
    2092              :         {
    2093     92942855 :           gimple_set_bb (stmt, a);
    2094     92942855 :           gsi_next (&gsi);
    2095              :         }
    2096              :     }
    2097              : 
    2098              :   /* When merging two BBs, if their counts are different, the larger count
    2099              :      is selected as the new bb count. This is to handle inconsistent
    2100              :      profiles.  */
    2101     16770583 :   if (a->loop_father == b->loop_father)
    2102              :     {
    2103     16692282 :       a->count = a->count.merge (b->count);
    2104              :     }
    2105              : 
    2106              :   /* Merge the sequences.  */
    2107     16770583 :   last = gsi_last_bb (a);
    2108     33541166 :   gsi_insert_seq_after (&last, bb_seq (b), GSI_NEW_STMT);
    2109     16770583 :   set_bb_seq (b, NULL);
    2110              : 
    2111     16770583 :   if (cfgcleanup_altered_bbs)
    2112     16741590 :     bitmap_set_bit (cfgcleanup_altered_bbs, a->index);
    2113     16770583 : }
    2114              : 
    2115              : 
    2116              : /* Return the one of two successors of BB that is not reachable by a
    2117              :    complex edge, if there is one.  Else, return BB.  We use
    2118              :    this in optimizations that use post-dominators for their heuristics,
    2119              :    to catch the cases in C++ where function calls are involved.  */
    2120              : 
    2121              : basic_block
    2122            6 : single_noncomplex_succ (basic_block bb)
    2123              : {
    2124            6 :   edge e0, e1;
    2125            6 :   if (EDGE_COUNT (bb->succs) != 2)
    2126              :     return bb;
    2127              : 
    2128            6 :   e0 = EDGE_SUCC (bb, 0);
    2129            6 :   e1 = EDGE_SUCC (bb, 1);
    2130            6 :   if (e0->flags & EDGE_COMPLEX)
    2131            6 :     return e1->dest;
    2132            0 :   if (e1->flags & EDGE_COMPLEX)
    2133            0 :     return e0->dest;
    2134              : 
    2135              :   return bb;
    2136              : }
    2137              : 
    2138              : /* T is CALL_EXPR.  Set current_function_calls_* flags.  */
    2139              : 
    2140              : void
    2141     52752912 : notice_special_calls (gcall *call)
    2142              : {
    2143     52752912 :   int flags = gimple_call_flags (call);
    2144              : 
    2145     52752912 :   if (flags & ECF_MAY_BE_ALLOCA)
    2146       160340 :     cfun->calls_alloca = true;
    2147     52752912 :   if (flags & ECF_RETURNS_TWICE)
    2148         7900 :     cfun->calls_setjmp = true;
    2149     52752912 :   if (gimple_call_must_tail_p (call))
    2150         3640 :     cfun->has_musttail = true;
    2151     52752912 : }
    2152              : 
    2153              : 
    2154              : /* Clear flags set by notice_special_calls.  Used by dead code removal
    2155              :    to update the flags.  */
    2156              : 
    2157              : void
    2158      8051220 : clear_special_calls (void)
    2159              : {
    2160      8051220 :   cfun->calls_alloca = false;
    2161      8051220 :   cfun->calls_setjmp = false;
    2162      8051220 :   cfun->has_musttail = false;
    2163      8051220 : }
    2164              : 
    2165              : /* Remove PHI nodes associated with basic block BB and all edges out of BB.  */
    2166              : 
    2167              : static void
    2168     35267939 : remove_phi_nodes_and_edges_for_unreachable_block (basic_block bb)
    2169              : {
    2170              :   /* Since this block is no longer reachable, we can just delete all
    2171              :      of its PHI nodes.  */
    2172     35267939 :   remove_phi_nodes (bb);
    2173              : 
    2174              :   /* Remove edges to BB's successors.  */
    2175    103830723 :   while (EDGE_COUNT (bb->succs) > 0)
    2176     33294845 :     remove_edge (EDGE_SUCC (bb, 0));
    2177     35267939 : }
    2178              : 
    2179              : 
    2180              : /* Remove statements of basic block BB.  */
    2181              : 
    2182              : static void
    2183     35267939 : remove_bb (basic_block bb)
    2184              : {
    2185     35267939 :   gimple_stmt_iterator i;
    2186              : 
    2187     35267939 :   if (dump_file)
    2188              :     {
    2189        47535 :       fprintf (dump_file, "Removing basic block %d\n", bb->index);
    2190        47535 :       if (dump_flags & TDF_DETAILS)
    2191              :         {
    2192        33216 :           dump_bb (dump_file, bb, 0, TDF_BLOCKS);
    2193        33216 :           fprintf (dump_file, "\n");
    2194              :         }
    2195              :     }
    2196              : 
    2197     35267939 :   if (current_loops)
    2198              :     {
    2199     33385949 :       class loop *loop = bb->loop_father;
    2200              : 
    2201              :       /* If a loop gets removed, clean up the information associated
    2202              :          with it.  */
    2203     33385949 :       if (loop->latch == bb
    2204     33186260 :           || loop->header == bb)
    2205       245973 :         free_numbers_of_iterations_estimates (loop);
    2206              :     }
    2207              : 
    2208              :   /* Remove all the instructions in the block.  */
    2209     35267939 :   if (bb_seq (bb) != NULL)
    2210              :     {
    2211              :       /* Walk backwards so as to get a chance to substitute all
    2212              :          released DEFs into debug stmts.  See
    2213              :          eliminate_unnecessary_stmts() in tree-ssa-dce.cc for more
    2214              :          details.  */
    2215      6704100 :       for (i = gsi_last_bb (bb); !gsi_end_p (i);)
    2216              :         {
    2217     20495236 :           gimple *stmt = gsi_stmt (i);
    2218     20495236 :           glabel *label_stmt = dyn_cast <glabel *> (stmt);
    2219      1891214 :           if (label_stmt
    2220      1891214 :               && (FORCED_LABEL (gimple_label_label (label_stmt))
    2221      1888275 :                   || DECL_NONLOCAL (gimple_label_label (label_stmt))))
    2222              :             {
    2223         2941 :               basic_block new_bb;
    2224         2941 :               gimple_stmt_iterator new_gsi;
    2225              : 
    2226              :               /* A non-reachable non-local label may still be referenced.
    2227              :                  But it no longer needs to carry the extra semantics of
    2228              :                  non-locality.  */
    2229         2941 :               if (DECL_NONLOCAL (gimple_label_label (label_stmt)))
    2230              :                 {
    2231            2 :                   DECL_NONLOCAL (gimple_label_label (label_stmt)) = 0;
    2232            2 :                   FORCED_LABEL (gimple_label_label (label_stmt)) = 1;
    2233              :                 }
    2234              : 
    2235         2941 :               new_bb = bb->prev_bb;
    2236              :               /* Don't move any labels into ENTRY block.  */
    2237         2941 :               if (new_bb == ENTRY_BLOCK_PTR_FOR_FN (cfun))
    2238              :                 {
    2239            0 :                   new_bb = single_succ (new_bb);
    2240            0 :                   gcc_assert (new_bb != bb);
    2241              :                 }
    2242         2941 :               if ((unsigned) bb->index < bb_to_omp_idx.length ()
    2243            8 :                   && ((unsigned) new_bb->index >= bb_to_omp_idx.length ()
    2244            8 :                       || (bb_to_omp_idx[bb->index]
    2245            8 :                           != bb_to_omp_idx[new_bb->index])))
    2246              :                 {
    2247              :                   /* During cfg pass make sure to put orphaned labels
    2248              :                      into the right OMP region.  */
    2249              :                   unsigned int i;
    2250              :                   int idx;
    2251           24 :                   new_bb = NULL;
    2252           24 :                   FOR_EACH_VEC_ELT (bb_to_omp_idx, i, idx)
    2253           24 :                     if (i >= NUM_FIXED_BLOCKS
    2254            8 :                         && idx == bb_to_omp_idx[bb->index]
    2255           32 :                         && i != (unsigned) bb->index)
    2256              :                       {
    2257            8 :                         new_bb = BASIC_BLOCK_FOR_FN (cfun, i);
    2258            8 :                         break;
    2259              :                       }
    2260            8 :                   if (new_bb == NULL)
    2261              :                     {
    2262            0 :                       new_bb = single_succ (ENTRY_BLOCK_PTR_FOR_FN (cfun));
    2263            0 :                       gcc_assert (new_bb != bb);
    2264              :                     }
    2265              :                 }
    2266         2941 :               new_gsi = gsi_after_labels (new_bb);
    2267         2941 :               gsi_remove (&i, false);
    2268         2941 :               gsi_insert_before (&new_gsi, stmt, GSI_NEW_STMT);
    2269              :             }
    2270              :           else
    2271              :             {
    2272              :               /* Release SSA definitions.  */
    2273     20492295 :               release_defs (stmt);
    2274     20492295 :               gsi_remove (&i, true);
    2275              :             }
    2276              : 
    2277     20495236 :           if (gsi_end_p (i))
    2278     40990472 :             i = gsi_last_bb (bb);
    2279              :           else
    2280     27199336 :             gsi_prev (&i);
    2281              :         }
    2282              :     }
    2283              : 
    2284     35267939 :   if ((unsigned) bb->index < bb_to_omp_idx.length ())
    2285        13643 :     bb_to_omp_idx[bb->index] = -1;
    2286     35267939 :   remove_phi_nodes_and_edges_for_unreachable_block (bb);
    2287     35267939 :   bb->il.gimple.seq = NULL;
    2288     35267939 :   bb->il.gimple.phi_nodes = NULL;
    2289     35267939 : }
    2290              : 
    2291              : 
    2292              : /* Given a basic block BB and a value VAL for use in the final statement
    2293              :    of the block (if a GIMPLE_COND, GIMPLE_SWITCH, or computed goto), return
    2294              :    the edge that will be taken out of the block.
    2295              :    If VAL is NULL_TREE, then the current value of the final statement's
    2296              :    predicate or index is used.
    2297              :    If the value does not match a unique edge, NULL is returned.  */
    2298              : 
    2299              : edge
    2300    241836063 : find_taken_edge (basic_block bb, tree val)
    2301              : {
    2302    241836063 :   gimple *stmt;
    2303              : 
    2304    241836063 :   stmt = *gsi_last_bb (bb);
    2305              : 
    2306              :   /* Handle ENTRY and EXIT.  */
    2307    241836063 :   if (!stmt)
    2308              :     ;
    2309              : 
    2310    238339748 :   else if (gimple_code (stmt) == GIMPLE_COND)
    2311    194185500 :     return find_taken_edge_cond_expr (as_a <gcond *> (stmt), val);
    2312              : 
    2313     44154248 :   else if (gimple_code (stmt) == GIMPLE_SWITCH)
    2314      1030689 :     return find_taken_edge_switch_expr (as_a <gswitch *> (stmt), val);
    2315              : 
    2316     43123559 :   else if (computed_goto_p (stmt))
    2317              :     {
    2318              :       /* Only optimize if the argument is a label, if the argument is
    2319              :          not a label then we cannot construct a proper CFG.
    2320              : 
    2321              :          It may be the case that we only need to allow the LABEL_REF to
    2322              :          appear inside an ADDR_EXPR, but we also allow the LABEL_REF to
    2323              :          appear inside a LABEL_EXPR just to be safe.  */
    2324         2947 :       if (val
    2325         1613 :           && (TREE_CODE (val) == ADDR_EXPR || TREE_CODE (val) == LABEL_EXPR)
    2326         3242 :           && TREE_CODE (TREE_OPERAND (val, 0)) == LABEL_DECL)
    2327          208 :         return find_taken_edge_computed_goto (bb, TREE_OPERAND (val, 0));
    2328              :     }
    2329              : 
    2330              :   /* Otherwise we only know the taken successor edge if it's unique.  */
    2331     46619666 :   return single_succ_p (bb) ? single_succ_edge (bb) : NULL;
    2332              : }
    2333              : 
    2334              : /* Given a constant value VAL and the entry block BB to a GOTO_EXPR
    2335              :    statement, determine which of the outgoing edges will be taken out of the
    2336              :    block.  Return NULL if either edge may be taken.  */
    2337              : 
    2338              : static edge
    2339          208 : find_taken_edge_computed_goto (basic_block bb, tree val)
    2340              : {
    2341          208 :   basic_block dest;
    2342          208 :   edge e = NULL;
    2343              : 
    2344          208 :   dest = label_to_block (cfun, val);
    2345          208 :   if (dest)
    2346          204 :     e = find_edge (bb, dest);
    2347              : 
    2348              :   /* It's possible for find_edge to return NULL here on invalid code
    2349              :      that abuses the labels-as-values extension (e.g. code that attempts to
    2350              :      jump *between* functions via stored labels-as-values; PR 84136).
    2351              :      If so, then we simply return that NULL for the edge.
    2352              :      We don't currently have a way of detecting such invalid code, so we
    2353              :      can't assert that it was the case when a NULL edge occurs here.  */
    2354              : 
    2355          208 :   return e;
    2356              : }
    2357              : 
    2358              : /* Given COND_STMT and a constant value VAL for use as the predicate,
    2359              :    determine which of the two edges will be taken out of
    2360              :    the statement's block.  Return NULL if either edge may be taken.
    2361              :    If VAL is NULL_TREE, then the current value of COND_STMT's predicate
    2362              :    is used.  */
    2363              : 
    2364              : static edge
    2365    194185500 : find_taken_edge_cond_expr (const gcond *cond_stmt, tree val)
    2366              : {
    2367    194185500 :   edge true_edge, false_edge;
    2368              : 
    2369    194185500 :   if (val == NULL_TREE)
    2370              :     {
    2371              :       /* Use the current value of the predicate.  */
    2372    180190075 :       if (gimple_cond_true_p (cond_stmt))
    2373        69220 :         val = integer_one_node;
    2374    180120855 :       else if (gimple_cond_false_p (cond_stmt))
    2375       151447 :         val = integer_zero_node;
    2376              :       else
    2377              :         return NULL;
    2378              :     }
    2379     13995425 :   else if (TREE_CODE (val) != INTEGER_CST)
    2380              :     return NULL;
    2381              : 
    2382     12978139 :   extract_true_false_edges_from_block (gimple_bb (cond_stmt),
    2383              :                                        &true_edge, &false_edge);
    2384              : 
    2385     12978139 :   return (integer_zerop (val) ? false_edge : true_edge);
    2386              : }
    2387              : 
    2388              : /* Given SWITCH_STMT and an INTEGER_CST VAL for use as the index, determine
    2389              :    which edge will be taken out of the statement's block.  Return NULL if any
    2390              :    edge may be taken.
    2391              :    If VAL is NULL_TREE, then the current value of SWITCH_STMT's index
    2392              :    is used.  */
    2393              : 
    2394              : edge
    2395      1030839 : find_taken_edge_switch_expr (const gswitch *switch_stmt, tree val)
    2396              : {
    2397      1030839 :   basic_block dest_bb;
    2398      1030839 :   edge e;
    2399      1030839 :   tree taken_case;
    2400              : 
    2401      1030839 :   if (gimple_switch_num_labels (switch_stmt) == 1)
    2402            0 :     taken_case = gimple_switch_default_label (switch_stmt);
    2403              :   else
    2404              :     {
    2405      1030839 :       if (val == NULL_TREE)
    2406       146232 :         val = gimple_switch_index (switch_stmt);
    2407      1030839 :       if (TREE_CODE (val) != INTEGER_CST)
    2408              :         return NULL;
    2409              :       else
    2410        23002 :         taken_case = find_case_label_for_value (switch_stmt, val);
    2411              :     }
    2412        23002 :   dest_bb = label_to_block (cfun, CASE_LABEL (taken_case));
    2413              : 
    2414        23002 :   e = find_edge (gimple_bb (switch_stmt), dest_bb);
    2415        23002 :   gcc_assert (e);
    2416              :   return e;
    2417              : }
    2418              : 
    2419              : 
    2420              : /* Return the CASE_LABEL_EXPR that SWITCH_STMT will take for VAL.
    2421              :    We can make optimal use here of the fact that the case labels are
    2422              :    sorted: We can do a binary search for a case matching VAL.  */
    2423              : 
    2424              : tree
    2425        23002 : find_case_label_for_value (const gswitch *switch_stmt, tree val)
    2426              : {
    2427        23002 :   size_t low, high, n = gimple_switch_num_labels (switch_stmt);
    2428        23002 :   tree default_case = gimple_switch_default_label (switch_stmt);
    2429              : 
    2430        48991 :   for (low = 0, high = n; high - low > 1; )
    2431              :     {
    2432        45304 :       size_t i = (high + low) / 2;
    2433        45304 :       tree t = gimple_switch_label (switch_stmt, i);
    2434        45304 :       int cmp;
    2435              : 
    2436              :       /* Cache the result of comparing CASE_LOW and val.  */
    2437        45304 :       cmp = tree_int_cst_compare (CASE_LOW (t), val);
    2438              : 
    2439        45304 :       if (cmp > 0)
    2440              :         high = i;
    2441              :       else
    2442        32932 :         low = i;
    2443              : 
    2444        45304 :       if (CASE_HIGH (t) == NULL)
    2445              :         {
    2446              :           /* A single-valued case label.  */
    2447        44202 :           if (cmp == 0)
    2448              :             return t;
    2449              :         }
    2450              :       else
    2451              :         {
    2452              :           /* A case range.  We can only handle integer ranges.  */
    2453         1102 :           if (cmp <= 0 && tree_int_cst_compare (CASE_HIGH (t), val) >= 0)
    2454              :             return t;
    2455              :         }
    2456              :     }
    2457              : 
    2458              :   return default_case;
    2459              : }
    2460              : 
    2461              : 
    2462              : /* Dump a basic block on stderr.  */
    2463              : 
    2464              : void
    2465            0 : gimple_debug_bb (basic_block bb)
    2466              : {
    2467            0 :   dump_bb (stderr, bb, 0, TDF_VOPS|TDF_MEMSYMS|TDF_BLOCKS);
    2468            0 : }
    2469              : 
    2470              : 
    2471              : /* Dump basic block with index N on stderr.  */
    2472              : 
    2473              : basic_block
    2474            0 : gimple_debug_bb_n (int n)
    2475              : {
    2476            0 :   gimple_debug_bb (BASIC_BLOCK_FOR_FN (cfun, n));
    2477            0 :   return BASIC_BLOCK_FOR_FN (cfun, n);
    2478              : }
    2479              : 
    2480              : 
    2481              : /* Dump the CFG on stderr.
    2482              : 
    2483              :    FLAGS are the same used by the tree dumping functions
    2484              :    (see TDF_* in dumpfile.h).  */
    2485              : 
    2486              : void
    2487            0 : gimple_debug_cfg (dump_flags_t flags)
    2488              : {
    2489            0 :   gimple_dump_cfg (stderr, flags);
    2490            0 : }
    2491              : 
    2492              : 
    2493              : /* Dump the program showing basic block boundaries on the given FILE.
    2494              : 
    2495              :    FLAGS are the same used by the tree dumping functions (see TDF_* in
    2496              :    tree.h).  */
    2497              : 
    2498              : void
    2499          211 : gimple_dump_cfg (FILE *file, dump_flags_t flags)
    2500              : {
    2501          211 :   if (flags & TDF_DETAILS)
    2502              :     {
    2503            2 :       dump_function_header (file, current_function_decl, flags);
    2504            2 :       fprintf (file, ";; \n%d basic blocks, %d edges, last basic block %d.\n\n",
    2505              :                n_basic_blocks_for_fn (cfun), n_edges_for_fn (cfun),
    2506            2 :                last_basic_block_for_fn (cfun));
    2507              : 
    2508            2 :       brief_dump_cfg (file, flags);
    2509            2 :       fprintf (file, "\n");
    2510              :     }
    2511              : 
    2512          211 :   if (flags & TDF_STATS)
    2513           54 :     dump_cfg_stats (file);
    2514              : 
    2515          211 :   dump_function_to_file (current_function_decl, file, flags | TDF_BLOCKS);
    2516          211 : }
    2517              : 
    2518              : 
    2519              : /* Dump CFG statistics on FILE.  */
    2520              : 
    2521              : void
    2522           54 : dump_cfg_stats (FILE *file)
    2523              : {
    2524           54 :   static long max_num_merged_labels = 0;
    2525           54 :   unsigned long size, total = 0;
    2526           54 :   long num_edges;
    2527           54 :   basic_block bb;
    2528           54 :   const char * const fmt_str   = "%-30s%-13s%12s\n";
    2529           54 :   const char * const fmt_str_1 = "%-30s%13d" PRsa (11) "\n";
    2530           54 :   const char * const fmt_str_2 = "%-30s%13ld" PRsa (11) "\n";
    2531           54 :   const char * const fmt_str_3 = "%-43s" PRsa (11) "\n";
    2532           54 :   const char *funcname = current_function_name ();
    2533              : 
    2534           54 :   fprintf (file, "\nCFG Statistics for %s\n\n", funcname);
    2535              : 
    2536           54 :   fprintf (file, "---------------------------------------------------------\n");
    2537           54 :   fprintf (file, fmt_str, "", "  Number of  ", "Memory");
    2538           54 :   fprintf (file, fmt_str, "", "  instances  ", "used ");
    2539           54 :   fprintf (file, "---------------------------------------------------------\n");
    2540              : 
    2541           54 :   size = n_basic_blocks_for_fn (cfun) * sizeof (struct basic_block_def);
    2542           54 :   total += size;
    2543           54 :   fprintf (file, fmt_str_1, "Basic blocks", n_basic_blocks_for_fn (cfun),
    2544            0 :            SIZE_AMOUNT (size));
    2545              : 
    2546           54 :   num_edges = 0;
    2547          151 :   FOR_EACH_BB_FN (bb, cfun)
    2548          194 :     num_edges += EDGE_COUNT (bb->succs);
    2549           54 :   size = num_edges * sizeof (class edge_def);
    2550           54 :   total += size;
    2551           54 :   fprintf (file, fmt_str_2, "Edges", num_edges, SIZE_AMOUNT (size));
    2552              : 
    2553           54 :   fprintf (file, "---------------------------------------------------------\n");
    2554           54 :   fprintf (file, fmt_str_3, "Total memory used by CFG data",
    2555            0 :            SIZE_AMOUNT (total));
    2556           54 :   fprintf (file, "---------------------------------------------------------\n");
    2557           54 :   fprintf (file, "\n");
    2558              : 
    2559           54 :   if (cfg_stats.num_merged_labels > max_num_merged_labels)
    2560            0 :     max_num_merged_labels = cfg_stats.num_merged_labels;
    2561              : 
    2562           54 :   fprintf (file, "Coalesced label blocks: %ld (Max so far: %ld)\n",
    2563              :            cfg_stats.num_merged_labels, max_num_merged_labels);
    2564              : 
    2565           54 :   fprintf (file, "\n");
    2566           54 : }
    2567              : 
    2568              : 
    2569              : /* Dump CFG statistics on stderr.  Keep extern so that it's always
    2570              :    linked in the final executable.  */
    2571              : 
    2572              : DEBUG_FUNCTION void
    2573            0 : debug_cfg_stats (void)
    2574              : {
    2575            0 :   dump_cfg_stats (stderr);
    2576            0 : }
    2577              : 
    2578              : /*---------------------------------------------------------------------------
    2579              :                              Miscellaneous helpers
    2580              : ---------------------------------------------------------------------------*/
    2581              : 
    2582              : /* Return true if T, a GIMPLE_CALL, can make an abnormal transfer of control
    2583              :    flow.  Transfers of control flow associated with EH are excluded.  */
    2584              : 
    2585              : static bool
    2586    141794690 : call_can_make_abnormal_goto (gimple *t)
    2587              : {
    2588              :   /* If the function has no non-local labels, then a call cannot make an
    2589              :      abnormal transfer of control.  */
    2590    141794690 :   if (!cfun->has_nonlocal_label
    2591    141681526 :       && !cfun->calls_setjmp)
    2592              :    return false;
    2593              : 
    2594              :   /* Likewise if the call has no side effects.  */
    2595       224037 :   if (!gimple_has_side_effects (t))
    2596              :     return false;
    2597              : 
    2598              :   /* Likewise if the called function is leaf.  */
    2599       216319 :   if (gimple_call_flags (t) & ECF_LEAF)
    2600              :     return false;
    2601              : 
    2602              :   return true;
    2603              : }
    2604              : 
    2605              : 
    2606              : /* Return true if T can make an abnormal transfer of control flow.
    2607              :    Transfers of control flow associated with EH are excluded.  */
    2608              : 
    2609              : bool
    2610    590394193 : stmt_can_make_abnormal_goto (gimple *t)
    2611              : {
    2612    590394193 :   if (computed_goto_p (t))
    2613              :     return true;
    2614    590390197 :   if (is_gimple_call (t))
    2615    130887586 :     return call_can_make_abnormal_goto (t);
    2616              :   return false;
    2617              : }
    2618              : 
    2619              : 
    2620              : /* Return true if T represents a stmt that always transfers control.  */
    2621              : 
    2622              : bool
    2623  16464945556 : is_ctrl_stmt (gimple *t)
    2624              : {
    2625  16464945556 :   switch (gimple_code (t))
    2626              :     {
    2627              :     case GIMPLE_COND:
    2628              :     case GIMPLE_SWITCH:
    2629              :     case GIMPLE_GOTO:
    2630              :     case GIMPLE_RETURN:
    2631              :     case GIMPLE_RESX:
    2632              :       return true;
    2633  14282130614 :     default:
    2634  14282130614 :       return false;
    2635              :     }
    2636              : }
    2637              : 
    2638              : 
    2639              : /* Return true if T is a statement that may alter the flow of control
    2640              :    (e.g., a call to a non-returning function).  */
    2641              : 
    2642              : bool
    2643  13582396101 : is_ctrl_altering_stmt (gimple *t)
    2644              : {
    2645  13582396101 :   gcc_assert (t);
    2646              : 
    2647  13582396101 :   switch (gimple_code (t))
    2648              :     {
    2649   1077846616 :     case GIMPLE_CALL:
    2650              :       /* Per stmt call flag indicates whether the call could alter
    2651              :          controlflow.  */
    2652   1077846616 :       if (gimple_call_ctrl_altering_p (t))
    2653              :         return true;
    2654              :       break;
    2655              : 
    2656              :     case GIMPLE_EH_DISPATCH:
    2657              :       /* EH_DISPATCH branches to the individual catch handlers at
    2658              :          this level of a try or allowed-exceptions region.  It can
    2659              :          fallthru to the next statement as well.  */
    2660              :       return true;
    2661              : 
    2662     14027073 :     case GIMPLE_ASM:
    2663     14027073 :       if (gimple_asm_nlabels (as_a <gasm *> (t)) > 0)
    2664              :         return true;
    2665              :       break;
    2666              : 
    2667              :     CASE_GIMPLE_OMP:
    2668              :       /* OpenMP directives alter control flow.  */
    2669              :       return true;
    2670              : 
    2671              :     case GIMPLE_TRANSACTION:
    2672              :       /* A transaction start alters control flow.  */
    2673              :       return true;
    2674              : 
    2675              :     default:
    2676              :       break;
    2677              :     }
    2678              : 
    2679              :   /* If a statement can throw, it alters control flow.  */
    2680  13412913791 :   return stmt_can_throw_internal (cfun, t);
    2681              : }
    2682              : 
    2683              : 
    2684              : /* Return true if T is a simple local goto.  */
    2685              : 
    2686              : bool
    2687      6166400 : simple_goto_p (gimple *t)
    2688              : {
    2689      6166400 :   return (gimple_code (t) == GIMPLE_GOTO
    2690      6166400 :           && TREE_CODE (gimple_goto_dest (t)) == LABEL_DECL);
    2691              : }
    2692              : 
    2693              : 
    2694              : /* Return true if STMT should start a new basic block.  PREV_STMT is
    2695              :    the statement preceding STMT.  It is used when STMT is a label or a
    2696              :    case label.  Labels should only start a new basic block if their
    2697              :    previous statement wasn't a label.  Otherwise, sequence of labels
    2698              :    would generate unnecessary basic blocks that only contain a single
    2699              :    label.  */
    2700              : 
    2701              : static inline bool
    2702     71310505 : stmt_starts_bb_p (gimple *stmt, gimple *prev_stmt)
    2703              : {
    2704     71310505 :   if (stmt == NULL)
    2705              :     return false;
    2706              : 
    2707              :   /* PREV_STMT is only set to a debug stmt if the debug stmt is before
    2708              :      any nondebug stmts in the block.  We don't want to start another
    2709              :      block in this case: the debug stmt will already have started the
    2710              :      one STMT would start if we weren't outputting debug stmts.  */
    2711     71310505 :   if (prev_stmt && is_gimple_debug (prev_stmt))
    2712              :     return false;
    2713              : 
    2714              :   /* Labels start a new basic block only if the preceding statement
    2715              :      wasn't a label of the same type.  This prevents the creation of
    2716              :      consecutive blocks that have nothing but a single label.  */
    2717     70871426 :   if (glabel *label_stmt = dyn_cast <glabel *> (stmt))
    2718              :     {
    2719              :       /* Nonlocal and computed GOTO targets always start a new block.  */
    2720      4098459 :       if (DECL_NONLOCAL (gimple_label_label (label_stmt))
    2721      4098459 :           || FORCED_LABEL (gimple_label_label (label_stmt)))
    2722              :         return true;
    2723              : 
    2724      5970810 :       if (glabel *plabel = safe_dyn_cast <glabel *> (prev_stmt))
    2725              :         {
    2726      2224720 :           if (DECL_NONLOCAL (gimple_label_label (plabel))
    2727      2224720 :               || !DECL_ARTIFICIAL (gimple_label_label (plabel)))
    2728              :             return true;
    2729              : 
    2730      2213547 :           cfg_stats.num_merged_labels++;
    2731      2213547 :           return false;
    2732              :         }
    2733              :       else
    2734              :         return true;
    2735              :     }
    2736     66772967 :   else if (gimple_code (stmt) == GIMPLE_CALL)
    2737              :     {
    2738      9234734 :       if (gimple_call_flags (stmt) & ECF_RETURNS_TWICE)
    2739              :         /* setjmp acts similar to a nonlocal GOTO target and thus should
    2740              :            start a new block.  */
    2741              :         return true;
    2742      9233563 :       if (gimple_call_internal_p (stmt, IFN_PHI)
    2743            0 :           && prev_stmt
    2744            0 :           && gimple_code (prev_stmt) != GIMPLE_LABEL
    2745      9233563 :           && (gimple_code (prev_stmt) != GIMPLE_CALL
    2746            0 :               || ! gimple_call_internal_p (prev_stmt, IFN_PHI)))
    2747              :         /* PHI nodes start a new block unless preceded by a label
    2748              :            or another PHI.  */
    2749              :         return true;
    2750              :     }
    2751              : 
    2752              :   return false;
    2753              : }
    2754              : 
    2755              : 
    2756              : /* Return true if T should end a basic block.  */
    2757              : 
    2758              : bool
    2759  14515500406 : stmt_ends_bb_p (gimple *t)
    2760              : {
    2761  14515500406 :   return is_ctrl_stmt (t) || is_ctrl_altering_stmt (t);
    2762              : }
    2763              : 
    2764              : /* Remove block annotations and other data structures.  */
    2765              : 
    2766              : void
    2767      3160030 : delete_tree_cfg_annotations (struct function *fn)
    2768              : {
    2769      3160030 :   vec_free (label_to_block_map_for_fn (fn));
    2770      3160030 : }
    2771              : 
    2772              : /* Return the virtual phi in BB.  */
    2773              : 
    2774              : gphi *
    2775   2737360351 : get_virtual_phi (basic_block bb)
    2776              : {
    2777   2737360351 :   for (gphi_iterator gsi = gsi_start_phis (bb);
    2778   3386340377 :        !gsi_end_p (gsi);
    2779    648980026 :        gsi_next (&gsi))
    2780              :     {
    2781   1456117718 :       gphi *phi = gsi.phi ();
    2782              : 
    2783   2912235436 :       if (virtual_operand_p (PHI_RESULT (phi)))
    2784    807137692 :         return phi;
    2785              :     }
    2786              : 
    2787   1930222659 :   return NULL;
    2788              : }
    2789              : 
    2790              : /* Return the first statement in basic block BB.  */
    2791              : 
    2792              : gimple *
    2793    146711501 : first_stmt (basic_block bb)
    2794              : {
    2795    146711501 :   gimple_stmt_iterator i = gsi_start_bb (bb);
    2796    146711501 :   gimple *stmt = NULL;
    2797              : 
    2798    516342125 :   while (!gsi_end_p (i) && is_gimple_debug ((stmt = gsi_stmt (i))))
    2799              :     {
    2800    369630624 :       gsi_next (&i);
    2801    369630624 :       stmt = NULL;
    2802              :     }
    2803    146711501 :   return stmt;
    2804              : }
    2805              : 
    2806              : /* Return the last statement in basic block BB.  */
    2807              : 
    2808              : gimple *
    2809    174866870 : last_nondebug_stmt (basic_block bb)
    2810              : {
    2811    174866870 :   gimple_stmt_iterator i = gsi_last_bb (bb);
    2812              :   gimple *stmt = NULL;
    2813              : 
    2814    194347853 :   while (!gsi_end_p (i) && is_gimple_debug ((stmt = gsi_stmt (i))))
    2815              :     {
    2816    263831266 :       gsi_prev (&i);
    2817              :       stmt = NULL;
    2818              :     }
    2819    174866870 :   return stmt;
    2820              : }
    2821              : 
    2822              : /* Return the last statement of an otherwise empty block.  Return NULL
    2823              :    if the block is totally empty, or if it contains more than one
    2824              :    statement.  */
    2825              : 
    2826              : gimple *
    2827      9059351 : last_and_only_stmt (basic_block bb)
    2828              : {
    2829      9059351 :   gimple_stmt_iterator i = gsi_last_nondebug_bb (bb);
    2830      9059351 :   gimple *last, *prev;
    2831              : 
    2832      9059351 :   if (gsi_end_p (i))
    2833              :     return NULL;
    2834              : 
    2835      8883165 :   last = gsi_stmt (i);
    2836      8883165 :   gsi_prev_nondebug (&i);
    2837      8883165 :   if (gsi_end_p (i))
    2838              :     return last;
    2839              : 
    2840              :   /* Empty statements should no longer appear in the instruction stream.
    2841              :      Everything that might have appeared before should be deleted by
    2842              :      remove_useless_stmts, and the optimizers should just gsi_remove
    2843              :      instead of smashing with build_empty_stmt.
    2844              : 
    2845              :      Thus the only thing that should appear here in a block containing
    2846              :      one executable statement is a label.  */
    2847      7519580 :   prev = gsi_stmt (i);
    2848      7519580 :   if (gimple_code (prev) == GIMPLE_LABEL)
    2849              :     return last;
    2850              :   else
    2851              :     return NULL;
    2852              : }
    2853              : 
    2854              : /* Returns the basic block after which the new basic block created
    2855              :    by splitting edge EDGE_IN should be placed.  Tries to keep the new block
    2856              :    near its "logical" location.  This is of most help to humans looking
    2857              :    at debugging dumps.  */
    2858              : 
    2859              : basic_block
    2860     26520623 : split_edge_bb_loc (edge edge_in)
    2861              : {
    2862     26520623 :   basic_block dest = edge_in->dest;
    2863     26520623 :   basic_block dest_prev = dest->prev_bb;
    2864              : 
    2865     26520623 :   if (dest_prev)
    2866              :     {
    2867     26520623 :       edge e = find_edge (dest_prev, dest);
    2868     26520623 :       if (e && !(e->flags & EDGE_COMPLEX))
    2869     22456083 :         return edge_in->src;
    2870              :     }
    2871              :   return dest_prev;
    2872              : }
    2873              : 
    2874              : /* Split a (typically critical) edge EDGE_IN.  Return the new block.
    2875              :    Abort on abnormal edges.  */
    2876              : 
    2877              : static basic_block
    2878     24763134 : gimple_split_edge (edge edge_in)
    2879              : {
    2880     24763134 :   basic_block new_bb, after_bb, dest;
    2881     24763134 :   edge new_edge, e;
    2882              : 
    2883              :   /* Abnormal edges cannot be split.  */
    2884     24763134 :   gcc_assert (!(edge_in->flags & EDGE_ABNORMAL));
    2885              : 
    2886     24763134 :   dest = edge_in->dest;
    2887              : 
    2888     24763134 :   after_bb = split_edge_bb_loc (edge_in);
    2889              : 
    2890     24763134 :   new_bb = create_empty_bb (after_bb);
    2891     24763134 :   new_bb->count = edge_in->count ();
    2892              : 
    2893              :   /* We want to avoid re-allocating PHIs when we first
    2894              :      add the fallthru edge from new_bb to dest but we also
    2895              :      want to avoid changing PHI argument order when
    2896              :      first redirecting edge_in away from dest.  The former
    2897              :      avoids changing PHI argument order by adding them
    2898              :      last and then the redirection swapping it back into
    2899              :      place by means of unordered remove.
    2900              :      So hack around things by temporarily removing all PHIs
    2901              :      from the destination during the edge redirection and then
    2902              :      making sure the edges stay in order.  */
    2903     24763134 :   gimple_seq saved_phis = phi_nodes (dest);
    2904     24763134 :   unsigned old_dest_idx = edge_in->dest_idx;
    2905     24763134 :   set_phi_nodes (dest, NULL);
    2906     24763134 :   new_edge = make_single_succ_edge (new_bb, dest, EDGE_FALLTHRU);
    2907     24763134 :   e = redirect_edge_and_branch (edge_in, new_bb);
    2908     24763134 :   gcc_assert (e == edge_in && new_edge->dest_idx == old_dest_idx);
    2909              :   /* set_phi_nodes sets the BB of the PHI nodes, so do it manually here.  */
    2910     24763134 :   dest->il.gimple.phi_nodes = saved_phis;
    2911              : 
    2912     24763134 :   return new_bb;
    2913              : }
    2914              : 
    2915              : 
    2916              : /* Verify properties of the address expression T whose base should be
    2917              :    TREE_ADDRESSABLE if VERIFY_ADDRESSABLE is true.  */
    2918              : 
    2919              : static bool
    2920    602308302 : verify_address (tree t, bool verify_addressable)
    2921              : {
    2922    602308302 :   bool old_constant;
    2923    602308302 :   bool old_side_effects;
    2924    602308302 :   bool new_constant;
    2925    602308302 :   bool new_side_effects;
    2926              : 
    2927    602308302 :   old_constant = TREE_CONSTANT (t);
    2928    602308302 :   old_side_effects = TREE_SIDE_EFFECTS (t);
    2929              : 
    2930    602308302 :   recompute_tree_invariant_for_addr_expr (t);
    2931    602308302 :   new_side_effects = TREE_SIDE_EFFECTS (t);
    2932    602308302 :   new_constant = TREE_CONSTANT (t);
    2933              : 
    2934    602308302 :   if (old_constant != new_constant)
    2935              :     {
    2936            0 :       error ("constant not recomputed when %<ADDR_EXPR%> changed");
    2937            0 :       return true;
    2938              :     }
    2939    602308302 :   if (old_side_effects != new_side_effects)
    2940              :     {
    2941            0 :       error ("side effects not recomputed when %<ADDR_EXPR%> changed");
    2942            0 :       return true;
    2943              :     }
    2944              : 
    2945    602308302 :   tree base = TREE_OPERAND (t, 0);
    2946    744074419 :   while (handled_component_p (base))
    2947    141766117 :     base = TREE_OPERAND (base, 0);
    2948              : 
    2949    602308302 :   if (!(VAR_P (base)
    2950              :         || TREE_CODE (base) == PARM_DECL
    2951              :         || TREE_CODE (base) == RESULT_DECL))
    2952              :     return false;
    2953              : 
    2954    440474317 :   if (verify_addressable && !TREE_ADDRESSABLE (base))
    2955              :     {
    2956            0 :       error ("address taken but %<TREE_ADDRESSABLE%> bit not set");
    2957            0 :       return true;
    2958              :     }
    2959              : 
    2960              :   return false;
    2961              : }
    2962              : 
    2963              : 
    2964              : /* Verify if EXPR is a valid GIMPLE reference expression.  If
    2965              :    REQUIRE_LVALUE is true verifies it is an lvalue.  Returns true
    2966              :    if there is an error, otherwise false.  */
    2967              : 
    2968              : static bool
    2969   3663338740 : verify_types_in_gimple_reference (tree expr, bool require_lvalue)
    2970              : {
    2971   3663338740 :   const char *code_name = get_tree_code_name (TREE_CODE (expr));
    2972              : 
    2973   3663338740 :   if (TREE_CODE (expr) == REALPART_EXPR
    2974   3663338740 :       || TREE_CODE (expr) == IMAGPART_EXPR
    2975   3630520310 :       || TREE_CODE (expr) == BIT_FIELD_REF
    2976   3617567399 :       || TREE_CODE (expr) == VIEW_CONVERT_EXPR)
    2977              :     {
    2978     89641219 :       tree op = TREE_OPERAND (expr, 0);
    2979     89641219 :       if (TREE_CODE (expr) != VIEW_CONVERT_EXPR
    2980     89641219 :           && !is_gimple_reg_type (TREE_TYPE (expr)))
    2981              :         {
    2982            0 :           error ("non-scalar %qs", code_name);
    2983            0 :           return true;
    2984              :         }
    2985              : 
    2986     89641219 :       if (TREE_CODE (expr) == BIT_FIELD_REF)
    2987              :         {
    2988     12952911 :           tree t1 = TREE_OPERAND (expr, 1);
    2989     12952911 :           tree t2 = TREE_OPERAND (expr, 2);
    2990     12952911 :           poly_uint64 size, bitpos;
    2991     12952911 :           if (!poly_int_tree_p (t1, &size)
    2992     12952911 :               || !poly_int_tree_p (t2, &bitpos)
    2993     12952911 :               || !types_compatible_p (bitsizetype, TREE_TYPE (t1))
    2994     25905822 :               || !types_compatible_p (bitsizetype, TREE_TYPE (t2)))
    2995              :             {
    2996            0 :               error ("invalid position or size operand to %qs", code_name);
    2997            0 :               return true;
    2998              :             }
    2999     25865904 :           if (INTEGRAL_TYPE_P (TREE_TYPE (expr))
    3000     23761090 :               && maybe_ne (TYPE_PRECISION (TREE_TYPE (expr)), size))
    3001              :             {
    3002            0 :               error ("integral result type precision does not match "
    3003              :                      "field size of %qs", code_name);
    3004            0 :               return true;
    3005              :             }
    3006     12952911 :           else if (!INTEGRAL_TYPE_P (TREE_TYPE (expr))
    3007      2104814 :                    && TYPE_MODE (TREE_TYPE (expr)) != BLKmode
    3008      4207982 :                    && maybe_ne (GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (expr))),
    3009              :                                 size))
    3010              :             {
    3011            0 :               error ("mode size of non-integral result does not "
    3012              :                      "match field size of %qs",
    3013              :                      code_name);
    3014            0 :               return true;
    3015              :             }
    3016     25905122 :           if (INTEGRAL_TYPE_P (TREE_TYPE (op))
    3017     13177168 :               && !type_has_mode_precision_p (TREE_TYPE (op)))
    3018              :             {
    3019            0 :               error ("%qs of non-mode-precision operand", code_name);
    3020            0 :               return true;
    3021              :             }
    3022     12952911 :           if (!AGGREGATE_TYPE_P (TREE_TYPE (op))
    3023     12952911 :               && known_gt (size + bitpos,
    3024              :                            tree_to_poly_uint64 (TYPE_SIZE (TREE_TYPE (op)))))
    3025              :             {
    3026            0 :               error ("position plus size exceeds size of referenced object in "
    3027              :                      "%qs", code_name);
    3028            0 :               return true;
    3029              :             }
    3030              :         }
    3031              : 
    3032     89641219 :       if ((TREE_CODE (expr) == REALPART_EXPR
    3033     89641219 :            || TREE_CODE (expr) == IMAGPART_EXPR)
    3034    122459649 :           && !useless_type_conversion_p (TREE_TYPE (expr),
    3035     32818430 :                                          TREE_TYPE (TREE_TYPE (op))))
    3036              :         {
    3037            0 :           error ("type mismatch in %qs reference", code_name);
    3038            0 :           debug_generic_stmt (TREE_TYPE (expr));
    3039            0 :           debug_generic_stmt (TREE_TYPE (TREE_TYPE (op)));
    3040            0 :           return true;
    3041              :         }
    3042              : 
    3043     89641219 :       if (TREE_CODE (expr) == VIEW_CONVERT_EXPR)
    3044              :         {
    3045              :           /* For VIEW_CONVERT_EXPRs which are allowed here too, we only check
    3046              :              that their operand is not a register an invariant when
    3047              :              requiring an lvalue (this usually means there is a SRA or IPA-SRA
    3048              :              bug).  Otherwise there is nothing to verify, gross mismatches at
    3049              :              most invoke undefined behavior.  */
    3050     43869878 :           if (require_lvalue
    3051     43869878 :               && (is_gimple_reg (op) || is_gimple_min_invariant (op)))
    3052              :             {
    3053            0 :               error ("conversion of %qs on the left hand side of %qs",
    3054            0 :                      get_tree_code_name (TREE_CODE (op)), code_name);
    3055            0 :               debug_generic_stmt (expr);
    3056            0 :               return true;
    3057              :             }
    3058     43869878 :           else if (is_gimple_reg (op)
    3059     43869878 :                    && TYPE_SIZE (TREE_TYPE (expr)) != TYPE_SIZE (TREE_TYPE (op)))
    3060              :             {
    3061            0 :               error ("conversion of register to a different size in %qs",
    3062              :                      code_name);
    3063            0 :               debug_generic_stmt (expr);
    3064            0 :               return true;
    3065              :             }
    3066              :         }
    3067              : 
    3068              :       expr = op;
    3069              :     }
    3070              : 
    3071              :   bool require_non_reg = false;
    3072   5980079279 :   while (handled_component_p (expr))
    3073              :     {
    3074   2316740539 :       require_non_reg = true;
    3075   2316740539 :       code_name = get_tree_code_name (TREE_CODE (expr));
    3076              : 
    3077   2316740539 :       if (TREE_CODE (expr) == REALPART_EXPR
    3078   2316740539 :           || TREE_CODE (expr) == IMAGPART_EXPR
    3079   2316740539 :           || TREE_CODE (expr) == BIT_FIELD_REF)
    3080              :         {
    3081            0 :           error ("non-top-level %qs", code_name);
    3082            0 :           return true;
    3083              :         }
    3084              : 
    3085   2316740539 :       tree op = TREE_OPERAND (expr, 0);
    3086              : 
    3087   2316740539 :       if (TREE_CODE (expr) == ARRAY_REF
    3088   2316740539 :           || TREE_CODE (expr) == ARRAY_RANGE_REF)
    3089              :         {
    3090    436377894 :           if (!is_gimple_val (TREE_OPERAND (expr, 1))
    3091    436377894 :               || (TREE_OPERAND (expr, 2)
    3092      3649590 :                   && !is_gimple_val (TREE_OPERAND (expr, 2)))
    3093    872755788 :               || (TREE_OPERAND (expr, 3)
    3094       675568 :                   && !is_gimple_val (TREE_OPERAND (expr, 3))))
    3095              :             {
    3096            0 :               error ("invalid operands to %qs", code_name);
    3097            0 :               debug_generic_stmt (expr);
    3098            0 :               return true;
    3099              :             }
    3100              :         }
    3101              : 
    3102              :       /* Verify if the reference array element types are compatible.  */
    3103   2316740539 :       if (TREE_CODE (expr) == ARRAY_REF
    3104   2752816354 :           && !useless_type_conversion_p (TREE_TYPE (expr),
    3105    436075815 :                                          TREE_TYPE (TREE_TYPE (op))))
    3106              :         {
    3107            0 :           error ("type mismatch in %qs", code_name);
    3108            0 :           debug_generic_stmt (TREE_TYPE (expr));
    3109            0 :           debug_generic_stmt (TREE_TYPE (TREE_TYPE (op)));
    3110            0 :           return true;
    3111              :         }
    3112   2316740539 :       if (TREE_CODE (expr) == ARRAY_RANGE_REF
    3113   2317042618 :           && !useless_type_conversion_p (TREE_TYPE (TREE_TYPE (expr)),
    3114       302079 :                                          TREE_TYPE (TREE_TYPE (op))))
    3115              :         {
    3116            0 :           error ("type mismatch in %qs", code_name);
    3117            0 :           debug_generic_stmt (TREE_TYPE (TREE_TYPE (expr)));
    3118            0 :           debug_generic_stmt (TREE_TYPE (TREE_TYPE (op)));
    3119            0 :           return true;
    3120              :         }
    3121              : 
    3122   2316740539 :       if (TREE_CODE (expr) == COMPONENT_REF)
    3123              :         {
    3124   1877894599 :           if (TREE_OPERAND (expr, 2)
    3125   1877894599 :               && !is_gimple_val (TREE_OPERAND (expr, 2)))
    3126              :             {
    3127            0 :               error ("invalid %qs offset operator", code_name);
    3128            0 :               return true;
    3129              :             }
    3130   1877894599 :           if (!useless_type_conversion_p (TREE_TYPE (expr),
    3131   1877894599 :                                           TREE_TYPE (TREE_OPERAND (expr, 1))))
    3132              :             {
    3133            0 :               error ("type mismatch in %qs", code_name);
    3134            0 :               debug_generic_stmt (TREE_TYPE (expr));
    3135            0 :               debug_generic_stmt (TREE_TYPE (TREE_OPERAND (expr, 1)));
    3136            0 :               return true;
    3137              :             }
    3138              :         }
    3139              : 
    3140              :       expr = op;
    3141              :     }
    3142              : 
    3143   3663338740 :   code_name = get_tree_code_name (TREE_CODE (expr));
    3144              : 
    3145   3663338740 :   if (TREE_CODE (expr) == MEM_REF)
    3146              :     {
    3147   1239036305 :       if (!is_gimple_mem_ref_addr (TREE_OPERAND (expr, 0))
    3148   1239036305 :           || (TREE_CODE (TREE_OPERAND (expr, 0)) == ADDR_EXPR
    3149    338321763 :               && verify_address (TREE_OPERAND (expr, 0), false)))
    3150              :         {
    3151            0 :           error ("invalid address operand in %qs", code_name);
    3152            0 :           debug_generic_stmt (expr);
    3153            0 :           return true;
    3154              :         }
    3155   1239036305 :       if (!poly_int_tree_p (TREE_OPERAND (expr, 1))
    3156   1239036305 :           || !POINTER_TYPE_P (TREE_TYPE (TREE_OPERAND (expr, 1))))
    3157              :         {
    3158            0 :           error ("invalid offset operand in %qs", code_name);
    3159            0 :           debug_generic_stmt (expr);
    3160            0 :           return true;
    3161              :         }
    3162   1239036305 :       if (MR_DEPENDENCE_CLIQUE (expr) != 0
    3163   1239036305 :           && MR_DEPENDENCE_CLIQUE (expr) > cfun->last_clique)
    3164              :         {
    3165            0 :           error ("invalid clique in %qs", code_name);
    3166            0 :           debug_generic_stmt (expr);
    3167            0 :           return true;
    3168              :         }
    3169              :     }
    3170   2424302435 :   else if (TREE_CODE (expr) == TARGET_MEM_REF)
    3171              :     {
    3172     29249938 :       if (!TMR_BASE (expr)
    3173     29249938 :           || !is_gimple_mem_ref_addr (TMR_BASE (expr))
    3174     58499876 :           || (TREE_CODE (TMR_BASE (expr)) == ADDR_EXPR
    3175      6663003 :               && verify_address (TMR_BASE (expr), false)))
    3176              :         {
    3177            0 :           error ("invalid address operand in %qs", code_name);
    3178            0 :           return true;
    3179              :         }
    3180     29249938 :       if (!TMR_OFFSET (expr)
    3181     29249938 :           || !poly_int_tree_p (TMR_OFFSET (expr))
    3182     58499876 :           || !POINTER_TYPE_P (TREE_TYPE (TMR_OFFSET (expr))))
    3183              :         {
    3184            0 :           error ("invalid offset operand in %qs", code_name);
    3185            0 :           debug_generic_stmt (expr);
    3186            0 :           return true;
    3187              :         }
    3188     29249938 :       if (MR_DEPENDENCE_CLIQUE (expr) != 0
    3189     29249938 :           && MR_DEPENDENCE_CLIQUE (expr) > cfun->last_clique)
    3190              :         {
    3191            0 :           error ("invalid clique in %qs", code_name);
    3192            0 :           debug_generic_stmt (expr);
    3193            0 :           return true;
    3194              :         }
    3195              :     }
    3196   2395052497 :   else if (INDIRECT_REF_P (expr))
    3197              :     {
    3198            0 :       error ("%qs in gimple IL", code_name);
    3199            0 :       debug_generic_stmt (expr);
    3200            0 :       return true;
    3201              :     }
    3202   2395052497 :   else if (require_non_reg
    3203   2395052497 :            && (is_gimple_reg (expr)
    3204    895826194 :                || (is_gimple_min_invariant (expr)
    3205              :                    /* STRING_CSTs are representatives of the string table
    3206              :                       entry which lives in memory.  */
    3207      8893697 :                    && TREE_CODE (expr) != STRING_CST)))
    3208              :     {
    3209            0 :       error ("%qs as base where non-register is required", code_name);
    3210            0 :       debug_generic_stmt (expr);
    3211            0 :       return true;
    3212              :     }
    3213              : 
    3214   3663338740 :   if (!require_lvalue
    3215   3663338740 :       && (is_gimple_reg (expr) || is_gimple_min_invariant (expr)))
    3216   1174448556 :     return false;
    3217              : 
    3218   2488890184 :   if (TREE_CODE (expr) != SSA_NAME && is_gimple_id (expr))
    3219              :     return false;
    3220              : 
    3221   1268286243 :   if (TREE_CODE (expr) != TARGET_MEM_REF
    3222   1268286243 :       && TREE_CODE (expr) != MEM_REF)
    3223              :     {
    3224            0 :       error ("invalid expression for min lvalue");
    3225            0 :       return true;
    3226              :     }
    3227              : 
    3228              :   return false;
    3229              : }
    3230              : 
    3231              : /* Returns true if there is one pointer type in TYPE_POINTER_TO (SRC_OBJ)
    3232              :    list of pointer-to types that is trivially convertible to DEST.  */
    3233              : 
    3234              : static bool
    3235          180 : one_pointer_to_useless_type_conversion_p (tree dest, tree src_obj)
    3236              : {
    3237          180 :   tree src;
    3238              : 
    3239          180 :   if (!TYPE_POINTER_TO (src_obj))
    3240              :     return true;
    3241              : 
    3242          180 :   for (src = TYPE_POINTER_TO (src_obj); src; src = TYPE_NEXT_PTR_TO (src))
    3243          180 :     if (useless_type_conversion_p (dest, src))
    3244              :       return true;
    3245              : 
    3246              :   return false;
    3247              : }
    3248              : 
    3249              : /* Return true if TYPE1 is a fixed-point type and if conversions to and
    3250              :    from TYPE2 can be handled by FIXED_CONVERT_EXPR.  */
    3251              : 
    3252              : static bool
    3253            0 : valid_fixed_convert_types_p (tree type1, tree type2)
    3254              : {
    3255            0 :   return (FIXED_POINT_TYPE_P (type1)
    3256            0 :           && (INTEGRAL_TYPE_P (type2)
    3257            0 :               || SCALAR_FLOAT_TYPE_P (type2)
    3258            0 :               || FIXED_POINT_TYPE_P (type2)));
    3259              : }
    3260              : 
    3261              : /* Verify the contents of a GIMPLE_CALL STMT.  Returns true when there
    3262              :    is a problem, otherwise false.  */
    3263              : 
    3264              : static bool
    3265   1056414328 : verify_gimple_call (gcall *stmt)
    3266              : {
    3267   1056414328 :   tree fn = gimple_call_fn (stmt);
    3268   1056414328 :   tree fntype, fndecl;
    3269   1056414328 :   unsigned i;
    3270              : 
    3271   1056414328 :   if (gimple_call_internal_p (stmt))
    3272              :     {
    3273     39071266 :       if (fn)
    3274              :         {
    3275            0 :           error ("gimple call has two targets");
    3276            0 :           debug_generic_stmt (fn);
    3277            0 :           return true;
    3278              :         }
    3279              :     }
    3280              :   else
    3281              :     {
    3282   1017343062 :       if (!fn)
    3283              :         {
    3284            0 :           error ("gimple call has no target");
    3285            0 :           return true;
    3286              :         }
    3287              :     }
    3288              : 
    3289   1017343062 :   if (fn && !is_gimple_call_addr (fn))
    3290              :     {
    3291            0 :       error ("invalid function in gimple call");
    3292            0 :       debug_generic_stmt (fn);
    3293            0 :       return true;
    3294              :     }
    3295              : 
    3296   1056414328 :   if (fn
    3297   1056414328 :       && (!POINTER_TYPE_P (TREE_TYPE (fn))
    3298   1017343062 :           || (TREE_CODE (TREE_TYPE (TREE_TYPE (fn))) != FUNCTION_TYPE
    3299    161970126 :               && TREE_CODE (TREE_TYPE (TREE_TYPE (fn))) != METHOD_TYPE)))
    3300              :     {
    3301            0 :       error ("non-function in gimple call");
    3302            0 :       return true;
    3303              :     }
    3304              : 
    3305   1056414328 :    fndecl = gimple_call_fndecl (stmt);
    3306   1056414328 :    if (fndecl
    3307    991621983 :        && TREE_CODE (fndecl) == FUNCTION_DECL
    3308    991621983 :        && DECL_LOOPING_CONST_OR_PURE_P (fndecl)
    3309      6031189 :        && !DECL_PURE_P (fndecl)
    3310   1056786963 :        && !TREE_READONLY (fndecl))
    3311              :      {
    3312            0 :        error ("invalid pure const state for function");
    3313            0 :        return true;
    3314              :      }
    3315              : 
    3316   1056414328 :   tree lhs = gimple_call_lhs (stmt);
    3317   1056414328 :   if (lhs
    3318   1056414328 :       && (!is_gimple_reg (lhs)
    3319     68328422 :           && (!is_gimple_lvalue (lhs)
    3320     68328422 :               || verify_types_in_gimple_reference
    3321     68328422 :                    (TREE_CODE (lhs) == WITH_SIZE_EXPR
    3322            0 :                     ? TREE_OPERAND (lhs, 0) : lhs, true))))
    3323              :     {
    3324            0 :       error ("invalid LHS in gimple call");
    3325            0 :       return true;
    3326              :     }
    3327              : 
    3328   1056414328 :   if (gimple_call_ctrl_altering_p (stmt)
    3329    147512675 :       && gimple_call_noreturn_p (stmt)
    3330   1198831849 :       && should_remove_lhs_p (lhs))
    3331              :     {
    3332            0 :       error ("LHS in %<noreturn%> call");
    3333            0 :       return true;
    3334              :     }
    3335              : 
    3336   1056414328 :   fntype = gimple_call_fntype (stmt);
    3337   1056414328 :   if (fntype
    3338   1056414328 :       && lhs
    3339    386091160 :       && !useless_type_conversion_p (TREE_TYPE (lhs), TREE_TYPE (fntype))
    3340              :       /* ???  At least C++ misses conversions at assignments from
    3341              :          void * call results.
    3342              :          For now simply allow arbitrary pointer type conversions.  */
    3343   1056414328 :       && !(POINTER_TYPE_P (TREE_TYPE (lhs))
    3344            0 :            && POINTER_TYPE_P (TREE_TYPE (fntype))))
    3345              :     {
    3346            0 :       error ("invalid conversion in gimple call");
    3347            0 :       debug_generic_stmt (TREE_TYPE (lhs));
    3348            0 :       debug_generic_stmt (TREE_TYPE (fntype));
    3349            0 :       return true;
    3350              :     }
    3351              : 
    3352   1056414328 :   if (gimple_call_chain (stmt)
    3353   1056414328 :       && !is_gimple_val (gimple_call_chain (stmt)))
    3354              :     {
    3355            0 :       error ("invalid static chain in gimple call");
    3356            0 :       debug_generic_stmt (gimple_call_chain (stmt));
    3357            0 :       return true;
    3358              :     }
    3359              : 
    3360              :   /* If there is a static chain argument, the call should either be
    3361              :      indirect, or the decl should have DECL_STATIC_CHAIN set.  */
    3362   1056414328 :   if (gimple_call_chain (stmt)
    3363      4995068 :       && fndecl
    3364   1057932988 :       && !DECL_STATIC_CHAIN (fndecl))
    3365              :     {
    3366            0 :       error ("static chain with function that doesn%'t use one");
    3367            0 :       return true;
    3368              :     }
    3369              : 
    3370   1056414328 :   if (fndecl && fndecl_built_in_p (fndecl, BUILT_IN_NORMAL))
    3371              :     {
    3372    251473610 :       switch (DECL_FUNCTION_CODE (fndecl))
    3373              :         {
    3374     25240774 :         case BUILT_IN_UNREACHABLE:
    3375     25240774 :         case BUILT_IN_UNREACHABLE_TRAP:
    3376     25240774 :         case BUILT_IN_TRAP:
    3377     25240774 :           if (gimple_call_num_args (stmt) > 0)
    3378              :             {
    3379              :               /* Built-in unreachable with parameters might not be caught by
    3380              :                  undefined behavior sanitizer.  Front-ends do check users do not
    3381              :                  call them that way but we also produce calls to
    3382              :                  __builtin_unreachable internally, for example when IPA figures
    3383              :                  out a call cannot happen in a legal program.  In such cases,
    3384              :                  we must make sure arguments are stripped off.  */
    3385            0 :               error ("%<__builtin_unreachable%> or %<__builtin_trap%> call "
    3386              :                      "with arguments");
    3387            0 :               return true;
    3388              :             }
    3389              :           break;
    3390              :         default:
    3391              :           break;
    3392              :         }
    3393              :     }
    3394              : 
    3395              :   /* For a call to .DEFERRED_INIT,
    3396              :      LHS = DEFERRED_INIT (SIZE of the DECL, INIT_TYPE, NAME of the DECL)
    3397              :      we should guarantee that when the 1st argument is a constant, it should
    3398              :      be the same as the size of the LHS.  */
    3399              : 
    3400   1056414328 :   if (gimple_call_internal_p (stmt, IFN_DEFERRED_INIT))
    3401              :     {
    3402      7531775 :       tree size_of_arg0 = gimple_call_arg (stmt, 0);
    3403      7531775 :       tree size_of_lhs = TYPE_SIZE_UNIT (TREE_TYPE (lhs));
    3404              : 
    3405      7531775 :       if (TREE_CODE (lhs) == SSA_NAME)
    3406      7531775 :         lhs = SSA_NAME_VAR (lhs);
    3407              : 
    3408      7531775 :       poly_uint64 size_from_arg0, size_from_lhs;
    3409      7531775 :       bool is_constant_size_arg0 = poly_int_tree_p (size_of_arg0,
    3410              :                                                     &size_from_arg0);
    3411      7531775 :       bool is_constant_size_lhs = poly_int_tree_p (size_of_lhs,
    3412              :                                                    &size_from_lhs);
    3413      7531775 :       if (is_constant_size_arg0 && is_constant_size_lhs)
    3414      7521324 :         if (maybe_ne (size_from_arg0, size_from_lhs))
    3415              :           {
    3416            0 :             error ("%<DEFERRED_INIT%> calls should have same "
    3417              :                    "constant size for the first argument and LHS");
    3418            0 :             return true;
    3419              :           }
    3420              :     }
    3421              : 
    3422              :   /* IFN_VARING is not allowed to be present after the completion of any pass
    3423              :      as it should have been replaced.  */
    3424   1056414328 :   if (gimple_call_internal_p (stmt, IFN_VARYING))
    3425              :     {
    3426            0 :       error ("%<.VARYING%> calls should have been replaced and are not allowed "
    3427              :              "outside of the pass that introduced them");
    3428            0 :       return true;
    3429              :     }
    3430              :   /* ???  The C frontend passes unpromoted arguments in case it
    3431              :      didn't see a function declaration before the call.  So for now
    3432              :      leave the call arguments mostly unverified.  Once we gimplify
    3433              :      unit-at-a-time we have a chance to fix this.  */
    3434   3146700003 :   for (i = 0; i < gimple_call_num_args (stmt); ++i)
    3435              :     {
    3436   2090285676 :       tree arg = gimple_call_arg (stmt, i);
    3437   2090285676 :       if ((is_gimple_reg_type (TREE_TYPE (arg))
    3438   1974225366 :            && !is_gimple_val (arg))
    3439   4064511041 :           || (!is_gimple_reg_type (TREE_TYPE (arg))
    3440    116060310 :               && !is_gimple_lvalue (arg)))
    3441              :         {
    3442            1 :           error ("invalid argument to gimple call");
    3443            1 :           debug_generic_expr (arg);
    3444            1 :           return true;
    3445              :         }
    3446   2090285675 :       if (!is_gimple_reg (arg))
    3447              :         {
    3448   1235454120 :           if (TREE_CODE (arg) == WITH_SIZE_EXPR)
    3449        22374 :             arg = TREE_OPERAND (arg, 0);
    3450   1235454120 :           if (verify_types_in_gimple_reference (arg, false))
    3451              :             return true;
    3452              :         }
    3453              :     }
    3454              : 
    3455              :   return false;
    3456              : }
    3457              : 
    3458              : /* Verifies the gimple comparison with the result type TYPE and
    3459              :    the operands OP0 and OP1, comparison code is CODE.  */
    3460              : 
    3461              : static bool
    3462    833468767 : verify_gimple_comparison (tree type, tree op0, tree op1, enum tree_code code)
    3463              : {
    3464    833468767 :   tree op0_type = TREE_TYPE (op0);
    3465    833468767 :   tree op1_type = TREE_TYPE (op1);
    3466              : 
    3467    833468767 :   if (!is_gimple_val (op0) || !is_gimple_val (op1))
    3468              :     {
    3469            0 :       error ("invalid operands in gimple comparison");
    3470            0 :       return true;
    3471              :     }
    3472              : 
    3473              :   /* For comparisons we do not have the operations type as the
    3474              :      effective type the comparison is carried out in.  Instead
    3475              :      we require that either the first operand is trivially
    3476              :      convertible into the second, or the other way around.  */
    3477    833468767 :   if (!useless_type_conversion_p (op0_type, op1_type)
    3478    833468767 :       && !useless_type_conversion_p (op1_type, op0_type))
    3479              :     {
    3480            0 :       error ("mismatching comparison operand types");
    3481            0 :       debug_generic_expr (op0_type);
    3482            0 :       debug_generic_expr (op1_type);
    3483            0 :       return true;
    3484              :     }
    3485              : 
    3486              :   /* The resulting type of a comparison may be an effective boolean type.  */
    3487    833468767 :   if (INTEGRAL_TYPE_P (type)
    3488    833468767 :       && (TREE_CODE (type) == BOOLEAN_TYPE
    3489          278 :           || TYPE_PRECISION (type) == 1))
    3490              :     {
    3491    831799117 :       if ((VECTOR_TYPE_P (op0_type)
    3492    831696149 :            || VECTOR_TYPE_P (op1_type))
    3493       102968 :           && code != EQ_EXPR && code != NE_EXPR
    3494            0 :           && !VECTOR_BOOLEAN_TYPE_P (op0_type)
    3495    831799117 :           && !VECTOR_INTEGER_TYPE_P (op0_type))
    3496              :         {
    3497            0 :           error ("unsupported operation or type for vector comparison"
    3498              :                  " returning a boolean");
    3499            0 :           debug_generic_expr (op0_type);
    3500            0 :           debug_generic_expr (op1_type);
    3501            0 :           return true;
    3502              :         }
    3503              :     }
    3504              :   /* Or a boolean vector type with the same element count
    3505              :      as the comparison operand types.  */
    3506      1669650 :   else if (VECTOR_TYPE_P (type)
    3507      1669650 :            && TREE_CODE (TREE_TYPE (type)) == BOOLEAN_TYPE)
    3508              :     {
    3509      1669650 :       if (TREE_CODE (op0_type) != VECTOR_TYPE
    3510      1669650 :           || TREE_CODE (op1_type) != VECTOR_TYPE)
    3511              :         {
    3512            0 :           error ("non-vector operands in vector comparison");
    3513            0 :           debug_generic_expr (op0_type);
    3514            0 :           debug_generic_expr (op1_type);
    3515            0 :           return true;
    3516              :         }
    3517              : 
    3518      1669650 :       if (maybe_ne (TYPE_VECTOR_SUBPARTS (type),
    3519      3339300 :                     TYPE_VECTOR_SUBPARTS (op0_type)))
    3520              :         {
    3521            0 :           error ("invalid vector comparison resulting type");
    3522            0 :           debug_generic_expr (type);
    3523            0 :           return true;
    3524              :         }
    3525              :     }
    3526              :   else
    3527              :     {
    3528            0 :       error ("bogus comparison result type");
    3529            0 :       debug_generic_expr (type);
    3530            0 :       return true;
    3531              :     }
    3532              : 
    3533              :   return false;
    3534              : }
    3535              : 
    3536              : /* Verify a gimple assignment statement STMT with an unary rhs.
    3537              :    Returns true if anything is wrong.  */
    3538              : 
    3539              : static bool
    3540    410916502 : verify_gimple_assign_unary (gassign *stmt)
    3541              : {
    3542    410916502 :   enum tree_code rhs_code = gimple_assign_rhs_code (stmt);
    3543    410916502 :   tree lhs = gimple_assign_lhs (stmt);
    3544    410916502 :   tree lhs_type = TREE_TYPE (lhs);
    3545    410916502 :   tree rhs1 = gimple_assign_rhs1 (stmt);
    3546    410916502 :   tree rhs1_type = TREE_TYPE (rhs1);
    3547              : 
    3548    410916502 :   if (!is_gimple_reg (lhs))
    3549              :     {
    3550            0 :       error ("non-register as LHS of unary operation");
    3551            0 :       return true;
    3552              :     }
    3553              : 
    3554    410916502 :   if (!is_gimple_val (rhs1))
    3555              :     {
    3556            0 :       error ("invalid operand in unary operation");
    3557            0 :       return true;
    3558              :     }
    3559              : 
    3560    410916502 :   const char* const code_name = get_tree_code_name (rhs_code);
    3561              : 
    3562              :   /* First handle conversions.  */
    3563    410916502 :   switch (rhs_code)
    3564              :     {
    3565    363834833 :     CASE_CONVERT:
    3566    363834833 :       {
    3567              :         /* Allow conversions between vectors with the same number of elements,
    3568              :            provided that the conversion is OK for the element types too.  */
    3569    363834833 :         if (VECTOR_TYPE_P (lhs_type)
    3570       125978 :             && VECTOR_TYPE_P (rhs1_type)
    3571    363960811 :             && known_eq (TYPE_VECTOR_SUBPARTS (lhs_type),
    3572              :                          TYPE_VECTOR_SUBPARTS (rhs1_type)))
    3573              :           {
    3574       125978 :             lhs_type = TREE_TYPE (lhs_type);
    3575       125978 :             rhs1_type = TREE_TYPE (rhs1_type);
    3576              :           }
    3577    363708855 :         else if (VECTOR_TYPE_P (lhs_type) || VECTOR_TYPE_P (rhs1_type))
    3578              :           {
    3579            0 :             error ("invalid vector types in nop conversion");
    3580            0 :             debug_generic_expr (lhs_type);
    3581            0 :             debug_generic_expr (rhs1_type);
    3582            0 :             return true;
    3583              :           }
    3584              : 
    3585              :         /* Allow conversions from pointer type to integral type only if
    3586              :            there is no sign or zero extension involved.
    3587              :            For targets were the precision of ptrofftype doesn't match that
    3588              :            of pointers we allow conversions to types where
    3589              :            POINTERS_EXTEND_UNSIGNED specifies how that works.  */
    3590    363834833 :         if ((POINTER_TYPE_P (lhs_type)
    3591     22816005 :              && INTEGRAL_TYPE_P (rhs1_type))
    3592    367924476 :             || (POINTER_TYPE_P (rhs1_type)
    3593     46802803 :                 && INTEGRAL_TYPE_P (lhs_type)
    3594     42713160 :                 && (TYPE_PRECISION (rhs1_type) >= TYPE_PRECISION (lhs_type)
    3595              : #if defined(POINTERS_EXTEND_UNSIGNED)
    3596            0 :                     || (TYPE_MODE (rhs1_type) == ptr_mode
    3597            0 :                         && (TYPE_PRECISION (lhs_type)
    3598            0 :                               == BITS_PER_WORD /* word_mode */
    3599            0 :                             || (TYPE_PRECISION (lhs_type)
    3600            0 :                                   == GET_MODE_PRECISION (Pmode))))
    3601              : #endif
    3602              :                    )))
    3603     61439522 :           return false;
    3604              : 
    3605              :         /* Allow conversion from integral to offset type and vice versa.  */
    3606    302395311 :         if ((TREE_CODE (lhs_type) == OFFSET_TYPE
    3607         7587 :              && INTEGRAL_TYPE_P (rhs1_type))
    3608    302394154 :             || (INTEGRAL_TYPE_P (lhs_type)
    3609    278507852 :                 && TREE_CODE (rhs1_type) == OFFSET_TYPE))
    3610              :           return false;
    3611              : 
    3612              :         /* Otherwise assert we are converting between types of the
    3613              :            same kind.  */
    3614    302361442 :         if (INTEGRAL_TYPE_P (lhs_type) != INTEGRAL_TYPE_P (rhs1_type))
    3615              :           {
    3616            0 :             error ("invalid types in nop conversion");
    3617            0 :             debug_generic_expr (lhs_type);
    3618            0 :             debug_generic_expr (rhs1_type);
    3619            0 :             return true;
    3620              :           }
    3621              : 
    3622              :         return false;
    3623              :       }
    3624              : 
    3625            0 :     case ADDR_SPACE_CONVERT_EXPR:
    3626            0 :       {
    3627            0 :         if (!POINTER_TYPE_P (rhs1_type) || !POINTER_TYPE_P (lhs_type)
    3628            0 :             || (TYPE_ADDR_SPACE (TREE_TYPE (rhs1_type))
    3629            0 :                 == TYPE_ADDR_SPACE (TREE_TYPE (lhs_type))))
    3630              :           {
    3631            0 :             error ("invalid types in address space conversion");
    3632            0 :             debug_generic_expr (lhs_type);
    3633            0 :             debug_generic_expr (rhs1_type);
    3634            0 :             return true;
    3635              :           }
    3636              : 
    3637              :         return false;
    3638              :       }
    3639              : 
    3640            0 :     case FIXED_CONVERT_EXPR:
    3641            0 :       {
    3642            0 :         if (!valid_fixed_convert_types_p (lhs_type, rhs1_type)
    3643    410916502 :             && !valid_fixed_convert_types_p (rhs1_type, lhs_type))
    3644              :           {
    3645            0 :             error ("invalid types in fixed-point conversion");
    3646            0 :             debug_generic_expr (lhs_type);
    3647            0 :             debug_generic_expr (rhs1_type);
    3648            0 :             return true;
    3649              :           }
    3650              : 
    3651              :         return false;
    3652              :       }
    3653              : 
    3654     16449237 :     case FLOAT_EXPR:
    3655     16449237 :       {
    3656     16356961 :         if ((!INTEGRAL_TYPE_P (rhs1_type) || !SCALAR_FLOAT_TYPE_P (lhs_type))
    3657     16449237 :             && (!VECTOR_INTEGER_TYPE_P (rhs1_type)
    3658        92276 :                 || !VECTOR_FLOAT_TYPE_P (lhs_type)))
    3659              :           {
    3660            0 :             error ("invalid types in conversion to floating-point");
    3661            0 :             debug_generic_expr (lhs_type);
    3662            0 :             debug_generic_expr (rhs1_type);
    3663            0 :             return true;
    3664              :           }
    3665              : 
    3666              :         return false;
    3667              :       }
    3668              : 
    3669      5130114 :     case FIX_TRUNC_EXPR:
    3670      5130114 :       {
    3671      5106096 :         if ((!INTEGRAL_TYPE_P (lhs_type) || !SCALAR_FLOAT_TYPE_P (rhs1_type))
    3672      5130114 :             && (!VECTOR_INTEGER_TYPE_P (lhs_type)
    3673        24018 :                 || !VECTOR_FLOAT_TYPE_P (rhs1_type)))
    3674              :           {
    3675            0 :             error ("invalid types in conversion to integer");
    3676            0 :             debug_generic_expr (lhs_type);
    3677            0 :             debug_generic_expr (rhs1_type);
    3678            0 :             return true;
    3679              :           }
    3680              : 
    3681              :         return false;
    3682              :       }
    3683              : 
    3684       851841 :     case VEC_UNPACK_HI_EXPR:
    3685       851841 :     case VEC_UNPACK_LO_EXPR:
    3686       851841 :     case VEC_UNPACK_FLOAT_HI_EXPR:
    3687       851841 :     case VEC_UNPACK_FLOAT_LO_EXPR:
    3688       851841 :     case VEC_UNPACK_FIX_TRUNC_HI_EXPR:
    3689       851841 :     case VEC_UNPACK_FIX_TRUNC_LO_EXPR:
    3690       851841 :       if (TREE_CODE (rhs1_type) != VECTOR_TYPE
    3691       851841 :           || TREE_CODE (lhs_type) != VECTOR_TYPE
    3692       851841 :           || (!INTEGRAL_TYPE_P (TREE_TYPE (lhs_type))
    3693       118504 :               && !SCALAR_FLOAT_TYPE_P (TREE_TYPE (lhs_type)))
    3694       851841 :           || (!INTEGRAL_TYPE_P (TREE_TYPE (rhs1_type))
    3695        34032 :               && !SCALAR_FLOAT_TYPE_P (TREE_TYPE (rhs1_type)))
    3696       851841 :           || ((rhs_code == VEC_UNPACK_HI_EXPR
    3697       851841 :                || rhs_code == VEC_UNPACK_LO_EXPR)
    3698      1528874 :               && (INTEGRAL_TYPE_P (TREE_TYPE (lhs_type))
    3699       764437 :                   != INTEGRAL_TYPE_P (TREE_TYPE (rhs1_type))))
    3700       851841 :           || ((rhs_code == VEC_UNPACK_FLOAT_HI_EXPR
    3701       851841 :                || rhs_code == VEC_UNPACK_FLOAT_LO_EXPR)
    3702        85938 :               && (INTEGRAL_TYPE_P (TREE_TYPE (lhs_type))
    3703        85938 :                   || SCALAR_FLOAT_TYPE_P (TREE_TYPE (rhs1_type))))
    3704       851841 :           || ((rhs_code == VEC_UNPACK_FIX_TRUNC_HI_EXPR
    3705       851841 :                || rhs_code == VEC_UNPACK_FIX_TRUNC_LO_EXPR)
    3706         1466 :               && (INTEGRAL_TYPE_P (TREE_TYPE (rhs1_type))
    3707         1466 :                   || SCALAR_FLOAT_TYPE_P (TREE_TYPE (lhs_type))))
    3708      1703682 :           || (maybe_ne (GET_MODE_SIZE (element_mode (lhs_type)),
    3709      1703682 :                         2 * GET_MODE_SIZE (element_mode (rhs1_type)))
    3710        88402 :               && (!VECTOR_BOOLEAN_TYPE_P (lhs_type)
    3711        88402 :                   || !VECTOR_BOOLEAN_TYPE_P (rhs1_type)))
    3712      1703682 :           || maybe_ne (2 * TYPE_VECTOR_SUBPARTS (lhs_type),
    3713      1703682 :                        TYPE_VECTOR_SUBPARTS (rhs1_type)))
    3714              :         {
    3715            0 :           error ("type mismatch in %qs expression", code_name);
    3716            0 :           debug_generic_expr (lhs_type);
    3717            0 :           debug_generic_expr (rhs1_type);
    3718            0 :           return true;
    3719              :         }
    3720              : 
    3721              :       return false;
    3722              : 
    3723       143783 :     case ABSU_EXPR:
    3724        32220 :       if (!ANY_INTEGRAL_TYPE_P (lhs_type)
    3725       143783 :           || !TYPE_UNSIGNED (lhs_type)
    3726       143783 :           || !ANY_INTEGRAL_TYPE_P (rhs1_type)
    3727       143783 :           || TYPE_UNSIGNED (rhs1_type)
    3728       287566 :           || element_precision (lhs_type) != element_precision (rhs1_type))
    3729              :         {
    3730            0 :           error ("invalid types for %qs", code_name);
    3731            0 :           debug_generic_expr (lhs_type);
    3732            0 :           debug_generic_expr (rhs1_type);
    3733            0 :           return true;
    3734              :         }
    3735              :       return false;
    3736              : 
    3737            0 :     case VEC_DUPLICATE_EXPR:
    3738            0 :       if (TREE_CODE (lhs_type) != VECTOR_TYPE
    3739            0 :           || !useless_type_conversion_p (TREE_TYPE (lhs_type), rhs1_type))
    3740              :         {
    3741            0 :           error ("%qs should be from a scalar to a like vector", code_name);
    3742            0 :           debug_generic_expr (lhs_type);
    3743            0 :           debug_generic_expr (rhs1_type);
    3744            0 :           return true;
    3745              :         }
    3746              :       return false;
    3747              : 
    3748        38652 :     case CONJ_EXPR:
    3749        38652 :       if (TREE_CODE (lhs_type) != COMPLEX_TYPE)
    3750              :         {
    3751            0 : diagnose_unary_lhs:
    3752            0 :           error ("invalid type for %qs", code_name);
    3753            0 :           debug_generic_expr (lhs_type);
    3754            0 :           return true;
    3755              :         }
    3756              :       break;
    3757              : 
    3758     24030941 :     case NEGATE_EXPR:
    3759     24030941 :     case ABS_EXPR:
    3760     24030941 :     case BIT_NOT_EXPR:
    3761     24030941 :       if (POINTER_TYPE_P (lhs_type) || TREE_CODE (lhs_type) == OFFSET_TYPE)
    3762            0 :         goto diagnose_unary_lhs;
    3763              :       /* FALLTHRU */
    3764     24468042 :     case PAREN_EXPR:
    3765     24468042 :       if (AGGREGATE_TYPE_P (lhs_type))
    3766            0 :         goto diagnose_unary_lhs;
    3767              :       break;
    3768              : 
    3769            0 :     default:
    3770            0 :       gcc_unreachable ();
    3771              :     }
    3772              : 
    3773              :   /* For the remaining codes assert there is no conversion involved.  */
    3774     24506694 :   if (!useless_type_conversion_p (lhs_type, rhs1_type))
    3775              :     {
    3776            0 :       error ("non-trivial conversion in unary operation");
    3777            0 :       debug_generic_expr (lhs_type);
    3778            0 :       debug_generic_expr (rhs1_type);
    3779            0 :       return true;
    3780              :     }
    3781              : 
    3782              :   return false;
    3783              : }
    3784              : 
    3785              : /* Verify a gimple assignment statement STMT with a binary rhs.
    3786              :    Returns true if anything is wrong.  */
    3787              : 
    3788              : static bool
    3789   1026083796 : verify_gimple_assign_binary (gassign *stmt)
    3790              : {
    3791   1026083796 :   enum tree_code rhs_code = gimple_assign_rhs_code (stmt);
    3792   1026083796 :   tree lhs = gimple_assign_lhs (stmt);
    3793   1026083796 :   tree lhs_type = TREE_TYPE (lhs);
    3794   1026083796 :   tree rhs1 = gimple_assign_rhs1 (stmt);
    3795   1026083796 :   tree rhs1_type = TREE_TYPE (rhs1);
    3796   1026083796 :   tree rhs2 = gimple_assign_rhs2 (stmt);
    3797   1026083796 :   tree rhs2_type = TREE_TYPE (rhs2);
    3798              : 
    3799   1026083796 :   if (!is_gimple_reg (lhs))
    3800              :     {
    3801            0 :       error ("non-register as LHS of binary operation");
    3802            0 :       return true;
    3803              :     }
    3804              : 
    3805   1026083796 :   if (!is_gimple_val (rhs1)
    3806   1026083796 :       || !is_gimple_val (rhs2))
    3807              :     {
    3808            0 :       error ("invalid operands in binary operation");
    3809            0 :       return true;
    3810              :     }
    3811              : 
    3812   1026083796 :   const char* const code_name = get_tree_code_name (rhs_code);
    3813              : 
    3814              :   /* First handle operations that involve different types.  */
    3815   1026083796 :   switch (rhs_code)
    3816              :     {
    3817      2439347 :     case COMPLEX_EXPR:
    3818      2439347 :       {
    3819      2439347 :         if (TREE_CODE (lhs_type) != COMPLEX_TYPE
    3820      2439347 :             || !(INTEGRAL_TYPE_P (rhs1_type)
    3821              :                  || SCALAR_FLOAT_TYPE_P (rhs1_type))
    3822      2439347 :             || !(INTEGRAL_TYPE_P (rhs2_type)
    3823              :                  || SCALAR_FLOAT_TYPE_P (rhs2_type)))
    3824              :           {
    3825            0 :             error ("type mismatch in %qs", code_name);
    3826            0 :             debug_generic_expr (lhs_type);
    3827            0 :             debug_generic_expr (rhs1_type);
    3828            0 :             debug_generic_expr (rhs2_type);
    3829            0 :             return true;
    3830              :           }
    3831              : 
    3832              :         return false;
    3833              :       }
    3834              : 
    3835     32589956 :     case LSHIFT_EXPR:
    3836     32589956 :     case RSHIFT_EXPR:
    3837     32589956 :     case LROTATE_EXPR:
    3838     32589956 :     case RROTATE_EXPR:
    3839     32589956 :       {
    3840              :         /* Shifts and rotates are ok on integral types, fixed point
    3841              :            types and integer vector types.  */
    3842     32589956 :         if ((!INTEGRAL_TYPE_P (rhs1_type)
    3843       657660 :              && !FIXED_POINT_TYPE_P (rhs1_type)
    3844       657660 :              && ! (VECTOR_TYPE_P (rhs1_type)
    3845       657660 :                   && INTEGRAL_TYPE_P (TREE_TYPE (rhs1_type))))
    3846     32589956 :             || (!INTEGRAL_TYPE_P (rhs2_type)
    3847              :                 /* Vector shifts of vectors are also ok.  */
    3848       162140 :                 && ! (VECTOR_TYPE_P (rhs1_type)
    3849       162140 :                      && INTEGRAL_TYPE_P (TREE_TYPE (rhs1_type))
    3850       162140 :                      && VECTOR_TYPE_P (rhs2_type)
    3851       162140 :                      && INTEGRAL_TYPE_P (TREE_TYPE (rhs2_type))))
    3852     65179912 :             || !useless_type_conversion_p (lhs_type, rhs1_type))
    3853              :           {
    3854            0 :             error ("type mismatch in %qs", code_name);
    3855            0 :             debug_generic_expr (lhs_type);
    3856            0 :             debug_generic_expr (rhs1_type);
    3857            0 :             debug_generic_expr (rhs2_type);
    3858            0 :             return true;
    3859              :           }
    3860              : 
    3861              :         return false;
    3862              :       }
    3863              : 
    3864            0 :     case WIDEN_LSHIFT_EXPR:
    3865            0 :       {
    3866            0 :         if (!INTEGRAL_TYPE_P (lhs_type)
    3867            0 :             || !INTEGRAL_TYPE_P (rhs1_type)
    3868            0 :             || TREE_CODE (rhs2) != INTEGER_CST
    3869            0 :             || (2 * TYPE_PRECISION (rhs1_type) > TYPE_PRECISION (lhs_type)))
    3870              :           {
    3871            0 :             error ("type mismatch in %qs", code_name);
    3872            0 :             debug_generic_expr (lhs_type);
    3873            0 :             debug_generic_expr (rhs1_type);
    3874            0 :             debug_generic_expr (rhs2_type);
    3875            0 :             return true;
    3876              :           }
    3877              : 
    3878              :         return false;
    3879              :       }
    3880              : 
    3881            0 :     case VEC_WIDEN_LSHIFT_HI_EXPR:
    3882            0 :     case VEC_WIDEN_LSHIFT_LO_EXPR:
    3883            0 :       {
    3884            0 :         if (TREE_CODE (rhs1_type) != VECTOR_TYPE
    3885            0 :             || TREE_CODE (lhs_type) != VECTOR_TYPE
    3886            0 :             || !INTEGRAL_TYPE_P (TREE_TYPE (rhs1_type))
    3887            0 :             || !INTEGRAL_TYPE_P (TREE_TYPE (lhs_type))
    3888            0 :             || TREE_CODE (rhs2) != INTEGER_CST
    3889            0 :             || (2 * TYPE_PRECISION (TREE_TYPE (rhs1_type))
    3890            0 :                 > TYPE_PRECISION (TREE_TYPE (lhs_type))))
    3891              :           {
    3892            0 :             error ("type mismatch in %qs", code_name);
    3893            0 :             debug_generic_expr (lhs_type);
    3894            0 :             debug_generic_expr (rhs1_type);
    3895            0 :             debug_generic_expr (rhs2_type);
    3896            0 :             return true;
    3897              :           }
    3898              : 
    3899              :         return false;
    3900              :       }
    3901              : 
    3902    459023394 :     case PLUS_EXPR:
    3903    459023394 :     case MINUS_EXPR:
    3904    459023394 :       {
    3905    459023394 :         tree lhs_etype = lhs_type;
    3906    459023394 :         tree rhs1_etype = rhs1_type;
    3907    459023394 :         tree rhs2_etype = rhs2_type;
    3908    459023394 :         if (VECTOR_TYPE_P (lhs_type))
    3909              :           {
    3910      4627112 :             if (TREE_CODE (rhs1_type) != VECTOR_TYPE
    3911      4627112 :                 || TREE_CODE (rhs2_type) != VECTOR_TYPE)
    3912              :               {
    3913            0 :                 error ("invalid non-vector operands to %qs", code_name);
    3914            0 :                 return true;
    3915              :               }
    3916      4627112 :             lhs_etype = TREE_TYPE (lhs_type);
    3917      4627112 :             rhs1_etype = TREE_TYPE (rhs1_type);
    3918      4627112 :             rhs2_etype = TREE_TYPE (rhs2_type);
    3919              :           }
    3920    459023394 :         if (POINTER_TYPE_P (lhs_etype)
    3921    459023394 :             || POINTER_TYPE_P (rhs1_etype)
    3922    459023394 :             || POINTER_TYPE_P (rhs2_etype))
    3923              :           {
    3924            0 :             error ("invalid (pointer) operands %qs", code_name);
    3925            0 :             return true;
    3926              :           }
    3927              : 
    3928              :         /* Continue with generic binary expression handling.  */
    3929              :         break;
    3930              :       }
    3931              : 
    3932    152690237 :     case POINTER_PLUS_EXPR:
    3933    152690237 :       {
    3934    152690237 :         if (!POINTER_TYPE_P (rhs1_type)
    3935    152690237 :             || !useless_type_conversion_p (lhs_type, rhs1_type)
    3936    305380474 :             || !ptrofftype_p (rhs2_type))
    3937              :           {
    3938            0 :             error ("type mismatch in %qs", code_name);
    3939            0 :             debug_generic_stmt (lhs_type);
    3940            0 :             debug_generic_stmt (rhs1_type);
    3941            0 :             debug_generic_stmt (rhs2_type);
    3942            0 :             return true;
    3943              :           }
    3944              : 
    3945              :         return false;
    3946              :       }
    3947              : 
    3948     15052847 :     case POINTER_DIFF_EXPR:
    3949     15052847 :       {
    3950     15052847 :         if (!POINTER_TYPE_P (rhs1_type)
    3951     15052847 :             || !POINTER_TYPE_P (rhs2_type)
    3952              :             /* Because we special-case pointers to void we allow difference
    3953              :                of arbitrary pointers with the same mode.  */
    3954     15052847 :             || TYPE_MODE (rhs1_type) != TYPE_MODE (rhs2_type)
    3955     15052847 :             || !INTEGRAL_TYPE_P (lhs_type)
    3956     15052847 :             || TYPE_UNSIGNED (lhs_type)
    3957     30105694 :             || TYPE_PRECISION (lhs_type) != TYPE_PRECISION (rhs1_type))
    3958              :           {
    3959            0 :             error ("type mismatch in %qs", code_name);
    3960            0 :             debug_generic_stmt (lhs_type);
    3961            0 :             debug_generic_stmt (rhs1_type);
    3962            0 :             debug_generic_stmt (rhs2_type);
    3963            0 :             return true;
    3964              :           }
    3965              : 
    3966              :         return false;
    3967              :       }
    3968              : 
    3969            0 :     case TRUTH_ANDIF_EXPR:
    3970            0 :     case TRUTH_ORIF_EXPR:
    3971            0 :     case TRUTH_AND_EXPR:
    3972            0 :     case TRUTH_OR_EXPR:
    3973            0 :     case TRUTH_XOR_EXPR:
    3974              : 
    3975            0 :       gcc_unreachable ();
    3976              : 
    3977     86180247 :     case LT_EXPR:
    3978     86180247 :     case LE_EXPR:
    3979     86180247 :     case GT_EXPR:
    3980     86180247 :     case GE_EXPR:
    3981     86180247 :     case EQ_EXPR:
    3982     86180247 :     case NE_EXPR:
    3983     86180247 :     case UNORDERED_EXPR:
    3984     86180247 :     case ORDERED_EXPR:
    3985     86180247 :     case UNLT_EXPR:
    3986     86180247 :     case UNLE_EXPR:
    3987     86180247 :     case UNGT_EXPR:
    3988     86180247 :     case UNGE_EXPR:
    3989     86180247 :     case UNEQ_EXPR:
    3990     86180247 :     case LTGT_EXPR:
    3991              :       /* Comparisons are also binary, but the result type is not
    3992              :          connected to the operand types.  */
    3993     86180247 :       return verify_gimple_comparison (lhs_type, rhs1, rhs2, rhs_code);
    3994              : 
    3995       127544 :     case WIDEN_MULT_EXPR:
    3996       127544 :       if (TREE_CODE (lhs_type) != INTEGER_TYPE)
    3997              :         return true;
    3998       127544 :       return ((2 * TYPE_PRECISION (rhs1_type) > TYPE_PRECISION (lhs_type))
    3999       127544 :               || (TYPE_PRECISION (rhs1_type) != TYPE_PRECISION (rhs2_type)));
    4000              : 
    4001            0 :     case WIDEN_SUM_EXPR:
    4002            0 :       {
    4003            0 :         if (((TREE_CODE (rhs1_type) != VECTOR_TYPE
    4004            0 :               || TREE_CODE (lhs_type) != VECTOR_TYPE)
    4005            0 :              && ((!INTEGRAL_TYPE_P (rhs1_type)
    4006            0 :                   && !SCALAR_FLOAT_TYPE_P (rhs1_type))
    4007            0 :                  || (!INTEGRAL_TYPE_P (lhs_type)
    4008            0 :                      && !SCALAR_FLOAT_TYPE_P (lhs_type))))
    4009            0 :             || !useless_type_conversion_p (lhs_type, rhs2_type)
    4010            0 :             || maybe_lt (GET_MODE_SIZE (element_mode (rhs2_type)),
    4011            0 :                          2 * GET_MODE_SIZE (element_mode (rhs1_type))))
    4012              :           {
    4013            0 :             error ("type mismatch in %qs", code_name);
    4014            0 :             debug_generic_expr (lhs_type);
    4015            0 :             debug_generic_expr (rhs1_type);
    4016            0 :             debug_generic_expr (rhs2_type);
    4017            0 :             return true;
    4018              :           }
    4019              :         return false;
    4020              :       }
    4021              : 
    4022        40038 :     case VEC_WIDEN_MULT_HI_EXPR:
    4023        40038 :     case VEC_WIDEN_MULT_LO_EXPR:
    4024        40038 :     case VEC_WIDEN_MULT_EVEN_EXPR:
    4025        40038 :     case VEC_WIDEN_MULT_ODD_EXPR:
    4026        40038 :       {
    4027        40038 :         if (TREE_CODE (rhs1_type) != VECTOR_TYPE
    4028        40038 :             || TREE_CODE (lhs_type) != VECTOR_TYPE
    4029        40038 :             || !types_compatible_p (rhs1_type, rhs2_type)
    4030       120114 :             || maybe_ne (GET_MODE_SIZE (element_mode (lhs_type)),
    4031        80076 :                          2 * GET_MODE_SIZE (element_mode (rhs1_type))))
    4032              :           {
    4033            0 :             error ("type mismatch in %qs", code_name);
    4034            0 :             debug_generic_expr (lhs_type);
    4035            0 :             debug_generic_expr (rhs1_type);
    4036            0 :             debug_generic_expr (rhs2_type);
    4037            0 :             return true;
    4038              :           }
    4039              :         return false;
    4040              :       }
    4041              : 
    4042       478550 :     case VEC_PACK_TRUNC_EXPR:
    4043              :       /* ???  We currently use VEC_PACK_TRUNC_EXPR to simply concat
    4044              :          vector boolean types.  */
    4045       478550 :       if (VECTOR_BOOLEAN_TYPE_P (lhs_type)
    4046       113532 :           && VECTOR_BOOLEAN_TYPE_P (rhs1_type)
    4047       113532 :           && types_compatible_p (rhs1_type, rhs2_type)
    4048       957100 :           && known_eq (TYPE_VECTOR_SUBPARTS (lhs_type),
    4049              :                        2 * TYPE_VECTOR_SUBPARTS (rhs1_type)))
    4050       113532 :         return false;
    4051              : 
    4052              :       /* Fallthru.  */
    4053       378818 :     case VEC_PACK_SAT_EXPR:
    4054       378818 :     case VEC_PACK_FIX_TRUNC_EXPR:
    4055       378818 :       {
    4056       378818 :         if (TREE_CODE (rhs1_type) != VECTOR_TYPE
    4057       378818 :             || TREE_CODE (lhs_type) != VECTOR_TYPE
    4058       743836 :             || !((rhs_code == VEC_PACK_FIX_TRUNC_EXPR
    4059        13800 :                   && SCALAR_FLOAT_TYPE_P (TREE_TYPE (rhs1_type))
    4060        13800 :                   && INTEGRAL_TYPE_P (TREE_TYPE (lhs_type)))
    4061       365018 :                  || (INTEGRAL_TYPE_P (TREE_TYPE (rhs1_type))
    4062       365018 :                      == INTEGRAL_TYPE_P (TREE_TYPE (lhs_type))))
    4063       378818 :             || !types_compatible_p (rhs1_type, rhs2_type)
    4064       757636 :             || maybe_ne (GET_MODE_SIZE (element_mode (rhs1_type)),
    4065       757636 :                          2 * GET_MODE_SIZE (element_mode (lhs_type)))
    4066       757636 :             || maybe_ne (2 * TYPE_VECTOR_SUBPARTS (rhs1_type),
    4067       757636 :                          TYPE_VECTOR_SUBPARTS (lhs_type)))
    4068              :           {
    4069            0 :             error ("type mismatch in %qs", code_name);
    4070            0 :             debug_generic_expr (lhs_type);
    4071            0 :             debug_generic_expr (rhs1_type);
    4072            0 :             debug_generic_expr (rhs2_type);
    4073            0 :             return true;
    4074              :           }
    4075              : 
    4076              :         return false;
    4077              :       }
    4078              : 
    4079         1205 :     case VEC_PACK_FLOAT_EXPR:
    4080         1205 :       if (TREE_CODE (rhs1_type) != VECTOR_TYPE
    4081         1205 :           || TREE_CODE (lhs_type) != VECTOR_TYPE
    4082         1205 :           || !INTEGRAL_TYPE_P (TREE_TYPE (rhs1_type))
    4083         1205 :           || !SCALAR_FLOAT_TYPE_P (TREE_TYPE (lhs_type))
    4084         1205 :           || !types_compatible_p (rhs1_type, rhs2_type)
    4085         2410 :           || maybe_ne (GET_MODE_SIZE (element_mode (rhs1_type)),
    4086         2410 :                        2 * GET_MODE_SIZE (element_mode (lhs_type)))
    4087         2410 :           || maybe_ne (2 * TYPE_VECTOR_SUBPARTS (rhs1_type),
    4088         2410 :                        TYPE_VECTOR_SUBPARTS (lhs_type)))
    4089              :         {
    4090            0 :           error ("type mismatch in %qs", code_name);
    4091            0 :           debug_generic_expr (lhs_type);
    4092            0 :           debug_generic_expr (rhs1_type);
    4093            0 :           debug_generic_expr (rhs2_type);
    4094            0 :           return true;
    4095              :         }
    4096              : 
    4097              :       return false;
    4098              : 
    4099    211183130 :     case MULT_EXPR:
    4100    211183130 :     case MULT_HIGHPART_EXPR:
    4101    211183130 :     case TRUNC_DIV_EXPR:
    4102    211183130 :     case CEIL_DIV_EXPR:
    4103    211183130 :     case FLOOR_DIV_EXPR:
    4104    211183130 :     case ROUND_DIV_EXPR:
    4105    211183130 :     case TRUNC_MOD_EXPR:
    4106    211183130 :     case CEIL_MOD_EXPR:
    4107    211183130 :     case FLOOR_MOD_EXPR:
    4108    211183130 :     case ROUND_MOD_EXPR:
    4109    211183130 :     case RDIV_EXPR:
    4110    211183130 :     case EXACT_DIV_EXPR:
    4111    211183130 :     case BIT_IOR_EXPR:
    4112    211183130 :     case BIT_XOR_EXPR:
    4113              :       /* Disallow pointer and offset types for many of the binary gimple. */
    4114    211183130 :       if (POINTER_TYPE_P (lhs_type)
    4115    211183130 :           || TREE_CODE (lhs_type) == OFFSET_TYPE)
    4116              :         {
    4117            0 :           error ("invalid types for %qs", code_name);
    4118            0 :           debug_generic_expr (lhs_type);
    4119            0 :           debug_generic_expr (rhs1_type);
    4120            0 :           debug_generic_expr (rhs2_type);
    4121            0 :           return true;
    4122              :         }
    4123              :       /* Continue with generic binary expression handling.  */
    4124              :       break;
    4125              : 
    4126              :     case MIN_EXPR:
    4127              :     case MAX_EXPR:
    4128              :       /* Continue with generic binary expression handling.  */
    4129              :       break;
    4130              : 
    4131     50197618 :     case BIT_AND_EXPR:
    4132     50197618 :       if (POINTER_TYPE_P (lhs_type)
    4133       173719 :           && TREE_CODE (rhs2) == INTEGER_CST)
    4134              :         break;
    4135              :       /* Disallow pointer and offset types for many of the binary gimple. */
    4136     50023899 :       if (POINTER_TYPE_P (lhs_type)
    4137     50023899 :           || TREE_CODE (lhs_type) == OFFSET_TYPE)
    4138              :         {
    4139            0 :           error ("invalid types for %qs", code_name);
    4140            0 :           debug_generic_expr (lhs_type);
    4141            0 :           debug_generic_expr (rhs1_type);
    4142            0 :           debug_generic_expr (rhs2_type);
    4143            0 :           return true;
    4144              :         }
    4145              :       /* Continue with generic binary expression handling.  */
    4146              :       break;
    4147              : 
    4148            0 :     case VEC_SERIES_EXPR:
    4149            0 :       if (!useless_type_conversion_p (rhs1_type, rhs2_type))
    4150              :         {
    4151            0 :           error ("type mismatch in %qs", code_name);
    4152            0 :           debug_generic_expr (rhs1_type);
    4153            0 :           debug_generic_expr (rhs2_type);
    4154            0 :           return true;
    4155              :         }
    4156            0 :       if (TREE_CODE (lhs_type) != VECTOR_TYPE
    4157            0 :           || !useless_type_conversion_p (TREE_TYPE (lhs_type), rhs1_type))
    4158              :         {
    4159            0 :           error ("vector type expected in %qs", code_name);
    4160            0 :           debug_generic_expr (lhs_type);
    4161            0 :           return true;
    4162              :         }
    4163              :       return false;
    4164              : 
    4165            0 :     default:
    4166            0 :       gcc_unreachable ();
    4167              :     }
    4168              : 
    4169    736470025 :   if (!useless_type_conversion_p (lhs_type, rhs1_type)
    4170    736470025 :       || !useless_type_conversion_p (lhs_type, rhs2_type))
    4171              :     {
    4172            0 :       error ("type mismatch in binary expression");
    4173            0 :       debug_generic_stmt (lhs_type);
    4174            0 :       debug_generic_stmt (rhs1_type);
    4175            0 :       debug_generic_stmt (rhs2_type);
    4176            0 :       return true;
    4177              :     }
    4178              : 
    4179              :   return false;
    4180              : }
    4181              : 
    4182              : /* Verify a gimple assignment statement STMT with a ternary rhs.
    4183              :    Returns true if anything is wrong.  */
    4184              : 
    4185              : static bool
    4186      9442585 : verify_gimple_assign_ternary (gassign *stmt)
    4187              : {
    4188      9442585 :   enum tree_code rhs_code = gimple_assign_rhs_code (stmt);
    4189      9442585 :   tree lhs = gimple_assign_lhs (stmt);
    4190      9442585 :   tree lhs_type = TREE_TYPE (lhs);
    4191      9442585 :   tree rhs1 = gimple_assign_rhs1 (stmt);
    4192      9442585 :   tree rhs1_type = TREE_TYPE (rhs1);
    4193      9442585 :   tree rhs2 = gimple_assign_rhs2 (stmt);
    4194      9442585 :   tree rhs2_type = TREE_TYPE (rhs2);
    4195      9442585 :   tree rhs3 = gimple_assign_rhs3 (stmt);
    4196      9442585 :   tree rhs3_type = TREE_TYPE (rhs3);
    4197              : 
    4198      9442585 :   if (!is_gimple_reg (lhs))
    4199              :     {
    4200            0 :       error ("non-register as LHS of ternary operation");
    4201            0 :       return true;
    4202              :     }
    4203              : 
    4204      9442585 :   if (!is_gimple_val (rhs1)
    4205      9442585 :       || !is_gimple_val (rhs2)
    4206     18885170 :       || !is_gimple_val (rhs3))
    4207              :     {
    4208            0 :       error ("invalid operands in ternary operation");
    4209            0 :       return true;
    4210              :     }
    4211              : 
    4212      9442585 :   const char* const code_name = get_tree_code_name (rhs_code);
    4213              : 
    4214              :   /* First handle operations that involve different types.  */
    4215      9442585 :   switch (rhs_code)
    4216              :     {
    4217            0 :     case WIDEN_MULT_PLUS_EXPR:
    4218            0 :     case WIDEN_MULT_MINUS_EXPR:
    4219            0 :       if ((!INTEGRAL_TYPE_P (rhs1_type)
    4220            0 :            && !FIXED_POINT_TYPE_P (rhs1_type))
    4221            0 :           || !useless_type_conversion_p (rhs1_type, rhs2_type)
    4222            0 :           || !useless_type_conversion_p (lhs_type, rhs3_type)
    4223            0 :           || 2 * TYPE_PRECISION (rhs1_type) > TYPE_PRECISION (lhs_type)
    4224            0 :           || TYPE_PRECISION (rhs1_type) != TYPE_PRECISION (rhs2_type))
    4225              :         {
    4226            0 :           error ("type mismatch in %qs", code_name);
    4227            0 :           debug_generic_expr (lhs_type);
    4228            0 :           debug_generic_expr (rhs1_type);
    4229            0 :           debug_generic_expr (rhs2_type);
    4230            0 :           debug_generic_expr (rhs3_type);
    4231            0 :           return true;
    4232              :         }
    4233              :       break;
    4234              : 
    4235      1500023 :     case VEC_COND_EXPR:
    4236      1500023 :       if (!VECTOR_BOOLEAN_TYPE_P (rhs1_type)
    4237      3000046 :           || maybe_ne (TYPE_VECTOR_SUBPARTS (rhs1_type),
    4238      3000046 :                        TYPE_VECTOR_SUBPARTS (lhs_type)))
    4239              :         {
    4240            0 :           error ("the first argument of a %qs must be of a "
    4241              :                  "boolean vector type of the same number of elements "
    4242              :                  "as the result", code_name);
    4243            0 :           debug_generic_expr (lhs_type);
    4244            0 :           debug_generic_expr (rhs1_type);
    4245            0 :           return true;
    4246              :         }
    4247              :       /* Fallthrough.  */
    4248      2608047 :     case COND_EXPR:
    4249      2608047 :       if (!useless_type_conversion_p (lhs_type, rhs2_type)
    4250      2608047 :           || !useless_type_conversion_p (lhs_type, rhs3_type))
    4251              :         {
    4252            0 :           error ("type mismatch in %qs", code_name);
    4253            0 :           debug_generic_expr (lhs_type);
    4254            0 :           debug_generic_expr (rhs2_type);
    4255            0 :           debug_generic_expr (rhs3_type);
    4256            0 :           return true;
    4257              :         }
    4258              :       break;
    4259              : 
    4260      6721215 :     case VEC_PERM_EXPR:
    4261              :       /* If permute is constant, then we allow for lhs and rhs
    4262              :          to have different vector types, provided:
    4263              :          (1) lhs, rhs1, rhs2 have same element type.
    4264              :          (2) rhs3 vector is constant and has integer element type.
    4265              :          (3) len(lhs) == len(rhs3) && len(rhs1) == len(rhs2).  */
    4266              : 
    4267      6721215 :       if (TREE_CODE (lhs_type) != VECTOR_TYPE
    4268      6721215 :           || TREE_CODE (rhs1_type) != VECTOR_TYPE
    4269      6721215 :           || TREE_CODE (rhs2_type) != VECTOR_TYPE
    4270      6721215 :           || TREE_CODE (rhs3_type) != VECTOR_TYPE)
    4271              :         {
    4272            0 :           error ("vector types expected in %qs", code_name);
    4273            0 :           debug_generic_expr (lhs_type);
    4274            0 :           debug_generic_expr (rhs1_type);
    4275            0 :           debug_generic_expr (rhs2_type);
    4276            0 :           debug_generic_expr (rhs3_type);
    4277            0 :           return true;
    4278              :         }
    4279              : 
    4280              :       /* If rhs3 is constant, we allow lhs, rhs1 and rhs2 to be different vector types,
    4281              :          as long as lhs, rhs1 and rhs2 have same element type.  */
    4282      6721215 :       if (TREE_CONSTANT (rhs3)
    4283      6721215 :           ? (!useless_type_conversion_p (TREE_TYPE (lhs_type), TREE_TYPE (rhs1_type))
    4284      6601443 :              || !useless_type_conversion_p (TREE_TYPE (lhs_type), TREE_TYPE (rhs2_type)))
    4285       119772 :           : (!useless_type_conversion_p (lhs_type, rhs1_type)
    4286       119772 :              || !useless_type_conversion_p (lhs_type, rhs2_type)))
    4287              :         {
    4288            0 :             error ("type mismatch in %qs", code_name);
    4289            0 :             debug_generic_expr (lhs_type);
    4290            0 :             debug_generic_expr (rhs1_type);
    4291            0 :             debug_generic_expr (rhs2_type);
    4292            0 :             debug_generic_expr (rhs3_type);
    4293            0 :             return true;
    4294              :         }
    4295              : 
    4296              :       /* If rhs3 is constant, relax the check len(rhs2) == len(rhs3).  */
    4297      6721215 :       if (maybe_ne (TYPE_VECTOR_SUBPARTS (rhs1_type),
    4298      6721215 :                     TYPE_VECTOR_SUBPARTS (rhs2_type))
    4299      6721215 :           || (!TREE_CONSTANT(rhs3)
    4300       119772 :               && maybe_ne (TYPE_VECTOR_SUBPARTS (rhs2_type),
    4301       119772 :                            TYPE_VECTOR_SUBPARTS (rhs3_type)))
    4302     13442430 :           || maybe_ne (TYPE_VECTOR_SUBPARTS (rhs3_type),
    4303      6721215 :                        TYPE_VECTOR_SUBPARTS (lhs_type)))
    4304              :         {
    4305            0 :           error ("vectors with different element number found in %qs",
    4306              :                  code_name);
    4307            0 :           debug_generic_expr (lhs_type);
    4308            0 :           debug_generic_expr (rhs1_type);
    4309            0 :           debug_generic_expr (rhs2_type);
    4310            0 :           debug_generic_expr (rhs3_type);
    4311            0 :           return true;
    4312              :         }
    4313              : 
    4314      6721215 :       if (TREE_CODE (TREE_TYPE (rhs3_type)) != INTEGER_TYPE
    4315      6721215 :           || (TREE_CODE (rhs3) != VECTOR_CST
    4316       119772 :               && (GET_MODE_BITSIZE (SCALAR_INT_TYPE_MODE
    4317              :                                     (TREE_TYPE (rhs3_type)))
    4318      6840987 :                   != GET_MODE_BITSIZE (SCALAR_TYPE_MODE
    4319              :                                        (TREE_TYPE (rhs1_type))))))
    4320              :         {
    4321            0 :           error ("invalid mask type in %qs", code_name);
    4322            0 :           debug_generic_expr (lhs_type);
    4323            0 :           debug_generic_expr (rhs1_type);
    4324            0 :           debug_generic_expr (rhs2_type);
    4325            0 :           debug_generic_expr (rhs3_type);
    4326            0 :           return true;
    4327              :         }
    4328              : 
    4329              :       return false;
    4330              : 
    4331         4623 :     case SAD_EXPR:
    4332         4623 :       if (!useless_type_conversion_p (rhs1_type, rhs2_type)
    4333         4623 :           || !useless_type_conversion_p (lhs_type, rhs3_type)
    4334         9246 :           || 2 * GET_MODE_UNIT_BITSIZE (TYPE_MODE (TREE_TYPE (rhs1_type)))
    4335         9246 :                > GET_MODE_UNIT_BITSIZE (TYPE_MODE (TREE_TYPE (lhs_type))))
    4336              :         {
    4337            0 :           error ("type mismatch in %qs", code_name);
    4338            0 :           debug_generic_expr (lhs_type);
    4339            0 :           debug_generic_expr (rhs1_type);
    4340            0 :           debug_generic_expr (rhs2_type);
    4341            0 :           debug_generic_expr (rhs3_type);
    4342            0 :           return true;
    4343              :         }
    4344              : 
    4345         4623 :       if (TREE_CODE (rhs1_type) != VECTOR_TYPE
    4346         4623 :           || TREE_CODE (rhs2_type) != VECTOR_TYPE
    4347         4623 :           || TREE_CODE (rhs3_type) != VECTOR_TYPE)
    4348              :         {
    4349            0 :           error ("vector types expected in %qs", code_name);
    4350            0 :           debug_generic_expr (lhs_type);
    4351            0 :           debug_generic_expr (rhs1_type);
    4352            0 :           debug_generic_expr (rhs2_type);
    4353            0 :           debug_generic_expr (rhs3_type);
    4354            0 :           return true;
    4355              :         }
    4356              : 
    4357              :       return false;
    4358              : 
    4359        91492 :     case BIT_INSERT_EXPR:
    4360        91492 :       if (! useless_type_conversion_p (lhs_type, rhs1_type))
    4361              :         {
    4362            0 :           error ("type mismatch in %qs", code_name);
    4363            0 :           debug_generic_expr (lhs_type);
    4364            0 :           debug_generic_expr (rhs1_type);
    4365            0 :           return true;
    4366              :         }
    4367        91492 :       if (! ((INTEGRAL_TYPE_P (rhs1_type)
    4368         5456 :               && INTEGRAL_TYPE_P (rhs2_type))
    4369              :              /* Vector element insert.  */
    4370        86036 :              || (VECTOR_TYPE_P (rhs1_type)
    4371        86036 :                  && types_compatible_p (TREE_TYPE (rhs1_type), rhs2_type))
    4372              :              /* Aligned sub-vector insert.  */
    4373         4292 :              || (VECTOR_TYPE_P (rhs1_type)
    4374         4292 :                  && VECTOR_TYPE_P (rhs2_type)
    4375         4292 :                  && types_compatible_p (TREE_TYPE (rhs1_type),
    4376         4292 :                                         TREE_TYPE (rhs2_type))
    4377         4292 :                  && multiple_p (TYPE_VECTOR_SUBPARTS (rhs1_type),
    4378         4292 :                                 TYPE_VECTOR_SUBPARTS (rhs2_type))
    4379         4292 :                  && multiple_p (wi::to_poly_offset (rhs3),
    4380         4292 :                                 wi::to_poly_offset (TYPE_SIZE (rhs2_type))))))
    4381              :         {
    4382            0 :           error ("not allowed type combination in %qs", code_name);
    4383            0 :           debug_generic_expr (rhs1_type);
    4384            0 :           debug_generic_expr (rhs2_type);
    4385            0 :           return true;
    4386              :         }
    4387        91492 :       if (! tree_fits_uhwi_p (rhs3)
    4388        91492 :           || ! types_compatible_p (bitsizetype, TREE_TYPE (rhs3))
    4389       182984 :           || ! tree_fits_uhwi_p (TYPE_SIZE (rhs2_type)))
    4390              :         {
    4391            0 :           error ("invalid position or size in %qs", code_name);
    4392            0 :           return true;
    4393              :         }
    4394        91492 :       if (INTEGRAL_TYPE_P (rhs1_type)
    4395        91492 :           && !type_has_mode_precision_p (rhs1_type))
    4396              :         {
    4397            0 :           error ("%qs into non-mode-precision operand", code_name);
    4398            0 :           return true;
    4399              :         }
    4400        91492 :       if (INTEGRAL_TYPE_P (rhs1_type))
    4401              :         {
    4402         5456 :           unsigned HOST_WIDE_INT bitpos = tree_to_uhwi (rhs3);
    4403         5456 :           if (bitpos >= TYPE_PRECISION (rhs1_type)
    4404         5456 :               || (bitpos + TYPE_PRECISION (rhs2_type)
    4405         5456 :                   > TYPE_PRECISION (rhs1_type)))
    4406              :             {
    4407            0 :               error ("insertion out of range in %qs", code_name);
    4408            0 :               return true;
    4409              :             }
    4410              :         }
    4411        86036 :       else if (VECTOR_TYPE_P (rhs1_type))
    4412              :         {
    4413        86036 :           unsigned HOST_WIDE_INT bitpos = tree_to_uhwi (rhs3);
    4414        86036 :           unsigned HOST_WIDE_INT bitsize = tree_to_uhwi (TYPE_SIZE (rhs2_type));
    4415        86036 :           if (bitpos % bitsize != 0)
    4416              :             {
    4417            0 :               error ("%qs not at element boundary", code_name);
    4418            0 :               return true;
    4419              :             }
    4420              :         }
    4421              :       return false;
    4422              : 
    4423        17208 :     case DOT_PROD_EXPR:
    4424        17208 :       {
    4425        17208 :         if (((TREE_CODE (rhs1_type) != VECTOR_TYPE
    4426        17208 :               || TREE_CODE (lhs_type) != VECTOR_TYPE)
    4427            0 :              && ((!INTEGRAL_TYPE_P (rhs1_type)
    4428            0 :                   && !SCALAR_FLOAT_TYPE_P (rhs1_type))
    4429            0 :                  || (!INTEGRAL_TYPE_P (lhs_type)
    4430            0 :                      && !SCALAR_FLOAT_TYPE_P (lhs_type))))
    4431              :             /* rhs1_type and rhs2_type may differ in sign.  */
    4432        17208 :             || !tree_nop_conversion_p (rhs1_type, rhs2_type)
    4433        17208 :             || !useless_type_conversion_p (lhs_type, rhs3_type)
    4434        51624 :             || maybe_lt (GET_MODE_SIZE (element_mode (rhs3_type)),
    4435        34416 :                          2 * GET_MODE_SIZE (element_mode (rhs1_type))))
    4436              :           {
    4437            0 :             error ("type mismatch in %qs", code_name);
    4438            0 :             debug_generic_expr (lhs_type);
    4439            0 :             debug_generic_expr (rhs1_type);
    4440            0 :             debug_generic_expr (rhs2_type);
    4441            0 :             return true;
    4442              :           }
    4443              :         return false;
    4444              :       }
    4445              : 
    4446              :     case REALIGN_LOAD_EXPR:
    4447              :       /* FIXME.  */
    4448              :       return false;
    4449              : 
    4450            0 :     default:
    4451            0 :       gcc_unreachable ();
    4452              :     }
    4453              :   return false;
    4454              : }
    4455              : 
    4456              : /* Verify a gimple assignment statement STMT with a single rhs.
    4457              :    Returns true if anything is wrong.  */
    4458              : 
    4459              : static bool
    4460   3070135207 : verify_gimple_assign_single (gassign *stmt)
    4461              : {
    4462   3070135207 :   enum tree_code rhs_code = gimple_assign_rhs_code (stmt);
    4463   3070135207 :   tree lhs = gimple_assign_lhs (stmt);
    4464   3070135207 :   tree lhs_type = TREE_TYPE (lhs);
    4465   3070135207 :   tree rhs1 = gimple_assign_rhs1 (stmt);
    4466   3070135207 :   tree rhs1_type = TREE_TYPE (rhs1);
    4467   3070135207 :   bool res = false;
    4468              : 
    4469   3070135207 :   const char* const code_name = get_tree_code_name (rhs_code);
    4470              : 
    4471   3070135207 :   if (!useless_type_conversion_p (lhs_type, rhs1_type))
    4472              :     {
    4473            0 :       error ("non-trivial conversion in %qs", code_name);
    4474            0 :       debug_generic_expr (lhs_type);
    4475            0 :       debug_generic_expr (rhs1_type);
    4476            0 :       return true;
    4477              :     }
    4478              : 
    4479              :   /* LHS can't be a constant or an address expression. */
    4480   3070135207 :   if (CONSTANT_CLASS_P (lhs)|| TREE_CODE (lhs) == ADDR_EXPR)
    4481              :     {
    4482            0 :       error ("invalid LHS (%qs) for assignment: %qs",
    4483              :              get_tree_code_name (TREE_CODE (lhs)), code_name);
    4484            0 :       return true;
    4485              :     }
    4486              : 
    4487   3070135207 :   if (gimple_clobber_p (stmt)
    4488   3070135207 :       && !(DECL_P (lhs) || TREE_CODE (lhs) == MEM_REF))
    4489              :     {
    4490            0 :       error ("%qs LHS in clobber statement",
    4491              :              get_tree_code_name (TREE_CODE (lhs)));
    4492            0 :       debug_generic_expr (lhs);
    4493            0 :       return true;
    4494              :     }
    4495              : 
    4496   3070135207 :   if (TREE_CODE (lhs) == WITH_SIZE_EXPR)
    4497              :     {
    4498            0 :       error ("%qs LHS in assignment statement",
    4499              :              get_tree_code_name (TREE_CODE (lhs)));
    4500            0 :       debug_generic_expr (lhs);
    4501            0 :       return true;
    4502              :     }
    4503              : 
    4504   3070135207 :   if (handled_component_p (lhs)
    4505   2272662039 :       || TREE_CODE (lhs) == MEM_REF
    4506   2027008984 :       || TREE_CODE (lhs) == TARGET_MEM_REF)
    4507   1052211220 :     res |= verify_types_in_gimple_reference (lhs, true);
    4508              : 
    4509              :   /* Special codes we cannot handle via their class.  */
    4510   3070135207 :   switch (rhs_code)
    4511              :     {
    4512    257323536 :     case ADDR_EXPR:
    4513    257323536 :       {
    4514    257323536 :         tree op = TREE_OPERAND (rhs1, 0);
    4515    257323536 :         if (!is_gimple_addressable (op))
    4516              :           {
    4517            0 :             error ("invalid operand in %qs", code_name);
    4518            0 :             return true;
    4519              :           }
    4520              : 
    4521              :         /* Technically there is no longer a need for matching types, but
    4522              :            gimple hygiene asks for this check.  In LTO we can end up
    4523              :            combining incompatible units and thus end up with addresses
    4524              :            of globals that change their type to a common one.  */
    4525    257323536 :         if (!in_lto_p
    4526    256814617 :             && !types_compatible_p (TREE_TYPE (op),
    4527    256814617 :                                     TREE_TYPE (TREE_TYPE (rhs1)))
    4528    257323716 :             && !one_pointer_to_useless_type_conversion_p (TREE_TYPE (rhs1),
    4529          180 :                                                           TREE_TYPE (op)))
    4530              :           {
    4531            0 :             error ("type mismatch in %qs", code_name);
    4532            0 :             debug_generic_stmt (TREE_TYPE (rhs1));
    4533            0 :             debug_generic_stmt (TREE_TYPE (op));
    4534            0 :             return true;
    4535              :           }
    4536              : 
    4537    257323536 :         return (verify_address (rhs1, true)
    4538    257323536 :                 || verify_types_in_gimple_reference (op, true));
    4539              :       }
    4540              : 
    4541              :     /* tcc_reference  */
    4542            0 :     case INDIRECT_REF:
    4543            0 :       error ("%qs in gimple IL", code_name);
    4544            0 :       return true;
    4545              : 
    4546           46 :     case WITH_SIZE_EXPR:
    4547           46 :       if (!is_gimple_val (TREE_OPERAND (rhs1, 1)))
    4548              :         {
    4549            0 :           error ("invalid %qs size argument in load", code_name);
    4550            0 :           debug_generic_stmt (lhs);
    4551            0 :           debug_generic_stmt (rhs1);
    4552            0 :           return true;
    4553              :         }
    4554           46 :       rhs1 = TREE_OPERAND (rhs1, 0);
    4555              :       /* Fallthru.  */
    4556   1050021442 :     case COMPONENT_REF:
    4557   1050021442 :     case BIT_FIELD_REF:
    4558   1050021442 :     case ARRAY_REF:
    4559   1050021442 :     case ARRAY_RANGE_REF:
    4560   1050021442 :     case VIEW_CONVERT_EXPR:
    4561   1050021442 :     case REALPART_EXPR:
    4562   1050021442 :     case IMAGPART_EXPR:
    4563   1050021442 :     case TARGET_MEM_REF:
    4564   1050021442 :     case MEM_REF:
    4565   1050021442 :       if (!is_gimple_reg (lhs)
    4566   1050021442 :           && is_gimple_reg_type (TREE_TYPE (lhs)))
    4567              :         {
    4568            0 :           error ("invalid RHS for gimple memory store: %qs", code_name);
    4569            0 :           debug_generic_stmt (lhs);
    4570            0 :           debug_generic_stmt (rhs1);
    4571            0 :           return true;
    4572              :         }
    4573   1050021442 :       return res || verify_types_in_gimple_reference (rhs1, false);
    4574              : 
    4575              :     /* tcc_constant  */
    4576              :     case SSA_NAME:
    4577              :     case INTEGER_CST:
    4578              :     case REAL_CST:
    4579              :     case FIXED_CST:
    4580              :     case COMPLEX_CST:
    4581              :     case VECTOR_CST:
    4582              :     case STRING_CST:
    4583              :       return res;
    4584              : 
    4585              :     /* tcc_declaration  */
    4586              :     case CONST_DECL:
    4587              :       return res;
    4588    322721659 :     case VAR_DECL:
    4589    322721659 :     case PARM_DECL:
    4590    322721659 :       if (!is_gimple_reg (lhs)
    4591     88348071 :           && !is_gimple_reg (rhs1)
    4592    399333992 :           && is_gimple_reg_type (TREE_TYPE (lhs)))
    4593              :         {
    4594            0 :           error ("invalid RHS for gimple memory store: %qs", code_name);
    4595            0 :           debug_generic_stmt (lhs);
    4596            0 :           debug_generic_stmt (rhs1);
    4597            0 :           return true;
    4598              :         }
    4599              :       return res;
    4600              : 
    4601    307114075 :     case CONSTRUCTOR:
    4602    307114075 :       if (VECTOR_TYPE_P (rhs1_type))
    4603              :         {
    4604      6287529 :           unsigned int i;
    4605      6287529 :           tree elt_i, elt_v, elt_t = NULL_TREE;
    4606              : 
    4607   1768458271 :           if (CONSTRUCTOR_NELTS (rhs1) == 0)
    4608              :             return res;
    4609      5668042 :           if (!is_gimple_reg (lhs))
    4610              :             {
    4611            0 :               error ("non-register as LHS with vector constructor");
    4612            0 :               return true;
    4613              :             }
    4614              :           /* For vector CONSTRUCTORs we require that either it is empty
    4615              :              CONSTRUCTOR, or it is a CONSTRUCTOR of smaller vector elements
    4616              :              (then the element count must be correct to cover the whole
    4617              :              outer vector and index must be NULL on all elements, or it is
    4618              :              a CONSTRUCTOR of scalar elements, where we as an exception allow
    4619              :              smaller number of elements (assuming zero filling) and
    4620              :              consecutive indexes as compared to NULL indexes (such
    4621              :              CONSTRUCTORs can appear in the IL from FEs).  */
    4622     26228663 :           FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (rhs1), i, elt_i, elt_v)
    4623              :             {
    4624     20560621 :               if (elt_t == NULL_TREE)
    4625              :                 {
    4626      5668042 :                   elt_t = TREE_TYPE (elt_v);
    4627      5668042 :                   if (VECTOR_TYPE_P (elt_t))
    4628              :                     {
    4629       131164 :                       tree elt_t = TREE_TYPE (elt_v);
    4630       131164 :                       if (!useless_type_conversion_p (TREE_TYPE (rhs1_type),
    4631       131164 :                                                       TREE_TYPE (elt_t)))
    4632              :                         {
    4633            0 :                           error ("incorrect type of vector %qs elements",
    4634              :                                  code_name);
    4635            0 :                           debug_generic_stmt (rhs1);
    4636            0 :                           return true;
    4637              :                         }
    4638       262328 :                       else if (maybe_ne (CONSTRUCTOR_NELTS (rhs1)
    4639       262328 :                                          * TYPE_VECTOR_SUBPARTS (elt_t),
    4640       262328 :                                          TYPE_VECTOR_SUBPARTS (rhs1_type)))
    4641              :                         {
    4642            0 :                           error ("incorrect number of vector %qs elements",
    4643              :                                  code_name);
    4644            0 :                           debug_generic_stmt (rhs1);
    4645            0 :                           return true;
    4646              :                         }
    4647              :                     }
    4648      5536878 :                   else if (!useless_type_conversion_p (TREE_TYPE (rhs1_type),
    4649              :                                                        elt_t))
    4650              :                     {
    4651            0 :                       error ("incorrect type of vector %qs elements",
    4652              :                              code_name);
    4653            0 :                       debug_generic_stmt (rhs1);
    4654            0 :                       return true;
    4655              :                     }
    4656     11073756 :                   else if (maybe_gt (CONSTRUCTOR_NELTS (rhs1),
    4657              :                                      TYPE_VECTOR_SUBPARTS (rhs1_type)))
    4658              :                     {
    4659            0 :                       error ("incorrect number of vector %qs elements",
    4660              :                              code_name);
    4661            0 :                       debug_generic_stmt (rhs1);
    4662            0 :                       return true;
    4663              :                     }
    4664              :                 }
    4665     14892579 :               else if (!useless_type_conversion_p (elt_t, TREE_TYPE (elt_v)))
    4666              :                 {
    4667            0 :                   error ("incorrect type of vector CONSTRUCTOR elements");
    4668            0 :                   debug_generic_stmt (rhs1);
    4669            0 :                   return true;
    4670              :                 }
    4671     20560621 :               if (elt_i != NULL_TREE
    4672     20560621 :                   && (VECTOR_TYPE_P (elt_t)
    4673      6711653 :                       || TREE_CODE (elt_i) != INTEGER_CST
    4674      6711653 :                       || compare_tree_int (elt_i, i) != 0))
    4675              :                 {
    4676            0 :                   error ("vector %qs with non-NULL element index",
    4677              :                          code_name);
    4678            0 :                   debug_generic_stmt (rhs1);
    4679            0 :                   return true;
    4680              :                 }
    4681     20560621 :               if (!is_gimple_val (elt_v))
    4682              :                 {
    4683            0 :                   error ("vector %qs element is not a GIMPLE value",
    4684              :                          code_name);
    4685            0 :                   debug_generic_stmt (rhs1);
    4686            0 :                   return true;
    4687              :                 }
    4688              :             }
    4689              :         }
    4690    300826546 :       else if (CONSTRUCTOR_NELTS (rhs1) != 0)
    4691              :         {
    4692            0 :           error ("non-vector %qs with elements", code_name);
    4693            0 :           debug_generic_stmt (rhs1);
    4694            0 :           return true;
    4695              :         }
    4696              :       return res;
    4697              : 
    4698              :     case OBJ_TYPE_REF:
    4699              :       /* FIXME.  */
    4700              :       return res;
    4701              : 
    4702              :     default:;
    4703              :     }
    4704              : 
    4705              :   return res;
    4706              : }
    4707              : 
    4708              : /* Verify the contents of a GIMPLE_ASSIGN STMT.  Returns true when there
    4709              :    is a problem, otherwise false.  */
    4710              : 
    4711              : static bool
    4712   4516578090 : verify_gimple_assign (gassign *stmt)
    4713              : {
    4714   4516578090 :   if (gimple_assign_nontemporal_move_p (stmt))
    4715              :     {
    4716          595 :       tree lhs = gimple_assign_lhs (stmt);
    4717          595 :       if (is_gimple_reg (lhs))
    4718              :         {
    4719            0 :           error ("nontemporal store lhs cannot be a gimple register");
    4720            0 :           debug_generic_stmt (lhs);
    4721            0 :           return true;
    4722              :         }
    4723              :     }
    4724              : 
    4725   4516578090 :   switch (gimple_assign_rhs_class (stmt))
    4726              :     {
    4727   3070135207 :     case GIMPLE_SINGLE_RHS:
    4728   3070135207 :       return verify_gimple_assign_single (stmt);
    4729              : 
    4730    410916502 :     case GIMPLE_UNARY_RHS:
    4731    410916502 :       return verify_gimple_assign_unary (stmt);
    4732              : 
    4733   1026083796 :     case GIMPLE_BINARY_RHS:
    4734   1026083796 :       return verify_gimple_assign_binary (stmt);
    4735              : 
    4736      9442585 :     case GIMPLE_TERNARY_RHS:
    4737      9442585 :       return verify_gimple_assign_ternary (stmt);
    4738              : 
    4739            0 :     default:
    4740            0 :       gcc_unreachable ();
    4741              :     }
    4742              : }
    4743              : 
    4744              : /* Verify the contents of a GIMPLE_RETURN STMT.  Returns true when there
    4745              :    is a problem, otherwise false.  */
    4746              : 
    4747              : static bool
    4748    254520423 : verify_gimple_return (greturn *stmt)
    4749              : {
    4750    254520423 :   tree op = gimple_return_retval (stmt);
    4751    254520423 :   tree restype = TREE_TYPE (TREE_TYPE (cfun->decl));
    4752    254520423 :   tree resdecl = DECL_RESULT (cfun->decl);
    4753              : 
    4754              :   /* We cannot test for present return values as we do not fix up missing
    4755              :      return values from the original source.  */
    4756    254520423 :   if (op == NULL)
    4757              :     return false;
    4758              : 
    4759    142090263 :   if (!is_gimple_val (op)
    4760    142090263 :       && TREE_CODE (op) != RESULT_DECL)
    4761              :     {
    4762            0 :       error ("invalid operand in return statement");
    4763            0 :       debug_generic_stmt (op);
    4764            0 :       return true;
    4765              :     }
    4766              : 
    4767    142090263 :   if (resdecl && DECL_BY_REFERENCE (resdecl))
    4768      3215499 :     op = TREE_TYPE (op);
    4769              : 
    4770    142090263 :   if (!useless_type_conversion_p (restype, TREE_TYPE (op)))
    4771              :     {
    4772            0 :       error ("invalid conversion in return statement");
    4773            0 :       debug_generic_stmt (restype);
    4774            0 :       debug_generic_stmt (TREE_TYPE (op));
    4775            0 :       return true;
    4776              :     }
    4777              : 
    4778              :   return false;
    4779              : }
    4780              : 
    4781              : 
    4782              : /* Verify the contents of a GIMPLE_GOTO STMT.  Returns true when there
    4783              :    is a problem, otherwise false.  */
    4784              : 
    4785              : static bool
    4786     25367103 : verify_gimple_goto (ggoto *stmt)
    4787              : {
    4788     25367103 :   tree dest = gimple_goto_dest (stmt);
    4789              : 
    4790              :   /* ???  We have two canonical forms of direct goto destinations, a
    4791              :      bare LABEL_DECL and an ADDR_EXPR of a LABEL_DECL.  */
    4792     25367103 :   if (TREE_CODE (dest) != LABEL_DECL
    4793     25367103 :       && (!is_gimple_val (dest)
    4794        60981 :           || !POINTER_TYPE_P (TREE_TYPE (dest))))
    4795              :     {
    4796            0 :       error ("goto destination is neither a label nor a pointer");
    4797            0 :       return true;
    4798              :     }
    4799              : 
    4800              :   return false;
    4801              : }
    4802              : 
    4803              : /* Verify the contents of a GIMPLE_SWITCH STMT.  Returns true when there
    4804              :    is a problem, otherwise false.  */
    4805              : 
    4806              : static bool
    4807      4567758 : verify_gimple_switch (gswitch *stmt)
    4808              : {
    4809      4567758 :   unsigned int i, n;
    4810      4567758 :   tree elt, prev_upper_bound = NULL_TREE;
    4811      4567758 :   tree index_type, elt_type = NULL_TREE;
    4812              : 
    4813      4567758 :   if (!is_gimple_val (gimple_switch_index (stmt)))
    4814              :     {
    4815            0 :       error ("invalid operand to switch statement");
    4816            0 :       debug_generic_stmt (gimple_switch_index (stmt));
    4817            0 :       return true;
    4818              :     }
    4819              : 
    4820      4567758 :   index_type = TREE_TYPE (gimple_switch_index (stmt));
    4821      4567758 :   if (! INTEGRAL_TYPE_P (index_type))
    4822              :     {
    4823            0 :       error ("non-integral type switch statement");
    4824            0 :       debug_generic_expr (index_type);
    4825            0 :       return true;
    4826              :     }
    4827              : 
    4828      4567758 :   elt = gimple_switch_label (stmt, 0);
    4829      4567758 :   if (CASE_LOW (elt) != NULL_TREE
    4830      4567758 :       || CASE_HIGH (elt) != NULL_TREE
    4831      9135516 :       || CASE_CHAIN (elt) != NULL_TREE)
    4832              :     {
    4833            0 :       error ("invalid default case label in switch statement");
    4834            0 :       debug_generic_expr (elt);
    4835            0 :       return true;
    4836              :     }
    4837              : 
    4838      4567758 :   n = gimple_switch_num_labels (stmt);
    4839     39475971 :   for (i = 1; i < n; i++)
    4840              :     {
    4841     30340455 :       elt = gimple_switch_label (stmt, i);
    4842              : 
    4843     30340455 :       if (CASE_CHAIN (elt))
    4844              :         {
    4845            0 :           error ("invalid %<CASE_CHAIN%>");
    4846            0 :           debug_generic_expr (elt);
    4847            0 :           return true;
    4848              :         }
    4849     30340455 :       if (! CASE_LOW (elt))
    4850              :         {
    4851            0 :           error ("invalid case label in switch statement");
    4852            0 :           debug_generic_expr (elt);
    4853            0 :           return true;
    4854              :         }
    4855     30340455 :       if (CASE_HIGH (elt)
    4856     30340455 :           && ! tree_int_cst_lt (CASE_LOW (elt), CASE_HIGH (elt)))
    4857              :         {
    4858            0 :           error ("invalid case range in switch statement");
    4859            0 :           debug_generic_expr (elt);
    4860            0 :           return true;
    4861              :         }
    4862              : 
    4863     30340455 :       if (! elt_type)
    4864              :         {
    4865      4564665 :           elt_type = TREE_TYPE (CASE_LOW (elt));
    4866      4564665 :           if (TYPE_PRECISION (index_type) < TYPE_PRECISION (elt_type))
    4867              :             {
    4868            0 :               error ("type precision mismatch in switch statement");
    4869            0 :               return true;
    4870              :             }
    4871              :         }
    4872     30340455 :       if (TREE_TYPE (CASE_LOW (elt)) != elt_type
    4873     30340455 :           || (CASE_HIGH (elt) && TREE_TYPE (CASE_HIGH (elt)) != elt_type))
    4874              :         {
    4875            0 :           error ("type mismatch for case label in switch statement");
    4876            0 :           debug_generic_expr (elt);
    4877            0 :           return true;
    4878              :         }
    4879              : 
    4880     30340455 :       if (prev_upper_bound)
    4881              :         {
    4882     25775790 :           if (! tree_int_cst_lt (prev_upper_bound, CASE_LOW (elt)))
    4883              :             {
    4884            0 :               error ("case labels not sorted in switch statement");
    4885            0 :               return true;
    4886              :             }
    4887              :         }
    4888              : 
    4889     30340455 :       prev_upper_bound = CASE_HIGH (elt);
    4890     30340455 :       if (! prev_upper_bound)
    4891     28362664 :         prev_upper_bound = CASE_LOW (elt);
    4892              :     }
    4893              : 
    4894              :   return false;
    4895              : }
    4896              : 
    4897              : /* Verify a gimple debug statement STMT.
    4898              :    Returns true if anything is wrong.  */
    4899              : 
    4900              : static bool
    4901            0 : verify_gimple_debug (gimple *stmt ATTRIBUTE_UNUSED)
    4902              : {
    4903              :   /* There isn't much that could be wrong in a gimple debug stmt.  A
    4904              :      gimple debug bind stmt, for example, maps a tree, that's usually
    4905              :      a VAR_DECL or a PARM_DECL, but that could also be some scalarized
    4906              :      component or member of an aggregate type, to another tree, that
    4907              :      can be an arbitrary expression.  These stmts expand into debug
    4908              :      insns, and are converted to debug notes by var-tracking.cc.  */
    4909            0 :   return false;
    4910              : }
    4911              : 
    4912              : /* Verify a gimple label statement STMT.
    4913              :    Returns true if anything is wrong.  */
    4914              : 
    4915              : static bool
    4916    219955160 : verify_gimple_label (glabel *stmt)
    4917              : {
    4918    219955160 :   tree decl = gimple_label_label (stmt);
    4919    219955160 :   int uid;
    4920    219955160 :   bool err = false;
    4921              : 
    4922    219955160 :   if (TREE_CODE (decl) != LABEL_DECL)
    4923              :     return true;
    4924    439853263 :   if (!DECL_NONLOCAL (decl) && !FORCED_LABEL (decl)
    4925    436535818 :       && DECL_CONTEXT (decl) != current_function_decl)
    4926              :     {
    4927            0 :       error ("label context is not the current function declaration");
    4928            0 :       err |= true;
    4929              :     }
    4930              : 
    4931    219955160 :   uid = LABEL_DECL_UID (decl);
    4932    219955160 :   if (cfun->cfg
    4933    219955160 :       && (uid == -1
    4934    134462496 :           || (*label_to_block_map_for_fn (cfun))[uid] != gimple_bb (stmt)))
    4935              :     {
    4936            0 :       error ("incorrect entry in %<label_to_block_map%>");
    4937            0 :       err |= true;
    4938              :     }
    4939              : 
    4940    219955160 :   uid = EH_LANDING_PAD_NR (decl);
    4941    219955160 :   if (uid)
    4942              :     {
    4943     73177679 :       eh_landing_pad lp = get_eh_landing_pad_from_number (uid);
    4944     73177679 :       if (decl != lp->post_landing_pad)
    4945              :         {
    4946            0 :           error ("incorrect setting of landing pad number");
    4947            0 :           err |= true;
    4948              :         }
    4949              :     }
    4950              : 
    4951              :   return err;
    4952              : }
    4953              : 
    4954              : /* Verify a gimple cond statement STMT.
    4955              :    Returns true if anything is wrong.  */
    4956              : 
    4957              : static bool
    4958    747288520 : verify_gimple_cond (gcond *stmt)
    4959              : {
    4960    747288520 :   if (TREE_CODE_CLASS (gimple_cond_code (stmt)) != tcc_comparison)
    4961              :     {
    4962            0 :       error ("invalid comparison code in gimple cond");
    4963            0 :       return true;
    4964              :     }
    4965    747288520 :   if (!(!gimple_cond_true_label (stmt)
    4966     28937136 :         || TREE_CODE (gimple_cond_true_label (stmt)) == LABEL_DECL)
    4967    776225656 :       || !(!gimple_cond_false_label (stmt)
    4968     28937136 :            || TREE_CODE (gimple_cond_false_label (stmt)) == LABEL_DECL))
    4969              :     {
    4970            0 :       error ("invalid labels in gimple cond");
    4971            0 :       return true;
    4972              :     }
    4973              : 
    4974    747288520 :   tree lhs = gimple_cond_lhs (stmt);
    4975              : 
    4976              :   /* GIMPLE_CONDs condition may not throw.  */
    4977    747288520 :   if (flag_exceptions
    4978    423528143 :       && cfun->can_throw_non_call_exceptions
    4979    905215428 :       && operation_could_trap_p (gimple_cond_code (stmt),
    4980    157926908 :                                  FLOAT_TYPE_P (TREE_TYPE (lhs)),
    4981              :                                  false, NULL_TREE))
    4982              :     {
    4983            0 :       error ("gimple cond condition cannot throw");
    4984            0 :       return true;
    4985              :     }
    4986              : 
    4987    747288520 :   return verify_gimple_comparison (boolean_type_node,
    4988              :                                    gimple_cond_lhs (stmt),
    4989              :                                    gimple_cond_rhs (stmt),
    4990    747288520 :                                    gimple_cond_code (stmt));
    4991              : }
    4992              : 
    4993              : /* Verify the GIMPLE statement STMT.  Returns true if there is an
    4994              :    error, otherwise false.  */
    4995              : 
    4996              : static bool
    4997  12995170354 : verify_gimple_stmt (gimple *stmt)
    4998              : {
    4999  12995170354 :   switch (gimple_code (stmt))
    5000              :     {
    5001   4516578090 :     case GIMPLE_ASSIGN:
    5002   4516578090 :       return verify_gimple_assign (as_a <gassign *> (stmt));
    5003              : 
    5004    219955160 :     case GIMPLE_LABEL:
    5005    219955160 :       return verify_gimple_label (as_a <glabel *> (stmt));
    5006              : 
    5007   1056414328 :     case GIMPLE_CALL:
    5008   1056414328 :       return verify_gimple_call (as_a <gcall *> (stmt));
    5009              : 
    5010    747288520 :     case GIMPLE_COND:
    5011    747288520 :       return verify_gimple_cond (as_a <gcond *> (stmt));
    5012              : 
    5013     25367103 :     case GIMPLE_GOTO:
    5014     25367103 :       return verify_gimple_goto (as_a <ggoto *> (stmt));
    5015              : 
    5016      4567758 :     case GIMPLE_SWITCH:
    5017      4567758 :       return verify_gimple_switch (as_a <gswitch *> (stmt));
    5018              : 
    5019    254520423 :     case GIMPLE_RETURN:
    5020    254520423 :       return verify_gimple_return (as_a <greturn *> (stmt));
    5021              : 
    5022              :     case GIMPLE_ASM:
    5023              :       return false;
    5024              : 
    5025        31120 :     case GIMPLE_TRANSACTION:
    5026        31120 :       return verify_gimple_transaction (as_a <gtransaction *> (stmt));
    5027              : 
    5028              :     /* Tuples that do not have tree operands.  */
    5029              :     case GIMPLE_NOP:
    5030              :     case GIMPLE_PREDICT:
    5031              :     case GIMPLE_RESX:
    5032              :     case GIMPLE_EH_DISPATCH:
    5033              :     case GIMPLE_EH_MUST_NOT_THROW:
    5034              :       return false;
    5035              : 
    5036              :     CASE_GIMPLE_OMP:
    5037              :       /* OpenMP directives are validated by the FE and never operated
    5038              :          on by the optimizers.  Furthermore, GIMPLE_OMP_FOR may contain
    5039              :          non-gimple expressions when the main index variable has had
    5040              :          its address taken.  This does not affect the loop itself
    5041              :          because the header of an GIMPLE_OMP_FOR is merely used to determine
    5042              :          how to setup the parallel iteration.  */
    5043              :       return false;
    5044              : 
    5045              :     case GIMPLE_ASSUME:
    5046              :       return false;
    5047              : 
    5048              :     case GIMPLE_DEBUG:
    5049              :       return verify_gimple_debug (stmt);
    5050              : 
    5051            0 :     default:
    5052            0 :       gcc_unreachable ();
    5053              :     }
    5054              : }
    5055              : 
    5056              : /* Verify the contents of a GIMPLE_PHI.  Returns true if there is a problem,
    5057              :    and false otherwise.  */
    5058              : 
    5059              : static bool
    5060    637598086 : verify_gimple_phi (gphi *phi)
    5061              : {
    5062    637598086 :   bool err = false;
    5063    637598086 :   unsigned i;
    5064    637598086 :   tree phi_result = gimple_phi_result (phi);
    5065    637598086 :   bool virtual_p;
    5066              : 
    5067    637598086 :   if (!phi_result)
    5068              :     {
    5069            0 :       error ("invalid %<PHI%> result");
    5070            0 :       return true;
    5071              :     }
    5072              : 
    5073    637598086 :   virtual_p = virtual_operand_p (phi_result);
    5074    637598086 :   if (TREE_CODE (phi_result) != SSA_NAME
    5075    637598086 :       || (virtual_p
    5076    299793686 :           && SSA_NAME_VAR (phi_result) != gimple_vop (cfun)))
    5077              :     {
    5078            0 :       error ("invalid %<PHI%> result");
    5079            0 :       err = true;
    5080              :     }
    5081              : 
    5082   2254150982 :   for (i = 0; i < gimple_phi_num_args (phi); i++)
    5083              :     {
    5084   1616552896 :       tree t = gimple_phi_arg_def (phi, i);
    5085              : 
    5086   1616552896 :       if (!t)
    5087              :         {
    5088            0 :           error ("missing %<PHI%> def");
    5089            0 :           err |= true;
    5090            0 :           continue;
    5091              :         }
    5092              :       /* Addressable variables do have SSA_NAMEs but they
    5093              :          are not considered gimple values.  */
    5094   1616552896 :       else if ((TREE_CODE (t) == SSA_NAME
    5095   1394795108 :                 && virtual_p != virtual_operand_p (t))
    5096   1616552896 :                || (virtual_p
    5097    793802942 :                    && (TREE_CODE (t) != SSA_NAME
    5098    793802942 :                        || SSA_NAME_VAR (t) != gimple_vop (cfun)))
    5099   1616552896 :                || (!virtual_p
    5100    822749954 :                    && !is_gimple_val (t)))
    5101              :         {
    5102            0 :           error ("invalid %<PHI%> argument");
    5103            0 :           debug_generic_expr (t);
    5104            0 :           err |= true;
    5105              :         }
    5106              : #ifdef ENABLE_TYPES_CHECKING
    5107   1616552896 :       if (!useless_type_conversion_p (TREE_TYPE (phi_result), TREE_TYPE (t)))
    5108              :         {
    5109            0 :           error ("incompatible types in %<PHI%> argument %u", i);
    5110            0 :           debug_generic_stmt (TREE_TYPE (phi_result));
    5111            0 :           debug_generic_stmt (TREE_TYPE (t));
    5112            0 :           err |= true;
    5113              :         }
    5114              : #endif
    5115              :     }
    5116              : 
    5117              :   return err;
    5118              : }
    5119              : 
    5120              : /* Verify the GIMPLE statements inside the sequence STMTS.  */
    5121              : 
    5122              : static bool
    5123     54149570 : verify_gimple_in_seq_2 (gimple_seq stmts)
    5124              : {
    5125     54149570 :   gimple_stmt_iterator ittr;
    5126     54149570 :   bool err = false;
    5127              : 
    5128    530877532 :   for (ittr = gsi_start (stmts); !gsi_end_p (ittr); gsi_next (&ittr))
    5129              :     {
    5130    476727962 :       gimple *stmt = gsi_stmt (ittr);
    5131              : 
    5132    476727962 :       switch (gimple_code (stmt))
    5133              :         {
    5134     14689233 :         case GIMPLE_BIND:
    5135     14689233 :           err |= verify_gimple_in_seq_2 (
    5136     14689233 :                    gimple_bind_body (as_a <gbind *> (stmt)));
    5137     14689233 :           break;
    5138              : 
    5139     10947519 :         case GIMPLE_TRY:
    5140     10947519 :           err |= verify_gimple_in_seq_2 (gimple_try_eval (stmt));
    5141     10947519 :           err |= verify_gimple_in_seq_2 (gimple_try_cleanup (stmt));
    5142     10947519 :           break;
    5143              : 
    5144        22787 :         case GIMPLE_EH_FILTER:
    5145        22787 :           err |= verify_gimple_in_seq_2 (gimple_eh_filter_failure (stmt));
    5146        22787 :           break;
    5147              : 
    5148         1648 :         case GIMPLE_EH_ELSE:
    5149         1648 :           {
    5150         1648 :             geh_else *eh_else = as_a <geh_else *> (stmt);
    5151         1648 :             err |= verify_gimple_in_seq_2 (gimple_eh_else_n_body (eh_else));
    5152         1648 :             err |= verify_gimple_in_seq_2 (gimple_eh_else_e_body (eh_else));
    5153              :           }
    5154         1648 :           break;
    5155              : 
    5156       177208 :         case GIMPLE_CATCH:
    5157       177208 :           err |= verify_gimple_in_seq_2 (gimple_catch_handler (
    5158       177208 :                                            as_a <gcatch *> (stmt)));
    5159       177208 :           break;
    5160              : 
    5161          384 :         case GIMPLE_ASSUME:
    5162          384 :           err |= verify_gimple_in_seq_2 (gimple_assume_body (stmt));
    5163          384 :           break;
    5164              : 
    5165         3076 :         case GIMPLE_TRANSACTION:
    5166         3076 :           err |= verify_gimple_transaction (as_a <gtransaction *> (stmt));
    5167         3076 :           break;
    5168              : 
    5169    450886107 :         default:
    5170    450886107 :           {
    5171    450886107 :             bool err2 = verify_gimple_stmt (stmt);
    5172    450886107 :             if (err2)
    5173            1 :               debug_gimple_stmt (stmt);
    5174    450886107 :             err |= err2;
    5175              :           }
    5176              :         }
    5177              :     }
    5178              : 
    5179     54149570 :   return err;
    5180              : }
    5181              : 
    5182              : /* Verify the contents of a GIMPLE_TRANSACTION.  Returns true if there
    5183              :    is a problem, otherwise false.  */
    5184              : 
    5185              : static bool
    5186        34196 : verify_gimple_transaction (gtransaction *stmt)
    5187              : {
    5188        34196 :   tree lab;
    5189              : 
    5190        34196 :   lab = gimple_transaction_label_norm (stmt);
    5191        34196 :   if (lab != NULL && TREE_CODE (lab) != LABEL_DECL)
    5192              :     return true;
    5193        34196 :   lab = gimple_transaction_label_uninst (stmt);
    5194        34196 :   if (lab != NULL && TREE_CODE (lab) != LABEL_DECL)
    5195              :     return true;
    5196        34196 :   lab = gimple_transaction_label_over (stmt);
    5197        34196 :   if (lab != NULL && TREE_CODE (lab) != LABEL_DECL)
    5198              :     return true;
    5199              : 
    5200        34196 :   return verify_gimple_in_seq_2 (gimple_transaction_body (stmt));
    5201              : }
    5202              : 
    5203              : 
    5204              : /* Verify the GIMPLE statements inside the statement list STMTS.  */
    5205              : 
    5206              : DEBUG_FUNCTION bool
    5207     17327428 : verify_gimple_in_seq (gimple_seq stmts, bool ice)
    5208              : {
    5209     17327428 :   timevar_push (TV_TREE_STMT_VERIFY);
    5210     17327428 :   bool res = verify_gimple_in_seq_2 (stmts);
    5211     17327428 :   if (res && ice)
    5212            0 :     internal_error ("%<verify_gimple%> failed");
    5213     17327428 :   timevar_pop (TV_TREE_STMT_VERIFY);
    5214     17327428 :   return res;
    5215              : }
    5216              : 
    5217              : /* Return true when the T can be shared.  */
    5218              : 
    5219              : static bool
    5220  31851165010 : tree_node_can_be_shared (tree t)
    5221              : {
    5222  31851165010 :   if (IS_TYPE_OR_DECL_P (t)
    5223              :       || TREE_CODE (t) == SSA_NAME
    5224              :       || TREE_CODE (t) == IDENTIFIER_NODE
    5225              :       || TREE_CODE (t) == CASE_LABEL_EXPR
    5226              :       || TREE_CODE (t) == OMP_NEXT_VARIANT
    5227  43504336992 :       || is_gimple_min_invariant (t))
    5228  27261746940 :     return true;
    5229              : 
    5230   4589418070 :   if (t == error_mark_node)
    5231              :     return true;
    5232              : 
    5233              :   return false;
    5234              : }
    5235              : 
    5236              : /* Called via walk_tree.  Verify tree sharing.  */
    5237              : 
    5238              : static tree
    5239  31851165010 : verify_node_sharing_1 (tree *tp, int *walk_subtrees, void *data)
    5240              : {
    5241  31851165010 :   hash_set<void *> *visited = (hash_set<void *> *) data;
    5242              : 
    5243  31851165010 :   if (tree_node_can_be_shared (*tp))
    5244              :     {
    5245  27261746940 :       *walk_subtrees = false;
    5246  27261746940 :       return NULL;
    5247              :     }
    5248              : 
    5249   4589418070 :   if (visited->add (*tp))
    5250            0 :     return *tp;
    5251              : 
    5252              :   return NULL;
    5253              : }
    5254              : 
    5255              : /* Called via walk_gimple_stmt.  Verify tree sharing.  */
    5256              : 
    5257              : static tree
    5258  30234612114 : verify_node_sharing (tree *tp, int *walk_subtrees, void *data)
    5259              : {
    5260  30234612114 :   struct walk_stmt_info *wi = (struct walk_stmt_info *) data;
    5261  30234612114 :   return verify_node_sharing_1 (tp, walk_subtrees, wi->info);
    5262              : }
    5263              : 
    5264              : static bool eh_error_found;
    5265              : bool
    5266    187726630 : verify_eh_throw_stmt_node (gimple *const &stmt, const int &,
    5267              :                            hash_set<gimple *> *visited)
    5268              : {
    5269    187726630 :   if (!visited->contains (stmt))
    5270              :     {
    5271            0 :       error ("dead statement in EH table");
    5272            0 :       debug_gimple_stmt (stmt);
    5273            0 :       eh_error_found = true;
    5274              :     }
    5275    187726630 :   return true;
    5276              : }
    5277              : 
    5278              : /* Verify if the location LOCs block is in BLOCKS.  */
    5279              : 
    5280              : static bool
    5281  22186864129 : verify_location (hash_set<tree> *blocks, location_t loc)
    5282              : {
    5283  35959603810 :   tree block = LOCATION_BLOCK (loc);
    5284  35959603810 :   if (block != NULL_TREE
    5285  35959603810 :       && !blocks->contains (block))
    5286              :     {
    5287            0 :       error ("location references block not in block tree");
    5288            0 :       return true;
    5289              :     }
    5290  35959603810 :   if (block != NULL_TREE)
    5291  13772739681 :     return verify_location (blocks, BLOCK_SOURCE_LOCATION (block));
    5292              :   return false;
    5293              : }
    5294              : 
    5295              : /* Called via walk_tree.  Verify that expressions have no blocks.  */
    5296              : 
    5297              : static tree
    5298   1551515703 : verify_expr_no_block (tree *tp, int *walk_subtrees, void *)
    5299              : {
    5300   1551515703 :   if (!EXPR_P (*tp))
    5301              :     {
    5302    931988781 :       *walk_subtrees = false;
    5303    931988781 :       return NULL;
    5304              :     }
    5305              : 
    5306    619526922 :   location_t loc = EXPR_LOCATION (*tp);
    5307    619526922 :   if (LOCATION_BLOCK (loc) != NULL)
    5308            0 :     return *tp;
    5309              : 
    5310              :   return NULL;
    5311              : }
    5312              : 
    5313              : /* Called via walk_tree.  Verify locations of expressions.  */
    5314              : 
    5315              : static tree
    5316  35499449862 : verify_expr_location_1 (tree *tp, int *walk_subtrees, void *data)
    5317              : {
    5318  35499449862 :   hash_set<tree> *blocks = (hash_set<tree> *) data;
    5319  35499449862 :   tree t = *tp;
    5320              : 
    5321              :   /* ???  This doesn't really belong here but there's no good place to
    5322              :      stick this remainder of old verify_expr.  */
    5323              :   /* ???  This barfs on debug stmts which contain binds to vars with
    5324              :      different function context.  */
    5325              : #if 0
    5326              :   if (VAR_P (t)
    5327              :       || TREE_CODE (t) == PARM_DECL
    5328              :       || TREE_CODE (t) == RESULT_DECL)
    5329              :     {
    5330              :       tree context = decl_function_context (t);
    5331              :       if (context != cfun->decl
    5332              :           && !SCOPE_FILE_SCOPE_P (context)
    5333              :           && !TREE_STATIC (t)
    5334              :           && !DECL_EXTERNAL (t))
    5335              :         {
    5336              :           error ("local declaration from a different function");
    5337              :           return t;
    5338              :         }
    5339              :     }
    5340              : #endif
    5341              : 
    5342  35499449862 :   if (VAR_P (t) && DECL_HAS_DEBUG_EXPR_P (t))
    5343              :     {
    5344    408932371 :       tree x = DECL_DEBUG_EXPR (t);
    5345    408932371 :       tree addr = walk_tree (&x, verify_expr_no_block, NULL, NULL);
    5346    408932371 :       if (addr)
    5347            0 :         return addr;
    5348              :     }
    5349  35499449862 :   if ((VAR_P (t)
    5350              :        || TREE_CODE (t) == PARM_DECL
    5351              :        || TREE_CODE (t) == RESULT_DECL)
    5352   7781694498 :       && DECL_HAS_VALUE_EXPR_P (t))
    5353              :     {
    5354         1906 :       tree x = DECL_VALUE_EXPR (t);
    5355         1906 :       tree addr = walk_tree (&x, verify_expr_no_block, NULL, NULL);
    5356         1906 :       if (addr)
    5357            0 :         return addr;
    5358              :     }
    5359              : 
    5360  35499449862 :   if (!EXPR_P (t))
    5361              :     {
    5362  27990163526 :       *walk_subtrees = false;
    5363  27990163526 :       return NULL;
    5364              :     }
    5365              : 
    5366   7509286336 :   location_t loc = EXPR_LOCATION (t);
    5367   7509286336 :   if (verify_location (blocks, loc))
    5368              :     return t;
    5369              : 
    5370              :   return NULL;
    5371              : }
    5372              : 
    5373              : /* Called via walk_gimple_op.  Verify locations of expressions.  */
    5374              : 
    5375              : static tree
    5376  33856002225 : verify_expr_location (tree *tp, int *walk_subtrees, void *data)
    5377              : {
    5378  33856002225 :   struct walk_stmt_info *wi = (struct walk_stmt_info *) data;
    5379  33856002225 :   return verify_expr_location_1 (tp, walk_subtrees, wi->info);
    5380              : }
    5381              : 
    5382              : /* Insert all subblocks of BLOCK into BLOCKS and recurse.  */
    5383              : 
    5384              : static void
    5385   2315286082 : collect_subblocks (hash_set<tree> *blocks, tree block)
    5386              : {
    5387   2315286082 :   tree t;
    5388   4387046448 :   for (t = BLOCK_SUBBLOCKS (block); t; t = BLOCK_CHAIN (t))
    5389              :     {
    5390   2071760366 :       blocks->add (t);
    5391   2071760366 :       collect_subblocks (blocks, t);
    5392              :     }
    5393   2315286082 : }
    5394              : 
    5395              : /* Disable warnings about missing quoting in GCC diagnostics for
    5396              :    the verification errors.  Their format strings don't follow
    5397              :    GCC diagnostic conventions and trigger an ICE in the end.  */
    5398              : #if __GNUC__ >= 10
    5399              : #  pragma GCC diagnostic push
    5400              : #  pragma GCC diagnostic ignored "-Wformat-diag"
    5401              : #endif
    5402              : 
    5403              : /* Verify the GIMPLE statements in the CFG of FN.  */
    5404              : 
    5405              : DEBUG_FUNCTION bool
    5406    243525716 : verify_gimple_in_cfg (struct function *fn, bool verify_nothrow, bool ice)
    5407              : {
    5408    243525716 :   basic_block bb;
    5409    243525716 :   bool err = false;
    5410              : 
    5411    243525716 :   timevar_push (TV_TREE_STMT_VERIFY);
    5412    243525716 :   hash_set<void *> visited;
    5413    243525716 :   hash_set<gimple *> visited_throwing_stmts;
    5414              : 
    5415              :   /* Collect all BLOCKs referenced by the BLOCK tree of FN.  */
    5416    243525716 :   hash_set<tree> blocks;
    5417    243525716 :   if (DECL_INITIAL (fn->decl))
    5418              :     {
    5419    243525716 :       blocks.add (DECL_INITIAL (fn->decl));
    5420    243525716 :       collect_subblocks (&blocks, DECL_INITIAL (fn->decl));
    5421              :     }
    5422              : 
    5423   2173551907 :   FOR_EACH_BB_FN (bb, fn)
    5424              :     {
    5425   1930026191 :       gimple_stmt_iterator gsi;
    5426   1930026191 :       edge_iterator ei;
    5427   1930026191 :       edge e;
    5428              : 
    5429   1930026191 :       for (gphi_iterator gpi = gsi_start_phis (bb);
    5430   2567624277 :            !gsi_end_p (gpi);
    5431    637598086 :            gsi_next (&gpi))
    5432              :         {
    5433    637598086 :           gphi *phi = gpi.phi ();
    5434    637598086 :           bool err2 = false;
    5435    637598086 :           unsigned i;
    5436              : 
    5437    637598086 :           if (gimple_bb (phi) != bb)
    5438              :             {
    5439            0 :               error ("gimple_bb (phi) is set to a wrong basic block");
    5440            0 :               err2 = true;
    5441              :             }
    5442              : 
    5443    637598086 :           err2 |= verify_gimple_phi (phi);
    5444              : 
    5445              :           /* Only PHI arguments have locations.  */
    5446    637598086 :           if (gimple_location (phi) != UNKNOWN_LOCATION)
    5447              :             {
    5448            0 :               error ("PHI node with location");
    5449            0 :               err2 = true;
    5450              :             }
    5451              : 
    5452   2254150982 :           for (i = 0; i < gimple_phi_num_args (phi); i++)
    5453              :             {
    5454   1616552896 :               tree arg = gimple_phi_arg_def (phi, i);
    5455   1616552896 :               tree addr = walk_tree (&arg, verify_node_sharing_1,
    5456              :                                      &visited, NULL);
    5457   1616552896 :               if (addr)
    5458              :                 {
    5459            0 :                   error ("incorrect sharing of tree nodes");
    5460            0 :                   debug_generic_expr (addr);
    5461            0 :                   err2 |= true;
    5462              :                 }
    5463   1616552896 :               location_t loc = gimple_phi_arg_location (phi, i);
    5464   1616552896 :               if (virtual_operand_p (gimple_phi_result (phi))
    5465   1616552896 :                   && loc != UNKNOWN_LOCATION)
    5466              :                 {
    5467            0 :                   error ("virtual PHI with argument locations");
    5468            0 :                   err2 = true;
    5469              :                 }
    5470   1616552896 :               addr = walk_tree (&arg, verify_expr_location_1, &blocks, NULL);
    5471   1616552896 :               if (addr)
    5472              :                 {
    5473            0 :                   debug_generic_expr (addr);
    5474            0 :                   err2 = true;
    5475              :                 }
    5476   1616552896 :               err2 |= verify_location (&blocks, loc);
    5477              :             }
    5478              : 
    5479    637598086 :           if (err2)
    5480            0 :             debug_gimple_stmt (phi);
    5481    637598086 :           err |= err2;
    5482              :         }
    5483              : 
    5484  16404336629 :       for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
    5485              :         {
    5486  12544284247 :           gimple *stmt = gsi_stmt (gsi);
    5487  12544284247 :           bool err2 = false;
    5488  12544284247 :           struct walk_stmt_info wi;
    5489  12544284247 :           tree addr;
    5490  12544284247 :           int lp_nr;
    5491              : 
    5492  12544284247 :           if (gimple_bb (stmt) != bb)
    5493              :             {
    5494            0 :               error ("gimple_bb (stmt) is set to a wrong basic block");
    5495            0 :               err2 = true;
    5496              :             }
    5497              : 
    5498  12544284247 :           err2 |= verify_gimple_stmt (stmt);
    5499  12544284247 :           err2 |= verify_location (&blocks, gimple_location (stmt));
    5500              : 
    5501  12544284247 :           memset (&wi, 0, sizeof (wi));
    5502  12544284247 :           wi.info = (void *) &visited;
    5503  12544284247 :           addr = walk_gimple_op (stmt, verify_node_sharing, &wi);
    5504  12544284247 :           if (addr)
    5505              :             {
    5506            0 :               error ("incorrect sharing of tree nodes");
    5507            0 :               debug_generic_expr (addr);
    5508            0 :               err2 |= true;
    5509              :             }
    5510              : 
    5511  12544284247 :           memset (&wi, 0, sizeof (wi));
    5512  12544284247 :           wi.info = (void *) &blocks;
    5513  12544284247 :           addr = walk_gimple_op (stmt, verify_expr_location, &wi);
    5514  12544284247 :           if (addr)
    5515              :             {
    5516            0 :               debug_generic_expr (addr);
    5517            0 :               err2 |= true;
    5518              :             }
    5519              : 
    5520              :           /* If the statement is marked as part of an EH region, then it is
    5521              :              expected that the statement could throw.  Verify that when we
    5522              :              have optimizations that simplify statements such that we prove
    5523              :              that they cannot throw, that we update other data structures
    5524              :              to match.  */
    5525  12544284247 :           lp_nr = lookup_stmt_eh_lp (stmt);
    5526  12544284247 :           if (lp_nr != 0)
    5527    187726630 :             visited_throwing_stmts.add (stmt);
    5528    187726630 :           if (lp_nr > 0)
    5529              :             {
    5530    180525935 :               if (!stmt_could_throw_p (cfun, stmt))
    5531              :                 {
    5532           24 :                   if (verify_nothrow)
    5533              :                     {
    5534            0 :                       error ("statement marked for throw, but doesn%'t");
    5535            0 :                       err2 |= true;
    5536              :                     }
    5537              :                 }
    5538    180525911 :               else if (!gsi_one_before_end_p (gsi))
    5539              :                 {
    5540            0 :                   error ("statement marked for throw in middle of block");
    5541            0 :                   err2 |= true;
    5542              :                 }
    5543              :             }
    5544              : 
    5545  12544284247 :           if (err2)
    5546            0 :             debug_gimple_stmt (stmt);
    5547  12544284247 :           err |= err2;
    5548              :         }
    5549              : 
    5550   4597046659 :       FOR_EACH_EDGE (e, ei, bb->succs)
    5551   2667020468 :         if (e->goto_locus != UNKNOWN_LOCATION)
    5552    516740650 :           err |= verify_location (&blocks, e->goto_locus);
    5553              :     }
    5554              : 
    5555    243525716 :   hash_map<gimple *, int> *eh_table = get_eh_throw_stmt_table (cfun);
    5556    243525716 :   eh_error_found = false;
    5557    243525716 :   if (eh_table)
    5558     35858211 :     eh_table->traverse<hash_set<gimple *> *, verify_eh_throw_stmt_node>
    5559    223584841 :       (&visited_throwing_stmts);
    5560              : 
    5561    243525716 :   if (ice && (err || eh_error_found))
    5562            0 :     internal_error ("verify_gimple failed");
    5563              : 
    5564    243525716 :   verify_histograms ();
    5565    243525716 :   timevar_pop (TV_TREE_STMT_VERIFY);
    5566              : 
    5567    243525716 :   return (err || eh_error_found);
    5568    243525716 : }
    5569              : 
    5570              : 
    5571              : /* Verifies that the flow information is OK.  */
    5572              : 
    5573              : static bool
    5574    227676336 : gimple_verify_flow_info (void)
    5575              : {
    5576    227676336 :   bool err = false;
    5577    227676336 :   basic_block bb;
    5578    227676336 :   gimple_stmt_iterator gsi;
    5579    227676336 :   gimple *stmt;
    5580    227676336 :   edge e;
    5581    227676336 :   edge_iterator ei;
    5582              : 
    5583    227676336 :   if (ENTRY_BLOCK_PTR_FOR_FN (cfun)->il.gimple.seq
    5584    227676336 :       || ENTRY_BLOCK_PTR_FOR_FN (cfun)->il.gimple.phi_nodes)
    5585              :     {
    5586            0 :       error ("ENTRY_BLOCK has IL associated with it");
    5587            0 :       err = true;
    5588              :     }
    5589              : 
    5590    227676336 :   if (EXIT_BLOCK_PTR_FOR_FN (cfun)->il.gimple.seq
    5591    227676336 :       || EXIT_BLOCK_PTR_FOR_FN (cfun)->il.gimple.phi_nodes)
    5592              :     {
    5593            0 :       error ("EXIT_BLOCK has IL associated with it");
    5594            0 :       err = true;
    5595              :     }
    5596              : 
    5597    451396880 :   FOR_EACH_EDGE (e, ei, EXIT_BLOCK_PTR_FOR_FN (cfun)->preds)
    5598    223720544 :     if (e->flags & EDGE_FALLTHRU)
    5599              :       {
    5600            0 :         error ("fallthru to exit from bb %d", e->src->index);
    5601            0 :         err = true;
    5602              :       }
    5603    227676336 :   if (cfun->cfg->full_profile
    5604    227676336 :       && !ENTRY_BLOCK_PTR_FOR_FN (cfun)->count.initialized_p ())
    5605              :     {
    5606            0 :       error ("entry block count not initialized");
    5607            0 :       err = true;
    5608              :     }
    5609    227676336 :   if (cfun->cfg->full_profile
    5610    227676336 :       && !EXIT_BLOCK_PTR_FOR_FN (cfun)->count.initialized_p ())
    5611              :     {
    5612            0 :       error ("exit block count not initialized");
    5613            0 :       err = true;
    5614              :     }
    5615    227676336 :   if (cfun->cfg->full_profile
    5616    344263107 :       && !single_succ_edge
    5617    116586771 :               (ENTRY_BLOCK_PTR_FOR_FN (cfun))->probability.initialized_p ())
    5618              :     {
    5619            0 :       error ("probability of edge from entry block not initialized");
    5620            0 :       err = true;
    5621              :     }
    5622    227676336 :   if (!EXIT_BLOCK_PTR_FOR_FN (cfun)
    5623    227676336 :         ->count.compatible_p (ENTRY_BLOCK_PTR_FOR_FN (cfun)->count))
    5624              :     {
    5625            0 :       error ("exit block count is not compatible with entry block count");
    5626            0 :       err = true;
    5627              :     }
    5628              : 
    5629              : 
    5630   2173756133 :   FOR_EACH_BB_FN (bb, cfun)
    5631              :     {
    5632   1946079797 :       bool found_ctrl_stmt = false;
    5633              : 
    5634   1946079797 :       stmt = NULL;
    5635              : 
    5636   1946079797 :       if (cfun->cfg->full_profile)
    5637              :         {
    5638   1272718606 :           if (!bb->count.initialized_p ())
    5639              :             {
    5640            0 :               error ("count of bb %d not initialized", bb->index);
    5641            0 :               err = true;
    5642              :             }
    5643   3066402048 :           FOR_EACH_EDGE (e, ei, bb->succs)
    5644   1793683442 :             if (!e->probability.initialized_p ())
    5645              :               {
    5646            0 :                 error ("probability of edge %d->%d not initialized",
    5647            0 :                        bb->index, e->dest->index);
    5648            0 :                 err = true;
    5649              :               }
    5650              :         }
    5651   1946079797 :       if (!bb->count.compatible_p (ENTRY_BLOCK_PTR_FOR_FN (cfun)->count))
    5652              :         {
    5653            0 :           error ("count of bb %d is not compatible with entry block count",
    5654              :                  bb->index);
    5655            0 :           err = true;
    5656              :         }
    5657              : 
    5658              :       /* Skip labels on the start of basic block.  */
    5659   4030845265 :       for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
    5660              :         {
    5661   1935983858 :           tree label;
    5662   1935983858 :           gimple *prev_stmt = stmt;
    5663              : 
    5664   1935983858 :           stmt = gsi_stmt (gsi);
    5665              : 
    5666   1935983858 :           if (gimple_code (stmt) != GIMPLE_LABEL)
    5667              :             break;
    5668              : 
    5669    138685671 :           label = gimple_label_label (as_a <glabel *> (stmt));
    5670    138685671 :           if (prev_stmt && DECL_NONLOCAL (label))
    5671              :             {
    5672            0 :               error ("nonlocal label %qD is not first in a sequence "
    5673              :                      "of labels in bb %d", label, bb->index);
    5674            0 :               err = true;
    5675              :             }
    5676              : 
    5677    141425533 :           if (prev_stmt && EH_LANDING_PAD_NR (label) != 0)
    5678              :             {
    5679            0 :               error ("EH landing pad label %qD is not first in a sequence "
    5680              :                      "of labels in bb %d", label, bb->index);
    5681            0 :               err = true;
    5682              :             }
    5683              : 
    5684    138685671 :           if (label_to_block (cfun, label) != bb)
    5685              :             {
    5686            0 :               error ("label %qD to block does not match in bb %d",
    5687              :                      label, bb->index);
    5688            0 :               err = true;
    5689              :             }
    5690              : 
    5691    138685671 :           if (decl_function_context (label) != current_function_decl)
    5692              :             {
    5693            0 :               error ("label %qD has incorrect context in bb %d",
    5694              :                      label, bb->index);
    5695            0 :               err = true;
    5696              :             }
    5697              :         }
    5698              : 
    5699              :       /* Verify that body of basic block BB is free of control flow.  */
    5700              :       bool seen_nondebug_stmt = false;
    5701  15392054034 :       for (; !gsi_end_p (gsi); gsi_next (&gsi))
    5702              :         {
    5703  13445974237 :           gimple *stmt = gsi_stmt (gsi);
    5704              : 
    5705              :           /* Do NOT disregard debug stmts after found_ctrl_stmt.  */
    5706  13445974237 :           if (found_ctrl_stmt)
    5707              :             {
    5708            0 :               error ("control flow in the middle of basic block %d",
    5709              :                      bb->index);
    5710            0 :               err = true;
    5711              :             }
    5712              : 
    5713  13445974237 :           if (stmt_ends_bb_p (stmt))
    5714   1316280805 :             found_ctrl_stmt = true;
    5715              : 
    5716  13445974237 :           if (glabel *label_stmt = dyn_cast <glabel *> (stmt))
    5717              :             {
    5718            0 :               error ("label %qD in the middle of basic block %d",
    5719              :                      gimple_label_label (label_stmt), bb->index);
    5720            0 :               err = true;
    5721              :             }
    5722              : 
    5723              :           /* Check that no statements appear between a returns_twice call
    5724              :              and its associated abnormal edge.  */
    5725  13445974237 :           if (gimple_code (stmt) == GIMPLE_CALL
    5726  13445974237 :               && gimple_call_flags (stmt) & ECF_RETURNS_TWICE)
    5727              :             {
    5728       147179 :               bool misplaced = false;
    5729              :               /* TM is an exception: it points abnormal edges just after the
    5730              :                  call that starts a transaction, i.e. it must end the BB.  */
    5731       147179 :               if (gimple_call_builtin_p (stmt, BUILT_IN_TM_START))
    5732              :                 {
    5733         3779 :                   if (single_succ_p (bb)
    5734         2989 :                       && bb_has_abnormal_pred (single_succ (bb))
    5735         6121 :                       && !gsi_one_nondebug_before_end_p (gsi))
    5736              :                     {
    5737            0 :                       error ("returns_twice call is not last in basic block "
    5738              :                              "%d", bb->index);
    5739            0 :                       misplaced = true;
    5740              :                     }
    5741              :                 }
    5742              :               else
    5743              :                 {
    5744       143400 :                   if (seen_nondebug_stmt && bb_has_abnormal_pred (bb))
    5745              :                     {
    5746            0 :                       error ("returns_twice call is not first in basic block "
    5747              :                              "%d", bb->index);
    5748            0 :                       misplaced = true;
    5749              :                     }
    5750              :                 }
    5751            0 :               if (misplaced)
    5752              :                 {
    5753            0 :                   print_gimple_stmt (stderr, stmt, 0, TDF_SLIM);
    5754            0 :                   err = true;
    5755              :                 }
    5756              :             }
    5757  13445974237 :           if (!is_gimple_debug (stmt))
    5758   6409973197 :             seen_nondebug_stmt = true;
    5759              :         }
    5760              : 
    5761   1946079797 :       gsi = gsi_last_nondebug_bb (bb);
    5762   1946079797 :       if (gsi_end_p (gsi))
    5763    121591391 :         continue;
    5764              : 
    5765   1824488406 :       stmt = gsi_stmt (gsi);
    5766              : 
    5767   1824488406 :       if (gimple_code (stmt) == GIMPLE_LABEL)
    5768     38561960 :         continue;
    5769              : 
    5770   1785926446 :       if (verify_eh_edges (stmt))
    5771            0 :         err = true;
    5772              : 
    5773   1785926446 :       if (is_ctrl_stmt (stmt))
    5774              :         {
    5775   2783737967 :           FOR_EACH_EDGE (e, ei, bb->succs)
    5776   1765757669 :             if (e->flags & EDGE_FALLTHRU)
    5777              :               {
    5778            0 :                 error ("fallthru edge after a control statement in bb %d",
    5779              :                        bb->index);
    5780            0 :                 err = true;
    5781              :               }
    5782              :         }
    5783              : 
    5784   1785926446 :       if (gimple_code (stmt) != GIMPLE_COND)
    5785              :         {
    5786              :           /* Verify that there are no edges with EDGE_TRUE/FALSE_FLAG set
    5787              :              after anything else but if statement.  */
    5788   2103094880 :           FOR_EACH_EDGE (e, ei, bb->succs)
    5789   1063213643 :             if (e->flags & (EDGE_TRUE_VALUE | EDGE_FALSE_VALUE))
    5790              :               {
    5791            0 :                 error ("true/false edge after a non-GIMPLE_COND in bb %d",
    5792              :                        bb->index);
    5793            0 :                 err = true;
    5794              :               }
    5795              :         }
    5796              : 
    5797   1785926446 :       switch (gimple_code (stmt))
    5798              :         {
    5799    746045209 :         case GIMPLE_COND:
    5800    746045209 :           {
    5801    746045209 :             edge true_edge;
    5802    746045209 :             edge false_edge;
    5803              : 
    5804    746045209 :             extract_true_false_edges_from_block (bb, &true_edge, &false_edge);
    5805              : 
    5806    746045209 :             if (!true_edge
    5807    746045209 :                 || !false_edge
    5808    746045209 :                 || !(true_edge->flags & EDGE_TRUE_VALUE)
    5809    746045209 :                 || !(false_edge->flags & EDGE_FALSE_VALUE)
    5810    746045209 :                 || (true_edge->flags & (EDGE_FALLTHRU | EDGE_ABNORMAL))
    5811    746045209 :                 || (false_edge->flags & (EDGE_FALLTHRU | EDGE_ABNORMAL))
    5812   1492090418 :                 || EDGE_COUNT (bb->succs) >= 3)
    5813              :               {
    5814            0 :                 error ("wrong outgoing edge flags at end of bb %d",
    5815              :                        bb->index);
    5816            0 :                 err = true;
    5817              :               }
    5818              :           }
    5819    746045209 :           break;
    5820              : 
    5821        51240 :         case GIMPLE_GOTO:
    5822        51240 :           if (simple_goto_p (stmt))
    5823              :             {
    5824            0 :               error ("explicit goto at end of bb %d", bb->index);
    5825            0 :               err = true;
    5826              :             }
    5827              :           else
    5828              :             {
    5829              :               /* FIXME.  We should double check that the labels in the
    5830              :                  destination blocks have their address taken.  */
    5831       182788 :               FOR_EACH_EDGE (e, ei, bb->succs)
    5832       131548 :                 if ((e->flags & (EDGE_FALLTHRU | EDGE_TRUE_VALUE
    5833              :                                  | EDGE_FALSE_VALUE))
    5834       131548 :                     || !(e->flags & EDGE_ABNORMAL))
    5835              :                   {
    5836            0 :                     error ("wrong outgoing edge flags at end of bb %d",
    5837              :                            bb->index);
    5838            0 :                     err = true;
    5839              :                   }
    5840              :             }
    5841              :           break;
    5842              : 
    5843    378457804 :         case GIMPLE_CALL:
    5844    378457804 :           if (!gimple_call_builtin_p (stmt, BUILT_IN_RETURN))
    5845              :             break;
    5846              :           /* fallthru */
    5847    223717285 :         case GIMPLE_RETURN:
    5848    223717285 :           if (!single_succ_p (bb)
    5849    223717285 :               || (single_succ_edge (bb)->flags
    5850    223717285 :                   & (EDGE_FALLTHRU | EDGE_ABNORMAL
    5851              :                      | EDGE_TRUE_VALUE | EDGE_FALSE_VALUE)))
    5852              :             {
    5853            0 :               error ("wrong outgoing edge flags at end of bb %d", bb->index);
    5854            0 :               err = true;
    5855              :             }
    5856    223717285 :           if (single_succ (bb) != EXIT_BLOCK_PTR_FOR_FN (cfun))
    5857              :             {
    5858            0 :               error ("return edge does not point to exit in bb %d",
    5859              :                      bb->index);
    5860            0 :               err = true;
    5861              :             }
    5862              :           break;
    5863              : 
    5864      4099697 :         case GIMPLE_SWITCH:
    5865      4099697 :           {
    5866      4099697 :             gswitch *switch_stmt = as_a <gswitch *> (stmt);
    5867      4099697 :             tree prev;
    5868      4099697 :             edge e;
    5869      4099697 :             size_t i, n;
    5870              : 
    5871      4099697 :             n = gimple_switch_num_labels (switch_stmt);
    5872              : 
    5873              :             /* Mark all the destination basic blocks.  */
    5874     32298590 :             for (i = 0; i < n; ++i)
    5875              :               {
    5876     28198893 :                 basic_block label_bb = gimple_switch_label_bb (cfun, switch_stmt, i);
    5877     28198893 :                 gcc_assert (!label_bb->aux || label_bb->aux == (void *)1);
    5878     28198893 :                 label_bb->aux = (void *)1;
    5879              :               }
    5880              : 
    5881              :             /* Verify that the case labels are sorted.  */
    5882      4099697 :             prev = gimple_switch_label (switch_stmt, 0);
    5883     28198893 :             for (i = 1; i < n; ++i)
    5884              :               {
    5885     24099196 :                 tree c = gimple_switch_label (switch_stmt, i);
    5886     24099196 :                 if (!CASE_LOW (c))
    5887              :                   {
    5888            0 :                     error ("found default case not at the start of "
    5889              :                            "case vector");
    5890            0 :                     err = true;
    5891            0 :                     continue;
    5892              :                   }
    5893     24099196 :                 if (CASE_LOW (prev)
    5894     24099196 :                     && !tree_int_cst_lt (CASE_LOW (prev), CASE_LOW (c)))
    5895              :                   {
    5896            0 :                     error ("case labels not sorted: ");
    5897            0 :                     print_generic_expr (stderr, prev);
    5898            0 :                     fprintf (stderr," is greater than ");
    5899            0 :                     print_generic_expr (stderr, c);
    5900            0 :                     fprintf (stderr," but comes before it.\n");
    5901            0 :                     err = true;
    5902              :                   }
    5903              :                 prev = c;
    5904              :               }
    5905              :             /* VRP will remove the default case if it can prove it will
    5906              :                never be executed.  So do not verify there always exists
    5907              :                a default case here.  */
    5908              : 
    5909     28775674 :             FOR_EACH_EDGE (e, ei, bb->succs)
    5910              :               {
    5911     24675977 :                 if (!e->dest->aux)
    5912              :                   {
    5913            0 :                     error ("extra outgoing edge %d->%d",
    5914              :                            bb->index, e->dest->index);
    5915            0 :                     err = true;
    5916              :                   }
    5917              : 
    5918     24675977 :                 e->dest->aux = (void *)2;
    5919     24675977 :                 if ((e->flags & (EDGE_FALLTHRU | EDGE_ABNORMAL
    5920              :                                  | EDGE_TRUE_VALUE | EDGE_FALSE_VALUE)))
    5921              :                   {
    5922            0 :                     error ("wrong outgoing edge flags at end of bb %d",
    5923              :                            bb->index);
    5924            0 :                     err = true;
    5925              :                   }
    5926              :               }
    5927              : 
    5928              :             /* Check that we have all of them.  */
    5929     32298590 :             for (i = 0; i < n; ++i)
    5930              :               {
    5931     28198893 :                 basic_block label_bb = gimple_switch_label_bb (cfun,
    5932              :                                                                switch_stmt, i);
    5933              : 
    5934     28198893 :                 if (label_bb->aux != (void *)2)
    5935              :                   {
    5936            0 :                     error ("missing edge %i->%i", bb->index, label_bb->index);
    5937            0 :                     err = true;
    5938              :                   }
    5939              :               }
    5940              : 
    5941     28775674 :             FOR_EACH_EDGE (e, ei, bb->succs)
    5942     24675977 :               e->dest->aux = (void *)0;
    5943              :           }
    5944      4099697 :           break;
    5945              : 
    5946      1883558 :         case GIMPLE_EH_DISPATCH:
    5947      1883558 :           if (verify_eh_dispatch_edge (as_a <geh_dispatch *> (stmt)))
    5948            0 :             err = true;
    5949              :           break;
    5950              : 
    5951              :         default:
    5952              :           break;
    5953              :         }
    5954              :     }
    5955              : 
    5956    227676336 :   if (dom_info_state (CDI_DOMINATORS) >= DOM_NO_FAST_QUERY)
    5957    185210878 :     verify_dominators (CDI_DOMINATORS);
    5958              : 
    5959    227676336 :   return err;
    5960              : }
    5961              : 
    5962              : #if __GNUC__ >= 10
    5963              : #  pragma GCC diagnostic pop
    5964              : #endif
    5965              : 
    5966              : /* Updates phi nodes after creating a forwarder block joined
    5967              :    by edge FALLTHRU.  */
    5968              : 
    5969              : static void
    5970        90266 : gimple_make_forwarder_block (edge fallthru)
    5971              : {
    5972        90266 :   edge e;
    5973        90266 :   edge_iterator ei;
    5974        90266 :   basic_block dummy, bb;
    5975        90266 :   tree var;
    5976        90266 :   gphi_iterator gsi;
    5977        90266 :   bool forward_location_p;
    5978              : 
    5979        90266 :   dummy = fallthru->src;
    5980        90266 :   bb = fallthru->dest;
    5981              : 
    5982        90266 :   if (single_pred_p (bb))
    5983          226 :     return;
    5984              : 
    5985              :   /* We can forward location info if we have only one predecessor.  */
    5986        90040 :   forward_location_p = single_pred_p (dummy);
    5987              : 
    5988              :   /* If we redirected a branch we must create new PHI nodes at the
    5989              :      start of BB.  */
    5990       304761 :   for (gsi = gsi_start_phis (dummy); !gsi_end_p (gsi); gsi_next (&gsi))
    5991              :     {
    5992       214721 :       gphi *phi, *new_phi;
    5993              : 
    5994       214721 :       phi = gsi.phi ();
    5995       214721 :       var = gimple_phi_result (phi);
    5996       214721 :       new_phi = create_phi_node (var, bb);
    5997       214721 :       gimple_phi_set_result (phi, copy_ssa_name (var, phi));
    5998       214776 :       add_phi_arg (new_phi, gimple_phi_result (phi), fallthru,
    5999              :                    forward_location_p
    6000           55 :                    ? gimple_phi_arg_location (phi, 0) : UNKNOWN_LOCATION);
    6001              :     }
    6002              : 
    6003              :   /* Add the arguments we have stored on edges.  */
    6004       272554 :   FOR_EACH_EDGE (e, ei, bb->preds)
    6005              :     {
    6006       182514 :       if (e == fallthru)
    6007        90040 :         continue;
    6008              : 
    6009        92474 :       flush_pending_stmts (e);
    6010              :     }
    6011              : }
    6012              : 
    6013              : 
    6014              : /* Return a non-special label in the head of basic block BLOCK.
    6015              :    Create one if it doesn't exist.  */
    6016              : 
    6017              : tree
    6018      5642352 : gimple_block_label (basic_block bb)
    6019              : {
    6020      5642352 :   gimple_stmt_iterator i, s = gsi_start_bb (bb);
    6021      5642352 :   bool first = true;
    6022      5642352 :   tree label;
    6023      5642352 :   glabel *stmt;
    6024              : 
    6025      5642352 :   for (i = s; !gsi_end_p (i); first = false, gsi_next (&i))
    6026              :     {
    6027      4614524 :       stmt = dyn_cast <glabel *> (gsi_stmt (i));
    6028      4529567 :       if (!stmt)
    6029              :         break;
    6030      4529567 :       label = gimple_label_label (stmt);
    6031      4529567 :       if (!DECL_NONLOCAL (label))
    6032              :         {
    6033      4529567 :           if (!first)
    6034            0 :             gsi_move_before (&i, &s);
    6035      4529567 :           return label;
    6036              :         }
    6037              :     }
    6038              : 
    6039      1112785 :   label = create_artificial_label (UNKNOWN_LOCATION);
    6040      1112785 :   stmt = gimple_build_label (label);
    6041      1112785 :   gsi_insert_before (&s, stmt, GSI_NEW_STMT);
    6042      1112785 :   return label;
    6043              : }
    6044              : 
    6045              : 
    6046              : /* Attempt to perform edge redirection by replacing a possibly complex
    6047              :    jump instruction by a goto or by removing the jump completely.
    6048              :    This can apply only if all edges now point to the same block.  The
    6049              :    parameters and return values are equivalent to
    6050              :    redirect_edge_and_branch.  */
    6051              : 
    6052              : static edge
    6053     61154818 : gimple_try_redirect_by_replacing_jump (edge e, basic_block target)
    6054              : {
    6055     61154818 :   basic_block src = e->src;
    6056     61154818 :   gimple_stmt_iterator i;
    6057     61154818 :   gimple *stmt;
    6058              : 
    6059              :   /* We can replace or remove a complex jump only when we have exactly
    6060              :      two edges.  */
    6061    121901127 :   if (EDGE_COUNT (src->succs) != 2
    6062              :       /* Verify that all targets will be TARGET.  Specifically, the
    6063              :          edge that is not E must also go to TARGET.  */
    6064     61154818 :       || EDGE_SUCC (src, EDGE_SUCC (src, 0) == e)->dest != target)
    6065              :     return NULL;
    6066              : 
    6067       408539 :   i = gsi_last_bb (src);
    6068       408539 :   if (gsi_end_p (i))
    6069              :     return NULL;
    6070              : 
    6071       408539 :   stmt = gsi_stmt (i);
    6072              : 
    6073       408539 :   if (gimple_code (stmt) == GIMPLE_COND || gimple_code (stmt) == GIMPLE_SWITCH)
    6074              :     {
    6075       408509 :       gsi_remove (&i, true);
    6076       408509 :       e = ssa_redirect_edge (e, target);
    6077       408509 :       e->flags = EDGE_FALLTHRU;
    6078       408509 :       return e;
    6079              :     }
    6080              : 
    6081              :   return NULL;
    6082              : }
    6083              : 
    6084              : 
    6085              : /* Redirect E to DEST.  Return NULL on failure.  Otherwise, return the
    6086              :    edge representing the redirected branch.  */
    6087              : 
    6088              : static edge
    6089     62384797 : gimple_redirect_edge_and_branch (edge e, basic_block dest)
    6090              : {
    6091     62384797 :   basic_block bb = e->src;
    6092     62384797 :   gimple_stmt_iterator gsi;
    6093     62384797 :   edge ret;
    6094     62384797 :   gimple *stmt;
    6095              : 
    6096     62384797 :   if (e->flags & EDGE_ABNORMAL)
    6097              :     return NULL;
    6098              : 
    6099     62384797 :   if (e->dest == dest)
    6100              :     return NULL;
    6101              : 
    6102     62355442 :   if (e->flags & EDGE_EH)
    6103       954534 :     return redirect_eh_edge (e, dest);
    6104              : 
    6105     61400908 :   if (e->src != ENTRY_BLOCK_PTR_FOR_FN (cfun))
    6106              :     {
    6107     61154818 :       ret = gimple_try_redirect_by_replacing_jump (e, dest);
    6108     61154818 :       if (ret)
    6109              :         return ret;
    6110              :     }
    6111              : 
    6112     60992399 :   gsi = gsi_last_nondebug_bb (bb);
    6113     60992399 :   stmt = gsi_end_p (gsi) ? NULL : gsi_stmt (gsi);
    6114              : 
    6115     60992399 :   switch (stmt ? gimple_code (stmt) : GIMPLE_ERROR_MARK)
    6116              :     {
    6117              :     case GIMPLE_COND:
    6118              :       /* For COND_EXPR, we only need to redirect the edge.  */
    6119              :       break;
    6120              : 
    6121            0 :     case GIMPLE_GOTO:
    6122              :       /* No non-abnormal edges should lead from a non-simple goto, and
    6123              :          simple ones should be represented implicitly.  */
    6124            0 :       gcc_unreachable ();
    6125              : 
    6126       359140 :     case GIMPLE_SWITCH:
    6127       359140 :       {
    6128       359140 :         gswitch *switch_stmt = as_a <gswitch *> (stmt);
    6129       359140 :         tree label = gimple_block_label (dest);
    6130       359140 :         tree cases = get_cases_for_edge (e, switch_stmt);
    6131              : 
    6132              :         /* If we have a list of cases associated with E, then use it
    6133              :            as it's a lot faster than walking the entire case vector.  */
    6134       359140 :         if (cases)
    6135              :           {
    6136       313290 :             edge e2 = find_edge (e->src, dest);
    6137       313290 :             tree last, first;
    6138              : 
    6139       313290 :             first = cases;
    6140      1006063 :             while (cases)
    6141              :               {
    6142       379483 :                 last = cases;
    6143       379483 :                 CASE_LABEL (cases) = label;
    6144       379483 :                 cases = CASE_CHAIN (cases);
    6145              :               }
    6146              : 
    6147              :             /* If there was already an edge in the CFG, then we need
    6148              :                to move all the cases associated with E to E2.  */
    6149       313290 :             if (e2)
    6150              :               {
    6151         8575 :                 tree cases2 = get_cases_for_edge (e2, switch_stmt);
    6152              : 
    6153         8575 :                 CASE_CHAIN (last) = CASE_CHAIN (cases2);
    6154         8575 :                 CASE_CHAIN (cases2) = first;
    6155              :               }
    6156       313290 :             bitmap_set_bit (touched_switch_bbs, gimple_bb (stmt)->index);
    6157              :           }
    6158              :         else
    6159              :           {
    6160        45850 :             size_t i, n = gimple_switch_num_labels (switch_stmt);
    6161              : 
    6162      4623818 :             for (i = 0; i < n; i++)
    6163              :               {
    6164      4577968 :                 tree elt = gimple_switch_label (switch_stmt, i);
    6165      4577968 :                 if (label_to_block (cfun, CASE_LABEL (elt)) == e->dest)
    6166        52536 :                   CASE_LABEL (elt) = label;
    6167              :               }
    6168              :           }
    6169              :       }
    6170              :       break;
    6171              : 
    6172         9988 :     case GIMPLE_ASM:
    6173         9988 :       {
    6174         9988 :         gasm *asm_stmt = as_a <gasm *> (stmt);
    6175         9988 :         int i, n = gimple_asm_nlabels (asm_stmt);
    6176         9988 :         tree label = NULL;
    6177              : 
    6178        14147 :         for (i = 0; i < n; ++i)
    6179              :           {
    6180         4159 :             tree cons = gimple_asm_label_op (asm_stmt, i);
    6181         4159 :             if (label_to_block (cfun, TREE_VALUE (cons)) == e->dest)
    6182              :               {
    6183         2002 :                 if (!label)
    6184         2002 :                   label = gimple_block_label (dest);
    6185         2002 :                 TREE_VALUE (cons) = label;
    6186              :               }
    6187              :           }
    6188              : 
    6189              :         /* If we didn't find any label matching the former edge in the
    6190              :            asm labels, we must be redirecting the fallthrough
    6191              :            edge.  */
    6192         9988 :         gcc_assert (label || (e->flags & EDGE_FALLTHRU));
    6193              :       }
    6194              :       break;
    6195              : 
    6196          254 :     case GIMPLE_RETURN:
    6197          254 :       gsi_remove (&gsi, true);
    6198          254 :       e->flags |= EDGE_FALLTHRU;
    6199          254 :       break;
    6200              : 
    6201              :     case GIMPLE_OMP_RETURN:
    6202              :     case GIMPLE_OMP_CONTINUE:
    6203              :     case GIMPLE_OMP_SECTIONS_SWITCH:
    6204              :     case GIMPLE_OMP_FOR:
    6205              :       /* The edges from OMP constructs can be simply redirected.  */
    6206              :       break;
    6207              : 
    6208            0 :     case GIMPLE_EH_DISPATCH:
    6209            0 :       if (!(e->flags & EDGE_FALLTHRU))
    6210            0 :         redirect_eh_dispatch_edge (as_a <geh_dispatch *> (stmt), e, dest);
    6211              :       break;
    6212              : 
    6213          346 :     case GIMPLE_TRANSACTION:
    6214          346 :       if (e->flags & EDGE_TM_ABORT)
    6215           81 :         gimple_transaction_set_label_over (as_a <gtransaction *> (stmt),
    6216              :                                            gimple_block_label (dest));
    6217          265 :       else if (e->flags & EDGE_TM_UNINSTRUMENTED)
    6218          128 :         gimple_transaction_set_label_uninst (as_a <gtransaction *> (stmt),
    6219              :                                              gimple_block_label (dest));
    6220              :       else
    6221          137 :         gimple_transaction_set_label_norm (as_a <gtransaction *> (stmt),
    6222              :                                            gimple_block_label (dest));
    6223              :       break;
    6224              : 
    6225      7340364 :     default:
    6226              :       /* Otherwise it must be a fallthru edge, and we don't need to
    6227              :          do anything besides redirecting it.  */
    6228      7340364 :       gcc_assert (e->flags & EDGE_FALLTHRU);
    6229              :       break;
    6230              :     }
    6231              : 
    6232              :   /* Update/insert PHI nodes as necessary.  */
    6233              : 
    6234              :   /* Now update the edges in the CFG.  */
    6235     60992399 :   e = ssa_redirect_edge (e, dest);
    6236              : 
    6237     60992399 :   return e;
    6238              : }
    6239              : 
    6240              : /* Returns true if it is possible to remove edge E by redirecting
    6241              :    it to the destination of the other edge from E->src.  */
    6242              : 
    6243              : static bool
    6244       297780 : gimple_can_remove_branch_p (const_edge e)
    6245              : {
    6246       297780 :   if (e->flags & (EDGE_ABNORMAL | EDGE_EH))
    6247            0 :     return false;
    6248              : 
    6249              :   return true;
    6250              : }
    6251              : 
    6252              : /* Simple wrapper, as we can always redirect fallthru edges.  */
    6253              : 
    6254              : static basic_block
    6255      3745115 : gimple_redirect_edge_and_branch_force (edge e, basic_block dest)
    6256              : {
    6257      3745115 :   e = gimple_redirect_edge_and_branch (e, dest);
    6258      3745115 :   gcc_assert (e);
    6259              : 
    6260      3745115 :   return NULL;
    6261              : }
    6262              : 
    6263              : 
    6264              : /* Splits basic block BB after statement STMT (but at least after the
    6265              :    labels).  If STMT is NULL, BB is split just after the labels.  */
    6266              : 
    6267              : static basic_block
    6268      5478855 : gimple_split_block (basic_block bb, void *stmt)
    6269              : {
    6270      5478855 :   gimple_stmt_iterator gsi;
    6271      5478855 :   gimple_stmt_iterator gsi_tgt;
    6272      5478855 :   gimple_seq list;
    6273      5478855 :   basic_block new_bb;
    6274      5478855 :   edge e;
    6275      5478855 :   edge_iterator ei;
    6276              : 
    6277      5478855 :   new_bb = create_empty_bb (bb);
    6278              : 
    6279              :   /* Redirect the outgoing edges.  */
    6280      5478855 :   new_bb->succs = bb->succs;
    6281      5478855 :   bb->succs = NULL;
    6282     12631103 :   FOR_EACH_EDGE (e, ei, new_bb->succs)
    6283      7152248 :     e->src = new_bb;
    6284              : 
    6285              :   /* Get a stmt iterator pointing to the first stmt to move.  */
    6286      5478855 :   if (!stmt || gimple_code ((gimple *) stmt) == GIMPLE_LABEL)
    6287      1357742 :     gsi = gsi_after_labels (bb);
    6288              :   else
    6289              :     {
    6290      4121113 :       gsi = gsi_for_stmt ((gimple *) stmt);
    6291      4121113 :       gsi_next (&gsi);
    6292              :     }
    6293              : 
    6294              :   /* Move everything from GSI to the new basic block.  */
    6295      5478855 :   if (gsi_end_p (gsi))
    6296              :     return new_bb;
    6297              : 
    6298              :   /* Split the statement list - avoid re-creating new containers as this
    6299              :      brings ugly quadratic memory consumption in the inliner.
    6300              :      (We are still quadratic since we need to update stmt BB pointers,
    6301              :      sadly.)  */
    6302      5066236 :   gsi_split_seq_before (&gsi, &list);
    6303      5066236 :   set_bb_seq (new_bb, list);
    6304      5066236 :   for (gsi_tgt = gsi_start (list);
    6305     28937742 :        !gsi_end_p (gsi_tgt); gsi_next (&gsi_tgt))
    6306     23871506 :     gimple_set_bb (gsi_stmt (gsi_tgt), new_bb);
    6307              : 
    6308              :   return new_bb;
    6309              : }
    6310              : 
    6311              : 
    6312              : /* Moves basic block BB after block AFTER.  */
    6313              : 
    6314              : static bool
    6315     22464307 : gimple_move_block_after (basic_block bb, basic_block after)
    6316              : {
    6317     22464307 :   if (bb->prev_bb == after)
    6318              :     return true;
    6319              : 
    6320      5388267 :   unlink_block (bb);
    6321      5388267 :   link_block (bb, after);
    6322              : 
    6323      5388267 :   return true;
    6324              : }
    6325              : 
    6326              : 
    6327              : /* Return TRUE if block BB has no executable statements, otherwise return
    6328              :    FALSE.  */
    6329              : 
    6330              : static bool
    6331     14245329 : gimple_empty_block_p (basic_block bb)
    6332              : {
    6333              :   /* BB must have no executable statements.  */
    6334     14245329 :   gimple_stmt_iterator gsi = gsi_after_labels (bb);
    6335     14245329 :   if (phi_nodes (bb))
    6336              :     return false;
    6337     19171948 :   while (!gsi_end_p (gsi))
    6338              :     {
    6339      9469601 :       gimple *stmt = gsi_stmt (gsi);
    6340      9469601 :       if (is_gimple_debug (stmt))
    6341              :         ;
    6342      3461108 :       else if (gimple_code (stmt) == GIMPLE_NOP
    6343      3461108 :                || gimple_code (stmt) == GIMPLE_PREDICT)
    6344              :         ;
    6345              :       else
    6346              :         return false;
    6347      6049542 :       gsi_next (&gsi);
    6348              :     }
    6349              :   return true;
    6350              : }
    6351              : 
    6352              : 
    6353              : /* Split a basic block if it ends with a conditional branch and if the
    6354              :    other part of the block is not empty.  */
    6355              : 
    6356              : static basic_block
    6357          558 : gimple_split_block_before_cond_jump (basic_block bb)
    6358              : {
    6359          558 :   gimple *last, *split_point;
    6360          558 :   gimple_stmt_iterator gsi = gsi_last_nondebug_bb (bb);
    6361          558 :   if (gsi_end_p (gsi))
    6362              :     return NULL;
    6363          558 :   last = gsi_stmt (gsi);
    6364          558 :   if (gimple_code (last) != GIMPLE_COND
    6365          558 :       && gimple_code (last) != GIMPLE_SWITCH)
    6366              :     return NULL;
    6367          558 :   gsi_prev (&gsi);
    6368          558 :   split_point = gsi_stmt (gsi);
    6369          558 :   return split_block (bb, split_point)->dest;
    6370              : }
    6371              : 
    6372              : 
    6373              : /* Return true if basic_block can be duplicated.  */
    6374              : 
    6375              : static bool
    6376      9583026 : gimple_can_duplicate_bb_p (const_basic_block bb)
    6377              : {
    6378      9583026 :   gimple *last = last_nondebug_stmt (const_cast<basic_block> (bb));
    6379              : 
    6380              :   /* Do checks that can only fail for the last stmt, to minimize the work in the
    6381              :      stmt loop.  */
    6382      9583026 :   if (last) {
    6383              :     /* A transaction is a single entry multiple exit region.  It
    6384              :        must be duplicated in its entirety or not at all.  */
    6385      8154953 :     if (gimple_code (last) == GIMPLE_TRANSACTION)
    6386              :       return false;
    6387              : 
    6388              :     /* An IFN_UNIQUE call must be duplicated as part of its group,
    6389              :        or not at all.  */
    6390      8154951 :     if (is_gimple_call (last)
    6391        68656 :         && gimple_call_internal_p (last)
    6392      8155417 :         && gimple_call_internal_unique_p (last))
    6393              :       return false;
    6394              : 
    6395              :     /* Prohibit duplication of returns_twice calls, otherwise associated
    6396              :        abnormal edges also need to be duplicated properly.
    6397              :        return_twice functions will always be the last statement.  */
    6398      8154951 :     if (is_gimple_call (last)
    6399      8154951 :         && (gimple_call_flags (last) & ECF_RETURNS_TWICE))
    6400              :       return false;
    6401              :   }
    6402              : 
    6403     19165916 :   for (gimple_stmt_iterator gsi = gsi_start_bb (const_cast<basic_block> (bb));
    6404     66385179 :        !gsi_end_p (gsi); gsi_next (&gsi))
    6405              :     {
    6406     56802221 :       gimple *g = gsi_stmt (gsi);
    6407              : 
    6408              :       /* An IFN_GOMP_SIMT_ENTER_ALLOC/IFN_GOMP_SIMT_EXIT call must be
    6409              :          duplicated as part of its group, or not at all.
    6410              :          The IFN_GOMP_SIMT_VOTE_ANY and IFN_GOMP_SIMT_XCHG_* are part of such a
    6411              :          group, so the same holds there.  */
    6412     56802221 :       if (is_gimple_call (g)
    6413     56802221 :           && (gimple_call_internal_p (g, IFN_GOMP_SIMT_ENTER_ALLOC)
    6414       493330 :               || gimple_call_internal_p (g, IFN_GOMP_SIMT_EXIT)
    6415       493330 :               || gimple_call_internal_p (g, IFN_GOMP_SIMT_VOTE_ANY)
    6416       493330 :               || gimple_call_internal_p (g, IFN_GOMP_SIMT_XCHG_BFLY)
    6417       493330 :               || gimple_call_internal_p (g, IFN_GOMP_SIMT_XCHG_IDX)))
    6418           68 :         return false;
    6419              :     }
    6420              : 
    6421              :   return true;
    6422              : }
    6423              : 
    6424              : /* Create a duplicate of the basic block BB.  NOTE: This does not
    6425              :    preserve SSA form.  */
    6426              : 
    6427              : static basic_block
    6428      3792806 : gimple_duplicate_bb (basic_block bb, copy_bb_data *id)
    6429              : {
    6430      3792806 :   basic_block new_bb;
    6431      3792806 :   gimple_stmt_iterator gsi_tgt;
    6432              : 
    6433      3792806 :   new_bb = create_empty_bb (EXIT_BLOCK_PTR_FOR_FN (cfun)->prev_bb);
    6434              : 
    6435              :   /* Copy the PHI nodes.  We ignore PHI node arguments here because
    6436              :      the incoming edges have not been setup yet.  */
    6437      3792806 :   for (gphi_iterator gpi = gsi_start_phis (bb);
    6438      8836174 :        !gsi_end_p (gpi);
    6439      5043368 :        gsi_next (&gpi))
    6440              :     {
    6441      5043368 :       gphi *phi, *copy;
    6442      5043368 :       phi = gpi.phi ();
    6443      5043368 :       copy = create_phi_node (NULL_TREE, new_bb);
    6444      5043368 :       create_new_def_for (gimple_phi_result (phi), copy,
    6445              :                           gimple_phi_result_ptr (copy));
    6446      5043368 :       gimple_set_uid (copy, gimple_uid (phi));
    6447              :     }
    6448              : 
    6449      3792806 :   gsi_tgt = gsi_start_bb (new_bb);
    6450      7585612 :   for (gimple_stmt_iterator gsi = gsi_start_bb (bb);
    6451     24873859 :        !gsi_end_p (gsi);
    6452     21081053 :        gsi_next (&gsi))
    6453              :     {
    6454     21081053 :       def_operand_p def_p;
    6455     21081053 :       ssa_op_iter op_iter;
    6456     21081053 :       tree lhs;
    6457     21081053 :       gimple *stmt, *copy;
    6458              : 
    6459     21081053 :       stmt = gsi_stmt (gsi);
    6460     21081053 :       if (gimple_code (stmt) == GIMPLE_LABEL)
    6461        80358 :         continue;
    6462              : 
    6463              :       /* Don't duplicate label debug stmts.  */
    6464     21003118 :       if (gimple_debug_bind_p (stmt)
    6465     12844502 :           && TREE_CODE (gimple_debug_bind_get_var (stmt))
    6466              :              == LABEL_DECL)
    6467         2423 :         continue;
    6468              : 
    6469              :       /* Create a new copy of STMT and duplicate STMT's virtual
    6470              :          operands.  */
    6471     21000695 :       copy = gimple_copy (stmt);
    6472     21000695 :       gsi_insert_after (&gsi_tgt, copy, GSI_NEW_STMT);
    6473              : 
    6474     21000695 :       maybe_duplicate_eh_stmt (copy, stmt);
    6475     21000695 :       gimple_duplicate_stmt_histograms (cfun, copy, cfun, stmt);
    6476              : 
    6477              :       /* When copying around a stmt writing into a local non-user
    6478              :          aggregate, make sure it won't share stack slot with other
    6479              :          vars.  */
    6480     21000695 :       lhs = gimple_get_lhs (stmt);
    6481     21000695 :       if (lhs && TREE_CODE (lhs) != SSA_NAME)
    6482              :         {
    6483       796699 :           tree base = get_base_address (lhs);
    6484       796699 :           if (base
    6485       796699 :               && (VAR_P (base) || TREE_CODE (base) == RESULT_DECL)
    6486       523158 :               && DECL_IGNORED_P (base)
    6487       193480 :               && !TREE_STATIC (base)
    6488       192147 :               && !DECL_EXTERNAL (base)
    6489       988844 :               && (!VAR_P (base) || !DECL_HAS_VALUE_EXPR_P (base)))
    6490       192145 :             DECL_NONSHAREABLE (base) = 1;
    6491              :         }
    6492              : 
    6493              :       /* If requested remap dependence info of cliques brought in
    6494              :          via inlining.  */
    6495     21000695 :       if (id)
    6496     56305329 :         for (unsigned i = 0; i < gimple_num_ops (copy); ++i)
    6497              :           {
    6498     38982671 :             tree op = gimple_op (copy, i);
    6499     38982671 :             if (!op)
    6500     10014893 :               continue;
    6501     28967778 :             if (TREE_CODE (op) == ADDR_EXPR
    6502     27859567 :                 || TREE_CODE (op) == WITH_SIZE_EXPR)
    6503      1108211 :               op = TREE_OPERAND (op, 0);
    6504     30864701 :             while (handled_component_p (op))
    6505      1896923 :               op = TREE_OPERAND (op, 0);
    6506     28967778 :             if ((TREE_CODE (op) == MEM_REF
    6507     28967778 :                  || TREE_CODE (op) == TARGET_MEM_REF)
    6508      1033708 :                 && MR_DEPENDENCE_CLIQUE (op) > 1
    6509     29036877 :                 && MR_DEPENDENCE_CLIQUE (op) != bb->loop_father->owned_clique)
    6510              :               {
    6511        26662 :                 if (!id->dependence_map)
    6512        13330 :                   id->dependence_map = new hash_map<dependence_hash,
    6513              :                                                     unsigned short>;
    6514        26662 :                 bool existed;
    6515        26662 :                 unsigned short &newc = id->dependence_map->get_or_insert
    6516        26662 :                     (MR_DEPENDENCE_CLIQUE (op), &existed);
    6517        26662 :                 if (!existed)
    6518              :                   {
    6519        17992 :                     gcc_assert (MR_DEPENDENCE_CLIQUE (op) <= cfun->last_clique);
    6520        35984 :                     newc = get_new_clique (cfun);
    6521              :                   }
    6522        26662 :                 MR_DEPENDENCE_CLIQUE (op) = newc;
    6523              :               }
    6524              :           }
    6525              : 
    6526              :       /* Create new names for all the definitions created by COPY and
    6527              :          add replacement mappings for each new name.  */
    6528     26117798 :       FOR_EACH_SSA_DEF_OPERAND (def_p, copy, op_iter, SSA_OP_ALL_DEFS)
    6529      5117103 :         create_new_def_for (DEF_FROM_PTR (def_p), copy, def_p);
    6530              :     }
    6531              : 
    6532      3792806 :   return new_bb;
    6533              : }
    6534              : 
    6535              : /* Adds phi node arguments for edge E_COPY after basic block duplication.  */
    6536              : 
    6537              : static void
    6538      5039270 : add_phi_args_after_copy_edge (edge e_copy)
    6539              : {
    6540      5039270 :   basic_block bb, bb_copy = e_copy->src, dest;
    6541      5039270 :   edge e;
    6542      5039270 :   edge_iterator ei;
    6543      5039270 :   gphi *phi, *phi_copy;
    6544      5039270 :   tree def;
    6545      5039270 :   gphi_iterator psi, psi_copy;
    6546              : 
    6547      5039270 :   if (gimple_seq_empty_p (phi_nodes (e_copy->dest)))
    6548      3233578 :     return;
    6549              : 
    6550      1805692 :   bb = bb_copy->flags & BB_DUPLICATED ? get_bb_original (bb_copy) : bb_copy;
    6551              : 
    6552      1805692 :   if (e_copy->dest->flags & BB_DUPLICATED)
    6553       737001 :     dest = get_bb_original (e_copy->dest);
    6554              :   else
    6555              :     dest = e_copy->dest;
    6556              : 
    6557      1805692 :   e = find_edge (bb, dest);
    6558      1805692 :   if (!e)
    6559              :     {
    6560              :       /* During loop unrolling the target of the latch edge is copied.
    6561              :          In this case we are not looking for edge to dest, but to
    6562              :          duplicated block whose original was dest.  */
    6563         1078 :       FOR_EACH_EDGE (e, ei, bb->succs)
    6564              :         {
    6565         1078 :           if ((e->dest->flags & BB_DUPLICATED)
    6566         1078 :               && get_bb_original (e->dest) == dest)
    6567              :             break;
    6568              :         }
    6569              : 
    6570         1078 :       gcc_assert (e != NULL);
    6571              :     }
    6572              : 
    6573      1805692 :   for (psi = gsi_start_phis (e->dest),
    6574      1805692 :        psi_copy = gsi_start_phis (e_copy->dest);
    6575      5266841 :        !gsi_end_p (psi);
    6576      3461149 :        gsi_next (&psi), gsi_next (&psi_copy))
    6577              :     {
    6578      3461149 :       phi = psi.phi ();
    6579      3461149 :       phi_copy = psi_copy.phi ();
    6580      3461149 :       def = PHI_ARG_DEF_FROM_EDGE (phi, e);
    6581      3461149 :       add_phi_arg (phi_copy, def, e_copy,
    6582              :                    gimple_phi_arg_location_from_edge (phi, e));
    6583              :     }
    6584              : }
    6585              : 
    6586              : 
    6587              : /* Basic block BB_COPY was created by code duplication.  Add phi node
    6588              :    arguments for edges going out of BB_COPY.  The blocks that were
    6589              :    duplicated have BB_DUPLICATED set.  */
    6590              : 
    6591              : void
    6592      3475345 : add_phi_args_after_copy_bb (basic_block bb_copy)
    6593              : {
    6594      3475345 :   edge e_copy;
    6595      3475345 :   edge_iterator ei;
    6596              : 
    6597      8514591 :   FOR_EACH_EDGE (e_copy, ei, bb_copy->succs)
    6598              :     {
    6599      5039246 :       add_phi_args_after_copy_edge (e_copy);
    6600              :     }
    6601      3475345 : }
    6602              : 
    6603              : /* Blocks in REGION_COPY array of length N_REGION were created by
    6604              :    duplication of basic blocks.  Add phi node arguments for edges
    6605              :    going from these blocks.  If E_COPY is not NULL, also add
    6606              :    phi node arguments for its destination.*/
    6607              : 
    6608              : void
    6609      1807927 : add_phi_args_after_copy (basic_block *region_copy, unsigned n_region,
    6610              :                          edge e_copy)
    6611              : {
    6612      1807927 :   unsigned i;
    6613              : 
    6614      4143328 :   for (i = 0; i < n_region; i++)
    6615      2335401 :     region_copy[i]->flags |= BB_DUPLICATED;
    6616              : 
    6617      4143328 :   for (i = 0; i < n_region; i++)
    6618      2335401 :     add_phi_args_after_copy_bb (region_copy[i]);
    6619      1807927 :   if (e_copy)
    6620           24 :     add_phi_args_after_copy_edge (e_copy);
    6621              : 
    6622      4143328 :   for (i = 0; i < n_region; i++)
    6623      2335401 :     region_copy[i]->flags &= ~BB_DUPLICATED;
    6624      1807927 : }
    6625              : 
    6626              : /* Duplicates a REGION (set of N_REGION basic blocks) with just a single
    6627              :    important exit edge EXIT.  By important we mean that no SSA name defined
    6628              :    inside region is live over the other exit edges of the region.  All entry
    6629              :    edges to the region must go to ENTRY->dest.  The edge ENTRY is redirected
    6630              :    to the duplicate of the region.  Dominance and loop information is
    6631              :    updated if UPDATE_DOMINANCE is true, but not the SSA web.  If
    6632              :    UPDATE_DOMINANCE is false then we assume that the caller will update the
    6633              :    dominance information after calling this function.  The new basic
    6634              :    blocks are stored to REGION_COPY in the same order as they had in REGION,
    6635              :    provided that REGION_COPY is not NULL.
    6636              :    The function returns false if it is unable to copy the region,
    6637              :    true otherwise.
    6638              : 
    6639              :    It is callers responsibility to update profile.  */
    6640              : 
    6641              : bool
    6642       564800 : gimple_duplicate_seme_region (edge entry, edge exit,
    6643              :                               basic_block *region, unsigned n_region,
    6644              :                               basic_block *region_copy,
    6645              :                               bool update_dominance)
    6646              : {
    6647       564800 :   unsigned i;
    6648       564800 :   bool free_region_copy = false, copying_header = false;
    6649       564800 :   class loop *loop = entry->dest->loop_father;
    6650       564800 :   edge exit_copy;
    6651       564800 :   edge redirected;
    6652              : 
    6653       564800 :   if (!can_copy_bbs_p (region, n_region))
    6654              :     return false;
    6655              : 
    6656              :   /* Some sanity checking.  Note that we do not check for all possible
    6657              :      missuses of the functions.  I.e. if you ask to copy something weird,
    6658              :      it will work, but the state of structures probably will not be
    6659              :      correct.  */
    6660      1139079 :   for (i = 0; i < n_region; i++)
    6661              :     {
    6662              :       /* We do not handle subloops, i.e. all the blocks must belong to the
    6663              :          same loop.  */
    6664       574279 :       if (region[i]->loop_father != loop)
    6665              :         return false;
    6666              : 
    6667       574279 :       if (region[i] != entry->dest
    6668         9479 :           && region[i] == loop->header)
    6669              :         return false;
    6670              :     }
    6671              : 
    6672              :   /* In case the function is used for loop header copying (which is the primary
    6673              :      use), ensure that EXIT and its copy will be new latch and entry edges.  */
    6674       564800 :   if (loop->header == entry->dest)
    6675              :     {
    6676       564800 :       copying_header = true;
    6677              : 
    6678       564800 :       if (!dominated_by_p (CDI_DOMINATORS, loop->latch, exit->src))
    6679              :         return false;
    6680              : 
    6681      1139079 :       for (i = 0; i < n_region; i++)
    6682       574279 :         if (region[i] != exit->src
    6683       574279 :             && dominated_by_p (CDI_DOMINATORS, region[i], exit->src))
    6684              :           return false;
    6685              :     }
    6686              : 
    6687       564800 :   initialize_original_copy_tables ();
    6688              : 
    6689       564800 :   if (copying_header)
    6690       564800 :     set_loop_copy (loop, loop_outer (loop));
    6691              :   else
    6692            0 :     set_loop_copy (loop, loop);
    6693              : 
    6694       564800 :   if (!region_copy)
    6695              :     {
    6696            0 :       region_copy = XNEWVEC (basic_block, n_region);
    6697            0 :       free_region_copy = true;
    6698              :     }
    6699              : 
    6700              :   /* Record blocks outside the region that are dominated by something
    6701              :      inside.  */
    6702       564800 :   auto_vec<basic_block> doms;
    6703       564800 :   if (update_dominance)
    6704       564800 :     doms = get_dominated_by_region (CDI_DOMINATORS, region, n_region);
    6705              : 
    6706       564800 :   copy_bbs (region, n_region, region_copy, &exit, 1, &exit_copy, loop,
    6707              :             split_edge_bb_loc (entry), update_dominance);
    6708              : 
    6709       564800 :   if (copying_header)
    6710              :     {
    6711       564800 :       loop->header = exit->dest;
    6712       564800 :       loop->latch = exit->src;
    6713              :     }
    6714              : 
    6715              :   /* Redirect the entry and add the phi node arguments.  */
    6716       564800 :   redirected = redirect_edge_and_branch (entry, get_bb_copy (entry->dest));
    6717       564800 :   gcc_assert (redirected != NULL);
    6718       564800 :   flush_pending_stmts (entry);
    6719              : 
    6720              :   /* Concerning updating of dominators:  We must recount dominators
    6721              :      for entry block and its copy.  Anything that is outside of the
    6722              :      region, but was dominated by something inside needs recounting as
    6723              :      well.  */
    6724       564800 :   if (update_dominance)
    6725              :     {
    6726       564800 :       set_immediate_dominator (CDI_DOMINATORS, entry->dest, entry->src);
    6727       564800 :       doms.safe_push (get_bb_original (entry->dest));
    6728       564800 :       iterate_fix_dominators (CDI_DOMINATORS, doms, false);
    6729              :     }
    6730              : 
    6731              :   /* Add the other PHI node arguments.  */
    6732       564800 :   add_phi_args_after_copy (region_copy, n_region, NULL);
    6733              : 
    6734       564800 :   if (free_region_copy)
    6735            0 :     free (region_copy);
    6736              : 
    6737       564800 :   free_original_copy_tables ();
    6738       564800 :   return true;
    6739       564800 : }
    6740              : 
    6741              : /* Checks if BB is part of the region defined by N_REGION BBS.  */
    6742              : static bool
    6743            0 : bb_part_of_region_p (basic_block bb, basic_block* bbs, unsigned n_region)
    6744              : {
    6745            0 :   unsigned int n;
    6746              : 
    6747            0 :   for (n = 0; n < n_region; n++)
    6748              :     {
    6749            0 :      if (bb == bbs[n])
    6750              :        return true;
    6751              :     }
    6752              :   return false;
    6753              : }
    6754              : 
    6755              : 
    6756              : /* For each PHI in BB, copy the argument associated with SRC_E to TGT_E.
    6757              :    Assuming the argument exists, just does not have a value.
    6758              :    If USE_MAP is true, then use the redirect edge var map of TGT_E
    6759              :    for the new arguments; clearing the map afterwards.  */
    6760              : 
    6761              : void
    6762     29877366 : copy_phi_arg_into_existing_phi (edge src_e, edge tgt_e, bool use_map)
    6763              : {
    6764     29877366 :   int src_idx = src_e->dest_idx;
    6765     29877366 :   int tgt_idx = tgt_e->dest_idx;
    6766              : 
    6767              :   /* Iterate over each PHI in e->dest.  */
    6768     29877366 :   for (gphi_iterator gsi = gsi_start_phis (src_e->dest),
    6769     29877366 :                            gsi2 = gsi_start_phis (tgt_e->dest);
    6770     75150133 :        !gsi_end_p (gsi);
    6771     45272767 :        gsi_next (&gsi), gsi_next (&gsi2))
    6772              :     {
    6773     45272767 :       gphi *src_phi = gsi.phi ();
    6774     45272767 :       gphi *dest_phi = gsi2.phi ();
    6775     45272767 :       tree val = gimple_phi_arg_def (src_phi, src_idx);
    6776     45272767 :       location_t locus = gimple_phi_arg_location (src_phi, src_idx);
    6777              : 
    6778     45272767 :       if (use_map && TREE_CODE (val) == SSA_NAME)
    6779              :         {
    6780              :           /* If DEF is one of the results of PHI nodes removed during
    6781              :              redirection, replace it with the PHI argument that used
    6782              :              to be on E.  */
    6783      4629878 :           vec<edge_var_map> *head = redirect_edge_var_map_vector (tgt_e);
    6784      9259756 :           size_t length = head ? head->length () : 0;
    6785      7971040 :           for (size_t i = 0; i < length; i++)
    6786              :             {
    6787      6585423 :               edge_var_map *vm = &(*head)[i];
    6788      6585423 :               tree old_arg = redirect_edge_var_map_result (vm);
    6789      6585423 :               tree new_arg = redirect_edge_var_map_def (vm);
    6790              : 
    6791      6585423 :               if (val == old_arg)
    6792              :                 {
    6793      3244261 :                   val = new_arg;
    6794      3244261 :                   location_t locus1 = redirect_edge_var_map_location (vm);
    6795              :                   /* Don't remove the location if we remap one does not have one.  */
    6796      3244261 :                   if (locus1 != UNKNOWN_LOCATION)
    6797       484647 :                     locus = locus1;
    6798              :                   break;
    6799              :                 }
    6800              :             }
    6801              :         }
    6802              : 
    6803     45272767 :       SET_PHI_ARG_DEF (dest_phi, tgt_idx, val);
    6804     45272767 :       gimple_phi_arg_set_location (dest_phi, tgt_idx, locus);
    6805              :     }
    6806     29877366 :   if (use_map)
    6807      2745420 :     redirect_edge_var_map_clear (tgt_e);
    6808     29877366 : }
    6809              : 
    6810              : /* Duplicates REGION consisting of N_REGION blocks.  The new blocks
    6811              :    are stored to REGION_COPY in the same order in that they appear
    6812              :    in REGION, if REGION_COPY is not NULL.  ENTRY is the entry to
    6813              :    the region, EXIT an exit from it.  The condition guarding EXIT
    6814              :    is moved to ENTRY.  Returns true if duplication succeeds, false
    6815              :    otherwise.
    6816              : 
    6817              :    For example,
    6818              : 
    6819              :    some_code;
    6820              :    if (cond)
    6821              :      A;
    6822              :    else
    6823              :      B;
    6824              : 
    6825              :    is transformed to
    6826              : 
    6827              :    if (cond)
    6828              :      {
    6829              :        some_code;
    6830              :        A;
    6831              :      }
    6832              :    else
    6833              :      {
    6834              :        some_code;
    6835              :        B;
    6836              :      }
    6837              : */
    6838              : 
    6839              : bool
    6840           24 : gimple_duplicate_sese_tail (edge entry, edge exit,
    6841              :                           basic_block *region, unsigned n_region,
    6842              :                           basic_block *region_copy)
    6843              : {
    6844           24 :   unsigned i;
    6845           24 :   bool free_region_copy = false;
    6846           24 :   class loop *loop = exit->dest->loop_father;
    6847           24 :   class loop *orig_loop = entry->dest->loop_father;
    6848           24 :   basic_block switch_bb, entry_bb, nentry_bb;
    6849           24 :   profile_count total_count = profile_count::uninitialized (),
    6850              :                 exit_count = profile_count::uninitialized ();
    6851           24 :   edge exits[2], nexits[2], e;
    6852           24 :   gimple_stmt_iterator gsi;
    6853           24 :   edge sorig, snew;
    6854           24 :   basic_block exit_bb;
    6855           24 :   class loop *target, *aloop, *cloop;
    6856              : 
    6857           24 :   gcc_assert (EDGE_COUNT (exit->src->succs) == 2);
    6858           24 :   exits[0] = exit;
    6859           24 :   exits[1] = EDGE_SUCC (exit->src, EDGE_SUCC (exit->src, 0) == exit);
    6860              : 
    6861           24 :   if (!can_copy_bbs_p (region, n_region))
    6862              :     return false;
    6863              : 
    6864           24 :   initialize_original_copy_tables ();
    6865           24 :   set_loop_copy (orig_loop, loop);
    6866              : 
    6867           24 :   target= loop;
    6868           24 :   for (aloop = orig_loop->inner; aloop; aloop = aloop->next)
    6869              :     {
    6870            0 :       if (bb_part_of_region_p (aloop->header, region, n_region))
    6871              :         {
    6872            0 :           cloop = duplicate_loop (aloop, target);
    6873            0 :           duplicate_subloops (aloop, cloop);
    6874              :         }
    6875              :     }
    6876              : 
    6877           24 :   if (!region_copy)
    6878              :     {
    6879            0 :       region_copy = XNEWVEC (basic_block, n_region);
    6880            0 :       free_region_copy = true;
    6881              :     }
    6882              : 
    6883           24 :   gcc_assert (!need_ssa_update_p (cfun));
    6884              : 
    6885              :   /* Record blocks outside the region that are dominated by something
    6886              :      inside.  */
    6887           24 :   auto_vec<basic_block> doms = get_dominated_by_region (CDI_DOMINATORS, region,
    6888           24 :                                                         n_region);
    6889              : 
    6890           24 :   total_count = exit->src->count;
    6891           24 :   exit_count = exit->count ();
    6892              :   /* Fix up corner cases, to avoid division by zero or creation of negative
    6893              :      frequencies.  */
    6894           24 :   if (exit_count > total_count)
    6895            0 :     exit_count = total_count;
    6896              : 
    6897           24 :   copy_bbs (region, n_region, region_copy, exits, 2, nexits, orig_loop,
    6898              :             split_edge_bb_loc (exit), true);
    6899           24 :   if (total_count.initialized_p () && exit_count.initialized_p ())
    6900              :     {
    6901           24 :       scale_bbs_frequencies_profile_count (region, n_region,
    6902              :                                            total_count - exit_count,
    6903              :                                            total_count);
    6904           24 :       scale_bbs_frequencies_profile_count (region_copy, n_region, exit_count,
    6905              :                                            total_count);
    6906              :     }
    6907              : 
    6908              :   /* Create the switch block, and put the exit condition to it.  */
    6909           24 :   entry_bb = entry->dest;
    6910           24 :   nentry_bb = get_bb_copy (entry_bb);
    6911           24 :   if (!*gsi_last_bb (entry->src)
    6912           24 :       || !stmt_ends_bb_p (*gsi_last_bb (entry->src)))
    6913           24 :     switch_bb = entry->src;
    6914              :   else
    6915            0 :     switch_bb = split_edge (entry);
    6916           24 :   set_immediate_dominator (CDI_DOMINATORS, nentry_bb, switch_bb);
    6917              : 
    6918           48 :   gcond *cond_stmt = as_a <gcond *> (*gsi_last_bb (exit->src));
    6919           24 :   cond_stmt = as_a <gcond *> (gimple_copy (cond_stmt));
    6920              : 
    6921           24 :   gsi = gsi_last_bb (switch_bb);
    6922           24 :   gsi_insert_after (&gsi, cond_stmt, GSI_NEW_STMT);
    6923              : 
    6924           24 :   sorig = single_succ_edge (switch_bb);
    6925           24 :   sorig->flags = exits[1]->flags;
    6926           24 :   sorig->probability = exits[1]->probability;
    6927           24 :   snew = make_edge (switch_bb, nentry_bb, exits[0]->flags);
    6928           24 :   snew->probability = exits[0]->probability;
    6929              : 
    6930              : 
    6931              :   /* Register the new edge from SWITCH_BB in loop exit lists.  */
    6932           24 :   rescan_loop_exit (snew, true, false);
    6933              : 
    6934              :   /* Add the PHI node arguments.  */
    6935           24 :   add_phi_args_after_copy (region_copy, n_region, snew);
    6936              : 
    6937              :   /* Get rid of now superfluous conditions and associated edges (and phi node
    6938              :      arguments).  */
    6939           24 :   exit_bb = exit->dest;
    6940              : 
    6941           24 :   e = redirect_edge_and_branch (exits[0], exits[1]->dest);
    6942           24 :   PENDING_STMT (e) = NULL;
    6943              : 
    6944              :   /* The latch of ORIG_LOOP was copied, and so was the backedge
    6945              :      to the original header.  We redirect this backedge to EXIT_BB.  */
    6946           50 :   for (i = 0; i < n_region; i++)
    6947           26 :     if (get_bb_original (region_copy[i]) == orig_loop->latch)
    6948              :       {
    6949            0 :         gcc_assert (single_succ_edge (region_copy[i]));
    6950            0 :         e = redirect_edge_and_branch (single_succ_edge (region_copy[i]), exit_bb);
    6951            0 :         PENDING_STMT (e) = NULL;
    6952            0 :         copy_phi_arg_into_existing_phi (nexits[0], e);
    6953              :       }
    6954           24 :   e = redirect_edge_and_branch (nexits[1], nexits[0]->dest);
    6955           24 :   PENDING_STMT (e) = NULL;
    6956              : 
    6957              :   /* Anything that is outside of the region, but was dominated by something
    6958              :      inside needs to update dominance info.  */
    6959           24 :   iterate_fix_dominators (CDI_DOMINATORS, doms, false);
    6960              : 
    6961           24 :   if (free_region_copy)
    6962            0 :     free (region_copy);
    6963              : 
    6964           24 :   free_original_copy_tables ();
    6965           24 :   return true;
    6966           24 : }
    6967              : 
    6968              : /* Add all the blocks dominated by ENTRY to the array BBS_P.  Stop
    6969              :    adding blocks when the dominator traversal reaches EXIT.  This
    6970              :    function silently assumes that ENTRY strictly dominates EXIT.  */
    6971              : 
    6972              : void
    6973       599884 : gather_blocks_in_sese_region (basic_block entry, basic_block exit,
    6974              :                               vec<basic_block> *bbs_p)
    6975              : {
    6976       599884 :   basic_block son;
    6977              : 
    6978       599884 :   for (son = first_dom_son (CDI_DOMINATORS, entry);
    6979      1199648 :        son;
    6980       599764 :        son = next_dom_son (CDI_DOMINATORS, son))
    6981              :     {
    6982       599764 :       bbs_p->safe_push (son);
    6983       599764 :       if (son != exit)
    6984       555872 :         gather_blocks_in_sese_region (son, exit, bbs_p);
    6985              :     }
    6986       599884 : }
    6987              : 
    6988              : /* Replaces *TP with a duplicate (belonging to function TO_CONTEXT).
    6989              :    The duplicates are recorded in VARS_MAP.  */
    6990              : 
    6991              : static void
    6992      4421886 : replace_by_duplicate_decl (tree *tp, hash_map<tree, tree> *vars_map,
    6993              :                            tree to_context)
    6994              : {
    6995      4421886 :   tree t = *tp, new_t;
    6996      4421886 :   struct function *f = DECL_STRUCT_FUNCTION (to_context);
    6997              : 
    6998      4421886 :   if (DECL_CONTEXT (t) == to_context)
    6999        35344 :     return;
    7000              : 
    7001      4386542 :   bool existed;
    7002      4386542 :   tree &loc = vars_map->get_or_insert (t, &existed);
    7003              : 
    7004      4386542 :   if (!existed)
    7005              :     {
    7006      1295722 :       if (SSA_VAR_P (t))
    7007              :         {
    7008      1285124 :           new_t = copy_var_decl (t, DECL_NAME (t), TREE_TYPE (t));
    7009      1285124 :           add_local_decl (f, new_t);
    7010              :         }
    7011              :       else
    7012              :         {
    7013        10598 :           gcc_assert (TREE_CODE (t) == CONST_DECL);
    7014        10598 :           new_t = copy_node (t);
    7015              :         }
    7016      1295722 :       DECL_CONTEXT (new_t) = to_context;
    7017              : 
    7018      1295722 :       loc = new_t;
    7019              :     }
    7020              :   else
    7021      3090820 :     new_t = loc;
    7022              : 
    7023      4386542 :   *tp = new_t;
    7024              : }
    7025              : 
    7026              : 
    7027              : /* Creates an ssa name in TO_CONTEXT equivalent to NAME.
    7028              :    VARS_MAP maps old ssa names and var_decls to the new ones.  */
    7029              : 
    7030              : static tree
    7031        13734 : replace_ssa_name (tree name, hash_map<tree, tree> *vars_map,
    7032              :                   tree to_context)
    7033              : {
    7034        13734 :   tree new_name;
    7035              : 
    7036        27468 :   gcc_assert (!virtual_operand_p (name));
    7037              : 
    7038        13734 :   tree *loc = vars_map->get (name);
    7039              : 
    7040        13734 :   if (!loc)
    7041              :     {
    7042         5737 :       tree decl = SSA_NAME_VAR (name);
    7043         5737 :       if (decl)
    7044              :         {
    7045         1204 :           gcc_assert (!SSA_NAME_IS_DEFAULT_DEF (name));
    7046         1204 :           replace_by_duplicate_decl (&decl, vars_map, to_context);
    7047         1204 :           new_name = make_ssa_name_fn (DECL_STRUCT_FUNCTION (to_context),
    7048         1204 :                                        decl, SSA_NAME_DEF_STMT (name));
    7049              :         }
    7050              :       else
    7051         4533 :         new_name = copy_ssa_name_fn (DECL_STRUCT_FUNCTION (to_context),
    7052         4533 :                                      name, SSA_NAME_DEF_STMT (name));
    7053              : 
    7054              :       /* Now that we've used the def stmt to define new_name, make sure it
    7055              :          doesn't define name anymore.  */
    7056         5737 :       SSA_NAME_DEF_STMT (name) = NULL;
    7057              : 
    7058         5737 :       vars_map->put (name, new_name);
    7059              :     }
    7060              :   else
    7061         7997 :     new_name = *loc;
    7062              : 
    7063        13734 :   return new_name;
    7064              : }
    7065              : 
    7066              : struct move_stmt_d
    7067              : {
    7068              :   tree orig_block;
    7069              :   tree new_block;
    7070              :   tree from_context;
    7071              :   tree to_context;
    7072              :   hash_map<tree, tree> *vars_map;
    7073              :   htab_t new_label_map;
    7074              :   hash_map<void *, void *> *eh_map;
    7075              :   bool remap_decls_p;
    7076              : };
    7077              : 
    7078              : /* Helper for move_block_to_fn.  Set TREE_BLOCK in every expression
    7079              :    contained in *TP if it has been ORIG_BLOCK previously and change the
    7080              :    DECL_CONTEXT of every local variable referenced in *TP.  */
    7081              : 
    7082              : static tree
    7083      7335380 : move_stmt_op (tree *tp, int *walk_subtrees, void *data)
    7084              : {
    7085      7335380 :   struct walk_stmt_info *wi = (struct walk_stmt_info *) data;
    7086      7335380 :   struct move_stmt_d *p = (struct move_stmt_d *) wi->info;
    7087      7335380 :   tree t = *tp;
    7088              : 
    7089      7335380 :   if (EXPR_P (t))
    7090              :     {
    7091      1159701 :       tree block = TREE_BLOCK (t);
    7092      1159701 :       if (block == NULL_TREE)
    7093              :         ;
    7094        30429 :       else if (block == p->orig_block
    7095        28464 :                || p->orig_block == NULL_TREE)
    7096              :         {
    7097              :           /* tree_node_can_be_shared says we can share invariant
    7098              :              addresses but unshare_expr copies them anyways.  Make sure
    7099              :              to unshare before adjusting the block in place - we do not
    7100              :              always see a copy here.  */
    7101         1989 :           if (TREE_CODE (t) == ADDR_EXPR
    7102         1989 :               && is_gimple_min_invariant (t))
    7103         1965 :             *tp = t = unshare_expr (t);
    7104         1989 :           TREE_SET_BLOCK (t, p->new_block);
    7105              :         }
    7106        28440 :       else if (flag_checking)
    7107              :         {
    7108       102743 :           while (block && TREE_CODE (block) == BLOCK && block != p->orig_block)
    7109        74303 :             block = BLOCK_SUPERCONTEXT (block);
    7110        28440 :           gcc_assert (block == p->orig_block);
    7111              :         }
    7112              :     }
    7113      6175679 :   else if (DECL_P (t) || TREE_CODE (t) == SSA_NAME)
    7114              :     {
    7115      4490615 :       if (TREE_CODE (t) == SSA_NAME)
    7116        12176 :         *tp = replace_ssa_name (t, p->vars_map, p->to_context);
    7117      4478439 :       else if (TREE_CODE (t) == PARM_DECL
    7118      4478439 :                && gimple_in_ssa_p (cfun))
    7119          184 :         *tp = *(p->vars_map->get (t));
    7120      4478255 :       else if (TREE_CODE (t) == LABEL_DECL)
    7121              :         {
    7122         2796 :           if (p->new_label_map)
    7123              :             {
    7124          461 :               struct tree_map in, *out;
    7125          461 :               in.base.from = t;
    7126          461 :               out = (struct tree_map *)
    7127          461 :                 htab_find_with_hash (p->new_label_map, &in, DECL_UID (t));
    7128          461 :               if (out)
    7129           13 :                 *tp = t = out->to;
    7130              :             }
    7131              : 
    7132              :           /* For FORCED_LABELs we can end up with references from other
    7133              :              functions if some SESE regions are outlined.  It is UB to
    7134              :              jump in between them, but they could be used just for printing
    7135              :              addresses etc.  In that case, DECL_CONTEXT on the label should
    7136              :              be the function containing the glabel stmt with that LABEL_DECL,
    7137              :              rather than whatever function a reference to the label was seen
    7138              :              last time.  */
    7139         2796 :           if (!FORCED_LABEL (t) && !DECL_NONLOCAL (t))
    7140         2789 :             DECL_CONTEXT (t) = p->to_context;
    7141              :         }
    7142      4475459 :       else if (p->remap_decls_p)
    7143              :         {
    7144              :           /* Replace T with its duplicate.  T should no longer appear in the
    7145              :              parent function, so this looks wasteful; however, it may appear
    7146              :              in referenced_vars, and more importantly, as virtual operands of
    7147              :              statements, and in alias lists of other variables.  It would be
    7148              :              quite difficult to expunge it from all those places.  ??? It might
    7149              :              suffice to do this for addressable variables.  */
    7150      3744962 :           if ((VAR_P (t) && !is_global_var (t))
    7151      4516122 :               || TREE_CODE (t) == CONST_DECL)
    7152      3714691 :             replace_by_duplicate_decl (tp, p->vars_map, p->to_context);
    7153              :         }
    7154      4490615 :       *walk_subtrees = 0;
    7155      4490615 :     }
    7156      1685064 :   else if (TYPE_P (t))
    7157            0 :     *walk_subtrees = 0;
    7158              : 
    7159      7335380 :   return NULL_TREE;
    7160              : }
    7161              : 
    7162              : /* Helper for move_stmt_r.  Given an EH region number for the source
    7163              :    function, map that to the duplicate EH region number in the dest.  */
    7164              : 
    7165              : static int
    7166           18 : move_stmt_eh_region_nr (int old_nr, struct move_stmt_d *p)
    7167              : {
    7168           18 :   eh_region old_r, new_r;
    7169              : 
    7170           18 :   old_r = get_eh_region_from_number (old_nr);
    7171           18 :   new_r = static_cast<eh_region> (*p->eh_map->get (old_r));
    7172              : 
    7173           18 :   return new_r->index;
    7174              : }
    7175              : 
    7176              : /* Similar, but operate on INTEGER_CSTs.  */
    7177              : 
    7178              : static tree
    7179            5 : move_stmt_eh_region_tree_nr (tree old_t_nr, struct move_stmt_d *p)
    7180              : {
    7181            5 :   int old_nr, new_nr;
    7182              : 
    7183            5 :   old_nr = tree_to_shwi (old_t_nr);
    7184            5 :   new_nr = move_stmt_eh_region_nr (old_nr, p);
    7185              : 
    7186            5 :   return build_int_cst (integer_type_node, new_nr);
    7187              : }
    7188              : 
    7189              : /* Like move_stmt_op, but for gimple statements.
    7190              : 
    7191              :    Helper for move_block_to_fn.  Set GIMPLE_BLOCK in every expression
    7192              :    contained in the current statement in *GSI_P and change the
    7193              :    DECL_CONTEXT of every local variable referenced in the current
    7194              :    statement.  */
    7195              : 
    7196              : static tree
    7197      2057371 : move_stmt_r (gimple_stmt_iterator *gsi_p, bool *handled_ops_p,
    7198              :              struct walk_stmt_info *wi)
    7199              : {
    7200      2057371 :   struct move_stmt_d *p = (struct move_stmt_d *) wi->info;
    7201      2057371 :   gimple *stmt = gsi_stmt (*gsi_p);
    7202      2057371 :   tree block = gimple_block (stmt);
    7203              : 
    7204      2057371 :   if (block == p->orig_block
    7205      1826570 :       || (p->orig_block == NULL_TREE
    7206          958 :           && block != NULL_TREE))
    7207       231759 :     gimple_set_block (stmt, p->new_block);
    7208              : 
    7209      2057371 :   switch (gimple_code (stmt))
    7210              :     {
    7211       290500 :     case GIMPLE_CALL:
    7212              :       /* Remap the region numbers for __builtin_eh_{pointer,filter}.  */
    7213       290500 :       {
    7214       290500 :         tree r, fndecl = gimple_call_fndecl (stmt);
    7215       290500 :         if (fndecl && fndecl_built_in_p (fndecl, BUILT_IN_NORMAL))
    7216        95766 :           switch (DECL_FUNCTION_CODE (fndecl))
    7217              :             {
    7218            0 :             case BUILT_IN_EH_COPY_VALUES:
    7219            0 :               r = gimple_call_arg (stmt, 1);
    7220            0 :               r = move_stmt_eh_region_tree_nr (r, p);
    7221            0 :               gimple_call_set_arg (stmt, 1, r);
    7222              :               /* FALLTHRU */
    7223              : 
    7224            5 :             case BUILT_IN_EH_POINTER:
    7225            5 :             case BUILT_IN_EH_FILTER:
    7226            5 :               r = gimple_call_arg (stmt, 0);
    7227            5 :               r = move_stmt_eh_region_tree_nr (r, p);
    7228            5 :               gimple_call_set_arg (stmt, 0, r);
    7229            5 :               break;
    7230              : 
    7231              :             default:
    7232              :               break;
    7233              :             }
    7234              :       }
    7235              :       break;
    7236              : 
    7237            8 :     case GIMPLE_RESX:
    7238            8 :       {
    7239            8 :         gresx *resx_stmt = as_a <gresx *> (stmt);
    7240            8 :         int r = gimple_resx_region (resx_stmt);
    7241            8 :         r = move_stmt_eh_region_nr (r, p);
    7242            8 :         gimple_resx_set_region (resx_stmt, r);
    7243              :       }
    7244            8 :       break;
    7245              : 
    7246            5 :     case GIMPLE_EH_DISPATCH:
    7247            5 :       {
    7248            5 :         geh_dispatch *eh_dispatch_stmt = as_a <geh_dispatch *> (stmt);
    7249            5 :         int r = gimple_eh_dispatch_region (eh_dispatch_stmt);
    7250            5 :         r = move_stmt_eh_region_nr (r, p);
    7251            5 :         gimple_eh_dispatch_set_region (eh_dispatch_stmt, r);
    7252              :       }
    7253            5 :       break;
    7254              : 
    7255              :     case GIMPLE_OMP_RETURN:
    7256              :     case GIMPLE_OMP_CONTINUE:
    7257              :       break;
    7258              : 
    7259         1406 :     case GIMPLE_LABEL:
    7260         1406 :       {
    7261              :         /* For FORCED_LABEL, move_stmt_op doesn't adjust DECL_CONTEXT,
    7262              :            so that such labels can be referenced from other regions.
    7263              :            Make sure to update it when seeing a GIMPLE_LABEL though,
    7264              :            that is the owner of the label.  */
    7265         1406 :         walk_gimple_op (stmt, move_stmt_op, wi);
    7266         1406 :         *handled_ops_p = true;
    7267         1406 :         tree label = gimple_label_label (as_a <glabel *> (stmt));
    7268         1406 :         if (FORCED_LABEL (label) || DECL_NONLOCAL (label))
    7269            5 :           DECL_CONTEXT (label) = p->to_context;
    7270              :       }
    7271              :       break;
    7272              : 
    7273      1765452 :     default:
    7274      1765452 :       if (is_gimple_omp (stmt))
    7275              :         {
    7276              :           /* Do not remap variables inside OMP directives.  Variables
    7277              :              referenced in clauses and directive header belong to the
    7278              :              parent function and should not be moved into the child
    7279              :              function.  */
    7280            0 :           bool save_remap_decls_p = p->remap_decls_p;
    7281            0 :           p->remap_decls_p = false;
    7282            0 :           *handled_ops_p = true;
    7283              : 
    7284            0 :           walk_gimple_seq_mod (gimple_omp_body_ptr (stmt), move_stmt_r,
    7285              :                                move_stmt_op, wi);
    7286              : 
    7287            0 :           p->remap_decls_p = save_remap_decls_p;
    7288              :         }
    7289              :       break;
    7290              :     }
    7291              : 
    7292      2057371 :   return NULL_TREE;
    7293              : }
    7294              : 
    7295              : /* Move basic block BB from function CFUN to function DEST_FN.  The
    7296              :    block is moved out of the original linked list and placed after
    7297              :    block AFTER in the new list.  Also, the block is removed from the
    7298              :    original array of blocks and placed in DEST_FN's array of blocks.
    7299              :    If UPDATE_EDGE_COUNT_P is true, the edge counts on both CFGs is
    7300              :    updated to reflect the moved edges.
    7301              : 
    7302              :    The local variables are remapped to new instances, VARS_MAP is used
    7303              :    to record the mapping.  */
    7304              : 
    7305              : static void
    7306       641582 : move_block_to_fn (struct function *dest_cfun, basic_block bb,
    7307              :                   basic_block after, bool update_edge_count_p,
    7308              :                   struct move_stmt_d *d)
    7309              : {
    7310       641582 :   struct control_flow_graph *cfg;
    7311       641582 :   edge_iterator ei;
    7312       641582 :   edge e;
    7313       641582 :   gimple_stmt_iterator si;
    7314       641582 :   unsigned old_len;
    7315              : 
    7316              :   /* Remove BB from dominance structures.  */
    7317       641582 :   delete_from_dominance_info (CDI_DOMINATORS, bb);
    7318              : 
    7319              :   /* Move BB from its current loop to the copy in the new function.  */
    7320       641582 :   if (current_loops)
    7321              :     {
    7322       641582 :       class loop *new_loop = (class loop *)bb->loop_father->aux;
    7323       641582 :       if (new_loop)
    7324       360836 :         bb->loop_father = new_loop;
    7325              :     }
    7326              : 
    7327              :   /* Link BB to the new linked list.  */
    7328       641582 :   move_block_after (bb, after);
    7329              : 
    7330              :   /* Update the edge count in the corresponding flowgraphs.  */
    7331       641582 :   if (update_edge_count_p)
    7332      1374753 :     FOR_EACH_EDGE (e, ei, bb->succs)
    7333              :       {
    7334       776671 :         cfun->cfg->x_n_edges--;
    7335       776671 :         dest_cfun->cfg->x_n_edges++;
    7336              :       }
    7337              : 
    7338              :   /* Remove BB from the original basic block array.  */
    7339       641582 :   (*cfun->cfg->x_basic_block_info)[bb->index] = NULL;
    7340       641582 :   cfun->cfg->x_n_basic_blocks--;
    7341              : 
    7342              :   /* Grow DEST_CFUN's basic block array if needed.  */
    7343       641582 :   cfg = dest_cfun->cfg;
    7344       641582 :   cfg->x_n_basic_blocks++;
    7345       641582 :   if (bb->index >= cfg->x_last_basic_block)
    7346        43620 :     cfg->x_last_basic_block = bb->index + 1;
    7347              : 
    7348       641582 :   old_len = vec_safe_length (cfg->x_basic_block_info);
    7349       641582 :   if ((unsigned) cfg->x_last_basic_block >= old_len)
    7350        35240 :     vec_safe_grow_cleared (cfg->x_basic_block_info,
    7351        35240 :                            cfg->x_last_basic_block + 1);
    7352              : 
    7353       641582 :   (*cfg->x_basic_block_info)[bb->index] = bb;
    7354              : 
    7355              :   /* Remap the variables in phi nodes.  */
    7356       641582 :   for (gphi_iterator psi = gsi_start_phis (bb);
    7357       642766 :        !gsi_end_p (psi); )
    7358              :     {
    7359         1184 :       gphi *phi = psi.phi ();
    7360         1184 :       use_operand_p use;
    7361         1184 :       tree op = PHI_RESULT (phi);
    7362         1184 :       ssa_op_iter oi;
    7363         1184 :       unsigned i;
    7364              : 
    7365         2368 :       if (virtual_operand_p (op))
    7366              :         {
    7367              :           /* Remove the phi nodes for virtual operands (alias analysis will be
    7368              :              run for the new function, anyway).  But replace all uses that
    7369              :              might be outside of the region we move.  */
    7370          534 :           use_operand_p use_p;
    7371          534 :           imm_use_iterator iter;
    7372          534 :           gimple *use_stmt;
    7373         1593 :           FOR_EACH_IMM_USE_STMT (use_stmt, iter, op)
    7374         1575 :             FOR_EACH_IMM_USE_ON_STMT (use_p, iter)
    7375          525 :               SET_USE (use_p, SSA_NAME_VAR (op));
    7376          534 :           remove_phi_node (&psi, true);
    7377          534 :           continue;
    7378          534 :         }
    7379              : 
    7380          650 :       SET_PHI_RESULT (phi,
    7381              :                       replace_ssa_name (op, d->vars_map, dest_cfun->decl));
    7382         1711 :       FOR_EACH_PHI_ARG (use, phi, oi, SSA_OP_USE)
    7383              :         {
    7384         1061 :           op = USE_FROM_PTR (use);
    7385         1061 :           if (TREE_CODE (op) == SSA_NAME)
    7386          908 :             SET_USE (use, replace_ssa_name (op, d->vars_map, dest_cfun->decl));
    7387              :         }
    7388              : 
    7389         1711 :       for (i = 0; i < EDGE_COUNT (bb->preds); i++)
    7390              :         {
    7391         1061 :           location_t locus = gimple_phi_arg_location (phi, i);
    7392         1061 :           tree block = LOCATION_BLOCK (locus);
    7393              : 
    7394         1061 :           if (locus == UNKNOWN_LOCATION)
    7395          898 :             continue;
    7396          163 :           if (d->orig_block == NULL_TREE || block == d->orig_block)
    7397              :             {
    7398          163 :               locus = set_block (locus, d->new_block);
    7399          163 :               gimple_phi_arg_set_location (phi, i, locus);
    7400              :             }
    7401              :         }
    7402              : 
    7403          650 :       gsi_next (&psi);
    7404              :     }
    7405              : 
    7406      3340535 :   for (si = gsi_start_bb (bb); !gsi_end_p (si); gsi_next (&si))
    7407              :     {
    7408      2057371 :       gimple *stmt = gsi_stmt (si);
    7409      2057371 :       struct walk_stmt_info wi;
    7410              : 
    7411      2057371 :       memset (&wi, 0, sizeof (wi));
    7412      2057371 :       wi.info = d;
    7413      2057371 :       walk_gimple_stmt (&si, move_stmt_r, move_stmt_op, &wi);
    7414              : 
    7415      2057371 :       if (glabel *label_stmt = dyn_cast <glabel *> (stmt))
    7416              :         {
    7417         1406 :           tree label = gimple_label_label (label_stmt);
    7418         1406 :           int uid = LABEL_DECL_UID (label);
    7419              : 
    7420         1406 :           gcc_assert (uid > -1);
    7421              : 
    7422         1406 :           old_len = vec_safe_length (cfg->x_label_to_block_map);
    7423         1406 :           if (old_len <= (unsigned) uid)
    7424          171 :             vec_safe_grow_cleared (cfg->x_label_to_block_map, uid + 1);
    7425              : 
    7426         1406 :           (*cfg->x_label_to_block_map)[uid] = bb;
    7427         1406 :           (*cfun->cfg->x_label_to_block_map)[uid] = NULL;
    7428              : 
    7429         1406 :           gcc_assert (DECL_CONTEXT (label) == dest_cfun->decl);
    7430              : 
    7431         1406 :           if (uid >= dest_cfun->cfg->last_label_uid)
    7432          316 :             dest_cfun->cfg->last_label_uid = uid + 1;
    7433              :         }
    7434              : 
    7435      2057371 :       maybe_duplicate_eh_stmt_fn (dest_cfun, stmt, cfun, stmt, d->eh_map, 0);
    7436      2057371 :       remove_stmt_from_eh_lp_fn (cfun, stmt);
    7437              : 
    7438      2057371 :       gimple_duplicate_stmt_histograms (dest_cfun, stmt, cfun, stmt);
    7439      2057371 :       gimple_remove_stmt_histograms (cfun, stmt);
    7440              : 
    7441              :       /* We cannot leave any operands allocated from the operand caches of
    7442              :          the current function.  */
    7443      2057371 :       free_stmt_operands (cfun, stmt);
    7444      2057371 :       push_cfun (dest_cfun);
    7445      2057371 :       update_stmt (stmt);
    7446      2057371 :       if (is_gimple_call (stmt))
    7447       290500 :         notice_special_calls (as_a <gcall *> (stmt));
    7448      2057371 :       pop_cfun ();
    7449              :     }
    7450              : 
    7451      1418253 :   FOR_EACH_EDGE (e, ei, bb->succs)
    7452       776671 :     if (e->goto_locus != UNKNOWN_LOCATION)
    7453              :       {
    7454        35245 :         tree block = LOCATION_BLOCK (e->goto_locus);
    7455        35245 :         if (d->orig_block == NULL_TREE
    7456        35243 :             || block == d->orig_block)
    7457         2611 :           e->goto_locus = set_block (e->goto_locus, d->new_block);
    7458              :       }
    7459       641582 : }
    7460              : 
    7461              : /* Examine the statements in BB (which is in SRC_CFUN); find and return
    7462              :    the outermost EH region.  Use REGION as the incoming base EH region.
    7463              :    If there is no single outermost region, return NULL and set *ALL to
    7464              :    true.  */
    7465              : 
    7466              : static eh_region
    7467       641577 : find_outermost_region_in_block (struct function *src_cfun,
    7468              :                                 basic_block bb, eh_region region,
    7469              :                                 bool *all)
    7470              : {
    7471       641577 :   gimple_stmt_iterator si;
    7472              : 
    7473      3340513 :   for (si = gsi_start_bb (bb); !gsi_end_p (si); gsi_next (&si))
    7474              :     {
    7475      2057360 :       gimple *stmt = gsi_stmt (si);
    7476      2057360 :       eh_region stmt_region;
    7477      2057360 :       int lp_nr;
    7478              : 
    7479      2057360 :       lp_nr = lookup_stmt_eh_lp_fn (src_cfun, stmt);
    7480      2057360 :       stmt_region = get_eh_region_from_lp_number_fn (src_cfun, lp_nr);
    7481      2057360 :       if (stmt_region)
    7482              :         {
    7483         3805 :           if (region == NULL)
    7484              :             region = stmt_region;
    7485         1804 :           else if (stmt_region != region)
    7486              :             {
    7487          249 :               region = eh_region_outermost (src_cfun, stmt_region, region);
    7488          249 :               if (region == NULL)
    7489              :                 {
    7490            1 :                   *all = true;
    7491            1 :                   return NULL;
    7492              :                 }
    7493              :             }
    7494              :         }
    7495              :     }
    7496              : 
    7497              :   return region;
    7498              : }
    7499              : 
    7500              : static tree
    7501           13 : new_label_mapper (tree decl, void *data)
    7502              : {
    7503           13 :   htab_t hash = (htab_t) data;
    7504           13 :   struct tree_map *m;
    7505           13 :   void **slot;
    7506              : 
    7507           13 :   gcc_assert (TREE_CODE (decl) == LABEL_DECL);
    7508              : 
    7509           13 :   m = XNEW (struct tree_map);
    7510           13 :   m->hash = DECL_UID (decl);
    7511           13 :   m->base.from = decl;
    7512           13 :   m->to = create_artificial_label (UNKNOWN_LOCATION);
    7513           13 :   LABEL_DECL_UID (m->to) = LABEL_DECL_UID (decl);
    7514           13 :   if (LABEL_DECL_UID (m->to) >= cfun->cfg->last_label_uid)
    7515            5 :     cfun->cfg->last_label_uid = LABEL_DECL_UID (m->to) + 1;
    7516              : 
    7517           13 :   slot = htab_find_slot_with_hash (hash, m, m->hash, INSERT);
    7518           13 :   gcc_assert (*slot == NULL);
    7519              : 
    7520           13 :   *slot = m;
    7521              : 
    7522           13 :   return m->to;
    7523              : }
    7524              : 
    7525              : /* Tree walker to replace the decls used inside value expressions by
    7526              :    duplicates.  */
    7527              : 
    7528              : static tree
    7529       264605 : replace_block_vars_by_duplicates_1 (tree *tp, int *walk_subtrees, void *data)
    7530              : {
    7531       264605 :   struct replace_decls_d *rd = (struct replace_decls_d *)data;
    7532              : 
    7533       264605 :   switch (TREE_CODE (*tp))
    7534              :     {
    7535        50307 :     case VAR_DECL:
    7536        50307 :     case PARM_DECL:
    7537        50307 :     case RESULT_DECL:
    7538        50307 :       replace_by_duplicate_decl (tp, rd->vars_map, rd->to_context);
    7539        50307 :       break;
    7540              :     default:
    7541              :       break;
    7542              :     }
    7543              : 
    7544       264605 :   if (IS_TYPE_OR_DECL_P (*tp))
    7545        85685 :     *walk_subtrees = false;
    7546              : 
    7547       264605 :   return NULL;
    7548              : }
    7549              : 
    7550              : /* Change DECL_CONTEXT of all BLOCK_VARS in block, including
    7551              :    subblocks.  */
    7552              : 
    7553              : static void
    7554       169953 : replace_block_vars_by_duplicates (tree block, hash_map<tree, tree> *vars_map,
    7555              :                                   tree to_context)
    7556              : {
    7557       169953 :   tree *tp, t;
    7558              : 
    7559       830430 :   for (tp = &BLOCK_VARS (block); *tp; tp = &DECL_CHAIN (*tp))
    7560              :     {
    7561       660477 :       t = *tp;
    7562       660477 :       if (!VAR_P (t) && TREE_CODE (t) != CONST_DECL)
    7563         7188 :         continue;
    7564       653289 :       replace_by_duplicate_decl (&t, vars_map, to_context);
    7565       653289 :       if (t != *tp)
    7566              :         {
    7567       653289 :           if (VAR_P (*tp) && DECL_HAS_VALUE_EXPR_P (*tp))
    7568              :             {
    7569        45415 :               tree x = DECL_VALUE_EXPR (*tp);
    7570        45415 :               struct replace_decls_d rd = { vars_map, to_context };
    7571        45415 :               unshare_expr (x);
    7572        45415 :               walk_tree (&x, replace_block_vars_by_duplicates_1, &rd, NULL);
    7573        45415 :               SET_DECL_VALUE_EXPR (t, x);
    7574        45415 :               DECL_HAS_VALUE_EXPR_P (t) = 1;
    7575              :             }
    7576       653289 :           DECL_CHAIN (t) = DECL_CHAIN (*tp);
    7577       653289 :           *tp = t;
    7578              :         }
    7579              :     }
    7580              : 
    7581       296286 :   for (block = BLOCK_SUBBLOCKS (block); block; block = BLOCK_CHAIN (block))
    7582       126333 :     replace_block_vars_by_duplicates (block, vars_map, to_context);
    7583       169953 : }
    7584              : 
    7585              : /* Fixup the loop arrays and numbers after moving LOOP and its subloops
    7586              :    from FN1 to FN2.  */
    7587              : 
    7588              : static void
    7589        71321 : fixup_loop_arrays_after_move (struct function *fn1, struct function *fn2,
    7590              :                               class loop *loop)
    7591              : {
    7592              :   /* Discard it from the old loop array.  */
    7593       142642 :   (*get_loops (fn1))[loop->num] = NULL;
    7594              : 
    7595              :   /* Place it in the new loop array, assigning it a new number.  */
    7596        71321 :   loop->num = number_of_loops (fn2);
    7597        71321 :   vec_safe_push (loops_for_fn (fn2)->larray, loop);
    7598              : 
    7599              :   /* Recurse to children.  */
    7600       102029 :   for (loop = loop->inner; loop; loop = loop->next)
    7601        30708 :     fixup_loop_arrays_after_move (fn1, fn2, loop);
    7602        71321 : }
    7603              : 
    7604              : /* Verify that the blocks in BBS_P are a single-entry, single-exit region
    7605              :    delimited by ENTRY_BB and EXIT_BB, possibly containing noreturn blocks.  */
    7606              : 
    7607              : DEBUG_FUNCTION void
    7608        43620 : verify_sese (basic_block entry, basic_block exit, vec<basic_block> *bbs_p)
    7609              : {
    7610        43620 :   basic_block bb;
    7611        43620 :   edge_iterator ei;
    7612        43620 :   edge e;
    7613        43620 :   bitmap bbs = BITMAP_ALLOC (NULL);
    7614        43620 :   int i;
    7615              : 
    7616        43620 :   gcc_assert (entry != NULL);
    7617        43620 :   gcc_assert (entry != exit);
    7618        43620 :   gcc_assert (bbs_p != NULL);
    7619              : 
    7620        43620 :   gcc_assert (bbs_p->length () > 0);
    7621              : 
    7622       685202 :   FOR_EACH_VEC_ELT (*bbs_p, i, bb)
    7623       641582 :     bitmap_set_bit (bbs, bb->index);
    7624              : 
    7625        43620 :   gcc_assert (bitmap_bit_p (bbs, entry->index));
    7626        43620 :   gcc_assert (exit == NULL || bitmap_bit_p (bbs, exit->index));
    7627              : 
    7628       685202 :   FOR_EACH_VEC_ELT (*bbs_p, i, bb)
    7629              :     {
    7630       641582 :       if (bb == entry)
    7631              :         {
    7632        43620 :           gcc_assert (single_pred_p (entry));
    7633        43620 :           gcc_assert (!bitmap_bit_p (bbs, single_pred (entry)->index));
    7634              :         }
    7635              :       else
    7636      1374633 :         for (ei = ei_start (bb->preds); !ei_end_p (ei); ei_next (&ei))
    7637              :           {
    7638       776671 :             e = ei_edge (ei);
    7639       776671 :             gcc_assert (bitmap_bit_p (bbs, e->src->index));
    7640              :           }
    7641              : 
    7642       641582 :       if (bb == exit)
    7643              :         {
    7644        43500 :           gcc_assert (single_succ_p (exit));
    7645        43500 :           gcc_assert (!bitmap_bit_p (bbs, single_succ (exit)->index));
    7646              :         }
    7647              :       else
    7648      1374753 :         for (ei = ei_start (bb->succs); !ei_end_p (ei); ei_next (&ei))
    7649              :           {
    7650       776671 :             e = ei_edge (ei);
    7651       776671 :             gcc_assert (bitmap_bit_p (bbs, e->dest->index));
    7652              :           }
    7653              :     }
    7654              : 
    7655        43620 :   BITMAP_FREE (bbs);
    7656        43620 : }
    7657              : 
    7658              : /* If FROM is an SSA_NAME, mark the version in bitmap DATA.  */
    7659              : 
    7660              : bool
    7661      1301655 : gather_ssa_name_hash_map_from (tree const &from, tree const &, void *data)
    7662              : {
    7663      1301655 :   bitmap release_names = (bitmap)data;
    7664              : 
    7665      1301655 :   if (TREE_CODE (from) != SSA_NAME)
    7666              :     return true;
    7667              : 
    7668         5737 :   bitmap_set_bit (release_names, SSA_NAME_VERSION (from));
    7669         5737 :   return true;
    7670              : }
    7671              : 
    7672              : /* Return LOOP_DIST_ALIAS call if present in BB.  */
    7673              : 
    7674              : static gimple *
    7675          113 : find_loop_dist_alias (basic_block bb)
    7676              : {
    7677          113 :   gimple_stmt_iterator gsi = gsi_last_bb (bb);
    7678          113 :   if (!safe_is_a <gcond *> (*gsi))
    7679              :     return NULL;
    7680              : 
    7681           30 :   gsi_prev (&gsi);
    7682           30 :   if (gsi_end_p (gsi))
    7683              :     return NULL;
    7684              : 
    7685           22 :   gimple *g = gsi_stmt (gsi);
    7686           22 :   if (gimple_call_internal_p (g, IFN_LOOP_DIST_ALIAS))
    7687            1 :     return g;
    7688              :   return NULL;
    7689              : }
    7690              : 
    7691              : /* Fold loop internal call G like IFN_LOOP_VECTORIZED/IFN_LOOP_DIST_ALIAS
    7692              :    to VALUE and update any immediate uses of it's LHS.  */
    7693              : 
    7694              : void
    7695        29247 : fold_loop_internal_call (gimple *g, tree value)
    7696              : {
    7697        29247 :   tree lhs = gimple_call_lhs (g);
    7698        29247 :   use_operand_p use_p;
    7699        29247 :   imm_use_iterator iter;
    7700        29247 :   gimple *use_stmt;
    7701        29247 :   gimple_stmt_iterator gsi = gsi_for_stmt (g);
    7702              : 
    7703        29247 :   replace_call_with_value (&gsi, value);
    7704        87648 :   FOR_EACH_IMM_USE_STMT (use_stmt, iter, lhs)
    7705              :     {
    7706        87462 :       FOR_EACH_IMM_USE_ON_STMT (use_p, iter)
    7707        29154 :         SET_USE (use_p, value);
    7708        29154 :       update_stmt (use_stmt);
    7709              :       /* If we turn conditional to constant, scale profile counts.
    7710              :          We know that the conditional was created by loop distribution
    7711              :          and all basic blocks dominated by the taken edge are part of
    7712              :          the loop distributed.  */
    7713        29154 :       if (gimple_code (use_stmt) == GIMPLE_COND)
    7714              :         {
    7715        29154 :           edge true_edge, false_edge;
    7716        29154 :           extract_true_false_edges_from_block (gimple_bb (use_stmt),
    7717              :                                                &true_edge, &false_edge);
    7718        29154 :           edge taken_edge = NULL, other_edge = NULL;
    7719        29154 :           if (gimple_cond_true_p (as_a <gcond *>(use_stmt)))
    7720              :             {
    7721         7794 :               taken_edge = true_edge;
    7722         7794 :               other_edge = false_edge;
    7723              :             }
    7724        21360 :           else if (gimple_cond_false_p (as_a <gcond *>(use_stmt)))
    7725              :             {
    7726        21351 :               taken_edge = false_edge;
    7727        21351 :               other_edge = true_edge;
    7728              :             }
    7729        29145 :           if (taken_edge
    7730        29154 :               && !(taken_edge->probability == profile_probability::always ()))
    7731              :             {
    7732           30 :               profile_count old_count = taken_edge->count ();
    7733           30 :               profile_count new_count = taken_edge->src->count;
    7734           30 :               taken_edge->probability = profile_probability::always ();
    7735           30 :               other_edge->probability = profile_probability::never ();
    7736              :               /* If we have multiple predecessors, we can't use the dominance
    7737              :                  test.  This should not happen as the guarded code should
    7738              :                  start with pre-header.  */
    7739           30 :               gcc_assert (single_pred_edge (taken_edge->dest));
    7740           60 :               if (old_count.nonzero_p ())
    7741              :                 {
    7742           28 :                   taken_edge->dest->count
    7743           28 :                     = taken_edge->dest->count.apply_scale (new_count,
    7744              :                                                            old_count);
    7745           28 :                   scale_strictly_dominated_blocks (taken_edge->dest,
    7746              :                                                    new_count, old_count);
    7747              :                 }
    7748              :             }
    7749              :         }
    7750        29247 :     }
    7751        29247 : }
    7752              : 
    7753              : /* Move a single-entry, single-exit region delimited by ENTRY_BB and
    7754              :    EXIT_BB to function DEST_CFUN.  The whole region is replaced by a
    7755              :    single basic block in the original CFG and the new basic block is
    7756              :    returned.  DEST_CFUN must not have a CFG yet.
    7757              : 
    7758              :    Note that the region need not be a pure SESE region.  Blocks inside
    7759              :    the region may contain calls to abort/exit.  The only restriction
    7760              :    is that ENTRY_BB should be the only entry point and it must
    7761              :    dominate EXIT_BB.
    7762              : 
    7763              :    Change TREE_BLOCK of all statements in ORIG_BLOCK to the new
    7764              :    functions outermost BLOCK, move all subblocks of ORIG_BLOCK
    7765              :    to the new function.
    7766              : 
    7767              :    All local variables referenced in the region are assumed to be in
    7768              :    the corresponding BLOCK_VARS and unexpanded variable lists
    7769              :    associated with DEST_CFUN.
    7770              : 
    7771              :    TODO: investigate whether we can reuse gimple_duplicate_sese_region to
    7772              :    reimplement move_sese_region_to_fn by duplicating the region rather than
    7773              :    moving it.  */
    7774              : 
    7775              : basic_block
    7776        43620 : move_sese_region_to_fn (struct function *dest_cfun, basic_block entry_bb,
    7777              :                         basic_block exit_bb, tree orig_block)
    7778              : {
    7779        43620 :   vec<basic_block> bbs;
    7780        43620 :   basic_block dom_entry = get_immediate_dominator (CDI_DOMINATORS, entry_bb);
    7781        43620 :   basic_block after, bb, *entry_pred, *exit_succ, abb;
    7782        43620 :   struct function *saved_cfun = cfun;
    7783        43620 :   int *entry_flag, *exit_flag;
    7784        43620 :   profile_probability *entry_prob, *exit_prob;
    7785        43620 :   unsigned i, num_entry_edges, num_exit_edges, num_nodes;
    7786        43620 :   edge e;
    7787        43620 :   edge_iterator ei;
    7788        43620 :   htab_t new_label_map;
    7789        43620 :   hash_map<void *, void *> *eh_map;
    7790        43620 :   class loop *loop = entry_bb->loop_father;
    7791        43620 :   class loop *loop0 = get_loop (saved_cfun, 0);
    7792        43620 :   struct move_stmt_d d;
    7793              : 
    7794              :   /* If ENTRY does not strictly dominate EXIT, this cannot be an SESE
    7795              :      region.  */
    7796        43620 :   gcc_assert (entry_bb != exit_bb
    7797              :               && (!exit_bb
    7798              :                   || dominated_by_p (CDI_DOMINATORS, exit_bb, entry_bb)));
    7799              : 
    7800              :   /* Collect all the blocks in the region.  Manually add ENTRY_BB
    7801              :      because it won't be added by dfs_enumerate_from.  */
    7802        43620 :   bbs.create (0);
    7803        43620 :   bbs.safe_push (entry_bb);
    7804        43620 :   gather_blocks_in_sese_region (entry_bb, exit_bb, &bbs);
    7805              : 
    7806        43620 :   if (flag_checking)
    7807        43620 :     verify_sese (entry_bb, exit_bb, &bbs);
    7808              : 
    7809              :   /* The blocks that used to be dominated by something in BBS will now be
    7810              :      dominated by the new block.  */
    7811        43620 :   auto_vec<basic_block> dom_bbs = get_dominated_by_region (CDI_DOMINATORS,
    7812              :                                                            bbs.address (),
    7813        87240 :                                                            bbs.length ());
    7814              : 
    7815              :   /* Detach ENTRY_BB and EXIT_BB from CFUN->CFG.  We need to remember
    7816              :      the predecessor edges to ENTRY_BB and the successor edges to
    7817              :      EXIT_BB so that we can re-attach them to the new basic block that
    7818              :      will replace the region.  */
    7819        43620 :   num_entry_edges = EDGE_COUNT (entry_bb->preds);
    7820        43620 :   entry_pred = XNEWVEC (basic_block, num_entry_edges);
    7821        43620 :   entry_flag = XNEWVEC (int, num_entry_edges);
    7822        43620 :   entry_prob = XNEWVEC (profile_probability, num_entry_edges);
    7823        43620 :   i = 0;
    7824        87240 :   for (ei = ei_start (entry_bb->preds); (e = ei_safe_edge (ei)) != NULL;)
    7825              :     {
    7826        43620 :       entry_prob[i] = e->probability;
    7827        43620 :       entry_flag[i] = e->flags;
    7828        43620 :       entry_pred[i++] = e->src;
    7829        43620 :       remove_edge (e);
    7830              :     }
    7831              : 
    7832        43620 :   if (exit_bb)
    7833              :     {
    7834        43500 :       num_exit_edges = EDGE_COUNT (exit_bb->succs);
    7835        43500 :       exit_succ = XNEWVEC (basic_block, num_exit_edges);
    7836        43500 :       exit_flag = XNEWVEC (int, num_exit_edges);
    7837        43500 :       exit_prob = XNEWVEC (profile_probability, num_exit_edges);
    7838        43500 :       i = 0;
    7839        87000 :       for (ei = ei_start (exit_bb->succs); (e = ei_safe_edge (ei)) != NULL;)
    7840              :         {
    7841        43500 :           exit_prob[i] = e->probability;
    7842        43500 :           exit_flag[i] = e->flags;
    7843        43500 :           exit_succ[i++] = e->dest;
    7844        43500 :           remove_edge (e);
    7845              :         }
    7846              :     }
    7847              :   else
    7848              :     {
    7849              :       num_exit_edges = 0;
    7850              :       exit_succ = NULL;
    7851              :       exit_flag = NULL;
    7852              :       exit_prob = NULL;
    7853              :     }
    7854              : 
    7855              :   /* Switch context to the child function to initialize DEST_FN's CFG.  */
    7856        43620 :   gcc_assert (dest_cfun->cfg == NULL);
    7857        43620 :   push_cfun (dest_cfun);
    7858              : 
    7859        43620 :   init_empty_tree_cfg ();
    7860              : 
    7861              :   /* Initialize EH information for the new function.  */
    7862        43620 :   eh_map = NULL;
    7863        43620 :   new_label_map = NULL;
    7864        43620 :   if (saved_cfun->eh)
    7865              :     {
    7866        43620 :       eh_region region = NULL;
    7867        43620 :       bool all = false;
    7868              : 
    7869       685196 :       FOR_EACH_VEC_ELT (bbs, i, bb)
    7870              :         {
    7871       641577 :           region = find_outermost_region_in_block (saved_cfun, bb, region, &all);
    7872       641577 :           if (all)
    7873              :             break;
    7874              :         }
    7875              : 
    7876        43620 :       init_eh_for_function ();
    7877        43620 :       if (region != NULL || all)
    7878              :         {
    7879         2001 :           new_label_map = htab_create (17, tree_map_hash, tree_map_eq, free);
    7880         2001 :           eh_map = duplicate_eh_regions (saved_cfun, region, 0,
    7881              :                                          new_label_mapper, new_label_map);
    7882              :         }
    7883              :     }
    7884              : 
    7885              :   /* Initialize an empty loop tree.  */
    7886        43620 :   struct loops *loops = ggc_cleared_alloc<struct loops> ();
    7887        43620 :   init_loops_structure (dest_cfun, loops, 1);
    7888        43620 :   loops->state = LOOPS_MAY_HAVE_MULTIPLE_LATCHES;
    7889        43620 :   set_loops_for_fn (dest_cfun, loops);
    7890              : 
    7891        87240 :   vec<loop_p, va_gc> *larray = get_loops (saved_cfun)->copy ();
    7892              : 
    7893              :   /* Move the outlined loop tree part.  */
    7894        43620 :   num_nodes = bbs.length ();
    7895       685202 :   FOR_EACH_VEC_ELT (bbs, i, bb)
    7896              :     {
    7897       641582 :       if (bb->loop_father->header == bb)
    7898              :         {
    7899        71321 :           class loop *this_loop = bb->loop_father;
    7900              :           /* Avoid the need to remap SSA names used in nb_iterations.  */
    7901        71321 :           free_numbers_of_iterations_estimates (this_loop);
    7902        71321 :           class loop *outer = loop_outer (this_loop);
    7903        71321 :           if (outer == loop
    7904              :               /* If the SESE region contains some bbs ending with
    7905              :                  a noreturn call, those are considered to belong
    7906              :                  to the outermost loop in saved_cfun, rather than
    7907              :                  the entry_bb's loop_father.  */
    7908        71321 :               || outer == loop0)
    7909              :             {
    7910        40613 :               if (outer != loop)
    7911            8 :                 num_nodes -= this_loop->num_nodes;
    7912        40613 :               flow_loop_tree_node_remove (bb->loop_father);
    7913        40613 :               flow_loop_tree_node_add (get_loop (dest_cfun, 0), this_loop);
    7914        40613 :               fixup_loop_arrays_after_move (saved_cfun, cfun, this_loop);
    7915              :             }
    7916              :         }
    7917       570261 :       else if (bb->loop_father == loop0 && loop0 != loop)
    7918         1240 :         num_nodes--;
    7919              : 
    7920              :       /* Remove loop exits from the outlined region.  */
    7921       641582 :       if (loops_for_fn (saved_cfun)->exits)
    7922         5682 :         FOR_EACH_EDGE (e, ei, bb->succs)
    7923              :           {
    7924         3084 :             struct loops *l = loops_for_fn (saved_cfun);
    7925         3084 :             loop_exit **slot
    7926         3084 :               = l->exits->find_slot_with_hash (e, htab_hash_pointer (e),
    7927              :                                                NO_INSERT);
    7928         3084 :             if (slot)
    7929          291 :               l->exits->clear_slot (slot);
    7930              :           }
    7931              :     }
    7932              : 
    7933              :   /* Adjust the number of blocks in the tree root of the outlined part.  */
    7934        87240 :   get_loop (dest_cfun, 0)->num_nodes = bbs.length () + 2;
    7935              : 
    7936              :   /* Setup a mapping to be used by move_block_to_fn.  */
    7937        43620 :   loop->aux = current_loops->tree_root;
    7938        43620 :   loop0->aux = current_loops->tree_root;
    7939              : 
    7940              :   /* Fix up orig_loop_num.  If the block referenced in it has been moved
    7941              :      to dest_cfun, update orig_loop_num field, otherwise clear it.  */
    7942        43620 :   signed char *moved_orig_loop_num = NULL;
    7943       202181 :   for (auto dloop : loops_list (dest_cfun, 0))
    7944        71321 :     if (dloop->orig_loop_num)
    7945              :       {
    7946            2 :         if (moved_orig_loop_num == NULL)
    7947            2 :           moved_orig_loop_num
    7948            2 :             = XCNEWVEC (signed char, vec_safe_length (larray));
    7949            2 :         if ((*larray)[dloop->orig_loop_num] != NULL
    7950            2 :             && get_loop (saved_cfun, dloop->orig_loop_num) == NULL)
    7951              :           {
    7952            0 :             if (moved_orig_loop_num[dloop->orig_loop_num] >= 0
    7953            0 :                 && moved_orig_loop_num[dloop->orig_loop_num] < 2)
    7954            0 :               moved_orig_loop_num[dloop->orig_loop_num]++;
    7955            0 :             dloop->orig_loop_num = (*larray)[dloop->orig_loop_num]->num;
    7956              :           }
    7957              :         else
    7958              :           {
    7959            2 :             moved_orig_loop_num[dloop->orig_loop_num] = -1;
    7960            2 :             dloop->orig_loop_num = 0;
    7961              :           }
    7962        43620 :       }
    7963        43620 :   pop_cfun ();
    7964              : 
    7965        43620 :   if (moved_orig_loop_num)
    7966              :     {
    7967           29 :       FOR_EACH_VEC_ELT (bbs, i, bb)
    7968              :         {
    7969           27 :           gimple *g = find_loop_dist_alias (bb);
    7970           27 :           if (g == NULL)
    7971           27 :             continue;
    7972              : 
    7973            0 :           int orig_loop_num = tree_to_shwi (gimple_call_arg (g, 0));
    7974            0 :           gcc_assert (orig_loop_num
    7975              :                       && (unsigned) orig_loop_num < vec_safe_length (larray));
    7976            0 :           if (moved_orig_loop_num[orig_loop_num] == 2)
    7977              :             {
    7978              :               /* If we have moved both loops with this orig_loop_num into
    7979              :                  dest_cfun and the LOOP_DIST_ALIAS call is being moved there
    7980              :                  too, update the first argument.  */
    7981            0 :               gcc_assert ((*larray)[orig_loop_num] != NULL
    7982              :                           && (get_loop (saved_cfun, orig_loop_num) == NULL));
    7983            0 :               tree t = build_int_cst (integer_type_node,
    7984            0 :                                       (*larray)[orig_loop_num]->num);
    7985            0 :               gimple_call_set_arg (g, 0, t);
    7986            0 :               update_stmt (g);
    7987              :               /* Make sure the following loop will not update it.  */
    7988            0 :               moved_orig_loop_num[orig_loop_num] = 0;
    7989              :             }
    7990              :           else
    7991              :             /* Otherwise at least one of the loops stayed in saved_cfun.
    7992              :                Remove the LOOP_DIST_ALIAS call.  */
    7993            0 :             fold_loop_internal_call (g, gimple_call_arg (g, 1));
    7994              :         }
    7995           88 :       FOR_EACH_BB_FN (bb, saved_cfun)
    7996              :         {
    7997           86 :           gimple *g = find_loop_dist_alias (bb);
    7998           86 :           if (g == NULL)
    7999           85 :             continue;
    8000            1 :           int orig_loop_num = tree_to_shwi (gimple_call_arg (g, 0));
    8001            2 :           gcc_assert (orig_loop_num
    8002              :                       && (unsigned) orig_loop_num < vec_safe_length (larray));
    8003            1 :           if (moved_orig_loop_num[orig_loop_num])
    8004              :             /* LOOP_DIST_ALIAS call remained in saved_cfun, if at least one
    8005              :                of the corresponding loops was moved, remove it.  */
    8006            1 :             fold_loop_internal_call (g, gimple_call_arg (g, 1));
    8007              :         }
    8008            2 :       XDELETEVEC (moved_orig_loop_num);
    8009              :     }
    8010        43620 :   ggc_free (larray);
    8011              : 
    8012              :   /* Move blocks from BBS into DEST_CFUN.  */
    8013        43620 :   gcc_assert (bbs.length () >= 2);
    8014        43620 :   after = dest_cfun->cfg->x_entry_block_ptr;
    8015        43620 :   hash_map<tree, tree> vars_map;
    8016              : 
    8017        43620 :   memset (&d, 0, sizeof (d));
    8018        43620 :   d.orig_block = orig_block;
    8019        43620 :   d.new_block = DECL_INITIAL (dest_cfun->decl);
    8020        43620 :   d.from_context = cfun->decl;
    8021        43620 :   d.to_context = dest_cfun->decl;
    8022        43620 :   d.vars_map = &vars_map;
    8023        43620 :   d.new_label_map = new_label_map;
    8024        43620 :   d.eh_map = eh_map;
    8025        43620 :   d.remap_decls_p = true;
    8026              : 
    8027        43620 :   if (gimple_in_ssa_p (cfun))
    8028          392 :     for (tree arg = DECL_ARGUMENTS (d.to_context); arg; arg = DECL_CHAIN (arg))
    8029              :       {
    8030          196 :         tree narg = make_ssa_name_fn (dest_cfun, arg, gimple_build_nop ());
    8031          196 :         set_ssa_default_def (dest_cfun, arg, narg);
    8032          196 :         vars_map.put (arg, narg);
    8033              :       }
    8034              : 
    8035       685202 :   FOR_EACH_VEC_ELT (bbs, i, bb)
    8036              :     {
    8037              :       /* No need to update edge counts on the last block.  It has
    8038              :          already been updated earlier when we detached the region from
    8039              :          the original CFG.  */
    8040       641582 :       move_block_to_fn (dest_cfun, bb, after, bb != exit_bb, &d);
    8041       641582 :       after = bb;
    8042              :     }
    8043              : 
    8044              :   /* Adjust the maximum clique used.  */
    8045        43620 :   dest_cfun->last_clique = saved_cfun->last_clique;
    8046              : 
    8047        43620 :   loop->aux = NULL;
    8048        43620 :   loop0->aux = NULL;
    8049              :   /* Loop sizes are no longer correct, fix them up.  */
    8050        43620 :   loop->num_nodes -= num_nodes;
    8051        43620 :   for (class loop *outer = loop_outer (loop);
    8052        47765 :        outer; outer = loop_outer (outer))
    8053         4145 :     outer->num_nodes -= num_nodes;
    8054        43620 :   loop0->num_nodes -= bbs.length () - num_nodes;
    8055              : 
    8056        43620 :   if (saved_cfun->has_simduid_loops || saved_cfun->has_force_vectorize_loops)
    8057              :     {
    8058         9292 :       class loop *aloop;
    8059        31207 :       for (i = 0; vec_safe_iterate (loops->larray, i, &aloop); i++)
    8060        21915 :         if (aloop != NULL)
    8061              :           {
    8062        21915 :             if (aloop->simduid)
    8063              :               {
    8064         2395 :                 replace_by_duplicate_decl (&aloop->simduid, d.vars_map,
    8065              :                                            d.to_context);
    8066         2395 :                 dest_cfun->has_simduid_loops = true;
    8067              :               }
    8068        21915 :             if (aloop->force_vectorize)
    8069         4238 :               dest_cfun->has_force_vectorize_loops = true;
    8070              :           }
    8071              :     }
    8072              : 
    8073              :   /* Rewire BLOCK_SUBBLOCKS of orig_block.  */
    8074        43620 :   if (orig_block)
    8075              :     {
    8076        43424 :       tree block;
    8077        43424 :       gcc_assert (BLOCK_SUBBLOCKS (DECL_INITIAL (dest_cfun->decl))
    8078              :                   == NULL_TREE);
    8079        86848 :       BLOCK_SUBBLOCKS (DECL_INITIAL (dest_cfun->decl))
    8080        43424 :         = BLOCK_SUBBLOCKS (orig_block);
    8081        43424 :       for (block = BLOCK_SUBBLOCKS (orig_block);
    8082        83509 :            block; block = BLOCK_CHAIN (block))
    8083        40085 :         BLOCK_SUPERCONTEXT (block) = DECL_INITIAL (dest_cfun->decl);
    8084        43424 :       BLOCK_SUBBLOCKS (orig_block) = NULL_TREE;
    8085              :     }
    8086              : 
    8087        43620 :   replace_block_vars_by_duplicates (DECL_INITIAL (dest_cfun->decl),
    8088              :                                     &vars_map, dest_cfun->decl);
    8089              : 
    8090        43620 :   if (new_label_map)
    8091         2001 :     htab_delete (new_label_map);
    8092        43620 :   if (eh_map)
    8093         2001 :     delete eh_map;
    8094              : 
    8095              :   /* We need to release ssa-names in a defined order, so first find them,
    8096              :      and then iterate in ascending version order.  */
    8097        43620 :   bitmap release_names = BITMAP_ALLOC (NULL);
    8098      1345275 :   vars_map.traverse<void *, gather_ssa_name_hash_map_from> (release_names);
    8099        43620 :   bitmap_iterator bi;
    8100        49357 :   EXECUTE_IF_SET_IN_BITMAP (release_names, 0, i, bi)
    8101         5737 :     release_ssa_name (ssa_name (i));
    8102        43620 :   BITMAP_FREE (release_names);
    8103              : 
    8104              :   /* Rewire the entry and exit blocks.  The successor to the entry
    8105              :      block turns into the successor of DEST_FN's ENTRY_BLOCK_PTR in
    8106              :      the child function.  Similarly, the predecessor of DEST_FN's
    8107              :      EXIT_BLOCK_PTR turns into the predecessor of EXIT_BLOCK_PTR.  We
    8108              :      need to switch CFUN between DEST_CFUN and SAVED_CFUN so that the
    8109              :      various CFG manipulation function get to the right CFG.
    8110              : 
    8111              :      FIXME, this is silly.  The CFG ought to become a parameter to
    8112              :      these helpers.  */
    8113        43620 :   push_cfun (dest_cfun);
    8114        43620 :   ENTRY_BLOCK_PTR_FOR_FN (cfun)->count = entry_bb->count;
    8115        43620 :   make_single_succ_edge (ENTRY_BLOCK_PTR_FOR_FN (cfun), entry_bb, EDGE_FALLTHRU);
    8116        43620 :   if (exit_bb)
    8117              :     {
    8118        43500 :       make_single_succ_edge (exit_bb,  EXIT_BLOCK_PTR_FOR_FN (cfun), 0);
    8119        43500 :       EXIT_BLOCK_PTR_FOR_FN (cfun)->count = exit_bb->count;
    8120              :     }
    8121              :   else
    8122          120 :     EXIT_BLOCK_PTR_FOR_FN (cfun)->count = profile_count::zero ();
    8123        43620 :   pop_cfun ();
    8124              : 
    8125              :   /* Back in the original function, the SESE region has disappeared,
    8126              :      create a new basic block in its place.  */
    8127        43620 :   bb = create_empty_bb (entry_pred[0]);
    8128        43620 :   if (current_loops)
    8129        43620 :     add_bb_to_loop (bb, loop);
    8130        43620 :   profile_count count = profile_count::zero ();
    8131        87240 :   for (i = 0; i < num_entry_edges; i++)
    8132              :     {
    8133        43620 :       e = make_edge (entry_pred[i], bb, entry_flag[i]);
    8134        43620 :       e->probability = entry_prob[i];
    8135        43620 :       count += e->count ();
    8136              :     }
    8137        43620 :   bb->count = count;
    8138              : 
    8139        87120 :   for (i = 0; i < num_exit_edges; i++)
    8140              :     {
    8141        43500 :       e = make_edge (bb, exit_succ[i], exit_flag[i]);
    8142        43500 :       e->probability = exit_prob[i];
    8143              :     }
    8144              : 
    8145        43620 :   set_immediate_dominator (CDI_DOMINATORS, bb, dom_entry);
    8146        83330 :   FOR_EACH_VEC_ELT (dom_bbs, i, abb)
    8147        39710 :     set_immediate_dominator (CDI_DOMINATORS, abb, bb);
    8148              : 
    8149        43620 :   if (exit_bb)
    8150              :     {
    8151        43500 :       free (exit_prob);
    8152        43500 :       free (exit_flag);
    8153        43500 :       free (exit_succ);
    8154              :     }
    8155        43620 :   free (entry_prob);
    8156        43620 :   free (entry_flag);
    8157        43620 :   free (entry_pred);
    8158        43620 :   bbs.release ();
    8159              : 
    8160        43620 :   return bb;
    8161        43620 : }
    8162              : 
    8163              : /* Dump default def DEF to file FILE using FLAGS and indentation
    8164              :    SPC.  */
    8165              : 
    8166              : static void
    8167          539 : dump_default_def (FILE *file, tree def, int spc, dump_flags_t flags)
    8168              : {
    8169         1617 :   for (int i = 0; i < spc; ++i)
    8170         1078 :     fprintf (file, " ");
    8171          539 :   dump_ssaname_info_to_file (file, def, spc);
    8172              : 
    8173          539 :   print_generic_expr (file, TREE_TYPE (def), flags);
    8174          539 :   fprintf (file, " ");
    8175          539 :   print_generic_expr (file, def, flags);
    8176          539 :   fprintf (file, " = ");
    8177          539 :   print_generic_expr (file, SSA_NAME_VAR (def), flags);
    8178          539 :   fprintf (file, ";\n");
    8179          539 : }
    8180              : 
    8181              : /* Print no_sanitize attribute to FILE for a given attribute VALUE.  */
    8182              : 
    8183              : static void
    8184           69 : print_no_sanitize_attr_value (FILE *file, tree value)
    8185              : {
    8186           69 :   sanitize_code_type flags = tree_to_sanitize_code_type (value);
    8187           69 :   bool first = true;
    8188         2415 :   for (int i = 0; sanitizer_opts[i].name != NULL; ++i)
    8189              :     {
    8190         2346 :       if ((sanitizer_opts[i].flag & flags) == sanitizer_opts[i].flag)
    8191              :         {
    8192          289 :           if (!first)
    8193          220 :             fprintf (file, " | ");
    8194          289 :           fprintf (file, "%s", sanitizer_opts[i].name);
    8195          289 :           first = false;
    8196              :         }
    8197              :     }
    8198           69 : }
    8199              : 
    8200              : /* Dump FUNCTION_DECL FN to file FILE using FLAGS (see TDF_* in dumpfile.h)
    8201              :    */
    8202              : 
    8203              : void
    8204        64354 : dump_function_to_file (tree fndecl, FILE *file, dump_flags_t flags)
    8205              : {
    8206        64354 :   tree arg, var, old_current_fndecl = current_function_decl;
    8207        64354 :   struct function *dsf;
    8208        64354 :   bool ignore_topmost_bind = false, any_var = false;
    8209        64354 :   basic_block bb;
    8210        64354 :   tree chain;
    8211        64354 :   bool tmclone = (TREE_CODE (fndecl) == FUNCTION_DECL
    8212       123182 :                   && decl_is_tm_clone (fndecl));
    8213        64354 :   struct function *fun = DECL_STRUCT_FUNCTION (fndecl);
    8214              : 
    8215        64354 :   tree fntype = TREE_TYPE (fndecl);
    8216        64354 :   tree attrs[] = { DECL_ATTRIBUTES (fndecl), TYPE_ATTRIBUTES (fntype) };
    8217              : 
    8218       193062 :   for (int i = 0; i != 2; ++i)
    8219              :     {
    8220       128708 :       if (!attrs[i])
    8221       104797 :         continue;
    8222              : 
    8223        23911 :       fprintf (file, "__attribute__((");
    8224              : 
    8225        23911 :       bool first = true;
    8226        23911 :       tree chain;
    8227        66662 :       for (chain = attrs[i]; chain; first = false, chain = TREE_CHAIN (chain))
    8228              :         {
    8229        42751 :           if (!first)
    8230        18840 :             fprintf (file, ", ");
    8231              : 
    8232        42751 :           tree name = get_attribute_name (chain);
    8233        42751 :           print_generic_expr (file, name, flags);
    8234        42751 :           if (TREE_VALUE (chain) != NULL_TREE)
    8235              :             {
    8236        10995 :               fprintf (file, " (");
    8237              : 
    8238        10995 :               if (strstr (IDENTIFIER_POINTER (name), "no_sanitize"))
    8239           69 :                 print_no_sanitize_attr_value (file, TREE_VALUE (chain));
    8240        10926 :               else if (!strcmp (IDENTIFIER_POINTER (name),
    8241              :                                 "omp declare variant base"))
    8242              :                 {
    8243          230 :                   tree a = TREE_VALUE (chain);
    8244          230 :                   print_generic_expr (file, TREE_PURPOSE (a), flags);
    8245          230 :                   fprintf (file, " match ");
    8246          230 :                   print_omp_context_selector (file, TREE_VALUE (a),
    8247              :                                               flags);
    8248              :                 }
    8249              :               else
    8250        10696 :                 print_generic_expr (file, TREE_VALUE (chain), flags);
    8251        10995 :               fprintf (file, ")");
    8252              :             }
    8253              :         }
    8254              : 
    8255        23911 :       fprintf (file, "))\n");
    8256              :     }
    8257              : 
    8258        64354 :   current_function_decl = fndecl;
    8259        64354 :   if (flags & TDF_GIMPLE)
    8260              :     {
    8261           44 :       static bool hotness_bb_param_printed = false;
    8262           44 :       if (profile_info != NULL
    8263            0 :           && !hotness_bb_param_printed)
    8264              :         {
    8265            0 :           hotness_bb_param_printed = true;
    8266            0 :           fprintf (file,
    8267              :                    "/* --param=gimple-fe-computed-hot-bb-threshold=%" PRId64
    8268              :                    " */\n", get_hot_bb_threshold ());
    8269              :         }
    8270              : 
    8271           44 :       print_generic_expr (file, TREE_TYPE (TREE_TYPE (fndecl)),
    8272              :                           flags | TDF_SLIM);
    8273           44 :       fprintf (file, " __GIMPLE (%s",
    8274           44 :                (fun->curr_properties & PROP_ssa) ? "ssa"
    8275            9 :                : (fun->curr_properties & PROP_cfg) ? "cfg"
    8276              :                : "");
    8277              : 
    8278           44 :       if (fun && fun->cfg)
    8279              :         {
    8280           40 :           basic_block bb = ENTRY_BLOCK_PTR_FOR_FN (fun);
    8281           40 :           if (bb->count.initialized_p ())
    8282            0 :             fprintf (file, ",%s(%" PRIu64 ")",
    8283              :                      profile_quality_as_string (bb->count.quality ()),
    8284              :                      bb->count.value ());
    8285           40 :           if (flags & TDF_UID)
    8286            0 :             fprintf (file, ")\n%sD_%u (", function_name (fun),
    8287            0 :                      DECL_UID (fndecl));
    8288              :           else
    8289           40 :             fprintf (file, ")\n%s (", function_name (fun));
    8290              :         }
    8291              :     }
    8292              :   else
    8293              :     {
    8294        64310 :       print_generic_expr (file, TREE_TYPE (fntype), flags);
    8295        64310 :       if (flags & TDF_UID)
    8296         1312 :         fprintf (file, " %sD.%u %s(", function_name (fun), DECL_UID (fndecl),
    8297              :                  tmclone ? "[tm-clone] " : "");
    8298              :       else
    8299       127271 :         fprintf (file, " %s %s(", function_name (fun),
    8300              :                  tmclone ? "[tm-clone] " : "");
    8301              :     }
    8302              : 
    8303        64354 :   arg = DECL_ARGUMENTS (fndecl);
    8304       151798 :   while (arg)
    8305              :     {
    8306        87444 :       print_generic_expr (file, TREE_TYPE (arg), flags);
    8307        87444 :       fprintf (file, " ");
    8308        87444 :       print_generic_expr (file, arg, flags);
    8309        87444 :       if (DECL_CHAIN (arg))
    8310        44789 :         fprintf (file, ", ");
    8311        87444 :       arg = DECL_CHAIN (arg);
    8312              :     }
    8313        64354 :   fprintf (file, ")\n");
    8314              : 
    8315        64354 :   dsf = DECL_STRUCT_FUNCTION (fndecl);
    8316        64354 :   if (dsf && (flags & TDF_EH))
    8317          665 :     dump_eh_tree (file, dsf);
    8318              : 
    8319        64354 :   if (flags & TDF_RAW && !gimple_has_body_p (fndecl))
    8320              :     {
    8321            2 :       dump_node (fndecl, TDF_SLIM | flags, file);
    8322            2 :       current_function_decl = old_current_fndecl;
    8323            2 :       return;
    8324              :     }
    8325              : 
    8326              :   /* When GIMPLE is lowered, the variables are no longer available in
    8327              :      BIND_EXPRs, so display them separately.  */
    8328        64352 :   if (fun && fun->decl == fndecl && (fun->curr_properties & PROP_gimple_lcf))
    8329              :     {
    8330        53340 :       unsigned ix;
    8331        53340 :       ignore_topmost_bind = true;
    8332              : 
    8333        53340 :       fprintf (file, "{\n");
    8334       105675 :       if (gimple_in_ssa_p (fun)
    8335        52335 :           && (flags & TDF_ALIAS))
    8336              :         {
    8337         1221 :           for (arg = DECL_ARGUMENTS (fndecl); arg != NULL;
    8338          565 :                arg = DECL_CHAIN (arg))
    8339              :             {
    8340          565 :               tree def = ssa_default_def (fun, arg);
    8341          565 :               if (def)
    8342          539 :                 dump_default_def (file, def, 2, flags);
    8343              :             }
    8344              : 
    8345          656 :           tree res = DECL_RESULT (fun->decl);
    8346          656 :           if (res != NULL_TREE
    8347          656 :               && DECL_BY_REFERENCE (res))
    8348              :             {
    8349            0 :               tree def = ssa_default_def (fun, res);
    8350            0 :               if (def)
    8351            0 :                 dump_default_def (file, def, 2, flags);
    8352              :             }
    8353              : 
    8354          656 :           tree static_chain = fun->static_chain_decl;
    8355          656 :           if (static_chain != NULL_TREE)
    8356              :             {
    8357            0 :               tree def = ssa_default_def (fun, static_chain);
    8358            0 :               if (def)
    8359            0 :                 dump_default_def (file, def, 2, flags);
    8360              :             }
    8361              :         }
    8362              : 
    8363        53340 :       if (!vec_safe_is_empty (fun->local_decls))
    8364       292561 :         FOR_EACH_LOCAL_DECL (fun, ix, var)
    8365              :           {
    8366       261589 :             print_generic_decl (file, var, flags);
    8367       261589 :             fprintf (file, "\n");
    8368              : 
    8369       261589 :             any_var = true;
    8370              :           }
    8371              : 
    8372        53340 :       tree name;
    8373              : 
    8374        53340 :       if (gimple_in_ssa_p (fun))
    8375      1769666 :         FOR_EACH_SSA_NAME (ix, name, fun)
    8376              :           {
    8377      1286094 :             if (!SSA_NAME_VAR (name)
    8378              :                 /* SSA name with decls without a name still get
    8379              :                    dumped as _N, list those explicitly as well even
    8380              :                    though we've dumped the decl declaration as D.xxx
    8381              :                    above.  */
    8382       747144 :                 || !SSA_NAME_IDENTIFIER (name))
    8383              :               {
    8384       541677 :                 fprintf (file, "  ");
    8385       541677 :                 print_generic_expr (file, TREE_TYPE (name), flags);
    8386       541677 :                 fprintf (file, " ");
    8387       541677 :                 print_generic_expr (file, name, flags);
    8388       541677 :                 fprintf (file, ";\n");
    8389              : 
    8390       541677 :                 any_var = true;
    8391              :               }
    8392              :           }
    8393              :     }
    8394              : 
    8395        64352 :   if (fun && fun->decl == fndecl
    8396        64352 :       && fun->cfg
    8397        53062 :       && basic_block_info_for_fn (fun))
    8398              :     {
    8399              :       /* If the CFG has been built, emit a CFG-based dump.  */
    8400        53062 :       if (!ignore_topmost_bind)
    8401            0 :         fprintf (file, "{\n");
    8402              : 
    8403        53062 :       if (any_var && n_basic_blocks_for_fn (fun))
    8404        46041 :         fprintf (file, "\n");
    8405              : 
    8406       318014 :       FOR_EACH_BB_FN (bb, fun)
    8407       264952 :         dump_bb (file, bb, 2, flags);
    8408              : 
    8409        53062 :       fprintf (file, "}\n");
    8410              :     }
    8411        11290 :   else if (fun && (fun->curr_properties & PROP_gimple_any))
    8412              :     {
    8413              :       /* The function is now in GIMPLE form but the CFG has not been
    8414              :          built yet.  Emit the single sequence of GIMPLE statements
    8415              :          that make up its body.  */
    8416         5227 :       gimple_seq body = gimple_body (fndecl);
    8417              : 
    8418         5227 :       if (gimple_seq_first_stmt (body)
    8419         5227 :           && gimple_seq_first_stmt (body) == gimple_seq_last_stmt (body)
    8420        10188 :           && gimple_code (gimple_seq_first_stmt (body)) == GIMPLE_BIND)
    8421         4949 :         print_gimple_seq (file, body, 0, flags);
    8422              :       else
    8423              :         {
    8424          278 :           if (!ignore_topmost_bind)
    8425            0 :             fprintf (file, "{\n");
    8426              : 
    8427          278 :           if (any_var)
    8428          186 :             fprintf (file, "\n");
    8429              : 
    8430          278 :           print_gimple_seq (file, body, 2, flags);
    8431          278 :           fprintf (file, "}\n");
    8432              :         }
    8433              :     }
    8434              :   else
    8435              :     {
    8436         6063 :       int indent;
    8437              : 
    8438              :       /* Make a tree based dump.  */
    8439         6063 :       chain = DECL_SAVED_TREE (fndecl);
    8440         6063 :       if (chain && TREE_CODE (chain) == BIND_EXPR)
    8441              :         {
    8442         6063 :           if (ignore_topmost_bind)
    8443              :             {
    8444            0 :               chain = BIND_EXPR_BODY (chain);
    8445            0 :               indent = 2;
    8446              :             }
    8447              :           else
    8448              :             indent = 0;
    8449              :         }
    8450              :       else
    8451              :         {
    8452            0 :           if (!ignore_topmost_bind)
    8453              :             {
    8454            0 :               fprintf (file, "{\n");
    8455              :               /* No topmost bind, pretend it's ignored for later.  */
    8456            0 :               ignore_topmost_bind = true;
    8457              :             }
    8458              :           indent = 2;
    8459              :         }
    8460              : 
    8461         6063 :       if (any_var)
    8462            0 :         fprintf (file, "\n");
    8463              : 
    8464         6063 :       print_generic_stmt_indented (file, chain, flags, indent);
    8465         6063 :       if (ignore_topmost_bind)
    8466            0 :         fprintf (file, "}\n");
    8467              :     }
    8468              : 
    8469        64352 :   if (flags & TDF_ENUMERATE_LOCALS)
    8470           39 :     dump_enumerated_decls (file, flags);
    8471        64352 :   fprintf (file, "\n\n");
    8472              : 
    8473        64352 :   current_function_decl = old_current_fndecl;
    8474              : }
    8475              : 
    8476              : /* Dump FUNCTION_DECL FN to stderr using FLAGS (see TDF_* in tree.h)  */
    8477              : 
    8478              : DEBUG_FUNCTION void
    8479            0 : debug_function (tree fn, dump_flags_t flags)
    8480              : {
    8481            0 :   dump_function_to_file (fn, stderr, flags);
    8482            0 : }
    8483              : 
    8484              : 
    8485              : /* Print on FILE the indexes for the predecessors of basic_block BB.  */
    8486              : 
    8487              : static void
    8488         5344 : print_pred_bbs (FILE *file, basic_block bb)
    8489              : {
    8490         5344 :   edge e;
    8491         5344 :   edge_iterator ei;
    8492              : 
    8493        12101 :   FOR_EACH_EDGE (e, ei, bb->preds)
    8494         6757 :     fprintf (file, "bb_%d ", e->src->index);
    8495         5344 : }
    8496              : 
    8497              : 
    8498              : /* Print on FILE the indexes for the successors of basic_block BB.  */
    8499              : 
    8500              : static void
    8501         5344 : print_succ_bbs (FILE *file, basic_block bb)
    8502              : {
    8503         5344 :   edge e;
    8504         5344 :   edge_iterator ei;
    8505              : 
    8506        12196 :   FOR_EACH_EDGE (e, ei, bb->succs)
    8507         6852 :     fprintf (file, "bb_%d ", e->dest->index);
    8508         5344 : }
    8509              : 
    8510              : /* Print to FILE the basic block BB following the VERBOSITY level.  */
    8511              : 
    8512              : void
    8513         5344 : print_loops_bb (FILE *file, basic_block bb, int indent, int verbosity)
    8514              : {
    8515         5344 :   char *s_indent = (char *) alloca ((size_t) indent + 1);
    8516         5344 :   memset ((void *) s_indent, ' ', (size_t) indent);
    8517         5344 :   s_indent[indent] = '\0';
    8518              : 
    8519              :   /* Print basic_block's header.  */
    8520         5344 :   if (verbosity >= 2)
    8521              :     {
    8522         5344 :       fprintf (file, "%s  bb_%d (preds = {", s_indent, bb->index);
    8523         5344 :       print_pred_bbs (file, bb);
    8524         5344 :       fprintf (file, "}, succs = {");
    8525         5344 :       print_succ_bbs (file, bb);
    8526         5344 :       fprintf (file, "})\n");
    8527              :     }
    8528              : 
    8529              :   /* Print basic_block's body.  */
    8530         5344 :   if (verbosity >= 3)
    8531              :     {
    8532         2928 :       fprintf (file, "%s  {\n", s_indent);
    8533         2928 :       dump_bb (file, bb, indent + 4, TDF_VOPS|TDF_MEMSYMS);
    8534         2928 :       fprintf (file, "%s  }\n", s_indent);
    8535              :     }
    8536         5344 : }
    8537              : 
    8538              : /* Print loop information.  */
    8539              : 
    8540              : void
    8541         9762 : print_loop_info (FILE *file, const class loop *loop, const char *prefix)
    8542              : {
    8543         9762 :   if (loop->can_be_parallel)
    8544            0 :     fprintf (file, ", can_be_parallel");
    8545         9762 :   if (loop->warned_aggressive_loop_optimizations)
    8546            0 :     fprintf (file, ", warned_aggressive_loop_optimizations");
    8547         9762 :   if (loop->dont_vectorize)
    8548            7 :     fprintf (file, ", dont_vectorize");
    8549         9762 :   if (loop->force_vectorize)
    8550            0 :     fprintf (file, ", force_vectorize");
    8551         9762 :   if (loop->in_oacc_kernels_region)
    8552          181 :     fprintf (file, ", in_oacc_kernels_region");
    8553         9762 :   if (loop->finite_p)
    8554         2039 :     fprintf (file, ", finite_p");
    8555         9762 :   if (loop->unroll)
    8556           68 :     fprintf (file, "\n%sunroll %d", prefix, loop->unroll);
    8557         9762 :   if (loop->nb_iterations)
    8558              :     {
    8559           35 :       fprintf (file, "\n%sniter ", prefix);
    8560           35 :       print_generic_expr (file, loop->nb_iterations);
    8561              :     }
    8562              : 
    8563         9762 :   if (loop->any_upper_bound)
    8564              :     {
    8565         1990 :       fprintf (file, "\n%supper_bound ", prefix);
    8566         1990 :       print_decu (loop->nb_iterations_upper_bound, file);
    8567              :     }
    8568         9762 :   if (loop->any_likely_upper_bound)
    8569              :     {
    8570         1990 :       fprintf (file, "\n%slikely_upper_bound ", prefix);
    8571         1990 :       print_decu (loop->nb_iterations_likely_upper_bound, file);
    8572              :     }
    8573              : 
    8574         9762 :   if (loop->any_estimate)
    8575              :     {
    8576          940 :       fprintf (file, "\n%sestimate ", prefix);
    8577          940 :       print_decu (loop->nb_iterations_estimate, file);
    8578              :     }
    8579         9762 :   bool reliable;
    8580         9762 :   sreal iterations;
    8581         9762 :   if (loop->num && expected_loop_iterations_by_profile (loop, &iterations, &reliable))
    8582              :     {
    8583         5121 :       fprintf (file, "\n%siterations by profile: %f (%s%s) entry count:", prefix,
    8584              :                iterations.to_double (), reliable ? "reliable" : "unreliable",
    8585         2338 :                maybe_flat_loop_profile (loop) ? ", maybe flat" : "");
    8586         2338 :       loop_count_in (loop).dump (file, cfun);
    8587              :     }
    8588              : 
    8589         9762 : }
    8590              : 
    8591              : static void print_loop_and_siblings (FILE *, class loop *, int, int);
    8592              : 
    8593              : /* Pretty print LOOP on FILE, indented INDENT spaces.  Following
    8594              :    VERBOSITY level this outputs the contents of the loop, or just its
    8595              :    structure.  */
    8596              : 
    8597              : static void
    8598         1266 : print_loop (FILE *file, class loop *loop, int indent, int verbosity)
    8599              : {
    8600         1266 :   char *s_indent;
    8601         1266 :   basic_block bb;
    8602              : 
    8603         1266 :   if (loop == NULL)
    8604              :     return;
    8605              : 
    8606         1266 :   s_indent = (char *) alloca ((size_t) indent + 1);
    8607         1266 :   memset ((void *) s_indent, ' ', (size_t) indent);
    8608         1266 :   s_indent[indent] = '\0';
    8609              : 
    8610              :   /* Print loop's header.  */
    8611         1266 :   fprintf (file, "%sloop_%d (", s_indent, loop->num);
    8612         1266 :   if (loop->header)
    8613         1266 :     fprintf (file, "header = %d", loop->header->index);
    8614              :   else
    8615              :     {
    8616            0 :       fprintf (file, "deleted)\n");
    8617            0 :       return;
    8618              :     }
    8619         1266 :   if (loop->latch)
    8620         1266 :     fprintf (file, ", latch = %d", loop->latch->index);
    8621              :   else
    8622            0 :     fprintf (file, ", multiple latches");
    8623         1266 :   print_loop_info (file, loop, s_indent);
    8624         1266 :   fprintf (file, ")\n");
    8625              : 
    8626              :   /* Print loop's body.  */
    8627         1266 :   if (verbosity >= 1)
    8628              :     {
    8629         1266 :       fprintf (file, "%s{\n", s_indent);
    8630        21548 :       FOR_EACH_BB_FN (bb, cfun)
    8631        20282 :         if (bb->loop_father == loop)
    8632         4832 :           print_loops_bb (file, bb, indent, verbosity);
    8633              : 
    8634         1266 :       print_loop_and_siblings (file, loop->inner, indent + 2, verbosity);
    8635         1266 :       fprintf (file, "%s}\n", s_indent);
    8636              :     }
    8637              : }
    8638              : 
    8639              : /* Print the LOOP and its sibling loops on FILE, indented INDENT
    8640              :    spaces.  Following VERBOSITY level this outputs the contents of the
    8641              :    loop, or just its structure.  */
    8642              : 
    8643              : static void
    8644         1266 : print_loop_and_siblings (FILE *file, class loop *loop, int indent,
    8645              :                          int verbosity)
    8646              : {
    8647         2154 :   if (loop == NULL)
    8648         1266 :     return;
    8649              : 
    8650         1266 :   print_loop (file, loop, indent, verbosity);
    8651          378 :   print_loop_and_siblings (file, loop->next, indent, verbosity);
    8652              : }
    8653              : 
    8654              : /* Follow a CFG edge from the entry point of the program, and on entry
    8655              :    of a loop, pretty print the loop structure on FILE.  */
    8656              : 
    8657              : void
    8658          378 : print_loops (FILE *file, int verbosity)
    8659              : {
    8660          378 :   basic_block bb;
    8661              : 
    8662          378 :   bb = ENTRY_BLOCK_PTR_FOR_FN (cfun);
    8663          378 :   fprintf (file, "\nLoops in function: %s\n", current_function_name ());
    8664          378 :   if (bb && bb->loop_father)
    8665          756 :     print_loop_and_siblings (file, bb->loop_father, 0, verbosity);
    8666          378 : }
    8667              : 
    8668              : /* Dump a loop.  */
    8669              : 
    8670              : DEBUG_FUNCTION void
    8671            0 : debug (class loop &ref)
    8672              : {
    8673            0 :   print_loop (stderr, &ref, 0, /*verbosity*/0);
    8674            0 : }
    8675              : 
    8676              : DEBUG_FUNCTION void
    8677            0 : debug (class loop *ptr)
    8678              : {
    8679            0 :   if (ptr)
    8680            0 :     debug (*ptr);
    8681              :   else
    8682            0 :     fprintf (stderr, "<nil>\n");
    8683            0 : }
    8684              : 
    8685              : /* Dump a loop verbosely.  */
    8686              : 
    8687              : DEBUG_FUNCTION void
    8688            0 : debug_verbose (class loop &ref)
    8689              : {
    8690            0 :   print_loop (stderr, &ref, 0, /*verbosity*/3);
    8691            0 : }
    8692              : 
    8693              : DEBUG_FUNCTION void
    8694            0 : debug_verbose (class loop *ptr)
    8695              : {
    8696            0 :   if (ptr)
    8697            0 :     debug (*ptr);
    8698              :   else
    8699            0 :     fprintf (stderr, "<nil>\n");
    8700            0 : }
    8701              : 
    8702              : 
    8703              : /* Debugging loops structure at tree level, at some VERBOSITY level.  */
    8704              : 
    8705              : DEBUG_FUNCTION void
    8706            0 : debug_loops (int verbosity)
    8707              : {
    8708            0 :   print_loops (stderr, verbosity);
    8709            0 : }
    8710              : 
    8711              : /* Print on stderr the code of LOOP, at some VERBOSITY level.  */
    8712              : 
    8713              : DEBUG_FUNCTION void
    8714            0 : debug_loop (class loop *loop, int verbosity)
    8715              : {
    8716            0 :   print_loop (stderr, loop, 0, verbosity);
    8717            0 : }
    8718              : 
    8719              : /* Print on stderr the code of loop number NUM, at some VERBOSITY
    8720              :    level.  */
    8721              : 
    8722              : DEBUG_FUNCTION void
    8723            0 : debug_loop_num (unsigned num, int verbosity)
    8724              : {
    8725            0 :   debug_loop (get_loop (cfun, num), verbosity);
    8726            0 : }
    8727              : 
    8728              : /* Return true if BB ends with a call, possibly followed by some
    8729              :    instructions that must stay with the call.  Return false,
    8730              :    otherwise.  */
    8731              : 
    8732              : static bool
    8733            3 : gimple_block_ends_with_call_p (basic_block bb)
    8734              : {
    8735            3 :   gimple_stmt_iterator gsi = gsi_last_nondebug_bb (bb);
    8736            3 :   return !gsi_end_p (gsi) && is_gimple_call (gsi_stmt (gsi));
    8737              : }
    8738              : 
    8739              : 
    8740              : /* Return true if BB ends with a conditional branch.  Return false,
    8741              :    otherwise.  */
    8742              : 
    8743              : static bool
    8744         1796 : gimple_block_ends_with_condjump_p (const_basic_block bb)
    8745              : {
    8746         3592 :   return safe_is_a <gcond *> (*gsi_last_bb (const_cast <basic_block> (bb)));
    8747              : }
    8748              : 
    8749              : 
    8750              : /* Return true if statement T may terminate execution of BB in ways not
    8751              :    explicitly represtented in the CFG.  */
    8752              : 
    8753              : bool
    8754    436341156 : stmt_can_terminate_bb_p (gimple *t)
    8755              : {
    8756    436341156 :   tree fndecl = NULL_TREE;
    8757    436341156 :   int call_flags = 0;
    8758              : 
    8759              :   /* Eh exception not handled internally terminates execution of the whole
    8760              :      function.  */
    8761    436341156 :   if (stmt_can_throw_external (cfun, t))
    8762              :     return true;
    8763              : 
    8764              :   /* NORETURN and LONGJMP calls already have an edge to exit.
    8765              :      CONST and PURE calls do not need one.
    8766              :      We don't currently check for CONST and PURE here, although
    8767              :      it would be a good idea, because those attributes are
    8768              :      figured out from the RTL in mark_constant_function, and
    8769              :      the counter incrementation code from -fprofile-arcs
    8770              :      leads to different results from -fbranch-probabilities.  */
    8771    428418544 :   if (is_gimple_call (t))
    8772              :     {
    8773     14251520 :       fndecl = gimple_call_fndecl (t);
    8774     14251520 :       call_flags = gimple_call_flags (t);
    8775              :     }
    8776              : 
    8777    428418544 :   if (is_gimple_call (t)
    8778     14251520 :       && fndecl
    8779     12384706 :       && fndecl_built_in_p (fndecl)
    8780      5109547 :       && (call_flags & ECF_NOTHROW)
    8781      4445216 :       && !(call_flags & ECF_RETURNS_TWICE)
    8782              :       /* fork() doesn't really return twice, but the effect of
    8783              :          wrapping it in __gcov_fork() which calls __gcov_dump() and
    8784              :          __gcov_reset() and clears the counters before forking has the same
    8785              :          effect as returning twice.  Force a fake edge.  */
    8786    432863393 :       && !fndecl_built_in_p (fndecl, BUILT_IN_FORK))
    8787              :     return false;
    8788              : 
    8789    423973910 :   if (is_gimple_call (t))
    8790              :     {
    8791      9806886 :       edge_iterator ei;
    8792      9806886 :       edge e;
    8793      9806886 :       basic_block bb;
    8794              : 
    8795      9806886 :       if (call_flags & (ECF_PURE | ECF_CONST)
    8796      2017990 :           && !(call_flags & ECF_LOOPING_CONST_OR_PURE))
    8797      8638575 :         return false;
    8798              : 
    8799              :       /* Function call may do longjmp, terminate program or do other things.
    8800              :          Special case noreturn that have non-abnormal edges out as in this case
    8801              :          the fact is sufficiently represented by lack of edges out of T.  */
    8802      7916847 :       if (!(call_flags & ECF_NORETURN))
    8803              :         return true;
    8804              : 
    8805      1266984 :       bb = gimple_bb (t);
    8806      2093922 :       FOR_EACH_EDGE (e, ei, bb->succs)
    8807       925611 :         if ((e->flags & EDGE_FAKE) == 0)
    8808              :           return true;
    8809              :     }
    8810              : 
    8811    415335335 :   if (gasm *asm_stmt = dyn_cast <gasm *> (t))
    8812       311291 :     if (gimple_asm_volatile_p (asm_stmt) || gimple_asm_basic_p (asm_stmt))
    8813              :       return true;
    8814              : 
    8815              :   return false;
    8816              : }
    8817              : 
    8818              : 
    8819              : /* Add fake edges to the function exit for any non constant and non
    8820              :    noreturn calls (or noreturn calls with EH/abnormal edges),
    8821              :    volatile inline assembly in the bitmap of blocks specified by BLOCKS
    8822              :    or to the whole CFG if BLOCKS is zero.  Return the number of blocks
    8823              :    that were split.
    8824              : 
    8825              :    The goal is to expose cases in which entering a basic block does
    8826              :    not imply that all subsequent instructions must be executed.  */
    8827              : 
    8828              : static int
    8829         2597 : gimple_flow_call_edges_add (sbitmap blocks)
    8830              : {
    8831         2597 :   int i;
    8832         2597 :   int blocks_split = 0;
    8833         2597 :   int last_bb = last_basic_block_for_fn (cfun);
    8834         2597 :   bool check_last_block = false;
    8835              : 
    8836         2597 :   if (n_basic_blocks_for_fn (cfun) == NUM_FIXED_BLOCKS)
    8837              :     return 0;
    8838              : 
    8839         2597 :   if (! blocks)
    8840              :     check_last_block = true;
    8841              :   else
    8842            0 :     check_last_block = bitmap_bit_p (blocks,
    8843            0 :                                      EXIT_BLOCK_PTR_FOR_FN (cfun)->prev_bb->index);
    8844              : 
    8845              :   /* In the last basic block, before epilogue generation, there will be
    8846              :      a fallthru edge to EXIT.  Special care is required if the last insn
    8847              :      of the last basic block is a call because make_edge folds duplicate
    8848              :      edges, which would result in the fallthru edge also being marked
    8849              :      fake, which would result in the fallthru edge being removed by
    8850              :      remove_fake_edges, which would result in an invalid CFG.
    8851              : 
    8852              :      Moreover, we can't elide the outgoing fake edge, since the block
    8853              :      profiler needs to take this into account in order to solve the minimal
    8854              :      spanning tree in the case that the call doesn't return.
    8855              : 
    8856              :      Handle this by adding a dummy instruction in a new last basic block.  */
    8857            0 :   if (check_last_block)
    8858              :     {
    8859         2597 :       basic_block bb = EXIT_BLOCK_PTR_FOR_FN (cfun)->prev_bb;
    8860         2597 :       gimple_stmt_iterator gsi = gsi_last_nondebug_bb (bb);
    8861         2597 :       gimple *t = NULL;
    8862              : 
    8863         2597 :       if (!gsi_end_p (gsi))
    8864         2585 :         t = gsi_stmt (gsi);
    8865              : 
    8866         2585 :       if (t && stmt_can_terminate_bb_p (t))
    8867              :         {
    8868          159 :           edge e;
    8869              : 
    8870          159 :           e = find_edge (bb, EXIT_BLOCK_PTR_FOR_FN (cfun));
    8871          159 :           if (e)
    8872              :             {
    8873            0 :               gsi_insert_on_edge (e, gimple_build_nop ());
    8874            0 :               gsi_commit_edge_inserts ();
    8875              :             }
    8876              :         }
    8877              :     }
    8878              : 
    8879              :   /* Now add fake edges to the function exit for any non constant
    8880              :      calls since there is no way that we can determine if they will
    8881              :      return or not...  */
    8882        19358 :   for (i = 0; i < last_bb; i++)
    8883              :     {
    8884        16761 :       basic_block bb = BASIC_BLOCK_FOR_FN (cfun, i);
    8885        16761 :       gimple_stmt_iterator gsi;
    8886        16761 :       gimple *stmt, *last_stmt;
    8887              : 
    8888        16761 :       if (!bb)
    8889            6 :         continue;
    8890              : 
    8891        16755 :       if (blocks && !bitmap_bit_p (blocks, i))
    8892            0 :         continue;
    8893              : 
    8894        16755 :       gsi = gsi_last_nondebug_bb (bb);
    8895        16755 :       if (!gsi_end_p (gsi))
    8896              :         {
    8897              :           last_stmt = gsi_stmt (gsi);
    8898        25775 :           do
    8899              :             {
    8900        25775 :               stmt = gsi_stmt (gsi);
    8901        25775 :               if (stmt_can_terminate_bb_p (stmt))
    8902              :                 {
    8903         3675 :                   edge e;
    8904              : 
    8905              :                   /* The handling above of the final block before the
    8906              :                      epilogue should be enough to verify that there is
    8907              :                      no edge to the exit block in CFG already.
    8908              :                      Calling make_edge in such case would cause us to
    8909              :                      mark that edge as fake and remove it later.  */
    8910         3675 :                   if (flag_checking && stmt == last_stmt)
    8911              :                     {
    8912         1148 :                       e = find_edge (bb, EXIT_BLOCK_PTR_FOR_FN (cfun));
    8913         1148 :                       gcc_assert (e == NULL);
    8914              :                     }
    8915              : 
    8916              :                   /* Note that the following may create a new basic block
    8917              :                      and renumber the existing basic blocks.  */
    8918         3675 :                   if (stmt != last_stmt)
    8919              :                     {
    8920         2527 :                       e = split_block (bb, stmt);
    8921         2527 :                       if (e)
    8922         2527 :                         blocks_split++;
    8923              :                     }
    8924         3675 :                   e = make_edge (bb, EXIT_BLOCK_PTR_FOR_FN (cfun), EDGE_FAKE);
    8925         3675 :                   e->probability = profile_probability::guessed_never ();
    8926              :                 }
    8927        25775 :               gsi_prev (&gsi);
    8928              :             }
    8929        25775 :           while (!gsi_end_p (gsi));
    8930              :         }
    8931              :     }
    8932              : 
    8933         2597 :   if (blocks_split)
    8934         1072 :     checking_verify_flow_info ();
    8935              : 
    8936              :   return blocks_split;
    8937              : }
    8938              : 
    8939              : /* Removes edge E and all the blocks dominated by it, and updates dominance
    8940              :    information.  The IL in E->src needs to be updated separately.
    8941              :    If dominance info is not available, only the edge E is removed.*/
    8942              : 
    8943              : void
    8944      3562834 : remove_edge_and_dominated_blocks (edge e)
    8945              : {
    8946      3562834 :   vec<basic_block> bbs_to_fix_dom = vNULL;
    8947      3562834 :   edge f;
    8948      3562834 :   edge_iterator ei;
    8949      3562834 :   bool none_removed = false;
    8950      3562834 :   unsigned i;
    8951      3562834 :   basic_block bb, dbb;
    8952      3562834 :   bitmap_iterator bi;
    8953              : 
    8954              :   /* If we are removing a path inside a non-root loop that may change
    8955              :      loop ownership of blocks or remove loops.  Mark loops for fixup.  */
    8956      3562834 :   class loop *src_loop = e->src->loop_father;
    8957      3562834 :   if (current_loops
    8958      3305395 :       && loop_outer (src_loop) != NULL
    8959      4210321 :       && src_loop == e->dest->loop_father)
    8960              :     {
    8961       265562 :       loops_state_set (LOOPS_NEED_FIXUP);
    8962              :       /* If we are removing a backedge clear the number of iterations
    8963              :          and estimates.  */
    8964       265562 :       class loop *dest_loop = e->dest->loop_father;
    8965       265562 :       if (e->dest == src_loop->header
    8966       265562 :           || (e->dest == dest_loop->header
    8967            0 :               && flow_loop_nested_p (dest_loop, src_loop)))
    8968              :         {
    8969         9156 :           free_numbers_of_iterations_estimates (dest_loop);
    8970              :           /* If we removed the last backedge mark the loop for removal.  */
    8971        27389 :           FOR_EACH_EDGE (f, ei, dest_loop->header->preds)
    8972        18446 :             if (f != e
    8973        18446 :                 && (f->src->loop_father == dest_loop
    8974         9158 :                     || flow_loop_nested_p (dest_loop, f->src->loop_father)))
    8975              :               break;
    8976         9156 :           if (!f)
    8977         8943 :             mark_loop_for_removal (dest_loop);
    8978              :         }
    8979              :     }
    8980              : 
    8981      3562834 :   if (!dom_info_available_p (CDI_DOMINATORS))
    8982              :     {
    8983      3365108 :       remove_edge (e);
    8984      6730216 :       return;
    8985              :     }
    8986              : 
    8987              :   /* No updating is needed for edges to exit.  */
    8988       197726 :   if (e->dest == EXIT_BLOCK_PTR_FOR_FN (cfun))
    8989              :     {
    8990            0 :       if (cfgcleanup_altered_bbs)
    8991            0 :         bitmap_set_bit (cfgcleanup_altered_bbs, e->src->index);
    8992            0 :       remove_edge (e);
    8993            0 :       return;
    8994              :     }
    8995              : 
    8996              :   /* First, we find the basic blocks to remove.  If E->dest has a predecessor
    8997              :      that is not dominated by E->dest, then this set is empty.  Otherwise,
    8998              :      all the basic blocks dominated by E->dest are removed.
    8999              : 
    9000              :      Also, to DF_IDOM we store the immediate dominators of the blocks in
    9001              :      the dominance frontier of E (i.e., of the successors of the
    9002              :      removed blocks, if there are any, and of E->dest otherwise).  */
    9003       213320 :   FOR_EACH_EDGE (f, ei, e->dest->preds)
    9004              :     {
    9005       208233 :       if (f == e)
    9006        15539 :         continue;
    9007              : 
    9008       192694 :       if (!dominated_by_p (CDI_DOMINATORS, f->src, e->dest))
    9009              :         {
    9010              :           none_removed = true;
    9011              :           break;
    9012              :         }
    9013              :     }
    9014              : 
    9015       197726 :   auto_bitmap df, df_idom;
    9016       197726 :   auto_vec<basic_block> bbs_to_remove;
    9017       197726 :   if (none_removed)
    9018       192639 :     bitmap_set_bit (df_idom,
    9019       192639 :                     get_immediate_dominator (CDI_DOMINATORS, e->dest)->index);
    9020              :   else
    9021              :     {
    9022         5087 :       bbs_to_remove = get_all_dominated_blocks (CDI_DOMINATORS, e->dest);
    9023        11377 :       FOR_EACH_VEC_ELT (bbs_to_remove, i, bb)
    9024              :         {
    9025        12708 :           FOR_EACH_EDGE (f, ei, bb->succs)
    9026              :             {
    9027         6418 :               if (f->dest != EXIT_BLOCK_PTR_FOR_FN (cfun))
    9028         6415 :                 bitmap_set_bit (df, f->dest->index);
    9029              :             }
    9030              :         }
    9031        11377 :       FOR_EACH_VEC_ELT (bbs_to_remove, i, bb)
    9032         6290 :         bitmap_clear_bit (df, bb->index);
    9033              : 
    9034         9948 :       EXECUTE_IF_SET_IN_BITMAP (df, 0, i, bi)
    9035              :         {
    9036         4861 :           bb = BASIC_BLOCK_FOR_FN (cfun, i);
    9037         4861 :           bitmap_set_bit (df_idom,
    9038         4861 :                           get_immediate_dominator (CDI_DOMINATORS, bb)->index);
    9039              :         }
    9040              :     }
    9041              : 
    9042       197726 :   if (cfgcleanup_altered_bbs)
    9043              :     {
    9044              :       /* Record the set of the altered basic blocks.  */
    9045        15048 :       bitmap_set_bit (cfgcleanup_altered_bbs, e->src->index);
    9046        15048 :       bitmap_ior_into (cfgcleanup_altered_bbs, df);
    9047              :     }
    9048              : 
    9049              :   /* Remove E and the cancelled blocks.  */
    9050       197726 :   if (none_removed)
    9051       192639 :     remove_edge (e);
    9052              :   else
    9053              :     {
    9054              :       /* Walk backwards so as to get a chance to substitute all
    9055              :          released DEFs into debug stmts.  See
    9056              :          eliminate_unnecessary_stmts() in tree-ssa-dce.cc for more
    9057              :          details.  */
    9058        16464 :       for (i = bbs_to_remove.length (); i-- > 0; )
    9059         6290 :         delete_basic_block (bbs_to_remove[i]);
    9060              :     }
    9061              : 
    9062              :   /* Update the dominance information.  The immediate dominator may change only
    9063              :      for blocks whose immediate dominator belongs to DF_IDOM:
    9064              : 
    9065              :      Suppose that idom(X) = Y before removal of E and idom(X) != Y after the
    9066              :      removal.  Let Z the arbitrary block such that idom(Z) = Y and
    9067              :      Z dominates X after the removal.  Before removal, there exists a path P
    9068              :      from Y to X that avoids Z.  Let F be the last edge on P that is
    9069              :      removed, and let W = F->dest.  Before removal, idom(W) = Y (since Y
    9070              :      dominates W, and because of P, Z does not dominate W), and W belongs to
    9071              :      the dominance frontier of E.  Therefore, Y belongs to DF_IDOM.  */
    9072       394578 :   EXECUTE_IF_SET_IN_BITMAP (df_idom, 0, i, bi)
    9073              :     {
    9074       196852 :       bb = BASIC_BLOCK_FOR_FN (cfun, i);
    9075       196852 :       for (dbb = first_dom_son (CDI_DOMINATORS, bb);
    9076       690630 :            dbb;
    9077       493778 :            dbb = next_dom_son (CDI_DOMINATORS, dbb))
    9078       493778 :         bbs_to_fix_dom.safe_push (dbb);
    9079              :     }
    9080              : 
    9081       197726 :   iterate_fix_dominators (CDI_DOMINATORS, bbs_to_fix_dom, true);
    9082              : 
    9083       197726 :   bbs_to_fix_dom.release ();
    9084       197726 : }
    9085              : 
    9086              : /* Purge dead EH edges from basic block BB.  */
    9087              : 
    9088              : bool
    9089    420313586 : gimple_purge_dead_eh_edges (basic_block bb)
    9090              : {
    9091    420313586 :   bool changed = false;
    9092    420313586 :   edge e;
    9093    420313586 :   edge_iterator ei;
    9094    420313586 :   gimple *stmt = *gsi_last_bb (bb);
    9095              : 
    9096    420313586 :   if (stmt && stmt_can_throw_internal (cfun, stmt))
    9097              :     return false;
    9098              : 
    9099    907494610 :   for (ei = ei_start (bb->succs); (e = ei_safe_edge (ei)); )
    9100              :     {
    9101    527278620 :       if (e->flags & EDGE_EH)
    9102              :         {
    9103       868166 :           remove_edge_and_dominated_blocks (e);
    9104       868166 :           changed = true;
    9105              :         }
    9106              :       else
    9107    526410454 :         ei_next (&ei);
    9108              :     }
    9109              : 
    9110              :   return changed;
    9111              : }
    9112              : 
    9113              : /* Purge dead EH edges from basic block listed in BLOCKS.  */
    9114              : 
    9115              : bool
    9116      7144922 : gimple_purge_all_dead_eh_edges (const_bitmap blocks)
    9117              : {
    9118      7144922 :   bool changed = false;
    9119      7144922 :   unsigned i;
    9120      7144922 :   bitmap_iterator bi;
    9121              : 
    9122      7332015 :   EXECUTE_IF_SET_IN_BITMAP (blocks, 0, i, bi)
    9123              :     {
    9124       187093 :       basic_block bb = BASIC_BLOCK_FOR_FN (cfun, i);
    9125              : 
    9126              :       /* Earlier gimple_purge_dead_eh_edges could have removed
    9127              :          this basic block already.  */
    9128       187093 :       gcc_assert (bb || changed);
    9129       187093 :       if (bb != NULL)
    9130       187075 :         changed |= gimple_purge_dead_eh_edges (bb);
    9131              :     }
    9132              : 
    9133      7144922 :   return changed;
    9134              : }
    9135              : 
    9136              : /* Purge dead abnormal call edges from basic block BB.  */
    9137              : 
    9138              : bool
    9139     83113870 : gimple_purge_dead_abnormal_call_edges (basic_block bb)
    9140              : {
    9141     83113870 :   bool changed = false;
    9142     83113870 :   edge e;
    9143     83113870 :   edge_iterator ei;
    9144     83113870 :   gimple *stmt = *gsi_last_bb (bb);
    9145              : 
    9146     83113870 :   if (stmt && stmt_can_make_abnormal_goto (stmt))
    9147              :     return false;
    9148              : 
    9149    196165653 :   for (ei = ei_start (bb->succs); (e = ei_safe_edge (ei)); )
    9150              :     {
    9151    113098665 :       if (e->flags & EDGE_ABNORMAL)
    9152              :         {
    9153         1445 :           if (e->flags & EDGE_FALLTHRU)
    9154            0 :             e->flags &= ~EDGE_ABNORMAL;
    9155              :           else
    9156         1445 :             remove_edge_and_dominated_blocks (e);
    9157              :           changed = true;
    9158              :         }
    9159              :       else
    9160    113097220 :         ei_next (&ei);
    9161              :     }
    9162              : 
    9163              :   return changed;
    9164              : }
    9165              : 
    9166              : /* Purge dead abnormal call edges from basic block listed in BLOCKS.  */
    9167              : 
    9168              : bool
    9169      7087255 : gimple_purge_all_dead_abnormal_call_edges (const_bitmap blocks)
    9170              : {
    9171      7087255 :   bool changed = false;
    9172      7087255 :   unsigned i;
    9173      7087255 :   bitmap_iterator bi;
    9174              : 
    9175      7087274 :   EXECUTE_IF_SET_IN_BITMAP (blocks, 0, i, bi)
    9176              :     {
    9177           19 :       basic_block bb = BASIC_BLOCK_FOR_FN (cfun, i);
    9178              : 
    9179              :       /* Earlier gimple_purge_dead_abnormal_call_edges could have removed
    9180              :          this basic block already.  */
    9181           19 :       gcc_assert (bb || changed);
    9182           19 :       if (bb != NULL)
    9183           19 :         changed |= gimple_purge_dead_abnormal_call_edges (bb);
    9184              :     }
    9185              : 
    9186      7087255 :   return changed;
    9187              : }
    9188              : 
    9189              : /* This function is called whenever a new edge is created or
    9190              :    redirected.  */
    9191              : 
    9192              : static void
    9193    156582398 : gimple_execute_on_growing_pred (edge e)
    9194              : {
    9195    156582398 :   basic_block bb = e->dest;
    9196              : 
    9197    156582398 :   if (!gimple_seq_empty_p (phi_nodes (bb)))
    9198     30036669 :     reserve_phi_args_for_new_edge (bb);
    9199    156582398 : }
    9200              : 
    9201              : /* This function is called immediately before edge E is removed from
    9202              :    the edge vector E->dest->preds.  */
    9203              : 
    9204              : static void
    9205    128053128 : gimple_execute_on_shrinking_pred (edge e)
    9206              : {
    9207    128053128 :   if (!gimple_seq_empty_p (phi_nodes (e->dest)))
    9208     34209704 :     remove_phi_args (e);
    9209    128053128 : }
    9210              : 
    9211              : /*---------------------------------------------------------------------------
    9212              :   Helper functions for Loop versioning
    9213              :   ---------------------------------------------------------------------------*/
    9214              : 
    9215              : /* Adjust phi nodes for 'first' basic block.  'second' basic block is a copy
    9216              :    of 'first'. Both of them are dominated by 'new_head' basic block. When
    9217              :    'new_head' was created by 'second's incoming edge it received phi arguments
    9218              :    on the edge by split_edge(). Later, additional edge 'e' was created to
    9219              :    connect 'new_head' and 'first'. Now this routine adds phi args on this
    9220              :    additional edge 'e' that new_head to second edge received as part of edge
    9221              :    splitting.  */
    9222              : 
    9223              : static void
    9224        38993 : gimple_lv_adjust_loop_header_phi (basic_block first, basic_block second,
    9225              :                                   basic_block new_head, edge e)
    9226              : {
    9227        38993 :   gphi *phi1, *phi2;
    9228        38993 :   gphi_iterator psi1, psi2;
    9229        38993 :   tree def;
    9230        38993 :   edge e2 = find_edge (new_head, second);
    9231              : 
    9232              :   /* Because NEW_HEAD has been created by splitting SECOND's incoming
    9233              :      edge, we should always have an edge from NEW_HEAD to SECOND.  */
    9234        38993 :   gcc_assert (e2 != NULL);
    9235              : 
    9236              :   /* Browse all 'second' basic block phi nodes and add phi args to
    9237              :      edge 'e' for 'first' head. PHI args are always in correct order.  */
    9238              : 
    9239        38993 :   for (psi2 = gsi_start_phis (second),
    9240        38993 :        psi1 = gsi_start_phis (first);
    9241       149026 :        !gsi_end_p (psi2) && !gsi_end_p (psi1);
    9242       110033 :        gsi_next (&psi2),  gsi_next (&psi1))
    9243              :     {
    9244       110033 :       phi1 = psi1.phi ();
    9245       110033 :       phi2 = psi2.phi ();
    9246       110033 :       def = PHI_ARG_DEF (phi2, e2->dest_idx);
    9247       110033 :       add_phi_arg (phi1, def, e, gimple_phi_arg_location_from_edge (phi2, e2));
    9248              :     }
    9249        38993 : }
    9250              : 
    9251              : 
    9252              : /* Adds a if else statement to COND_BB with condition COND_EXPR.
    9253              :    SECOND_HEAD is the destination of the THEN and FIRST_HEAD is
    9254              :    the destination of the ELSE part.  */
    9255              : 
    9256              : static void
    9257        38993 : gimple_lv_add_condition_to_bb (basic_block first_head ATTRIBUTE_UNUSED,
    9258              :                                basic_block second_head ATTRIBUTE_UNUSED,
    9259              :                                basic_block cond_bb, void *cond_e)
    9260              : {
    9261        38993 :   gimple_stmt_iterator gsi;
    9262        38993 :   gimple *new_cond_expr;
    9263        38993 :   tree cond_expr = (tree) cond_e;
    9264        38993 :   edge e0;
    9265              : 
    9266              :   /* Build new conditional expr */
    9267        38993 :   gsi = gsi_last_bb (cond_bb);
    9268              : 
    9269        38993 :   cond_expr = force_gimple_operand_gsi_1 (&gsi, cond_expr,
    9270              :                                           is_gimple_condexpr_for_cond,
    9271              :                                           NULL_TREE, false,
    9272              :                                           GSI_CONTINUE_LINKING);
    9273        38993 :   new_cond_expr = gimple_build_cond_from_tree (cond_expr,
    9274              :                                                NULL_TREE, NULL_TREE);
    9275              : 
    9276              :   /* Add new cond in cond_bb.  */
    9277        38993 :   gsi_insert_after (&gsi, new_cond_expr, GSI_NEW_STMT);
    9278              : 
    9279              :   /* Adjust edges appropriately to connect new head with first head
    9280              :      as well as second head.  */
    9281        38993 :   e0 = single_succ_edge (cond_bb);
    9282        38993 :   e0->flags &= ~EDGE_FALLTHRU;
    9283        38993 :   e0->flags |= EDGE_FALSE_VALUE;
    9284        38993 : }
    9285              : 
    9286              : 
    9287              : /* Do book-keeping of basic block BB for the profile consistency checker.
    9288              :    Store the counting in RECORD.  */
    9289              : static void
    9290            0 : gimple_account_profile_record (basic_block bb,
    9291              :                                struct profile_record *record)
    9292              : {
    9293            0 :   gimple_stmt_iterator i;
    9294            0 :   for (i = gsi_start_nondebug_after_labels_bb (bb); !gsi_end_p (i);
    9295            0 :        gsi_next_nondebug (&i))
    9296              :     {
    9297            0 :       record->size
    9298            0 :         += estimate_num_insns (gsi_stmt (i), &eni_size_weights);
    9299            0 :       if (profile_info)
    9300              :         {
    9301            0 :           if (ENTRY_BLOCK_PTR_FOR_FN (cfun)->count.ipa ().initialized_p ()
    9302            0 :               && ENTRY_BLOCK_PTR_FOR_FN (cfun)->count.ipa ().nonzero_p ()
    9303            0 :               && bb->count.ipa ().initialized_p ())
    9304            0 :             record->time
    9305            0 :               += estimate_num_insns (gsi_stmt (i),
    9306              :                                      &eni_time_weights)
    9307            0 :                                      * bb->count.ipa ().to_gcov_type ();
    9308              :         }
    9309            0 :       else if (bb->count.initialized_p ()
    9310            0 :                && ENTRY_BLOCK_PTR_FOR_FN (cfun)->count.initialized_p ())
    9311            0 :         record->time
    9312            0 :           += estimate_num_insns
    9313            0 :                 (gsi_stmt (i),
    9314              :                  &eni_time_weights)
    9315            0 :                  * bb->count.to_sreal_scale
    9316            0 :                         (ENTRY_BLOCK_PTR_FOR_FN (cfun)->count).to_double ();
    9317              :      else
    9318            0 :       record->time
    9319            0 :         += estimate_num_insns (gsi_stmt (i), &eni_time_weights);
    9320              :     }
    9321            0 : }
    9322              : 
    9323              : const struct cfg_hooks gimple_cfg_hooks = {
    9324              :   IR_GIMPLE,
    9325              :   gimple_verify_flow_info,
    9326              :   gimple_dump_bb,               /* dump_bb  */
    9327              :   gimple_dump_bb_for_graph,     /* dump_bb_for_graph  */
    9328              :   gimple_dump_bb_as_sarif_properties,
    9329              :   create_bb,                    /* create_basic_block  */
    9330              :   gimple_redirect_edge_and_branch, /* redirect_edge_and_branch  */
    9331              :   gimple_redirect_edge_and_branch_force, /* redirect_edge_and_branch_force  */
    9332              :   gimple_can_remove_branch_p,   /* can_remove_branch_p  */
    9333              :   remove_bb,                    /* delete_basic_block  */
    9334              :   gimple_split_block,           /* split_block  */
    9335              :   gimple_move_block_after,      /* move_block_after  */
    9336              :   gimple_can_merge_blocks_p,    /* can_merge_blocks_p  */
    9337              :   gimple_merge_blocks,          /* merge_blocks  */
    9338              :   gimple_predict_edge,          /* predict_edge  */
    9339              :   gimple_predicted_by_p,        /* predicted_by_p  */
    9340              :   gimple_can_duplicate_bb_p,    /* can_duplicate_block_p  */
    9341              :   gimple_duplicate_bb,          /* duplicate_block  */
    9342              :   gimple_split_edge,            /* split_edge  */
    9343              :   gimple_make_forwarder_block,  /* make_forward_block  */
    9344              :   NULL,                         /* tidy_fallthru_edge  */
    9345              :   NULL,                         /* force_nonfallthru */
    9346              :   gimple_block_ends_with_call_p,/* block_ends_with_call_p */
    9347              :   gimple_block_ends_with_condjump_p, /* block_ends_with_condjump_p */
    9348              :   gimple_flow_call_edges_add,   /* flow_call_edges_add */
    9349              :   gimple_execute_on_growing_pred,       /* execute_on_growing_pred */
    9350              :   gimple_execute_on_shrinking_pred, /* execute_on_shrinking_pred */
    9351              :   gimple_duplicate_loop_body_to_header_edge, /* duplicate loop for trees */
    9352              :   gimple_lv_add_condition_to_bb, /* lv_add_condition_to_bb */
    9353              :   gimple_lv_adjust_loop_header_phi, /* lv_adjust_loop_header_phi*/
    9354              :   extract_true_false_edges_from_block, /* extract_cond_bb_edges */
    9355              :   flush_pending_stmts,          /* flush_pending_stmts */
    9356              :   gimple_empty_block_p,           /* block_empty_p */
    9357              :   gimple_split_block_before_cond_jump, /* split_block_before_cond_jump */
    9358              :   gimple_account_profile_record,
    9359              : };
    9360              : 
    9361              : 
    9362              : /* Split all critical edges.  Split some extra (not necessarily critical) edges
    9363              :    if FOR_EDGE_INSERTION_P is true.  */
    9364              : 
    9365              : unsigned int
    9366      4220060 : split_critical_edges (bool for_edge_insertion_p /* = false */)
    9367              : {
    9368      4220060 :   basic_block bb;
    9369      4220060 :   edge e;
    9370      4220060 :   edge_iterator ei;
    9371              : 
    9372              :   /* split_edge can redirect edges out of SWITCH_EXPRs, which can get
    9373              :      expensive.  So we want to enable recording of edge to CASE_LABEL_EXPR
    9374              :      mappings around the calls to split_edge.  */
    9375      4220060 :   start_recording_case_labels ();
    9376     73277002 :   FOR_ALL_BB_FN (bb, cfun)
    9377              :     {
    9378    153124821 :       FOR_EACH_EDGE (e, ei, bb->succs)
    9379              :         {
    9380     84067879 :           if (EDGE_CRITICAL_P (e) && !(e->flags & EDGE_ABNORMAL))
    9381     14578847 :             split_edge (e);
    9382              :           /* PRE inserts statements to edges and expects that
    9383              :              since split_critical_edges was done beforehand, committing edge
    9384              :              insertions will not split more edges.  In addition to critical
    9385              :              edges we must split edges that have multiple successors and
    9386              :              end by control flow statements, such as RESX.
    9387              :              Go ahead and split them too.  This matches the logic in
    9388              :              gimple_find_edge_insert_loc.  */
    9389     69489032 :           else if (for_edge_insertion_p
    9390     54316540 :                    && (!single_pred_p (e->dest)
    9391     30305433 :                        || !gimple_seq_empty_p (phi_nodes (e->dest))
    9392     30070163 :                        || e->dest == EXIT_BLOCK_PTR_FOR_FN (cfun))
    9393     27337027 :                    && e->src != ENTRY_BLOCK_PTR_FOR_FN (cfun)
    9394     96825644 :                    && !(e->flags & EDGE_ABNORMAL))
    9395              :             {
    9396     27320814 :               gimple_stmt_iterator gsi;
    9397              : 
    9398     27320814 :               gsi = gsi_last_bb (e->src);
    9399     27320814 :               if (!gsi_end_p (gsi)
    9400     13360250 :                   && stmt_ends_bb_p (gsi_stmt (gsi))
    9401     30614370 :                   && (gimple_code (gsi_stmt (gsi)) != GIMPLE_RETURN
    9402       195505 :                       && !gimple_call_builtin_p (gsi_stmt (gsi),
    9403              :                                                  BUILT_IN_RETURN)))
    9404       194454 :                 split_edge (e);
    9405              :             }
    9406              :         }
    9407              :     }
    9408      4220060 :   end_recording_case_labels ();
    9409      4220060 :   return 0;
    9410              : }
    9411              : 
    9412              : namespace {
    9413              : 
    9414              : const pass_data pass_data_split_crit_edges =
    9415              : {
    9416              :   GIMPLE_PASS, /* type */
    9417              :   "crited", /* name */
    9418              :   OPTGROUP_NONE, /* optinfo_flags */
    9419              :   TV_TREE_SPLIT_EDGES, /* tv_id */
    9420              :   PROP_cfg, /* properties_required */
    9421              :   PROP_no_crit_edges, /* properties_provided */
    9422              :   0, /* properties_destroyed */
    9423              :   0, /* todo_flags_start */
    9424              :   0, /* todo_flags_finish */
    9425              : };
    9426              : 
    9427              : class pass_split_crit_edges : public gimple_opt_pass
    9428              : {
    9429              : public:
    9430       597656 :   pass_split_crit_edges (gcc::context *ctxt)
    9431      1195312 :     : gimple_opt_pass (pass_data_split_crit_edges, ctxt)
    9432              :   {}
    9433              : 
    9434              :   /* opt_pass methods: */
    9435      1042216 :   unsigned int execute (function *)  final override
    9436              :   {
    9437      1042216 :     return split_critical_edges ();
    9438              :   }
    9439              : 
    9440       298828 :   opt_pass * clone () final override
    9441              :   {
    9442       298828 :     return new pass_split_crit_edges (m_ctxt);
    9443              :   }
    9444              : }; // class pass_split_crit_edges
    9445              : 
    9446              : } // anon namespace
    9447              : 
    9448              : gimple_opt_pass *
    9449       298828 : make_pass_split_crit_edges (gcc::context *ctxt)
    9450              : {
    9451       298828 :   return new pass_split_crit_edges (ctxt);
    9452              : }
    9453              : 
    9454              : 
    9455              : /* Insert COND expression which is GIMPLE_COND after STMT
    9456              :    in basic block BB with appropriate basic block split
    9457              :    and creation of a new conditionally executed basic block.
    9458              :    Update profile so the new bb is visited with probability PROB.
    9459              :    Return created basic block.  */
    9460              : basic_block
    9461         2091 : insert_cond_bb (basic_block bb, gimple *stmt, gimple *cond,
    9462              :                 profile_probability prob)
    9463              : {
    9464         2091 :   edge fall = split_block (bb, stmt);
    9465         2091 :   gimple_stmt_iterator iter = gsi_last_bb (bb);
    9466         2091 :   basic_block new_bb;
    9467              : 
    9468              :   /* Insert cond statement.  */
    9469         2091 :   gcc_assert (gimple_code (cond) == GIMPLE_COND);
    9470         2091 :   if (gsi_end_p (iter))
    9471            0 :     gsi_insert_before (&iter, cond, GSI_CONTINUE_LINKING);
    9472              :   else
    9473         2091 :     gsi_insert_after (&iter, cond, GSI_CONTINUE_LINKING);
    9474              : 
    9475              :   /* Create conditionally executed block.  */
    9476         2091 :   new_bb = create_empty_bb (bb);
    9477         2091 :   edge e = make_edge (bb, new_bb, EDGE_TRUE_VALUE);
    9478         2091 :   e->probability = prob;
    9479         2091 :   new_bb->count = e->count ();
    9480         2091 :   make_single_succ_edge (new_bb, fall->dest, EDGE_FALLTHRU);
    9481              : 
    9482              :   /* Fix edge for split bb.  */
    9483         2091 :   fall->flags = EDGE_FALSE_VALUE;
    9484         2091 :   fall->probability -= e->probability;
    9485              : 
    9486              :   /* Update dominance info.  */
    9487         2091 :   if (dom_info_available_p (CDI_DOMINATORS))
    9488              :     {
    9489         2091 :       set_immediate_dominator (CDI_DOMINATORS, new_bb, bb);
    9490         2091 :       set_immediate_dominator (CDI_DOMINATORS, fall->dest, bb);
    9491              :     }
    9492              : 
    9493              :   /* Update loop info.  */
    9494         2091 :   if (current_loops)
    9495         2091 :     add_bb_to_loop (new_bb, bb->loop_father);
    9496              : 
    9497         2091 :   return new_bb;
    9498              : }
    9499              : 
    9500              : 
    9501              : 
    9502              : /* Given a basic block B which ends with a conditional and has
    9503              :    precisely two successors, determine which of the edges is taken if
    9504              :    the conditional is true and which is taken if the conditional is
    9505              :    false.  Set TRUE_EDGE and FALSE_EDGE appropriately.  */
    9506              : 
    9507              : void
    9508    824927926 : extract_true_false_edges_from_block (basic_block b,
    9509              :                                      edge *true_edge,
    9510              :                                      edge *false_edge)
    9511              : {
    9512    824927926 :   edge e = EDGE_SUCC (b, 0);
    9513              : 
    9514    824927926 :   if (e->flags & EDGE_TRUE_VALUE)
    9515              :     {
    9516    790877921 :       *true_edge = e;
    9517    790877921 :       *false_edge = EDGE_SUCC (b, 1);
    9518              :     }
    9519              :   else
    9520              :     {
    9521     34050005 :       *false_edge = e;
    9522     34050005 :       *true_edge = EDGE_SUCC (b, 1);
    9523              :     }
    9524    824927926 : }
    9525              : 
    9526              : 
    9527              : /* From a controlling predicate in the immediate dominator DOM of
    9528              :    PHIBLOCK determine the edges into PHIBLOCK that are chosen if the
    9529              :    predicate evaluates to true and false and store them to
    9530              :    *TRUE_CONTROLLED_EDGE and *FALSE_CONTROLLED_EDGE if
    9531              :    they are non-NULL.  Returns true if the edges can be determined,
    9532              :    else return false.  */
    9533              : 
    9534              : bool
    9535       142608 : extract_true_false_controlled_edges (basic_block dom, basic_block phiblock,
    9536              :                                      edge *true_controlled_edge,
    9537              :                                      edge *false_controlled_edge)
    9538              : {
    9539       142608 :   basic_block bb = phiblock;
    9540       142608 :   edge true_edge, false_edge, tem;
    9541       142608 :   edge e0 = NULL, e1 = NULL;
    9542              : 
    9543              :   /* We have to verify that one edge into the PHI node is dominated
    9544              :      by the true edge of the predicate block and the other edge
    9545              :      dominated by the false edge.  This ensures that the PHI argument
    9546              :      we are going to take is completely determined by the path we
    9547              :      take from the predicate block.
    9548              :      We can only use BB dominance checks below if the destination of
    9549              :      the true/false edges are dominated by their edge, thus only
    9550              :      have a single predecessor.  */
    9551       142608 :   extract_true_false_edges_from_block (dom, &true_edge, &false_edge);
    9552       142608 :   tem = EDGE_PRED (bb, 0);
    9553       142608 :   if (tem == true_edge
    9554       142608 :       || (single_pred_p (true_edge->dest)
    9555       104684 :           && (tem->src == true_edge->dest
    9556        64776 :               || dominated_by_p (CDI_DOMINATORS,
    9557              :                                  tem->src, true_edge->dest))))
    9558              :     e0 = tem;
    9559        57694 :   else if (tem == false_edge
    9560        57694 :            || (single_pred_p (false_edge->dest)
    9561        47877 :                && (tem->src == false_edge->dest
    9562        34718 :                    || dominated_by_p (CDI_DOMINATORS,
    9563              :                                       tem->src, false_edge->dest))))
    9564              :     e1 = tem;
    9565              :   else
    9566        25434 :     return false;
    9567       117174 :   tem = EDGE_PRED (bb, 1);
    9568       117174 :   if (tem == true_edge
    9569       117174 :       || (single_pred_p (true_edge->dest)
    9570        84988 :           && (tem->src == true_edge->dest
    9571        67855 :               || dominated_by_p (CDI_DOMINATORS,
    9572              :                                  tem->src, true_edge->dest))))
    9573              :     e0 = tem;
    9574        88589 :   else if (tem == false_edge
    9575        88589 :            || (single_pred_p (false_edge->dest)
    9576        71045 :                && (tem->src == false_edge->dest
    9577        29666 :                    || dominated_by_p (CDI_DOMINATORS,
    9578              :                                       tem->src, false_edge->dest))))
    9579              :     e1 = tem;
    9580              :   else
    9581        11695 :     return false;
    9582       105479 :   if (!e0 || !e1)
    9583              :     return false;
    9584              : 
    9585       105479 :   if (true_controlled_edge)
    9586       105479 :     *true_controlled_edge = e0;
    9587       105479 :   if (false_controlled_edge)
    9588       105479 :     *false_controlled_edge = e1;
    9589              : 
    9590              :   return true;
    9591              : }
    9592              : 
    9593              : /* Generate a range test LHS CODE RHS that determines whether INDEX is in the
    9594              :     range [low, high].  Place associated stmts before *GSI.  */
    9595              : 
    9596              : void
    9597         2954 : generate_range_test (basic_block bb, tree index, tree low, tree high,
    9598              :                      tree *lhs, tree *rhs)
    9599              : {
    9600         2954 :   tree type = TREE_TYPE (index);
    9601         2954 :   tree utype = range_check_type (type);
    9602              : 
    9603         2954 :   low = fold_convert (utype, low);
    9604         2954 :   high = fold_convert (utype, high);
    9605              : 
    9606         2954 :   gimple_seq seq = NULL;
    9607         2954 :   index = gimple_convert (&seq, utype, index);
    9608         2954 :   *lhs = gimple_build (&seq, MINUS_EXPR, utype, index, low);
    9609         2954 :   *rhs = const_binop (MINUS_EXPR, utype, high, low);
    9610              : 
    9611         2954 :   gimple_stmt_iterator gsi = gsi_last_bb (bb);
    9612         2954 :   gsi_insert_seq_before (&gsi, seq, GSI_SAME_STMT);
    9613         2954 : }
    9614              : 
    9615              : /* Return the basic block that belongs to label numbered INDEX
    9616              :    of a switch statement.  */
    9617              : 
    9618              : basic_block
    9619     58328043 : gimple_switch_label_bb (function *ifun, gswitch *gs, unsigned index)
    9620              : {
    9621     58328043 :   return label_to_block (ifun, CASE_LABEL (gimple_switch_label (gs, index)));
    9622              : }
    9623              : 
    9624              : /* Return the default basic block of a switch statement.  */
    9625              : 
    9626              : basic_block
    9627       327512 : gimple_switch_default_bb (function *ifun, gswitch *gs)
    9628              : {
    9629       327512 :   return gimple_switch_label_bb (ifun, gs, 0);
    9630              : }
    9631              : 
    9632              : /* Return the edge that belongs to label numbered INDEX
    9633              :    of a switch statement.  */
    9634              : 
    9635              : edge
    9636      1284214 : gimple_switch_edge (function *ifun, gswitch *gs, unsigned index)
    9637              : {
    9638      1284214 :   return find_edge (gimple_bb (gs), gimple_switch_label_bb (ifun, gs, index));
    9639              : }
    9640              : 
    9641              : /* Return the default edge of a switch statement.  */
    9642              : 
    9643              : edge
    9644       163025 : gimple_switch_default_edge (function *ifun, gswitch *gs)
    9645              : {
    9646       163025 :   return gimple_switch_edge (ifun, gs, 0);
    9647              : }
    9648              : 
    9649              : /* Return true if the only executable statement in BB is a GIMPLE_COND.  */
    9650              : 
    9651              : bool
    9652        12696 : cond_only_block_p (basic_block bb)
    9653              : {
    9654              :   /* BB must have no executable statements.  */
    9655        12696 :   gimple_stmt_iterator gsi = gsi_after_labels (bb);
    9656        12696 :   if (phi_nodes (bb))
    9657              :     return false;
    9658        28612 :   while (!gsi_end_p (gsi))
    9659              :     {
    9660        16625 :       gimple *stmt = gsi_stmt (gsi);
    9661        16625 :       if (is_gimple_debug (stmt))
    9662              :         ;
    9663        12696 :       else if (gimple_code (stmt) == GIMPLE_NOP
    9664              :                || gimple_code (stmt) == GIMPLE_PREDICT
    9665              :                || gimple_code (stmt) == GIMPLE_COND)
    9666              :         ;
    9667              :       else
    9668              :         return false;
    9669        15916 :       gsi_next (&gsi);
    9670              :     }
    9671              :   return true;
    9672              : }
    9673              : 
    9674              : 
    9675              : /* Emit return warnings.  */
    9676              : 
    9677              : namespace {
    9678              : 
    9679              : const pass_data pass_data_warn_function_return =
    9680              : {
    9681              :   GIMPLE_PASS, /* type */
    9682              :   "*warn_function_return", /* name */
    9683              :   OPTGROUP_NONE, /* optinfo_flags */
    9684              :   TV_NONE, /* tv_id */
    9685              :   PROP_cfg, /* properties_required */
    9686              :   0, /* properties_provided */
    9687              :   0, /* properties_destroyed */
    9688              :   0, /* todo_flags_start */
    9689              :   0, /* todo_flags_finish */
    9690              : };
    9691              : 
    9692              : class pass_warn_function_return : public gimple_opt_pass
    9693              : {
    9694              : public:
    9695       298828 :   pass_warn_function_return (gcc::context *ctxt)
    9696       597656 :     : gimple_opt_pass (pass_data_warn_function_return, ctxt)
    9697              :   {}
    9698              : 
    9699              :   /* opt_pass methods: */
    9700              :   unsigned int execute (function *) final override;
    9701              : 
    9702              : }; // class pass_warn_function_return
    9703              : 
    9704              : unsigned int
    9705      2880188 : pass_warn_function_return::execute (function *fun)
    9706              : {
    9707      2880188 :   location_t location;
    9708      2880188 :   gimple *last;
    9709      2880188 :   edge e;
    9710      2880188 :   edge_iterator ei;
    9711              : 
    9712      2880188 :   if (!targetm.warn_func_return (fun->decl))
    9713              :     return 0;
    9714              : 
    9715              :   /* If we have a path to EXIT, then we do return.  */
    9716      2880116 :   if (TREE_THIS_VOLATILE (fun->decl)
    9717      2880116 :       && EDGE_COUNT (EXIT_BLOCK_PTR_FOR_FN (fun)->preds) > 0)
    9718              :     {
    9719           90 :       location = UNKNOWN_LOCATION;
    9720           90 :       for (ei = ei_start (EXIT_BLOCK_PTR_FOR_FN (fun)->preds);
    9721          180 :            (e = ei_safe_edge (ei)); )
    9722              :         {
    9723           90 :           last = *gsi_last_bb (e->src);
    9724              :           /* Warn about __builtin_return .*/
    9725           90 :           if (gimple_call_builtin_p (last, BUILT_IN_RETURN)
    9726           90 :               && location == UNKNOWN_LOCATION)
    9727              :             {
    9728            1 :               location = LOCATION_LOCUS (gimple_location (last));
    9729            1 :               ei_next (&ei);
    9730              :             }
    9731              :           /* Replace return stmts in noreturn functions
    9732              :              with __builtin_unreachable () call.  */
    9733           89 :           else if (gimple_code (last) == GIMPLE_RETURN)
    9734              :             {
    9735           89 :               location_t loc = gimple_location (last);
    9736           89 :               if (location == UNKNOWN_LOCATION)
    9737           89 :                 location = LOCATION_LOCUS (loc);
    9738           89 :               gimple *new_stmt = gimple_build_builtin_unreachable (loc);
    9739           89 :               gimple_stmt_iterator gsi = gsi_for_stmt (last);
    9740           89 :               gsi_replace (&gsi, new_stmt, true);
    9741           89 :               remove_edge (e);
    9742              :             }
    9743              :           else
    9744            0 :             ei_next (&ei);
    9745              :         }
    9746           90 :       if (location == UNKNOWN_LOCATION)
    9747            2 :         location = cfun->function_end_locus;
    9748           90 :       warning_at (location, 0, "%<noreturn%> function does return");
    9749              :     }
    9750              : 
    9751              :   /* If we see "return;" in some basic block, then we do reach the end
    9752              :      without returning a value.  */
    9753      2880026 :   else if (warn_return_type > 0
    9754      1907295 :            && !warning_suppressed_p (fun->decl, OPT_Wreturn_type)
    9755      4784203 :            && !VOID_TYPE_P (TREE_TYPE (TREE_TYPE (fun->decl))))
    9756              :     {
    9757      1998113 :       FOR_EACH_EDGE (e, ei, EXIT_BLOCK_PTR_FOR_FN (fun)->preds)
    9758              :         {
    9759      2990014 :           greturn *return_stmt = dyn_cast <greturn *> (*gsi_last_bb (e->src));
    9760       996586 :           if (return_stmt
    9761       996586 :               && gimple_return_retval (return_stmt) == NULL
    9762           37 :               && !warning_suppressed_p (return_stmt, OPT_Wreturn_type))
    9763              :             {
    9764           16 :               location = gimple_location (return_stmt);
    9765           16 :               if (LOCATION_LOCUS (location) == UNKNOWN_LOCATION)
    9766            0 :                 location = fun->function_end_locus;
    9767           16 :               if (warning_at (location, OPT_Wreturn_type,
    9768              :                               "control reaches end of non-void function"))
    9769           14 :                 suppress_warning (fun->decl, OPT_Wreturn_type);
    9770              :               break;
    9771              :             }
    9772              :         }
    9773              :       /* The C++ FE turns fallthrough from the end of non-void function
    9774              :          into __builtin_unreachable () call with BUILTINS_LOCATION.
    9775              :          Recognize those as well as calls from ubsan_instrument_return.  */
    9776      1001407 :       basic_block bb;
    9777      1001407 :       if (!warning_suppressed_p (fun->decl, OPT_Wreturn_type))
    9778      4746231 :         FOR_EACH_BB_FN (bb, fun)
    9779      3745372 :           if (EDGE_COUNT (bb->succs) == 0)
    9780              :             {
    9781       177769 :               gimple *last = *gsi_last_bb (bb);
    9782       177769 :               const enum built_in_function ubsan_missing_ret
    9783              :                 = BUILT_IN_UBSAN_HANDLE_MISSING_RETURN;
    9784       177769 :               if (last
    9785       177769 :                   && ((LOCATION_LOCUS (gimple_location (last))
    9786              :                        == BUILTINS_LOCATION
    9787          519 :                        && (gimple_call_builtin_p (last, BUILT_IN_UNREACHABLE)
    9788          190 :                            || gimple_call_builtin_p (last,
    9789              :                                                      BUILT_IN_UNREACHABLE_TRAP)
    9790            3 :                            || gimple_call_builtin_p (last, BUILT_IN_TRAP)))
    9791       177250 :                       || gimple_call_builtin_p (last, ubsan_missing_ret)))
    9792              :                 {
    9793          534 :                   gimple_stmt_iterator gsi = gsi_for_stmt (last);
    9794          534 :                   gsi_prev_nondebug (&gsi);
    9795          534 :                   gimple *prev = gsi_stmt (gsi);
    9796          534 :                   if (prev == NULL)
    9797              :                     location = UNKNOWN_LOCATION;
    9798              :                   else
    9799          186 :                     location = gimple_location (prev);
    9800          534 :                   if (LOCATION_LOCUS (location) == UNKNOWN_LOCATION)
    9801          374 :                     location = fun->function_end_locus;
    9802          534 :                   if (warning_at (location, OPT_Wreturn_type,
    9803              :                                   "control reaches end of non-void function"))
    9804          123 :                     suppress_warning (fun->decl, OPT_Wreturn_type);
    9805          534 :                   break;
    9806              :                 }
    9807              :             }
    9808              :     }
    9809              :   return 0;
    9810              : }
    9811              : 
    9812              : } // anon namespace
    9813              : 
    9814              : gimple_opt_pass *
    9815       298828 : make_pass_warn_function_return (gcc::context *ctxt)
    9816              : {
    9817       298828 :   return new pass_warn_function_return (ctxt);
    9818              : }
    9819              : 
    9820              : /* Walk a gimplified function and warn for functions whose return value is
    9821              :    ignored and attribute((warn_unused_result)) is set.  This is done before
    9822              :    inlining, so we don't have to worry about that.  */
    9823              : 
    9824              : static void
    9825      9710303 : do_warn_unused_result (gimple_seq seq)
    9826              : {
    9827      9710303 :   tree fdecl, ftype;
    9828      9710303 :   gimple_stmt_iterator i;
    9829              : 
    9830     61354434 :   for (i = gsi_start (seq); !gsi_end_p (i); gsi_next (&i))
    9831              :     {
    9832     51644131 :       gimple *g = gsi_stmt (i);
    9833              : 
    9834     51644131 :       switch (gimple_code (g))
    9835              :         {
    9836      3456287 :         case GIMPLE_BIND:
    9837      3456287 :           do_warn_unused_result (gimple_bind_body (as_a <gbind *>(g)));
    9838      3456287 :           break;
    9839      1935895 :         case GIMPLE_TRY:
    9840      1935895 :           do_warn_unused_result (gimple_try_eval (g));
    9841      1935895 :           do_warn_unused_result (gimple_try_cleanup (g));
    9842      1935895 :           break;
    9843        20262 :         case GIMPLE_CATCH:
    9844        40524 :           do_warn_unused_result (gimple_catch_handler (
    9845        20262 :                                    as_a <gcatch *> (g)));
    9846        20262 :           break;
    9847         4632 :         case GIMPLE_EH_FILTER:
    9848         4632 :           do_warn_unused_result (gimple_eh_filter_failure (g));
    9849         4632 :           break;
    9850              : 
    9851      7652378 :         case GIMPLE_CALL:
    9852      7652378 :           if (gimple_call_lhs (g))
    9853              :             break;
    9854      4266953 :           if (gimple_call_internal_p (g))
    9855              :             break;
    9856      4244306 :           if (warning_suppressed_p (g, OPT_Wunused_result))
    9857              :             break;
    9858              : 
    9859              :           /* This is a naked call, as opposed to a GIMPLE_CALL with an
    9860              :              LHS.  All calls whose value is ignored should be
    9861              :              represented like this.  Look for the attribute.  */
    9862      4205164 :           fdecl = gimple_call_fndecl (g);
    9863      4205164 :           ftype = gimple_call_fntype (g);
    9864              : 
    9865      4205164 :           if (lookup_attribute ("warn_unused_result", TYPE_ATTRIBUTES (ftype)))
    9866              :             {
    9867          186 :               auto_urlify_attributes sentinel;
    9868              : 
    9869          186 :               location_t loc = gimple_location (g);
    9870              : 
    9871          186 :               if (fdecl)
    9872          114 :                 warning_at (loc, OPT_Wunused_result,
    9873              :                             "ignoring return value of %qD "
    9874              :                             "declared with attribute %<warn_unused_result%>",
    9875              :                             fdecl);
    9876              :               else
    9877           72 :                 warning_at (loc, OPT_Wunused_result,
    9878              :                             "ignoring return value of function "
    9879              :                             "declared with attribute %<warn_unused_result%>");
    9880          186 :             }
    9881              :           break;
    9882              : 
    9883              :         default:
    9884              :           /* Not a container, not a call, or a call whose value is used.  */
    9885              :           break;
    9886              :         }
    9887              :     }
    9888      9710303 : }
    9889              : 
    9890              : namespace {
    9891              : 
    9892              : const pass_data pass_data_warn_unused_result =
    9893              : {
    9894              :   GIMPLE_PASS, /* type */
    9895              :   "*warn_unused_result", /* name */
    9896              :   OPTGROUP_NONE, /* optinfo_flags */
    9897              :   TV_NONE, /* tv_id */
    9898              :   PROP_gimple_any, /* properties_required */
    9899              :   0, /* properties_provided */
    9900              :   0, /* properties_destroyed */
    9901              :   0, /* todo_flags_start */
    9902              :   0, /* todo_flags_finish */
    9903              : };
    9904              : 
    9905              : class pass_warn_unused_result : public gimple_opt_pass
    9906              : {
    9907              : public:
    9908       298828 :   pass_warn_unused_result (gcc::context *ctxt)
    9909       597656 :     : gimple_opt_pass (pass_data_warn_unused_result, ctxt)
    9910              :   {}
    9911              : 
    9912              :   /* opt_pass methods: */
    9913      2880212 :   bool gate (function *)  final override { return flag_warn_unused_result; }
    9914      2357332 :   unsigned int execute (function *) final override
    9915              :     {
    9916      2357332 :       do_warn_unused_result (gimple_body (current_function_decl));
    9917      2357332 :       return 0;
    9918              :     }
    9919              : 
    9920              : }; // class pass_warn_unused_result
    9921              : 
    9922              : } // anon namespace
    9923              : 
    9924              : gimple_opt_pass *
    9925       298828 : make_pass_warn_unused_result (gcc::context *ctxt)
    9926              : {
    9927       298828 :   return new pass_warn_unused_result (ctxt);
    9928              : }
    9929              : 
    9930              : /* Maybe Remove stores to variables we marked write-only.
    9931              :    Return true if a store was removed. */
    9932              : static bool
    9933    445231413 : maybe_remove_writeonly_store (gimple_stmt_iterator &gsi, gimple *stmt,
    9934              :                               bitmap dce_ssa_names)
    9935              : {
    9936              :   /* Keep access when store has side effect, i.e. in case when source
    9937              :      is volatile.  */
    9938    445231413 :   if (!gimple_store_p (stmt)
    9939     61867582 :       || gimple_has_side_effects (stmt)
    9940    495443572 :       || optimize_debug)
    9941    395070941 :     return false;
    9942              : 
    9943     50160472 :   tree lhs = get_base_address (gimple_get_lhs (stmt));
    9944              : 
    9945     50160472 :   if (!VAR_P (lhs)
    9946     39398045 :       || (!TREE_STATIC (lhs) && !DECL_EXTERNAL (lhs))
    9947     57101596 :       || !varpool_node::get (lhs)->writeonly)
    9948              :     return false;
    9949              : 
    9950        30436 :   if (dump_file && (dump_flags & TDF_DETAILS))
    9951              :     {
    9952            0 :       fprintf (dump_file, "Removing statement, writes"
    9953              :                " to write only var:\n");
    9954            0 :       print_gimple_stmt (dump_file, stmt, 0,
    9955              :                          TDF_VOPS|TDF_MEMSYMS);
    9956              :     }
    9957              : 
    9958              :   /* Mark ssa name defining to be checked for simple dce. */
    9959        30436 :   if (gimple_assign_single_p (stmt))
    9960              :     {
    9961        30436 :       tree rhs = gimple_assign_rhs1 (stmt);
    9962        30436 :       if (TREE_CODE (rhs) == SSA_NAME
    9963        30436 :           && !SSA_NAME_IS_DEFAULT_DEF (rhs))
    9964         9615 :         bitmap_set_bit (dce_ssa_names, SSA_NAME_VERSION (rhs));
    9965              :     }
    9966        30436 :   unlink_stmt_vdef (stmt);
    9967        30436 :   gsi_remove (&gsi, true);
    9968        30436 :   release_defs (stmt);
    9969        30436 :   return true;
    9970              : }
    9971              : 
    9972              : /* IPA passes, compilation of earlier functions or inlining
    9973              :    might have changed some properties, such as marked functions nothrow,
    9974              :    pure, const or noreturn.
    9975              :    Remove redundant edges and basic blocks, and create new ones if necessary. */
    9976              : 
    9977              : unsigned int
    9978     11062215 : execute_fixup_cfg (void)
    9979              : {
    9980     11062215 :   basic_block bb;
    9981     11062215 :   gimple_stmt_iterator gsi;
    9982     11062215 :   int todo = 0;
    9983     11062215 :   cgraph_node *node = cgraph_node::get (current_function_decl);
    9984              :   /* Same scaling is also done by ipa_merge_profiles.  */
    9985     11062215 :   profile_count num = node->count;
    9986     11062215 :   profile_count den = ENTRY_BLOCK_PTR_FOR_FN (cfun)->count;
    9987     11062215 :   bool scale = num.initialized_p () && !(num == den);
    9988     11062215 :   auto_bitmap dce_ssa_names;
    9989              : 
    9990     11062215 :   if (scale)
    9991              :     {
    9992        28937 :       profile_count::adjust_for_ipa_scaling (&num, &den);
    9993        28937 :       ENTRY_BLOCK_PTR_FOR_FN (cfun)->count = node->count;
    9994        28937 :       EXIT_BLOCK_PTR_FOR_FN (cfun)->count
    9995        28937 :         = EXIT_BLOCK_PTR_FOR_FN (cfun)->count.apply_scale (num, den);
    9996              :     }
    9997              : 
    9998     99133529 :   FOR_EACH_BB_FN (bb, cfun)
    9999              :     {
   10000     88071314 :       if (scale)
   10001      1374893 :         bb->count = bb->count.apply_scale (num, den);
   10002    621374041 :       for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi);)
   10003              :         {
   10004    445231413 :           gimple *stmt = gsi_stmt (gsi);
   10005    445231413 :           tree decl = is_gimple_call (stmt)
   10006    445231413 :                       ? gimple_call_fndecl (stmt)
   10007              :                       : NULL;
   10008     43819096 :           if (decl)
   10009              :             {
   10010     40814895 :               int flags = gimple_call_flags (stmt);
   10011     40814895 :               if (flags & (ECF_CONST | ECF_PURE | ECF_LOOPING_CONST_OR_PURE))
   10012              :                 {
   10013      6701431 :                   if (gimple_in_ssa_p (cfun))
   10014              :                     {
   10015      5990318 :                       todo |= TODO_update_ssa | TODO_cleanup_cfg;
   10016      5990318 :                       update_stmt (stmt);
   10017              :                     }
   10018              :                 }
   10019     40814895 :               if (flags & ECF_NORETURN
   10020     40814895 :                   && fixup_noreturn_call (stmt))
   10021        84915 :                 todo |= TODO_cleanup_cfg;
   10022              :              }
   10023              : 
   10024              :           /* Remove stores to variables we marked write-only. */
   10025    445231413 :           if (maybe_remove_writeonly_store (gsi, stmt, dce_ssa_names))
   10026              :             {
   10027        30436 :               todo |= TODO_update_ssa | TODO_cleanup_cfg;
   10028        30436 :               continue;
   10029              :             }
   10030              : 
   10031              :           /* For calls we can simply remove LHS when it is known
   10032              :              to be write-only.  */
   10033    445200977 :           if (is_gimple_call (stmt)
   10034    445200977 :               && gimple_get_lhs (stmt))
   10035              :             {
   10036     17964783 :               tree lhs = get_base_address (gimple_get_lhs (stmt));
   10037              : 
   10038     17964783 :               if (VAR_P (lhs)
   10039      4602350 :                   && (TREE_STATIC (lhs) || DECL_EXTERNAL (lhs))
   10040     17975160 :                   && varpool_node::get (lhs)->writeonly)
   10041              :                 {
   10042            2 :                   gimple_call_set_lhs (stmt, NULL);
   10043            2 :                   update_stmt (stmt);
   10044            2 :                   todo |= TODO_update_ssa | TODO_cleanup_cfg;
   10045              :                 }
   10046              :             }
   10047              : 
   10048    445200977 :           gsi_next (&gsi);
   10049              :         }
   10050    176142628 :       if (gimple *last = *gsi_last_bb (bb))
   10051              :         {
   10052     82072797 :           if (maybe_clean_eh_stmt (last)
   10053     82072797 :               && gimple_purge_dead_eh_edges (bb))
   10054       209608 :             todo |= TODO_cleanup_cfg;
   10055     82072797 :           if (gimple_purge_dead_abnormal_call_edges (bb))
   10056         1096 :             todo |= TODO_cleanup_cfg;
   10057              :         }
   10058              : 
   10059              :       /* If we have a basic block with no successors that does not
   10060              :          end with a control statement or a noreturn call end it with
   10061              :          a call to __builtin_unreachable.  This situation can occur
   10062              :          when inlining a noreturn call that does in fact return.  */
   10063     88071314 :       if (EDGE_COUNT (bb->succs) == 0)
   10064              :         {
   10065      6419180 :           gimple *stmt = last_nondebug_stmt (bb);
   10066      6419180 :           if (!stmt
   10067      6419180 :               || (!is_ctrl_stmt (stmt)
   10068      5598598 :                   && (!is_gimple_call (stmt)
   10069      5598580 :                       || !gimple_call_noreturn_p (stmt))))
   10070              :             {
   10071          132 :               if (stmt && is_gimple_call (stmt))
   10072          103 :                 gimple_call_set_ctrl_altering (stmt, false);
   10073          132 :               stmt = gimple_build_builtin_unreachable (UNKNOWN_LOCATION);
   10074          132 :               gimple_stmt_iterator gsi = gsi_last_bb (bb);
   10075          132 :               gsi_insert_after (&gsi, stmt, GSI_NEW_STMT);
   10076          132 :               if (!cfun->after_inlining)
   10077          108 :                 if (tree fndecl = gimple_call_fndecl (stmt))
   10078              :                   {
   10079          108 :                     gcall *call_stmt = dyn_cast <gcall *> (stmt);
   10080          108 :                     node->create_edge (cgraph_node::get_create (fndecl),
   10081              :                                        call_stmt, bb->count);
   10082              :                   }
   10083              :             }
   10084              :         }
   10085              :     }
   10086     11062215 :   if (scale)
   10087              :     {
   10088        28937 :       update_max_bb_count ();
   10089        28937 :       compute_function_frequency ();
   10090              :     }
   10091              : 
   10092     11062215 :   if (current_loops
   10093     11062215 :       && (todo & TODO_cleanup_cfg))
   10094      1922049 :     loops_state_set (LOOPS_NEED_FIXUP);
   10095              : 
   10096     11062215 :   simple_dce_from_worklist (dce_ssa_names);
   10097              : 
   10098     11062215 :   return todo;
   10099     11062215 : }
   10100              : 
   10101              : namespace {
   10102              : 
   10103              : const pass_data pass_data_fixup_cfg =
   10104              : {
   10105              :   GIMPLE_PASS, /* type */
   10106              :   "fixup_cfg", /* name */
   10107              :   OPTGROUP_NONE, /* optinfo_flags */
   10108              :   TV_NONE, /* tv_id */
   10109              :   PROP_cfg, /* properties_required */
   10110              :   0, /* properties_provided */
   10111              :   0, /* properties_destroyed */
   10112              :   0, /* todo_flags_start */
   10113              :   0, /* todo_flags_finish */
   10114              : };
   10115              : 
   10116              : class pass_fixup_cfg : public gimple_opt_pass
   10117              : {
   10118              : public:
   10119       896484 :   pass_fixup_cfg (gcc::context *ctxt)
   10120      1792968 :     : gimple_opt_pass (pass_data_fixup_cfg, ctxt)
   10121              :   {}
   10122              : 
   10123              :   /* opt_pass methods: */
   10124       597656 :   opt_pass * clone () final override { return new pass_fixup_cfg (m_ctxt); }
   10125      7207885 :   unsigned int execute (function *) final override
   10126              :   {
   10127      7207885 :     return execute_fixup_cfg ();
   10128              :   }
   10129              : 
   10130              : }; // class pass_fixup_cfg
   10131              : 
   10132              : } // anon namespace
   10133              : 
   10134              : gimple_opt_pass *
   10135       298828 : make_pass_fixup_cfg (gcc::context *ctxt)
   10136              : {
   10137       298828 :   return new pass_fixup_cfg (ctxt);
   10138              : }
   10139              : 
   10140              : 
   10141              : /* Sort PHI argument values for make_forwarders_with_degenerate_phis.  */
   10142              : 
   10143              : static int
   10144     45082188 : sort_phi_args (const void *a_, const void *b_)
   10145              : {
   10146     45082188 :   auto *a = (const std::pair<edge, hashval_t> *) a_;
   10147     45082188 :   auto *b = (const std::pair<edge, hashval_t> *) b_;
   10148     45082188 :   hashval_t ha = a->second;
   10149     45082188 :   hashval_t hb = b->second;
   10150     45082188 :   if (ha < hb)
   10151              :     return -1;
   10152     28407002 :   else if (ha > hb)
   10153              :     return 1;
   10154     14309598 :   else if (a->first->dest_idx < b->first->dest_idx)
   10155              :     return -1;
   10156      7475300 :   else if (a->first->dest_idx > b->first->dest_idx)
   10157              :     return 1;
   10158              :   else
   10159            0 :     return 0;
   10160              : }
   10161              : 
   10162              : /* Returns true if edge E comes from a possible ifconvertable branch.
   10163              :    That is:
   10164              :    ```
   10165              :    BB0:
   10166              :    if (a) goto BB1; else goto BB2;
   10167              :    BB1:
   10168              :    BB2:
   10169              :    ```
   10170              :    Returns true for the edge from BB0->BB2 or BB1->BB2.
   10171              :    This function assumes we only have one middle block.
   10172              :    And the middle block is empty. */
   10173              : 
   10174              : static bool
   10175      1173822 : ifconvertable_edge (edge e)
   10176              : {
   10177      1173822 :   basic_block bb2 = e->dest;
   10178      1173822 :   basic_block bb0 = e->src;
   10179      1173822 :   basic_block bb1 = nullptr, rbb1;
   10180      1173822 :   if (e->src == e->dest)
   10181              :     return false;
   10182      1173822 :   if (EDGE_COUNT (bb0->succs) > 2)
   10183              :     return false;
   10184      1169274 :   if (single_succ_p (bb0))
   10185              :     {
   10186       459507 :       if (!single_pred_p (bb0))
   10187              :         return false;
   10188              :       /* The middle block can only be empty,
   10189              :          otherwise the phis will be
   10190              :          different anyways. */
   10191       370919 :       if (!empty_block_p (bb0))
   10192              :         return false;
   10193        46681 :       bb1 = bb0;
   10194        46681 :       bb0 = single_pred (bb0);
   10195      1148414 :       if (EDGE_COUNT (bb0->succs) != 2)
   10196              :         return false;
   10197              :     }
   10198              : 
   10199              :   /* If convertibles are only for conditionals. */
   10200       735319 :   if (!is_a<gcond*>(*gsi_last_nondebug_bb (bb0)))
   10201              :     return false;
   10202              : 
   10203              :   /* Find the other basic block.  */
   10204       682977 :   if (EDGE_SUCC (bb0, 0)->dest == bb2)
   10205       333246 :     rbb1 = EDGE_SUCC (bb0, 1)->dest;
   10206       349731 :   else if (EDGE_SUCC (bb0, 1)->dest == bb2)
   10207              :     rbb1 = EDGE_SUCC (bb0, 0)->dest;
   10208              :   else
   10209              :     return false;
   10210              : 
   10211              :   /* If we already know bb1, then just test it. */
   10212       682906 :   if (bb1)
   10213        25480 :     return rbb1 == bb1;
   10214              : 
   10215      1450990 :   if (!single_succ_p (rbb1) || !single_pred_p (rbb1))
   10216              :     return false;
   10217              :   /* The middle block can only be empty,
   10218              :      otherwise the phis will be
   10219              :      different anyways. */
   10220       130962 :   if (!empty_block_p (rbb1))
   10221              :     return false;
   10222              : 
   10223        25480 :   return single_succ (rbb1) == bb2;
   10224              : }
   10225              : 
   10226              : /* Look for a non-virtual PHIs and make a forwarder block when all PHIs
   10227              :    have the same argument on a set of edges.  This is to not consider
   10228              :    control dependences of individual edges for same values but only for
   10229              :    the common set.  Returns true if changed the CFG.  */
   10230              : 
   10231              : bool
   10232      4522888 : make_forwarders_with_degenerate_phis (function *fn, bool skip_ifcvtable)
   10233              : {
   10234      4522888 :   bool didsomething = false;
   10235              : 
   10236      4522888 :   basic_block bb;
   10237     43054920 :   FOR_EACH_BB_FN (bb, fn)
   10238              :     {
   10239              :       /* Only PHIs with three or more arguments have opportunities.  */
   10240     38532032 :       if (EDGE_COUNT (bb->preds) < 3)
   10241     38078287 :         continue;
   10242              :       /* Do not touch loop headers or blocks with abnormal predecessors.
   10243              :          ???  This is to avoid creating valid loops here, see PR103458.
   10244              :          We might want to improve things to either explicitly add those
   10245              :          loops or at least consider blocks with no backedges.  */
   10246      1794587 :       if (bb->loop_father->header == bb
   10247      1791239 :           || bb_has_abnormal_pred (bb))
   10248         3348 :         continue;
   10249              : 
   10250              :       /* Take one PHI node as template to look for identical
   10251              :          arguments.  Build a vector of candidates forming sets
   10252              :          of argument edges with equal values.  Note optimality
   10253              :          depends on the particular choice of the template PHI
   10254              :          since equal arguments are unordered leaving other PHIs
   10255              :          with more than one set of equal arguments within this
   10256              :          argument range unsorted.  We'd have to break ties by
   10257              :          looking at other PHI nodes.  */
   10258      1787891 :       gphi_iterator gsi = gsi_start_nonvirtual_phis (bb);
   10259      1787891 :       if (gsi_end_p (gsi))
   10260      1042762 :         continue;
   10261       745129 :       gphi *phi = gsi.phi ();
   10262       745129 :       auto_vec<std::pair<edge, hashval_t>, 8> args;
   10263       745129 :       bool need_resort = false;
   10264      4492554 :       for (unsigned i = 0; i < gimple_phi_num_args (phi); ++i)
   10265              :         {
   10266      3747425 :           edge e = gimple_phi_arg_edge (phi, i);
   10267              :           /* Skip abnormal edges since we cannot redirect them.  */
   10268      3747425 :           if (e->flags & EDGE_ABNORMAL)
   10269      3747425 :             continue;
   10270              :           /* Skip loop exit edges when we are in loop-closed SSA form
   10271              :              since the forwarder we'd create does not have a PHI node.  */
   10272      3747425 :           if (loops_state_satisfies_p (LOOP_CLOSED_SSA)
   10273      3747425 :               && loop_exit_edge_p (e->src->loop_father, e))
   10274        23044 :             continue;
   10275              : 
   10276              :           /* Skip ifconvertable edges when asked as we want the
   10277              :              copy/constant on that edge still when going out of ssa.
   10278              :              FIXME: phiopt should produce COND_EXPR but there
   10279              :              are regressions with that.  */
   10280      3724381 :           if (skip_ifcvtable && ifconvertable_edge (e))
   10281        50960 :             continue;
   10282              : 
   10283      3673421 :           tree arg = gimple_phi_arg_def (phi, i);
   10284      3673421 :           if (!CONSTANT_CLASS_P (arg) && TREE_CODE (arg) != SSA_NAME)
   10285      3673421 :             need_resort = true;
   10286      3673421 :           args.safe_push (std::make_pair (e, iterative_hash_expr (arg, 0)));
   10287              :         }
   10288       745129 :       if (args.length () < 2)
   10289        12988 :         continue;
   10290       732141 :       args.qsort (sort_phi_args);
   10291              :       /* The above sorting can be different between -g and -g0, as e.g. decls
   10292              :          can have different uids (-g could have bigger gaps in between them).
   10293              :          So, only use that to determine which args are equal, then change
   10294              :          second from hash value to smallest dest_idx of the edges which have
   10295              :          equal argument and sort again.  If all the phi arguments are
   10296              :          constants or SSA_NAME, there is no need for the second sort, the hash
   10297              :          values are stable in that case.  */
   10298       732141 :       hashval_t hash = args[0].second;
   10299       732141 :       args[0].second = args[0].first->dest_idx;
   10300       732141 :       bool any_equal = false;
   10301      3663253 :       for (unsigned i = 1; i < args.length (); ++i)
   10302      2931112 :         if (hash == args[i].second
   10303      4130950 :             && operand_equal_p (PHI_ARG_DEF_FROM_EDGE (phi, args[i - 1].first),
   10304      1199838 :                                 PHI_ARG_DEF_FROM_EDGE (phi, args[i].first)))
   10305              :           {
   10306      1198625 :             args[i].second = args[i - 1].second;
   10307      1198625 :             any_equal = true;
   10308              :           }
   10309              :         else
   10310              :           {
   10311      1732487 :             hash = args[i].second;
   10312      1732487 :             args[i].second = args[i].first->dest_idx;
   10313              :           }
   10314       732141 :       if (!any_equal)
   10315       278396 :         continue;
   10316       453745 :       if (need_resort)
   10317        25265 :         args.qsort (sort_phi_args);
   10318              : 
   10319              :       /* From the candidates vector now verify true candidates for
   10320              :          forwarders and create them.  */
   10321       453745 :       gphi *vphi = get_virtual_phi (bb);
   10322       453745 :       unsigned start = 0;
   10323      3728415 :       while (start < args.length () - 1)
   10324              :         {
   10325      1185712 :           unsigned i;
   10326      3508982 :           for (i = start + 1; i < args.length (); ++i)
   10327      3272506 :             if (args[start].second != args[i].second)
   10328              :               break;
   10329              :           /* args[start]..args[i-1] are equal.  */
   10330      1185712 :           if (start != i - 1)
   10331              :             {
   10332              :               /* Check all PHI nodes for argument equality
   10333              :                  except for vops.  */
   10334       688155 :               bool equal = true;
   10335       688155 :               gphi_iterator gsi2 = gsi;
   10336       688155 :               gsi_next (&gsi2);
   10337      1457649 :               for (; !gsi_end_p (gsi2); gsi_next (&gsi2))
   10338              :                 {
   10339       992918 :                   gphi *phi2 = gsi2.phi ();
   10340      1985836 :                   if (virtual_operand_p (gimple_phi_result (phi2)))
   10341       243261 :                     continue;
   10342       749657 :                   tree start_arg
   10343       749657 :                     = PHI_ARG_DEF_FROM_EDGE (phi2, args[start].first);
   10344      3163601 :                   for (unsigned j = start + 1; j < i; ++j)
   10345              :                     {
   10346      5366332 :                       if (!operand_equal_p (start_arg,
   10347      2683166 :                                             PHI_ARG_DEF_FROM_EDGE
   10348              :                                               (phi2, args[j].first)))
   10349              :                         {
   10350              :                           /* Another PHI might have a shorter set of
   10351              :                              equivalent args.  Go for that.  */
   10352       269222 :                           i = j;
   10353       269222 :                           if (j == start + 1)
   10354              :                             equal = false;
   10355              :                           break;
   10356              :                         }
   10357              :                     }
   10358              :                   if (!equal)
   10359              :                     break;
   10360              :                 }
   10361       688155 :               if (equal)
   10362              :                 {
   10363              :                   /* If we are asked to forward all edges the block
   10364              :                      has all degenerate PHIs.  Do nothing in that case.  */
   10365       464731 :                   if (start == 0
   10366       221713 :                       && i == args.length ()
   10367       468572 :                       && args.length () == gimple_phi_num_args (phi))
   10368              :                     break;
   10369              :                   /* Instead of using make_forwarder_block we are
   10370              :                      rolling our own variant knowing that the forwarder
   10371              :                      does not need PHI nodes apart from eventually
   10372              :                      a virtual one.  */
   10373       462609 :                   auto_vec<tree, 8> vphi_args;
   10374       462609 :                   if (vphi)
   10375              :                     {
   10376       309352 :                       vphi_args.reserve_exact (i - start);
   10377      1246329 :                       for (unsigned j = start; j < i; ++j)
   10378       936977 :                         vphi_args.quick_push
   10379       936977 :                           (PHI_ARG_DEF_FROM_EDGE (vphi, args[j].first));
   10380              :                     }
   10381       462609 :                   free_dominance_info (fn, CDI_DOMINATORS);
   10382       462609 :                   if (dump_file && (dump_flags & TDF_DETAILS))
   10383              :                     {
   10384            1 :                       fprintf (dump_file, "New forwarder block for edge ");
   10385            1 :                       fprintf (dump_file, "%d -> %d.\n",
   10386            1 :                                args[start].first->src->index,
   10387            1 :                                args[start].first->dest->index);
   10388              :                     }
   10389       462609 :                   basic_block forwarder = split_edge (args[start].first);
   10390       462609 :                   profile_count count = forwarder->count;
   10391       462609 :                   bool irr = false;
   10392      1421559 :                   for (unsigned j = start + 1; j < i; ++j)
   10393              :                     {
   10394       958950 :                       edge e = args[j].first;
   10395       958950 :                       if (e->flags & EDGE_IRREDUCIBLE_LOOP)
   10396         3331 :                         irr = true;
   10397       958950 :                       redirect_edge_and_branch_force (e, forwarder);
   10398       958950 :                       redirect_edge_var_map_clear (e);
   10399       958950 :                       count += e->count ();
   10400              :                     }
   10401       462609 :                   forwarder->count = count;
   10402       462609 :                   if (irr)
   10403              :                     {
   10404         2611 :                       forwarder->flags |= BB_IRREDUCIBLE_LOOP;
   10405         2611 :                       single_succ_edge (forwarder)->flags
   10406         2611 :                         |= EDGE_IRREDUCIBLE_LOOP;
   10407              :                     }
   10408              : 
   10409       462609 :                   if (vphi)
   10410              :                     {
   10411       309352 :                       tree def = copy_ssa_name (vphi_args[0]);
   10412       309352 :                       gphi *vphi_copy = create_phi_node (def, forwarder);
   10413      1246329 :                       for (unsigned j = start; j < i; ++j)
   10414      1873954 :                         add_phi_arg (vphi_copy, vphi_args[j - start],
   10415       936977 :                                      args[j].first, UNKNOWN_LOCATION);
   10416       309352 :                       SET_PHI_ARG_DEF
   10417              :                         (vphi, single_succ_edge (forwarder)->dest_idx, def);
   10418              :                     }
   10419       462609 :                   didsomething = true;
   10420       462609 :                 }
   10421              :             }
   10422              :           /* Continue searching for more opportunities.  */
   10423              :           start = i;
   10424              :         }
   10425       745129 :     }
   10426      4522888 :   return didsomething;
   10427              : }
   10428              : 
   10429              : /* Garbage collection support for edge_def.  */
   10430              : 
   10431              : extern void gt_ggc_mx (tree&);
   10432              : extern void gt_ggc_mx (gimple *&);
   10433              : extern void gt_ggc_mx (rtx&);
   10434              : extern void gt_ggc_mx (basic_block&);
   10435              : 
   10436              : static void
   10437     48002532 : gt_ggc_mx (rtx_insn *& x)
   10438              : {
   10439            0 :   if (x)
   10440            0 :     gt_ggc_mx_rtx_def ((void *) x);
   10441            0 : }
   10442              : 
   10443              : void
   10444    160223640 : gt_ggc_mx (edge_def *e)
   10445              : {
   10446    160223640 :   tree block = LOCATION_BLOCK (e->goto_locus);
   10447    160223640 :   gt_ggc_mx (e->src);
   10448    160223640 :   gt_ggc_mx (e->dest);
   10449    160223640 :   if (current_ir_type () == IR_GIMPLE)
   10450    112221108 :     gt_ggc_mx (e->insns.g);
   10451              :   else
   10452     48002532 :     gt_ggc_mx (e->insns.r);
   10453    160223640 :   gt_ggc_mx (block);
   10454    160223640 : }
   10455              : 
   10456              : /* PCH support for edge_def.  */
   10457              : 
   10458              : extern void gt_pch_nx (tree&);
   10459              : extern void gt_pch_nx (gimple *&);
   10460              : extern void gt_pch_nx (rtx&);
   10461              : extern void gt_pch_nx (basic_block&);
   10462              : 
   10463              : static void
   10464            0 : gt_pch_nx (rtx_insn *& x)
   10465              : {
   10466            0 :   if (x)
   10467            0 :     gt_pch_nx_rtx_def ((void *) x);
   10468            0 : }
   10469              : 
   10470              : void
   10471            0 : gt_pch_nx (edge_def *e)
   10472              : {
   10473            0 :   tree block = LOCATION_BLOCK (e->goto_locus);
   10474            0 :   gt_pch_nx (e->src);
   10475            0 :   gt_pch_nx (e->dest);
   10476            0 :   if (current_ir_type () == IR_GIMPLE)
   10477            0 :     gt_pch_nx (e->insns.g);
   10478              :   else
   10479            0 :     gt_pch_nx (e->insns.r);
   10480            0 :   gt_pch_nx (block);
   10481            0 : }
   10482              : 
   10483              : void
   10484            0 : gt_pch_nx (edge_def *e, gt_pointer_operator op, void *cookie)
   10485              : {
   10486            0 :   tree block = LOCATION_BLOCK (e->goto_locus);
   10487            0 :   op (&(e->src), NULL, cookie);
   10488            0 :   op (&(e->dest), NULL, cookie);
   10489            0 :   if (current_ir_type () == IR_GIMPLE)
   10490            0 :     op (&(e->insns.g), NULL, cookie);
   10491              :   else
   10492            0 :     op (&(e->insns.r), NULL, cookie);
   10493            0 :   op (&(block), &(block), cookie);
   10494            0 : }
   10495              : 
   10496              : #if CHECKING_P
   10497              : 
   10498              : namespace selftest {
   10499              : 
   10500              : /* Helper function for CFG selftests: create a dummy function decl
   10501              :    and push it as cfun.  */
   10502              : 
   10503              : static tree
   10504           12 : push_fndecl (const char *name)
   10505              : {
   10506           12 :   tree fn_type = build_function_type_array (integer_type_node, 0, NULL);
   10507              :   /* FIXME: this uses input_location: */
   10508           12 :   tree fndecl = build_fn_decl (name, fn_type);
   10509           12 :   tree retval = build_decl (UNKNOWN_LOCATION, RESULT_DECL,
   10510              :                             NULL_TREE, integer_type_node);
   10511           12 :   DECL_RESULT (fndecl) = retval;
   10512           12 :   push_struct_function (fndecl);
   10513           12 :   function *fun = DECL_STRUCT_FUNCTION (fndecl);
   10514           12 :   ASSERT_TRUE (fun != NULL);
   10515           12 :   init_empty_tree_cfg_for_function (fun);
   10516           12 :   ASSERT_EQ (2, n_basic_blocks_for_fn (fun));
   10517           12 :   ASSERT_EQ (0, n_edges_for_fn (fun));
   10518           12 :   return fndecl;
   10519              : }
   10520              : 
   10521              : /* These tests directly create CFGs.
   10522              :    Compare with the static fns within tree-cfg.cc:
   10523              :      - build_gimple_cfg
   10524              :      - make_blocks: calls create_basic_block (seq, bb);
   10525              :      - make_edges.   */
   10526              : 
   10527              : /* Verify a simple cfg of the form:
   10528              :      ENTRY -> A -> B -> C -> EXIT.  */
   10529              : 
   10530              : static void
   10531            4 : test_linear_chain ()
   10532              : {
   10533            4 :   gimple_register_cfg_hooks ();
   10534              : 
   10535            4 :   tree fndecl = push_fndecl ("cfg_test_linear_chain");
   10536            4 :   function *fun = DECL_STRUCT_FUNCTION (fndecl);
   10537              : 
   10538              :   /* Create some empty blocks.  */
   10539            4 :   basic_block bb_a = create_empty_bb (ENTRY_BLOCK_PTR_FOR_FN (fun));
   10540            4 :   basic_block bb_b = create_empty_bb (bb_a);
   10541            4 :   basic_block bb_c = create_empty_bb (bb_b);
   10542              : 
   10543            4 :   ASSERT_EQ (5, n_basic_blocks_for_fn (fun));
   10544            4 :   ASSERT_EQ (0, n_edges_for_fn (fun));
   10545              : 
   10546              :   /* Create some edges: a simple linear chain of BBs.  */
   10547            4 :   make_edge (ENTRY_BLOCK_PTR_FOR_FN (fun), bb_a, EDGE_FALLTHRU);
   10548            4 :   make_edge (bb_a, bb_b, 0);
   10549            4 :   make_edge (bb_b, bb_c, 0);
   10550            4 :   make_edge (bb_c, EXIT_BLOCK_PTR_FOR_FN (fun), 0);
   10551              : 
   10552              :   /* Verify the edges.  */
   10553            4 :   ASSERT_EQ (4, n_edges_for_fn (fun));
   10554            4 :   ASSERT_EQ (NULL, ENTRY_BLOCK_PTR_FOR_FN (fun)->preds);
   10555            4 :   ASSERT_EQ (1, ENTRY_BLOCK_PTR_FOR_FN (fun)->succs->length ());
   10556            4 :   ASSERT_EQ (1, bb_a->preds->length ());
   10557            4 :   ASSERT_EQ (1, bb_a->succs->length ());
   10558            4 :   ASSERT_EQ (1, bb_b->preds->length ());
   10559            4 :   ASSERT_EQ (1, bb_b->succs->length ());
   10560            4 :   ASSERT_EQ (1, bb_c->preds->length ());
   10561            4 :   ASSERT_EQ (1, bb_c->succs->length ());
   10562            4 :   ASSERT_EQ (1, EXIT_BLOCK_PTR_FOR_FN (fun)->preds->length ());
   10563            4 :   ASSERT_EQ (NULL, EXIT_BLOCK_PTR_FOR_FN (fun)->succs);
   10564              : 
   10565              :   /* Verify the dominance information
   10566              :      Each BB in our simple chain should be dominated by the one before
   10567              :      it.  */
   10568            4 :   calculate_dominance_info (CDI_DOMINATORS);
   10569            4 :   ASSERT_EQ (bb_a, get_immediate_dominator (CDI_DOMINATORS, bb_b));
   10570            4 :   ASSERT_EQ (bb_b, get_immediate_dominator (CDI_DOMINATORS, bb_c));
   10571            4 :   auto_vec<basic_block> dom_by_b = get_dominated_by (CDI_DOMINATORS, bb_b);
   10572            4 :   ASSERT_EQ (1, dom_by_b.length ());
   10573            4 :   ASSERT_EQ (bb_c, dom_by_b[0]);
   10574            4 :   free_dominance_info (CDI_DOMINATORS);
   10575              : 
   10576              :   /* Similarly for post-dominance: each BB in our chain is post-dominated
   10577              :      by the one after it.  */
   10578            4 :   calculate_dominance_info (CDI_POST_DOMINATORS);
   10579            4 :   ASSERT_EQ (bb_b, get_immediate_dominator (CDI_POST_DOMINATORS, bb_a));
   10580            4 :   ASSERT_EQ (bb_c, get_immediate_dominator (CDI_POST_DOMINATORS, bb_b));
   10581            4 :   auto_vec<basic_block> postdom_by_b = get_dominated_by (CDI_POST_DOMINATORS, bb_b);
   10582            4 :   ASSERT_EQ (1, postdom_by_b.length ());
   10583            4 :   ASSERT_EQ (bb_a, postdom_by_b[0]);
   10584            4 :   free_dominance_info (CDI_POST_DOMINATORS);
   10585              : 
   10586            4 :   pop_cfun ();
   10587            4 : }
   10588              : 
   10589              : /* Verify a simple CFG of the form:
   10590              :      ENTRY
   10591              :        |
   10592              :        A
   10593              :       / \
   10594              :      /t  \f
   10595              :     B     C
   10596              :      \   /
   10597              :       \ /
   10598              :        D
   10599              :        |
   10600              :       EXIT.  */
   10601              : 
   10602              : static void
   10603            4 : test_diamond ()
   10604              : {
   10605            4 :   gimple_register_cfg_hooks ();
   10606              : 
   10607            4 :   tree fndecl = push_fndecl ("cfg_test_diamond");
   10608            4 :   function *fun = DECL_STRUCT_FUNCTION (fndecl);
   10609              : 
   10610              :   /* Create some empty blocks.  */
   10611            4 :   basic_block bb_a = create_empty_bb (ENTRY_BLOCK_PTR_FOR_FN (fun));
   10612            4 :   basic_block bb_b = create_empty_bb (bb_a);
   10613            4 :   basic_block bb_c = create_empty_bb (bb_a);
   10614            4 :   basic_block bb_d = create_empty_bb (bb_b);
   10615              : 
   10616            4 :   ASSERT_EQ (6, n_basic_blocks_for_fn (fun));
   10617            4 :   ASSERT_EQ (0, n_edges_for_fn (fun));
   10618              : 
   10619              :   /* Create the edges.  */
   10620            4 :   make_edge (ENTRY_BLOCK_PTR_FOR_FN (fun), bb_a, EDGE_FALLTHRU);
   10621            4 :   make_edge (bb_a, bb_b, EDGE_TRUE_VALUE);
   10622            4 :   make_edge (bb_a, bb_c, EDGE_FALSE_VALUE);
   10623            4 :   make_edge (bb_b, bb_d, 0);
   10624            4 :   make_edge (bb_c, bb_d, 0);
   10625            4 :   make_edge (bb_d, EXIT_BLOCK_PTR_FOR_FN (fun), 0);
   10626              : 
   10627              :   /* Verify the edges.  */
   10628            4 :   ASSERT_EQ (6, n_edges_for_fn (fun));
   10629            4 :   ASSERT_EQ (1, bb_a->preds->length ());
   10630            4 :   ASSERT_EQ (2, bb_a->succs->length ());
   10631            4 :   ASSERT_EQ (1, bb_b->preds->length ());
   10632            4 :   ASSERT_EQ (1, bb_b->succs->length ());
   10633            4 :   ASSERT_EQ (1, bb_c->preds->length ());
   10634            4 :   ASSERT_EQ (1, bb_c->succs->length ());
   10635            4 :   ASSERT_EQ (2, bb_d->preds->length ());
   10636            4 :   ASSERT_EQ (1, bb_d->succs->length ());
   10637              : 
   10638              :   /* Verify the dominance information.  */
   10639            4 :   calculate_dominance_info (CDI_DOMINATORS);
   10640            4 :   ASSERT_EQ (bb_a, get_immediate_dominator (CDI_DOMINATORS, bb_b));
   10641            4 :   ASSERT_EQ (bb_a, get_immediate_dominator (CDI_DOMINATORS, bb_c));
   10642            4 :   ASSERT_EQ (bb_a, get_immediate_dominator (CDI_DOMINATORS, bb_d));
   10643            4 :   auto_vec<basic_block> dom_by_a = get_dominated_by (CDI_DOMINATORS, bb_a);
   10644            4 :   ASSERT_EQ (3, dom_by_a.length ()); /* B, C, D, in some order.  */
   10645            4 :   dom_by_a.release ();
   10646            4 :   auto_vec<basic_block> dom_by_b = get_dominated_by (CDI_DOMINATORS, bb_b);
   10647            4 :   ASSERT_EQ (0, dom_by_b.length ());
   10648            4 :   dom_by_b.release ();
   10649            4 :   free_dominance_info (CDI_DOMINATORS);
   10650              : 
   10651              :   /* Similarly for post-dominance.  */
   10652            4 :   calculate_dominance_info (CDI_POST_DOMINATORS);
   10653            4 :   ASSERT_EQ (bb_d, get_immediate_dominator (CDI_POST_DOMINATORS, bb_a));
   10654            4 :   ASSERT_EQ (bb_d, get_immediate_dominator (CDI_POST_DOMINATORS, bb_b));
   10655            4 :   ASSERT_EQ (bb_d, get_immediate_dominator (CDI_POST_DOMINATORS, bb_c));
   10656            4 :   auto_vec<basic_block> postdom_by_d = get_dominated_by (CDI_POST_DOMINATORS, bb_d);
   10657            4 :   ASSERT_EQ (3, postdom_by_d.length ()); /* A, B, C in some order.  */
   10658            4 :   postdom_by_d.release ();
   10659            4 :   auto_vec<basic_block> postdom_by_b = get_dominated_by (CDI_POST_DOMINATORS, bb_b);
   10660            4 :   ASSERT_EQ (0, postdom_by_b.length ());
   10661            4 :   postdom_by_b.release ();
   10662            4 :   free_dominance_info (CDI_POST_DOMINATORS);
   10663              : 
   10664            4 :   pop_cfun ();
   10665            4 : }
   10666              : 
   10667              : /* Verify that we can handle a CFG containing a "complete" aka
   10668              :    fully-connected subgraph (where A B C D below all have edges
   10669              :    pointing to each other node, also to themselves).
   10670              :    e.g.:
   10671              :      ENTRY  EXIT
   10672              :        |    ^
   10673              :        |   /
   10674              :        |  /
   10675              :        | /
   10676              :        V/
   10677              :        A<--->B
   10678              :        ^^   ^^
   10679              :        | \ / |
   10680              :        |  X  |
   10681              :        | / \ |
   10682              :        VV   VV
   10683              :        C<--->D
   10684              : */
   10685              : 
   10686              : static void
   10687            4 : test_fully_connected ()
   10688              : {
   10689            4 :   gimple_register_cfg_hooks ();
   10690              : 
   10691            4 :   tree fndecl = push_fndecl ("cfg_fully_connected");
   10692            4 :   function *fun = DECL_STRUCT_FUNCTION (fndecl);
   10693              : 
   10694            4 :   const int n = 4;
   10695              : 
   10696              :   /* Create some empty blocks.  */
   10697            4 :   auto_vec <basic_block> subgraph_nodes;
   10698           20 :   for (int i = 0; i < n; i++)
   10699           16 :     subgraph_nodes.safe_push (create_empty_bb (ENTRY_BLOCK_PTR_FOR_FN (fun)));
   10700              : 
   10701            4 :   ASSERT_EQ (n + 2, n_basic_blocks_for_fn (fun));
   10702            4 :   ASSERT_EQ (0, n_edges_for_fn (fun));
   10703              : 
   10704              :   /* Create the edges.  */
   10705            4 :   make_edge (ENTRY_BLOCK_PTR_FOR_FN (fun), subgraph_nodes[0], EDGE_FALLTHRU);
   10706            4 :   make_edge (subgraph_nodes[0], EXIT_BLOCK_PTR_FOR_FN (fun), 0);
   10707           20 :   for (int i = 0; i < n; i++)
   10708           80 :     for (int j = 0; j < n; j++)
   10709           64 :       make_edge (subgraph_nodes[i], subgraph_nodes[j], 0);
   10710              : 
   10711              :   /* Verify the edges.  */
   10712            4 :   ASSERT_EQ (2 + (n * n), n_edges_for_fn (fun));
   10713              :   /* The first one is linked to ENTRY/EXIT as well as itself and
   10714              :      everything else.  */
   10715            4 :   ASSERT_EQ (n + 1, subgraph_nodes[0]->preds->length ());
   10716            4 :   ASSERT_EQ (n + 1, subgraph_nodes[0]->succs->length ());
   10717              :   /* The other ones in the subgraph are linked to everything in
   10718              :      the subgraph (including themselves).  */
   10719           16 :   for (int i = 1; i < n; i++)
   10720              :     {
   10721           12 :       ASSERT_EQ (n, subgraph_nodes[i]->preds->length ());
   10722           12 :       ASSERT_EQ (n, subgraph_nodes[i]->succs->length ());
   10723              :     }
   10724              : 
   10725              :   /* Verify the dominance information.  */
   10726            4 :   calculate_dominance_info (CDI_DOMINATORS);
   10727              :   /* The initial block in the subgraph should be dominated by ENTRY.  */
   10728            4 :   ASSERT_EQ (ENTRY_BLOCK_PTR_FOR_FN (fun),
   10729              :              get_immediate_dominator (CDI_DOMINATORS,
   10730              :                                       subgraph_nodes[0]));
   10731              :   /* Every other block in the subgraph should be dominated by the
   10732              :      initial block.  */
   10733           16 :   for (int i = 1; i < n; i++)
   10734           12 :     ASSERT_EQ (subgraph_nodes[0],
   10735              :                get_immediate_dominator (CDI_DOMINATORS,
   10736              :                                         subgraph_nodes[i]));
   10737            4 :   free_dominance_info (CDI_DOMINATORS);
   10738              : 
   10739              :   /* Similarly for post-dominance.  */
   10740            4 :   calculate_dominance_info (CDI_POST_DOMINATORS);
   10741              :   /* The initial block in the subgraph should be postdominated by EXIT.  */
   10742            4 :   ASSERT_EQ (EXIT_BLOCK_PTR_FOR_FN (fun),
   10743              :              get_immediate_dominator (CDI_POST_DOMINATORS,
   10744              :                                       subgraph_nodes[0]));
   10745              :   /* Every other block in the subgraph should be postdominated by the
   10746              :      initial block, since that leads to EXIT.  */
   10747           16 :   for (int i = 1; i < n; i++)
   10748           12 :     ASSERT_EQ (subgraph_nodes[0],
   10749              :                get_immediate_dominator (CDI_POST_DOMINATORS,
   10750              :                                         subgraph_nodes[i]));
   10751            4 :   free_dominance_info (CDI_POST_DOMINATORS);
   10752              : 
   10753            4 :   pop_cfun ();
   10754            4 : }
   10755              : 
   10756              : /* Run all of the selftests within this file.  */
   10757              : 
   10758              : void
   10759            4 : tree_cfg_cc_tests ()
   10760              : {
   10761            4 :   test_linear_chain ();
   10762            4 :   test_diamond ();
   10763            4 :   test_fully_connected ();
   10764            4 : }
   10765              : 
   10766              : } // namespace selftest
   10767              : 
   10768              : /* TODO: test the dominator/postdominator logic with various graphs/nodes:
   10769              :    - loop
   10770              :    - nested loops
   10771              :    - switch statement (a block with many out-edges)
   10772              :    - something that jumps to itself
   10773              :    - etc  */
   10774              : 
   10775              : #endif /* CHECKING_P */
        

Generated by: LCOV version 2.4-beta

LCOV profile is generated on x86_64 machine using following configure options: configure --disable-bootstrap --enable-coverage=opt --enable-languages=c,c++,fortran,go,jit,lto,rust,m2 --enable-host-shared. GCC test suite is run with the built compiler.