Home | History | Annotate | Line # | Download | only in gcc
      1 /* Instruction scheduling pass.
      2    Copyright (C) 1992-2022 Free Software Foundation, Inc.
      3    Contributed by Michael Tiemann (tiemann (at) cygnus.com) Enhanced by,
      4    and currently maintained by, Jim Wilson (wilson (at) cygnus.com)
      5 
      6 This file is part of GCC.
      7 
      8 GCC is free software; you can redistribute it and/or modify it under
      9 the terms of the GNU General Public License as published by the Free
     10 Software Foundation; either version 3, or (at your option) any later
     11 version.
     12 
     13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
     14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
     15 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
     16 for more details.
     17 
     18 You should have received a copy of the GNU General Public License
     19 along with GCC; see the file COPYING3.  If not see
     20 <http://www.gnu.org/licenses/>.  */
     21 
     22 #include "config.h"
     24 #include "system.h"
     25 #include "coretypes.h"
     26 #include "backend.h"
     27 #include "target.h"
     28 #include "rtl.h"
     29 #include "cfghooks.h"
     30 #include "df.h"
     31 #include "profile.h"
     32 #include "insn-attr.h"
     33 #include "cfgrtl.h"
     34 #include "cfgbuild.h"
     35 #include "sched-int.h"
     36 
     37 
     38 #ifdef INSN_SCHEDULING
     40 
     41 /* The number of insns to be scheduled in total.  */
     42 static int rgn_n_insns;
     43 
     44 /* The number of insns scheduled so far.  */
     45 static int sched_rgn_n_insns;
     46 
     47 /* Set of blocks, that already have their dependencies calculated.  */
     48 static bitmap_head dont_calc_deps;
     49 
     50 /* Last basic block in current ebb.  */
     51 static basic_block last_bb;
     52 
     53 /* Implementations of the sched_info functions for region scheduling.  */
     54 static void init_ready_list (void);
     55 static void begin_schedule_ready (rtx_insn *);
     56 static int schedule_more_p (void);
     57 static const char *ebb_print_insn (const rtx_insn *, int);
     58 static int rank (rtx_insn *, rtx_insn *);
     59 static int ebb_contributes_to_priority (rtx_insn *, rtx_insn *);
     60 static basic_block earliest_block_with_similiar_load (basic_block, rtx);
     61 static void add_deps_for_risky_insns (rtx_insn *, rtx_insn *);
     62 static void debug_ebb_dependencies (rtx_insn *, rtx_insn *);
     63 
     64 static void ebb_add_remove_insn (rtx_insn *, int);
     65 static void ebb_add_block (basic_block, basic_block);
     66 static basic_block advance_target_bb (basic_block, rtx_insn *);
     67 static void ebb_fix_recovery_cfg (int, int, int);
     68 
     69 /* Allocate memory and store the state of the frontend.  Return the allocated
     70    memory.  */
     71 static void *
     72 save_ebb_state (void)
     73 {
     74   int *p = XNEW (int);
     75   *p = sched_rgn_n_insns;
     76   return p;
     77 }
     78 
     79 /* Restore the state of the frontend from P_, then free it.  */
     80 static void
     81 restore_ebb_state (void *p_)
     82 {
     83   int *p = (int *)p_;
     84   sched_rgn_n_insns = *p;
     85   free (p_);
     86 }
     87 
     88 /* Return nonzero if there are more insns that should be scheduled.  */
     89 
     90 static int
     91 schedule_more_p (void)
     92 {
     93   return sched_rgn_n_insns < rgn_n_insns;
     94 }
     95 
     96 /* Print dependency information about ebb between HEAD and TAIL.  */
     97 static void
     98 debug_ebb_dependencies (rtx_insn *head, rtx_insn *tail)
     99 {
    100   fprintf (sched_dump,
    101 	   ";;   --------------- forward dependences: ------------ \n");
    102 
    103   fprintf (sched_dump, "\n;;   --- EBB Dependences --- from bb%d to bb%d \n",
    104 	   BLOCK_NUM (head), BLOCK_NUM (tail));
    105 
    106   debug_dependencies (head, tail);
    107 }
    108 
    109 /* Add all insns that are initially ready to the ready list READY.  Called
    110    once before scheduling a set of insns.  */
    111 
    112 static void
    113 init_ready_list (void)
    114 {
    115   int n = 0;
    116   rtx_insn *prev_head = current_sched_info->prev_head;
    117   rtx_insn *next_tail = current_sched_info->next_tail;
    118   rtx_insn *insn;
    119 
    120   sched_rgn_n_insns = 0;
    121 
    122   /* Print debugging information.  */
    123   if (sched_verbose >= 5)
    124     debug_ebb_dependencies (NEXT_INSN (prev_head), PREV_INSN (next_tail));
    125 
    126   /* Initialize ready list with all 'ready' insns in target block.
    127      Count number of insns in the target block being scheduled.  */
    128   for (insn = NEXT_INSN (prev_head); insn != next_tail; insn = NEXT_INSN (insn))
    129     {
    130       try_ready (insn);
    131       n++;
    132     }
    133 
    134   gcc_assert (n == rgn_n_insns);
    135 }
    136 
    137 /* INSN is being scheduled after LAST.  Update counters.  */
    138 static void
    139 begin_schedule_ready (rtx_insn *insn ATTRIBUTE_UNUSED)
    140 {
    141   sched_rgn_n_insns++;
    142 }
    143 
    144 /* INSN is being moved to its place in the schedule, after LAST.  */
    145 static void
    146 begin_move_insn (rtx_insn *insn, rtx_insn *last)
    147 {
    148   if (BLOCK_FOR_INSN (insn) == last_bb
    149       /* INSN is a jump in the last block, ...  */
    150       && control_flow_insn_p (insn)
    151       /* that is going to be moved over some instructions.  */
    152       && last != PREV_INSN (insn))
    153     {
    154       edge e;
    155       basic_block bb;
    156 
    157       /* An obscure special case, where we do have partially dead
    158 	 instruction scheduled after last control flow instruction.
    159 	 In this case we can create new basic block.  It is
    160 	 always exactly one basic block last in the sequence.  */
    161 
    162       e = find_fallthru_edge (last_bb->succs);
    163 
    164       gcc_checking_assert (!e || !(e->flags & EDGE_COMPLEX));
    165 
    166       gcc_checking_assert (BLOCK_FOR_INSN (insn) == last_bb
    167 			   && !IS_SPECULATION_CHECK_P (insn)
    168 			   && BB_HEAD (last_bb) != insn
    169 			   && BB_END (last_bb) == insn);
    170 
    171       {
    172 	rtx_insn *x = NEXT_INSN (insn);
    173 	if (e)
    174 	  gcc_checking_assert (NOTE_P (x) || LABEL_P (x));
    175 	else
    176 	  gcc_checking_assert (BARRIER_P (x));
    177       }
    178 
    179       if (e)
    180 	{
    181 	  bb = split_edge (e);
    182 	  gcc_assert (NOTE_INSN_BASIC_BLOCK_P (BB_END (bb)));
    183 	}
    184       else
    185 	{
    186 	  /* Create an empty unreachable block after the INSN.  */
    187 	  rtx_insn *next = NEXT_INSN (insn);
    188 	  if (next && BARRIER_P (next))
    189 	    next = NEXT_INSN (next);
    190 	  bb = create_basic_block (next, NULL_RTX, last_bb);
    191 	}
    192 
    193       /* split_edge () creates BB before E->DEST.  Keep in mind, that
    194 	 this operation extends scheduling region till the end of BB.
    195 	 Hence, we need to shift NEXT_TAIL, so haifa-sched.cc won't go out
    196 	 of the scheduling region.  */
    197       current_sched_info->next_tail = NEXT_INSN (BB_END (bb));
    198       gcc_assert (current_sched_info->next_tail);
    199 
    200       /* Append new basic block to the end of the ebb.  */
    201       sched_init_only_bb (bb, last_bb);
    202       gcc_assert (last_bb == bb);
    203     }
    204 }
    205 
    206 /* Return a string that contains the insn uid and optionally anything else
    207    necessary to identify this insn in an output.  It's valid to use a
    208    static buffer for this.  The ALIGNED parameter should cause the string
    209    to be formatted so that multiple output lines will line up nicely.  */
    210 
    211 static const char *
    212 ebb_print_insn (const rtx_insn *insn, int aligned ATTRIBUTE_UNUSED)
    213 {
    214   static char tmp[80];
    215 
    216   /* '+' before insn means it is a new cycle start.  */
    217   if (GET_MODE (insn) == TImode)
    218     sprintf (tmp, "+ %4d", INSN_UID (insn));
    219   else
    220     sprintf (tmp, "  %4d", INSN_UID (insn));
    221 
    222   return tmp;
    223 }
    224 
    225 /* Compare priority of two insns.  Return a positive number if the second
    226    insn is to be preferred for scheduling, and a negative one if the first
    227    is to be preferred.  Zero if they are equally good.  */
    228 
    229 static int
    230 rank (rtx_insn *insn1, rtx_insn *insn2)
    231 {
    232   basic_block bb1 = BLOCK_FOR_INSN (insn1);
    233   basic_block bb2 = BLOCK_FOR_INSN (insn2);
    234 
    235   if (bb1->count > bb2->count)
    236     return -1;
    237   if (bb1->count < bb2->count)
    238     return 1;
    239   return 0;
    240 }
    241 
    242 /* NEXT is an instruction that depends on INSN (a backward dependence);
    243    return nonzero if we should include this dependence in priority
    244    calculations.  */
    245 
    246 static int
    247 ebb_contributes_to_priority (rtx_insn *next ATTRIBUTE_UNUSED,
    248                              rtx_insn *insn ATTRIBUTE_UNUSED)
    249 {
    250   return 1;
    251 }
    252 
    253  /* INSN is a JUMP_INSN.  Store the set of registers that
    254     must be considered as used by this jump in USED.  */
    255 
    256 void
    257 ebb_compute_jump_reg_dependencies (rtx insn, regset used)
    258 {
    259   basic_block b = BLOCK_FOR_INSN (insn);
    260   edge e;
    261   edge_iterator ei;
    262 
    263   FOR_EACH_EDGE (e, ei, b->succs)
    264     if ((e->flags & EDGE_FALLTHRU) == 0)
    265       bitmap_ior_into (used, df_get_live_in (e->dest));
    266 }
    267 
    268 /* Used in schedule_insns to initialize current_sched_info for scheduling
    269    regions (or single basic blocks).  */
    270 
    271 static struct common_sched_info_def ebb_common_sched_info;
    272 
    273 static struct sched_deps_info_def ebb_sched_deps_info =
    274   {
    275     ebb_compute_jump_reg_dependencies,
    276     NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
    277     NULL,
    278     1, 0, 0
    279   };
    280 
    281 static struct haifa_sched_info ebb_sched_info =
    282 {
    283   init_ready_list,
    284   NULL,
    285   schedule_more_p,
    286   NULL,
    287   rank,
    288   ebb_print_insn,
    289   ebb_contributes_to_priority,
    290   NULL, /* insn_finishes_block_p */
    291 
    292   NULL, NULL,
    293   NULL, NULL,
    294   1, 0,
    295 
    296   ebb_add_remove_insn,
    297   begin_schedule_ready,
    298   begin_move_insn,
    299   advance_target_bb,
    300 
    301   save_ebb_state,
    302   restore_ebb_state,
    303 
    304   SCHED_EBB
    305   /* We can create new blocks in begin_schedule_ready ().  */
    306   | NEW_BBS
    307 };
    308 
    309 /* Returns the earliest block in EBB currently being processed where a
    311    "similar load" 'insn2' is found, and hence LOAD_INSN can move
    312    speculatively into the found block.  All the following must hold:
    313 
    314    (1) both loads have 1 base register (PFREE_CANDIDATEs).
    315    (2) load_insn and load2 have a def-use dependence upon
    316    the same insn 'insn1'.
    317 
    318    From all these we can conclude that the two loads access memory
    319    addresses that differ at most by a constant, and hence if moving
    320    load_insn would cause an exception, it would have been caused by
    321    load2 anyhow.
    322 
    323    The function uses list (given by LAST_BLOCK) of already processed
    324    blocks in EBB.  The list is formed in `add_deps_for_risky_insns'.  */
    325 
    326 static basic_block
    327 earliest_block_with_similiar_load (basic_block last_block, rtx load_insn)
    328 {
    329   sd_iterator_def back_sd_it;
    330   dep_t back_dep;
    331   basic_block bb, earliest_block = NULL;
    332 
    333   FOR_EACH_DEP (load_insn, SD_LIST_BACK, back_sd_it, back_dep)
    334     {
    335       rtx_insn *insn1 = DEP_PRO (back_dep);
    336 
    337       if (DEP_TYPE (back_dep) == REG_DEP_TRUE)
    338 	/* Found a DEF-USE dependence (insn1, load_insn).  */
    339 	{
    340 	  sd_iterator_def fore_sd_it;
    341 	  dep_t fore_dep;
    342 
    343 	  FOR_EACH_DEP (insn1, SD_LIST_FORW, fore_sd_it, fore_dep)
    344 	    {
    345 	      rtx_insn *insn2 = DEP_CON (fore_dep);
    346 	      basic_block insn2_block = BLOCK_FOR_INSN (insn2);
    347 
    348 	      if (DEP_TYPE (fore_dep) == REG_DEP_TRUE)
    349 		{
    350 		  if (earliest_block != NULL
    351 		      && earliest_block->index < insn2_block->index)
    352 		    continue;
    353 
    354 		  /* Found a DEF-USE dependence (insn1, insn2).  */
    355 		  if (haifa_classify_insn (insn2) != PFREE_CANDIDATE)
    356 		    /* insn2 not guaranteed to be a 1 base reg load.  */
    357 		    continue;
    358 
    359 		  for (bb = last_block; bb; bb = (basic_block) bb->aux)
    360 		    if (insn2_block == bb)
    361 		      break;
    362 
    363 		  if (!bb)
    364 		    /* insn2 is the similar load.  */
    365 		    earliest_block = insn2_block;
    366 		}
    367 	    }
    368 	}
    369     }
    370 
    371   return earliest_block;
    372 }
    373 
    374 /* The following function adds dependencies between jumps and risky
    375    insns in given ebb.  */
    376 
    377 static void
    378 add_deps_for_risky_insns (rtx_insn *head, rtx_insn *tail)
    379 {
    380   rtx_insn *insn, *prev;
    381   int classification;
    382   rtx_insn *last_jump = NULL;
    383   rtx_insn *next_tail = NEXT_INSN (tail);
    384   basic_block last_block = NULL, bb;
    385 
    386   for (insn = head; insn != next_tail; insn = NEXT_INSN (insn))
    387     {
    388       add_delay_dependencies (insn);
    389       if (control_flow_insn_p (insn))
    390 	{
    391 	  bb = BLOCK_FOR_INSN (insn);
    392 	  bb->aux = last_block;
    393 	  last_block = bb;
    394 	  /* Ensure blocks stay in the same order.  */
    395 	  if (last_jump)
    396 	    add_dependence (insn, last_jump, REG_DEP_ANTI);
    397 	  last_jump = insn;
    398 	}
    399       else if (INSN_P (insn) && last_jump != NULL_RTX)
    400 	{
    401 	  classification = haifa_classify_insn (insn);
    402 	  prev = last_jump;
    403 
    404 	  switch (classification)
    405 	    {
    406 	    case PFREE_CANDIDATE:
    407 	      if (flag_schedule_speculative_load)
    408 		{
    409 		  bb = earliest_block_with_similiar_load (last_block, insn);
    410 		  if (bb)
    411 		    {
    412 		      bb = (basic_block) bb->aux;
    413 		      if (!bb)
    414 			break;
    415 		      prev = BB_END (bb);
    416 		    }
    417 		}
    418 	      /* Fall through.  */
    419 	    case TRAP_RISKY:
    420 	    case IRISKY:
    421 	    case PRISKY_CANDIDATE:
    422 	      /* ??? We could implement better checking PRISKY_CANDIDATEs
    423 		 analogous to sched-rgn.cc.  */
    424 	      /* We cannot change the mode of the backward
    425 		 dependency because REG_DEP_ANTI has the lowest
    426 		 rank.  */
    427 	      if (! sched_insns_conditions_mutex_p (insn, prev))
    428 		{
    429 		  if ((current_sched_info->flags & DO_SPECULATION)
    430 		      && (spec_info->mask & BEGIN_CONTROL))
    431 		    {
    432 		      dep_def _dep, *dep = &_dep;
    433 
    434 		      init_dep (dep, prev, insn, REG_DEP_ANTI);
    435 
    436 		      if (current_sched_info->flags & USE_DEPS_LIST)
    437 			{
    438 			  DEP_STATUS (dep) = set_dep_weak (DEP_ANTI, BEGIN_CONTROL,
    439 							   MAX_DEP_WEAK);
    440 
    441 			}
    442 		      sd_add_or_update_dep (dep, false);
    443 		    }
    444 		  else
    445 		    add_dependence (insn, prev, REG_DEP_CONTROL);
    446 		}
    447 
    448 	      break;
    449 
    450 	    default:
    451 	      break;
    452 	    }
    453 	}
    454     }
    455   /* Maintain the invariant that bb->aux is clear after use.  */
    456   while (last_block)
    457     {
    458       bb = (basic_block) last_block->aux;
    459       last_block->aux = NULL;
    460       last_block = bb;
    461     }
    462 }
    463 
    464 /* Schedule a single extended basic block, defined by the boundaries
    465    HEAD and TAIL.
    466 
    467    We change our expectations about scheduler behavior depending on
    468    whether MODULO_SCHEDULING is true.  If it is, we expect that the
    469    caller has already called set_modulo_params and created delay pairs
    470    as appropriate.  If the modulo schedule failed, we return
    471    NULL_RTX.  */
    472 
    473 basic_block
    474 schedule_ebb (rtx_insn *head, rtx_insn *tail, bool modulo_scheduling)
    475 {
    476   basic_block first_bb, target_bb;
    477   class deps_desc tmp_deps;
    478   bool success;
    479 
    480   /* Blah.  We should fix the rest of the code not to get confused by
    481      a note or two.  */
    482   while (head != tail)
    483     {
    484       if (NOTE_P (head) || DEBUG_INSN_P (head))
    485 	head = NEXT_INSN (head);
    486       else if (NOTE_P (tail) || DEBUG_INSN_P (tail))
    487 	tail = PREV_INSN (tail);
    488       else if (LABEL_P (head))
    489 	head = NEXT_INSN (head);
    490       else
    491 	break;
    492     }
    493 
    494   first_bb = BLOCK_FOR_INSN (head);
    495   last_bb = BLOCK_FOR_INSN (tail);
    496 
    497   if (no_real_insns_p (head, tail))
    498     return BLOCK_FOR_INSN (tail);
    499 
    500   gcc_assert (INSN_P (head) && INSN_P (tail));
    501 
    502   if (!bitmap_bit_p (&dont_calc_deps, first_bb->index))
    503     {
    504       init_deps_global ();
    505 
    506       /* Compute dependencies.  */
    507       init_deps (&tmp_deps, false);
    508       sched_analyze (&tmp_deps, head, tail);
    509       free_deps (&tmp_deps);
    510 
    511       add_deps_for_risky_insns (head, tail);
    512 
    513       if (targetm.sched.dependencies_evaluation_hook)
    514         targetm.sched.dependencies_evaluation_hook (head, tail);
    515 
    516       finish_deps_global ();
    517     }
    518   else
    519     /* Only recovery blocks can have their dependencies already calculated,
    520        and they always are single block ebbs.  */
    521     gcc_assert (first_bb == last_bb);
    522 
    523   /* Set priorities.  */
    524   current_sched_info->sched_max_insns_priority = 0;
    525   rgn_n_insns = set_priorities (head, tail);
    526   current_sched_info->sched_max_insns_priority++;
    527 
    528   current_sched_info->prev_head = PREV_INSN (head);
    529   current_sched_info->next_tail = NEXT_INSN (tail);
    530 
    531   remove_notes (head, tail);
    532 
    533   unlink_bb_notes (first_bb, last_bb);
    534 
    535   target_bb = first_bb;
    536 
    537   /* Make ready list big enough to hold all the instructions from the ebb.  */
    538   sched_extend_ready_list (rgn_n_insns);
    539   success = schedule_block (&target_bb, NULL);
    540   gcc_assert (success || modulo_scheduling);
    541 
    542   /* Free ready list.  */
    543   sched_finish_ready_list ();
    544 
    545   /* We might pack all instructions into fewer blocks,
    546      so we may made some of them empty.  Can't assert (b == last_bb).  */
    547 
    548   /* Sanity check: verify that all region insns were scheduled.  */
    549   gcc_assert (modulo_scheduling || sched_rgn_n_insns == rgn_n_insns);
    550 
    551   /* Free dependencies.  */
    552   sched_free_deps (current_sched_info->head, current_sched_info->tail, true);
    553 
    554   gcc_assert (haifa_recovery_bb_ever_added_p
    555 	      || deps_pools_are_empty_p ());
    556 
    557   if (EDGE_COUNT (last_bb->preds) == 0)
    558     /* LAST_BB is unreachable.  */
    559     {
    560       gcc_assert (first_bb != last_bb
    561 		  && EDGE_COUNT (last_bb->succs) == 0);
    562       last_bb = last_bb->prev_bb;
    563       delete_basic_block (last_bb->next_bb);
    564     }
    565 
    566   return success ? last_bb : NULL;
    567 }
    568 
    569 /* Perform initializations before running schedule_ebbs or a single
    570    schedule_ebb.  */
    571 void
    572 schedule_ebbs_init (void)
    573 {
    574   /* Setup infos.  */
    575   {
    576     memcpy (&ebb_common_sched_info, &haifa_common_sched_info,
    577 	    sizeof (ebb_common_sched_info));
    578 
    579     ebb_common_sched_info.fix_recovery_cfg = ebb_fix_recovery_cfg;
    580     ebb_common_sched_info.add_block = ebb_add_block;
    581     ebb_common_sched_info.sched_pass_id = SCHED_EBB_PASS;
    582 
    583     common_sched_info = &ebb_common_sched_info;
    584     sched_deps_info = &ebb_sched_deps_info;
    585     current_sched_info = &ebb_sched_info;
    586   }
    587 
    588   haifa_sched_init ();
    589 
    590   compute_bb_for_insn ();
    591 
    592   /* Initialize DONT_CALC_DEPS and ebb-{start, end} markers.  */
    593   bitmap_initialize (&dont_calc_deps, &bitmap_default_obstack);
    594 }
    595 
    596 /* Perform cleanups after scheduling using schedules_ebbs or schedule_ebb.  */
    597 void
    598 schedule_ebbs_finish (void)
    599 {
    600   bitmap_release (&dont_calc_deps);
    601 
    602   /* Reposition the prologue and epilogue notes in case we moved the
    603      prologue/epilogue insns.  */
    604   if (reload_completed)
    605     reposition_prologue_and_epilogue_notes ();
    606 
    607   haifa_sched_finish ();
    608 }
    609 
    610 /* The main entry point in this file.  */
    611 
    612 void
    613 schedule_ebbs (void)
    614 {
    615   basic_block bb;
    616   int probability_cutoff;
    617   rtx_insn *tail;
    618 
    619   /* Taking care of this degenerate case makes the rest of
    620      this code simpler.  */
    621   if (n_basic_blocks_for_fn (cfun) == NUM_FIXED_BLOCKS)
    622     return;
    623 
    624   if (profile_info && profile_status_for_fn (cfun) == PROFILE_READ)
    625     probability_cutoff = param_tracer_min_branch_probability_feedback;
    626   else
    627     probability_cutoff = param_tracer_min_branch_probability;
    628   probability_cutoff = REG_BR_PROB_BASE / 100 * probability_cutoff;
    629 
    630   schedule_ebbs_init ();
    631 
    632   /* Schedule every region in the subroutine.  */
    633   FOR_EACH_BB_FN (bb, cfun)
    634     {
    635       rtx_insn *head = BB_HEAD (bb);
    636 
    637       if (bb->flags & BB_DISABLE_SCHEDULE)
    638 	continue;
    639 
    640       for (;;)
    641 	{
    642 	  edge e;
    643 	  tail = BB_END (bb);
    644 	  if (bb->next_bb == EXIT_BLOCK_PTR_FOR_FN (cfun)
    645 	      || LABEL_P (BB_HEAD (bb->next_bb)))
    646 	    break;
    647 	  e = find_fallthru_edge (bb->succs);
    648 	  if (! e)
    649 	    break;
    650 	  if (e->probability.initialized_p ()
    651 	      && e->probability.to_reg_br_prob_base () <= probability_cutoff)
    652 	    break;
    653 	  if (e->dest->flags & BB_DISABLE_SCHEDULE)
    654  	    break;
    655 	  bb = bb->next_bb;
    656 	}
    657 
    658       bb = schedule_ebb (head, tail, false);
    659     }
    660   schedule_ebbs_finish ();
    661 }
    662 
    663 /* INSN has been added to/removed from current ebb.  */
    664 static void
    665 ebb_add_remove_insn (rtx_insn *insn ATTRIBUTE_UNUSED, int remove_p)
    666 {
    667   if (!remove_p)
    668     rgn_n_insns++;
    669   else
    670     rgn_n_insns--;
    671 }
    672 
    673 /* BB was added to ebb after AFTER.  */
    674 static void
    675 ebb_add_block (basic_block bb, basic_block after)
    676 {
    677   /* Recovery blocks are always bounded by BARRIERS,
    678      therefore, they always form single block EBB,
    679      therefore, we can use rec->index to identify such EBBs.  */
    680   if (after == EXIT_BLOCK_PTR_FOR_FN (cfun))
    681     bitmap_set_bit (&dont_calc_deps, bb->index);
    682   else if (after == last_bb)
    683     last_bb = bb;
    684 }
    685 
    686 /* Return next block in ebb chain.  For parameter meaning please refer to
    687    sched-int.h: struct sched_info: advance_target_bb.  */
    688 static basic_block
    689 advance_target_bb (basic_block bb, rtx_insn *insn)
    690 {
    691   if (insn)
    692     {
    693       if (BLOCK_FOR_INSN (insn) != bb
    694 	  && control_flow_insn_p (insn)
    695 	  /* We handle interblock movement of the speculation check
    696 	     or over a speculation check in
    697 	     haifa-sched.cc: move_block_after_check ().  */
    698 	  && !IS_SPECULATION_BRANCHY_CHECK_P (insn)
    699 	  && !IS_SPECULATION_BRANCHY_CHECK_P (BB_END (bb)))
    700 	{
    701 	  /* Assert that we don't move jumps across blocks.  */
    702 	  gcc_assert (!control_flow_insn_p (BB_END (bb))
    703 		      && NOTE_INSN_BASIC_BLOCK_P (BB_HEAD (bb->next_bb)));
    704 	  return bb;
    705 	}
    706       else
    707 	return 0;
    708     }
    709   else
    710     /* Return next non empty block.  */
    711     {
    712       do
    713 	{
    714 	  gcc_assert (bb != last_bb);
    715 
    716 	  bb = bb->next_bb;
    717 	}
    718       while (bb_note (bb) == BB_END (bb));
    719 
    720       return bb;
    721     }
    722 }
    723 
    724 /* Fix internal data after interblock movement of jump instruction.
    725    For parameter meaning please refer to
    726    sched-int.h: struct sched_info: fix_recovery_cfg.  */
    727 static void
    728 ebb_fix_recovery_cfg (int bbi ATTRIBUTE_UNUSED, int jump_bbi,
    729 		      int jump_bb_nexti)
    730 {
    731   gcc_assert (last_bb->index != bbi);
    732 
    733   if (jump_bb_nexti == last_bb->index)
    734     last_bb = BASIC_BLOCK_FOR_FN (cfun, jump_bbi);
    735 }
    736 
    737 #endif /* INSN_SCHEDULING */
    738