home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Tools / Languages / GCC 1.37.1r14 / usr / gcc-1.37.1r14 / (gcc-1.37.π) / reload.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-09-28  |  100.8 KB  |  3,291 lines  |  [TEXT/KAHL]

  1. /* Search an insn for pseudo regs that must be in hard regs and are not.
  2.    Copyright (C) 1987, 1988, 1989 Free Software Foundation, Inc.
  3.    Copyright (C) 1989, 1990 Apple Computer, Inc.
  4.  
  5. This file is part of GNU CC.
  6.  
  7. GNU CC is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 1, or (at your option)
  10. any later version.
  11.  
  12. GNU CC is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. GNU General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with GNU CC; see the file COPYING.  If not, write to
  19. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  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. Using a reload register for several reloads in one insn:
  70.  
  71. When an insn has reloads, it is considered as having three parts:
  72. the input reloads, the insn itself after reloading, and the output reloads.
  73. Reloads of values used in memory addresses are often needed for only one part.
  74.  
  75. When this is so, reload_when_needed records which part needs the reload.
  76. Two reloads for different parts of the insn can share the same reload
  77. register.
  78.  
  79. When a reload is used for addresses in multiple parts, or when it is
  80. an ordinary operand, it is classified as RELOAD_OTHER, and cannot share
  81. a register with any other reload.  */
  82.  
  83. #define REG_OK_STRICT
  84.  
  85. #include "config.h"
  86. #include "rtl.h"
  87. #include "insn-config.h"
  88. #include "recog.h"
  89. #include "reload.h"
  90. #include "regs.h"
  91. #include "hard-reg-set.h"
  92. #include "flags.h"
  93. #include "real.h"
  94.  
  95. /* The variables set up by `find_reloads' are:
  96.  
  97.    n_reloads          number of distinct reloads needed; max reload # + 1
  98.        tables indexed by reload number
  99.    reload_in          rtx for value to reload from
  100.    reload_out          rtx for where to store reload-reg afterward if nec
  101.                (often the same as reload_in)
  102.    reload_reg_class      enum reg_class, saying what regs to reload into
  103.    reload_inmode      enum machine_mode; mode this operand should have
  104.                when reloaded, on input.
  105.    reload_outmode      enum machine_mode; mode this operand should have
  106.                when reloaded, on output.
  107.    reload_strict_low      char; 1 if this reload is inside a STRICT_LOW_PART.
  108.    reload_optional      char, nonzero for an optional reload.
  109.                Optional reloads are ignored unless the
  110.                value is already sitting in a register.
  111.    reload_inc          int, positive amount to increment or decrement by if
  112.                reload_in is a PRE_DEC, PRE_INC, POST_DEC, POST_INC.
  113.                Ignored otherwise (don't assume it is zero).
  114.    reload_in_reg      rtx.  A reg for which reload_in is the equivalent.
  115.                If reload_in is a symbol_ref which came from
  116.                reg_equiv_constant, then this is the pseudo
  117.                which has that symbol_ref as equivalent.
  118.    reload_reg_rtx      rtx.  This is the register to reload into.
  119.                If it is zero when `find_reloads' returns,
  120.                you must find a suitable register in the class
  121.                specified by reload_reg_class, and store here
  122.                an rtx for that register with mode from
  123.                reload_inmode or reload_outmode.
  124.    reload_nocombine      char, nonzero if this reload shouldn't be
  125.                combined with another reload.
  126.    reload_needed_for      rtx, operand this reload is needed for address of.
  127.                0 means it isn't needed for addressing.
  128.    reload_needed_for_multiple
  129.               int, 1 if this reload needed for more than one thing.
  130.    reload_when_needed     enum, classifies reload as needed either for
  131.                addressing an input reload, addressing an output,
  132.                for addressing a non-reloaded mem ref,
  133.                or for unspecified purposes (i.e., more than one
  134.                of the above).  */
  135.  
  136. int n_reloads;
  137.  
  138. rtx reload_in[MAX_RELOADS];
  139. rtx reload_out[MAX_RELOADS];
  140. enum reg_class reload_reg_class[MAX_RELOADS];
  141. enum machine_mode reload_inmode[MAX_RELOADS];
  142. enum machine_mode reload_outmode[MAX_RELOADS];
  143. char reload_strict_low[MAX_RELOADS];
  144. rtx reload_reg_rtx[MAX_RELOADS];
  145. char reload_optional[MAX_RELOADS];
  146. int reload_inc[MAX_RELOADS];
  147. rtx reload_in_reg[MAX_RELOADS];
  148. char reload_nocombine[MAX_RELOADS];
  149. int reload_needed_for_multiple[MAX_RELOADS];
  150. rtx reload_needed_for[MAX_RELOADS];
  151. enum reload_when_needed reload_when_needed[MAX_RELOADS];
  152.  
  153. /* All the "earlyclobber" operands of the current insn
  154.    are recorded here.  */
  155. int n_earlyclobbers;
  156. rtx reload_earlyclobbers[MAX_RECOG_OPERANDS];
  157.  
  158. /* Replacing reloads.
  159.  
  160.    If `replace_reloads' is nonzero, then as each reload is recorded
  161.    an entry is made for it in the table `replacements'.
  162.    Then later `subst_reloads' can look through that table and
  163.    perform all the replacements needed.  */
  164.  
  165. /* Nonzero means record the places to replace.  */
  166. static int replace_reloads;
  167.  
  168. /* Each replacement is recorded with a structure like this.  */
  169. struct replacement
  170. {
  171.   rtx *where;            /* Location to store in */
  172.   int what;            /* which reload this is for */
  173.   enum machine_mode mode;    /* mode it must have */
  174. };
  175.  
  176. static struct replacement replacements[MAX_RECOG_OPERANDS * ((MAX_REGS_PER_ADDRESS * 2) + 1)];
  177.  
  178. /* Number of replacements currently recorded.  */
  179. static int n_replacements;
  180.  
  181. /* MEM-rtx's created for pseudo-regs in stack slots not directly addressable;
  182.    (see reg_equiv_address).  */
  183. static rtx memlocs[MAX_RECOG_OPERANDS * ((MAX_REGS_PER_ADDRESS * 2) + 1)];
  184. static int n_memlocs;
  185.  
  186. /* The instruction we are doing reloads for;
  187.    so we can test whether a register dies in it.  */
  188. static rtx this_insn;
  189.  
  190. /* Nonzero means (MEM (REG n)) is valid even if (REG n) is spilled.  */
  191. static int indirect_ok;
  192.  
  193. /* If hard_regs_live_known is nonzero,
  194.    we can tell which hard regs are currently live,
  195.    at least enough to succeed in choosing dummy reloads.  */
  196. static int hard_regs_live_known;
  197.  
  198. /* Indexed by hard reg number,
  199.    element is nonegative if hard reg has been spilled.
  200.    This vector is passed to `find_reloads' as an argument
  201.    and is not changed here.  */
  202. static short *static_reload_reg_p;
  203.  
  204. /* Set to 1 in subst_reg_equivs if it changes anything.  */
  205. static int subst_reg_equivs_changed;
  206.  
  207. /* On return from push_reload, holds the reload-number for the OUT
  208.    operand, which can be different for that from the input operand.  */
  209. static int output_reloadnum;
  210.  
  211. static int alternative_allows_memconst ();
  212. static rtx find_dummy_reload ();
  213. static rtx find_reloads_toplev ();
  214. static int find_reloads_address ();
  215. static int find_reloads_address_1 ();
  216. static int hard_reg_set_here_p ();
  217. /* static rtx forget_volatility (); */
  218. static rtx subst_reg_equivs ();
  219. static rtx subst_indexed_address ();
  220. rtx find_equiv_reg ();
  221. static int find_inc_amount ();
  222.  
  223. /* Record one (sometimes two) reload that needs to be performed.
  224.    IN is an rtx saying where the data are to be found before this instruction.
  225.    OUT says where they must be stored after the instruction.
  226.    (IN is zero for data not read, and OUT is zero for data not written.)
  227.    INLOC and OUTLOC point to the places in the instructions where
  228.    IN and OUT were found.
  229.    CLASS is a register class required for the reloaded data.
  230.    INMODE is the machine mode that the instruction requires
  231.    for the reg that replaces IN and OUTMODE is likewise for OUT.
  232.  
  233.    If IN is zero, then OUT's location and mode should be passed as
  234.    INLOC and INMODE.
  235.  
  236.    STRICT_LOW is the 1 if there is a containing STRICT_LOW_PART rtx.
  237.  
  238.    OPTIONAL nonzero means this reload does not need to be performed:
  239.    it can be discarded if that is more convenient.
  240.  
  241.    The return value is the reload-number for this reload.
  242.  
  243.    If both IN and OUT are nonzero, in some rare cases we might
  244.    want to make two separate reloads.  (Actually we never do this now.)
  245.    Therefore, the reload-number for OUT is stored in
  246.    output_reloadnum when we return; the return value applies to IN.
  247.    Usually (presently always), when IN and OUT are nonzero,
  248.    the two reload-numbers are equal, but the caller should be careful to
  249.    distinguish them.  */
  250.  
  251. static int
  252. push_reload (in, out, inloc, outloc, class,
  253.          inmode, outmode, strict_low, optional, needed_for)
  254.      register rtx in, out;
  255.      rtx *inloc, *outloc;
  256.      enum reg_class class;
  257.      enum machine_mode inmode, outmode;
  258.      int strict_low;
  259.      int optional;
  260.      rtx needed_for;
  261. {
  262.   register int i;
  263.   int dont_share = 0;
  264.  
  265.   /* Compare two RTX's.  */
  266. #define MATCHES(x, y) (x == y || (x != 0 && GET_CODE (x) != REG && rtx_equal_p (x, y)))
  267.  
  268.   /* INMODE and/or OUTMODE could be VOIDmode if no mode
  269.      has been specified for the operand.  In that case,
  270.      use the operand's mode as the mode to reload.  */
  271.   if (inmode == VOIDmode && in != 0)
  272.     inmode = GET_MODE (in);
  273.   if (outmode == VOIDmode && out != 0)
  274.     outmode = GET_MODE (out);
  275.  
  276.   /* If IN is a pseudo register everywhere-equivalent to a constant, and 
  277.      it is not in a hard register, reload straight from the constant,
  278.      since we want to get rid of such pseudo registers.
  279.      Often this is done earlier, but not always in find_reloads_address.  */
  280.   if (in != 0 && GET_CODE (in) == REG)
  281.     {
  282.       register int regno = REGNO (in);
  283.  
  284.       if (regno >= FIRST_PSEUDO_REGISTER && reg_renumber[regno] < 0
  285.       && reg_equiv_constant[regno] != 0)
  286.     in = reg_equiv_constant[regno];
  287.     }
  288.  
  289.   /* Likewise for OUT.  Of course, OUT will never be equivalent to
  290.      an actual constant, but it might be equivalent to a memory location
  291.      (in the case of a parameter).  */
  292.   if (out != 0 && GET_CODE (out) == REG)
  293.     {
  294.       register int regno = REGNO (out);
  295.  
  296.       if (regno >= FIRST_PSEUDO_REGISTER && reg_renumber[regno] < 0
  297.       && reg_equiv_constant[regno] != 0)
  298.     out = reg_equiv_constant[regno];
  299.     }
  300.  
  301.   /* If we have a read-write operand with an address side-effect,
  302.      change either IN or OUT so the side-effect happens only once.  */
  303.   if (in != 0 && out != 0 && GET_CODE (in) == MEM && rtx_equal_p (in, out))
  304.     {
  305.       if (GET_CODE (XEXP (in, 0)) == POST_INC
  306.       || GET_CODE (XEXP (in, 0)) == POST_DEC)
  307.     in = gen_rtx (MEM, GET_MODE (in), XEXP (XEXP (in, 0), 0));
  308.       if (GET_CODE (XEXP (in, 0)) == PRE_INC
  309.       || GET_CODE (XEXP (in, 0)) == PRE_DEC)
  310.     out = gen_rtx (MEM, GET_MODE (out), XEXP (XEXP (out, 0), 0));
  311.     }
  312.  
  313.   /* If we are reloading a (SUBREG (MEM ...) ...) or (SUBREG constant ...),
  314.      really reload just the inside expression in its own mode.
  315.      Note that the case of (SUBREG (CONST_INT...)...) is handled elsewhere;
  316.      we can't handle it here because CONST_INT does not indicate a mode.  */
  317.  
  318.   if (in != 0 && GET_CODE (in) == SUBREG && GET_CODE (SUBREG_REG (in)) != REG)
  319.     {
  320.       inloc = &SUBREG_REG (in);
  321.       in = *inloc;
  322.       if (GET_CODE (SUBREG_REG (in)) == MEM)
  323.     /* This is supposed to happen only for paradoxical subregs made by
  324.        combine.c.  (SUBREG (MEM)) isn't supposed to occur other ways.  */
  325.     if (GET_MODE_SIZE (GET_MODE (in)) > GET_MODE_SIZE (inmode))
  326.       abort ();
  327.       inmode = GET_MODE (in);
  328.     }
  329.  
  330.   /* If IN appears in OUT, we can't share any input-only reload for IN.  */
  331.   if (in != 0 && out != 0 && reg_overlap_mentioned_p (in, out))
  332.     dont_share = 1;
  333.  
  334.   /* Narrow down the class of register wanted if that is
  335.      desirable on this machine for efficiency.  */
  336.   if (in != 0)
  337.     class = PREFERRED_RELOAD_CLASS (in, class);
  338.  
  339.   if (class == NO_REGS)
  340.     abort ();
  341.  
  342.   /* We can use an existing reload if the class is right
  343.      and at least one of IN and OUT is a match
  344.      and the other is at worst neutral.
  345.      (A zero compared against anything is neutral.)  */
  346.   for (i = 0; i < n_reloads; i++)
  347.     if (reload_reg_class[i] == class
  348.     && reload_strict_low[i] == strict_low
  349.     && ((in != 0 && MATCHES (reload_in[i], in) && ! dont_share
  350.          && (out == 0 || reload_out[i] == 0 || MATCHES (reload_out[i], out)))
  351.         ||
  352.         (out != 0 && MATCHES (reload_out[i], out)
  353.          && (in == 0 || reload_in[i] == 0 || MATCHES (reload_in[i], in)))))
  354.       break;
  355.  
  356.   /* Reloading a plain reg for input can match a reload to postincrement
  357.      that reg, since the postincrement's value is the right value.
  358.      Likewise, it can match a preincrement reload, since we regard
  359.      the preincrementation as happening before any ref in this insn
  360.      to that register.  */
  361.   if (i == n_reloads)
  362.     for (i = 0; i < n_reloads; i++)
  363.       if (reload_reg_class[i] == class
  364.       && reload_strict_low[i] == strict_low
  365.       && out == 0 && reload_out[i] == 0
  366.       && ((GET_CODE (in) == REG
  367.            && (GET_CODE (reload_in[i]) == POST_INC
  368.            || GET_CODE (reload_in[i]) == POST_DEC
  369.            || GET_CODE (reload_in[i]) == PRE_INC
  370.            || GET_CODE (reload_in[i]) == PRE_DEC)
  371.            && MATCHES (XEXP (reload_in[i], 0), in))
  372.           ||
  373.           (GET_CODE (reload_in[i]) == REG
  374.            && (GET_CODE (in) == POST_INC
  375.            || GET_CODE (in) == POST_DEC
  376.            || GET_CODE (in) == PRE_INC
  377.            || GET_CODE (in) == PRE_DEC)
  378.            && MATCHES (XEXP (in, 0), reload_in[i]))))
  379.     {
  380.       /* Make sure reload_in ultimately has the increment,
  381.          not the plain register.  */
  382.       if (GET_CODE (in) == REG)
  383.         in = reload_in[i];
  384.       break;
  385.     }
  386.  
  387.   if (i == n_reloads)
  388.     {
  389.       /* We found no existing reload suitable for re-use.
  390.      So add an additional reload.  */
  391.  
  392.       reload_in[i] = in;
  393.       reload_out[i] = out;
  394.       reload_reg_class[i] = class;
  395.       reload_inmode[i] = inmode;
  396.       reload_outmode[i] = outmode;
  397.       reload_reg_rtx[i] = 0;
  398.       reload_optional[i] = optional;
  399.       reload_inc[i] = 0;
  400.       reload_strict_low[i] = strict_low;
  401.       reload_nocombine[i] = 0;
  402.       reload_in_reg[i] = *inloc;
  403.       reload_needed_for[i] = needed_for;
  404.       reload_needed_for_multiple[i] = 0;
  405.  
  406.       n_reloads++;
  407.     }
  408.   else
  409.     {
  410.       /* We are reusing an existing reload,
  411.      but we may have additional information for it.
  412.      For example, we may now have both IN and OUT
  413.      while the old one may have just one of them.  */
  414.  
  415.       if (inmode != VOIDmode)
  416.     reload_inmode[i] = inmode;
  417.       if (outmode != VOIDmode)
  418.     reload_outmode[i] = outmode;
  419.       if (in != 0)
  420.     reload_in[i] = in;
  421.       if (out != 0)
  422.     reload_out[i] = out;
  423.       reload_optional[i] &= optional;
  424.       if (reload_needed_for[i] != needed_for)
  425.     reload_needed_for_multiple[i] = 1;
  426.     }
  427.  
  428.   /* If the ostensible rtx being reload differs from the rtx found
  429.      in the location to substitute, this reload is not safe to combine
  430.      because we cannot reliably tell whether it appears in the insn.  */
  431.  
  432.   if (in != 0 && in != *inloc)
  433.     reload_nocombine[i] = 1;
  434.  
  435. #if 0
  436.   /* This was replaced by changes in find_reloads_address_1 and the new
  437.      function inc_for_reload, which go with a new meaning of reload_inc.  */
  438.  
  439.   /* If this is an IN/OUT reload in an insn that sets the CC,
  440.      it must be for an autoincrement.  It doesn't work to store
  441.      the incremented value after the insn because that would clobber the CC.
  442.      So we must do the increment of the value reloaded from,
  443.      increment it, store it back, then decrement again.  */
  444.   if (out != 0 && sets_cc0_p (PATTERN (this_insn)))
  445.     {
  446.       out = 0;
  447.       reload_out[i] = 0;
  448.       reload_inc[i] = find_inc_amount (PATTERN (this_insn), in);
  449.       /* If we did not find a nonzero amount-to-increment-by,
  450.      that contradicts the belief that IN is being incremented
  451.      in an address in this insn.  */
  452.       if (reload_inc[i] == 0)
  453.     abort ();
  454.     }
  455. #endif
  456.  
  457.   /* If we will replace IN and OUT with the reload-reg,
  458.      record where they are located so that substitution need
  459.      not do a tree walk.  */
  460.  
  461.   if (replace_reloads)
  462.     {
  463.       if (inloc != 0)
  464.     {
  465.       register struct replacement *r = &replacements[n_replacements++];
  466.       r->what = i;
  467.       r->where = inloc;
  468.       r->mode = inmode;
  469.     }
  470.       if (outloc != 0 && outloc != inloc)
  471.     {
  472.       register struct replacement *r = &replacements[n_replacements++];
  473.       r->what = i;
  474.       r->where = outloc;
  475.       r->mode = outmode;
  476.     }
  477.     }
  478.  
  479.   /* If this reload is just being introduced and it has both
  480.      an incoming quantity and an outgoing quantity that are
  481.      supposed to be made to match, see if either one of the two
  482.      can serve as the place to reload into.
  483.  
  484.      If one of them is acceptable, set reload_reg_rtx[i]
  485.      to that one.  */
  486.  
  487.   if (in != 0 && out != 0 && in != out && reload_reg_rtx[i] == 0)
  488.     {
  489.       reload_reg_rtx[i] = find_dummy_reload (in, out, inloc, outloc,
  490.                          reload_reg_class[i], i);
  491.  
  492.       /* If the outgoing register already contains the same value
  493.      as the incoming one, we can dispense with loading it.
  494.      The easiest way to tell the caller that is to give a phony
  495.      value for the incoming operand (same as outgoing one).  */
  496.       if (reload_reg_rtx[i] == out
  497.       && (GET_CODE (in) == REG || CONSTANT_P (in))
  498.       && 0 != find_equiv_reg (in, this_insn, 0, REGNO (out),
  499.                   static_reload_reg_p, i, inmode))
  500.     reload_in[i] = out;
  501.     }
  502.  
  503.   if (out)
  504.     output_reloadnum = i;
  505.  
  506.   return i;
  507. }
  508.  
  509. /* Record an additional place we must replace a value
  510.    for which we have already recorded a reload.
  511.    RELOADNUM is the value returned by push_reload
  512.    when the reload was recorded.
  513.    This is used in insn patterns that use match_dup.  */
  514.  
  515. static void
  516. push_replacement (loc, reloadnum, mode)
  517.      rtx *loc;
  518.      int reloadnum;
  519.      enum machine_mode mode;
  520. {
  521.   if (replace_reloads)
  522.     {
  523.       register struct replacement *r = &replacements[n_replacements++];
  524.       r->what = reloadnum;
  525.       r->where = loc;
  526.       r->mode = mode;
  527.     }
  528. }
  529.  
  530. /* If there is only one output reload, try to combine it
  531.    with a (logically unrelated) input reload
  532.    to reduce the number of reload registers needed.
  533.  
  534.    This is safe if the input reload does not appear in
  535.    the value being output-reloaded, because this implies
  536.    it is not needed any more once the original insn completes.  */
  537.  
  538. static void
  539. combine_reloads ()
  540. {
  541.   int i;
  542.   int output_reload = -1;
  543.  
  544.   /* Find the output reload; return unless there is exactly one
  545.      and that one is mandatory.  */
  546.  
  547.   for (i = 0; i < n_reloads; i++)
  548.     if (reload_out[i] != 0)
  549.       {
  550.     if (output_reload >= 0)
  551.       return;
  552.     output_reload = i;
  553.       }
  554.  
  555.   if (output_reload < 0 || reload_optional[output_reload])
  556.     return;
  557.  
  558.   /* An input-output reload isn't combinable.  */
  559.  
  560.   if (reload_in[output_reload] != 0)
  561.     return;
  562.  
  563.   /* Check each input reload; can we combine it?  */
  564.  
  565.   for (i = 0; i < n_reloads; i++)
  566.     if (reload_in[i] && ! reload_optional[i] && ! reload_nocombine[i]
  567.     /* Life span of this reload must not extend past main insn.  */
  568.     && reload_when_needed[i] != RELOAD_FOR_OUTPUT_RELOAD_ADDRESS
  569.     && reload_inmode[i] == reload_outmode[output_reload]
  570.     && reload_inc[i] == 0
  571.     && reload_reg_rtx[i] == 0
  572.     && reload_strict_low[i] == 0
  573.     && reload_reg_class[i] == reload_reg_class[output_reload]
  574.     && ! reg_overlap_mentioned_p (reload_in[i], reload_out[output_reload]))
  575.       {
  576.     int j;
  577.  
  578.     /* We have found a reload to combine with!  */
  579.     reload_out[i] = reload_out[output_reload];
  580.     reload_outmode[i] = reload_outmode[output_reload];
  581.     /* Mark the old output reload as inoperative.  */
  582.     reload_out[output_reload] = 0;
  583.     /* The combined reload is needed for the entire insn.  */
  584.     reload_needed_for_multiple[i] = 1;
  585.     reload_when_needed[i] = RELOAD_OTHER;
  586.  
  587.     /* Transfer all replacements from the old reload to the combined.  */
  588.     for (j = 0; j < n_replacements; j++)
  589.       if (replacements[j].what == output_reload)
  590.         replacements[j].what = i;
  591.  
  592.     return;
  593.       }
  594. }
  595.  
  596. /* Try to find a reload register for an in-out reload (expressions IN and OUT).
  597.    See if one of IN and OUT is a register that may be used;
  598.    this is desirable since a spill-register won't be needed.
  599.    If so, return the register rtx that proves acceptable.
  600.  
  601.    INLOC and OUTLOC are locations where IN and OUT appear in the insn.
  602.    CLASS is the register class required for the reload.
  603.  
  604.    If FOR_REAL is >= 0, it is the number of the reload,
  605.    and in some cases when it can be discovered that OUT doesn't need
  606.    to be computed, clear out reload_out[FOR_REAL].
  607.  
  608.    If FOR_REAL is -1, this should not be done, because this call
  609.    is just to see if a register can be found, not to find and install it.  */
  610.  
  611. static rtx
  612. find_dummy_reload (in, out, inloc, outloc, class, for_real)
  613.      rtx in, out;
  614.      rtx *inloc, *outloc;
  615.      enum reg_class class;
  616.      int for_real;
  617. {
  618.   rtx value = 0;
  619.   rtx orig_in = in;
  620.  
  621.   while (GET_CODE (out) == SUBREG)
  622.     out = SUBREG_REG (out);
  623.   while (GET_CODE (in) == SUBREG)
  624.     in = SUBREG_REG (in);
  625.  
  626.   /* If operands exceed a word, we can't use either of them
  627.      unless they have the same size.  */
  628.   if (GET_MODE_SIZE (GET_MODE (out)) != GET_MODE_SIZE (GET_MODE (in))
  629.       && (GET_MODE_SIZE (GET_MODE (out)) > UNITS_PER_WORD
  630.       || GET_MODE_SIZE (GET_MODE (in)) > UNITS_PER_WORD))
  631.     return 0;
  632.  
  633.   /* See if OUT will do.  */
  634.   if (GET_CODE (out) == REG)
  635.     {
  636.       register int regno = REGNO (out);
  637.  
  638.       /* When we consider whether the insn uses OUT,
  639.      ignore references within IN.  They don't prevent us
  640.      from copying IN into OUT, because those refs would
  641.      move into the insn that reloads IN.
  642.  
  643.      However, we only ignore IN in its role as this operand.
  644.      If the insn uses IN elsewhere and it contains OUT,
  645.      that counts.  We can't be sure it's the "same" operand
  646.      so it might not go through this reload.  */
  647.       *inloc = const0_rtx;
  648.  
  649.       if (reg_renumber[regno] >= 0)
  650.     regno = reg_renumber[regno];
  651.       if (regno < FIRST_PSEUDO_REGISTER
  652.       /* A fixed reg that can overlap other regs better not be used
  653.          for reloading in any way.  */
  654. #ifdef OVERLAPPING_REGNO_P
  655.       && ! (fixed_regs[regno] && OVERLAPPING_REGNO_P (regno))
  656. #endif
  657.       && ! refers_to_regno_p (regno, regno + HARD_REGNO_NREGS (regno, GET_MODE (out)),
  658.                   PATTERN (this_insn), outloc)
  659.       && TEST_HARD_REG_BIT (reg_class_contents[(int) class], regno))
  660.     value = out;
  661.  
  662.       *inloc = orig_in;
  663.     }
  664.  
  665.   /* Consider using IN if OUT was not acceptable
  666.      or if OUT dies in this insn (like the quotient in a divmod insn).
  667.      We can't use IN unless it is free after this insn,
  668.      which means we must know accurately which hard regs are live.
  669.      Also, the result can't go in IN if IN is used within OUT.  */
  670.   if (hard_regs_live_known
  671.       && GET_CODE (in) == REG
  672.       && ! find_reg_note (this_insn, REG_UNSET, in)
  673.       && (value == 0
  674.       || find_regno_note (this_insn, REG_DEAD, REGNO (value))))
  675.     {
  676.       register int regno = REGNO (in);
  677.       if (find_regno_note (this_insn, REG_DEAD, regno))
  678.     {
  679.       if (reg_renumber[regno] >= 0)
  680.         regno = reg_renumber[regno];
  681.       if (regno < FIRST_PSEUDO_REGISTER
  682.           && ! refers_to_regno_p (regno,
  683.                       regno + HARD_REGNO_NREGS (regno, GET_MODE (in)),
  684.                       out, 0)
  685.           && ! hard_reg_set_here_p (regno, PATTERN (this_insn))
  686.           && TEST_HARD_REG_BIT (reg_class_contents[(int) class], regno))
  687.         {
  688.           /* If we were going to use OUT as the reload reg
  689.          and changed our mind, it means OUT is a dummy that
  690.          dies here.  So don't bother copying value to it.  */
  691.           if (for_real >= 0 && value == out)
  692.         reload_out[for_real] = 0;
  693.           value = in;
  694.         }
  695.     }
  696.     }
  697.  
  698.   return value;
  699. }
  700.  
  701. /* This page contains subroutines used mainly for determining
  702.    whether the IN or an OUT of a reload can serve as the
  703.    reload register.  */
  704.  
  705. /* Return 1 if hard reg number REGNO is stored in by expression X,
  706.    either explicitly or in the guise of a pseudo-reg allocated to REGNO.
  707.    X should be the body of an instruction.  */
  708.  
  709. static int
  710. hard_reg_set_here_p (regno, x)
  711.      register int regno;
  712.      rtx x;
  713. {
  714.   if (GET_CODE (x) == SET || GET_CODE (x) == CLOBBER)
  715.     {
  716.       register rtx op0 = SET_DEST (x);
  717.       while (GET_CODE (op0) == SUBREG)
  718.     op0 = SUBREG_REG (op0);
  719.       if (GET_CODE (op0) == REG)
  720.     {
  721.       register int r = REGNO (op0);
  722.       /* See if this reg includes the specified one.  */
  723.       if (r <= regno && r + HARD_REGNO_NREGS (r, GET_MODE (op0)) > regno)
  724.         return 1;
  725.     }
  726.     }
  727.   else if (GET_CODE (x) == PARALLEL)
  728.     {
  729.       register int i = XVECLEN (x, 0) - 1;
  730.       for (; i >= 0; i--)
  731.     if (hard_reg_set_here_p (regno, XVECEXP (x, 0, i)))
  732.       return 1;
  733.     }
  734.  
  735.   return 0;
  736. }
  737.  
  738. /* Return 1 if ADDR is a valid memory address for mode MODE,
  739.    and check that each pseudo reg has the proper kind of
  740.    hard reg.  */
  741.  
  742. int
  743. strict_memory_address_p (mode, addr)
  744.      enum machine_mode mode;
  745.      register rtx addr;
  746. {
  747.   GO_IF_LEGITIMATE_ADDRESS (mode, addr, win);
  748.   return 0;
  749.  
  750.  win:
  751.   return 1;
  752. }
  753.  
  754.  
  755. /* Like rtx_equal_p except that it allows a REG and a SUBREG to match
  756.    if they are the same hard reg, and has special hacks for
  757.    autoincrement and autodecrement.
  758.    This is specifically intended for find_reloads to use
  759.    in determining whether two operands match.
  760.    X is the operand whose number is the lower of the two.
  761.  
  762.    The value is 2 if Y contains a pre-increment that matches
  763.    a non-incrementing address in X.  */
  764.  
  765. /* ??? To be completely correct, we should arrange to pass
  766.    for X the output operand and for Y the input operand.
  767.    For now, we assume that the output operand has the lower number
  768.    because that is natural in (SET output (... input ...)).  */
  769.  
  770. int
  771. operands_match_p (x, y)
  772.      register rtx x, y;
  773. {
  774.   register int i;
  775.   register RTX_CODE code = GET_CODE (x);
  776.   register char *fmt;
  777.   int success_2;
  778.       
  779.   if (x == y)
  780.     return 1;
  781.   if ((code == REG || (code == SUBREG && GET_CODE (SUBREG_REG (x)) == REG))
  782.       && (GET_CODE (y) == REG || (GET_CODE (y) == SUBREG
  783.                   && GET_CODE (SUBREG_REG (y)) == REG)))
  784.     {
  785.       register int j;
  786.  
  787.       if (code == SUBREG)
  788.     {
  789.       i = REGNO (SUBREG_REG (x));
  790.       if (i >= FIRST_PSEUDO_REGISTER)
  791.         goto slow;
  792.       i += SUBREG_WORD (x);
  793.     }
  794.       else
  795.     i = REGNO (x);
  796.  
  797.       if (GET_CODE (y) == SUBREG)
  798.     {
  799.       j = REGNO (SUBREG_REG (y));
  800.       if (j >= FIRST_PSEUDO_REGISTER)
  801.         goto slow;
  802.       j += SUBREG_WORD (y);
  803.     }
  804.       else
  805.     j = REGNO (y);
  806.  
  807.       return i == j;
  808.     }
  809.   /* If two operands must match, because they are really a single
  810.      operand of an assembler insn, then two postincrements are invalid
  811.      because the assembler insn would increment only once.
  812.      On the other hand, an postincrement matches ordinary indexing
  813.      if the postincrement is the output operand.  */
  814.   if (code == POST_DEC || code == POST_INC)
  815.     return operands_match_p (XEXP (x, 0), y);
  816.   /* Two preincrements are invalid
  817.      because the assembler insn would increment only once.
  818.      On the other hand, an preincrement matches ordinary indexing
  819.      if the preincrement is the input operand.
  820.      In this case, return 2, since some callers need to do special
  821.      things when this happens.  */
  822.   if (GET_CODE (y) == PRE_DEC || GET_CODE (y) == PRE_INC)
  823.     return operands_match_p (x, XEXP (y, 0)) ? 2 : 0;
  824.  
  825.  slow:
  826.  
  827.   /* Now we have disposed of all the cases 
  828.      in which different rtx codes can match.  */
  829.   if (code != GET_CODE (y))
  830.     return 0;
  831.   if (code == LABEL_REF)
  832.     return XEXP (x, 0) == XEXP (y, 0);
  833.   if (code == SYMBOL_REF)
  834.     return XSTR (x, 0) == XSTR (y, 0);
  835.  
  836.   /* (MULT:SI x y) and (MULT:HI x y) are NOT equivalent.  */
  837.  
  838.   if (GET_MODE (x) != GET_MODE (y))
  839.     return 0;
  840.  
  841.   /* Compare the elements.  If any pair of corresponding elements
  842.      fail to match, return 0 for the whole things.  */
  843.  
  844.   success_2 = 0;
  845.   fmt = GET_RTX_FORMAT (code);
  846.   for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
  847.     {
  848.       int val;
  849.       switch (fmt[i])
  850.     {
  851.     case 'i':
  852.       if (XINT (x, i) != XINT (y, i))
  853.         return 0;
  854.       break;
  855.  
  856.     case 'e':
  857.       val = operands_match_p (XEXP (x, i), XEXP (y, i));
  858.       if (val == 0)
  859.         return 0;
  860.       /* If any subexpression returns 2,
  861.          we should return 2 if we are successful.  */
  862.       if (val == 2)
  863.         success_2 = 1;
  864.       break;
  865.  
  866.     case '0':
  867.       break;
  868.  
  869.       /* It is believed that rtx's at this level will never
  870.          contain anything but integers and other rtx's,
  871.          except for within LABEL_REFs and SYMBOL_REFs.  */
  872.     default:
  873.       abort ();
  874.     }
  875.     }
  876.   return 1 + success_2;
  877. }
  878.  
  879. /* Return the number of times character C occurs in string S.  */
  880.  
  881. static int
  882. n_occurrences (c, s)
  883.      char c;
  884.      char *s;
  885. {
  886.   int n = 0;
  887.   while (*s)
  888.     n += (*s++ == c);
  889.   return n;
  890. }
  891.  
  892. struct decomposition
  893. {
  894.   int reg_flag;
  895.   int safe;
  896.   rtx base;
  897.   int start;
  898.   int end;
  899. };
  900.  
  901. /* Describe the range of registers or memory referenced by X.
  902.    If X is a register, set REG_FLAG and put the first register 
  903.    number into START and the last plus one into END.
  904.    If X is a memory reference, put a base address into BASE 
  905.    and a range of integer offsets into START and END.
  906.    If X is pushing on the stack, we can assume it causes no trouble, 
  907.    so we set the SAFE field.  */
  908.  
  909. static struct decomposition
  910. decompose (x)
  911.      rtx x;
  912. {
  913.   struct decomposition val;
  914.   int all_const = 0;
  915.  
  916.   val.reg_flag = 0;
  917.   val.safe = 0;
  918.   if (GET_CODE (x) == MEM)
  919.     {
  920.       rtx base, offset = 0;
  921.       rtx addr = XEXP (x, 0);
  922.  
  923.       if (GET_CODE (addr) == PRE_DEC || GET_CODE (addr) == PRE_INC
  924.       || GET_CODE (addr) == POST_DEC || GET_CODE (addr) == POST_INC)
  925.     {
  926.       val.base = XEXP (addr, 0);
  927.       val.start = - GET_MODE_SIZE (GET_MODE (x));
  928.       val.end = GET_MODE_SIZE (GET_MODE (x));
  929.       val.safe = REGNO (val.base) == STACK_POINTER_REGNUM;
  930.       return val;
  931.     }
  932.  
  933.       if (GET_CODE (addr) == CONST)
  934.     {
  935.       addr = XEXP (addr, 0);
  936.       all_const = 1;
  937.     }
  938.       if (GET_CODE (addr) == PLUS)
  939.     {
  940.       if (CONSTANT_P (XEXP (addr, 0)))
  941.         {
  942.           base = XEXP (addr, 1);
  943.           offset = XEXP (addr, 0);
  944.         }
  945.       else if (CONSTANT_P (XEXP (addr, 1)))
  946.         {
  947.           base = XEXP (addr, 0);
  948.           offset = XEXP (addr, 1);
  949.         }
  950.     }
  951.  
  952.       if (offset == 0)
  953.     {
  954.       base = addr;
  955.       offset = const0_rtx;
  956.     } 
  957.       if (GET_CODE (offset) == CONST)
  958.     offset = XEXP (offset, 0);
  959.       if (GET_CODE (offset) == PLUS)
  960.     {
  961.       if (GET_CODE (XEXP (offset, 0)) == CONST_INT)
  962.         {
  963.           base = gen_rtx (PLUS, GET_MODE (base), base, XEXP (offset, 1));
  964.           offset = XEXP (offset, 0);
  965.         }
  966.       else if (GET_CODE (XEXP (offset, 1)) == CONST_INT)
  967.         {
  968.           base = gen_rtx (PLUS, GET_MODE (base), base, XEXP (offset, 0));
  969.           offset = XEXP (offset, 1);
  970.         }
  971.       else
  972.         {
  973.           base = gen_rtx (PLUS, GET_MODE (base), base, offset);
  974.           offset = const0_rtx;
  975.         }
  976.     }
  977.       else if (GET_CODE (offset) != CONST_INT)
  978.     {
  979.       base = gen_rtx (PLUS, GET_MODE (base), base, offset);
  980.       offset = const0_rtx;
  981.     }
  982.  
  983.       if (all_const && GET_CODE (base) == PLUS)
  984.     base = gen_rtx (CONST, GET_MODE (base), base);
  985.  
  986.       if (GET_CODE (offset) != CONST_INT)
  987.     abort ();
  988.  
  989.       val.start = INTVAL (offset);
  990.       val.end = val.start + GET_MODE_SIZE (GET_MODE (x));
  991.       val.base = base;
  992.       return val;
  993.     }
  994.   else if (GET_CODE (x) == REG)
  995.     {
  996.       val.reg_flag = 1;
  997.       val.start = true_regnum (x); 
  998.       if (val.start < 0)
  999.     {
  1000.       /* A pseudo with no hard reg.  */
  1001.       val.start = REGNO (x);
  1002.       val.end = val.start + 1;
  1003.     }
  1004.       else
  1005.     /* A hard reg.  */
  1006.     val.end = val.start + HARD_REGNO_NREGS (val.start, GET_MODE (x));
  1007.     }
  1008.   else if (GET_CODE (x) == SUBREG)
  1009.     {
  1010.       if (GET_CODE (SUBREG_REG (x)) != REG)
  1011.     /* This could be more precise, but it's good enough.  */
  1012.     return decompose (SUBREG_REG (x));
  1013.       val.reg_flag = 1;
  1014.       val.start = true_regnum (x); 
  1015.       if (val.start < 0)
  1016.     return decompose (SUBREG_REG (x));
  1017.       else
  1018.     /* A hard reg.  */
  1019.     val.end = val.start + HARD_REGNO_NREGS (val.start, GET_MODE (x));
  1020.     }
  1021.   else
  1022.     abort ();
  1023.   return val;
  1024. }
  1025.  
  1026. /* Return 1 if altering Y will not modify the value of X.
  1027.    Y is also described by YDATA, which should be decompose (Y).  */
  1028.  
  1029. static int
  1030. immune_p (x, y, ydata)
  1031.      rtx x, y;
  1032.      struct decomposition ydata;
  1033. {
  1034.   struct decomposition xdata;
  1035.  
  1036.   if (ydata.reg_flag)
  1037.     return !refers_to_regno_p (ydata.start, ydata.end, x, 0);
  1038.   if (ydata.safe)
  1039.     return 1;
  1040.  
  1041.   if (GET_CODE (y) != MEM)
  1042.     abort ();
  1043.   /* If Y is memory and X is not, Y can't affect X.  */
  1044.   if (GET_CODE (x) != MEM)
  1045.     return 1;
  1046.  
  1047.   xdata =  decompose (x);
  1048.  
  1049.   if (! rtx_equal_p (xdata.base, ydata.base))
  1050.     {
  1051.       /* If bases are distinct symbolic constants, there is no overlap.  */
  1052.       if (CONSTANT_P (xdata.base) && CONSTANT_P (ydata.base))
  1053.     return 1;
  1054.       /* Constants and stack slots never overlap.  */
  1055.       if (CONSTANT_P (xdata.base)
  1056.       && (ydata.base == frame_pointer_rtx
  1057.           || ydata.base == stack_pointer_rtx))
  1058.     return 1;
  1059.       if (CONSTANT_P (ydata.base)
  1060.       && (xdata.base == frame_pointer_rtx
  1061.           || xdata.base == stack_pointer_rtx))
  1062.     return 1;
  1063.       /* If either base is variable, we don't know anything.  */
  1064.       return 0;
  1065.     }
  1066.  
  1067.  
  1068.   return (xdata.start >= ydata.end || ydata.start >= xdata.end);
  1069. }
  1070.  
  1071. /* Main entry point of this file: search the body of INSN
  1072.    for values that need reloading and record them with push_reload.
  1073.    REPLACE nonzero means record also where the values occur
  1074.    so that subst_reloads can be used.
  1075.    IND_OK says that a memory reference is a valid memory address.
  1076.  
  1077.    LIVE_KNOWN says we have valid information about which hard
  1078.    regs are live at each point in the program; this is true when
  1079.    we are called from global_alloc but false when stupid register
  1080.    allocation has been done.
  1081.  
  1082.    RELOAD_REG_P if nonzero is a vector indexed by hard reg number
  1083.    which is nonnegative if the reg has been commandeered for reloading into.
  1084.    It is copied into STATIC_RELOAD_REG_P and referenced from there
  1085.    by various subroutines.  */
  1086.  
  1087. void
  1088. find_reloads (insn, replace, ind_ok, live_known, reload_reg_p)
  1089.      rtx insn;
  1090.      int replace, ind_ok;
  1091.      int live_known;
  1092.      short *reload_reg_p;
  1093. {
  1094. #ifdef REGISTER_CONSTRAINTS
  1095.  
  1096. #ifdef MPW_C
  1097.   enum reload_modified { RELOAD_NOTHING, RELOAD_READ, RELOAD_READ_WRITE, RELOAD_WRITE };
  1098. #else
  1099.   enum reload_modified { RELOAD_NOTHING, RELOAD_READ, RELOAD_READ_WRITE, RELOAD_WRITE, r_m_intifier = 1000000 };
  1100. #endif /* MPW_C */
  1101.  
  1102.   register int insn_code_number;
  1103.   register int i;
  1104.   int noperands;
  1105.   /* These are the constraints for the insn.  We don't change them.  */
  1106.   char *constraints1[MAX_RECOG_OPERANDS];
  1107.   /* These start out as the constraints for the insn
  1108.      and they are chewed up as we consider alternatives.  */
  1109.   char *constraints[MAX_RECOG_OPERANDS];
  1110.   /* Nonzero for a MEM operand whose entire address needs a reload.  */
  1111.   int address_reloaded[MAX_RECOG_OPERANDS];
  1112.   int n_alternatives;
  1113.   int this_alternative[MAX_RECOG_OPERANDS];
  1114.   char this_alternative_win[MAX_RECOG_OPERANDS];
  1115.   char this_alternative_offmemok[MAX_RECOG_OPERANDS];
  1116.   char this_alternative_earlyclobber[MAX_RECOG_OPERANDS];
  1117.   int this_alternative_matches[MAX_RECOG_OPERANDS];
  1118.   int swapped;
  1119.   int goal_alternative[MAX_RECOG_OPERANDS];
  1120.   int this_alternative_number;
  1121.   int goal_alternative_number;
  1122.   int operand_reloadnum[MAX_RECOG_OPERANDS];
  1123.   int goal_alternative_matches[MAX_RECOG_OPERANDS];
  1124.   int goal_alternative_matched[MAX_RECOG_OPERANDS];
  1125.   char goal_alternative_win[MAX_RECOG_OPERANDS];
  1126.   char goal_alternative_offmemok[MAX_RECOG_OPERANDS];
  1127.   char goal_alternative_earlyclobber[MAX_RECOG_OPERANDS];
  1128.   int goal_alternative_swapped;
  1129.   enum reload_modified modified[MAX_RECOG_OPERANDS];
  1130.   int best;
  1131.   int commutative;
  1132.   char operands_match[MAX_RECOG_OPERANDS][MAX_RECOG_OPERANDS];
  1133.   rtx substed_operand[MAX_RECOG_OPERANDS];
  1134.   rtx body = PATTERN (insn);
  1135.   int goal_earlyclobber, this_earlyclobber;
  1136.   enum machine_mode operand_mode[MAX_RECOG_OPERANDS];
  1137.  
  1138.   this_insn = insn;
  1139.   n_reloads = 0;
  1140.   n_replacements = 0;
  1141.   n_memlocs = 0;
  1142.   n_earlyclobbers = 0;
  1143.   replace_reloads = replace;
  1144.   indirect_ok = ind_ok;
  1145.   hard_regs_live_known = live_known;
  1146.   static_reload_reg_p = reload_reg_p;
  1147.  
  1148.   /* Find what kind of insn this is.  NOPERANDS gets number of operands.
  1149.      Make OPERANDS point to a vector of operand values.
  1150.      Make OPERAND_LOCS point to a vector of pointers to
  1151.      where the operands were found.
  1152.      Fill CONSTRAINTS and CONSTRAINTS1 with pointers to the
  1153.      constraint-strings for this insn.
  1154.      Return if the insn needs no reload processing.  */
  1155.  
  1156.   switch (GET_CODE (body))
  1157.     {
  1158.     case USE:
  1159.     case CLOBBER:
  1160.     case ASM_INPUT:
  1161.     case ADDR_VEC:
  1162.     case ADDR_DIFF_VEC:
  1163.       return;
  1164.  
  1165.     case SET:
  1166.       /* Dispose quickly of (set (reg..) (reg..)) if both have hard regs.  */
  1167.       if (GET_CODE (SET_DEST (body)) == REG
  1168.       && REGNO (SET_DEST (body)) < FIRST_PSEUDO_REGISTER
  1169.       && GET_CODE (SET_SRC (body)) == REG
  1170.       && REGNO (SET_SRC (body)) < FIRST_PSEUDO_REGISTER)
  1171.     return;
  1172.     case PARALLEL:
  1173.     case ASM_OPERANDS:
  1174.       noperands = asm_noperands (body);
  1175.       if (noperands >= 0)
  1176.     {
  1177.       /* This insn is an `asm' with operands.  */
  1178.  
  1179.       insn_code_number = -1;
  1180.  
  1181.       /* expand_asm_operands makes sure there aren't too many operands.  */
  1182.       if (noperands > MAX_RECOG_OPERANDS)
  1183.         abort ();
  1184.  
  1185.       /* Now get the operand values and constraints out of the insn.  */
  1186.  
  1187.       decode_asm_operands (body, recog_operand, recog_operand_loc,
  1188.                    constraints, operand_mode);
  1189.       if (noperands > 0)
  1190.         {
  1191.           bcopy (constraints, constraints1, noperands * sizeof (char *));
  1192.           n_alternatives = n_occurrences (',', constraints[0]) + 1;
  1193.           for (i = 1; i < noperands; i++)
  1194.         if (n_alternatives != n_occurrences (',', constraints[0]) + 1)
  1195.           {
  1196.             error_for_asm (insn, "operand constraints differ in number of alternatives");
  1197.             /* Avoid further trouble with this insn.  */
  1198.             PATTERN (insn) = gen_rtx (USE, VOIDmode, const0_rtx);
  1199.             n_reloads = 0;
  1200.             return;
  1201.           }
  1202.         }
  1203.       break;
  1204.     }
  1205.  
  1206.     default:
  1207.       /* Ordinary insn: recognize it, allocate space for operands and
  1208.      constraints, and get them out via insn_extract.  */
  1209.  
  1210.       insn_code_number = recog_memoized (insn);
  1211.       noperands = insn_n_operands[insn_code_number];
  1212.       n_alternatives = insn_n_alternatives[insn_code_number];
  1213.       /* Just return "no reloads" if insn has no operands with constraints.  */
  1214.       if (n_alternatives == 0)
  1215.     return;
  1216.       insn_extract (insn);
  1217.       for (i = 0; i < noperands; i++)
  1218.     {
  1219.       constraints[i] = constraints1[i]
  1220.         = insn_operand_constraint[insn_code_number][i];
  1221.       operand_mode[i] = insn_operand_mode[insn_code_number][i];
  1222.     }
  1223.     }
  1224.  
  1225.   if (noperands == 0)
  1226.     return;
  1227.  
  1228.   commutative = -1;
  1229.  
  1230.   /* If we will need to know, later, whether some pair of operands
  1231.      are the same, we must compare them now and save the result.
  1232.      Reloading the base and index registers will clobber them
  1233.      and afterward they will fail to match.  */
  1234.  
  1235.   for (i = 0; i < noperands; i++)
  1236.     {
  1237.       register char *p;
  1238.       register int c;
  1239.  
  1240.       substed_operand[i] = recog_operand[i];
  1241.       p = constraints[i];
  1242.  
  1243.       /* Scan this operand's constraint to see if it should match another.  */
  1244.  
  1245.       while (c = *p++)
  1246.     if (c == '%')
  1247.       commutative = i;
  1248.     else if (c >= '0' && c <= '9')
  1249.       {
  1250.         c -= '0';
  1251.         operands_match[c][i]
  1252.           = operands_match_p (recog_operand[c], recog_operand[i]);
  1253.         /* If C can be commuted with C+1, and C might need to match I,
  1254.            then C+1 might also need to match I.  */
  1255.         if (commutative >= 0)
  1256.           {
  1257.         if (c == commutative || c == commutative + 1)
  1258.           {
  1259.             int other = c + (c == commutative ? 1 : -1);
  1260.             operands_match[other][i]
  1261.               = operands_match_p (recog_operand[other], recog_operand[i]);
  1262.           }
  1263.         if (i == commutative || i == commutative + 1)
  1264.           {
  1265.             int other = i + (i == commutative ? 1 : -1);
  1266.             operands_match[c][other]
  1267.             = operands_match_p (recog_operand[c], recog_operand[other]);
  1268.           }
  1269.         /* Note that C is supposed to be less than I.
  1270.            No need to consider altering both C and I
  1271.            because in that case we would alter one into the other.  */
  1272.           }
  1273.       }
  1274.     }
  1275.  
  1276.   /* Examine each operand that is a memory reference or memory address
  1277.      and reload parts of the addresses into index registers.
  1278.      While we are at it, initialize the array `modified'.
  1279.      Also here any references to pseudo regs that didn't get hard regs
  1280.      but are equivalent to constants get replaced in the insn itself
  1281.      with those constants.  Nobody will ever see them again.  */
  1282.  
  1283.   for (i = 0; i < noperands; i++)
  1284.     {
  1285.       register RTX_CODE code = GET_CODE (recog_operand[i]);
  1286.       modified[i] = RELOAD_READ;
  1287.       address_reloaded[i] = 0;
  1288.       if (constraints[i][0] == 'p')
  1289.     {
  1290.       find_reloads_address (VOIDmode, 0,
  1291.                 recog_operand[i], recog_operand_loc[i],
  1292.                 recog_operand[i]);
  1293.       substed_operand[i] = recog_operand[i] = *recog_operand_loc[i];
  1294.     }
  1295.       else if (code == MEM)
  1296.     {
  1297.       if (find_reloads_address (GET_MODE (recog_operand[i]),
  1298.                     recog_operand_loc[i],
  1299.                     XEXP (recog_operand[i], 0),
  1300.                     &XEXP (recog_operand[i], 0),
  1301.                     recog_operand[i]))
  1302.         address_reloaded[i] = 1;
  1303.       substed_operand[i] = recog_operand[i] = *recog_operand_loc[i];
  1304.     }
  1305.       else if (code == SUBREG)
  1306.     substed_operand[i] = recog_operand[i] = *recog_operand_loc[i]
  1307.       = find_reloads_toplev (recog_operand[i]);
  1308.       else if (code == REG)
  1309.     {
  1310.       /* This is equivalent to calling find_reloads_toplev.
  1311.          The code is duplicated for speed.  */
  1312.       register int regno = REGNO (recog_operand[i]);
  1313.       if (reg_equiv_constant[regno] != 0)
  1314.         substed_operand[i] = recog_operand[i]
  1315.           = reg_equiv_constant[regno];
  1316. #if 0 /* This might screw code in reload1.c to delete prior output-reload
  1317.      that feeds this insn.  */
  1318.       if (reg_equiv_mem[regno] != 0)
  1319.         substed_operand[i] = recog_operand[i]
  1320.           = reg_equiv_mem[regno];
  1321. #endif
  1322.       if (reg_equiv_address[regno] != 0)
  1323.         {
  1324.           *recog_operand_loc[i] = recog_operand[i]
  1325.         = gen_rtx (MEM, GET_MODE (recog_operand[i]),
  1326.                reg_equiv_address[regno]);
  1327.           find_reloads_address (GET_MODE (recog_operand[i]),
  1328.                     recog_operand_loc[i],
  1329.                     XEXP (recog_operand[i], 0),
  1330.                     &XEXP (recog_operand[i], 0),
  1331.                     recog_operand[i]);
  1332.           substed_operand[i] = recog_operand[i] = *recog_operand_loc[i];
  1333.         }
  1334.     }
  1335.     }
  1336.  
  1337.   /* Now see what we need for pseudo-regs that didn't get hard regs
  1338.      or got the wrong kind of hard reg.  For this, we must consider
  1339.      all the operands together against the register constraints.  */
  1340.  
  1341.   best = MAX_RECOG_OPERANDS + 100;
  1342.  
  1343.   swapped = 0;
  1344.  try_swapped:
  1345.  
  1346.   /* The constraints are made of several alternatives.
  1347.      Each operand's constraint looks like foo,bar,... with commas
  1348.      separating the alternatives.  The first alternatives for all
  1349.      operands go together, the second alternatives go together, etc.
  1350.  
  1351.      First loop over alternatives.  */
  1352.  
  1353.   for (this_alternative_number = 0;
  1354.        this_alternative_number < n_alternatives;
  1355.        this_alternative_number++)
  1356.     {
  1357.       /* Loop over operands for one constraint alternative.  */
  1358.       /* LOSERS counts those that don't fit this alternative
  1359.      and would require loading.  */
  1360.       int losers = 0;
  1361.       /* BAD is set to 1 if it some operand can't fit this alternative
  1362.      even after reloading.  */
  1363.       int bad = 0;
  1364.       /* REJECT is a count of how undesirable this alternative says it is
  1365.      if any reloading is required.  If the alternative matches exactly
  1366.      then REJECT is ignored, but otherwise it gets this much
  1367.      counted against it in addition to the reloading needed.  */
  1368.       int reject = 0;
  1369.  
  1370.       this_earlyclobber = 0;
  1371.  
  1372.       for (i = 0; i < noperands; i++)
  1373.     {
  1374.       register char *p = constraints[i];
  1375.       register int win = 0;
  1376.       /* 0 => this operand can be reloaded somehow for this alternative */
  1377.       int badop = 1;
  1378.       /* 0 => this operand can be reloaded if the alternative allows regs.  */
  1379.       int winreg = 0;
  1380.       int c;
  1381.       register rtx operand = recog_operand[i];
  1382.       int offset = 0;
  1383.       /* Nonzero means this is a MEM that must be reloaded into a reg
  1384.          regardless of what the constraint says.  */
  1385.       int force_reload = 0;
  1386.       int offmemok = 0;
  1387.       int earlyclobber = 0;
  1388.  
  1389.       /* If the operand is a SUBREG, extract
  1390.          the REG or MEM (or maybe even a constant) within.
  1391.          (Constants can occur as a result of reg_equiv_constant.)  */
  1392.  
  1393.       while (GET_CODE (operand) == SUBREG)
  1394.         {
  1395.           offset += SUBREG_WORD (operand);
  1396.           operand = SUBREG_REG (operand);
  1397.           if (GET_CODE (operand) != REG)
  1398.         force_reload = 1;
  1399.         }
  1400.  
  1401.       this_alternative[i] = (int) NO_REGS;
  1402.       this_alternative_win[i] = 0;
  1403.       this_alternative_offmemok[i] = 0;
  1404.       this_alternative_earlyclobber[i] = 0;
  1405.       this_alternative_matches[i] = -1;
  1406.  
  1407.       /* An empty constraint or empty alternative
  1408.          allows anything which matched the pattern.  */
  1409.       if (*p == 0 || *p == ',')
  1410.         win = 1, badop = 0;
  1411.  
  1412.       /* Scan this alternative's specs for this operand;
  1413.          set WIN if the operand fits any letter in this alternative.
  1414.          Otherwise, clear BADOP if this operand could
  1415.          fit some letter after reloads,
  1416.          or set WINREG if this operand could fit after reloads
  1417.          provided the constraint allows some registers.  */
  1418.  
  1419.       while (*p && (c = *p++) != ',')
  1420.         switch (c)
  1421.           {
  1422.           case '=':
  1423.         modified[i] = RELOAD_WRITE;
  1424.         break;
  1425.  
  1426.           case '+':
  1427.         modified[i] = RELOAD_READ_WRITE;
  1428.         break;
  1429.  
  1430.           case '*':
  1431.         break;
  1432.  
  1433.           case '%':
  1434.         commutative = i;
  1435.         break;
  1436.  
  1437.           case '?':
  1438.         reject++;
  1439.         break;
  1440.  
  1441.           case '!':
  1442.         reject = 100;
  1443.         break;
  1444.  
  1445.           case '#':
  1446.         /* Ignore rest of this alternative as far as
  1447.            reloading is concerned.  */
  1448.         while (*p && *p != ',') p++;
  1449.         break;
  1450.  
  1451.           case '0':
  1452.           case '1':
  1453.           case '2':
  1454.           case '3':
  1455.           case '4':
  1456.         c -= '0';
  1457.         this_alternative_matches[i] = c;
  1458.         /* We are supposed to match a previous operand.
  1459.            If we do, we win if that one did.
  1460.            If we do not, count both of the operands as losers.
  1461.            (This is too conservative, since most of the time
  1462.            only a single reload insn will be needed to make
  1463.            the two operands win.  As a result, this alternative
  1464.            may be rejected when it is actually desirable.)  */
  1465.         if ((swapped && (c != commutative || i != commutative + 1))
  1466.             /* If we are matching as if two operands were swapped,
  1467.                also pretend that operands_match had been computed
  1468.                with swapped.
  1469.                But if I is the second of those and C is the first,
  1470.                don't exchange them, because operands_match is valid
  1471.                only on one side of its diagonal.  */
  1472.             ? (operands_match
  1473.                 [(c == commutative || c == commutative + 1)
  1474.              ? 2*commutative + 1 - c : c]
  1475.                 [(i == commutative || i == commutative + 1)
  1476.              ? 2*commutative + 1 - i : i])
  1477.             : operands_match[c][i])
  1478.           win = this_alternative_win[c];
  1479.         else
  1480.           {
  1481.             /* Operands don't match.  */
  1482.             rtx value;
  1483.             /* Retroactively mark the operand we had to match
  1484.                as a loser, if it wasn't already.  */
  1485.             if (this_alternative_win[c])
  1486.               losers++;
  1487.             this_alternative_win[c] = 0;
  1488.             if (this_alternative[c] == (int) NO_REGS)
  1489.               bad = 1;
  1490.             /* But count the pair only once in the total badness of
  1491.                this alternative, if the pair can be a dummy reload.  */
  1492.             value
  1493.               = find_dummy_reload (recog_operand[i], recog_operand[c],
  1494.                        recog_operand_loc[i], recog_operand_loc[c],
  1495.                        this_alternative[c], -1);
  1496.  
  1497.             if (value != 0)
  1498.               losers--;
  1499.           }
  1500.         /* This can be fixed with reloads if the operand
  1501.            we are supposed to match can be fixed with reloads.  */
  1502.         badop = 0;
  1503.         this_alternative[i] = this_alternative[c];
  1504.         break;
  1505.  
  1506.           case 'p':
  1507.         /* All necessary reloads for an address_operand
  1508.            were handled in find_reloads_address.  */
  1509.         this_alternative[i] = (int) ALL_REGS;
  1510.         win = 1;
  1511.         break;
  1512.  
  1513.           case 'm':
  1514.         if (force_reload)
  1515.           break;
  1516.         if (GET_CODE (operand) == MEM
  1517.             || (GET_CODE (operand) == REG
  1518.             && REGNO (operand) >= FIRST_PSEUDO_REGISTER
  1519.             && reg_renumber[REGNO (operand)] < 0))
  1520.           win = 1;
  1521.         if (GET_CODE (operand) == CONST_DOUBLE
  1522.             || CONSTANT_P (operand))
  1523.           badop = 0;
  1524.         break;
  1525.  
  1526.           case '<':
  1527.         if (GET_CODE (operand) == MEM
  1528.             && ! address_reloaded[i]
  1529.             && (GET_CODE (XEXP (operand, 0)) == PRE_DEC
  1530.             || GET_CODE (XEXP (operand, 0)) == POST_DEC))
  1531.           win = 1;
  1532.         break;
  1533.  
  1534.           case '>':
  1535.         if (GET_CODE (operand) == MEM
  1536.             && ! address_reloaded[i]
  1537.             && (GET_CODE (XEXP (operand, 0)) == PRE_INC
  1538.             || GET_CODE (XEXP (operand, 0)) == POST_INC))
  1539.           win = 1;
  1540.         break;
  1541.  
  1542.         /* Memory operand whose address is offsettable.  */
  1543.           case 'o':
  1544.         if (force_reload)
  1545.           break;
  1546.         if ((GET_CODE (operand) == MEM
  1547.              && offsettable_memref_p (operand))
  1548.             /* Certain mem addresses will become offsettable
  1549.                after they themselves are reloaded.  This is important;
  1550.                we don't want our own handling of unoffsettables
  1551.                to override the handling of reg_equiv_address.  */
  1552.             || (GET_CODE (operand) == MEM
  1553.             && GET_CODE (XEXP (operand, 0)) == REG
  1554.             && (! ind_ok
  1555.                 || reg_equiv_address[REGNO (XEXP (operand, 0))] != 0))
  1556.             || (GET_CODE (operand) == REG
  1557.             && REGNO (operand) >= FIRST_PSEUDO_REGISTER
  1558.             && reg_renumber[REGNO (operand)] < 0))
  1559.           win = 1;
  1560.         if (GET_CODE (operand) == CONST_DOUBLE
  1561.             || CONSTANT_P (operand)
  1562.             || GET_CODE (operand) == MEM)
  1563.           badop = 0;
  1564.         offmemok = 1;
  1565.         break;
  1566.  
  1567.           case '&':
  1568.         /* Output operand that is stored before the need for the
  1569.            input operands (and their index registers) is over.  */
  1570.         if (GET_CODE (operand) == REG
  1571.             || GET_CODE (operand) == MEM)
  1572.           earlyclobber = 1, this_earlyclobber = 1;
  1573.         break;
  1574.  
  1575.           case 'F':
  1576.         if (GET_CODE (operand) == CONST_DOUBLE)
  1577.           win = 1;
  1578.         break;
  1579.  
  1580.           case 'G':
  1581.           case 'H':
  1582.         if (GET_CODE (operand) == CONST_DOUBLE
  1583.             && CONST_DOUBLE_OK_FOR_LETTER_P (operand, c))
  1584.           win = 1;
  1585.         break;
  1586.  
  1587.           case 's':
  1588.         if (GET_CODE (operand) == CONST_INT)
  1589.           break;
  1590.           case 'i':
  1591.         if (CONSTANT_P (operand))
  1592.           win = 1;
  1593.         break;
  1594.  
  1595.           case 'n':
  1596.         if (GET_CODE (operand) == CONST_INT)
  1597.           win = 1;
  1598.         break;
  1599.  
  1600.           case 'I':
  1601.           case 'J':
  1602.           case 'K':
  1603.           case 'L':
  1604.           case 'M':
  1605.         if (GET_CODE (operand) == CONST_INT
  1606.             && CONST_OK_FOR_LETTER_P (INTVAL (operand), c))
  1607.           win = 1;
  1608.         break;
  1609.  
  1610.           case 'g':
  1611.         if (! force_reload
  1612.             && (GENERAL_REGS == ALL_REGS
  1613.             || GET_CODE (operand) != REG
  1614.             || (REGNO (operand) >= FIRST_PSEUDO_REGISTER
  1615.                 && reg_renumber[REGNO (operand)] < 0)))
  1616.           win = 1;
  1617.         /* Drop through into 'r' case */
  1618.  
  1619.           case 'r':
  1620.         this_alternative[i]
  1621.           = (int) reg_class_subunion[this_alternative[i]][(int) GENERAL_REGS];
  1622.         goto reg;
  1623.  
  1624.           default:
  1625.         this_alternative[i]
  1626.           = (int) reg_class_subunion[this_alternative[i]][(int) REG_CLASS_FROM_LETTER (c)];
  1627.         
  1628.           reg:
  1629.         winreg = 1;
  1630.         if (GET_CODE (operand) == REG
  1631.             && reg_fits_class_p (operand, this_alternative[i],
  1632.                      offset, GET_MODE (recog_operand[i])))
  1633.           win = 1;
  1634.         break;
  1635.           }
  1636.  
  1637.       constraints[i] = p;
  1638.  
  1639.       /* If this operand could be handled with a reg,
  1640.          and some reg is allowed, then this operand can be handled.  */
  1641.       if (winreg && this_alternative[i] != (int) NO_REGS)
  1642.         badop = 0;
  1643.  
  1644.       /* Record which operands fit this alternative.  */
  1645.       this_alternative_earlyclobber[i] = earlyclobber;
  1646.       if (win && ! force_reload)
  1647.         this_alternative_win[i] = 1;
  1648.       else
  1649.         {
  1650.           this_alternative_offmemok[i] = offmemok;
  1651.           losers++;
  1652.           if (badop)
  1653.         bad = 1;
  1654.           /* Alternative loses if it has no regs for a reg operand.  */
  1655.           if (GET_CODE (operand) == REG
  1656.           && this_alternative[i] == (int) NO_REGS
  1657.           && this_alternative_matches[i] < 0)
  1658.         bad = 1;
  1659.         }
  1660.     }
  1661.  
  1662.       /* Now see if any output operands that are marked "earlyclobber"
  1663.      in this alternative conflict with any input operands
  1664.      or any memory addresses.  */
  1665.  
  1666.       for (i = 0; i < noperands; i++)
  1667.     if (this_alternative_earlyclobber[i]
  1668.         && this_alternative_win[i])
  1669.       {
  1670.         struct decomposition early_data; 
  1671.         int j;
  1672.  
  1673.         early_data = decompose (recog_operand[i]);
  1674.  
  1675.         for (j = 0; j < noperands; j++)
  1676.           /* Is this an input operand or a memory ref?  */
  1677.           if ((GET_CODE (recog_operand[j]) == MEM
  1678.            || modified[j] != RELOAD_WRITE)
  1679.           && j != i
  1680.           /* Don't count an input operand that is constrained to match
  1681.              the early clobber operand.  */
  1682.           && ! (this_alternative_matches[j] == i
  1683.             && rtx_equal_p (recog_operand[i], recog_operand[j]))
  1684.           /* Is it altered by storing the earlyclobber operand?  */
  1685.           && !immune_p (recog_operand[j], recog_operand[i], early_data))
  1686.         {
  1687.           /* If the output is in a single-reg class,
  1688.              it's costly to reload it, so reload the input instead.  */
  1689.           if (reg_class_size[this_alternative[i]] == 1
  1690.               && (GET_CODE (recog_operand[j]) == REG
  1691.               || GET_CODE (recog_operand[j]) == SUBREG))
  1692.             {
  1693.               losers++;
  1694.               this_alternative_win[j] = 0;
  1695.             }
  1696.           else
  1697.             break;
  1698.         }
  1699.         /* If an earlyclobber operand conflicts with something,
  1700.            it must be reloaded, so request this and count the cost.  */
  1701.         if (j != noperands)
  1702.           {
  1703.         losers++;
  1704.         this_alternative_win[i] = 0;
  1705.         for (j = 0; j < noperands; j++)
  1706.           if (this_alternative_matches[j] == i
  1707.               && this_alternative_win[j])
  1708.             {
  1709.               this_alternative_win[j] = 0;
  1710.               losers++;
  1711.             }
  1712.           }
  1713.       }
  1714.  
  1715.       /* If one alternative accepts all the operands, no reload required,
  1716.      choose that alternative; don't consider the remaining ones.  */
  1717.       if (losers == 0)
  1718.     {
  1719.       /* Unswap these so that they are never swapped at `finish'.  */
  1720.       if (commutative >= 0)
  1721.         {
  1722.           recog_operand[commutative] = substed_operand[commutative];
  1723.           recog_operand[commutative + 1]
  1724.         = substed_operand[commutative + 1];
  1725.         }
  1726.       for (i = 0; i < noperands; i++)
  1727.         {
  1728.           goal_alternative_win[i] = 1;
  1729.           goal_alternative[i] = this_alternative[i];
  1730.           goal_alternative_offmemok[i] = this_alternative_offmemok[i];
  1731.           goal_alternative_matches[i] = this_alternative_matches[i];
  1732.           goal_alternative_earlyclobber[i]
  1733.         = this_alternative_earlyclobber[i];
  1734.         }
  1735.       goal_alternative_number = this_alternative_number;
  1736.       goal_alternative_swapped = swapped;
  1737.       goal_earlyclobber = this_earlyclobber;
  1738.       goto finish;
  1739.     }
  1740.  
  1741.       /* REJECT, set by the ! and ? constraint characters,
  1742.      discourages the use of this alternative for a reload goal.  */
  1743.       if (reject > 0)
  1744.     losers += reject;
  1745.  
  1746.       /* If this alternative can be made to work by reloading,
  1747.      and it needs less reloading than the others checked so far,
  1748.      record it as the chosen goal for reloading.  */
  1749.       if (! bad && best > losers)
  1750.     {
  1751.       for (i = 0; i < noperands; i++)
  1752.         {
  1753.           goal_alternative[i] = this_alternative[i];
  1754.           goal_alternative_win[i] = this_alternative_win[i];
  1755.           goal_alternative_offmemok[i] = this_alternative_offmemok[i];
  1756.           goal_alternative_matches[i] = this_alternative_matches[i];
  1757.           goal_alternative_earlyclobber[i]
  1758.         = this_alternative_earlyclobber[i];
  1759.         }
  1760.       goal_alternative_swapped = swapped;
  1761.       best = losers;
  1762.       goal_alternative_number = this_alternative_number;
  1763.       goal_earlyclobber = this_earlyclobber;
  1764.     }
  1765.     }
  1766.  
  1767.   /* If insn is commutative (it's safe to exchange a certain pair of operands)
  1768.      then we need to try each alternative twice,
  1769.      the second time matching those two operands
  1770.      as if we had exchanged them.
  1771.      To do this, really exchange them in operands.
  1772.  
  1773.      If we have just tried the alternatives the second time,
  1774.      return operands to normal and drop through.  */
  1775.  
  1776.   if (commutative >= 0)
  1777.     {
  1778.       swapped = !swapped;
  1779.       if (swapped)
  1780.     {
  1781.       recog_operand[commutative] = substed_operand[commutative + 1];
  1782.       recog_operand[commutative + 1] = substed_operand[commutative];
  1783.  
  1784.       bcopy (constraints1, constraints, noperands * sizeof (char *));
  1785.       goto try_swapped;
  1786.     }
  1787.       else
  1788.     {
  1789.       recog_operand[commutative] = substed_operand[commutative];
  1790.       recog_operand[commutative + 1] = substed_operand[commutative + 1];
  1791.     }
  1792.     }
  1793.  
  1794.   /* The operands don't meet the constraints.
  1795.      goal_alternative describes the alternative
  1796.      that we could reach by reloading the fewest operands.
  1797.      Reload so as to fit it.  */
  1798.  
  1799.   if (best == MAX_RECOG_OPERANDS + 100)
  1800.     {
  1801.       /* No alternative works with reloads??  */
  1802.       if (insn_code_number >= 0)
  1803.     abort ();
  1804.       error_for_asm (insn, "inconsistent operand constraints in an `asm'");
  1805.       /* Avoid further trouble with this insn.  */
  1806.       PATTERN (insn) = gen_rtx (USE, VOIDmode, const0_rtx);
  1807.       n_reloads = 0;
  1808.       return;
  1809.     }
  1810.  
  1811.   /* Jump to `finish' from above if all operands are valid already.
  1812.      In that case, goal_alternative_win is all 1.  */
  1813.  finish:
  1814.  
  1815.   /* Right now, for any pair of operands I and J that are required to match,
  1816.      with I < J,
  1817.      goal_alternative_matches[J] is I.
  1818.      Set up goal_alternative_matched as the inverse function:
  1819.      goal_alternative_matched[I] = J.  */
  1820.  
  1821.   for (i = 0; i < noperands; i++)
  1822.     goal_alternative_matched[i] = -1;
  1823.  
  1824.   for (i = 0; i < noperands; i++)
  1825.     if (! goal_alternative_win[i]
  1826.     && goal_alternative_matches[i] >= 0)
  1827.       goal_alternative_matched[goal_alternative_matches[i]] = i;
  1828.  
  1829.   /* If the best alternative is with operands 1 and 2 swapped,
  1830.      consider them swapped before reporting the reloads.  */
  1831.  
  1832.   if (goal_alternative_swapped)
  1833.     {
  1834.       register rtx tem;
  1835.  
  1836.       tem = substed_operand[commutative];
  1837.       substed_operand[commutative] = substed_operand[commutative + 1];
  1838.       substed_operand[commutative + 1] = tem;
  1839.       tem = recog_operand[commutative];
  1840.       recog_operand[commutative] = recog_operand[commutative + 1];
  1841.       recog_operand[commutative + 1] = tem;
  1842.     }
  1843.  
  1844.   /* Perform whatever substitutions on the operands we are supposed
  1845.      to make due to commutativity or replacement of registers
  1846.      with equivalent constants or memory slots.  */
  1847.  
  1848.   for (i = 0; i < noperands; i++)
  1849.     {
  1850.       *recog_operand_loc[i] = substed_operand[i];
  1851.       /* While we are looping on operands, initialize this.  */
  1852.       operand_reloadnum[i] = -1;
  1853.     }
  1854.  
  1855.   /* Any constants that aren't allowed and can't be reloaded
  1856.      into memory locations are here changed into memory references.  */
  1857.   for (i = 0; i < noperands; i++)
  1858.     if (! goal_alternative_win[i]
  1859.     && (GET_CODE (recog_operand[i]) == CONST_DOUBLE
  1860.         || CONSTANT_P (recog_operand[i]))
  1861.     && (PREFERRED_RELOAD_CLASS (recog_operand[i],
  1862.                     (enum reg_class) goal_alternative[i])
  1863.         == NO_REGS))
  1864.       {
  1865.     enum machine_mode mode = operand_mode[i];
  1866.     *recog_operand_loc[i] = recog_operand[i]
  1867.       = (GET_CODE (recog_operand[i]) == CONST_DOUBLE
  1868.          ? force_const_double_mem (recog_operand[i])
  1869.          : force_const_mem (mode != VOIDmode ? mode : SImode,
  1870.                 recog_operand[i]));
  1871.     find_reloads_toplev (recog_operand[i]);
  1872.     if (alternative_allows_memconst (constraints1[i], goal_alternative_number))
  1873.       goal_alternative_win[i] = 1;
  1874.       }
  1875.  
  1876.   /* Now record reloads for all the operands that need them.  */
  1877.   for (i = 0; i < noperands; i++)
  1878.     if (! goal_alternative_win[i])
  1879.       {
  1880.     /* Operands that match previous ones have already been handled.  */
  1881.     if (goal_alternative_matches[i] >= 0)
  1882.       ;
  1883.     /* Handle an operand with a nonoffsettable address
  1884.        appearing where an offsettable address will do
  1885.        by reloading the address into a base register.  */
  1886.     else if (goal_alternative_matched[i] == -1
  1887.          && goal_alternative_offmemok[i]
  1888.          && GET_CODE (recog_operand[i]) == MEM)
  1889.       {
  1890.         operand_reloadnum[i]
  1891.           = push_reload (XEXP (recog_operand[i], 0), 0,
  1892.                  &XEXP (recog_operand[i], 0), 0,
  1893.                  BASE_REG_CLASS, GET_MODE (XEXP (recog_operand[i], 0)),
  1894.                  0, 0, 0, 0);
  1895.         reload_inc[operand_reloadnum[i]]
  1896.           = GET_MODE_SIZE (GET_MODE (recog_operand[i]));
  1897.       }
  1898.     else if (goal_alternative_matched[i] == -1)
  1899.       operand_reloadnum[i] =
  1900.         push_reload (modified[i] != RELOAD_WRITE ? recog_operand[i] : 0,
  1901.              modified[i] != RELOAD_READ ? recog_operand[i] : 0,
  1902.              recog_operand_loc[i], 0,
  1903.              (enum reg_class) goal_alternative[i],
  1904.              (modified[i] == RELOAD_WRITE ? VOIDmode : operand_mode[i]),
  1905.              (modified[i] == RELOAD_READ ? VOIDmode : operand_mode[i]),
  1906.              (insn_code_number < 0 ? 0
  1907.               : insn_operand_strict_low[insn_code_number][i]),
  1908.              0, 0);
  1909.     /* In a matching pair of operands, one must be input only
  1910.        and the other must be output only.
  1911.        Pass the input operand as IN and the other as OUT.  */
  1912.     else if (modified[i] == RELOAD_READ
  1913.          && modified[goal_alternative_matched[i]] == RELOAD_WRITE)
  1914.       {
  1915.         operand_reloadnum[i]
  1916.           = push_reload (recog_operand[i],
  1917.                  recog_operand[goal_alternative_matched[i]],
  1918.                  recog_operand_loc[i],
  1919.                  recog_operand_loc[goal_alternative_matched[i]],
  1920.                  (enum reg_class) goal_alternative[i],
  1921.                  operand_mode[i],
  1922.                  operand_mode[goal_alternative_matched[i]],
  1923.                  VOIDmode, 0, 0);
  1924.         operand_reloadnum[goal_alternative_matched[i]] = output_reloadnum;
  1925.       }
  1926.     else if (modified[i] == RELOAD_WRITE
  1927.          && modified[goal_alternative_matched[i]] == RELOAD_READ)
  1928.       {
  1929.         operand_reloadnum[goal_alternative_matched[i]]
  1930.           = push_reload (recog_operand[goal_alternative_matched[i]],
  1931.                  recog_operand[i],
  1932.                  recog_operand_loc[goal_alternative_matched[i]],
  1933.                  recog_operand_loc[i],
  1934.                  (enum reg_class) goal_alternative[i],
  1935.                  operand_mode[goal_alternative_matched[i]],
  1936.                  operand_mode[i],
  1937.                  VOIDmode, 0, 0);
  1938.         operand_reloadnum[i] = output_reloadnum;
  1939.       }
  1940.     else if (insn_code_number >= 0)
  1941.       abort ();
  1942.     else
  1943.       {
  1944.         error_for_asm (insn, "inconsistent operand constraints in an `asm'");
  1945.         /* Avoid further trouble with this insn.  */
  1946.         PATTERN (insn) = gen_rtx (USE, VOIDmode, const0_rtx);
  1947.         n_reloads = 0;
  1948.         return;
  1949.       }
  1950.       }
  1951.     else if (goal_alternative_matched[i] < 0
  1952.          && goal_alternative_matches[i] < 0
  1953.          && optimize)
  1954.       {
  1955.     rtx operand = recog_operand[i];
  1956.     /* For each non-matching operand that's a pseudo-register 
  1957.        that didn't get a hard register, make an optional reload.
  1958.        This may get done even if the insn needs no reloads otherwise.  */
  1959.     /* (It would be safe to make an optional reload for a matching pair
  1960.        of operands, but we don't bother yet.)  */
  1961.     while (GET_CODE (operand) == SUBREG)
  1962.       operand = XEXP (operand, 0);
  1963.     if (GET_CODE (operand) == REG
  1964.         && REGNO (operand) >= FIRST_PSEUDO_REGISTER
  1965.         && reg_renumber[REGNO (operand)] < 0
  1966.         && (enum reg_class) goal_alternative[i] != NO_REGS
  1967.         /* Don't make optional output reloads for jump insns
  1968.            (such as aobjeq on the vax).  */
  1969.         && (modified[i] == RELOAD_READ
  1970.         || GET_CODE (insn) != JUMP_INSN))
  1971.       operand_reloadnum[i]
  1972.         = push_reload (modified[i] != RELOAD_WRITE ? recog_operand[i] : 0,
  1973.                modified[i] != RELOAD_READ ? recog_operand[i] : 0,
  1974.                recog_operand_loc[i], 0,
  1975.                (enum reg_class) goal_alternative[i],
  1976.                (modified[i] == RELOAD_WRITE ? VOIDmode : operand_mode[i]),
  1977.                (modified[i] == RELOAD_READ ? VOIDmode : operand_mode[i]),
  1978.                (insn_code_number < 0 ? 0
  1979.                 : insn_operand_strict_low[insn_code_number][i]),
  1980.                1, 0);
  1981.     /* Make an optional reload for an explicit mem ref.  */
  1982.     else if (GET_CODE (operand) == MEM
  1983.          && (enum reg_class) goal_alternative[i] != NO_REGS
  1984.          /* Don't make optional output reloads for jump insns
  1985.             (such as aobjeq on the vax).  */
  1986.          && (modified[i] == RELOAD_READ
  1987.              || GET_CODE (insn) != JUMP_INSN))
  1988.       operand_reloadnum[i]
  1989.         = push_reload (modified[i] != RELOAD_WRITE ? recog_operand[i] : 0,
  1990.                modified[i] != RELOAD_READ ? recog_operand[i] : 0,
  1991.                recog_operand_loc[i], 0,
  1992.                (enum reg_class) goal_alternative[i],
  1993.                (modified[i] == RELOAD_WRITE ? VOIDmode : operand_mode[i]),
  1994.                (modified[i] == RELOAD_READ ? VOIDmode : operand_mode[i]),
  1995.                (insn_code_number < 0 ? 0
  1996.                 : insn_operand_strict_low[insn_code_number][i]),
  1997.                1, 0);
  1998.       }
  1999.  
  2000.   /* Record the values of the earlyclobber operands for the caller.  */
  2001.   if (goal_earlyclobber)
  2002.     for (i = 0; i < noperands; i++)
  2003.       if (goal_alternative_earlyclobber[i])
  2004.     reload_earlyclobbers[n_earlyclobbers++] = recog_operand[i];
  2005.  
  2006.   /* If this insn pattern contains any MATCH_DUP's, make sure that
  2007.      they will be substituted if the operands they match are substituted.
  2008.      Also do now any substitutions we already did on the operands.  */
  2009.   if (insn_code_number >= 0)
  2010.     for (i = insn_n_dups[insn_code_number] - 1; i >= 0; i--)
  2011.       {
  2012.     int opno = recog_dup_num[i];
  2013.     *recog_dup_loc[i] = *recog_operand_loc[opno];
  2014.     if (operand_reloadnum[opno] >= 0)
  2015.       push_replacement (recog_dup_loc[i], operand_reloadnum[opno],
  2016.                 insn_operand_mode[insn_code_number][opno]);
  2017.       }
  2018.  
  2019. #if 0
  2020.   /* This loses because reloading of prior insns can invalidate the equivalence
  2021.      (or at least find_equiv_reg isn't smart enough to find it any more),
  2022.      causing this insn to need more reload regs than it needed before.
  2023.      It may be too late to make the reload regs available.
  2024.      Now this optimization is done safely in choose_reload_targets.  */
  2025.  
  2026.   /* For each reload of a reg into some other class of reg,
  2027.      search for an existing equivalent reg (same value now) in the right class.
  2028.      We can use it as long as we don't need to change its contents.  */
  2029.   for (i = 0; i < n_reloads; i++)
  2030.     if (reload_reg_rtx[i] == 0
  2031.     && reload_in[i] != 0
  2032.     && GET_CODE (reload_in[i]) == REG
  2033.     && reload_out[i] == 0)
  2034.       {
  2035.     reload_reg_rtx[i]
  2036.       = find_equiv_reg (reload_in[i], insn, reload_reg_class[i], -1,
  2037.                 static_reload_reg_p, 0, reload_inmode[i]);
  2038.     /* Prevent generation of insn to load the value
  2039.        because the one we found already has the value.  */
  2040.     if (reload_reg_rtx[i])
  2041.       reload_in[i] = reload_reg_rtx[i];
  2042.       }
  2043. #endif
  2044.  
  2045. #else /* no REGISTER_CONSTRAINTS */
  2046.   int noperands;
  2047.   int insn_code_number;
  2048.   int goal_earlyclobber = 0; /* Always 0, to make combine_reloads happen.  */
  2049.   register int i;
  2050.   rtx body = PATTERN (insn);
  2051.  
  2052.   n_reloads = 0;
  2053.   n_replacements = 0;
  2054.   n_earlyclobbers = 0;
  2055.   replace_reloads = replace;
  2056.   indirect_ok = ind_ok;
  2057.   this_insn = insn;
  2058.  
  2059.   /* Find what kind of insn this is.  NOPERANDS gets number of operands.
  2060.      Store the operand values in RECOG_OPERAND and the locations
  2061.      of the words in the insn that point to them in RECOG_OPERAND_LOC.
  2062.      Return if the insn needs no reload processing.  */
  2063.  
  2064.   switch (GET_CODE (body))
  2065.     {
  2066.     case USE:
  2067.     case CLOBBER:
  2068.     case ASM_INPUT:
  2069.     case ADDR_VEC:
  2070.     case ADDR_DIFF_VEC:
  2071.       return;
  2072.  
  2073.     case PARALLEL:
  2074.     case SET:
  2075.       noperands = asm_noperands (body);
  2076.       if (noperands >= 0)
  2077.     {
  2078.       /* This insn is an `asm' with operands.
  2079.          First, find out how many operands, and allocate space.  */
  2080.  
  2081.       insn_code_number = -1;
  2082.       /* ??? This is a bug! ???
  2083.          Give up and delete this insn if it has too many operands.  */
  2084.       if (noperands > MAX_RECOG_OPERANDS)
  2085.         abort ();
  2086.  
  2087.       /* Now get the operand values out of the insn.  */
  2088.  
  2089.       decode_asm_operands (body, recog_operand, recog_operand_loc, 0, 0);
  2090.       break;
  2091.     }
  2092.  
  2093.     default:
  2094.       /* Ordinary insn: recognize it, allocate space for operands and
  2095.      constraints, and get them out via insn_extract.  */
  2096.  
  2097.       insn_code_number = recog_memoized (insn);
  2098.       noperands = insn_n_operands[insn_code_number];
  2099.       insn_extract (insn);
  2100.     }
  2101.  
  2102.   if (noperands == 0)
  2103.     return;
  2104.  
  2105.   for (i = 0; i < noperands; i++)
  2106.     {
  2107.       register RTX_CODE code = GET_CODE (recog_operand[i]);
  2108.  
  2109.       if (insn_code_number >= 0)
  2110.     if (insn_operand_address_p[insn_code_number][i])
  2111.       find_reloads_address (VOIDmode, 0,
  2112.                 recog_operand[i], recog_operand_loc[i],
  2113.                 recog_operand[i]);
  2114.       if (code == MEM)
  2115.     find_reloads_address (GET_MODE (recog_operand[i]),
  2116.                   recog_operand_loc[i],
  2117.                   XEXP (recog_operand[i], 0),
  2118.                   &XEXP (recog_operand[i], 0),
  2119.                   recog_operand[i]);
  2120.       if (code == SUBREG)
  2121.     recog_operand[i] = *recog_operand_loc[i]
  2122.       = find_reloads_toplev (recog_operand[i]);
  2123.       if (code == REG)
  2124.     {
  2125.       register int regno = REGNO (recog_operand[i]);
  2126.       if (reg_equiv_constant[regno] != 0)
  2127.         recog_operand[i] = *recog_operand_loc[i]
  2128.           = reg_equiv_constant[regno];
  2129. #if 0 /* This might screw code in reload1.c to delete prior output-reload
  2130.      that feeds this insn.  */
  2131.       if (reg_equiv_mem[regno] != 0)
  2132.         recog_operand[i] = *recog_operand_loc[i]
  2133.           = reg_equiv_mem[regno];
  2134. #endif
  2135.     }
  2136.     }
  2137. #endif /* no REGISTER_CONSTRAINTS */
  2138.  
  2139.   /* Determine which part of the insn each reload is needed for,
  2140.      based on which operand the reload is needed for.
  2141.      Reloads of entire operands are classified as RELOAD_OTHER.
  2142.      So are reloads for which a unique purpose is not known.  */
  2143.  
  2144.   for (i = 0; i < n_reloads; i++)
  2145.     {
  2146.       reload_when_needed[i] = RELOAD_OTHER;
  2147.  
  2148.       if (reload_needed_for[i] != 0 && ! reload_needed_for_multiple[i])
  2149.     {
  2150.       int j;
  2151.       int output_address = 0;
  2152.       int input_address = 0;
  2153.       int operand_address = 0;
  2154.  
  2155.       /* This reload is needed only for the address of something.
  2156.          Determine whether it is needed for addressing an operand
  2157.          being reloaded for input, whether it is needed for an
  2158.          operand being reloaded for output, and whether it is needed
  2159.          for addressing an operand that won't really be reloaded.  */
  2160.  
  2161.       for (j = 0; j < n_reloads; j++)
  2162.         if (reload_needed_for[i] == reload_in[j]
  2163.         || reload_needed_for[i] == reload_out[j])
  2164.           {
  2165.         if (reload_optional[j])
  2166.           operand_address = 1;
  2167.         else
  2168.           {
  2169.             if (reload_needed_for[i] == reload_in[j])
  2170.               input_address = 1;
  2171.             if (reload_needed_for[i] == reload_out[j])
  2172.               output_address = 1;
  2173.           }
  2174.           }
  2175.  
  2176.       /* If it is needed for only one of those, record which one.  */
  2177.  
  2178.       if (input_address && ! output_address && ! operand_address)
  2179.         reload_when_needed[i] = RELOAD_FOR_INPUT_RELOAD_ADDRESS;
  2180.       if (output_address && ! input_address && ! operand_address)
  2181.         reload_when_needed[i] = RELOAD_FOR_OUTPUT_RELOAD_ADDRESS;
  2182.       if (operand_address && ! input_address && ! output_address)
  2183.         reload_when_needed[i] = RELOAD_FOR_OPERAND_ADDRESS;
  2184.     }
  2185.     }
  2186.  
  2187.   /* Perhaps an output reload can be combined with another
  2188.      to reduce needs by one.  */
  2189.   if (!goal_earlyclobber)
  2190.     combine_reloads ();
  2191. }
  2192.  
  2193. /* Return 1 if alternative number ALTNUM in constraint-string CONSTRAINT
  2194.    accepts a memory operand with constant address.  */
  2195.  
  2196. static int
  2197. alternative_allows_memconst (constraint, altnum)
  2198.      char *constraint;
  2199.      int altnum;
  2200. {
  2201.   register int c;
  2202.   /* Skip alternatives before the one requested.  */
  2203.   while (altnum > 0)
  2204.     {
  2205.       while (*constraint++ != ',');
  2206.       altnum--;
  2207.     }
  2208.   /* Scan the requested alternative for 'm' or 'o'.
  2209.      If one of them is present, this alternative accepts memory constants.  */
  2210.   while ((c = *constraint++) && c != ',' && c != '#')
  2211.     if (c == 'm' || c == 'o')
  2212.       return 1;
  2213.   return 0;
  2214. }
  2215.  
  2216. /* Scan X for memory references and scan the addresses for reloading.
  2217.    Also checks for references to "constant" regs that we want to eliminate
  2218.    and replaces them with the values they stand for.
  2219.    We may alter X descructively if it contains a reference to such.
  2220.    If X is just a constant reg, we return the equivalent value
  2221.    instead of X.  */
  2222.  
  2223. static rtx
  2224. find_reloads_toplev (x)
  2225.      rtx x;
  2226. {
  2227.   register RTX_CODE code = GET_CODE (x);
  2228.  
  2229.   register char *fmt = GET_RTX_FORMAT (code);
  2230.   register int i;
  2231.  
  2232.   if (code == REG)
  2233.     {
  2234.       /* This code is duplicated for speed in find_reloads.  */
  2235.       register int regno = REGNO (x);
  2236.       if (reg_equiv_constant[regno] != 0)
  2237.     x = reg_equiv_constant[regno];
  2238. #if 0
  2239. /*  This creates (subreg (mem...)) which would cause an unnecessary
  2240.     reload of the mem.  */
  2241.       else if (reg_equiv_mem[regno] != 0)
  2242.     x = reg_equiv_mem[regno];
  2243. #endif
  2244.       else if (reg_equiv_address[regno] != 0)
  2245.     {
  2246.       x = gen_rtx (MEM, GET_MODE (x),
  2247.                reg_equiv_address[regno]);
  2248.       find_reloads_address (GET_MODE (x), 0,
  2249.                 XEXP (x, 0),
  2250.                 &XEXP (x, 0), x);
  2251.     }
  2252.       return x;
  2253.     }
  2254.   if (code == MEM)
  2255.     {
  2256.       rtx tem = x;
  2257.       find_reloads_address (GET_MODE (x), &tem, XEXP (x, 0), &XEXP (x, 0), x);
  2258.       return tem;
  2259.     }
  2260.  
  2261.   if (code == SUBREG && GET_CODE (SUBREG_REG (x)) == REG)
  2262.     {
  2263.       /* Check for SUBREG containing a REG that's equivalent to a constant.  */
  2264.       register int regno = REGNO (SUBREG_REG (x));
  2265.       if (regno >= FIRST_PSEUDO_REGISTER && reg_renumber[regno] < 0
  2266.       && reg_equiv_constant[regno] != 0)
  2267.     {
  2268.       /* If the constant has a known value, truncate it right now.  */
  2269.       if (GET_CODE (reg_equiv_constant[regno]) == CONST_INT)
  2270.         {
  2271.           int size = GET_MODE_BITSIZE (GET_MODE (x));
  2272.           if (size < BITS_PER_WORD)
  2273.         return gen_rtx (CONST_INT, VOIDmode,
  2274.                 INTVAL (reg_equiv_constant[regno])
  2275.                 & ((1 << size) - 1));
  2276.           return reg_equiv_constant[regno];
  2277.         }
  2278.       /* If the constant is symbolic, allow it to be substituted normally.
  2279.          push_reload will strip the subreg later.  */
  2280.     }
  2281.       /* If the subreg contains a reg that will be converted to a mem,
  2282.      convert the subreg to a narrower memref now.
  2283.      Otherwise, we would get (subreg (mem ...) ...),
  2284.      which would force reload of the mem.  */
  2285.       else if (regno >= FIRST_PSEUDO_REGISTER && reg_equiv_address[regno] != 0)
  2286.     {
  2287.       int offset = SUBREG_WORD (x) * UNITS_PER_WORD;
  2288.       rtx addr;
  2289. #ifdef BYTES_BIG_ENDIAN
  2290.       offset += (GET_MODE_SIZE (GET_MODE (SUBREG_REG (x)))
  2291.              - GET_MODE_SIZE (GET_MODE (x)));
  2292. #endif
  2293.       addr = plus_constant (reg_equiv_address[regno], offset);
  2294.       x = gen_rtx (MEM, GET_MODE (x), addr);
  2295.       find_reloads_address (GET_MODE (x), 0,
  2296.                 XEXP (x, 0),
  2297.                 &XEXP (x, 0), x);
  2298.     }
  2299.  
  2300.     }
  2301.  
  2302.   for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
  2303.     {
  2304.       if (fmt[i] == 'e')
  2305.     XEXP (x, i) = find_reloads_toplev (XEXP (x, i));
  2306.     }
  2307.   return x;
  2308. }
  2309.  
  2310. static rtx
  2311. make_memloc (ad, regno)
  2312.      rtx ad;
  2313.      int regno;
  2314. {
  2315.   register int i;
  2316.   rtx tem = reg_equiv_address[regno];
  2317.   for (i = 0; i < n_memlocs; i++)
  2318.     if (rtx_equal_p (tem, XEXP (memlocs[i], 0)))
  2319.       return memlocs[i];
  2320.   tem = gen_rtx (MEM, GET_MODE (ad), tem);
  2321.   memlocs[n_memlocs++] = tem;
  2322.   return tem;
  2323. }
  2324.  
  2325. /* Record all reloads needed for handling memory address AD
  2326.    which appears in *LOC in a memory reference to mode MODE
  2327.    which itself is found in location  *MEMREFLOC.
  2328.    Note that we take shortcuts assuming that no multi-reg machine mode
  2329.    occurs as part of an address.
  2330.  
  2331.    OPERAND is the operand of the insn within which this address appears.
  2332.  
  2333.    Value is nonzero if this address is reloaded or replaced as a whole.
  2334.    This is interesting to the caller if the address is an autoincrement.  */
  2335.  
  2336. static int
  2337. find_reloads_address (mode, memrefloc, ad, loc, operand)
  2338.      enum machine_mode mode;
  2339.      rtx *memrefloc;
  2340.      rtx ad;
  2341.      rtx *loc;
  2342.      rtx operand;
  2343. {
  2344.   register int regno;
  2345.   rtx tem;
  2346.  
  2347.   if (GET_CODE (ad) == REG)
  2348.     {
  2349.       regno = REGNO (ad);
  2350.  
  2351.       if (reg_equiv_constant[regno] != 0)
  2352.     {
  2353.       if (strict_memory_address_p (mode, reg_equiv_constant[regno]))
  2354.         {
  2355.           *loc = ad = reg_equiv_constant[regno];
  2356.           return 1;
  2357.         }
  2358.     }
  2359. #if 0 /* This might screw code in reload1.c to delete prior output-reload
  2360.      that feeds this insn.  */
  2361.       if (reg_equiv_mem[regno] != 0)
  2362.     {
  2363.       if (strict_memory_address_p (mode, reg_equiv_mem[regno]))
  2364.         {
  2365.           *loc = ad = reg_equiv_mem[regno];
  2366.           return 1;
  2367.         }
  2368.     }
  2369. #endif
  2370.       if (reg_equiv_address[regno] != 0)
  2371.     {
  2372.       rtx tem = make_memloc (ad, regno);
  2373.       push_reload (XEXP (tem, 0), 0, &XEXP (tem, 0), 0,
  2374.                BASE_REG_CLASS,
  2375.                GET_MODE (XEXP (tem, 0)), 0, VOIDmode, 0,
  2376.                operand);
  2377.       push_reload (tem, 0, loc, 0, BASE_REG_CLASS,
  2378.                GET_MODE (ad), 0, VOIDmode, 0,
  2379.                operand);
  2380.       return 1;
  2381.     }
  2382.       if (! (regno >= FIRST_PSEUDO_REGISTER && reg_renumber[regno] < 0
  2383.          ? indirect_ok
  2384.          : REGNO_OK_FOR_BASE_P (regno)))
  2385.     {
  2386.       push_reload (ad, 0, loc, 0, BASE_REG_CLASS,
  2387.                GET_MODE (ad), 0, VOIDmode, 0, operand);
  2388.       return 1;
  2389.     }
  2390.       return 0;
  2391.     }
  2392.  
  2393.   if (strict_memory_address_p (mode, ad))
  2394.     {
  2395.       /* The address appears valid, so reloads are not needed.
  2396.      But the address may contain an eliminable register.
  2397.      This can happen because a machine with indirect addressing
  2398.      may consider a pseudo register by itself a valid address even when
  2399.      it has failed to get a hard reg.
  2400.      So do a tree-walk to find and eliminate all such regs.  */
  2401.  
  2402.       /* But first quickly dispose of a common case.  */
  2403.       if (GET_CODE (ad) == PLUS
  2404.       && GET_CODE (XEXP (ad, 1)) == CONST_INT
  2405.       && GET_CODE (XEXP (ad, 0)) == REG
  2406.       && reg_equiv_constant[REGNO (XEXP (ad, 0))] == 0)
  2407.     return 0;
  2408.  
  2409.       subst_reg_equivs_changed = 0;
  2410.       *loc = subst_reg_equivs (ad);
  2411.  
  2412.       if (! subst_reg_equivs_changed)
  2413.     return 0;
  2414.  
  2415.       /* Check result for validity after substitution.  */
  2416.       if (strict_memory_address_p (mode, ad))
  2417.     return 0;
  2418.     }
  2419.  
  2420.   /* If we have address of a stack slot but it's not valid
  2421.      (displacement is too large), compute the sum in a register.  */
  2422.   if (GET_CODE (ad) == PLUS
  2423.       && (XEXP (ad, 0) == frame_pointer_rtx
  2424. #if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM
  2425.       || XEXP (ad, 0) == arg_pointer_rtx
  2426. #endif
  2427.       )
  2428.       && GET_CODE (XEXP (ad, 1)) == CONST_INT)
  2429.     {
  2430.       /* Unshare the MEM rtx so we can safely alter it.  */
  2431.       if (memrefloc)
  2432.     {
  2433.       rtx oldref = *memrefloc;
  2434.       *memrefloc = copy_rtx (*memrefloc);
  2435.       loc = &XEXP (*memrefloc, 0);
  2436.       if (operand == oldref)
  2437.         operand = *memrefloc;
  2438.     }
  2439.       if (double_reg_address_ok)
  2440.     {
  2441.       /* Unshare the sum as well.  */
  2442.       *loc = ad = copy_rtx (ad);
  2443.       /* Reload the displacement into an index reg.
  2444.          We assume the frame pointer or arg pointer is a base reg.  */
  2445.       push_reload (XEXP (ad, 1), 0, &XEXP (ad, 1), 0, INDEX_REG_CLASS, 
  2446.                GET_MODE (ad), VOIDmode, 0, 0, operand);
  2447.     }
  2448.       else
  2449.     {
  2450.       /* If the sum of two regs is not necessarily valid,
  2451.          reload the sum into a base reg.
  2452.          That will at least work.  */
  2453.       push_reload (ad, 0, loc, 0, BASE_REG_CLASS,
  2454.                GET_MODE (ad), VOIDmode, 0, 0, operand);
  2455.     }
  2456.       return 1;
  2457.     }
  2458.  
  2459.   /* See if address becomes valid when an eliminable register
  2460.      in a sum is replaced.  */
  2461.  
  2462.   tem = ad;
  2463.   if (GET_CODE (ad) == PLUS)
  2464.     tem = subst_indexed_address (ad);
  2465.   if (tem != ad && strict_memory_address_p (mode, tem))
  2466.     {
  2467.       /* Ok, we win that way.  Replace any additional eliminable
  2468.      registers.  */
  2469.  
  2470.       subst_reg_equivs_changed = 0;
  2471.       tem = subst_reg_equivs (tem);
  2472.  
  2473.       /* Make sure that didn't make the address invalid again.  */
  2474.  
  2475.       if (! subst_reg_equivs_changed || strict_memory_address_p (mode, tem))
  2476.     {
  2477.       *loc = tem;
  2478.       return 0;
  2479.     }
  2480.     }
  2481.  
  2482.   /* If constants aren't valid addresses, reload the constant address
  2483.      into a register.  */
  2484.   if (CONSTANT_ADDRESS_P (ad) && ! strict_memory_address_p (mode, ad))
  2485.     {
  2486.       push_reload (ad, 0, loc, 0,
  2487.            BASE_REG_CLASS,
  2488.            Pmode, 0, VOIDmode, 0, operand);
  2489.       return 1;
  2490.     }
  2491.  
  2492.   return find_reloads_address_1 (ad, 0, loc, operand);
  2493. }
  2494.  
  2495. /* Find all pseudo regs appearing in AD
  2496.    that are eliminable in favor of equivalent values
  2497.    and do not have hard regs; replace them by their equivalents.  */
  2498.  
  2499. static rtx
  2500. subst_reg_equivs (ad)
  2501.      rtx ad;
  2502. {
  2503.   register RTX_CODE code = GET_CODE (ad);
  2504.   register int i;
  2505.   register char *fmt;
  2506.  
  2507.   switch (code)
  2508.     {
  2509.     case CONST_INT:
  2510.     case CONST:
  2511.     case CONST_DOUBLE:
  2512.     case SYMBOL_REF:
  2513.     case LABEL_REF:
  2514.     case PC:
  2515.     case CC0:
  2516.       return ad;
  2517.  
  2518.     case REG:
  2519.       {
  2520.     register int regno = REGNO (ad);
  2521.  
  2522.     if (reg_equiv_constant[regno] != 0)
  2523.       {
  2524.         subst_reg_equivs_changed = 1;
  2525.         return reg_equiv_constant[regno];
  2526.       }
  2527.       }
  2528.       return ad;
  2529.  
  2530.     case PLUS:
  2531.       /* Quickly dispose of a common case.  */
  2532.       if (XEXP (ad, 0) == frame_pointer_rtx
  2533.       && GET_CODE (XEXP (ad, 1)) == CONST_INT)
  2534.     return ad;
  2535.     }
  2536.  
  2537.   fmt = GET_RTX_FORMAT (code);
  2538.   for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
  2539.     if (fmt[i] == 'e')
  2540.       XEXP (ad, i) = subst_reg_equivs (XEXP (ad, i));
  2541.   return ad;
  2542. }
  2543.  
  2544. /* If ADDR is a sum containing a pseudo register that should be
  2545.    replaced with a constant (from reg_equiv_constant),
  2546.    return the result of doing so, and also apply the associative
  2547.    law so that the result is more likely to be a valid address.
  2548.    (But it is not guaranteed to be one.)
  2549.  
  2550.    In all other cases, return ADDR.  */
  2551.  
  2552. static rtx
  2553. subst_indexed_address (addr)
  2554.      rtx addr;
  2555. {
  2556.   rtx const_part = 0;
  2557.   rtx var_part = 0;
  2558.   int regno;
  2559.  
  2560.   if (GET_CODE (addr) == PLUS)
  2561.     {
  2562.       if (CONSTANT_P (XEXP (addr, 0)))
  2563.     const_part = XEXP (addr, 0),
  2564.     var_part = XEXP (addr, 1);
  2565.       else if (CONSTANT_P (XEXP (addr, 1)))
  2566.     const_part = XEXP (addr, 1),
  2567.     var_part = XEXP (addr, 0);
  2568.       else
  2569.     var_part = addr;
  2570.  
  2571.       if (const_part && GET_CODE (const_part) == CONST)
  2572.     const_part = XEXP (const_part, 0);
  2573.  
  2574.       if (GET_CODE (var_part) == REG
  2575.       && (regno = REGNO (var_part)) >= FIRST_PSEUDO_REGISTER
  2576.       && reg_renumber[regno] < 0
  2577.       && reg_equiv_constant[regno] != 0)
  2578.     return (const_part
  2579.             ? gen_rtx (CONST, VOIDmode,
  2580.                gen_rtx (PLUS, Pmode, const_part,
  2581.                     reg_equiv_constant[regno]))
  2582.         : reg_equiv_constant[regno]);
  2583.  
  2584.       if (GET_CODE (var_part) != PLUS)
  2585.     return addr;
  2586.  
  2587.       if (GET_CODE (XEXP (var_part, 0)) == REG
  2588.       && (regno = REGNO (XEXP (var_part, 0))) >= FIRST_PSEUDO_REGISTER
  2589.       && reg_renumber[regno] < 0
  2590.       && reg_equiv_constant[regno] != 0)
  2591.     return gen_rtx (PLUS, Pmode, XEXP (var_part, 1),
  2592.             (const_part
  2593.              ? gen_rtx (CONST, VOIDmode,
  2594.                     gen_rtx (PLUS, Pmode, const_part,
  2595.                          reg_equiv_constant[regno]))
  2596.              : reg_equiv_constant[regno]));
  2597.  
  2598.       if (GET_CODE (XEXP (var_part, 1)) == REG
  2599.       && (regno = REGNO (XEXP (var_part, 1))) >= FIRST_PSEUDO_REGISTER
  2600.       && reg_renumber[regno] < 0
  2601.       && reg_equiv_constant[regno] != 0)
  2602.     return gen_rtx (PLUS, Pmode, XEXP (var_part, 0),
  2603.             (const_part
  2604.              ? gen_rtx (CONST, VOIDmode,
  2605.                     gen_rtx (PLUS, Pmode, const_part,
  2606.                          reg_equiv_constant[regno]))
  2607.              : reg_equiv_constant[regno]));
  2608.     }
  2609.   return addr;
  2610. }
  2611.  
  2612. /* Record the pseudo registers we must reload into hard registers
  2613.    in a subexpression of a would-be memory address, X.
  2614.    (This function is not called if the address we find is strictly valid.)
  2615.    CONTEXT = 1 means we are considering regs as index regs,
  2616.    = 0 means we are considering them as base regs.
  2617.  
  2618.    OPERAND is the operand of the insn within which this address appears.
  2619.  
  2620.    We return nonzero if X, as a whole, is reloaded or replaced.  */
  2621.  
  2622. /* Note that we take shortcuts assuming that no multi-reg machine mode
  2623.    occurs as part of an address.
  2624.    Also, this is not fully machine-customizable; it works for machines
  2625.    such as vaxes and 68000's and 32000's, but other possible machines
  2626.    could have addressing modes that this does not handle right.  */
  2627.  
  2628. static int
  2629. find_reloads_address_1 (x, context, loc, operand)
  2630.      rtx x;
  2631.      int context;
  2632.      rtx *loc;
  2633.      rtx operand;
  2634. {
  2635.   register RTX_CODE code = GET_CODE (x);
  2636.  
  2637.   if (code == PLUS)
  2638.     {
  2639.       register rtx op0 = XEXP (x, 0);
  2640.       register rtx op1 = XEXP (x, 1);
  2641.       register RTX_CODE code0 = GET_CODE (op0);
  2642.       register RTX_CODE code1 = GET_CODE (op1);
  2643.       if (code0 == MULT || code0 == SIGN_EXTEND || code1 == MEM)
  2644.     {
  2645.       find_reloads_address_1 (op0, 1, &XEXP (x, 0), operand);
  2646.       find_reloads_address_1 (op1, 0, &XEXP (x, 1), operand);
  2647.     }
  2648.       else if (code1 == MULT || code1 == SIGN_EXTEND || code0 == MEM)
  2649.     {
  2650.       find_reloads_address_1 (op0, 0, &XEXP (x, 0), operand);
  2651.       find_reloads_address_1 (op1, 1, &XEXP (x, 1), operand);
  2652.     }
  2653.       else if (code0 == CONST_INT || code0 == CONST
  2654.            || code0 == SYMBOL_REF || code0 == LABEL_REF)
  2655.     {
  2656.       find_reloads_address_1 (op1, 0, &XEXP (x, 1), operand);
  2657.     }
  2658.       else if (code1 == CONST_INT || code1 == CONST
  2659.            || code1 == SYMBOL_REF || code1 == LABEL_REF)
  2660.     {
  2661.       find_reloads_address_1 (op0, 0, &XEXP (x, 0), operand);
  2662.     }
  2663.       else if (code0 == REG && code1 == REG)
  2664.     {
  2665.       if (REG_OK_FOR_INDEX_P (op0)
  2666.           && REG_OK_FOR_BASE_P (op1))
  2667.         return 0;
  2668.       else if (REG_OK_FOR_INDEX_P (op1)
  2669.           && REG_OK_FOR_BASE_P (op0))
  2670.         return 0;
  2671.       else if (REG_OK_FOR_BASE_P (op1))
  2672.         find_reloads_address_1 (op0, 1, &XEXP (x, 0), operand);
  2673.       else if (REG_OK_FOR_BASE_P (op0))
  2674.         find_reloads_address_1 (op1, 1, &XEXP (x, 1), operand);
  2675.       else if (REG_OK_FOR_INDEX_P (op1))
  2676.         find_reloads_address_1 (op0, 0, &XEXP (x, 0), operand);
  2677.       else if (REG_OK_FOR_INDEX_P (op0))
  2678.         find_reloads_address_1 (op1, 0, &XEXP (x, 1), operand);
  2679.       else
  2680.         {
  2681.           find_reloads_address_1 (op0, 1, &XEXP (x, 0), operand);
  2682.           find_reloads_address_1 (op1, 0, &XEXP (x, 1), operand);
  2683.         }
  2684.     }
  2685.       else if (code0 == REG)
  2686.     {
  2687.       find_reloads_address_1 (op0, 1, &XEXP (x, 0), operand);
  2688.       find_reloads_address_1 (op1, 0, &XEXP (x, 1), operand);
  2689.     }
  2690.       else if (code1 == REG)
  2691.     {
  2692.       find_reloads_address_1 (op1, 1, &XEXP (x, 1), operand);
  2693.       find_reloads_address_1 (op0, 0, &XEXP (x, 0), operand);
  2694.     }
  2695.     }
  2696.   else if (code == POST_INC || code == POST_DEC
  2697.        || code == PRE_INC || code == PRE_DEC)
  2698.     {
  2699.       if (GET_CODE (XEXP (x, 0)) == REG)
  2700.     {
  2701.       register int regno = REGNO (XEXP (x, 0));
  2702.       int value = 0;
  2703.  
  2704.       /* A register that is incremented cannot be constant!  */
  2705.       if (regno >= FIRST_PSEUDO_REGISTER
  2706.           && reg_equiv_constant[regno] != 0)
  2707.         abort ();
  2708.  
  2709.       /* Handle a register that is equivalent to a memory location
  2710.          which cannot be addressed directly.  */
  2711.       if (reg_equiv_address[regno] != 0)
  2712.         {
  2713.           rtx tem = make_memloc (XEXP (x, 0), regno);
  2714.           /* First reload the memory location's address.  */
  2715.           push_reload (XEXP (tem, 0), 0, &XEXP (tem, 0), 0,
  2716.                BASE_REG_CLASS,
  2717.                GET_MODE (XEXP (tem, 0)), 0, VOIDmode, 0,
  2718.                operand);
  2719.           /* Put this inside a new increment-expression.  */
  2720.           x = gen_rtx (GET_CODE (x), GET_MODE (x), tem);
  2721.           /* Proceed to reload that, as if it contained a register.  */
  2722.         }
  2723.  
  2724.       /* If we have a hard register that is ok as an index,
  2725.          don't make a reload.  If an autoincrement of a nice register
  2726.          isn't "valid", it must be that no autoincrement is "valid".
  2727.          If that is true and something made an autoincrement anyway,
  2728.          this must be a special context where one is allowed.
  2729.          (For example, a "push" instruction.)
  2730.          We can't improve this address, so leave it alone.  */
  2731.  
  2732.       /* Otherwise, reload the autoincrement into a suitable hard reg
  2733.          and record how much to increment by.  */
  2734.  
  2735.       if (reg_renumber[regno] >= 0)
  2736.         regno = reg_renumber[regno];
  2737.       if ((regno >= FIRST_PSEUDO_REGISTER
  2738.            || !(context ? REGNO_OK_FOR_INDEX_P (regno)
  2739.             : REGNO_OK_FOR_BASE_P (regno))))
  2740.         {
  2741.           register rtx link;
  2742.  
  2743.           int reloadnum
  2744.         = push_reload (x, 0, loc, 0,
  2745.                    context ? INDEX_REG_CLASS : BASE_REG_CLASS,
  2746.                    GET_MODE (x), GET_MODE (x), VOIDmode, 0, operand);
  2747.           reload_inc[reloadnum]
  2748.         = find_inc_amount (PATTERN (this_insn), XEXP (x, 0));
  2749.  
  2750.           value = 1;
  2751.  
  2752.           /* Update the REG_INC notes.  */
  2753.  
  2754.           for (link = REG_NOTES (this_insn);
  2755.            link; link = XEXP (link, 1))
  2756.         if (REG_NOTE_KIND (link) == REG_INC
  2757.             && REGNO (XEXP (link, 0)) == REGNO (XEXP (x, 0)))
  2758.           push_replacement (&XEXP (link, 0), reloadnum, VOIDmode);
  2759.         }
  2760.       return value;
  2761.     }
  2762.     }
  2763.   else if (code == REG)
  2764.     {
  2765.       register int regno = REGNO (x);
  2766.  
  2767.       if (reg_equiv_constant[regno] != 0)
  2768.     {
  2769.       push_reload (reg_equiv_constant[regno], 0, loc, 0,
  2770.                context ? INDEX_REG_CLASS : BASE_REG_CLASS,
  2771.                GET_MODE (x), 0, VOIDmode, 0, operand);
  2772.       return 1;
  2773.     }
  2774.  
  2775. #if 0 /* This might screw code in reload1.c to delete prior output-reload
  2776.      that feeds this insn.  */
  2777.       if (reg_equiv_mem[regno] != 0)
  2778.     {
  2779.       push_reload (reg_equiv_mem[regno], 0, loc, 0,
  2780.                context ? INDEX_REG_CLASS : BASE_REG_CLASS,
  2781.                GET_MODE (x), 0, VOIDmode, 0, operand);
  2782.       return 1;
  2783.     }
  2784. #endif
  2785.       if (reg_equiv_address[regno] != 0)
  2786.     {
  2787.       x = make_memloc (x, regno);
  2788.       push_reload (XEXP (x, 0), 0, &XEXP (x, 0), 0,
  2789.                BASE_REG_CLASS,
  2790.                GET_MODE (XEXP (x, 0)), 0, VOIDmode, 0, operand);
  2791.     }
  2792.  
  2793.       if (reg_renumber[regno] >= 0)
  2794.     regno = reg_renumber[regno];
  2795.       if ((regno >= FIRST_PSEUDO_REGISTER
  2796.        || !(context ? REGNO_OK_FOR_INDEX_P (regno)
  2797.         : REGNO_OK_FOR_BASE_P (regno))))
  2798.     {
  2799.       push_reload (x, 0, loc, 0,
  2800.                context ? INDEX_REG_CLASS : BASE_REG_CLASS,
  2801.                GET_MODE (x), 0, VOIDmode, 0, operand);
  2802.       return 1;
  2803.     }
  2804.     }
  2805.   else
  2806.     {
  2807.       register char *fmt = GET_RTX_FORMAT (code);
  2808.       register int i;
  2809.       for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
  2810.     {
  2811.       if (fmt[i] == 'e')
  2812.         find_reloads_address_1 (XEXP (x, i), context, &XEXP (x, i), operand);
  2813.     }
  2814.     }
  2815.  
  2816.   return 0;
  2817. }
  2818.  
  2819. /* Substitute into X the registers into which we have reloaded
  2820.    the things that need reloading.  The array `replacements'
  2821.    says contains the locations of all pointers that must be changed
  2822.    and says what to replace them with.
  2823.  
  2824.    Return the rtx that X translates into; usually X, but modified.  */
  2825.  
  2826. void
  2827. subst_reloads ()
  2828. {
  2829.   register int i;
  2830.  
  2831.   for (i = 0; i < n_replacements; i++)
  2832.     {
  2833.       register struct replacement *r = &replacements[i];
  2834.       register rtx reloadreg = reload_reg_rtx[r->what];
  2835.       if (reloadreg)
  2836.     {
  2837.       /* Encapsulate RELOADREG so its machine mode matches what
  2838.          used to be there.  */
  2839.       if (GET_MODE (reloadreg) != r->mode && r->mode != VOIDmode)
  2840.         reloadreg = gen_rtx (SUBREG, r->mode, reloadreg, 0);
  2841.       *r->where = reloadreg;
  2842.     }
  2843.       /* If reload got no reg and isn't optional, something's wrong.  */
  2844.       else if (! reload_optional[r->what])
  2845.     abort ();
  2846.     }
  2847. }
  2848.  
  2849. #if 0
  2850.  
  2851. /* [[This function is currently obsolete, now that volatility
  2852.    is represented by a special bit `volatil' so VOLATILE is never used;
  2853.    and UNCHANGING has never been brought into use.]]
  2854.  
  2855.    Alter X by eliminating all VOLATILE and UNCHANGING expressions.
  2856.    Each of them is replaced by its operand.
  2857.    Thus, (PLUS (VOLATILE (MEM (REG 5))) (CONST_INT 4))
  2858.    becomes (PLUS (MEM (REG 5)) (CONST_INT 4)).
  2859.  
  2860.    If X is itself a VOLATILE expression,
  2861.    we return the expression that should replace it
  2862.    but we do not modify X.  */
  2863.  
  2864. static rtx
  2865. forget_volatility (x)
  2866.      register rtx x;
  2867. {
  2868.   enum rtx_code code = GET_CODE (x);
  2869.   register char *fmt;
  2870.   register int i;
  2871.   register rtx value = 0;
  2872.  
  2873.   switch (code)
  2874.     {
  2875.     case LABEL_REF:
  2876.     case SYMBOL_REF:
  2877.     case CONST_INT:
  2878.     case CONST_DOUBLE:
  2879.     case CONST:
  2880.     case REG:
  2881.     case CC0:
  2882.     case PC:
  2883.       return x;
  2884.  
  2885.     case VOLATILE:
  2886.     case UNCHANGING:
  2887.       return XEXP (x, 0);
  2888.     }
  2889.  
  2890.   fmt = GET_RTX_FORMAT (code);
  2891.   for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
  2892.     {
  2893.       if (fmt[i] == 'e')
  2894.     XEXP (x, i) = forget_volatility (XEXP (x, i));
  2895.       if (fmt[i] == 'E')
  2896.     {
  2897.       register int j;
  2898.       for (j = XVECLEN (x, i) - 1; j >= 0; j--)
  2899.         XVECEXP (x, i, j) = forget_volatility (XVECEXP (x, i, j));
  2900.     }
  2901.     }
  2902.  
  2903.   return x;
  2904. }
  2905.  
  2906. #endif
  2907.  
  2908. /* Check the insns before INSN to see if there is a suitable register
  2909.    containing the same value as GOAL.
  2910.    If OTHER is -1, look for a register in class CLASS.
  2911.    Otherwise, just see if register number OTHER shares GOAL's value.
  2912.  
  2913.    Return an rtx for the register found, or zero if none is found.
  2914.  
  2915.    If RELOAD_REG_P is (short *)1,
  2916.    we reject any hard reg that appears in reload_reg_rtx
  2917.    because such a hard reg is also needed coming into this insn.
  2918.  
  2919.    If RELOAD_REG_P is any other nonzero value,
  2920.    it is a vector indexed by hard reg number
  2921.    and we reject any hard reg whose element in the vector is nonnegative
  2922.    as well as any that appears in reload_reg_rtx.
  2923.  
  2924.    If GOAL is zero, then GOALREG is a register number; we look
  2925.    for an equivalent for that register.
  2926.  
  2927.    MODE is the machine mode of the value we want an equivalence for.
  2928.    If GOAL is nonzero and not VOIDmode, then it must have mode MODE.
  2929.  
  2930.    This function is used by jump.c as well as in the reload pass.
  2931.  
  2932.    If GOAL is a PLUS, we assume it adds the stack pointer to a constant.  */
  2933.  
  2934. rtx
  2935. find_equiv_reg (goal, insn, class, other, reload_reg_p, goalreg, mode)
  2936.      register rtx goal;
  2937.      rtx insn;
  2938.      enum reg_class class;
  2939.      register int other;
  2940.      short *reload_reg_p;
  2941.      int goalreg;
  2942.      enum machine_mode mode;
  2943. {
  2944.   register rtx p = insn;
  2945.   rtx valtry, value, where;
  2946.   register rtx pat;
  2947.   register int regno = -1;
  2948.   int valueno;
  2949.   int goal_mem = 0;
  2950.   int goal_const = 0;
  2951.   int goal_mem_addr_varies = 0;
  2952.   int nregs;
  2953.   int valuenregs;
  2954.  
  2955.   if (goal == 0)
  2956.     regno = goalreg;
  2957.   else if (GET_CODE (goal) == REG)
  2958.     regno = REGNO (goal);
  2959.   else if (GET_CODE (goal) == MEM)
  2960.     {
  2961.       enum rtx_code code = GET_CODE (XEXP (goal, 0));
  2962.       if (MEM_VOLATILE_P (goal))
  2963.     return 0;
  2964.       if (flag_float_store
  2965. #ifdef APPLE_HAX
  2966.       && (GET_MODE_CLASS (GET_MODE (goal)) == MODE_FLOAT))
  2967. #else
  2968.       && (GET_MODE (goal) == DFmode || GET_MODE (goal) == SFmode))
  2969. #endif /* APPLE_HAX */
  2970.     return 0;
  2971.       /* An address with side effects must be reexecuted.  */
  2972.       switch (code)
  2973.     {
  2974.     case POST_INC:
  2975.     case PRE_INC:
  2976.     case POST_DEC:
  2977.     case PRE_DEC:
  2978.       return 0;
  2979.     }
  2980.       goal_mem = 1;
  2981.     }
  2982.   else if (CONSTANT_P (goal))
  2983.     goal_const = 1;
  2984.   else
  2985.     return 0;
  2986.  
  2987.   /* On some machines, certain regs must always be rejected
  2988.      because they don't behave the way ordinary registers do.  */
  2989.   
  2990. #ifdef OVERLAPPING_REGNO_P
  2991.    if (regno >= 0 && regno < FIRST_PSEUDO_REGISTER
  2992.        && OVERLAPPING_REGNO_P (regno))
  2993.      return 0;
  2994. #endif      
  2995.  
  2996.   /* Scan insns back from INSN, looking for one that copies
  2997.      a value into or out of GOAL.
  2998.      Stop and give up if we reach a label.  */
  2999.  
  3000.   while (1)
  3001.     {
  3002.       p = PREV_INSN (p);
  3003.       if (p == 0 || GET_CODE (p) == CODE_LABEL)
  3004.     return 0;
  3005.       if (GET_CODE (p) == INSN
  3006.       /* If we don't want spill regs (true for all calls in this file) */
  3007.       && (! (reload_reg_p != 0 && reload_reg_p != (short *)1)
  3008.       /* then ignore insns introduced by reload; they aren't useful
  3009.          and can cause results in reload_as_needed to be different
  3010.          from what they were when calculating the need for spills.
  3011.          If we notice an input-reload insn here, we will reject it below,
  3012.          but it might hide a usable equivalent.  That makes bad code.
  3013.          It may even abort: perhaps no reg was spilled for this insn
  3014.          because it was assumed we would find that equivalent.  */
  3015.           || INSN_UID (p) < reload_first_uid))
  3016.     {
  3017.       pat = PATTERN (p);
  3018.       /* First check for something that sets some reg equal to GOAL.  */
  3019.       if (GET_CODE (pat) == SET
  3020.           && ((regno >= 0
  3021.            && GET_CODE (SET_SRC (pat)) == REG
  3022.            && REGNO (SET_SRC (pat)) == regno
  3023.            && GET_CODE (valtry = SET_DEST (pat)) == REG)
  3024.           ||
  3025.           (regno >= 0
  3026.            && GET_CODE (SET_DEST (pat)) == REG
  3027.            && REGNO (SET_DEST (pat)) == regno
  3028.            && GET_CODE (valtry = SET_SRC (pat)) == REG)
  3029.           ||
  3030.           (goal_const && rtx_equal_p (SET_SRC (pat), goal)
  3031.            && GET_CODE (valtry = SET_DEST (pat)) == REG)
  3032.           || (goal_mem
  3033.               && GET_CODE (valtry = SET_DEST (pat)) == REG
  3034.               && rtx_renumbered_equal_p (goal, SET_SRC (pat)))
  3035.           || (goal_mem
  3036.               && GET_CODE (valtry = SET_SRC (pat)) == REG
  3037.               && rtx_renumbered_equal_p (goal, SET_DEST (pat)))))
  3038.         if (valueno = REGNO (valtry),
  3039.         other >= 0
  3040.         ? valueno == other
  3041.         : ((unsigned) valueno < FIRST_PSEUDO_REGISTER
  3042.            && TEST_HARD_REG_BIT (reg_class_contents[(int) class],
  3043.                      valueno)))
  3044.           {
  3045.         value = valtry;
  3046.         where = p;
  3047.         break;
  3048.           }
  3049.     }
  3050.     }
  3051.  
  3052.   /* We found a previous insn copying GOAL into a suitable other reg VALUE
  3053.      (or copying VALUE into GOAL, if GOAL is also a register).
  3054.      Now verify that VALUE is really valid.  */
  3055.  
  3056.   /* VALUENO is the register number of VALUE; a hard register.  */
  3057.  
  3058.   /* Don't find the sp as an equiv, since pushes that we don't notice
  3059.      would invalidate it.  */
  3060.   if (valueno == STACK_POINTER_REGNUM)
  3061.     return 0;
  3062.  
  3063.   /* Reject VALUE if the copy-insn moved the wrong sort of datum.  */
  3064.   if (GET_MODE (value) != mode)
  3065.     return 0;
  3066.  
  3067.   /* Reject VALUE if it was loaded from GOAL
  3068.      and is also a register that appears in the address of GOAL.  */
  3069.  
  3070.   if (goal_mem && value == SET_DEST (PATTERN (where))
  3071.       && refers_to_regno_p (valueno,
  3072.                 valueno + HARD_REGNO_NREGS (valueno, mode),
  3073.                 goal, 0))
  3074.     return 0;
  3075.  
  3076.   /* Reject VALUE if it is one of the regs reserved for reloads.
  3077.      Reload1 knows how to reuse them anyway, and it would get
  3078.      confused if we allocated one without its knowledge.
  3079.      (Now that insns introduced by reload are ignored above,
  3080.      this case shouldn't happen, but I'm not positive.)  */
  3081.  
  3082.   if (reload_reg_p != 0 && reload_reg_p != (short *)1
  3083.       && reload_reg_p[valueno] >= 0)
  3084.     return 0;
  3085.  
  3086.   /* On some machines, certain regs must always be rejected
  3087.      because they don't behave the way ordinary registers do.  */
  3088.   
  3089. #ifdef OVERLAPPING_REGNO_P
  3090.   if (OVERLAPPING_REGNO_P (valueno))
  3091.     return 0;
  3092. #endif      
  3093.  
  3094.   nregs = HARD_REGNO_NREGS (regno, mode);
  3095.   valuenregs = HARD_REGNO_NREGS (valueno, mode);
  3096.  
  3097.   /* Reject VALUE if it is a register being used for an input reload
  3098.      even if it is not one of those reserved.  */
  3099.  
  3100.   if (reload_reg_p != 0)
  3101.     {
  3102.       int i;
  3103.       for (i = 0; i < n_reloads; i++)
  3104.     if (reload_reg_rtx[i] != 0 && reload_in[i])
  3105.       {
  3106.         int regno1 = REGNO (reload_reg_rtx[i]);
  3107.         int nregs1 = HARD_REGNO_NREGS (regno1,
  3108.                        GET_MODE (reload_reg_rtx[i]));
  3109.         if (regno1 < valueno + valuenregs
  3110.         && regno1 + nregs1 > valueno)
  3111.           return 0;
  3112.       }
  3113.     }
  3114.  
  3115.   if (goal_mem)
  3116.     goal_mem_addr_varies = rtx_addr_varies_p (goal);
  3117.  
  3118.   /* Now verify that the values of GOAL and VALUE remain unaltered
  3119.      until INSN is reached.  */
  3120.  
  3121.   p = insn;
  3122.   while (1)
  3123.     {
  3124.       p = PREV_INSN (p);
  3125.       if (p == where)
  3126.     return value;
  3127.  
  3128.       /* Don't trust the conversion past a function call
  3129.      if either of the two is in a call-clobbered register, or memory.  */
  3130.       if (GET_CODE (p) == CALL_INSN
  3131.       && ((regno >= 0 && regno < FIRST_PSEUDO_REGISTER
  3132.            && call_used_regs[regno])
  3133.           ||
  3134.           (valueno >= 0 && valueno < FIRST_PSEUDO_REGISTER
  3135.            && call_used_regs[valueno])
  3136.           ||
  3137.           goal_mem))
  3138.     return 0;
  3139.  
  3140.       if (GET_CODE (p) == INSN || GET_CODE (p) == JUMP_INSN
  3141.       || GET_CODE (p) == CALL_INSN)
  3142.     {
  3143.       /* If this insn P stores in either GOAL or VALUE, return 0.
  3144.          If GOAL is a memory ref and this insn writes memory, return 0.
  3145.          If GOAL is a memory ref and its address is not constant,
  3146.          and this insn P changes a register, return 0.
  3147.          That is in lieue of checking whether GOAL uses this register.  */
  3148.  
  3149.       pat = PATTERN (p);
  3150.       if (GET_CODE (pat) == SET || GET_CODE (pat) == CLOBBER)
  3151.         {
  3152.           register rtx dest = SET_DEST (pat);
  3153.           while (GET_CODE (dest) == SUBREG
  3154.              || GET_CODE (dest) == ZERO_EXTRACT
  3155.              || GET_CODE (dest) == SIGN_EXTRACT
  3156.              || GET_CODE (dest) == STRICT_LOW_PART)
  3157.         dest = XEXP (dest, 0);
  3158.           if (GET_CODE (dest) == REG)
  3159.         {
  3160.           register int xregno = REGNO (dest);
  3161.           int xnregs;
  3162.           if (REGNO (dest) < FIRST_PSEUDO_REGISTER)
  3163.             xnregs = HARD_REGNO_NREGS (xregno, GET_MODE (dest));
  3164.           else
  3165.             xnregs = 1;
  3166.           if (xregno < regno + nregs && xregno + xnregs > regno)
  3167.             return 0;
  3168.           if (xregno < valueno + valuenregs
  3169.               && xregno + xnregs > valueno)
  3170.             return 0;
  3171.           if (goal_mem_addr_varies)
  3172.             return 0;
  3173.         }
  3174.           else if (goal_mem && GET_CODE (dest) == MEM
  3175.                && ! push_operand (dest, GET_MODE (dest)))
  3176.         return 0;
  3177.         }
  3178.       else if (GET_CODE (pat) == PARALLEL)
  3179.         {
  3180.           register int i;
  3181.           for (i = XVECLEN (pat, 0) - 1; i >= 0; i--)
  3182.         {
  3183.           register rtx v1 = XVECEXP (pat, 0, i);
  3184.           if (GET_CODE (v1) == SET || GET_CODE (v1) == CLOBBER)
  3185.             {
  3186.               register rtx dest = SET_DEST (v1);
  3187.               while (GET_CODE (dest) == SUBREG
  3188.                  || GET_CODE (dest) == ZERO_EXTRACT
  3189.                  || GET_CODE (dest) == SIGN_EXTRACT
  3190.                  || GET_CODE (dest) == STRICT_LOW_PART)
  3191.             dest = XEXP (dest, 0);
  3192.               if (GET_CODE (dest) == REG)
  3193.             {
  3194.               register int xregno = REGNO (dest);
  3195.               int xnregs;
  3196.               if (REGNO (dest) < FIRST_PSEUDO_REGISTER)
  3197.                 xnregs = HARD_REGNO_NREGS (xregno, GET_MODE (dest));
  3198.               else
  3199.                 xnregs = 1;
  3200.               if (xregno < regno + nregs
  3201.                   && xregno + xnregs > regno)
  3202.                 return 0;
  3203.               if (xregno < valueno + valuenregs
  3204.                   && xregno + xnregs > valueno)
  3205.                 return 0;
  3206.               if (goal_mem_addr_varies)
  3207.                 return 0;
  3208.             }
  3209.               else if (goal_mem && GET_CODE (dest) == MEM
  3210.                    && ! push_operand (dest, GET_MODE (dest)))
  3211.             return 0;
  3212.             }
  3213.         }
  3214.         }
  3215.       /* If this insn auto-increments or auto-decrements
  3216.          either regno or valueno, return 0 now.
  3217.          If GOAL is a memory ref and its address is not constant,
  3218.          and this insn P increments a register, return 0.
  3219.          That is in lieue of checking whether GOAL uses this register.  */
  3220.       {
  3221.         register rtx link;
  3222.  
  3223.         for (link = REG_NOTES (p); link; link = XEXP (link, 1))
  3224.           if (REG_NOTE_KIND (link) == REG_INC)
  3225.         {
  3226.           register int incno = REGNO (XEXP (link, 0));
  3227.           if (incno < regno + nregs && incno >= regno)
  3228.             return 0;
  3229.           if (incno < valueno + valuenregs && incno >= valueno)
  3230.             return 0;
  3231.           if (goal_mem_addr_varies)
  3232.             return 0;
  3233.         }
  3234.       }
  3235.     }
  3236.     }
  3237. }
  3238.  
  3239. /* Find a place where INCED appears in an increment or decrement operator
  3240.    within X, and return the amount INCED is incremented or decremented by.
  3241.    The value is always positive.  */
  3242.  
  3243. static int
  3244. find_inc_amount (x, inced)
  3245.      rtx x, inced;
  3246. {
  3247.   register enum rtx_code code = GET_CODE (x);
  3248.   register char *fmt;
  3249.   register int i;
  3250.  
  3251.   if (code == MEM)
  3252.     {
  3253.       register rtx addr = XEXP (x, 0);
  3254.       if ((GET_CODE (addr) == PRE_DEC
  3255.        || GET_CODE (addr) == POST_DEC
  3256.        || GET_CODE (addr) == PRE_INC
  3257.        || GET_CODE (addr) == POST_INC)
  3258.       && XEXP (addr, 0) == inced)
  3259.     return GET_MODE_SIZE (GET_MODE (x));
  3260.     }
  3261.  
  3262.   fmt = GET_RTX_FORMAT (code);
  3263.   for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
  3264.     {
  3265.       if (fmt[i] == 'e')
  3266.     {
  3267.       register int tem = find_inc_amount (XEXP (x, i), inced);
  3268.       if (tem != 0)
  3269.         return tem;
  3270.     }
  3271.       if (fmt[i] == 'E')
  3272.     {
  3273.       register int j;
  3274.       for (j = XVECLEN (x, i) - 1; j >= 0; j--)
  3275.         {
  3276.           register int tem = find_inc_amount (XVECEXP (x, i, j), inced);
  3277.           if (tem != 0)
  3278.         return tem;
  3279.         }
  3280.     }
  3281.     }
  3282.  
  3283.   return 0;
  3284. }
  3285.  
  3286. init_reload2()
  3287. {
  3288. #define INIT_RELOAD
  3289. #include "init.c"
  3290. }
  3291.