home *** CD-ROM | disk | FTP | other *** search
/ Education Sampler 1992 [NeXTSTEP] / Education_1992_Sampler.iso / NeXT / GnuSource / cc-61.0.1 / cc / reload1.c < prev    next >
C/C++ Source or Header  |  1991-08-02  |  173KB  |  5,078 lines

  1. /* Reload pseudo regs into hard regs for insns that require hard regs.
  2.    Copyright (C) 1987-1991 Free Software Foundation, Inc.
  3.  
  4. This file is part of GNU CC.
  5.  
  6. GNU CC is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2, or (at your option)
  9. any later version.
  10.  
  11. GNU CC is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with GNU CC; see the file COPYING.  If not, write to
  18. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20.  
  21. #include "config.h"
  22. #include "rtl.h"
  23. #include "obstack.h"
  24. #include "insn-config.h"
  25. #include "insn-flags.h"
  26. #include "flags.h"
  27. #include "regs.h"
  28. #include "hard-reg-set.h"
  29. #include "reload.h"
  30. #include "recog.h"
  31. #include "basic-block.h"
  32. #include "output.h"
  33. #include <stdio.h>
  34.  
  35. #define min(A,B) ((A) < (B) ? (A) : (B))
  36. #define max(A,B) ((A) > (B) ? (A) : (B))
  37.  
  38. /* This file contains the reload pass of the compiler, which is
  39.    run after register allocation has been done.  It checks that
  40.    each insn is valid (operands required to be in registers really
  41.    are in registers of the proper class) and fixes up invalid ones
  42.    by copying values temporarily into registers for the insns
  43.    that need them.
  44.  
  45.    The results of register allocation are described by the vector
  46.    reg_renumber; the insns still contain pseudo regs, but reg_renumber
  47.    can be used to find which hard reg, if any, a pseudo reg is in.
  48.  
  49.    The technique we always use is to free up a few hard regs that are
  50.    called ``reload regs'', and for each place where a pseudo reg
  51.    must be in a hard reg, copy it temporarily into one of the reload regs.
  52.  
  53.    All the pseudos that were formerly allocated to the hard regs that
  54.    are now in use as reload regs must be ``spilled''.  This means
  55.    that they go to other hard regs, or to stack slots if no other
  56.    available hard regs can be found.  Spilling can invalidate more
  57.    insns, requiring additional need for reloads, so we must keep checking
  58.    until the process stabilizes.
  59.  
  60.    For machines with different classes of registers, we must keep track
  61.    of the register class needed for each reload, and make sure that
  62.    we allocate enough reload registers of each class.
  63.  
  64.    The file reload.c contains the code that checks one insn for
  65.    validity and reports the reloads that it needs.  This file
  66.    is in charge of scanning the entire rtl code, accumulating the
  67.    reload needs, spilling, assigning reload registers to use for
  68.    fixing up each insn, and generating the new insns to copy values
  69.    into the reload registers.  */
  70.  
  71. /* During reload_as_needed, element N contains a REG rtx for the hard reg
  72.    into which pseudo reg N has been reloaded (perhaps for a previous insn). */
  73. static rtx *reg_last_reload_reg;
  74.  
  75. /* Elt N nonzero if reg_last_reload_reg[N] has been set in this insn
  76.    for an output reload that stores into reg N.  */
  77. static char *reg_has_output_reload;
  78.  
  79. /* Indicates which hard regs are reload-registers for an output reload
  80.    in the current insn.  */
  81. static HARD_REG_SET reg_is_output_reload;
  82.  
  83. /* Element N is the constant value to which pseudo reg N is equivalent,
  84.    or zero if pseudo reg N is not equivalent to a constant.
  85.    find_reloads looks at this in order to replace pseudo reg N
  86.    with the constant it stands for.  */
  87. rtx *reg_equiv_constant;
  88.  
  89. /* Element N is a memory location to which pseudo reg N is equivalent,
  90.    prior to any register elimination (such as frame pointer to stack
  91.    pointer).  Depending on whether or not it is a valid address, this value
  92.    is transferred to either reg_equiv_address or reg_equiv_mem.  */
  93. static rtx *reg_equiv_memory_loc;
  94.  
  95. /* Element N is the address of stack slot to which pseudo reg N is equivalent.
  96.    This is used when the address is not valid as a memory address
  97.    (because its displacement is too big for the machine.)  */
  98. rtx *reg_equiv_address;
  99.  
  100. /* Element N is the memory slot to which pseudo reg N is equivalent,
  101.    or zero if pseudo reg N is not equivalent to a memory slot.  */
  102. rtx *reg_equiv_mem;
  103.  
  104. /* Widest width in which each pseudo reg is referred to (via subreg).  */
  105. static int *reg_max_ref_width;
  106.  
  107. /* Element N is the insn that initialized reg N from its equivalent
  108.    constant or memory slot.  */
  109. static rtx *reg_equiv_init;
  110.  
  111. /* During reload_as_needed, element N contains the last pseudo regno
  112.    reloaded into the Nth reload register.  This vector is in parallel
  113.    with spill_regs.  */
  114. static int reg_reloaded_contents[FIRST_PSEUDO_REGISTER];
  115.  
  116. /* During reload_as_needed, element N contains the insn for which
  117.    the Nth reload register was last used.  This vector is in parallel
  118.    with spill_regs, and its contents are significant only when
  119.    reg_reloaded_contents is significant.  */
  120. static rtx reg_reloaded_insn[FIRST_PSEUDO_REGISTER];
  121.  
  122. /* Number of spill-regs so far; number of valid elements of spill_regs.  */
  123. static int n_spills;
  124.  
  125. /* In parallel with spill_regs, contains REG rtx's for those regs.
  126.    Holds the last rtx used for any given reg, or 0 if it has never
  127.    been used for spilling yet.  This rtx is reused, provided it has
  128.    the proper mode.  */
  129. static rtx spill_reg_rtx[FIRST_PSEUDO_REGISTER];
  130.  
  131. /* In parallel with spill_regs, contains nonzero for a spill reg
  132.    that was stored after the last time it was used.
  133.    The precise value is the insn generated to do the store.  */
  134. static rtx spill_reg_store[FIRST_PSEUDO_REGISTER];
  135.  
  136. /* This table is the inverse mapping of spill_regs:
  137.    indexed by hard reg number,
  138.    it contains the position of that reg in spill_regs,
  139.    or -1 for something that is not in spill_regs.  */
  140. static short spill_reg_order[FIRST_PSEUDO_REGISTER];
  141.  
  142. /* This reg set indicates registers that may not be used for retrying global
  143.    allocation.  The registers that may not be used include all spill registers
  144.    and the frame pointer (if we are using one).  */
  145. HARD_REG_SET forbidden_regs;
  146.  
  147. /* This reg set indicates registers that are not good for spill registers.
  148.    They will not be used to complete groups of spill registers.  This includes
  149.    all fixed registers, registers that may be eliminated, and registers
  150.    explicitly used in the rtl.
  151.  
  152.    (spill_reg_order prevents these registers from being used to start a
  153.    group.)  */
  154. static HARD_REG_SET bad_spill_regs;
  155.  
  156. /* Describes order of use of registers for reloading
  157.    of spilled pseudo-registers.  `spills' is the number of
  158.    elements that are actually valid; new ones are added at the end.  */
  159. static short spill_regs[FIRST_PSEUDO_REGISTER];
  160.  
  161. /* Describes order of preference for putting regs into spill_regs.
  162.    Contains the numbers of all the hard regs, in order most preferred first.
  163.    This order is different for each function.
  164.    It is set up by order_regs_for_reload.
  165.    Empty elements at the end contain -1.  */
  166. static short potential_reload_regs[FIRST_PSEUDO_REGISTER];
  167.  
  168. /* 1 for a hard register that appears explicitly in the rtl
  169.    (for example, function value registers, special registers
  170.    used by insns, structure value pointer registers).  */
  171. static char regs_explicitly_used[FIRST_PSEUDO_REGISTER];
  172.  
  173. /* Indicates if a register was counted against the need for
  174.    groups.  0 means it can count against max_nongroup instead.  */
  175. static HARD_REG_SET counted_for_groups;
  176.  
  177. /* Indicates if a register was counted against the need for
  178.    non-groups.  0 means it can become part of a new group.
  179.    During choose_reload_regs, 1 here means don't use this reg
  180.    as part of a group, even if it seems to be otherwise ok.  */
  181. static HARD_REG_SET counted_for_nongroups;
  182.  
  183. /* Nonzero if indirect addressing is supported on the machine; this means
  184.    that spilling (REG n) does not require reloading it into a register in
  185.    order to do (MEM (REG n)).  The value indicates the level of indirect
  186.    addressing supported, e.g., two means that (MEM (MEM (REG n))) is also
  187.    valid if (REG n) does not get a hard register.  */
  188.  
  189. static char spill_indirect_levels;
  190.  
  191. /* Nonzero if an address (plus (reg frame_pointer) (reg ...)) is valid.  */
  192.  
  193. char double_reg_address_ok;
  194.  
  195. /* Record the stack slot for each spilled hard register.  */
  196.  
  197. static rtx spill_stack_slot[FIRST_PSEUDO_REGISTER];
  198.  
  199. /* Width allocated so far for that stack slot.  */
  200.  
  201. static int spill_stack_slot_width[FIRST_PSEUDO_REGISTER];
  202.  
  203. /* Indexed by register class and basic block number, nonzero if there is
  204.    any need for a spill register of that class in that basic block.
  205.    The pointer is 0 if we did stupid allocation and don't know
  206.    the structure of basic blocks.  */
  207.  
  208. char *basic_block_needs[N_REG_CLASSES];
  209.  
  210. /* First uid used by insns created by reload in this function.
  211.    Used in find_equiv_reg.  */
  212. int reload_first_uid;
  213.  
  214. /* Flag set by local-alloc or global-alloc if anything is live in
  215.    a call-clobbered reg across calls.  */
  216.  
  217. int caller_save_needed;
  218.  
  219. /* Set to 1 while reload_as_needed is operating.
  220.    Required by some machines to handle any generated moves differently.  */
  221.  
  222. int reload_in_progress = 0;
  223.  
  224. /* This obstack is used for allocation of rtl during register elmination.
  225.    The allocated storage can be freed once find_reloads has processed the
  226.    insn.  */
  227.  
  228. struct obstack reload_obstack;
  229. char *reload_firstobj;
  230.  
  231. #define obstack_chunk_alloc xmalloc
  232. #define obstack_chunk_free free
  233.  
  234. extern int xmalloc ();
  235. extern void free ();
  236.  
  237. /* This structure is used to record information about register eliminations.
  238.    Each array entry describes one possible way of eliminating a register
  239.    in favor of another.   If there is more than one way of eliminating a
  240.    particular register, the most preferred should be specified first.  */
  241.  
  242. static struct elim_table
  243. {
  244.   int from;            /* Register number to be eliminated. */
  245.   int to;            /* Register number used as replacement. */
  246.   int initial_offset;        /* Initial difference between values. */
  247.   int can_eliminate;        /* Non-zero if this elimination can be done. */
  248.   int can_eliminate_previous;    /* Value of CAN_ELIMINATE in previous scan over
  249.                    insns made by reload. */
  250.   int offset;            /* Current offset between the two regs. */
  251.   int previous_offset;        /* Offset at end of previous insn. */
  252.   int ref_outside_mem;        /* "to" has been referenced outside a MEM. */
  253.   rtx from_rtx;            /* REG rtx for the register to be eliminated.
  254.                    We cannot simply compare the number since
  255.                    we might then spuriously replace a hard
  256.                    register corresponding to a pseudo
  257.                    assigned to the reg to be eliminated. */
  258.   rtx to_rtx;            /* REG rtx for the replacement. */
  259. } reg_eliminate[] =
  260.  
  261. /* If a set of eliminable registers was specified, define the table from it.
  262.    Otherwise, default to the normal case of the frame pointer being
  263.    replaced by the stack pointer.  */
  264.  
  265. #ifdef ELIMINABLE_REGS
  266.   ELIMINABLE_REGS;
  267. #else
  268.   {{ FRAME_POINTER_REGNUM, STACK_POINTER_REGNUM}};
  269. #endif
  270.  
  271. #define NUM_ELIMINABLE_REGS (sizeof reg_eliminate / sizeof reg_eliminate[0])
  272.  
  273. /* Record the number of pending eliminations that have an offset not equal
  274.    to their initial offset.  If non-zero, we use a new copy of each
  275.    replacement result in any insns encountered.  */
  276. static int num_not_at_initial_offset;
  277.  
  278. /* Count the number of registers that we may be able to eliminate.  */
  279. static int num_eliminable;
  280.  
  281. void mark_home_live ();
  282. static void count_possible_groups ();
  283. static int possible_group_p ();
  284. static void scan_paradoxical_subregs ();
  285. static void reload_as_needed ();
  286. static int modes_equiv_for_class_p ();
  287. static void alter_reg ();
  288. static void delete_dead_insn ();
  289. static int new_spill_reg();
  290. static int eliminate_regs_in_insn ();
  291. static void mark_not_eliminable ();
  292. static int spill_hard_reg ();
  293. static void choose_reload_regs ();
  294. static void emit_reload_insns ();
  295. static void delete_output_reload ();
  296. static void forget_old_reloads_1 ();
  297. static void order_regs_for_reload ();
  298. static rtx inc_for_reload ();
  299. static int constraint_accepts_reg_p ();
  300. static int count_occurrences ();
  301. static rtx gen_input_reload ();
  302.  
  303. extern void remove_death ();
  304. extern rtx adj_offsettable_operand ();
  305. extern rtx form_sum ();
  306.  
  307. void
  308. init_reload ()
  309. {
  310.   /* Initialize obstack for our rtl allocation. */
  311.   gcc_obstack_init (&reload_obstack);
  312.   reload_firstobj = (char *) obstack_alloc (&reload_obstack, 0);
  313. }
  314.  
  315. /* Main entry point for the reload pass, and only entry point
  316.    in this file.
  317.  
  318.    FIRST is the first insn of the function being compiled.
  319.  
  320.    GLOBAL nonzero means we were called from global_alloc
  321.    and should attempt to reallocate any pseudoregs that we
  322.    displace from hard regs we will use for reloads.
  323.    If GLOBAL is zero, we do not have enough information to do that,
  324.    so any pseudo reg that is spilled must go to the stack.
  325.  
  326.    DUMPFILE is the global-reg debugging dump file stream, or 0.
  327.    If it is nonzero, messages are written to it to describe
  328.    which registers are seized as reload regs, which pseudo regs
  329.    are spilled from them, and where the pseudo regs are reallocated to.  */
  330.  
  331. void
  332. reload (first, global, dumpfile)
  333.      rtx first;
  334.      int global;
  335.      FILE *dumpfile;
  336. {
  337.   register int class;
  338.   register int i;
  339.   register rtx insn;
  340.   register struct elim_table *ep;
  341.  
  342.   int something_changed;
  343.   int something_needs_reloads;
  344.   int something_needs_elimination;
  345.   int new_basic_block_needs;
  346.  
  347.   /* The basic block number currently being processed for INSN.  */
  348.   int this_block;
  349.  
  350.   /* Often (MEM (REG n)) is still valid even if (REG n) is put on the stack.
  351.      Set spill_indirect_levels to the number of levels such addressing is
  352.      permitted, zero if it is not permitted at all.  */
  353.   register rtx tem
  354.     = gen_rtx (MEM, Pmode,
  355.            gen_rtx (PLUS, Pmode,
  356.             gen_rtx (REG, Pmode, FRAME_POINTER_REGNUM),
  357.             gen_rtx (CONST_INT, VOIDmode, 4)));
  358.   spill_indirect_levels = 0;
  359.  
  360.   while (memory_address_p (QImode, tem))
  361.     {
  362.       spill_indirect_levels++;
  363.       tem = gen_rtx (MEM, Pmode, tem);
  364.     }
  365.  
  366.   /* Make sure even insns with volatile mem refs are recognizable.  */
  367.   init_recog ();
  368.  
  369.   tem = gen_rtx (PLUS, Pmode, 
  370.          gen_rtx (REG, Pmode, FRAME_POINTER_REGNUM),
  371.          gen_rtx (REG, Pmode, FRAME_POINTER_REGNUM));
  372.   /* This way, we make sure that reg+reg is an offsettable address.  */
  373.   tem = plus_constant (tem, 4);
  374.  
  375.   double_reg_address_ok = memory_address_p (QImode, tem);
  376.  
  377.   /* Enable find_equiv_reg to distinguish insns made by reload.  */
  378.   reload_first_uid = get_max_uid ();
  379.  
  380.   for (i = 0; i < N_REG_CLASSES; i++)
  381.     basic_block_needs[i] = 0;
  382.  
  383.   /* Remember which hard regs appear explicitly
  384.      before we merge into `regs_ever_live' the ones in which
  385.      pseudo regs have been allocated.  */
  386.   bcopy (regs_ever_live, regs_explicitly_used, sizeof regs_ever_live);
  387.  
  388.   /* We don't have a stack slot for any spill reg yet.  */
  389.   bzero (spill_stack_slot, sizeof spill_stack_slot);
  390.   bzero (spill_stack_slot_width, sizeof spill_stack_slot_width);
  391.  
  392.   /* Compute which hard registers are now in use
  393.      as homes for pseudo registers.
  394.      This is done here rather than (eg) in global_alloc
  395.      because this point is reached even if not optimizing.  */
  396.  
  397.   for (i = FIRST_PSEUDO_REGISTER; i < max_regno; i++)
  398.     mark_home_live (i);
  399.  
  400.   /* Make sure that the last insn in the chain
  401.      is not something that needs reloading.  */
  402.   emit_note (0, NOTE_INSN_DELETED);
  403.  
  404.   /* Find all the pseudo registers that didn't get hard regs
  405.      but do have known equivalent constants or memory slots.
  406.      These include parameters (known equivalent to parameter slots)
  407.      and cse'd or loop-moved constant memory addresses.
  408.  
  409.      Record constant equivalents in reg_equiv_constant
  410.      so they will be substituted by find_reloads.
  411.      Record memory equivalents in reg_mem_equiv so they can
  412.      be substituted eventually by altering the REG-rtx's.  */
  413.  
  414.   reg_equiv_constant = (rtx *) alloca (max_regno * sizeof (rtx));
  415.   bzero (reg_equiv_constant, max_regno * sizeof (rtx));
  416.   reg_equiv_memory_loc = (rtx *) alloca (max_regno * sizeof (rtx));
  417.   bzero (reg_equiv_memory_loc, max_regno * sizeof (rtx));
  418.   reg_equiv_mem = (rtx *) alloca (max_regno * sizeof (rtx));
  419.   bzero (reg_equiv_mem, max_regno * sizeof (rtx));
  420.   reg_equiv_init = (rtx *) alloca (max_regno * sizeof (rtx));
  421.   bzero (reg_equiv_init, max_regno * sizeof (rtx));
  422.   reg_equiv_address = (rtx *) alloca (max_regno * sizeof (rtx));
  423.   bzero (reg_equiv_address, max_regno * sizeof (rtx));
  424.   reg_max_ref_width = (int *) alloca (max_regno * sizeof (int));
  425.   bzero (reg_max_ref_width, max_regno * sizeof (int));
  426.  
  427.   /* Look for REG_EQUIV notes; record what each pseudo is equivalent to.
  428.      Also find all paradoxical subregs
  429.      and find largest such for each pseudo.  */
  430.  
  431.   for (insn = first; insn; insn = NEXT_INSN (insn))
  432.     {
  433.       rtx set = single_set (insn);
  434.  
  435.       if (set != 0 && GET_CODE (SET_DEST (set)) == REG)
  436.     {
  437.       rtx note = find_reg_note (insn, REG_EQUIV, 0);
  438.       if (note)
  439.         {
  440.           rtx x = XEXP (note, 0);
  441.           i = REGNO (SET_DEST (set));
  442.           if (i > LAST_VIRTUAL_REGISTER)
  443.         {
  444.           if (GET_CODE (x) == MEM)
  445.             reg_equiv_memory_loc[i] = x;
  446.           else if (CONSTANT_P (x))
  447.             {
  448.               if (LEGITIMATE_CONSTANT_P (x))
  449.             reg_equiv_constant[i] = x;
  450.               else
  451.             reg_equiv_memory_loc[i]
  452.               = force_const_mem (GET_MODE (x), x);
  453.             }
  454.           else
  455.             continue;
  456.  
  457.           /* If this register is being made equivalent to a MEM
  458.              and the MEM is not SET_SRC, the equivalencing insn
  459.              is one with the MEM as a SET_DEST and it occurs later.
  460.              So don't mark this insn now.  */
  461.           if (GET_CODE (x) != MEM
  462.               || rtx_equal_p (SET_SRC (set), x))
  463.             reg_equiv_init[i] = insn;
  464.         }
  465.         }
  466.     }
  467.  
  468.       /* If this insn is setting a MEM from a register equivalent to it,
  469.      this is the equivalencing insn.  */
  470.       else if (set && GET_CODE (SET_DEST (set)) == MEM
  471.            && GET_CODE (SET_SRC (set)) == REG
  472.            && reg_equiv_memory_loc[REGNO (SET_SRC (set))]
  473.            && rtx_equal_p (SET_DEST (set),
  474.                    reg_equiv_memory_loc[REGNO (SET_SRC (set))]))
  475.     reg_equiv_init[REGNO (SET_SRC (set))] = insn;
  476.  
  477.       if (GET_RTX_CLASS (GET_CODE (insn)) == 'i')
  478.     scan_paradoxical_subregs (PATTERN (insn));
  479.     }
  480.  
  481.   /* Does this function require a frame pointer?  */
  482.  
  483.   frame_pointer_needed = (! flag_omit_frame_pointer
  484.               || FRAME_POINTER_REQUIRED
  485.               || caller_save_needed);
  486.  
  487.   num_eliminable = 0;
  488.  
  489.   /* Initialize the table of registers to eliminate.  The way we do this
  490.      depends on how the eliminable registers were defined.  */
  491. #ifdef ELIMINABLE_REGS
  492.   for (ep = reg_eliminate; ep < ®_eliminate[NUM_ELIMINABLE_REGS]; ep++)
  493.     {
  494.       ep->can_eliminate = ep->can_eliminate_previous
  495.     = (CAN_ELIMINATE (ep->from, ep->to)
  496.        && (ep->from != FRAME_POINTER_REGNUM || ! frame_pointer_needed));
  497.     }
  498. #else
  499.   reg_eliminate[0].can_eliminate = reg_eliminate[0].can_eliminate_previous
  500.     = ! frame_pointer_needed;
  501. #endif
  502.  
  503.   /* Count the number of eliminable registers and build the FROM and TO
  504.      REG rtx's.  Note that code in gen_rtx will cause, e.g., 
  505.      gen_rtx (REG, Pmode, STACK_POINTER_REGNUM) to equal stack_pointer_rtx.
  506.      We depend on this.  */
  507.   for (ep = reg_eliminate; ep < ®_eliminate[NUM_ELIMINABLE_REGS]; ep++)
  508.     {
  509.       num_eliminable += ep->can_eliminate;
  510.       ep->from_rtx = gen_rtx (REG, Pmode, ep->from);
  511.       ep->to_rtx = gen_rtx (REG, Pmode, ep->to);
  512.     }
  513.  
  514.   /* Alter each pseudo-reg rtx to contain its hard reg number.
  515.      Delete initializations of pseudos that don't have hard regs
  516.      and do have equivalents.
  517.      Assign stack slots to the pseudos that lack hard regs or equivalents.
  518.      Do not touch virtual registers.  */
  519.  
  520.   for (i = LAST_VIRTUAL_REGISTER + 1; i < max_regno; i++)
  521.     alter_reg (i, -1);
  522.  
  523.   /* Round size of stack frame to BIGGEST_ALIGNMENT.  This must be done here
  524.      because the stack size may be a part of the offset computation for
  525.      register elimination.   */
  526.   assign_stack_local (BLKmode, 0, 0);
  527.  
  528.   /* If we have some registers we think can be eliminated, scan all insns to
  529.      see if there is an insn that sets one of these registers to something
  530.      other than itself plus a constant.  If so, the register cannot be
  531.      eliminated.  Doing this scan here eliminates an extra pass through the
  532.      main reload loop in the most common case where register elimination
  533.      cannot be done.  */
  534.   for (insn = first; insn && num_eliminable; insn = NEXT_INSN (insn))
  535.     if (GET_CODE (insn) == INSN || GET_CODE (insn) == JUMP_INSN
  536.     || GET_CODE (insn) == CALL_INSN)
  537.       note_stores (PATTERN (insn), mark_not_eliminable);
  538.  
  539. #ifndef REGISTER_CONSTRAINTS
  540.   /* If all the pseudo regs have hard regs,
  541.      except for those that are never referenced,
  542.      we know that no reloads are needed.  */
  543.   /* But that is not true if there are register constraints, since
  544.      in that case some pseudos might be in the wrong kind of hard reg.  */
  545.  
  546.   for (i = FIRST_PSEUDO_REGISTER; i < max_regno; i++)
  547.     if (reg_renumber[i] == -1 && reg_n_refs[i] != 0)
  548.       break;
  549.  
  550.   if (i == max_regno && num_eliminable = 0 && ! caller_save_needed)
  551.     return;
  552. #endif
  553.  
  554.   /* Compute the order of preference for hard registers to spill.
  555.      Store them by decreasing preference in potential_reload_regs.  */
  556.  
  557.   order_regs_for_reload ();
  558.  
  559.   /* So far, no hard regs have been spilled.  */
  560.   n_spills = 0;
  561.   for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
  562.     spill_reg_order[i] = -1;
  563.  
  564.   /* On most machines, we can't use any register explicitly used in the
  565.      rtl as a spill register.  But on some, we have to.  Those will have
  566.      taken care to keep the life of hard regs as short as possible.  */
  567.  
  568. #ifdef SMALL_REGISTER_CLASSES
  569.   CLEAR_HARD_REG_SET (forbidden_regs);
  570. #else
  571.   COPY_HARD_REG_SET (forbidden_regs, bad_spill_regs);
  572. #endif
  573.  
  574.   /* Spill any hard regs that we know we can't eliminate.  */
  575.   for (ep = reg_eliminate; ep < ®_eliminate[NUM_ELIMINABLE_REGS]; ep++)
  576.     if (! ep->can_eliminate)
  577.       {
  578.     spill_hard_reg (ep->from, global, dumpfile, 1);
  579.     regs_ever_live[ep->from] = 1;
  580.       }
  581.  
  582.   if (global)
  583.     for (i = 0; i < N_REG_CLASSES; i++)
  584.       {
  585.     basic_block_needs[i] = (char *)alloca (n_basic_blocks);
  586.     bzero (basic_block_needs[i], n_basic_blocks);
  587.       }
  588.  
  589.   /* This loop scans the entire function each go-round
  590.      and repeats until one repetition spills no additional hard regs.  */
  591.  
  592.   /* This flag is set when a psuedo reg is spilled,
  593.      to require another pass.  Note that getting an additional reload
  594.      reg does not necessarily imply any pseudo reg was spilled;
  595.      sometimes we find a reload reg that no pseudo reg was allocated in.  */
  596.   something_changed = 1;
  597.   /* This flag is set if there are any insns that require reloading.  */
  598.   something_needs_reloads = 0;
  599.   /* This flag is set if there are any insns that require register
  600.      eliminations.  */
  601.   something_needs_elimination = 0;
  602.   while (something_changed)
  603.     {
  604.       rtx after_call = 0;
  605.  
  606.       /* For each class, number of reload regs needed in that class.
  607.      This is the maximum over all insns of the needs in that class
  608.      of the individual insn.  */
  609.       int max_needs[N_REG_CLASSES];
  610.       /* For each class, size of group of consecutive regs
  611.      that is needed for the reloads of this class.  */
  612.       int group_size[N_REG_CLASSES];
  613.       /* For each class, max number of consecutive groups needed.
  614.      (Each group contains max_needs_size[CLASS] consecutive registers.)  */
  615.       int max_groups[N_REG_CLASSES];
  616.       /* For each class, max number needed of regs that don't belong
  617.      to any of the groups.  */
  618.       int max_nongroups[N_REG_CLASSES];
  619.       /* For each class, the machine mode which requires consecutive
  620.      groups of regs of that class.
  621.      If two different modes ever require groups of one class,
  622.      they must be the same size and equally restrictive for that class,
  623.      otherwise we can't handle the complexity.  */
  624.       enum machine_mode group_mode[N_REG_CLASSES];
  625.  
  626.       something_changed = 0;
  627.       bzero (max_needs, sizeof max_needs);
  628.       bzero (max_groups, sizeof max_groups);
  629.       bzero (max_nongroups, sizeof max_nongroups);
  630.       bzero (group_size, sizeof group_size);
  631.       for (i = 0; i < N_REG_CLASSES; i++)
  632.     group_mode[i] = VOIDmode;
  633.  
  634.       /* Keep track of which basic blocks are needing the reloads.  */
  635.       this_block = 0;
  636.  
  637.       /* Remember whether any element of basic_block_needs
  638.      changes from 0 to 1 in this pass.  */
  639.       new_basic_block_needs = 0;
  640.  
  641.       /* Reset all offsets on eliminable registers to their initial values.  */
  642. #ifdef ELIMINABLE_REGS
  643.       for (ep = reg_eliminate; ep < ®_eliminate[NUM_ELIMINABLE_REGS]; ep++)
  644.     {
  645.       INITIAL_ELIMINATION_OFFSET (ep->from, ep->to, ep->initial_offset);
  646.       ep->previous_offset = ep->offset = ep->initial_offset;
  647.     }
  648. #else
  649. #ifdef INITIAL_FRAME_POINTER_OFFSET
  650.       INITIAL_FRAME_POINTER_OFFSET (reg_eliminate[0].initial_offset);
  651. #else
  652.       if (!FRAME_POINTER_REQUIRED)
  653.     abort ();
  654.       reg_eliminate[0].initial_offset = 0;
  655. #endif
  656.       reg_eliminate[0].previous_offset
  657.     = reg_eliminate[0].offset = reg_eliminate[0].initial_offset;
  658. #endif
  659.  
  660.       num_not_at_initial_offset = 0;
  661.  
  662.       /* For each pseudo register that has an equivalent location defined,
  663.      try to eliminate any eliminable registers (such as the frame pointer)
  664.      assuming initial offsets for the replacement register, which
  665.      is the normal case.
  666.  
  667.      If the resulting location is directly addressable, substitute
  668.      the MEM we just got directly for the old REG.
  669.  
  670.      If it is not addressable but is a constant or the sum of a hard reg
  671.      and constant, it is probably not addressable because the constant is
  672.      out of range, in that case record the address; we will generate
  673.      hairy code to compute the address in a register each time it is
  674.      needed. 
  675.  
  676.      If the location is not addressable, but does not have one of the
  677.      above forms, assign a stack slot.  We have to do this to avoid the
  678.      potential of producing lots of reloads if, e.g., a location involves
  679.      a pseudo that didn't get a hard register and has an equivalent memory
  680.      location that also involves a pseudo that didn't get a hard register.
  681.  
  682.      Perhaps at some point we will improve reload_when_needed handling
  683.      so this problem goes away.  But that's very hairy.  */
  684.  
  685.       for (i = FIRST_PSEUDO_REGISTER; i < max_regno; i++)
  686.     if (reg_renumber[i] < 0 && reg_equiv_memory_loc[i])
  687.       {
  688.         rtx x = eliminate_regs (reg_equiv_memory_loc[i], 0, 0);
  689.  
  690.         if (strict_memory_address_p (GET_MODE (regno_reg_rtx[i]),
  691.                      XEXP (x, 0)))
  692.           reg_equiv_mem[i] = x, reg_equiv_address[i] = 0;
  693. #ifdef NeXT
  694.         else if (CONSTANT_P (XEXP (x, 0))
  695.              || (GET_CODE (XEXP (x, 0)) == PLUS
  696.              && GET_CODE (XEXP (XEXP (x, 0), 0)) == REG
  697.              && (REGNO (XEXP (XEXP (x, 0), 0))
  698.                  < FIRST_PSEUDO_REGISTER)
  699.              && CONSTANT_P (XEXP (XEXP (x, 0), 1))))
  700. #else /* NeXT */
  701.         else if (CONSTANT_P (x)
  702.              || (GET_CODE (x) == PLUS && GET_CODE (XEXP (x, 0)) == REG
  703.              && REGNO (XEXP (x, 0)) < FIRST_PSEUDO_REGISTER
  704.              && CONSTANT_P (XEXP (x, 1))))
  705. #endif /* NeXT */
  706.           reg_equiv_address[i] = XEXP (x, 0), reg_equiv_mem[i] = 0;
  707.         else
  708.           {
  709.         /* Make a new stack slot.  Then indicate that something
  710.            changed so we go back and recompute offsets for 
  711.            eliminable registers because the allocation of memory
  712.            below might change some offset.  reg_equiv_{mem,address}
  713.            will be set up for this pseudo on the next pass around
  714.            the loop.  */
  715.         reg_equiv_memory_loc[i] = 0;
  716.         reg_equiv_init[i] = 0;
  717.         alter_reg (i, -1);
  718.         something_changed = 1;
  719.           }
  720.       }
  721.     
  722.       /* If we allocated another psuedo to the stack, redo elimination
  723.      bookkeeping.  */
  724.       if (something_changed)
  725.     continue;
  726.  
  727.       /* Compute the most additional registers needed by any instruction.
  728.      Collect information separately for each class of regs.  */
  729.  
  730.       for (insn = first; insn; insn = NEXT_INSN (insn))
  731.     {
  732.       if (global && this_block + 1 < n_basic_blocks
  733.           && insn == basic_block_head[this_block+1])
  734.         ++this_block;
  735.  
  736.       if (GET_CODE (insn) == INSN || GET_CODE (insn) == JUMP_INSN
  737.           || GET_CODE (insn) == CALL_INSN)
  738.         {
  739.           /* Nonzero means don't use a reload reg that overlaps
  740.          the place where a function value can be returned.  */
  741.           rtx avoid_return_reg = 0;
  742.  
  743.           rtx old_body = PATTERN (insn);
  744.           int old_code = INSN_CODE (insn);
  745.            rtx old_notes = REG_NOTES (insn);
  746.           int did_elimination = 0;
  747.  
  748.           /* Initially, count RELOAD_OTHER reloads.
  749.          Later, merge in the other kinds.  */
  750.           int insn_needs[N_REG_CLASSES];
  751.           int insn_groups[N_REG_CLASSES];
  752.           int insn_total_groups = 0;
  753.  
  754.           /* Count RELOAD_FOR_INPUT_RELOAD_ADDRESS reloads.  */
  755.           int insn_needs_for_inputs[N_REG_CLASSES];
  756.           int insn_groups_for_inputs[N_REG_CLASSES];
  757.           int insn_total_groups_for_inputs = 0;
  758.  
  759.           /* Count RELOAD_FOR_OUTPUT_RELOAD_ADDRESS reloads.  */
  760.           int insn_needs_for_outputs[N_REG_CLASSES];
  761.           int insn_groups_for_outputs[N_REG_CLASSES];
  762.           int insn_total_groups_for_outputs = 0;
  763.  
  764.           /* Count RELOAD_FOR_OPERAND_ADDRESS reloads.  */
  765.           int insn_needs_for_operands[N_REG_CLASSES];
  766.           int insn_groups_for_operands[N_REG_CLASSES];
  767.           int insn_total_groups_for_operands = 0;
  768.  
  769.           for (i = 0; i < N_REG_CLASSES; i++)
  770.         {
  771.           insn_needs[i] = 0, insn_groups[i] = 0;
  772.           insn_needs_for_inputs[i] = 0, insn_groups_for_inputs[i] = 0;
  773.           insn_needs_for_outputs[i] = 0, insn_groups_for_outputs[i] = 0;
  774.           insn_needs_for_operands[i] = 0, insn_groups_for_operands[i] = 0;
  775.         }
  776.  
  777. #if 0  /* This wouldn't work nowadays, since optimize_bit_field
  778.       looks for non-strict memory addresses.  */
  779.           /* Optimization: a bit-field instruction whose field
  780.          happens to be a byte or halfword in memory
  781.          can be changed to a move instruction.  */
  782.  
  783.           if (GET_CODE (PATTERN (insn)) == SET)
  784.         {
  785.           rtx dest = SET_DEST (PATTERN (insn));
  786.           rtx src = SET_SRC (PATTERN (insn));
  787.  
  788.           if (GET_CODE (dest) == ZERO_EXTRACT
  789.               || GET_CODE (dest) == SIGN_EXTRACT)
  790.             optimize_bit_field (PATTERN (insn), insn, reg_equiv_mem);
  791.           if (GET_CODE (src) == ZERO_EXTRACT
  792.               || GET_CODE (src) == SIGN_EXTRACT)
  793.             optimize_bit_field (PATTERN (insn), insn, reg_equiv_mem);
  794.         }
  795. #endif
  796.  
  797.           /* If needed, eliminate any eliminable registers.  */
  798.           if (num_eliminable)
  799.         did_elimination = eliminate_regs_in_insn (insn, 0);
  800.  
  801. #ifdef SMALL_REGISTER_CLASSES
  802.           /* Set avoid_return_reg if this is an insn
  803.          that might use the value of a function call.  */
  804.           if (GET_CODE (insn) == CALL_INSN)
  805.         {
  806.           if (GET_CODE (PATTERN (insn)) == SET)
  807.             after_call = SET_DEST (PATTERN (insn));
  808.           else if (GET_CODE (PATTERN (insn)) == PARALLEL
  809.                && GET_CODE (XVECEXP (PATTERN (insn), 0, 0)) == SET)
  810.             after_call = SET_DEST (XVECEXP (PATTERN (insn), 0, 0));
  811.           else
  812.             after_call = 0;
  813.         }
  814.           else if (after_call != 0
  815.                && !(GET_CODE (PATTERN (insn)) == SET
  816.                 && SET_DEST (PATTERN (insn)) == stack_pointer_rtx))
  817.         {
  818.           if (reg_mentioned_p (after_call, PATTERN (insn)))
  819.             avoid_return_reg = after_call;
  820.           after_call = 0;
  821.         }
  822. #endif /* SMALL_REGISTER_CLASSES */
  823.  
  824.           /* Analyze the instruction.  */
  825.           find_reloads (insn, 0, spill_indirect_levels, global,
  826.                 spill_reg_order);
  827.  
  828.           /* Remember for later shortcuts which insns had any reloads or
  829.          register eliminations.
  830.  
  831.          One might think that it would be worthwhile to mark insns
  832.          that need register replacements but not reloads, but this is
  833.          not safe because find_reloads may do some manipulation of
  834.          the insn (such as swapping commutative operands), which would
  835.          be lost when we restore the old pattern after register
  836.          replacement.  So the actions of find_reloads must be redone in
  837.          subsequent passes or in reload_as_needed.
  838.  
  839.          However, it is safe to mark insns that need reloads
  840.          but not register replacement.  */
  841.  
  842.           PUT_MODE (insn, (did_elimination ? QImode
  843.                    : n_reloads ? HImode
  844.                    : VOIDmode));
  845.  
  846.           /* Discard any register replacements done.  */
  847.           if (did_elimination)
  848.         {
  849.           obstack_free (&reload_obstack, reload_firstobj);
  850.           PATTERN (insn) = old_body;
  851.           INSN_CODE (insn) = old_code;
  852.            REG_NOTES (insn) = old_notes;
  853.           something_needs_elimination = 1;
  854.         }
  855.  
  856.           if (n_reloads == 0)
  857.         continue;
  858.  
  859.           something_needs_reloads = 1;
  860.  
  861.           /* Count each reload once in every class
  862.          containing the reload's own class.  */
  863.  
  864.           for (i = 0; i < n_reloads; i++)
  865.         {
  866.           register enum reg_class *p;
  867.           int size;
  868.           enum machine_mode mode;
  869.           int *this_groups;
  870.           int *this_needs;
  871.           int *this_total_groups;
  872.  
  873.           /* Don't count the dummy reloads, for which one of the
  874.              regs mentioned in the insn can be used for reloading.
  875.              Don't count optional reloads.
  876.              Don't count reloads that got combined with others.  */
  877.           if (reload_reg_rtx[i] != 0
  878.               || reload_optional[i] != 0
  879.               || (reload_out[i] == 0 && reload_in[i] == 0
  880.               && ! reload_secondary_p[i]))
  881.               continue;
  882.  
  883.           /* Decide which time-of-use to count this reload for.  */
  884.           switch (reload_when_needed[i])
  885.             {
  886.             case RELOAD_OTHER:
  887.             case RELOAD_FOR_OUTPUT:
  888.             case RELOAD_FOR_INPUT:
  889.               this_needs = insn_needs;
  890.               this_groups = insn_groups;
  891.               this_total_groups = &insn_total_groups;
  892.               break;
  893.  
  894.             case RELOAD_FOR_INPUT_RELOAD_ADDRESS:
  895.               this_needs = insn_needs_for_inputs;
  896.               this_groups = insn_groups_for_inputs;
  897.               this_total_groups = &insn_total_groups_for_inputs;
  898.               break;
  899.  
  900.             case RELOAD_FOR_OUTPUT_RELOAD_ADDRESS:
  901.               this_needs = insn_needs_for_outputs;
  902.               this_groups = insn_groups_for_outputs;
  903.               this_total_groups = &insn_total_groups_for_outputs;
  904.               break;
  905.  
  906.             case RELOAD_FOR_OPERAND_ADDRESS:
  907.               this_needs = insn_needs_for_operands;
  908.               this_groups = insn_groups_for_operands;
  909.               this_total_groups = &insn_total_groups_for_operands;
  910.               break;
  911.             }
  912.  
  913.           mode = reload_inmode[i];
  914.           if (GET_MODE_SIZE (reload_outmode[i]) > GET_MODE_SIZE (mode))
  915.             mode = reload_outmode[i];
  916.           size = CLASS_MAX_NREGS (reload_reg_class[i], mode);
  917.           if (size > 1)
  918.             {
  919.               enum machine_mode other_mode, allocate_mode;
  920.  
  921.               /* Count number of groups needed separately from
  922.              number of individual regs needed.  */
  923.               this_groups[(int) reload_reg_class[i]]++;
  924.               p = reg_class_superclasses[(int) reload_reg_class[i]];
  925.               while (*p != LIM_REG_CLASSES)
  926.             this_groups[(int) *p++]++;
  927.               (*this_total_groups)++;
  928.  
  929.               /* Record size and mode of a group of this class.  */
  930.               /* If more than one size group is needed,
  931.              make all groups the largest needed size.  */
  932.               if (group_size[(int) reload_reg_class[i]] < size)
  933.             {
  934.               other_mode = group_mode[(int) reload_reg_class[i]];
  935.               allocate_mode = mode;
  936.  
  937.               group_size[(int) reload_reg_class[i]] = size;
  938.               group_mode[(int) reload_reg_class[i]] = mode;
  939.             }
  940.               else
  941.             {
  942.               other_mode = mode;
  943.               allocate_mode = group_mode[(int) reload_reg_class[i]];
  944.             }
  945.  
  946.               /* Crash if two dissimilar machine modes both need
  947.              groups of consecutive regs of the same class.  */
  948.  
  949.               if (other_mode != VOIDmode
  950.               && other_mode != allocate_mode
  951.               && ! modes_equiv_for_class_p (allocate_mode,
  952.                             other_mode,
  953.                             reload_reg_class[i]))
  954.             abort ();
  955.             }
  956.           else if (size == 1)
  957.             {
  958.               this_needs[(int) reload_reg_class[i]] += 1;
  959.               p = reg_class_superclasses[(int) reload_reg_class[i]];
  960.               while (*p != LIM_REG_CLASSES)
  961.             this_needs[(int) *p++] += 1;
  962.             }
  963.           else
  964.             abort ();
  965.         }
  966.  
  967.           /* All reloads have been counted for this insn;
  968.          now merge the various times of use.
  969.          This sets insn_needs, etc., to the maximum total number
  970.          of registers needed at any point in this insn.  */
  971.  
  972.           for (i = 0; i < N_REG_CLASSES; i++)
  973.         {
  974.           int this_max;
  975.           this_max = insn_needs_for_inputs[i];
  976.           if (insn_needs_for_outputs[i] > this_max)
  977.             this_max = insn_needs_for_outputs[i];
  978.           if (insn_needs_for_operands[i] > this_max)
  979.             this_max = insn_needs_for_operands[i];
  980.           insn_needs[i] += this_max;
  981.           this_max = insn_groups_for_inputs[i];
  982.           if (insn_groups_for_outputs[i] > this_max)
  983.             this_max = insn_groups_for_outputs[i];
  984.           if (insn_groups_for_operands[i] > this_max)
  985.             this_max = insn_groups_for_operands[i];
  986.           insn_groups[i] += this_max;
  987.  
  988.           if (global && (insn_needs[i] || insn_groups[i])
  989.               && ! basic_block_needs[i][this_block])
  990.             {
  991.               new_basic_block_needs = 1;
  992.               basic_block_needs[i][this_block] = 1;
  993.             }
  994.         }
  995.           insn_total_groups += max (insn_total_groups_for_inputs,
  996.                     max (insn_total_groups_for_outputs,
  997.                          insn_total_groups_for_operands));
  998.  
  999. #ifdef SMALL_REGISTER_CLASSES
  1000.           /* If this insn stores the value of a function call,
  1001.          and that value is in a register that has been spilled,
  1002.          and if the insn needs a reload in a class
  1003.          that might use that register as the reload register,
  1004.          then add add an extra need in that class.
  1005.          This makes sure we have a register available that does
  1006.          not overlap the return value.  */
  1007.           if (avoid_return_reg)
  1008.         {
  1009.           int regno = REGNO (avoid_return_reg);
  1010.           int nregs
  1011.             = HARD_REGNO_NREGS (regno, GET_MODE (avoid_return_reg));
  1012.           int r;
  1013.           int inc_groups = 0;
  1014.           for (r = regno; r < regno + nregs; r++)
  1015.             if (spill_reg_order[r] >= 0)
  1016.               for (i = 0; i < N_REG_CLASSES; i++)
  1017.             if (TEST_HARD_REG_BIT (reg_class_contents[i], r))
  1018.               {
  1019.                 if (insn_needs[i] > 0)
  1020.                   insn_needs[i]++;
  1021.                 if (insn_groups[i] > 0
  1022.                 && nregs > 1)
  1023.                   inc_groups = 1;
  1024.               }
  1025.           if (inc_groups)
  1026.             insn_groups[i]++;
  1027.         }
  1028. #endif /* SMALL_REGISTER_CLASSES */
  1029.  
  1030.           /* For each class, collect maximum need of any insn.  */
  1031.  
  1032.           for (i = 0; i < N_REG_CLASSES; i++)
  1033.         {
  1034.           if (max_needs[i] < insn_needs[i])
  1035.             max_needs[i] = insn_needs[i];
  1036.           if (max_groups[i] < insn_groups[i])
  1037.             max_groups[i] = insn_groups[i];
  1038.           if (insn_total_groups > 0)
  1039.             if (max_nongroups[i] < insn_needs[i])
  1040.               max_nongroups[i] = insn_needs[i];
  1041.         }
  1042.         }
  1043.       /* Note that there is a continue statement above.  */
  1044.     }
  1045.  
  1046.       /* Now deduct from the needs for the registers already
  1047.      available (already spilled).  */
  1048.  
  1049.       CLEAR_HARD_REG_SET (counted_for_groups);
  1050.       CLEAR_HARD_REG_SET (counted_for_nongroups);
  1051.  
  1052.       /* First find all regs alone in their class
  1053.      and count them (if desired) for non-groups.
  1054.      We would be screwed if a group took the only reg in a class
  1055.      for which a non-group reload ius needed.
  1056.      (Note there is still a bug; if a class has 2 regs,
  1057.      both could be stolen by groups and we would lose the same way.
  1058.      With luck, no machine will need a nongroup in a 2-reg class.)  */
  1059.  
  1060.       for (i = 0; i < n_spills; i++)
  1061.     {
  1062.       register enum reg_class *p;
  1063.       class = (int) REGNO_REG_CLASS (spill_regs[i]);
  1064.  
  1065.       if (reg_class_size[class] == 1 && max_nongroups[class] > 0)
  1066.         {
  1067.           max_needs[class]--;
  1068.           p = reg_class_superclasses[class];
  1069.           while (*p != LIM_REG_CLASSES)
  1070.         max_needs[(int) *p++]--;
  1071.  
  1072.           SET_HARD_REG_BIT (counted_for_nongroups, spill_regs[i]);
  1073.           max_nongroups[class]--;
  1074.           p = reg_class_superclasses[class];
  1075.           while (*p != LIM_REG_CLASSES)
  1076.         {
  1077.           if (max_nongroups[(int) *p] > 0)
  1078.             SET_HARD_REG_BIT (counted_for_nongroups, spill_regs[i]);
  1079.           max_nongroups[(int) *p++]--;
  1080.         }
  1081.         }
  1082.     }
  1083.  
  1084.       /* Now find all consecutive groups of spilled registers
  1085.      and mark each group off against the need for such groups.
  1086.      But don't count them against ordinary need, yet.  */
  1087.  
  1088.       count_possible_groups (group_size, group_mode, max_groups);
  1089.  
  1090.       /* Now count all spill regs against the individual need,
  1091.      This includes those counted above for groups, 
  1092.      but not those previously counted for nongroups.
  1093.  
  1094.      Those that weren't counted_for_groups can also count against
  1095.      the not-in-group need.  */
  1096.  
  1097.       for (i = 0; i < n_spills; i++)
  1098.     {
  1099.       register enum reg_class *p;
  1100.       class = (int) REGNO_REG_CLASS (spill_regs[i]);
  1101.  
  1102.       /* Those counted at the beginning shouldn't be counted twice.  */
  1103.       if (! TEST_HARD_REG_BIT (counted_for_nongroups, spill_regs[i]))
  1104.         {
  1105.           max_needs[class]--;
  1106.           p = reg_class_superclasses[class];
  1107.           while (*p != LIM_REG_CLASSES)
  1108.         max_needs[(int) *p++]--;
  1109.  
  1110.           if (! TEST_HARD_REG_BIT (counted_for_groups, spill_regs[i]))
  1111.         {
  1112.           if (max_nongroups[class] > 0)
  1113.             SET_HARD_REG_BIT (counted_for_nongroups, spill_regs[i]);
  1114.           max_nongroups[class]--;
  1115.           p = reg_class_superclasses[class];
  1116.           while (*p != LIM_REG_CLASSES)
  1117.             {
  1118.               if (max_nongroups[(int) *p] > 0)
  1119.             SET_HARD_REG_BIT (counted_for_nongroups,
  1120.                       spill_regs[i]);
  1121.               max_nongroups[(int) *p++]--;
  1122.             }
  1123.         }
  1124.         }
  1125.     }
  1126.  
  1127.       /* Look for the case where we have discovered that we can't replace
  1128.      register A with register B and that means that we will now be
  1129.      trying to replace register A with register C.  This means we can
  1130.      no longer replace register C with register B and we need to disable
  1131.      such an elimination, if it exists.  This occurs often with A == ap,
  1132.      B == sp, and C == fp.  */
  1133.      
  1134.       for (ep = reg_eliminate; ep < ®_eliminate[NUM_ELIMINABLE_REGS]; ep++)
  1135.     {
  1136.       struct elim_table *op;
  1137.       register int new_to = -1;
  1138.  
  1139.       if (! ep->can_eliminate && ep->can_eliminate_previous)
  1140.         {
  1141.           /* Find the current elimination for ep->from, if there is a
  1142.          new one.  */
  1143.           for (op = reg_eliminate;
  1144.            op < ®_eliminate[NUM_ELIMINABLE_REGS]; op++)
  1145.         if (op->from == ep->from && op->can_eliminate)
  1146.           {
  1147.             new_to = op->to;
  1148.             break;
  1149.           }
  1150.  
  1151.           /* See if there is an elimination of NEW_TO -> EP->TO.  If so,
  1152.          disable it.  */
  1153.           for (op = reg_eliminate;
  1154.            op < ®_eliminate[NUM_ELIMINABLE_REGS]; op++)
  1155.         if (op->from == new_to && op->to == ep->to)
  1156.           op->can_eliminate = 0;
  1157.         }
  1158.     }
  1159.  
  1160.       /* See if any registers that we thought we could eliminate the previous
  1161.      time are no longer eliminable.  If so, something has changed and we
  1162.      must spill the register.  Also, recompute the number of eliminable
  1163.      registers and see if the frame pointer is needed; it is if there is
  1164.      no elimination of the frame pointer that we can perform.  */
  1165.  
  1166.       frame_pointer_needed = 1;
  1167.       for (ep = reg_eliminate; ep < ®_eliminate[NUM_ELIMINABLE_REGS]; ep++)
  1168.     {
  1169.       if (ep->can_eliminate && ep->from == FRAME_POINTER_REGNUM)
  1170.         frame_pointer_needed = 0;
  1171.  
  1172.       if (! ep->can_eliminate && ep->can_eliminate_previous)
  1173.         {
  1174.           ep->can_eliminate_previous = 0;
  1175.           spill_hard_reg (ep->from, global, dumpfile, 1);
  1176.           regs_ever_live[ep->from] = 1;
  1177.           something_changed = 1;
  1178.           num_eliminable--;
  1179.         }
  1180.     }
  1181.  
  1182.       /* If all needs are met, we win.  */
  1183.  
  1184.       for (i = 0; i < N_REG_CLASSES; i++)
  1185.     if (max_needs[i] > 0 || max_groups[i] > 0 || max_nongroups[i] > 0)
  1186.       break;
  1187.       if (i == N_REG_CLASSES && !new_basic_block_needs && ! something_changed)
  1188.     break;
  1189.  
  1190.       /* Not all needs are met; must spill more hard regs.  */
  1191.  
  1192.       /* If any element of basic_block_needs changed from 0 to 1,
  1193.      re-spill all the regs already spilled.  This may spill
  1194.      additional pseudos that didn't spill before.  */
  1195.  
  1196.       if (new_basic_block_needs)
  1197.     for (i = 0; i < n_spills; i++)
  1198.       something_changed
  1199.         |= spill_hard_reg (spill_regs[i], global, dumpfile, 0);
  1200.  
  1201.       /* Now find more reload regs to satisfy the remaining need
  1202.      Do it by ascending class number, since otherwise a reg
  1203.      might be spilled for a big class and might fail to count
  1204.      for a smaller class even though it belongs to that class.
  1205.  
  1206.      Count spilled regs in `spills', and add entries to
  1207.      `spill_regs' and `spill_reg_order'.
  1208.  
  1209.      ??? Note there is a problem here.
  1210.      When there is a need for a group in a high-numbered class,
  1211.      and also need for non-group regs that come from a lower class,
  1212.      the non-group regs are chosen first.  If there aren't many regs,
  1213.      they might leave no room for a group.
  1214.      This was happening on the 386.  Luckily, the problem was avoided
  1215.      by making those insns need fewer non-group regs.
  1216.  
  1217.      Really fixing the problem would require changes above
  1218.      in counting the regs already spilled, and in choose_reload_regs.
  1219.      It might be hard to avoid introducing bugs there.  */
  1220.  
  1221.       for (class = 0; class < N_REG_CLASSES; class++)
  1222.     {
  1223.       /* First get the groups of registers.
  1224.          If we got single registers first, we might fragment
  1225.          possible groups.  */
  1226.       while (max_groups[class] > 0)
  1227.         {
  1228.           /* If any single spilled regs happen to form groups,
  1229.          count them now.  Maybe we don't really need
  1230.          to spill another group.  */
  1231.           count_possible_groups (group_size, group_mode, max_groups);
  1232.  
  1233.           /* Groups of size 2 (the only groups used on most machines)
  1234.          are treated specially.  */
  1235.           if (group_size[class] == 2)
  1236.         {
  1237.           /* First, look for a register that will complete a group.  */
  1238.           for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
  1239.             {
  1240.               int j = potential_reload_regs[i];
  1241.               int other;
  1242.               if (j >= 0 && ! TEST_HARD_REG_BIT (bad_spill_regs, j)
  1243.               &&
  1244.               ((j > 0 && (other = j - 1, spill_reg_order[other] >= 0)
  1245.                 && TEST_HARD_REG_BIT (reg_class_contents[class], j)
  1246.                 && TEST_HARD_REG_BIT (reg_class_contents[class], other)
  1247.                 && HARD_REGNO_MODE_OK (other, group_mode[class])
  1248.                 && ! TEST_HARD_REG_BIT (counted_for_nongroups,
  1249.                             other)
  1250.                 /* We don't want one part of another group.
  1251.                    We could get "two groups" that overlap!  */
  1252.                 && ! TEST_HARD_REG_BIT (counted_for_groups, other))
  1253.                ||
  1254.                (j < FIRST_PSEUDO_REGISTER - 1
  1255.                 && (other = j + 1, spill_reg_order[other] >= 0)
  1256.                 && TEST_HARD_REG_BIT (reg_class_contents[class], j)
  1257.                 && TEST_HARD_REG_BIT (reg_class_contents[class], other)
  1258.                 && HARD_REGNO_MODE_OK (j, group_mode[class])
  1259.                 && ! TEST_HARD_REG_BIT (counted_for_nongroups,
  1260.                             other)
  1261.                 && ! TEST_HARD_REG_BIT (counted_for_groups,
  1262.                             other))))
  1263.             {
  1264.               register enum reg_class *p;
  1265.  
  1266.               /* We have found one that will complete a group,
  1267.                  so count off one group as provided.  */
  1268.               max_groups[class]--;
  1269.               p = reg_class_superclasses[class];
  1270.               while (*p != LIM_REG_CLASSES)
  1271.                 max_groups[(int) *p++]--;
  1272.  
  1273.               /* Indicate both these regs are part of a group.  */
  1274.               SET_HARD_REG_BIT (counted_for_groups, j);
  1275.               SET_HARD_REG_BIT (counted_for_groups, other);
  1276.               break;
  1277.             }
  1278.             }
  1279.           /* We can't complete a group, so start one.  */
  1280.           if (i == FIRST_PSEUDO_REGISTER)
  1281.             for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
  1282.               {
  1283.             int j = potential_reload_regs[i];
  1284.             if (j >= 0 && j + 1 < FIRST_PSEUDO_REGISTER
  1285.                 && spill_reg_order[j] < 0 && spill_reg_order[j + 1] < 0
  1286.                 && TEST_HARD_REG_BIT (reg_class_contents[class], j)
  1287.                 && TEST_HARD_REG_BIT (reg_class_contents[class], j + 1)
  1288.                 && HARD_REGNO_MODE_OK (j, group_mode[class])
  1289.                 && ! TEST_HARD_REG_BIT (counted_for_nongroups,
  1290.                             j + 1))
  1291.               break;
  1292.               }
  1293.  
  1294.           /* I should be the index in potential_reload_regs
  1295.              of the new reload reg we have found.  */
  1296.  
  1297.           something_changed
  1298.             |= new_spill_reg (i, class, max_needs, 0,
  1299.                       global, dumpfile);
  1300.         }
  1301.           else
  1302.         {
  1303.           /* For groups of more than 2 registers,
  1304.              look for a sufficient sequence of unspilled registers,
  1305.              and spill them all at once.  */
  1306.           for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
  1307.             {
  1308.               int j = potential_reload_regs[i];
  1309.               int k;
  1310.               if (j >= 0 && j + 1 < FIRST_PSEUDO_REGISTER
  1311.               && HARD_REGNO_MODE_OK (j, group_mode[class]))
  1312.             {
  1313.               /* Check each reg in the sequence.  */
  1314.               for (k = 0; k < group_size[class]; k++)
  1315.                 if (! (spill_reg_order[j + k] < 0
  1316.                    && ! TEST_HARD_REG_BIT (bad_spill_regs, j + k)
  1317.                    && TEST_HARD_REG_BIT (reg_class_contents[class], j + k)))
  1318.                   break;
  1319.               /* We got a full sequence, so spill them all.  */
  1320.               if (k == group_size[class])
  1321.                 {
  1322.                   register enum reg_class *p;
  1323.                   for (k = 0; k < group_size[class]; k++)
  1324.                 {
  1325.                   int idx;
  1326.                   SET_HARD_REG_BIT (counted_for_groups, j + k);
  1327.                   for (idx = 0; idx < FIRST_PSEUDO_REGISTER; idx++)
  1328.                     if (potential_reload_regs[idx] == j + k)
  1329.                       break;
  1330.                   something_changed
  1331.                     |= new_spill_reg (idx, class, max_needs, 0,
  1332.                               global, dumpfile);
  1333.                 }
  1334.  
  1335.                   /* We have found one that will complete a group,
  1336.                  so count off one group as provided.  */
  1337.                   max_groups[class]--;
  1338.                   p = reg_class_superclasses[class];
  1339.                   while (*p != LIM_REG_CLASSES)
  1340.                 max_groups[(int) *p++]--;
  1341.  
  1342.                   break;
  1343.                 }
  1344.             }
  1345.             }
  1346.         }
  1347.         }
  1348.  
  1349.       /* Now similarly satisfy all need for single registers.  */
  1350.  
  1351.       while (max_needs[class] > 0 || max_nongroups[class] > 0)
  1352.         {
  1353.           /* Consider the potential reload regs that aren't
  1354.          yet in use as reload regs, in order of preference.
  1355.          Find the most preferred one that's in this class.  */
  1356.  
  1357.           for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
  1358.         if (potential_reload_regs[i] >= 0
  1359.             && TEST_HARD_REG_BIT (reg_class_contents[class],
  1360.                       potential_reload_regs[i])
  1361.             /* If this reg will not be available for groups,
  1362.                pick one that does not foreclose possible groups.
  1363.                This is a kludge, and not very general,
  1364.                but it should be sufficient to make the 386 work,
  1365.                and the problem should not occur on machines with
  1366.                more registers.  */
  1367.             && (max_nongroups[class] == 0
  1368.             || possible_group_p (potential_reload_regs[i], max_groups)))
  1369.           break;
  1370.  
  1371.           /* I should be the index in potential_reload_regs
  1372.          of the new reload reg we have found.  */
  1373.  
  1374.           something_changed
  1375.         |= new_spill_reg (i, class, max_needs, max_nongroups,
  1376.                   global, dumpfile);
  1377.         }
  1378.     }
  1379.     }
  1380.  
  1381.   /* Insert code to save and restore call-clobbered hard regs
  1382.      around calls.  */
  1383.  
  1384.   if (caller_save_needed)
  1385.     save_call_clobbered_regs ();
  1386.  
  1387.   /* Use the reload registers where necessary
  1388.      by generating move instructions to move the must-be-register
  1389.      values into or out of the reload registers.  */
  1390.  
  1391.   if (something_needs_reloads || something_needs_elimination)
  1392.     reload_as_needed (first, global);
  1393.  
  1394.   /* Now eliminate all pseudo regs by modifying them into
  1395.      their equivalent memory references.
  1396.      The REG-rtx's for the pseudos are modified in place,
  1397.      so all insns that used to refer to them now refer to memory.
  1398.  
  1399.      For a reg that has a reg_equiv_address, all those insns
  1400.      were changed by reloading so that no insns refer to it any longer;
  1401.      but the DECL_RTL of a variable decl may refer to it,
  1402.      and if so this causes the debugging info to mention the variable.  */
  1403.  
  1404.   for (i = FIRST_PSEUDO_REGISTER; i < max_regno; i++)
  1405.     {
  1406.       rtx addr = 0;
  1407.       if (reg_equiv_mem[i])
  1408.     addr = XEXP (reg_equiv_mem[i], 0);
  1409.       if (reg_equiv_address[i])
  1410.     addr = reg_equiv_address[i];
  1411.       if (addr)
  1412.     {
  1413.       if (reg_renumber[i] < 0)
  1414.         {
  1415.           rtx reg = regno_reg_rtx[i];
  1416.           XEXP (reg, 0) = addr;
  1417.           REG_USERVAR_P (reg) = 0;
  1418.           PUT_CODE (reg, MEM);
  1419.         }
  1420.       else if (reg_equiv_mem[i])
  1421.         XEXP (reg_equiv_mem[i], 0) = addr;
  1422.     }
  1423.     }
  1424.  
  1425. #ifdef PRESERVE_DEATH_INFO_REGNO_P
  1426.   /* Make a pass over all the insns and remove death notes for things that
  1427.      are no longer registers or no longer die in the insn (e.g., an input
  1428.      and output pseudo being tied).  */
  1429.  
  1430.   for (insn = first; insn; insn = NEXT_INSN (insn))
  1431.     if (GET_RTX_CLASS (GET_CODE (insn)) == 'i')
  1432.       {
  1433.     rtx note, next;
  1434.  
  1435.     for (note = REG_NOTES (insn); note; note = next)
  1436.       {
  1437.         next = XEXP (note, 1);
  1438.         if (REG_NOTE_KIND (note) == REG_DEAD
  1439.         && (GET_CODE (XEXP (note, 0)) != REG
  1440.             || reg_set_p (XEXP (note, 0), PATTERN (insn))))
  1441.           remove_note (insn, note);
  1442.       }
  1443.       }
  1444. #endif
  1445.  
  1446.   /* Indicate that we no longer have known memory locations or constants.  */
  1447.   reg_equiv_constant = 0;
  1448.   reg_equiv_memory_loc = 0;
  1449. }
  1450.  
  1451. /* Nonzero if, after spilling reg REGNO for non-groups,
  1452.    it will still be possible to find a group if we still need one.  */
  1453.  
  1454. static int
  1455. possible_group_p (regno, max_groups)
  1456.      int regno;
  1457.      int *max_groups;
  1458. {
  1459.   int i;
  1460.   int group = 0;
  1461.  
  1462.   for (i = 0; i < (int) N_REG_CLASSES; i++)
  1463.     group |= max_groups[i];
  1464.  
  1465.   if (group == 0)
  1466.     return 1;
  1467.  
  1468.   /* Consider each pair of consecutive registers.  */
  1469.   for (i = 0; i < FIRST_PSEUDO_REGISTER - 1; i++)
  1470.     {
  1471.       if (i == regno || i + 1 == regno)
  1472.     continue;
  1473.  
  1474.       /* A pair of consecutive regs we can still spill does the trick.  */
  1475.       if (spill_reg_order[i] < 0 && spill_reg_order[i + 1] < 0
  1476.       && TEST_HARD_REG_BIT (bad_spill_regs, i)
  1477.       && TEST_HARD_REG_BIT (bad_spill_regs, i + 1))
  1478.     return 1;
  1479.  
  1480.       /* A pair of one already spilled and one we can spill does it
  1481.      provided the one already spilled is not otherwise reserved.  */
  1482.       if (spill_reg_order[i] < 0
  1483.       && TEST_HARD_REG_BIT (bad_spill_regs, i)
  1484.       && spill_reg_order[i + 1] >= 0
  1485.       && ! TEST_HARD_REG_BIT (counted_for_groups, i + 1)
  1486.       && ! TEST_HARD_REG_BIT (counted_for_nongroups, i + 1))
  1487.     return 1;
  1488.       if (spill_reg_order[i + 1] < 0
  1489.       && TEST_HARD_REG_BIT (bad_spill_regs, i + 1)
  1490.       && spill_reg_order[i] >= 0
  1491.       && ! TEST_HARD_REG_BIT (counted_for_groups, i)
  1492.       && ! TEST_HARD_REG_BIT (counted_for_nongroups, i))
  1493.     return 1;
  1494.     }
  1495.  
  1496.   return 0;
  1497. }
  1498.  
  1499. /* Count any groups that can be formed from the registers recently spilled.
  1500.    This is done class by class, in order of ascending class number.  */
  1501.  
  1502. static void
  1503. count_possible_groups (group_size, group_mode, max_groups)
  1504.      int *group_size, *max_groups;
  1505.      enum machine_mode *group_mode;
  1506. {
  1507.   int i;
  1508.   /* Now find all consecutive groups of spilled registers
  1509.      and mark each group off against the need for such groups.
  1510.      But don't count them against ordinary need, yet.  */
  1511.  
  1512.   for (i = 0; i < N_REG_CLASSES; i++)
  1513.     if (group_size[i] > 1)
  1514.       {
  1515.     char regmask[FIRST_PSEUDO_REGISTER];
  1516.     int j;
  1517.  
  1518.     bzero (regmask, sizeof regmask);
  1519.     /* Make a mask of all the regs that are spill regs in class I.  */
  1520.     for (j = 0; j < n_spills; j++)
  1521.       if (TEST_HARD_REG_BIT (reg_class_contents[i], spill_regs[j])
  1522.           && ! TEST_HARD_REG_BIT (counted_for_groups, spill_regs[j])
  1523.           && ! TEST_HARD_REG_BIT (counted_for_nongroups,
  1524.                       spill_regs[j]))
  1525.         regmask[spill_regs[j]] = 1;
  1526.     /* Find each consecutive group of them.  */
  1527.     for (j = 0; j < FIRST_PSEUDO_REGISTER && max_groups[i] > 0; j++)
  1528.       if (regmask[j] && j + group_size[i] <= FIRST_PSEUDO_REGISTER
  1529.           /* Next line in case group-mode for this class
  1530.          demands an even-odd pair.  */
  1531.           && HARD_REGNO_MODE_OK (j, group_mode[i]))
  1532.         {
  1533.           int k;
  1534.           for (k = 1; k < group_size[i]; k++)
  1535.         if (! regmask[j + k])
  1536.           break;
  1537.           if (k == group_size[i])
  1538.         {
  1539.           /* We found a group.  Mark it off against this class's
  1540.              need for groups, and against each superclass too.  */
  1541.           register enum reg_class *p;
  1542.           max_groups[i]--;
  1543.           p = reg_class_superclasses[i];
  1544.           while (*p != LIM_REG_CLASSES)
  1545.             max_groups[(int) *p++]--;
  1546.           /* Don't count these registers again.  */ 
  1547.           for (k = 0; k < group_size[i]; k++)
  1548.             SET_HARD_REG_BIT (counted_for_groups, j + k);
  1549.         }
  1550.           j += k;
  1551.         }
  1552.       }
  1553.  
  1554. }
  1555.  
  1556. /* ALLOCATE_MODE is a register mode that needs to be reloaded.  OTHER_MODE is
  1557.    another mode that needs to be reloaded for the same register class CLASS.
  1558.    If any reg in CLASS allows ALLOCATE_MODE but not OTHER_MODE, fail.
  1559.    ALLOCATE_MODE will never be smaller than OTHER_MODE.
  1560.  
  1561.    This code used to also fail if any reg in CLASS allows OTHER_MODE but not
  1562.    ALLOCATE_MODE.  This test is unnecessary, because we will never try to put
  1563.    something of mode ALLOCATE_MODE into an OTHER_MODE register.  Testing this
  1564.    causes unnecessary failures on machines requiring alignment of register
  1565.    groups when the two modes are different sizes, because the larger mode has
  1566.    more strict alignment rules than the smaller mode.  */
  1567.  
  1568. static int
  1569. modes_equiv_for_class_p (allocate_mode, other_mode, class)
  1570.      enum machine_mode allocate_mode, other_mode;
  1571.      enum reg_class class;
  1572. {
  1573.   register int regno;
  1574.   for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
  1575.     {
  1576.       if (TEST_HARD_REG_BIT (reg_class_contents[(int) class], regno)
  1577.       && HARD_REGNO_MODE_OK (regno, allocate_mode)
  1578.       && ! HARD_REGNO_MODE_OK (regno, other_mode))
  1579.     return 0;
  1580.     }
  1581.   return 1;
  1582. }
  1583.  
  1584. /* Add a new register to the tables of available spill-registers
  1585.     (as well as spilling all pseudos allocated to the register).
  1586.    I is the index of this register in potential_reload_regs.
  1587.    CLASS is the regclass whose need is being satisfied.
  1588.    MAX_NEEDS and MAX_NONGROUPS are the vectors of needs,
  1589.     so that this register can count off against them.
  1590.     MAX_NONGROUPS is 0 if this register is part of a group.
  1591.    GLOBAL and DUMPFILE are the same as the args that `reload' got.  */
  1592.  
  1593. static int
  1594. new_spill_reg (i, class, max_needs, max_nongroups, global, dumpfile)
  1595.      int i;
  1596.      int class;
  1597.      int *max_needs;
  1598.      int *max_nongroups;
  1599.      int global;
  1600.      FILE *dumpfile;
  1601. {
  1602.   register enum reg_class *p;
  1603.   int val;
  1604.   int regno = potential_reload_regs[i];
  1605.  
  1606.   if (i >= FIRST_PSEUDO_REGISTER)
  1607.     abort ();    /* Caller failed to find any register.  */
  1608.  
  1609.   if (fixed_regs[regno] || TEST_HARD_REG_BIT (forbidden_regs, regno))
  1610.     fatal ("fixed or forbidden register was spilled.\n\
  1611. This may be due to a compiler bug or to impossible asm statements.");
  1612.  
  1613.   /* Make reg REGNO an additional reload reg.  */
  1614.  
  1615.   potential_reload_regs[i] = -1;
  1616.   spill_regs[n_spills] = regno;
  1617.   spill_reg_order[regno] = n_spills;
  1618.   if (dumpfile)
  1619.     fprintf (dumpfile, "Spilling reg %d.\n", spill_regs[n_spills]);
  1620.  
  1621.   /* Clear off the needs we just satisfied.  */
  1622.  
  1623.   max_needs[class]--;
  1624.   p = reg_class_superclasses[class];
  1625.   while (*p != LIM_REG_CLASSES)
  1626.     max_needs[(int) *p++]--;
  1627.  
  1628.   if (max_nongroups && max_nongroups[class] > 0)
  1629.     {
  1630.       SET_HARD_REG_BIT (counted_for_nongroups, regno);
  1631.       max_nongroups[class]--;
  1632.       p = reg_class_superclasses[class];
  1633.       while (*p != LIM_REG_CLASSES)
  1634.     max_nongroups[(int) *p++]--;
  1635.     }
  1636.  
  1637.   /* Spill every pseudo reg that was allocated to this reg
  1638.      or to something that overlaps this reg.  */
  1639.  
  1640.   val = spill_hard_reg (spill_regs[n_spills], global, dumpfile, 0);
  1641.  
  1642.   /* If there are some registers still to eliminate and this register
  1643.      wasn't ever used before, additional stack space may have to be
  1644.      allocated to store this register.  Thus, we may have changed the offset
  1645.      between the stack and frame pointers, so mark that something has changed.
  1646.      (If new pseudos were spilled, thus requiring more space, VAL would have
  1647.      been set non-zero by the call to spill_hard_reg above since additional
  1648.      reloads may be needed in that case.
  1649.  
  1650.      One might think that we need only set VAL to 1 if this is a call-used
  1651.      register.  However, the set of registers that must be saved by the
  1652.      prologue is not identical to the call-used set.  For example, the
  1653.      register used by the call insn for the return PC is a call-used register,
  1654.      but must be saved by the prologue.  */
  1655.   if (num_eliminable && ! regs_ever_live[spill_regs[n_spills]])
  1656.     val = 1;
  1657.  
  1658.   regs_ever_live[spill_regs[n_spills]] = 1;
  1659.   n_spills++;
  1660.  
  1661.   return val;
  1662. }
  1663.  
  1664. /* Delete an unneeded INSN and any previous insns who sole purpose is loading
  1665.    data that is dead in INSN.  */
  1666.  
  1667. static void
  1668. delete_dead_insn (insn)
  1669.      rtx insn;
  1670. {
  1671.   rtx prev = prev_real_insn (insn);
  1672.   rtx prev_dest;
  1673.  
  1674.   /* If the previous insn sets a register that dies in our insn, delete it
  1675.      too.  */
  1676.   if (prev && GET_CODE (PATTERN (prev)) == SET
  1677.       && (prev_dest = SET_DEST (PATTERN (prev)), GET_CODE (prev_dest) == REG)
  1678.       && reg_mentioned_p (prev_dest, PATTERN (insn))
  1679.       && find_regno_note (insn, REG_DEAD, REGNO (prev_dest)))
  1680.     delete_dead_insn (prev);
  1681.  
  1682.   PUT_CODE (insn, NOTE);
  1683.   NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
  1684.   NOTE_SOURCE_FILE (insn) = 0;
  1685. }
  1686.  
  1687. /* Modify the home of pseudo-reg I.
  1688.    The new home is present in reg_renumber[I].
  1689.  
  1690.    FROM_REG may be the hard reg that the pseudo-reg is being spilled from;
  1691.    or it may be -1, meaning there is none or it is not relevant.
  1692.    This is used so that all pseudos spilled from a given hard reg
  1693.    can share one stack slot.  */
  1694.  
  1695. static void
  1696. alter_reg (i, from_reg)
  1697.      register int i;
  1698.      int from_reg;
  1699. {
  1700.   /* When outputting an inline function, this can happen
  1701.      for a reg that isn't actually used.  */
  1702.   if (regno_reg_rtx[i] == 0)
  1703.     return;
  1704.  
  1705.   /* If the reg got changed to a MEM at rtl-generation time,
  1706.      ignore it.  */
  1707.   if (GET_CODE (regno_reg_rtx[i]) != REG)
  1708.     return;
  1709.  
  1710.   /* Modify the reg-rtx to contain the new hard reg
  1711.      number or else to contain its pseudo reg number.  */
  1712.   REGNO (regno_reg_rtx[i])
  1713.     = reg_renumber[i] >= 0 ? reg_renumber[i] : i;
  1714.  
  1715.   /* If we have a pseudo that is needed but has no hard reg or equivalent,
  1716.      allocate a stack slot for it.  */
  1717.  
  1718.   if (reg_renumber[i] < 0
  1719.       && reg_n_refs[i] > 0
  1720.       && reg_equiv_constant[i] == 0
  1721.       && reg_equiv_memory_loc[i] == 0)
  1722.     {
  1723.       register rtx x;
  1724.       int inherent_size = PSEUDO_REGNO_BYTES (i);
  1725.       int total_size = max (inherent_size, reg_max_ref_width[i]);
  1726.  
  1727.       /* Each pseudo reg has an inherent size which comes from its own mode,
  1728.      and a total size which provides room for paradoxical subregs
  1729.      which refer to the pseudo reg in wider modes.
  1730.  
  1731.      We can use a slot already allocated if it provides both
  1732.      enough inherent space and enough total space.
  1733.      Otherwise, we allocate a new slot, making sure that it has no less
  1734.      inherent space, and no less total space, then the previous slot.  */
  1735.       if (from_reg == -1)
  1736.     {
  1737.       /* No known place to spill from => no slot to reuse.  */
  1738.       x = assign_stack_local (GET_MODE (regno_reg_rtx[i]), total_size, -1);
  1739. #if BYTES_BIG_ENDIAN
  1740.       /* Cancel the  big-endian correction done in assign_stack_local.
  1741.          Get the address of the beginning of the slot.
  1742.          This is so we can do a big-endian correction unconditionally
  1743.          below.  */
  1744.       x = gen_rtx (MEM, GET_MODE (regno_reg_rtx[i]),
  1745.                plus_constant (XEXP (x, 0),
  1746.                       inherent_size - total_size));
  1747. #endif
  1748.       RTX_UNCHANGING_P (x) = RTX_UNCHANGING_P (regno_reg_rtx[i]);
  1749.     }
  1750.       /* Reuse a stack slot if possible.  */
  1751.       else if (spill_stack_slot[from_reg] != 0
  1752.            && spill_stack_slot_width[from_reg] >= total_size
  1753.            && (GET_MODE_SIZE (GET_MODE (spill_stack_slot[from_reg]))
  1754.            >= inherent_size))
  1755.     x = spill_stack_slot[from_reg];
  1756.       /* Allocate a bigger slot.  */
  1757.       else
  1758.     {
  1759.       /* Compute maximum size needed, both for inherent size
  1760.          and for total size.  */
  1761.       enum machine_mode mode = GET_MODE (regno_reg_rtx[i]);
  1762.       if (spill_stack_slot[from_reg])
  1763.         {
  1764.           if (GET_MODE_SIZE (GET_MODE (spill_stack_slot[from_reg]))
  1765.           > inherent_size)
  1766.         mode = GET_MODE (spill_stack_slot[from_reg]);
  1767.           if (spill_stack_slot_width[from_reg] > total_size)
  1768.         total_size = spill_stack_slot_width[from_reg];
  1769.         }
  1770.       /* Make a slot with that size.  */
  1771.       x = assign_stack_local (mode, total_size, -1);
  1772. #if BYTES_BIG_ENDIAN
  1773.       /* Cancel the  big-endian correction done in assign_stack_local.
  1774.          Get the address of the beginning of the slot.
  1775.          This is so we can do a big-endian correction unconditionally
  1776.          below.  */
  1777.       x = gen_rtx (MEM, mode,
  1778.                plus_constant (XEXP (x, 0),
  1779.                       GET_MODE_SIZE (mode) - total_size));
  1780. #endif
  1781.       spill_stack_slot[from_reg] = x;
  1782.       spill_stack_slot_width[from_reg] = total_size;
  1783.     }
  1784.  
  1785. #if BYTES_BIG_ENDIAN
  1786.       /* On a big endian machine, the "address" of the slot
  1787.      is the address of the low part that fits its inherent mode.  */
  1788.       if (inherent_size < total_size)
  1789.     {
  1790.       x = gen_rtx (MEM, GET_MODE (regno_reg_rtx[i]),
  1791.                plus_constant (XEXP (x, 0),
  1792.                       total_size - inherent_size));
  1793.       RTX_UNCHANGING_P (x) = RTX_UNCHANGING_P (regno_reg_rtx[i]);
  1794.     }
  1795. #endif /* BYTES_BIG_ENDIAN */
  1796.  
  1797.       /* Save the stack slot for later.   */
  1798.       reg_equiv_memory_loc[i] = x;
  1799.     }
  1800. }
  1801.  
  1802. /* Mark the slots in regs_ever_live for the hard regs
  1803.    used by pseudo-reg number REGNO.  */
  1804.  
  1805. void
  1806. mark_home_live (regno)
  1807.      int regno;
  1808. {
  1809.   register int i, lim;
  1810.   i = reg_renumber[regno];
  1811.   if (i < 0)
  1812.     return;
  1813.   lim = i + HARD_REGNO_NREGS (i, PSEUDO_REGNO_MODE (regno));
  1814.   while (i < lim)
  1815.     regs_ever_live[i++] = 1;
  1816. }
  1817.  
  1818. /* Used for communication between the next two function to properly share
  1819.    the vector for an ASM_OPERANDS.  */
  1820.  
  1821. static struct rtvec_def *old_asm_operands_vec, *new_asm_operands_vec;
  1822.  
  1823. /* Scan X and replace any eliminable registers (such as fp) with a 
  1824.    replacement (such as sp), plus an offset.
  1825.  
  1826.    MEM_MODE is the mode of an enclosing MEM.  We need this to know how
  1827.    much to adjust a register for, e.g., PRE_DEC.  Also, if we are inside a
  1828.    MEM, we are allowed to replace a sum of a register and the constant zero
  1829.    with the register, which we cannot do outside a MEM.  In addition, we need
  1830.    to record the fact that a register is referenced outside a MEM.
  1831.  
  1832.    If INSN is nonzero, it is the insn containing X.  If we replace a REG
  1833.    in a SET_DEST with an equivalent MEM and INSN is non-zero, write a
  1834.    CLOBBER of the pseudo after INSN so find_equiv_regs will know that
  1835.    that the REG is being modified.
  1836.  
  1837.    If we see a modification to a register we know about, take the
  1838.    appropriate action (see case SET, below).
  1839.  
  1840.    REG_EQUIV_MEM and REG_EQUIV_ADDRESS contain address that have had
  1841.    replacements done assuming all offsets are at their initial values.  If
  1842.    they are not, or if REG_EQUIV_ADDRESS is nonzero for a pseudo we
  1843.    encounter, return the actual location so that find_reloads will do
  1844.    the proper thing.  */
  1845.  
  1846. rtx
  1847. eliminate_regs (x, mem_mode, insn)
  1848.      rtx x;
  1849.      enum machine_mode mem_mode;
  1850.      rtx insn;
  1851. {
  1852.   enum rtx_code code = GET_CODE (x);
  1853.   struct elim_table *ep;
  1854.   int regno;
  1855.   rtx new;
  1856.   int i, j;
  1857.   char *fmt;
  1858.   int copied = 0;
  1859.  
  1860.   switch (code)
  1861.     {
  1862.     case CONST_INT:
  1863.     case CONST_DOUBLE:
  1864.     case CONST:
  1865.     case SYMBOL_REF:
  1866.     case CODE_LABEL:
  1867.     case PC:
  1868.     case CC0:
  1869.     case ASM_INPUT:
  1870.     case ADDR_VEC:
  1871.     case ADDR_DIFF_VEC:
  1872.     case RETURN:
  1873.       return x;
  1874.  
  1875.     case REG:
  1876.       regno = REGNO (x);
  1877.  
  1878.       /* First handle the case where we encounter a bare register that
  1879.      is eliminable.  Replace it with a PLUS.  */
  1880.       if (regno < FIRST_PSEUDO_REGISTER)
  1881.     {
  1882.       for (ep = reg_eliminate; ep < ®_eliminate[NUM_ELIMINABLE_REGS];
  1883.            ep++)
  1884.         if (ep->from_rtx == x && ep->can_eliminate)
  1885.           {
  1886.         if (! mem_mode)
  1887.           ep->ref_outside_mem = 1;
  1888.         return plus_constant (ep->to_rtx, ep->previous_offset);
  1889.           }
  1890.  
  1891.     }
  1892.       else if (reg_equiv_memory_loc && reg_equiv_memory_loc[regno]
  1893.            && (reg_equiv_address[regno] || num_not_at_initial_offset))
  1894.     {
  1895.       /* In this case, find_reloads would attempt to either use an
  1896.          incorrect address (if something is not at its initial offset)
  1897.          or substitute an replaced address into an insn (which loses
  1898.          if the offset is changed by some later action).  So we simply
  1899.          return the replaced stack slot (assuming it is changed by
  1900.          elimination) and ignore the fact that this is actually a
  1901.          reference to the pseudo.  Ensure we make a copy of the
  1902.          address in case it is shared.  */
  1903.       new = eliminate_regs (reg_equiv_memory_loc[regno], mem_mode, 0);
  1904.       if (new != reg_equiv_memory_loc[regno])
  1905.         return copy_rtx (new);
  1906.     }
  1907.       return x;
  1908.  
  1909.     case PLUS:
  1910.       /* If this is the sum of an eliminable register and a constant, rework
  1911.      the sum.   */
  1912.       if (GET_CODE (XEXP (x, 0)) == REG
  1913.       && REGNO (XEXP (x, 0)) < FIRST_PSEUDO_REGISTER
  1914.       && CONSTANT_P (XEXP (x, 1)))
  1915.     {
  1916.       for (ep = reg_eliminate; ep < ®_eliminate[NUM_ELIMINABLE_REGS];
  1917.            ep++)
  1918.         if (ep->from_rtx == XEXP (x, 0) && ep->can_eliminate)
  1919.           {
  1920.         if (! mem_mode)
  1921.           ep->ref_outside_mem = 1;
  1922.  
  1923.         /* The only time we want to replace a PLUS with a REG (this
  1924.            occurs when the constant operand of the PLUS is the negative
  1925.            of the offset) is when we are inside a MEM.  We won't want
  1926.            to do so at other times because that would change the
  1927.            structure of the insn in a way that reload can't handle.
  1928.            We special-case the commonest situation in
  1929.            eliminate_regs_in_insn, so just replace a PLUS with a
  1930.            PLUS here, unless inside a MEM.  */
  1931.         if (mem_mode && GET_CODE (XEXP (x, 1)) == CONST_INT
  1932.             && INTVAL (XEXP (x, 1)) == - ep->previous_offset)
  1933.           return ep->to_rtx;
  1934.         else
  1935.           return gen_rtx (PLUS, Pmode, ep->to_rtx,
  1936.                   plus_constant (XEXP (x, 1),
  1937.                          ep->previous_offset));
  1938.           }
  1939.  
  1940.       /* If the register is not eliminable, we are done since the other
  1941.          operand is a constant.  */
  1942.       return x;
  1943.     }
  1944.  
  1945.       /* If this is part of an address, we want to bring any constant to the
  1946.      outermost PLUS.  We will do this by doing register replacement in
  1947.      our operands and seeing if a constant shows up in one of them.
  1948.  
  1949.      We assume here this is part of an address (or a "load address" insn)
  1950.      since an eliminable register is not likely to appear in any other
  1951.      context.
  1952.  
  1953.      If we have (plus (eliminable) (reg)), we want to produce
  1954.      (plus (plus (replacement) (reg) (const))).  If this was part of a
  1955.      normal add insn, (plus (replacement) (reg)) will be pushed as a
  1956.      reload.  This is the desired action.  */
  1957.  
  1958.       {
  1959.     rtx new0 = eliminate_regs (XEXP (x, 0), mem_mode, 0);
  1960.     rtx new1 = eliminate_regs (XEXP (x, 1), mem_mode, 0);
  1961.  
  1962.     if (new0 != XEXP (x, 0) || new1 != XEXP (x, 1))
  1963.       {
  1964.         /* If one side is a PLUS and the other side is a pseudo that
  1965.            didn't get a hard register but has a reg_equiv_constant, 
  1966.            we must replace the constant here since it may no longer
  1967.            be in the position of any operand.  */
  1968.         if (GET_CODE (new0) == PLUS && GET_CODE (new1) == REG
  1969.         && REGNO (new1) >= FIRST_PSEUDO_REGISTER
  1970.         && reg_renumber[REGNO (new1)] < 0
  1971.         && reg_equiv_constant != 0
  1972.         && reg_equiv_constant[REGNO (new1)] != 0)
  1973.           new1 = reg_equiv_constant[REGNO (new1)];
  1974.         else if (GET_CODE (new1) == PLUS && GET_CODE (new0) == REG
  1975.              && REGNO (new0) >= FIRST_PSEUDO_REGISTER
  1976.              && reg_renumber[REGNO (new0)] < 0
  1977.              && reg_equiv_constant[REGNO (new0)] != 0)
  1978.           new0 = reg_equiv_constant[REGNO (new0)];
  1979.  
  1980.         new = form_sum (new0, new1);
  1981.  
  1982.         /* As above, if we are not inside a MEM we do not want to
  1983.            turn a PLUS into something else.  We might try to do so here
  1984.            for an addition of 0 if we aren't optimizing.  */
  1985.         if (! mem_mode && GET_CODE (new) != PLUS)
  1986.           return gen_rtx (PLUS, GET_MODE (x), new, const0_rtx);
  1987.         else
  1988.           return new;
  1989.       }
  1990.       }
  1991.       return x;
  1992.  
  1993.     case EXPR_LIST:
  1994.       /* If we have something in XEXP (x, 0), the usual case, eliminate it.  */
  1995.       if (XEXP (x, 0))
  1996.     {
  1997.       new = eliminate_regs (XEXP (x, 0), mem_mode, 0);
  1998.       if (new != XEXP (x, 0))
  1999.         x = gen_rtx (EXPR_LIST, REG_NOTE_KIND (x), new, XEXP (x, 1));
  2000.     }
  2001.  
  2002.       /* ... fall through ... */
  2003.  
  2004.     case INSN_LIST:
  2005.       /* Now do eliminations in the rest of the chain.  If this was
  2006.      an EXPR_LIST, this might result in allocating more memory than is
  2007.      strictly needed, but it simplifies the code.  */
  2008.       if (XEXP (x, 1))
  2009.     {
  2010.       new = eliminate_regs (XEXP (x, 1), mem_mode, 0);
  2011.       if (new != XEXP (x, 1))
  2012.         return gen_rtx (INSN_LIST, GET_MODE (x), XEXP (x, 0), new);
  2013.     }
  2014.       return x;
  2015.  
  2016.     case CALL:
  2017.     case COMPARE:
  2018.     case MINUS:
  2019.     case MULT:
  2020.     case DIV:      case UDIV:
  2021.     case MOD:      case UMOD:
  2022.     case AND:      case IOR:      case XOR:
  2023.     case LSHIFT:   case ASHIFT:   case ROTATE:
  2024.     case ASHIFTRT: case LSHIFTRT: case ROTATERT:
  2025.     case NE:       case EQ:
  2026.     case GE:       case GT:       case GEU:    case GTU:
  2027.     case LE:       case LT:       case LEU:    case LTU:
  2028.       {
  2029.     rtx new0 = eliminate_regs (XEXP (x, 0), mem_mode, 0);
  2030.     rtx new1 = XEXP (x, 1) ? eliminate_regs (XEXP (x, 1), mem_mode, 0) : 0;
  2031.  
  2032.     if (new0 != XEXP (x, 0) || new1 != XEXP (x, 1))
  2033.       return gen_rtx (code, GET_MODE (x), new0, new1);
  2034.       }
  2035.       return x;
  2036.  
  2037.     case PRE_INC:
  2038.     case POST_INC:
  2039.     case PRE_DEC:
  2040.     case POST_DEC:
  2041.       for (ep = reg_eliminate; ep < ®_eliminate[NUM_ELIMINABLE_REGS]; ep++)
  2042.     if (ep->to_rtx == XEXP (x, 0))
  2043.       {
  2044.         if (code == PRE_DEC || code == POST_DEC)
  2045.           ep->offset += GET_MODE_SIZE (mem_mode);
  2046.         else
  2047.           ep->offset -= GET_MODE_SIZE (mem_mode);
  2048.       }
  2049.  
  2050.       /* Fall through to generic unary operation case.  */
  2051.     case USE:
  2052.     case STRICT_LOW_PART:
  2053.     case NEG:          case NOT:
  2054.     case SIGN_EXTEND:  case ZERO_EXTEND:
  2055.     case TRUNCATE:     case FLOAT_EXTEND: case FLOAT_TRUNCATE:
  2056.     case FLOAT:        case FIX:
  2057.     case UNSIGNED_FIX: case UNSIGNED_FLOAT:
  2058.     case ABS:
  2059.     case SQRT:
  2060.     case FFS:
  2061.       new = eliminate_regs (XEXP (x, 0), mem_mode, 0);
  2062.       if (new != XEXP (x, 0))
  2063.     return gen_rtx (code, GET_MODE (x), new);
  2064.       return x;
  2065.  
  2066.     case SUBREG:
  2067.       /* Similar to above processing, but preserve SUBREG_WORD.
  2068.      Convert (subreg (mem)) to (mem) if not paradoxical.
  2069.      Also, if we have a non-paradoxical (subreg (pseudo)) and the
  2070.      pseudo didn't get a hard reg, we must replace this with the
  2071.      eliminated version of the memory location because push_reloads
  2072.      may do the replacement in certain circumstances.  */
  2073.       if (GET_CODE (SUBREG_REG (x)) == REG
  2074.       && (GET_MODE_SIZE (GET_MODE (x))
  2075.           <= GET_MODE_SIZE (GET_MODE (SUBREG_REG (x))))
  2076.       && reg_equiv_memory_loc != 0
  2077.       && reg_equiv_memory_loc[REGNO (SUBREG_REG (x))] != 0)
  2078.     {
  2079.       new = eliminate_regs (reg_equiv_memory_loc[REGNO (SUBREG_REG (x))],
  2080.                 mem_mode, 0);
  2081.  
  2082.       /* If we didn't change anything, we must retain the pseudo.  */
  2083.       if (new == reg_equiv_memory_loc[REGNO (SUBREG_REG (x))])
  2084.         new = XEXP (x, 0);
  2085.       else
  2086.         /* Otherwise, ensure NEW isn't shared in case we have to reload
  2087.            it.  */
  2088.         new = copy_rtx (new);
  2089.     }
  2090.       else
  2091.     new = eliminate_regs (SUBREG_REG (x), mem_mode, 0);
  2092.  
  2093.       if (new != XEXP (x, 0))
  2094.     {
  2095.       if (GET_CODE (new) == MEM
  2096.           && (GET_MODE_SIZE (GET_MODE (x))
  2097.           <= GET_MODE_SIZE (GET_MODE (new))))
  2098.         {
  2099.           int offset = SUBREG_WORD (x) * UNITS_PER_WORD;
  2100.           enum machine_mode mode = GET_MODE (x);
  2101.  
  2102. #if BYTES_BIG_ENDIAN
  2103.           offset += (min (UNITS_PER_WORD,
  2104.                   GET_MODE_SIZE (GET_MODE (new)))
  2105.              - min (UNITS_PER_WORD, GET_MODE_SIZE (mode)));
  2106. #endif
  2107.  
  2108.           PUT_MODE (new, mode);
  2109.           XEXP (new, 0) = plus_constant (XEXP (new, 0), offset);
  2110.           return new;
  2111.         }
  2112.       else
  2113.         return gen_rtx (SUBREG, GET_MODE (x), new, SUBREG_WORD (x));
  2114.     }
  2115.  
  2116.       return x;
  2117.  
  2118.     case CLOBBER:
  2119.       /* If clobbering a register that is the replacement register for an
  2120.      elimination we still think can be peformed, note that it cannot
  2121.      be performed.  Otherwise, we need not be concerned about it.  */
  2122.       for (ep = reg_eliminate; ep < ®_eliminate[NUM_ELIMINABLE_REGS]; ep++)
  2123.     if (ep->to_rtx == XEXP (x, 0))
  2124.       ep->can_eliminate = 0;
  2125.  
  2126.       return x;
  2127.  
  2128.     case ASM_OPERANDS:
  2129.       {
  2130.     rtx *temp_vec;
  2131.     /* Properly handle sharing input and constraint vectors.  */
  2132.     if (ASM_OPERANDS_INPUT_VEC (x) != old_asm_operands_vec)
  2133.       {
  2134.         /* When we come to a new vector not seen before,
  2135.            scan all its elements; keep the old vector if none
  2136.            of them changes; otherwise, make a copy.  */
  2137.         old_asm_operands_vec = ASM_OPERANDS_INPUT_VEC (x);
  2138.         temp_vec = (rtx *) alloca (XVECLEN (x, 3) * sizeof (rtx));
  2139.         for (i = 0; i < ASM_OPERANDS_INPUT_LENGTH (x); i++)
  2140.           temp_vec[i] = eliminate_regs (ASM_OPERANDS_INPUT (x, i),
  2141.                         mem_mode, 0);
  2142.  
  2143.         for (i = 0; i < ASM_OPERANDS_INPUT_LENGTH (x); i++)
  2144.           if (temp_vec[i] != ASM_OPERANDS_INPUT (x, i))
  2145.         break;
  2146.  
  2147.         if (i == ASM_OPERANDS_INPUT_LENGTH (x))
  2148.           new_asm_operands_vec = old_asm_operands_vec;
  2149.         else
  2150.           new_asm_operands_vec
  2151.         = gen_rtvec_v (ASM_OPERANDS_INPUT_LENGTH (x), temp_vec);
  2152.       }
  2153.  
  2154.     /* If we had to copy the vector, copy the entire ASM_OPERANDS.  */
  2155.     if (new_asm_operands_vec == old_asm_operands_vec)
  2156.       return x;
  2157.  
  2158.     new = gen_rtx (ASM_OPERANDS, VOIDmode, ASM_OPERANDS_TEMPLATE (x),
  2159.                ASM_OPERANDS_OUTPUT_CONSTRAINT (x),
  2160.                ASM_OPERANDS_OUTPUT_IDX (x), new_asm_operands_vec,
  2161.                ASM_OPERANDS_INPUT_CONSTRAINT_VEC (x),
  2162.                ASM_OPERANDS_SOURCE_FILE (x),
  2163.                ASM_OPERANDS_SOURCE_LINE (x));
  2164.     new->volatil = x->volatil;
  2165.     return new;
  2166.       }
  2167.  
  2168.     case SET:
  2169.       /* Check for setting a register that we know about.  */
  2170.       if (GET_CODE (SET_DEST (x)) == REG)
  2171.     {
  2172.       /* See if this is setting the replacement register for an
  2173.          elimination.  */
  2174.       for (ep = reg_eliminate; ep < ®_eliminate[NUM_ELIMINABLE_REGS];
  2175.            ep++)
  2176.         if (ep->to_rtx == SET_DEST (x))
  2177.           {
  2178.         /* If it is being incrememented, adjust the offset.  Otherwise,
  2179.            this elimination can't be done.  */
  2180.         rtx src = SET_SRC (x);
  2181.  
  2182.         if (GET_CODE (src) == PLUS
  2183.             && XEXP (src, 0) == SET_DEST (x)
  2184.             && GET_CODE (XEXP (src, 1)) == CONST_INT)
  2185.           ep->offset -= INTVAL (XEXP (src, 1));
  2186.         else
  2187.           ep->can_eliminate = 0;
  2188.           }
  2189.  
  2190.       /* Now check to see we are assigning to a register that can be
  2191.          eliminated.  If so, it must be as part of a PARALLEL, since we
  2192.          will not have been called if this is a single SET.  So indicate
  2193.          that we can no longer eliminate this reg.  */
  2194.       for (ep = reg_eliminate; ep < ®_eliminate[NUM_ELIMINABLE_REGS];
  2195.            ep++)
  2196.         if (ep->from_rtx == SET_DEST (x) && ep->can_eliminate)
  2197.           ep->can_eliminate = 0;
  2198.     }
  2199.  
  2200.       /* Now avoid the loop below in this common case.  */
  2201.       {
  2202.     rtx new0 = eliminate_regs (SET_DEST (x), 0, 0);
  2203.     rtx new1 = eliminate_regs (SET_SRC (x), 0, 0);
  2204.  
  2205.     /* If SET_DEST changed from a REG to a MEM and INSN is non-zero,
  2206.        write a CLOBBER insn.  */
  2207.     if (GET_CODE (SET_DEST (x)) == REG && GET_CODE (new0) == MEM
  2208.         && insn != 0)
  2209.       emit_insn_after (gen_rtx (CLOBBER, VOIDmode, SET_DEST (x)), insn);
  2210.  
  2211.     if (new0 != SET_DEST (x) || new1 != SET_SRC (x))
  2212.       return gen_rtx (SET, VOIDmode, new0, new1);
  2213.       }
  2214.  
  2215.       return x;
  2216.  
  2217.     case MEM:
  2218.       /* Our only special processing is to pass the mode of the MEM to our
  2219.      recursive call and copy the flags.  While we are here, handle this
  2220.      case more efficiently.  */
  2221.       new = eliminate_regs (XEXP (x, 0), GET_MODE (x), 0);
  2222.       if (new != XEXP (x, 0))
  2223.     {
  2224.       new = gen_rtx (MEM, GET_MODE (x), new);
  2225.       new->volatil = x->volatil;
  2226.       new->unchanging = x->unchanging;
  2227.       new->in_struct = x->in_struct;
  2228.       return new;
  2229.     }
  2230.       else
  2231.     return x;
  2232.     }
  2233.  
  2234.   /* Process each of our operands recursively.  If any have changed, make a
  2235.      copy of the rtx.  */
  2236.   fmt = GET_RTX_FORMAT (code);
  2237.   for (i = 0; i < GET_RTX_LENGTH (code); i++, fmt++)
  2238.     {
  2239.       if (*fmt == 'e')
  2240.     {
  2241.       new = eliminate_regs (XEXP (x, i), mem_mode, 0);
  2242.       if (new != XEXP (x, i) && ! copied)
  2243.         {
  2244.           rtx new_x = rtx_alloc (code);
  2245.           bcopy (x, new_x, (sizeof (*new_x) - sizeof (new_x->fld)
  2246.                 + (sizeof (new_x->fld[0])
  2247.                    * GET_RTX_LENGTH (code))));
  2248.           x = new_x;
  2249.           copied = 1;
  2250.         }
  2251.       XEXP (x, i) = new;
  2252.     }
  2253.       else if (*fmt == 'E')
  2254.     {
  2255.       int copied_vec = 0;
  2256.       for (j = 0; j < XVECLEN (x, i); j++)
  2257.         {
  2258.           new = eliminate_regs (XVECEXP (x, i, j), mem_mode, insn);
  2259.           if (new != XVECEXP (x, i, j) && ! copied_vec)
  2260.         {
  2261.           rtvec new_v = gen_rtvec_v (XVECLEN (x, i),
  2262.                          &XVECEXP (x, i, 0));
  2263.           if (! copied)
  2264.             {
  2265.               rtx new_x = rtx_alloc (code);
  2266.               bcopy (x, new_x, (sizeof (*new_x) - sizeof (new_x->fld)
  2267.                     + (sizeof (new_x->fld[0])
  2268.                        * GET_RTX_LENGTH (code))));
  2269.               x = new_x;
  2270.               copied = 1;
  2271.             }
  2272.           XVEC (x, i) = new_v;
  2273.           copied_vec = 1;
  2274.         }
  2275.           XVECEXP (x, i, j) = new;
  2276.         }
  2277.     }
  2278.     }
  2279.  
  2280.   return x;
  2281. }
  2282.  
  2283. /* Scan INSN and eliminate all eliminable registers in it.
  2284.  
  2285.    If REPLACE is nonzero, do the replacement destructively.  Also
  2286.    delete the insn as dead it if it is setting an eliminable register.
  2287.  
  2288.    If REPLACE is zero, do all our allocations in reload_obstack.
  2289.  
  2290.    If no eliminations were done and this insn doesn't require any elimination
  2291.    processing (these are not identical conditions: it might be updating sp,
  2292.    but not referencing fp; this needs to be seen during reload_as_needed so
  2293.    that the offset between fp and sp can be taken into consideration), zero
  2294.    is returned.  Otherwise, 1 is returned.  */
  2295.  
  2296. static int
  2297. eliminate_regs_in_insn (insn, replace)
  2298.      rtx insn;
  2299.      int replace;
  2300. {
  2301.   rtx old_body = PATTERN (insn);
  2302.   int val = 0;
  2303.   struct elim_table *ep;
  2304.  
  2305.   if (! replace)
  2306.     push_obstacks (&reload_obstack, &reload_obstack);
  2307.  
  2308.   if (GET_CODE (old_body) == SET && GET_CODE (SET_DEST (old_body)) == REG
  2309.       && REGNO (SET_DEST (old_body)) < FIRST_PSEUDO_REGISTER)
  2310.     {
  2311.       /* Check for setting an eliminable register.  */
  2312.       for (ep = reg_eliminate; ep < ®_eliminate[NUM_ELIMINABLE_REGS]; ep++)
  2313.     if (ep->from_rtx == SET_DEST (old_body) && ep->can_eliminate)
  2314.       {
  2315.         /* In this case this insn isn't serving a useful purpose.  We
  2316.            will delete it in reload_as_needed once we know that this
  2317.            elimination is, in fact, being done.
  2318.  
  2319.            If REPLACE isn't set, we can't delete this insn, but neededn't
  2320.            process it since it won't be used unless something changes.  */
  2321.         if (replace)
  2322.           delete_dead_insn (insn);
  2323.         val = 1;
  2324.         goto done;
  2325.       }
  2326.  
  2327.       /* Check for (set (reg) (plus (reg from) (offset))) where the offset
  2328.      in the insn is the negative of the offset in FROM.  Substitute
  2329.      (set (reg) (reg to)) for the insn and change its code.
  2330.  
  2331.      We have to do this here, rather than in eliminate_regs, do that we can
  2332.      change the insn code.  */
  2333.  
  2334.       if (GET_CODE (SET_SRC (old_body)) == PLUS
  2335.       && GET_CODE (XEXP (SET_SRC (old_body), 0)) == REG
  2336.       && GET_CODE (XEXP (SET_SRC (old_body), 1)) == CONST_INT)
  2337.     for (ep = reg_eliminate; ep < ®_eliminate[NUM_ELIMINABLE_REGS];
  2338.          ep++)
  2339.       if (ep->from_rtx == XEXP (SET_SRC (old_body), 0)
  2340.           && ep->can_eliminate
  2341.           && ep->offset == - INTVAL (XEXP (SET_SRC (old_body), 1)))
  2342.         {
  2343.           PATTERN (insn) = gen_rtx (SET, VOIDmode,
  2344.                     SET_DEST (old_body), ep->to_rtx);
  2345.           INSN_CODE (insn) = -1;
  2346.           val = 1;
  2347.           goto done;
  2348.         }
  2349.     }
  2350.  
  2351.   old_asm_operands_vec = 0;
  2352.  
  2353.   /* Replace the body of this insn with a substituted form.  If we changed
  2354.      something, return non-zero.  If this is the final call for this
  2355.      insn (REPLACE is non-zero), do the elimination in REG_NOTES as well.  */
  2356.  
  2357.   PATTERN (insn) = eliminate_regs (old_body, 0, replace ? insn : 0);
  2358.   if (PATTERN (insn) != old_body)
  2359.     {
  2360.       if (replace && REG_NOTES (insn))
  2361.     REG_NOTES (insn) = eliminate_regs (REG_NOTES (insn), 0, 0);
  2362.       val = 1;
  2363.     }
  2364.   
  2365.   /* Loop through all elimination pairs.  See if any have changed and
  2366.      recalculate the number not at initial offset.
  2367.  
  2368.      We also detect two cases where register elimination cannot be done.
  2369.      The first is when we are processing a jump insn and the current offset
  2370.      of some elimination pair is not at its initial offset.  In that case,
  2371.      that elimination pair can't be used.  For sp, the compiler rarely
  2372.      produces code that branches while sp has been adjusted; the most common
  2373.      case where this can occur is a conditional test while pushing arguments
  2374.      to a function.  It might be desirable to improve this code to allow
  2375.      frame pointer elimination in such a case.
  2376.  
  2377.      The pair also can't be used if a register would be both changed and
  2378.      referenced outside a MEM in the resulting insn since such an insn is
  2379.      often undefined and, even if not, we cannot know what meaning will be
  2380.      given to it.  Note that it is valid to have a register used in an address
  2381.      in an insn that changes it (presumably with a pre- or post-increment or
  2382.      decrement).
  2383.  
  2384.      If anything changes, return nonzero.  */
  2385.  
  2386.   num_not_at_initial_offset = 0;
  2387.   for (ep = reg_eliminate; ep < ®_eliminate[NUM_ELIMINABLE_REGS]; ep++)
  2388.     {
  2389.       if ((GET_CODE (insn) == JUMP_INSN
  2390.        && ep->offset != ep->initial_offset)
  2391.       || (ep->previous_offset != ep->offset && ep->ref_outside_mem))
  2392.     ep->can_eliminate = 0;
  2393.  
  2394.       ep->ref_outside_mem = 0;
  2395.  
  2396.       if (ep->previous_offset != ep->offset)
  2397.     val = 1;
  2398.  
  2399.       ep->previous_offset = ep->offset;
  2400.       if (ep->can_eliminate && ep->offset != ep->initial_offset)
  2401.     num_not_at_initial_offset++;
  2402.     }
  2403.  
  2404.  done:
  2405.   if (! replace)
  2406.     pop_obstacks ();
  2407.  
  2408.   return val;
  2409. }
  2410.  
  2411. /* Given X, a SET or CLOBBER of DEST, if DEST is the target of a register
  2412.    replacement we currently believe is valid, mark it as not eliminable if X
  2413.    modifies DEST in any way other than by adding a constant integer to it.
  2414.  
  2415.    Called via note_stores from reload before starting its passes to scan
  2416.    the insns of the function.  */
  2417.  
  2418. static void
  2419. mark_not_eliminable (dest, x)
  2420.      rtx dest;
  2421.      rtx x;
  2422. {
  2423.   register int i;
  2424.  
  2425.   /* A SUBREG of a hard register here is just changing its mode.  We should
  2426.      not see a SUBREG of an eliminable hard register, but check just in
  2427.      case.  */
  2428.   if (GET_CODE (dest) == SUBREG)
  2429.     dest = SUBREG_REG (dest);
  2430.  
  2431.   for (i = 0; i < NUM_ELIMINABLE_REGS; i++)
  2432.     if (reg_eliminate[i].can_eliminate && dest == reg_eliminate[i].to_rtx
  2433.     && (GET_CODE (x) != SET
  2434.         || GET_CODE (SET_SRC (x)) != PLUS
  2435.         || XEXP (SET_SRC (x), 0) != dest
  2436.         || GET_CODE (XEXP (SET_SRC (x), 1)) != CONST_INT))
  2437.       {
  2438.     reg_eliminate[i].can_eliminate_previous
  2439.       = reg_eliminate[i].can_eliminate = 0;
  2440.     num_eliminable--;
  2441.       }
  2442. }
  2443.  
  2444. /* Kick all pseudos out of hard register REGNO.
  2445.    If GLOBAL is nonzero, try to find someplace else to put them.
  2446.    If DUMPFILE is nonzero, log actions taken on that file.
  2447.  
  2448.    If CANT_ELIMINATE is nonzero, it means that we are doing this spill
  2449.    because we found we can't eliminate some register.  In the case, no pseudos
  2450.    are allowed to be in the register, even if they are only in a block that
  2451.    doesn't require spill registers, unlike the case when we are spilling this
  2452.    hard reg to produce another spill register.
  2453.  
  2454.    Return nonzero if any pseudos needed to be kicked out.  */
  2455.  
  2456. static int
  2457. spill_hard_reg (regno, global, dumpfile, cant_eliminate)
  2458.      register int regno;
  2459.      int global;
  2460.      FILE *dumpfile;
  2461.      int cant_eliminate;
  2462. {
  2463.   int something_changed = 0;
  2464.   register int i;
  2465.  
  2466.   SET_HARD_REG_BIT (forbidden_regs, regno);
  2467.  
  2468.   /* Spill every pseudo reg that was allocated to this reg
  2469.      or to something that overlaps this reg.  */
  2470.  
  2471.   for (i = FIRST_PSEUDO_REGISTER; i < max_regno; i++)
  2472.     if (reg_renumber[i] >= 0
  2473.     && reg_renumber[i] <= regno
  2474.     && (reg_renumber[i] 
  2475.         + HARD_REGNO_NREGS (reg_renumber[i],
  2476.                 PSEUDO_REGNO_MODE (i))
  2477.         > regno))
  2478.       {
  2479.     /* If this register belongs solely to a basic block which needed no
  2480.        spilling of any class that this register is contained in,
  2481.        leave it be, unless we are spilling this register because
  2482.        it was a hard register that can't be eliminated.   */
  2483.  
  2484.     if (! cant_eliminate
  2485.         && basic_block_needs[0]
  2486.         && reg_basic_block[i] >= 0)
  2487.       {
  2488.         enum reg_class *p;
  2489.  
  2490.         /* This code relies on the fact that
  2491.            reg_class_superclasses[i][0] == i.  */
  2492.  
  2493.         for (p = reg_class_superclasses[(int) REGNO_REG_CLASS (regno)];
  2494.          *p != LIM_REG_CLASSES; p++)
  2495.           if (TEST_HARD_REG_BIT (reg_class_contents[(int) *p], regno)
  2496.           && basic_block_needs[(int) *p][reg_basic_block[i]] > 0)
  2497.         break;
  2498.       
  2499.         if (*p == LIM_REG_CLASSES)
  2500.           continue;
  2501.       }
  2502.  
  2503.     /* Mark it as no longer having a hard register home.  */
  2504.     reg_renumber[i] = -1;
  2505.     /* We will need to scan everything again.  */
  2506.     something_changed = 1;
  2507.     if (global)
  2508.       {
  2509.         retry_global_alloc (i, forbidden_regs);
  2510.         /* Update regs_ever_live for new home (if any).  */
  2511.         mark_home_live (i);
  2512.       }
  2513.     alter_reg (i, regno);
  2514.     if (dumpfile)
  2515.       {
  2516.         if (reg_renumber[i] == -1)
  2517.           fprintf (dumpfile, " Register %d now on stack.\n\n", i);
  2518.         else
  2519.           fprintf (dumpfile, " Register %d now in %d.\n\n",
  2520.                i, reg_renumber[i]);
  2521.       }
  2522.       }
  2523.  
  2524.   return something_changed;
  2525. }
  2526.  
  2527. /* Find all paradoxical subregs within X and update reg_max_ref_width.  */
  2528.  
  2529. static void
  2530. scan_paradoxical_subregs (x)
  2531.      register rtx x;
  2532. {
  2533.   register int i;
  2534.   register char *fmt;
  2535.   register enum rtx_code code = GET_CODE (x);
  2536.  
  2537.   switch (code)
  2538.     {
  2539.     case CONST_INT:
  2540.     case CONST:
  2541.     case SYMBOL_REF:
  2542.     case LABEL_REF:
  2543.     case CONST_DOUBLE:
  2544.     case CC0:
  2545.     case PC:
  2546.     case REG:
  2547.     case USE:
  2548.     case CLOBBER:
  2549.       return;
  2550.  
  2551.     case SUBREG:
  2552.       if (GET_CODE (SUBREG_REG (x)) == REG
  2553.       && GET_MODE_SIZE (GET_MODE (x)) > GET_MODE_SIZE (GET_MODE (SUBREG_REG (x))))
  2554.     reg_max_ref_width[REGNO (SUBREG_REG (x))]
  2555.       = GET_MODE_SIZE (GET_MODE (x));
  2556.       return;
  2557.     }
  2558.  
  2559.   fmt = GET_RTX_FORMAT (code);
  2560.   for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
  2561.     {
  2562.       if (fmt[i] == 'e')
  2563.     scan_paradoxical_subregs (XEXP (x, i));
  2564.       else if (fmt[i] == 'E')
  2565.     {
  2566.       register int j;
  2567.       for (j = XVECLEN (x, i) - 1; j >=0; j--)
  2568.         scan_paradoxical_subregs (XVECEXP (x, i, j));
  2569.     }
  2570.     }
  2571. }
  2572.  
  2573. struct hard_reg_n_uses { int regno; int uses; };
  2574.  
  2575. static int
  2576. hard_reg_use_compare (p1, p2)
  2577.      struct hard_reg_n_uses *p1, *p2;
  2578. {
  2579.   int tem = p1->uses - p2->uses;
  2580.   if (tem != 0) return tem;
  2581.   /* If regs are equally good, sort by regno,
  2582.      so that the results of qsort leave nothing to chance.  */
  2583.   return p1->regno - p2->regno;
  2584. }
  2585.  
  2586. /* Choose the order to consider regs for use as reload registers
  2587.    based on how much trouble would be caused by spilling one.
  2588.    Store them in order of decreasing preference in potential_reload_regs.  */
  2589.  
  2590. static void
  2591. order_regs_for_reload ()
  2592. {
  2593.   register int i;
  2594.   register int o = 0;
  2595.   int large = 0;
  2596.  
  2597.   struct hard_reg_n_uses hard_reg_n_uses[FIRST_PSEUDO_REGISTER];
  2598.  
  2599.   CLEAR_HARD_REG_SET (bad_spill_regs);
  2600.  
  2601.   for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
  2602.     potential_reload_regs[i] = -1;
  2603.  
  2604.   /* Count number of uses of each hard reg by pseudo regs allocated to it
  2605.      and then order them by decreasing use.  */
  2606.  
  2607.   for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
  2608.     {
  2609.       hard_reg_n_uses[i].uses = 0;
  2610.       hard_reg_n_uses[i].regno = i;
  2611.     }
  2612.  
  2613.   for (i = FIRST_PSEUDO_REGISTER; i < max_regno; i++)
  2614.     {
  2615.       int regno = reg_renumber[i];
  2616.       if (regno >= 0)
  2617.     {
  2618.       int lim = regno + HARD_REGNO_NREGS (regno, PSEUDO_REGNO_MODE (i));
  2619.       while (regno < lim)
  2620.         hard_reg_n_uses[regno++].uses += reg_n_refs[i];
  2621.     }
  2622.       large += reg_n_refs[i];
  2623.     }
  2624.  
  2625.   /* Now fixed registers (which cannot safely be used for reloading)
  2626.      get a very high use count so they will be considered least desirable.
  2627.      Registers used explicitly in the rtl code are almost as bad.  */
  2628.  
  2629.   for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
  2630.     {
  2631.       if (fixed_regs[i])
  2632.     {
  2633.       hard_reg_n_uses[i].uses += 2 * large + 2;
  2634.       SET_HARD_REG_BIT (bad_spill_regs, i);
  2635.     }
  2636.       else if (regs_explicitly_used[i])
  2637.     {
  2638.       hard_reg_n_uses[i].uses += large + 1;
  2639.       /* ??? We are doing this here because of the potential that
  2640.          bad code may be generated if a register explicitly used in
  2641.          an insn was used as a spill register for that insn.  But
  2642.          not using these are spill registers may lose on some machine.
  2643.          We'll have to see how this works out.  */
  2644.       SET_HARD_REG_BIT (bad_spill_regs, i);
  2645.     }
  2646.     }
  2647.   hard_reg_n_uses[FRAME_POINTER_REGNUM].uses += 2 * large + 2;
  2648.   SET_HARD_REG_BIT (bad_spill_regs, FRAME_POINTER_REGNUM);
  2649.  
  2650. #ifdef ELIMINABLE_REGS
  2651.   /* If registers other than the frame pointer are eliminable, mark them as
  2652.      poor choices.  */
  2653.   for (i = 0; i < NUM_ELIMINABLE_REGS; i++)
  2654.     {
  2655.       hard_reg_n_uses[reg_eliminate[i].from].uses += 2 * large + 2;
  2656.       SET_HARD_REG_BIT (bad_spill_regs, reg_eliminate[i].from);
  2657.     }
  2658. #endif
  2659.  
  2660.   /* Prefer registers not so far used, for use in temporary loading.
  2661.      Among them, if REG_ALLOC_ORDER is defined, use that order.
  2662.      Otherwise, prefer registers not preserved by calls.  */
  2663.  
  2664. #ifdef REG_ALLOC_ORDER
  2665.   for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
  2666.     {
  2667.       int regno = reg_alloc_order[i];
  2668.  
  2669.       if (hard_reg_n_uses[regno].uses == 0)
  2670.     potential_reload_regs[o++] = regno;
  2671.     }
  2672. #else
  2673.   for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
  2674.     {
  2675.       if (hard_reg_n_uses[i].uses == 0 && call_used_regs[i])
  2676.     potential_reload_regs[o++] = i;
  2677.     }
  2678.   for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
  2679.     {
  2680.       if (hard_reg_n_uses[i].uses == 0 && ! call_used_regs[i])
  2681.     potential_reload_regs[o++] = i;
  2682.     }
  2683. #endif
  2684.  
  2685.   qsort (hard_reg_n_uses, FIRST_PSEUDO_REGISTER,
  2686.      sizeof hard_reg_n_uses[0], hard_reg_use_compare);
  2687.  
  2688.   /* Now add the regs that are already used,
  2689.      preferring those used less often.  The fixed and otherwise forbidden
  2690.      registers will be at the end of this list.  */
  2691.  
  2692.   for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
  2693.     if (hard_reg_n_uses[i].uses != 0)
  2694.       potential_reload_regs[o++] = hard_reg_n_uses[i].regno;
  2695. }
  2696.  
  2697. /* Reload pseudo-registers into hard regs around each insn as needed.
  2698.    Additional register load insns are output before the insn that needs it
  2699.    and perhaps store insns after insns that modify the reloaded pseudo reg.
  2700.  
  2701.    reg_last_reload_reg and reg_reloaded_contents keep track of
  2702.    which pseudo-registers are already available in reload registers.
  2703.    We update these for the reloads that we perform,
  2704.    as the insns are scanned.  */
  2705.  
  2706. static void
  2707. reload_as_needed (first, live_known)
  2708.      rtx first;
  2709.      int live_known;
  2710. {
  2711.   register rtx insn;
  2712.   register int i;
  2713.   int this_block = 0;
  2714.   rtx x;
  2715.   rtx after_call = 0;
  2716.  
  2717.   bzero (spill_reg_rtx, sizeof spill_reg_rtx);
  2718.   reg_last_reload_reg = (rtx *) alloca (max_regno * sizeof (rtx));
  2719.   bzero (reg_last_reload_reg, max_regno * sizeof (rtx));
  2720.   reg_has_output_reload = (char *) alloca (max_regno);
  2721.   for (i = 0; i < n_spills; i++)
  2722.     {
  2723.       reg_reloaded_contents[i] = -1;
  2724.       reg_reloaded_insn[i] = 0;
  2725.     }
  2726.  
  2727.   reload_in_progress = 1;
  2728.  
  2729.   /* Reset all offsets on eliminable registers to their initial values.  */
  2730. #ifdef ELIMINABLE_REGS
  2731.   for (i = 0; i < NUM_ELIMINABLE_REGS; i++)
  2732.     {
  2733.       INITIAL_ELIMINATION_OFFSET (reg_eliminate[i].from, reg_eliminate[i].to,
  2734.                   reg_eliminate[i].initial_offset)
  2735.       reg_eliminate[i].previous_offset
  2736.     = reg_eliminate[i].offset = reg_eliminate[i].initial_offset;
  2737.     }
  2738. #else
  2739.   INITIAL_FRAME_POINTER_OFFSET (reg_eliminate[0].initial_offset);
  2740.   reg_eliminate[0].previous_offset
  2741.     = reg_eliminate[0].offset = reg_eliminate[0].initial_offset;
  2742. #endif
  2743.  
  2744.   /* If a pseudo has no hard reg, delete the insns that made the equivalence.
  2745.      If that insn didn't set the register (i.e., it copied the register to
  2746.      memory), just delete that insn instead of the equivalencing insn plus
  2747.      anything now dead.  If we call delete_dead_insn on that insn, we may
  2748.      delete the insn that actually sets the register if the register die
  2749.      there and that is incorrect.  */
  2750.  
  2751.   for (i = FIRST_PSEUDO_REGISTER; i < max_regno; i++)
  2752.     if (reg_renumber[i] < 0 && reg_equiv_init[i] != 0
  2753.     && GET_CODE (reg_equiv_init[i]) != NOTE)
  2754.       {
  2755.     if (reg_set_p (regno_reg_rtx[i], PATTERN (reg_equiv_init[i])))
  2756.       delete_dead_insn (reg_equiv_init[i]);
  2757.     else
  2758.       {
  2759.         PUT_CODE (reg_equiv_init[i], NOTE);
  2760.         NOTE_SOURCE_FILE (reg_equiv_init[i]) = 0;
  2761.         NOTE_LINE_NUMBER (reg_equiv_init[i]) = NOTE_INSN_DELETED;
  2762.       }
  2763.       }
  2764.  
  2765.   num_not_at_initial_offset = 0;
  2766.  
  2767.   for (insn = first; insn;)
  2768.     {
  2769.       register rtx next = NEXT_INSN (insn);
  2770.  
  2771.       /* Notice when we move to a new basic block.  */
  2772.       if (live_known && basic_block_needs && this_block + 1 < n_basic_blocks
  2773.       && insn == basic_block_head[this_block+1])
  2774.     ++this_block;
  2775.  
  2776.       if (GET_CODE (insn) == INSN || GET_CODE (insn) == JUMP_INSN
  2777.       || GET_CODE (insn) == CALL_INSN)
  2778.     {
  2779.       rtx avoid_return_reg = 0;
  2780.  
  2781. #ifdef SMALL_REGISTER_CLASSES
  2782.       /* Set avoid_return_reg if this is an insn
  2783.          that might use the value of a function call.  */
  2784.       if (GET_CODE (insn) == CALL_INSN)
  2785.         {
  2786.           if (GET_CODE (PATTERN (insn)) == SET)
  2787.         after_call = SET_DEST (PATTERN (insn));
  2788.           else if (GET_CODE (PATTERN (insn)) == PARALLEL
  2789.                && GET_CODE (XVECEXP (PATTERN (insn), 0, 0)) == SET)
  2790.         after_call = SET_DEST (XVECEXP (PATTERN (insn), 0, 0));
  2791.           else
  2792.         after_call = 0;
  2793.         }
  2794.       else if (after_call != 0
  2795.            && !(GET_CODE (PATTERN (insn)) == SET
  2796.             && SET_DEST (PATTERN (insn)) == stack_pointer_rtx))
  2797.         {
  2798.           if (reg_mentioned_p (after_call, PATTERN (insn)))
  2799.         avoid_return_reg = after_call;
  2800.           after_call = 0;
  2801.         }
  2802. #endif /* SMALL_REGISTER_CLASSES */
  2803.  
  2804.       /* If we need to do register elimination processing, do so.
  2805.          This might delete the insn, in which case we are done.  */
  2806.       if (num_eliminable && GET_MODE (insn) == QImode)
  2807.         {
  2808.           eliminate_regs_in_insn (insn, 1);
  2809.           if (GET_CODE (insn) == NOTE)
  2810.         {
  2811.           insn = next;
  2812.           continue;
  2813.         }
  2814.         }
  2815.  
  2816.       if (GET_MODE (insn) == VOIDmode)
  2817.         n_reloads = 0;
  2818.       /* First find the pseudo regs that must be reloaded for this insn.
  2819.          This info is returned in the tables reload_... (see reload.h).
  2820.          Also modify the body of INSN by substituting RELOAD
  2821.          rtx's for those pseudo regs.  */
  2822.       else
  2823.         {
  2824.           bzero (reg_has_output_reload, max_regno);
  2825.           CLEAR_HARD_REG_SET (reg_is_output_reload);
  2826.  
  2827.           find_reloads (insn, 1, spill_indirect_levels, live_known,
  2828.                 spill_reg_order);
  2829.         }
  2830.  
  2831.       if (n_reloads > 0)
  2832.         {
  2833.           int class;
  2834.  
  2835.           /* If this block has not had spilling done for a
  2836.          particular class, deactivate any optional reloads 
  2837.          of that class lest they try to use a spill-reg which isn't
  2838.          available here.  If we have any non-optionals that need a
  2839.          spill reg, abort.  */
  2840.  
  2841.           for (class = 0; class < N_REG_CLASSES; class++)
  2842.         if (basic_block_needs[class] != 0
  2843.             && basic_block_needs[class][this_block] == 0)
  2844.           for (i = 0; i < n_reloads; i++)
  2845.             if (class == (int) reload_reg_class[i])
  2846.               {
  2847.             if (reload_optional[i])
  2848.               reload_in[i] = reload_out[i] = reload_reg_rtx[i] = 0;
  2849.             else if (reload_reg_rtx[i] == 0)
  2850.               abort ();
  2851.               }
  2852.  
  2853.           /* Now compute which reload regs to reload them into.  Perhaps
  2854.          reusing reload regs from previous insns, or else output
  2855.          load insns to reload them.  Maybe output store insns too.
  2856.          Record the choices of reload reg in reload_reg_rtx.  */
  2857.           choose_reload_regs (insn, avoid_return_reg);
  2858.  
  2859.           /* Generate the insns to reload operands into or out of
  2860.          their reload regs.  */
  2861.           emit_reload_insns (insn);
  2862.  
  2863.           /* Substitute the chosen reload regs from reload_reg_rtx
  2864.          into the insn's body (or perhaps into the bodies of other
  2865.          load and store insn that we just made for reloading
  2866.          and that we moved the structure into).  */
  2867.           subst_reloads ();
  2868.         }
  2869.       /* Any previously reloaded spilled pseudo reg, stored in this insn,
  2870.          is no longer validly lying around to save a future reload.
  2871.          Note that this does not detect pseudos that were reloaded
  2872.          for this insn in order to be stored in
  2873.          (obeying register constraints).  That is correct; such reload
  2874.          registers ARE still valid.  */
  2875.       note_stores (PATTERN (insn), forget_old_reloads_1);
  2876.  
  2877. #ifdef AUTO_INC_DEC
  2878.       /* Likewise for regs altered by auto-increment in this insn.
  2879.          But note that the reg-notes are not changed by reloading:
  2880.          they still contain the pseudo-regs, not the spill regs.  */
  2881.       for (x = REG_NOTES (insn); x; x = XEXP (x, 1))
  2882.         if (REG_NOTE_KIND (x) == REG_INC)
  2883.           {
  2884.         /* See if this pseudo reg was reloaded in this insn.
  2885.            If so, its last-reload info is still valid
  2886.            because it is based on this insn's reload.  */
  2887.         for (i = 0; i < n_reloads; i++)
  2888.           if (reload_out[i] == XEXP (x, 0))
  2889.             break;
  2890.  
  2891.         if (i != n_reloads)
  2892.           forget_old_reloads_1 (XEXP (x, 0));
  2893.           }
  2894. #endif
  2895.     }
  2896.       /* A reload reg's contents are unknown after a label.  */
  2897.       if (GET_CODE (insn) == CODE_LABEL)
  2898.     for (i = 0; i < n_spills; i++)
  2899.       {
  2900.         reg_reloaded_contents[i] = -1;
  2901.         reg_reloaded_insn[i] = 0;
  2902.       }
  2903.  
  2904.       /* Don't assume a reload reg is still good after a call insn
  2905.      if it is a call-used reg.  */
  2906.       if (GET_CODE (insn) == CODE_LABEL || GET_CODE (insn) == CALL_INSN)
  2907.     for (i = 0; i < n_spills; i++)
  2908.       if (call_used_regs[spill_regs[i]])
  2909.         {
  2910.           reg_reloaded_contents[i] = -1;
  2911.           reg_reloaded_insn[i] = 0;
  2912.         }
  2913.  
  2914.       /* In case registers overlap, allow certain insns to invalidate
  2915.      particular hard registers.  */
  2916.  
  2917. #ifdef INSN_CLOBBERS_REGNO_P
  2918.       for (i = 0 ; i < n_spills ; i++)
  2919.     if (INSN_CLOBBERS_REGNO_P (insn, spill_regs[i]))
  2920.       {
  2921.         reg_reloaded_contents[i] = -1;
  2922.         reg_reloaded_insn[i] = 0;
  2923.       }
  2924. #endif
  2925.  
  2926.       insn = next;
  2927.  
  2928. #ifdef USE_C_ALLOCA
  2929.       alloca (0);
  2930. #endif
  2931.     }
  2932.  
  2933.   reload_in_progress = 0;
  2934. }
  2935.  
  2936. /* Discard all record of any value reloaded from X,
  2937.    or reloaded in X from someplace else;
  2938.    unless X is an output reload reg of the current insn.
  2939.  
  2940.    X may be a hard reg (the reload reg)
  2941.    or it may be a pseudo reg that was reloaded from.  */
  2942.  
  2943. static void
  2944. forget_old_reloads_1 (x)
  2945.      rtx x;
  2946. {
  2947.   register int regno;
  2948.   int nr;
  2949.  
  2950.   if (GET_CODE (x) != REG)
  2951.     return;
  2952.  
  2953.   regno = REGNO (x);
  2954.  
  2955.   if (regno >= FIRST_PSEUDO_REGISTER)
  2956.     nr = 1;
  2957.   else
  2958.     {
  2959.       int i;
  2960.       nr = HARD_REGNO_NREGS (regno, GET_MODE (x));
  2961.       /* Storing into a spilled-reg invalidates its contents.
  2962.      This can happen if a block-local pseudo is allocated to that reg
  2963.      and it wasn't spilled because this block's total need is 0.
  2964.      Then some insn might have an optional reload and use this reg.  */
  2965.       for (i = 0; i < nr; i++)
  2966.     if (spill_reg_order[regno + i] >= 0
  2967.         /* But don't do this if the reg actually serves as an output
  2968.            reload reg in the current instruction.  */
  2969.         && (n_reloads == 0
  2970.         || ! TEST_HARD_REG_BIT (reg_is_output_reload, regno + i)))
  2971.       {
  2972.         reg_reloaded_contents[spill_reg_order[regno + i]] = -1;
  2973.         reg_reloaded_insn[spill_reg_order[regno + i]] = 0;
  2974.       }
  2975.     }
  2976.  
  2977.   /* Since value of X has changed,
  2978.      forget any value previously copied from it.  */
  2979.  
  2980.   while (nr-- > 0)
  2981.     /* But don't forget a copy if this is the output reload
  2982.        that establishes the copy's validity.  */
  2983.     if (n_reloads == 0 || reg_has_output_reload[regno + nr] == 0)
  2984.       reg_last_reload_reg[regno + nr] = 0;
  2985. }
  2986.  
  2987. /* For each reload, the mode of the reload register.  */
  2988. static enum machine_mode reload_mode[MAX_RELOADS];
  2989.  
  2990. /* For each reload, the largest number of registers it will require.  */
  2991. static int reload_nregs[MAX_RELOADS];
  2992.  
  2993. /* Comparison function for qsort to decide which of two reloads
  2994.    should be handled first.  *P1 and *P2 are the reload numbers.  */
  2995.  
  2996. static int
  2997. reload_reg_class_lower (p1, p2)
  2998.      short *p1, *p2;
  2999. {
  3000.   register int r1 = *p1, r2 = *p2;
  3001.   register int t;
  3002.   
  3003.   /* Consider required reloads before optional ones.  */
  3004.   t = reload_optional[r1] - reload_optional[r2];
  3005.   if (t != 0)
  3006.     return t;
  3007.  
  3008.   /* Count all solitary classes before non-solitary ones.  */
  3009.   t = ((reg_class_size[(int) reload_reg_class[r2]] == 1)
  3010.        - (reg_class_size[(int) reload_reg_class[r1]] == 1));
  3011.   if (t != 0)
  3012.     return t;
  3013.  
  3014.   /* Aside from solitaires, consider all multi-reg groups first.  */
  3015.   t = reload_nregs[r2] - reload_nregs[r1];
  3016.   if (t != 0)
  3017.     return t;
  3018.  
  3019.   /* Consider reloads in order of increasing reg-class number.  */
  3020.   t = (int) reload_reg_class[r1] - (int) reload_reg_class[r2];
  3021.   if (t != 0)
  3022.     return t;
  3023.  
  3024.   /* If reloads are equally urgent, sort by reload number,
  3025.      so that the results of qsort leave nothing to chance.  */
  3026.   return r1 - r2;
  3027. }
  3028.  
  3029. /* The following HARD_REG_SETs indicate when each hard register is
  3030.    used for a reload of various parts of the current insn.  */
  3031.  
  3032. /* If reg is in use as a reload reg for a RELOAD_OTHER reload.  */
  3033. static HARD_REG_SET reload_reg_used;
  3034. /* If reg is in use for a RELOAD_FOR_INPUT_RELOAD_ADDRESS reload.  */
  3035. static HARD_REG_SET reload_reg_used_in_input_addr;
  3036. /* If reg is in use for a RELOAD_FOR_OUTPUT_RELOAD_ADDRESS reload.  */
  3037. static HARD_REG_SET reload_reg_used_in_output_addr;
  3038. /* If reg is in use for a RELOAD_FOR_OPERAND_ADDRESS reload.  */
  3039. static HARD_REG_SET reload_reg_used_in_op_addr;
  3040. /* If reg is in use for a RELOAD_FOR_INPUT reload.  */
  3041. static HARD_REG_SET reload_reg_used_in_input;
  3042. /* If reg is in use for a RELOAD_FOR_OUTPUT reload.  */
  3043. static HARD_REG_SET reload_reg_used_in_output;
  3044.  
  3045. /* If reg is in use as a reload reg for any sort of reload.  */
  3046. static HARD_REG_SET reload_reg_used_at_all;
  3047.  
  3048. /* Mark reg REGNO as in use for a reload of the sort spec'd by WHEN_NEEDED.
  3049.    MODE is used to indicate how many consecutive regs are actually used.  */
  3050.  
  3051. static void
  3052. mark_reload_reg_in_use (regno, when_needed, mode)
  3053.      int regno;
  3054.      enum reload_when_needed when_needed;
  3055.      enum machine_mode mode;
  3056. {
  3057.   int nregs = HARD_REGNO_NREGS (regno, mode);
  3058.   int i;
  3059.  
  3060.   for (i = regno; i < nregs + regno; i++)
  3061.     {
  3062.       switch (when_needed)
  3063.     {
  3064.     case RELOAD_OTHER:
  3065.       SET_HARD_REG_BIT (reload_reg_used, i);
  3066.       break;
  3067.  
  3068.     case RELOAD_FOR_INPUT_RELOAD_ADDRESS:
  3069.       SET_HARD_REG_BIT (reload_reg_used_in_input_addr, i);
  3070.       break;
  3071.  
  3072.     case RELOAD_FOR_OUTPUT_RELOAD_ADDRESS:
  3073.       SET_HARD_REG_BIT (reload_reg_used_in_output_addr, i);
  3074.       break;
  3075.  
  3076.     case RELOAD_FOR_OPERAND_ADDRESS:
  3077.       SET_HARD_REG_BIT (reload_reg_used_in_op_addr, i);
  3078.       break;
  3079.  
  3080.     case RELOAD_FOR_INPUT:
  3081.       SET_HARD_REG_BIT (reload_reg_used_in_input, i);
  3082.       break;
  3083.  
  3084.     case RELOAD_FOR_OUTPUT:
  3085.       SET_HARD_REG_BIT (reload_reg_used_in_output, i);
  3086.       break;
  3087.     }
  3088.  
  3089.       SET_HARD_REG_BIT (reload_reg_used_at_all, i);
  3090.     }
  3091. }
  3092.  
  3093. /* 1 if reg REGNO is free as a reload reg for a reload of the sort
  3094.    specified by WHEN_NEEDED.  */
  3095.  
  3096. static int
  3097. reload_reg_free_p (regno, when_needed)
  3098.      int regno;
  3099.      enum reload_when_needed when_needed;
  3100. {
  3101.   /* In use for a RELOAD_OTHER means it's not available for anything.  */
  3102.   if (TEST_HARD_REG_BIT (reload_reg_used, regno))
  3103.     return 0;
  3104.   switch (when_needed)
  3105.     {
  3106.     case RELOAD_OTHER:
  3107.       /* In use for anything means not available for a RELOAD_OTHER.  */
  3108.       return ! TEST_HARD_REG_BIT (reload_reg_used_at_all, regno);
  3109.  
  3110.       /* The other kinds of use can sometimes share a register.  */
  3111.     case RELOAD_FOR_INPUT:
  3112.       return (! TEST_HARD_REG_BIT (reload_reg_used_in_input, regno)
  3113.           && ! TEST_HARD_REG_BIT (reload_reg_used_in_op_addr, regno)
  3114.           && ! TEST_HARD_REG_BIT (reload_reg_used_in_input_addr, regno));
  3115.     case RELOAD_FOR_INPUT_RELOAD_ADDRESS:
  3116.       return (! TEST_HARD_REG_BIT (reload_reg_used_in_input_addr, regno)
  3117.           && ! TEST_HARD_REG_BIT (reload_reg_used_in_input, regno));
  3118.     case RELOAD_FOR_OUTPUT_RELOAD_ADDRESS:
  3119.       return (! TEST_HARD_REG_BIT (reload_reg_used_in_output_addr, regno)
  3120.           && ! TEST_HARD_REG_BIT (reload_reg_used_in_output, regno));
  3121.     case RELOAD_FOR_OPERAND_ADDRESS:
  3122.       return (! TEST_HARD_REG_BIT (reload_reg_used_in_op_addr, regno)
  3123.           && ! TEST_HARD_REG_BIT (reload_reg_used_in_input, regno)
  3124.           && ! TEST_HARD_REG_BIT (reload_reg_used_in_output, regno));
  3125.     case RELOAD_FOR_OUTPUT:
  3126.       return (! TEST_HARD_REG_BIT (reload_reg_used_in_op_addr, regno)
  3127.           && ! TEST_HARD_REG_BIT (reload_reg_used_in_output_addr, regno)
  3128.           && ! TEST_HARD_REG_BIT (reload_reg_used_in_output, regno));
  3129.     }
  3130.   abort ();
  3131. }
  3132.  
  3133. /* Return 1 if the value in reload reg REGNO, as used by a reload
  3134.    needed for the part of the insn specified by WHEN_NEEDED,
  3135.    is not in use for a reload in any prior part of the insn.
  3136.  
  3137.    We can assume that the reload reg was already tested for availability
  3138.    at the time it is needed, and we should not check this again,
  3139.    in case the reg has already been marked in use.  */
  3140.  
  3141. static int
  3142. reload_reg_free_before_p (regno, when_needed)
  3143.      int regno;
  3144.      enum reload_when_needed when_needed;
  3145. {
  3146.   switch (when_needed)
  3147.     {
  3148.     case RELOAD_OTHER:
  3149.       /* Since a RELOAD_OTHER reload claims the reg for the entire insn,
  3150.      its use starts from the beginning, so nothing can use it earlier.  */
  3151.       return 1;
  3152.  
  3153.       /* If this use is for part of the insn,
  3154.      check the reg is not in use for any prior part.  */
  3155.     case RELOAD_FOR_OUTPUT_RELOAD_ADDRESS:
  3156.       if (TEST_HARD_REG_BIT (reload_reg_used_in_op_addr, regno))
  3157.     return 0;
  3158.     case RELOAD_FOR_OUTPUT:
  3159.       if (TEST_HARD_REG_BIT (reload_reg_used_in_input, regno))
  3160.     return 0;
  3161.     case RELOAD_FOR_OPERAND_ADDRESS:
  3162.       if (TEST_HARD_REG_BIT (reload_reg_used_in_input_addr, regno))
  3163.     return 0;
  3164.     case RELOAD_FOR_INPUT_RELOAD_ADDRESS:
  3165.     case RELOAD_FOR_INPUT:
  3166.       return 1;
  3167.     }
  3168.   abort ();
  3169. }
  3170.  
  3171. /* Return 1 if the value in reload reg REGNO, as used by a reload
  3172.    needed for the part of the insn specified by WHEN_NEEDED,
  3173.    is still available in REGNO at the end of the insn.
  3174.  
  3175.    We can assume that the reload reg was already tested for availability
  3176.    at the time it is needed, and we should not check this again,
  3177.    in case the reg has already been marked in use.  */
  3178.  
  3179. static int
  3180. reload_reg_reaches_end_p (regno, when_needed)
  3181.      int regno;
  3182.      enum reload_when_needed when_needed;
  3183. {
  3184.   switch (when_needed)
  3185.     {
  3186.     case RELOAD_OTHER:
  3187.       /* Since a RELOAD_OTHER reload claims the reg for the entire insn,
  3188.      its value must reach the end.  */
  3189.       return 1;
  3190.  
  3191.       /* If this use is for part of the insn,
  3192.      its value reaches if no subsequent part uses the same register.  */
  3193.     case RELOAD_FOR_INPUT_RELOAD_ADDRESS:
  3194.     case RELOAD_FOR_INPUT:
  3195.       if (TEST_HARD_REG_BIT (reload_reg_used_in_op_addr, regno)
  3196.       || TEST_HARD_REG_BIT (reload_reg_used_in_output, regno))
  3197.     return 0;
  3198.     case RELOAD_FOR_OPERAND_ADDRESS:
  3199.       if (TEST_HARD_REG_BIT (reload_reg_used_in_output_addr, regno))
  3200.     return 0;
  3201.     case RELOAD_FOR_OUTPUT:
  3202.     case RELOAD_FOR_OUTPUT_RELOAD_ADDRESS:
  3203.       return 1;
  3204.     }
  3205.   abort ();
  3206. }
  3207.  
  3208. /* Vector of reload-numbers showing the order in which the reloads should
  3209.    be processed.  */
  3210. short reload_order[MAX_RELOADS];
  3211.  
  3212. /* Indexed by reload number, 1 if incoming value
  3213.    inherited from previous insns.  */
  3214. char reload_inherited[MAX_RELOADS];
  3215.  
  3216. /* For an inherited reload, this is the insn the reload was inherited from,
  3217.    if we know it.  Otherwise, this is 0.  */
  3218. rtx reload_inheritance_insn[MAX_RELOADS];
  3219.  
  3220. /* If non-zero, this is a place to get the value of the reload,
  3221.    rather than using reload_in.  */
  3222. rtx reload_override_in[MAX_RELOADS];
  3223.  
  3224. /* For each reload, the index in spill_regs of the spill register used,
  3225.    or -1 if we did not need one of the spill registers for this reload.  */
  3226. int reload_spill_index[MAX_RELOADS];
  3227.  
  3228. /* Index of last register assigned as a spill register.  We allocate in
  3229.    a round-robin fashio.  */
  3230.  
  3231. static last_spill_reg = 0;
  3232.  
  3233. /* Find a spill register to use as a reload register for reload R.
  3234.    LAST_RELOAD is non-zero if this is the last reload for the insn being
  3235.    processed.
  3236.  
  3237.    Set reload_reg_rtx[R] to the register allocated.
  3238.  
  3239.    If NOERROR is nonzero, we return 1 if successful,
  3240.    or 0 if we couldn't find a spill reg and we didn't change anything.  */
  3241.  
  3242. static int
  3243. allocate_reload_reg (r, insn, last_reload, noerror)
  3244.      int r;
  3245.      rtx insn;
  3246.      int last_reload;
  3247.      int noerror;
  3248. {
  3249.   int i;
  3250.   int pass;
  3251.   int count;
  3252.   rtx new;
  3253.   int regno;
  3254.  
  3255.   /* If we put this reload ahead, thinking it is a group,
  3256.      then insist on finding a group.  Otherwise we can grab a
  3257.      reg that some other reload needs. 
  3258.      (That can happen when we have a 68000 DATA_OR_FP_REG
  3259.      which is a group of data regs or one fp reg.)
  3260.      We need not be so restrictive if there are no more reloads
  3261.      for this insn.
  3262.  
  3263.      ??? Really it would be nicer to have smarter handling
  3264.      for that kind of reg class, where a problem like this is normal.
  3265.      Perhaps those classes should be avoided for reloading
  3266.      by use of more alternatives.  */
  3267.  
  3268.   int force_group = reload_nregs[r] > 1 && ! last_reload;
  3269.  
  3270.   /* If we want a single register and haven't yet found one,
  3271.      take any reg in the right class and not in use.
  3272.      If we want a consecutive group, here is where we look for it.
  3273.  
  3274.      We use two passes so we can first look for reload regs to
  3275.      reuse, which are already in use for other reloads in this insn,
  3276.      and only then use additional registers.
  3277.      I think that maximizing reuse is needed to make sure we don't
  3278.      run out of reload regs.  Suppose we have three reloads, and
  3279.      reloads A and B can share regs.  These need two regs.
  3280.      Suppose A and B are given different regs.
  3281.      That leaves none for C.  */
  3282.   for (pass = 0; pass < 2; pass++)
  3283.     {
  3284.       /* I is the index in spill_regs.
  3285.      We advance it round-robin between insns to use all spill regs
  3286.      equally, so that inherited reloads have a chance
  3287.      of leapfrogging each other.  */
  3288.  
  3289.       for (count = 0, i = last_spill_reg; count < n_spills; count++)
  3290.     {
  3291.       int class = (int) reload_reg_class[r];
  3292.  
  3293.       i = (i + 1) % n_spills;
  3294.  
  3295.       if (reload_reg_free_p (spill_regs[i], reload_when_needed[r])
  3296.           && TEST_HARD_REG_BIT (reg_class_contents[class], spill_regs[i])
  3297.           && HARD_REGNO_MODE_OK (spill_regs[i], reload_mode[r])
  3298.           /* Look first for regs to share, then for unshared.  */
  3299.           && (pass || TEST_HARD_REG_BIT (reload_reg_used_at_all,
  3300.                          spill_regs[i])))
  3301.         {
  3302.           int nr = HARD_REGNO_NREGS (spill_regs[i], reload_mode[r]);
  3303.           /* Avoid the problem where spilling a GENERAL_OR_FP_REG
  3304.          (on 68000) got us two FP regs.  If NR is 1,
  3305.          we would reject both of them.  */
  3306.           if (force_group)
  3307.         nr = CLASS_MAX_NREGS (reload_reg_class[r], reload_mode[r]);
  3308.           /* If we need only one reg, we have already won.  */
  3309.           if (nr == 1)
  3310.         {
  3311.           /* But reject a single reg if we demand a group.  */
  3312.           if (force_group)
  3313.             continue;
  3314.           break;
  3315.         }
  3316.           /* Otherwise check that as many consecutive regs as we need
  3317.          are available here.
  3318.          Also, don't use for a group registers that are
  3319.          needed for nongroups.  */
  3320.           if (! TEST_HARD_REG_BIT (counted_for_nongroups, spill_regs[i]))
  3321.         while (nr > 1)
  3322.           {
  3323.             regno = spill_regs[i] + nr - 1;
  3324.             if (!(TEST_HARD_REG_BIT (reg_class_contents[class], regno)
  3325.               && spill_reg_order[regno] >= 0
  3326.               && reload_reg_free_p (regno, reload_when_needed[r])
  3327.               && ! TEST_HARD_REG_BIT (counted_for_nongroups,
  3328.                           regno)))
  3329.               break;
  3330.             nr--;
  3331.           }
  3332.           if (nr == 1)
  3333.         break;
  3334.         }
  3335.     }
  3336.  
  3337.       /* If we found something on pass 1, omit pass 2.  */
  3338.       if (count < n_spills)
  3339.     break;
  3340.     }
  3341.  
  3342.   /* We should have found a spill register by now.  */
  3343.   if (count == n_spills)
  3344.     {
  3345.       if (noerror)
  3346.     return 0;
  3347.       abort ();
  3348.     }
  3349.  
  3350.   last_spill_reg = i;
  3351.  
  3352.   /* Mark as in use for this insn the reload regs we use for this.  */
  3353.   mark_reload_reg_in_use (spill_regs[i], reload_when_needed[r],
  3354.               reload_mode[r]);
  3355.  
  3356.   new = spill_reg_rtx[i];
  3357.  
  3358.   if (new == 0 || GET_MODE (new) != reload_mode[r])
  3359.     spill_reg_rtx[i] = new = gen_rtx (REG, reload_mode[r], spill_regs[i]);
  3360.  
  3361.   reload_reg_rtx[r] = new;
  3362.   reload_spill_index[r] = i;
  3363.   regno = true_regnum (new);
  3364.  
  3365.   /* Detect when the reload reg can't hold the reload mode.
  3366.      This used to be one `if', but Sequent compiler can't handle that.  */
  3367.   if (HARD_REGNO_MODE_OK (regno, reload_mode[r]))
  3368.     {
  3369.       enum machine_mode test_mode = VOIDmode;
  3370.       if (reload_in[r])
  3371.     test_mode = GET_MODE (reload_in[r]);
  3372.       if (test_mode == VOIDmode)
  3373.     test_mode = SImode;
  3374.       if (! (reload_in[r] != 0
  3375.          && ! HARD_REGNO_MODE_OK (regno, test_mode)))
  3376.     if (! (reload_out[r] != 0
  3377.            && ! HARD_REGNO_MODE_OK (regno, GET_MODE (reload_out[r]))))
  3378.       /* The reg is OK.  */
  3379.       return 1;
  3380.     }
  3381.  
  3382.   /* The reg is not OK.  */
  3383.   if (noerror)
  3384.     return 0;
  3385.  
  3386.   if (asm_noperands (PATTERN (insn)) < 0)
  3387.     /* It's the compiler's fault.  */
  3388.     abort ();
  3389.  
  3390.   /* It's the user's fault; the operand's mode and constraint
  3391.      don't match.  Disable this reload so we don't crash in final.  */
  3392.   error_for_asm (insn,
  3393.          "`asm' operand constraint incompatible with operand size");
  3394.   reload_in[r] = 0;
  3395.   reload_out[r] = 0;
  3396.   reload_reg_rtx[r] = 0;
  3397.   reload_optional[r] = 1;
  3398.   reload_secondary_p[r] = 1;
  3399.  
  3400.   return 1;
  3401. }
  3402.  
  3403. /* Assign hard reg targets for the pseudo-registers we must reload
  3404.    into hard regs for this insn.
  3405.    Also output the instructions to copy them in and out of the hard regs.
  3406.  
  3407.    For machines with register classes, we are responsible for
  3408.    finding a reload reg in the proper class.  */
  3409.  
  3410. static void
  3411. choose_reload_regs (insn, avoid_return_reg)
  3412.      rtx insn;
  3413.      /* This argument is currently ignored.  */
  3414.      rtx avoid_return_reg;
  3415. {
  3416.   register int i, j;
  3417.   int max_group_size = 1;
  3418.   enum reg_class group_class = NO_REGS;
  3419.   int inheritance;
  3420.  
  3421.   rtx save_reload_reg_rtx[MAX_RELOADS];
  3422.   char save_reload_inherited[MAX_RELOADS];
  3423.   rtx save_reload_inheritance_insn[MAX_RELOADS];
  3424.   rtx save_reload_override_in[MAX_RELOADS];
  3425.   int save_reload_spill_index[MAX_RELOADS];
  3426.   HARD_REG_SET save_reload_reg_used;
  3427.   HARD_REG_SET save_reload_reg_used_in_input_addr;
  3428.   HARD_REG_SET save_reload_reg_used_in_output_addr;
  3429.   HARD_REG_SET save_reload_reg_used_in_op_addr;
  3430.   HARD_REG_SET save_reload_reg_used_in_input;
  3431.   HARD_REG_SET save_reload_reg_used_in_output;
  3432.   HARD_REG_SET save_reload_reg_used_at_all;
  3433.  
  3434.   bzero (reload_inherited, MAX_RELOADS);
  3435.   bzero (reload_inheritance_insn, MAX_RELOADS * sizeof (rtx));
  3436.   bzero (reload_override_in, MAX_RELOADS * sizeof (rtx));
  3437.  
  3438.   CLEAR_HARD_REG_SET (reload_reg_used);
  3439.   CLEAR_HARD_REG_SET (reload_reg_used_at_all);
  3440.   CLEAR_HARD_REG_SET (reload_reg_used_in_input_addr);
  3441.   CLEAR_HARD_REG_SET (reload_reg_used_in_output_addr);
  3442.   CLEAR_HARD_REG_SET (reload_reg_used_in_op_addr);
  3443.   CLEAR_HARD_REG_SET (reload_reg_used_in_output);
  3444.   CLEAR_HARD_REG_SET (reload_reg_used_in_input);
  3445.  
  3446.   /* Distinguish output-only and input-only reloads
  3447.      because they can overlap with other things.  */
  3448.   for (j = 0; j < n_reloads; j++)
  3449.     if (reload_when_needed[j] == RELOAD_OTHER
  3450.     && ! reload_needed_for_multiple[j])
  3451.       {
  3452.     if (reload_in[j] == 0)
  3453.       {
  3454.         /* But earlyclobber operands must stay as RELOAD_OTHER.  */
  3455.         for (i = 0; i < n_earlyclobbers; i++)
  3456.           if (rtx_equal_p (reload_out[j], reload_earlyclobbers[i]))
  3457.         break;
  3458.         if (i == n_earlyclobbers)
  3459.           reload_when_needed[j] = RELOAD_FOR_OUTPUT;
  3460.       }
  3461.     if (reload_out[j] == 0)
  3462.       reload_when_needed[j] = RELOAD_FOR_INPUT;
  3463.  
  3464.     if (reload_secondary_reload[j] >= 0
  3465.         && ! reload_needed_for_multiple[reload_secondary_reload[j]])
  3466.       reload_when_needed[reload_secondary_reload[j]]
  3467.         = reload_when_needed[j];
  3468.       }
  3469.  
  3470. #ifdef SMALL_REGISTER_CLASSES
  3471.   /* Don't bother with avoiding the return reg
  3472.      if we have no mandatory reload that could use it.  */
  3473.   if (avoid_return_reg)
  3474.     {
  3475.       int do_avoid = 0;
  3476.       int regno = REGNO (avoid_return_reg);
  3477.       int nregs
  3478.     = HARD_REGNO_NREGS (regno, GET_MODE (avoid_return_reg));
  3479.       int r;
  3480.  
  3481.       for (r = regno; r < regno + nregs; r++)
  3482.     if (spill_reg_order[r] >= 0)
  3483.       for (j = 0; j < n_reloads; j++)
  3484.         if (!reload_optional[j] && reload_reg_rtx[j] == 0
  3485.         &&
  3486.         TEST_HARD_REG_BIT (reg_class_contents[(int) reload_reg_class[j]], r))
  3487.           do_avoid = 1;
  3488.       if (!do_avoid)
  3489.     avoid_return_reg = 0;
  3490.     }
  3491. #endif /* SMALL_REGISTER_CLASSES */
  3492.  
  3493. #if 0  /* Not needed, now that we can always retry without inheritance.  */
  3494.   /* See if we have more mandatory reloads than spill regs.
  3495.      If so, then we cannot risk optimizations that could prevent
  3496.      reloads from sharing one spill register. 
  3497.  
  3498.      Since we will try finding a better register than reload_reg_rtx
  3499.      unless it is equal to reload_in or reload_out, count such reloads.  */
  3500.  
  3501.   {
  3502.     int tem = 0;
  3503. #ifdef SMALL_REGISTER_CLASSES
  3504.     int tem = (avoid_return_reg != 0);
  3505. #endif 
  3506.     for (j = 0; j < n_reloads; j++)
  3507.       if (! reload_optional[j]
  3508.       && (reload_in[j] != 0 || reload_out[j] != 0 || reload_secondary_p[j])
  3509.       && (reload_reg_rtx[j] == 0
  3510.           || (! rtx_equal_p (reload_reg_rtx[j], reload_in[j])
  3511.           && ! rtx_equal_p (reload_reg_rtx[j], reload_out[j]))))
  3512.     tem++;
  3513.     if (tem > n_spills)
  3514.       must_reuse = 1;
  3515.   }
  3516. #endif
  3517.  
  3518. #ifdef SMALL_REGISTER_CLASSES
  3519.   /* Don't use the subroutine call return reg for a reload
  3520.      if we are supposed to avoid it.  */
  3521.   if (avoid_return_reg)
  3522.     {
  3523.       int regno = REGNO (avoid_return_reg);
  3524.       int nregs
  3525.     = HARD_REGNO_NREGS (regno, GET_MODE (avoid_return_reg));
  3526.       int r;
  3527.  
  3528.       for (r = regno; r < regno + nregs; r++)
  3529.     if (spill_reg_order[r] >= 0)
  3530.       SET_HARD_REG_BIT (reload_reg_used, r);
  3531.     }
  3532. #endif /* SMALL_REGISTER_CLASSES */
  3533.  
  3534.   /* In order to be certain of getting the registers we need,
  3535.      we must sort the reloads into order of increasing register class.
  3536.      Then our grabbing of reload registers will parallel the process
  3537.      that provided the reload registers. 
  3538.  
  3539.      Also note whether any of the reloads wants a consecutive group of regs.
  3540.      If so, record the maximum size of the group desired and what
  3541.      register class contains all the groups needed by this insn.  */
  3542.  
  3543.   for (j = 0; j < n_reloads; j++)
  3544.     {
  3545.       reload_order[j] = j;
  3546.       reload_spill_index[j] = -1;
  3547.  
  3548.       reload_mode[j]
  3549.     = (reload_strict_low[j] && reload_out[j]
  3550.        ? GET_MODE (SUBREG_REG (reload_out[j]))
  3551.        : (reload_inmode[j] == VOIDmode
  3552.           || (GET_MODE_SIZE (reload_outmode[j])
  3553.           > GET_MODE_SIZE (reload_inmode[j])))
  3554.        ? reload_outmode[j] : reload_inmode[j]);
  3555.  
  3556.       reload_nregs[j] = CLASS_MAX_NREGS (reload_reg_class[j], reload_mode[j]);
  3557.  
  3558.       if (reload_nregs[j] > 1)
  3559.     {
  3560.       max_group_size = max (reload_nregs[j], max_group_size);
  3561.       group_class = reg_class_superunion[(int)reload_reg_class[j]][(int)group_class];
  3562.     }
  3563.  
  3564.       /* If we have already decided to use a certain register,
  3565.      don't use it in another way.  */
  3566.       if (reload_reg_rtx[j])
  3567.     mark_reload_reg_in_use (REGNO (reload_reg_rtx[j]),
  3568.                 reload_when_needed[j], reload_mode[j]);
  3569.     }
  3570.  
  3571.   if (n_reloads > 1)
  3572.     qsort (reload_order, n_reloads, sizeof (short), reload_reg_class_lower);
  3573.  
  3574.   bcopy (reload_reg_rtx, save_reload_reg_rtx, sizeof reload_reg_rtx);
  3575.   bcopy (reload_inherited, save_reload_inherited, sizeof reload_inherited);
  3576.   bcopy (reload_inheritance_insn, save_reload_inheritance_insn,
  3577.      sizeof reload_inheritance_insn);
  3578.   bcopy (reload_override_in, save_reload_override_in,
  3579.      sizeof reload_override_in);
  3580.   bcopy (reload_spill_index, save_reload_spill_index,
  3581.      sizeof reload_spill_index);
  3582.   COPY_HARD_REG_SET (save_reload_reg_used, reload_reg_used);
  3583.   COPY_HARD_REG_SET (save_reload_reg_used_at_all, reload_reg_used_at_all);
  3584.   COPY_HARD_REG_SET (save_reload_reg_used_in_output,
  3585.              reload_reg_used_in_output);
  3586.   COPY_HARD_REG_SET (save_reload_reg_used_in_input,
  3587.              reload_reg_used_in_input);
  3588.   COPY_HARD_REG_SET (save_reload_reg_used_in_input_addr,
  3589.              reload_reg_used_in_input_addr);
  3590.   COPY_HARD_REG_SET (save_reload_reg_used_in_output_addr,
  3591.              reload_reg_used_in_output_addr);
  3592.   COPY_HARD_REG_SET (save_reload_reg_used_in_op_addr,
  3593.              reload_reg_used_in_op_addr);
  3594.  
  3595.   /* Try first with inheritance, then turning it off.  */
  3596.  
  3597.   for (inheritance = 1; inheritance >= 0; inheritance--)
  3598.     {
  3599.       /* Process the reloads in order of preference just found.
  3600.      Beyond this point, subregs can be found in reload_reg_rtx.
  3601.  
  3602.      This used to look for an existing reloaded home for all
  3603.      of the reloads, and only then perform any new reloads.
  3604.      But that could lose if the reloads were done out of reg-class order
  3605.      because a later reload with a looser constraint might have an old
  3606.      home in a register needed by an earlier reload with a tighter constraint.
  3607.  
  3608.      To solve this, we make two passes over the reloads, in the order
  3609.      described above.  In the first pass we try to inherit a reload
  3610.      from a previous insn.  If there is a later reload that needs a
  3611.      class that is a proper subset of the class being processed, we must
  3612.      also allocate a spill register during the first pass.
  3613.  
  3614.      Then make a second pass over the reloads to allocate any reloads
  3615.      that haven't been given registers yet.  */
  3616.  
  3617.       for (j = 0; j < n_reloads; j++)
  3618.     {
  3619.       register int r = reload_order[j];
  3620.  
  3621.       /* Ignore reloads that got marked inoperative.  */
  3622.       if (reload_out[r] == 0 && reload_in[r] == 0 && ! reload_secondary_p[r])
  3623.         continue;
  3624.  
  3625.       /* If find_reloads chose a to use reload_in or reload_out as a reload
  3626.          register, we don't need to chose one.  Otherwise, try even if it found
  3627.          one since we might save an insn if we find the value lying around.  */
  3628.       if (reload_in[r] != 0 && reload_reg_rtx[r] != 0
  3629.           && (rtx_equal_p (reload_in[r], reload_reg_rtx[r])
  3630.           || rtx_equal_p (reload_out[r], reload_reg_rtx[r])))
  3631.         continue;
  3632.  
  3633. #if 0 /* No longer needed for correct operation.
  3634.      It might give better code, or might not; worth an experiment?  */
  3635.       /* If this is an optional reload, we can't inherit from earlier insns
  3636.          until we are sure that any non-optional reloads have been allocated.
  3637.          The following code takes advantage of the fact that optional reloads
  3638.          are at the end of reload_order.  */
  3639.       if (reload_optional[r] != 0)
  3640.         for (i = 0; i < j; i++)
  3641.           if ((reload_out[reload_order[i]] != 0
  3642.            || reload_in[reload_order[i]] != 0
  3643.            || reload_secondary_p[reload_order[i]])
  3644.           && ! reload_optional[reload_order[i]]
  3645.           && reload_reg_rtx[reload_order[i]] == 0)
  3646.         allocate_reload_reg (reload_order[i], insn, 0, inheritance);
  3647. #endif
  3648.  
  3649.       /* First see if this pseudo is already available as reloaded
  3650.          for a previous insn.  We cannot try to inherit for reloads
  3651.          that are smaller than the maximum number of registers needed
  3652.          for groups unless the register we would allocate cannot be used
  3653.          for the groups.
  3654.  
  3655.          We could check here to see if this is a secondary reload for
  3656.          an object that is already in a register of the desired class.
  3657.          This would avoid the need for the secondary reload register.
  3658.          But this is complex because we can't easily determine what
  3659.          objects might want to be loaded via this reload.  So let a register
  3660.          be allocated here.  In `emit_reload_insns' we suppress one of the
  3661.          loads in the case described above.  */
  3662.  
  3663.       if (inheritance)
  3664.         {
  3665.           register int regno = -1;
  3666.  
  3667.           if (reload_in[r] == 0)
  3668.         ;
  3669.           else if (GET_CODE (reload_in[r]) == REG)
  3670.         regno = REGNO (reload_in[r]);
  3671.           else if (GET_CODE (reload_in_reg[r]) == REG)
  3672.         regno = REGNO (reload_in_reg[r]);
  3673. #if 0
  3674.           /* This won't work, since REGNO can be a pseudo reg number.
  3675.          Also, it takes much more hair to keep track of all the things
  3676.          that can invalidate an inherited reload of part of a pseudoreg.  */
  3677.           else if (GET_CODE (reload_in[r]) == SUBREG
  3678.                && GET_CODE (SUBREG_REG (reload_in[r])) == REG)
  3679.         regno = REGNO (SUBREG_REG (reload_in[r])) + SUBREG_WORD (reload_in[r]);
  3680. #endif
  3681.  
  3682.           if (regno >= 0 && reg_last_reload_reg[regno] != 0)
  3683.         {
  3684.           i = spill_reg_order[REGNO (reg_last_reload_reg[regno])];
  3685.  
  3686.           if (reg_reloaded_contents[i] == regno
  3687.               && HARD_REGNO_MODE_OK (spill_regs[i], reload_mode[r])
  3688.               && TEST_HARD_REG_BIT (reg_class_contents[(int) reload_reg_class[r]],
  3689.                         spill_regs[i])
  3690.               && (reload_nregs[r] == max_group_size
  3691.               || ! TEST_HARD_REG_BIT (reg_class_contents[(int) group_class],
  3692.                           spill_regs[i]))
  3693.               && reload_reg_free_p (spill_regs[i], reload_when_needed[r])
  3694.               && reload_reg_free_before_p (spill_regs[i],
  3695.                            reload_when_needed[r]))
  3696.             {
  3697.               /* Mark the register as in use for this part of the insn.  */
  3698.               mark_reload_reg_in_use (spill_regs[i], reload_when_needed[r],
  3699.                           reload_mode[r]);
  3700.               reload_reg_rtx[r] = reg_last_reload_reg[regno];
  3701.               reload_inherited[r] = 1;
  3702.               reload_inheritance_insn[r] = reg_reloaded_insn[i];
  3703.               reload_spill_index[r] = i;
  3704.             }
  3705.         }
  3706.         }
  3707.  
  3708.       /* Here's another way to see if the value is already lying around.  */
  3709.       if (inheritance
  3710.           && reload_in[r] != 0
  3711.           && ! reload_inherited[r]
  3712.           && reload_out[r] == 0
  3713.           && (CONSTANT_P (reload_in[r])
  3714.           || GET_CODE (reload_in[r]) == PLUS
  3715.           || GET_CODE (reload_in[r]) == REG
  3716.           || GET_CODE (reload_in[r]) == MEM)
  3717.           && (reload_nregs[r] == max_group_size
  3718.           || ! reg_classes_intersect_p (reload_reg_class[r], group_class)))
  3719.         {
  3720.           register rtx equiv
  3721.         = find_equiv_reg (reload_in[r], insn, reload_reg_class[r],
  3722.                   -1, 0, 0, reload_mode[r]);
  3723.           int regno;
  3724.  
  3725.           if (equiv != 0)
  3726.         {
  3727.           if (GET_CODE (equiv) == REG)
  3728.             regno = REGNO (equiv);
  3729.           else if (GET_CODE (equiv) == SUBREG)
  3730.             {
  3731.               regno = REGNO (SUBREG_REG (equiv));
  3732.               if (regno < FIRST_PSEUDO_REGISTER)
  3733.             regno += SUBREG_WORD (equiv);
  3734.             }
  3735.           else
  3736.             abort ();
  3737.         }
  3738.  
  3739.           /* If we found a spill reg, reject it unless it is free
  3740.          and of the desired class.  */
  3741.           if (equiv != 0
  3742.           && ((spill_reg_order[regno] >= 0
  3743.                && ! reload_reg_free_before_p (regno,
  3744.                               reload_when_needed[r]))
  3745.               || ! TEST_HARD_REG_BIT (reg_class_contents[(int) reload_reg_class[r]],
  3746.                           regno)))
  3747.         equiv = 0;
  3748.  
  3749.           if (equiv != 0 && TEST_HARD_REG_BIT (reload_reg_used_at_all, regno))
  3750.         equiv = 0;
  3751.  
  3752.           if (equiv != 0 && ! HARD_REGNO_MODE_OK (regno, reload_mode[r]))
  3753.         equiv = 0;
  3754.  
  3755.           /* We found a register that contains the value we need.
  3756.          If this register is the same as an `earlyclobber' operand
  3757.          of the current insn, just mark it as a place to reload from
  3758.          since we can't use it as the reload register itself.  */
  3759.  
  3760.           if (equiv != 0)
  3761.         for (i = 0; i < n_earlyclobbers; i++)
  3762.           if (reg_overlap_mentioned_p (equiv, reload_earlyclobbers[i]))
  3763.             {
  3764.               reload_override_in[r] = equiv;
  3765.               equiv = 0;
  3766.               break;
  3767.             }
  3768.  
  3769.           /* JRV: If the equiv register we have found is explicitly
  3770.          clobbered in the current insn, mark but don't use, as above. */
  3771.  
  3772.           if (equiv != 0 && regno_clobbered_p (regno, insn))
  3773.         {
  3774.           reload_override_in[r] = equiv;
  3775.           equiv = 0;
  3776.         }
  3777.  
  3778.           /* If we found an equivalent reg, say no code need be generated
  3779.          to load it, and use it as our reload reg.  */
  3780.           if (equiv != 0 && regno != FRAME_POINTER_REGNUM)
  3781.         {
  3782.           reload_reg_rtx[r] = equiv;
  3783.           reload_inherited[r] = 1;
  3784.           /* If it is a spill reg,
  3785.              mark the spill reg as in use for this insn.  */
  3786.           i = spill_reg_order[regno];
  3787.           if (i >= 0)
  3788.             mark_reload_reg_in_use (regno, reload_when_needed[r],
  3789.                         reload_mode[r]);
  3790.         }
  3791.         }
  3792.  
  3793.       /* If we found a register to use already, or if this is an optional
  3794.          reload, we are done.  */
  3795.       if (reload_reg_rtx[r] != 0 || reload_optional[r] != 0)
  3796.         continue;
  3797.  
  3798. #if 0 /* No longer needed for correct operation.  Might or might not
  3799.      give better code on the average.  Want to experiment?  */
  3800.  
  3801.       /* See if there is a later reload that has a class different from our
  3802.          class that intersects our class or that requires less register
  3803.          than our reload.  If so, we must allocate a register to this
  3804.          reload now, since that reload might inherit a previous reload
  3805.          and take the only available register in our class.  Don't do this
  3806.          for optional reloads since they will force all previous reloads
  3807.          to be allocated.  Also don't do this for reloads that have been
  3808.          turned off.  */
  3809.  
  3810.       for (i = j + 1; i < n_reloads; i++)
  3811.         {
  3812.           int s = reload_order[i];
  3813.  
  3814.           if ((reload_in[s] == 0 && reload_out[s] == 0 &&
  3815.            ! reload_secondary_p[s])
  3816.           || reload_optional[s])
  3817.         continue;
  3818.  
  3819.           if ((reload_reg_class[s] != reload_reg_class[r]
  3820.            && reg_classes_intersect_p (reload_reg_class[r],
  3821.                            reload_reg_class[s]))
  3822.           || reload_nregs[s] < reload_nregs[r])
  3823.           break;
  3824.         }
  3825.  
  3826.       if (i == n_reloads)
  3827.         continue;
  3828.  
  3829.       allocate_reload_reg (r, insn, j == n_reloads - 1, inheritance);
  3830. #endif
  3831.     }
  3832.  
  3833.       /* Now allocate reload registers for anything non-optional that
  3834.      didn't get one yet.  */
  3835.       for (j = 0; j < n_reloads; j++)
  3836.     {
  3837.       register int r = reload_order[j];
  3838.  
  3839.       /* Ignore reloads that got marked inoperative.  */
  3840.       if (reload_out[r] == 0 && reload_in[r] == 0 && ! reload_secondary_p[r])
  3841.         continue;
  3842.  
  3843.       /* Skip reloads that already have a register allocated or are
  3844.          optional. */
  3845.       if (reload_reg_rtx[r] != 0 || reload_optional[r])
  3846.         continue;
  3847.  
  3848.       if (! allocate_reload_reg (r, insn, j == n_reloads - 1, inheritance))
  3849.         break;
  3850.     }
  3851.  
  3852.       /* If that loop got all the way, we have won.  */
  3853.       if (j == n_reloads)
  3854.     break;
  3855.  
  3856.     fail:
  3857.       /* Loop around and try without any inheritance.  */
  3858.       /* First undo everything done by the failed attempt
  3859.      to allocate with inheritance.  */
  3860.       bcopy (save_reload_reg_rtx, reload_reg_rtx, sizeof reload_reg_rtx);
  3861.       bcopy (save_reload_inherited, reload_inherited, sizeof reload_inherited);
  3862.       bcopy (save_reload_inheritance_insn, reload_inheritance_insn,
  3863.          sizeof reload_inheritance_insn);
  3864.       bcopy (save_reload_override_in, reload_override_in,
  3865.          sizeof reload_override_in);
  3866.       bcopy (save_reload_spill_index, reload_spill_index,
  3867.          sizeof reload_spill_index);
  3868.       COPY_HARD_REG_SET (reload_reg_used, save_reload_reg_used);
  3869.       COPY_HARD_REG_SET (reload_reg_used_at_all, save_reload_reg_used_at_all);
  3870.       COPY_HARD_REG_SET (reload_reg_used_in_input,
  3871.              save_reload_reg_used_in_input);
  3872.       COPY_HARD_REG_SET (reload_reg_used_in_output,
  3873.              save_reload_reg_used_in_output);
  3874.       COPY_HARD_REG_SET (reload_reg_used_in_input_addr,
  3875.              save_reload_reg_used_in_input_addr);
  3876.       COPY_HARD_REG_SET (reload_reg_used_in_output_addr,
  3877.              save_reload_reg_used_in_output_addr);
  3878.       COPY_HARD_REG_SET (reload_reg_used_in_op_addr,
  3879.              save_reload_reg_used_in_op_addr);
  3880.     }
  3881.  
  3882.   /* If we thought we could inherit a reload, because it seemed that
  3883.      nothing else wanted the same reload register earlier in the insn,
  3884.      verify that assumption, now that all reloads have been assigned.  */
  3885.  
  3886.   for (j = 0; j < n_reloads; j++)
  3887.     {
  3888.       register int r = reload_order[j];
  3889.  
  3890.       if (reload_inherited[r] && reload_reg_rtx[r] != 0
  3891.       && ! reload_reg_free_before_p (true_regnum (reload_reg_rtx[r]),
  3892.                      reload_when_needed[r]))
  3893.     reload_inherited[r] = 0;
  3894.  
  3895.       /* If we found a better place to reload from,
  3896.      validate it in the same fashion, if it is a reload reg.  */
  3897.       if (reload_override_in[r]
  3898.       && (GET_CODE (reload_override_in[r]) == REG
  3899.           || GET_CODE (reload_override_in[r]) == SUBREG))
  3900.     {
  3901.       int regno = true_regnum (reload_override_in[r]);
  3902.       if (spill_reg_order[regno] >= 0
  3903.           && ! reload_reg_free_before_p (regno, reload_when_needed[r]))
  3904.         reload_override_in[r] = 0;
  3905.     }
  3906.     }
  3907.  
  3908.   /* Now that reload_override_in is known valid,
  3909.      actually override reload_in.  */
  3910.   for (j = 0; j < n_reloads; j++)
  3911.     if (reload_override_in[j])
  3912.       reload_in[j] = reload_override_in[j];
  3913.  
  3914.   /* If this reload won't be done because it has been cancelled or is
  3915.      optional and not inherited, clear reload_reg_rtx so other
  3916.      routines (such as subst_reloads) don't get confused.  */
  3917.   for (j = 0; j < n_reloads; j++)
  3918.     if ((reload_optional[j] && ! reload_inherited[j])
  3919.     || (reload_in[j] == 0 && reload_out[j] == 0
  3920.         && ! reload_secondary_p[j]))
  3921.       reload_reg_rtx[j] = 0;
  3922.  
  3923.   /* Record which pseudos and which spill regs have output reloads.  */
  3924.   for (j = 0; j < n_reloads; j++)
  3925.     {
  3926.       register int r = reload_order[j];
  3927.  
  3928.       i = reload_spill_index[r];
  3929.  
  3930.       /* I is nonneg if this reload used one of the spill regs.
  3931.      If reload_reg_rtx[r] is 0, this is an optional reload
  3932.      that we opted to ignore.  */
  3933.       if (reload_out[r] != 0 && GET_CODE (reload_out[r]) == REG
  3934.       && reload_reg_rtx[r] != 0)
  3935.     {
  3936.       register int nregno = REGNO (reload_out[r]);
  3937.       int nr = HARD_REGNO_NREGS (nregno, reload_mode[r]);
  3938.  
  3939.       while (--nr >= 0)
  3940.         {
  3941.           reg_has_output_reload[nregno + nr] = 1;
  3942.           if (i >= 0)
  3943.         SET_HARD_REG_BIT (reg_is_output_reload, spill_regs[i] + nr);
  3944.         }
  3945.  
  3946.       if (reload_when_needed[r] != RELOAD_OTHER
  3947.           && reload_when_needed[r] != RELOAD_FOR_OUTPUT)
  3948.         abort ();
  3949.     }
  3950.     }
  3951. }
  3952.  
  3953. /* Output insns to reload values in and out of the chosen reload regs.  */
  3954.  
  3955. static void
  3956. emit_reload_insns (insn)
  3957.      rtx insn;
  3958. {
  3959.   register int j;
  3960.   rtx following_insn = NEXT_INSN (insn);
  3961.   rtx first_output_reload_insn = NEXT_INSN (insn);
  3962.   rtx first_other_reload_insn = insn;
  3963.   rtx first_operand_address_reload_insn = insn;
  3964.   int special;
  3965.   /* Values to be put in spill_reg_store are put here first.  */
  3966.   rtx new_spill_reg_store[FIRST_PSEUDO_REGISTER];
  3967.  
  3968.   /* Now output the instructions to copy the data into and out of the
  3969.      reload registers.  Do these in the order that the reloads were reported,
  3970.      since reloads of base and index registers precede reloads of operands
  3971.      and the operands may need the base and index registers reloaded.  */
  3972.  
  3973.   for (j = 0; j < n_reloads; j++)
  3974.     {
  3975.       register rtx old;
  3976.       rtx oldequiv_reg = 0;
  3977.       rtx this_reload_insn = 0;
  3978.       rtx store_insn = 0;
  3979.  
  3980.       old = reload_in[j];
  3981.       if (old != 0 && ! reload_inherited[j]
  3982.       && ! rtx_equal_p (reload_reg_rtx[j], old)
  3983.       && reload_reg_rtx[j] != 0)
  3984.     {
  3985.       register rtx reloadreg = reload_reg_rtx[j];
  3986.       rtx oldequiv = 0;
  3987.       enum machine_mode mode;
  3988.       rtx where;
  3989.  
  3990.       /* Determine the mode to reload in.
  3991.          This is very tricky because we have three to choose from.
  3992.          There is the mode the insn operand wants (reload_inmode[J]).
  3993.          There is the mode of the reload register RELOADREG.
  3994.          There is the intrinsic mode of the operand, which we could find
  3995.          by stripping some SUBREGs.
  3996.          It turns out that RELOADREG's mode is irrelevant:
  3997.          we can change that arbitrarily.
  3998.  
  3999.          Consider (SUBREG:SI foo:QI) as an operand that must be SImode;
  4000.          then the reload reg may not support QImode moves, so use SImode.
  4001.          If foo is in memory due to spilling a pseudo reg, this is safe,
  4002.          because the QImode value is in the least significant part of a
  4003.          slot big enough for a SImode.  If foo is some other sort of
  4004.          memory reference, then it is impossible to reload this case,
  4005.          so previous passes had better make sure this never happens.
  4006.  
  4007.          Then consider a one-word union which has SImode and one of its
  4008.          members is a float, being fetched as (SUBREG:SF union:SI).
  4009.          We must fetch that as SFmode because we could be loading into
  4010.          a float-only register.  In this case OLD's mode is correct.
  4011.  
  4012.          Consider an immediate integer: it has VOIDmode.  Here we need
  4013.          to get a mode from something else.
  4014.  
  4015.          In some cases, there is a fourth mode, the operand's
  4016.          containing mode.  If the insn specifies a containing mode for
  4017.          this operand, it overrides all others.
  4018.  
  4019.          I am not sure whether the algorithm here is always right,
  4020.          but it does the right things in those cases.  */
  4021.  
  4022.       mode = GET_MODE (old);
  4023.       if (mode == VOIDmode)
  4024.         mode = reload_inmode[j];
  4025.       if (reload_strict_low[j])
  4026.         mode = GET_MODE (SUBREG_REG (reload_in[j]));
  4027.  
  4028. #ifdef SECONDARY_RELOAD_CLASS
  4029.       /* If we need a secondary register for this operation, see if
  4030.          the value is already in a register in that class.  */
  4031.       if (reload_secondary_reload[j] >= 0)
  4032.         oldequiv
  4033.           = find_equiv_reg (old, insn,
  4034.                 reload_reg_class[reload_secondary_reload[j]],
  4035.                 -1, 0, 0, mode);
  4036. #endif
  4037.  
  4038.       /* If reloading from memory, see if there is a register
  4039.          that already holds the same value.  If so, reload from there.
  4040.          We can pass 0 as the reload_reg_p argument because
  4041.          any other reload has either already been emitted,
  4042.          in which case find_equiv_reg will see the reload-insn,
  4043.          or has yet to be emitted, in which case it doesn't matter
  4044.          because we will use this equiv reg right away.  */
  4045.  
  4046.       if (oldequiv == 0
  4047.           && (GET_CODE (old) == MEM
  4048.           || (GET_CODE (old) == REG
  4049.               && REGNO (old) >= FIRST_PSEUDO_REGISTER
  4050.               && reg_renumber[REGNO (old)] < 0)))
  4051.         oldequiv = find_equiv_reg (old, insn, GENERAL_REGS,
  4052.                        -1, 0, 0, mode);
  4053.  
  4054.       if (oldequiv)
  4055.         {
  4056.           int regno = true_regnum (oldequiv);
  4057.  
  4058.           /* If OLDEQUIV is a spill register, don't use it for this
  4059.          if any other reload needs it at an earlier stage of this insn
  4060.          or at this stage.  */       
  4061.           if (spill_reg_order[regno] >= 0
  4062.           && (! reload_reg_free_p (regno, reload_when_needed[j])
  4063.               || ! reload_reg_free_before_p (regno,
  4064.                              reload_when_needed[j])))
  4065.         oldequiv = 0;
  4066.  
  4067.           /* If OLDEQUIV is not a spill register,
  4068.          don't use it if any other reload wants it.  */
  4069.           if (spill_reg_order[regno] < 0)
  4070.         {
  4071.           int k;
  4072.           for (k = 0; k < n_reloads; k++)
  4073.             if (reload_reg_rtx[k] != 0 && k != j
  4074.             && reg_overlap_mentioned_p (reload_reg_rtx[k], oldequiv))
  4075.               {
  4076.             oldequiv = 0;
  4077.             break;
  4078.               }
  4079.         }
  4080.         }
  4081.  
  4082.       if (oldequiv == 0)
  4083.         oldequiv = old;
  4084.       else if (GET_CODE (oldequiv) == REG)
  4085.         oldequiv_reg = oldequiv;
  4086.       else if (GET_CODE (oldequiv) == SUBREG)
  4087.         oldequiv_reg = SUBREG_REG (oldequiv);
  4088.  
  4089.       /* Encapsulate both RELOADREG and OLDEQUIV into that mode,
  4090.          then load RELOADREG from OLDEQUIV.  */
  4091.  
  4092.       if (GET_MODE (reloadreg) != mode)
  4093.         reloadreg = gen_rtx (REG, mode, REGNO (reloadreg));
  4094.       while (GET_CODE (oldequiv) == SUBREG && GET_MODE (oldequiv) != mode)
  4095.         oldequiv = SUBREG_REG (oldequiv);
  4096.       if (GET_MODE (oldequiv) != VOIDmode
  4097.           && mode != GET_MODE (oldequiv))
  4098.         oldequiv = gen_rtx (SUBREG, mode, oldequiv, 0);
  4099.  
  4100.       /* Decide where to put reload insn for this reload.  */
  4101.       switch (reload_when_needed[j])
  4102.         {
  4103.         case RELOAD_FOR_INPUT:
  4104.         case RELOAD_OTHER:
  4105.           where = first_operand_address_reload_insn;
  4106.           break;
  4107.         case RELOAD_FOR_INPUT_RELOAD_ADDRESS:
  4108.           where = first_other_reload_insn;
  4109.           break;
  4110.         case RELOAD_FOR_OUTPUT_RELOAD_ADDRESS:
  4111.           where = first_output_reload_insn;
  4112.           break;
  4113.         case RELOAD_FOR_OPERAND_ADDRESS:
  4114.           where = insn;
  4115.         }
  4116.  
  4117.       special = 0;
  4118.  
  4119.       /* Auto-increment addresses must be reloaded in a special way.  */
  4120.       if (GET_CODE (oldequiv) == POST_INC
  4121.           || GET_CODE (oldequiv) == POST_DEC
  4122.           || GET_CODE (oldequiv) == PRE_INC
  4123.           || GET_CODE (oldequiv) == PRE_DEC)
  4124.         {
  4125.           /* We are not going to bother supporting the case where a
  4126.          incremented register can't be copied directly from
  4127.          OLDEQUIV since this seems highly unlikely.  */
  4128.           if (reload_secondary_reload[j] >= 0)
  4129.         abort ();
  4130.           /* Prevent normal processing of this reload.  */
  4131.           special = 1;
  4132.           /* Output a special code sequence for this case.  */
  4133.           this_reload_insn
  4134.         = inc_for_reload (reloadreg, oldequiv, reload_inc[j], where);
  4135.         }
  4136.  
  4137.       /* If we are reloading a pseudo-register that was set by the previous
  4138.          insn, see if we can get rid of that pseudo-register entirely
  4139.          by redirecting the previous insn into our reload register.  */
  4140.  
  4141.       else if (optimize && GET_CODE (old) == REG
  4142.            && REGNO (old) >= FIRST_PSEUDO_REGISTER
  4143.            && dead_or_set_p (insn, old)
  4144.            /* This is unsafe if some other reload
  4145.               uses the same reg first.  */
  4146.            && (reload_when_needed[j] == RELOAD_OTHER
  4147.                || reload_when_needed[j] == RELOAD_FOR_INPUT
  4148.                || reload_when_needed[j] == RELOAD_FOR_INPUT_RELOAD_ADDRESS))
  4149.         {
  4150.           rtx temp = PREV_INSN (insn);
  4151.           while (temp && GET_CODE (temp) == NOTE)
  4152.         temp = PREV_INSN (temp);
  4153.           if (temp
  4154.           && GET_CODE (temp) == INSN
  4155.           && GET_CODE (PATTERN (temp)) == SET
  4156.           && SET_DEST (PATTERN (temp)) == old
  4157.           /* Make sure we can access insn_operand_constraint.  */
  4158.           && asm_noperands (PATTERN (temp)) < 0
  4159.           /* This is unsafe if prev insn rejects our reload reg.  */
  4160.           && constraint_accepts_reg_p (insn_operand_constraint[recog_memoized (temp)][0],
  4161.                            reloadreg)
  4162.           /* This is unsafe if operand occurs more than once in current
  4163.              insn.  Perhaps some occurrences aren't reloaded.  */
  4164.           && count_occurrences (PATTERN (insn), old) == 1
  4165.           /* Don't risk splitting a matching pair of operands.  */
  4166.           && ! reg_mentioned_p (old, SET_SRC (PATTERN (temp))))
  4167.         {
  4168.           /* Store into the reload register instead of the pseudo.  */
  4169.           SET_DEST (PATTERN (temp)) = reloadreg;
  4170.           /* If these are the only uses of the pseudo reg,
  4171.              pretend for GDB it lives in the reload reg we used.  */
  4172.           if (reg_n_deaths[REGNO (old)] == 1
  4173.               && reg_n_sets[REGNO (old)] == 1)
  4174.             {
  4175.               reg_renumber[REGNO (old)] = REGNO (reload_reg_rtx[j]);
  4176.               alter_reg (REGNO (old), -1);
  4177.             }
  4178.           special = 1;
  4179.         }
  4180.         }
  4181.  
  4182.       /* We can't do that, so output an insn to load RELOADREG.
  4183.          Keep them in the following order:
  4184.          all reloads for input reload addresses,
  4185.          all reloads for ordinary input operands,
  4186.          all reloads for addresses of non-reloaded operands,
  4187.          the insn being reloaded,
  4188.          all reloads for addresses of output reloads,
  4189.          the output reloads.  */
  4190.       if (! special)
  4191.         {
  4192.           rtx second_reload_reg = 0;
  4193.  
  4194. #ifdef SECONDARY_RELOAD_CLASS
  4195.           /* See if this OLDEQUIV still requires the secondary
  4196.          register.  If so, load it into the secondary register.  */
  4197.           if (SECONDARY_RELOAD_CLASS (reload_reg_class[j], mode, oldequiv)
  4198.           != NO_REGS)
  4199.         {
  4200.           second_reload_reg
  4201.             = reload_reg_rtx[reload_secondary_reload[j]];
  4202.           if (GET_MODE (second_reload_reg) != mode)
  4203.             second_reload_reg = gen_rtx (REG, mode,
  4204.                          REGNO (second_reload_reg));
  4205.           gen_input_reload (second_reload_reg, oldequiv, where);
  4206.           oldequiv = second_reload_reg;
  4207.         }
  4208. #endif
  4209.  
  4210.           this_reload_insn = gen_input_reload (reloadreg, oldequiv, where);
  4211.  
  4212. #if defined(SECONDARY_RELOAD_CLASS) && defined(PRESERVE_DEATH_INFO_REGNO_P)
  4213.           /* We may have to make a REG_DEAD note for the secondary reload
  4214.          register in the insns we just made.  Find the last insn that
  4215.          mentioned the register.  */
  4216.           if (second_reload_reg
  4217.           && PRESERVE_DEATH_INFO_REGNO_P (REGNO (second_reload_reg)))
  4218.         {
  4219.           rtx prev;
  4220.  
  4221.           for (prev = where;
  4222.                prev != PREV_INSN (this_reload_insn);
  4223.                prev = PREV_INSN (prev))
  4224.             if (GET_RTX_CLASS (GET_CODE (prev) == 'i')
  4225.             && reg_overlap_mentioned_p (second_reload_reg,
  4226.                             PATTERN (prev)))
  4227.               {
  4228.             REG_NOTES (prev) = gen_rtx (EXPR_LIST, REG_DEAD,
  4229.                             second_reload_reg,
  4230.                             REG_NOTES (prev));
  4231.             break;
  4232.               }
  4233.         }
  4234. #endif
  4235.         }
  4236.  
  4237.       /* Update where to put other reload insns.  */
  4238.       if (this_reload_insn)
  4239.         switch (reload_when_needed[j])
  4240.           {
  4241.           case RELOAD_FOR_INPUT:
  4242.           case RELOAD_OTHER:
  4243.         if (first_other_reload_insn == first_operand_address_reload_insn)
  4244.           first_other_reload_insn = this_reload_insn;
  4245.         break;
  4246.           case RELOAD_FOR_OPERAND_ADDRESS:
  4247.         if (first_operand_address_reload_insn == insn)
  4248.           first_operand_address_reload_insn = this_reload_insn;
  4249.         if (first_other_reload_insn == insn)
  4250.           first_other_reload_insn = this_reload_insn;
  4251.           }
  4252.  
  4253.       /* reload_inc[j] was formerly processed here.  */
  4254.     }
  4255.  
  4256.       /* Add a note saying the input reload reg
  4257.      dies in this insn, if anyone cares.  */
  4258. #ifdef PRESERVE_DEATH_INFO_REGNO_P
  4259.       if (old != 0
  4260.       && reload_reg_rtx[j] != old
  4261.       && reload_reg_rtx[j] != 0
  4262.       && reload_out[j] == 0
  4263.       && ! reload_inherited[j]
  4264.       && PRESERVE_DEATH_INFO_REGNO_P (REGNO (reload_reg_rtx[j])))
  4265.     {
  4266.       register rtx reloadreg = reload_reg_rtx[j];
  4267.  
  4268. #if 0      
  4269.       /* We can't abort here because we need to support this for sched.c.
  4270.          It's not terrible to miss a REG_DEAD note, but we should try
  4271.          to figure out how to do this correctly.  */
  4272.       /* The code below is incorrect for address-only reloads.  */
  4273.       if (reload_when_needed[j] != RELOAD_OTHER
  4274.           && reload_when_needed[j] != RELOAD_FOR_INPUT)
  4275.         abort ();
  4276. #endif
  4277.  
  4278.       /* Add a death note to this insn, for an input reload.  */
  4279.  
  4280.       if ((reload_when_needed[j] == RELOAD_OTHER
  4281.            || reload_when_needed[j] == RELOAD_FOR_INPUT)
  4282.           && ! dead_or_set_p (insn, reloadreg))
  4283.         REG_NOTES (insn)
  4284.           = gen_rtx (EXPR_LIST, REG_DEAD,
  4285.              reloadreg, REG_NOTES (insn));
  4286.     }
  4287.  
  4288.       /* When we inherit a reload, the last marked death of the reload reg
  4289.      may no longer really be a death.  */
  4290.       if (reload_reg_rtx[j] != 0
  4291.       && PRESERVE_DEATH_INFO_REGNO_P (REGNO (reload_reg_rtx[j]))
  4292.       && reload_inherited[j])
  4293.     {
  4294.       /* Handle inheriting an output reload.
  4295.          Remove the death note from the output reload insn.  */
  4296.       if (reload_spill_index[j] >= 0
  4297.           && GET_CODE (reload_in[j]) == REG
  4298.           && spill_reg_store[reload_spill_index[j]] != 0
  4299.           && find_regno_note (spill_reg_store[reload_spill_index[j]],
  4300.                   REG_DEAD, REGNO (reload_reg_rtx[j])))
  4301.         remove_death (REGNO (reload_reg_rtx[j]),
  4302.               spill_reg_store[reload_spill_index[j]]);
  4303.       /* Likewise for input reloads that were inherited.  */
  4304.       else if (reload_spill_index[j] >= 0
  4305.            && GET_CODE (reload_in[j]) == REG
  4306.            && spill_reg_store[reload_spill_index[j]] == 0
  4307.            && reload_inheritance_insn[j] != 0
  4308.            && find_regno_note (reload_inheritance_insn[j], REG_DEAD, 
  4309.                        REGNO (reload_reg_rtx[j])))
  4310.         remove_death (REGNO (reload_reg_rtx[j]),
  4311.               reload_inheritance_insn[j]);
  4312.       else
  4313.         {
  4314.           rtx prev;
  4315.  
  4316.           /* We got this register from find_equiv_reg.
  4317.          Search back for its last death note and get rid of it.
  4318.          But don't search back too far.
  4319.          Don't go past a place where this reg is set,
  4320.          since a death note before that remains valid.  */
  4321.           for (prev = PREV_INSN (insn);
  4322.            prev && GET_CODE (prev) != CODE_LABEL;
  4323.            prev = PREV_INSN (prev))
  4324.         if (GET_RTX_CLASS (GET_CODE (prev)) == 'i'
  4325.             && dead_or_set_p (prev, reload_reg_rtx[j]))
  4326.           {
  4327.             if (find_regno_note (prev, REG_DEAD,
  4328.                      REGNO (reload_reg_rtx[j])))
  4329.               remove_death (REGNO (reload_reg_rtx[j]), prev);
  4330.             break;
  4331.           }
  4332.         }
  4333.     }
  4334.  
  4335.       /* We might have used find_equiv_reg above to choose an alternate
  4336.      place from which to reload.  If so, and it died, we need to remove
  4337.      that death and move it to one of the insns we just made.  */
  4338.  
  4339.       if (oldequiv_reg != 0
  4340.       && PRESERVE_DEATH_INFO_REGNO_P (true_regnum (oldequiv_reg)))
  4341.     {
  4342.       rtx prev, prev1;
  4343.  
  4344.       for (prev = PREV_INSN (insn); prev && GET_CODE (prev) != CODE_LABEL;
  4345.            prev = PREV_INSN (prev))
  4346.         if (GET_RTX_CLASS (GET_CODE (prev)) == 'i'
  4347.         && dead_or_set_p (prev, oldequiv_reg))
  4348.           {
  4349.         if (find_regno_note (prev, REG_DEAD, REGNO (oldequiv_reg)))
  4350.           {
  4351.             for (prev1 = this_reload_insn;
  4352.              prev1; prev1 = PREV_INSN (prev1))
  4353.               if (GET_RTX_CLASS (GET_CODE (prev1) == 'i')
  4354.             && reg_overlap_mentioned_p (oldequiv_reg,
  4355.                             PATTERN (prev1)))
  4356.               {
  4357.             REG_NOTES (prev1) = gen_rtx (EXPR_LIST, REG_DEAD,
  4358.                              oldequiv_reg,
  4359.                              REG_NOTES (prev1));
  4360.             break;
  4361.               }
  4362.             remove_death (REGNO (oldequiv_reg), prev);
  4363.           }
  4364.         break;
  4365.           }
  4366.     }
  4367. #endif
  4368.  
  4369.       /* If we are reloading a register that was recently stored in with an
  4370.      output-reload, see if we can prove there was
  4371.      actually no need to store the old value in it.  */
  4372.  
  4373.       if (optimize && reload_inherited[j] && reload_spill_index[j] >= 0
  4374.       /* This is unsafe if some other reload uses the same reg first.  */
  4375.       && (reload_when_needed[j] == RELOAD_OTHER
  4376.           || reload_when_needed[j] == RELOAD_FOR_INPUT
  4377.           || reload_when_needed[j] == RELOAD_FOR_INPUT_RELOAD_ADDRESS)
  4378.       && GET_CODE (reload_in[j]) == REG
  4379. #if 0
  4380.       /* There doesn't seem to be any reason to restrict this to pseudos
  4381.          and doing so loses in the case where we are copying from a
  4382.          register of the wrong class.  */
  4383.       && REGNO (reload_in[j]) >= FIRST_PSEUDO_REGISTER
  4384. #endif
  4385.       && spill_reg_store[reload_spill_index[j]] != 0
  4386.       && dead_or_set_p (insn, reload_in[j])
  4387.       /* This is unsafe if operand occurs more than once in current
  4388.          insn.  Perhaps some occurrences weren't reloaded.  */
  4389.       && count_occurrences (PATTERN (insn), reload_in[j]) == 1)
  4390.     delete_output_reload (insn, j,
  4391.                   spill_reg_store[reload_spill_index[j]]);
  4392.  
  4393.       /* Input-reloading is done.  Now do output-reloading,
  4394.      storing the value from the reload-register after the main insn
  4395.      if reload_out[j] is nonzero.
  4396.  
  4397.      ??? At some point we need to support handling output reloads of
  4398.      JUMP_INSNs or insns that set cc0.  */
  4399.       old = reload_out[j];
  4400.       if (old != 0
  4401.       && reload_reg_rtx[j] != old
  4402.       && reload_reg_rtx[j] != 0)
  4403.     {
  4404.       register rtx reloadreg = reload_reg_rtx[j];
  4405.       register rtx second_reloadreg = 0;
  4406.       rtx prev_insn = PREV_INSN (first_output_reload_insn);
  4407.       rtx note, p;
  4408.       enum machine_mode mode;
  4409.  
  4410.       /* An output operand that dies right away does need a reload,
  4411.          but need not be copied from it.  Show the new location in the
  4412.          REG_UNUSED note.  */
  4413.       if ((GET_CODE (old) == REG || GET_CODE (old) == SCRATCH)
  4414.           && (note = find_reg_note (insn, REG_UNUSED, old)) != 0)
  4415.         {
  4416.           XEXP (note, 0) = reload_reg_rtx[j];
  4417.           continue;
  4418.         }
  4419.       else if (GET_CODE (old) == SCRATCH)
  4420.         /* If we aren't optimizing, there won't be a REG_UNUSED note,
  4421.            but we don't want to make an output reload.  */
  4422.         continue;
  4423.  
  4424. #if 0
  4425.       /* Strip off of OLD any size-increasing SUBREGs such as
  4426.          (SUBREG:SI foo:QI 0).  */
  4427.  
  4428.       while (GET_CODE (old) == SUBREG && SUBREG_WORD (old) == 0
  4429.          && (GET_MODE_SIZE (GET_MODE (old))
  4430.              > GET_MODE_SIZE (GET_MODE (SUBREG_REG (old)))))
  4431.         old = SUBREG_REG (old);
  4432. #endif
  4433.  
  4434.       /* If is a JUMP_INSN, we can't support output reloads yet.  */
  4435.       if (GET_CODE (insn) == JUMP_INSN)
  4436.         abort ();
  4437.  
  4438.       /* Determine the mode to reload in.
  4439.          See comments above (for input reloading).  */
  4440.  
  4441.       mode = GET_MODE (old);
  4442.       if (mode == VOIDmode)
  4443.         abort ();        /* Should never happen for an output.  */
  4444.  
  4445.       /* A strict-low-part output operand needs to be reloaded
  4446.          in the mode of the entire value.  */
  4447.       if (reload_strict_low[j])
  4448.         {
  4449.           mode = GET_MODE (SUBREG_REG (reload_out[j]));
  4450.           /* Encapsulate OLD into that mode.  */
  4451.           /* If OLD is a subreg, then strip it, since the subreg will
  4452.          be altered by this very reload.  */
  4453.           while (GET_CODE (old) == SUBREG && GET_MODE (old) != mode)
  4454.         old = SUBREG_REG (old);
  4455.           if (GET_MODE (old) != VOIDmode
  4456.           && mode != GET_MODE (old))
  4457.         old = gen_rtx (SUBREG, mode, old, 0);
  4458.         }
  4459.  
  4460.       if (GET_MODE (reloadreg) != mode)
  4461.         reloadreg = gen_rtx (REG, mode, REGNO (reloadreg));
  4462.  
  4463. #ifdef SECONDARY_RELOAD_CLASS
  4464.       /* If we need two reload regs, set RELOADREG to the intermediate
  4465.          one, since it will be stored into OUT.  We might need a secondary
  4466.          register only for an input reload, so check again here.  */
  4467.       if (reload_secondary_reload[j] >= 0
  4468.           && (SECONDARY_RELOAD_CLASS (reload_reg_class[j], mode, old)
  4469.           != NO_REGS))
  4470.         {
  4471.           second_reloadreg = reloadreg;
  4472.           reloadreg = reload_reg_rtx[reload_secondary_reload[j]];
  4473.  
  4474.           if (GET_MODE (reloadreg) != mode)
  4475.         reloadreg = gen_rtx (REG, mode, REGNO (reloadreg));
  4476.  
  4477.           emit_insn_before (gen_move_insn (reloadreg, second_reloadreg),
  4478.                 first_output_reload_insn);
  4479.         }
  4480. #endif
  4481.  
  4482.       /* Output the last reload insn.  */
  4483.       emit_insn_before (gen_move_insn (old, reloadreg),
  4484.                 first_output_reload_insn);
  4485.  
  4486. #ifdef PRESERVE_DEATH_INFO_REGNO_P
  4487.       /* If final will look at death notes for this reg,
  4488.          put one on the last output-reload insn to use it.  Similarly
  4489.          for any secondary register.  */
  4490.       if (PRESERVE_DEATH_INFO_REGNO_P (REGNO (reloadreg)))
  4491.         for (p = PREV_INSN (first_output_reload_insn);
  4492.          p != prev_insn; p = PREV_INSN (p))
  4493.           if (GET_RTX_CLASS (GET_CODE (p)) == 'i'
  4494.           && reg_overlap_mentioned_p (reloadreg, PATTERN (p)))
  4495.         REG_NOTES (p) = gen_rtx (EXPR_LIST, REG_DEAD,
  4496.                      reloadreg, REG_NOTES (p));
  4497.  
  4498. #ifdef SECONDARY_RELOAD_CLASS
  4499.       if (PRESERVE_DEATH_INFO_REGNO_P (REGNO (second_reloadreg)))
  4500.         for (p = PREV_INSN (first_output_reload_insn);
  4501.          p != prev_insn; p = PREV_INSN (p))
  4502.           if (GET_RTX_CLASS (GET_CODE (p)) == 'i'
  4503.           && reg_overlap_mentioned_p (second_reloadreg, PATTERN (p)))
  4504.         REG_NOTES (p) = gen_rtx (EXPR_LIST, REG_DEAD,
  4505.                      second_reloadreg, REG_NOTES (p));
  4506. #endif
  4507. #endif
  4508.       /* Look at all insns we emitted, just to be safe.  */
  4509.       for (p = NEXT_INSN (prev_insn); p != first_output_reload_insn;
  4510.            p = NEXT_INSN (p))
  4511.         if (GET_RTX_CLASS (GET_CODE (p)) == 'i')
  4512.           {
  4513.         /* If this output reload doesn't come from a spill reg,
  4514.            clear any memory of reloaded copies of the pseudo reg.
  4515.            If this output reload comes from a spill reg,
  4516.            reg_has_output_reload will make this do nothing.  */
  4517.         note_stores (PATTERN (p), forget_old_reloads_1);
  4518.  
  4519.         if (reg_mentioned_p (reload_reg_rtx[j], PATTERN (p)))
  4520.           store_insn = p;
  4521.           }
  4522.  
  4523.       first_output_reload_insn = NEXT_INSN (prev_insn);
  4524.     }
  4525.  
  4526.       if (reload_spill_index[j] >= 0)
  4527.     new_spill_reg_store[reload_spill_index[j]] = store_insn;
  4528.     }
  4529.  
  4530.   /* Now update spill_reg_store for the reloads of this insn.  */
  4531.   /* Copy the elements that were updated in the loop above.  */
  4532.   for (j = 0; j < n_reloads; j++)
  4533.     {
  4534.       int regno = reload_spill_index[j];
  4535.       if (regno >= 0)
  4536.     spill_reg_store[regno] = new_spill_reg_store[regno];
  4537.     }
  4538.  
  4539.   /* Move death notes from INSN
  4540.      to output-operand-address and output reload insns.  */
  4541. #ifdef PRESERVE_DEATH_INFO_REGNO_P
  4542.   {
  4543.     rtx insn1;
  4544.     /* Loop over those insns, last ones first.  */
  4545.     for (insn1 = PREV_INSN (following_insn); insn1 != insn;
  4546.      insn1 = PREV_INSN (insn1))
  4547.       if (GET_CODE (insn1) == INSN && GET_CODE (PATTERN (insn1)) == SET)
  4548.     {
  4549.       rtx source = SET_SRC (PATTERN (insn1));
  4550.       rtx dest = SET_DEST (PATTERN (insn1));
  4551.  
  4552.       /* The note we will examine next.  */
  4553.       rtx reg_notes = REG_NOTES (insn);
  4554.       /* The place that pointed to this note.  */
  4555.       rtx *prev_reg_note = ®_NOTES (insn);
  4556.  
  4557.       /* If the note is for something used in the source of this
  4558.          reload insn, or in the output address, move the note.  */
  4559.       while (reg_notes)
  4560.         {
  4561.           rtx next_reg_notes = XEXP (reg_notes, 1);
  4562.           if (REG_NOTE_KIND (reg_notes) == REG_DEAD
  4563.           && GET_CODE (XEXP (reg_notes, 0)) == REG
  4564.           && ((GET_CODE (dest) != REG
  4565.                && reg_overlap_mentioned_p (XEXP (reg_notes, 0), dest))
  4566.               || reg_overlap_mentioned_p (XEXP (reg_notes, 0), source)))
  4567.         {
  4568.           *prev_reg_note = next_reg_notes;
  4569.           XEXP (reg_notes, 1) = REG_NOTES (insn1);
  4570.           REG_NOTES (insn1) = reg_notes;
  4571.         }
  4572.           else
  4573.         prev_reg_note = &XEXP (reg_notes, 1);
  4574.  
  4575.           reg_notes = next_reg_notes;
  4576.         }
  4577.     }
  4578.   }
  4579. #endif
  4580.  
  4581.   /* For all the spill regs newly reloaded in this instruction,
  4582.      record what they were reloaded from, so subsequent instructions
  4583.      can inherit the reloads.  */
  4584.  
  4585.   for (j = 0; j < n_reloads; j++)
  4586.     {
  4587.       register int r = reload_order[j];
  4588.       register int i = reload_spill_index[r];
  4589.  
  4590.       /* I is nonneg if this reload used one of the spill regs.
  4591.      If reload_reg_rtx[r] is 0, this is an optional reload
  4592.      that we opted to ignore.  */
  4593.       if (i >= 0 && reload_reg_rtx[r] != 0)
  4594.     {
  4595.       /* First, clear out memory of what used to be in this spill reg.
  4596.          If consecutive registers are used, clear them all.  */
  4597.       int nr
  4598.         = HARD_REGNO_NREGS (spill_regs[i], GET_MODE (reload_reg_rtx[r]));
  4599.       while (--nr >= 0)
  4600.         {
  4601.           reg_reloaded_contents[spill_reg_order[spill_regs[i] + nr]] = -1;
  4602.           reg_reloaded_insn[spill_reg_order[spill_regs[i] + nr]] = 0;
  4603.         }
  4604.  
  4605.       /* Maybe the spill reg contains a copy of reload_out.  */
  4606.       if (reload_out[r] != 0 && GET_CODE (reload_out[r]) == REG)
  4607.         {
  4608.           register int nregno = REGNO (reload_out[r]);
  4609.           reg_last_reload_reg[nregno] = reload_reg_rtx[r];
  4610.           reg_reloaded_contents[i] = nregno;
  4611.           reg_reloaded_insn[i] = insn;
  4612.         }
  4613.       /* Maybe the spill reg contains a copy of reload_in.  */
  4614.       else if (reload_out[r] == 0
  4615.            && reload_in[r] != 0
  4616.            && (GET_CODE (reload_in[r]) == REG
  4617.                || GET_CODE (reload_in_reg[r]) == REG))
  4618.         {
  4619.           register int nregno;
  4620.           if (GET_CODE (reload_in[r]) == REG)
  4621.         nregno = REGNO (reload_in[r]);
  4622.           else
  4623.         nregno = REGNO (reload_in_reg[r]);
  4624.  
  4625.           /* If there are two separate reloads (one in and one out)
  4626.          for the same (hard or pseudo) reg,
  4627.          leave reg_last_reload_reg set 
  4628.          based on the output reload.
  4629.          Otherwise, set it from this input reload.  */
  4630.           if (!reg_has_output_reload[nregno]
  4631.           /* But don't do so if another input reload
  4632.              will clobber this one's value.  */
  4633.           && reload_reg_reaches_end_p (spill_regs[i],
  4634.                            reload_when_needed[r]))
  4635.         {
  4636.           reg_last_reload_reg[nregno] = reload_reg_rtx[r];
  4637.           reg_reloaded_contents[i] = nregno;
  4638.           reg_reloaded_insn[i] = insn;
  4639.  
  4640.         }
  4641.         }
  4642.     }
  4643.  
  4644.       /* The following if-statement was #if 0'd in 1.34 (or before...).
  4645.      It's reenabled in 1.35 because supposedly nothing else
  4646.      deals with this problem.  */
  4647.  
  4648.       /* If a register gets output-reloaded from a non-spill register,
  4649.      that invalidates any previous reloaded copy of it.
  4650.      But forget_old_reloads_1 won't get to see it, because
  4651.      it thinks only about the original insn.  So invalidate it here.  */
  4652.       if (i < 0 && reload_out[r] != 0 && GET_CODE (reload_out[r]) == REG)
  4653.     {
  4654.       register int nregno = REGNO (reload_out[r]);
  4655.       reg_last_reload_reg[nregno] = 0;
  4656.     }
  4657.     }
  4658. }
  4659.  
  4660. /* Emit code before BEFORE_INSN to perform an input reload of IN to RELOADREG.
  4661.    Returns last insn emitted.  */
  4662.  
  4663. static rtx
  4664. gen_input_reload (reloadreg, in, before_insn)
  4665.      rtx reloadreg;
  4666.      rtx in;
  4667.      rtx before_insn;
  4668. {
  4669.   register rtx prev_insn = PREV_INSN (before_insn);
  4670.  
  4671.   /* How to do this reload can get quite tricky.  Normally, we are being 
  4672.      asked to reload a simple operand, such as a MEM, a constant, or a pseudo
  4673.      register that didn't get a hard register.  In that case we can just
  4674.      call emit_move_insn.
  4675.  
  4676.      We can also be asked to reload a PLUS that adds either two registers or
  4677.      a register and a constant.  This can occur during frame pointer
  4678.      elimination.  That case if handled by trying to emit a single insn
  4679.      to perform the add.  If it is not valid, we use a two insn sequence.
  4680.  
  4681.      Finally, we could be called to handle an 'o' constraint by putting
  4682.      an address into a register.  In that case, we first try to do this
  4683.      with a named pattern of "reload_load_address".  If no such pattern
  4684.      exists, we just emit a SET insn and hope for the best (it will normally
  4685.      be valid on machines that use 'o').
  4686.  
  4687.      This entire process is made complex because reload will never
  4688.      process the insns we generate here and so we must ensure that
  4689.      they will fit their constraints and also by the fact that parts of
  4690.      IN might be being reloaded separately and replaced with spill registers.
  4691.      Because of this, we are, in some sense, just guessing the right approach
  4692.      here.  The one listed above seems to work.
  4693.  
  4694.      ??? At some point, this whole thing needs to be rethought.  */
  4695.  
  4696.   if (GET_CODE (in) == PLUS
  4697.       && GET_CODE (XEXP (in, 0)) == REG
  4698.       && (GET_CODE (XEXP (in, 1)) == REG
  4699.       || CONSTANT_P (XEXP (in, 1))))
  4700.     {
  4701.       /* We need to compute the sum of what is either a register and a
  4702.      constant or a hard register and a pseudo register and put it into
  4703.      the reload register.  The best possible way of doing this is if the
  4704.      machine has a three-operand ADD insn that accepts the required
  4705.      operands.
  4706.  
  4707.      The simplest approach is to try to generate such an insn and see if it
  4708.      is recognized and matches its constraints.  If so, it can be used.
  4709.  
  4710.      It might be better not to actually emit the insn unless it is valid,
  4711.      but we need to pass the insn as an operand to `recog' and it is
  4712.      simpler to emit and then delete the insn if not valid than to
  4713.      dummy things up.  */
  4714.       rtx move_operand, other_operand;
  4715.       rtx insn = emit_insn_before (gen_rtx (SET, VOIDmode, reloadreg, in),
  4716.                    before_insn);
  4717.       int code = recog_memoized (insn);
  4718.  
  4719.       if (code >= 0)
  4720.     {
  4721.       insn_extract (insn);
  4722.       /* We want constrain operands to treat this insn strictly in
  4723.          its validity determination, i.e., the way it would after reload
  4724.          has completed.  */
  4725.       if (constrain_operands (code, 1))
  4726.         return insn;
  4727.     }
  4728.  
  4729.       if (PREV_INSN (insn))
  4730.     NEXT_INSN (PREV_INSN (insn)) = NEXT_INSN (insn);
  4731.       if (NEXT_INSN (insn))
  4732.     PREV_INSN (NEXT_INSN (insn)) = PREV_INSN (insn);
  4733.  
  4734.       /* If that failed, we must use a conservative two-insn sequence.
  4735.      use move to copy constant or pseudo register to the reload register
  4736.      since it will be able to handle arbitrary operand, unlike add which
  4737.      can't, in general.  Then add the registers.
  4738.  
  4739.      If there is another way to do this for a specific machine, a
  4740.      DEFINE_PEEPHOLE should be specified that recognizes the sequence
  4741.      we emit below.  */
  4742.  
  4743.       if (CONSTANT_P (XEXP (in, 1))
  4744.       || (GET_CODE (XEXP (in, 1)) == REG
  4745.           && REGNO (XEXP (in, 1)) >= FIRST_PSEUDO_REGISTER))
  4746.     move_operand = XEXP (in, 1), other_operand = XEXP (in, 0);
  4747.       else
  4748.     move_operand = XEXP (in, 0), other_operand = XEXP (in, 1);
  4749.  
  4750.       emit_insn_before (gen_move_insn (reloadreg, move_operand), before_insn);
  4751.       emit_insn_before (gen_add2_insn (reloadreg, other_operand), before_insn);
  4752.     }
  4753.  
  4754.   /* If IN is a simple operand, use gen_move_insn.  */
  4755.   else if (GET_RTX_CLASS (GET_CODE (in)) == 'o' || GET_CODE (in) == SUBREG)
  4756.     emit_insn_before (gen_move_insn (reloadreg, in), before_insn);
  4757.  
  4758. #ifdef HAVE_reload_load_address
  4759.   else if (HAVE_reload_load_address)
  4760.     emit_insn_before (gen_reload_load_address (reloadreg, in), before_insn);
  4761. #endif
  4762.  
  4763.   /* Otherwise, just write (set REGLOADREG IN) and hope for the best.  */
  4764.   else
  4765.     emit_insn_before (gen_rtx (SET, VOIDmode, reloadreg, in), before_insn);
  4766.  
  4767.   /* Return the first insn emitted.
  4768.      We can not just return PREV_INSN (before_insn), because there may have
  4769.      been multiple instructions emitted.  Also note that gen_move_insn may
  4770.      emit more than one insn itself, so we can not assume that there is one
  4771.      insn emitted per emit_insn_before call.  */
  4772.  
  4773.   return NEXT_INSN (prev_insn);
  4774. }
  4775.  
  4776. /* Delete a previously made output-reload
  4777.    whose result we now believe is not needed.
  4778.    First we double-check.
  4779.  
  4780.    INSN is the insn now being processed.
  4781.    OUTPUT_RELOAD_INSN is the insn of the output reload.
  4782.    J is the reload-number for this insn.  */
  4783.  
  4784. static void
  4785. delete_output_reload (insn, j, output_reload_insn)
  4786.      rtx insn;
  4787.      int j;
  4788.      rtx output_reload_insn;
  4789. {
  4790.   register rtx i1;
  4791.  
  4792.   /* Get the raw pseudo-register referred to.  */
  4793.  
  4794.   rtx reg = reload_in[j];
  4795.   while (GET_CODE (reg) == SUBREG)
  4796.     reg = SUBREG_REG (reg);
  4797.  
  4798.   /* If the pseudo-reg we are reloading is no longer referenced
  4799.      anywhere between the store into it and here,
  4800.      and no jumps or labels intervene, then the value can get
  4801.      here through the reload reg alone.
  4802.      Otherwise, give up--return.  */
  4803.   for (i1 = NEXT_INSN (output_reload_insn);
  4804.        i1 != insn; i1 = NEXT_INSN (i1))
  4805.     {
  4806.       if (GET_CODE (i1) == CODE_LABEL || GET_CODE (i1) == JUMP_INSN)
  4807.     return;
  4808.       if ((GET_CODE (i1) == INSN || GET_CODE (i1) == CALL_INSN)
  4809.       && reg_mentioned_p (reg, PATTERN (i1)))
  4810.     return;
  4811.     }
  4812.  
  4813.   /* If this insn will store in the pseudo again,
  4814.      the previous store can be removed.  */
  4815.   if (reload_out[j] == reload_in[j])
  4816.     delete_insn (output_reload_insn);
  4817.  
  4818.   /* See if the pseudo reg has been completely replaced
  4819.      with reload regs.  If so, delete the store insn
  4820.      and forget we had a stack slot for the pseudo.  */
  4821.   else if (reg_n_deaths[REGNO (reg)] == 1
  4822.        && reg_basic_block[REGNO (reg)] >= 0
  4823.        && find_regno_note (insn, REG_DEAD, REGNO (reg)))
  4824.     {
  4825.       rtx i2;
  4826.  
  4827.       /* We know that it was used only between here
  4828.      and the beginning of the current basic block.
  4829.      (We also know that the last use before INSN was
  4830.      the output reload we are thinking of deleting, but never mind that.)
  4831.      Search that range; see if any ref remains.  */
  4832.       for (i2 = PREV_INSN (insn); i2; i2 = PREV_INSN (i2))
  4833.     {
  4834.       /* Uses which just store in the pseudo don't count,
  4835.          since if they are the only uses, they are dead.  */
  4836.       if (GET_CODE (i2) == INSN
  4837.           && GET_CODE (PATTERN (i2)) == SET
  4838.           && SET_DEST (PATTERN (i2)) == reg)
  4839.         continue;
  4840.       if (GET_CODE (i2) == CODE_LABEL
  4841.           || GET_CODE (i2) == JUMP_INSN)
  4842.         break;
  4843.       if ((GET_CODE (i2) == INSN || GET_CODE (i2) == CALL_INSN)
  4844.           && reg_mentioned_p (reg, PATTERN (i2)))
  4845.         /* Some other ref remains;
  4846.            we can't do anything.  */
  4847.         return;
  4848.     }
  4849.  
  4850.       /* Delete the now-dead stores into this pseudo.  */
  4851.       for (i2 = PREV_INSN (insn); i2; i2 = PREV_INSN (i2))
  4852.     {
  4853.       /* Uses which just store in the pseudo don't count,
  4854.          since if they are the only uses, they are dead.  */
  4855.       if (GET_CODE (i2) == INSN
  4856.           && GET_CODE (PATTERN (i2)) == SET
  4857.           && SET_DEST (PATTERN (i2)) == reg)
  4858.         delete_insn (i2);
  4859.       if (GET_CODE (i2) == CODE_LABEL
  4860.           || GET_CODE (i2) == JUMP_INSN)
  4861.         break;
  4862.     }
  4863.  
  4864.       /* For the debugging info,
  4865.      say the pseudo lives in this reload reg.  */
  4866.       reg_renumber[REGNO (reg)] = REGNO (reload_reg_rtx[j]);
  4867.       alter_reg (REGNO (reg), -1);
  4868.     }
  4869. }
  4870.  
  4871.  
  4872. /* Output reload-insns to reload VALUE into RELOADREG. 
  4873.    VALUE is a autoincrement or autodecrement RTX whose operand
  4874.    is a register or memory location;
  4875.    so reloading involves incrementing that location.
  4876.  
  4877.    INC_AMOUNT is the number to increment or decrement by (always positive).
  4878.    This cannot be deduced from VALUE.
  4879.  
  4880.    INSN is the insn before which the new insns should be emitted.
  4881.  
  4882.    The return value is the first of the insns emitted.  */
  4883.  
  4884. static rtx
  4885. inc_for_reload (reloadreg, value, inc_amount, insn)
  4886.      rtx reloadreg;
  4887.      rtx value;
  4888.      int inc_amount;
  4889.      rtx insn;
  4890. {
  4891.   /* REG or MEM to be copied and incremented.  */
  4892.   rtx incloc = XEXP (value, 0);
  4893.   /* Nonzero if increment after copying.  */
  4894.   int post = (GET_CODE (value) == POST_DEC || GET_CODE (value) == POST_INC);
  4895.  
  4896.   /* No hard register is equivalent to this register after
  4897.      inc/dec operation.  If REG_LAST_RELOAD_REG were non-zero,
  4898.      we could inc/dec that register as well (maybe even using it for
  4899.      the source), but I'm not sure it's worth worrying about.  */
  4900.   if (GET_CODE (incloc) == REG)
  4901.     reg_last_reload_reg[REGNO (incloc)] = 0;
  4902.  
  4903.   if (GET_CODE (value) == PRE_DEC || GET_CODE (value) == POST_DEC)
  4904.     inc_amount = - inc_amount;
  4905.  
  4906.   /* First handle preincrement, which is simpler.  */
  4907.   if (! post)
  4908.     {
  4909.       /* If incrementing a register, assume we can
  4910.      output an insn to increment it directly.  */
  4911.       if (GET_CODE (incloc) == REG &&
  4912.       (REGNO (incloc) < FIRST_PSEUDO_REGISTER
  4913.        || reg_renumber[REGNO (incloc)] >= 0))
  4914.     {
  4915.       rtx first_new
  4916.         = emit_insn_before (gen_add2_insn (incloc,
  4917.                            gen_rtx (CONST_INT, VOIDmode,
  4918.                             inc_amount)),
  4919.                 insn);
  4920.       emit_insn_before (gen_move_insn (reloadreg, incloc), insn);
  4921.       return first_new;
  4922.     }
  4923.       else
  4924.     /* Else we must not assume we can increment the location directly
  4925.        (even though on many target machines we can);
  4926.        copy it to the reload register, increment there, then save back.  */
  4927.     {
  4928.       rtx first_new
  4929.         = emit_insn_before (gen_move_insn (reloadreg, incloc), insn);
  4930.       emit_insn_before (gen_add2_insn (reloadreg,
  4931.                        gen_rtx (CONST_INT, VOIDmode,
  4932.                             inc_amount)),
  4933.                 insn);
  4934.       emit_insn_before (gen_move_insn (incloc, reloadreg), insn);
  4935.       return first_new;
  4936.     }
  4937.     }
  4938.   /* Postincrement.
  4939.      Because this might be a jump insn or a compare, and because RELOADREG
  4940.      may not be available after the insn in an input reload,
  4941.      we must do the incrementation before the insn being reloaded for.  */
  4942.   else
  4943.     {
  4944.       /* Copy the value, then increment it.  */
  4945.       rtx first_new
  4946.     = emit_insn_before (gen_move_insn (reloadreg, incloc), insn);
  4947.  
  4948.       /* If incrementing a register, assume we can
  4949.      output an insn to increment it directly.  */
  4950.       if (GET_CODE (incloc) == REG &&
  4951.       (REGNO (incloc) < FIRST_PSEUDO_REGISTER
  4952.        || reg_renumber[REGNO (incloc)] >= 0))
  4953.     {
  4954.       emit_insn_before (gen_add2_insn (incloc,
  4955.                        gen_rtx (CONST_INT, VOIDmode,
  4956.                             inc_amount)),
  4957.                 insn);
  4958.     }
  4959.       else
  4960.     /* Else we must not assume we can increment INCLOC
  4961.        (even though on many target machines we can);
  4962.        increment the copy in the reload register,
  4963.        save that back, then decrement the reload register
  4964.        so it has the original value.  */
  4965.     {
  4966.       emit_insn_before (gen_add2_insn (reloadreg,
  4967.                        gen_rtx (CONST_INT, VOIDmode,
  4968.                             inc_amount)),
  4969.                 insn);
  4970.       emit_insn_before (gen_move_insn (incloc, reloadreg), insn);
  4971.       emit_insn_before (gen_sub2_insn (reloadreg,
  4972.                        gen_rtx (CONST_INT, VOIDmode,
  4973.                             inc_amount)),
  4974.                 insn);
  4975.     }
  4976.       return first_new;
  4977.     }
  4978. }
  4979.  
  4980. /* Return 1 if we are certain that the constraint-string STRING allows
  4981.    the hard register REG.  Return 0 if we can't be sure of this.  */
  4982.  
  4983. static int
  4984. constraint_accepts_reg_p (string, reg)
  4985.      char *string;
  4986.      rtx reg;
  4987. {
  4988.   int value = 0;
  4989.   int regno = true_regnum (reg);
  4990.   int c;
  4991.  
  4992.   /* Initialize for first alternative.  */
  4993.   value = 0;
  4994.   /* Check that each alternative contains `g' or `r'.  */
  4995.   while (1)
  4996.     switch (c = *string++)
  4997.       {
  4998.       case 0:
  4999.     /* If an alternative lacks `g' or `r', we lose.  */
  5000.     return value;
  5001.       case ',':
  5002.     /* If an alternative lacks `g' or `r', we lose.  */
  5003.     if (value == 0)
  5004.       return 0;
  5005.     /* Initialize for next alternative.  */
  5006.     value = 0;
  5007.     break;
  5008.       case 'g':
  5009.       case 'r':
  5010.     /* Any general reg wins for this alternative.  */
  5011.     if (TEST_HARD_REG_BIT (reg_class_contents[(int) GENERAL_REGS], regno))
  5012.       value = 1;
  5013.     break;
  5014.       default:
  5015.     /* Any reg in specified class wins for this alternative.  */
  5016.     {
  5017.       int class = REG_CLASS_FROM_LETTER (c);
  5018.  
  5019.       if (TEST_HARD_REG_BIT (reg_class_contents[class], regno))
  5020.         value = 1;
  5021.     }
  5022.       }
  5023. }
  5024.  
  5025. /* Return the number of places FIND appears within X.  */
  5026.  
  5027. static int
  5028. count_occurrences (x, find)
  5029.      register rtx x, find;
  5030. {
  5031.   register int i, j;
  5032.   register enum rtx_code code;
  5033.   register char *format_ptr;
  5034.   int count;
  5035.  
  5036.   if (x == find)
  5037.     return 1;
  5038.   if (x == 0)
  5039.     return 0;
  5040.  
  5041.   code = GET_CODE (x);
  5042.  
  5043.   switch (code)
  5044.     {
  5045.     case REG:
  5046.     case QUEUED:
  5047.     case CONST_INT:
  5048.     case CONST_DOUBLE:
  5049.     case SYMBOL_REF:
  5050.     case CODE_LABEL:
  5051.     case PC:
  5052.     case CC0:
  5053.       return 0;
  5054.     }
  5055.  
  5056.   format_ptr = GET_RTX_FORMAT (code);
  5057.   count = 0;
  5058.  
  5059.   for (i = 0; i < GET_RTX_LENGTH (code); i++)
  5060.     {
  5061.       switch (*format_ptr++)
  5062.     {
  5063.     case 'e':
  5064.       count += count_occurrences (XEXP (x, i), find);
  5065.       break;
  5066.  
  5067.     case 'E':
  5068.       if (XVEC (x, i) != NULL)
  5069.         {
  5070.           for (j = 0; j < XVECLEN (x, i); j++)
  5071.         count += count_occurrences (XVECEXP (x, i, j), find);
  5072.         }
  5073.       break;
  5074.     }
  5075.     }
  5076.   return count;
  5077. }
  5078.