LCOV - code coverage report
Current view: top level - gcc - cfgbuild.c (source / functions) Hit Total Coverage
Test: gcc.info Lines: 284 302 94.0 %
Date: 2020-03-28 11:57:23 Functions: 10 10 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : /* Control flow graph building code for GNU compiler.
       2                 :            :    Copyright (C) 1987-2020 Free Software Foundation, Inc.
       3                 :            : 
       4                 :            : This file is part of GCC.
       5                 :            : 
       6                 :            : GCC is free software; you can redistribute it and/or modify it under
       7                 :            : the terms of the GNU General Public License as published by the Free
       8                 :            : Software Foundation; either version 3, or (at your option) any later
       9                 :            : version.
      10                 :            : 
      11                 :            : GCC is distributed in the hope that it will be useful, but WITHOUT ANY
      12                 :            : WARRANTY; without even the implied warranty of MERCHANTABILITY or
      13                 :            : FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
      14                 :            : for more details.
      15                 :            : 
      16                 :            : You should have received a copy of the GNU General Public License
      17                 :            : along with GCC; see the file COPYING3.  If not see
      18                 :            : <http://www.gnu.org/licenses/>.  */
      19                 :            : 
      20                 :            : 
      21                 :            : #include "config.h"
      22                 :            : #include "system.h"
      23                 :            : #include "coretypes.h"
      24                 :            : #include "backend.h"
      25                 :            : #include "rtl.h"
      26                 :            : #include "cfghooks.h"
      27                 :            : #include "memmodel.h"
      28                 :            : #include "emit-rtl.h"
      29                 :            : #include "cfgrtl.h"
      30                 :            : #include "cfganal.h"
      31                 :            : #include "cfgbuild.h"
      32                 :            : #include "except.h"
      33                 :            : #include "stmt.h"
      34                 :            : 
      35                 :            : static void make_edges (basic_block, basic_block, int);
      36                 :            : static void make_label_edge (sbitmap, basic_block, rtx, int);
      37                 :            : static void find_bb_boundaries (basic_block);
      38                 :            : static void compute_outgoing_frequencies (basic_block);
      39                 :            : 
      40                 :            : /* Return true if insn is something that should be contained inside basic
      41                 :            :    block.  */
      42                 :            : 
      43                 :            : bool
      44                 :  116175000 : inside_basic_block_p (const rtx_insn *insn)
      45                 :            : {
      46                 :  116175000 :   switch (GET_CODE (insn))
      47                 :            :     {
      48                 :    7199860 :     case CODE_LABEL:
      49                 :            :       /* Avoid creating of basic block for jumptables.  */
      50                 :    7199860 :       return (NEXT_INSN (insn) == 0
      51                 :    7199860 :               || ! JUMP_TABLE_DATA_P (NEXT_INSN (insn)));
      52                 :            : 
      53                 :            :     case JUMP_INSN:
      54                 :            :     case CALL_INSN:
      55                 :            :     case INSN:
      56                 :            :     case DEBUG_INSN:
      57                 :            :       return true;
      58                 :            : 
      59                 :   50422000 :     case JUMP_TABLE_DATA:
      60                 :   50422000 :     case BARRIER:
      61                 :   50422000 :     case NOTE:
      62                 :   50422000 :       return false;
      63                 :            : 
      64                 :          0 :     default:
      65                 :          0 :       gcc_unreachable ();
      66                 :            :     }
      67                 :            : }
      68                 :            : 
      69                 :            : /* Return true if INSN may cause control flow transfer, so it should be last in
      70                 :            :    the basic block.  */
      71                 :            : 
      72                 :            : bool
      73                 : 5837740000 : control_flow_insn_p (const rtx_insn *insn)
      74                 :            : {
      75                 : 5837740000 :   switch (GET_CODE (insn))
      76                 :            :     {
      77                 :            :     case NOTE:
      78                 :            :     case CODE_LABEL:
      79                 :            :     case DEBUG_INSN:
      80                 :            :       return false;
      81                 :            : 
      82                 :   15076800 :     case JUMP_INSN:
      83                 :   15076800 :       return true;
      84                 :            : 
      85                 :  226798000 :     case CALL_INSN:
      86                 :            :       /* Noreturn and sibling call instructions terminate the basic blocks
      87                 :            :          (but only if they happen unconditionally).  */
      88                 :  226798000 :       if ((SIBLING_CALL_P (insn)
      89                 :  226311000 :            || find_reg_note (insn, REG_NORETURN, 0))
      90                 :  231062000 :           && GET_CODE (PATTERN (insn)) != COND_EXEC)
      91                 :            :         return true;
      92                 :            : 
      93                 :            :       /* Call insn may return to the nonlocal goto handler.  */
      94                 :  222047000 :       if (can_nonlocal_goto (insn))
      95                 :            :         return true;
      96                 :            :       break;
      97                 :            : 
      98                 : 2990980000 :     case INSN:
      99                 :            :       /* Treat trap instructions like noreturn calls (same provision).  */
     100                 : 2990980000 :       if (GET_CODE (PATTERN (insn)) == TRAP_IF
     101                 : 2990980000 :           && XEXP (PATTERN (insn), 0) == const1_rtx)
     102                 :            :         return true;
     103                 : 2990930000 :       if (!cfun->can_throw_non_call_exceptions)
     104                 :            :         return false;
     105                 :            :       break;
     106                 :            : 
     107                 :            :     case JUMP_TABLE_DATA:
     108                 :            :     case BARRIER:
     109                 :            :       /* It is nonsense to reach this when looking for the
     110                 :            :          end of basic block, but before dead code is eliminated
     111                 :            :          this may happen.  */
     112                 :            :       return false;
     113                 :            : 
     114                 :          0 :     default:
     115                 :          0 :       gcc_unreachable ();
     116                 :            :     }
     117                 :            : 
     118                 : 1215200000 :   return can_throw_internal (insn);
     119                 :            : }
     120                 :            : 
     121                 :            : 
     122                 :            : /* Create an edge between two basic blocks.  FLAGS are auxiliary information
     123                 :            :    about the edge that is accumulated between calls.  */
     124                 :            : 
     125                 :            : /* Create an edge from a basic block to a label.  */
     126                 :            : 
     127                 :            : static void
     128                 :   10241500 : make_label_edge (sbitmap edge_cache, basic_block src, rtx label, int flags)
     129                 :            : {
     130                 :   10241500 :   gcc_assert (LABEL_P (label));
     131                 :            : 
     132                 :            :   /* If the label was never emitted, this insn is junk, but avoid a
     133                 :            :      crash trying to refer to BLOCK_FOR_INSN (label).  This can happen
     134                 :            :      as a result of a syntax error and a diagnostic has already been
     135                 :            :      printed.  */
     136                 :            : 
     137                 :   10241500 :   if (INSN_UID (label) == 0)
     138                 :            :     return;
     139                 :            : 
     140                 :   10241500 :   cached_make_edge (edge_cache, src, BLOCK_FOR_INSN (label), flags);
     141                 :            : }
     142                 :            : 
     143                 :            : /* Create the edges generated by INSN in REGION.  */
     144                 :            : 
     145                 :            : void
     146                 :    7146440 : rtl_make_eh_edge (sbitmap edge_cache, basic_block src, rtx insn)
     147                 :            : {
     148                 :    7146440 :   eh_landing_pad lp = get_eh_landing_pad_from_rtx (insn);
     149                 :            : 
     150                 :    7146440 :   if (lp)
     151                 :            :     {
     152                 :     857890 :       rtx_insn *label = lp->landing_pad;
     153                 :            : 
     154                 :            :       /* During initial rtl generation, use the post_landing_pad.  */
     155                 :     857890 :       if (label == NULL)
     156                 :            :         {
     157                 :     478520 :           gcc_assert (lp->post_landing_pad);
     158                 :     478520 :           label = label_rtx (lp->post_landing_pad);
     159                 :            :         }
     160                 :            : 
     161                 :     857890 :       make_label_edge (edge_cache, src, label,
     162                 :            :                        EDGE_ABNORMAL | EDGE_EH
     163                 :     857890 :                        | (CALL_P (insn) ? EDGE_ABNORMAL_CALL : 0));
     164                 :            :     }
     165                 :    7146440 : }
     166                 :            : 
     167                 :            : /* States of basic block as seen by find_many_sub_basic_blocks.  */
     168                 :            : enum state {
     169                 :            :   /* Basic blocks created via split_block belong to this state.
     170                 :            :      make_edges will examine these basic blocks to see if we need to
     171                 :            :      create edges going out of them.  */
     172                 :            :   BLOCK_NEW = 0,
     173                 :            : 
     174                 :            :   /* Basic blocks that do not need examining belong to this state.
     175                 :            :      These blocks will be left intact.  In particular, make_edges will
     176                 :            :      not create edges going out of these basic blocks.  */
     177                 :            :   BLOCK_ORIGINAL,
     178                 :            : 
     179                 :            :   /* Basic blocks that may need splitting (due to a label appearing in
     180                 :            :      the middle, etc) belong to this state.  After splitting them,
     181                 :            :      make_edges will create edges going out of them as needed.  */
     182                 :            :   BLOCK_TO_SPLIT
     183                 :            : };
     184                 :            : 
     185                 :            : #define STATE(BB) (enum state) ((size_t) (BB)->aux)
     186                 :            : #define SET_STATE(BB, STATE) ((BB)->aux = (void *) (size_t) (STATE))
     187                 :            : 
     188                 :            : /* Used internally by purge_dead_tablejump_edges, ORed into state.  */
     189                 :            : #define BLOCK_USED_BY_TABLEJUMP         32
     190                 :            : #define FULL_STATE(BB) ((size_t) (BB)->aux)
     191                 :            : 
     192                 :            : /* Identify the edges going out of basic blocks between MIN and MAX,
     193                 :            :    inclusive, that have their states set to BLOCK_NEW or
     194                 :            :    BLOCK_TO_SPLIT.
     195                 :            : 
     196                 :            :    UPDATE_P should be nonzero if we are updating CFG and zero if we
     197                 :            :    are building CFG from scratch.  */
     198                 :            : 
     199                 :            : static void
     200                 :    2287400 : make_edges (basic_block min, basic_block max, int update_p)
     201                 :            : {
     202                 :    2287400 :   basic_block bb;
     203                 :    2287400 :   sbitmap edge_cache = NULL;
     204                 :            : 
     205                 :            :   /* Heavy use of computed goto in machine-generated code can lead to
     206                 :            :      nearly fully-connected CFGs.  In that case we spend a significant
     207                 :            :      amount of time searching the edge lists for duplicates.  */
     208                 :    2287400 :   if (!vec_safe_is_empty (forced_labels)
     209                 :    2262720 :       || cfun->cfg->max_jumptable_ents > 100)
     210                 :      24807 :     edge_cache = sbitmap_alloc (last_basic_block_for_fn (cfun));
     211                 :            : 
     212                 :            :   /* By nature of the way these get numbered, ENTRY_BLOCK_PTR->next_bb block
     213                 :            :      is always the entry.  */
     214                 :    2287400 :   if (min == ENTRY_BLOCK_PTR_FOR_FN (cfun)->next_bb)
     215                 :    2010250 :     make_edge (ENTRY_BLOCK_PTR_FOR_FN (cfun), min, EDGE_FALLTHRU);
     216                 :            : 
     217                 :   23733400 :   FOR_BB_BETWEEN (bb, min, max->next_bb, next_bb)
     218                 :            :     {
     219                 :   21446000 :       rtx_insn *insn;
     220                 :   21446000 :       enum rtx_code code;
     221                 :   21446000 :       edge e;
     222                 :   21446000 :       edge_iterator ei;
     223                 :            : 
     224                 :   21446000 :       if (STATE (bb) == BLOCK_ORIGINAL)
     225                 :    4707430 :         continue;
     226                 :            : 
     227                 :            :       /* If we have an edge cache, cache edges going out of BB.  */
     228                 :   16738500 :       if (edge_cache)
     229                 :            :         {
     230                 :     109089 :           bitmap_clear (edge_cache);
     231                 :     109089 :           if (update_p)
     232                 :            :             {
     233                 :     240873 :               FOR_EACH_EDGE (e, ei, bb->succs)
     234                 :     131784 :                 if (e->dest != EXIT_BLOCK_PTR_FOR_FN (cfun))
     235                 :     247858 :                   bitmap_set_bit (edge_cache, e->dest->index);
     236                 :            :             }
     237                 :            :         }
     238                 :            : 
     239                 :   16738500 :       if (LABEL_P (BB_HEAD (bb))
     240                 :   16738500 :           && LABEL_ALT_ENTRY_P (BB_HEAD (bb)))
     241                 :          0 :         cached_make_edge (NULL, ENTRY_BLOCK_PTR_FOR_FN (cfun), bb, 0);
     242                 :            : 
     243                 :            :       /* Examine the last instruction of the block, and discover the
     244                 :            :          ways we can leave the block.  */
     245                 :            : 
     246                 :   16738500 :       insn = BB_END (bb);
     247                 :   16738500 :       code = GET_CODE (insn);
     248                 :            : 
     249                 :            :       /* A branch.  */
     250                 :   16738500 :       if (code == JUMP_INSN)
     251                 :            :         {
     252                 :    9303480 :           rtx tmp;
     253                 :    9303480 :           rtx_jump_table_data *table;
     254                 :            : 
     255                 :            :           /* Recognize a non-local goto as a branch outside the
     256                 :            :              current function.  */
     257                 :    9303480 :           if (find_reg_note (insn, REG_NON_LOCAL_GOTO, NULL_RTX))
     258                 :            :             ;
     259                 :            : 
     260                 :            :           /* Recognize a tablejump and do the right thing.  */
     261                 :    9302090 :           else if (tablejump_p (insn, NULL, &table))
     262                 :            :             {
     263                 :      12319 :               rtvec vec = table->get_labels ();
     264                 :      12319 :               int j;
     265                 :            : 
     266                 :     279795 :               for (j = GET_NUM_ELEM (vec) - 1; j >= 0; --j)
     267                 :     267476 :                 make_label_edge (edge_cache, bb,
     268                 :     267476 :                                  XEXP (RTVEC_ELT (vec, j), 0), 0);
     269                 :            : 
     270                 :            :               /* Some targets (eg, ARM) emit a conditional jump that also
     271                 :            :                  contains the out-of-range target.  Scan for these and
     272                 :            :                  add an edge if necessary.  */
     273                 :      12319 :               if ((tmp = single_set (insn)) != NULL
     274                 :      12319 :                   && SET_DEST (tmp) == pc_rtx
     275                 :      12319 :                   && GET_CODE (SET_SRC (tmp)) == IF_THEN_ELSE
     276                 :      12319 :                   && GET_CODE (XEXP (SET_SRC (tmp), 2)) == LABEL_REF)
     277                 :          0 :                 make_label_edge (edge_cache, bb,
     278                 :          0 :                                  label_ref_label (XEXP (SET_SRC (tmp), 2)), 0);
     279                 :            :             }
     280                 :            : 
     281                 :            :           /* If this is a computed jump, then mark it as reaching
     282                 :            :              everything on the forced_labels list.  */
     283                 :    9289770 :           else if (computed_jump_p (insn))
     284                 :            :             {
     285                 :            :               rtx_insn *insn;
     286                 :            :               unsigned int i;
     287                 :    9305070 :               FOR_EACH_VEC_SAFE_ELT (forced_labels, i, insn)
     288                 :       1240 :                 make_label_edge (edge_cache, bb, insn, EDGE_ABNORMAL);
     289                 :            :             }
     290                 :            : 
     291                 :            :           /* Returns create an exit out.  */
     292                 :    9289360 :           else if (returnjump_p (insn))
     293                 :     242353 :             cached_make_edge (edge_cache, bb, EXIT_BLOCK_PTR_FOR_FN (cfun), 0);
     294                 :            : 
     295                 :            :           /* Recognize asm goto and do the right thing.  */
     296                 :    9047000 :           else if ((tmp = extract_asm_operands (PATTERN (insn))) != NULL)
     297                 :            :             {
     298                 :        290 :               int i, n = ASM_OPERANDS_LABEL_LENGTH (tmp);
     299                 :        653 :               for (i = 0; i < n; ++i)
     300                 :        363 :                 make_label_edge (edge_cache, bb,
     301                 :        363 :                                  XEXP (ASM_OPERANDS_LABEL (tmp, i), 0), 0);
     302                 :            :             }
     303                 :            : 
     304                 :            :           /* Otherwise, we have a plain conditional or unconditional jump.  */
     305                 :            :           else
     306                 :            :             {
     307                 :    9046710 :               gcc_assert (JUMP_LABEL (insn));
     308                 :    9046710 :               make_label_edge (edge_cache, bb, JUMP_LABEL (insn), 0);
     309                 :            :             }
     310                 :            :         }
     311                 :            : 
     312                 :            :       /* If this is a sibling call insn, then this is in effect a combined call
     313                 :            :          and return, and so we need an edge to the exit block.  No need to
     314                 :            :          worry about EH edges, since we wouldn't have created the sibling call
     315                 :            :          in the first place.  */
     316                 :   16738500 :       if (code == CALL_INSN && SIBLING_CALL_P (insn))
     317                 :     120118 :         cached_make_edge (edge_cache, bb, EXIT_BLOCK_PTR_FOR_FN (cfun),
     318                 :            :                           EDGE_SIBCALL | EDGE_ABNORMAL);
     319                 :            : 
     320                 :            :       /* If this is a CALL_INSN, then mark it as reaching the active EH
     321                 :            :          handler for this CALL_INSN.  If we're handling non-call
     322                 :            :          exceptions then any insn can reach any of the active handlers.
     323                 :            :          Also mark the CALL_INSN as reaching any nonlocal goto handler.  */
     324                 :   16618400 :       else if (code == CALL_INSN || cfun->can_throw_non_call_exceptions)
     325                 :            :         {
     326                 :            :           /* Add any appropriate EH edges.  */
     327                 :    7141860 :           rtl_make_eh_edge (edge_cache, bb, insn);
     328                 :            : 
     329                 :    7141860 :           if (code == CALL_INSN)
     330                 :            :             {
     331                 :    1778390 :               if (can_nonlocal_goto (insn))
     332                 :            :                 {
     333                 :            :                   /* ??? This could be made smarter: in some cases it's
     334                 :            :                      possible to tell that certain calls will not do a
     335                 :            :                      nonlocal goto.  For example, if the nested functions
     336                 :            :                      that do the nonlocal gotos do not have their addresses
     337                 :            :                      taken, then only calls to those functions or to other
     338                 :            :                      nested functions that use them could possibly do
     339                 :            :                      nonlocal gotos.  */
     340                 :       4206 :                   for (rtx_insn_list *x = nonlocal_goto_handler_labels;
     341                 :      67796 :                        x;
     342                 :     135592 :                        x = x->next ())
     343                 :      67796 :                     make_label_edge (edge_cache, bb, x->insn (),
     344                 :            :                                      EDGE_ABNORMAL | EDGE_ABNORMAL_CALL);
     345                 :            :                 }
     346                 :            : 
     347                 :    1778390 :               if (flag_tm)
     348                 :            :                 {
     349                 :       2224 :                   rtx note;
     350                 :       5113 :                   for (note = REG_NOTES (insn); note; note = XEXP (note, 1))
     351                 :       2889 :                     if (REG_NOTE_KIND (note) == REG_TM)
     352                 :          0 :                       make_label_edge (edge_cache, bb, XEXP (note, 0),
     353                 :            :                                        EDGE_ABNORMAL | EDGE_ABNORMAL_CALL);
     354                 :            :                 }
     355                 :            :             }
     356                 :            :         }
     357                 :            : 
     358                 :            :       /* Find out if we can drop through to the next block.  */
     359                 :   16738500 :       insn = NEXT_INSN (insn);
     360                 :   16738500 :       e = find_edge (bb, EXIT_BLOCK_PTR_FOR_FN (cfun));
     361                 :   16738500 :       if (e && e->flags & EDGE_FALLTHRU)
     362                 :    1188500 :         insn = NULL;
     363                 :            : 
     364                 :   16743300 :       while (insn
     365                 :   15554800 :              && NOTE_P (insn)
     366                 :   24302000 :              && NOTE_KIND (insn) != NOTE_INSN_BASIC_BLOCK)
     367                 :       4781 :         insn = NEXT_INSN (insn);
     368                 :            : 
     369                 :   16738500 :       if (!insn)
     370                 :    1188500 :         cached_make_edge (edge_cache, bb, EXIT_BLOCK_PTR_FOR_FN (cfun),
     371                 :            :                           EDGE_FALLTHRU);
     372                 :   15550000 :       else if (bb->next_bb != EXIT_BLOCK_PTR_FOR_FN (cfun))
     373                 :            :         {
     374                 :   15266000 :           if (insn == BB_HEAD (bb->next_bb))
     375                 :   11527000 :             cached_make_edge (edge_cache, bb, bb->next_bb, EDGE_FALLTHRU);
     376                 :            :         }
     377                 :            :     }
     378                 :            : 
     379                 :    2287400 :   if (edge_cache)
     380                 :      24807 :     sbitmap_free (edge_cache);
     381                 :    2287400 : }
     382                 :            : 
     383                 :            : static void
     384                 :     214168 : mark_tablejump_edge (rtx label)
     385                 :            : {
     386                 :     214168 :   basic_block bb;
     387                 :            : 
     388                 :     214168 :   gcc_assert (LABEL_P (label));
     389                 :            :   /* See comment in make_label_edge.  */
     390                 :     214168 :   if (INSN_UID (label) == 0)
     391                 :            :     return;
     392                 :     214168 :   bb = BLOCK_FOR_INSN (label);
     393                 :     214168 :   SET_STATE (bb, FULL_STATE (bb) | BLOCK_USED_BY_TABLEJUMP);
     394                 :            : }
     395                 :            : 
     396                 :            : static void
     397                 :       9415 : purge_dead_tablejump_edges (basic_block bb, rtx_jump_table_data *table)
     398                 :            : {
     399                 :       9415 :   rtx_insn *insn = BB_END (bb);
     400                 :       9415 :   rtx tmp;
     401                 :       9415 :   rtvec vec;
     402                 :       9415 :   int j;
     403                 :       9415 :   edge_iterator ei;
     404                 :       9415 :   edge e;
     405                 :            : 
     406                 :       9415 :   vec = table->get_labels ();
     407                 :            : 
     408                 :     223583 :   for (j = GET_NUM_ELEM (vec) - 1; j >= 0; --j)
     409                 :     214168 :     mark_tablejump_edge (XEXP (RTVEC_ELT (vec, j), 0));
     410                 :            : 
     411                 :            :   /* Some targets (eg, ARM) emit a conditional jump that also
     412                 :            :      contains the out-of-range target.  Scan for these and
     413                 :            :      add an edge if necessary.  */
     414                 :       9415 :   if ((tmp = single_set (insn)) != NULL
     415                 :       9415 :        && SET_DEST (tmp) == pc_rtx
     416                 :       9415 :        && GET_CODE (SET_SRC (tmp)) == IF_THEN_ELSE
     417                 :       9415 :        && GET_CODE (XEXP (SET_SRC (tmp), 2)) == LABEL_REF)
     418                 :          0 :     mark_tablejump_edge (label_ref_label (XEXP (SET_SRC (tmp), 2)));
     419                 :            : 
     420                 :      80637 :   for (ei = ei_start (bb->succs); (e = ei_safe_edge (ei)); )
     421                 :            :     {
     422                 :      71222 :       if (FULL_STATE (e->dest) & BLOCK_USED_BY_TABLEJUMP)
     423                 :      70341 :         SET_STATE (e->dest, FULL_STATE (e->dest)
     424                 :            :                             & ~(size_t) BLOCK_USED_BY_TABLEJUMP);
     425                 :        881 :       else if (!(e->flags & (EDGE_ABNORMAL | EDGE_EH)))
     426                 :            :         {
     427                 :        881 :           remove_edge (e);
     428                 :        881 :           continue;
     429                 :            :         }
     430                 :      70341 :       ei_next (&ei);
     431                 :            :     }
     432                 :       9415 : }
     433                 :            : 
     434                 :            : /* Scan basic block BB for possible BB boundaries inside the block
     435                 :            :    and create new basic blocks in the progress.  */
     436                 :            : 
     437                 :            : static void
     438                 :   15201100 : find_bb_boundaries (basic_block bb)
     439                 :            : {
     440                 :   15201100 :   basic_block orig_bb = bb;
     441                 :   15201100 :   rtx_insn *insn = BB_HEAD (bb);
     442                 :   15201100 :   rtx_insn *end = BB_END (bb), *x;
     443                 :   15201100 :   rtx_jump_table_data *table;
     444                 :   15201100 :   rtx_insn *flow_transfer_insn = NULL;
     445                 :   15201100 :   rtx_insn *debug_insn = NULL;
     446                 :   15201100 :   edge fallthru = NULL;
     447                 :   15201100 :   bool skip_purge;
     448                 :            : 
     449                 :   15201100 :   if (insn == end)
     450                 :      85152 :     return;
     451                 :            : 
     452                 :   15125200 :   if (DEBUG_INSN_P (insn) || DEBUG_INSN_P (end))
     453                 :            :     {
     454                 :            :       /* Check whether, without debug insns, the insn==end test above
     455                 :            :          would have caused us to return immediately, and behave the
     456                 :            :          same way even with debug insns.  If we don't do this, debug
     457                 :            :          insns could cause us to purge dead edges at different times,
     458                 :            :          which could in turn change the cfg and affect codegen
     459                 :            :          decisions in subtle but undesirable ways.  */
     460                 :     220189 :       while (insn != end && DEBUG_INSN_P (insn))
     461                 :          0 :         insn = NEXT_INSN (insn);
     462                 :            :       rtx_insn *e = end;
     463                 :    1550340 :       while (insn != e && DEBUG_INSN_P (e))
     464                 :    1330160 :         e = PREV_INSN (e);
     465                 :     220189 :       if (insn == e)
     466                 :            :         {
     467                 :            :           /* If there are debug insns after a single insn that is a
     468                 :            :              control flow insn in the block, we'd have left right
     469                 :            :              away, but we should clean up the debug insns after the
     470                 :            :              control flow insn, because they can't remain in the same
     471                 :            :              block.  So, do the debug insn cleaning up, but then bail
     472                 :            :              out without purging dead edges as we would if the debug
     473                 :            :              insns hadn't been there.  */
     474                 :       9298 :           if (e != end && !DEBUG_INSN_P (e) && control_flow_insn_p (e))
     475                 :            :             {
     476                 :          0 :               skip_purge = true;
     477                 :          0 :               flow_transfer_insn = e;
     478                 :          0 :               goto clean_up_debug_after_control_flow;
     479                 :            :             }
     480                 :       9298 :           return;
     481                 :            :         }
     482                 :            :     }
     483                 :            : 
     484                 :   15115900 :   if (LABEL_P (insn))
     485                 :    7305090 :     insn = NEXT_INSN (insn);
     486                 :            : 
     487                 :            :   /* Scan insn chain and try to find new basic block boundaries.  */
     488                 :  159900000 :   while (1)
     489                 :            :     {
     490                 :  175016000 :       enum rtx_code code = GET_CODE (insn);
     491                 :            : 
     492                 :  175016000 :       if (code == DEBUG_INSN)
     493                 :            :         {
     494                 :   43884400 :           if (flow_transfer_insn && !debug_insn)
     495                 :        222 :             debug_insn = insn;
     496                 :            :         }
     497                 :            :       /* In case we've previously seen an insn that effects a control
     498                 :            :          flow transfer, split the block.  */
     499                 :  131132000 :       else if ((flow_transfer_insn || code == CODE_LABEL)
     500                 :  131132000 :                && inside_basic_block_p (insn))
     501                 :            :         {
     502                 :    1537440 :           rtx_insn *prev = PREV_INSN (insn);
     503                 :            : 
     504                 :            :           /* If the first non-debug inside_basic_block_p insn after a control
     505                 :            :              flow transfer is not a label, split the block before the debug
     506                 :            :              insn instead of before the non-debug insn, so that the debug
     507                 :            :              insns are not lost.  */
     508                 :    1537440 :           if (debug_insn && code != CODE_LABEL && code != BARRIER)
     509                 :        222 :             prev = PREV_INSN (debug_insn);
     510                 :    1537440 :           fallthru = split_block (bb, prev);
     511                 :    1537440 :           if (flow_transfer_insn)
     512                 :            :             {
     513                 :    1186300 :               BB_END (bb) = flow_transfer_insn;
     514                 :            : 
     515                 :    1186300 :               rtx_insn *next;
     516                 :            :               /* Clean up the bb field for the insns between the blocks.  */
     517                 :    1186300 :               for (x = NEXT_INSN (flow_transfer_insn);
     518                 :    1361880 :                    x != BB_HEAD (fallthru->dest);
     519                 :            :                    x = next)
     520                 :            :                 {
     521                 :     175576 :                   next = NEXT_INSN (x);
     522                 :            :                   /* Debug insns should not be in between basic blocks,
     523                 :            :                      drop them on the floor.  */
     524                 :     175576 :                   if (DEBUG_INSN_P (x))
     525                 :          0 :                     delete_insn (x);
     526                 :     175576 :                   else if (!BARRIER_P (x))
     527                 :    1361880 :                     set_block_for_insn (x, NULL);
     528                 :            :                 }
     529                 :            :             }
     530                 :            : 
     531                 :    1537440 :           bb = fallthru->dest;
     532                 :    1537440 :           remove_edge (fallthru);
     533                 :            :           /* BB is unreachable at this point - we need to determine its profile
     534                 :            :              once edges are built.  */
     535                 :    1537440 :           bb->count = profile_count::uninitialized ();
     536                 :    1537440 :           flow_transfer_insn = NULL;
     537                 :    1537440 :           debug_insn = NULL;
     538                 :    1537440 :           if (code == CODE_LABEL && LABEL_ALT_ENTRY_P (insn))
     539                 :          0 :             make_edge (ENTRY_BLOCK_PTR_FOR_FN (cfun), bb, 0);
     540                 :            :         }
     541                 :  129594000 :       else if (code == BARRIER)
     542                 :            :         {
     543                 :            :           /* __builtin_unreachable () may cause a barrier to be emitted in
     544                 :            :              the middle of a BB.  We need to split it in the same manner as
     545                 :            :              if the barrier were preceded by a control_flow_insn_p insn.  */
     546                 :     266411 :           if (!flow_transfer_insn)
     547                 :         43 :             flow_transfer_insn = prev_nonnote_nondebug_insn_bb (insn);
     548                 :            :         }
     549                 :            : 
     550                 :  175016000 :       if (control_flow_insn_p (insn))
     551                 :   10956100 :         flow_transfer_insn = insn;
     552                 :  175016000 :       if (insn == end)
     553                 :            :         break;
     554                 :  159900000 :       insn = NEXT_INSN (insn);
     555                 :  159900000 :     }
     556                 :            : 
     557                 :            :   /* In case expander replaced normal insn by sequence terminating by
     558                 :            :      return and barrier, or possibly other sequence not behaving like
     559                 :            :      ordinary jump, we need to take care and move basic block boundary.  */
     560                 :   15115900 :   if (flow_transfer_insn && flow_transfer_insn != end)
     561                 :            :     {
     562                 :            :       skip_purge = false;
     563                 :            : 
     564                 :      90835 :     clean_up_debug_after_control_flow:
     565                 :      90835 :       BB_END (bb) = flow_transfer_insn;
     566                 :            : 
     567                 :            :       /* Clean up the bb field for the insns that do not belong to BB.  */
     568                 :      90835 :       rtx_insn *next;
     569                 :      90835 :       for (x = NEXT_INSN (flow_transfer_insn); ; x = next)
     570                 :            :         {
     571                 :      90835 :           next = NEXT_INSN (x);
     572                 :            :           /* Debug insns should not be in between basic blocks,
     573                 :            :              drop them on the floor.  */
     574                 :      90835 :           if (DEBUG_INSN_P (x))
     575                 :          0 :             delete_insn (x);
     576                 :      90835 :           else if (!BARRIER_P (x))
     577                 :          0 :             set_block_for_insn (x, NULL);
     578                 :      90835 :           if (x == end)
     579                 :            :             break;
     580                 :            :         }
     581                 :            : 
     582                 :      90835 :       if (skip_purge)
     583                 :            :         return;
     584                 :            :     }
     585                 :            : 
     586                 :            :   /* We've possibly replaced the conditional jump by conditional jump
     587                 :            :      followed by cleanup at fallthru edge, so the outgoing edges may
     588                 :            :      be dead.  */
     589                 :   15115900 :   purge_dead_edges (bb);
     590                 :            : 
     591                 :            :   /* purge_dead_edges doesn't handle tablejump's, but if we have split the
     592                 :            :      basic block, we might need to kill some edges.  */
     593                 :   15115900 :   if (bb != orig_bb && tablejump_p (BB_END (bb), NULL, &table))
     594                 :       9415 :     purge_dead_tablejump_edges (bb, table);
     595                 :            : }
     596                 :            : 
     597                 :            : /*  Assume that frequency of basic block B is known.  Compute frequencies
     598                 :            :     and probabilities of outgoing edges.  */
     599                 :            : 
     600                 :            : static void
     601                 :    1936880 : compute_outgoing_frequencies (basic_block b)
     602                 :            : {
     603                 :    1936880 :   edge e, f;
     604                 :    1936880 :   edge_iterator ei;
     605                 :            : 
     606                 :    1936880 :   if (EDGE_COUNT (b->succs) == 2)
     607                 :            :     {
     608                 :    1148680 :       rtx note = find_reg_note (BB_END (b), REG_BR_PROB, NULL);
     609                 :    1148680 :       int probability;
     610                 :            : 
     611                 :    1148680 :       if (note)
     612                 :            :         {
     613                 :     831324 :           probability = XINT (note, 0);
     614                 :     831324 :           e = BRANCH_EDGE (b);
     615                 :     831324 :           e->probability
     616                 :     831324 :                  = profile_probability::from_reg_br_prob_note (probability);
     617                 :     831324 :           f = FALLTHRU_EDGE (b);
     618                 :     831324 :           f->probability = e->probability.invert ();
     619                 :    1613100 :           return;
     620                 :            :         }
     621                 :            :       else
     622                 :            :         {
     623                 :     317358 :           guess_outgoing_edge_probabilities (b);
     624                 :            :         }
     625                 :            :     }
     626                 :     788197 :   else if (single_succ_p (b))
     627                 :            :     {
     628                 :     781779 :       e = single_succ_edge (b);
     629                 :     781779 :       e->probability = profile_probability::always ();
     630                 :     781779 :       return;
     631                 :            :     }
     632                 :            :   else
     633                 :            :     {
     634                 :            :       /* We rely on BBs with more than two successors to have sane probabilities
     635                 :            :          and do not guess them here. For BBs terminated by switch statements
     636                 :            :          expanded to jump-table jump, we have done the right thing during
     637                 :            :          expansion. For EH edges, we still guess the probabilities here.  */
     638                 :       6418 :       bool complex_edge = false;
     639                 :      35356 :       FOR_EACH_EDGE (e, ei, b->succs)
     640                 :      30022 :         if (e->flags & EDGE_COMPLEX)
     641                 :            :           {
     642                 :            :             complex_edge = true;
     643                 :            :             break;
     644                 :            :           }
     645                 :       6418 :       if (complex_edge)
     646                 :       1084 :         guess_outgoing_edge_probabilities (b);
     647                 :            :     }
     648                 :            : }
     649                 :            : 
     650                 :            : /* Assume that some pass has inserted labels or control flow
     651                 :            :    instructions within a basic block.  Split basic blocks as needed
     652                 :            :    and create edges.  */
     653                 :            : 
     654                 :            : void
     655                 :    2287400 : find_many_sub_basic_blocks (sbitmap blocks)
     656                 :            : {
     657                 :    2287400 :   basic_block bb, min, max;
     658                 :    2287400 :   bool found = false;
     659                 :    4574800 :   auto_vec<unsigned int> n_succs;
     660                 :    2287400 :   n_succs.safe_grow_cleared (last_basic_block_for_fn (cfun));
     661                 :            : 
     662                 :   35093000 :   FOR_EACH_BB_FN (bb, cfun)
     663                 :   50410200 :     SET_STATE (bb,
     664                 :            :                bitmap_bit_p (blocks, bb->index) ? BLOCK_TO_SPLIT : BLOCK_ORIGINAL);
     665                 :            : 
     666                 :   36630500 :   FOR_EACH_BB_FN (bb, cfun)
     667                 :   34343100 :     if (STATE (bb) == BLOCK_TO_SPLIT)
     668                 :            :       {
     669                 :   15201100 :         int n = last_basic_block_for_fn (cfun);
     670                 :   15201100 :         unsigned int ns = EDGE_COUNT (bb->succs);
     671                 :            : 
     672                 :   15201100 :         find_bb_boundaries (bb);
     673                 :   29470100 :         if (n == last_basic_block_for_fn (cfun) && ns == EDGE_COUNT (bb->succs))
     674                 :   14391300 :           n_succs[bb->index] = EDGE_COUNT (bb->succs);
     675                 :            :       }
     676                 :            : 
     677                 :    4737740 :   FOR_EACH_BB_FN (bb, cfun)
     678                 :    4737740 :     if (STATE (bb) != BLOCK_ORIGINAL)
     679                 :            :       {
     680                 :            :         found = true;
     681                 :            :         break;
     682                 :            :       }
     683                 :            : 
     684                 :    2287400 :   if (!found)
     685                 :          0 :     return;
     686                 :            : 
     687                 :   34180100 :   min = max = bb;
     688                 :   34180100 :   for (; bb != EXIT_BLOCK_PTR_FOR_FN (cfun); bb = bb->next_bb)
     689                 :   31892700 :     if (STATE (bb) != BLOCK_ORIGINAL)
     690                 :   16738500 :       max = bb;
     691                 :            : 
     692                 :            :   /* Now re-scan and wire in all edges.  This expect simple (conditional)
     693                 :            :      jumps at the end of each new basic blocks.  */
     694                 :    2287400 :   make_edges (min, max, 1);
     695                 :            : 
     696                 :            :   /* Update branch probabilities.  Expect only (un)conditional jumps
     697                 :            :      to be created with only the forward edges.  */
     698                 :    2287400 :   if (profile_status_for_fn (cfun) != PROFILE_ABSENT)
     699                 :   18952000 :     FOR_BB_BETWEEN (bb, min, max->next_bb, next_bb)
     700                 :            :       {
     701                 :   17295700 :         edge e;
     702                 :   17295700 :         edge_iterator ei;
     703                 :            : 
     704                 :   17295700 :         if (STATE (bb) == BLOCK_ORIGINAL)
     705                 :   15358800 :           continue;
     706                 :   13261500 :         if (STATE (bb) == BLOCK_NEW)
     707                 :            :           {
     708                 :    1239950 :             bool initialized_src = false, uninitialized_src = false;
     709                 :    1239950 :             bb->count = profile_count::zero ();
     710                 :    2864800 :             FOR_EACH_EDGE (e, ei, bb->preds)
     711                 :            :               {
     712                 :    1624850 :                 if (e->count ().initialized_p ())
     713                 :            :                   {
     714                 :    1616990 :                     bb->count += e->count ();
     715                 :    1616990 :                     initialized_src = true;
     716                 :            :                   }
     717                 :            :                 else
     718                 :            :                   uninitialized_src = true;
     719                 :            :               }
     720                 :            :             /* When some edges are missing with read profile, this is
     721                 :            :                most likely because RTL expansion introduced loop.
     722                 :            :                When profile is guessed we may have BB that is reachable
     723                 :            :                from unlikely path as well as from normal path.
     724                 :            : 
     725                 :            :                TODO: We should handle loops created during BB expansion
     726                 :            :                correctly here.  For now we assume all those loop to cycle
     727                 :            :                precisely once.  */
     728                 :    1239950 :             if (!initialized_src
     729                 :    1234940 :                 || (uninitialized_src
     730                 :       3085 :                      && profile_status_for_fn (cfun) < PROFILE_GUESSED))
     731                 :       5015 :               bb->count = profile_count::uninitialized ();
     732                 :            :           }
     733                 :            :         /* If nothing changed, there is no need to create new BBs.  */
     734                 :   24038200 :         else if (EDGE_COUNT (bb->succs) == n_succs[bb->index])
     735                 :            :           {
     736                 :            :             /* In rare occassions RTL expansion might have mistakely assigned
     737                 :            :                a probabilities different from what is in CFG.  This happens
     738                 :            :                when we try to split branch to two but optimize out the
     739                 :            :                second branch during the way. See PR81030.  */
     740                 :    6468600 :             if (JUMP_P (BB_END (bb)) && any_condjump_p (BB_END (bb))
     741                 :   15435300 :                 && EDGE_COUNT (bb->succs) >= 2)
     742                 :    4110690 :               update_br_prob_note (bb);
     743                 :   11324600 :             continue;
     744                 :            :           }
     745                 :            : 
     746                 :    1936880 :         compute_outgoing_frequencies (bb);
     747                 :            :       }
     748                 :            : 
     749                 :   36630500 :   FOR_EACH_BB_FN (bb, cfun)
     750                 :   34343100 :     SET_STATE (bb, 0);
     751                 :            : }

Generated by: LCOV version 1.0

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 --enable-host-shared. GCC test suite is run with the built compiler.