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