home *** CD-ROM | disk | FTP | other *** search
/ Education Sampler 1992 [NeXTSTEP] / Education_1992_Sampler.iso / NeXT / GnuSource / cc-61.0.1 / cc / local-alloc.c < prev    next >
C/C++ Source or Header  |  1991-08-01  |  62KB  |  1,937 lines

  1. /* Allocate registers within a basic block, for GNU compiler.
  2.    Copyright (C) 1987-1991 Free Software Foundation, Inc.
  3.  
  4. This file is part of GNU CC.
  5.  
  6. GNU CC is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2, or (at your option)
  9. any later version.
  10.  
  11. GNU CC is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with GNU CC; see the file COPYING.  If not, write to
  18. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20.  
  21. /* Allocation of hard register numbers to pseudo registers is done in
  22.    two passes.  In this pass we consider only regs that are born and
  23.    die once within one basic block.  We do this one basic block at a
  24.    time.  Then the next pass allocates the registers that remain.
  25.    Two passes are used because this pass uses methods that work only
  26.    on linear code, but that do a better job than the general methods
  27.    used in global_alloc, and more quickly too.
  28.  
  29.    The assignments made are recorded in the vector reg_renumber
  30.    whose space is allocated here.  The rtl code itself is not altered.
  31.  
  32.    We assign each instruction in the basic block a number
  33.    which is its order from the beginning of the block.
  34.    Then we can represent the lifetime of a pseudo register with
  35.    a pair of numbers, and check for conflicts easily.
  36.    We can record the availability of hard registers with a
  37.    HARD_REG_SET for each instruction.  The HARD_REG_SET
  38.    contains 0 or 1 for each hard reg.
  39.  
  40.    To avoid register shuffling, we tie registers together when one
  41.    dies by being copied into another, or dies in an instruction that
  42.    does arithmetic to produce another.  The tied registers are
  43.    allocated as one.  Registers with different reg class preferences
  44.    can never be tied unless the class preferred by one is a subclass
  45.    of the one preferred by the other.
  46.  
  47.    Tying is represented with "quantity numbers".
  48.    A non-tied register is given a new quantity number.
  49.    Tied registers have the same quantity number.
  50.    
  51.    We have provision to exempt registers, even when they are contained
  52.    within the block, that can be tied to others that are not contained in it.
  53.    This is so that global_alloc could process them both and tie them then.
  54.    But this is currently disabled since tying in global_alloc is not
  55.    yet implemented.  */
  56.  
  57. #include <stdio.h>
  58. #include "config.h"
  59. #include "rtl.h"
  60. #include "flags.h"
  61. #include "basic-block.h"
  62. #include "regs.h"
  63. #include "hard-reg-set.h"
  64. #include "insn-config.h"
  65. #include "recog.h"
  66. #include "output.h"
  67.  
  68. /* Next quantity number available for allocation.  */
  69.  
  70. static int next_qty;
  71.  
  72. /* In all the following vectors indexed by quantity number.  */
  73.  
  74. /* Element Q is the hard reg number chosen for quantity Q,
  75.    or -1 if none was found.  */
  76.  
  77. static short *qty_phys_reg;
  78.  
  79. /* We maintain two hard register sets that indicate suggested hard registers
  80.    for each quantity.  The first, qty_phys_copy_sugg, contains hard registers
  81.    that are tied to the quantity by a simple copy.  The second contains all
  82.    hard registers that are tied to the quantity via an arithmetic operation.
  83.  
  84.    The former register set is given priority for allocation.  This tends to
  85.    eliminate copy insns.  */
  86.  
  87. /* Element Q is a set of hard registers that are suggested for quantity Q by
  88.    copy insns.  */
  89.  
  90. static HARD_REG_SET *qty_phys_copy_sugg;
  91.  
  92. /* Element Q is a set of hard registers that are suggested for quantity Q by
  93.    arithmetic insns.  */
  94.  
  95. static HARD_REG_SET *qty_phys_sugg;
  96.  
  97. /* Element Q is non-zero if there is a suggested register in
  98.    qty_phys_copy_sugg.  */
  99.  
  100. static char *qty_phys_has_copy_sugg;
  101.  
  102. /* Element Q is non-zero if there is a suggested register in qty_phys_sugg. */
  103.  
  104. static char *qty_phys_has_sugg;
  105.  
  106. /* Element Q is the number of refs to quantity Q.  */
  107.  
  108. static short *qty_n_refs;
  109.  
  110. /* Element Q is a reg class contained in (smaller than) the
  111.    preferred classes of all the pseudo regs that are tied in quantity Q.
  112.    This is the preferred class for allocating that quantity.  */
  113.  
  114. static enum reg_class *qty_min_class;
  115.  
  116. /* Insn number (counting from head of basic block)
  117.    where quantity Q was born.  -1 if birth has not been recorded.  */
  118.  
  119. static int *qty_birth;
  120.  
  121. /* Insn number (counting from head of basic block)
  122.    where quantity Q died.  Due to the way tying is done,
  123.    and the fact that we consider in this pass only regs that die but once,
  124.    a quantity can die only once.  Each quantity's life span
  125.    is a set of consecutive insns.  -1 if death has not been recorded.  */
  126.  
  127. static int *qty_death;
  128.  
  129. /* Number of words needed to hold the data in quantity Q.
  130.    This depends on its machine mode.  It is used for these purposes:
  131.    1. It is used in computing the relative importances of qtys,
  132.       which determines the order in which we look for regs for them.
  133.    2. It is used in rules that prevent tying several registers of
  134.       different sizes in a way that is geometrically impossible
  135.       (see combine_regs).  */
  136.  
  137. static int *qty_size;
  138.  
  139. /* This holds the mode of the registers that are tied to qty Q,
  140.    or VOIDmode if registers with differing modes are tied together.  */
  141.  
  142. static enum machine_mode *qty_mode;
  143.  
  144. /* Number of times a reg tied to qty Q lives across a CALL_INSN.  */
  145.  
  146. static int *qty_n_calls_crossed;
  147.  
  148. /* Nonzero means don't allocate qty Q if we can't get its preferred class.  */
  149.  
  150. static char *qty_preferred_or_nothing;
  151.  
  152. /* Element Q is the SCRATCH expression for which this quantity is being
  153.    allocated or 0 if this quantity is allocating registers.  */
  154.  
  155. static rtx *qty_scratch_rtx;
  156.  
  157. /* Element Q is the register number of one pseudo register whose
  158.    reg_qty value is Q, or -1 is this quantity is for a SCRATCH.  This
  159.    register should be the head of the chain maintained in reg_next_in_qty.  */
  160.  
  161. static short *qty_first_reg;
  162.  
  163. /* If (REG N) has been assigned a quantity number, is a register number
  164.    of another register assigned the same quantity number, or -1 for the
  165.    end of the chain.  qty_first_reg point to the head of this chain.  */
  166.  
  167. static short *reg_next_in_qty;
  168.  
  169. /* reg_qty[N] (where N is a pseudo reg number) is the qty number of that reg
  170.    if it is >= 0,
  171.    of -1 if this register cannot be allocated by local-alloc,
  172.    or -2 if not known yet.
  173.  
  174.    Note that if we see a use or death of pseudo register N with
  175.    reg_qty[N] == -2, register N must be local to the current block.  If
  176.    it were used in more than one block, we would have reg_qty[N] == -1.
  177.    This relies on the fact that if reg_basic_block[N] is >= 0, register N
  178.    will not appear in any other block.  We save a considerable number of
  179.    tests by exploiting this.
  180.  
  181.    If N is < FIRST_PSEUDO_REGISTER, reg_qty[N] is undefined and should not
  182.    be referenced.  */
  183.  
  184. static int *reg_qty;
  185.  
  186. /* The offset (in words) of register N within its quantity.
  187.    This can be nonzero if register N is SImode, and has been tied
  188.    to a subreg of a DImode register.  */
  189.  
  190. static char *reg_offset;
  191.  
  192. /* Vector of substitutions of register numbers,
  193.    used to map pseudo regs into hardware regs.
  194.    This is set up as a result of register allocation.
  195.    Element N is the hard reg assigned to pseudo reg N,
  196.    or is -1 if no hard reg was assigned.
  197.    If N is a hard reg number, element N is N.  */
  198.  
  199. short *reg_renumber;
  200.  
  201. /* Set of hard registers live at the current point in the scan
  202.    of the instructions in a basic block.  */
  203.  
  204. static HARD_REG_SET regs_live;
  205.  
  206. /* Each set of hard registers indicates registers live at a particular
  207.    point in the basic block.  For N even, regs_live_at[N] says which
  208.    hard registers are needed *after* insn N/2 (i.e., they may not
  209.    conflict with the outputs of insn N/2 or the inputs of insn N/2 + 1.
  210.  
  211.    If an object is to conflict with the inputs of insn J but not the
  212.    outputs of insn J + 1, we say it is born at index J*2 - 1.  Similarly,
  213.    if it is to conflict with the outputs of insn J but not the inputs of
  214.    insn J + 1, it is said to die at index J*2 + 1.  */
  215.  
  216. static HARD_REG_SET *regs_live_at;
  217.  
  218. /* Communicate local vars `insn_number' and `insn'
  219.    from `block_alloc' to `reg_is_set', `wipe_dead_reg', and `alloc_qty'.  */
  220. static int this_insn_number;
  221. static rtx this_insn;
  222.  
  223. static void block_alloc ();
  224. static void update_equiv_regs ();
  225. static int no_conflict_p ();
  226. static int combine_regs ();
  227. static void wipe_dead_reg ();
  228. static int find_free_reg ();
  229. static void reg_is_born ();
  230. static void reg_is_set ();
  231. static void mark_life ();
  232. static void post_mark_life ();
  233. static int qty_compare ();
  234. static int qty_compare_1 ();
  235. static int reg_meets_class_p ();
  236. static void update_qty_class ();
  237. static int requires_inout_p ();
  238.  
  239. /* Allocate a new quantity (new within current basic block)
  240.    for register number REGNO which is born at index BIRTH
  241.    within the block.  MODE and SIZE are info on reg REGNO.  */
  242.  
  243. static void
  244. alloc_qty (regno, mode, size, birth)
  245.      int regno;
  246.      enum machine_mode mode;
  247.      int size, birth;
  248. {
  249.   register int qty = next_qty++;
  250.  
  251.   reg_qty[regno] = qty;
  252.   reg_offset[regno] = 0;
  253.   reg_next_in_qty[regno] = -1;
  254.  
  255.   qty_first_reg[qty] = regno;
  256.   qty_size[qty] = size;
  257.   qty_mode[qty] = mode;
  258.   qty_birth[qty] = birth;
  259.   qty_n_calls_crossed[qty] = reg_n_calls_crossed[regno];
  260.   qty_min_class[qty] = reg_preferred_class (regno);
  261.   qty_preferred_or_nothing[qty] = reg_preferred_or_nothing (regno);
  262.   qty_n_refs[qty] = reg_n_refs[regno];
  263. }
  264.  
  265. /* Similar to `alloc_qty', but allocates a quantity for a SCRATCH rtx
  266.    used as operand N in INSN.  We assume here that the SCRATCH is used in
  267.    a CLOBBER.  */
  268.  
  269. static void
  270. alloc_qty_for_scratch (scratch, n, insn, insn_code_num, insn_number)
  271.      rtx scratch;
  272.      int n;
  273.      rtx insn;
  274.      int insn_code_num, insn_number;
  275. {
  276.   register int qty;
  277.   enum reg_class class;
  278.   char *p, c;
  279.   int i;
  280.  
  281.   /* If we haven't yet computed which alternative will be used, do so now.
  282.      Then set P to the constraints for that alternative.  */
  283.   if (which_alternative == -1)
  284.     if (! constrain_operands (insn_code_num, 0))
  285.       return;
  286.  
  287.   for (p = insn_operand_constraint[insn_code_num][n], i = 0;
  288.        *p && i < which_alternative; p++)
  289.     if (*p == ',')
  290.       i++;
  291.  
  292.   /* Compute the class required for this SCRATCH.  If we don't need a
  293.      register, the class will remain NO_REGS.  If we guessed the alternative
  294.      number incorrectly, reload will fix things up for us.  */
  295.  
  296.   class = NO_REGS;
  297.   while ((c = *p++) != '\0' && c != ',')
  298.     switch (c)
  299.       {
  300.       case '=':  case '+':  case '?':
  301.       case '#':  case '&':  case '!':
  302.       case '*':  case '%':  
  303.       case '0':  case '1':  case '2':  case '3':  case '4':
  304.       case 'm':  case '<':  case '>':  case 'V':  case 'o':
  305.       case 'E':  case 'F':  case 'G':  case 'H':
  306.       case 's':  case 'i':  case 'n':
  307.       case 'I':  case 'J':  case 'K':  case 'L':
  308.       case 'M':  case 'N':  case 'O':  case 'P':
  309.       case 'Q':  case 'R':  case 'S':  case 'T':  case 'U':
  310.       case 'p':
  311.     /* These don't say anything we care about.  */
  312.     break;
  313.  
  314.       case 'X':
  315.     /* We don't need to allocate this SCRATCH.  */
  316.     return;
  317.  
  318.       case 'g': case 'r':
  319.     class = reg_class_subunion[(int) class][(int) GENERAL_REGS];
  320.     break;
  321.  
  322.       default:
  323.     class
  324.       = reg_class_subunion[(int) class][(int) REG_CLASS_FROM_LETTER (c)];
  325.     break;
  326.       }
  327.  
  328.   /* If CLASS has only one register, don't allocate the SCRATCH here since
  329.      it will prevent that register from being used as a spill register.
  330.      reload will do the allocation.  */
  331.  
  332.   if (class == NO_REGS || reg_class_size[(int) class] == 1)
  333.     return;
  334.  
  335.   qty = next_qty++;
  336.  
  337.   qty_first_reg[qty] = -1;
  338.   qty_scratch_rtx[qty] = scratch;
  339.   qty_size[qty] = GET_MODE_SIZE (GET_MODE (scratch));
  340.   qty_mode[qty] = GET_MODE (scratch);
  341.   qty_birth[qty] = 2 * insn_number - 1;
  342.   qty_death[qty] = 2 * insn_number + 1;
  343.   qty_n_calls_crossed[qty] = 0;
  344.   qty_min_class[qty] = class;
  345.   qty_preferred_or_nothing[qty] = 1;
  346.   qty_n_refs[qty] = 1;
  347. }
  348.  
  349. /* Main entry point of this file.  */
  350.  
  351. void
  352. local_alloc ()
  353. {
  354.   register int b, i;
  355.   int max_qty;
  356.  
  357.   /* Leaf functions and non-leaf functions have different needs.
  358.      If defined, let the machine say what kind of ordering we
  359.      should use.  */
  360. #ifdef ORDER_REGS_FOR_LOCAL_ALLOC
  361.   ORDER_REGS_FOR_LOCAL_ALLOC;
  362. #endif
  363.  
  364.   /* Promote REG_EQUAL notes to REG_EQUIV notes and adjust status of affected
  365.      registers.  */
  366.   update_equiv_regs ();
  367.  
  368.   /* This sets the maximum number of quantities we can have.  Quantity
  369.      numbers start at zero and we can have one for each psuedo plus the
  370.      number of SCRATCHs in the largest block, in the worst case.  */
  371.   max_qty = (max_regno - FIRST_PSEUDO_REGISTER) + max_scratch;
  372.  
  373.   /* Allocate vectors of temporary data.
  374.      See the declarations of these variables, above,
  375.      for what they mean.  */
  376.  
  377.   qty_phys_reg = (short *) alloca (max_qty * sizeof (short));
  378.   qty_phys_copy_sugg = (HARD_REG_SET *) alloca (max_qty * sizeof (HARD_REG_SET));
  379.   qty_phys_has_copy_sugg = (char *) alloca (max_qty * sizeof (char));
  380.   qty_phys_sugg = (HARD_REG_SET *) alloca (max_qty * sizeof (HARD_REG_SET));
  381.   qty_phys_has_sugg = (char *) alloca (max_qty * sizeof (char));
  382.   qty_birth = (int *) alloca (max_qty * sizeof (int));
  383.   qty_death = (int *) alloca (max_qty * sizeof (int));
  384.   qty_scratch_rtx = (rtx *) alloca (max_qty * sizeof (rtx));
  385.   qty_first_reg = (short *) alloca (max_qty * sizeof (short));
  386.   qty_size = (int *) alloca (max_qty * sizeof (int));
  387.   qty_mode = (enum machine_mode *) alloca (max_qty * sizeof (enum machine_mode));
  388.   qty_n_calls_crossed = (int *) alloca (max_qty * sizeof (int));
  389.   qty_min_class = (enum reg_class *) alloca (max_qty * sizeof (enum reg_class));
  390.   qty_preferred_or_nothing = (char *) alloca (max_qty);
  391.   qty_n_refs = (short *) alloca (max_qty * sizeof (short));
  392.  
  393.   reg_qty = (int *) alloca (max_regno * sizeof (int));
  394.   reg_offset = (char *) alloca (max_regno * sizeof (char));
  395.   reg_next_in_qty = (short *) alloca (max_regno * sizeof (short));
  396.  
  397.   reg_renumber = (short *) oballoc (max_regno * sizeof (short));
  398.   for (i = 0; i < max_regno; i++)
  399.     reg_renumber[i] = -1;
  400.  
  401.   /* Determine which pseudo-registers can be allocated by local-alloc.
  402.      In general, these are the registers used only in a single block and
  403.      which only die once.  However, if a register's preferred class has only
  404.      one entry, don't allocate this register here unless it is preferred
  405.      or nothing since retry_global_alloc won't be able to move it to
  406.      GENERAL_REGS if a reload register of this class is needed.
  407.  
  408.      We need not be concerned with which block actually uses the register
  409.      since we will never see it outside that block.  */
  410.  
  411.   for (i = FIRST_PSEUDO_REGISTER; i < max_regno; i++)
  412.     {
  413.       if (reg_basic_block[i] >= 0 && reg_n_deaths[i] == 1
  414.       && (reg_preferred_or_nothing (i)
  415.           || reg_class_size[(int) reg_preferred_class (i)] > 1))
  416.     reg_qty[i] = -2;
  417.       else
  418.     reg_qty[i] = -1;
  419.     }
  420.  
  421.   /* Force loop below to initialize entire quantity array.  */
  422.   next_qty = max_qty;
  423.  
  424.   /* Allocate each block's local registers, block by block.  */
  425.  
  426.   for (b = 0; b < n_basic_blocks; b++)
  427.     {
  428.       /* NEXT_QTY indicates which elements of the `qty_...'
  429.      vectors might need to be initialized because they were used
  430.      for the previous block; it is set to the entire array before
  431.      block 0.  Initialize those, with explicit loop if there are few,
  432.      else with bzero and bcopy.  Do not initialize vectors that are
  433.      explicit set by `alloc_qty'.  */
  434.  
  435.       if (next_qty < 6)
  436.     {
  437.       for (i = 0; i < next_qty; i++)
  438.         {
  439.           qty_scratch_rtx[i] = 0;
  440.           CLEAR_HARD_REG_SET (qty_phys_copy_sugg[i]);
  441.           qty_phys_has_copy_sugg[i] = 0;
  442.           CLEAR_HARD_REG_SET (qty_phys_sugg[i]);
  443.           qty_phys_has_sugg[i] = 0;
  444.         }
  445.     }
  446.       else
  447.     {
  448. #define CLEAR(vector)  \
  449.       bzero ((vector), (sizeof (*(vector))) * next_qty);
  450.  
  451.       CLEAR (qty_scratch_rtx);
  452.       CLEAR (qty_phys_copy_sugg);
  453.       CLEAR (qty_phys_has_copy_sugg);
  454.       CLEAR (qty_phys_sugg);
  455.       CLEAR (qty_phys_has_sugg);
  456.     }
  457.  
  458.       next_qty = 0;
  459.  
  460.       block_alloc (b);
  461. #ifdef USE_C_ALLOCA
  462.       alloca (0);
  463. #endif
  464.     }
  465. }
  466.  
  467. /* Depth of loops we are in while in update_equiv_regs.  */
  468. static int loop_depth;
  469.  
  470. /* Used for communication between the following two functions: contains
  471.    a MEM that we wish to ensure remains unchanged.  */
  472. static rtx equiv_mem;
  473.  
  474. /* Set nonzero if EQUIV_MEM is modified.  */
  475. static int equiv_mem_modified;
  476.  
  477. /* If EQUIV_MEM is modified by modifying DEST, indicate that it is modified.
  478.    Called via note_stores.  */
  479.  
  480. static void
  481. validate_equiv_mem_from_store (dest, set)
  482.      rtx dest;
  483.      rtx set;
  484. {
  485.   if ((GET_CODE (dest) == REG
  486.        && reg_overlap_mentioned_p (dest, equiv_mem))
  487.       || (GET_CODE (dest) == MEM
  488.       && true_dependence (dest, equiv_mem)))
  489.     equiv_mem_modified = 1;
  490. }
  491.  
  492. /* Verify that no store between START and the death of REG invalidates
  493.    MEMREF.  MEMREF is invalidated by modifying a register used in MEMREF,
  494.    by storing into an overlapping memory location, or with a CALL_INSN.
  495.  
  496.    Return 1 if MEMREF remains valid.  */
  497.  
  498. static int
  499. validate_equiv_mem (start, reg, memref)
  500.      rtx start;
  501.      rtx reg;
  502.      rtx memref;
  503. {
  504.   rtx insn;
  505.   rtx note;
  506.  
  507.   equiv_mem = memref;
  508.   equiv_mem_modified = 0;
  509.  
  510.   /* If the memory reference has side effects or is volatile, it isn't a
  511.      valid equivalence.  */
  512.   if (side_effects_p (memref))
  513.     return 0;
  514.  
  515.   for (insn = start; insn && ! equiv_mem_modified; insn = NEXT_INSN (insn))
  516.     {
  517.       if (GET_RTX_CLASS (GET_CODE (insn)) != 'i')
  518.     continue;
  519.  
  520.       if (find_reg_note (insn, REG_DEAD, reg))
  521.     return 1;
  522.  
  523.       if (GET_CODE (insn) == CALL_INSN && ! RTX_UNCHANGING_P (memref))
  524.     return 0;
  525.  
  526.       note_stores (PATTERN (insn), validate_equiv_mem_from_store);
  527.  
  528.       /* If a register mentioned in MEMREF is modified via an
  529.      auto-increment, we lose the equivalence.  Do the same if one
  530.      dies; although we could extend the life, it doesn't seem worth
  531.      the trouble.  */
  532.  
  533.       for (note = REG_NOTES (insn); note; note = XEXP (note, 1))
  534.     if ((REG_NOTE_KIND (note) == REG_INC
  535.          || REG_NOTE_KIND (note) == REG_DEAD)
  536.         && GET_CODE (XEXP (note, 0)) == REG
  537.         && reg_overlap_mentioned_p (XEXP (note, 0), memref))
  538.       return 0;
  539.     }
  540.  
  541.   return 0;
  542. }
  543.  
  544. /* TRUE if X references a memory location that would be affected by a store
  545.    to MEMREF.  */
  546.  
  547. static int
  548. memref_referenced_p (memref, x)
  549.      rtx x;
  550.      rtx memref;
  551. {
  552.   int i, j;
  553.   char *fmt;
  554.   enum rtx_code code = GET_CODE (x);
  555.  
  556.   switch (code)
  557.     {
  558.     case REG:
  559.     case CONST_INT:
  560.     case CONST:
  561.     case LABEL_REF:
  562.     case SYMBOL_REF:
  563.     case CONST_DOUBLE:
  564.     case PC:
  565.     case CC0:
  566.     case HIGH:
  567.     case LO_SUM:
  568.       return 0;
  569.  
  570.     case MEM:
  571.       if (true_dependence (memref, x))
  572.     return 1;
  573.       break;
  574.  
  575.     case SET:
  576.       /* If we are setting a MEM, it doesn't count (its address does), but any
  577.      other SET_DEST that has a MEM in it is referencing the MEM.  */
  578.       if (GET_CODE (SET_DEST (x)) == MEM)
  579.     {
  580.       if (memref_referenced_p (memref, XEXP (SET_DEST (x), 0)))
  581.         return 1;
  582.     }
  583.       else if (memref_referenced_p (memref, SET_DEST (x)))
  584.     return 1;
  585.  
  586.       return memref_referenced_p (memref, SET_SRC (x));
  587.     }
  588.  
  589.   fmt = GET_RTX_FORMAT (code);
  590.   for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
  591.     switch (fmt[i])
  592.       {
  593.       case 'e':
  594.     if (memref_referenced_p (memref, XEXP (x, i)))
  595.       return 1;
  596.     break;
  597.       case 'E':
  598.     for (j = XVECLEN (x, i) - 1; j >= 0; j--)
  599.       if (memref_referenced_p (memref, XVECEXP (x, i, j)))
  600.         return 1;
  601.     break;
  602.       }
  603.  
  604.   return 0;
  605. }
  606.  
  607. /* TRUE if some insn in the range (START, END] references a memory location
  608.    that would be affected by a store to MEMREF.  */
  609.  
  610. static int
  611. memref_used_between_p (memref, start, end)
  612.      rtx memref;
  613.      rtx start;
  614.      rtx end;
  615. {
  616.   rtx insn;
  617.  
  618.   for (insn = NEXT_INSN (start); insn != NEXT_INSN (end);
  619.        insn = NEXT_INSN (insn))
  620.     if (GET_RTX_CLASS (GET_CODE (insn)) == 'i'
  621.     && memref_referenced_p (memref, PATTERN (insn)))
  622.       return 1;
  623.  
  624.   return 0;
  625. }
  626.  
  627. /* INSN is a copy from SRC to DEST, both registers, and SRC does not die
  628.    in INSN.
  629.  
  630.    Search forward to see if SRC dies before either it or DEST is modified,
  631.    but don't scan past the end of a basic block.  If so, we can replace SRC
  632.    with DEST and let SRC die in INSN. 
  633.  
  634.    This will reduce the number of registers live in that range and may enable
  635.    DEST to be tied to SRC, thus often saving one register in addition to a
  636.    register-register copy.  */
  637.  
  638. static void
  639. optimize_reg_copy (insn, dest, src)
  640.      rtx insn;
  641.      rtx dest;
  642.      rtx src;
  643. {
  644.   rtx p, q;
  645.   rtx note;
  646.   rtx dest_death = 0;
  647.   int sregno = REGNO (src);
  648.   int dregno = REGNO (dest);
  649.  
  650.   if (sregno == dregno
  651. #ifdef SMALL_REGISTER_CLASSES
  652.       /* We don't want to mess with hard regs if register classes are small. */
  653.       || sregno < FIRST_PSEUDO_REGISTER || dregno < FIRST_PSEUDO_REGISTER
  654. #endif
  655.       /* We don't see all updates to SP if they are in an auto-inc memory
  656.      reference, so we must disallow this optimization on them.  */
  657.       || sregno == STACK_POINTER_REGNUM || dregno == STACK_POINTER_REGNUM)
  658.     return;
  659.  
  660.   for (p = NEXT_INSN (insn); p; p = NEXT_INSN (p))
  661.     {
  662.       if (GET_CODE (p) == CODE_LABEL || GET_CODE (p) == JUMP_INSN
  663.       || (GET_CODE (p) == NOTE
  664.           && (NOTE_LINE_NUMBER (p) == NOTE_INSN_LOOP_BEG
  665.           || NOTE_LINE_NUMBER (p) == NOTE_INSN_LOOP_END)))
  666.     break;
  667.  
  668.       if (GET_RTX_CLASS (GET_CODE (p)) != 'i')
  669.     continue;
  670.  
  671.       if (reg_set_p (src, p) || reg_set_p (dest, p)
  672.       /* Don't change a USE of a register.  */
  673.       || (GET_CODE (PATTERN (p)) == USE
  674.           && reg_overlap_mentioned_p (src, XEXP (PATTERN (p), 0))))
  675.     break;
  676.  
  677.       if ((note = find_regno_note (p, REG_DEAD, sregno)) != 0)
  678.     {
  679.       int failed = 0;
  680.       int length = 0;
  681.       int n_calls = 0;
  682.  
  683.       /* We can do the optimization.  Scan forward from INSN again,
  684.          replacing regs as we go.  Set FAILED if a replacement can't
  685.          be done.  In that case, we can't move the death note for SRC.
  686.          This should be rare.  */
  687.  
  688.       /* Set to stop at next insn.  */
  689.       for (q = next_real_insn (insn);
  690.            q != next_real_insn (p);
  691.            q = next_real_insn (q))
  692.         {
  693.           if (reg_mentioned_p (src, PATTERN (q)))
  694.         {
  695.           if (validate_replace_rtx (src, dest, q))
  696.             {
  697.               /* We assume that a register is used exactly once per
  698.              insn in the updates below.  If this is not correct,
  699.              no great harm is done.  */
  700.               if (sregno >= FIRST_PSEUDO_REGISTER)
  701.             reg_n_refs[sregno] -= loop_depth;
  702.               if (dregno >= FIRST_PSEUDO_REGISTER)
  703.             reg_n_refs[dregno] += loop_depth;
  704.             }
  705.           else
  706.             failed = 1;
  707.         }
  708.  
  709.           /* Count the insns and CALL_INSNs passed.  If we passed the
  710.          death note of DEST, show increased live length.  */
  711.           length++;
  712.           if (dest_death)
  713.         reg_live_length[dregno]++;
  714.  
  715.           if (GET_CODE (q) == CALL_INSN)
  716.         {
  717.           n_calls++;
  718.           if (dest_death)
  719.             reg_n_calls_crossed[dregno]++;
  720.         }
  721.  
  722.           /* If DEST dies here, remove the death note and save it for
  723.          later.  */
  724.           if (dest_death == 0
  725.           && (dest_death = find_regno_note (q, REG_DEAD, dregno)) != 0)
  726.         remove_note (q, dest_death);
  727.         }
  728.  
  729.       if (! failed)
  730.         {
  731.           if (sregno >= FIRST_PSEUDO_REGISTER)
  732.         {
  733.           reg_live_length[sregno] -= length;
  734.           reg_n_calls_crossed[sregno] -= n_calls;
  735.         }
  736.  
  737.           /* Move death note of SRC from P to INSN.  */
  738.           remove_note (p, note);
  739.           XEXP (note, 1) = REG_NOTES (insn);
  740.           REG_NOTES (insn) = note;
  741.         }
  742.  
  743.       /* Put death note of DEST on P if we saw it die.  */
  744.       if (dest_death)
  745.         {
  746.           XEXP (dest_death, 1) = REG_NOTES (p);
  747.           REG_NOTES (p) = dest_death;
  748.         }
  749.  
  750.       return;
  751.     }
  752.     }
  753. }
  754.           
  755. /* Find registers that are equivalent to a single value throughout the
  756.    compilation (either because they can be referenced in memory or are set once
  757.    from a single constant).  Lower their priority for a register.
  758.  
  759.    If such a register is only referenced once, try substituting its value
  760.    into the using insn.  If it succeeds, we can eliminate the register
  761.    completely.  */
  762.  
  763. static void
  764. update_equiv_regs ()
  765. {
  766.   rtx *reg_equiv_init_insn = (rtx *) alloca (max_regno * sizeof (rtx *));
  767.   rtx *reg_equiv_replacement = (rtx *) alloca (max_regno * sizeof (rtx *));
  768.   rtx insn;
  769.  
  770.   bzero (reg_equiv_init_insn, max_regno * sizeof (rtx *));
  771.   bzero (reg_equiv_replacement, max_regno * sizeof (rtx *));
  772.  
  773.   init_alias_analysis ();
  774.  
  775.   loop_depth = 1;
  776.  
  777.   /* Scan the insns and find which registers have equivalences.  Do this
  778.      in a separate scan of the insns because (due to -fcse-follow-jumps)
  779.      a register can be set below its use.  */
  780.   for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
  781.     {
  782.       rtx note;
  783.       rtx set = single_set (insn);
  784.       rtx dest;
  785.       int regno;
  786.  
  787.       if (GET_CODE (insn) == NOTE)
  788.     {
  789.       if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_LOOP_BEG)
  790.         loop_depth++;
  791.       else if (NOTE_LINE_NUMBER (insn) == NOTE_INSN_LOOP_END)
  792.         loop_depth--;
  793.     }
  794.  
  795.       /* If this insn contains more (or less) than a single SET, ignore it.  */
  796.       if (set == 0)
  797.     continue;
  798.  
  799.       dest = SET_DEST (set);
  800.  
  801.       /* If this sets a MEM to the contents of a REG that is only used
  802.      in a single basic block, see if the register is always equivalent
  803.      to that memory location and if moving the store from INSN to the
  804.      insn that set REG is safe.  If so, put a REG_EQUIV note on the
  805.      initializing insn.  */
  806.  
  807.       if (GET_CODE (dest) == MEM && GET_CODE (SET_SRC (set)) == REG
  808.       && (regno = REGNO (SET_SRC (set))) >= FIRST_PSEUDO_REGISTER
  809.       && reg_basic_block[regno] >= 0
  810.       && reg_equiv_init_insn[regno] != 0
  811.       && validate_equiv_mem (reg_equiv_init_insn[regno], SET_SRC (set),
  812.                  dest)
  813.       && ! memref_used_between_p (SET_DEST (set),
  814.                       reg_equiv_init_insn[regno], insn))
  815.     REG_NOTES (reg_equiv_init_insn[regno])
  816.       = gen_rtx (EXPR_LIST, REG_EQUIV, dest,
  817.              REG_NOTES (reg_equiv_init_insn[regno]));
  818.  
  819.       /* If this is a register-register copy where SRC is not dead, see if we
  820.      can optimize it.  */
  821.       if (flag_expensive_optimizations && GET_CODE (dest) == REG
  822.       && GET_CODE (SET_SRC (set)) == REG
  823.       && ! find_reg_note (insn, REG_DEAD, SET_SRC (set)))
  824.     optimize_reg_copy (insn, dest, SET_SRC (set));
  825.  
  826.       /* Otherwise, we only handle the case of a pseudo register being set
  827.      once.  */
  828.       if (GET_CODE (dest) != REG
  829.       || (regno = REGNO (dest)) < FIRST_PSEUDO_REGISTER
  830.       || reg_n_sets[regno] != 1)
  831.     continue;
  832.  
  833.       note = find_reg_note (insn, REG_EQUAL, 0);
  834.  
  835.       /* Record this insn as initializing this register.  */
  836.       reg_equiv_init_insn[regno] = insn;
  837.  
  838.       /* If this register is known to be equal to a constant, record that
  839.      it is always equivalent to the constant.  */
  840.       if (note && CONSTANT_P (XEXP (note, 0)))
  841.     PUT_MODE (note, (enum machine_mode) REG_EQUIV);
  842.  
  843.       /* If this insn introduces a "constant" register, decrease the priority
  844.      of that register.  Record this insn if the register is only used once
  845.      more and the equivalence value is the same as our source.
  846.  
  847.      The latter condition is checked for two reasons:  First, it is an
  848.      indication that it may be more efficient to actually emit the insn
  849.      as written (if no registers are available, reload will substitute
  850.      the equivalence).  Secondly, it avoids problems with any registers
  851.      dying in this insn whose death notes would be missed.
  852.  
  853.      If we don't have a REG_EQUIV note, see if this insn is loading
  854.      a register user only in one basic block from a MEM.  If so, and the
  855.      MEM remains unchanged for the life of the register, add a REG_EQUIV
  856.      note.  */
  857.      
  858.       note = find_reg_note (insn, REG_EQUIV, 0);
  859.  
  860.       if (note == 0 && reg_basic_block[regno] >= 0
  861.       && GET_CODE (SET_SRC (set)) == MEM
  862.       && validate_equiv_mem (insn, dest, SET_SRC (set)))
  863.     REG_NOTES (insn) = note = gen_rtx (EXPR_LIST, REG_EQUIV, SET_SRC (set),
  864.                        REG_NOTES (insn));
  865.  
  866.       /* Don't mess with things live during setjmp.  */
  867.       if (note && reg_live_length[regno] >= 0)
  868.     {
  869.       int regno = REGNO (dest);
  870.  
  871.       /* Note that the statement below does not affect the priority
  872.          in local-alloc!  */
  873.       reg_live_length[regno] *= 2;
  874.  
  875.       /* If the register is referenced exactly twice, meaning it is set
  876.          once and used once, indicate that the reference may be replaced
  877.          by the equivalence we computed above.  If the register is only
  878.          used in one basic block, this can't succeed or combine would
  879.          have done it.
  880.  
  881.          It would be nice to use "loop_depth * 2" in the compare
  882.          below.  Unfortunately, LOOP_DEPTH need not be constant within
  883.          a basic block so this would be too complicated.
  884.  
  885.          This case normally occurs when a parameter is read from memory
  886.          and then used exactly once, not in a loop.  */
  887.  
  888.       if (reg_n_refs[regno] == 2
  889.           && reg_basic_block[regno] < 0
  890.           && rtx_equal_p (XEXP (note, 0), SET_SRC (set)))
  891.         reg_equiv_replacement[regno] = SET_SRC (set);
  892.     }
  893.     }
  894.  
  895.   /* Now scan all regs killed in an insn to see if any of them are registers
  896.      only used that once.  If so, see if we can replace the reference with
  897.      the equivalent from.  If we can, delete the initializing reference
  898.      and this register will go away.  */
  899.   for (insn = next_active_insn (get_insns ());
  900.        insn;
  901.        insn = next_active_insn (insn))
  902.     {
  903.       rtx link;
  904.  
  905.       for (link = REG_NOTES (insn); link; link = XEXP (link, 1))
  906.     if (REG_NOTE_KIND (link) == REG_DEAD
  907.         /* Make sure this insn still refers to the register.  */
  908.         && reg_mentioned_p (XEXP (link, 0), PATTERN (insn)))
  909.       {
  910.         int regno = REGNO (XEXP (link, 0));
  911.  
  912.         if (reg_equiv_replacement[regno]
  913.         && validate_replace_rtx (regno_reg_rtx[regno],
  914.                      reg_equiv_replacement[regno], insn))
  915.           {
  916.         rtx equiv_insn = reg_equiv_init_insn[regno];
  917.  
  918.         remove_death (regno, insn);
  919.         reg_n_refs[regno] = 0;
  920.         PUT_CODE (equiv_insn, NOTE);
  921.         NOTE_LINE_NUMBER (equiv_insn) = NOTE_INSN_DELETED;
  922.         NOTE_SOURCE_FILE (equiv_insn) = 0;
  923.           }
  924.       }
  925.     }
  926. }
  927.  
  928. /* Allocate hard regs to the pseudo regs used only within block number B.
  929.    Only the pseudos that die but once can be handled.  */
  930.  
  931. static void
  932. block_alloc (b)
  933.      int b;
  934. {
  935.   register int i, q;
  936.   register rtx insn;
  937.   rtx note;
  938.   int insn_number = 0;
  939.   int insn_count = 0;
  940.   int max_uid = get_max_uid ();
  941.   short *qty_order;
  942.   int no_conflict_combined_regno = -1;
  943.  
  944.   /* Count the instructions in the basic block.  */
  945.  
  946.   insn = basic_block_end[b];
  947.   while (1)
  948.     {
  949.       if (GET_CODE (insn) != NOTE)
  950.     if (++insn_count > max_uid)
  951.       abort ();
  952.       if (insn == basic_block_head[b])
  953.     break;
  954.       insn = PREV_INSN (insn);
  955.     }
  956.  
  957.   /* +2 to leave room for a post_mark_life at the last insn and for
  958.      the birth of a CLOBBER in the first insn.  */
  959.   regs_live_at = (HARD_REG_SET *) alloca ((2 * insn_count + 2)
  960.                       * sizeof (HARD_REG_SET));
  961.   bzero (regs_live_at, (2 * insn_count + 2) * sizeof (HARD_REG_SET));
  962.  
  963.   /* Initialize table of hardware registers currently live.  */
  964.  
  965. #ifdef HARD_REG_SET
  966.   regs_live = *basic_block_live_at_start[b];
  967. #else
  968.   COPY_HARD_REG_SET (regs_live, basic_block_live_at_start[b]);
  969. #endif
  970.  
  971.   /* This loop scans the instructions of the basic block
  972.      and assigns quantities to registers.
  973.      It computes which registers to tie.  */
  974.  
  975.   insn = basic_block_head[b];
  976.   while (1)
  977.     {
  978.       register rtx body = PATTERN (insn);
  979.  
  980.       if (GET_CODE (insn) != NOTE)
  981.     insn_number++;
  982.  
  983.       if (GET_RTX_CLASS (GET_CODE (insn)) == 'i')
  984.     {
  985.       register rtx link, set;
  986.       register int win = 0;
  987.       register rtx r0, r1;
  988.       int combined_regno = -1;
  989.       int i;
  990.       int insn_code_number = recog_memoized (insn);
  991.  
  992.       this_insn_number = insn_number;
  993.       this_insn = insn;
  994.  
  995.       if (insn_code_number >= 0)
  996.         insn_extract (insn);
  997.       which_alternative = -1;
  998.  
  999.       /* Is this insn suitable for tying two registers?
  1000.          If so, try doing that.
  1001.          Suitable insns are those with at least two operands and where
  1002.          operand 0 is an output that is a register that is not
  1003.          earlyclobber.
  1004.          For a commutative operation, try (set reg0 (arithop ... reg1)).
  1005.          Subregs in place of regs are also ok.
  1006.  
  1007.          If tying is done, WIN is set nonzero.  */
  1008.  
  1009.       if (insn_code_number >= 0
  1010.           && insn_n_operands[insn_code_number] > 1
  1011.           && insn_operand_constraint[insn_code_number][0][0] == '='
  1012.           && insn_operand_constraint[insn_code_number][0][1] != '&')
  1013.         {
  1014.           r0 = recog_operand[0];
  1015.           r1 = recog_operand[1];
  1016.  
  1017.           /* If the first operand is an address, find a register in it.
  1018.          There may be more than one register, but we only try one of
  1019.          them.  */
  1020.           if (insn_operand_constraint[insn_code_number][1][0] == 'p')
  1021.         while (GET_CODE (r1) == PLUS || GET_CODE (r1) == MULT)
  1022.           r1 = XEXP (r1, 0);
  1023.  
  1024.           if (GET_CODE (r0) == REG || GET_CODE (r0) == SUBREG)
  1025.         {
  1026.           /* We have two priorities for hard register preferrences.
  1027.              If we have a move insn or an insn whose first input can
  1028.              only be in the same register as the output, give
  1029.              priority to an equivalence found from that insn.  */
  1030.           int may_save_copy
  1031.             = ((SET_DEST (body) == r0 && SET_SRC (body) == r1)
  1032.                || (r1 == recog_operand[1]
  1033.                && (requires_inout_p (insn_operand_constraint[insn_code_number][1]))));
  1034.  
  1035.           if (GET_CODE (r1) == REG || GET_CODE (r1) == SUBREG)
  1036.             win = combine_regs (r1, r0, may_save_copy,
  1037.                     insn_number, insn, 0);
  1038.  
  1039.           if (win == 0
  1040.               && insn_n_operands[insn_code_number] > 2
  1041.               && insn_operand_constraint[insn_code_number][1][0] == '%'
  1042.               && (r1 = recog_operand[2],
  1043.               GET_CODE (r1) == REG || GET_CODE (r1) == SUBREG))
  1044.             win = combine_regs (r1, r0, may_save_copy,
  1045.                     insn_number, insn, 0);
  1046.         }
  1047.         }
  1048.  
  1049.       /* Recognize an insn sequence with an ultimate result
  1050.          which can safely overlap one of the inputs.
  1051.          The sequence begins with a CLOBBER of its result,
  1052.          and ends with an insn that copies the result to itself
  1053.          and has a REG_EQUAL note for an equivalent formula.
  1054.          That note indicates what the inputs are.
  1055.          The result and the input can overlap if each insn in
  1056.          the sequence either doesn't mention the input
  1057.          or has a REG_NO_CONFLICT note to inhibit the conflict.
  1058.  
  1059.          We do the combining test at the CLOBBER so that the
  1060.          destination register won't have had a quantity number
  1061.          assigned, since that would prevent combining.  */
  1062.  
  1063.       if (GET_CODE (PATTERN (insn)) == CLOBBER
  1064.           && (r0 = XEXP (PATTERN (insn), 0),
  1065.           GET_CODE (r0) == REG)
  1066.           && (link = find_reg_note (insn, REG_LIBCALL, 0)) != 0
  1067.           && GET_CODE (XEXP (link, 0)) == INSN
  1068.           && (set = single_set (XEXP (link, 0))) != 0
  1069.           && SET_DEST (set) == r0 && SET_SRC (set) == r0
  1070.           && (note = find_reg_note (XEXP (link, 0), REG_EQUAL, 0)) != 0)
  1071.         {
  1072.           if (r1 = XEXP (note, 0), GET_CODE (r1) == REG
  1073.           /* Check that we have such a sequence.  */
  1074.           && no_conflict_p (insn, r0, r1))
  1075.         win = combine_regs (r1, r0, 1, insn_number, insn, 1);
  1076.           else if (GET_RTX_FORMAT (GET_CODE (XEXP (note, 0)))[0] == 'e'
  1077.                && (r1 = XEXP (XEXP (note, 0), 0),
  1078.                GET_CODE (r1) == REG || GET_CODE (r1) == SUBREG)
  1079.                && no_conflict_p (insn, r0, r1))
  1080.         win = combine_regs (r1, r0, 0, insn_number, insn, 1);
  1081.  
  1082.           /* Here we care if the operation to be computed is
  1083.          commutative.  */
  1084.           else if ((GET_CODE (XEXP (note, 0)) == EQ
  1085.             || GET_CODE (XEXP (note, 0)) == NE
  1086.             || GET_RTX_CLASS (GET_CODE (XEXP (note, 0))) == 'c')
  1087.                && (r1 = XEXP (XEXP (note, 0), 1),
  1088.                (GET_CODE (r1) == REG || GET_CODE (r1) == SUBREG))
  1089.                && no_conflict_p (insn, r0, r1))
  1090.         win = combine_regs (r1, r0, 0, insn_number, insn, 1);
  1091.  
  1092.           /* If we did combine something, show the register number
  1093.          in question so that we know to ignore its death.  */
  1094.           if (win)
  1095.         no_conflict_combined_regno = REGNO (r1);
  1096.         }
  1097.  
  1098.       /* If registers were just tied, set COMBINED_REGNO
  1099.          to the number of the register used in this insn
  1100.          that was tied to the register set in this insn.
  1101.          This register's qty should not be "killed".  */
  1102.  
  1103.       if (win)
  1104.         {
  1105.           while (GET_CODE (r1) == SUBREG)
  1106.         r1 = SUBREG_REG (r1);
  1107.           combined_regno = REGNO (r1);
  1108.         }
  1109.  
  1110.       /* Mark the death of everything that dies in this instruction,
  1111.          except for anything that was just combined.  */
  1112.  
  1113.       for (link = REG_NOTES (insn); link; link = XEXP (link, 1))
  1114.         if (REG_NOTE_KIND (link) == REG_DEAD
  1115.         && GET_CODE (XEXP (link, 0)) == REG
  1116.         && combined_regno != REGNO (XEXP (link, 0))
  1117.         && (no_conflict_combined_regno != REGNO (XEXP (link, 0))
  1118.             || ! find_reg_note (insn, REG_NO_CONFLICT, XEXP (link, 0))))
  1119.           wipe_dead_reg (XEXP (link, 0), 0);
  1120.  
  1121.       /* Allocate qty numbers for all registers local to this block
  1122.          that are born (set) in this instruction.
  1123.          A pseudo that already has a qty is not changed.  */
  1124.  
  1125.       note_stores (PATTERN (insn), reg_is_set);
  1126.  
  1127.       /* If anything is set in this insn and then unused, mark it as dying
  1128.          after this insn, so it will conflict with our outputs.  This
  1129.          can't match with something that combined, and it doesn't matter
  1130.          if it did.  Do this after the calls to reg_is_set since these
  1131.          die after, not during, the current insn.  */
  1132.  
  1133.       for (link = REG_NOTES (insn); link; link = XEXP (link, 1))
  1134.         if (REG_NOTE_KIND (link) == REG_UNUSED
  1135.         && GET_CODE (XEXP (link, 0)) == REG)
  1136.           wipe_dead_reg (XEXP (link, 0), 1);
  1137.  
  1138.       /* Allocate quantities for any SCRATCH operands of this insn.  */
  1139.       if (insn_code_number >= 0)
  1140.         for (i = 0; i < insn_n_operands[insn_code_number]; i++)
  1141.           if (GET_CODE (recog_operand[i]) == SCRATCH)
  1142.         alloc_qty_for_scratch (recog_operand[i], i, insn,
  1143.                        insn_code_number, insn_number);
  1144.  
  1145.       /* If this is an insn that has a REG_RETVAL note pointing at a 
  1146.          CLOBBER insn, we have reached the end of a REG_NO_CONFLICT
  1147.          block, so clear any register number that combined within it.  */
  1148.       if ((note = find_reg_note (insn, REG_RETVAL, 0)) != 0
  1149.           && GET_CODE (XEXP (note, 0)) == INSN
  1150.           && GET_CODE (PATTERN (XEXP (note, 0))) == CLOBBER)
  1151.         no_conflict_combined_regno = -1;
  1152.     }
  1153.  
  1154.       /* Set the registers live after INSN_NUMBER.  Note that we never
  1155.      record the registers live before the block's first insn, since no
  1156.      pseudos we care about are live before that insn.  */
  1157.  
  1158.       IOR_HARD_REG_SET (regs_live_at[2 * insn_number], regs_live);
  1159.       IOR_HARD_REG_SET (regs_live_at[2 * insn_number + 1], regs_live);
  1160.  
  1161.       if (insn == basic_block_end[b])
  1162.     break;
  1163.  
  1164.       insn = NEXT_INSN (insn);
  1165.     }
  1166.  
  1167.   /* Now every register that is local to this basic block
  1168.      should have been given a quantity, or else -1 meaning ignore it.
  1169.      Every quantity should have a known birth and death.  
  1170.  
  1171.      Order the qtys so we assign them registers in order of 
  1172.      decreasing length of life.  Normally call qsort, but if we 
  1173.      have only a very small number of quantities, sort them ourselves.  */
  1174.  
  1175.   qty_order = (short *) alloca (next_qty * sizeof (short));
  1176.   for (i = 0; i < next_qty; i++)
  1177.     qty_order[i] = i;
  1178.  
  1179. #define EXCHANGE(I1, I2)  \
  1180.   { i = qty_order[I1]; qty_order[I1] = qty_order[I2]; qty_order[I2] = i; }
  1181.  
  1182.   switch (next_qty)
  1183.     {
  1184.     case 3:
  1185.       /* Make qty_order[2] be the one to allocate last.  */
  1186.       if (qty_compare (0, 1) > 0)
  1187.     EXCHANGE (0, 1);
  1188.       if (qty_compare (1, 2) > 0)
  1189.     EXCHANGE (2, 1);
  1190.  
  1191.       /* ... Fall through ... */
  1192.     case 2:
  1193.       /* Put the best one to allocate in qty_order[0].  */
  1194.       if (qty_compare (0, 1) > 0)
  1195.     EXCHANGE (0, 1);
  1196.  
  1197.       /* ... Fall through ... */
  1198.  
  1199.     case 1:
  1200.     case 0:
  1201.       /* Nothing to do here.  */
  1202.       break;
  1203.  
  1204.     default:
  1205.       qsort (qty_order, next_qty, sizeof (short), qty_compare_1);
  1206.     }
  1207.  
  1208.   /* Try to put each quantity in a suggested physical register, if it has one.
  1209.      This may cause registers to be allocated that otherwise wouldn't be, but
  1210.      this seems acceptable in local allocation (unlike global allocation).  */
  1211.   for (i = 0; i < next_qty; i++)
  1212.     {
  1213.       q = qty_order[i];
  1214.       if (qty_phys_has_sugg[q] || qty_phys_has_copy_sugg[q])
  1215.     qty_phys_reg[q] = find_free_reg (qty_min_class[q], qty_mode[q], q,
  1216.                      0, 1, qty_birth[q], qty_death[q]);
  1217.       else
  1218.     qty_phys_reg[q] = -1;
  1219.     }
  1220.  
  1221.   /* Now for each qty that is not a hardware register,
  1222.      look for a hardware register to put it in.
  1223.      First try the register class that is cheapest for this qty,
  1224.      if there is more than one class.  */
  1225.  
  1226.   for (i = 0; i < next_qty; i++)
  1227.     {
  1228.       q = qty_order[i];
  1229.       if (qty_phys_reg[q] < 0)
  1230.     {
  1231.       if (N_REG_CLASSES > 1)
  1232.         {
  1233.           qty_phys_reg[q] = find_free_reg (qty_min_class[q], 
  1234.                            qty_mode[q], q, 0, 0,
  1235.                            qty_birth[q], qty_death[q]);
  1236.           if (qty_phys_reg[q] >= 0)
  1237.         continue;
  1238.         }
  1239.  
  1240.       if (!qty_preferred_or_nothing[q])
  1241.         qty_phys_reg[q] = find_free_reg (GENERAL_REGS, 
  1242.                          qty_mode[q], q, 0, 0,
  1243.                          qty_birth[q], qty_death[q]);
  1244.     }
  1245.     }
  1246.  
  1247.   /* Now propagate the register assignments
  1248.      to the pseudo regs belonging to the qtys.  */
  1249.  
  1250.   for (q = 0; q < next_qty; q++)
  1251.     if (qty_phys_reg[q] >= 0)
  1252.       {
  1253.     for (i = qty_first_reg[q]; i >= 0; i = reg_next_in_qty[i])
  1254.       reg_renumber[i] = qty_phys_reg[q] + reg_offset[i];
  1255.     if (qty_scratch_rtx[q])
  1256.       {
  1257.         PUT_CODE (qty_scratch_rtx[q], REG);
  1258.         REGNO (qty_scratch_rtx[q]) = qty_phys_reg[q];
  1259.         regs_ever_live[qty_phys_reg[q]] = 1;
  1260.       }
  1261.       }
  1262. }
  1263.  
  1264. /* Compare two quantities' priority for getting real registers.
  1265.    We give shorter-lived quantities higher priority.
  1266.    Quantities with more references are also preferred, as are quanties that
  1267.    require multiple registers.  This is the identical prioritorization as
  1268.    done by global-alloc.
  1269.  
  1270.    We used to give preference to registers with *longer* lives, but using
  1271.    the same algorithm in both local- and global-alloc can speed up execution
  1272.    of some programs by as much as a factor of three!  */
  1273.  
  1274. static int
  1275. qty_compare (q1, q2)
  1276.      int q1, q2;
  1277. {
  1278.   /* Note that the quotient will never be bigger than
  1279.      the value of floor_log2 times the maximum number of
  1280.      times a register can occur in one insn (surely less than 100).
  1281.      Multiplying this by 10000 can't overflow.  */
  1282.   register int pri1
  1283.     = (((double) (floor_log2 (qty_n_refs[q1]) * qty_n_refs[q1])
  1284.     / ((qty_death[q1] - qty_birth[q1]) * qty_size[q1]))
  1285.        * 10000);
  1286.   register int pri2
  1287.     = (((double) (floor_log2 (qty_n_refs[q2]) * qty_n_refs[q2])
  1288.     / ((qty_death[q2] - qty_birth[q2]) * qty_size[q2]))
  1289.        * 10000);
  1290.   return pri2 - pri1;
  1291. }
  1292.  
  1293. static int
  1294. qty_compare_1 (q1, q2)
  1295.      short *q1, *q2;
  1296. {
  1297.   register int tem;
  1298.  
  1299.   /* Note that the quotient will never be bigger than
  1300.      the value of floor_log2 times the maximum number of
  1301.      times a register can occur in one insn (surely less than 100).
  1302.      Multiplying this by 10000 can't overflow.  */
  1303.   register int pri1
  1304.     = (((double) (floor_log2 (qty_n_refs[*q1]) * qty_n_refs[*q1])
  1305.     / ((qty_death[*q1] - qty_birth[*q1]) * qty_size[*q1]))
  1306.        * 10000);
  1307.   register int pri2
  1308.     = (((double) (floor_log2 (qty_n_refs[*q2]) * qty_n_refs[*q2])
  1309.     / ((qty_death[*q2] - qty_birth[*q2]) * qty_size[*q2]))
  1310.        * 10000);
  1311.  
  1312.   tem = pri2 - pri1;
  1313.   if (tem != 0) return tem;
  1314.   /* If qtys are equally good, sort by qty number,
  1315.      so that the results of qsort leave nothing to chance.  */
  1316.   return *q1 - *q2;
  1317. }
  1318.  
  1319. /* Attempt to combine the two registers (rtx's) USEDREG and SETREG.
  1320.    Returns 1 if have done so, or 0 if cannot.
  1321.  
  1322.    Combining registers means marking them as having the same quantity
  1323.    and adjusting the offsets within the quantity if either of
  1324.    them is a SUBREG).
  1325.  
  1326.    We don't actually combine a hard reg with a pseudo; instead
  1327.    we just record the hard reg as the suggestion for the pseudo's quantity.
  1328.    If we really combined them, we could lose if the pseudo lives
  1329.    across an insn that clobbers the hard reg (eg, movstr).
  1330.  
  1331.    ALREADY_DEAD is non-zero if USEDREG is known to be dead even though
  1332.    there is no REG_DEAD note on INSN.  This occurs during the processing
  1333.    of REG_NO_CONFLICT blocks.
  1334.  
  1335.    MAY_SAVE_COPYCOPY is non-zero if this insn is simply copying USEDREG to
  1336.    SETREG or if the input and output must share a register.
  1337.    In that case, we record a hard reg suggestion in QTY_PHYS_COPY_SUGG.
  1338.    
  1339.    There are elaborate checks for the validity of combining.  */
  1340.  
  1341.    
  1342. static int
  1343. combine_regs (usedreg, setreg, may_save_copy, insn_number, insn, already_dead)
  1344.      rtx usedreg, setreg;
  1345.      int may_save_copy;
  1346.      int insn_number;
  1347.      rtx insn;
  1348.      int already_dead;
  1349. {
  1350.   register int ureg, sreg;
  1351.   register int offset = 0;
  1352.   int usize, ssize;
  1353.   register int sqty;
  1354.  
  1355.   /* Determine the numbers and sizes of registers being used.  If a subreg
  1356.      is present that does not change the entire register, don't conside
  1357.      this a copy insn.  */
  1358.  
  1359.   while (GET_CODE (usedreg) == SUBREG)
  1360.     {
  1361.       if (GET_MODE_SIZE (GET_MODE (SUBREG_REG (usedreg))) > UNITS_PER_WORD)
  1362.     may_save_copy = 0;
  1363.       offset += SUBREG_WORD (usedreg);
  1364.       usedreg = SUBREG_REG (usedreg);
  1365.     }
  1366.   if (GET_CODE (usedreg) != REG)
  1367.     return 0;
  1368.   ureg = REGNO (usedreg);
  1369.   usize = REG_SIZE (usedreg);
  1370.  
  1371.   while (GET_CODE (setreg) == SUBREG)
  1372.     {
  1373.       if (GET_MODE_SIZE (GET_MODE (SUBREG_REG (setreg))) > UNITS_PER_WORD)
  1374.     may_save_copy = 0;
  1375.       offset -= SUBREG_WORD (setreg);
  1376.       setreg = SUBREG_REG (setreg);
  1377.     }
  1378.   if (GET_CODE (setreg) != REG)
  1379.     return 0;
  1380.   sreg = REGNO (setreg);
  1381.   ssize = REG_SIZE (setreg);
  1382.  
  1383.   /* If UREG is a pseudo-register that hasn't already been assigned a
  1384.      quantity number, it means that it is not local to this block or dies
  1385.      more than once.  In either event, we can't do anything with it.  */
  1386.   if ((ureg >= FIRST_PSEUDO_REGISTER && reg_qty[ureg] < 0)
  1387.       /* Do not combine registers unless one fits within the other.  */
  1388.       || (offset > 0 && usize + offset > ssize)
  1389.       || (offset < 0 && usize + offset < ssize)
  1390.       /* Do not combine with a smaller already-assigned object
  1391.      if that smaller object is already combined with something bigger. */
  1392.       || (ssize > usize && ureg >= FIRST_PSEUDO_REGISTER
  1393.       && usize < qty_size[reg_qty[ureg]])
  1394.       /* Can't combine if SREG is not a register we can allocate.  */
  1395.       || (sreg >= FIRST_PSEUDO_REGISTER && reg_qty[sreg] == -1)
  1396.       /* Don't combine with a pseudo mentioned in a REG_NO_CONFLICT note.
  1397.      These have already been taken care of.  This probably wouldn't
  1398.      combine anyway, but don't take any chances.  */
  1399.       || (ureg >= FIRST_PSEUDO_REGISTER
  1400.       && find_reg_note (insn, REG_NO_CONFLICT, usedreg))
  1401.       /* Don't tie something to itself.  In most cases it would make no
  1402.      difference, but it would screw up if the reg being tied to itself
  1403.      also dies in this insn.  */
  1404.       || ureg == sreg
  1405.       /* Don't try to connect two different hardware registers.  */
  1406.       || (ureg < FIRST_PSEUDO_REGISTER && sreg < FIRST_PSEUDO_REGISTER)
  1407.       /* Don't connect two different machine modes if they have different
  1408.      implications as to which registers may be used.  */
  1409.       || !MODES_TIEABLE_P (GET_MODE (usedreg), GET_MODE (setreg)))
  1410.     return 0;
  1411.  
  1412.   /* Now, if UREG is a hard reg and SREG is a pseudo, record the hard reg in
  1413.      qty_phys_sugg for the pseudo instead of tying them.
  1414.  
  1415.      Return "failure" so that the lifespan of UREG is terminated here;
  1416.      that way the two lifespans will be disjoint and nothing will prevent
  1417.      the pseudo reg from being given this hard reg.  */
  1418.  
  1419.   if (ureg < FIRST_PSEUDO_REGISTER)
  1420.     {
  1421.       /* Allocate a quantity number so we have a place to put our
  1422.      suggestions.  */
  1423.       if (reg_qty[sreg] == -2)
  1424.     reg_is_born (setreg, 2 * insn_number);
  1425.  
  1426.       if (reg_qty[sreg] >= 0)
  1427.     {
  1428.       if (may_save_copy)
  1429.         {
  1430.           SET_HARD_REG_BIT (qty_phys_copy_sugg[reg_qty[sreg]], ureg);
  1431.           qty_phys_has_copy_sugg[reg_qty[sreg]] = 1;
  1432.         }
  1433.       else
  1434.         {
  1435.           SET_HARD_REG_BIT (qty_phys_sugg[reg_qty[sreg]], ureg);
  1436.           qty_phys_has_sugg[reg_qty[sreg]] = 1;
  1437.         }
  1438.     }
  1439.       return 0;
  1440.     }
  1441.  
  1442.   /* Similarly for SREG a hard register and UREG a pseudo register.  */
  1443.  
  1444.   if (sreg < FIRST_PSEUDO_REGISTER)
  1445.     {
  1446.       if (may_save_copy)
  1447.     {
  1448.       SET_HARD_REG_BIT (qty_phys_copy_sugg[reg_qty[ureg]], sreg);
  1449.       qty_phys_has_copy_sugg[reg_qty[ureg]] = 1;
  1450.     }
  1451.       else
  1452.     {
  1453.       SET_HARD_REG_BIT (qty_phys_sugg[reg_qty[ureg]], sreg);
  1454.       qty_phys_has_sugg[reg_qty[ureg]] = 1;
  1455.     }
  1456.       return 0;
  1457.     }
  1458.  
  1459.   /* At this point we know that SREG and UREG are both pseudos.
  1460.      Do nothing if SREG already has a quantity or is a register that we
  1461.      don't allocate.  */
  1462.   if (reg_qty[sreg] >= -1
  1463.       /* If we are not going to let any regs live across calls,
  1464.      don't tie a call-crossing reg to a non-call-crossing reg.  */
  1465.       || (current_function_has_nonlocal_label
  1466.       && ((reg_n_calls_crossed[ureg] > 0)
  1467.           != (reg_n_calls_crossed[sreg] > 0))))
  1468.     return 0;
  1469.  
  1470.   /* We don't already know about SREG, so tie it to UREG
  1471.      if this is the last use of UREG, provided the classes they want
  1472.      are compatible.  */
  1473.  
  1474.   if ((already_dead || find_regno_note (insn, REG_DEAD, ureg))
  1475.       && reg_meets_class_p (sreg, qty_min_class[reg_qty[ureg]]))
  1476.     {
  1477.       /* Add SREG to UREG's quantity.  */
  1478.       sqty = reg_qty[ureg];
  1479.       reg_qty[sreg] = sqty;
  1480.       reg_offset[sreg] = reg_offset[ureg] + offset;
  1481.       reg_next_in_qty[sreg] = qty_first_reg[sqty];
  1482.       qty_first_reg[sqty] = sreg;
  1483.  
  1484.       /* If SREG's reg class is smaller, set qty_min_class[SQTY].  */
  1485.       update_qty_class (sqty, sreg);
  1486.  
  1487.       /* Update info about quantity SQTY.  */
  1488.       qty_n_calls_crossed[sqty] += reg_n_calls_crossed[sreg];
  1489.       qty_n_refs[sqty] += reg_n_refs[sreg];
  1490.       if (! reg_preferred_or_nothing (sreg))
  1491.     qty_preferred_or_nothing[sqty] = 0;
  1492.       if (usize < ssize)
  1493.     {
  1494.       register int i;
  1495.  
  1496.       for (i = qty_first_reg[sqty]; i >= 0; i = reg_next_in_qty[i])
  1497.         reg_offset[i] -= offset;
  1498.  
  1499.       qty_size[sqty] = ssize;
  1500.       qty_mode[sqty] = GET_MODE (setreg);
  1501.     }
  1502.     }
  1503.   else
  1504.     return 0;
  1505.  
  1506.   return 1;
  1507. }
  1508.  
  1509. /* Return 1 if the preferred class of REG allows it to be tied
  1510.    to a quantity or register whose class is CLASS.
  1511.    True if REG's reg class either contains or is contained in CLASS.  */
  1512.  
  1513. static int
  1514. reg_meets_class_p (reg, class)
  1515.      int reg;
  1516.      enum reg_class class;
  1517. {
  1518.   register enum reg_class rclass = reg_preferred_class (reg);
  1519.   return (reg_class_subset_p (rclass, class)
  1520.       || reg_class_subset_p (class, rclass));
  1521. }
  1522.  
  1523. /* Return 1 if the two specified classes have registers in common.
  1524.    If CALL_SAVED, then consider only call-saved registers.  */
  1525.  
  1526. static int
  1527. reg_classes_overlap_p (c1, c2, call_saved)
  1528.      register enum reg_class c1;
  1529.      register enum reg_class c2;
  1530.      int call_saved;
  1531. {
  1532.   HARD_REG_SET c;
  1533.   int i;
  1534.  
  1535.   COPY_HARD_REG_SET (c, reg_class_contents[(int) c1]);
  1536.   AND_HARD_REG_SET (c, reg_class_contents[(int) c2]);
  1537.  
  1538.   for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
  1539.     if (TEST_HARD_REG_BIT (c, i)
  1540.     && (! call_saved || ! call_used_regs[i]))
  1541.       return 1;
  1542.  
  1543.   return 0;
  1544. }
  1545.  
  1546. /* Update the class of QTY assuming that REG is being tied to it.  */
  1547.  
  1548. static void
  1549. update_qty_class (qty, reg)
  1550.      int qty;
  1551.      int reg;
  1552. {
  1553.   enum reg_class rclass = reg_preferred_class (reg);
  1554.   if (reg_class_subset_p (rclass, qty_min_class[qty]))
  1555.     qty_min_class[qty] = rclass;
  1556. }
  1557.  
  1558. /* Handle something which alters the value of an rtx REG.
  1559.  
  1560.    REG is whatever is set or clobbered.  SETTER is the rtx that
  1561.    is modifying the register.
  1562.  
  1563.    If it is not really a register, we do nothing.
  1564.    The file-global variables `this_insn' and `this_insn_number'
  1565.    carry info from `block_alloc'.  */
  1566.  
  1567. static void
  1568. reg_is_set (reg, setter)
  1569.      rtx reg;
  1570.      rtx setter;
  1571. {
  1572.   /* Note that note_stores will only pass us a SUBREG if it is a SUBREG of
  1573.      a hard register.  These may actually not exist any more.  */
  1574.  
  1575.   if (GET_CODE (reg) != SUBREG
  1576.       && GET_CODE (reg) != REG)
  1577.     return;
  1578.  
  1579.   /* Mark this register as being born.  If it is used in a CLOBBER, mark
  1580.      it as being born halfway between the previous insn and this insn so that
  1581.      it conflicts with our inputs but not the outputs of the previous insn.  */
  1582.  
  1583.   reg_is_born (reg, 2 * this_insn_number - (GET_CODE (setter) == CLOBBER));
  1584. }
  1585.  
  1586. /* Handle beginning of the life of register REG.
  1587.    BIRTH is the index at which this is happening.  */
  1588.  
  1589. static void
  1590. reg_is_born (reg, birth)
  1591.      rtx reg;
  1592.      int birth;
  1593. {
  1594.   register int regno;
  1595.      
  1596.   if (GET_CODE (reg) == SUBREG)
  1597.     regno = REGNO (SUBREG_REG (reg)) + SUBREG_WORD (reg);
  1598.   else
  1599.     regno = REGNO (reg);
  1600.  
  1601.   if (regno < FIRST_PSEUDO_REGISTER)
  1602.     {
  1603.       mark_life (regno, GET_MODE (reg), 1);
  1604.  
  1605.       /* If the register was to have been born earlier that the present
  1606.      insn, mark it as live where it is actually born.  */
  1607.       if (birth < 2 * this_insn_number)
  1608.     post_mark_life (regno, GET_MODE (reg), 1, birth, 2 * this_insn_number);
  1609.     }
  1610.   else
  1611.     {
  1612.       if (reg_qty[regno] == -2)
  1613.     alloc_qty (regno, GET_MODE (reg), PSEUDO_REGNO_SIZE (regno), birth);
  1614.  
  1615.       /* If this register has a quantity number, show that it isn't dead.  */
  1616.       if (reg_qty[regno] >= 0)
  1617.     qty_death[reg_qty[regno]] = -1;
  1618.     }
  1619. }
  1620.  
  1621. /* Record the death of REG in the current insn.  If OUTPUT_P is non-zero,
  1622.    REG is an output that is dying (i.e., it is never used), otherwise it
  1623.    is an input (the normal case).  */
  1624.  
  1625. static void
  1626. wipe_dead_reg (reg, output_p)
  1627.      register rtx reg;
  1628.      int output_p;
  1629. {
  1630.   register int regno = REGNO (reg);
  1631.  
  1632.   if (regno < FIRST_PSEUDO_REGISTER)
  1633.     {
  1634.       mark_life (regno, GET_MODE (reg), 0);
  1635.  
  1636.       /* If a hard register is dying as an output, mark it as in use at
  1637.      the beginning of this insn (the above statement would cause this
  1638.      not to happen).  */
  1639.       if (output_p)
  1640.     post_mark_life (regno, GET_MODE (reg), 1,
  1641.             2 * this_insn_number, 2 * this_insn_number+ 1);
  1642.     }
  1643.  
  1644.   else if (reg_qty[regno] >= 0)
  1645.     qty_death[reg_qty[regno]] = 2 * this_insn_number + output_p;
  1646. }
  1647.  
  1648. /* Find a block of SIZE words of hard regs in reg_class CLASS
  1649.    that can hold something of machine-mode MODE
  1650.      (but actually we test only the first of the block for holding MODE)
  1651.    and still free between insn BORN_INDEX and insn DEAD_INDEX,
  1652.    and return the number of the first of them.
  1653.    Return -1 if such a block cannot be found. 
  1654.    If QTY crosses calls, insist on a register preserved by calls,
  1655.    unless ACCEPT_CALL_CLOBBERED is nonzero.
  1656.  
  1657.    If JUST_TRY_SUGGESTED is non-zero, only try to see if the suggested
  1658.    register is available.  If not, return -1.  */
  1659.  
  1660. static int
  1661. find_free_reg (class, mode, qty, accept_call_clobbered, just_try_suggested,
  1662.            born_index, dead_index)
  1663.      enum reg_class class;
  1664.      enum machine_mode mode;
  1665.      int accept_call_clobbered;
  1666.      int just_try_suggested;
  1667.      int qty;
  1668.      int born_index, dead_index;
  1669. {
  1670.   register int i, ins;
  1671. #ifdef HARD_REG_SET
  1672.   register        /* Declare it register if it's a scalar.  */
  1673. #endif
  1674.     HARD_REG_SET used, first_used;
  1675. #ifdef ELIMINABLE_REGS
  1676.   static struct {int from, to; } eliminables[] = ELIMINABLE_REGS;
  1677. #endif
  1678.  
  1679.   /* Validate our parameters.  */
  1680.   if (born_index < 0 || born_index > dead_index)
  1681.     abort ();
  1682.  
  1683.   /* Don't let a pseudo live in a reg across a function call
  1684.      if we might get a nonlocal goto.  */
  1685.   if (current_function_has_nonlocal_label
  1686.       && qty_n_calls_crossed[qty] > 0)
  1687.     return -1;
  1688.  
  1689.   if (accept_call_clobbered)
  1690.     COPY_HARD_REG_SET (used, call_fixed_reg_set);
  1691.   else if (qty_n_calls_crossed[qty] == 0)
  1692.     COPY_HARD_REG_SET (used, fixed_reg_set);
  1693.   else
  1694.     COPY_HARD_REG_SET (used, call_used_reg_set);
  1695.  
  1696.   for (ins = born_index; ins < dead_index; ins++)
  1697.     IOR_HARD_REG_SET (used, regs_live_at[ins]);
  1698.  
  1699.   IOR_COMPL_HARD_REG_SET (used, reg_class_contents[(int) class]);
  1700.  
  1701.   /* Don't use the frame pointer reg in local-alloc even if
  1702.      we may omit the frame pointer, because if we do that and then we
  1703.      need a frame pointer, reload won't know how to move the pseudo
  1704.      to another hard reg.  It can move only regs made by global-alloc.
  1705.  
  1706.      This is true of any register that can be eliminated.  */
  1707. #ifdef ELIMINABLE_REGS
  1708.   for (i = 0; i < sizeof eliminables / sizeof eliminables[0]; i++)
  1709.     SET_HARD_REG_BIT (used, eliminables[i].from);
  1710. #else
  1711.   SET_HARD_REG_BIT (used, FRAME_POINTER_REGNUM);
  1712. #endif
  1713.  
  1714.   /* Normally, the registers that can be used for the first register in
  1715.      a multi-register quantity are the same as those that can be used for
  1716.      subsequent registers.  However, if just trying suggested registers,
  1717.      restrict our consideration to them.  If there are copy-suggested
  1718.      register, try them.  Otherwise, try the arithmetic-suggested
  1719.      registers.  */
  1720.   COPY_HARD_REG_SET (first_used, used);
  1721.  
  1722.   if (just_try_suggested)
  1723.     {
  1724.       if (qty_phys_has_copy_sugg[qty])
  1725.     IOR_COMPL_HARD_REG_SET (first_used, qty_phys_copy_sugg[qty]);
  1726.       else
  1727.     IOR_COMPL_HARD_REG_SET (first_used, qty_phys_sugg[qty]);
  1728.     }
  1729.  
  1730.   /* If all registers are excluded, we can't do anything.  */
  1731.   GO_IF_HARD_REG_SUBSET (reg_class_contents[(int) ALL_REGS], first_used, fail);
  1732.  
  1733.   /* If at least one would be suitable, test each hard reg.  */
  1734.  
  1735.   for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
  1736.     {
  1737. #ifdef REG_ALLOC_ORDER
  1738.       int regno = reg_alloc_order[i];
  1739. #else
  1740.       int regno = i;
  1741. #endif
  1742.       if (! TEST_HARD_REG_BIT (first_used, regno)
  1743.       && HARD_REGNO_MODE_OK (regno, mode))
  1744.     {
  1745.       register int j;
  1746.       register int size1 = HARD_REGNO_NREGS (regno, mode);
  1747.       for (j = 1; j < size1 && ! TEST_HARD_REG_BIT (used, regno + j); j++);
  1748.       if (j == size1)
  1749.         {
  1750.           /* Mark that this register is in use between its birth and death
  1751.          insns.  */
  1752.           post_mark_life (regno, mode, 1, born_index, dead_index);
  1753.           return regno;
  1754.         }
  1755. #ifndef REG_ALLOC_ORDER
  1756.       i += j;        /* Skip starting points we know will lose */
  1757. #endif
  1758.     }
  1759.     }
  1760.  
  1761.  fail:
  1762.  
  1763.   /* If we are just trying suggested register, we have just tried copy-
  1764.      suggested registers, and there are arithmetic-suggested registers,
  1765.      try them.  */
  1766.   
  1767.   /* If it would be profitable to allocate a call-clobbered register
  1768.      and save and restore it around calls, do that.  */
  1769.   if (just_try_suggested && qty_phys_has_copy_sugg[qty]
  1770.       && qty_phys_has_sugg[qty])
  1771.     {
  1772.       /* Don't try the copy-suggested regs again.  */
  1773.       qty_phys_has_copy_sugg[qty] = 0;
  1774.       return find_free_reg (class, mode, qty, accept_call_clobbered, 1,
  1775.                 born_index, dead_index);
  1776.     }
  1777.  
  1778.   if (! accept_call_clobbered
  1779.       && flag_caller_saves
  1780.       && ! just_try_suggested
  1781.       && qty_n_calls_crossed[qty] != 0
  1782.       && CALLER_SAVE_PROFITABLE (qty_n_refs[qty], qty_n_calls_crossed[qty]))
  1783.     {
  1784.       i = find_free_reg (class, mode, qty, 1, 0, born_index, dead_index);
  1785.       if (i >= 0)
  1786.     caller_save_needed = 1;
  1787.       return i;
  1788.     }
  1789.   return -1;
  1790. }
  1791.  
  1792. /* Mark that REGNO with machine-mode MODE is live starting from the current
  1793.    insn (if LIFE is non-zero) or dead starting at the current insn (if LIFE
  1794.    is zero).  */
  1795.  
  1796. static void
  1797. mark_life (regno, mode, life)
  1798.      register int regno;
  1799.      enum machine_mode mode;
  1800.      int life;
  1801. {
  1802.   register int j = HARD_REGNO_NREGS (regno, mode);
  1803.   if (life)
  1804.     while (--j >= 0)
  1805.       SET_HARD_REG_BIT (regs_live, regno + j);
  1806.   else
  1807.     while (--j >= 0)
  1808.       CLEAR_HARD_REG_BIT (regs_live, regno + j);
  1809. }
  1810.  
  1811. /* Mark register number REGNO (with machine-mode MODE) as live (if LIFE
  1812.    is non-zero) or dead (if LIFE is zero) from insn number BIRTH (inclusive)
  1813.    to insn number DEATH (exclusive).  */
  1814.  
  1815. static void
  1816. post_mark_life (regno, mode, life, birth, death)
  1817.      register int regno, life, birth;
  1818.      enum machine_mode mode;
  1819.      int death;
  1820. {
  1821.   register int j = HARD_REGNO_NREGS (regno, mode);
  1822. #ifdef HARD_REG_SET
  1823.   register        /* Declare it register if it's a scalar.  */
  1824. #endif
  1825.     HARD_REG_SET this_reg;
  1826.  
  1827.   CLEAR_HARD_REG_SET (this_reg);
  1828.   while (--j >= 0)
  1829.     SET_HARD_REG_BIT (this_reg, regno + j);
  1830.  
  1831.   if (life)
  1832.     while (birth < death)
  1833.       {
  1834.     IOR_HARD_REG_SET (regs_live_at[birth], this_reg);
  1835.     birth++;
  1836.       }
  1837.   else
  1838.     while (birth < death)
  1839.       {
  1840.     AND_COMPL_HARD_REG_SET (regs_live_at[birth], this_reg);
  1841.     birth++;
  1842.       }
  1843. }
  1844.  
  1845. /* INSN is the CLOBBER insn that starts a REG_NO_NOCONFLICT block, R0
  1846.    is the register being clobbered, and R1 is a register being used in
  1847.    the equivalent expression.
  1848.  
  1849.    If R1 dies in the block and has a REG_NO_CONFLICT note on every insn
  1850.    in which it is used, return 1.
  1851.  
  1852.    Otherwise, return 0.  */
  1853.  
  1854. static int
  1855. no_conflict_p (insn, r0, r1)
  1856.      rtx insn, r0, r1;
  1857. {
  1858.   int ok = 0;
  1859.   rtx note = find_reg_note (insn, REG_LIBCALL, 0);
  1860.   rtx p, last;
  1861.  
  1862.   /* If R1 is a hard register, return 0 since we handle this case
  1863.      when we scan the insns that actually use it.  */
  1864.  
  1865.   if (note == 0
  1866.       || (GET_CODE (r1) == REG && REGNO (r1) < FIRST_PSEUDO_REGISTER)
  1867.       || (GET_CODE (r1) == SUBREG && GET_CODE (SUBREG_REG (r1)) == REG
  1868.       && REGNO (SUBREG_REG (r1)) < FIRST_PSEUDO_REGISTER))
  1869.     return 0;
  1870.  
  1871.   last = XEXP (note, 0);
  1872.  
  1873.   for (p = NEXT_INSN (insn); p && p != last; p = NEXT_INSN (p))
  1874.     if (GET_RTX_CLASS (GET_CODE (p)) == 'i')
  1875.       {
  1876.     if (find_reg_note (p, REG_DEAD, r1))
  1877.       ok = 1;
  1878.  
  1879.     if (reg_mentioned_p (r1, PATTERN (p))
  1880.         && ! find_reg_note (p, REG_NO_CONFLICT, r1))
  1881.       return 0;
  1882.       }
  1883.       
  1884.   return ok;
  1885. }
  1886.  
  1887. /* Return 1 if the constraint string P indicates that the a the operand
  1888.    must be equal to operand 0 and that no register is acceptable.  */
  1889.  
  1890. static int
  1891. requires_inout_p (p)
  1892.      char *p;
  1893. {
  1894.   char c;
  1895.   int found_zero = 0;
  1896.  
  1897.   while (c = *p++)
  1898.     switch (c)
  1899.       {
  1900.       case '0':
  1901.     found_zero = 1;
  1902.     break;
  1903.  
  1904.       case '=':  case '+':  case '?':
  1905.       case '#':  case '&':  case '!':
  1906.       case '*':  case '%':  case ',':
  1907.       case '1':  case '2':  case '3':  case '4':
  1908.       case 'm':  case '<':  case '>':  case 'V':  case 'o':
  1909.       case 'E':  case 'F':  case 'G':  case 'H':
  1910.       case 's':  case 'i':  case 'n':
  1911.       case 'I':  case 'J':  case 'K':  case 'L':
  1912.       case 'M':  case 'N':  case 'O':  case 'P':
  1913.       case 'Q':  case 'R':  case 'S':  case 'T':  case 'U':
  1914.       case 'X':
  1915.     /* These don't say anything we care about.  */
  1916.     break;
  1917.  
  1918.       case 'p':
  1919.       case 'g': case 'r':
  1920.       default:
  1921.     /* These mean a register is allowed.  Fail if so.  */
  1922.     return 0;
  1923.       }
  1924.  
  1925.   return found_zero;
  1926. }
  1927.  
  1928. void
  1929. dump_local_alloc (file)
  1930.      FILE *file;
  1931. {
  1932.   register int i;
  1933.   for (i = FIRST_PSEUDO_REGISTER; i < max_regno; i++)
  1934.     if (reg_renumber[i] != -1)
  1935.       fprintf (file, ";; Register %d in %d.\n", i, reg_renumber[i]);
  1936. }
  1937.