home *** CD-ROM | disk | FTP | other *** search
/ SPACE 2 / SPACE - Library 2 - Volume 1.iso / program / 321 / compsrc3 / reload.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-10-20  |  83.1 KB  |  2,678 lines

  1. /* Search an insn for pseudo regs that must be in hard regs and are not.
  2.    Copyright (C) 1987, 1988 Free Software Foundation, Inc.
  3.  
  4. This file is part of GNU CC.
  5.  
  6. GNU CC is distributed in the hope that it will be useful,
  7. but WITHOUT ANY WARRANTY.  No author or distributor
  8. accepts responsibility to anyone for the consequences of using it
  9. or for whether it serves any particular purpose or works at all,
  10. unless he says so in writing.  Refer to the GNU CC General Public
  11. License for full details.
  12.  
  13. Everyone is granted permission to copy, modify and redistribute
  14. GNU CC, but only under the conditions described in the
  15. GNU CC General Public License.   A copy of this license is
  16. supposed to have been given to you along with GNU CC so you
  17. can know your rights and responsibilities.  It should be in a
  18. file named COPYING.  Among other things, the copyright notice
  19. and this notice must be preserved on all copies.  */
  20.  
  21.  
  22. /* This file contains subroutines used only from the file reload1.c.
  23.    It knows how to scan one insn for operands and values
  24.    that need to be copied into registers to make valid code.
  25.    It also finds other operands and values which are valid
  26.    but for which equivalent values in registers exist and
  27.    ought to be used instead.
  28.  
  29.    Before processing the first insn of the function, call `init_reload'.
  30.  
  31.    To scan an insn, call `find_reloads'.  This does two things:
  32.    1. sets up tables describing which values must be reloaded
  33.    for this insn, and what kind of hard regs they must be reloaded into;
  34.    2. optionally record the locations where those values appear in
  35.    the data, so they can be replaced properly later.
  36.    This is done only if the second arg to `find_reloads' is nonzero.
  37.  
  38.    The third arg to `find_reloads' specifies the value of `indirect_ok'.
  39.  
  40.    Then you must choose the hard regs to reload those pseudo regs into,
  41.    and generate appropriate load insns before this insn and perhaps
  42.    also store insns after this insn.  Set up the array `reload_reg_rtx'
  43.    to contain the REG rtx's for the registers you used.  In some
  44.    cases `find_reloads' will return a nonzero value in `reload_reg_rtx'
  45.    for certain reloads.  Then that tells you which register to use,
  46.    so you do not need to allocate one.  But you still do need to add extra
  47.    instructions to copy the value into and out of that register.
  48.  
  49.    Finally you must call `subst_reloads' to substitute the reload reg rtx's
  50.    into the locations already recorded.
  51.  
  52. NOTE SIDE EFFECTS:
  53.  
  54.    find_reloads can alter the operands of the instruction it is called on.
  55.  
  56.    1. Two operands of any sort may be interchanged, if they are in a
  57.    commutative instruction.
  58.    This happens only if find_reloads thinks the instruction will compile
  59.    better that way.
  60.  
  61.    2. Pseudo-registers that are equivalent to constants are replaced
  62.    with those constants if they are not in hard registers.
  63.  
  64. 1 happens every time find_reloads is called.
  65. 2 happens only when REPLACE is 1, which is only when
  66. actually doing the reloads, not when just counting them.
  67. */
  68.  
  69. #define REG_OK_STRICT
  70.  
  71. #include "config.h"
  72. #include "rtl.h"
  73. #include "insn-config.h"
  74. #include "recog.h"
  75. #include "reload.h"
  76. #include "regs.h"
  77. #include "hard-reg-set.h"
  78.  
  79. /* The variables set up by `find_reloads' are:
  80.  
  81.    n_reloads          number of distinct reloads needed; max reload # + 1
  82.        tables indexed by reload number
  83.    reload_in          rtx for value to reload from
  84.    reload_out          rtx for where to store reload-reg afterward if nec
  85.                (often the same as reload_in)
  86.    reload_reg_class      enum reg_class, saying what regs to reload into
  87.    reload_inmode      enum machine_mode; mode this operand should have
  88.                when reloaded, on input.
  89.    reload_outmode      enum machine_mode; mode this operand should have
  90.                when reloaded, on output.
  91.    reload_strict_low      char; 1 if this reload is inside a STRICT_LOW_PART.
  92.    reload_optional      char, nonzero for an optional reload.
  93.                Optional reloads are ignored unless the
  94.                value is already sitting in a register.
  95.    reload_inc          int, amount to increment reload_in by
  96.                before this insn.
  97.    reload_reg_rtx      rtx.  This is the register to reload into.
  98.                If it is zero when `find_reloads' returns,
  99.                you must find a suitable register in the class
  100.                specified by reload_reg_class, and store here
  101.                an rtx for that register with mode from
  102.                reload_inmode or reload_outmode.
  103.    reload_nocombine      char, nonzero if this reload shouldn't be
  104.                combined with another reload.  */
  105.  
  106. int n_reloads;
  107.  
  108. rtx reload_in[FIRST_PSEUDO_REGISTER];
  109. rtx reload_out[FIRST_PSEUDO_REGISTER];
  110. enum reg_class reload_reg_class[FIRST_PSEUDO_REGISTER];
  111. enum machine_mode reload_inmode[FIRST_PSEUDO_REGISTER];
  112. enum machine_mode reload_outmode[FIRST_PSEUDO_REGISTER];
  113. char reload_strict_low[FIRST_PSEUDO_REGISTER];
  114. rtx reload_reg_rtx[FIRST_PSEUDO_REGISTER];
  115. char reload_optional[FIRST_PSEUDO_REGISTER];
  116. int reload_inc[FIRST_PSEUDO_REGISTER];
  117. char reload_nocombine[FIRST_PSEUDO_REGISTER];
  118.  
  119. /* Replacing reloads.
  120.  
  121.    If `replace_reloads' is nonzero, then as each reload is recorded
  122.    an entry is made for it in the table `replacements'.
  123.    Then later `subst_reloads' can look through that table and
  124.    perform all the replacements needed.  */
  125.  
  126. /* Nonzero means record the places to replace.  */
  127. static int replace_reloads;
  128.  
  129. /* Each replacement is recorded with a structure like this.  */
  130. struct replacement
  131. {
  132.   rtx *where;            /* Location to store in */
  133.   int what;            /* which reload this is for */
  134.   enum machine_mode mode;    /* mode it must have */
  135. };
  136.  
  137. static struct replacement replacements[MAX_RECOG_OPERANDS * ((MAX_REGS_PER_ADDRESS * 2) + 1)];
  138.  
  139. /* Number of replacements currently recorded.  */
  140. static int n_replacements;
  141.  
  142. /* MEM-rtx's created for pseudo-regs in stack slots not directly addressable;
  143.    (see reg_equiv_address).  */
  144. static rtx memlocs[MAX_RECOG_OPERANDS * ((MAX_REGS_PER_ADDRESS * 2) + 1)];
  145. static int n_memlocs;
  146.  
  147. /* The instruction we are doing reloads for;
  148.    so we can test whether a register dies in it.  */
  149. static rtx this_insn;
  150.  
  151. /* Nonzero means (MEM (REG n)) is valid even if (REG n) is spilled.  */
  152. static int indirect_ok;
  153.  
  154. /* If hard_regs_live_known is nonzero,
  155.    we can tell which hard regs are currently live,
  156.    at least enough to succeed in choosing dummy reloads.  */
  157. static int hard_regs_live_known;
  158.  
  159. /* Indexed by hard reg number,
  160.    element is nonegative if hard reg has been spilled.
  161.    This vector is passed to `find_reloads' as an argument
  162.    and is not changed here.  */
  163. static short *static_reload_reg_p;
  164.  
  165. /* Set to 1 in subst_reg_equivs if it changes anything.  */
  166. static int subst_reg_equivs_changed;
  167.  
  168. static int alternative_allows_memconst ();
  169. static rtx find_dummy_reload ();
  170. static rtx find_reloads_toplev ();
  171. static void find_reloads_address ();
  172. static void find_reloads_address_1 ();
  173. static int hard_reg_set_here_p ();
  174. static int refers_to_regno_p ();
  175. static rtx forget_volatility ();
  176. static rtx subst_reg_equivs ();
  177. static rtx subst_indexed_address ();
  178. rtx find_equiv_reg ();
  179. static int find_inc_amount ();
  180.  
  181. /* Record one reload that needs to be performed.
  182.    IN is an rtx saying where the data are to be found before this instruction.
  183.    OUT says where they must be stored after the instruction.
  184.    (IN is zero for data not read, and OUT is zero for data not written.)
  185.    INLOC and OUTLOC point to the places in the instructions where
  186.    IN and OUT were found.
  187.    CLASS is a register class required for the reloaded data.
  188.    INMODE is the machine mode that the instruction requires
  189.    for the reg that replaces IN and OUTMODE is likewise for OUT.
  190.  
  191.    If IN is zero, then OUT's location and mode should be passed as
  192.    INLOC and INMODE.
  193.  
  194.    STRICT_LOW is the 1 if there is a containing STRICT_LOW_PART rtx.
  195.  
  196.    OPTIONAL nonzero means this reload does not need to be performed:
  197.    it can be discarded if that is more convenient.  */
  198.    
  199. static int
  200. push_reload (in, out, inloc, outloc, class,
  201.          inmode, outmode, strict_low, optional)
  202.      register rtx in, out;
  203.      rtx *inloc, *outloc;
  204.      enum reg_class class;
  205.      enum machine_mode inmode, outmode;
  206.      int strict_low;
  207.      int optional;
  208. {
  209.   register int i;
  210.   int noshare = 0;
  211.  
  212.   /* Compare two RTX's.  */
  213. #define MATCHES(x, y) (x == y || (x != 0 && GET_CODE (x) != REG && rtx_equal_p (x, y)))
  214.  
  215.   /* If IN is a pseudo register everywhere-equivalent to a constant, and 
  216.      it is not in a hard register, reload straight from the constant,
  217.      since we want to get rid of such pseudo registers.  */
  218.   if (in != 0 && GET_CODE (in) == REG)
  219.     {
  220.       register int regno = REGNO (in);
  221.  
  222.       if (regno >= FIRST_PSEUDO_REGISTER && reg_renumber[regno] < 0
  223.       && reg_equiv_constant[regno] != 0)
  224.     in = reg_equiv_constant[regno];
  225.     }
  226.  
  227.   /* Likewise for OUT.  Of course, OUT will never be equivalent to
  228.      an actual constant, but it might be equivalent to a memory location
  229.      (in the case of a parameter).  */
  230.   if (out != 0 && GET_CODE (out) == REG)
  231.     {
  232.       register int regno = REGNO (out);
  233.  
  234.       if (regno >= FIRST_PSEUDO_REGISTER && reg_renumber[regno] < 0
  235.       && reg_equiv_constant[regno] != 0)
  236.     out = reg_equiv_constant[regno];
  237.     }
  238.  
  239.   /* If we have a read-write operand with an address side-effect,
  240.      change either IN or OUT so the side-effect happens only once.  */
  241.   if (in != 0 && out != 0 && GET_CODE (in) == MEM && rtx_equal_p (in, out))
  242.     {
  243.       if (GET_CODE (XEXP (in, 0)) == POST_INC
  244.       || GET_CODE (XEXP (in, 0)) == POST_DEC)
  245.     in = gen_rtx (MEM, GET_MODE (in), XEXP (XEXP (in, 0), 0));
  246.       if (GET_CODE (XEXP (in, 0)) == PRE_INC
  247.       || GET_CODE (XEXP (in, 0)) == PRE_DEC)
  248.     out = gen_rtx (MEM, GET_MODE (out), XEXP (XEXP (out, 0), 0));
  249.     }
  250.  
  251.   /* If IN appears in OUT, we can't share any input-only reload for IN.  */
  252.   if (in != 0 && out != 0 && reg_mentioned_p (in, out))
  253.     noshare = 1;
  254.  
  255.   if (class == NO_REGS)
  256.     abort ();
  257.  
  258.   /* Narrow down the class of register wanted if that is
  259.      desirable on this machine for efficiency.  */
  260.   if (in != 0)
  261.     class = PREFERRED_RELOAD_CLASS(in, class);
  262.  
  263.   /* We can use an existing reload if the class is right
  264.      and at least one of IN and OUT is a match
  265.      and the other is at worst neutral.
  266.      (A zero compared against anything is neutral.)  */
  267.   for (i = 0; i < n_reloads; i++)
  268.     if (reload_reg_class[i] == class
  269.     && reload_strict_low[i] == strict_low
  270.     && ((in != 0 && MATCHES (reload_in[i], in) && ! noshare
  271.          && (out == 0 || reload_out[i] == 0 || MATCHES (reload_out[i], out)))
  272.         ||
  273.         (out != 0 && MATCHES (reload_out[i], out)
  274.          && (in == 0 || reload_in[i] == 0 || MATCHES (reload_in[i], in)))))
  275.       break;
  276.  
  277.   if (i == n_reloads)
  278.     {
  279.       /* We found no existing reload suitable for re-use.
  280.      So add an additional reload.  */
  281.  
  282.       reload_in[i] = in;
  283.       reload_out[i] = out;
  284.       reload_reg_class[i] = class;
  285.       reload_inmode[i] = inmode;
  286.       reload_outmode[i] = outmode;
  287.       reload_reg_rtx[i] = 0;
  288.       reload_optional[i] = optional;
  289.       reload_inc[i] = 0;
  290.       reload_strict_low[i] = strict_low;
  291.       reload_nocombine[i] = 0;
  292.  
  293.       n_reloads++;
  294.     }
  295.   else
  296.     {
  297.       /* We are reusing an existing reload,
  298.      but we may have additional information for it.
  299.      For example, we may now have both IN and OUT
  300.      while the old one may have just one of them.  */
  301.  
  302.       if (inmode != VOIDmode)
  303.     reload_inmode[i] = inmode;
  304.       if (outmode != VOIDmode)
  305.     reload_outmode[i] = outmode;
  306.       if (in != 0)
  307.     reload_in[i] = in;
  308.       if (out != 0)
  309.     reload_out[i] = out;
  310.       reload_optional[i] &= optional;
  311.     }
  312.  
  313.   /* If the ostensible rtx being reload differs from the rtx found
  314.      in the location to substitute, this reload is not safe to combine
  315.      because we cannot reliably tell whether it appears in the insn.  */
  316.  
  317.   if (in != 0 && in != *inloc)
  318.     reload_nocombine[i] = 1;
  319.  
  320.   /* If this is an IN/OUT reload in an insn that sets the CC,
  321.      it must be for an autoincrement.  It doesn't work to store
  322.      the incremented value after the insn because that would clobber the CC.
  323.      So we must do the increment of the value reloaded from,
  324.      increment it, store it back, then decrement again.  */
  325.   if (out != 0 && GET_CODE (PATTERN (this_insn)) == SET
  326.       && SET_DEST (PATTERN (this_insn)) == cc0_rtx)
  327.     {
  328.       out = 0;
  329.       reload_out[i] = 0;
  330.       reload_inc[i] = find_inc_amount (PATTERN (this_insn), in);
  331.       /* If we did not find a nonzero amount-to-increment-by,
  332.      that contradicts the belief that IN is being incremented
  333.      in an address in this insn.  */
  334.       if (reload_inc[i] == 0)
  335.     abort ();
  336.     }
  337.  
  338.   /* If we will replace IN and OUT with the reload-reg,
  339.      record where they are located so that substitution need
  340.      not do a tree walk.  */
  341.  
  342.   if (replace_reloads)
  343.     {
  344.       if (inloc != 0)
  345.     {
  346.       register struct replacement *r = &replacements[n_replacements++];
  347.       r->what = i;
  348.       r->where = inloc;
  349.       r->mode = inmode;
  350.     }
  351.       if (outloc != 0 && outloc != inloc)
  352.     {
  353.       register struct replacement *r = &replacements[n_replacements++];
  354.       r->what = i;
  355.       r->where = outloc;
  356.       r->mode = outmode;
  357.     }
  358.     }
  359.  
  360.   /* If this reload is just being introduced and it has both
  361.      an incoming quantity and an outgoing quantity that are
  362.      supposed to be made to match, see if either one of the two
  363.      can serve as the place to reload into.
  364.  
  365.      If one of them is acceptable, set reload_reg_rtx[i]
  366.      to that one.  */
  367.  
  368.   if (in != 0 && out != 0 && in != out && reload_reg_rtx[i] == 0)
  369.     {
  370.       reload_reg_rtx[i] = find_dummy_reload (in, out, inloc, outloc,
  371.                          reload_reg_class[i], i);
  372.  
  373.       /* If the outgoing register already contains the same value
  374.      as the incoming one, we can dispense with loading it.
  375.      The easiest way to tell the caller that is to give a phony
  376.      value for the incoming operand (same as outgoing one).  */
  377.       if (reload_reg_rtx[i] == out
  378.       && (GET_CODE (in) == REG || CONSTANT_P (in))
  379.       && 0 != find_equiv_reg (in, this_insn, 0, REGNO (out),
  380.                   static_reload_reg_p, i, inmode))
  381.     reload_in[i] = out;
  382.     }
  383.  
  384.   return i;
  385. }
  386.  
  387. /* Record an additional place we must replace a value
  388.    for which we have already recorded a reload.
  389.    RELOADNUM is the value returned by push_reload
  390.    when the reload was recorded.
  391.    This is used in insn patterns that use match_dup.  */
  392.  
  393. static void
  394. push_replacement (loc, reloadnum, mode)
  395.      rtx *loc;
  396.      int reloadnum;
  397.      enum machine_mode mode;
  398. {
  399.   if (replace_reloads)
  400.     {
  401.       register struct replacement *r = &replacements[n_replacements++];
  402.       r->what = reloadnum;
  403.       r->where = loc;
  404.       r->mode = mode;
  405.     }
  406. }
  407.  
  408. /* If there is only one output reload, try to combine it
  409.    with a (logically unrelated) input reload
  410.    to reduce the number of reload registers needed.
  411.  
  412.    This is safe if the input reload does not appear in
  413.    the value being output-reloaded, because this implies
  414.    it is not needed any more once the original insn completes.  */
  415.  
  416. static void
  417. combine_reloads ()
  418. {
  419.   int i;
  420.   int output_reload = -1;
  421.  
  422.   /* Find the output reload; return unless there is exactly one
  423.      and that one is mandatory.  */
  424.  
  425.   for (i = 0; i < n_reloads; i++)
  426.     if (reload_out[i] != 0)
  427.       {
  428.     if (output_reload >= 0)
  429.       return;
  430.     output_reload = i;
  431.       }
  432.  
  433.   if (output_reload < 0 || reload_optional[output_reload])
  434.     return;
  435.  
  436.   /* An input-output reload isn't combinable.  */
  437.  
  438.   if (reload_in[output_reload] != 0)
  439.     return;
  440.  
  441.   /* Check each input reload; can we combine it?  */
  442.  
  443.   for (i = 0; i < n_reloads; i++)
  444.     if (reload_in[i] && ! reload_optional[i] && ! reload_nocombine[i]
  445.     && reload_inmode[i] == reload_outmode[output_reload]
  446.     && reload_inc[i] == 0
  447.     && reload_reg_rtx[i] == 0
  448.     && reload_strict_low[i] == 0
  449.     && reload_reg_class[i] == reload_reg_class[output_reload]
  450.     && ! reg_mentioned_p (reload_in[i], reload_out[output_reload]))
  451.       {
  452.     int j;
  453.  
  454.     /* We have found a reload to combine with!  */
  455.     reload_out[i] = reload_out[output_reload];
  456.     reload_outmode[i] = reload_outmode[output_reload];
  457.     /* Mark the old output reload as inoperative.  */
  458.     reload_out[output_reload] = 0;
  459.  
  460.     /* Transfer all replacements from the old reload to the combined.  */
  461.     for (j = 0; j < n_replacements; j++)
  462.       if (replacements[j].what == output_reload)
  463.         replacements[j].what = i;
  464.  
  465.     return;
  466.       }
  467. }
  468.  
  469. /* Try to find a reload register for an in-out reload (expressions IN and OUT).
  470.    See if one of IN and OUT is a register that may be used;
  471.    this is desirable since a spill-register won't be needed.
  472.    If so, return the register rtx that proves acceptable.
  473.  
  474.    INLOC and OUTLOC are locations where IN and OUT appear in the insn.
  475.    CLASS is the register class required for the reload.
  476.  
  477.    If FOR_REAL is >= 0, it is the number of the reload,
  478.    and in some cases when it can be discovered that OUT doesn't need
  479.    to be computed, clear out reload_out[FOR_REAL].
  480.  
  481.    If FOR_REAL is -1, this should not be done, because this call
  482.    is just to see if a register can be found, not to find and install it.  */
  483.  
  484. static rtx
  485. find_dummy_reload (in, out, inloc, outloc, class, for_real)
  486.      rtx in, out;
  487.      rtx *inloc, *outloc;
  488.      enum reg_class class;
  489.      int for_real;
  490. {
  491.   rtx value = 0;
  492.   rtx orig_in = in;
  493.  
  494.   while (GET_CODE (out) == SUBREG)
  495.     out = SUBREG_REG (out);
  496.   while (GET_CODE (in) == SUBREG)
  497.     in = SUBREG_REG (in);
  498.  
  499.   /* If operands exceed a word, we can't use either of them
  500.      unless they have the same size.  */
  501.   if (GET_MODE_SIZE (GET_MODE (out)) != GET_MODE_SIZE (GET_MODE (in))
  502.       && (GET_MODE_SIZE (GET_MODE (out)) > UNITS_PER_WORD
  503.       || GET_MODE_SIZE (GET_MODE (in)) > UNITS_PER_WORD))
  504.     return 0;
  505.  
  506.   /* See if OUT will do.  */
  507.   if (GET_CODE (out) == REG)
  508.     {
  509.       register int regno = REGNO (out);
  510.  
  511.       /* When we consider whether the insn uses OUT,
  512.      ignore references within IN.  They don't prevent us
  513.      from copying IN into OUT, because those refs would
  514.      move into the insn that reloads IN.
  515.  
  516.      However, we only ignore IN in its role as this operand.
  517.      If the insn uses IN elsewhere and it contains OUT,
  518.      that counts.  We can't be sure it's the "same" operand
  519.      so it might not go through this reload.  */
  520.       *inloc = const0_rtx;
  521.  
  522.       if (reg_renumber[regno] >= 0)
  523.     regno = reg_renumber[regno];
  524.       if (regno < FIRST_PSEUDO_REGISTER
  525.       && ! refers_to_regno_p (regno, PATTERN (this_insn), outloc)
  526.       && TEST_HARD_REG_BIT (reg_class_contents[(int) class], regno))
  527.     value = out;
  528.  
  529.       *inloc = orig_in;
  530.     }
  531.  
  532.   /* Consider using IN if OUT was not acceptable
  533.      or if OUT dies in this insn (like the quotient in a divmod insn).
  534.      We can't use IN unless it is free after this insn,
  535.      which means we must know accurately which hard regs are live.
  536.      Also, the result can't go in IN if IN is used within OUT.  */
  537.   if (hard_regs_live_known
  538.       && GET_CODE (in) == REG
  539.       && (value == 0
  540.       || find_regno_note (this_insn, REG_DEAD, REGNO (value))))
  541.     {
  542.       register int regno = REGNO (in);
  543.       if (find_regno_note (this_insn, REG_DEAD, regno))
  544.     {
  545.       if (reg_renumber[regno] >= 0)
  546.         regno = reg_renumber[regno];
  547.       if (regno < FIRST_PSEUDO_REGISTER
  548.           && ! refers_to_regno_p (regno, out, 0)
  549.           && ! hard_reg_set_here_p (regno, PATTERN (this_insn))
  550.           && TEST_HARD_REG_BIT (reg_class_contents[(int) class], regno))
  551.         {
  552.           /* If we were going to use OUT as the reload reg
  553.          and changed our mind, it means OUT is a dummy that
  554.          dies here.  So don't bother copying value to it.  */
  555.           if (for_real >= 0 && value == out)
  556.         reload_out[for_real] = 0;
  557.           value = in;
  558.         }
  559.     }
  560.     }
  561.  
  562.   return value;
  563. }
  564.  
  565. /* This page contains subroutines used mainly for determining
  566.    whether the IN or an OUT of a reload can serve as the
  567.    reload register.  */
  568.  
  569. /* Return 1 if hard reg number REGNO is stored in by expression X,
  570.    either explicitly or in the guise of a pseudo-reg allocated to REGNO.
  571.    X should be the body of an instruction.  */
  572.  
  573. static int
  574. hard_reg_set_here_p (regno, x)
  575.      register int regno;
  576.      rtx x;
  577. {
  578.   if (GET_CODE (x) == SET)
  579.     {
  580.       register rtx op0 = SET_DEST (x);
  581.       if (GET_CODE (op0) == REG)
  582.     {
  583.       register int r = REGNO (op0);
  584.       if (reg_renumber[r] >= 0)
  585.         r = reg_renumber[r];
  586.       if (r == regno)
  587.         return 1;
  588.     }
  589.     }
  590.   else if (GET_CODE (x) == PARALLEL)
  591.     {
  592.       register int i = XVECLEN (x, 0) - 1;
  593.       for (; i >= 0; i--)
  594.     if (hard_reg_set_here_p (regno, XVECEXP (x, 0, i)))
  595.       return 1;
  596.     }
  597.  
  598.   return 0;
  599. }
  600.  
  601. /* Return nonzero if hard register REGNO appears 
  602.    either explicitly or implicitly in X
  603.    other than being stored into.
  604.  
  605.    References contained within the substructure at LOC do not count.
  606.    LOC may be zero, meaning don't ignore anything.  */
  607.  
  608. static int
  609. refers_to_regno_p (regno, x, loc)
  610.      int regno;
  611.      rtx x;
  612.      rtx *loc;
  613. {
  614.   register int i;
  615.   register RTX_CODE code;
  616.   register char *fmt;
  617.  
  618.  repeat:
  619.   code = GET_CODE (x);
  620.   if (code == REG)
  621.     {
  622.       i = REGNO (x);
  623.       if (reg_renumber[i] >= 0)
  624.     i = reg_renumber[i];
  625.       return i == regno;
  626.     }
  627.  
  628.   if (code == SET)
  629.     {
  630.       if (GET_CODE (SET_DEST (x)) != REG
  631.       && refers_to_regno_p (regno, SET_DEST (x), loc))
  632.     return 1;
  633.       if (loc == &SET_SRC (x))
  634.     return 0;
  635.       x = SET_SRC (x);
  636.       goto repeat;
  637.     }
  638.  
  639.   /* X does not match, so try its subexpressions.  */
  640.  
  641.   fmt = GET_RTX_FORMAT (code);
  642.   for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
  643.     {
  644.       if (fmt[i] == 'e' && loc != &XEXP (x, i))
  645.     {
  646.       if (i == 0)
  647.         {
  648.           x = XEXP (x, 0);
  649.           goto repeat;
  650.         }
  651.       else
  652.         if (refers_to_regno_p (regno, XEXP (x, i), loc))
  653.           return 1;
  654.     }
  655.       else if (fmt[i] == 'E')
  656.     {
  657.       register int j;
  658.       for (j = XVECLEN (x, i) - 1; j >=0; j--)
  659.         if (loc != &XVECEXP (x, i, j)
  660.         && refers_to_regno_p (regno, XVECEXP (x, i, j), loc))
  661.           return 1;
  662.     }
  663.     }
  664.   return 0;
  665. }
  666.  
  667. /* Return 1 if ADDR is a valid memory address for mode MODE,
  668.    and check that each pseudo reg has the proper kind of
  669.    hard reg.  */
  670.  
  671. int
  672. strict_memory_address_p (mode, addr)
  673.      enum machine_mode mode;
  674.      register rtx addr;
  675. {
  676.   GO_IF_LEGITIMATE_ADDRESS (mode, addr, win);
  677.   return 0;
  678.  
  679.  win:
  680.   return 1;
  681. }
  682.  
  683.  
  684. /* Like rtx_equal_p except that it allows a REG and a SUBREG to match
  685.    if they are the same hard reg, and has special hacks for
  686.    autoincrement and autodecrement.
  687.    This is specifically intended for find_reloads to use
  688.    in determining whether two operands match.
  689.    X is the operand whose number is the lower of the two.
  690.  
  691.    The value is 2 if Y contains a pre-increment that matches
  692.    a non-incrementing address in X.  */
  693.  
  694. /* ??? To be completely correct, we should arrange to pass
  695.    for X the output operand and for Y the input operand.
  696.    For now, we assume that the output operand has the lower number
  697.    because that is natural in (SET output (... input ...)).  */
  698.  
  699. int
  700. operands_match_p (x, y)
  701.      register rtx x, y;
  702. {
  703.   register int i;
  704.   register RTX_CODE code = GET_CODE (x);
  705.   register char *fmt;
  706.   int success_2;
  707.       
  708.   if (x == y)
  709.     return 1;
  710.   if ((code == REG || (code == SUBREG && GET_CODE (SUBREG_REG (x)) == REG))
  711.       && (GET_CODE (y) == REG || (GET_CODE (y) == SUBREG
  712.                   && GET_CODE (SUBREG_REG (y)) == REG)))
  713.     {
  714.       register int j;
  715.  
  716.       if (code == SUBREG)
  717.     {
  718.       i = REGNO (SUBREG_REG (x));
  719.       if (i >= FIRST_PSEUDO_REGISTER)
  720.         goto slow;
  721.       i += SUBREG_WORD (x);
  722.     }
  723.       else
  724.     i = REGNO (x);
  725.  
  726.       if (GET_CODE (y) == SUBREG)
  727.     {
  728.       j = REGNO (SUBREG_REG (y));
  729.       if (j >= FIRST_PSEUDO_REGISTER)
  730.         goto slow;
  731.       j += SUBREG_WORD (y);
  732.     }
  733.       else
  734.     j = REGNO (y);
  735.  
  736.       return i == j;
  737.     }
  738.   /* If two operands must match, because they are really a single
  739.      operand of an assembler insn, then two postincrements are invalid
  740.      because the assembler insn would increment only once.
  741.      On the other hand, an postincrement matches ordinary indexing
  742.      if the postincrement is the output operand.  */
  743.   if (code == POST_DEC || code == POST_INC)
  744.     return operands_match_p (XEXP (x, 0), y);
  745.   /* Two preincrements are invalid
  746.      because the assembler insn would increment only once.
  747.      On the other hand, an preincrement matches ordinary indexing
  748.      if the preincrement is the input operand.
  749.      In this case, return 2, since some callers need to do special
  750.      things when this happens.  */
  751.   if (GET_CODE (y) == PRE_DEC || GET_CODE (y) == PRE_INC)
  752.     return operands_match_p (x, XEXP (y, 0)) ? 2 : 0;
  753.   /* Now we have disposed of all the cases 
  754.      in which different rtx codes can match.  */
  755.   if (code != GET_CODE (y))
  756.     return 0;
  757.   if (code == LABEL_REF)
  758.     return XEXP (x, 0) == XEXP (y, 0);
  759.   if (code == SYMBOL_REF)
  760.     return XSTR (x, 0) == XSTR (y, 0);
  761.  
  762.  slow:
  763.   /* (MULT:SI x y) and (MULT:HI x y) are NOT equivalent.  */
  764.  
  765.   if (GET_MODE (x) != GET_MODE (y))
  766.     return 0;
  767.  
  768.   /* Compare the elements.  If any pair of corresponding elements
  769.      fail to match, return 0 for the whole things.  */
  770.  
  771.   success_2 = 0;
  772.   fmt = GET_RTX_FORMAT (code);
  773.   for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
  774.     {
  775.       int val;
  776.       switch (fmt[i])
  777.     {
  778.     case 'i':
  779.       if (XINT (x, i) != XINT (y, i))
  780.         return 0;
  781.       break;
  782.  
  783.     case 'e':
  784.       val = operands_match_p (XEXP (x, i), XEXP (y, i));
  785.       if (val == 0)
  786.         return 0;
  787.       /* If any subexpression returns 2,
  788.          we should return 2 if we are successful.  */
  789.       if (val == 2)
  790.         success_2 = 1;
  791.       break;
  792.  
  793.     case '0':
  794.       break;
  795.  
  796.       /* It is believed that rtx's at this level will never
  797.          contain anything but integers and other rtx's,
  798.          except for within LABEL_REFs and SYMBOL_REFs.  */
  799.     default:
  800.       abort ();
  801.     }
  802.     }
  803.   return 1 + success_2;
  804. }
  805.  
  806. /* Main entry point of this file: search the body of INSN
  807.    for values that need reloading and record them with push_reload.
  808.    REPLACE nonzero means record also where the values occur
  809.    so that subst_reloads can be used.
  810.    IND_OK says that a memory reference is a valid memory address.
  811.  
  812.    LIVE_KNOWN says we have valid information about which hard
  813.    regs are live at each point in the program; this is true when
  814.    we are called from global_alloc but false when stupid register
  815.    allocation has been done.
  816.  
  817.    RELOAD_REG_P if nonzero is a vector indexed by hard reg number
  818.    which is nonnegative if the reg has been commandeered for reloading into.
  819.    It is copied into STATIC_RELOAD_REG_P and referenced from there
  820.    by various subroutines.  */
  821.  
  822. void
  823. find_reloads (insn, replace, ind_ok, live_known, reload_reg_p)
  824.      rtx insn;
  825.      int replace, ind_ok;
  826.      int live_known;
  827.      short *reload_reg_p;
  828. {
  829. #ifdef REGISTER_CONSTRAINTS
  830.  
  831.   enum reload_modified { RELOAD_NOTHING, RELOAD_READ, RELOAD_READ_WRITE, RELOAD_WRITE };
  832.  
  833.   register int insn_code_number;
  834.   register int i;
  835.   int noperands;
  836.   /* These are the constraints for the insn.  We don't change them.  */
  837.   char *constraints1[MAX_RECOG_OPERANDS];
  838.   /* These start out as the constraints for the insn
  839.      and they are chewed up as we consider alternatives.  */
  840.   char *constraints[MAX_RECOG_OPERANDS];
  841.   int this_alternative[MAX_RECOG_OPERANDS];
  842.   char this_alternative_win[MAX_RECOG_OPERANDS];
  843.   char this_alternative_offmemok[MAX_RECOG_OPERANDS];
  844.   char this_alternative_earlyclobber[MAX_RECOG_OPERANDS];
  845.   int this_alternative_matches[MAX_RECOG_OPERANDS];
  846.   int swapped;
  847.   int goal_alternative[MAX_RECOG_OPERANDS];
  848.   int this_alternative_number;
  849.   int goal_alternative_number;
  850.   int operand_reloadnum[MAX_RECOG_OPERANDS];
  851.   int goal_alternative_matches[MAX_RECOG_OPERANDS];
  852.   int goal_alternative_matched[MAX_RECOG_OPERANDS];
  853.   char goal_alternative_win[MAX_RECOG_OPERANDS];
  854.   char goal_alternative_offmemok[MAX_RECOG_OPERANDS];
  855.   int goal_alternative_swapped;
  856.   enum reload_modified modified[MAX_RECOG_OPERANDS];
  857.   int best;
  858.   int commutative;
  859.   char operands_match[MAX_RECOG_OPERANDS][MAX_RECOG_OPERANDS];
  860.   rtx substed_operand[MAX_RECOG_OPERANDS];
  861.   rtx body = PATTERN (insn);
  862.   int goal_earlyclobber, this_earlyclobber;
  863.   enum machine_mode operand_mode[MAX_RECOG_OPERANDS];
  864.  
  865.   this_insn = insn;
  866.   n_reloads = 0;
  867.   n_replacements = 0;
  868.   n_memlocs = 0;
  869.   replace_reloads = replace;
  870.   indirect_ok = ind_ok;
  871.   hard_regs_live_known = live_known;
  872.   static_reload_reg_p = reload_reg_p;
  873.  
  874.   /* Find what kind of insn this is.  NOPERANDS gets number of operands.
  875.      Make OPERANDS point to a vector of operand values.
  876.      Make OPERAND_LOCS point to a vector of pointers to
  877.      where the operands were found.
  878.      Fill CONSTRAINTS and CONSTRAINTS1 with pointers to the
  879.      constraint-strings for this insn.
  880.      Return if the insn needs no reload processing.  */
  881.  
  882.   switch (GET_CODE (body))
  883.     {
  884.     case USE:
  885.     case CLOBBER:
  886.     case ASM_INPUT:
  887.     case ADDR_VEC:
  888.     case ADDR_DIFF_VEC:
  889.       return;
  890.  
  891.     case SET:
  892.       /* Dispose quickly of (set (reg..) (reg..)) if both have hard regs.  */
  893.       if (GET_CODE (SET_DEST (body)) == REG
  894.       && REGNO (SET_DEST (body)) < FIRST_PSEUDO_REGISTER
  895.       && GET_CODE (SET_SRC (body)) == REG
  896.       && REGNO (SET_SRC (body)) < FIRST_PSEUDO_REGISTER)
  897.     return;
  898.     case PARALLEL:
  899.       noperands = asm_noperands (body);
  900.       if (noperands > 0)
  901.     {
  902.       /* This insn is an `asm' with operands.  */
  903.  
  904.       insn_code_number = -1;
  905.  
  906.       /* expand_asm_operands makes sure there aren't too many operands.  */
  907.       if (noperands > MAX_RECOG_OPERANDS)
  908.         abort ();
  909.  
  910.       /* Now get the operand values and constraints out of the insn.  */
  911.  
  912.       decode_asm_operands (body, recog_operand, recog_operand_loc,
  913.                    constraints, operand_mode);
  914.       bcopy (constraints, constraints1, noperands * sizeof (char *));
  915.       break;
  916.     }
  917.  
  918.     default:
  919.       /* Ordinary insn: recognize it, allocate space for operands and
  920.      constraints, and get them out via insn_extract.  */
  921.  
  922.       insn_code_number = recog_memoized (insn);
  923.       noperands = insn_n_operands[insn_code_number];
  924.       insn_extract (insn);
  925.       {
  926.     /* Nonzero if some operand has a nonnull constraint.
  927.        If none has, we have no work to do.
  928.        Even a general_operand should have `g' in its constraint.  */
  929.     int have_constraints = 0;
  930.  
  931.     for (i = 0; i < noperands; i++)
  932.       {
  933.         constraints[i] = constraints1[i]
  934.           = insn_operand_constraint[insn_code_number][i];
  935.         operand_mode[i] = insn_operand_mode[insn_code_number][i];
  936.         if (constraints[i] != 0)
  937.           have_constraints = 1;
  938.       }
  939.     if (!have_constraints)
  940.       return;
  941.       }
  942.     }
  943.  
  944.   if (noperands == 0)
  945.     return;
  946.  
  947.   commutative = -1;
  948.  
  949.   /* If we will need to know, later, whether some pair of operands
  950.      are the same, we must compare them now and save the result.
  951.      Reloading the base and index registers will clobber them
  952.      and afterward they will fail to match.  */
  953.  
  954.   for (i = 0; i < noperands; i++)
  955.     {
  956.       register char *p;
  957.       register int c;
  958.  
  959.       substed_operand[i] = recog_operand[i];
  960.       p = constraints[i];
  961.  
  962.       /* Scan this operand's constraint to see if it should match another.  */
  963.  
  964.       while (c = *p++)
  965.     if (c == '%')
  966.       commutative = i;
  967.     else if (c >= '0' && c <= '9')
  968.       {
  969.         c -= '0';
  970.         operands_match[c][i]
  971.           = operands_match_p (recog_operand[c], recog_operand[i]);
  972.         /* If C can be commuted with C+1, and C might need to match I,
  973.            then C+1 might also need to match I.  */
  974.         if (commutative >= 0)
  975.           {
  976.         if (c == commutative || c == commutative + 1)
  977.           {
  978.             int other = c + (c == commutative ? 1 : -1);
  979.             operands_match[other][i]
  980.               = operands_match_p (recog_operand[other], recog_operand[i]);
  981.           }
  982.         if (i == commutative || i == commutative + 1)
  983.           {
  984.             int other = i + (i == commutative ? 1 : -1);
  985.             operands_match[c][other]
  986.             = operands_match_p (recog_operand[c], recog_operand[other]);
  987.           }
  988.         /* Note that C is supposed to be less than I.
  989.            No need to consider altering both C and I
  990.            because in that case we would alter one into the other.  */
  991.           }
  992.       }
  993.     }
  994.  
  995.   /* Examine each operand that is a memory reference or memory address
  996.      and reload parts of the addresses into index registers.
  997.      While we are at it, initialize the array `modified'.
  998.      Also here any references to pseudo regs that didn't get hard regs
  999.      but are equivalent to constants get replaced in the insn itself
  1000.      with those constants.  Nobody will ever see them again.  */
  1001.  
  1002.   for (i = 0; i < noperands; i++)
  1003.     {
  1004.       register RTX_CODE code = GET_CODE (recog_operand[i]);
  1005.       modified[i] = RELOAD_READ;
  1006.       if (constraints[i][0] == 'p')
  1007.     {
  1008.       find_reloads_address (VOIDmode, 0,
  1009.                 recog_operand[i], recog_operand_loc[i]);
  1010.       substed_operand[i] = recog_operand[i] = *recog_operand_loc[i];
  1011.     }
  1012.       else if (code == MEM)
  1013.     {
  1014.       find_reloads_address (GET_MODE (recog_operand[i]),
  1015.                 recog_operand_loc[i],
  1016.                 XEXP (recog_operand[i], 0),
  1017.                 &XEXP (recog_operand[i], 0));
  1018.       substed_operand[i] = recog_operand[i] = *recog_operand_loc[i];
  1019.     }
  1020.       else if (code == SUBREG)
  1021.     find_reloads_toplev (recog_operand[i]);
  1022.       else if (code == REG)
  1023.     {
  1024.       /* This is equivalent to calling find_reloads_toplev.
  1025.          The code is duplicated for speed.  */
  1026.       register int regno = REGNO (recog_operand[i]);
  1027.       if (regno >= FIRST_PSEUDO_REGISTER && reg_renumber[regno] < 0
  1028.           && reg_equiv_constant[regno] != 0)
  1029.         substed_operand[i] = recog_operand[i]
  1030.           = reg_equiv_constant[regno];
  1031.       if (reg_equiv_address[regno] != 0)
  1032.         {
  1033.           *recog_operand_loc[i] = recog_operand[i]
  1034.         = gen_rtx (MEM, GET_MODE (recog_operand[i]),
  1035.                reg_equiv_address[regno]);
  1036.           find_reloads_address (GET_MODE (recog_operand[i]),
  1037.                     recog_operand_loc[i],
  1038.                     XEXP (recog_operand[i], 0),
  1039.                     &XEXP (recog_operand[i], 0));
  1040.           substed_operand[i] = recog_operand[i] = *recog_operand_loc[i];
  1041.         }
  1042.     }
  1043.     }
  1044.  
  1045.   /* Now see what we need for pseudo-regs that didn't get hard regs
  1046.      or got the wrong kind of hard reg.  For this, we must consider
  1047.      all the operands together against the register constraints.  */
  1048.  
  1049.   best = MAX_RECOG_OPERANDS + 100;
  1050.  
  1051.   swapped = 0;
  1052.  try_swapped:
  1053.   this_alternative_number = 0;
  1054.   /* The constraints are made of several alternatives.
  1055.      Each operand's constraint looks like foo,bar,... with commas
  1056.      separating the alternatives.  The first alternatives for all
  1057.      operands go together, the second alternatives go together, etc.
  1058.  
  1059.      First loop over alternatives.  */
  1060.  
  1061.   while (*constraints[0])
  1062.     {
  1063.       /* Loop over operands for one constraint alternative.  */
  1064.       /* LOSERS counts those that don't fit this alternative
  1065.      and would require loading.  */
  1066.       int losers = 0;
  1067.       /* BAD is set to 1 if it some operand can't fit this alternative
  1068.      even after reloading.  */
  1069.       int bad = 0;
  1070.       /* REJECT is a count of how undesirable this alternative says it is
  1071.      if any reloading is required.  If the alternative matches exactly
  1072.      then REJECT is ignored, but otherwise it gets this much
  1073.      counted against it in addition to the reloading needed.  */
  1074.       int reject = 0;
  1075.  
  1076.       this_earlyclobber = 0;
  1077.  
  1078.       for (i = 0; i < noperands; i++)
  1079.     {
  1080.       register char *p = constraints[i];
  1081.       register int win = 0;
  1082.       int badop = 1;
  1083.       int c;
  1084.       register rtx operand = recog_operand[i];
  1085.       int offset = 0;
  1086.       int force_reload = 0;
  1087.       int offmemok = 0;
  1088.       int earlyclobber = 0;
  1089.  
  1090.       /* If the operand is a SUBREG, extract
  1091.          the REG or MEM within.  */
  1092.  
  1093.       while (GET_CODE (operand) == SUBREG)
  1094.         {
  1095.           offset += SUBREG_WORD (operand);
  1096.           operand = SUBREG_REG (operand);
  1097.           if (GET_CODE (operand) == MEM
  1098. /*** This is overcautious, as for BYTES_BIG_ENDIAN it is still possible
  1099.      to avoid setting force_reload if the mode of the subreg
  1100.      is SImode or bigger.  */
  1101. #ifndef BYTES_BIG_ENDIAN
  1102.           && offset != 0
  1103. #endif
  1104.           && !offsetable_memref_p (operand))
  1105.         force_reload = 1;
  1106.         }
  1107.  
  1108.       this_alternative[i] = (int) NO_REGS;
  1109.       this_alternative_win[i] = 0;
  1110.       this_alternative_offmemok[i] = 0;
  1111.       this_alternative_earlyclobber[i] = 0;
  1112.       this_alternative_matches[i] = -1;
  1113.  
  1114.       /* Scan this alternative's specs for this operand;
  1115.          set WIN if the operand fits any letter in this alternative.
  1116.          Otherwise, clear BADOP if this operand could
  1117.          fit some letter after reloads. */
  1118.  
  1119.       while (*p && (c = *p++) != ',')
  1120.         switch (c)
  1121.           {
  1122.           case '=':
  1123.         modified[i] = RELOAD_WRITE;
  1124.         break;
  1125.  
  1126.           case '+':
  1127.         modified[i] = RELOAD_READ_WRITE;
  1128.         break;
  1129.  
  1130.           case '*':
  1131.         break;
  1132.  
  1133.           case '%':
  1134.         commutative = i;
  1135.         break;
  1136.  
  1137.           case '?':
  1138.         reject++;
  1139.         break;
  1140.  
  1141.           case '!':
  1142.         reject = 100;
  1143.         break;
  1144.  
  1145.           case '#':
  1146.         /* Ignore rest of this alternative as far as
  1147.            reloading is concerned.  */
  1148.         while (*p && *p != ',') p++;
  1149.         break;
  1150.  
  1151.           case '0':
  1152.           case '1':
  1153.           case '2':
  1154.           case '3':
  1155.           case '4':
  1156.         c -= '0';
  1157.         this_alternative_matches[i] = c;
  1158.         /* We are supposed to match a previous operand.
  1159.            If we do, we win if that one did.
  1160.            If we do not, count both of the operands as losers.
  1161.            (This is too conservative, since most of the time
  1162.            only a single reload insn will be needed to make
  1163.            the two operands win.  As a result, this alternative
  1164.            may be rejected when it is actually desirable.)  */
  1165.         if ((swapped && (c != commutative || i != commutative + 1))
  1166.             /* If we are matching as if two operands were swapped,
  1167.                also pretend that operands_match had been computed
  1168.                with swapped.
  1169.                But if I is the second of those and C is the first,
  1170.                don't exchange them, because operands_match is valid
  1171.                only on one side of its diagonal.  */
  1172.             ? (operands_match
  1173.                 [(c == commutative || c == commutative + 1)
  1174.              ? 2*commutative + 1 - c : c]
  1175.                 [(i == commutative || i == commutative + 1)
  1176.              ? 2*commutative + 1 - i : i])
  1177.             : operands_match[c][i])
  1178.           win = this_alternative_win[c];
  1179.         else
  1180.           {
  1181.             /* Operands don't match.  */
  1182.             rtx value;
  1183.             /* Retroactively mark the operand we had to match
  1184.                as a loser, if it wasn't already.  */
  1185.             if (this_alternative_win[c])
  1186.               losers++;
  1187.             this_alternative_win[c] = 0;
  1188.             if (this_alternative[c] == (int) NO_REGS)
  1189.               bad = 1;
  1190.             /* But count the pair only once in the total badness of
  1191.                this alternative, if the pair can be a dummy reload.  */
  1192.             value
  1193.               = find_dummy_reload (recog_operand[i], recog_operand[c],
  1194.                        recog_operand_loc[i], recog_operand_loc[c],
  1195.                        this_alternative[c], -1);
  1196.  
  1197.             if (value != 0)
  1198.               losers--;
  1199.           }
  1200.         /* This can be fixed with reloads if the operand
  1201.            we are supposed to match can be fixed with reloads.  */
  1202.         badop = 0;
  1203.         break;
  1204.  
  1205.           case 'p':
  1206.         /* All necessary reloads for an address_operand
  1207.            were handled in find_reloads_address.  */
  1208.         this_alternative[i] = (int) ALL_REGS;
  1209.         win = 1;
  1210.         break;
  1211.  
  1212.           case 'm':
  1213.         if (GET_CODE (operand) == MEM
  1214.             || (GET_CODE (operand) == REG
  1215.             && REGNO (operand) >= FIRST_PSEUDO_REGISTER
  1216.             && reg_renumber[REGNO (operand)] < 0))
  1217.           win = 1;
  1218.         if (GET_CODE (operand) == CONST_DOUBLE)
  1219.           badop = 0;
  1220.         break;
  1221.  
  1222.           case '<':
  1223.         if (GET_CODE (operand) == MEM
  1224.             && (GET_CODE (XEXP (operand, 0)) == PRE_DEC
  1225.             || GET_CODE (XEXP (operand, 0)) == POST_DEC))
  1226.           win = 1;
  1227.         break;
  1228.  
  1229.           case '>':
  1230.         if (GET_CODE (operand) == MEM
  1231.             && (GET_CODE (XEXP (operand, 0)) == PRE_INC
  1232.             || GET_CODE (XEXP (operand, 0)) == POST_INC))
  1233.           win = 1;
  1234.         break;
  1235.  
  1236.         /* Memory operand whose address is offsettable.  */
  1237.           case 'o':
  1238.         if ((GET_CODE (operand) == MEM
  1239.              && offsetable_memref_p (operand))
  1240.             || (GET_CODE (operand) == REG
  1241.             && REGNO (operand) >= FIRST_PSEUDO_REGISTER
  1242.             && reg_renumber[REGNO (operand)] < 0))
  1243.           win = 1;
  1244.         if (GET_CODE (operand) == CONST_DOUBLE
  1245.             || (GET_CODE (operand) == MEM
  1246.             && GET_CODE (XEXP (operand, 0)) != POST_INC
  1247.             && GET_CODE (XEXP (operand, 0)) != POST_DEC
  1248.             && GET_CODE (XEXP (operand, 0)) != PRE_INC
  1249.             && GET_CODE (XEXP (operand, 0)) != PRE_DEC))
  1250.           badop = 0;
  1251.         offmemok = 1;
  1252.         break;
  1253.  
  1254.           case '&':
  1255.         /* Output operand that is stored before the need for the
  1256.            input operands (and their index registers) is over.  */
  1257.         if (GET_CODE (operand) == REG)
  1258.           earlyclobber = 1, this_earlyclobber = 1;
  1259.         break;
  1260.  
  1261.           case 'F':
  1262.         if (GET_CODE (operand) == CONST_DOUBLE)
  1263.           win = 1;
  1264.         break;
  1265.  
  1266.           case 'G':
  1267.           case 'H':
  1268.         if (GET_CODE (operand) == CONST_DOUBLE
  1269.             && CONST_DOUBLE_OK_FOR_LETTER_P (operand, c))
  1270.           win = 1;
  1271.         break;
  1272.  
  1273.           case 's':
  1274.         if (GET_CODE (operand) == CONST_INT)
  1275.           break;
  1276.           case 'i':
  1277.         if (CONSTANT_P (operand))
  1278.           win = 1;
  1279.         break;
  1280.  
  1281.           case 'n':
  1282.         if (GET_CODE (operand) == CONST_INT)
  1283.           win = 1;
  1284.         break;
  1285.  
  1286.           case 'I':
  1287.           case 'J':
  1288.           case 'K':
  1289.           case 'L':
  1290.           case 'M':
  1291.         if (GET_CODE (operand) == CONST_INT
  1292.             && CONST_OK_FOR_LETTER_P (INTVAL (operand), c))
  1293.           win = 1;
  1294.         break;
  1295.  
  1296.           case 'g':
  1297.         if (GENERAL_REGS == ALL_REGS
  1298.             || GET_CODE (operand) != REG
  1299.             || (REGNO (operand) >= FIRST_PSEUDO_REGISTER
  1300.             && reg_renumber[REGNO (operand)] < 0))
  1301.           win = 1;
  1302.         /* Drop through into 'r' case */
  1303.  
  1304.           case 'r':
  1305.         this_alternative[i]
  1306.           = (int) reg_class_subunion[this_alternative[i]][(int) GENERAL_REGS];
  1307.         goto reg;
  1308.  
  1309.           default:
  1310.         this_alternative[i]
  1311.           = (int) reg_class_subunion[this_alternative[i]][(int) REG_CLASS_FROM_LETTER (c)];
  1312.  
  1313.           reg:
  1314.         badop = 0;
  1315.         if (GET_CODE (operand) == REG
  1316.             && reg_renumbered_fits_class_p (operand,
  1317.                             this_alternative[i],
  1318.                             offset, GET_MODE (recog_operand[i])))
  1319.           win = 1;
  1320.         break;
  1321.           }
  1322.       constraints[i] = p;
  1323.  
  1324.       /* Record which operands fit this alternative.  */
  1325.       this_alternative_earlyclobber[i] = earlyclobber;
  1326.       if (win && ! force_reload)
  1327.         this_alternative_win[i] = 1;
  1328.       else
  1329.         {
  1330.           this_alternative_offmemok[i] = offmemok;
  1331.           losers++;
  1332.           if (badop)
  1333.         bad = 1;
  1334.         }
  1335.     }
  1336.  
  1337.       /* Now see if any output operands that are marked "earlyclobber"
  1338.      in this alternative conflict with any input operands
  1339.      or any memory addresses.  */
  1340.  
  1341.       for (i = 0; i < noperands; i++)
  1342.     if (this_alternative_earlyclobber[i]
  1343.         && this_alternative_win[i])
  1344.       {
  1345.         int j;
  1346.         for (j = 0; j < noperands; j++)
  1347.           /* Is this an input operand or a memory ref?  */
  1348.           if ((GET_CODE (recog_operand[j]) == MEM
  1349.            || modified[j] != RELOAD_WRITE)
  1350.           /* Does it refer to the earlyclobber operand?  */
  1351.           && refers_to_regno_p (REGNO (recog_operand[i]),
  1352.                     recog_operand[j], 0))
  1353.         break;
  1354.         /* If an earlyclobber operand conflicts with something,
  1355.            it must be reloaded, so request this and count the cost.  */
  1356.         if (j != noperands)
  1357.           {
  1358.         losers++;
  1359.         this_alternative_win[i] = 0;
  1360.           }
  1361.       }
  1362.  
  1363.       /* If one alternative accepts all the operands, no reload required,
  1364.      choose that alternative; don't consider the remaining ones.  */
  1365.       if (losers == 0)
  1366.     {
  1367.       /* Unswap these so that they are never swapped at `finish'.  */
  1368.       recog_operand[1] = substed_operand[1];
  1369.       recog_operand[2] = substed_operand[2];
  1370.       for (i = 0; i < noperands; i++)
  1371.         {
  1372.           goal_alternative_win[i] = 1;
  1373.           goal_alternative[i] = this_alternative[i];
  1374.           goal_alternative_offmemok[i] = this_alternative_offmemok[i];
  1375.           goal_alternative_matches[i] = this_alternative_matches[i];
  1376.         }
  1377.       goal_alternative_number = this_alternative_number;
  1378.       goal_alternative_swapped = swapped;
  1379.       goal_earlyclobber = this_earlyclobber;
  1380.       goto finish;
  1381.     }
  1382.  
  1383.       /* REJECT, set by the ! and ? constraint characters,
  1384.      discourages the use of this alternative for a reload goal.  */
  1385.       if (reject > 0)
  1386.     losers += reject;
  1387.  
  1388.       /* If this alternative can be made to work by reloading,
  1389.      and it needs less reloading than the others checked so far,
  1390.      record it as the chosen goal for reloading.  */
  1391.       if (! bad && best > losers)
  1392.     {
  1393.       for (i = 0; i < noperands; i++)
  1394.         {
  1395.           goal_alternative[i] = this_alternative[i];
  1396.           goal_alternative_win[i] = this_alternative_win[i];
  1397.           goal_alternative_offmemok[i] = this_alternative_offmemok[i];
  1398.           goal_alternative_matches[i] = this_alternative_matches[i];
  1399.         }
  1400.       goal_alternative_swapped = swapped;
  1401.       best = losers;
  1402.       goal_alternative_number = this_alternative_number;
  1403.       goal_earlyclobber = this_earlyclobber;
  1404.     }
  1405.       this_alternative_number++;
  1406.     }
  1407.  
  1408.   /* If insn is commutative (it's safe to exchange a certain pair of operands)
  1409.      then we need to try each alternative twice,
  1410.      the second time matching those two operands
  1411.      as if we had exchanged them.
  1412.      To do this, really exchange them in operands.
  1413.  
  1414.      If we have just tried the alternatives the second time,
  1415.      return operands to normal and drop through.  */
  1416.  
  1417.   if (commutative >= 0)
  1418.     {
  1419.       swapped = !swapped;
  1420.       if (swapped)
  1421.     {
  1422.       recog_operand[commutative] = substed_operand[commutative + 1];
  1423.       recog_operand[commutative + 1] = substed_operand[commutative];
  1424.  
  1425.       bcopy (constraints1, constraints, noperands * sizeof (char *));
  1426.       goto try_swapped;
  1427.     }
  1428.       else
  1429.     {
  1430.       recog_operand[commutative] = substed_operand[commutative];
  1431.       recog_operand[commutative + 1] = substed_operand[commutative + 1];
  1432.     }
  1433.     }
  1434.  
  1435.   /* The operands don't meet the constraints.
  1436.      goal_alternative describes the alternative
  1437.      that we could reach by reloading the fewest operands.
  1438.      Reload so as to fit it.  */
  1439.  
  1440.   if (best == MAX_RECOG_OPERANDS + 100)
  1441.     {
  1442.       /* No alternative works with reloads??  */
  1443.       if (insn_code_number >= 0)
  1444.     abort ();
  1445.       error ("inconsistent operand constraints in an `asm' in this function");
  1446.       n_reloads = 0;
  1447.       return;
  1448.     }
  1449.  
  1450.   /* Jump to `finish' from above if all operands are valid already.
  1451.      In that case, goal_alternative_win is all 1.  */
  1452.  finish:
  1453.  
  1454.   /* Right now, for any pair of operands I and J that are required to match,
  1455.      with I < J,
  1456.      goal_alternative_matches[J] is I.
  1457.      Set up goal_alternative_matched as the inverse function:
  1458.      goal_alternative_matched[I] = J.  */
  1459.  
  1460.   for (i = 0; i < noperands; i++)
  1461.     goal_alternative_matched[i] = -1;
  1462.  
  1463.   for (i = 0; i < noperands; i++)
  1464.     if (! goal_alternative_win[i]
  1465.     && goal_alternative_matches[i] >= 0)
  1466.       goal_alternative_matched[goal_alternative_matches[i]] = i;
  1467.  
  1468.   /* If the best alternative is with operands 1 and 2 swapped,
  1469.      consider them swapped before reporting the reloads.  */
  1470.  
  1471.   if (goal_alternative_swapped)
  1472.     {
  1473.       register rtx tem;
  1474.  
  1475.       tem = substed_operand[commutative];
  1476.       substed_operand[commutative] = substed_operand[commutative + 1];
  1477.       substed_operand[commutative + 1] = tem;
  1478.       tem = recog_operand[commutative];
  1479.       recog_operand[commutative] = recog_operand[commutative + 1];
  1480.       recog_operand[commutative + 1] = tem;
  1481.     }
  1482.  
  1483.   /* Perform whatever substitutions on the operands we are supposed
  1484.      to make due to commutativity or replacement of registers
  1485.      with equivalent constants or memory slots.  */
  1486.  
  1487.   for (i = 0; i < noperands; i++)
  1488.     {
  1489.       *recog_operand_loc[i] = substed_operand[i];
  1490.       /* While we are looping on operands, initialize this.  */
  1491.       operand_reloadnum[i] = -1;
  1492.     }
  1493.  
  1494.   /* Now record reloads for all the operands that need them.  */
  1495.   for (i = 0; i < noperands; i++)
  1496.     if (! goal_alternative_win[i])
  1497.       {
  1498.     /* Operands that match previous ones have already been handled.  */
  1499.     if (goal_alternative_matches[i] >= 0)
  1500.       ;
  1501.     /* This clause forces a double constant into memory
  1502.        if necessary.  But right now it appears never necessary.
  1503.        Perhaps there should be a heuristic here to detect cases
  1504.        when it is desirable, even though not necessary, to move
  1505.        the constant to memory.  I can't decide when it is desirable.  */
  1506.     else if (GET_CODE (recog_operand[i]) == CONST_DOUBLE
  1507.          && alternative_allows_memconst (constraints1[i], goal_alternative_number)
  1508.          && goal_alternative[i] == (int) NO_REGS)
  1509.       {
  1510.         *recog_operand_loc[i] = recog_operand[i]
  1511.           = force_const_double_mem (recog_operand[i]);
  1512.         find_reloads_toplev (recog_operand[i]);
  1513.       }
  1514.     /* Handle an operand with a nonoffsetable address
  1515.        appearing where an offsetable address will do
  1516.        by reloading the address into a base register.  */
  1517.     else if (goal_alternative_matched[i] == -1
  1518.          && goal_alternative_offmemok[i]
  1519.          && GET_CODE (recog_operand[i]) == MEM
  1520.          && GET_CODE (XEXP (recog_operand[i], 0)) != POST_INC
  1521.          && GET_CODE (XEXP (recog_operand[i], 0)) != POST_DEC
  1522.          && GET_CODE (XEXP (recog_operand[i], 0)) != PRE_INC
  1523.          && GET_CODE (XEXP (recog_operand[i], 0)) != PRE_DEC)
  1524.       push_reload (XEXP (recog_operand[i], 0), 0,
  1525.                &XEXP (recog_operand[i], 0), 0,
  1526.                BASE_REG_CLASS, GET_MODE (XEXP (recog_operand[i], 0)),
  1527.                0, 0, 0);
  1528.     else if (goal_alternative_matched[i] == -1)
  1529.       operand_reloadnum[i] =
  1530.         push_reload (modified[i] != RELOAD_WRITE ? recog_operand[i] : 0,
  1531.              modified[i] != RELOAD_READ ? recog_operand[i] : 0,
  1532.              recog_operand_loc[i], 0,
  1533.              (enum reg_class) goal_alternative[i],
  1534.              (modified[i] == RELOAD_WRITE ? VOIDmode : operand_mode[i]),
  1535.              (modified[i] == RELOAD_READ ? VOIDmode : operand_mode[i]),
  1536.              (insn_code_number < 0 ? 0
  1537.               : insn_operand_strict_low[insn_code_number][i]),
  1538.              0);
  1539.     /* In a matching pair of operands, one must be input only
  1540.        and the other must be output only.
  1541.        Pass the input operand as IN and the other as OUT.  */
  1542.     else if (modified[i] == RELOAD_READ
  1543.          && modified[goal_alternative_matched[i]] == RELOAD_WRITE)
  1544.       operand_reloadnum[goal_alternative_matched[i]]
  1545.         = operand_reloadnum[i]
  1546.         = push_reload (recog_operand[i],
  1547.                recog_operand[goal_alternative_matched[i]],
  1548.                recog_operand_loc[i],
  1549.                recog_operand_loc[goal_alternative_matched[i]],
  1550.                (enum reg_class) goal_alternative[i],
  1551.                operand_mode[i],
  1552.                operand_mode[goal_alternative_matched[i]],
  1553.                VOIDmode, 0);
  1554.     else if (modified[i] == RELOAD_WRITE
  1555.          && modified[goal_alternative_matched[i]] == RELOAD_READ)
  1556.       operand_reloadnum[goal_alternative_matched[i]]
  1557.         = operand_reloadnum[i]
  1558.         = push_reload (recog_operand[goal_alternative_matched[i]],
  1559.                recog_operand[i],
  1560.                recog_operand_loc[goal_alternative_matched[i]],
  1561.                recog_operand_loc[i],
  1562.                (enum reg_class) goal_alternative[i],
  1563.                operand_mode[goal_alternative_matched[i]],
  1564.                operand_mode[i],
  1565.                VOIDmode, 0);
  1566.     else abort ();
  1567.       }
  1568.     else if (goal_alternative_matched[i] < 0
  1569.          && goal_alternative_matches[i] < 0)
  1570.       {
  1571.     rtx operand = recog_operand[i];
  1572.     /* For each non-matching operand that's a pseudo-register 
  1573.        that didn't get a hard register, make an optional reload.
  1574.        This may get done even if the insn needs no reloads otherwise.  */
  1575.     /* (It would be safe to make an optional reload for a matching pair
  1576.        of operands, but we don't bother yet.)  */
  1577.     while (GET_CODE (operand) == SUBREG)
  1578.       operand = XEXP (operand, 0);
  1579.     if (GET_CODE (operand) == REG
  1580.         && REGNO (operand) >= FIRST_PSEUDO_REGISTER
  1581.         && reg_renumber[REGNO (operand)] < 0
  1582.         && (enum reg_class) goal_alternative[i] != NO_REGS
  1583.         /* Don't make optional output reloads for jump insns
  1584.            (such as aobjeq on the vax).  */
  1585.         && (modified[i] == RELOAD_READ
  1586.         || GET_CODE (insn) != JUMP_INSN))
  1587.       operand_reloadnum[i]
  1588.         = push_reload (modified[i] != RELOAD_WRITE ? recog_operand[i] : 0,
  1589.                modified[i] != RELOAD_READ ? recog_operand[i] : 0,
  1590.                recog_operand_loc[i], 0,
  1591.                (enum reg_class) goal_alternative[i],
  1592.                (modified[i] == RELOAD_WRITE ? VOIDmode : operand_mode[i]),
  1593.                (modified[i] == RELOAD_READ ? VOIDmode : operand_mode[i]),
  1594.                insn_operand_strict_low[insn_code_number][i],
  1595.                1);
  1596.     else
  1597.       operand_reloadnum[i] = -1;
  1598.       }
  1599.  
  1600.   /* Perhaps an output reload can be combined with another
  1601.      to reduce needs by one.  */
  1602.   if (!goal_earlyclobber)
  1603.     combine_reloads ();
  1604.  
  1605.   /* If this insn pattern contains any MATCH_DUP's, make sure that
  1606.      they will be substituted if the operands they match are substituted.
  1607.      Also do now any substitutions we already did on the operands.  */
  1608.   if (insn_code_number >= 0)
  1609.     for (i = insn_n_dups[insn_code_number] - 1; i >= 0; i--)
  1610.       {
  1611.     int opno = recog_dup_num[i];
  1612.     *recog_dup_loc[i] = *recog_operand_loc[opno];
  1613.     if (operand_reloadnum[opno] >= 0)
  1614.       push_replacement (recog_dup_loc[i], operand_reloadnum[opno],
  1615.                 insn_operand_mode[insn_code_number][opno]);
  1616.       }
  1617.  
  1618.   /* For each reload of a reg into some other class of reg,
  1619.      search for an existing equivalent reg (same value now) in the right class.
  1620.      We can use it as long as we don't need to change its contents.  */
  1621.   for (i = 0; i < n_reloads; i++)
  1622.     if (reload_reg_rtx[i] == 0
  1623.     && reload_in[i] != 0
  1624.     && GET_CODE (reload_in[i]) == REG
  1625.     && reload_out[i] == 0)
  1626.       {
  1627.     reload_reg_rtx[i]
  1628.       = find_equiv_reg (reload_in[i], insn, reload_reg_class[i], -1,
  1629.                 static_reload_reg_p, 0, reload_inmode[i]);
  1630.     /* Prevent generation of insn to load the value
  1631.        because the one we found already has the value.  */
  1632.     if (reload_reg_rtx[i])
  1633.       reload_in[i] = reload_reg_rtx[i];
  1634.       }
  1635.  
  1636. #else /* no REGISTER_CONSTRAINTS */
  1637.   int noperands;
  1638.   int insn_code_number;
  1639.   register int i;
  1640.   rtx body = PATTERN (insn);
  1641.  
  1642.   n_reloads = 0;
  1643.   n_replacements = 0;
  1644.   replace_reloads = replace;
  1645.   indirect_ok = ind_ok;
  1646.   this_insn = insn;
  1647.  
  1648.   /* Find what kind of insn this is.  NOPERANDS gets number of operands.
  1649.      Store the operand values in RECOG_OPERAND and the locations
  1650.      of the words in the insn that point to them in RECOG_OPERAND_LOC.
  1651.      Return if the insn needs no reload processing.  */
  1652.  
  1653.   switch (GET_CODE (body))
  1654.     {
  1655.     case USE:
  1656.     case CLOBBER:
  1657.     case ASM_INPUT:
  1658.     case ADDR_VEC:
  1659.     case ADDR_DIFF_VEC:
  1660.       return;
  1661.  
  1662.     case PARALLEL:
  1663.     case SET:
  1664.       noperands = asm_noperands (body);
  1665.       if (noperands > 0)
  1666.     {
  1667.       /* This insn is an `asm' with operands.
  1668.          First, find out how many operands, and allocate space.  */
  1669.  
  1670.       insn_code_number = -1;
  1671.       /* ??? This is a bug! ???
  1672.          Give up and delete this insn if it has too many operands.  */
  1673.       if (noperands > MAX_RECOG_OPERANDS)
  1674.         abort ();
  1675.  
  1676.       /* Now get the operand values out of the insn.  */
  1677.  
  1678.       decode_asm_operands (body, recog_operand, recog_operand_loc, 0, 0);
  1679.       break;
  1680.     }
  1681.  
  1682.     default:
  1683.       /* Ordinary insn: recognize it, allocate space for operands and
  1684.      constraints, and get them out via insn_extract.  */
  1685.  
  1686.       insn_code_number = recog_memoized (insn);
  1687.       noperands = insn_n_operands[insn_code_number];
  1688.       insn_extract (insn);
  1689.     }
  1690.  
  1691.   if (noperands == 0)
  1692.     return;
  1693.  
  1694.   for (i = 0; i < noperands; i++)
  1695.     {
  1696.       register RTX_CODE code = GET_CODE (recog_operand[i]);
  1697.  
  1698.       if (insn_code_number >= 0)
  1699.     if (insn_operand_address_p[insn_code_number][i])
  1700.       find_reloads_address (VOIDmode, 0,
  1701.                 recog_operand[i], recog_operand_loc[i]);
  1702.       if (code == MEM)
  1703.     find_reloads_address (GET_MODE (recog_operand[i]),
  1704.                   recog_operand_loc[i],
  1705.                   XEXP (recog_operand[i], 0),
  1706.                   &XEXP (recog_operand[i], 0));
  1707.       if (code == SUBREG)
  1708.     find_reloads_toplev (recog_operand[i]);
  1709.       if (code == REG)
  1710.     {
  1711.       register int regno = REGNO (recog_operand[i]);
  1712.       if (regno >= FIRST_PSEUDO_REGISTER && reg_renumber[regno] < 0
  1713.           && reg_equiv_constant[regno] != 0)
  1714.         recog_operand[i] = *recog_operand_loc[i]
  1715.           = reg_equiv_constant[regno];
  1716.     }
  1717.     }
  1718. #endif /* no REGISTER_CONSTRAINTS */
  1719. }
  1720.  
  1721. /* Return 1 if alternative number ALTNUM in constraint-string CONSTRAINT
  1722.    accepts a memory operand with constant address.  */
  1723.  
  1724. static int
  1725. alternative_allows_memconst (constraint, altnum)
  1726.      char *constraint;
  1727.      int altnum;
  1728. {
  1729.   register int c;
  1730.   /* Skip alternatives before the one requested.  */
  1731.   while (altnum > 0)
  1732.     {
  1733.       while (*constraint++ != ',');
  1734.       altnum--;
  1735.     }
  1736.   /* Scan the requested alternative for 'm' or 'o'.
  1737.      If one of them is present, this alternative accepts memory constants.  */
  1738.   while ((c = *constraint++) && c != ',' && c != '#')
  1739.     if (c == 'm' || c == 'o')
  1740.       return 1;
  1741.   return 0;
  1742. }
  1743.  
  1744. /* Scan X for memory references and scan the addresses for reloading.
  1745.    Also checks for references to "constant" regs that we want to eliminate
  1746.    and replaces them with the values they stand for.
  1747.    We may alter X descructively if it contains a reference to such.
  1748.    If X is just a constant reg, we return the equivalent value
  1749.    instead of X.  */
  1750.  
  1751. static rtx
  1752. find_reloads_toplev (x)
  1753.      rtx x;
  1754. {
  1755.   register RTX_CODE code = GET_CODE (x);
  1756.  
  1757.   register char *fmt = GET_RTX_FORMAT (code);
  1758.   register int i;
  1759.  
  1760.   if (code == REG)
  1761.     {
  1762.       /* This code is duplicated for speed in find_reloads.  */
  1763.       register int regno = REGNO (x);
  1764.       if (regno >= FIRST_PSEUDO_REGISTER && reg_renumber[regno] < 0
  1765.       && reg_equiv_constant[regno] != 0)
  1766.     x = reg_equiv_constant[regno];
  1767.       else if (reg_equiv_address[regno] != 0)
  1768.     {
  1769.       x = gen_rtx (MEM, GET_MODE (x),
  1770.                reg_equiv_address[regno]);
  1771.       find_reloads_address (GET_MODE (x), 0,
  1772.                 XEXP (x, 0),
  1773.                 &XEXP (x, 0));
  1774.     }
  1775.       return x;
  1776.  
  1777.  
  1778.     }
  1779.   else if (code == MEM)
  1780.     {
  1781.       rtx tem = x;
  1782.       find_reloads_address (GET_MODE (x), &tem, XEXP (x, 0), &XEXP (x, 0));
  1783.       return tem;
  1784.     }
  1785.   else
  1786.     for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
  1787.       {
  1788.     if (fmt[i] == 'e')
  1789.       XEXP (x, i) = find_reloads_toplev (XEXP (x, i));
  1790.       }
  1791.   return x;
  1792. }
  1793.  
  1794. static rtx
  1795. make_memloc (ad, regno)
  1796.      rtx ad;
  1797.      int regno;
  1798. {
  1799.   register int i;
  1800.   rtx tem = reg_equiv_address[regno];
  1801.   for (i = 0; i < n_memlocs; i++)
  1802.     if (rtx_equal_p (tem, XEXP (memlocs[i], 0)))
  1803.       return memlocs[i];
  1804.   tem = gen_rtx (MEM, GET_MODE (ad), tem);
  1805.   memlocs[n_memlocs++] = tem;
  1806.   return tem;
  1807. }
  1808.  
  1809. /* Record all reloads needed for handling memory address AD
  1810.    which appears in *LOC in a memory reference to mode MODE
  1811.    which itself is stored in location  *MEMREFLOC.
  1812.    (MEMREFLOC may be zero, meaning don't ever bother to copy the memref.)
  1813.    Note that we take shortcuts assuming that no multi-reg machine mode
  1814.    occurs as part of an address.  */
  1815.  
  1816. static void
  1817. find_reloads_address (mode, memrefloc, ad, loc)
  1818.      enum machine_mode mode;
  1819.      rtx *memrefloc;
  1820.      rtx ad;
  1821.      rtx *loc;
  1822. {
  1823.   register int regno;
  1824.   rtx tem;
  1825.  
  1826.   if (GET_CODE (ad) == REG)
  1827.     {
  1828.       regno = REGNO (ad);
  1829.  
  1830.       if (regno >= FIRST_PSEUDO_REGISTER && reg_renumber[regno] < 0
  1831.       && reg_equiv_constant[regno] != 0)
  1832.     {
  1833.       if (strict_memory_address_p (mode, reg_equiv_constant[regno]))
  1834.         {
  1835.           *loc = ad = reg_equiv_constant[regno];
  1836.           return;
  1837.         }
  1838.     }
  1839.       if (reg_equiv_address[regno] != 0)
  1840.     {
  1841.       rtx tem = make_memloc (ad, regno);
  1842.       push_reload (XEXP (tem, 0), 0, &XEXP (tem, 0), 0,
  1843.                BASE_REG_CLASS,
  1844.                GET_MODE (XEXP (tem, 0)), 0, VOIDmode, 0);
  1845.       push_reload (tem, 0, loc, 0, BASE_REG_CLASS,
  1846.                GET_MODE (ad), 0, VOIDmode, 0);
  1847.       return;
  1848.     }
  1849.       if (! (regno >= FIRST_PSEUDO_REGISTER && reg_renumber[regno] < 0
  1850.          ? indirect_ok
  1851.          : REGNO_OK_FOR_BASE_P (regno)))
  1852.     push_reload (ad, 0, loc, 0, BASE_REG_CLASS,
  1853.              GET_MODE (ad), 0, VOIDmode, 0);
  1854.       return;
  1855.     }
  1856.  
  1857.   if (strict_memory_address_p (mode, ad))
  1858.     {
  1859.       /* The address appears valid, so reloads are not needed.
  1860.      But the address may contain an eliminable register.
  1861.      This can happen because a machine with indirect addressing
  1862.      may consider a pseudo register by itself a valid address even when
  1863.      it has failed to get a hard reg.
  1864.      So do a tree-walk to find and eliminate all such regs.  */
  1865.  
  1866.       /* But first quickly dispose of a common case.  */
  1867.       if (GET_CODE (ad) == PLUS
  1868.       && GET_CODE (XEXP (ad, 1)) == CONST_INT
  1869.       && GET_CODE (XEXP (ad, 0)) == REG
  1870.       && reg_equiv_constant[REGNO (XEXP (ad, 0))] == 0)
  1871.     return;
  1872.  
  1873.       subst_reg_equivs_changed = 0;
  1874.       *loc = subst_reg_equivs (ad);
  1875.  
  1876.       if (! subst_reg_equivs_changed)
  1877.     return;
  1878.  
  1879.       /* Check result for validity after substitution.  */
  1880.       if (strict_memory_address_p (mode, ad))
  1881.     return;
  1882.     }
  1883.  
  1884.   /* If we have address of a stack slot but it's not valid
  1885.      (displacement is too large), compute the sum in a register.  */
  1886.   if (GET_CODE (ad) == PLUS
  1887.       && (XEXP (ad, 0) == frame_pointer_rtx
  1888. #if FRAME_POINTER_REGNUM == ARG_POINTER_REGNUM
  1889.       || XEXP (ad, 0) == arg_pointer_rtx
  1890. #endif
  1891.       )
  1892.       && GET_CODE (XEXP (ad, 1)) == CONST_INT)
  1893.     {
  1894.       /* Unshare the MEM rtx so we can safely alter it.  */
  1895.       if (memrefloc)
  1896.     {
  1897.       *memrefloc = copy_rtx (*memrefloc);
  1898.       loc = &XEXP (*memrefloc, 0);
  1899.     }
  1900.       push_reload (ad, 0, loc, 0, BASE_REG_CLASS,
  1901.            GET_MODE (ad), 0, VOIDmode, 0);
  1902.       return;
  1903.     }
  1904.  
  1905.   /* See if address becomes valid when an eliminable register
  1906.      in a sum is replaced.  */
  1907.  
  1908.   tem = ad;
  1909.   if (GET_CODE (ad) == PLUS)
  1910.     tem = subst_indexed_address (ad);
  1911.   if (tem != ad && strict_memory_address_p (mode, tem))
  1912.     {
  1913.       /* Ok, we win that way.  Replace any additional eliminable
  1914.      registers.  */
  1915.  
  1916.       subst_reg_equivs_changed = 0;
  1917.       tem = subst_reg_equivs (tem);
  1918.  
  1919.       /* Make sure that didn't make the address invalid again.  */
  1920.  
  1921.       if (! subst_reg_equivs_changed || strict_memory_address_p (mode, tem))
  1922.     {
  1923.       *loc = tem;
  1924.       return;
  1925.     }
  1926.     }
  1927.  
  1928.   /* If constants aren't valid addresses, reload the constant address
  1929.      into a register.  */
  1930.   if (CONSTANT_ADDRESS_P (ad) && ! strict_memory_address_p (mode, ad))
  1931.     {
  1932.       push_reload (ad, 0, loc, 0,
  1933.            BASE_REG_CLASS,
  1934.            GET_MODE (ad), 0, VOIDmode, 0);
  1935.       return;
  1936.     }
  1937.  
  1938.   find_reloads_address_1 (ad, 0, loc);
  1939. }
  1940.  
  1941. /* Find all pseudo regs appearing in AD
  1942.    that are eliminable in favor of equivalent values
  1943.    and do not have hard regs; replace them by their equivalents.  */
  1944.  
  1945. static rtx
  1946. subst_reg_equivs (ad)
  1947.      rtx ad;
  1948. {
  1949.   register RTX_CODE code = GET_CODE (ad);
  1950.   register int i;
  1951.   register char *fmt;
  1952.  
  1953.   switch (code)
  1954.     {
  1955.     case CONST_INT:
  1956.     case CONST:
  1957.     case CONST_DOUBLE:
  1958.     case SYMBOL_REF:
  1959.     case LABEL_REF:
  1960.     case PC:
  1961.     case CC0:
  1962.       return ad;
  1963.  
  1964.     case REG:
  1965.       {
  1966.     register int regno = REGNO (ad);
  1967.  
  1968.     if (reg_equiv_constant[regno] != 0)
  1969.       {
  1970.         subst_reg_equivs_changed = 1;
  1971.         return reg_equiv_constant[regno];
  1972.       }
  1973.       }
  1974.       return ad;
  1975.  
  1976.     case PLUS:
  1977.       /* Quickly dispose of a common case.  */
  1978.       if (XEXP (ad, 0) == frame_pointer_rtx
  1979.       && GET_CODE (XEXP (ad, 1)) == CONST_INT)
  1980.     return ad;
  1981.     }
  1982.  
  1983.   fmt = GET_RTX_FORMAT (code);
  1984.   for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
  1985.     if (fmt[i] == 'e')
  1986.       XEXP (ad, i) = subst_reg_equivs (XEXP (ad, i));
  1987.   return ad;
  1988. }
  1989.  
  1990. /* If ADDR is a sum containing a pseudo register that should be
  1991.    replaced with a constant (from reg_equiv_constant),
  1992.    return the result of doing so, and also apply the associative
  1993.    law so that the result is more likely to be a valid address.
  1994.    (But it is not guaranteed to be one.)
  1995.  
  1996.    In all other cases, return ADDR.  */
  1997.  
  1998. static rtx
  1999. subst_indexed_address (addr)
  2000.      rtx addr;
  2001. {
  2002.   rtx const_part = 0;
  2003.   rtx var_part = 0;
  2004.   int regno;
  2005.  
  2006.   if (GET_CODE (addr) == PLUS)
  2007.     {
  2008.       if (CONSTANT_P (XEXP (addr, 0)))
  2009.     const_part = XEXP (addr, 0),
  2010.     var_part = XEXP (addr, 1);
  2011.       else if (CONSTANT_P (XEXP (addr, 1)))
  2012.     const_part = XEXP (addr, 1),
  2013.     var_part = XEXP (addr, 0);
  2014.  
  2015.       if (const_part == 0)
  2016.     return addr;
  2017.  
  2018.       if (GET_CODE (const_part) == CONST)
  2019.     const_part = XEXP (const_part, 0);
  2020.  
  2021.       if (GET_CODE (var_part) == REG
  2022.       && (regno = REGNO (var_part)) >= FIRST_PSEUDO_REGISTER
  2023.       && reg_renumber[regno] < 0
  2024.       && reg_equiv_constant[regno] != 0)
  2025.     return gen_rtx (CONST, VOIDmode,
  2026.             gen_rtx (PLUS, Pmode, const_part,
  2027.                  reg_equiv_constant[regno]));
  2028.  
  2029.       if (GET_CODE (var_part) != PLUS)
  2030.     return addr;
  2031.  
  2032.       if (GET_CODE (XEXP (var_part, 0)) == REG
  2033.       && (regno = REGNO (XEXP (var_part, 0))) >= FIRST_PSEUDO_REGISTER
  2034.       && reg_renumber[regno] < 0
  2035.       && reg_equiv_constant[regno] != 0)
  2036.     return gen_rtx (PLUS, Pmode, XEXP (var_part, 1),
  2037.             gen_rtx (CONST, VOIDmode,
  2038.                  gen_rtx (PLUS, Pmode, const_part,
  2039.                       reg_equiv_constant[regno])));
  2040.  
  2041.       if (GET_CODE (XEXP (var_part, 1)) == REG
  2042.       && (regno = REGNO (XEXP (var_part, 1))) >= FIRST_PSEUDO_REGISTER
  2043.       && reg_renumber[regno] < 0
  2044.       && reg_equiv_constant[regno] != 0)
  2045.     return gen_rtx (PLUS, Pmode, XEXP (var_part, 0),
  2046.             gen_rtx (CONST, VOIDmode,
  2047.                  gen_rtx (PLUS, Pmode, const_part,
  2048.                       reg_equiv_constant[regno])));
  2049.     }
  2050.   return addr;
  2051. }
  2052.  
  2053. /* Record the pseudo registers we must reload into hard registers
  2054.    in a subexpression of a memory address, X.
  2055.    CONTEXT = 1 means we are considering regs as index regs,
  2056.    = 0 means we are considering them as base regs.
  2057.  
  2058.    We return X, whose operands may have been altered,
  2059.    or perhaps a RELOAD rtx if X itself was a REG that must be reloaded.  */
  2060.  
  2061. /* Note that we take shortcuts assuming that no multi-reg machine mode
  2062.    occurs as part of an address.
  2063.    Also, this is not fully machine-customizable; it works for machines
  2064.    such as vaxes and 68000's and 32000's, but other possible machines
  2065.    could have addressing modes that this does not handle right.  */
  2066.  
  2067. static void
  2068. find_reloads_address_1 (x, context, loc)
  2069.      rtx x;
  2070.      int context;
  2071.      rtx *loc;
  2072. {
  2073.   register RTX_CODE code = GET_CODE (x);
  2074.  
  2075.   if (code == PLUS)
  2076.     {
  2077.       register rtx op0 = XEXP (x, 0);
  2078.       register rtx op1 = XEXP (x, 1);
  2079.       register RTX_CODE code0 = GET_CODE (op0);
  2080.       register RTX_CODE code1 = GET_CODE (op1);
  2081.       if (code0 == MULT || code0 == SIGN_EXTEND || code1 == MEM)
  2082.     {
  2083.       find_reloads_address_1 (op0, 1, &XEXP (x, 0));
  2084.       find_reloads_address_1 (op1, 0, &XEXP (x, 1));
  2085.     }
  2086.       else if (code1 == MULT || code1 == SIGN_EXTEND || code0 == MEM)
  2087.     {
  2088.       find_reloads_address_1 (op0, 0, &XEXP (x, 0));
  2089.       find_reloads_address_1 (op1, 1, &XEXP (x, 1));
  2090.     }
  2091.       else if (code0 == CONST_INT || code0 == CONST
  2092.            || code0 == SYMBOL_REF || code0 == LABEL_REF)
  2093.     {
  2094.       find_reloads_address_1 (op1, 0, &XEXP (x, 1));
  2095.     }
  2096.       else if (code1 == CONST_INT || code1 == CONST
  2097.            || code1 == SYMBOL_REF || code1 == LABEL_REF)
  2098.     {
  2099.       find_reloads_address_1 (op0, 0, &XEXP (x, 0));
  2100.     }
  2101.       else if (code0 == REG && code1 == REG)
  2102.     {
  2103.       if (REG_OK_FOR_INDEX_P (op0)
  2104.           && REG_OK_FOR_BASE_P (op1))
  2105.         return;
  2106.       else if (REG_OK_FOR_INDEX_P (op1)
  2107.           && REG_OK_FOR_BASE_P (op0))
  2108.         return;
  2109.       else if (REG_OK_FOR_BASE_P (op1))
  2110.         find_reloads_address_1 (op0, 1, &XEXP (x, 0));
  2111.       else if (REG_OK_FOR_BASE_P (op0))
  2112.         find_reloads_address_1 (op1, 1, &XEXP (x, 1));
  2113.       else if (REG_OK_FOR_INDEX_P (op1))
  2114.         find_reloads_address_1 (op0, 0, &XEXP (x, 0));
  2115.       else if (REG_OK_FOR_INDEX_P (op0))
  2116.         find_reloads_address_1 (op1, 0, &XEXP (x, 1));
  2117.       else
  2118.         {
  2119.           find_reloads_address_1 (op0, 1, &XEXP (x, 0));
  2120.           find_reloads_address_1 (op1, 0, &XEXP (x, 1));
  2121.         }
  2122.     }
  2123.       else if (code0 == REG)
  2124.     {
  2125.       find_reloads_address_1 (op0, 1, &XEXP (x, 0));
  2126.       find_reloads_address_1 (op1, 0, &XEXP (x, 1));
  2127.     }
  2128.       else if (code1 == REG)
  2129.     {
  2130.       find_reloads_address_1 (op1, 1, &XEXP (x, 1));
  2131.       find_reloads_address_1 (op0, 0, &XEXP (x, 0));
  2132.     }
  2133.     }
  2134.   else if (code == POST_INC || code == POST_DEC
  2135.        || code == PRE_INC || code == PRE_DEC)
  2136.     {
  2137.       if (GET_CODE (XEXP (x, 0)) == REG)
  2138.     {
  2139.       register int regno = REGNO (XEXP (x, 0));
  2140.  
  2141.       /* A register that is incremented cannot be constant!  */
  2142.       if (regno >= FIRST_PSEUDO_REGISTER
  2143.           && reg_equiv_constant[regno] != 0)
  2144.         abort ();
  2145.  
  2146.       /* Handle a register that is equivalent to a memory location
  2147.          which cannot be addressed directly.  */
  2148.       if (reg_equiv_address[regno] != 0)
  2149.         {
  2150.           rtx tem = make_memloc (XEXP (x, 0), regno);
  2151.           /* First reload the memory location's address.  */
  2152.           push_reload (XEXP (tem, 0), 0, &XEXP (tem, 0), 0,
  2153.                BASE_REG_CLASS,
  2154.                GET_MODE (XEXP (tem, 0)), 0, VOIDmode, 0);
  2155.           /* Then reload the memory reference itself,
  2156.          pretending it is located in the PRE_INC or whatever.  */
  2157.           push_reload (tem, tem, &XEXP (x, 0), 0,
  2158.                context ? INDEX_REG_CLASS : BASE_REG_CLASS,
  2159.                GET_MODE (tem), GET_MODE (tem), VOIDmode, 0);
  2160.           return;
  2161.         }
  2162.  
  2163.       /* Handle any other sort of register.  */
  2164.  
  2165.       if (reg_renumber[regno] >= 0)
  2166.         regno = reg_renumber[regno];
  2167.       if ((regno >= FIRST_PSEUDO_REGISTER
  2168.            || !(context ? REGNO_OK_FOR_INDEX_P (regno)
  2169.             : REGNO_OK_FOR_BASE_P (regno))))
  2170.         {
  2171.           register rtx link;
  2172.           int reloadnum
  2173.         = push_reload (XEXP (x, 0), XEXP (x, 0),
  2174.                    &XEXP (x, 0), 0,
  2175.                    context ? INDEX_REG_CLASS : BASE_REG_CLASS,
  2176.                    GET_MODE (XEXP (x, 0)),
  2177.                    GET_MODE (XEXP (x, 0)), VOIDmode, 0);
  2178.  
  2179.           for (link = REG_NOTES (this_insn);
  2180.            link; link = XEXP (link, 1))
  2181.         if (REG_NOTE_KIND (link) == REG_INC
  2182.             && REGNO (XEXP (link, 0)) == REGNO (XEXP (x, 0)))
  2183.           push_replacement (&XEXP (link, 0), reloadnum, VOIDmode);
  2184.         }
  2185.       return;
  2186.     }
  2187.     }
  2188.   else if (code == REG)
  2189.     {
  2190.       register int regno = REGNO (x);
  2191.  
  2192.       if (regno >= FIRST_PSEUDO_REGISTER && reg_renumber[regno] < 0
  2193.       && reg_equiv_constant[regno] != 0)
  2194.     {
  2195.       push_reload (reg_equiv_constant[regno], 0, loc, 0,
  2196.                context ? INDEX_REG_CLASS : BASE_REG_CLASS,
  2197.                GET_MODE (x), 0, VOIDmode, 0);
  2198.       return;
  2199.     }
  2200.  
  2201.       if (reg_equiv_address[regno] != 0)
  2202.     {
  2203.       x = make_memloc (x, regno);
  2204.       push_reload (XEXP (x, 0), 0, &XEXP (x, 0), 0,
  2205.                BASE_REG_CLASS,
  2206.                GET_MODE (XEXP (x, 0)), 0, VOIDmode, 0);
  2207.     }
  2208.  
  2209.       if (reg_renumber[regno] >= 0)
  2210.     regno = reg_renumber[regno];
  2211.       if ((regno >= FIRST_PSEUDO_REGISTER
  2212.        || !(context ? REGNO_OK_FOR_INDEX_P (regno)
  2213.         : REGNO_OK_FOR_BASE_P (regno))))
  2214.     {
  2215.       push_reload (x, 0, loc, 0,
  2216.                context ? INDEX_REG_CLASS : BASE_REG_CLASS,
  2217.                GET_MODE (x), 0, VOIDmode, 0);
  2218.       return;
  2219.     }
  2220.     }
  2221.   else
  2222.     {
  2223.       register char *fmt = GET_RTX_FORMAT (code);
  2224.       register int i;
  2225.       for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
  2226.     {
  2227.       if (fmt[i] == 'e')
  2228.         find_reloads_address_1 (XEXP (x, i), context, &XEXP (x, i));
  2229.     }
  2230.     }
  2231. }
  2232.  
  2233. /* Substitute into X the registers into which we have reloaded
  2234.    the things that need reloading.  The array `replacements'
  2235.    says contains the locations of all pointers that must be changed
  2236.    and says what to replace them with.
  2237.  
  2238.    Return the rtx that X translates into; usually X, but modified.  */
  2239.  
  2240. void
  2241. subst_reloads ()
  2242. {
  2243.   register int i;
  2244.  
  2245.   for (i = 0; i < n_replacements; i++)
  2246.     {
  2247.       register struct replacement *r = &replacements[i];
  2248.       register rtx reloadreg = reload_reg_rtx[r->what];
  2249.       if (reloadreg)
  2250.     {
  2251.       /* Encapsulate RELOADREG so its machine mode matches what
  2252.          used to be there.  */
  2253.       if (GET_MODE (reloadreg) != r->mode && r->mode != VOIDmode)
  2254.         reloadreg = gen_rtx (SUBREG, r->mode, reloadreg, 0);
  2255.       *r->where = reloadreg;
  2256.     }
  2257.       /* If reload got no reg and isn't optional, something's wrong.  */
  2258.       else if (! reload_optional[r->what])
  2259.     abort ();
  2260.     }
  2261. }
  2262.  
  2263. #if 0
  2264.  
  2265. /* [[This function is currently obsolete, now that volatility
  2266.    is represented by a special bit `volatil' so VOLATILE is never used;
  2267.    and UNCHANGING has never been brought into use.]]
  2268.  
  2269.    Alter X by eliminating all VOLATILE and UNCHANGING expressions.
  2270.    Each of them is replaced by its operand.
  2271.    Thus, (PLUS (VOLATILE (MEM (REG 5))) (CONST_INT 4))
  2272.    becomes (PLUS (MEM (REG 5)) (CONST_INT 4)).
  2273.  
  2274.    If X is itself a VOLATILE expression,
  2275.    we return the expression that should replace it
  2276.    but we do not modify X.  */
  2277.  
  2278. static rtx
  2279. forget_volatility (x)
  2280.      register rtx x;
  2281. {
  2282.   enum rtx_code code = GET_CODE (x);
  2283.   register char *fmt;
  2284.   register int i;
  2285.   register rtx value = 0;
  2286.  
  2287.   switch (code)
  2288.     {
  2289.     case LABEL_REF:
  2290.     case SYMBOL_REF:
  2291.     case CONST_INT:
  2292.     case CONST_DOUBLE:
  2293.     case CONST:
  2294.     case REG:
  2295.     case CC0:
  2296.     case PC:
  2297.       return x;
  2298.  
  2299.     case VOLATILE:
  2300.     case UNCHANGING:
  2301.       return XEXP (x, 0);
  2302.     }
  2303.  
  2304.   fmt = GET_RTX_FORMAT (code);
  2305.   for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
  2306.     {
  2307.       if (fmt[i] == 'e')
  2308.     XEXP (x, i) = forget_volatility (XEXP (x, i));
  2309.       if (fmt[i] == 'E')
  2310.     {
  2311.       register int j;
  2312.       for (j = XVECLEN (x, i) - 1; j >= 0; j--)
  2313.         XVECEXP (x, i, j) = forget_volatility (XVECEXP (x, i, j));
  2314.     }
  2315.     }
  2316.  
  2317.   return x;
  2318. }
  2319.  
  2320. #endif
  2321.  
  2322. /* Check the insns before INSN to see if there is a suitable register
  2323.    containing the same value as GOAL.
  2324.    If OTHER is -1, look for a register in class CLASS.
  2325.    Otherwise, just see if register number OTHER shares GOAL's value.
  2326.  
  2327.    Return an rtx for the register found, or zero if none is found.
  2328.  
  2329.    If RELOAD_REG_P is (short *)1,
  2330.    we reject any hard reg that appears in reload_reg_rtx
  2331.    because such a hard reg is also needed coming into this insn.
  2332.  
  2333.    If RELOAD_REG_P is any other nonzero value,
  2334.    it is a vector indexed by hard reg number
  2335.    and we reject any hard reg whose element in the vector is nonnegative
  2336.    as well as any that appears in reload_reg_rtx.
  2337.  
  2338.    If GOAL is zero, then GOALREG is a register number; we look
  2339.    for an equivalent for that register.
  2340.  
  2341.    MODE is the machine mode of the value we want an equivalence for.
  2342.    If GOAL is nonzero and not VOIDmode, then it must have mode MODE.
  2343.  
  2344.    This function is used by jump.c as well as in the reload pass.
  2345.  
  2346.    If GOAL is a PLUS, we assume it adds the stack pointer to a constant.  */
  2347.  
  2348. rtx
  2349. find_equiv_reg (goal, insn, class, other, reload_reg_p, goalreg, mode)
  2350.      register rtx goal;
  2351.      rtx insn;
  2352.      enum reg_class class;
  2353.      register int other;
  2354.      short *reload_reg_p;
  2355.      int goalreg;
  2356.      enum machine_mode mode;
  2357. {
  2358.   register rtx p = insn;
  2359.   rtx valtry, value, where;
  2360.   register rtx pat;
  2361.   register int regno = -1;
  2362.   int valueno;
  2363.   int goal_mem = 0;
  2364.   int goal_const = 0;
  2365.   int goal_mem_addr_varies = 0;
  2366.   int nregs;
  2367.   int valuenregs;
  2368.  
  2369.   if (goal == 0)
  2370.     regno = goalreg;
  2371.   else if (GET_CODE (goal) == REG)
  2372.     regno = REGNO (goal);
  2373.   else if (GET_CODE (goal) == MEM)
  2374.     {
  2375.       enum rtx_code code = GET_CODE (XEXP (goal, 0));
  2376.       /* An address with side effects must be reexecuted.  */
  2377.       switch (code)
  2378.     {
  2379.     case POST_INC:
  2380.     case PRE_INC:
  2381.     case POST_DEC:
  2382.     case PRE_DEC:
  2383.       return 0;
  2384.     }
  2385.       goal_mem = 1;
  2386.     }
  2387.   else if (CONSTANT_P (goal))
  2388.     goal_const = 1;
  2389.   else
  2390.     return 0;
  2391.  
  2392.   /* On some machines, certain regs must always be rejected
  2393.      because they don't behave the way ordinary registers do.  */
  2394.   
  2395. #ifdef OVERLAPPING_REGNO_P
  2396.    if (regno >= 0 && OVERLAPPING_REGNO_P (regno))
  2397.      return 0;
  2398. #endif      
  2399.  
  2400.   /* Scan insns back from INSN, looking for one that copies
  2401.      a value into or out of GOAL.
  2402.      Stop and give up if we reach a label.  */
  2403.  
  2404.   while (1)
  2405.     {
  2406.       p = PREV_INSN (p);
  2407.       if (p == 0 || GET_CODE (p) == CODE_LABEL)
  2408.     return 0;
  2409.       if (GET_CODE (p) == INSN
  2410.       /* If we don't want spill regs (true for all calls in this file) */
  2411.       && (! (reload_reg_p != 0 && reload_reg_p != (short *)1)
  2412.       /* then ignore insns introduced by reload; they aren't useful
  2413.          and can cause results in reload_as_needed to be different
  2414.          from what they were when calculating the need for spills.
  2415.          If we notice an input-reload insn here, we will reject it below,
  2416.          but it might hide a usable equivalent.  That makes bad code.
  2417.          It may even abort: perhaps no reg was spilled for this insn
  2418.          because it was assumed we would find that equivalent.  */
  2419.           || INSN_UID (p) < reload_first_uid))
  2420.     {
  2421.       pat = PATTERN (p);
  2422.       /* First check for something that sets some reg equal to GOAL.  */
  2423.       if (GET_CODE (pat) == SET
  2424.           && ((regno >= 0
  2425.            && GET_CODE (SET_SRC (pat)) == REG
  2426.            && REGNO (SET_SRC (pat)) == regno
  2427.            && GET_CODE (valtry = SET_DEST (pat)) == REG)
  2428.           ||
  2429.           (regno >= 0
  2430.            && GET_CODE (SET_DEST (pat)) == REG
  2431.            && REGNO (SET_DEST (pat)) == regno
  2432.            && GET_CODE (valtry = SET_SRC (pat)) == REG)
  2433.           ||
  2434.           (goal_const && rtx_equal_p (SET_SRC (pat), goal)
  2435.            && GET_CODE (valtry = SET_DEST (pat)) == REG)
  2436.           || (goal_mem
  2437.               && GET_CODE (valtry = SET_DEST (pat)) == REG
  2438.               && rtx_renumbered_equal_p (goal, SET_SRC (pat)))
  2439.           || (goal_mem
  2440.               && GET_CODE (valtry = SET_SRC (pat)) == REG
  2441.               && rtx_renumbered_equal_p (goal, SET_DEST (pat)))))
  2442.         if (valueno = REGNO (valtry),
  2443.         other >= 0
  2444.         ? valueno == other
  2445.         : ((unsigned) valueno < FIRST_PSEUDO_REGISTER
  2446.            && TEST_HARD_REG_BIT (reg_class_contents[(int) class],
  2447.                      valueno)))
  2448.           {
  2449.         value = valtry;
  2450.         where = p;
  2451.         break;
  2452.           }
  2453.     }
  2454.     }
  2455.  
  2456.   /* We found a previous insn copying GOAL into a suitable other reg VALUE
  2457.      (or copying VALUE into GOAL, if GOAL is also a register).
  2458.      Now verify that VALUE is really valid.  */
  2459.  
  2460.   /* VALUENO is the register number of VALUE; a hard register.  */
  2461.  
  2462.   /* Don't find the sp as an equiv, since pushes that we don't notice
  2463.      would invalidate it.  */
  2464.   if (valueno == STACK_POINTER_REGNUM)
  2465.     return 0;
  2466.  
  2467.   /* Reject VALUE if the copy-insn moved the wrong sort of datum.  */
  2468.   if (GET_MODE (value) != mode)
  2469.     return 0;
  2470.  
  2471.   /* Reject VALUE if it was loaded from GOAL
  2472.      and is also a register that appears in the address of GOAL.  */
  2473.  
  2474.   if (goal_mem && value == SET_DEST (PATTERN (where))
  2475.       && refers_to_regno_p (valueno, goal, 0))
  2476.     return 0;
  2477.  
  2478.   /* Reject VALUE if it is one of the regs reserved for reloads.
  2479.      Reload1 knows how to reuse them anyway, and it would get
  2480.      confused if we allocated one without its knowledge.
  2481.      (Now that insns introduced by reload are ignored above,
  2482.      this case shouldn't happen, but I'm not positive.)  */
  2483.  
  2484.   if (reload_reg_p != 0 && reload_reg_p != (short *)1
  2485.       && reload_reg_p[valueno] >= 0)
  2486.     return 0;
  2487.  
  2488.   /* On some machines, certain regs must always be rejected
  2489.      because they don't behave the way ordinary registers do.  */
  2490.   
  2491. #ifdef OVERLAPPING_REGNO_P
  2492.    if (OVERLAPPING_REGNO_P (valueno))
  2493.      return 0;
  2494. #endif      
  2495.  
  2496.   /* Reject VALUE if it is a register being used for an input reload
  2497.      even if it is not one of those reserved.  */
  2498.  
  2499.   if (reload_reg_p != 0)
  2500.     {
  2501.       int i;
  2502.       for (i = 0; i < n_reloads; i++)
  2503.     if (reload_reg_rtx[i] != 0 && reload_in[i])
  2504.       {
  2505.         int regno1 = REGNO (reload_reg_rtx[i]);
  2506.         if (valueno == regno1)
  2507.           return 0;
  2508.       }
  2509.     }
  2510.  
  2511.   if (goal_mem)
  2512.     goal_mem_addr_varies = rtx_addr_varies_p (goal);
  2513.  
  2514.   nregs = HARD_REGNO_NREGS (regno, mode);
  2515.   valuenregs = HARD_REGNO_NREGS (valueno, mode);
  2516.  
  2517.   /* Now verify that the values of GOAL and VALUE remain unaltered
  2518.      until INSN is reached.  */
  2519.  
  2520.   p = insn;
  2521.   while (1)
  2522.     {
  2523.       p = PREV_INSN (p);
  2524.       if (p == where)
  2525.     return value;
  2526.  
  2527.       /* Don't trust the conversion past a function call
  2528.      if either of the two is in a call-clobbered register, or memory.  */
  2529.       if (GET_CODE (p) == CALL_INSN
  2530.       && ((regno >= 0 && regno < FIRST_PSEUDO_REGISTER
  2531.            && call_used_regs[regno])
  2532.           ||
  2533.           (valueno >= 0 && valueno < FIRST_PSEUDO_REGISTER
  2534.            && call_used_regs[valueno])
  2535.           ||
  2536.           goal_mem))
  2537.     return 0;
  2538.  
  2539.       if (GET_CODE (p) == INSN || GET_CODE (p) == JUMP_INSN
  2540.       || GET_CODE (p) == CALL_INSN)
  2541.     {
  2542.       /* If this insn P stores in either GOAL or VALUE, return 0.
  2543.          If GOAL is a memory ref and this insn writes memory, return 0.
  2544.          If GOAL is a memory ref and its address is not constant,
  2545.          and this insn P changes a register, return 0.
  2546.          That is in lieue of checking whether GOAL uses this register.  */
  2547.  
  2548.       pat = PATTERN (p);
  2549.       if (GET_CODE (pat) == SET || GET_CODE (pat) == CLOBBER)
  2550.         {
  2551.           register rtx dest = SET_DEST (pat);
  2552.           while (GET_CODE (dest) == SUBREG
  2553.              || GET_CODE (dest) == ZERO_EXTRACT
  2554.              || GET_CODE (dest) == SIGN_EXTRACT
  2555.              || GET_CODE (dest) == STRICT_LOW_PART)
  2556.         dest = XEXP (dest, 0);
  2557.           if (GET_CODE (dest) == REG)
  2558.         {
  2559.           register int xregno = REGNO (dest);
  2560.           int xnregs = HARD_REGNO_NREGS (xregno, GET_MODE_SIZE (GET_MODE (dest)));
  2561.           if (xregno < regno + nregs && xregno + xnregs > regno)
  2562.             return 0;
  2563.           if (xregno < valueno + valuenregs
  2564.               && xregno + xnregs > valueno)
  2565.             return 0;
  2566.           if (goal_mem_addr_varies)
  2567.             return 0;
  2568.         }
  2569.           else if (goal_mem && GET_CODE (dest) == MEM
  2570.                && ! push_operand (dest, GET_MODE (dest)))
  2571.         return 0;
  2572.         }
  2573.       else if (GET_CODE (pat) == PARALLEL)
  2574.         {
  2575.           register int i;
  2576.           for (i = XVECLEN (pat, 0) - 1; i >= 0; i--)
  2577.         {
  2578.           register rtx v1 = XVECEXP (pat, 0, i);
  2579.           if (GET_CODE (v1) == SET || GET_CODE (v1) == CLOBBER)
  2580.             {
  2581.               register rtx dest = SET_DEST (v1);
  2582.               while (GET_CODE (dest) == SUBREG
  2583.                  || GET_CODE (dest) == ZERO_EXTRACT
  2584.                  || GET_CODE (dest) == SIGN_EXTRACT
  2585.                  || GET_CODE (dest) == STRICT_LOW_PART)
  2586.             dest = XEXP (dest, 0);
  2587.               if (GET_CODE (dest) == REG)
  2588.             {
  2589.               register int xregno = REGNO (dest);
  2590.               int xnregs = HARD_REGNO_NREGS (xregno, GET_MODE_SIZE (GET_MODE (dest)));
  2591.               if (xregno < regno + nregs
  2592.                   && xregno + xnregs > regno)
  2593.                 return 0;
  2594.               if (xregno < valueno + valuenregs
  2595.                   && xregno + xnregs > valueno)
  2596.                 return 0;
  2597.               if (goal_mem_addr_varies)
  2598.                 return 0;
  2599.             }
  2600.               else if (goal_mem && GET_CODE (dest) == MEM
  2601.                    && ! push_operand (dest, GET_MODE (dest)))
  2602.             return 0;
  2603.             }
  2604.         }
  2605.         }
  2606.       /* If this insn auto-increments or auto-decrements
  2607.          either regno or valueno, return 0 now.
  2608.          If GOAL is a memory ref and its address is not constant,
  2609.          and this insn P increments a register, return 0.
  2610.          That is in lieue of checking whether GOAL uses this register.  */
  2611.       {
  2612.         register rtx link;
  2613.  
  2614.         for (link = REG_NOTES (p); link; link = XEXP (link, 1))
  2615.           if (REG_NOTE_KIND (link) == REG_INC)
  2616.         {
  2617.           register int incno = REGNO (XEXP (link, 0));
  2618.           if (incno < regno + nregs && incno >= regno)
  2619.             return 0;
  2620.           if (incno < valueno + valuenregs && incno >= valueno)
  2621.             return 0;
  2622.           if (goal_mem_addr_varies)
  2623.             return 0;
  2624.         }
  2625.       }
  2626.     }
  2627.     }
  2628. }
  2629.  
  2630. /* Find a place where INCED appears in an increment or decrement operator
  2631.    within X, and return the amount INCED is incremented by
  2632.    (negative if decremented).  */
  2633.  
  2634. static int
  2635. find_inc_amount (x, inced)
  2636.      rtx x, inced;
  2637. {
  2638.   register enum rtx_code code = GET_CODE (x);
  2639.   register char *fmt;
  2640.   register int i;
  2641.  
  2642.   if (code == MEM)
  2643.     {
  2644.       register rtx addr = XEXP (x, 0);
  2645.       if ((GET_CODE (addr) == PRE_DEC
  2646.        || GET_CODE (addr) == POST_DEC)
  2647.       && XEXP (addr, 0) == inced)
  2648.     return - GET_MODE_SIZE (GET_MODE (x));
  2649.       if ((GET_CODE (addr) == PRE_INC
  2650.        || GET_CODE (addr) == POST_INC)
  2651.       && XEXP (addr, 0) == inced)
  2652.     return GET_MODE_SIZE (GET_MODE (x));
  2653.     }
  2654.  
  2655.   fmt = GET_RTX_FORMAT (code);
  2656.   for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
  2657.     {
  2658.       if (fmt[i] == 'e')
  2659.     {
  2660.       register int tem = find_inc_amount (XEXP (x, i), inced);
  2661.       if (tem != 0)
  2662.         return tem;
  2663.     }
  2664.       if (fmt[i] == 'E')
  2665.     {
  2666.       register int j;
  2667.       for (j = XVECLEN (x, i) - 1; j >= 0; j--)
  2668.         {
  2669.           register int tem = find_inc_amount (XVECEXP (x, i, j), inced);
  2670.           if (tem != 0)
  2671.         return tem;
  2672.         }
  2673.     }
  2674.     }
  2675.  
  2676.   return 0;
  2677. }
  2678.