home *** CD-ROM | disk | FTP | other *** search
/ Education Sampler 1992 [NeXTSTEP] / Education_1992_Sampler.iso / NeXT / GnuSource / cc-61.0.1 / cc / sched.c < prev    next >
C/C++ Source or Header  |  1991-12-04  |  123KB  |  4,224 lines

  1. /* Instruction scheduling pass.
  2.    Copyright (C) 1989-1991 Free Software Foundation, Inc.
  3.    Contributed by Michael Tiemann (tiemann@lurch.stanford.edu)
  4.    Enhanced by, and currently maintained by, Jim Wilson (wilson@cygnus.com)
  5.  
  6. This file is part of GNU CC.
  7.  
  8. GNU CC is free software; you can redistribute it and/or modify
  9. it under the terms of the GNU General Public License as published by
  10. the Free Software Foundation; either version 2, or (at your option)
  11. any later version.
  12.  
  13. GNU CC is distributed in the hope that it will be useful,
  14. but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16. GNU General Public License for more details.
  17.  
  18. You should have received a copy of the GNU General Public License
  19. along with GNU CC; see the file COPYING.  If not, write to
  20. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  21.  
  22. /* Instruction scheduling pass.
  23.  
  24.    This pass implements list scheduling within basic blocks.  It is
  25.    run after flow analysis, but before register allocation.  The
  26.    sceduler works as follows:
  27.  
  28.    We compute insn priorities based on data dependencies.  Flow
  29.    analysis only creates a fraction of the data-dependencies we must
  30.    observe: namely, only those dependencies which the combiner can be
  31.    expected to use.  For this pass, we must therefore create the
  32.    remaining dependencies we need to observe: register dependencies,
  33.    memory dependencies, dependencies to keep function calls in order,
  34.    and the dependence between a conditional branch and the setting of
  35.    condition codes are all dealt with here.
  36.  
  37.    The scheduler first traverses the data flow graph, starting with
  38.    the last instruction, and proceeding to the first, assigning
  39.    values to insn_priority as it goes.  This sorts the instructions
  40.    topologically by data dependence.
  41.  
  42.    Once priorities have been established, we order the insns using
  43.    list scheduling.  This works as follows: starting with a list of
  44.    all the ready insns, and sorted according to priority number, we
  45.    schedule the insn from the end of the list by placing its
  46.    predecessors in the list according to their priority order.  We
  47.    consider this insn scheduled by setting the pointer to the "end" of
  48.    the list to point to the previous insn.  When an insn has no
  49.    predecessors, we also add it to the ready list.  When all insns down
  50.    to the lowest priority have been scheduled, the critical path of the
  51.    basic block has been made as short as possible.  The remaining insns
  52.    are then scheduled in remaining slots.
  53.  
  54.    The following list shows the order in which we want to break ties:
  55.  
  56.     1.  choose insn with lowest conflict cost, ties broken by
  57.     2.  choose insn with the longest path to end of bb, ties broken by
  58.     3.  choose insn that kills the most registers, ties broken by
  59.     4.  choose insn that conflicts with the most ready insns, or finally
  60.     5.  choose insn with lowest UID.
  61.  
  62.    Memory references complicate matters.  Only if we can be certain
  63.    that memory references are not part of the data dependency graph
  64.    (via true, anti, or output dependence), can we move operations past
  65.    memory references.  To first approximation, reads can be done
  66.    independently, while writes introduce dependencies.  Better
  67.    approximations will yield fewer dependencies.
  68.  
  69.    Dependencies set up by memory references are treated in exactly the
  70.    same way as other dependencies, by using LOG_LINKS.
  71.  
  72.    Having optimized the critical path, we may have also unduly
  73.    extended the lifetimes of some registers.  If an operation requires
  74.    that constants be loaded into registers, it is certainly desirable
  75.    to load those constants as early as necessary, but no earlier.
  76.    I.e., it will not do to load up a bunch of registers at the
  77.    beginning of a basic block only to use them at the end, if they
  78.    could be loaded later, since this may result in excessive register
  79.    utilization.
  80.  
  81.    Note that since branches are never in basic blocks, but only end
  82.    basic blocks, this pass will not do any branch scheduling.  But
  83.    that is ok, since we can use GNU's delayed branch scheduling
  84.    pass to take care of this case.
  85.  
  86.    Also note that no further optimizations based on algebraic identities
  87.    are performed, so this pass would be a good one to perform instruction
  88.    splitting, such as breaking up a multiply instruction into shifts
  89.    and adds where that is profitable.
  90.  
  91.    Given the memory aliasing analysis that this pass should perform,
  92.    it should be possible to remove redundant stores to memory, and to
  93.    load values from registers instead of hitting memory.
  94.  
  95.    This pass must update information that subsequent passes expect to be
  96.    correct.  Namely: reg_n_refs, reg_n_sets, reg_n_deaths,
  97.    reg_n_calls_crossed, and reg_live_length.  Also, basic_block_head,
  98.    basic_block_end.
  99.  
  100.    I see two possible strategies for dealing with the debugger;
  101.    the first is implemented here, and only produces debugging information
  102.    accurate to a basic block boundary.  It is hard to solve the problem
  103.    of doing maximal optimization while retaining accurate source-code
  104.    correspondence.  The second is to only permit reorganization within
  105.    a binding contour.  This means potentially less performance, but
  106.    then full debugging information can be retained.  I invite someone
  107.    to implement that.  */
  108.  
  109. #include <stdio.h>
  110. #include "config.h"
  111. #include "rtl.h"
  112. #include "basic-block.h"
  113. #include "regs.h"
  114. #include "hard-reg-set.h"
  115. #include "flags.h"
  116. #include "insn-config.h"
  117. #include "insn-attr.h"
  118.  
  119. /* Arrays set up by flow analysis to control register allocation.  */
  120. extern short *reg_n_refs;
  121. extern short *reg_n_sets;
  122. extern short *reg_n_deaths;
  123. extern int *reg_n_calls_crossed;
  124. extern int *reg_live_length;
  125.  
  126. /* Arrays set up by scheduling for the same respective purposes as
  127.    the above arrays.  We work with these arrays during the scheduling
  128.    pass so we can compare values against unscheduled code.
  129.  
  130.    Values of these arrays are copied into the above arrays at the end
  131.    of this pass.  */
  132. static short *sched_reg_n_deaths;
  133. static int *sched_reg_n_calls_crossed;
  134. static int *sched_reg_live_length;
  135.  
  136. /* Element N is the next insn that sets (hard or pseudo) register
  137.    N within the current basic block; or zero, if there is no
  138.    such insn.  Needed for new registers which may be introduced
  139.    by splitting insns.  */
  140. static rtx *reg_last_uses;
  141. static rtx *reg_last_sets;
  142.  
  143. /* Number of last pseudo register assigned in assign_parms.
  144.    Under certain conditions, it would be nice to assume that all
  145.    pseudos numbered with this number or lower are not aliases to
  146.    the same address in memory if they are set only once (i.e., when born).  */
  147. static int max_parm_regno;
  148.  
  149. /* Vector indexed by INSN_UID giving each instruction a priority.  */
  150. static int *insn_priority;
  151. #define INSN_PRIORITY(INSN) (insn_priority[INSN_UID (INSN)])
  152.  
  153. /* Vector indexed by INSN_UID giving number of insns refering to this insn.  */
  154. static int *insn_ref_count;
  155. #define INSN_REF_COUNT(INSN) (insn_ref_count[INSN_UID (INSN)])
  156.  
  157. /* Vector indexed by INSN_UID giving true target for dependency.
  158.    If insn I1 has become a note, and insn I2 depends on I1, then
  159.    INSN_DEP_TARGET (I1) will tell I2 what new insn it depends upon.  */
  160. static rtx *insn_dep_target;
  161. #define INSN_DEP_TARGET(INSN) (insn_dep_target[INSN_UID (INSN)])
  162.  
  163. /* Vector indexed by INSN_UID translating CODE_LABELs to basic
  164.    block numbers.  */
  165. static int *sched_block_number;
  166. #define SCHED_BLOCK_NUM(INSN) (sched_block_number[INSN_UID (INSN)])
  167.  
  168. /* Vector indexed by INSN_UID giving line-number note in effect for each
  169.    insn.  For line-number notes, this indicates whether the note may be
  170.    reused.  */
  171. static rtx *line_note;
  172. #define LINE_NOTE(INSN) (line_note[INSN_UID (INSN)])
  173.  
  174. /* Vector indexed by basic block number giving the starting line-number
  175.    for each basic block.  */
  176. static rtx *line_note_head;
  177.  
  178. /* List of important notes we must keep around.  */
  179. static rtx note_list;
  180.  
  181. /* regset telling whether a given register is set in the current basic
  182.    block.  When this number is zero, we know to treat the value of a
  183.    register as being constant.  */
  184. static regset bb_reg_sets;
  185.  
  186. /* regset telling whether a given pseudo register must die in the current
  187.    basic block.  Hard register deaths don't need special treatment because
  188.    we don't disorganize hard registers too much.  Initially, when scanning
  189.    the insns, if we see a REG_DEAD note, we mark this regset.  The first
  190.    time we schedule an insn which uses a marked register, we put the
  191.    REG_DEAD note on that insn, and clear the entry in the regset.
  192.    We reuse notes that were allocated in previous passes.  */
  193. static regset bb_dead_regs;
  194.  
  195. /* regset telling whether a given pseudo register is alive right now.
  196.    If it is alive, and an insn which sets this register becomes ready to
  197.    fire, then increase its priority in the list, since that will shorten
  198.    the register's life.  */
  199. static regset bb_live_regs;
  200.  
  201. /* regset telling whether a given pseudo register is alive.  Before processing
  202.    an insn, this is equal to bb_live_regs above.  This is used so that we
  203.    can find regsiters that are newly born/dead after processing an insn.  */
  204.  
  205. static regset old_live_regs;
  206.  
  207. /* The chain of REG_DEAD notes.  */
  208. static rtx dead_notes;
  209.  
  210. /* Queues, etc.  */
  211.  
  212. /* An instruction is ready to be scheduled when all insns following it
  213.    have already been scheduled.  It is important to ensure that all
  214.    insns which use its result will not be executed until its result
  215.    has been computed.  We maintain three lists (conceptually):
  216.  
  217.    (1) a "Ready" list of unscheduled, uncommitted insns
  218.    (2) a "Scheduled" list of scheduled insns
  219.    (3) a "Pending" list of insns which can be scheduled, but
  220.        for stalls.
  221.  
  222.    Insns move from the "Ready" list to the "Pending" list when
  223.    all insns following them have been scheduled.
  224.  
  225.    Insns move from the "Pending" list to the "Scheduled" list
  226.    when there is sufficient space in the pipeline to prevent
  227.    stalls between the insn and scheduled insns which use it.
  228.  
  229.    The "Pending" list acts as a buffer to preven insns
  230.    from avalanching.
  231.  
  232.    The "Ready" list is implemented by the variable `ready'.
  233.    The "Pending" list are the insns in the LOG_LINKS of ready insns.
  234.    The "Scheduled" list is the new insn chain built by this pass.  */
  235.  
  236. /* Implement a circular buffer from which instructions are issued.  */
  237. #define Q_SIZE 128
  238. static rtx insn_queue[Q_SIZE];
  239. static int insn_resources[Q_SIZE];
  240. static int q_ptr = 0;
  241. static int q_size = 0;
  242. #define PREV_Q(X) (((X)-1) & (Q_SIZE-1))
  243. #define NEXT_Q(X) (((X)+1) & (Q_SIZE-1))
  244. #define NEXT_Q_AFTER(X,C) (((X)+C) & (Q_SIZE-1))
  245. #define Q_REF(I) (insn_queue[(q_ptr+(I)) & (Q_SIZE-1)])
  246.  
  247. /* Local functions.  */
  248. static rtx find_insn_list ();
  249. static int priority ();
  250. static void sched_analyze_insn ();
  251. static void schedule_block ();
  252.  
  253. /* Main entry point of this file.  */
  254. void schedule_insns ();
  255.  
  256. #define SIZE_FOR_MODE(X) (GET_MODE_SIZE (GET_MODE (X)))
  257.  
  258. /* Vector indexed by N number giving the initial (unchanging) value known
  259.    for pseudo-register N.  */
  260. static rtx *reg_known_value;
  261. /* Indicates number of valid entries in reg_known_value.  */
  262. static int reg_known_value_size;
  263.  
  264. static rtx
  265. canon_rtx (x)
  266.      rtx x;
  267. {
  268.   if (GET_CODE (x) == REG && REGNO (x) >= FIRST_PSEUDO_REGISTER
  269.       && REGNO (x) <= reg_known_value_size)
  270.     return reg_known_value[REGNO (x)];
  271.   else if (GET_CODE (x) == PLUS)
  272.     {
  273.       rtx x0 = canon_rtx (XEXP (x, 0));
  274.       rtx x1 = canon_rtx (XEXP (x, 1));
  275.  
  276.       if (x0 != XEXP (x, 0) || x1 != XEXP (x, 1))
  277.     {
  278.       /* We can tolerate LO_SUMs being offset here; these
  279.          rtl are used for nothing other than comparisons.  */
  280.       if (GET_CODE (x0) == CONST_INT)
  281.         return plus_constant_for_output (x1, INTVAL (x0));
  282.       else if (GET_CODE (x1) == CONST_INT)
  283.         return plus_constant_for_output (x0, INTVAL (x1));
  284.       return gen_rtx (PLUS, GET_MODE (x), x0, x1);
  285.     }
  286.     }
  287.   return x;
  288. }
  289.  
  290. void
  291. init_alias_analysis ()
  292. {
  293.   int maxreg = max_reg_num ();
  294.   rtx insn;
  295.   rtx note;
  296.   rtx set;
  297.  
  298.   reg_known_value_size = maxreg;
  299.  
  300.   reg_known_value
  301.     = (rtx *) oballoc ((maxreg-FIRST_PSEUDO_REGISTER) * sizeof (rtx))
  302.       - FIRST_PSEUDO_REGISTER;
  303.   bzero (reg_known_value+FIRST_PSEUDO_REGISTER,
  304.      (maxreg-FIRST_PSEUDO_REGISTER) * sizeof (rtx));
  305.  
  306.   /* Fill in the entries with known constant values.  */
  307.   for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
  308.     if ((set = single_set (insn)) != 0
  309.     && GET_CODE (SET_DEST (set)) == REG
  310.     && REGNO (SET_DEST (set)) >= FIRST_PSEUDO_REGISTER
  311.     && (((note = find_reg_note (insn, REG_EQUAL, 0)) != 0
  312.          && reg_n_sets[REGNO (SET_DEST (set))] == 1)
  313.         || (note = find_reg_note (insn, REG_EQUIV, 0)) != 0)
  314.     && GET_CODE (XEXP (note, 0)) != EXPR_LIST)
  315.       reg_known_value[REGNO (SET_DEST (set))] = XEXP (note, 0);
  316.  
  317.   /* Fill in the remaining entries.  */
  318.   while (--maxreg >= FIRST_PSEUDO_REGISTER)
  319.     if (reg_known_value[maxreg] == 0)
  320.       reg_known_value[maxreg] = regno_reg_rtx[maxreg];
  321. }
  322.  
  323. /* Return 1 if X and Y are identical-looking rtx's.
  324.  
  325.    We use the data in reg_known_value above to see if two registers with
  326.    different numbers are, in fact, equivalent.  */
  327.  
  328. static int
  329. rtx_equal_for_memref_p (x, y)
  330.      rtx x, y;
  331. {
  332.   register int i;
  333.   register int j;
  334.   register enum rtx_code code;
  335.   register char *fmt;
  336.  
  337.   if (x == 0 && y == 0)
  338.     return 1;
  339.   if (x == 0 || y == 0)
  340.     return 0;
  341.   x = canon_rtx (x);
  342.   y = canon_rtx (y);
  343.  
  344.   if (x == y)
  345.     return 1;
  346.  
  347.   code = GET_CODE (x);
  348.   /* Rtx's of different codes cannot be equal.  */
  349.   if (code != GET_CODE (y))
  350.     return 0;
  351.  
  352.   /* (MULT:SI x y) and (MULT:HI x y) are NOT equivalent.
  353.      (REG:SI x) and (REG:HI x) are NOT equivalent.  */
  354.  
  355.   if (GET_MODE (x) != GET_MODE (y))
  356.     return 0;
  357.  
  358.   /* REG, LABEL_REF, and SYMBOL_REF can be compared nonrecursively.  */
  359.  
  360.   if (code == REG)
  361.     return REGNO (x) == REGNO (y);
  362.   if (code == LABEL_REF)
  363.     return XEXP (x, 0) == XEXP (y, 0);
  364.   if (code == SYMBOL_REF)
  365.     return XSTR (x, 0) == XSTR (y, 0);
  366.  
  367.   /* Compare the elements.  If any pair of corresponding elements
  368.      fail to match, return 0 for the whole things.  */
  369.  
  370.   fmt = GET_RTX_FORMAT (code);
  371.   for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
  372.     {
  373.       switch (fmt[i])
  374.     {
  375.     case 'n':
  376.     case 'i':
  377.       if (XINT (x, i) != XINT (y, i))
  378.         return 0;
  379.       break;
  380.  
  381.     case 'V':
  382.     case 'E':
  383.       /* Two vectors must have the same length.  */
  384.       if (XVECLEN (x, i) != XVECLEN (y, i))
  385.         return 0;
  386.  
  387.       /* And the corresponding elements must match.  */
  388.       for (j = 0; j < XVECLEN (x, i); j++)
  389.         if (rtx_equal_for_memref_p (XVECEXP (x, i, j), XVECEXP (y, i, j)) == 0)
  390.           return 0;
  391.       break;
  392.  
  393.     case 'e':
  394.       if (rtx_equal_for_memref_p (XEXP (x, i), XEXP (y, i)) == 0)
  395.         return 0;
  396.       break;
  397.  
  398.     case 'S':
  399.     case 's':
  400.       if (strcmp (XSTR (x, i), XSTR (y, i)))
  401.         return 0;
  402.       break;
  403.  
  404.     case 'u':
  405.       /* These are just backpointers, so they don't matter.  */
  406.       break;
  407.  
  408.     case '0':
  409.       break;
  410.  
  411.       /* It is believed that rtx's at this level will never
  412.          contain anything but integers and other rtx's,
  413.          except for within LABEL_REFs and SYMBOL_REFs.  */
  414.     default:
  415.       abort ();
  416.     }
  417.     }
  418.   return 1;
  419. }
  420.  
  421. /* Given an rtx X, find a SYMBOL_REF or LABEL_REF within
  422.    X and return it, or return 0 if none found.  */
  423.  
  424. static rtx
  425. find_symbolic_term (x)
  426.      rtx x;
  427. {
  428.   register int i;
  429.   register enum rtx_code code;
  430.   register char *fmt;
  431.  
  432.   code = GET_CODE (x);
  433.   if (code == SYMBOL_REF || code == LABEL_REF)
  434.     return x;
  435.   if (GET_RTX_CLASS (code) == 'o')
  436.     return 0;
  437.  
  438.   fmt = GET_RTX_FORMAT (code);
  439.   for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
  440.     {
  441.       rtx t;
  442.  
  443.       if (fmt[i] == 'e')
  444.     {
  445.       t = find_symbolic_term (XEXP (x, i));
  446.       if (t != 0)
  447.         return t;
  448.     }
  449.       else if (fmt[i] == 'E')
  450.     break;
  451.     }
  452.   return 0;
  453. }
  454.  
  455. /* Return nonzero if X and Y (memory addresses) could reference the
  456.    same location in memory.  C is an offset accumulator.  When
  457.    C is nonzero, we are testing aliases between X and Y + C.
  458.    XSIZE is the size in bytes of the X reference,
  459.    similarly YSIZE is the size in bytes for Y.
  460.  
  461.    If XSIZE or YSIZE is zero, we do not know the amount of memory being
  462.    referenced (the reference was BLKmode), so make the most pessimistic
  463.    assumptions.
  464.  
  465.    We recognize the following cases of non-conflicting memory:
  466.  
  467.     (1) addresses involving the frame pointer cannot conflict
  468.         with addresses involving static variables.
  469.     (2) static variables with different addresses cannot conflict.
  470.  
  471.    Nice to notice that varying addresses cannot confict with fp if no
  472.    local variables had their addresses taken, but that's too hard now.  */
  473.  
  474. static int
  475. memrefs_conflict_p (xsize, x, ysize, y, c)
  476.      rtx x, y;
  477.      int xsize, ysize;
  478.      int c;
  479. {
  480.   if (GET_CODE (x) == HIGH)
  481.     x = XEXP (x, 0);
  482.   else if (GET_CODE (x) == LO_SUM)
  483.     x = XEXP (x, 1);
  484.   else
  485.     x = canon_rtx (x);
  486.   if (GET_CODE (y) == HIGH)
  487.     y = XEXP (y, 0);
  488.   else if (GET_CODE (y) == LO_SUM)
  489.     y = XEXP (y, 1);
  490.   else
  491.     y = canon_rtx (y);
  492.  
  493.   if (rtx_equal_for_memref_p (x, y))
  494.     return (xsize == 0 || ysize == 0 ||
  495.         (c >= 0 && xsize > c) || (c < 0 && ysize+c > 0));
  496.  
  497.   if (y == frame_pointer_rtx || y == stack_pointer_rtx)
  498.     {
  499.       rtx t = y;
  500.       y = x;
  501.       x = t;
  502.     }
  503.  
  504.   if (x == frame_pointer_rtx || x == stack_pointer_rtx)
  505.     {
  506.       rtx y1;
  507.  
  508.       if (CONSTANT_P (y))
  509.     return 0;
  510.  
  511.       if (GET_CODE (y) == PLUS
  512.       && canon_rtx (XEXP (y, 0)) == x
  513.       && (y1 = canon_rtx (XEXP (y, 1)))
  514.       && GET_CODE (y1) == CONST_INT)
  515.     {
  516.       c += INTVAL (y1);
  517.       return (xsize == 0 || ysize == 0
  518.           || (c >= 0 && xsize > c) || (c < 0 && ysize+c > 0));
  519.     }
  520.  
  521.       if (GET_CODE (y) == PLUS
  522.       && (y1 = canon_rtx (XEXP (y, 0)))
  523.       && CONSTANT_P (y1))
  524.     return 0;
  525.  
  526.       return 1;
  527.     }
  528.  
  529.   if (GET_CODE (x) == PLUS)
  530.     {
  531.       /* The fact that X is canonnicallized means that this
  532.      PLUS rtx is canonnicallized.  */
  533.       rtx x0 = XEXP (x, 0);
  534.       rtx x1 = XEXP (x, 1);
  535.  
  536.       if (GET_CODE (y) == PLUS)
  537.     {
  538.       /* The fact that Y is canonnicallized means that this
  539.          PLUS rtx is canonnicallized.  */
  540.       rtx y0 = XEXP (y, 0);
  541.       rtx y1 = XEXP (y, 1);
  542.  
  543.       if (rtx_equal_for_memref_p (x1, y1))
  544.         return memrefs_conflict_p (xsize, x0, ysize, y0, c);
  545.       if (rtx_equal_for_memref_p (x0, y0))
  546.         return memrefs_conflict_p (xsize, x1, ysize, y1, c);
  547.       if (GET_CODE (x1) == CONST_INT)
  548.         if (GET_CODE (y1) == CONST_INT)
  549.           return memrefs_conflict_p (xsize, x0, ysize, y0,
  550.                      c - INTVAL (x1) + INTVAL (y1));
  551.         else
  552.           return memrefs_conflict_p (xsize, x0, ysize, y, c - INTVAL (x1));
  553.       else if (GET_CODE (y1) == CONST_INT)
  554.         return memrefs_conflict_p (xsize, x, ysize, y0, c + INTVAL (y1));
  555.  
  556.       /* Handle case where we cannot understand iteration operators,
  557.          but we notice that the base addresses are distinct objects.  */
  558.       x = find_symbolic_term (x);
  559.       if (x == 0)
  560.         return 1;
  561.       y = find_symbolic_term (y);
  562.       if (y == 0)
  563.         return 1;
  564.       return rtx_equal_for_memref_p (x, y);
  565.     }
  566.       else if (GET_CODE (x1) == CONST_INT)
  567.     return memrefs_conflict_p (xsize, x0, ysize, y, c - INTVAL (x1));
  568.     }
  569.   else if (GET_CODE (y) == PLUS)
  570.     {
  571.       /* The fact that Y is canonnicallized means that this
  572.      PLUS rtx is canonnicallized.  */
  573.       rtx y0 = XEXP (y, 0);
  574.       rtx y1 = XEXP (y, 1);
  575.  
  576.       if (GET_CODE (y1) == CONST_INT)
  577.     return memrefs_conflict_p (xsize, x, ysize, y0, c + INTVAL (y1));
  578.       else
  579.     return 1;
  580.     }
  581.  
  582.   if (GET_CODE (x) == GET_CODE (y))
  583.     switch (GET_CODE (x))
  584.       {
  585.       case MULT:
  586.     {
  587.       /* Handle cases where we expect the second operands to be the
  588.          same, and check only whether the first operand would conflict
  589.          or not.  */
  590.       rtx x0, y0;
  591.       rtx x1 = canon_rtx (XEXP (x, 1));
  592.       rtx y1 = canon_rtx (XEXP (y, 1));
  593.       if (! rtx_equal_for_memref_p (x1, y1))
  594.         return 1;
  595.       x0 = canon_rtx (XEXP (x, 0));
  596.       y0 = canon_rtx (XEXP (y, 0));
  597.       if (rtx_equal_for_memref_p (x0, y0))
  598.         return (xsize == 0 || ysize == 0
  599.             || (c >= 0 && xsize > c) || (c < 0 && ysize+c > 0));
  600.  
  601.       /* Can't properly adjust our sizes.  */
  602.       if (GET_CODE (x1) != CONST_INT)
  603.         return 1;
  604.       xsize /= INTVAL (x1);
  605.       ysize /= INTVAL (x1);
  606.       c /= INTVAL (x1);
  607.       return memrefs_conflict_p (xsize, x0, ysize, y0, c);
  608.     }
  609.       }
  610.  
  611.   if (CONSTANT_P (x))
  612.     {
  613.       if (GET_CODE (x) == CONST_INT && GET_CODE (y) == CONST_INT)
  614.     {
  615.       c += (INTVAL (y) - INTVAL (x));
  616.       return (xsize == 0 || ysize == 0
  617.           || (c >= 0 && xsize > c) || (c < 0 && ysize+c > 0));
  618.     }
  619.  
  620.       if (GET_CODE (x) == CONST)
  621.     {
  622.       if (GET_CODE (y) == CONST)
  623.         return memrefs_conflict_p (xsize, canon_rtx (XEXP (x, 0)),
  624.                        ysize, canon_rtx (XEXP (y, 0)), c);
  625.       else
  626.         return memrefs_conflict_p (xsize, canon_rtx (XEXP (x, 0)),
  627.                        ysize, y, c);
  628.     }
  629.       if (GET_CODE (y) == CONST)
  630.     return memrefs_conflict_p (xsize, x, ysize,
  631.                    canon_rtx (XEXP (y, 0)), c);
  632.  
  633.       if (CONSTANT_P (y))
  634.     return (rtx_equal_for_memref_p (x, y)
  635.         && (xsize == 0 || ysize == 0
  636.             || (c >= 0 && xsize > c) || (c < 0 && ysize+c > 0)));
  637.  
  638.       return 1;
  639.     }
  640.   return 1;
  641. }
  642.  
  643. /* Functions to compute memory dependencies.  Each of these functions
  644.    take the following arguments:
  645.  
  646.    PAT is the pattern containing the prioritized memory reference.
  647.    X is the memory reference being tested.
  648.    INSN is the insn in which X appears.
  649.  
  650.    Since we process the insns in execution order, we can build tables
  651.    to keep track of what registers are fixed (and not aliased), what registers
  652.    are varying in known ways, and what registers are varying in unknown
  653.    ways.
  654.  
  655.    Nice to take care of redundant stores and unnecessary loads here.
  656.  
  657.    If both memory references are volatile, then there must always be a
  658.    dependence between the two references, since their order can not be
  659.    changed.  A volatile and non-volatile reference can be interchanged
  660.    though. 
  661.  
  662.    A MEM_IN_STRUCT reference at a varying address can never conflict with a
  663.    non-MEM_IN_STRUCT reference at a fixed address.  */
  664.  
  665. /* Read dependence: X is read after read in MEM takes place.  There can
  666.    only be a dependence here if both reads are volatile.  */
  667.  
  668. int
  669. read_dependence (mem, x)
  670.      rtx mem;
  671.      rtx x;
  672. {
  673.   return MEM_VOLATILE_P (x) && MEM_VOLATILE_P (mem);
  674. }
  675.  
  676. /* True dependence: X is read after store in MEM takes place.  */
  677.  
  678. int
  679. true_dependence (mem, x)
  680.      rtx mem;
  681.      rtx x;
  682. {
  683.   if (RTX_UNCHANGING_P (x))
  684.     return 0;
  685.  
  686.   return ((MEM_VOLATILE_P (x) && MEM_VOLATILE_P (mem))
  687.       || (memrefs_conflict_p (SIZE_FOR_MODE (mem), XEXP (mem, 0),
  688.                   SIZE_FOR_MODE (x), XEXP (x, 0), 0)
  689.           && ! (MEM_IN_STRUCT_P (mem) && rtx_addr_varies_p (mem)
  690.             && ! MEM_IN_STRUCT_P (x) && ! rtx_addr_varies_p (x))
  691.           && ! (MEM_IN_STRUCT_P (x) && rtx_addr_varies_p (x)
  692.             && ! MEM_IN_STRUCT_P (mem) && ! rtx_addr_varies_p (mem))));
  693. }
  694.  
  695. /* Anti dependence: X is written after read in MEM takes place.  */
  696.  
  697. int
  698. anti_dependence (mem, x)
  699.      rtx mem;
  700.      rtx x;
  701. {
  702.   if (RTX_UNCHANGING_P (mem))
  703.     return 0;
  704.  
  705.   return ((MEM_VOLATILE_P (x) && MEM_VOLATILE_P (mem))
  706.       || (memrefs_conflict_p (SIZE_FOR_MODE (mem), XEXP (mem, 0),
  707.                   SIZE_FOR_MODE (x), XEXP (x, 0), 0)
  708.           && ! (MEM_IN_STRUCT_P (mem) && rtx_addr_varies_p (mem)
  709.             && ! MEM_IN_STRUCT_P (x) && ! rtx_addr_varies_p (x))
  710.           && ! (MEM_IN_STRUCT_P (x) && rtx_addr_varies_p (x)
  711.             && ! MEM_IN_STRUCT_P (mem) && ! rtx_addr_varies_p (mem))));
  712. }
  713.  
  714. /* Output dependence: X is written after store in MEM takes place.  */
  715.  
  716. int
  717. output_dependence (mem, x)
  718.      rtx mem;
  719.      rtx x;
  720. {
  721.   return ((MEM_VOLATILE_P (x) && MEM_VOLATILE_P (mem))
  722.       || (memrefs_conflict_p (SIZE_FOR_MODE (mem), XEXP (mem, 0),
  723.                   SIZE_FOR_MODE (x), XEXP (x, 0), 0)
  724.           && ! (MEM_IN_STRUCT_P (mem) && rtx_addr_varies_p (mem)
  725.             && ! MEM_IN_STRUCT_P (x) && ! rtx_addr_varies_p (x))
  726.           && ! (MEM_IN_STRUCT_P (x) && rtx_addr_varies_p (x)
  727.             && ! MEM_IN_STRUCT_P (mem) && ! rtx_addr_varies_p (mem))));
  728. }
  729.  
  730. #ifndef INSN_SCHEDULING
  731. void schedule_insns () {}
  732. #else
  733. #ifndef __GNU__
  734. #define __inline
  735. #endif
  736.  
  737. /* Computation of memory dependencies.  */
  738.  
  739. /* The *_insns and *_mems are paired lists.  Each pending memory operations
  740.    will have a pointer to the MEM rtx on one list and a pointer to the
  741.    containing insn on the other list in the same place in the list.  */
  742.  
  743. /* We can't use add_dependence like the old code did, because a single insn
  744.    may have multiple memory accesses, and hence needs to be on the list
  745.    once for each memory access.  Add_dependence won't let you add an insn
  746.    to a list more than once.  */
  747.  
  748. /* An INSN_LIST containing all insns with pending read operations.  */
  749. static rtx pending_read_insns;
  750.  
  751. /* An EXPR_LIST containing all MEM rtx's which are pending reads.  */
  752. static rtx pending_read_mems;
  753.  
  754. /* An INSN_LIST containing all insns with pending write operations.  */
  755. static rtx pending_write_insns;
  756.  
  757. /* An EXPR_LIST containing all MEM rtx's which are pending writes.  */
  758. static rtx pending_write_mems;
  759.  
  760. /* Indicates the combined length of the two pending lists.  We must prevent
  761.    these lists from ever growing too large since dependencies produced is
  762.    at least O(N*N), and execution time is at least O(4*N*N), as a function
  763.    of the length of these pending lists.  */
  764.  
  765. static int pending_lists_length;
  766.  
  767. /* An INSN_LIST containing all INSN_LISTs allocated but currently unused.  */
  768.  
  769. static rtx unused_insn_list;
  770.  
  771. /* An EXPR_LIST containing all EXPR_LISTs allocated but currently unused.  */
  772.  
  773. static rtx unused_expr_list;
  774.  
  775. /* The last insn upon which all memory references must depend.
  776.    This is an insn which flushed the pending lists, creating a dependency
  777.    between it and all previously pending memory references.  This creates
  778.    a barrier (or a checkpoint) which no memory reference is allowed to cross.
  779.  
  780.    This includes all non constant CALL_INSNs.  When we do interprocedural
  781.    alias analysis, this restriction can be relaxed.
  782.    This may also be an INSN that writes memory if the pending lists grow
  783.    too large.  */
  784.  
  785. static rtx last_pending_memory_flush;
  786.  
  787. /* The last function call we have seen.  All hard regs, and, of course,
  788.    the last function call, must depend on this.  */
  789.  
  790. static rtx last_function_call;
  791.  
  792. /* The LOG_LINKS field of this is a list of insns which use a psuedo register
  793.    that does not already cross a call.  We create dependencies between each
  794.    of these and the next call insn, to ensure that that won't cross a call
  795.    after scheduling is done.  */
  796.  
  797. static rtx sched_before_next_call;
  798.  
  799. #if 0
  800. /* This is obsolete.  Since we can never split the user and the setter of cc0,
  801.    there is no need to keep any dependency info for cc0.  */
  802.  
  803. /* Build LOG_LINKS for condition codes.  This turns out to be needed
  804.    if one has pipelinable setcc insns.  */
  805. static rtx last_set_cc0;
  806. #endif
  807.  
  808. /* Process an insn's memory dependencies.  There are three kinds of
  809.    dependencies:
  810.  
  811.    (0) read dependence: read follows read
  812.    (1) true dependence: read follows write
  813.    (2) anti dependence: write follows read
  814.    (3) output dependence: write follows write
  815.  
  816.    We are careful to build only dependencies which actually exist, and
  817.    use trasitivity to avoid building too many links.  */
  818.  
  819. /* Return the INSN_LIST containing INSN in LIST, or NULL
  820.    if LIST does not contain INSN.  */
  821.  
  822. __inline static rtx
  823. find_insn_list (insn, list)
  824.      rtx insn;
  825.      rtx list;
  826. {
  827.   while (list)
  828.     {
  829.       if (XEXP (list, 0) == insn)
  830.     return list;
  831.       list = XEXP (list, 1);
  832.     }
  833.   return 0;
  834. }
  835.  
  836. /* Compute cost of executing INSN.  This is the number of virtual
  837.    cycles taken between instruction issue and instruction results.  */
  838.  
  839. __inline static int
  840. insn_cost (insn)
  841.      rtx insn;
  842. {
  843.   register int cost;
  844.  
  845.   recog_memoized (insn);
  846.   /* A USE insn, or something else we don't need to understand.  */
  847.   if (INSN_CODE (insn) < 0)
  848.     {
  849. #if 0
  850.       if (GET_CODE (PATTERN (insn)) == USE
  851.       || GET_CODE (PATTERN (insn)) == CLOBBER)
  852.     return 0;
  853.       warning ("insn not recognized");
  854.       debug_rtx (insn);
  855. #endif
  856.       cost = 1;
  857.     }
  858.   else
  859.     cost = result_ready_cost (insn);
  860.  
  861.   if (cost < 1)
  862.     cost = 1;
  863.  
  864.   return cost;
  865. }
  866.  
  867. /* Reassign a dependence INSN used to have on X to what X has now become.
  868.    PREV is the INSN_LIST in which X occurs.
  869.  
  870.    Return 0 if the dependence is now meaningless, or the
  871.    new dependence that is found.  This clears up dependencies that
  872.    the combiner might leave dangling on insns.  */
  873.  
  874. static rtx
  875. reassign_dependence (prev, x, insn)
  876.      rtx prev;
  877.      rtx x;
  878.      rtx insn;
  879. {
  880.   if (GET_MODE (prev) == VOIDmode)
  881.     {
  882.       /* This dependence used to be from a logical link.  */
  883.       if (INSN_DEP_TARGET (x) != 0
  884.       && INSN_DEP_TARGET (x) != insn)
  885.     {
  886.       if (find_insn_list (INSN_DEP_TARGET (x), LOG_LINKS (insn)))
  887.         {
  888.           remove_dependence (insn, XEXP (prev, 0));
  889.           return 0;
  890.         }
  891.       else
  892.         XEXP (prev, 0) = INSN_DEP_TARGET (x);
  893.     }
  894.       else
  895.     {
  896.       /* A LOG_LINK which points to a NOTE means that
  897.          this insn somehow contains the prev insn
  898.          pointed to, so we don't need to worry about
  899.          such a dependency.  We record that this
  900.          insn has taken over the one pointed to
  901.          by the LOG_LINK, so we don't have to perform
  902.          the search as in the case below.  */
  903.       INSN_DEP_TARGET (x) = insn;
  904.       return 0;
  905.     }
  906.     }
  907.   else
  908.     {
  909. #if 1
  910.       /* A LOG_DEP which points at a note is obsolete, a
  911.      consequence of computing LOG_LINKS before running
  912.      combine.  If we don't know which insn has taken
  913.      over the insn we depend upon, look between this
  914.      insn and our target insn for an insn which has
  915.      a dependency we understand.
  916.  
  917.      This can also be a consequence of reload deleting an insn and
  918.      adding others in its place.  We must recompute these
  919.      dependencies here.  */
  920.  
  921.       if (INSN_DEP_TARGET (x) == 0)
  922.     {
  923.       rtx y;
  924.  
  925.       /* First try to find a dependency as though
  926.          INSN were the USE of a SET.  */
  927.       for (y = NEXT_INSN (x); y != insn; y = NEXT_INSN (y))
  928.         {
  929.           if (GET_CODE (y) == NOTE)
  930.         continue;
  931.           if (GET_CODE (y) != INSN && GET_CODE (y) != CALL_INSN)
  932.         abort ();
  933.           if (find_insn_list (x, LOG_LINKS (y)))
  934.         {
  935.           INSN_DEP_TARGET (x) = y;
  936.           break;
  937.         }
  938.         }
  939.       /* Now try to find INSN as a SET of another's USE.  */
  940.       if (INSN_DEP_TARGET (x) == 0)
  941.         {
  942.           int i;
  943.           rtx pat = PATTERN (insn);
  944.           rtx destreg = 0;
  945.  
  946.           if (GET_CODE (pat) == PARALLEL)
  947.         {
  948.           for (i = 0; i < XVECLEN (pat, 0); i++)
  949.             {
  950.               if (GET_CODE (XVECEXP (pat, 0, i)) == SET
  951.               && GET_CODE (SET_DEST (XVECEXP (pat, 0, i))) == REG)
  952.             {
  953.               if (destreg)
  954.                 abort ();
  955.               destreg = SET_DEST (XVECEXP (pat, 0, i));
  956.             }
  957.             }
  958.           if (destreg == 0)
  959.             abort ();
  960.         }
  961.           else if (GET_CODE (pat) != SET
  962.                || GET_CODE (SET_DEST (pat)) != REG)
  963.         /* Right now, the cases that hit this abort
  964.            could be legitmately ignored--the dependence
  965.            not longer exists.  But I want to make
  966.            sure I see more cases before removing the
  967.            dependence.  */
  968.         abort ();
  969.           else
  970.         destreg = SET_DEST (pat);
  971.  
  972.           for (y = NEXT_INSN (x); y != insn; y = NEXT_INSN (y))
  973.         {
  974.           if (GET_CODE (y) == NOTE)
  975.             continue;
  976.           if (reg_mentioned_p (destreg, PATTERN (y)))
  977.             {
  978.               INSN_DEP_TARGET (x) = y;
  979.               break;
  980.             }
  981.         }
  982.         }
  983.       if (INSN_DEP_TARGET (x) == 0)
  984.         {
  985.           /* If not found as either, then it should
  986.          be the case that INSN no longer has the
  987.          dependency it thought it had.  Remove that
  988.          dependency.  */
  989.           remove_dependence (insn, x);
  990.           return 0;
  991.         }
  992.     }
  993.       if (INSN_DEP_TARGET (x) == insn)
  994.     {
  995.       /* Don't introduce a circularity if this
  996.          dependence leads us to ourselves.  */
  997.       if (prev == LOG_LINKS (insn))
  998.         LOG_LINKS (insn) = XEXP (prev, 1);
  999.       else
  1000.         {
  1001.           rtx t = LOG_LINKS (insn);
  1002.           while (XEXP (t, 1) != prev)
  1003.         t = XEXP (t, 1);
  1004.           XEXP (t, 1) = XEXP (prev, 1);
  1005.         }
  1006.       return 0;
  1007.     }
  1008.       if (find_insn_list (INSN_DEP_TARGET (x), LOG_LINKS (insn)))
  1009.     {
  1010.       remove_dependence (insn, XEXP (prev, 0));
  1011.       return 0;
  1012.     }
  1013.       else
  1014.     XEXP (prev, 0) = INSN_DEP_TARGET (x);
  1015. #else
  1016.       /* Should not happen anymore.  */
  1017.       abort ();
  1018. #endif
  1019.     }
  1020.   return INSN_DEP_TARGET (x);
  1021. }
  1022.  
  1023. /* Compute the priority number for INSN.
  1024.  
  1025.    Priority returned is cost of INSN, plus max of priorities
  1026.    of instructions in INSN's LOG_LINKS.
  1027.  
  1028.    Since condition codes don't have logical links, we must
  1029.    treat these cases specially.  */
  1030.  
  1031. static int
  1032. priority (insn)
  1033.      rtx insn;
  1034. {
  1035.   if (insn && GET_RTX_CLASS (GET_CODE (insn)) == 'i')
  1036.     {
  1037.       int prev_priority;
  1038.       int max_priority = 0;
  1039.       int this_cost = insn_cost (insn);
  1040.       int this_priority = INSN_PRIORITY (insn);
  1041.       rtx prev;
  1042.  
  1043.       if (this_priority > 0)
  1044.     return this_priority;
  1045.  
  1046.       /* Nonzero if these insns constitute a function call.  */
  1047.       if (RTX_UNCHANGING_P (insn))
  1048.     {
  1049.       prev = insn;
  1050.       while (RTX_UNCHANGING_P (prev))
  1051.         {
  1052.           while (GET_CODE (prev) == NOTE)
  1053.         {
  1054.           /* There should never be NOTEs here.  */
  1055. #if 0
  1056.           prev = PREV_INSN (prev);
  1057. #else
  1058.           abort ();
  1059. #endif
  1060.         }
  1061.           prev = PREV_INSN (prev);
  1062.           INSN_REF_COUNT (prev) += 1;
  1063.         }
  1064.     }
  1065.  
  1066.       for (prev = LOG_LINKS (insn); prev; prev = XEXP (prev, 1))
  1067.     {
  1068.       rtx x = XEXP (prev, 0);
  1069.       if (GET_CODE (x) == NOTE && GET_MODE (prev) == VOIDmode)
  1070.         {
  1071.           x = reassign_dependence (prev, x, insn);
  1072.           if (x == 0)
  1073.         continue;
  1074.         }
  1075.       prev_priority = priority (x);
  1076.       if (prev_priority > max_priority)
  1077.         max_priority = prev_priority;
  1078.       INSN_REF_COUNT (x) += 1;
  1079.     }
  1080.  
  1081.       INSN_PRIORITY (insn) = this_cost + max_priority;
  1082.       return INSN_PRIORITY (insn);
  1083.     }
  1084.   return 0;
  1085. }
  1086.  
  1087. /* Remove all INSN_LISTs and EXPR_LISTs from the pending lists and add
  1088.    them to the unused_*_list variables, so that they can be reused.  */
  1089.  
  1090. static void
  1091. free_pending_lists ()
  1092. {
  1093.   register rtx link, prev_link;
  1094.  
  1095.   if (pending_read_insns)
  1096.     {
  1097.       prev_link = pending_read_insns;
  1098.       link = XEXP (prev_link, 1);
  1099.  
  1100.       while (link)
  1101.     {
  1102.       prev_link = link;
  1103.       link = XEXP (link, 1);
  1104.     }
  1105.  
  1106.       XEXP (prev_link, 1) = unused_insn_list;
  1107.       unused_insn_list = pending_read_insns;
  1108.       pending_read_insns = 0;
  1109.     }
  1110.  
  1111.   if (pending_write_insns)
  1112.     {
  1113.       prev_link = pending_write_insns;
  1114.       link = XEXP (prev_link, 1);
  1115.  
  1116.       while (link)
  1117.     {
  1118.       prev_link = link;
  1119.       link = XEXP (link, 1);
  1120.     }
  1121.  
  1122.       XEXP (prev_link, 1) = unused_insn_list;
  1123.       unused_insn_list = pending_write_insns;
  1124.       pending_write_insns = 0;
  1125.     }
  1126.  
  1127.   if (pending_read_mems)
  1128.     {
  1129.       prev_link = pending_read_mems;
  1130.       link = XEXP (prev_link, 1);
  1131.  
  1132.       while (link)
  1133.     {
  1134.       prev_link = link;
  1135.       link = XEXP (link, 1);
  1136.     }
  1137.  
  1138.       XEXP (prev_link, 1) = unused_expr_list;
  1139.       unused_expr_list = pending_read_mems;
  1140.       pending_read_mems = 0;
  1141.     }
  1142.  
  1143.   if (pending_write_mems)
  1144.     {
  1145.       prev_link = pending_write_mems;
  1146.       link = XEXP (prev_link, 1);
  1147.  
  1148.       while (link)
  1149.     {
  1150.       prev_link = link;
  1151.       link = XEXP (link, 1);
  1152.     }
  1153.  
  1154.       XEXP (prev_link, 1) = unused_expr_list;
  1155.       unused_expr_list = pending_write_mems;
  1156.       pending_write_mems = 0;
  1157.     }
  1158. }
  1159.  
  1160. /* Add an INSN and MEM reference pair to a pending INSN_LIST and MEM_LIST.
  1161.    The MEM is a memory reference contained within INSN, which we are saving
  1162.    so that we can do memory aliasing on it.  */
  1163.  
  1164. static void
  1165. add_insn_mem_dependence (insn_list, mem_list, insn, mem)
  1166.      rtx *insn_list, *mem_list, insn, mem;
  1167. {
  1168.   register rtx link;
  1169.  
  1170.   if (unused_insn_list)
  1171.     {
  1172.       link = unused_insn_list;
  1173.       unused_insn_list = XEXP (link, 1);
  1174.     }
  1175.   else
  1176.     link = rtx_alloc (INSN_LIST);
  1177.   XEXP (link, 0) = insn;
  1178.   XEXP (link, 1) = *insn_list;
  1179.   *insn_list = link;
  1180.  
  1181.   if (unused_expr_list)
  1182.     {
  1183.       link = unused_expr_list;
  1184.       unused_expr_list = XEXP (link, 1);
  1185.     }
  1186.   else
  1187.     link = rtx_alloc (EXPR_LIST);
  1188.   XEXP (link, 0) = mem;
  1189.   XEXP (link, 1) = *mem_list;
  1190.   *mem_list = link;
  1191.  
  1192.   pending_lists_length++;
  1193. }
  1194.  
  1195. static void sched_analyze_1 (), sched_analyze_2 ();
  1196.  
  1197. /* Analyze a single SET rtx, X.  This routine focuses on the
  1198.    destination of the set.  */
  1199. static void
  1200. sched_analyze_1 (x, insn)
  1201.      rtx x;
  1202.      rtx insn;
  1203. {
  1204.   register int regno;
  1205.   register rtx dest = SET_DEST (x);
  1206.  
  1207.   if (dest == 0)
  1208.     return;
  1209.  
  1210.   while (GET_CODE (dest) == STRICT_LOW_PART || GET_CODE (dest) == SUBREG
  1211.      || GET_CODE (dest) == ZERO_EXTRACT || GET_CODE (dest) == SIGN_EXTRACT)
  1212.     dest = SUBREG_REG (dest);
  1213.  
  1214.   if (GET_CODE (dest) == REG)
  1215.     {
  1216.       register int offset, bit, i;
  1217.  
  1218.       regno = REGNO (dest);
  1219.       if (reload_completed == 0)
  1220.     {
  1221.       register int offset = regno / REGSET_ELT_BITS;
  1222.       register int bit = 1 << (regno % REGSET_ELT_BITS);
  1223.  
  1224.       /* If entire register being set, mark it as as dead before this insn.  */
  1225.       bb_reg_sets[offset] |= bit;
  1226.       i = HARD_REGNO_NREGS (regno, GET_MODE (dest));
  1227.       while (--i >= 0)
  1228.         bb_reg_sets[(regno + i) / REGSET_ELT_BITS]
  1229.           |= 1 << ((regno + i) % REGSET_ELT_BITS);
  1230.     }
  1231.  
  1232.       /* A hard reg in a wide mode may really be multiple registers.
  1233.      If so, mark all of them just like the first.  */
  1234.       if (regno < FIRST_PSEUDO_REGISTER)
  1235.     {
  1236.       i = HARD_REGNO_NREGS (regno, GET_MODE (dest));
  1237.       while (--i >= 0)
  1238.         {
  1239.           rtx u;
  1240.  
  1241.           for (u = reg_last_uses[regno+i]; u; u = XEXP (u, 1))
  1242.         add_dependence (insn, XEXP (u, 0));
  1243.           reg_last_uses[regno + i] = 0;
  1244.           if (reg_last_sets[regno + i])
  1245.         add_dependence (insn, reg_last_sets[regno + i]);
  1246.           reg_last_sets[regno + i] = insn;
  1247.           if ((call_used_regs[i] || global_regs[i])
  1248.           && last_function_call)
  1249.         /* Function calls clobber all call_used regs.  */
  1250.         add_dependence (insn, last_function_call);
  1251.         }
  1252.     }
  1253.       else
  1254.     {
  1255.       rtx u;
  1256.  
  1257.       for (u = reg_last_uses[regno]; u; u = XEXP (u, 1))
  1258.         add_dependence (insn, XEXP (u, 0));
  1259.       reg_last_uses[regno] = 0;
  1260.       if (reg_last_sets[regno])
  1261.         add_dependence (insn, reg_last_sets[regno]);
  1262.       reg_last_sets[regno] = insn;
  1263.  
  1264.       /* Don't let it cross a call after scheduling if it doesn't
  1265.          already cross one.  */
  1266.       if (reg_n_calls_crossed[regno] == 0 && last_function_call)
  1267.         add_dependence (insn, last_function_call);
  1268.     }
  1269.     }
  1270.   else if (GET_CODE (dest) == MEM)
  1271.     {
  1272.       /* Writing memory.  */
  1273.  
  1274.       if (pending_lists_length > 32)
  1275.     {
  1276.       rtx link;
  1277.  
  1278.       /* Flush all pending reads and writes to prevent the pending lists
  1279.          from getting any larger.  Insn scheduling runs too slowly when
  1280.          these lists get long.  The number 32 was chosen because it
  1281.          seems like a resonable number.  When compiling GCC with itself,
  1282.          this flush occurs 8 times for sparc, and 10 times for m88k using
  1283.          the number 32.  */
  1284.       while (pending_read_insns)
  1285.         {
  1286.           add_dependence (insn, XEXP (pending_read_insns, 0));
  1287.  
  1288.           link = pending_read_insns;
  1289.           pending_read_insns = XEXP (pending_read_insns, 1);
  1290.           XEXP (link, 1) = unused_insn_list;
  1291.           unused_insn_list = link;
  1292.  
  1293.           link = pending_read_mems;
  1294.           pending_read_mems = XEXP (pending_read_mems, 1);
  1295.           XEXP (link, 1) = unused_expr_list;
  1296.           unused_expr_list = link;
  1297.         }
  1298.       while (pending_write_insns)
  1299.         {
  1300.           add_dependence (insn, XEXP (pending_write_insns, 0));
  1301.  
  1302.           link = pending_write_insns;
  1303.           pending_write_insns = XEXP (pending_write_insns, 1);
  1304.           XEXP (link, 1) = unused_insn_list;
  1305.           unused_insn_list = link;
  1306.  
  1307.           link = pending_write_mems;
  1308.           pending_write_mems = XEXP (pending_write_mems, 1);
  1309.           XEXP (link, 1) = unused_expr_list;
  1310.           unused_expr_list = link;
  1311.         }
  1312.       pending_lists_length = 0;
  1313.  
  1314.       if (last_pending_memory_flush)
  1315.         add_dependence (insn, last_pending_memory_flush);
  1316.  
  1317.       last_pending_memory_flush = insn;
  1318.     }
  1319.       else
  1320.     {
  1321.       rtx pending, pending_mem;
  1322.  
  1323.       pending = pending_read_insns;
  1324.       pending_mem = pending_read_mems;
  1325.       while (pending)
  1326.         {
  1327.           /* If a dependency already exists, don't create a new one.  */
  1328.           if (! find_insn_list (XEXP (pending, 0), LOG_LINKS (insn)))
  1329.         if (anti_dependence (XEXP (pending_mem, 0), dest, insn))
  1330.           add_dependence (insn, XEXP (pending, 0));
  1331.  
  1332.           pending = XEXP (pending, 1);
  1333.           pending_mem = XEXP (pending_mem, 1);
  1334.         }
  1335.  
  1336.       pending = pending_write_insns;
  1337.       pending_mem = pending_write_mems;
  1338.       while (pending)
  1339.         {
  1340.           /* If a dependency already exists, don't create a new one.  */
  1341.           if (! find_insn_list (XEXP (pending, 0), LOG_LINKS (insn)))
  1342.         if (output_dependence (XEXP (pending_mem, 0), dest))
  1343.           add_dependence (insn, XEXP (pending, 0));
  1344.  
  1345.           pending = XEXP (pending, 1);
  1346.           pending_mem = XEXP (pending_mem, 1);
  1347.         }
  1348.  
  1349.       if (last_pending_memory_flush)
  1350.         add_dependence (insn, last_pending_memory_flush);
  1351.  
  1352.       add_insn_mem_dependence (&pending_write_insns, &pending_write_mems,
  1353.                    insn, dest);
  1354.     }
  1355.       sched_analyze_2 (XEXP (dest, 0), insn);
  1356.     }
  1357. #if 0
  1358.   /* Obsolete.  */
  1359. #ifdef HAVE_cc0
  1360. else if (GET_CODE (dest) == CC0)
  1361.   {
  1362.     if (last_set_cc0)
  1363.       {
  1364.     rtx next = NEXT_INSN (last_set_cc0);
  1365.     if (GET_CODE (next) == NOTE)
  1366.       /* Jump optimization removed the branch, but not the test.
  1367.          Keep things in order here, and a later pass (hopefully before
  1368.          register allocation is complete) will take care of things.  */
  1369.       {
  1370.         /* I don't understand what this is doing.  There should never
  1371.            be notes here since sched removes them all at the start.  */
  1372.         abort ();
  1373.         next = last_set_cc0;
  1374.       }
  1375.     else
  1376.       add_dependence (insn, last_set_cc0);
  1377.     add_dependence (insn, next);
  1378.       }
  1379.     if (last_function_call)
  1380.       add_dependence (insn, last_function_call);
  1381.     last_set_cc0 = insn;
  1382.   }
  1383. #endif
  1384. #endif
  1385.  
  1386.   /* Analyze reads.  */
  1387.   if (GET_CODE (x) == SET)
  1388.     sched_analyze_2 (SET_SRC (x), insn);
  1389.   else if (GET_CODE (x) != CLOBBER)
  1390.     sched_analyze_2 (dest, insn);
  1391. }
  1392.  
  1393. /* Analyze the uses of memory and registers in INSN.  */
  1394. static void
  1395. sched_analyze_2 (x, insn)
  1396.      rtx x;
  1397.      rtx insn;
  1398. {
  1399.   register int i;
  1400.   register int j;
  1401.   register enum rtx_code code;
  1402.   register char *fmt;
  1403.  
  1404.   if (x == 0)
  1405.     return;
  1406.  
  1407.   code = GET_CODE (x);
  1408.  
  1409.   /* Get rid of the easy cases first.  */
  1410. #ifdef HAVE_cc0
  1411.   if (code == CC0)
  1412.     {
  1413.       rtx link;
  1414.  
  1415.       /* User of CC0 depends on immediately preceding insn.
  1416.      All notes are removed from the list of insns to schedule before we
  1417.      reach here, so the previous insn must be the setter of cc0.  */
  1418.       if (GET_CODE (PREV_INSN (insn)) != INSN)
  1419.     abort ();
  1420.       RTX_UNCHANGING_P (insn) = 1;
  1421.  
  1422.       /* Make a copy of all dependencies on PREV_INSN, and add to this insn.
  1423.      This is so that the all dependencies will apply to the group.  */
  1424.  
  1425.       for (link = LOG_LINKS (PREV_INSN (insn)); link; link = XEXP (link, 1))
  1426.     add_dependence (insn, XEXP (link, 0));
  1427.  
  1428.       return;
  1429.     }
  1430. #endif
  1431.  
  1432.   /* Ignore constants.  Note that we must handle CONST_DOUBLE here
  1433.      because it may have a cc0_rtx in its CONST_DOUBLE_CHAIN field, but
  1434.      this does not mean that this insn is using cc0.  */
  1435.   if (code == CONST_INT || code == CONST_DOUBLE || code == SYMBOL_REF
  1436.       || code == CONST || code == LABEL_REF)
  1437.     return;
  1438.  
  1439.   if (code == REG)
  1440.     {
  1441.       int regno = REGNO (x);
  1442.       if (regno < FIRST_PSEUDO_REGISTER)
  1443.     {
  1444.       int i;
  1445.  
  1446.       i = HARD_REGNO_NREGS (regno, GET_MODE (x));
  1447.       while (--i >= 0)
  1448.         {
  1449.           reg_last_uses[regno + i]
  1450.         = gen_rtx (INSN_LIST, VOIDmode,
  1451.                insn, reg_last_uses[regno + i]);
  1452.           if (reg_last_sets[regno + i])
  1453.         add_dependence (insn, reg_last_sets[regno + i]);
  1454.           if ((call_used_regs[regno + i] || global_regs[regno + i])
  1455.           && last_function_call)
  1456.         /* Function calls clobber all call_used regs.  */
  1457.         add_dependence (insn, last_function_call);
  1458.         }
  1459.     }
  1460.       else
  1461.     {
  1462.       reg_last_uses[regno]
  1463.         = gen_rtx (INSN_LIST, VOIDmode, insn, reg_last_uses[regno]);
  1464.       if (reg_last_sets[regno])
  1465.         add_dependence (insn, reg_last_sets[regno]);
  1466.  
  1467.       /* If the register does not already cross any calls, then add this
  1468.          insn to the sched_before_next_call list so that it will still
  1469.          not cross calls after scheduling.  */
  1470.       if (reg_n_calls_crossed[regno] == 0)
  1471.         add_dependence (sched_before_next_call, insn);
  1472.     }
  1473.       return;
  1474.     }
  1475.  
  1476.   /* The interesting case.  */
  1477.   if (code == MEM)
  1478.     {
  1479.       /* Reading memory.  */
  1480.  
  1481.       /* Don't create a dependence for memory references which are known to
  1482.      be unchanging, such as constant pool accesses.  These will never
  1483.      conflict with any other memory access.  */
  1484.       if (RTX_UNCHANGING_P (x) == 0)
  1485.     {
  1486.       rtx pending, pending_mem;
  1487.  
  1488.       pending = pending_read_insns;
  1489.       pending_mem = pending_read_mems;
  1490.       while (pending)
  1491.         {
  1492.           /* If a dependency already exists, don't create a new one.  */
  1493.           if (! find_insn_list (XEXP (pending, 0), LOG_LINKS (insn)))
  1494.         if (read_dependence (XEXP (pending_mem, 0), x))
  1495.           add_dependence (insn, XEXP (pending, 0));
  1496.  
  1497.           pending = XEXP (pending, 1);
  1498.           pending_mem = XEXP (pending_mem, 1);
  1499.         }
  1500.  
  1501.       pending = pending_write_insns;
  1502.       pending_mem = pending_write_mems;
  1503.       while (pending)
  1504.         {
  1505.           /* If a dependency already exists, don't create a new one.  */
  1506.           if (! find_insn_list (XEXP (pending, 0), LOG_LINKS (insn)))
  1507.         if (true_dependence (XEXP (pending_mem, 0), x))
  1508.           add_dependence (insn, XEXP (pending, 0));
  1509.  
  1510.           pending = XEXP (pending, 1);
  1511.           pending_mem = XEXP (pending_mem, 1);
  1512.         }
  1513.       if (last_pending_memory_flush)
  1514.         add_dependence (insn, last_pending_memory_flush);
  1515.  
  1516.       /* Always add these dependencies to pending_reads, since
  1517.          this insn may be followed by a write.  */
  1518.       add_insn_mem_dependence (&pending_read_insns, &pending_read_mems,
  1519.                    insn, x);
  1520.     }
  1521.       /* Take advantage of tail recursion here.  */
  1522.       sched_analyze_2 (XEXP (x, 0), insn);
  1523.       return;
  1524.     }
  1525.  
  1526.   else if (code == ASM_OPERANDS || code == ASM_INPUT)
  1527.     {
  1528.       rtx u, link;
  1529.  
  1530.       /* Traditional and volatible asm instructions must be considered to use
  1531.      and clobber all hard registers and all of memory.  */
  1532.       if ((code == ASM_OPERANDS && MEM_VOLATILE_P (x)) || code == ASM_INPUT)
  1533.     {
  1534.       for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
  1535.         {
  1536.           for (u = reg_last_uses[i]; u; u = XEXP (u, 1))
  1537.         if (GET_CODE (PATTERN (XEXP (u, 0))) != USE)
  1538.           add_dependence (insn, XEXP (u, 0));
  1539.           reg_last_uses[i] = 0;
  1540.           if (reg_last_sets[i]
  1541.           && GET_CODE (PATTERN (reg_last_sets[i])) != USE)
  1542.         add_dependence (insn, reg_last_sets[i]);
  1543.           reg_last_sets[i] = insn;
  1544.         }
  1545.  
  1546.       while (pending_read_insns)
  1547.         {
  1548.           add_dependence (insn, XEXP (pending_read_insns, 0));
  1549.  
  1550.           link = pending_read_insns;
  1551.           pending_read_insns = XEXP (pending_read_insns, 1);
  1552.           XEXP (link, 1) = unused_insn_list;
  1553.           unused_insn_list = link;
  1554.  
  1555.           link = pending_read_mems;
  1556.           pending_read_mems = XEXP (pending_read_mems, 1);
  1557.           XEXP (link, 1) = unused_expr_list;
  1558.           unused_expr_list = link;
  1559.         }
  1560.       while (pending_write_insns)
  1561.         {
  1562.           add_dependence (insn, XEXP (pending_write_insns, 0));
  1563.  
  1564.           link = pending_write_insns;
  1565.           pending_write_insns = XEXP (pending_write_insns, 1);
  1566.           XEXP (link, 1) = unused_insn_list;
  1567.           unused_insn_list = link;
  1568.  
  1569.           link = pending_write_mems;
  1570.           pending_write_mems = XEXP (pending_write_mems, 1);
  1571.           XEXP (link, 1) = unused_expr_list;
  1572.           unused_expr_list = link;
  1573.         }
  1574.       pending_lists_length = 0;
  1575.  
  1576.       if (last_pending_memory_flush)
  1577.         add_dependence (insn, last_pending_memory_flush);
  1578.  
  1579.       last_pending_memory_flush = insn;
  1580.     }
  1581.  
  1582.       /* For all ASM_OPERANDS, we must traverse the vector of input operands.
  1583.      We can not just fall through here since then we would be confused
  1584.      by the ASM_INPUT rtx inside ASM_OPERANDS, which do not indicate
  1585.      traditional asms unlike their normal usage.  */
  1586.  
  1587.       if (code == ASM_OPERANDS)
  1588.     {
  1589.       for (j = 0; j < ASM_OPERANDS_INPUT_LENGTH (x); j++)
  1590.         sched_analyze_2 (ASM_OPERANDS_INPUT (x, j), insn);
  1591.     }
  1592.  
  1593.       return;
  1594.     }
  1595.  
  1596.   /* Other cases: walk the insn.  */
  1597.   fmt = GET_RTX_FORMAT (code);
  1598.   for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
  1599.     {
  1600.       if (fmt[i] == 'e')
  1601.     sched_analyze_2 (XEXP (x, i), insn);
  1602.       else if (fmt[i] == 'E')
  1603.     for (j = 0; j < XVECLEN (x, i); j++)
  1604.       sched_analyze_2 (XVECEXP (x, i, j), insn);
  1605.     }
  1606. }
  1607.  
  1608. static void
  1609. sched_analyze_insn (x, insn)
  1610.      rtx x, insn;
  1611. {
  1612.   register RTX_CODE code = GET_CODE (x);
  1613.   rtx link;
  1614.  
  1615.   if (code == SET || code == CLOBBER)
  1616.     sched_analyze_1 (x, insn);
  1617.   else if (code == PARALLEL)
  1618.     {
  1619.       register int i;
  1620.       for (i = XVECLEN (x, 0) - 1; i >= 0; i--)
  1621.     {
  1622.       code = GET_CODE (XVECEXP (x, 0, i));
  1623.       if (code == SET || code == CLOBBER)
  1624.         sched_analyze_1 (XVECEXP (x, 0, i), insn);
  1625.       else
  1626.         sched_analyze_2 (XVECEXP (x, 0, i), insn);
  1627.     }
  1628.     }
  1629.   else
  1630.     sched_analyze_2 (x, insn);
  1631.  
  1632.   for (link = REG_NOTES (insn); link; link = XEXP (link, 1))
  1633.     {
  1634.       /* Any REG_INC note is a SET of the register indicated.  */
  1635.       if (REG_NOTE_KIND (link) == REG_INC)
  1636.     {
  1637.       rtx dest = XEXP (link, 0);
  1638.       int regno = REGNO (dest);
  1639.       int i;
  1640.  
  1641.       /* A hard reg in a wide mode may really be multiple registers.
  1642.          If so, mark all of them just like the first.  */
  1643.       if (regno < FIRST_PSEUDO_REGISTER)
  1644.         {
  1645.           i = HARD_REGNO_NREGS (regno, GET_MODE (dest));
  1646.           while (--i >= 0)
  1647.         {
  1648.           rtx u;
  1649.           
  1650.           for (u = reg_last_uses[regno+i]; u; u = XEXP (u, 1))
  1651.             add_dependence (insn, XEXP (u, 0));
  1652.           reg_last_uses[regno + i] = 0;
  1653.           if (reg_last_sets[regno + i])
  1654.             add_dependence (insn, reg_last_sets[regno + i]);
  1655.           reg_last_sets[regno + i] = insn;
  1656.           if ((call_used_regs[i] || global_regs[i])
  1657.               && last_function_call)
  1658.             /* Function calls clobber all call_used regs.  */
  1659.             add_dependence (insn, last_function_call);
  1660.         }
  1661.         }
  1662.       else
  1663.         {
  1664.           rtx u;
  1665.           
  1666.           for (u = reg_last_uses[regno]; u; u = XEXP (u, 1))
  1667.         add_dependence (insn, XEXP (u, 0));
  1668.           reg_last_uses[regno] = 0;
  1669.           if (reg_last_sets[regno])
  1670.         add_dependence (insn, reg_last_sets[regno]);
  1671.           reg_last_sets[regno] = insn;
  1672.  
  1673.           /* Don't let it cross a call after scheduling if it doesn't
  1674.          already cross one.  */
  1675.           if (reg_n_calls_crossed[regno] == 0 && last_function_call)
  1676.         add_dependence (insn, last_function_call);
  1677.         }
  1678.     }
  1679.     }
  1680.  
  1681.   /* Handle normal function calls...  */
  1682.   if (GET_CODE (insn) == CALL_INSN
  1683.       /* ... and tail calls.  */
  1684.       || (GET_CODE (insn) == JUMP_INSN
  1685.       && GET_CODE (PATTERN (insn)) == SET
  1686.       && GET_CODE (SET_SRC (PATTERN (insn))) == MEM))
  1687.     {
  1688.       rtx dep_insn;
  1689.       rtx prev_dep_insn;
  1690.  
  1691.       /* When scheduling instructions, we make sure calls don't lose their
  1692.      accompanying USE insns by depending them one on another in order.   */
  1693.  
  1694.       prev_dep_insn = insn;
  1695.       dep_insn = PREV_INSN (insn);
  1696.       while (GET_CODE (dep_insn) == INSN
  1697.          && GET_CODE (PATTERN (dep_insn)) == USE)
  1698.     {
  1699.       RTX_UNCHANGING_P (prev_dep_insn) = 1;
  1700.  
  1701.       /* Make a copy of all dependencies on dep_insn, and add to insn.
  1702.          This is so that the all dependencies will apply to the group.  */
  1703.  
  1704.       for (link = LOG_LINKS (dep_insn); link; link = XEXP (link, 1))
  1705.         add_dependence (insn, XEXP (link, 0));
  1706.  
  1707.       prev_dep_insn = dep_insn;
  1708.       dep_insn = PREV_INSN (dep_insn);
  1709.     }
  1710.     }
  1711. }
  1712.  
  1713. static int
  1714. sched_analyze (head, tail)
  1715.      rtx head, tail;
  1716. {
  1717.   register rtx insn;
  1718.   register int n_insns = 0;
  1719.   register rtx u;
  1720.  
  1721.   for (insn = head; ; insn = NEXT_INSN (insn))
  1722.     {
  1723.       if (GET_CODE (insn) == INSN || GET_CODE (insn) == JUMP_INSN)
  1724.     {
  1725.       sched_analyze_insn (PATTERN (insn), insn);
  1726.       n_insns += 1;
  1727.     }
  1728.       else if (GET_CODE (insn) == CALL_INSN)
  1729.     {
  1730.       rtx dest = 0;
  1731.       rtx x;
  1732.       register int i;
  1733.  
  1734.       if (reload_completed == 0)
  1735.         {
  1736.           for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
  1737.         if (call_used_regs[i] || global_regs[i])
  1738.           {
  1739.             register int offset = i / REGSET_ELT_BITS;
  1740.             register int bit = 1 << (i % REGSET_ELT_BITS);
  1741.             bb_reg_sets[offset] |= bit;
  1742.           }
  1743.         }
  1744.  
  1745.       /* Any instruction using a hard register which may get clobbered
  1746.          by a call needs to be marked as dependent on this call.
  1747.          This prevents a use of a hard return reg from being moved
  1748.          past a void call (i.e. it does not explicitly set the hard
  1749.          return reg).  */
  1750.  
  1751.       for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
  1752.         if (call_used_regs[i] || global_regs[i])
  1753.           {
  1754.         for (u = reg_last_uses[i]; u; u = XEXP (u, 1))
  1755.           if (GET_CODE (PATTERN (XEXP (u, 0))) != USE)
  1756.             add_dependence (insn, XEXP (u, 0));
  1757.         reg_last_uses[i] = 0;
  1758.         if (reg_last_sets[i]
  1759.             && GET_CODE (PATTERN (reg_last_sets[i])) != USE)
  1760.           add_dependence (insn, reg_last_sets[i]);
  1761.         reg_last_sets[i] = insn;
  1762.         /* Insn, being a CALL_INSN, magically depends on
  1763.            `last_function_call' already.  */
  1764.           }
  1765.  
  1766.       /* For each insn which shouldn't cross a call, add a dependence
  1767.          between that insn and this call insn.  */
  1768.       x = LOG_LINKS (sched_before_next_call);
  1769.       while (x)
  1770.         {
  1771.           add_dependence (insn, XEXP (x, 0));
  1772.           x = XEXP (x, 1);
  1773.         }
  1774.       LOG_LINKS (sched_before_next_call) = 0;
  1775.  
  1776.       sched_analyze_insn (PATTERN (insn), insn);
  1777.  
  1778.       if (GET_CODE (PATTERN (insn)) == SET
  1779.           && GET_CODE (SET_SRC (PATTERN (insn))) == CALL
  1780.           && RTX_UNCHANGING_P (XEXP (SET_SRC (PATTERN (insn)), 0)))
  1781.         {
  1782.           /* We don't need to flush memory for a function call which does
  1783.          not involve memory.  */
  1784.           ;
  1785.         }
  1786.       else
  1787.         {
  1788.           rtx link;
  1789.  
  1790.           /* In the absence of interprocedural alias analysis,
  1791.          we must flush all pending reads and writes, and
  1792.          start new dependencies starting from here.  */
  1793.           while (pending_read_insns)
  1794.         {
  1795.           add_dependence (insn, XEXP (pending_read_insns, 0));
  1796.  
  1797.           link = pending_read_insns;
  1798.           pending_read_insns = XEXP (pending_read_insns, 1);
  1799.           XEXP (link, 1) = unused_insn_list;
  1800.           unused_insn_list = link;
  1801.  
  1802.           link = pending_read_mems;
  1803.           pending_read_mems = XEXP (pending_read_mems, 1);
  1804.           XEXP (link, 1) = unused_expr_list;
  1805.           unused_expr_list = link;
  1806.         }
  1807.           while (pending_write_insns)
  1808.         {
  1809.           add_dependence (insn, XEXP (pending_write_insns, 0));
  1810.  
  1811.           link = pending_write_insns;
  1812.           pending_write_insns = XEXP (pending_write_insns, 1);
  1813.           XEXP (link, 1) = unused_insn_list;
  1814.           unused_insn_list = link;
  1815.  
  1816.           link = pending_write_mems;
  1817.           pending_write_mems = XEXP (pending_write_mems, 1);
  1818.           XEXP (link, 1) = unused_expr_list;
  1819.           unused_expr_list = link;
  1820.         }
  1821.           pending_lists_length = 0;
  1822.  
  1823.           if (last_pending_memory_flush)
  1824.         add_dependence (insn, last_pending_memory_flush);
  1825.  
  1826.           last_pending_memory_flush = insn;
  1827.         }
  1828. #if 0
  1829.       /* Obsolete.  */
  1830. #ifdef HAVE_cc0
  1831.       /* Depend this function call on the last setter of the
  1832.          condition codes.  */
  1833.       if (last_set_cc0)
  1834.         {
  1835.           rtx next = NEXT_INSN (last_set_cc0);
  1836.           if (GET_CODE (next) == NOTE)
  1837.         next = last_set_cc0;
  1838.           add_dependence (insn, next);
  1839.         }
  1840. #endif
  1841. #endif
  1842.  
  1843.       /* Depend this function call (actually, the user of this
  1844.          function call) on all hard register clobberage.  */
  1845.       last_function_call = insn;
  1846.       n_insns += 1;
  1847.     }
  1848.       else if (GET_CODE (insn) == JUMP_INSN)
  1849.     {
  1850.       n_insns += 1;
  1851.     }
  1852.  
  1853.       if (insn == tail)
  1854.     return n_insns;
  1855.     }
  1856. }
  1857.  
  1858. /* Called when we see a set of a register.  If death is true, then we are
  1859.    scanning backwards.  Try marking that register as unborn.  If nobody says
  1860.    otherwise, that is how things will remain.  If death is false, then we
  1861.    are scanning forwards.  Try marking that register as being born.  */
  1862.  
  1863. static void
  1864. sched_note_set (b, x, death)
  1865.      int b;
  1866.      rtx x;
  1867.      int death;
  1868. {
  1869.   register int regno, j;
  1870.   register rtx reg = SET_DEST (x);
  1871.   int subreg_p = 0;
  1872.  
  1873.   if (reg == 0)
  1874.     return;
  1875.  
  1876.   while (GET_CODE (reg) == SUBREG || GET_CODE (reg) == STRICT_LOW_PART
  1877.      || GET_CODE (reg) == SIGN_EXTRACT || GET_CODE (reg) == ZERO_EXTRACT)
  1878.     {
  1879.       /* Must treat modification of just one hardware register of a multi-reg
  1880.      value or just a byte field of a register exactly the same way that
  1881.      mark_set_1 in flow.c does.  */
  1882.       if (GET_CODE (reg) == ZERO_EXTRACT
  1883.       || GET_CODE (reg) == SIGN_EXTRACT
  1884.       || (GET_CODE (reg) == SUBREG
  1885.           && REG_SIZE (SUBREG_REG (reg)) > REG_SIZE (reg)))
  1886.     subreg_p = 1;
  1887.  
  1888.       reg = SUBREG_REG (reg);
  1889.     }
  1890.  
  1891.   if (GET_CODE (reg) != REG)
  1892.     return;
  1893.  
  1894.   regno = REGNO (reg);
  1895.   if (GET_CODE (x) != SET || ! reg_mentioned_p (reg, SET_SRC (x)))
  1896.     {
  1897.       register int offset = regno / REGSET_ELT_BITS;
  1898.       register int bit = 1 << (regno % REGSET_ELT_BITS);
  1899.  
  1900.       if (death)
  1901.     {
  1902.       /* If we only set part of the register, then this set does not
  1903.          kill it.  */
  1904.       if (subreg_p)
  1905.         return;
  1906.  
  1907.       if ((bb_live_regs[offset] & bit) == 0)
  1908.         abort ();
  1909.  
  1910.       /* Try killing this register.  */
  1911.       if (regno < FIRST_PSEUDO_REGISTER)
  1912.         {
  1913.           int j = HARD_REGNO_NREGS (regno, GET_MODE (reg));
  1914.           while (--j >= 0)
  1915.         {
  1916.           offset = (regno + j) / REGSET_ELT_BITS;
  1917.           bit = 1 << ((regno + j) % REGSET_ELT_BITS);
  1918.           
  1919.           bb_live_regs[offset] &= ~bit;
  1920.           bb_dead_regs[offset] |= bit;
  1921.         }
  1922.         }
  1923.       else
  1924.         {
  1925.           bb_live_regs[offset] &= ~bit;
  1926.           bb_dead_regs[offset] |= bit;
  1927.         }
  1928.     }
  1929.       else
  1930.     {
  1931.       /* Make the register live again.  */
  1932.       if (regno < FIRST_PSEUDO_REGISTER)
  1933.         {
  1934.           int j = HARD_REGNO_NREGS (regno, GET_MODE (reg));
  1935.           while (--j >= 0)
  1936.         {
  1937.           offset = (regno + j) / REGSET_ELT_BITS;
  1938.           bit = 1 << ((regno + j) % REGSET_ELT_BITS);
  1939.           
  1940.           bb_live_regs[offset] |= bit;
  1941.           bb_dead_regs[offset] &= ~bit;
  1942.         }
  1943.         }
  1944.       else
  1945.         {
  1946.           bb_live_regs[offset] |= bit;
  1947.           bb_dead_regs[offset] &= ~bit;
  1948.         }
  1949.     }
  1950.     }
  1951. }
  1952.  
  1953. /* Macros and functions for keeping the priority queue sorted, and
  1954.    dealing with queueing and unqueueing of instructions.  */
  1955.  
  1956. #define SCHED_SORT(READY, NEW_READY, OLD_READY) \
  1957.   do { if ((NEW_READY) - (OLD_READY) == 1)                \
  1958.      swap_sort (READY, NEW_READY);                    \
  1959.        else if ((NEW_READY) - (OLD_READY) > 1)                \
  1960.      qsort (READY, NEW_READY, sizeof (rtx), rank_for_schedule); }    \
  1961.   while (0)
  1962.  
  1963. static int
  1964. rank_for_schedule (x, y)
  1965.      rtx *x, *y;
  1966. {
  1967.   rtx tmp = *y;
  1968.   rtx tmp2 = *x;
  1969.   int value;
  1970.  
  1971. #if 0
  1972.   /* If either of x or y is a sequence, and one of the members of the sequence
  1973.      is not ready to be scheduled yet, then it is a bug for us to be here.
  1974.      Such a sequence should not have been marked as ready in the first
  1975.      place.  */
  1976.  
  1977.   if (RTX_UNCHANGING_P (tmp))
  1978.     {
  1979.       do
  1980.     {
  1981.       tmp = PREV_INSN (tmp);
  1982.       if (INSN_REF_COUNT (tmp) > 1)
  1983.       {
  1984. #if 0
  1985.         return -1;
  1986. #else
  1987.         abort ();
  1988.       }
  1989. #endif
  1990.     }
  1991.       while (RTX_UNCHANGING_P (tmp));
  1992.       tmp = *y;
  1993.     }
  1994.   tmp2 = *x;
  1995.   if (RTX_UNCHANGING_P (tmp2))
  1996.     {
  1997.       do
  1998.     {
  1999.       tmp2 = PREV_INSN (tmp2);
  2000.       if (INSN_REF_COUNT (tmp2) > 1)
  2001.         {
  2002. #if 0
  2003.           return 1;
  2004. #else
  2005.           abort ();
  2006. #endif
  2007.         }
  2008.     }
  2009.       while (RTX_UNCHANGING_P (tmp2));
  2010.       tmp2 = *x;
  2011.     }
  2012. #endif
  2013.  
  2014.   if (value = INSN_PRIORITY (tmp) - INSN_PRIORITY (tmp2))
  2015.     return value;
  2016.  
  2017.   /* If insns are equally good, sort by INSN_UID (close to original order),
  2018.      so that the results of qsort leave nothing to chance.  */
  2019.   return INSN_UID (tmp) - INSN_UID (tmp2);
  2020. }
  2021.  
  2022. /* Resort the array A in which only element at index N
  2023.    may be out of order.  */
  2024. __inline static void
  2025. swap_sort (a, n)
  2026.      rtx *a;
  2027.      int n;
  2028. {
  2029.   rtx insn = a[n-1];
  2030.   int i = n-2;
  2031.  
  2032.   while (i >= 0 && rank_for_schedule (a+i, a+n-1) >= 0)
  2033.     {
  2034.       a[i+1] = a[i];
  2035.       i -= 1;
  2036.     }
  2037.   a[i+1] = insn;
  2038. }
  2039.  
  2040. static int max_priority;
  2041.  
  2042. /* Add INSN to the insn queue so that it fires at least N_CYCLES
  2043.    before the currently executing insn.  */
  2044. __inline static void
  2045. queue_insn (insn, n_cycles)
  2046.      rtx insn;
  2047.      int n_cycles;
  2048. {
  2049.   int next_q = NEXT_Q_AFTER (q_ptr, n_cycles);
  2050.   NEXT_INSN (insn) = insn_queue[next_q];
  2051.   insn_queue[next_q] = insn;
  2052.   q_size += 1;
  2053. }
  2054.  
  2055. /* Return nonzero if PAT is the pattern of an insn which
  2056.    makes a register live.  */
  2057. __inline static int
  2058. birthing_insn_p (pat)
  2059.      rtx pat;
  2060. {
  2061.   int j;
  2062.  
  2063.   if (reload_completed == 1)
  2064.     /* @@ This is not right, but it is conservative.  */
  2065.     return 0;
  2066.  
  2067.   if (GET_CODE (pat) == SET
  2068.       && GET_CODE (SET_DEST (pat)) == REG)
  2069.     {
  2070.       /* Fire this asap--this is the birthing insn.  */
  2071.       rtx dest = SET_DEST (pat);
  2072.       int i = REGNO (dest);
  2073.       int offset = i / REGSET_ELT_BITS;
  2074.       int bit = 1 << (i % REGSET_ELT_BITS);
  2075.  
  2076.       if (bb_live_regs[offset] & bit)
  2077.     return (reg_n_sets[i] == 1);
  2078.       return 0;
  2079.     }
  2080.   if (GET_CODE (pat) == PARALLEL)
  2081.     {
  2082.       for (j = 0; j < XVECLEN (pat, 0); j++)
  2083.     if (birthing_insn_p (XVECEXP (pat, 0, j)))
  2084.       return 1;
  2085.     }
  2086.   return 0;
  2087. }
  2088.  
  2089. /* If PREV is an insn which is immediately ready to execute,
  2090.    return 1, otherwise return 0.  */
  2091. __inline static int
  2092. launch_link (prev)
  2093.      rtx prev;
  2094. {
  2095.   /* This insn can be fired.  See if we should adjust
  2096.      its priority to shorten register lives.  */
  2097.   rtx pat = PATTERN (prev);
  2098.   rtx note;
  2099.   /* MAX of (a) number of cycles needed by prev
  2100.         (b) number of cycles before needed resources are free.  */
  2101.   int n_cycles = insn_cost (prev);
  2102.   int n_deaths = 0;
  2103.  
  2104.   /* Trying to shorten register lives after reload has completed
  2105.      is useless and wrong.  It gives inaccurate schedules.  */
  2106.   if (reload_completed == 0)
  2107.     {
  2108.       for (note = REG_NOTES (prev); note; note = XEXP (note, 1))
  2109.     if (REG_NOTE_KIND (note) == REG_DEAD)
  2110.       n_deaths += 1;
  2111.  
  2112.       /* Defer scheduling insns which kill registers, since that
  2113.      shortens register lives.  Prefer scheduling insns which
  2114.      make registers live for the same reason.  */
  2115.       switch (n_deaths)
  2116.     {
  2117.     default:
  2118.       INSN_PRIORITY (prev) >>= 3;
  2119.       break;
  2120.     case 3:
  2121.       INSN_PRIORITY (prev) >>= 2;
  2122.       break;
  2123.     case 2:
  2124.     case 1:
  2125.       INSN_PRIORITY (prev) >>= 1;
  2126.       break;
  2127.     case 0:
  2128.       if (birthing_insn_p (pat))
  2129.         {
  2130.           int max = --max_priority;
  2131.           if (max > INSN_PRIORITY (prev))
  2132.         INSN_PRIORITY (prev) = max;
  2133.         }
  2134.       break;
  2135.     }
  2136.     }
  2137.  
  2138.   if (n_cycles <= 1)
  2139.     return 1;
  2140.   queue_insn (prev, n_cycles);
  2141.   return 0;
  2142. }
  2143.  
  2144. /* INSN is an insn that will be the next "currently executing insn".
  2145.    Launch each insn which was waiting on INSN (in the backwards
  2146.    dataflow sense).  READY is a vector of insns which are ready to fire.
  2147.    N_READY is the number of elements in READY.  */
  2148. static int
  2149. launch_links (insn, ready, n_ready)
  2150.      rtx insn;
  2151.      rtx *ready;
  2152.      int n_ready;
  2153. {
  2154.   rtx link;
  2155.   int new_ready = n_ready;
  2156.   int i, n_links = 0, parity;
  2157.   rtx *sorted_links, two_links[2];
  2158.  
  2159.   if (LOG_LINKS (insn) == 0)
  2160.     return n_ready;
  2161.  
  2162.   if (n_ready > 0)
  2163.     max_priority = INSN_PRIORITY (ready[0]);
  2164.   else
  2165.     max_priority = 1;
  2166.  
  2167.   for (link = LOG_LINKS (insn); link != 0; link = XEXP (link, 1))
  2168.     n_links += 1;
  2169.  
  2170.   switch (n_links)
  2171.     {
  2172.     case 0:
  2173.       return n_ready;
  2174.     case 1:
  2175.       sorted_links = &XEXP (LOG_LINKS (insn), 0);
  2176.       break;
  2177.     case 2:
  2178.       sorted_links = two_links;
  2179.       link = LOG_LINKS (insn);
  2180.       parity = INSN_PRIORITY (XEXP (link, 0)) < INSN_PRIORITY (XEXP (XEXP (link, 1), 0));
  2181.       sorted_links[parity] = XEXP (link, 0);
  2182.       link = XEXP (link, 1);
  2183.       sorted_links[parity ^ 1] = XEXP (link, 0);
  2184.       break;
  2185.     default:
  2186.       sorted_links = (rtx *)alloca (n_links * sizeof (rtx));
  2187.       for (n_links = 0, link = LOG_LINKS (insn); link != 0; link = XEXP (link, 1))
  2188.     sorted_links[n_links++] = XEXP (link, 0);
  2189.       qsort (sorted_links, n_links, sizeof (rtx), rank_for_schedule);
  2190.     }
  2191.  
  2192.   for (i = 0; i < n_links; i++)
  2193.     {
  2194.       rtx prev = sorted_links[i];
  2195.       if (GET_CODE (prev) == NOTE)
  2196.     continue;
  2197.       if ((INSN_REF_COUNT (prev) -= 1) == 0 && launch_link (prev))
  2198.     ready[new_ready++] = prev;
  2199.     }
  2200.  
  2201.   SCHED_SORT (ready, new_ready, n_ready);
  2202.   return new_ready;
  2203. }
  2204.  
  2205. /* Subroutine on attach_deaths_insn--handles the recursive search
  2206.    through INSN.  If SET_P is true, then x is being modified by the insn.  */
  2207. /* ??? Set_p is no longer used.  This procedure, and the code that calls it
  2208.    can be greatly simplified by eliminating set_p.  */
  2209. static void
  2210. attach_deaths (x, insn, set_p)
  2211.      rtx x;
  2212.      rtx insn;
  2213.      int set_p;
  2214. {
  2215.   register int i;
  2216.   register int j;
  2217.   register enum rtx_code code;
  2218.   register char *fmt;
  2219.  
  2220.   if (x == 0)
  2221.     return;
  2222.  
  2223.   code = GET_CODE (x);
  2224.  
  2225.   switch (code)
  2226.     {
  2227.     case CC0:
  2228.     case CONST_INT:
  2229.       /* Get rid of the easy cases first.  */
  2230.       return;
  2231.  
  2232.     case REG:
  2233.       {
  2234.     /* If the register dies in this insn, queue that note,
  2235.        and mark this register as needing to die.  */
  2236.     register int i = REGNO (x);
  2237.     register int offset = i / REGSET_ELT_BITS;
  2238.     register int bit = 1 << (i % REGSET_ELT_BITS);
  2239.  
  2240.     /* If it wasn't live before we started, then make it live now.
  2241.        We must check the previous lifetime info not the current info,
  2242.        because we may have to execute this code several times, e.g.
  2243.        once for a clobber (which doesn't add a note) and later
  2244.        for a use (which does add a note).  */
  2245.     if (! (old_live_regs[offset] & bit))
  2246.       {
  2247.         /* Don't add a REG_DEAD note if there is already a REG_DEAD or
  2248.            a REG_UNUSED note on this insn.  */
  2249.         /* Never add REG_DEAD notes for the FRAME_POINTER_REGNUM
  2250.            or the ARG_POINTER_REGNUM, since these are always considered
  2251.            to be live.  */
  2252.         if (i != FRAME_POINTER_REGNUM
  2253. #if ARG_POINTER_REGNUM != FRAME_POINTER_REGNUM
  2254.         && i != ARG_POINTER_REGNUM
  2255. #endif
  2256.         && i != STACK_POINTER_REGNUM
  2257.         && ! find_regno_note (insn, REG_DEAD, i)
  2258.         /* Use the same scheme as combine.c, don't put both REG_DEAD
  2259.            and REG_UNUSED notes on the same insn.  */
  2260.         && ! find_regno_note (insn, REG_UNUSED, i))
  2261.           {
  2262.         rtx link = dead_notes;
  2263.         
  2264.         if (link == 0)
  2265.           /* In theory, we should not end up with more REG_DEAD reg
  2266.              notes than we started with.  In practice, this can occur
  2267.              as the result of bugs in flow, combine and/or sched.  */
  2268.           {
  2269. #if 0
  2270.             abort ();
  2271. #else
  2272.             warning ("extra REG_DEAD notes detected during scheduling");
  2273.             link = rtx_alloc (EXPR_LIST);
  2274.             PUT_REG_NOTE_KIND (link, REG_DEAD);
  2275. #endif
  2276.           }
  2277.         else
  2278.           dead_notes = XEXP (dead_notes, 1);
  2279.         XEXP (link, 0) = x;
  2280.         XEXP (link, 1) = REG_NOTES (insn);
  2281.         REG_NOTES (insn) = link;
  2282.           }
  2283.         
  2284.         if (i < FIRST_PSEUDO_REGISTER)
  2285.           {
  2286.         int j = HARD_REGNO_NREGS (i, GET_MODE (x));
  2287.         while (--j >= 0)
  2288.           {
  2289.             offset = (i + j) / REGSET_ELT_BITS;
  2290.             bit = 1 << ((i + j) % REGSET_ELT_BITS);
  2291.  
  2292.             bb_dead_regs[offset] &= ~bit;
  2293.             bb_live_regs[offset] |= bit;
  2294.           }
  2295.           }
  2296.         else
  2297.           {
  2298.         bb_dead_regs[offset] &= ~bit;
  2299.         bb_live_regs[offset] |= bit;
  2300.           }
  2301.       }
  2302.       }
  2303.       return;
  2304.  
  2305.     case MEM:
  2306.       /* Handle tail-recursive case.  */
  2307.       attach_deaths (XEXP (x, 0), insn, 0);
  2308.       return;
  2309.  
  2310.     case SUBREG:
  2311.     case STRICT_LOW_PART:
  2312.       /* These two cases preserve the value of SET_P, so handle them
  2313.      separately.  */
  2314.       attach_deaths (XEXP (x, 0), insn, set_p);
  2315.       return;
  2316.  
  2317.     case ZERO_EXTRACT:
  2318.       /* This case preserves the value of SET_P for the first operand, but
  2319.      clears it for the other two.  */
  2320.       attach_deaths (XEXP (x, 0), insn, set_p);
  2321.       attach_deaths (XEXP (x, 1), insn, 0);
  2322.       attach_deaths (XEXP (x, 2), insn, 0);
  2323.       return;
  2324.  
  2325.     default:
  2326.       /* Other cases: walk the insn.  */
  2327.       fmt = GET_RTX_FORMAT (code);
  2328.       for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
  2329.     {
  2330.       if (fmt[i] == 'e')
  2331.         attach_deaths (XEXP (x, i), insn, 0);
  2332.       else if (fmt[i] == 'E')
  2333.         for (j = 0; j < XVECLEN (x, i); j++)
  2334.           attach_deaths (XVECEXP (x, i, j), insn, 0);
  2335.     }
  2336.     }
  2337. }
  2338.  
  2339. /* After INSN has executed, add register death notes for each register
  2340.    that is dead after INSN.  */
  2341. static void
  2342. attach_deaths_insn (insn)
  2343.      rtx insn;
  2344. {
  2345.   rtx x = PATTERN (insn);
  2346.   register RTX_CODE code = GET_CODE (x);
  2347.  
  2348.   if (code == SET)
  2349.     {
  2350.       attach_deaths (SET_SRC (x), insn, 0);
  2351.  
  2352.       /* A register might die here even if it is the destination, e.g.
  2353.      it is the target of a volatile read and is otherwise unused.
  2354.      Hence we must always call attach_deaths for the SET_DEST.  */
  2355.       attach_deaths (SET_DEST (x), insn, 1);
  2356.     }
  2357.   else if (code == PARALLEL)
  2358.     {
  2359.       register int i;
  2360.       for (i = XVECLEN (x, 0) - 1; i >= 0; i--)
  2361.     {
  2362.       code = GET_CODE (XVECEXP (x, 0, i));
  2363.       if (code == SET)
  2364.         {
  2365.           attach_deaths (SET_SRC (XVECEXP (x, 0, i)), insn, 0);
  2366.  
  2367.           attach_deaths (SET_DEST (XVECEXP (x, 0, i)), insn, 1);
  2368.         }
  2369.       else if (code == CLOBBER)
  2370.         attach_deaths (XEXP (XVECEXP (x, 0, i), 0), insn, 1);
  2371.       else
  2372.         attach_deaths (XVECEXP (x, 0, i), insn, 0);
  2373.     }
  2374.     }
  2375.   else if (code == CLOBBER)
  2376.     attach_deaths (XEXP (x, 0), insn, 1);
  2377.   else
  2378.     attach_deaths (x, insn, 0);
  2379. }
  2380.  
  2381. /* Delete notes beginning with INSN and maybe put them in the chain
  2382.    of notes ended by NOTE_LIST.
  2383.    Returns the insn following the notes.  */
  2384.  
  2385. static rtx
  2386. unlink_notes (insn, tail)
  2387.      rtx insn, tail;
  2388. {
  2389.   rtx prev = PREV_INSN (insn);
  2390.   while (insn != tail && GET_CODE (insn) == NOTE)
  2391.     {
  2392.       rtx next = NEXT_INSN (insn);
  2393.       /* Delete the note from its current position.  */
  2394.       if (prev)
  2395.     NEXT_INSN (prev) = next;
  2396.       if (next)
  2397.     PREV_INSN (next) = prev;
  2398.  
  2399.       if (write_symbols && NOTE_LINE_NUMBER (insn) > 0)
  2400.     /* Record line-number notes so they can be reused.  */
  2401.     LINE_NOTE (insn) = insn;
  2402.       else
  2403.     {
  2404.       /* Insert the note at the end of the notes list.  */
  2405.       PREV_INSN (insn) = note_list;
  2406.       if (note_list)
  2407.         NEXT_INSN (note_list) = insn;
  2408.       note_list = insn;
  2409.     }
  2410.  
  2411.       insn = next;
  2412.     }
  2413.   return insn;
  2414. }
  2415.  
  2416. /* Data structure for keeping track of register information
  2417.    during that register's life.  */
  2418. struct sometimes
  2419. {
  2420.   short offset; short bit;
  2421.   short live_length; short calls_crossed;
  2422. };
  2423.  
  2424. /* Constructor for `sometimes' data structure.  */
  2425. static int
  2426. new_sometimes_live (regs_sometimes_live, offset, bit, sometimes_max)
  2427.      struct sometimes *regs_sometimes_live;
  2428.      int offset, bit;
  2429.      int sometimes_max;
  2430. {
  2431.   register struct sometimes *p;
  2432.   register int regno = offset * REGSET_ELT_BITS + bit;
  2433.   int i;
  2434.  
  2435.   /* There should never be a register greater than max_regno here.  If there
  2436.      is, it means that a define_split has created a new psuedo reg.  This
  2437.      is not allowed, since there will not be flow info available for any
  2438.      new register, so catch the error here.  */
  2439.   if (regno >= max_regno)
  2440.     abort ();
  2441.  
  2442.   for (i = 0; i < sometimes_max; i++)
  2443.     {
  2444.       p = ®s_sometimes_live[i];
  2445.       if (p->offset == offset && p->bit == bit)
  2446. #if 0
  2447.     /* It is already in the table.  */
  2448.     return sometimes_max;
  2449. #else
  2450.         /* This should never happen.  */
  2451.         abort ();
  2452. #endif
  2453.     }
  2454.  
  2455.   p = ®s_sometimes_live[sometimes_max];
  2456.   p->offset = offset;
  2457.   p->bit = bit;
  2458.   p->live_length = 0;
  2459.   p->calls_crossed = 0;
  2460.   sometimes_max++;
  2461.   return sometimes_max;
  2462. }
  2463.  
  2464. /* Count lengths of all regs we are currently tracking,
  2465.    and find new registers no longer live.  */
  2466. static void
  2467. finish_sometimes_live (regs_sometimes_live, sometimes_max)
  2468.      struct sometimes *regs_sometimes_live;
  2469.      int sometimes_max;
  2470. {
  2471.   int i;
  2472.  
  2473.   for (i = 0; i < sometimes_max; i++)
  2474.     {
  2475.       register struct sometimes *p = ®s_sometimes_live[i];
  2476.       int regno;
  2477.  
  2478.       regno = p->offset*REGSET_ELT_BITS + p->bit;
  2479.  
  2480.       sched_reg_live_length[regno] += p->live_length;
  2481.       sched_reg_n_calls_crossed[regno] += p->calls_crossed;
  2482.     }
  2483. }
  2484.  
  2485. /* Use modified list scheduling to rearrange insns in basic block
  2486.    B.  FILE, if nonzero, is where we dump interesting output about
  2487.    this pass.  */
  2488.  
  2489. static void
  2490. schedule_block (b, file)
  2491.      int b;
  2492.      FILE *file;
  2493. {
  2494.   rtx insn, last;
  2495.   rtx last_note = 0;
  2496.   rtx *ready, link;
  2497.   int i, j, n_ready = 0, n_insns = 0;
  2498.   int sched_n_insns = 0;
  2499.   enum { need_nothing, need_head = 1, need_tail = 2 } new_needs;
  2500.   int tail_priority = 0;
  2501.  
  2502.   /* HEAD and TAIL delimit the region being scheduled.  */
  2503.   rtx head = basic_block_head[b];
  2504.   rtx tail = basic_block_end[b];
  2505.   /* PREV_HEAD and NEXT_TAIL are the boundaries of the insns
  2506.      being scheduled.  When the insns have been ordered,
  2507.      these insns delimit where the new insns are to be
  2508.      spliced back into the insn chain.  */
  2509.   rtx next_tail;
  2510.   rtx prev_head;
  2511.  
  2512.   /* Keep life information accurate.  */
  2513.   register struct sometimes *regs_sometimes_live;
  2514.   int sometimes_max;
  2515.  
  2516.   if (file)
  2517.     fprintf (file, ";;\t -- basic block number %d from %d to %d --\n",
  2518.          b, INSN_UID (basic_block_head[b]), INSN_UID (basic_block_end[b]));
  2519.  
  2520.   i = max_reg_num ();
  2521.   reg_last_uses = (rtx *) alloca (i * sizeof (rtx));
  2522.   bzero (reg_last_uses, i * sizeof (rtx));
  2523.   reg_last_sets = (rtx *) alloca (i * sizeof (rtx));
  2524.   bzero (reg_last_sets, i * sizeof (rtx));
  2525.  
  2526.   /* Remove certain insns at the beginning
  2527.      from scheduling, by advancing HEAD.  */
  2528.  
  2529.   /* At the start of a function, before reload has run, don't delay getting
  2530.      parameters from hard registers into pseudo registers.  */
  2531.   if (reload_completed == 0 && b == 0)
  2532.     {
  2533.       while (head != tail
  2534.          && GET_CODE (head) == NOTE
  2535.          && NOTE_LINE_NUMBER (head) != NOTE_INSN_FUNCTION_BEG)
  2536.     head = NEXT_INSN (head);
  2537.       while (head != tail
  2538.          && GET_CODE (head) == INSN
  2539.          && GET_CODE (PATTERN (head)) == SET)
  2540.     {
  2541.       rtx src = SET_SRC (PATTERN (head));
  2542.       while (GET_CODE (src) == SUBREG
  2543.          || GET_CODE (src) == SIGN_EXTEND
  2544.          || GET_CODE (src) == ZERO_EXTEND
  2545.          || GET_CODE (src) == SIGN_EXTRACT
  2546.          || GET_CODE (src) == ZERO_EXTRACT)
  2547.         src = XEXP (src, 0);
  2548.       if (GET_CODE (src) != REG
  2549.           || REGNO (src) >= FIRST_PSEUDO_REGISTER)
  2550.         break;
  2551.       /* Keep this insn from ever being scheduled.  */
  2552.       INSN_REF_COUNT (head) = 1;
  2553.       head = NEXT_INSN (head);
  2554.     }
  2555.     }
  2556.  
  2557.   /* Don't include any notes or labels at the beginning of the
  2558.      basic block, or notes at the ends of basic blocks.  */
  2559.   while (head != tail)
  2560.     {
  2561.       if (GET_CODE (head) == NOTE)
  2562.     head = NEXT_INSN (head);
  2563.       else if (GET_CODE (tail) == NOTE)
  2564.     tail = PREV_INSN (tail);
  2565.       else if (GET_CODE (head) == CODE_LABEL)
  2566.     head = NEXT_INSN (head);
  2567.       else break;
  2568.     }
  2569.   /* If the only insn left is a NOTE or a CODE_LABEL, then there is no need
  2570.      to schedule this block.  */
  2571.   if (head == tail
  2572.       && (GET_CODE (head) == NOTE || GET_CODE (head) == CODE_LABEL))
  2573.     return;
  2574.  
  2575. #if 0
  2576.   /* This short-cut doesn't work.  It does not count call insns crossed by
  2577.      registers in reg_sometimes_live.  It does not mark these registers as
  2578.      dead if they die in this block.  It does not mark these registers live
  2579.      (or create new reg_sometimes_live entries if necessary) if they are born
  2580.      in this block.
  2581.  
  2582.      The easy solution is to just always schedule a block.  This block only
  2583.      has one insn, so this won't slow down this pass by much.  */
  2584.  
  2585.   if (head == tail)
  2586.     return;
  2587. #endif
  2588.  
  2589.   /* Exclude certain insns at the end of the basic block by advancing TAIL.  */
  2590.   /* This isn't correct.  Instead of advancing TAIL, should assign very high
  2591.      priorities to these insns to guarantee that they get scheduled last.
  2592.      If these insns are ignored, as is currently done, the register life info
  2593.      may be incorrectly computed.  */
  2594.   if (GET_CODE (tail) == INSN
  2595.       && GET_CODE (PATTERN (tail)) == USE
  2596.       && next_nonnote_insn (tail) == 0)
  2597.     {
  2598.       /* If this was the only insn in the block, then there are no insns to
  2599.      schedule.  */
  2600.       if (head == tail)
  2601.     return;
  2602.  
  2603.       /* We don't try to reorder the USE at the end of a function.  */
  2604.       tail = prev_nonnote_insn (tail);
  2605.  
  2606. #if 0
  2607.       /* This short-cut does not work.  See comment above.  */
  2608.       if (head == tail)
  2609.     return;
  2610. #endif
  2611.     }
  2612.   else if (GET_CODE (tail) == JUMP_INSN
  2613.        && RTX_UNCHANGING_P (tail) == 0
  2614.        && GET_CODE (PREV_INSN (tail)) == INSN
  2615.        && GET_CODE (PATTERN (PREV_INSN (tail))) == USE
  2616.        && REG_FUNCTION_VALUE_P (XEXP (PATTERN (PREV_INSN (tail)), 0)))
  2617.     {
  2618.       /* Don't let the setting of the function's return value register
  2619.      move from this jump.  For the same reason we want to get the
  2620.      parameters into pseudo registers as quickly as possible, we
  2621.      want to set the function's return value register as late as
  2622.      possible.  */
  2623.  
  2624.       /* If this is the only insn in the block, then there is no need to
  2625.      schedule the block.  */
  2626.       if (head == tail)
  2627.     return;
  2628.     
  2629.       tail = PREV_INSN (tail);
  2630.       if (head == tail)
  2631.     return;
  2632.  
  2633.       tail = prev_nonnote_insn (tail);
  2634.  
  2635. #if 0
  2636.       /* This shortcut does not work.  See comment above.  */
  2637.       if (head == tail)
  2638.     return;
  2639. #endif
  2640.     }
  2641.  
  2642. #ifdef HAVE_cc0
  2643.   /* This is probably wrong.  Instead of doing this, should give this insn
  2644.      a very high priority to guarantee that it gets scheduled last.  */
  2645.   /* Can not separate an insn that sets the condition code from one that
  2646.      uses it.  So we must leave an insn that sets cc0 where it is.  */
  2647.   if (sets_cc0_p (PATTERN (tail)))
  2648.     tail = PREV_INSN (tail);
  2649. #endif
  2650.  
  2651.   /* Now HEAD through TAIL are the insns actually to be rearranged;
  2652.      Let PREV_HEAD and NEXT_TAIL enclose them.  */
  2653.   prev_head = PREV_INSN (head);
  2654.   next_tail = NEXT_INSN (tail);
  2655.  
  2656.   /* Initialize basic block data structures.  */
  2657.   dead_notes = 0;
  2658.   pending_read_insns = 0;
  2659.   pending_read_mems = 0;
  2660.   pending_write_insns = 0;
  2661.   pending_write_mems = 0;
  2662.   pending_lists_length = 0;
  2663.   last_pending_memory_flush = 0;
  2664.   last_function_call = 0;
  2665. #if 0
  2666.   /* Obsolete.  */
  2667.   last_set_cc0 = 0;
  2668. #endif
  2669.   if (reload_completed == 0)
  2670.     {
  2671.       bzero (bb_reg_sets, regset_bytes);
  2672.       bzero (bb_dead_regs, regset_bytes);
  2673.     }
  2674.  
  2675.   LOG_LINKS (sched_before_next_call) = 0;
  2676.  
  2677.   n_insns += sched_analyze (head, tail);
  2678.   if (n_insns == 0)
  2679.     {
  2680.       free_pending_lists ();
  2681.       return;
  2682.     }
  2683.  
  2684.   /* Allocate vector to hold insns to be rearranged (except those
  2685.      insns which are controlled by an insn with RTX_UNCHANGING_P set).
  2686.      All these insns are included between ORIG_HEAD and ORIG_TAIL,
  2687.      as those variables ultimately are set up.  */
  2688.   ready = (rtx *) alloca ((n_insns+1) * sizeof (rtx));
  2689.  
  2690.   /* Omit certain insns from actual rearrangement, but do
  2691.      compute priorities for them.  */
  2692.  
  2693.   if (GET_CODE (tail) == JUMP_INSN)
  2694.     {
  2695.       for (insn = LOG_LINKS (tail); insn; insn = XEXP (insn, 1))
  2696.     {
  2697.       rtx x = XEXP (insn, 0);
  2698.       if (GET_CODE (x) != NOTE)
  2699.         INSN_REF_COUNT (x) += 1;
  2700.     }
  2701.       tail_priority = INSN_PRIORITY (tail);
  2702.  
  2703. #if 0
  2704.       /* This causes a failure later, because all of the dependencies on
  2705.      the original tail insn are not having their INSN_REF_COUNTs
  2706.      decremented.  */
  2707.  
  2708.       while (RTX_UNCHANGING_P (tail))
  2709.     {
  2710.       tail = PREV_INSN (tail);
  2711.       while (GET_CODE (tail) == NOTE)
  2712.         tail = PREV_INSN (tail);
  2713.       priority (tail);
  2714.       sched_n_insns += 1;
  2715.     }
  2716. #endif
  2717.  
  2718.       next_tail = NEXT_INSN (tail);
  2719.       INSN_REF_COUNT (tail) = 0;
  2720.       INSN_PRIORITY (tail) = 0x7ffffffe;
  2721.       /* Funny case where orignal code is:
  2722.      CODE_LABEL followed by USE followed by JUMP.  */
  2723.       if (sched_n_insns == n_insns)
  2724.     {
  2725.       free_pending_lists ();
  2726.       return;
  2727.     }
  2728.     }
  2729.  
  2730.   /* TAIL is now the last of the insns to be rearranged.
  2731.      Put those insns into the READY vector.  */
  2732.   insn = tail;
  2733.  
  2734.   /* If the last insn is a conditional branch whose outcome
  2735.      may vary, force it to be the last insn after scheduling.
  2736.      Also, don't try to reorder calls at the ends the basic
  2737.      block--this will only lead to worse register allocation.  */
  2738.   if (GET_CODE (tail) == CALL_INSN
  2739.       || (GET_CODE (tail) == JUMP_INSN && ! RTX_UNCHANGING_P (tail)))
  2740.     {
  2741.       if (GET_CODE (tail) == CALL_INSN)
  2742.     priority (tail);
  2743.       if ((INSN_PRIORITY (tail) & 0x7f000000) == 0
  2744.       && INSN_PRIORITY (tail) > tail_priority)
  2745.     tail_priority = INSN_PRIORITY (tail);
  2746.       ready[n_ready++] = tail;
  2747.       INSN_PRIORITY (tail) = 0x7ffffffe;
  2748.       INSN_REF_COUNT (tail) = 0;
  2749.       insn = PREV_INSN (tail);
  2750.     }
  2751.  
  2752.   /* Assign priorities to instructions.  Also check whether they
  2753.      are in priority order already.  If so then I will be nonnegative.
  2754.      We use this shortcut only before reloading.  */
  2755.   i = reload_completed ? -1 : 0x7fffffff;
  2756.  
  2757.   for (; insn != prev_head; insn = PREV_INSN (insn))
  2758.     {
  2759.       if (GET_RTX_CLASS (GET_CODE (insn)) == 'i')
  2760.     {
  2761.       priority (insn);
  2762.       if (INSN_REF_COUNT (insn) == 0)
  2763.         ready[n_ready++] = insn;
  2764.       if (RTX_UNCHANGING_P (insn))
  2765.         {
  2766.           while (RTX_UNCHANGING_P (insn))
  2767.         {
  2768.           insn = PREV_INSN (insn);
  2769.           while (GET_CODE (insn) == NOTE)
  2770.             insn = PREV_INSN (insn);
  2771.           priority (insn);
  2772.         }
  2773. #if 0
  2774.           /* This is simply plain wrong.  */
  2775.           insn = NEXT_INSN (insn);
  2776. #endif
  2777.           continue;
  2778.         }
  2779.       if (i < 0)
  2780.         continue;
  2781.       if (INSN_PRIORITY (insn) < i)
  2782.         i = INSN_PRIORITY (insn);
  2783.       else if (INSN_PRIORITY (insn) > i)
  2784.         i = -1;
  2785.     }
  2786.     }
  2787.  
  2788. #if 0
  2789.   /* This short-cut doesn't work.  It does not count call insns crossed by
  2790.      registers in reg_sometimes_live.  It does not mark these registers as
  2791.      dead if they die in this block.  It does not mark these registers live
  2792.      (or create new reg_sometimes_live entries if necessary) if they are born
  2793.      in this block.
  2794.  
  2795.      The easy solution is to just always schedule a block.  These blocks tend
  2796.      to be very short, so this doesn't slow down this pass by much.  */
  2797.  
  2798.   /* If existing order is good, don't bother to reorder.  */
  2799.   if (i != -1)
  2800.     {
  2801.       if (file)
  2802.     fprintf (file, ";; already scheduled\n");
  2803.  
  2804.       if (reload_completed == 0)
  2805.     {
  2806.       for (i = 0; i < sometimes_max; i++)
  2807.         regs_sometimes_live[i].live_length += n_insns;
  2808.  
  2809.       finish_sometimes_live (regs_sometimes_live, sometimes_max);
  2810.     }
  2811.       free_pending_lists ();
  2812.       return;
  2813.     }
  2814. #endif
  2815.  
  2816.   /* Scan all the insns to be scheduled, removing NOTE insns
  2817.      and register death notes.
  2818.      Line number NOTE insns end up in NOTE_LIST.
  2819.      Register death notes end up in DEAD_NOTES.
  2820.  
  2821.      Recreate the register life information for the end of this basic
  2822.      block.  */
  2823.  
  2824.   if (reload_completed == 0)
  2825.     {
  2826.       bcopy (basic_block_live_at_start[b], bb_live_regs, regset_bytes);
  2827.  
  2828.       if (b == 0)
  2829.     {
  2830.       /* This is the first block in the function.  There may be insns
  2831.          before head that we can't schedule.   We still need to examine
  2832.          them though for accurate register lifetime analysis.  */
  2833.  
  2834.       /* We don't want to remove any REG_DEAD notes as the code below
  2835.          does.  */
  2836.  
  2837.       for (insn = basic_block_head[b]; insn != head;
  2838.            insn = NEXT_INSN (insn))
  2839.         if (GET_RTX_CLASS (GET_CODE (insn)) == 'i')
  2840.           {
  2841.         /* See if the register gets born here.  */
  2842.         /* We must check for registers being born before we check for
  2843.            registers dying.  It is possible for a register to be born
  2844.            and die in the same insn, e.g. reading from a volatile
  2845.            memory location into an otherwise unused register.  Such
  2846.            a register must be marked as dead after this insn.  */
  2847.         if (GET_CODE (PATTERN (insn)) == SET)
  2848.           sched_note_set (b, PATTERN (insn), 0);
  2849.         else if (GET_CODE (PATTERN (insn)) == PARALLEL)
  2850.           {
  2851.             int j;
  2852.             for (j = XVECLEN (PATTERN (insn), 0) - 1; j >= 0; j--)
  2853.               if (GET_CODE (XVECEXP (PATTERN (insn), 0, j)) == SET)
  2854.             sched_note_set (b, XVECEXP (PATTERN (insn), 0, j), 0);
  2855.           }
  2856.  
  2857.         for (link = REG_NOTES (insn); link; link = XEXP (link, 1))
  2858.           {
  2859.             if ((REG_NOTE_KIND (link) == REG_DEAD
  2860.              || REG_NOTE_KIND (link) == REG_UNUSED)
  2861.             /* Verify that the REG_NOTE has a legal value.  */
  2862.             && GET_CODE (XEXP (link, 0)) == REG)
  2863.               {
  2864.             register int regno = REGNO (XEXP (link, 0));
  2865.             register int offset = regno / REGSET_ELT_BITS;
  2866.             register int bit = 1 << (regno % REGSET_ELT_BITS);
  2867.  
  2868.             if (regno < FIRST_PSEUDO_REGISTER)
  2869.               {
  2870.                 int j = HARD_REGNO_NREGS (regno,
  2871.                               GET_MODE (XEXP (link, 0)));
  2872.                 while (--j >= 0)
  2873.                   {
  2874.                 offset = (regno + j) / REGSET_ELT_BITS;
  2875.                 bit = 1 << ((regno + j) % REGSET_ELT_BITS);
  2876.  
  2877.                 bb_live_regs[offset] &= ~bit;
  2878.                 bb_dead_regs[offset] |= bit;
  2879.                   }
  2880.               }
  2881.             else
  2882.               {
  2883.                 bb_live_regs[offset] &= ~bit;
  2884.                 bb_dead_regs[offset] |= bit;
  2885.               }
  2886.               }
  2887.           }
  2888.           }
  2889.     }
  2890.     }
  2891.  
  2892.   /* If debugging information is being produced, keep track of the line
  2893.      number notes for each insn.  */
  2894.   if (write_symbols)
  2895.     {
  2896.       /* We must use the true line number for the first insn in the block
  2897.      that was computed and saved at the start of this pass.  We can't
  2898.      use the current line number, because scheduling of the previous
  2899.      block may have changed the current line number.  */
  2900.       rtx line = line_note_head[b];
  2901.  
  2902.       for (insn = basic_block_head[b];
  2903.        insn != next_tail;
  2904.        insn = NEXT_INSN (insn))
  2905.     if (GET_CODE (insn) == NOTE && NOTE_LINE_NUMBER (insn) > 0)
  2906.       line = insn;
  2907.     else
  2908.       LINE_NOTE (insn) = line;
  2909.     }
  2910.  
  2911.   for (insn = head; insn != next_tail; insn = NEXT_INSN (insn))
  2912.     {
  2913.       rtx prev, next, link;
  2914.  
  2915.       /* Farm out notes.  This is needed to keep the debugger from
  2916.      getting completely deranged.  */
  2917.       if (GET_CODE (insn) == NOTE)
  2918.     {
  2919.       prev = insn;
  2920.       insn = unlink_notes (insn, next_tail);
  2921.       if (prev == tail)
  2922.         abort ();
  2923.       if (prev == head)
  2924.         abort ();
  2925.       if (insn == next_tail)
  2926.         abort ();
  2927.     }
  2928.  
  2929.       if (reload_completed == 0
  2930.       && GET_RTX_CLASS (GET_CODE (insn)) == 'i')
  2931.     {
  2932.       /* See if the register gets born here.  */
  2933.       /* We must check for registers being born before we check for
  2934.          registers dying.  It is possible for a register to be born and
  2935.          die in the same insn, e.g. reading from a volatile memory
  2936.          location into an otherwise unused register.  Such a register
  2937.          must be marked as dead after this insn.  */
  2938.       if (GET_CODE (PATTERN (insn)) == SET
  2939.           || GET_CODE (PATTERN (insn)) == CLOBBER)
  2940.         sched_note_set (b, PATTERN (insn), 0);
  2941.       else if (GET_CODE (PATTERN (insn)) == PARALLEL)
  2942.         {
  2943.           int j;
  2944.           for (j = XVECLEN (PATTERN (insn), 0) - 1; j >= 0; j--)
  2945.         if (GET_CODE (XVECEXP (PATTERN (insn), 0, j)) == SET
  2946.             || GET_CODE (XVECEXP (PATTERN (insn), 0, j)) == CLOBBER)
  2947.           sched_note_set (b, XVECEXP (PATTERN (insn), 0, j), 0);
  2948.         }
  2949.  
  2950.       /* Need to know what registers this insn kills.  */
  2951.       for (prev = 0, link = REG_NOTES (insn); link; link = next)
  2952.         {
  2953.           int regno;
  2954.  
  2955.           next = XEXP (link, 1);
  2956.           if ((REG_NOTE_KIND (link) == REG_DEAD
  2957.            || REG_NOTE_KIND (link) == REG_UNUSED)
  2958.           /* Verify that the REG_NOTE has a legal value.  */
  2959.           && GET_CODE (XEXP (link, 0)) == REG)
  2960.         {
  2961.           register int regno = REGNO (XEXP (link, 0));
  2962.           register int offset = regno / REGSET_ELT_BITS;
  2963.           register int bit = 1 << (regno % REGSET_ELT_BITS);
  2964.  
  2965.           /* Only unlink REG_DEAD notes; leave REG_UNUSED notes
  2966.              alone.  */
  2967.           /* We have ways of keeping uses of hard registers in
  2968.              order, so we just leave their death notes around.  */
  2969.           if (REG_NOTE_KIND (link) == REG_DEAD)
  2970.             {
  2971.               if (prev)
  2972.             XEXP (prev, 1) = next;
  2973.               else
  2974.             REG_NOTES (insn) = next;
  2975.               XEXP (link, 1) = dead_notes;
  2976.               dead_notes = link;
  2977.             }
  2978.           else
  2979.             prev = link;
  2980.  
  2981.           if (regno < FIRST_PSEUDO_REGISTER)
  2982.             {
  2983.               int j = HARD_REGNO_NREGS (regno,
  2984.                         GET_MODE (XEXP (link, 0)));
  2985.               while (--j >= 0)
  2986.             {
  2987.               offset = (regno + j) / REGSET_ELT_BITS;
  2988.               bit = 1 << ((regno + j) % REGSET_ELT_BITS);
  2989.  
  2990.               bb_live_regs[offset] &= ~bit;
  2991.               bb_dead_regs[offset] |= bit;
  2992.             }
  2993.             }
  2994.           else
  2995.             {
  2996.               bb_live_regs[offset] &= ~bit;
  2997.               bb_dead_regs[offset] |= bit;
  2998.             }
  2999.         }
  3000.           else
  3001.         prev = link;
  3002.         }
  3003.     }
  3004.     }
  3005.  
  3006.   if (reload_completed == 0)
  3007.     {
  3008.       /* Keep track of register lives.  */
  3009.       old_live_regs = (regset) alloca (regset_bytes);
  3010.       regs_sometimes_live
  3011.     = (struct sometimes *) alloca (max_regno * sizeof (struct sometimes));
  3012.       sometimes_max = 0;
  3013.  
  3014.       /* Start with registers live at end.  */
  3015.       for (j = 0; j < regset_size; j++)
  3016.     {
  3017.       int live = bb_live_regs[j];
  3018.       old_live_regs[j] = live;
  3019.       if (live)
  3020.         {
  3021.           register int bit;
  3022.           for (bit = 0; bit < REGSET_ELT_BITS; bit++)
  3023.         if (live & (1 << bit))
  3024.           sometimes_max = new_sometimes_live (regs_sometimes_live, j,
  3025.                               bit, sometimes_max);
  3026.         }
  3027.     }
  3028.     }
  3029.  
  3030.   /* Sort the array of ready elements.  */
  3031.   if (n_ready > 1)
  3032.     qsort (ready, n_ready, sizeof (rtx), rank_for_schedule);
  3033.  
  3034.   if ((INSN_PRIORITY (ready[0]) & 0x7f000000) == 0
  3035.       && INSN_PRIORITY (ready[0]) > tail_priority)
  3036.     tail_priority = INSN_PRIORITY (ready[0]);
  3037.   if (tail_priority == 0 && n_ready > 1)
  3038.     tail_priority = INSN_PRIORITY (ready[1]) + 1;
  3039.   if (tail_priority == 0)
  3040.     {
  3041.       insn = ready[0];
  3042.       while (RTX_UNCHANGING_P (insn))
  3043.     insn = PREV_INSN (insn);
  3044.       if ((INSN_PRIORITY (insn) & 0x7f000000) == 0)
  3045.     tail_priority = INSN_PRIORITY (insn);
  3046.       else
  3047.     {
  3048.       link = LOG_LINKS (ready[0]);
  3049.       while (link)
  3050.         {
  3051.           if ((INSN_PRIORITY (XEXP (link, 0)) & 0x7f000000) == 0
  3052.           && INSN_PRIORITY (XEXP (link, 0)) > tail_priority)
  3053.         tail_priority = INSN_PRIORITY (XEXP (link, 0));
  3054.           link = XEXP (link, 1);
  3055.         }
  3056.       if (tail_priority > 0)
  3057.         /* Add the cost of the jump here.  */
  3058.         tail_priority += 1;
  3059.     }
  3060.     }
  3061.  
  3062.   if (file)
  3063.     {
  3064.       fprintf (file, ";; %d insns / %d cycles = %lg IPC\n\n",
  3065.            n_insns, tail_priority, (double)n_insns / (double)tail_priority);
  3066.  
  3067.       fprintf (file, ";; ready list initially:\n\n;; ");
  3068.       for (i = 0; i < n_ready; i++)
  3069.     fprintf (file, "%d ", INSN_UID (ready[i]));
  3070.       fprintf (file, "\n\n");
  3071.  
  3072.       for (insn = head; insn != tail; insn = NEXT_INSN (insn))
  3073.     if (INSN_PRIORITY (insn) > 0)
  3074.       fprintf (file, ";; insn[%4d]: priority = %4d, ref_count = %4d\n",
  3075.            INSN_UID (insn), INSN_PRIORITY (insn),
  3076.            INSN_REF_COUNT (insn));
  3077.     }
  3078.  
  3079.   /* Now HEAD and TAIL are going to become disconnected
  3080.      entirely from the insn chain.  */
  3081.   tail = ready[0];
  3082.  
  3083.   q_ptr = 0;
  3084.   bzero (insn_queue, sizeof (insn_queue));
  3085.  
  3086.   /* Now, perform list scheduling.  */
  3087.  
  3088.   /* Where we start inserting insns is after TAIL.  */
  3089.   last = next_tail;
  3090.  
  3091.   new_needs = (NEXT_INSN (prev_head) == basic_block_head[b]
  3092.            ? need_head : need_nothing);
  3093.   if (PREV_INSN (next_tail) == basic_block_end[b])
  3094.     new_needs |= need_tail;
  3095.  
  3096.   while (sched_n_insns < n_insns)
  3097.     {
  3098.       int new_ready = n_ready;
  3099.  
  3100.       q_ptr = NEXT_Q (q_ptr);
  3101.  
  3102.       /* If we come upon an insn ready to fire, fire away.  */
  3103.       if (insn_queue[q_ptr] != 0)
  3104.     {
  3105.       while (insn_queue[q_ptr])
  3106.         {
  3107.           if (file)
  3108.         fprintf (file, ";; launching %d from queue\n", INSN_UID (insn));
  3109.  
  3110.           insn = insn_queue[q_ptr];
  3111.           insn_queue[q_ptr] = NEXT_INSN (insn);
  3112.           ready[new_ready++] = insn;
  3113.           q_size -= 1;
  3114.         }
  3115.       SCHED_SORT (ready, new_ready, n_ready);
  3116.       n_ready = new_ready;
  3117.     }
  3118.       if (n_ready == 0)
  3119.     {
  3120.       int this_q = q_ptr;
  3121.       if (file)
  3122.         fprintf (file, ";; stalling before insn %d\n", INSN_UID (last));
  3123.       while (q_size > 0)
  3124.         {
  3125.           if (insn_queue[this_q] == 0)
  3126.         {
  3127.           this_q = NEXT_Q (this_q);
  3128.           continue;
  3129.         }
  3130.           while (insn_queue[this_q] != 0)
  3131.         {
  3132.           if (file)
  3133.             fprintf (file, ";; springing insn %d from queue\n", INSN_UID (insn_queue[this_q]));
  3134.           insn = insn_queue[this_q];
  3135.           insn_queue[this_q] = NEXT_INSN (insn);
  3136.           ready[n_ready++] = insn;
  3137.           q_size -= 1;
  3138.         }
  3139.           break;
  3140.         }
  3141.       /* Should be some instructions waiting to fire.  */
  3142.       if (n_ready == 0)
  3143.         abort ();
  3144.       if (n_ready > 1)
  3145.         qsort (ready, n_ready, sizeof (rtx), rank_for_schedule);
  3146.     }
  3147.  
  3148.       insn = ready[0];
  3149.       if (INSN_PRIORITY (insn) < 0)
  3150.     abort ();
  3151.  
  3152.       if (reload_completed == 0)
  3153.     {
  3154.       /* Process this insn, and each insn linked to this one which must
  3155.          be immediately output after this insn.  */
  3156.       do
  3157.         {
  3158.           /* If this register is the last use of any register which needs
  3159.          to die, attach such death notes now.  */
  3160.           attach_deaths_insn (insn);
  3161.  
  3162.           /* Find registers now made live by that instruction.  */
  3163.           for (i = 0; i < regset_size; i++)
  3164.         {
  3165.           int diff = bb_live_regs[i] & ~old_live_regs[i];
  3166.           if (diff)
  3167.             {
  3168.               register int bit;
  3169.               old_live_regs[i] |= diff;
  3170.               for (bit = 0; bit < REGSET_ELT_BITS; bit++)
  3171.             if (diff & (1 << bit))
  3172.               sometimes_max
  3173.                 = new_sometimes_live (regs_sometimes_live, i, bit,
  3174.                           sometimes_max);
  3175.             }
  3176.         }
  3177.  
  3178.           /* See if this is the last notice we must take of a register.  */
  3179.           if (GET_CODE (PATTERN (insn)) == SET
  3180.           || GET_CODE (PATTERN (insn)) == CLOBBER)
  3181.         sched_note_set (b, PATTERN (insn), 1);
  3182.           else if (GET_CODE (PATTERN (insn)) == PARALLEL)
  3183.         {
  3184.           rtx set = single_set (insn);
  3185.           int j;
  3186.  
  3187.           /* A CLOBBER indicates that a register is modified here;
  3188.              it is a birth if the register is not mentioned in any SET.
  3189.              If the register is mentioned in a SET, then the SET will
  3190.              indicate whether this is a birth (with unknown value),
  3191.              or a destructive use.  */
  3192.           for (j = XVECLEN (PATTERN (insn), 0) - 1; j >= 0; j--)
  3193.             if (GET_CODE (XVECEXP (PATTERN (insn), 0, j)) == SET
  3194.             || (GET_CODE (XVECEXP (PATTERN (insn), 0, j)) == CLOBBER
  3195.                 && ! reg_mentioned_p (XEXP (XVECEXP (PATTERN(insn),
  3196.                                  0, j), 0),
  3197.                           set)))
  3198.               sched_note_set (b, XVECEXP (PATTERN (insn), 0, j), 1);
  3199.  
  3200.           /* A USE indicates that a register is live before this
  3201.              insn, no matter what the CLOBBERs and SETs may indicate.
  3202.              Hence we must look for USEs now so that we can mark regs
  3203.              as live that we may have incorrectly killed above.  */
  3204.           for (j = XVECLEN (PATTERN (insn), 0) - 1; j >= 0; j--)
  3205.             if (GET_CODE (XVECEXP (PATTERN (insn), 0, j)) == USE)
  3206.               sched_note_set (b, XVECEXP (PATTERN (insn), 0, j), 0);
  3207.         }
  3208.           
  3209.           /* This code keep life analysis information up to date.  */
  3210.           if (GET_CODE (insn) == CALL_INSN)
  3211.         {
  3212.           register struct sometimes *p;
  3213.  
  3214.           /* A call kills all call used and global registers, except
  3215.              for those mentioned in the call pattern.  */
  3216.           for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
  3217.             if ((call_used_regs[i] || global_regs[i])
  3218.             && ! refers_to_regno_p (i, i+1, insn, 0))
  3219.               {
  3220.             register int offset = i / REGSET_ELT_BITS;
  3221.             register int bit = 1 << (i % REGSET_ELT_BITS);
  3222.  
  3223.             bb_live_regs[offset] &= ~bit;
  3224.             bb_dead_regs[offset] |= bit;
  3225.               }
  3226.         }
  3227.  
  3228.           /* Count lengths of all regs we are worrying about now, and
  3229.          find new registers no longer live.  */
  3230.           for (i = 0; i < sometimes_max; i++)
  3231.         {
  3232.           register struct sometimes *p = ®s_sometimes_live[i];
  3233.           int regno = p->offset*REGSET_ELT_BITS + p->bit;
  3234.           p->live_length += 1;
  3235.           if ((bb_live_regs[p->offset] & (1 << p->bit)) == 0)
  3236.             {
  3237.               /* This is the end of one of this register's lifetime
  3238.              segments.  Save the lifetime info collected so far,
  3239.              and clear its bit in the old_live_regs entry.  */
  3240.               sched_reg_live_length[regno] += p->live_length;
  3241.               sched_reg_n_calls_crossed[regno] += p->calls_crossed;
  3242.               old_live_regs[p->offset] &= ~(1 << p->bit);
  3243.  
  3244.               /* Delete the reg_sometimes_live entry for this reg by
  3245.              copying the last entry over top of it.  */
  3246.               *p = regs_sometimes_live[--sometimes_max];
  3247.               /* ...and decrement i so that this newly copied entry
  3248.              will be processed.  */
  3249.               i--;
  3250.             }
  3251.         }
  3252.  
  3253.           if (GET_CODE (insn) == CALL_INSN)
  3254.         {
  3255.           register struct sometimes *p;
  3256.  
  3257.           /* Dying regs live at the time of a call instruction
  3258.              must not go in a register clobbered by calls.
  3259.              Find all dying regs now live and record this for them.
  3260.              Other registers have already been dealt with by flow,
  3261.              so there is not need to duplicate that effort here.  */
  3262.  
  3263.           p = regs_sometimes_live;
  3264.           for (i = 0; i < sometimes_max; i++, p++)
  3265.             if (bb_live_regs[p->offset] & (1 << p->bit))
  3266.               {
  3267.             int regno = p->offset * REGSET_ELT_BITS + p->bit;
  3268.             p->calls_crossed += 1;
  3269.               }
  3270.         }
  3271.  
  3272.           link = insn;
  3273.           insn = PREV_INSN (insn);
  3274.         }
  3275.       while (RTX_UNCHANGING_P (link));
  3276.     }
  3277.       /* Set INSN back to the insn we are scheduling now.  */
  3278.       insn = ready[0];
  3279.  
  3280.       /* We are committing to schedule INSN.  So everything which precedes
  3281.      insn now either becomes "ready", if they can execute immediately
  3282.      before INSN, or "pending", if there must be a delay.  Give this
  3283.      insn high enough priority that at least one (maybe more) reg-killing
  3284.      insns can be launched ahead of all others.  */
  3285.       INSN_PRIORITY (insn) = 0x7fffff0;
  3286.       n_ready = launch_links (insn, ready, n_ready);
  3287.  
  3288.       /* We schedule INSN now.  Change its priority to -1 so it
  3289.      goes to the end of the list, should we sort the list again.  */
  3290.       INSN_PRIORITY (insn) = -1;
  3291. #if 1
  3292.       ready += 1;
  3293.       n_ready -= 1;
  3294. #else
  3295.       qsort (ready, n_ready, sizeof (rtx), rank_for_schedule);
  3296. #endif
  3297.  
  3298.       /* @@ It would be nice to get the right NOTE information to follow
  3299.      these instructions around.  */
  3300.  
  3301.       sched_n_insns += 1;
  3302.       NEXT_INSN (insn) = last;
  3303.       PREV_INSN (last) = insn;
  3304.       last = insn;
  3305.  
  3306.       /* Special kinds of insns require that their predecessors
  3307.      be output immediately.  */
  3308.       if (RTX_UNCHANGING_P (insn))
  3309.     {
  3310.       int new_ready = n_ready;
  3311.  
  3312.       link = insn;
  3313.       while (RTX_UNCHANGING_P (link))
  3314.         {
  3315.           /* Disable these insns from being launched by anybody.  */
  3316.           link = PREV_INSN (link);
  3317.           INSN_REF_COUNT (link) = 0;
  3318.         }
  3319.  
  3320.       /* None of these insns can move forward into delay slots.  */
  3321.       while (RTX_UNCHANGING_P (insn))
  3322.         {
  3323.           insn = PREV_INSN (insn);
  3324.  
  3325.           new_ready = launch_links (insn, ready, new_ready);
  3326.           sched_n_insns += 1;
  3327.  
  3328.           INSN_PRIORITY (insn) = -1;
  3329.           NEXT_INSN (insn) = last;
  3330.           PREV_INSN (last) = insn;
  3331.           last = insn;
  3332.         }
  3333.       SCHED_SORT (ready, new_ready, n_ready);
  3334.       n_ready = new_ready;
  3335.     }
  3336.     }
  3337.   if (q_size != 0)
  3338.     abort ();
  3339.  
  3340.   if (reload_completed == 0)
  3341.     finish_sometimes_live (regs_sometimes_live, sometimes_max);
  3342.  
  3343.   /* HEAD is now the first insn in the chain of insns that
  3344.      been scheduled by the loop above.
  3345.      TAIL is the last of those insns.  */
  3346.   head = insn;
  3347.  
  3348.   /* NOTE_LIST is the end of a chain of notes previously found
  3349.      among the insns.  Insert them at the beginning of the insns.  */
  3350.   if (note_list != 0)
  3351.     {
  3352.       rtx note_head = note_list;
  3353.       while (PREV_INSN (note_head))
  3354.     note_head = PREV_INSN (note_head);
  3355.  
  3356.       PREV_INSN (head) = note_list;
  3357.       NEXT_INSN (note_list) = head;
  3358.       head = note_head;
  3359.     }
  3360.  
  3361.   /* In theory, there should be no REG_DEAD notes leftover at the end.
  3362.      In practice, this can occur as the result of bugs in flow, combine.c,
  3363.      and/or sched.c.  */
  3364. #if 1
  3365.   if (dead_notes != 0)
  3366.     abort ();
  3367. #endif
  3368.  
  3369.   if (new_needs & need_head)
  3370.     basic_block_head[b] = head;
  3371.   PREV_INSN (head) = prev_head;
  3372.   NEXT_INSN (prev_head) = head;
  3373.  
  3374.   if (new_needs & need_tail)
  3375.     basic_block_end[b] = tail;
  3376.   NEXT_INSN (tail) = next_tail;
  3377.   PREV_INSN (next_tail) = tail;
  3378.  
  3379.   /* Restore the line-number notes of each insn.  */
  3380.   if (write_symbols)
  3381.     {
  3382.       rtx line, note, prev, new;
  3383.       int notes = 0;
  3384.  
  3385.       head = basic_block_head[b];
  3386.       next_tail = NEXT_INSN (basic_block_end[b]);
  3387.  
  3388.       /* Determine the current line-number.  We want to know the current
  3389.      line number of the first insn of the block here, in case it is
  3390.      different from the true line number that was saved earlier.  If
  3391.      different, then we need a line number note before the first insn
  3392.      of this block.  If it happens to be the same, then we don't want to
  3393.      emit another line number note here.  */
  3394.       for (line = head; line; line = PREV_INSN (line))
  3395.     if (GET_CODE (line) == NOTE && NOTE_LINE_NUMBER (line) > 0)
  3396.       break;
  3397.  
  3398.       /* Walk the insns keeping track of the current line-number and inserting
  3399.      the line-number notes as needed.  */
  3400.       for (insn = head; insn != next_tail; insn = NEXT_INSN (insn))
  3401.     if (GET_CODE (insn) == NOTE && NOTE_LINE_NUMBER (insn) > 0)
  3402.       line = insn;
  3403.     else if (! (GET_CODE (insn) == NOTE
  3404.             && NOTE_LINE_NUMBER (insn) == NOTE_INSN_DELETED)
  3405.          && (note = LINE_NOTE (insn)) != 0
  3406.          && note != line
  3407.          && (NOTE_LINE_NUMBER (note) != NOTE_LINE_NUMBER (line)
  3408.              || NOTE_SOURCE_FILE (note) != NOTE_SOURCE_FILE (line)))
  3409.       {
  3410.         line = note;
  3411.         prev = PREV_INSN (insn);
  3412.         if (LINE_NOTE (note))
  3413.           {
  3414.         /* Re-use the orignal line-number note. */
  3415.         LINE_NOTE (note) = 0;
  3416.         PREV_INSN (note) = prev;
  3417.         NEXT_INSN (prev) = note;
  3418.         PREV_INSN (insn) = note;
  3419.         NEXT_INSN (note) = insn;
  3420.           }
  3421.         else
  3422.           {
  3423.         notes++;
  3424.         new = emit_note_after (NOTE_LINE_NUMBER (note), prev);
  3425.         NOTE_SOURCE_FILE (new) = NOTE_SOURCE_FILE (note);
  3426.           }
  3427.       }
  3428.       if (file && notes)
  3429.     fprintf (file, ";; added %d line-number notes\n", notes);
  3430.     }
  3431.  
  3432.   if (file)
  3433.     {
  3434.       fprintf (file, ";; new basic block head = %d\n;; new basic block end = %d\n\n",
  3435.            INSN_UID (basic_block_head[b]), INSN_UID (basic_block_end[b]));
  3436.     }
  3437.  
  3438.   /* Yow! We're done!  */
  3439.   free_pending_lists ();
  3440.  
  3441.   return;
  3442. }
  3443.  
  3444. /* Subroutine of split_hard_reg_notes.  Searches X for any reference to
  3445.    REGNO, returning the rtx of the reference found if any.  Otherwise,
  3446.    returns 0.  */
  3447.  
  3448. rtx
  3449. regno_use_in (regno, x)
  3450.      int regno;
  3451.      rtx x;
  3452. {
  3453.   register char *fmt;
  3454.   int i, j;
  3455.   rtx tem;
  3456.  
  3457.   if (GET_CODE (x) == REG && REGNO (x) == regno)
  3458.     return x;
  3459.  
  3460.   fmt = GET_RTX_FORMAT (GET_CODE (x));
  3461.   for (i = GET_RTX_LENGTH (GET_CODE (x)) - 1; i >= 0; i--)
  3462.     {
  3463.       if (fmt[i] == 'e')
  3464.     {
  3465.       if (tem = regno_use_in (regno, XEXP (x, i)))
  3466.         return tem;
  3467.     }
  3468.       else if (fmt[i] == 'E')
  3469.     for (j = XVECLEN (x, i) - 1; j >= 0; j--)
  3470.       if (tem = regno_use_in (regno , XVECEXP (x, i, j)))
  3471.         return tem;
  3472.     }
  3473.  
  3474.   return 0;
  3475. }
  3476.  
  3477. /* Subroutine of update_links.  Determines whether any new REG_NOTEs are
  3478.    needed for the hard register mentioned in the note.  This can happen
  3479.    if the reference to the hard register in the original insn was split into
  3480.    several smaller hard register references in the split insns.  */
  3481.  
  3482. static void
  3483. split_hard_reg_notes (note, first, last, orig_insn)
  3484.      rtx note, first, last, orig_insn;
  3485. {
  3486.   rtx reg, temp, link;
  3487.   int n_regs, i, new_reg;
  3488.   rtx insn;
  3489.  
  3490.   /* Assume that this is a REG_DEAD note.  */
  3491.   if (REG_NOTE_KIND (note) != REG_DEAD)
  3492.     abort ();
  3493.  
  3494.   reg = XEXP (note, 0);
  3495.  
  3496.   n_regs = HARD_REGNO_NREGS (REGNO (reg), GET_MODE (reg));
  3497.  
  3498.   /* ??? Could add check here to see whether, the hard register is referenced
  3499.      in the same mode as in the original insn.  If so, then it has not been
  3500.      split, and the rest of the code below is unnecessary.  */
  3501.  
  3502.   for (i = 1; i < n_regs; i++)
  3503.     {
  3504.       new_reg = REGNO (reg) + i;
  3505.  
  3506.       /* Check for references to new_reg in the split insns.  */
  3507.       for (insn = last; ; insn = PREV_INSN (insn))
  3508.     {
  3509.       if (GET_RTX_CLASS (GET_CODE (insn)) == 'i'
  3510.           && (temp = regno_use_in (new_reg, PATTERN (insn))))
  3511.         {
  3512.           /* Create a new reg dead note here.  */
  3513.           link = rtx_alloc (EXPR_LIST);
  3514.           PUT_REG_NOTE_KIND (link, REG_DEAD);
  3515.           XEXP (link, 0) = temp;
  3516.           XEXP (link, 1) = REG_NOTES (insn);
  3517.           REG_NOTES (insn) = link;
  3518.           break;
  3519.         }
  3520.       /* It isn't mentioned anywhere, so no new reg note is needed for
  3521.          this register.  */
  3522.       if (insn == first)
  3523.         break;
  3524.     }
  3525.     }
  3526. }
  3527.  
  3528. /* Subroutine of update_links.  Determines whether a SET or CLOBBER in an
  3529.    insn created by splitting needs a REG_DEAD or REG_UNUSED note added.  */
  3530.  
  3531. static void
  3532. new_insn_dead_notes (pat, insn, last, orig_insn)
  3533.      rtx pat, insn, last, orig_insn;
  3534. {
  3535.   rtx dest, tem, set;
  3536.  
  3537.   /* PAT is either a CLOBBER or a SET here.  */
  3538.   dest = XEXP (pat, 0);
  3539.  
  3540.   while (GET_CODE (dest) == ZERO_EXTRACT || GET_CODE (dest) == SUBREG
  3541.      || GET_CODE (dest) == STRICT_LOW_PART
  3542.      || GET_CODE (dest) == SIGN_EXTRACT)
  3543.     dest = XEXP (dest, 0);
  3544.  
  3545.   if (GET_CODE (dest) == REG)
  3546.     {
  3547.       for (tem = last; tem != insn; tem = PREV_INSN (tem))
  3548.     {
  3549.       if (GET_RTX_CLASS (GET_CODE (tem)) == 'i'
  3550.           && reg_overlap_mentioned_p (dest, PATTERN (tem))
  3551.           && (set = single_set (tem)))
  3552.         {
  3553.           rtx tem_dest = SET_DEST (set);
  3554.  
  3555.           while (GET_CODE (tem_dest) == ZERO_EXTRACT
  3556.              || GET_CODE (tem_dest) == SUBREG
  3557.              || GET_CODE (tem_dest) == STRICT_LOW_PART
  3558.              || GET_CODE (tem_dest) == SIGN_EXTRACT)
  3559.         tem_dest = XEXP (tem_dest, 0);
  3560.  
  3561.           if (tem_dest != dest)
  3562.         {
  3563.           /* Use the same scheme as combine.c, don't put both REG_DEAD
  3564.              and REG_UNUSED notes on the same insn.  */
  3565.           if (! find_regno_note (tem, REG_UNUSED, REGNO (dest)))
  3566.             {
  3567.               rtx note = rtx_alloc (EXPR_LIST);
  3568.               PUT_REG_NOTE_KIND (note, REG_DEAD);
  3569.               XEXP (note, 0) = dest;
  3570.               XEXP (note, 1) = REG_NOTES (tem);
  3571.               REG_NOTES (tem) = note;
  3572.             }
  3573.           /* The reg only dies in one insn, the last one that uses
  3574.              it.  */
  3575.           break;
  3576.         }
  3577.         }
  3578.     }
  3579.       /* If this is a set, it must die somewhere, unless it is the dest of
  3580.      the original insn, and hence is live after the original insn.  Abort
  3581.      if it isn't supposed to be live after the original insn.
  3582.  
  3583.      If this is a clobber, then just add a REG_UNUSED note.  */
  3584.       if (tem == insn)
  3585.     {
  3586.       int live_after_orig_insn = 0;
  3587.       rtx pattern = PATTERN (orig_insn);
  3588.       int i;
  3589.  
  3590.       if (GET_CODE (pat) == CLOBBER)
  3591.         {
  3592.           rtx note = rtx_alloc (EXPR_LIST);
  3593.           PUT_REG_NOTE_KIND (note, REG_UNUSED);
  3594.           XEXP (note, 0) = dest;
  3595.           XEXP (note, 1) = REG_NOTES (insn);
  3596.           REG_NOTES (insn) = note;
  3597.           return;
  3598.         }
  3599.  
  3600.       /* The original insn could have multiple sets, so search the
  3601.          insn for all sets.  */
  3602.       if (GET_CODE (pattern) == SET)
  3603.         {
  3604.           if (reg_overlap_mentioned_p (dest, SET_DEST (pattern)))
  3605.         live_after_orig_insn = 1;
  3606.         }
  3607.       else if (GET_CODE (pattern) == PARALLEL)
  3608.         {
  3609.           for (i = 0; i < XVECLEN (pattern, 0); i++)
  3610.         if (GET_CODE (XVECEXP (pattern, 0, i)) == SET
  3611.             && reg_overlap_mentioned_p (dest,
  3612.                         SET_DEST (XVECEXP (pattern,
  3613.                                    0, i))))
  3614.           live_after_orig_insn = 1;
  3615.         }
  3616.  
  3617.       if (! live_after_orig_insn)
  3618.         abort ();
  3619.     }
  3620.     }
  3621. }
  3622.  
  3623. /* Updates all flow-analysis related quantities (except
  3624.    basic_block_head and basic_block_end changes).  */
  3625.  
  3626. /* Update flow info by distributing LINKS across the insns between
  3627.    FIRST and LAST (inclusive).  */
  3628. static void
  3629. update_links (links, notes, first, last, orig_insn)
  3630.      rtx links, notes;
  3631.      rtx first, last;
  3632.      rtx orig_insn;
  3633. {
  3634.   rtx insn, note;
  3635.   rtx next;
  3636.   rtx orig_dest, temp;
  3637.   rtx set;
  3638.  
  3639.   for (insn = last; insn != first; insn = PREV_INSN (insn))
  3640.     if (GET_RTX_CLASS (GET_CODE (insn)) == 'i')
  3641.       LOG_LINKS (insn)
  3642.     = gen_rtx (INSN_LIST, QImode,
  3643.            PREV_INSN (insn), LOG_LINKS (insn));
  3644.  
  3645.   LOG_LINKS (first) = links;
  3646.  
  3647.   /* Get and save the destination set by the original insn.  */
  3648.  
  3649.   orig_dest = single_set (orig_insn);
  3650.   if (orig_dest)
  3651.     orig_dest = SET_DEST (orig_dest);
  3652.  
  3653.   /* Move REG_NOTES from the original insn to where they now belong.  */
  3654.  
  3655.   for (note = notes; note; note = next)
  3656.     {
  3657.       next = XEXP (note, 1);
  3658.       switch (REG_NOTE_KIND (note))
  3659.     {
  3660.     case REG_DEAD:
  3661.     case REG_UNUSED:
  3662.       /* Move these notes from the original insn to the last new insn where
  3663.          the register is now set.  */
  3664.  
  3665.       for (insn = last; ; insn = PREV_INSN (insn))
  3666.         {
  3667.           if (GET_RTX_CLASS (GET_CODE (insn)) == 'i'
  3668.           && reg_mentioned_p (XEXP (note, 0), PATTERN (insn)))
  3669.         {
  3670.           XEXP (note, 1) = REG_NOTES (insn);
  3671.           REG_NOTES (insn) = note;
  3672.           /* The reg only dies in one insn, the last one that uses
  3673.              it.  */
  3674.           break;
  3675.         }
  3676.           /* It must die somewhere, fail it we couldn't find where it died.
  3677.  
  3678.          If this is a REG_UNUSED note, then it must be a temporary
  3679.          register that was not needed by this instantiation of the
  3680.          pattern, so we can safely ignore it.  */
  3681.           if (insn == first)
  3682.         {
  3683.           if (REG_NOTE_KIND (note) != REG_UNUSED)
  3684.             abort ();
  3685.  
  3686.           break;
  3687.         }
  3688.         }
  3689.  
  3690.       /* If this note refers to a multiple word hard register, it may
  3691.          have been split into several smaller hard register references.
  3692.          Check to see if there are any new register references that
  3693.          need REG_NOTES added for them.  */
  3694.       temp = XEXP (note, 0);
  3695.       if (REG_NOTE_KIND (note) == REG_DEAD
  3696.           && GET_CODE (temp) == REG
  3697.           && REGNO (temp) < FIRST_PSEUDO_REGISTER
  3698.           && HARD_REGNO_NREGS (REGNO (temp), GET_MODE (temp)))
  3699.         split_hard_reg_notes (note, first, last, orig_insn);
  3700.       break;
  3701.  
  3702.     case REG_WAS_0:
  3703.       /* This note applies to the dest of the original insn.  Find the
  3704.          first new insn that now has the same dest, and move the note
  3705.          there.  */
  3706.  
  3707.       if (! orig_dest)
  3708.         abort ();
  3709.  
  3710.       for (insn = first; ; insn = NEXT_INSN (insn))
  3711.         {
  3712.           if (GET_RTX_CLASS (GET_CODE (insn)) == 'i'
  3713.           && (temp = single_set (insn))
  3714.           && rtx_equal_p (SET_DEST (temp), orig_dest))
  3715.         {
  3716.           XEXP (note, 1) = REG_NOTES (insn);
  3717.           REG_NOTES (insn) = note;
  3718.           /* The reg is only zero before one insn, the first that
  3719.              uses it.  */
  3720.           break;
  3721.         }
  3722.           /* It must be set somewhere, fail if we couldn't find where it
  3723.          was set.  */
  3724.           if (insn == last)
  3725.         abort ();
  3726.         }
  3727.       break;
  3728.  
  3729.     case REG_EQUAL:
  3730.     case REG_EQUIV:
  3731.       /* A REG_EQUIV or REG_EQUAL note on an insn with more than one
  3732.          set is meaningless.  Just drop the note.  */
  3733.       if (! orig_dest)
  3734.         break;
  3735.  
  3736.     case REG_NO_CONFLICT:
  3737.       /* These notes apply to the dest of the original insn.  Find the last
  3738.          new insn that now has the same dest, and move the note there.  */
  3739.  
  3740.       if (! orig_dest)
  3741.         abort ();
  3742.  
  3743.       for (insn = last; ; insn = PREV_INSN (insn))
  3744.         {
  3745.           if (GET_RTX_CLASS (GET_CODE (insn)) == 'i'
  3746.           && (temp = single_set (insn))
  3747.           && rtx_equal_p (SET_DEST (temp), orig_dest))
  3748.         {
  3749.           XEXP (note, 1) = REG_NOTES (insn);
  3750.           REG_NOTES (insn) = note;
  3751.           /* Only put this note on one of the new insns.  */
  3752.           break;
  3753.         }
  3754.  
  3755.           /* The original dest must still be set someplace.  Abort if we
  3756.          couldn't find it.  */
  3757.           if (insn == first)
  3758.         abort ();
  3759.         }
  3760.       break;
  3761.  
  3762.     case REG_LIBCALL:
  3763.       /* Move a REG_LIBCALL note to the first insn created, and update
  3764.          the corresponding REG_RETVAL note.  */
  3765.       XEXP (note, 1) = REG_NOTES (first);
  3766.       REG_NOTES (first) = note;
  3767.  
  3768.       insn = XEXP (note, 0);
  3769.       note = find_reg_note (insn, REG_RETVAL, 0);
  3770.       if (note)
  3771.         XEXP (note, 0) = first;
  3772.       break;
  3773.  
  3774.     case REG_RETVAL:
  3775.       /* Move a REG_RETVAL note to the last insn created, and update
  3776.          the corresponding REG_LIBCALL note.  */
  3777.       XEXP (note, 1) = REG_NOTES (last);
  3778.       REG_NOTES (last) = note;
  3779.  
  3780.       insn = XEXP (note, 0);
  3781.       note = find_reg_note (insn, REG_LIBCALL, 0);
  3782.       if (note)
  3783.         XEXP (note, 0) = last;
  3784.       break;
  3785.  
  3786.     case REG_NONNEG:
  3787.       /* This should be moved to whichever instruction is a JUMP_INSN.  */
  3788.  
  3789.       for (insn = last; ; insn = PREV_INSN (insn))
  3790.         {
  3791.           if (GET_CODE (insn) == JUMP_INSN)
  3792.         {
  3793.           XEXP (note, 1) = REG_NOTES (insn);
  3794.           REG_NOTES (insn) = note;
  3795.           /* Only put this note on one of the new insns.  */
  3796.           break;
  3797.         }
  3798.           /* Fail if we couldn't find a JUMP_INSN.  */
  3799.           if (insn == first)
  3800.         abort ();
  3801.         }
  3802.       break;
  3803.  
  3804.     case REG_INC:
  3805.       /* This should be moved to whichever instruction now has the
  3806.          increment operation.  */
  3807.       abort ();
  3808.  
  3809.     case REG_LABEL:
  3810.       /* Should be moved to the new insn(s) which use the label.  */
  3811.       abort ();
  3812.  
  3813.     case REG_CC_SETTER:
  3814.     case REG_CC_USER:
  3815.       /* These two notes will never appear until after reorg, so we don't
  3816.          have to handle them here.  */
  3817.     default:
  3818.       abort ();
  3819.     }
  3820.     }
  3821.  
  3822.   /* Each new insn created, except the last, has a new set.  If the destination
  3823.      is a register, then this reg is now live across several insns, whereas
  3824.      previously the dest reg was born and died within the same insn.  To
  3825.      reflect this, we now need a REG_DEAD note on the insn where this
  3826.      dest reg dies.
  3827.  
  3828.      Similarly, the new insns may have clobbers that need REG_UNUSED notes.  */
  3829.  
  3830.   for (insn = first; insn != last; insn = NEXT_INSN (insn))
  3831.     {
  3832.       rtx pat;
  3833.       int i;
  3834.  
  3835.       pat = PATTERN (insn);
  3836.       if (GET_CODE (pat) == SET || GET_CODE (pat) == CLOBBER)
  3837.     new_insn_dead_notes (pat, insn, last, orig_insn);
  3838.       else if (GET_CODE (pat) == PARALLEL)
  3839.     {
  3840.       for (i = 0; i < XVECLEN (pat, 0); i++)
  3841.         if (GET_CODE (XVECEXP (pat, 0, i)) == SET
  3842.         || GET_CODE (XVECEXP (pat, 0, i)) == CLOBBER)
  3843.           new_insn_dead_notes (XVECEXP (pat, 0, i), insn, last, orig_insn);
  3844.     }
  3845.     }
  3846.  
  3847.   /* If any insn, except the last, uses the register set by the last insn,
  3848.      then we need a new REG_DEAD note on that insn.  In this case, there
  3849.      would not have been a REG_DEAD note for this register in the original
  3850.      insn because it was used and set within one insn.  */
  3851.  
  3852.   set = single_set (last);
  3853.   if (set)
  3854.     {
  3855.       rtx dest = SET_DEST (set);
  3856.       rtx set;
  3857.  
  3858.       while (GET_CODE (dest) == ZERO_EXTRACT || GET_CODE (dest) == SUBREG
  3859.          || GET_CODE (dest) == STRICT_LOW_PART
  3860.          || GET_CODE (dest) == SIGN_EXTRACT)
  3861.     dest = XEXP (dest, 0);
  3862.  
  3863.       if (GET_CODE (dest) == REG)
  3864.     {
  3865.       for (insn = PREV_INSN (last); ; insn = PREV_INSN (insn))
  3866.         {
  3867.           if (GET_RTX_CLASS (GET_CODE (insn)) == 'i'
  3868.           && reg_mentioned_p (dest, PATTERN (insn))
  3869.           && (set = single_set (insn)))
  3870.         {
  3871.           rtx insn_dest = SET_DEST (set);
  3872.  
  3873.           while (GET_CODE (insn_dest) == ZERO_EXTRACT
  3874.              || GET_CODE (insn_dest) == SUBREG
  3875.              || GET_CODE (insn_dest) == STRICT_LOW_PART
  3876.              || GET_CODE (insn_dest) == SIGN_EXTRACT)
  3877.             insn_dest = XEXP (insn_dest, 0);
  3878.  
  3879.           if (insn_dest != dest)
  3880.             {
  3881.               note = rtx_alloc (EXPR_LIST);
  3882.               PUT_REG_NOTE_KIND (note, REG_DEAD);
  3883.               XEXP (note, 0) = dest;
  3884.               XEXP (note, 1) = REG_NOTES (insn);
  3885.               REG_NOTES (insn) = note;
  3886.               /* The reg only dies in one insn, the last one
  3887.              that uses it.  */
  3888.               break;
  3889.             }
  3890.         }
  3891.           if (insn == first)
  3892.         break;
  3893.         }
  3894.     }
  3895.     }
  3896.  
  3897.   /* If the original dest is modifying a multiple register target, and the
  3898.      original instruction was split such that the original dest is now set
  3899.      by two or more SUBREG sets, then the split insns no longer kill the
  3900.      destination of the original insn.
  3901.  
  3902.      In this case, if there exists an instruction in the same basic block,
  3903.      before the split insn, which uses the original dest, and this use is
  3904.      killed by the original insn, then we must remove the REG_DEAD note on
  3905.      this insn, because it is now superfluous.
  3906.  
  3907.      This does not apply when a hard register gets split, because the code
  3908.      knows how to handle overlapping hard registers properly.  */
  3909.   if (orig_dest && GET_CODE (orig_dest) == REG)
  3910.     {
  3911.       int found_orig_dest = 0;
  3912.       int found_split_dest = 0;
  3913.  
  3914.       for (insn = first; ; insn = NEXT_INSN (insn))
  3915.     {
  3916.       set = single_set (insn);
  3917.       if (set)
  3918.         {
  3919.           if (GET_CODE (SET_DEST (set)) == REG
  3920.           && REGNO (SET_DEST (set)) == REGNO (orig_dest))
  3921.         {
  3922.           found_orig_dest = 1;
  3923.           break;
  3924.         }
  3925.           else if (GET_CODE (SET_DEST (set)) == SUBREG
  3926.                && SUBREG_REG (SET_DEST (set)) == orig_dest)
  3927.         {
  3928.           found_split_dest = 1;
  3929.           break;
  3930.         }
  3931.         }
  3932.  
  3933.       if (insn == last)
  3934.         break;
  3935.     }
  3936.  
  3937.       if (found_split_dest)
  3938.     {
  3939.       /* Search backwards from FIRST, looking for the first insn that uses
  3940.          the original dest.  Stop if we pass a CODE_LABEL or a JUMP_INSN.
  3941.          If we find an insn, and it has a REG_DEAD note, then delete the
  3942.          note.  */
  3943.  
  3944.       for (insn = first; insn; insn = PREV_INSN (insn))
  3945.         {
  3946.           if (GET_CODE (insn) == CODE_LABEL
  3947.           || GET_CODE (insn) == JUMP_INSN)
  3948.         break;
  3949.           else if (GET_RTX_CLASS (GET_CODE (insn)) == 'i'
  3950.                && reg_mentioned_p (orig_dest, insn))
  3951.         {
  3952.           note = find_regno_note (insn, REG_DEAD, REGNO (orig_dest));
  3953.           if (note)
  3954.             remove_note (insn, note);
  3955.         }
  3956.         }
  3957.     }
  3958.       else if (! found_orig_dest)
  3959.     {
  3960.       /* This should never happen.  */
  3961.       abort ();
  3962.     }
  3963.     }
  3964. }
  3965.  
  3966. /* The one entry point in this file.  DUMP_FILE is the dump file for
  3967.    this pass.  */
  3968. void
  3969. schedule_insns (dump_file)
  3970.      FILE *dump_file;
  3971. {
  3972.   int max_uid = MAX_INSNS_PER_SPLIT * (get_max_uid () + 1);
  3973.   int i, b;
  3974.   rtx insn;
  3975.  
  3976.   /* Taking care of this degenerate case makes the rest of
  3977.      this code simpler.  */
  3978.   if (n_basic_blocks == 0)
  3979.     return;
  3980.  
  3981.   /* Create an insn here so that we can hang dependencies off of it later.  */
  3982.   sched_before_next_call = gen_rtx (INSN, VOIDmode, 0, 0, 0, 0, 0, 0, 0);
  3983.  
  3984.   /* Initialize the unused_*_lists.  We can't use the ones left over
  3985.      from the previous function, because gcc has freed that memory.  */
  3986.  
  3987.   if (reload_completed == 0)
  3988.     {
  3989.       unused_insn_list = 0;
  3990.       unused_expr_list = 0;
  3991.     }
  3992.  
  3993.   /* We create no insns here, only reorder them, so we
  3994.      remember how far we can cut back the stack on exit.  */
  3995.  
  3996.   /* Allocate data for this pass.  See comments, above,
  3997.      for what these vectors do.  */
  3998.   insn_priority = (int *) alloca (max_uid * sizeof (int));
  3999.   insn_ref_count = (int *) alloca (max_uid * sizeof (int));
  4000.   insn_dep_target = (rtx *) alloca (max_uid * sizeof (rtx));
  4001.   sched_block_number = (int *) alloca (max_uid * sizeof (rtx));
  4002.  
  4003.   if (reload_completed == 0)
  4004.     {
  4005.       sched_reg_n_deaths = (short *) alloca (max_regno * sizeof (short));
  4006.       sched_reg_n_calls_crossed = (int *) alloca (max_regno * sizeof (int));
  4007.       sched_reg_live_length = (int *) alloca (max_regno * sizeof (int));
  4008.       bb_reg_sets = (regset) alloca (regset_bytes);
  4009.       bb_dead_regs = (regset) alloca (regset_bytes);
  4010.       bb_live_regs = (regset) alloca (regset_bytes);
  4011.       bzero (sched_reg_n_calls_crossed, max_regno * sizeof (int));
  4012.       bzero (sched_reg_live_length, max_regno * sizeof (int));
  4013.       bcopy (reg_n_deaths, sched_reg_n_deaths, max_regno * sizeof (short));
  4014.       init_alias_analysis ();
  4015.     }
  4016.   else
  4017.     {
  4018.       sched_reg_n_deaths = 0;
  4019.       sched_reg_n_calls_crossed = 0;
  4020.       sched_reg_live_length = 0;
  4021.       bb_reg_sets = 0;
  4022.       bb_dead_regs = 0;
  4023.       bb_live_regs = 0;
  4024.       if (! flag_schedule_insns)
  4025.     init_alias_analysis ();
  4026.     }
  4027.  
  4028.   if (write_symbols)
  4029.     {
  4030.       rtx line;
  4031.  
  4032.       line_note = (rtx *) alloca (max_uid * sizeof (rtx));
  4033.       bzero (line_note, max_uid * sizeof (rtx));
  4034.       line_note_head = (rtx *) alloca (n_basic_blocks * sizeof (rtx));
  4035.  
  4036.       /* Determine the line-number at the start of each basic block.
  4037.      This must be computed and saved now, because after a basic block's
  4038.      predecessor has been scheduled, it is impossible to accurately
  4039.      determine the correct line number for the first insn of the block.  */
  4040.      
  4041.       for (b = 0; b < n_basic_blocks; b++)
  4042.     for (line = basic_block_head[b]; line; line = PREV_INSN (line))
  4043.       if (GET_CODE (line) == NOTE && NOTE_LINE_NUMBER (line) > 0)
  4044.         {
  4045.           line_note_head[b] = line;
  4046.           break;
  4047.         }
  4048.     }
  4049.  
  4050.   bzero (insn_priority, max_uid * sizeof (int));
  4051.   bzero (insn_ref_count, max_uid * sizeof (int));
  4052.   bzero (insn_dep_target, max_uid * sizeof (rtx));
  4053.   for (i = 0; i < max_uid; i++)
  4054.     sched_block_number[i] = -1;
  4055.   for (b = 0; b < n_basic_blocks; b++)
  4056.     if (GET_CODE (basic_block_head[b]) == CODE_LABEL)
  4057.       SCHED_BLOCK_NUM (basic_block_head[b]) = b;
  4058.  
  4059.   max_parm_regno = max_parm_reg_num ();
  4060.  
  4061.   /* Schedule each basic block, block by block.  */
  4062.  
  4063.   if (NEXT_INSN (basic_block_end[n_basic_blocks-1]) == 0
  4064.       || (GET_CODE (basic_block_end[n_basic_blocks-1]) != NOTE
  4065.       && GET_CODE (basic_block_end[n_basic_blocks-1]) != CODE_LABEL))
  4066.     emit_note_after (NOTE_INSN_DELETED, basic_block_end[n_basic_blocks-1]);
  4067.  
  4068.   for (b = 0; b < n_basic_blocks; b++)
  4069.     {
  4070.       rtx insn, next;
  4071.       rtx insns;
  4072.  
  4073.       note_list = 0;
  4074.  
  4075.       for (insn = basic_block_head[b]; ; insn = next)
  4076.     {
  4077.       rtx prev;
  4078.       rtx set;
  4079.  
  4080.       /* Can't use `next_real_insn' because that
  4081.          might go across CODE_LABELS and short-out basic blocks.  */
  4082.       next = NEXT_INSN (insn);
  4083.       if (GET_CODE (insn) != INSN)
  4084.         {
  4085.           if (insn == basic_block_end[b])
  4086.         break;
  4087.           continue;
  4088.         }
  4089.  
  4090.       /* Don't split no-op move insns.  These should silently disappear
  4091.          later in final.  Splitting such insns would break the code
  4092.          that handles REG_NO_CONFLICT blocks.  */
  4093.       set = single_set (insn);
  4094.       if (set && rtx_equal_p (SET_SRC (set), SET_DEST (set)))
  4095.         {
  4096.           if (insn == basic_block_end[b])
  4097.         break;
  4098.           continue;
  4099.         }
  4100.  
  4101.       /* Split insns here to get max fine-grain parallelism.  */
  4102.       prev = PREV_INSN (insn);
  4103.       if (reload_completed == 0)
  4104.         {
  4105.           rtx last, first = PREV_INSN (insn);
  4106.           rtx links = LOG_LINKS (insn);
  4107.           rtx notes = REG_NOTES (insn);
  4108.  
  4109.           last = try_split (PATTERN (insn), insn, 1);
  4110.           if (last != insn)
  4111.         {
  4112.           /* try_split returns the NOTE that INSN became.  */
  4113.           first = NEXT_INSN (first);
  4114.           update_links (links, notes, first, last, insn);
  4115.           INSN_DEP_TARGET (insn) = last;
  4116.           PUT_CODE (insn, NOTE);
  4117.           NOTE_SOURCE_FILE (insn) = 0;
  4118.           NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
  4119.           if (insn == basic_block_head[b])
  4120.             basic_block_head[b] = first;
  4121.           if (insn == basic_block_end[b])
  4122.             {
  4123.               basic_block_end[b] = last;
  4124.               break;
  4125.             }
  4126.           /* Redirect NEXT's links, since that's easy here.
  4127.              Other dependencies should redirect through
  4128.              INSN_DEP_TARGET.  */
  4129.           else if (next && GET_CODE (next) == INSN
  4130.                && (links = find_insn_list (insn, LOG_LINKS (next))))
  4131.             XEXP (links, 0) = last;
  4132.         }
  4133.         }
  4134.       if (insn == basic_block_end[b])
  4135.         break;
  4136.     }
  4137.  
  4138.       schedule_block (b, dump_file);
  4139.  
  4140. #ifdef USE_C_ALLOCA
  4141.       alloca (0);
  4142. #endif
  4143.     }
  4144.  
  4145.   if (write_symbols)
  4146.     {
  4147.       rtx line = 0;
  4148.       rtx insn = get_insns ();
  4149.       int active_insn = 0;
  4150.       int notes = 0;
  4151.  
  4152.       /* Walk the insns deleting redundant line-number notes.  Many of these
  4153.      are already present.  The remainder tend to occur at basic
  4154.      block boundaries.  */
  4155.       for (insn = get_last_insn (); insn; insn = PREV_INSN (insn))
  4156.     if (GET_CODE (insn) == NOTE && NOTE_LINE_NUMBER (insn) > 0)
  4157.       {
  4158.         /* If there are no active insns following, INSN is redundant.  */
  4159.         if (active_insn == 0)
  4160.           {
  4161.         notes++;
  4162.         NOTE_SOURCE_FILE (insn) = 0;
  4163.         NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
  4164.           }
  4165.         /* If the line number is unchanged, LINE is redundant.  */
  4166.         else if (line
  4167.              && NOTE_LINE_NUMBER (line) == NOTE_LINE_NUMBER (insn)
  4168.              && NOTE_SOURCE_FILE (line) == NOTE_SOURCE_FILE (insn))
  4169.           {
  4170.         notes++;
  4171.         NOTE_SOURCE_FILE (line) = 0;
  4172.         NOTE_LINE_NUMBER (line) = NOTE_INSN_DELETED;
  4173.         line = insn;
  4174.           }
  4175.         else
  4176.           line = insn;
  4177.         active_insn = 0;
  4178.       }
  4179.     else if (! ((GET_CODE (insn) == NOTE
  4180.              && NOTE_LINE_NUMBER (insn) == NOTE_INSN_DELETED)
  4181.             || (GET_CODE (insn) == INSN
  4182.             && (GET_CODE (PATTERN (insn)) == USE
  4183.                 || GET_CODE (PATTERN (insn)) == CLOBBER))))
  4184.       active_insn++;
  4185.  
  4186.       if (dump_file && notes)
  4187.     fprintf (dump_file, ";; deleted %d line-number notes\n", notes);
  4188.     }
  4189.  
  4190.   if (reload_completed == 0)
  4191.     {
  4192.       int regno;
  4193.       for (regno = 0; regno < max_regno; regno++)
  4194.     if (sched_reg_live_length[regno])
  4195.       {
  4196.         if (dump_file)
  4197.           {
  4198.         if (reg_live_length[regno] > sched_reg_live_length[regno])
  4199.           fprintf (dump_file,
  4200.                ";; register %d life shortened from %d to %d\n",
  4201.                regno, reg_live_length[regno],
  4202.                sched_reg_live_length[regno]);
  4203.         else if (reg_live_length[regno] < sched_reg_live_length[regno])
  4204.           fprintf (dump_file,
  4205.                ";; register %d life extended from %d to %d\n",
  4206.                regno, reg_live_length[regno],
  4207.                sched_reg_live_length[regno]);
  4208.  
  4209.         if (reg_n_calls_crossed[regno]
  4210.             && ! sched_reg_n_calls_crossed[regno])
  4211.           fprintf (dump_file,
  4212.                ";; register %d no longer crosses calls\n", regno);
  4213.         else if (! reg_n_calls_crossed[regno]
  4214.              && sched_reg_n_calls_crossed[regno])
  4215.           fprintf (dump_file,
  4216.                ";; register %d now crosses calls\n", regno);
  4217.           }
  4218.         reg_live_length[regno] = sched_reg_live_length[regno];
  4219.         reg_n_calls_crossed[regno] = sched_reg_n_calls_crossed[regno];
  4220.       }
  4221.     }
  4222. }
  4223. #endif /* INSN_SCHEDULING */
  4224.