home *** CD-ROM | disk | FTP | other *** search
/ OpenStep 4.2J (Developer) / os42jdev.iso / NextDeveloper / Source / GNU / gcc / reload1.c < prev    next >
C/C++ Source or Header  |  1995-12-29  |  244KB  |  7,183 lines

  1. /* Reload pseudo regs into hard regs for insns that require hard regs.
  2.    Copyright (C) 1987, 88, 89, 92, 93, 94, 1995 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, 59 Temple Place - Suite 330,
  19. Boston, MA 02111-1307, USA.  */
  20.  
  21.  
  22. #include <stdio.h>
  23. #include "config.h"
  24. #include "rtl.h"
  25. #include "obstack.h"
  26. #include "insn-config.h"
  27. #include "insn-flags.h"
  28. #include "insn-codes.h"
  29. #include "flags.h"
  30. #include "expr.h"
  31. #include "regs.h"
  32. #include "hard-reg-set.h"
  33. #include "reload.h"
  34. #include "recog.h"
  35. #include "basic-block.h"
  36. #include "output.h"
  37. #include "real.h"
  38.  
  39. /* This file contains the reload pass of the compiler, which is
  40.    run after register allocation has been done.  It checks that
  41.    each insn is valid (operands required to be in registers really
  42.    are in registers of the proper class) and fixes up invalid ones
  43.    by copying values temporarily into registers for the insns
  44.    that need them.
  45.  
  46.    The results of register allocation are described by the vector
  47.    reg_renumber; the insns still contain pseudo regs, but reg_renumber
  48.    can be used to find which hard reg, if any, a pseudo reg is in.
  49.  
  50.    The technique we always use is to free up a few hard regs that are
  51.    called ``reload regs'', and for each place where a pseudo reg
  52.    must be in a hard reg, copy it temporarily into one of the reload regs.
  53.  
  54.    All the pseudos that were formerly allocated to the hard regs that
  55.    are now in use as reload regs must be ``spilled''.  This means
  56.    that they go to other hard regs, or to stack slots if no other
  57.    available hard regs can be found.  Spilling can invalidate more
  58.    insns, requiring additional need for reloads, so we must keep checking
  59.    until the process stabilizes.
  60.  
  61.    For machines with different classes of registers, we must keep track
  62.    of the register class needed for each reload, and make sure that
  63.    we allocate enough reload registers of each class.
  64.  
  65.    The file reload.c contains the code that checks one insn for
  66.    validity and reports the reloads that it needs.  This file
  67.    is in charge of scanning the entire rtl code, accumulating the
  68.    reload needs, spilling, assigning reload registers to use for
  69.    fixing up each insn, and generating the new insns to copy values
  70.    into the reload registers.  */
  71.  
  72.  
  73. #ifndef REGISTER_MOVE_COST
  74. #define REGISTER_MOVE_COST(x, y) 2
  75. #endif
  76.  
  77. #ifndef MEMORY_MOVE_COST
  78. #define MEMORY_MOVE_COST(x) 4
  79. #endif
  80.  
  81. /* During reload_as_needed, element N contains a REG rtx for the hard reg
  82.    into which reg N has been reloaded (perhaps for a previous insn). */
  83. static rtx *reg_last_reload_reg;
  84.  
  85. /* Elt N nonzero if reg_last_reload_reg[N] has been set in this insn
  86.    for an output reload that stores into reg N.  */
  87. static char *reg_has_output_reload;
  88.  
  89. /* Indicates which hard regs are reload-registers for an output reload
  90.    in the current insn.  */
  91. static HARD_REG_SET reg_is_output_reload;
  92.  
  93. /* Element N is the constant value to which pseudo reg N is equivalent,
  94.    or zero if pseudo reg N is not equivalent to a constant.
  95.    find_reloads looks at this in order to replace pseudo reg N
  96.    with the constant it stands for.  */
  97. rtx *reg_equiv_constant;
  98.  
  99. /* Element N is a memory location to which pseudo reg N is equivalent,
  100.    prior to any register elimination (such as frame pointer to stack
  101.    pointer).  Depending on whether or not it is a valid address, this value
  102.    is transferred to either reg_equiv_address or reg_equiv_mem.  */
  103. rtx *reg_equiv_memory_loc;
  104.  
  105. /* Element N is the address of stack slot to which pseudo reg N is equivalent.
  106.    This is used when the address is not valid as a memory address
  107.    (because its displacement is too big for the machine.)  */
  108. rtx *reg_equiv_address;
  109.  
  110. /* Element N is the memory slot to which pseudo reg N is equivalent,
  111.    or zero if pseudo reg N is not equivalent to a memory slot.  */
  112. rtx *reg_equiv_mem;
  113.  
  114. /* Widest width in which each pseudo reg is referred to (via subreg).  */
  115. static int *reg_max_ref_width;
  116.  
  117. /* Element N is the insn that initialized reg N from its equivalent
  118.    constant or memory slot.  */
  119. static rtx *reg_equiv_init;
  120.  
  121. /* During reload_as_needed, element N contains the last pseudo regno
  122.    reloaded into the Nth reload register.  This vector is in parallel
  123.    with spill_regs.  If that pseudo reg occupied more than one register,
  124.    reg_reloaded_contents points to that pseudo for each spill register in
  125.    use; all of these must remain set for an inheritance to occur.  */
  126. static int reg_reloaded_contents[FIRST_PSEUDO_REGISTER];
  127.  
  128. /* During reload_as_needed, element N contains the insn for which
  129.    the Nth reload register was last used.  This vector is in parallel
  130.    with spill_regs, and its contents are significant only when
  131.    reg_reloaded_contents is significant.  */
  132. static rtx reg_reloaded_insn[FIRST_PSEUDO_REGISTER];
  133.  
  134. /* Number of spill-regs so far; number of valid elements of spill_regs.  */
  135. static int n_spills;
  136.  
  137. /* In parallel with spill_regs, contains REG rtx's for those regs.
  138.    Holds the last rtx used for any given reg, or 0 if it has never
  139.    been used for spilling yet.  This rtx is reused, provided it has
  140.    the proper mode.  */
  141. static rtx spill_reg_rtx[FIRST_PSEUDO_REGISTER];
  142.  
  143. /* In parallel with spill_regs, contains nonzero for a spill reg
  144.    that was stored after the last time it was used.
  145.    The precise value is the insn generated to do the store.  */
  146. static rtx spill_reg_store[FIRST_PSEUDO_REGISTER];
  147.  
  148. /* This table is the inverse mapping of spill_regs:
  149.    indexed by hard reg number,
  150.    it contains the position of that reg in spill_regs,
  151.    or -1 for something that is not in spill_regs.  */
  152. static short spill_reg_order[FIRST_PSEUDO_REGISTER];
  153.  
  154. /* This reg set indicates registers that may not be used for retrying global
  155.    allocation.  The registers that may not be used include all spill registers
  156.    and the frame pointer (if we are using one).  */
  157. HARD_REG_SET forbidden_regs;
  158.  
  159. /* This reg set indicates registers that are not good for spill registers.
  160.    They will not be used to complete groups of spill registers.  This includes
  161.    all fixed registers, registers that may be eliminated, and, if
  162.    SMALL_REGISTER_CLASSES is not defined, registers explicitly used in the rtl.
  163.  
  164.    (spill_reg_order prevents these registers from being used to start a
  165.    group.)  */
  166. static HARD_REG_SET bad_spill_regs;
  167.  
  168. /* Describes order of use of registers for reloading
  169.    of spilled pseudo-registers.  `spills' is the number of
  170.    elements that are actually valid; new ones are added at the end.  */
  171. static short spill_regs[FIRST_PSEUDO_REGISTER];
  172.  
  173. /* Index of last register assigned as a spill register.  We allocate in
  174.    a round-robin fashion.  */
  175.  
  176. static int last_spill_reg;
  177.  
  178. /* Describes order of preference for putting regs into spill_regs.
  179.    Contains the numbers of all the hard regs, in order most preferred first.
  180.    This order is different for each function.
  181.    It is set up by order_regs_for_reload.
  182.    Empty elements at the end contain -1.  */
  183. static short potential_reload_regs[FIRST_PSEUDO_REGISTER];
  184.  
  185. /* 1 for a hard register that appears explicitly in the rtl
  186.    (for example, function value registers, special registers
  187.    used by insns, structure value pointer registers).  */
  188. static char regs_explicitly_used[FIRST_PSEUDO_REGISTER];
  189.  
  190. /* Indicates if a register was counted against the need for
  191.    groups.  0 means it can count against max_nongroup instead.  */
  192. static HARD_REG_SET counted_for_groups;
  193.  
  194. /* Indicates if a register was counted against the need for
  195.    non-groups.  0 means it can become part of a new group.
  196.    During choose_reload_regs, 1 here means don't use this reg
  197.    as part of a group, even if it seems to be otherwise ok.  */
  198. static HARD_REG_SET counted_for_nongroups;
  199.  
  200. /* Indexed by pseudo reg number N,
  201.    says may not delete stores into the real (memory) home of pseudo N.
  202.    This is set if we already substituted a memory equivalent in some uses,
  203.    which happens when we have to eliminate the fp from it.  */
  204. static char *cannot_omit_stores;
  205.  
  206. /* Nonzero if indirect addressing is supported on the machine; this means
  207.    that spilling (REG n) does not require reloading it into a register in
  208.    order to do (MEM (REG n)) or (MEM (PLUS (REG n) (CONST_INT c))).  The
  209.    value indicates the level of indirect addressing supported, e.g., two
  210.    means that (MEM (MEM (REG n))) is also valid if (REG n) does not get
  211.    a hard register.  */
  212.  
  213. static char spill_indirect_levels;
  214.  
  215. /* Nonzero if indirect addressing is supported when the innermost MEM is
  216.    of the form (MEM (SYMBOL_REF sym)).  It is assumed that the level to
  217.    which these are valid is the same as spill_indirect_levels, above.   */
  218.  
  219. char indirect_symref_ok;
  220.  
  221. /* Nonzero if an address (plus (reg frame_pointer) (reg ...)) is valid.  */
  222.  
  223. char double_reg_address_ok;
  224.  
  225. /* Record the stack slot for each spilled hard register.  */
  226.  
  227. static rtx spill_stack_slot[FIRST_PSEUDO_REGISTER];
  228.  
  229. /* Width allocated so far for that stack slot.  */
  230.  
  231. static int spill_stack_slot_width[FIRST_PSEUDO_REGISTER];
  232.  
  233. /* Indexed by register class and basic block number, nonzero if there is
  234.    any need for a spill register of that class in that basic block.
  235.    The pointer is 0 if we did stupid allocation and don't know
  236.    the structure of basic blocks.  */
  237.  
  238. char *basic_block_needs[N_REG_CLASSES];
  239.  
  240. /* First uid used by insns created by reload in this function.
  241.    Used in find_equiv_reg.  */
  242. int reload_first_uid;
  243.  
  244. /* Flag set by local-alloc or global-alloc if anything is live in
  245.    a call-clobbered reg across calls.  */
  246.  
  247. int caller_save_needed;
  248.  
  249. /* Set to 1 while reload_as_needed is operating.
  250.    Required by some machines to handle any generated moves differently.  */
  251.  
  252. int reload_in_progress = 0;
  253.  
  254. /* These arrays record the insn_code of insns that may be needed to
  255.    perform input and output reloads of special objects.  They provide a
  256.    place to pass a scratch register.  */
  257.  
  258. enum insn_code reload_in_optab[NUM_MACHINE_MODES];
  259. enum insn_code reload_out_optab[NUM_MACHINE_MODES];
  260.  
  261. /* This obstack is used for allocation of rtl during register elimination.
  262.    The allocated storage can be freed once find_reloads has processed the
  263.    insn.  */
  264.  
  265. struct obstack reload_obstack;
  266. char *reload_firstobj;
  267.  
  268. #define obstack_chunk_alloc xmalloc
  269. #define obstack_chunk_free free
  270.  
  271. /* List of labels that must never be deleted.  */
  272. extern rtx forced_labels;
  273.  
  274. /* This structure is used to record information about register eliminations.
  275.    Each array entry describes one possible way of eliminating a register
  276.    in favor of another.   If there is more than one way of eliminating a
  277.    particular register, the most preferred should be specified first.  */
  278.  
  279. static struct elim_table
  280. {
  281.   int from;            /* Register number to be eliminated. */
  282.   int to;            /* Register number used as replacement. */
  283.   int initial_offset;        /* Initial difference between values. */
  284.   int can_eliminate;        /* Non-zero if this elimination can be done. */
  285.   int can_eliminate_previous;    /* Value of CAN_ELIMINATE in previous scan over
  286.                    insns made by reload. */
  287.   int offset;            /* Current offset between the two regs. */
  288.   int max_offset;        /* Maximum offset between the two regs. */
  289.   int previous_offset;        /* Offset at end of previous insn. */
  290.   int ref_outside_mem;        /* "to" has been referenced outside a MEM. */
  291.   rtx from_rtx;            /* REG rtx for the register to be eliminated.
  292.                    We cannot simply compare the number since
  293.                    we might then spuriously replace a hard
  294.                    register corresponding to a pseudo
  295.                    assigned to the reg to be eliminated. */
  296.   rtx to_rtx;            /* REG rtx for the replacement. */
  297. } reg_eliminate[] =
  298.  
  299. /* If a set of eliminable registers was specified, define the table from it.
  300.    Otherwise, default to the normal case of the frame pointer being
  301.    replaced by the stack pointer.  */
  302.  
  303. #ifdef ELIMINABLE_REGS
  304.   ELIMINABLE_REGS;
  305. #else
  306.   {{ FRAME_POINTER_REGNUM, STACK_POINTER_REGNUM}};
  307. #endif
  308.  
  309. #define NUM_ELIMINABLE_REGS (sizeof reg_eliminate / sizeof reg_eliminate[0])
  310.  
  311. /* Record the number of pending eliminations that have an offset not equal
  312.    to their initial offset.  If non-zero, we use a new copy of each
  313.    replacement result in any insns encountered.  */
  314. static int num_not_at_initial_offset;
  315.  
  316. /* Count the number of registers that we may be able to eliminate.  */
  317. static int num_eliminable;
  318.  
  319. /* For each label, we record the offset of each elimination.  If we reach
  320.    a label by more than one path and an offset differs, we cannot do the
  321.    elimination.  This information is indexed by the number of the label.
  322.    The first table is an array of flags that records whether we have yet
  323.    encountered a label and the second table is an array of arrays, one
  324.    entry in the latter array for each elimination.  */
  325.  
  326. static char *offsets_known_at;
  327. static int (*offsets_at)[NUM_ELIMINABLE_REGS];
  328.  
  329. /* Number of labels in the current function.  */
  330.  
  331. static int num_labels;
  332.  
  333. struct hard_reg_n_uses { int regno; int uses; };
  334.  
  335. static int possible_group_p        PROTO((int, int *));
  336. static void count_possible_groups    PROTO((int *, enum machine_mode *,
  337.                            int *, int));
  338. static int modes_equiv_for_class_p    PROTO((enum machine_mode,
  339.                            enum machine_mode,
  340.                            enum reg_class));
  341. static void spill_failure        PROTO((rtx));
  342. static int new_spill_reg        PROTO((int, int, int *, int *, int,
  343.                            FILE *));
  344. static void delete_dead_insn        PROTO((rtx));
  345. static void alter_reg              PROTO((int, int));
  346. static void mark_scratch_live        PROTO((rtx));
  347. static void set_label_offsets        PROTO((rtx, rtx, int));
  348. static int eliminate_regs_in_insn    PROTO((rtx, int));
  349. static void mark_not_eliminable        PROTO((rtx, rtx));
  350. static int spill_hard_reg        PROTO((int, int, FILE *, int));
  351. static void scan_paradoxical_subregs    PROTO((rtx));
  352. static int hard_reg_use_compare        PROTO((struct hard_reg_n_uses *,
  353.                            struct hard_reg_n_uses *));
  354. static void order_regs_for_reload    PROTO((void));
  355. static int compare_spill_regs        PROTO((short *, short *));
  356. static void reload_as_needed        PROTO((rtx, int));
  357. static void forget_old_reloads_1    PROTO((rtx, rtx));
  358. static int reload_reg_class_lower    PROTO((short *, short *));
  359. static void mark_reload_reg_in_use    PROTO((int, int, enum reload_type,
  360.                            enum machine_mode));
  361. static void clear_reload_reg_in_use    PROTO((int, int, enum reload_type,
  362.                            enum machine_mode));
  363. static int reload_reg_free_p        PROTO((int, int, enum reload_type));
  364. static int reload_reg_free_before_p    PROTO((int, int, enum reload_type));
  365. static int reload_reg_reaches_end_p    PROTO((int, int, enum reload_type));
  366. static int reloads_conflict         PROTO((int, int));
  367. static int allocate_reload_reg        PROTO((int, rtx, int, int));
  368. static void choose_reload_regs        PROTO((rtx, rtx));
  369. static void merge_assigned_reloads    PROTO((rtx));
  370. static void emit_reload_insns        PROTO((rtx));
  371. static void delete_output_reload    PROTO((rtx, int, rtx));
  372. static void inc_for_reload        PROTO((rtx, rtx, int));
  373. static int constraint_accepts_reg_p    PROTO((char *, rtx));
  374. static int count_occurrences        PROTO((rtx, rtx));
  375.  
  376. /* Initialize the reload pass once per compilation.  */
  377.  
  378. void
  379. init_reload ()
  380. {
  381.   register int i;
  382.  
  383.   /* Often (MEM (REG n)) is still valid even if (REG n) is put on the stack.
  384.      Set spill_indirect_levels to the number of levels such addressing is
  385.      permitted, zero if it is not permitted at all.  */
  386.  
  387.   register rtx tem
  388.     = gen_rtx (MEM, Pmode,
  389.            gen_rtx (PLUS, Pmode,
  390.             gen_rtx (REG, Pmode, LAST_VIRTUAL_REGISTER + 1),
  391.             GEN_INT (4)));
  392.   spill_indirect_levels = 0;
  393.  
  394.   while (memory_address_p (QImode, tem))
  395.     {
  396.       spill_indirect_levels++;
  397.       tem = gen_rtx (MEM, Pmode, tem);
  398.     }
  399.  
  400.   /* See if indirect addressing is valid for (MEM (SYMBOL_REF ...)).  */
  401.  
  402.   tem = gen_rtx (MEM, Pmode, gen_rtx (SYMBOL_REF, Pmode, "foo"));
  403.   indirect_symref_ok = memory_address_p (QImode, tem);
  404.  
  405.   /* See if reg+reg is a valid (and offsettable) address.  */
  406.  
  407.   for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
  408.     {
  409.       tem = gen_rtx (PLUS, Pmode,
  410.              gen_rtx (REG, Pmode, HARD_FRAME_POINTER_REGNUM),
  411.              gen_rtx (REG, Pmode, i));
  412.       /* This way, we make sure that reg+reg is an offsettable address.  */
  413.       tem = plus_constant (tem, 4);
  414.  
  415.       if (memory_address_p (QImode, tem))
  416.     {
  417.       double_reg_address_ok = 1;
  418.       break;
  419.     }
  420.     }
  421.  
  422.   /* Initialize obstack for our rtl allocation. */
  423.   gcc_obstack_init (&reload_obstack);
  424.   reload_firstobj = (char *) obstack_alloc (&reload_obstack, 0);
  425. }
  426.  
  427. /* Main entry point for the reload pass.
  428.  
  429.    FIRST is the first insn of the function being compiled.
  430.  
  431.    GLOBAL nonzero means we were called from global_alloc
  432.    and should attempt to reallocate any pseudoregs that we
  433.    displace from hard regs we will use for reloads.
  434.    If GLOBAL is zero, we do not have enough information to do that,
  435.    so any pseudo reg that is spilled must go to the stack.
  436.  
  437.    DUMPFILE is the global-reg debugging dump file stream, or 0.
  438.    If it is nonzero, messages are written to it to describe
  439.    which registers are seized as reload regs, which pseudo regs
  440.    are spilled from them, and where the pseudo regs are reallocated to.
  441.  
  442.    Return value is nonzero if reload failed
  443.    and we must not do any more for this function.  */
  444.  
  445. int
  446. reload (first, global, dumpfile)
  447.      rtx first;
  448.      int global;
  449.      FILE *dumpfile;
  450. {
  451.   register int class;
  452.   register int i, j, k;
  453.   register rtx insn;
  454.   register struct elim_table *ep;
  455.  
  456.   int something_changed;
  457.   int something_needs_reloads;
  458.   int something_needs_elimination;
  459.   int new_basic_block_needs;
  460.   enum reg_class caller_save_spill_class = NO_REGS;
  461.   int caller_save_group_size = 1;
  462.  
  463.   /* Nonzero means we couldn't get enough spill regs.  */
  464.   int failure = 0;
  465.  
  466.   /* The basic block number currently being processed for INSN.  */
  467.   int this_block;
  468.  
  469.   /* Make sure even insns with volatile mem refs are recognizable.  */
  470.   init_recog ();
  471.  
  472.   /* Enable find_equiv_reg to distinguish insns made by reload.  */
  473.   reload_first_uid = get_max_uid ();
  474.  
  475.   for (i = 0; i < N_REG_CLASSES; i++)
  476.     basic_block_needs[i] = 0;
  477.  
  478. #ifdef SECONDARY_MEMORY_NEEDED
  479.   /* Initialize the secondary memory table.  */
  480.   clear_secondary_mem ();
  481. #endif
  482.  
  483.   /* Remember which hard regs appear explicitly
  484.      before we merge into `regs_ever_live' the ones in which
  485.      pseudo regs have been allocated.  */
  486.   bcopy (regs_ever_live, regs_explicitly_used, sizeof regs_ever_live);
  487.  
  488.   /* We don't have a stack slot for any spill reg yet.  */
  489.   bzero ((char *) spill_stack_slot, sizeof spill_stack_slot);
  490.   bzero ((char *) spill_stack_slot_width, sizeof spill_stack_slot_width);
  491.  
  492.   /* Initialize the save area information for caller-save, in case some
  493.      are needed.  */
  494.   init_save_areas ();
  495.  
  496.   /* Compute which hard registers are now in use
  497.      as homes for pseudo registers.
  498.      This is done here rather than (eg) in global_alloc
  499.      because this point is reached even if not optimizing.  */
  500.  
  501.   for (i = FIRST_PSEUDO_REGISTER; i < max_regno; i++)
  502.     mark_home_live (i);
  503.  
  504.   for (i = 0; i < scratch_list_length; i++)
  505.     if (scratch_list[i])
  506.       mark_scratch_live (scratch_list[i]);
  507.  
  508.   /* Make sure that the last insn in the chain
  509.      is not something that needs reloading.  */
  510.   emit_note (NULL_PTR, NOTE_INSN_DELETED);
  511.  
  512.   /* Find all the pseudo registers that didn't get hard regs
  513.      but do have known equivalent constants or memory slots.
  514.      These include parameters (known equivalent to parameter slots)
  515.      and cse'd or loop-moved constant memory addresses.
  516.  
  517.      Record constant equivalents in reg_equiv_constant
  518.      so they will be substituted by find_reloads.
  519.      Record memory equivalents in reg_mem_equiv so they can
  520.      be substituted eventually by altering the REG-rtx's.  */
  521.  
  522.   reg_equiv_constant = (rtx *) alloca (max_regno * sizeof (rtx));
  523.   bzero ((char *) reg_equiv_constant, max_regno * sizeof (rtx));
  524.   reg_equiv_memory_loc = (rtx *) alloca (max_regno * sizeof (rtx));
  525.   bzero ((char *) reg_equiv_memory_loc, max_regno * sizeof (rtx));
  526.   reg_equiv_mem = (rtx *) alloca (max_regno * sizeof (rtx));
  527.   bzero ((char *) reg_equiv_mem, max_regno * sizeof (rtx));
  528.   reg_equiv_init = (rtx *) alloca (max_regno * sizeof (rtx));
  529.   bzero ((char *) reg_equiv_init, max_regno * sizeof (rtx));
  530.   reg_equiv_address = (rtx *) alloca (max_regno * sizeof (rtx));
  531.   bzero ((char *) reg_equiv_address, max_regno * sizeof (rtx));
  532.   reg_max_ref_width = (int *) alloca (max_regno * sizeof (int));
  533.   bzero ((char *) reg_max_ref_width, max_regno * sizeof (int));
  534.   cannot_omit_stores = (char *) alloca (max_regno);
  535.   bzero (cannot_omit_stores, max_regno);
  536.  
  537. #ifdef SMALL_REGISTER_CLASSES
  538.   CLEAR_HARD_REG_SET (forbidden_regs);
  539. #endif
  540.  
  541.   /* Look for REG_EQUIV notes; record what each pseudo is equivalent to.
  542.      Also find all paradoxical subregs and find largest such for each pseudo.
  543.      On machines with small register classes, record hard registers that
  544.      are used for user variables.  These can never be used for spills.  */
  545.  
  546.   for (insn = first; insn; insn = NEXT_INSN (insn))
  547.     {
  548.       rtx set = single_set (insn);
  549.  
  550.       if (set != 0 && GET_CODE (SET_DEST (set)) == REG)
  551.     {
  552.       rtx note = find_reg_note (insn, REG_EQUIV, NULL_RTX);
  553.       if (note
  554. #ifdef LEGITIMATE_PIC_OPERAND_P
  555.           && (! CONSTANT_P (XEXP (note, 0)) || ! flag_pic
  556.           || LEGITIMATE_PIC_OPERAND_P (XEXP (note, 0)))
  557. #endif
  558.           )
  559.         {
  560.           rtx x = XEXP (note, 0);
  561.           i = REGNO (SET_DEST (set));
  562.           if (i > LAST_VIRTUAL_REGISTER)
  563.         {
  564.           if (GET_CODE (x) == MEM)
  565.             reg_equiv_memory_loc[i] = x;
  566.           else if (CONSTANT_P (x))
  567.             {
  568.               if (LEGITIMATE_CONSTANT_P (x))
  569.             reg_equiv_constant[i] = x;
  570.               else
  571.             reg_equiv_memory_loc[i]
  572.               = force_const_mem (GET_MODE (SET_DEST (set)), x);
  573.             }
  574.           else
  575.             continue;
  576.  
  577.           /* If this register is being made equivalent to a MEM
  578.              and the MEM is not SET_SRC, the equivalencing insn
  579.              is one with the MEM as a SET_DEST and it occurs later.
  580.              So don't mark this insn now.  */
  581.           if (GET_CODE (x) != MEM
  582.               || rtx_equal_p (SET_SRC (set), x))
  583.             reg_equiv_init[i] = insn;
  584.         }
  585.         }
  586.     }
  587.  
  588.       /* If this insn is setting a MEM from a register equivalent to it,
  589.      this is the equivalencing insn.  */
  590.       else if (set && GET_CODE (SET_DEST (set)) == MEM
  591.            && GET_CODE (SET_SRC (set)) == REG
  592.            && reg_equiv_memory_loc[REGNO (SET_SRC (set))]
  593.            && rtx_equal_p (SET_DEST (set),
  594.                    reg_equiv_memory_loc[REGNO (SET_SRC (set))]))
  595.     reg_equiv_init[REGNO (SET_SRC (set))] = insn;
  596.  
  597.       if (GET_RTX_CLASS (GET_CODE (insn)) == 'i')
  598.     scan_paradoxical_subregs (PATTERN (insn));
  599.     }
  600.  
  601.   /* Does this function require a frame pointer?  */
  602.  
  603.   frame_pointer_needed = (! flag_omit_frame_pointer
  604. #ifdef EXIT_IGNORE_STACK
  605.               /* ?? If EXIT_IGNORE_STACK is set, we will not save
  606.                  and restore sp for alloca.  So we can't eliminate
  607.                  the frame pointer in that case.  At some point,
  608.                  we should improve this by emitting the
  609.                  sp-adjusting insns for this case.  */
  610.               || (current_function_calls_alloca
  611.                   && EXIT_IGNORE_STACK)
  612. #endif
  613.               || FRAME_POINTER_REQUIRED);
  614.  
  615.   num_eliminable = 0;
  616.  
  617.   /* Initialize the table of registers to eliminate.  The way we do this
  618.      depends on how the eliminable registers were defined.  */
  619. #ifdef ELIMINABLE_REGS
  620.   for (ep = reg_eliminate; ep < ®_eliminate[NUM_ELIMINABLE_REGS]; ep++)
  621.     {
  622.       ep->can_eliminate = ep->can_eliminate_previous
  623.     = (CAN_ELIMINATE (ep->from, ep->to)
  624.        && ! (ep->to == STACK_POINTER_REGNUM && frame_pointer_needed));
  625.     }
  626. #else
  627.   reg_eliminate[0].can_eliminate = reg_eliminate[0].can_eliminate_previous
  628.     = ! frame_pointer_needed;
  629. #endif
  630.  
  631.   /* Count the number of eliminable registers and build the FROM and TO
  632.      REG rtx's.  Note that code in gen_rtx will cause, e.g.,
  633.      gen_rtx (REG, Pmode, STACK_POINTER_REGNUM) to equal stack_pointer_rtx.
  634.      We depend on this.  */
  635.   for (ep = reg_eliminate; ep < ®_eliminate[NUM_ELIMINABLE_REGS]; ep++)
  636.     {
  637.       num_eliminable += ep->can_eliminate;
  638.       ep->from_rtx = gen_rtx (REG, Pmode, ep->from);
  639.       ep->to_rtx = gen_rtx (REG, Pmode, ep->to);
  640.     }
  641.  
  642.   num_labels = max_label_num () - get_first_label_num ();
  643.  
  644.   /* Allocate the tables used to store offset information at labels.  */
  645.   offsets_known_at = (char *) alloca (num_labels);
  646.   offsets_at
  647.     = (int (*)[NUM_ELIMINABLE_REGS])
  648.       alloca (num_labels * NUM_ELIMINABLE_REGS * sizeof (int));
  649.  
  650.   offsets_known_at -= get_first_label_num ();
  651.   offsets_at -= get_first_label_num ();
  652.  
  653.   /* Alter each pseudo-reg rtx to contain its hard reg number.
  654.      Assign stack slots to the pseudos that lack hard regs or equivalents.
  655.      Do not touch virtual registers.  */
  656.  
  657.   for (i = LAST_VIRTUAL_REGISTER + 1; i < max_regno; i++)
  658.     alter_reg (i, -1);
  659.  
  660.   /* Round size of stack frame to BIGGEST_ALIGNMENT.  This must be done here
  661.      because the stack size may be a part of the offset computation for
  662.      register elimination.   */
  663.   assign_stack_local (BLKmode, 0, 0);
  664.  
  665.   /* If we have some registers we think can be eliminated, scan all insns to
  666.      see if there is an insn that sets one of these registers to something
  667.      other than itself plus a constant.  If so, the register cannot be
  668.      eliminated.  Doing this scan here eliminates an extra pass through the
  669.      main reload loop in the most common case where register elimination
  670.      cannot be done.  */
  671.   for (insn = first; insn && num_eliminable; insn = NEXT_INSN (insn))
  672.     if (GET_CODE (insn) == INSN || GET_CODE (insn) == JUMP_INSN
  673.     || GET_CODE (insn) == CALL_INSN)
  674.       note_stores (PATTERN (insn), mark_not_eliminable);
  675.  
  676. #ifndef REGISTER_CONSTRAINTS
  677.   /* If all the pseudo regs have hard regs,
  678.      except for those that are never referenced,
  679.      we know that no reloads are needed.  */
  680.   /* But that is not true if there are register constraints, since
  681.      in that case some pseudos might be in the wrong kind of hard reg.  */
  682.  
  683.   for (i = FIRST_PSEUDO_REGISTER; i < max_regno; i++)
  684.     if (reg_renumber[i] == -1 && reg_n_refs[i] != 0)
  685.       break;
  686.  
  687.   if (i == max_regno && num_eliminable == 0 && ! caller_save_needed)
  688.     return;
  689. #endif
  690.  
  691.   /* Compute the order of preference for hard registers to spill.
  692.      Store them by decreasing preference in potential_reload_regs.  */
  693.  
  694.   order_regs_for_reload ();
  695.  
  696.   /* So far, no hard regs have been spilled.  */
  697.   n_spills = 0;
  698.   for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
  699.     spill_reg_order[i] = -1;
  700.  
  701.   /* Initialize to -1, which means take the first spill register.  */
  702.   last_spill_reg = -1;
  703.  
  704.   /* On most machines, we can't use any register explicitly used in the
  705.      rtl as a spill register.  But on some, we have to.  Those will have
  706.      taken care to keep the life of hard regs as short as possible.  */
  707.  
  708. #ifndef SMALL_REGISTER_CLASSES
  709.   COPY_HARD_REG_SET (forbidden_regs, bad_spill_regs);
  710. #endif
  711.  
  712.   /* Spill any hard regs that we know we can't eliminate.  */
  713.   for (ep = reg_eliminate; ep < ®_eliminate[NUM_ELIMINABLE_REGS]; ep++)
  714.     if (! ep->can_eliminate)
  715.       spill_hard_reg (ep->from, global, dumpfile, 1);
  716.  
  717. #if HARD_FRAME_POINTER_REGNUM != FRAME_POINTER_REGNUM
  718.   if (frame_pointer_needed)
  719.     spill_hard_reg (HARD_FRAME_POINTER_REGNUM, global, dumpfile, 1);
  720. #endif
  721.  
  722.   if (global)
  723.     for (i = 0; i < N_REG_CLASSES; i++)
  724.       {
  725.     basic_block_needs[i] = (char *) alloca (n_basic_blocks);
  726.     bzero (basic_block_needs[i], n_basic_blocks);
  727.       }
  728.  
  729.   /* From now on, we need to emit any moves without making new pseudos.  */
  730.   reload_in_progress = 1;
  731.  
  732.   /* This loop scans the entire function each go-round
  733.      and repeats until one repetition spills no additional hard regs.  */
  734.  
  735.   /* This flag is set when a pseudo reg is spilled,
  736.      to require another pass.  Note that getting an additional reload
  737.      reg does not necessarily imply any pseudo reg was spilled;
  738.      sometimes we find a reload reg that no pseudo reg was allocated in.  */
  739.   something_changed = 1;
  740.   /* This flag is set if there are any insns that require reloading.  */
  741.   something_needs_reloads = 0;
  742.   /* This flag is set if there are any insns that require register
  743.      eliminations.  */
  744.   something_needs_elimination = 0;
  745.   while (something_changed)
  746.     {
  747.       rtx after_call = 0;
  748.  
  749.       /* For each class, number of reload regs needed in that class.
  750.      This is the maximum over all insns of the needs in that class
  751.      of the individual insn.  */
  752.       int max_needs[N_REG_CLASSES];
  753.       /* For each class, size of group of consecutive regs
  754.      that is needed for the reloads of this class.  */
  755.       int group_size[N_REG_CLASSES];
  756.       /* For each class, max number of consecutive groups needed.
  757.      (Each group contains group_size[CLASS] consecutive registers.)  */
  758.       int max_groups[N_REG_CLASSES];
  759.       /* For each class, max number needed of regs that don't belong
  760.      to any of the groups.  */
  761.       int max_nongroups[N_REG_CLASSES];
  762.       /* For each class, the machine mode which requires consecutive
  763.      groups of regs of that class.
  764.      If two different modes ever require groups of one class,
  765.      they must be the same size and equally restrictive for that class,
  766.      otherwise we can't handle the complexity.  */
  767.       enum machine_mode group_mode[N_REG_CLASSES];
  768.       /* Record the insn where each maximum need is first found.  */
  769.       rtx max_needs_insn[N_REG_CLASSES];
  770.       rtx max_groups_insn[N_REG_CLASSES];
  771.       rtx max_nongroups_insn[N_REG_CLASSES];
  772.       rtx x;
  773.       int starting_frame_size = get_frame_size ();
  774.       int previous_frame_pointer_needed = frame_pointer_needed;
  775.       static char *reg_class_names[] = REG_CLASS_NAMES;
  776.  
  777.       something_changed = 0;
  778.       bzero ((char *) max_needs, sizeof max_needs);
  779.       bzero ((char *) max_groups, sizeof max_groups);
  780.       bzero ((char *) max_nongroups, sizeof max_nongroups);
  781.       bzero ((char *) max_needs_insn, sizeof max_needs_insn);
  782.       bzero ((char *) max_groups_insn, sizeof max_groups_insn);
  783.       bzero ((char *) max_nongroups_insn, sizeof max_nongroups_insn);
  784.       bzero ((char *) group_size, sizeof group_size);
  785.       for (i = 0; i < N_REG_CLASSES; i++)
  786.     group_mode[i] = VOIDmode;
  787.  
  788.       /* Keep track of which basic blocks are needing the reloads.  */
  789.       this_block = 0;
  790.  
  791.       /* Remember whether any element of basic_block_needs
  792.      changes from 0 to 1 in this pass.  */
  793.       new_basic_block_needs = 0;
  794.  
  795.       /* Reset all offsets on eliminable registers to their initial values.  */
  796. #ifdef ELIMINABLE_REGS
  797.       for (ep = reg_eliminate; ep < ®_eliminate[NUM_ELIMINABLE_REGS]; ep++)
  798.     {
  799.       INITIAL_ELIMINATION_OFFSET (ep->from, ep->to, ep->initial_offset);
  800.       ep->previous_offset = ep->offset
  801.         = ep->max_offset = ep->initial_offset;
  802.     }
  803. #else
  804. #ifdef INITIAL_FRAME_POINTER_OFFSET
  805.       INITIAL_FRAME_POINTER_OFFSET (reg_eliminate[0].initial_offset);
  806. #else
  807.       if (!FRAME_POINTER_REQUIRED)
  808.     abort ();
  809.       reg_eliminate[0].initial_offset = 0;
  810. #endif
  811.       reg_eliminate[0].previous_offset = reg_eliminate[0].max_offset
  812.     = reg_eliminate[0].offset = reg_eliminate[0].initial_offset;
  813. #endif
  814.  
  815.       num_not_at_initial_offset = 0;
  816.  
  817.       bzero ((char *) &offsets_known_at[get_first_label_num ()], num_labels);
  818.  
  819.       /* Set a known offset for each forced label to be at the initial offset
  820.      of each elimination.  We do this because we assume that all
  821.      computed jumps occur from a location where each elimination is
  822.      at its initial offset.  */
  823.  
  824.       for (x = forced_labels; x; x = XEXP (x, 1))
  825.     if (XEXP (x, 0))
  826.       set_label_offsets (XEXP (x, 0), NULL_RTX, 1);
  827.  
  828.       /* For each pseudo register that has an equivalent location defined,
  829.      try to eliminate any eliminable registers (such as the frame pointer)
  830.      assuming initial offsets for the replacement register, which
  831.      is the normal case.
  832.  
  833.      If the resulting location is directly addressable, substitute
  834.      the MEM we just got directly for the old REG.
  835.  
  836.      If it is not addressable but is a constant or the sum of a hard reg
  837.      and constant, it is probably not addressable because the constant is
  838.      out of range, in that case record the address; we will generate
  839.      hairy code to compute the address in a register each time it is
  840.      needed.  Similarly if it is a hard register, but one that is not
  841.      valid as an address register.
  842.  
  843.      If the location is not addressable, but does not have one of the
  844.      above forms, assign a stack slot.  We have to do this to avoid the
  845.      potential of producing lots of reloads if, e.g., a location involves
  846.      a pseudo that didn't get a hard register and has an equivalent memory
  847.      location that also involves a pseudo that didn't get a hard register.
  848.  
  849.      Perhaps at some point we will improve reload_when_needed handling
  850.      so this problem goes away.  But that's very hairy.  */
  851.  
  852.       for (i = FIRST_PSEUDO_REGISTER; i < max_regno; i++)
  853.     if (reg_renumber[i] < 0 && reg_equiv_memory_loc[i])
  854.       {
  855.         rtx x = eliminate_regs (reg_equiv_memory_loc[i], 0, NULL_RTX);
  856.  
  857.         if (strict_memory_address_p (GET_MODE (regno_reg_rtx[i]),
  858.                      XEXP (x, 0)))
  859.           reg_equiv_mem[i] = x, reg_equiv_address[i] = 0;
  860.         else if (CONSTANT_P (XEXP (x, 0))
  861.              || (GET_CODE (XEXP (x, 0)) == REG
  862.              && REGNO (XEXP (x, 0)) < FIRST_PSEUDO_REGISTER)
  863.              || (GET_CODE (XEXP (x, 0)) == PLUS
  864.              && GET_CODE (XEXP (XEXP (x, 0), 0)) == REG
  865.              && (REGNO (XEXP (XEXP (x, 0), 0))
  866.                  < FIRST_PSEUDO_REGISTER)
  867.              && CONSTANT_P (XEXP (XEXP (x, 0), 1))))
  868.           reg_equiv_address[i] = XEXP (x, 0), reg_equiv_mem[i] = 0;
  869.         else
  870.           {
  871.         /* Make a new stack slot.  Then indicate that something
  872.            changed so we go back and recompute offsets for
  873.            eliminable registers because the allocation of memory
  874.            below might change some offset.  reg_equiv_{mem,address}
  875.            will be set up for this pseudo on the next pass around
  876.            the loop.  */
  877.         reg_equiv_memory_loc[i] = 0;
  878.         reg_equiv_init[i] = 0;
  879.         alter_reg (i, -1);
  880.         something_changed = 1;
  881.           }
  882.       }
  883.  
  884.       /* If we allocated another pseudo to the stack, redo elimination
  885.      bookkeeping.  */
  886.       if (something_changed)
  887.     continue;
  888.  
  889.       /* If caller-saves needs a group, initialize the group to include
  890.      the size and mode required for caller-saves.  */
  891.  
  892.       if (caller_save_group_size > 1)
  893.     {
  894.       group_mode[(int) caller_save_spill_class] = Pmode;
  895.       group_size[(int) caller_save_spill_class] = caller_save_group_size;
  896.     }
  897.  
  898.       /* Compute the most additional registers needed by any instruction.
  899.      Collect information separately for each class of regs.  */
  900.  
  901.       for (insn = first; insn; insn = NEXT_INSN (insn))
  902.     {
  903.       if (global && this_block + 1 < n_basic_blocks
  904.           && insn == basic_block_head[this_block+1])
  905.         ++this_block;
  906.  
  907.       /* If this is a label, a JUMP_INSN, or has REG_NOTES (which
  908.          might include REG_LABEL), we need to see what effects this
  909.          has on the known offsets at labels.  */
  910.  
  911.       if (GET_CODE (insn) == CODE_LABEL || GET_CODE (insn) == JUMP_INSN
  912.           || (GET_RTX_CLASS (GET_CODE (insn)) == 'i'
  913.           && REG_NOTES (insn) != 0))
  914.         set_label_offsets (insn, insn, 0);
  915.  
  916.       if (GET_RTX_CLASS (GET_CODE (insn)) == 'i')
  917.         {
  918.           /* Nonzero means don't use a reload reg that overlaps
  919.          the place where a function value can be returned.  */
  920.           rtx avoid_return_reg = 0;
  921.  
  922.           rtx old_body = PATTERN (insn);
  923.           int old_code = INSN_CODE (insn);
  924.            rtx old_notes = REG_NOTES (insn);
  925.           int did_elimination = 0;
  926.  
  927.           /* To compute the number of reload registers of each class 
  928.          needed for an insn, we must simulate what choose_reload_regs
  929.          can do.  We do this by splitting an insn into an "input" and
  930.          an "output" part.  RELOAD_OTHER reloads are used in both. 
  931.          The input part uses those reloads, RELOAD_FOR_INPUT reloads,
  932.          which must be live over the entire input section of reloads,
  933.          and the maximum of all the RELOAD_FOR_INPUT_ADDRESS and
  934.          RELOAD_FOR_OPERAND_ADDRESS reloads, which conflict with the
  935.          inputs.
  936.  
  937.          The registers needed for output are RELOAD_OTHER and
  938.          RELOAD_FOR_OUTPUT, which are live for the entire output
  939.          portion, and the maximum of all the RELOAD_FOR_OUTPUT_ADDRESS
  940.          reloads for each operand.
  941.  
  942.          The total number of registers needed is the maximum of the
  943.          inputs and outputs.  */
  944.  
  945.           struct needs
  946.         {
  947.           /* [0] is normal, [1] is nongroup.  */
  948.           int regs[2][N_REG_CLASSES];
  949.           int groups[N_REG_CLASSES];
  950.         };
  951.  
  952.           /* Each `struct needs' corresponds to one RELOAD_... type.  */
  953.           struct {
  954.         struct needs other;
  955.         struct needs input;
  956.         struct needs output;
  957.         struct needs insn;
  958.         struct needs other_addr;
  959.         struct needs op_addr;
  960.         struct needs op_addr_reload;
  961.         struct needs in_addr[MAX_RECOG_OPERANDS];
  962.         struct needs out_addr[MAX_RECOG_OPERANDS];
  963.           } insn_needs;
  964.  
  965.           /* If needed, eliminate any eliminable registers.  */
  966.           if (num_eliminable)
  967.         did_elimination = eliminate_regs_in_insn (insn, 0);
  968.  
  969. #ifdef SMALL_REGISTER_CLASSES
  970.           /* Set avoid_return_reg if this is an insn
  971.          that might use the value of a function call.  */
  972.           if (GET_CODE (insn) == CALL_INSN)
  973.         {
  974.           if (GET_CODE (PATTERN (insn)) == SET)
  975.             after_call = SET_DEST (PATTERN (insn));
  976.           else if (GET_CODE (PATTERN (insn)) == PARALLEL
  977.                && GET_CODE (XVECEXP (PATTERN (insn), 0, 0)) == SET)
  978.             after_call = SET_DEST (XVECEXP (PATTERN (insn), 0, 0));
  979.           else
  980.             after_call = 0;
  981.         }
  982.           else if (after_call != 0
  983.                && !(GET_CODE (PATTERN (insn)) == SET
  984.                 && SET_DEST (PATTERN (insn)) == stack_pointer_rtx))
  985.         {
  986.           if (reg_referenced_p (after_call, PATTERN (insn)))
  987.             avoid_return_reg = after_call;
  988.           after_call = 0;
  989.         }
  990. #endif /* SMALL_REGISTER_CLASSES */
  991.  
  992.           /* Analyze the instruction.  */
  993.           find_reloads (insn, 0, spill_indirect_levels, global,
  994.                 spill_reg_order);
  995.  
  996.           /* Remember for later shortcuts which insns had any reloads or
  997.          register eliminations.
  998.  
  999.          One might think that it would be worthwhile to mark insns
  1000.          that need register replacements but not reloads, but this is
  1001.          not safe because find_reloads may do some manipulation of
  1002.          the insn (such as swapping commutative operands), which would
  1003.          be lost when we restore the old pattern after register
  1004.          replacement.  So the actions of find_reloads must be redone in
  1005.          subsequent passes or in reload_as_needed.
  1006.  
  1007.          However, it is safe to mark insns that need reloads
  1008.          but not register replacement.  */
  1009.  
  1010.           PUT_MODE (insn, (did_elimination ? QImode
  1011.                    : n_reloads ? HImode
  1012.                    : GET_MODE (insn) == DImode ? DImode
  1013.                    : VOIDmode));
  1014.  
  1015.           /* Discard any register replacements done.  */
  1016.           if (did_elimination)
  1017.         {
  1018.           obstack_free (&reload_obstack, reload_firstobj);
  1019.           PATTERN (insn) = old_body;
  1020.           INSN_CODE (insn) = old_code;
  1021.            REG_NOTES (insn) = old_notes;
  1022.           something_needs_elimination = 1;
  1023.         }
  1024.  
  1025.           /* If this insn has no reloads, we need not do anything except
  1026.          in the case of a CALL_INSN when we have caller-saves and
  1027.          caller-save needs reloads.  */
  1028.  
  1029.           if (n_reloads == 0
  1030.           && ! (GET_CODE (insn) == CALL_INSN
  1031.             && caller_save_spill_class != NO_REGS))
  1032.         continue;
  1033.  
  1034.           something_needs_reloads = 1;
  1035.           bzero ((char *) &insn_needs, sizeof insn_needs);
  1036.  
  1037.           /* Count each reload once in every class
  1038.          containing the reload's own class.  */
  1039.  
  1040.           for (i = 0; i < n_reloads; i++)
  1041.         {
  1042.           register enum reg_class *p;
  1043.           enum reg_class class = reload_reg_class[i];
  1044.           int size;
  1045.           enum machine_mode mode;
  1046.           int nongroup_need;
  1047.           struct needs *this_needs;
  1048.  
  1049.           /* Don't count the dummy reloads, for which one of the
  1050.              regs mentioned in the insn can be used for reloading.
  1051.              Don't count optional reloads.
  1052.              Don't count reloads that got combined with others.  */
  1053.           if (reload_reg_rtx[i] != 0
  1054.               || reload_optional[i] != 0
  1055.               || (reload_out[i] == 0 && reload_in[i] == 0
  1056.               && ! reload_secondary_p[i]))
  1057.               continue;
  1058.  
  1059.           /* Show that a reload register of this class is needed
  1060.              in this basic block.  We do not use insn_needs and
  1061.              insn_groups because they are overly conservative for
  1062.              this purpose.  */
  1063.           if (global && ! basic_block_needs[(int) class][this_block])
  1064.             {
  1065.               basic_block_needs[(int) class][this_block] = 1;
  1066.               new_basic_block_needs = 1;
  1067.             }
  1068.  
  1069.  
  1070.           mode = reload_inmode[i];
  1071.           if (GET_MODE_SIZE (reload_outmode[i]) > GET_MODE_SIZE (mode))
  1072.             mode = reload_outmode[i];
  1073.           size = CLASS_MAX_NREGS (class, mode);
  1074.  
  1075.           /* If this class doesn't want a group, determine if we have
  1076.              a nongroup need or a regular need.  We have a nongroup
  1077.              need if this reload conflicts with a group reload whose
  1078.              class intersects with this reload's class.  */
  1079.  
  1080.           nongroup_need = 0;
  1081.           if (size == 1)
  1082.             for (j = 0; j < n_reloads; j++)
  1083.               if ((CLASS_MAX_NREGS (reload_reg_class[j],
  1084.                         (GET_MODE_SIZE (reload_outmode[j])
  1085.                          > GET_MODE_SIZE (reload_inmode[j]))
  1086.                         ? reload_outmode[j]
  1087.                         : reload_inmode[j])
  1088.                > 1)
  1089.               && (!reload_optional[j])
  1090.               && (reload_in[j] != 0 || reload_out[j] != 0
  1091.                   || reload_secondary_p[j])
  1092.               && reloads_conflict (i, j)
  1093.               && reg_classes_intersect_p (class,
  1094.                               reload_reg_class[j]))
  1095.             {
  1096.               nongroup_need = 1;
  1097.               break;
  1098.             }
  1099.  
  1100.           /* Decide which time-of-use to count this reload for.  */
  1101.           switch (reload_when_needed[i])
  1102.             {
  1103.             case RELOAD_OTHER:
  1104.               this_needs = &insn_needs.other;
  1105.               break;
  1106.             case RELOAD_FOR_INPUT:
  1107.               this_needs = &insn_needs.input;
  1108.               break;
  1109.             case RELOAD_FOR_OUTPUT:
  1110.               this_needs = &insn_needs.output;
  1111.               break;
  1112.             case RELOAD_FOR_INSN:
  1113.               this_needs = &insn_needs.insn;
  1114.               break;
  1115.             case RELOAD_FOR_OTHER_ADDRESS:
  1116.               this_needs = &insn_needs.other_addr;
  1117.               break;
  1118.             case RELOAD_FOR_INPUT_ADDRESS:
  1119.               this_needs = &insn_needs.in_addr[reload_opnum[i]];
  1120.               break;
  1121.             case RELOAD_FOR_OUTPUT_ADDRESS:
  1122.               this_needs = &insn_needs.out_addr[reload_opnum[i]];
  1123.               break;
  1124.             case RELOAD_FOR_OPERAND_ADDRESS:
  1125.               this_needs = &insn_needs.op_addr;
  1126.               break;
  1127.             case RELOAD_FOR_OPADDR_ADDR:
  1128.               this_needs = &insn_needs.op_addr_reload;
  1129.               break;
  1130.             }
  1131.  
  1132.           if (size > 1)
  1133.             {
  1134.               enum machine_mode other_mode, allocate_mode;
  1135.  
  1136.               /* Count number of groups needed separately from
  1137.              number of individual regs needed.  */
  1138.               this_needs->groups[(int) class]++;
  1139.               p = reg_class_superclasses[(int) class];
  1140.               while (*p != LIM_REG_CLASSES)
  1141.             this_needs->groups[(int) *p++]++;
  1142.  
  1143.               /* Record size and mode of a group of this class.  */
  1144.               /* If more than one size group is needed,
  1145.              make all groups the largest needed size.  */
  1146.               if (group_size[(int) class] < size)
  1147.             {
  1148.               other_mode = group_mode[(int) class];
  1149.               allocate_mode = mode;
  1150.  
  1151.               group_size[(int) class] = size;
  1152.               group_mode[(int) class] = mode;
  1153.             }
  1154.               else
  1155.             {
  1156.               other_mode = mode;
  1157.               allocate_mode = group_mode[(int) class];
  1158.             }
  1159.  
  1160.               /* Crash if two dissimilar machine modes both need
  1161.              groups of consecutive regs of the same class.  */
  1162.  
  1163.               if (other_mode != VOIDmode && other_mode != allocate_mode
  1164.               && ! modes_equiv_for_class_p (allocate_mode,
  1165.                             other_mode, class))
  1166.             fatal_insn ("Two dissimilar machine modes both need groups of consecutive regs of the same class",
  1167.                     insn);
  1168.             }
  1169.           else if (size == 1)
  1170.             {
  1171.               this_needs->regs[nongroup_need][(int) class] += 1;
  1172.               p = reg_class_superclasses[(int) class];
  1173.               while (*p != LIM_REG_CLASSES)
  1174.             this_needs->regs[nongroup_need][(int) *p++] += 1;
  1175.             }
  1176.           else
  1177.             abort ();
  1178.         }
  1179.  
  1180.           /* All reloads have been counted for this insn;
  1181.          now merge the various times of use.
  1182.          This sets insn_needs, etc., to the maximum total number
  1183.          of registers needed at any point in this insn.  */
  1184.  
  1185.           for (i = 0; i < N_REG_CLASSES; i++)
  1186.         {
  1187.           int in_max, out_max;
  1188.  
  1189.           /* Compute normal and nongroup needs.  */
  1190.           for (j = 0; j <= 1; j++)
  1191.             {
  1192.               for (in_max = 0, out_max = 0, k = 0;
  1193.                k < reload_n_operands; k++)
  1194.             {
  1195.               in_max
  1196.                 = MAX (in_max, insn_needs.in_addr[k].regs[j][i]);
  1197.               out_max
  1198.                 = MAX (out_max, insn_needs.out_addr[k].regs[j][i]);
  1199.             }
  1200.  
  1201.               /* RELOAD_FOR_INSN reloads conflict with inputs, outputs,
  1202.              and operand addresses but not things used to reload
  1203.              them.  Similarly, RELOAD_FOR_OPERAND_ADDRESS reloads
  1204.              don't conflict with things needed to reload inputs or
  1205.              outputs. */
  1206.  
  1207.               in_max = MAX (MAX (insn_needs.op_addr.regs[j][i],
  1208.                      insn_needs.op_addr_reload.regs[j][i]),
  1209.                     in_max);
  1210.  
  1211.               out_max = MAX (out_max, insn_needs.insn.regs[j][i]);
  1212.  
  1213.               insn_needs.input.regs[j][i]
  1214.             = MAX (insn_needs.input.regs[j][i]
  1215.                    + insn_needs.op_addr.regs[j][i]
  1216.                    + insn_needs.insn.regs[j][i],
  1217.                    in_max + insn_needs.input.regs[j][i]);
  1218.  
  1219.               insn_needs.output.regs[j][i] += out_max;
  1220.               insn_needs.other.regs[j][i]
  1221.             += MAX (MAX (insn_needs.input.regs[j][i],
  1222.                      insn_needs.output.regs[j][i]),
  1223.                 insn_needs.other_addr.regs[j][i]);
  1224.  
  1225.             }
  1226.  
  1227.           /* Now compute group needs.  */
  1228.           for (in_max = 0, out_max = 0, j = 0;
  1229.                j < reload_n_operands; j++)
  1230.             {
  1231.               in_max = MAX (in_max, insn_needs.in_addr[j].groups[i]);
  1232.               out_max
  1233.             = MAX (out_max, insn_needs.out_addr[j].groups[i]);
  1234.             }
  1235.  
  1236.           in_max = MAX (MAX (insn_needs.op_addr.groups[i],
  1237.                      insn_needs.op_addr_reload.groups[i]),
  1238.                 in_max);
  1239.           out_max = MAX (out_max, insn_needs.insn.groups[i]);
  1240.  
  1241.           insn_needs.input.groups[i]
  1242.             = MAX (insn_needs.input.groups[i]
  1243.                + insn_needs.op_addr.groups[i]
  1244.                + insn_needs.insn.groups[i],
  1245.                in_max + insn_needs.input.groups[i]);
  1246.  
  1247.           insn_needs.output.groups[i] += out_max;
  1248.           insn_needs.other.groups[i]
  1249.             += MAX (MAX (insn_needs.input.groups[i],
  1250.                  insn_needs.output.groups[i]),
  1251.                 insn_needs.other_addr.groups[i]);
  1252.         }
  1253.  
  1254.           /* If this is a CALL_INSN and caller-saves will need
  1255.          a spill register, act as if the spill register is
  1256.          needed for this insn.   However, the spill register
  1257.          can be used by any reload of this insn, so we only
  1258.          need do something if no need for that class has
  1259.          been recorded.
  1260.  
  1261.          The assumption that every CALL_INSN will trigger a
  1262.          caller-save is highly conservative, however, the number
  1263.          of cases where caller-saves will need a spill register but
  1264.          a block containing a CALL_INSN won't need a spill register
  1265.          of that class should be quite rare.
  1266.  
  1267.          If a group is needed, the size and mode of the group will
  1268.          have been set up at the beginning of this loop.  */
  1269.  
  1270.           if (GET_CODE (insn) == CALL_INSN
  1271.           && caller_save_spill_class != NO_REGS)
  1272.         {
  1273.           /* See if this register would conflict with any reload
  1274.              that needs a group.  */
  1275.           int nongroup_need = 0;
  1276.           int *caller_save_needs;
  1277.  
  1278.           for (j = 0; j < n_reloads; j++)
  1279.             if ((CLASS_MAX_NREGS (reload_reg_class[j],
  1280.                       (GET_MODE_SIZE (reload_outmode[j])
  1281.                        > GET_MODE_SIZE (reload_inmode[j]))
  1282.                       ? reload_outmode[j]
  1283.                       : reload_inmode[j])
  1284.              > 1)
  1285.             && reg_classes_intersect_p (caller_save_spill_class,
  1286.                             reload_reg_class[j]))
  1287.               {
  1288.             nongroup_need = 1;
  1289.             break;
  1290.               }
  1291.  
  1292.           caller_save_needs 
  1293.             = (caller_save_group_size > 1
  1294.                ? insn_needs.other.groups
  1295.                : insn_needs.other.regs[nongroup_need]); 
  1296.  
  1297.           if (caller_save_needs[(int) caller_save_spill_class] == 0)
  1298.             {
  1299.               register enum reg_class *p
  1300.             = reg_class_superclasses[(int) caller_save_spill_class];
  1301.  
  1302.               caller_save_needs[(int) caller_save_spill_class]++;
  1303.  
  1304.               while (*p != LIM_REG_CLASSES)
  1305.             caller_save_needs[(int) *p++] += 1;
  1306.             }
  1307.  
  1308.           /* Show that this basic block will need a register of
  1309.                    this class.  */
  1310.  
  1311.           if (global
  1312.               && ! (basic_block_needs[(int) caller_save_spill_class]
  1313.                 [this_block]))
  1314.             {
  1315.               basic_block_needs[(int) caller_save_spill_class]
  1316.             [this_block] = 1;
  1317.               new_basic_block_needs = 1;
  1318.             }
  1319.         }
  1320.  
  1321. #ifdef SMALL_REGISTER_CLASSES
  1322.           /* If this insn stores the value of a function call,
  1323.          and that value is in a register that has been spilled,
  1324.          and if the insn needs a reload in a class
  1325.          that might use that register as the reload register,
  1326.          then add add an extra need in that class.
  1327.          This makes sure we have a register available that does
  1328.          not overlap the return value.  */
  1329.  
  1330.           if (avoid_return_reg)
  1331.         {
  1332.           int regno = REGNO (avoid_return_reg);
  1333.           int nregs
  1334.             = HARD_REGNO_NREGS (regno, GET_MODE (avoid_return_reg));
  1335.           int r;
  1336.           int basic_needs[N_REG_CLASSES], basic_groups[N_REG_CLASSES];
  1337.  
  1338.           /* First compute the "basic needs", which counts a
  1339.              need only in the smallest class in which it
  1340.              is required.  */
  1341.  
  1342.           bcopy ((char *) insn_needs.other.regs[0],
  1343.              (char *) basic_needs, sizeof basic_needs);
  1344.           bcopy ((char *) insn_needs.other.groups,
  1345.              (char *) basic_groups, sizeof basic_groups);
  1346.  
  1347.           for (i = 0; i < N_REG_CLASSES; i++)
  1348.             {
  1349.               enum reg_class *p;
  1350.  
  1351.               if (basic_needs[i] >= 0)
  1352.             for (p = reg_class_superclasses[i];
  1353.                  *p != LIM_REG_CLASSES; p++)
  1354.               basic_needs[(int) *p] -= basic_needs[i];
  1355.  
  1356.               if (basic_groups[i] >= 0)
  1357.             for (p = reg_class_superclasses[i];
  1358.                  *p != LIM_REG_CLASSES; p++)
  1359.               basic_groups[(int) *p] -= basic_groups[i];
  1360.             }
  1361.  
  1362.           /* Now count extra regs if there might be a conflict with
  1363.              the return value register. */
  1364.  
  1365.           for (r = regno; r < regno + nregs; r++)
  1366.             if (spill_reg_order[r] >= 0)
  1367.               for (i = 0; i < N_REG_CLASSES; i++)
  1368.             if (TEST_HARD_REG_BIT (reg_class_contents[i], r))
  1369.               {
  1370.                 if (basic_needs[i] > 0)
  1371.                   {
  1372.                 enum reg_class *p;
  1373.  
  1374.                 insn_needs.other.regs[0][i]++;
  1375.                 p = reg_class_superclasses[i];
  1376.                 while (*p != LIM_REG_CLASSES)
  1377.                   insn_needs.other.regs[0][(int) *p++]++;
  1378.                   }
  1379.                 if (basic_groups[i] > 0)
  1380.                   {
  1381.                 enum reg_class *p;
  1382.  
  1383.                 insn_needs.other.groups[i]++;
  1384.                 p = reg_class_superclasses[i];
  1385.                 while (*p != LIM_REG_CLASSES)
  1386.                   insn_needs.other.groups[(int) *p++]++;
  1387.                   }
  1388.               }
  1389.         }
  1390. #endif /* SMALL_REGISTER_CLASSES */
  1391.  
  1392.           /* For each class, collect maximum need of any insn.  */
  1393.  
  1394.           for (i = 0; i < N_REG_CLASSES; i++)
  1395.         {
  1396.           if (max_needs[i] < insn_needs.other.regs[0][i])
  1397.             {
  1398.               max_needs[i] = insn_needs.other.regs[0][i];
  1399.               max_needs_insn[i] = insn;
  1400.             }
  1401.           if (max_groups[i] < insn_needs.other.groups[i])
  1402.             {
  1403.               max_groups[i] = insn_needs.other.groups[i];
  1404.               max_groups_insn[i] = insn;
  1405.             }
  1406.           if (max_nongroups[i] < insn_needs.other.regs[1][i])
  1407.             {
  1408.               max_nongroups[i] = insn_needs.other.regs[1][i];
  1409.               max_nongroups_insn[i] = insn;
  1410.             }
  1411.         }
  1412.         }
  1413.       /* Note that there is a continue statement above.  */
  1414.     }
  1415.  
  1416.       /* If we allocated any new memory locations, make another pass
  1417.      since it might have changed elimination offsets.  */
  1418.       if (starting_frame_size != get_frame_size ())
  1419.     something_changed = 1;
  1420.  
  1421.       if (dumpfile)
  1422.     for (i = 0; i < N_REG_CLASSES; i++)
  1423.       {
  1424.         if (max_needs[i] > 0)
  1425.           fprintf (dumpfile,
  1426.              ";; Need %d reg%s of class %s (for insn %d).\n",
  1427.                max_needs[i], max_needs[i] == 1 ? "" : "s",
  1428.                reg_class_names[i], INSN_UID (max_needs_insn[i]));
  1429.         if (max_nongroups[i] > 0)
  1430.           fprintf (dumpfile,
  1431.                ";; Need %d nongroup reg%s of class %s (for insn %d).\n",
  1432.                max_nongroups[i], max_nongroups[i] == 1 ? "" : "s",
  1433.                reg_class_names[i], INSN_UID (max_nongroups_insn[i]));
  1434.         if (max_groups[i] > 0)
  1435.           fprintf (dumpfile,
  1436.                ";; Need %d group%s (%smode) of class %s (for insn %d).\n",
  1437.                max_groups[i], max_groups[i] == 1 ? "" : "s",
  1438.                mode_name[(int) group_mode[i]],
  1439.                reg_class_names[i], INSN_UID (max_groups_insn[i]));
  1440.       }
  1441.              
  1442.       /* If we have caller-saves, set up the save areas and see if caller-save
  1443.      will need a spill register.  */
  1444.  
  1445.       if (caller_save_needed
  1446.       && ! setup_save_areas (&something_changed)
  1447.       && caller_save_spill_class  == NO_REGS)
  1448.     {
  1449.       /* The class we will need depends on whether the machine
  1450.          supports the sum of two registers for an address; see
  1451.          find_address_reloads for details.  */
  1452.  
  1453.       caller_save_spill_class
  1454.         = double_reg_address_ok ? INDEX_REG_CLASS : BASE_REG_CLASS;
  1455.       caller_save_group_size
  1456.         = CLASS_MAX_NREGS (caller_save_spill_class, Pmode);
  1457.       something_changed = 1;
  1458.     }
  1459.  
  1460.       /* See if anything that happened changes which eliminations are valid.
  1461.      For example, on the Sparc, whether or not the frame pointer can
  1462.      be eliminated can depend on what registers have been used.  We need
  1463.      not check some conditions again (such as flag_omit_frame_pointer)
  1464.      since they can't have changed.  */
  1465.  
  1466.       for (ep = reg_eliminate; ep < ®_eliminate[NUM_ELIMINABLE_REGS]; ep++)
  1467.     if ((ep->from == HARD_FRAME_POINTER_REGNUM && FRAME_POINTER_REQUIRED)
  1468. #ifdef ELIMINABLE_REGS
  1469.         || ! CAN_ELIMINATE (ep->from, ep->to)
  1470. #endif
  1471.         )
  1472.       ep->can_eliminate = 0;
  1473.  
  1474.       /* Look for the case where we have discovered that we can't replace
  1475.      register A with register B and that means that we will now be
  1476.      trying to replace register A with register C.  This means we can
  1477.      no longer replace register C with register B and we need to disable
  1478.      such an elimination, if it exists.  This occurs often with A == ap,
  1479.      B == sp, and C == fp.  */
  1480.  
  1481.       for (ep = reg_eliminate; ep < ®_eliminate[NUM_ELIMINABLE_REGS]; ep++)
  1482.     {
  1483.       struct elim_table *op;
  1484.       register int new_to = -1;
  1485.  
  1486.       if (! ep->can_eliminate && ep->can_eliminate_previous)
  1487.         {
  1488.           /* Find the current elimination for ep->from, if there is a
  1489.          new one.  */
  1490.           for (op = reg_eliminate;
  1491.            op < ®_eliminate[NUM_ELIMINABLE_REGS]; op++)
  1492.         if (op->from == ep->from && op->can_eliminate)
  1493.           {
  1494.             new_to = op->to;
  1495.             break;
  1496.           }
  1497.  
  1498.           /* See if there is an elimination of NEW_TO -> EP->TO.  If so,
  1499.          disable it.  */
  1500.           for (op = reg_eliminate;
  1501.            op < ®_eliminate[NUM_ELIMINABLE_REGS]; op++)
  1502.         if (op->from == new_to && op->to == ep->to)
  1503.           op->can_eliminate = 0;
  1504.         }
  1505.     }
  1506.  
  1507.       /* See if any registers that we thought we could eliminate the previous
  1508.      time are no longer eliminable.  If so, something has changed and we
  1509.      must spill the register.  Also, recompute the number of eliminable
  1510.      registers and see if the frame pointer is needed; it is if there is
  1511.      no elimination of the frame pointer that we can perform.  */
  1512.  
  1513.       frame_pointer_needed = 1;
  1514.       for (ep = reg_eliminate; ep < ®_eliminate[NUM_ELIMINABLE_REGS]; ep++)
  1515.     {
  1516.       if (ep->can_eliminate && ep->from == FRAME_POINTER_REGNUM
  1517.           && ep->to != HARD_FRAME_POINTER_REGNUM)
  1518.         frame_pointer_needed = 0;
  1519.  
  1520.       if (! ep->can_eliminate && ep->can_eliminate_previous)
  1521.         {
  1522.           ep->can_eliminate_previous = 0;
  1523.           spill_hard_reg (ep->from, global, dumpfile, 1);
  1524.           something_changed = 1;
  1525.           num_eliminable--;
  1526.         }
  1527.     }
  1528.  
  1529. #if HARD_FRAME_POINTER_REGNUM != FRAME_POINTER_REGNUM
  1530.       /* If we didn't need a frame pointer last time, but we do now, spill
  1531.      the hard frame pointer.  */
  1532.       if (frame_pointer_needed && ! previous_frame_pointer_needed)
  1533.     {
  1534.       spill_hard_reg (HARD_FRAME_POINTER_REGNUM, global, dumpfile, 1);
  1535.       something_changed = 1;
  1536.     }
  1537. #endif
  1538.  
  1539.       /* If all needs are met, we win.  */
  1540.  
  1541.       for (i = 0; i < N_REG_CLASSES; i++)
  1542.     if (max_needs[i] > 0 || max_groups[i] > 0 || max_nongroups[i] > 0)
  1543.       break;
  1544.       if (i == N_REG_CLASSES && !new_basic_block_needs && ! something_changed)
  1545.     break;
  1546.  
  1547.       /* Not all needs are met; must spill some hard regs.  */
  1548.  
  1549.       /* Put all registers spilled so far back in potential_reload_regs, but
  1550.      put them at the front, since we've already spilled most of the
  1551.      pseudos in them (we might have left some pseudos unspilled if they
  1552.      were in a block that didn't need any spill registers of a conflicting
  1553.      class.  We used to try to mark off the need for those registers,
  1554.      but doing so properly is very complex and reallocating them is the
  1555.      simpler approach.  First, "pack" potential_reload_regs by pushing 
  1556.      any nonnegative entries towards the end.  That will leave room 
  1557.      for the registers we already spilled.
  1558.  
  1559.      Also, undo the marking of the spill registers from the last time
  1560.      around in FORBIDDEN_REGS since we will be probably be allocating
  1561.      them again below.
  1562.  
  1563.      ??? It is theoretically possible that we might end up not using one
  1564.      of our previously-spilled registers in this allocation, even though
  1565.      they are at the head of the list.  It's not clear what to do about
  1566.      this, but it was no better before, when we marked off the needs met
  1567.      by the previously-spilled registers.  With the current code, globals
  1568.      can be allocated into these registers, but locals cannot.  */
  1569.  
  1570.       if (n_spills)
  1571.     {
  1572.       for (i = j = FIRST_PSEUDO_REGISTER - 1; i >= 0; i--)
  1573.         if (potential_reload_regs[i] != -1)
  1574.           potential_reload_regs[j--] = potential_reload_regs[i];
  1575.  
  1576.       for (i = 0; i < n_spills; i++)
  1577.         {
  1578.           potential_reload_regs[i] = spill_regs[i];
  1579.           spill_reg_order[spill_regs[i]] = -1;
  1580.           CLEAR_HARD_REG_BIT (forbidden_regs, spill_regs[i]);
  1581.         }
  1582.  
  1583.       n_spills = 0;
  1584.     }
  1585.  
  1586.       /* Now find more reload regs to satisfy the remaining need
  1587.      Do it by ascending class number, since otherwise a reg
  1588.      might be spilled for a big class and might fail to count
  1589.      for a smaller class even though it belongs to that class.
  1590.  
  1591.      Count spilled regs in `spills', and add entries to
  1592.      `spill_regs' and `spill_reg_order'.
  1593.  
  1594.      ??? Note there is a problem here.
  1595.      When there is a need for a group in a high-numbered class,
  1596.      and also need for non-group regs that come from a lower class,
  1597.      the non-group regs are chosen first.  If there aren't many regs,
  1598.      they might leave no room for a group.
  1599.  
  1600.      This was happening on the 386.  To fix it, we added the code
  1601.      that calls possible_group_p, so that the lower class won't
  1602.      break up the last possible group.
  1603.  
  1604.      Really fixing the problem would require changes above
  1605.      in counting the regs already spilled, and in choose_reload_regs.
  1606.      It might be hard to avoid introducing bugs there.  */
  1607.  
  1608.       CLEAR_HARD_REG_SET (counted_for_groups);
  1609.       CLEAR_HARD_REG_SET (counted_for_nongroups);
  1610.  
  1611.       for (class = 0; class < N_REG_CLASSES; class++)
  1612.     {
  1613.       /* First get the groups of registers.
  1614.          If we got single registers first, we might fragment
  1615.          possible groups.  */
  1616.       while (max_groups[class] > 0)
  1617.         {
  1618.           /* If any single spilled regs happen to form groups,
  1619.          count them now.  Maybe we don't really need
  1620.          to spill another group.  */
  1621.           count_possible_groups (group_size, group_mode, max_groups,
  1622.                      class);
  1623.  
  1624.           if (max_groups[class] <= 0)
  1625.         break;
  1626.  
  1627.           /* Groups of size 2 (the only groups used on most machines)
  1628.          are treated specially.  */
  1629.           if (group_size[class] == 2)
  1630.         {
  1631.           /* First, look for a register that will complete a group.  */
  1632.           for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
  1633.             {
  1634.               int other;
  1635.  
  1636.               j = potential_reload_regs[i];
  1637.               if (j >= 0 && ! TEST_HARD_REG_BIT (bad_spill_regs, j)
  1638.               &&
  1639.               ((j > 0 && (other = j - 1, spill_reg_order[other] >= 0)
  1640.                 && TEST_HARD_REG_BIT (reg_class_contents[class], j)
  1641.                 && TEST_HARD_REG_BIT (reg_class_contents[class], other)
  1642.                 && HARD_REGNO_MODE_OK (other, group_mode[class])
  1643.                 && ! TEST_HARD_REG_BIT (counted_for_nongroups,
  1644.                             other)
  1645.                 /* We don't want one part of another group.
  1646.                    We could get "two groups" that overlap!  */
  1647.                 && ! TEST_HARD_REG_BIT (counted_for_groups, other))
  1648.                ||
  1649.                (j < FIRST_PSEUDO_REGISTER - 1
  1650.                 && (other = j + 1, spill_reg_order[other] >= 0)
  1651.                 && TEST_HARD_REG_BIT (reg_class_contents[class], j)
  1652.                 && TEST_HARD_REG_BIT (reg_class_contents[class], other)
  1653.                 && HARD_REGNO_MODE_OK (j, group_mode[class])
  1654.                 && ! TEST_HARD_REG_BIT (counted_for_nongroups,
  1655.                             other)
  1656.                 && ! TEST_HARD_REG_BIT (counted_for_groups,
  1657.                             other))))
  1658.             {
  1659.               register enum reg_class *p;
  1660.  
  1661.               /* We have found one that will complete a group,
  1662.                  so count off one group as provided.  */
  1663.               max_groups[class]--;
  1664.               p = reg_class_superclasses[class];
  1665.               while (*p != LIM_REG_CLASSES)
  1666.                 {
  1667.                   if (group_size [(int) *p] <= group_size [class])
  1668.                 max_groups[(int) *p]--;
  1669.                   p++;
  1670.                 }
  1671.  
  1672.               /* Indicate both these regs are part of a group.  */
  1673.               SET_HARD_REG_BIT (counted_for_groups, j);
  1674.               SET_HARD_REG_BIT (counted_for_groups, other);
  1675.               break;
  1676.             }
  1677.             }
  1678.           /* We can't complete a group, so start one.  */
  1679. #ifdef SMALL_REGISTER_CLASSES
  1680.           /* Look for a pair neither of which is explicitly used.  */
  1681.           if (i == FIRST_PSEUDO_REGISTER)
  1682.             for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
  1683.               {
  1684.             int k;
  1685.             j = potential_reload_regs[i];
  1686.             /* Verify that J+1 is a potential reload reg.  */
  1687.             for (k = 0; k < FIRST_PSEUDO_REGISTER; k++)
  1688.               if (potential_reload_regs[k] == j + 1)
  1689.                 break;
  1690.             if (j >= 0 && j + 1 < FIRST_PSEUDO_REGISTER
  1691.                 && k < FIRST_PSEUDO_REGISTER
  1692.                 && spill_reg_order[j] < 0 && spill_reg_order[j + 1] < 0
  1693.                 && TEST_HARD_REG_BIT (reg_class_contents[class], j)
  1694.                 && TEST_HARD_REG_BIT (reg_class_contents[class], j + 1)
  1695.                 && HARD_REGNO_MODE_OK (j, group_mode[class])
  1696.                 && ! TEST_HARD_REG_BIT (counted_for_nongroups,
  1697.                             j + 1)
  1698.                 && ! TEST_HARD_REG_BIT (bad_spill_regs, j + 1)
  1699.                 /* Reject J at this stage
  1700.                    if J+1 was explicitly used.  */
  1701.                 && ! regs_explicitly_used[j + 1])
  1702.               break;
  1703.               }
  1704. #endif
  1705.           /* Now try any group at all
  1706.              whose registers are not in bad_spill_regs.  */
  1707.           if (i == FIRST_PSEUDO_REGISTER)
  1708.             for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
  1709.               {
  1710.             int k;
  1711.             j = potential_reload_regs[i];
  1712.             /* Verify that J+1 is a potential reload reg.  */
  1713.             for (k = 0; k < FIRST_PSEUDO_REGISTER; k++)
  1714.               if (potential_reload_regs[k] == j + 1)
  1715.                 break;
  1716.             if (j >= 0 && j + 1 < FIRST_PSEUDO_REGISTER
  1717.                 && k < FIRST_PSEUDO_REGISTER
  1718.                 && spill_reg_order[j] < 0 && spill_reg_order[j + 1] < 0
  1719.                 && TEST_HARD_REG_BIT (reg_class_contents[class], j)
  1720.                 && TEST_HARD_REG_BIT (reg_class_contents[class], j + 1)
  1721.                 && HARD_REGNO_MODE_OK (j, group_mode[class])
  1722.                 && ! TEST_HARD_REG_BIT (counted_for_nongroups,
  1723.                             j + 1)
  1724.                 && ! TEST_HARD_REG_BIT (bad_spill_regs, j + 1))
  1725.               break;
  1726.               }
  1727.  
  1728.           /* I should be the index in potential_reload_regs
  1729.              of the new reload reg we have found.  */
  1730.  
  1731.           if (i >= FIRST_PSEUDO_REGISTER)
  1732.             {
  1733.               /* There are no groups left to spill.  */
  1734.               spill_failure (max_groups_insn[class]);
  1735.               failure = 1;
  1736.               goto failed;
  1737.             }
  1738.           else
  1739.             something_changed
  1740.               |= new_spill_reg (i, class, max_needs, NULL_PTR,
  1741.                     global, dumpfile);
  1742.         }
  1743.           else
  1744.         {
  1745.           /* For groups of more than 2 registers,
  1746.              look for a sufficient sequence of unspilled registers,
  1747.              and spill them all at once.  */
  1748.           for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
  1749.             {
  1750.               int k;
  1751.  
  1752.               j = potential_reload_regs[i];
  1753.               if (j >= 0
  1754.               && j + group_size[class] <= FIRST_PSEUDO_REGISTER
  1755.               && HARD_REGNO_MODE_OK (j, group_mode[class]))
  1756.             {
  1757.               /* Check each reg in the sequence.  */
  1758.               for (k = 0; k < group_size[class]; k++)
  1759.                 if (! (spill_reg_order[j + k] < 0
  1760.                    && ! TEST_HARD_REG_BIT (bad_spill_regs, j + k)
  1761.                    && TEST_HARD_REG_BIT (reg_class_contents[class], j + k)))
  1762.                   break;
  1763.               /* We got a full sequence, so spill them all.  */
  1764.               if (k == group_size[class])
  1765.                 {
  1766.                   register enum reg_class *p;
  1767.                   for (k = 0; k < group_size[class]; k++)
  1768.                 {
  1769.                   int idx;
  1770.                   SET_HARD_REG_BIT (counted_for_groups, j + k);
  1771.                   for (idx = 0; idx < FIRST_PSEUDO_REGISTER; idx++)
  1772.                     if (potential_reload_regs[idx] == j + k)
  1773.                       break;
  1774.                   something_changed
  1775.                     |= new_spill_reg (idx, class,
  1776.                               max_needs, NULL_PTR,
  1777.                               global, dumpfile);
  1778.                 }
  1779.  
  1780.                   /* We have found one that will complete a group,
  1781.                  so count off one group as provided.  */
  1782.                   max_groups[class]--;
  1783.                   p = reg_class_superclasses[class];
  1784.                   while (*p != LIM_REG_CLASSES)
  1785.                 {
  1786.                   if (group_size [(int) *p]
  1787.                       <= group_size [class])
  1788.                     max_groups[(int) *p]--;
  1789.                   p++;
  1790.                 }
  1791.                   break;
  1792.                 }
  1793.             }
  1794.             }
  1795.           /* We couldn't find any registers for this reload.
  1796.              Avoid going into an infinite loop.  */
  1797.           if (i >= FIRST_PSEUDO_REGISTER)
  1798.             {
  1799.               /* There are no groups left.  */
  1800.               spill_failure (max_groups_insn[class]);
  1801.               failure = 1;
  1802.               goto failed;
  1803.             }
  1804.         }
  1805.         }
  1806.  
  1807.       /* Now similarly satisfy all need for single registers.  */
  1808.  
  1809.       while (max_needs[class] > 0 || max_nongroups[class] > 0)
  1810.         {
  1811. #ifdef SMALL_REGISTER_CLASSES
  1812.           /* This should be right for all machines, but only the 386
  1813.          is known to need it, so this conditional plays safe.
  1814.          ??? For 2.5, try making this unconditional.  */
  1815.           /* If we spilled enough regs, but they weren't counted
  1816.          against the non-group need, see if we can count them now.
  1817.          If so, we can avoid some actual spilling.  */
  1818.           if (max_needs[class] <= 0 && max_nongroups[class] > 0)
  1819.         for (i = 0; i < n_spills; i++)
  1820.           if (TEST_HARD_REG_BIT (reg_class_contents[class],
  1821.                      spill_regs[i])
  1822.               && !TEST_HARD_REG_BIT (counted_for_groups,
  1823.                          spill_regs[i])
  1824.               && !TEST_HARD_REG_BIT (counted_for_nongroups,
  1825.                          spill_regs[i])
  1826.               && max_nongroups[class] > 0)
  1827.             {
  1828.               register enum reg_class *p;
  1829.  
  1830.               SET_HARD_REG_BIT (counted_for_nongroups, spill_regs[i]);
  1831.               max_nongroups[class]--;
  1832.               p = reg_class_superclasses[class];
  1833.               while (*p != LIM_REG_CLASSES)
  1834.             max_nongroups[(int) *p++]--;
  1835.             }
  1836.           if (max_needs[class] <= 0 && max_nongroups[class] <= 0)
  1837.         break;
  1838. #endif
  1839.  
  1840.           /* Consider the potential reload regs that aren't
  1841.          yet in use as reload regs, in order of preference.
  1842.          Find the most preferred one that's in this class.  */
  1843.  
  1844.           for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
  1845.         if (potential_reload_regs[i] >= 0
  1846.             && TEST_HARD_REG_BIT (reg_class_contents[class],
  1847.                       potential_reload_regs[i])
  1848.             /* If this reg will not be available for groups,
  1849.                pick one that does not foreclose possible groups.
  1850.                This is a kludge, and not very general,
  1851.                but it should be sufficient to make the 386 work,
  1852.                and the problem should not occur on machines with
  1853.                more registers.  */
  1854.             && (max_nongroups[class] == 0
  1855.             || possible_group_p (potential_reload_regs[i], max_groups)))
  1856.           break;
  1857.  
  1858.           /* If we couldn't get a register, try to get one even if we
  1859.          might foreclose possible groups.  This may cause problems
  1860.          later, but that's better than aborting now, since it is
  1861.          possible that we will, in fact, be able to form the needed
  1862.          group even with this allocation.  */
  1863.  
  1864.           if (i >= FIRST_PSEUDO_REGISTER
  1865.           && (asm_noperands (max_needs[class] > 0
  1866.                      ? max_needs_insn[class]
  1867.                      : max_nongroups_insn[class])
  1868.               < 0))
  1869.         for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
  1870.           if (potential_reload_regs[i] >= 0
  1871.               && TEST_HARD_REG_BIT (reg_class_contents[class],
  1872.                         potential_reload_regs[i]))
  1873.             break;
  1874.  
  1875.           /* I should be the index in potential_reload_regs
  1876.          of the new reload reg we have found.  */
  1877.  
  1878.           if (i >= FIRST_PSEUDO_REGISTER)
  1879.         {
  1880.           /* There are no possible registers left to spill.  */
  1881.           spill_failure (max_needs[class] > 0 ? max_needs_insn[class]
  1882.                  : max_nongroups_insn[class]);
  1883.           failure = 1;
  1884.           goto failed;
  1885.         }
  1886.           else
  1887.         something_changed
  1888.           |= new_spill_reg (i, class, max_needs, max_nongroups,
  1889.                     global, dumpfile);
  1890.         }
  1891.     }
  1892.     }
  1893.  
  1894.   /* If global-alloc was run, notify it of any register eliminations we have
  1895.      done.  */
  1896.   if (global)
  1897.     for (ep = reg_eliminate; ep < ®_eliminate[NUM_ELIMINABLE_REGS]; ep++)
  1898.       if (ep->can_eliminate)
  1899.     mark_elimination (ep->from, ep->to);
  1900.  
  1901.   /* Insert code to save and restore call-clobbered hard regs
  1902.      around calls.  Tell if what mode to use so that we will process
  1903.      those insns in reload_as_needed if we have to.  */
  1904.  
  1905.   if (caller_save_needed)
  1906.     save_call_clobbered_regs (num_eliminable ? QImode
  1907.                   : caller_save_spill_class != NO_REGS ? HImode
  1908.                   : VOIDmode);
  1909.  
  1910.   /* If a pseudo has no hard reg, delete the insns that made the equivalence.
  1911.      If that insn didn't set the register (i.e., it copied the register to
  1912.      memory), just delete that insn instead of the equivalencing insn plus
  1913.      anything now dead.  If we call delete_dead_insn on that insn, we may
  1914.      delete the insn that actually sets the register if the register die
  1915.      there and that is incorrect.  */
  1916.  
  1917.   for (i = FIRST_PSEUDO_REGISTER; i < max_regno; i++)
  1918.     if (reg_renumber[i] < 0 && reg_equiv_init[i] != 0
  1919.     && GET_CODE (reg_equiv_init[i]) != NOTE)
  1920.       {
  1921.     if (reg_set_p (regno_reg_rtx[i], PATTERN (reg_equiv_init[i])))
  1922.       delete_dead_insn (reg_equiv_init[i]);
  1923.     else
  1924.       {
  1925.         PUT_CODE (reg_equiv_init[i], NOTE);
  1926.         NOTE_SOURCE_FILE (reg_equiv_init[i]) = 0;
  1927.         NOTE_LINE_NUMBER (reg_equiv_init[i]) = NOTE_INSN_DELETED;
  1928.       }
  1929.       }
  1930.  
  1931.   /* Use the reload registers where necessary
  1932.      by generating move instructions to move the must-be-register
  1933.      values into or out of the reload registers.  */
  1934.  
  1935.   if (something_needs_reloads || something_needs_elimination
  1936.       || (caller_save_needed && num_eliminable)
  1937.       || caller_save_spill_class != NO_REGS)
  1938.     reload_as_needed (first, global);
  1939.  
  1940.   /* If we were able to eliminate the frame pointer, show that it is no
  1941.      longer live at the start of any basic block.  If it ls live by
  1942.      virtue of being in a pseudo, that pseudo will be marked live
  1943.      and hence the frame pointer will be known to be live via that
  1944.      pseudo.  */
  1945.  
  1946.   if (! frame_pointer_needed)
  1947.     for (i = 0; i < n_basic_blocks; i++)
  1948.       basic_block_live_at_start[i][HARD_FRAME_POINTER_REGNUM / REGSET_ELT_BITS]
  1949.     &= ~ ((REGSET_ELT_TYPE) 1 << (HARD_FRAME_POINTER_REGNUM
  1950.                       % REGSET_ELT_BITS));
  1951.  
  1952.   /* Come here (with failure set nonzero) if we can't get enough spill regs
  1953.      and we decide not to abort about it.  */
  1954.  failed:
  1955.  
  1956.   reload_in_progress = 0;
  1957.  
  1958.   /* Now eliminate all pseudo regs by modifying them into
  1959.      their equivalent memory references.
  1960.      The REG-rtx's for the pseudos are modified in place,
  1961.      so all insns that used to refer to them now refer to memory.
  1962.  
  1963.      For a reg that has a reg_equiv_address, all those insns
  1964.      were changed by reloading so that no insns refer to it any longer;
  1965.      but the DECL_RTL of a variable decl may refer to it,
  1966.      and if so this causes the debugging info to mention the variable.  */
  1967.  
  1968.   for (i = FIRST_PSEUDO_REGISTER; i < max_regno; i++)
  1969.     {
  1970.       rtx addr = 0;
  1971.       int in_struct = 0;
  1972.       if (reg_equiv_mem[i])
  1973.     {
  1974.       addr = XEXP (reg_equiv_mem[i], 0);
  1975.       in_struct = MEM_IN_STRUCT_P (reg_equiv_mem[i]);
  1976.     }
  1977.       if (reg_equiv_address[i])
  1978.     addr = reg_equiv_address[i];
  1979.       if (addr)
  1980.     {
  1981.       if (reg_renumber[i] < 0)
  1982.         {
  1983.           rtx reg = regno_reg_rtx[i];
  1984.           XEXP (reg, 0) = addr;
  1985.           REG_USERVAR_P (reg) = 0;
  1986.           MEM_IN_STRUCT_P (reg) = in_struct;
  1987.           PUT_CODE (reg, MEM);
  1988.         }
  1989.       else if (reg_equiv_mem[i])
  1990.         XEXP (reg_equiv_mem[i], 0) = addr;
  1991.     }
  1992.     }
  1993.  
  1994. #ifdef PRESERVE_DEATH_INFO_REGNO_P
  1995.   /* Make a pass over all the insns and remove death notes for things that
  1996.      are no longer registers or no longer die in the insn (e.g., an input
  1997.      and output pseudo being tied).  */
  1998.  
  1999.   for (insn = first; insn; insn = NEXT_INSN (insn))
  2000.     if (GET_RTX_CLASS (GET_CODE (insn)) == 'i')
  2001.       {
  2002.     rtx note, next;
  2003.  
  2004.     for (note = REG_NOTES (insn); note; note = next)
  2005.       {
  2006.         next = XEXP (note, 1);
  2007.         if (REG_NOTE_KIND (note) == REG_DEAD
  2008.         && (GET_CODE (XEXP (note, 0)) != REG
  2009.             || reg_set_p (XEXP (note, 0), PATTERN (insn))))
  2010.           remove_note (insn, note);
  2011.       }
  2012.       }
  2013. #endif
  2014.  
  2015.   /* Indicate that we no longer have known memory locations or constants.  */
  2016.   reg_equiv_constant = 0;
  2017.   reg_equiv_memory_loc = 0;
  2018.  
  2019.   if (scratch_list)
  2020.     free (scratch_list);
  2021.   scratch_list = 0;
  2022. #ifdef MACHO_PIC
  2023.   scratch_list_length = 0;
  2024. #endif
  2025.   if (scratch_block)
  2026.     free (scratch_block);
  2027.   scratch_block = 0;
  2028.  
  2029.   return failure;
  2030. }
  2031.  
  2032. /* Nonzero if, after spilling reg REGNO for non-groups,
  2033.    it will still be possible to find a group if we still need one.  */
  2034.  
  2035. static int
  2036. possible_group_p (regno, max_groups)
  2037.      int regno;
  2038.      int *max_groups;
  2039. {
  2040.   int i;
  2041.   int class = (int) NO_REGS;
  2042.  
  2043.   for (i = 0; i < (int) N_REG_CLASSES; i++)
  2044.     if (max_groups[i] > 0)
  2045.       {
  2046.     class = i;
  2047.     break;
  2048.       }
  2049.  
  2050.   if (class == (int) NO_REGS)
  2051.     return 1;
  2052.  
  2053.   /* Consider each pair of consecutive registers.  */
  2054.   for (i = 0; i < FIRST_PSEUDO_REGISTER - 1; i++)
  2055.     {
  2056.       /* Ignore pairs that include reg REGNO.  */
  2057.       if (i == regno || i + 1 == regno)
  2058.     continue;
  2059.  
  2060.       /* Ignore pairs that are outside the class that needs the group.
  2061.      ??? Here we fail to handle the case where two different classes
  2062.      independently need groups.  But this never happens with our
  2063.      current machine descriptions.  */
  2064.       if (! (TEST_HARD_REG_BIT (reg_class_contents[class], i)
  2065.          && TEST_HARD_REG_BIT (reg_class_contents[class], i + 1)))
  2066.     continue;
  2067.  
  2068.       /* A pair of consecutive regs we can still spill does the trick.  */
  2069.       if (spill_reg_order[i] < 0 && spill_reg_order[i + 1] < 0
  2070.       && ! TEST_HARD_REG_BIT (bad_spill_regs, i)
  2071.       && ! TEST_HARD_REG_BIT (bad_spill_regs, i + 1))
  2072.     return 1;
  2073.  
  2074.       /* A pair of one already spilled and one we can spill does it
  2075.      provided the one already spilled is not otherwise reserved.  */
  2076.       if (spill_reg_order[i] < 0
  2077.       && ! TEST_HARD_REG_BIT (bad_spill_regs, i)
  2078.       && spill_reg_order[i + 1] >= 0
  2079.       && ! TEST_HARD_REG_BIT (counted_for_groups, i + 1)
  2080.       && ! TEST_HARD_REG_BIT (counted_for_nongroups, i + 1))
  2081.     return 1;
  2082.       if (spill_reg_order[i + 1] < 0
  2083.       && ! TEST_HARD_REG_BIT (bad_spill_regs, i + 1)
  2084.       && spill_reg_order[i] >= 0
  2085.       && ! TEST_HARD_REG_BIT (counted_for_groups, i)
  2086.       && ! TEST_HARD_REG_BIT (counted_for_nongroups, i))
  2087.     return 1;
  2088.     }
  2089.  
  2090.   return 0;
  2091. }
  2092.  
  2093. /* Count any groups of CLASS that can be formed from the registers recently
  2094.    spilled.  */
  2095.  
  2096. static void
  2097. count_possible_groups (group_size, group_mode, max_groups, class)
  2098.      int *group_size;
  2099.      enum machine_mode *group_mode;
  2100.      int *max_groups;
  2101.      int class;
  2102. {
  2103.   HARD_REG_SET new;
  2104.   int i, j;
  2105.  
  2106.   /* Now find all consecutive groups of spilled registers
  2107.      and mark each group off against the need for such groups.
  2108.      But don't count them against ordinary need, yet.  */
  2109.  
  2110.   if (group_size[class] == 0)
  2111.     return;
  2112.  
  2113.   CLEAR_HARD_REG_SET (new);
  2114.  
  2115.   /* Make a mask of all the regs that are spill regs in class I.  */
  2116.   for (i = 0; i < n_spills; i++)
  2117.     if (TEST_HARD_REG_BIT (reg_class_contents[class], spill_regs[i])
  2118.     && ! TEST_HARD_REG_BIT (counted_for_groups, spill_regs[i])
  2119.     && ! TEST_HARD_REG_BIT (counted_for_nongroups, spill_regs[i]))
  2120.       SET_HARD_REG_BIT (new, spill_regs[i]);
  2121.  
  2122.   /* Find each consecutive group of them.  */
  2123.   for (i = 0; i < FIRST_PSEUDO_REGISTER && max_groups[class] > 0; i++)
  2124.     if (TEST_HARD_REG_BIT (new, i)
  2125.     && i + group_size[class] <= FIRST_PSEUDO_REGISTER
  2126.     && HARD_REGNO_MODE_OK (i, group_mode[class]))
  2127.       {
  2128.     for (j = 1; j < group_size[class]; j++)
  2129.       if (! TEST_HARD_REG_BIT (new, i + j))
  2130.         break;
  2131.  
  2132.     if (j == group_size[class])
  2133.       {
  2134.         /* We found a group.  Mark it off against this class's need for
  2135.            groups, and against each superclass too.  */
  2136.         register enum reg_class *p;
  2137.  
  2138.         max_groups[class]--;
  2139.         p = reg_class_superclasses[class];
  2140.         while (*p != LIM_REG_CLASSES)
  2141.           {
  2142.         if (group_size [(int) *p] <= group_size [class])
  2143.           max_groups[(int) *p]--;
  2144.         p++;
  2145.           }
  2146.  
  2147.         /* Don't count these registers again.  */
  2148.         for (j = 0; j < group_size[class]; j++)
  2149.           SET_HARD_REG_BIT (counted_for_groups, i + j);
  2150.       }
  2151.  
  2152.     /* Skip to the last reg in this group.  When i is incremented above,
  2153.        it will then point to the first reg of the next possible group.  */
  2154.     i += j - 1;
  2155.       }
  2156. }
  2157.  
  2158. /* ALLOCATE_MODE is a register mode that needs to be reloaded.  OTHER_MODE is
  2159.    another mode that needs to be reloaded for the same register class CLASS.
  2160.    If any reg in CLASS allows ALLOCATE_MODE but not OTHER_MODE, fail.
  2161.    ALLOCATE_MODE will never be smaller than OTHER_MODE.
  2162.  
  2163.    This code used to also fail if any reg in CLASS allows OTHER_MODE but not
  2164.    ALLOCATE_MODE.  This test is unnecessary, because we will never try to put
  2165.    something of mode ALLOCATE_MODE into an OTHER_MODE register.  Testing this
  2166.    causes unnecessary failures on machines requiring alignment of register
  2167.    groups when the two modes are different sizes, because the larger mode has
  2168.    more strict alignment rules than the smaller mode.  */
  2169.  
  2170. static int
  2171. modes_equiv_for_class_p (allocate_mode, other_mode, class)
  2172.      enum machine_mode allocate_mode, other_mode;
  2173.      enum reg_class class;
  2174. {
  2175.   register int regno;
  2176.   for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
  2177.     {
  2178.       if (TEST_HARD_REG_BIT (reg_class_contents[(int) class], regno)
  2179.       && HARD_REGNO_MODE_OK (regno, allocate_mode)
  2180.       && ! HARD_REGNO_MODE_OK (regno, other_mode))
  2181.     return 0;
  2182.     }
  2183.   return 1;
  2184. }
  2185.  
  2186. /* Handle the failure to find a register to spill.
  2187.    INSN should be one of the insns which needed this particular spill reg.  */
  2188.  
  2189. static void
  2190. spill_failure (insn)
  2191.      rtx insn;
  2192. {
  2193.   if (asm_noperands (PATTERN (insn)) >= 0)
  2194.     error_for_asm (insn, "`asm' needs too many reloads");
  2195.   else
  2196.     fatal_insn ("Unable to find a register to spill.", insn);
  2197. }
  2198.  
  2199. /* Add a new register to the tables of available spill-registers
  2200.     (as well as spilling all pseudos allocated to the register).
  2201.    I is the index of this register in potential_reload_regs.
  2202.    CLASS is the regclass whose need is being satisfied.
  2203.    MAX_NEEDS and MAX_NONGROUPS are the vectors of needs,
  2204.     so that this register can count off against them.
  2205.     MAX_NONGROUPS is 0 if this register is part of a group.
  2206.    GLOBAL and DUMPFILE are the same as the args that `reload' got.  */
  2207.  
  2208. static int
  2209. new_spill_reg (i, class, max_needs, max_nongroups, global, dumpfile)
  2210.      int i;
  2211.      int class;
  2212.      int *max_needs;
  2213.      int *max_nongroups;
  2214.      int global;
  2215.      FILE *dumpfile;
  2216. {
  2217.   register enum reg_class *p;
  2218.   int val;
  2219.   int regno = potential_reload_regs[i];
  2220.  
  2221.   if (i >= FIRST_PSEUDO_REGISTER)
  2222.     abort ();    /* Caller failed to find any register.  */
  2223.  
  2224. #ifdef HI_SUM_TARGET_REGNO
  2225.   if (regno != HI_SUM_TARGET_REGNO)
  2226. #endif
  2227.   if (fixed_regs[regno] || TEST_HARD_REG_BIT (forbidden_regs, regno))
  2228.     fatal ("fixed or forbidden register was spilled.\n\
  2229. This may be due to a compiler bug or to impossible asm\n\
  2230. statements or clauses.");
  2231.  
  2232.   /* Make reg REGNO an additional reload reg.  */
  2233.  
  2234.   potential_reload_regs[i] = -1;
  2235.   spill_regs[n_spills] = regno;
  2236.   spill_reg_order[regno] = n_spills;
  2237.   if (dumpfile)
  2238.     fprintf (dumpfile, "Spilling reg %d.\n", spill_regs[n_spills]);
  2239.  
  2240.   /* Clear off the needs we just satisfied.  */
  2241.  
  2242.   max_needs[class]--;
  2243.   p = reg_class_superclasses[class];
  2244.   while (*p != LIM_REG_CLASSES)
  2245.     max_needs[(int) *p++]--;
  2246.  
  2247.   if (max_nongroups && max_nongroups[class] > 0)
  2248.     {
  2249.       SET_HARD_REG_BIT (counted_for_nongroups, regno);
  2250.       max_nongroups[class]--;
  2251.       p = reg_class_superclasses[class];
  2252.       while (*p != LIM_REG_CLASSES)
  2253.     max_nongroups[(int) *p++]--;
  2254.     }
  2255.  
  2256.   /* Spill every pseudo reg that was allocated to this reg
  2257.      or to something that overlaps this reg.  */
  2258.  
  2259.   val = spill_hard_reg (spill_regs[n_spills], global, dumpfile, 0);
  2260.  
  2261.   /* If there are some registers still to eliminate and this register
  2262.      wasn't ever used before, additional stack space may have to be
  2263.      allocated to store this register.  Thus, we may have changed the offset
  2264.      between the stack and frame pointers, so mark that something has changed.
  2265.      (If new pseudos were spilled, thus requiring more space, VAL would have
  2266.      been set non-zero by the call to spill_hard_reg above since additional
  2267.      reloads may be needed in that case.
  2268.  
  2269.      One might think that we need only set VAL to 1 if this is a call-used
  2270.      register.  However, the set of registers that must be saved by the
  2271.      prologue is not identical to the call-used set.  For example, the
  2272.      register used by the call insn for the return PC is a call-used register,
  2273.      but must be saved by the prologue.  */
  2274.   if (num_eliminable && ! regs_ever_live[spill_regs[n_spills]])
  2275.     val = 1;
  2276.  
  2277.   regs_ever_live[spill_regs[n_spills]] = 1;
  2278.   n_spills++;
  2279.  
  2280.   return val;
  2281. }
  2282.  
  2283. /* Delete an unneeded INSN and any previous insns who sole purpose is loading
  2284.    data that is dead in INSN.  */
  2285.  
  2286. static void
  2287. delete_dead_insn (insn)
  2288.      rtx insn;
  2289. {
  2290.   rtx prev = prev_real_insn (insn);
  2291.   rtx prev_dest;
  2292.  
  2293.   /* If the previous insn sets a register that dies in our insn, delete it
  2294.      too.  */
  2295.   if (prev && GET_CODE (PATTERN (prev)) == SET
  2296.       && (prev_dest = SET_DEST (PATTERN (prev)), GET_CODE (prev_dest) == REG)
  2297.       && reg_mentioned_p (prev_dest, PATTERN (insn))
  2298.       && find_regno_note (insn, REG_DEAD, REGNO (prev_dest)))
  2299.     delete_dead_insn (prev);
  2300.  
  2301.   PUT_CODE (insn, NOTE);
  2302.   NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
  2303.   NOTE_SOURCE_FILE (insn) = 0;
  2304. }
  2305.  
  2306. /* Modify the home of pseudo-reg I.
  2307.    The new home is present in reg_renumber[I].
  2308.  
  2309.    FROM_REG may be the hard reg that the pseudo-reg is being spilled from;
  2310.    or it may be -1, meaning there is none or it is not relevant.
  2311.    This is used so that all pseudos spilled from a given hard reg
  2312.    can share one stack slot.  */
  2313.  
  2314. static void
  2315. alter_reg (i, from_reg)
  2316.      register int i;
  2317.      int from_reg;
  2318. {
  2319.   /* When outputting an inline function, this can happen
  2320.      for a reg that isn't actually used.  */
  2321.   if (regno_reg_rtx[i] == 0)
  2322.     return;
  2323.  
  2324.   /* If the reg got changed to a MEM at rtl-generation time,
  2325.      ignore it.  */
  2326.   if (GET_CODE (regno_reg_rtx[i]) != REG)
  2327.     return;
  2328.  
  2329.   /* Modify the reg-rtx to contain the new hard reg
  2330.      number or else to contain its pseudo reg number.  */
  2331.   REGNO (regno_reg_rtx[i])
  2332.     = reg_renumber[i] >= 0 ? reg_renumber[i] : i;
  2333.  
  2334.   /* If we have a pseudo that is needed but has no hard reg or equivalent,
  2335.      allocate a stack slot for it.  */
  2336.  
  2337.   if (reg_renumber[i] < 0
  2338.       && reg_n_refs[i] > 0
  2339.       && reg_equiv_constant[i] == 0
  2340.       && reg_equiv_memory_loc[i] == 0)
  2341.     {
  2342.       register rtx x;
  2343.       int inherent_size = PSEUDO_REGNO_BYTES (i);
  2344.       int total_size = MAX (inherent_size, reg_max_ref_width[i]);
  2345.       int adjust = 0;
  2346.  
  2347.       /* Each pseudo reg has an inherent size which comes from its own mode,
  2348.      and a total size which provides room for paradoxical subregs
  2349.      which refer to the pseudo reg in wider modes.
  2350.  
  2351.      We can use a slot already allocated if it provides both
  2352.      enough inherent space and enough total space.
  2353.      Otherwise, we allocate a new slot, making sure that it has no less
  2354.      inherent space, and no less total space, then the previous slot.  */
  2355.       if (from_reg == -1)
  2356.     {
  2357.       /* No known place to spill from => no slot to reuse.  */
  2358.       x = assign_stack_local (GET_MODE (regno_reg_rtx[i]), total_size, -1);
  2359.       if (BYTES_BIG_ENDIAN)
  2360.         /* Cancel the  big-endian correction done in assign_stack_local.
  2361.            Get the address of the beginning of the slot.
  2362.            This is so we can do a big-endian correction unconditionally
  2363.            below.  */
  2364.         adjust = inherent_size - total_size;
  2365.  
  2366.       RTX_UNCHANGING_P (x) = RTX_UNCHANGING_P (regno_reg_rtx[i]);
  2367.     }
  2368.       /* Reuse a stack slot if possible.  */
  2369.       else if (spill_stack_slot[from_reg] != 0
  2370.            && spill_stack_slot_width[from_reg] >= total_size
  2371.            && (GET_MODE_SIZE (GET_MODE (spill_stack_slot[from_reg]))
  2372.            >= inherent_size))
  2373.     x = spill_stack_slot[from_reg];
  2374.       /* Allocate a bigger slot.  */
  2375.       else
  2376.     {
  2377.       /* Compute maximum size needed, both for inherent size
  2378.          and for total size.  */
  2379.       enum machine_mode mode = GET_MODE (regno_reg_rtx[i]);
  2380.       rtx stack_slot;
  2381.       if (spill_stack_slot[from_reg])
  2382.         {
  2383.           if (GET_MODE_SIZE (GET_MODE (spill_stack_slot[from_reg]))
  2384.           > inherent_size)
  2385.         mode = GET_MODE (spill_stack_slot[from_reg]);
  2386.           if (spill_stack_slot_width[from_reg] > total_size)
  2387.         total_size = spill_stack_slot_width[from_reg];
  2388.         }
  2389.       /* Make a slot with that size.  */
  2390.       x = assign_stack_local (mode, total_size, -1);
  2391.       stack_slot = x;
  2392.       if (BYTES_BIG_ENDIAN)
  2393.         {
  2394.           /* Cancel the  big-endian correction done in assign_stack_local.
  2395.          Get the address of the beginning of the slot.
  2396.          This is so we can do a big-endian correction unconditionally
  2397.          below.  */
  2398.           adjust = GET_MODE_SIZE (mode) - total_size;
  2399.           if (adjust)
  2400.         stack_slot = gen_rtx (MEM, mode_for_size (total_size
  2401.                               * BITS_PER_UNIT,
  2402.                               MODE_INT, 1),
  2403.                       plus_constant (XEXP (x, 0), adjust));
  2404.         }
  2405.       spill_stack_slot[from_reg] = stack_slot;
  2406.       spill_stack_slot_width[from_reg] = total_size;
  2407.     }
  2408.  
  2409.       /* On a big endian machine, the "address" of the slot
  2410.      is the address of the low part that fits its inherent mode.  */
  2411.       if (BYTES_BIG_ENDIAN && inherent_size < total_size)
  2412.     adjust += (total_size - inherent_size);
  2413.  
  2414.       /* If we have any adjustment to make, or if the stack slot is the
  2415.      wrong mode, make a new stack slot.  */
  2416.       if (adjust != 0 || GET_MODE (x) != GET_MODE (regno_reg_rtx[i]))
  2417.     {
  2418.       x = gen_rtx (MEM, GET_MODE (regno_reg_rtx[i]),
  2419.                plus_constant (XEXP (x, 0), adjust));
  2420.       RTX_UNCHANGING_P (x) = RTX_UNCHANGING_P (regno_reg_rtx[i]);
  2421.     }
  2422.  
  2423.       /* Save the stack slot for later.   */
  2424.       reg_equiv_memory_loc[i] = x;
  2425.     }
  2426. }
  2427.  
  2428. /* Mark the slots in regs_ever_live for the hard regs
  2429.    used by pseudo-reg number REGNO.  */
  2430.  
  2431. void
  2432. mark_home_live (regno)
  2433.      int regno;
  2434. {
  2435.   register int i, lim;
  2436.   i = reg_renumber[regno];
  2437.   if (i < 0)
  2438.     return;
  2439.   lim = i + HARD_REGNO_NREGS (i, PSEUDO_REGNO_MODE (regno));
  2440.   while (i < lim)
  2441.     regs_ever_live[i++] = 1;
  2442. }
  2443.  
  2444. /* Mark the registers used in SCRATCH as being live.  */
  2445.  
  2446. static void
  2447. mark_scratch_live (scratch)
  2448.      rtx scratch;
  2449. {
  2450.   register int i;
  2451.   int regno = REGNO (scratch);
  2452.   int lim = regno + HARD_REGNO_NREGS (regno, GET_MODE (scratch));
  2453.  
  2454.   for (i = regno; i < lim; i++)
  2455.     regs_ever_live[i] = 1;
  2456. }
  2457.  
  2458. /* This function handles the tracking of elimination offsets around branches.
  2459.  
  2460.    X is a piece of RTL being scanned.
  2461.  
  2462.    INSN is the insn that it came from, if any.
  2463.  
  2464.    INITIAL_P is non-zero if we are to set the offset to be the initial
  2465.    offset and zero if we are setting the offset of the label to be the
  2466.    current offset.  */
  2467.  
  2468. static void
  2469. set_label_offsets (x, insn, initial_p)
  2470.      rtx x;
  2471.      rtx insn;
  2472.      int initial_p;
  2473. {
  2474.   enum rtx_code code = GET_CODE (x);
  2475.   rtx tem;
  2476.   int i;
  2477.   struct elim_table *p;
  2478.  
  2479.   switch (code)
  2480.     {
  2481.     case LABEL_REF:
  2482.       if (LABEL_REF_NONLOCAL_P (x))
  2483.     return;
  2484.  
  2485.       x = XEXP (x, 0);
  2486.  
  2487.       /* ... fall through ... */
  2488.  
  2489.     case CODE_LABEL:
  2490.       /* If we know nothing about this label, set the desired offsets.  Note
  2491.      that this sets the offset at a label to be the offset before a label
  2492.      if we don't know anything about the label.  This is not correct for
  2493.      the label after a BARRIER, but is the best guess we can make.  If
  2494.      we guessed wrong, we will suppress an elimination that might have
  2495.      been possible had we been able to guess correctly.  */
  2496.  
  2497.       if (! offsets_known_at[CODE_LABEL_NUMBER (x)])
  2498.     {
  2499.       for (i = 0; i < NUM_ELIMINABLE_REGS; i++)
  2500.         offsets_at[CODE_LABEL_NUMBER (x)][i]
  2501.           = (initial_p ? reg_eliminate[i].initial_offset
  2502.          : reg_eliminate[i].offset);
  2503.       offsets_known_at[CODE_LABEL_NUMBER (x)] = 1;
  2504.     }
  2505.  
  2506.       /* Otherwise, if this is the definition of a label and it is
  2507.      preceded by a BARRIER, set our offsets to the known offset of
  2508.      that label.  */
  2509.  
  2510.       else if (x == insn
  2511.            && (tem = prev_nonnote_insn (insn)) != 0
  2512.            && GET_CODE (tem) == BARRIER)
  2513.     {
  2514.       num_not_at_initial_offset = 0;
  2515.       for (i = 0; i < NUM_ELIMINABLE_REGS; i++)
  2516.         {
  2517.           reg_eliminate[i].offset = reg_eliminate[i].previous_offset
  2518.         = offsets_at[CODE_LABEL_NUMBER (x)][i];
  2519.           if (reg_eliminate[i].can_eliminate
  2520.           && (reg_eliminate[i].offset
  2521.               != reg_eliminate[i].initial_offset))
  2522.         num_not_at_initial_offset++;
  2523.         }
  2524.     }
  2525.  
  2526.       else
  2527.     /* If neither of the above cases is true, compare each offset
  2528.        with those previously recorded and suppress any eliminations
  2529.        where the offsets disagree.  */
  2530.  
  2531.     for (i = 0; i < NUM_ELIMINABLE_REGS; i++)
  2532.       if (offsets_at[CODE_LABEL_NUMBER (x)][i]
  2533.           != (initial_p ? reg_eliminate[i].initial_offset
  2534.           : reg_eliminate[i].offset))
  2535.         reg_eliminate[i].can_eliminate = 0;
  2536.  
  2537.       return;
  2538.  
  2539.     case JUMP_INSN:
  2540.       set_label_offsets (PATTERN (insn), insn, initial_p);
  2541.  
  2542.       /* ... fall through ... */
  2543.  
  2544.     case INSN:
  2545.     case CALL_INSN:
  2546.       /* Any labels mentioned in REG_LABEL notes can be branched to indirectly
  2547.      and hence must have all eliminations at their initial offsets.  */
  2548.       for (tem = REG_NOTES (x); tem; tem = XEXP (tem, 1))
  2549.     if (REG_NOTE_KIND (tem) == REG_LABEL)
  2550.       set_label_offsets (XEXP (tem, 0), insn, 1);
  2551.       return;
  2552.  
  2553.     case ADDR_VEC:
  2554.     case ADDR_DIFF_VEC:
  2555.       /* Each of the labels in the address vector must be at their initial
  2556.      offsets.  We want the first first for ADDR_VEC and the second
  2557.      field for ADDR_DIFF_VEC.  */
  2558.  
  2559.       for (i = 0; i < XVECLEN (x, code == ADDR_DIFF_VEC); i++)
  2560.     set_label_offsets (XVECEXP (x, code == ADDR_DIFF_VEC, i),
  2561.                insn, initial_p);
  2562.       return;
  2563.  
  2564.     case SET:
  2565.       /* We only care about setting PC.  If the source is not RETURN,
  2566.      IF_THEN_ELSE, or a label, disable any eliminations not at
  2567.      their initial offsets.  Similarly if any arm of the IF_THEN_ELSE
  2568.      isn't one of those possibilities.  For branches to a label,
  2569.      call ourselves recursively.
  2570.  
  2571.      Note that this can disable elimination unnecessarily when we have
  2572.      a non-local goto since it will look like a non-constant jump to
  2573.      someplace in the current function.  This isn't a significant
  2574.      problem since such jumps will normally be when all elimination
  2575.      pairs are back to their initial offsets.  */
  2576.  
  2577.       if (SET_DEST (x) != pc_rtx)
  2578.     return;
  2579.  
  2580.       switch (GET_CODE (SET_SRC (x)))
  2581.     {
  2582.     case PC:
  2583.     case RETURN:
  2584.       return;
  2585.  
  2586.     case LABEL_REF:
  2587.       set_label_offsets (XEXP (SET_SRC (x), 0), insn, initial_p);
  2588.       return;
  2589.  
  2590.     case IF_THEN_ELSE:
  2591.       tem = XEXP (SET_SRC (x), 1);
  2592.       if (GET_CODE (tem) == LABEL_REF)
  2593.         set_label_offsets (XEXP (tem, 0), insn, initial_p);
  2594.       else if (GET_CODE (tem) != PC && GET_CODE (tem) != RETURN)
  2595.         break;
  2596.  
  2597.       tem = XEXP (SET_SRC (x), 2);
  2598.       if (GET_CODE (tem) == LABEL_REF)
  2599.         set_label_offsets (XEXP (tem, 0), insn, initial_p);
  2600.       else if (GET_CODE (tem) != PC && GET_CODE (tem) != RETURN)
  2601.         break;
  2602.       return;
  2603.     }
  2604.  
  2605.       /* If we reach here, all eliminations must be at their initial
  2606.      offset because we are doing a jump to a variable address.  */
  2607.       for (p = reg_eliminate; p < ®_eliminate[NUM_ELIMINABLE_REGS]; p++)
  2608.     if (p->offset != p->initial_offset)
  2609.       p->can_eliminate = 0;
  2610.     }
  2611. }
  2612.  
  2613. /* Used for communication between the next two function to properly share
  2614.    the vector for an ASM_OPERANDS.  */
  2615.  
  2616. static struct rtvec_def *old_asm_operands_vec, *new_asm_operands_vec;
  2617.  
  2618. /* Scan X and replace any eliminable registers (such as fp) with a
  2619.    replacement (such as sp), plus an offset.
  2620.  
  2621.    MEM_MODE is the mode of an enclosing MEM.  We need this to know how
  2622.    much to adjust a register for, e.g., PRE_DEC.  Also, if we are inside a
  2623.    MEM, we are allowed to replace a sum of a register and the constant zero
  2624.    with the register, which we cannot do outside a MEM.  In addition, we need
  2625.    to record the fact that a register is referenced outside a MEM.
  2626.  
  2627.    If INSN is an insn, it is the insn containing X.  If we replace a REG
  2628.    in a SET_DEST with an equivalent MEM and INSN is non-zero, write a
  2629.    CLOBBER of the pseudo after INSN so find_equiv_regs will know that
  2630.    that the REG is being modified.
  2631.  
  2632.    Alternatively, INSN may be a note (an EXPR_LIST or INSN_LIST).
  2633.    That's used when we eliminate in expressions stored in notes.
  2634.    This means, do not set ref_outside_mem even if the reference
  2635.    is outside of MEMs.
  2636.  
  2637.    If we see a modification to a register we know about, take the
  2638.    appropriate action (see case SET, below).
  2639.  
  2640.    REG_EQUIV_MEM and REG_EQUIV_ADDRESS contain address that have had
  2641.    replacements done assuming all offsets are at their initial values.  If
  2642.    they are not, or if REG_EQUIV_ADDRESS is nonzero for a pseudo we
  2643.    encounter, return the actual location so that find_reloads will do
  2644.    the proper thing.  */
  2645.  
  2646. rtx
  2647. eliminate_regs (x, mem_mode, insn)
  2648.      rtx x;
  2649.      enum machine_mode mem_mode;
  2650.      rtx insn;
  2651. {
  2652.   enum rtx_code code = GET_CODE (x);
  2653.   struct elim_table *ep;
  2654.   int regno;
  2655.   rtx new;
  2656.   int i, j;
  2657.   char *fmt;
  2658.   int copied = 0;
  2659.  
  2660.   switch (code)
  2661.     {
  2662.     case CONST_INT:
  2663.     case CONST_DOUBLE:
  2664.     case CONST:
  2665.     case SYMBOL_REF:
  2666.     case CODE_LABEL:
  2667.     case PC:
  2668.     case CC0:
  2669.     case ASM_INPUT:
  2670.     case ADDR_VEC:
  2671.     case ADDR_DIFF_VEC:
  2672.     case RETURN:
  2673.       return x;
  2674.  
  2675.     case REG:
  2676.       regno = REGNO (x);
  2677.  
  2678.       /* First handle the case where we encounter a bare register that
  2679.      is eliminable.  Replace it with a PLUS.  */
  2680.       if (regno < FIRST_PSEUDO_REGISTER)
  2681.     {
  2682.       for (ep = reg_eliminate; ep < ®_eliminate[NUM_ELIMINABLE_REGS];
  2683.            ep++)
  2684.         if (ep->from_rtx == x && ep->can_eliminate)
  2685.           {
  2686.         if (! mem_mode
  2687.             /* Refs inside notes don't count for this purpose.  */
  2688.             && ! (insn != 0 && (GET_CODE (insn) == EXPR_LIST
  2689.                     || GET_CODE (insn) == INSN_LIST)))
  2690.           ep->ref_outside_mem = 1;
  2691.         return plus_constant (ep->to_rtx, ep->previous_offset);
  2692.           }
  2693.  
  2694.     }
  2695.       else if (reg_equiv_memory_loc && reg_equiv_memory_loc[regno]
  2696.            && (reg_equiv_address[regno] || num_not_at_initial_offset))
  2697.     {
  2698.       /* In this case, find_reloads would attempt to either use an
  2699.          incorrect address (if something is not at its initial offset)
  2700.          or substitute an replaced address into an insn (which loses
  2701.          if the offset is changed by some later action).  So we simply
  2702.          return the replaced stack slot (assuming it is changed by
  2703.          elimination) and ignore the fact that this is actually a
  2704.          reference to the pseudo.  Ensure we make a copy of the
  2705.          address in case it is shared.  */
  2706.       new = eliminate_regs (reg_equiv_memory_loc[regno],
  2707.                 mem_mode, insn);
  2708.       if (new != reg_equiv_memory_loc[regno])
  2709.         {
  2710.           cannot_omit_stores[regno] = 1;
  2711.           return copy_rtx (new);
  2712.         }
  2713.     }
  2714.       return x;
  2715.  
  2716.     case PLUS:
  2717.       /* If this is the sum of an eliminable register and a constant, rework
  2718.      the sum.   */
  2719.       if (GET_CODE (XEXP (x, 0)) == REG
  2720.       && REGNO (XEXP (x, 0)) < FIRST_PSEUDO_REGISTER
  2721.       && CONSTANT_P (XEXP (x, 1)))
  2722.     {
  2723.       for (ep = reg_eliminate; ep < ®_eliminate[NUM_ELIMINABLE_REGS];
  2724.            ep++)
  2725.         if (ep->from_rtx == XEXP (x, 0) && ep->can_eliminate)
  2726.           {
  2727.         if (! mem_mode
  2728.             /* Refs inside notes don't count for this purpose.  */
  2729.             && ! (insn != 0 && (GET_CODE (insn) == EXPR_LIST
  2730.                     || GET_CODE (insn) == INSN_LIST)))
  2731.           ep->ref_outside_mem = 1;
  2732.  
  2733.         /* The only time we want to replace a PLUS with a REG (this
  2734.            occurs when the constant operand of the PLUS is the negative
  2735.            of the offset) is when we are inside a MEM.  We won't want
  2736.            to do so at other times because that would change the
  2737.            structure of the insn in a way that reload can't handle.
  2738.            We special-case the commonest situation in
  2739.            eliminate_regs_in_insn, so just replace a PLUS with a
  2740.            PLUS here, unless inside a MEM.  */
  2741.         if (mem_mode != 0 && GET_CODE (XEXP (x, 1)) == CONST_INT
  2742.             && INTVAL (XEXP (x, 1)) == - ep->previous_offset)
  2743.           return ep->to_rtx;
  2744.         else
  2745.           return gen_rtx (PLUS, Pmode, ep->to_rtx,
  2746.                   plus_constant (XEXP (x, 1),
  2747.                          ep->previous_offset));
  2748.           }
  2749.  
  2750.       /* If the register is not eliminable, we are done since the other
  2751.          operand is a constant.  */
  2752.       return x;
  2753.     }
  2754.  
  2755.       /* If this is part of an address, we want to bring any constant to the
  2756.      outermost PLUS.  We will do this by doing register replacement in
  2757.      our operands and seeing if a constant shows up in one of them.
  2758.  
  2759.      We assume here this is part of an address (or a "load address" insn)
  2760.      since an eliminable register is not likely to appear in any other
  2761.      context.
  2762.  
  2763.      If we have (plus (eliminable) (reg)), we want to produce
  2764.      (plus (plus (replacement) (reg) (const))).  If this was part of a
  2765.      normal add insn, (plus (replacement) (reg)) will be pushed as a
  2766.      reload.  This is the desired action.  */
  2767.  
  2768.       {
  2769.     rtx new0 = eliminate_regs (XEXP (x, 0), mem_mode, insn);
  2770.     rtx new1 = eliminate_regs (XEXP (x, 1), mem_mode, insn);
  2771.  
  2772.     if (new0 != XEXP (x, 0) || new1 != XEXP (x, 1))
  2773.       {
  2774.         /* If one side is a PLUS and the other side is a pseudo that
  2775.            didn't get a hard register but has a reg_equiv_constant,
  2776.            we must replace the constant here since it may no longer
  2777.            be in the position of any operand.  */
  2778.         if (GET_CODE (new0) == PLUS && GET_CODE (new1) == REG
  2779.         && REGNO (new1) >= FIRST_PSEUDO_REGISTER
  2780.         && reg_renumber[REGNO (new1)] < 0
  2781.         && reg_equiv_constant != 0
  2782.         && reg_equiv_constant[REGNO (new1)] != 0)
  2783.           new1 = reg_equiv_constant[REGNO (new1)];
  2784.         else if (GET_CODE (new1) == PLUS && GET_CODE (new0) == REG
  2785.              && REGNO (new0) >= FIRST_PSEUDO_REGISTER
  2786.              && reg_renumber[REGNO (new0)] < 0
  2787.              && reg_equiv_constant[REGNO (new0)] != 0)
  2788.           new0 = reg_equiv_constant[REGNO (new0)];
  2789.  
  2790.         new = form_sum (new0, new1);
  2791.  
  2792.         /* As above, if we are not inside a MEM we do not want to
  2793.            turn a PLUS into something else.  We might try to do so here
  2794.            for an addition of 0 if we aren't optimizing.  */
  2795.         if (! mem_mode && GET_CODE (new) != PLUS)
  2796.           return gen_rtx (PLUS, GET_MODE (x), new, const0_rtx);
  2797.         else
  2798.           return new;
  2799.       }
  2800.       }
  2801.       return x;
  2802.  
  2803.     case MULT:
  2804.       /* If this is the product of an eliminable register and a 
  2805.      constant, apply the distribute law and move the constant out
  2806.      so that we have (plus (mult ..) ..).  This is needed in order
  2807.      to keep load-address insns valid.   This case is pathological.
  2808.      We ignore the possibility of overflow here.  */
  2809.       if (GET_CODE (XEXP (x, 0)) == REG
  2810.       && REGNO (XEXP (x, 0)) < FIRST_PSEUDO_REGISTER
  2811.       && GET_CODE (XEXP (x, 1)) == CONST_INT)
  2812.     for (ep = reg_eliminate; ep < ®_eliminate[NUM_ELIMINABLE_REGS];
  2813.          ep++)
  2814.       if (ep->from_rtx == XEXP (x, 0) && ep->can_eliminate)
  2815.         {
  2816.           if (! mem_mode
  2817.           /* Refs inside notes don't count for this purpose.  */
  2818.           && ! (insn != 0 && (GET_CODE (insn) == EXPR_LIST
  2819.                       || GET_CODE (insn) == INSN_LIST)))
  2820.         ep->ref_outside_mem = 1;
  2821.  
  2822.           return
  2823.         plus_constant (gen_rtx (MULT, Pmode, ep->to_rtx, XEXP (x, 1)),
  2824.                    ep->previous_offset * INTVAL (XEXP (x, 1)));
  2825.         }
  2826.  
  2827.       /* ... fall through ... */
  2828.  
  2829.     case CALL:
  2830.     case COMPARE:
  2831.     case MINUS:
  2832.     case DIV:      case UDIV:
  2833.     case MOD:      case UMOD:
  2834.     case AND:      case IOR:      case XOR:
  2835.     case ROTATERT: case ROTATE:
  2836.     case ASHIFTRT: case LSHIFTRT: case ASHIFT:
  2837.     case NE:       case EQ:
  2838.     case GE:       case GT:       case GEU:    case GTU:
  2839.     case LE:       case LT:       case LEU:    case LTU:
  2840.       {
  2841.     rtx new0 = eliminate_regs (XEXP (x, 0), mem_mode, insn);
  2842.     rtx new1
  2843.       = XEXP (x, 1) ? eliminate_regs (XEXP (x, 1), mem_mode, insn) : 0;
  2844.  
  2845.     if (new0 != XEXP (x, 0) || new1 != XEXP (x, 1))
  2846.       return gen_rtx (code, GET_MODE (x), new0, new1);
  2847.       }
  2848.       return x;
  2849.  
  2850.     case EXPR_LIST:
  2851.       /* If we have something in XEXP (x, 0), the usual case, eliminate it.  */
  2852.       if (XEXP (x, 0))
  2853.     {
  2854.       new = eliminate_regs (XEXP (x, 0), mem_mode, insn);
  2855.       if (new != XEXP (x, 0))
  2856.         x = gen_rtx (EXPR_LIST, REG_NOTE_KIND (x), new, XEXP (x, 1));
  2857.     }
  2858.  
  2859.       /* ... fall through ... */
  2860.  
  2861.     case INSN_LIST:
  2862.       /* Now do eliminations in the rest of the chain.  If this was
  2863.      an EXPR_LIST, this might result in allocating more memory than is
  2864.      strictly needed, but it simplifies the code.  */
  2865.       if (XEXP (x, 1))
  2866.     {
  2867.       new = eliminate_regs (XEXP (x, 1), mem_mode, insn);
  2868.       if (new != XEXP (x, 1))
  2869.         return gen_rtx (GET_CODE (x), GET_MODE (x), XEXP (x, 0), new);
  2870.     }
  2871.       return x;
  2872.  
  2873.     case PRE_INC:
  2874.     case POST_INC:
  2875.     case PRE_DEC:
  2876.     case POST_DEC:
  2877.       for (ep = reg_eliminate; ep < ®_eliminate[NUM_ELIMINABLE_REGS]; ep++)
  2878.     if (ep->to_rtx == XEXP (x, 0))
  2879.       {
  2880.         int size = GET_MODE_SIZE (mem_mode);
  2881.  
  2882.         /* If more bytes than MEM_MODE are pushed, account for them.  */
  2883. #ifdef PUSH_ROUNDING
  2884.         if (ep->to_rtx == stack_pointer_rtx)
  2885.           size = PUSH_ROUNDING (size);
  2886. #endif
  2887.         if (code == PRE_DEC || code == POST_DEC)
  2888.           ep->offset += size;
  2889.         else
  2890.           ep->offset -= size;
  2891.       }
  2892.  
  2893.       /* Fall through to generic unary operation case.  */
  2894.     case USE:
  2895.     case STRICT_LOW_PART:
  2896.     case NEG:          case NOT:
  2897.     case SIGN_EXTEND:  case ZERO_EXTEND:
  2898.     case TRUNCATE:     case FLOAT_EXTEND: case FLOAT_TRUNCATE:
  2899.     case FLOAT:        case FIX:
  2900.     case UNSIGNED_FIX: case UNSIGNED_FLOAT:
  2901.     case ABS:
  2902.     case SQRT:
  2903.     case FFS:
  2904.       new = eliminate_regs (XEXP (x, 0), mem_mode, insn);
  2905.       if (new != XEXP (x, 0))
  2906.     return gen_rtx (code, GET_MODE (x), new);
  2907.       return x;
  2908.  
  2909.     case SUBREG:
  2910.       /* Similar to above processing, but preserve SUBREG_WORD.
  2911.      Convert (subreg (mem)) to (mem) if not paradoxical.
  2912.      Also, if we have a non-paradoxical (subreg (pseudo)) and the
  2913.      pseudo didn't get a hard reg, we must replace this with the
  2914.      eliminated version of the memory location because push_reloads
  2915.      may do the replacement in certain circumstances.  */
  2916.       if (GET_CODE (SUBREG_REG (x)) == REG
  2917.       && (GET_MODE_SIZE (GET_MODE (x))
  2918.           <= GET_MODE_SIZE (GET_MODE (SUBREG_REG (x))))
  2919.       && reg_equiv_memory_loc != 0
  2920.       && reg_equiv_memory_loc[REGNO (SUBREG_REG (x))] != 0)
  2921.     {
  2922.       new = eliminate_regs (reg_equiv_memory_loc[REGNO (SUBREG_REG (x))],
  2923.                 mem_mode, insn);
  2924.  
  2925.       /* If we didn't change anything, we must retain the pseudo.  */
  2926.       if (new == reg_equiv_memory_loc[REGNO (SUBREG_REG (x))])
  2927.         new = SUBREG_REG (x);
  2928.       else
  2929.         {
  2930.           /* Otherwise, ensure NEW isn't shared in case we have to reload
  2931.          it.  */
  2932.           new = copy_rtx (new);
  2933.  
  2934.           /* In this case, we must show that the pseudo is used in this
  2935.          insn so that delete_output_reload will do the right thing.  */
  2936.           if (insn != 0 && GET_CODE (insn) != EXPR_LIST
  2937.           && GET_CODE (insn) != INSN_LIST)
  2938.         emit_insn_before (gen_rtx (USE, VOIDmode, SUBREG_REG (x)),
  2939.                   insn);
  2940.         }
  2941.     }
  2942.       else
  2943.     new = eliminate_regs (SUBREG_REG (x), mem_mode, insn);
  2944.  
  2945.       if (new != XEXP (x, 0))
  2946.     {
  2947.       if (GET_CODE (new) == MEM
  2948.           && (GET_MODE_SIZE (GET_MODE (x))
  2949.           <= GET_MODE_SIZE (GET_MODE (new)))
  2950. #ifdef LOAD_EXTEND_OP
  2951.           /* On these machines we will be reloading what is
  2952.          inside the SUBREG if it originally was a pseudo and
  2953.          the inner and outer modes are both a word or
  2954.          smaller.  So leave the SUBREG then.  */
  2955.           && ! (GET_CODE (SUBREG_REG (x)) == REG
  2956.             && GET_MODE_SIZE (GET_MODE (x)) <= UNITS_PER_WORD
  2957.             && GET_MODE_SIZE (GET_MODE (new)) <= UNITS_PER_WORD
  2958.             && (GET_MODE_SIZE (GET_MODE (x))
  2959.             > GET_MODE_SIZE (GET_MODE (new)))
  2960.             && INTEGRAL_MODE_P (GET_MODE (new))
  2961.             && LOAD_EXTEND_OP (GET_MODE (new)) != NIL)
  2962. #endif
  2963.           )
  2964.         {
  2965.           int offset = SUBREG_WORD (x) * UNITS_PER_WORD;
  2966.           enum machine_mode mode = GET_MODE (x);
  2967.  
  2968.           if (BYTES_BIG_ENDIAN)
  2969.         offset += (MIN (UNITS_PER_WORD,
  2970.                 GET_MODE_SIZE (GET_MODE (new)))
  2971.                - MIN (UNITS_PER_WORD, GET_MODE_SIZE (mode)));
  2972.  
  2973.           PUT_MODE (new, mode);
  2974.           XEXP (new, 0) = plus_constant (XEXP (new, 0), offset);
  2975.           return new;
  2976.         }
  2977.       else
  2978.         return gen_rtx (SUBREG, GET_MODE (x), new, SUBREG_WORD (x));
  2979.     }
  2980.  
  2981.       return x;
  2982.  
  2983.     case CLOBBER:
  2984.       /* If clobbering a register that is the replacement register for an
  2985.      elimination we still think can be performed, note that it cannot
  2986.      be performed.  Otherwise, we need not be concerned about it.  */
  2987.       for (ep = reg_eliminate; ep < ®_eliminate[NUM_ELIMINABLE_REGS]; ep++)
  2988.     if (ep->to_rtx == XEXP (x, 0))
  2989.       ep->can_eliminate = 0;
  2990.  
  2991.       new = eliminate_regs (XEXP (x, 0), mem_mode, insn);
  2992.       if (new != XEXP (x, 0))
  2993.     return gen_rtx (code, GET_MODE (x), new);
  2994.       return x;
  2995.  
  2996.     case ASM_OPERANDS:
  2997.       {
  2998.     rtx *temp_vec;
  2999.     /* Properly handle sharing input and constraint vectors.  */
  3000.     if (ASM_OPERANDS_INPUT_VEC (x) != old_asm_operands_vec)
  3001.       {
  3002.         /* When we come to a new vector not seen before,
  3003.            scan all its elements; keep the old vector if none
  3004.            of them changes; otherwise, make a copy.  */
  3005.         old_asm_operands_vec = ASM_OPERANDS_INPUT_VEC (x);
  3006.         temp_vec = (rtx *) alloca (XVECLEN (x, 3) * sizeof (rtx));
  3007.         for (i = 0; i < ASM_OPERANDS_INPUT_LENGTH (x); i++)
  3008.           temp_vec[i] = eliminate_regs (ASM_OPERANDS_INPUT (x, i),
  3009.                         mem_mode, insn);
  3010.  
  3011.         for (i = 0; i < ASM_OPERANDS_INPUT_LENGTH (x); i++)
  3012.           if (temp_vec[i] != ASM_OPERANDS_INPUT (x, i))
  3013.         break;
  3014.  
  3015.         if (i == ASM_OPERANDS_INPUT_LENGTH (x))
  3016.           new_asm_operands_vec = old_asm_operands_vec;
  3017.         else
  3018.           new_asm_operands_vec
  3019.         = gen_rtvec_v (ASM_OPERANDS_INPUT_LENGTH (x), temp_vec);
  3020.       }
  3021.  
  3022.     /* If we had to copy the vector, copy the entire ASM_OPERANDS.  */
  3023.     if (new_asm_operands_vec == old_asm_operands_vec)
  3024.       return x;
  3025.  
  3026.     new = gen_rtx (ASM_OPERANDS, VOIDmode, ASM_OPERANDS_TEMPLATE (x),
  3027.                ASM_OPERANDS_OUTPUT_CONSTRAINT (x),
  3028.                ASM_OPERANDS_OUTPUT_IDX (x), new_asm_operands_vec,
  3029.                ASM_OPERANDS_INPUT_CONSTRAINT_VEC (x),
  3030.                ASM_OPERANDS_SOURCE_FILE (x),
  3031.                ASM_OPERANDS_SOURCE_LINE (x));
  3032.     new->volatil = x->volatil;
  3033.     return new;
  3034.       }
  3035.  
  3036.     case SET:
  3037.       /* Check for setting a register that we know about.  */
  3038.       if (GET_CODE (SET_DEST (x)) == REG)
  3039.     {
  3040.       /* See if this is setting the replacement register for an
  3041.          elimination.
  3042.  
  3043.          If DEST is the hard frame pointer, we do nothing because we
  3044.          assume that all assignments to the frame pointer are for
  3045.          non-local gotos and are being done at a time when they are valid
  3046.          and do not disturb anything else.  Some machines want to
  3047.          eliminate a fake argument pointer (or even a fake frame pointer)
  3048.          with either the real frame or the stack pointer.  Assignments to
  3049.          the hard frame pointer must not prevent this elimination.  */
  3050.  
  3051.       for (ep = reg_eliminate; ep < ®_eliminate[NUM_ELIMINABLE_REGS];
  3052.            ep++)
  3053.         if (ep->to_rtx == SET_DEST (x)
  3054.         && SET_DEST (x) != hard_frame_pointer_rtx)
  3055.           {
  3056.         /* If it is being incremented, adjust the offset.  Otherwise,
  3057.            this elimination can't be done.  */
  3058.         rtx src = SET_SRC (x);
  3059.  
  3060.         if (GET_CODE (src) == PLUS
  3061.             && XEXP (src, 0) == SET_DEST (x)
  3062.             && GET_CODE (XEXP (src, 1)) == CONST_INT)
  3063.           ep->offset -= INTVAL (XEXP (src, 1));
  3064.         else
  3065.           ep->can_eliminate = 0;
  3066.           }
  3067.  
  3068.       /* Now check to see we are assigning to a register that can be
  3069.          eliminated.  If so, it must be as part of a PARALLEL, since we
  3070.          will not have been called if this is a single SET.  So indicate
  3071.          that we can no longer eliminate this reg.  */
  3072.       for (ep = reg_eliminate; ep < ®_eliminate[NUM_ELIMINABLE_REGS];
  3073.            ep++)
  3074.         if (ep->from_rtx == SET_DEST (x) && ep->can_eliminate)
  3075.           ep->can_eliminate = 0;
  3076.     }
  3077.  
  3078.       /* Now avoid the loop below in this common case.  */
  3079.       {
  3080.     rtx new0 = eliminate_regs (SET_DEST (x), 0, insn);
  3081.     rtx new1 = eliminate_regs (SET_SRC (x), 0, insn);
  3082.  
  3083.     /* If SET_DEST changed from a REG to a MEM and INSN is an insn,
  3084.        write a CLOBBER insn.  */
  3085.     if (GET_CODE (SET_DEST (x)) == REG && GET_CODE (new0) == MEM
  3086.         && insn != 0 && GET_CODE (insn) != EXPR_LIST
  3087.         && GET_CODE (insn) != INSN_LIST)
  3088.       emit_insn_after (gen_rtx (CLOBBER, VOIDmode, SET_DEST (x)), insn);
  3089.  
  3090.     if (new0 != SET_DEST (x) || new1 != SET_SRC (x))
  3091.       return gen_rtx (SET, VOIDmode, new0, new1);
  3092.       }
  3093.  
  3094.       return x;
  3095.  
  3096.     case MEM:
  3097.       /* Our only special processing is to pass the mode of the MEM to our
  3098.      recursive call and copy the flags.  While we are here, handle this
  3099.      case more efficiently.  */
  3100.       new = eliminate_regs (XEXP (x, 0), GET_MODE (x), insn);
  3101.       if (new != XEXP (x, 0))
  3102.     {
  3103.       new = gen_rtx (MEM, GET_MODE (x), new);
  3104.       new->volatil = x->volatil;
  3105.       new->unchanging = x->unchanging;
  3106.       new->in_struct = x->in_struct;
  3107.       return new;
  3108.     }
  3109.       else
  3110.     return x;
  3111.     }
  3112.  
  3113.   /* Process each of our operands recursively.  If any have changed, make a
  3114.      copy of the rtx.  */
  3115.   fmt = GET_RTX_FORMAT (code);
  3116.   for (i = 0; i < GET_RTX_LENGTH (code); i++, fmt++)
  3117.     {
  3118.       if (*fmt == 'e')
  3119.     {
  3120.       new = eliminate_regs (XEXP (x, i), mem_mode, insn);
  3121.       if (new != XEXP (x, i) && ! copied)
  3122.         {
  3123.           rtx new_x = rtx_alloc (code);
  3124.           bcopy ((char *) x, (char *) new_x,
  3125.              (sizeof (*new_x) - sizeof (new_x->fld)
  3126.               + sizeof (new_x->fld[0]) * GET_RTX_LENGTH (code)));
  3127.           x = new_x;
  3128.           copied = 1;
  3129.         }
  3130.       XEXP (x, i) = new;
  3131.     }
  3132.       else if (*fmt == 'E')
  3133.     {
  3134.       int copied_vec = 0;
  3135.       for (j = 0; j < XVECLEN (x, i); j++)
  3136.         {
  3137.           new = eliminate_regs (XVECEXP (x, i, j), mem_mode, insn);
  3138.           if (new != XVECEXP (x, i, j) && ! copied_vec)
  3139.         {
  3140.           rtvec new_v = gen_rtvec_v (XVECLEN (x, i),
  3141.                          &XVECEXP (x, i, 0));
  3142.           if (! copied)
  3143.             {
  3144.               rtx new_x = rtx_alloc (code);
  3145.               bcopy ((char *) x, (char *) new_x,
  3146.                  (sizeof (*new_x) - sizeof (new_x->fld)
  3147.                   + (sizeof (new_x->fld[0])
  3148.                  * GET_RTX_LENGTH (code))));
  3149.               x = new_x;
  3150.               copied = 1;
  3151.             }
  3152.           XVEC (x, i) = new_v;
  3153.           copied_vec = 1;
  3154.         }
  3155.           XVECEXP (x, i, j) = new;
  3156.         }
  3157.     }
  3158.     }
  3159.  
  3160.   return x;
  3161. }
  3162.  
  3163. /* Scan INSN and eliminate all eliminable registers in it.
  3164.  
  3165.    If REPLACE is nonzero, do the replacement destructively.  Also
  3166.    delete the insn as dead it if it is setting an eliminable register.
  3167.  
  3168.    If REPLACE is zero, do all our allocations in reload_obstack.
  3169.  
  3170.    If no eliminations were done and this insn doesn't require any elimination
  3171.    processing (these are not identical conditions: it might be updating sp,
  3172.    but not referencing fp; this needs to be seen during reload_as_needed so
  3173.    that the offset between fp and sp can be taken into consideration), zero
  3174.    is returned.  Otherwise, 1 is returned.  */
  3175.  
  3176. static int
  3177. eliminate_regs_in_insn (insn, replace)
  3178.      rtx insn;
  3179.      int replace;
  3180. {
  3181.   rtx old_body = PATTERN (insn);
  3182.   rtx old_set = single_set (insn);
  3183.   rtx new_body;
  3184.   int val = 0;
  3185.   struct elim_table *ep;
  3186.  
  3187.   if (! replace)
  3188.     push_obstacks (&reload_obstack, &reload_obstack);
  3189.  
  3190.   if (old_set != 0 && GET_CODE (SET_DEST (old_set)) == REG
  3191.       && REGNO (SET_DEST (old_set)) < FIRST_PSEUDO_REGISTER)
  3192.     {
  3193.       /* Check for setting an eliminable register.  */
  3194.       for (ep = reg_eliminate; ep < ®_eliminate[NUM_ELIMINABLE_REGS]; ep++)
  3195.     if (ep->from_rtx == SET_DEST (old_set) && ep->can_eliminate)
  3196.       {
  3197. #if HARD_FRAME_POINTER_REGNUM != FRAME_POINTER_REGNUM
  3198.         /* If this is setting the frame pointer register to the
  3199.            hardware frame pointer register and this is an elimination
  3200.            that will be done (tested above), this insn is really
  3201.            adjusting the frame pointer downward to compensate for
  3202.            the adjustment done before a nonlocal goto.  */
  3203.         if (ep->from == FRAME_POINTER_REGNUM
  3204.         && ep->to == HARD_FRAME_POINTER_REGNUM)
  3205.           {
  3206.         rtx src = SET_SRC (old_set);
  3207.         int offset, ok = 0;
  3208.  
  3209.         if (src == ep->to_rtx)
  3210.           offset = 0, ok = 1;
  3211.         else if (GET_CODE (src) == PLUS
  3212.              && GET_CODE (XEXP (src, 0)) == CONST_INT)
  3213.           offset = INTVAL (XEXP (src, 0)), ok = 1;
  3214.  
  3215.         if (ok)
  3216.           {
  3217.             if (replace)
  3218.               {
  3219.             rtx src
  3220.               = plus_constant (ep->to_rtx, offset - ep->offset);
  3221.  
  3222.             /* First see if this insn remains valid when we
  3223.                make the change.  If not, keep the INSN_CODE
  3224.                the same and let reload fit it up.  */
  3225.             validate_change (insn, &SET_SRC (old_set), src, 1);
  3226.             validate_change (insn, &SET_DEST (old_set),
  3227.                      ep->to_rtx, 1);
  3228.             if (! apply_change_group ())
  3229.               {
  3230.                 SET_SRC (old_set) = src;
  3231.                 SET_DEST (old_set) = ep->to_rtx;
  3232.               }
  3233.               }
  3234.  
  3235.             val = 1;
  3236.             goto done;
  3237.           }
  3238.           }
  3239. #endif
  3240.  
  3241.         /* In this case this insn isn't serving a useful purpose.  We
  3242.            will delete it in reload_as_needed once we know that this
  3243.            elimination is, in fact, being done.
  3244.  
  3245.            If REPLACE isn't set, we can't delete this insn, but needn't
  3246.            process it since it won't be used unless something changes.  */
  3247.         if (replace)
  3248.           delete_dead_insn (insn);
  3249.         val = 1;
  3250.         goto done;
  3251.       }
  3252.  
  3253.       /* Check for (set (reg) (plus (reg from) (offset))) where the offset
  3254.      in the insn is the negative of the offset in FROM.  Substitute
  3255.      (set (reg) (reg to)) for the insn and change its code.
  3256.  
  3257.      We have to do this here, rather than in eliminate_regs, do that we can
  3258.      change the insn code.  */
  3259.  
  3260.       if (GET_CODE (SET_SRC (old_set)) == PLUS
  3261.       && GET_CODE (XEXP (SET_SRC (old_set), 0)) == REG
  3262.       && GET_CODE (XEXP (SET_SRC (old_set), 1)) == CONST_INT)
  3263.     for (ep = reg_eliminate; ep < ®_eliminate[NUM_ELIMINABLE_REGS];
  3264.          ep++)
  3265.       if (ep->from_rtx == XEXP (SET_SRC (old_set), 0)
  3266.           && ep->can_eliminate)
  3267.         {
  3268.           /* We must stop at the first elimination that will be used.
  3269.          If this one would replace the PLUS with a REG, do it
  3270.          now.  Otherwise, quit the loop and let eliminate_regs
  3271.          do its normal replacement.  */
  3272.           if (ep->offset == - INTVAL (XEXP (SET_SRC (old_set), 1)))
  3273.         {
  3274.           /* We assume here that we don't need a PARALLEL of
  3275.              any CLOBBERs for this assignment.  There's not
  3276.              much we can do if we do need it.  */
  3277.           PATTERN (insn) = gen_rtx (SET, VOIDmode,
  3278.                         SET_DEST (old_set), ep->to_rtx);
  3279.           INSN_CODE (insn) = -1;
  3280.           val = 1;
  3281.           goto done;
  3282.         }
  3283.  
  3284.           break;
  3285.         }
  3286.     }
  3287.  
  3288.   old_asm_operands_vec = 0;
  3289.  
  3290.   /* Replace the body of this insn with a substituted form.  If we changed
  3291.      something, return non-zero.  
  3292.  
  3293.      If we are replacing a body that was a (set X (plus Y Z)), try to
  3294.      re-recognize the insn.  We do this in case we had a simple addition
  3295.      but now can do this as a load-address.  This saves an insn in this
  3296.      common case. */
  3297.  
  3298.   new_body = eliminate_regs (old_body, 0, replace ? insn : NULL_RTX);
  3299.   if (new_body != old_body)
  3300.     {
  3301.       /* If we aren't replacing things permanently and we changed something,
  3302.      make another copy to ensure that all the RTL is new.  Otherwise
  3303.      things can go wrong if find_reload swaps commutative operands
  3304.      and one is inside RTL that has been copied while the other is not. */
  3305.  
  3306.       /* Don't copy an asm_operands because (1) there's no need and (2)
  3307.      copy_rtx can't do it properly when there are multiple outputs.  */
  3308.       if (! replace && asm_noperands (old_body) < 0)
  3309.     new_body = copy_rtx (new_body);
  3310.  
  3311.       /* If we had a move insn but now we don't, rerecognize it.  This will
  3312.      cause spurious re-recognition if the old move had a PARALLEL since
  3313.      the new one still will, but we can't call single_set without
  3314.      having put NEW_BODY into the insn and the re-recognition won't
  3315.      hurt in this rare case.  */
  3316.       if (old_set != 0
  3317.       && ((GET_CODE (SET_SRC (old_set)) == REG
  3318.            && (GET_CODE (new_body) != SET
  3319.            || GET_CODE (SET_SRC (new_body)) != REG))
  3320.           /* If this was a load from or store to memory, compare
  3321.          the MEM in recog_operand to the one in the insn.  If they
  3322.          are not equal, then rerecognize the insn.  */
  3323.           || (old_set != 0
  3324.           && ((GET_CODE (SET_SRC (old_set)) == MEM
  3325.                && SET_SRC (old_set) != recog_operand[1])
  3326.               || (GET_CODE (SET_DEST (old_set)) == MEM
  3327.               && SET_DEST (old_set) != recog_operand[0])))
  3328.           /* If this was an add insn before, rerecognize.  */
  3329.           || GET_CODE (SET_SRC (old_set)) == PLUS))
  3330.     {
  3331.       if (! validate_change (insn, &PATTERN (insn), new_body, 0))
  3332.         /* If recognition fails, store the new body anyway.
  3333.            It's normal to have recognition failures here
  3334.            due to bizarre memory addresses; reloading will fix them.  */
  3335.         PATTERN (insn) = new_body;
  3336.     }
  3337.       else
  3338.     PATTERN (insn) = new_body;
  3339.  
  3340.       val = 1;
  3341.     }
  3342.  
  3343.   /* Loop through all elimination pairs.  See if any have changed and
  3344.      recalculate the number not at initial offset.
  3345.  
  3346.      Compute the maximum offset (minimum offset if the stack does not
  3347.      grow downward) for each elimination pair.
  3348.  
  3349.      We also detect a cases where register elimination cannot be done,
  3350.      namely, if a register would be both changed and referenced outside a MEM
  3351.      in the resulting insn since such an insn is often undefined and, even if
  3352.      not, we cannot know what meaning will be given to it.  Note that it is
  3353.      valid to have a register used in an address in an insn that changes it
  3354.      (presumably with a pre- or post-increment or decrement).
  3355.  
  3356.      If anything changes, return nonzero.  */
  3357.  
  3358.   num_not_at_initial_offset = 0;
  3359.   for (ep = reg_eliminate; ep < ®_eliminate[NUM_ELIMINABLE_REGS]; ep++)
  3360.     {
  3361.       if (ep->previous_offset != ep->offset && ep->ref_outside_mem)
  3362.     ep->can_eliminate = 0;
  3363.  
  3364.       ep->ref_outside_mem = 0;
  3365.  
  3366.       if (ep->previous_offset != ep->offset)
  3367.     val = 1;
  3368.  
  3369.       ep->previous_offset = ep->offset;
  3370.       if (ep->can_eliminate && ep->offset != ep->initial_offset)
  3371.     num_not_at_initial_offset++;
  3372.  
  3373. #ifdef STACK_GROWS_DOWNWARD
  3374.       ep->max_offset = MAX (ep->max_offset, ep->offset);
  3375. #else
  3376.       ep->max_offset = MIN (ep->max_offset, ep->offset);
  3377. #endif
  3378.     }
  3379.  
  3380.  done:
  3381.   /* If we changed something, perform elimination in REG_NOTES.  This is
  3382.      needed even when REPLACE is zero because a REG_DEAD note might refer
  3383.      to a register that we eliminate and could cause a different number
  3384.      of spill registers to be needed in the final reload pass than in
  3385.      the pre-passes.  */
  3386.   if (val && REG_NOTES (insn) != 0)
  3387.     REG_NOTES (insn) = eliminate_regs (REG_NOTES (insn), 0, REG_NOTES (insn));
  3388.  
  3389.   if (! replace)
  3390.     pop_obstacks ();
  3391.  
  3392.   return val;
  3393. }
  3394.  
  3395. /* Given X, a SET or CLOBBER of DEST, if DEST is the target of a register
  3396.    replacement we currently believe is valid, mark it as not eliminable if X
  3397.    modifies DEST in any way other than by adding a constant integer to it.
  3398.  
  3399.    If DEST is the frame pointer, we do nothing because we assume that
  3400.    all assignments to the hard frame pointer are nonlocal gotos and are being
  3401.    done at a time when they are valid and do not disturb anything else.
  3402.    Some machines want to eliminate a fake argument pointer with either the
  3403.    frame or stack pointer.  Assignments to the hard frame pointer must not
  3404.    prevent this elimination.
  3405.  
  3406.    Called via note_stores from reload before starting its passes to scan
  3407.    the insns of the function.  */
  3408.  
  3409. static void
  3410. mark_not_eliminable (dest, x)
  3411.      rtx dest;
  3412.      rtx x;
  3413. {
  3414.   register int i;
  3415.  
  3416.   /* A SUBREG of a hard register here is just changing its mode.  We should
  3417.      not see a SUBREG of an eliminable hard register, but check just in
  3418.      case.  */
  3419.   if (GET_CODE (dest) == SUBREG)
  3420.     dest = SUBREG_REG (dest);
  3421.  
  3422.   if (dest == hard_frame_pointer_rtx)
  3423.     return;
  3424.  
  3425.   for (i = 0; i < NUM_ELIMINABLE_REGS; i++)
  3426.     if (reg_eliminate[i].can_eliminate && dest == reg_eliminate[i].to_rtx
  3427.     && (GET_CODE (x) != SET
  3428.         || GET_CODE (SET_SRC (x)) != PLUS
  3429.         || XEXP (SET_SRC (x), 0) != dest
  3430.         || GET_CODE (XEXP (SET_SRC (x), 1)) != CONST_INT))
  3431.       {
  3432.     reg_eliminate[i].can_eliminate_previous
  3433.       = reg_eliminate[i].can_eliminate = 0;
  3434.     num_eliminable--;
  3435.       }
  3436. }
  3437.  
  3438. /* Kick all pseudos out of hard register REGNO.
  3439.    If GLOBAL is nonzero, try to find someplace else to put them.
  3440.    If DUMPFILE is nonzero, log actions taken on that file.
  3441.  
  3442.    If CANT_ELIMINATE is nonzero, it means that we are doing this spill
  3443.    because we found we can't eliminate some register.  In the case, no pseudos
  3444.    are allowed to be in the register, even if they are only in a block that
  3445.    doesn't require spill registers, unlike the case when we are spilling this
  3446.    hard reg to produce another spill register.
  3447.  
  3448.    Return nonzero if any pseudos needed to be kicked out.  */
  3449.  
  3450. static int
  3451. spill_hard_reg (regno, global, dumpfile, cant_eliminate)
  3452.      register int regno;
  3453.      int global;
  3454.      FILE *dumpfile;
  3455.      int cant_eliminate;
  3456. {
  3457.   enum reg_class class = REGNO_REG_CLASS (regno);
  3458.   int something_changed = 0;
  3459.   register int i;
  3460.  
  3461.   SET_HARD_REG_BIT (forbidden_regs, regno);
  3462.  
  3463.   if (cant_eliminate)
  3464.     regs_ever_live[regno] = 1;
  3465.  
  3466.   /* Spill every pseudo reg that was allocated to this reg
  3467.      or to something that overlaps this reg.  */
  3468.  
  3469.   for (i = FIRST_PSEUDO_REGISTER; i < max_regno; i++)
  3470.     if (reg_renumber[i] >= 0
  3471.     && reg_renumber[i] <= regno
  3472.     && (reg_renumber[i]
  3473.         + HARD_REGNO_NREGS (reg_renumber[i],
  3474.                 PSEUDO_REGNO_MODE (i))
  3475.         > regno))
  3476.       {
  3477.     /* If this register belongs solely to a basic block which needed no
  3478.        spilling of any class that this register is contained in,
  3479.        leave it be, unless we are spilling this register because
  3480.        it was a hard register that can't be eliminated.   */
  3481.  
  3482.     if (! cant_eliminate
  3483.         && basic_block_needs[0]
  3484.         && reg_basic_block[i] >= 0
  3485.         && basic_block_needs[(int) class][reg_basic_block[i]] == 0)
  3486.       {
  3487.         enum reg_class *p;
  3488.  
  3489.         for (p = reg_class_superclasses[(int) class];
  3490.          *p != LIM_REG_CLASSES; p++)
  3491.           if (basic_block_needs[(int) *p][reg_basic_block[i]] > 0)
  3492.         break;
  3493.  
  3494.         if (*p == LIM_REG_CLASSES)
  3495.           continue;
  3496.       }
  3497.  
  3498.     /* Mark it as no longer having a hard register home.  */
  3499.     reg_renumber[i] = -1;
  3500.     /* We will need to scan everything again.  */
  3501.     something_changed = 1;
  3502.     if (global)
  3503.         retry_global_alloc (i, forbidden_regs);
  3504.  
  3505.     alter_reg (i, regno);
  3506.     if (dumpfile)
  3507.       {
  3508.         if (reg_renumber[i] == -1)
  3509.           fprintf (dumpfile, " Register %d now on stack.\n\n", i);
  3510.         else
  3511.           fprintf (dumpfile, " Register %d now in %d.\n\n",
  3512.                i, reg_renumber[i]);
  3513.       }
  3514.       }
  3515.   for (i = 0; i < scratch_list_length; i++)
  3516.     {
  3517.       if (scratch_list[i] && REGNO (scratch_list[i]) == regno)
  3518.     {
  3519.       if (! cant_eliminate && basic_block_needs[0]
  3520.           && ! basic_block_needs[(int) class][scratch_block[i]])
  3521.         {
  3522.           enum reg_class *p;
  3523.  
  3524.           for (p = reg_class_superclasses[(int) class];
  3525.            *p != LIM_REG_CLASSES; p++)
  3526.         if (basic_block_needs[(int) *p][scratch_block[i]] > 0)
  3527.           break;
  3528.  
  3529.           if (*p == LIM_REG_CLASSES)
  3530.         continue;
  3531.         }
  3532.       PUT_CODE (scratch_list[i], SCRATCH);
  3533.       scratch_list[i] = 0;
  3534.       something_changed = 1;
  3535.       continue;
  3536.     }
  3537.     }
  3538.  
  3539.   return something_changed;
  3540. }
  3541.  
  3542. /* Find all paradoxical subregs within X and update reg_max_ref_width. 
  3543.    Also mark any hard registers used to store user variables as
  3544.    forbidden from being used for spill registers.  */
  3545.  
  3546. static void
  3547. scan_paradoxical_subregs (x)
  3548.      register rtx x;
  3549. {
  3550.   register int i;
  3551.   register char *fmt;
  3552.   register enum rtx_code code = GET_CODE (x);
  3553.  
  3554.   switch (code)
  3555.     {
  3556.     case REG:
  3557. #ifdef SMALL_REGISTER_CLASSES
  3558.       if (REGNO (x) < FIRST_PSEUDO_REGISTER && REG_USERVAR_P (x))
  3559.     SET_HARD_REG_BIT (forbidden_regs, REGNO (x));
  3560. #endif
  3561.       return;
  3562.  
  3563.     case CONST_INT:
  3564.     case CONST:
  3565.     case SYMBOL_REF:
  3566.     case LABEL_REF:
  3567.     case CONST_DOUBLE:
  3568.     case CC0:
  3569.     case PC:
  3570.     case USE:
  3571.     case CLOBBER:
  3572.       return;
  3573.  
  3574.     case SUBREG:
  3575.       if (GET_CODE (SUBREG_REG (x)) == REG
  3576.       && GET_MODE_SIZE (GET_MODE (x)) > GET_MODE_SIZE (GET_MODE (SUBREG_REG (x))))
  3577.     reg_max_ref_width[REGNO (SUBREG_REG (x))]
  3578.       = GET_MODE_SIZE (GET_MODE (x));
  3579.       return;
  3580.     }
  3581.  
  3582.   fmt = GET_RTX_FORMAT (code);
  3583.   for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
  3584.     {
  3585.       if (fmt[i] == 'e')
  3586.     scan_paradoxical_subregs (XEXP (x, i));
  3587.       else if (fmt[i] == 'E')
  3588.     {
  3589.       register int j;
  3590.       for (j = XVECLEN (x, i) - 1; j >=0; j--)
  3591.         scan_paradoxical_subregs (XVECEXP (x, i, j));
  3592.     }
  3593.     }
  3594. }
  3595.  
  3596. static int
  3597. hard_reg_use_compare (p1, p2)
  3598.      struct hard_reg_n_uses *p1, *p2;
  3599. {
  3600.   int tem = p1->uses - p2->uses;
  3601.   if (tem != 0) return tem;
  3602.   /* If regs are equally good, sort by regno,
  3603.      so that the results of qsort leave nothing to chance.  */
  3604.   return p1->regno - p2->regno;
  3605. }
  3606.  
  3607. /* Choose the order to consider regs for use as reload registers
  3608.    based on how much trouble would be caused by spilling one.
  3609.    Store them in order of decreasing preference in potential_reload_regs.  */
  3610.  
  3611. static void
  3612. order_regs_for_reload ()
  3613. {
  3614.   register int i;
  3615.   register int o = 0;
  3616.   int large = 0;
  3617.  
  3618.   struct hard_reg_n_uses hard_reg_n_uses[FIRST_PSEUDO_REGISTER];
  3619.  
  3620.   CLEAR_HARD_REG_SET (bad_spill_regs);
  3621.  
  3622.   for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
  3623.     potential_reload_regs[i] = -1;
  3624.  
  3625.   /* Count number of uses of each hard reg by pseudo regs allocated to it
  3626.      and then order them by decreasing use.  */
  3627.  
  3628.   for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
  3629.     {
  3630.       hard_reg_n_uses[i].uses = 0;
  3631.       hard_reg_n_uses[i].regno = i;
  3632.     }
  3633.  
  3634.   for (i = FIRST_PSEUDO_REGISTER; i < max_regno; i++)
  3635.     {
  3636.       int regno = reg_renumber[i];
  3637.       if (regno >= 0)
  3638.     {
  3639.       int lim = regno + HARD_REGNO_NREGS (regno, PSEUDO_REGNO_MODE (i));
  3640.       while (regno < lim)
  3641.         hard_reg_n_uses[regno++].uses += reg_n_refs[i];
  3642.     }
  3643.       large += reg_n_refs[i];
  3644.     }
  3645.  
  3646.   /* Now fixed registers (which cannot safely be used for reloading)
  3647.      get a very high use count so they will be considered least desirable.
  3648.      Registers used explicitly in the rtl code are almost as bad.  */
  3649.  
  3650.   for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
  3651.     {
  3652.       if (fixed_regs[i])
  3653.     {
  3654.       hard_reg_n_uses[i].uses += 2 * large + 2;
  3655.       SET_HARD_REG_BIT (bad_spill_regs, i);
  3656.     }
  3657.       else if (regs_explicitly_used[i])
  3658.     {
  3659.       hard_reg_n_uses[i].uses += large + 1;
  3660. #ifndef SMALL_REGISTER_CLASSES
  3661.       /* ??? We are doing this here because of the potential that
  3662.          bad code may be generated if a register explicitly used in
  3663.          an insn was used as a spill register for that insn.  But
  3664.          not using these are spill registers may lose on some machine.
  3665.          We'll have to see how this works out.  */
  3666.       SET_HARD_REG_BIT (bad_spill_regs, i);
  3667. #endif
  3668.     }
  3669.     }
  3670.   hard_reg_n_uses[HARD_FRAME_POINTER_REGNUM].uses += 2 * large + 2;
  3671.   SET_HARD_REG_BIT (bad_spill_regs, HARD_FRAME_POINTER_REGNUM);
  3672.  
  3673. #ifdef ELIMINABLE_REGS
  3674.   /* If registers other than the frame pointer are eliminable, mark them as
  3675.      poor choices.  */
  3676.   for (i = 0; i < NUM_ELIMINABLE_REGS; i++)
  3677.     {
  3678.       hard_reg_n_uses[reg_eliminate[i].from].uses += 2 * large + 2;
  3679.       SET_HARD_REG_BIT (bad_spill_regs, reg_eliminate[i].from);
  3680.     }
  3681. #endif
  3682.  
  3683.   /* Prefer registers not so far used, for use in temporary loading.
  3684.      Among them, if REG_ALLOC_ORDER is defined, use that order.
  3685.      Otherwise, prefer registers not preserved by calls.  */
  3686.  
  3687. #ifdef REG_ALLOC_ORDER
  3688.   for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
  3689.     {
  3690.       int regno = reg_alloc_order[i];
  3691.  
  3692.       if (hard_reg_n_uses[regno].uses == 0)
  3693.     potential_reload_regs[o++] = regno;
  3694.     }
  3695. #else
  3696.   for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
  3697.     {
  3698.       if (hard_reg_n_uses[i].uses == 0 && call_used_regs[i])
  3699.     potential_reload_regs[o++] = i;
  3700.     }
  3701.   for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
  3702.     {
  3703.       if (hard_reg_n_uses[i].uses == 0 && ! call_used_regs[i])
  3704.     potential_reload_regs[o++] = i;
  3705.     }
  3706. #endif
  3707.  
  3708.   qsort (hard_reg_n_uses, FIRST_PSEUDO_REGISTER,
  3709.      sizeof hard_reg_n_uses[0], hard_reg_use_compare);
  3710.  
  3711.   /* Now add the regs that are already used,
  3712.      preferring those used less often.  The fixed and otherwise forbidden
  3713.      registers will be at the end of this list.  */
  3714.  
  3715.   for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
  3716.     if (hard_reg_n_uses[i].uses != 0)
  3717.       potential_reload_regs[o++] = hard_reg_n_uses[i].regno;
  3718. }
  3719.  
  3720. /* Used in reload_as_needed to sort the spilled regs.  */
  3721.  
  3722. static int
  3723. compare_spill_regs (r1, r2)
  3724.      short *r1, *r2;
  3725. {
  3726.   return *r1 - *r2;
  3727. }
  3728.  
  3729. /* Reload pseudo-registers into hard regs around each insn as needed.
  3730.    Additional register load insns are output before the insn that needs it
  3731.    and perhaps store insns after insns that modify the reloaded pseudo reg.
  3732.  
  3733.    reg_last_reload_reg and reg_reloaded_contents keep track of
  3734.    which registers are already available in reload registers.
  3735.    We update these for the reloads that we perform,
  3736.    as the insns are scanned.  */
  3737.  
  3738. static void
  3739. reload_as_needed (first, live_known)
  3740.      rtx first;
  3741.      int live_known;
  3742. {
  3743.   register rtx insn;
  3744.   register int i;
  3745.   int this_block = 0;
  3746.   rtx x;
  3747.   rtx after_call = 0;
  3748.  
  3749.   bzero ((char *) spill_reg_rtx, sizeof spill_reg_rtx);
  3750.   bzero ((char *) spill_reg_store, sizeof spill_reg_store);
  3751.   reg_last_reload_reg = (rtx *) alloca (max_regno * sizeof (rtx));
  3752.   bzero ((char *) reg_last_reload_reg, max_regno * sizeof (rtx));
  3753.   reg_has_output_reload = (char *) alloca (max_regno);
  3754.   for (i = 0; i < n_spills; i++)
  3755.     {
  3756.       reg_reloaded_contents[i] = -1;
  3757.       reg_reloaded_insn[i] = 0;
  3758.     }
  3759.  
  3760.   /* Reset all offsets on eliminable registers to their initial values.  */
  3761. #ifdef ELIMINABLE_REGS
  3762.   for (i = 0; i < NUM_ELIMINABLE_REGS; i++)
  3763.     {
  3764.       INITIAL_ELIMINATION_OFFSET (reg_eliminate[i].from, reg_eliminate[i].to,
  3765.                   reg_eliminate[i].initial_offset);
  3766.       reg_eliminate[i].previous_offset
  3767.     = reg_eliminate[i].offset = reg_eliminate[i].initial_offset;
  3768.     }
  3769. #else
  3770.   INITIAL_FRAME_POINTER_OFFSET (reg_eliminate[0].initial_offset);
  3771.   reg_eliminate[0].previous_offset
  3772.     = reg_eliminate[0].offset = reg_eliminate[0].initial_offset;
  3773. #endif
  3774.  
  3775.   num_not_at_initial_offset = 0;
  3776.  
  3777.   /* Order the spilled regs, so that allocate_reload_regs can guarantee to
  3778.      pack registers with group needs.  */
  3779.   if (n_spills > 1)
  3780.     {
  3781.       qsort (spill_regs, n_spills, sizeof (short), compare_spill_regs);
  3782.       for (i = 0; i < n_spills; i++)
  3783.     spill_reg_order[spill_regs[i]] = i;
  3784.     }
  3785.  
  3786.   for (insn = first; insn;)
  3787.     {
  3788.       register rtx next = NEXT_INSN (insn);
  3789.  
  3790.       /* Notice when we move to a new basic block.  */
  3791.       if (live_known && this_block + 1 < n_basic_blocks
  3792.       && insn == basic_block_head[this_block+1])
  3793.     ++this_block;
  3794.  
  3795.       /* If we pass a label, copy the offsets from the label information
  3796.      into the current offsets of each elimination.  */
  3797.       if (GET_CODE (insn) == CODE_LABEL)
  3798.     {
  3799.       num_not_at_initial_offset = 0;
  3800.       for (i = 0; i < NUM_ELIMINABLE_REGS; i++)
  3801.         {
  3802.           reg_eliminate[i].offset = reg_eliminate[i].previous_offset
  3803.         = offsets_at[CODE_LABEL_NUMBER (insn)][i];
  3804.           if (reg_eliminate[i].can_eliminate
  3805.           && (reg_eliminate[i].offset
  3806.               != reg_eliminate[i].initial_offset))
  3807.         num_not_at_initial_offset++;
  3808.         }
  3809.     }
  3810.  
  3811.       else if (GET_RTX_CLASS (GET_CODE (insn)) == 'i')
  3812.     {
  3813.       rtx avoid_return_reg = 0;
  3814.       rtx oldpat = PATTERN (insn);
  3815.  
  3816. #ifdef SMALL_REGISTER_CLASSES
  3817.       /* Set avoid_return_reg if this is an insn
  3818.          that might use the value of a function call.  */
  3819.       if (GET_CODE (insn) == CALL_INSN)
  3820.         {
  3821.           if (GET_CODE (PATTERN (insn)) == SET)
  3822.         after_call = SET_DEST (PATTERN (insn));
  3823.           else if (GET_CODE (PATTERN (insn)) == PARALLEL
  3824.                && GET_CODE (XVECEXP (PATTERN (insn), 0, 0)) == SET)
  3825.         after_call = SET_DEST (XVECEXP (PATTERN (insn), 0, 0));
  3826.           else
  3827.         after_call = 0;
  3828.         }
  3829.       else if (after_call != 0
  3830.            && !(GET_CODE (PATTERN (insn)) == SET
  3831.             && SET_DEST (PATTERN (insn)) == stack_pointer_rtx))
  3832.         {
  3833.           if (reg_referenced_p (after_call, PATTERN (insn)))
  3834.         avoid_return_reg = after_call;
  3835.           after_call = 0;
  3836.         }
  3837. #endif /* SMALL_REGISTER_CLASSES */
  3838.  
  3839.       /* If this is a USE and CLOBBER of a MEM, ensure that any
  3840.          references to eliminable registers have been removed.  */
  3841.  
  3842.       if ((GET_CODE (PATTERN (insn)) == USE
  3843.            || GET_CODE (PATTERN (insn)) == CLOBBER)
  3844.           && GET_CODE (XEXP (PATTERN (insn), 0)) == MEM)
  3845.         XEXP (XEXP (PATTERN (insn), 0), 0)
  3846.           = eliminate_regs (XEXP (XEXP (PATTERN (insn), 0), 0),
  3847.                 GET_MODE (XEXP (PATTERN (insn), 0)), NULL_RTX);
  3848.  
  3849.       /* If we need to do register elimination processing, do so.
  3850.          This might delete the insn, in which case we are done.  */
  3851.       if (num_eliminable && GET_MODE (insn) == QImode)
  3852.         {
  3853.           eliminate_regs_in_insn (insn, 1);
  3854.           if (GET_CODE (insn) == NOTE)
  3855.         {
  3856.           insn = next;
  3857.           continue;
  3858.         }
  3859.         }
  3860.  
  3861.       if (GET_MODE (insn) == VOIDmode)
  3862.         n_reloads = 0;
  3863.       /* First find the pseudo regs that must be reloaded for this insn.
  3864.          This info is returned in the tables reload_... (see reload.h).
  3865.          Also modify the body of INSN by substituting RELOAD
  3866.          rtx's for those pseudo regs.  */
  3867.       else
  3868.         {
  3869.           bzero (reg_has_output_reload, max_regno);
  3870.           CLEAR_HARD_REG_SET (reg_is_output_reload);
  3871.  
  3872.           find_reloads (insn, 1, spill_indirect_levels, live_known,
  3873.                 spill_reg_order);
  3874.         }
  3875.  
  3876.       if (n_reloads > 0)
  3877.         {
  3878.           rtx prev = PREV_INSN (insn), next = NEXT_INSN (insn);
  3879.           rtx p;
  3880.           int class;
  3881.  
  3882.           /* If this block has not had spilling done for a
  3883.          particular clas and we have any non-optionals that need a
  3884.          spill reg in that class, abort.  */
  3885.  
  3886.           for (class = 0; class < N_REG_CLASSES; class++)
  3887.         if (basic_block_needs[class] != 0
  3888.             && basic_block_needs[class][this_block] == 0)
  3889.           for (i = 0; i < n_reloads; i++)
  3890.             if (class == (int) reload_reg_class[i]
  3891.             && reload_reg_rtx[i] == 0
  3892.             && ! reload_optional[i]
  3893.             && (reload_in[i] != 0 || reload_out[i] != 0
  3894.                 || reload_secondary_p[i] != 0))
  3895.               fatal_insn ("Non-optional registers need a spill register", insn);
  3896.  
  3897.           /* Now compute which reload regs to reload them into.  Perhaps
  3898.          reusing reload regs from previous insns, or else output
  3899.          load insns to reload them.  Maybe output store insns too.
  3900.          Record the choices of reload reg in reload_reg_rtx.  */
  3901.           choose_reload_regs (insn, avoid_return_reg);
  3902.  
  3903. #ifdef SMALL_REGISTER_CLASSES
  3904.           /* Merge any reloads that we didn't combine for fear of 
  3905.          increasing the number of spill registers needed but now
  3906.          discover can be safely merged.  */
  3907.           merge_assigned_reloads (insn);
  3908. #endif
  3909.  
  3910.           /* Generate the insns to reload operands into or out of
  3911.          their reload regs.  */
  3912.           emit_reload_insns (insn);
  3913.  
  3914.           /* Substitute the chosen reload regs from reload_reg_rtx
  3915.          into the insn's body (or perhaps into the bodies of other
  3916.          load and store insn that we just made for reloading
  3917.          and that we moved the structure into).  */
  3918.           subst_reloads ();
  3919.  
  3920.           /* If this was an ASM, make sure that all the reload insns
  3921.          we have generated are valid.  If not, give an error
  3922.          and delete them.  */
  3923.  
  3924.           if (asm_noperands (PATTERN (insn)) >= 0)
  3925.         for (p = NEXT_INSN (prev); p != next; p = NEXT_INSN (p))
  3926.           if (p != insn && GET_RTX_CLASS (GET_CODE (p)) == 'i'
  3927.               && (recog_memoized (p) < 0
  3928.               || (insn_extract (p),
  3929.                   ! constrain_operands (INSN_CODE (p), 1))))
  3930.             {
  3931.               error_for_asm (insn,
  3932.                      "`asm' operand requires impossible reload");
  3933.               PUT_CODE (p, NOTE);
  3934.               NOTE_SOURCE_FILE (p) = 0;
  3935.               NOTE_LINE_NUMBER (p) = NOTE_INSN_DELETED;
  3936.             }
  3937.         }
  3938.       /* Any previously reloaded spilled pseudo reg, stored in this insn,
  3939.          is no longer validly lying around to save a future reload.
  3940.          Note that this does not detect pseudos that were reloaded
  3941.          for this insn in order to be stored in
  3942.          (obeying register constraints).  That is correct; such reload
  3943.          registers ARE still valid.  */
  3944.       note_stores (oldpat, forget_old_reloads_1);
  3945.  
  3946.       /* There may have been CLOBBER insns placed after INSN.  So scan
  3947.          between INSN and NEXT and use them to forget old reloads.  */
  3948.       for (x = NEXT_INSN (insn); x != next; x = NEXT_INSN (x))
  3949.         if (GET_CODE (x) == INSN && GET_CODE (PATTERN (x)) == CLOBBER)
  3950.           note_stores (PATTERN (x), forget_old_reloads_1);
  3951.  
  3952. #ifdef AUTO_INC_DEC
  3953.       /* Likewise for regs altered by auto-increment in this insn.
  3954.          But note that the reg-notes are not changed by reloading:
  3955.          they still contain the pseudo-regs, not the spill regs.  */
  3956.       for (x = REG_NOTES (insn); x; x = XEXP (x, 1))
  3957.         if (REG_NOTE_KIND (x) == REG_INC)
  3958.           {
  3959.         /* See if this pseudo reg was reloaded in this insn.
  3960.            If so, its last-reload info is still valid
  3961.            because it is based on this insn's reload.  */
  3962.         for (i = 0; i < n_reloads; i++)
  3963.           if (reload_out[i] == XEXP (x, 0))
  3964.             break;
  3965.  
  3966.         if (i == n_reloads)
  3967.           forget_old_reloads_1 (XEXP (x, 0), NULL_RTX);
  3968.           }
  3969. #endif
  3970.     }
  3971.       /* A reload reg's contents are unknown after a label.  */
  3972.       if (GET_CODE (insn) == CODE_LABEL)
  3973.     for (i = 0; i < n_spills; i++)
  3974.       {
  3975.         reg_reloaded_contents[i] = -1;
  3976.         reg_reloaded_insn[i] = 0;
  3977.       }
  3978.  
  3979.       /* Don't assume a reload reg is still good after a call insn
  3980.      if it is a call-used reg.  */
  3981.       else if (GET_CODE (insn) == CALL_INSN)
  3982.     for (i = 0; i < n_spills; i++)
  3983.       if (call_used_regs[spill_regs[i]])
  3984.         {
  3985.           reg_reloaded_contents[i] = -1;
  3986.           reg_reloaded_insn[i] = 0;
  3987.         }
  3988.  
  3989.       /* In case registers overlap, allow certain insns to invalidate
  3990.      particular hard registers.  */
  3991.  
  3992. #ifdef INSN_CLOBBERS_REGNO_P
  3993.       for (i = 0 ; i < n_spills ; i++)
  3994.     if (INSN_CLOBBERS_REGNO_P (insn, spill_regs[i]))
  3995.       {
  3996.         reg_reloaded_contents[i] = -1;
  3997.         reg_reloaded_insn[i] = 0;
  3998.       }
  3999. #endif
  4000.  
  4001.       insn = next;
  4002.  
  4003. #ifdef USE_C_ALLOCA
  4004.       alloca (0);
  4005. #endif
  4006.     }
  4007. }
  4008.  
  4009. /* Discard all record of any value reloaded from X,
  4010.    or reloaded in X from someplace else;
  4011.    unless X is an output reload reg of the current insn.
  4012.  
  4013.    X may be a hard reg (the reload reg)
  4014.    or it may be a pseudo reg that was reloaded from.  */
  4015.  
  4016. static void
  4017. forget_old_reloads_1 (x, ignored)
  4018.      rtx x;
  4019.      rtx ignored;
  4020. {
  4021.   register int regno;
  4022.   int nr;
  4023.   int offset = 0;
  4024.  
  4025.   /* note_stores does give us subregs of hard regs.  */
  4026.   while (GET_CODE (x) == SUBREG)
  4027.     {
  4028.       offset += SUBREG_WORD (x);
  4029.       x = SUBREG_REG (x);
  4030.     }
  4031.  
  4032.   if (GET_CODE (x) != REG)
  4033.     return;
  4034.  
  4035.   regno = REGNO (x) + offset;
  4036.  
  4037.   if (regno >= FIRST_PSEUDO_REGISTER)
  4038.     nr = 1;
  4039.   else
  4040.     {
  4041.       int i;
  4042.       nr = HARD_REGNO_NREGS (regno, GET_MODE (x));
  4043.       /* Storing into a spilled-reg invalidates its contents.
  4044.      This can happen if a block-local pseudo is allocated to that reg
  4045.      and it wasn't spilled because this block's total need is 0.
  4046.      Then some insn might have an optional reload and use this reg.  */
  4047.       for (i = 0; i < nr; i++)
  4048.     if (spill_reg_order[regno + i] >= 0
  4049.         /* But don't do this if the reg actually serves as an output
  4050.            reload reg in the current instruction.  */
  4051.         && (n_reloads == 0
  4052.         || ! TEST_HARD_REG_BIT (reg_is_output_reload, regno + i)))
  4053.       {
  4054.         reg_reloaded_contents[spill_reg_order[regno + i]] = -1;
  4055.         reg_reloaded_insn[spill_reg_order[regno + i]] = 0;
  4056.       }
  4057.     }
  4058.  
  4059.   /* Since value of X has changed,
  4060.      forget any value previously copied from it.  */
  4061.  
  4062.   while (nr-- > 0)
  4063.     /* But don't forget a copy if this is the output reload
  4064.        that establishes the copy's validity.  */
  4065.     if (n_reloads == 0 || reg_has_output_reload[regno + nr] == 0)
  4066.       reg_last_reload_reg[regno + nr] = 0;
  4067. }
  4068.  
  4069. /* For each reload, the mode of the reload register.  */
  4070. static enum machine_mode reload_mode[MAX_RELOADS];
  4071.  
  4072. /* For each reload, the largest number of registers it will require.  */
  4073. static int reload_nregs[MAX_RELOADS];
  4074.  
  4075. /* Comparison function for qsort to decide which of two reloads
  4076.    should be handled first.  *P1 and *P2 are the reload numbers.  */
  4077.  
  4078. static int
  4079. reload_reg_class_lower (p1, p2)
  4080.      short *p1, *p2;
  4081. {
  4082.   register int r1 = *p1, r2 = *p2;
  4083.   register int t;
  4084.  
  4085.   /* Consider required reloads before optional ones.  */
  4086.   t = reload_optional[r1] - reload_optional[r2];
  4087.   if (t != 0)
  4088.     return t;
  4089.  
  4090.   /* Count all solitary classes before non-solitary ones.  */
  4091.   t = ((reg_class_size[(int) reload_reg_class[r2]] == 1)
  4092.        - (reg_class_size[(int) reload_reg_class[r1]] == 1));
  4093.   if (t != 0)
  4094.     return t;
  4095.  
  4096.   /* Aside from solitaires, consider all multi-reg groups first.  */
  4097.   t = reload_nregs[r2] - reload_nregs[r1];
  4098.   if (t != 0)
  4099.     return t;
  4100.  
  4101.   /* Consider reloads in order of increasing reg-class number.  */
  4102.   t = (int) reload_reg_class[r1] - (int) reload_reg_class[r2];
  4103.   if (t != 0)
  4104.     return t;
  4105.  
  4106.   /* If reloads are equally urgent, sort by reload number,
  4107.      so that the results of qsort leave nothing to chance.  */
  4108.   return r1 - r2;
  4109. }
  4110.  
  4111. /* The following HARD_REG_SETs indicate when each hard register is
  4112.    used for a reload of various parts of the current insn.  */
  4113.  
  4114. /* If reg is in use as a reload reg for a RELOAD_OTHER reload.  */
  4115. static HARD_REG_SET reload_reg_used;
  4116. /* If reg is in use for a RELOAD_FOR_INPUT_ADDRESS reload for operand I.  */
  4117. static HARD_REG_SET reload_reg_used_in_input_addr[MAX_RECOG_OPERANDS];
  4118. /* If reg is in use for a RELOAD_FOR_OUTPUT_ADDRESS reload for operand I.  */
  4119. static HARD_REG_SET reload_reg_used_in_output_addr[MAX_RECOG_OPERANDS];
  4120. /* If reg is in use for a RELOAD_FOR_INPUT reload for operand I.  */
  4121. static HARD_REG_SET reload_reg_used_in_input[MAX_RECOG_OPERANDS];
  4122. /* If reg is in use for a RELOAD_FOR_OUTPUT reload for operand I.  */
  4123. static HARD_REG_SET reload_reg_used_in_output[MAX_RECOG_OPERANDS];
  4124. /* If reg is in use for a RELOAD_FOR_OPERAND_ADDRESS reload.  */
  4125. static HARD_REG_SET reload_reg_used_in_op_addr;
  4126. /* If reg is in use for a RELOAD_FOR_OPADDR_ADDR reload.  */
  4127. static HARD_REG_SET reload_reg_used_in_op_addr_reload;
  4128. /* If reg is in use for a RELOAD_FOR_INSN reload.  */
  4129. static HARD_REG_SET reload_reg_used_in_insn;
  4130. /* If reg is in use for a RELOAD_FOR_OTHER_ADDRESS reload.  */
  4131. static HARD_REG_SET reload_reg_used_in_other_addr;
  4132.  
  4133. /* If reg is in use as a reload reg for any sort of reload.  */
  4134. static HARD_REG_SET reload_reg_used_at_all;
  4135.  
  4136. /* If reg is use as an inherited reload.  We just mark the first register
  4137.    in the group.  */
  4138. static HARD_REG_SET reload_reg_used_for_inherit;
  4139.  
  4140. /* Mark reg REGNO as in use for a reload of the sort spec'd by OPNUM and
  4141.    TYPE. MODE is used to indicate how many consecutive regs are
  4142.    actually used.  */
  4143.  
  4144. static void
  4145. mark_reload_reg_in_use (regno, opnum, type, mode)
  4146.      int regno;
  4147.      int opnum;
  4148.      enum reload_type type;
  4149.      enum machine_mode mode;
  4150. {
  4151.   int nregs = HARD_REGNO_NREGS (regno, mode);
  4152.   int i;
  4153.  
  4154.   for (i = regno; i < nregs + regno; i++)
  4155.     {
  4156.       switch (type)
  4157.     {
  4158.     case RELOAD_OTHER:
  4159.       SET_HARD_REG_BIT (reload_reg_used, i);
  4160.       break;
  4161.  
  4162.     case RELOAD_FOR_INPUT_ADDRESS:
  4163.       SET_HARD_REG_BIT (reload_reg_used_in_input_addr[opnum], i);
  4164.       break;
  4165.  
  4166.     case RELOAD_FOR_OUTPUT_ADDRESS:
  4167.       SET_HARD_REG_BIT (reload_reg_used_in_output_addr[opnum], i);
  4168.       break;
  4169.  
  4170.     case RELOAD_FOR_OPERAND_ADDRESS:
  4171.       SET_HARD_REG_BIT (reload_reg_used_in_op_addr, i);
  4172.       break;
  4173.  
  4174.     case RELOAD_FOR_OPADDR_ADDR:
  4175.       SET_HARD_REG_BIT (reload_reg_used_in_op_addr_reload, i);
  4176.       break;
  4177.  
  4178.     case RELOAD_FOR_OTHER_ADDRESS:
  4179.       SET_HARD_REG_BIT (reload_reg_used_in_other_addr, i);
  4180.       break;
  4181.  
  4182.     case RELOAD_FOR_INPUT:
  4183.       SET_HARD_REG_BIT (reload_reg_used_in_input[opnum], i);
  4184.       break;
  4185.  
  4186.     case RELOAD_FOR_OUTPUT:
  4187.       SET_HARD_REG_BIT (reload_reg_used_in_output[opnum], i);
  4188.       break;
  4189.  
  4190.     case RELOAD_FOR_INSN:
  4191.       SET_HARD_REG_BIT (reload_reg_used_in_insn, i);
  4192.       break;
  4193.     }
  4194.  
  4195.       SET_HARD_REG_BIT (reload_reg_used_at_all, i);
  4196.     }
  4197. }
  4198.  
  4199. /* Similarly, but show REGNO is no longer in use for a reload.  */
  4200.  
  4201. static void
  4202. clear_reload_reg_in_use (regno, opnum, type, mode)
  4203.      int regno;
  4204.      int opnum;
  4205.      enum reload_type type;
  4206.      enum machine_mode mode;
  4207. {
  4208.   int nregs = HARD_REGNO_NREGS (regno, mode);
  4209.   int i;
  4210.  
  4211.   for (i = regno; i < nregs + regno; i++)
  4212.     {
  4213.       switch (type)
  4214.     {
  4215.     case RELOAD_OTHER:
  4216.       CLEAR_HARD_REG_BIT (reload_reg_used, i);
  4217.       break;
  4218.  
  4219.     case RELOAD_FOR_INPUT_ADDRESS:
  4220.       CLEAR_HARD_REG_BIT (reload_reg_used_in_input_addr[opnum], i);
  4221.       break;
  4222.  
  4223.     case RELOAD_FOR_OUTPUT_ADDRESS:
  4224.       CLEAR_HARD_REG_BIT (reload_reg_used_in_output_addr[opnum], i);
  4225.       break;
  4226.  
  4227.     case RELOAD_FOR_OPERAND_ADDRESS:
  4228.       CLEAR_HARD_REG_BIT (reload_reg_used_in_op_addr, i);
  4229.       break;
  4230.  
  4231.     case RELOAD_FOR_OPADDR_ADDR:
  4232.       CLEAR_HARD_REG_BIT (reload_reg_used_in_op_addr_reload, i);
  4233.       break;
  4234.  
  4235.     case RELOAD_FOR_OTHER_ADDRESS:
  4236.       CLEAR_HARD_REG_BIT (reload_reg_used_in_other_addr, i);
  4237.       break;
  4238.  
  4239.     case RELOAD_FOR_INPUT:
  4240.       CLEAR_HARD_REG_BIT (reload_reg_used_in_input[opnum], i);
  4241.       break;
  4242.  
  4243.     case RELOAD_FOR_OUTPUT:
  4244.       CLEAR_HARD_REG_BIT (reload_reg_used_in_output[opnum], i);
  4245.       break;
  4246.  
  4247.     case RELOAD_FOR_INSN:
  4248.       CLEAR_HARD_REG_BIT (reload_reg_used_in_insn, i);
  4249.       break;
  4250.     }
  4251.     }
  4252. }
  4253.  
  4254. /* 1 if reg REGNO is free as a reload reg for a reload of the sort
  4255.    specified by OPNUM and TYPE.  */
  4256.  
  4257. static int
  4258. reload_reg_free_p (regno, opnum, type)
  4259.      int regno;
  4260.      int opnum;
  4261.      enum reload_type type;
  4262. {
  4263.   int i;
  4264.  
  4265.   /* In use for a RELOAD_OTHER means it's not available for anything except
  4266.      RELOAD_FOR_OTHER_ADDRESS.  Recall that RELOAD_FOR_OTHER_ADDRESS is known
  4267.      to be used only for inputs.  */
  4268.  
  4269.   if (type != RELOAD_FOR_OTHER_ADDRESS
  4270.       && TEST_HARD_REG_BIT (reload_reg_used, regno))
  4271.     return 0;
  4272.  
  4273.   switch (type)
  4274.     {
  4275.     case RELOAD_OTHER:
  4276.       /* In use for anything except RELOAD_FOR_OTHER_ADDRESS means
  4277.      we can't use it for RELOAD_OTHER.  */
  4278.       if (TEST_HARD_REG_BIT (reload_reg_used, regno)
  4279.       || TEST_HARD_REG_BIT (reload_reg_used_in_op_addr, regno)
  4280.       || TEST_HARD_REG_BIT (reload_reg_used_in_insn, regno))
  4281.     return 0;
  4282.  
  4283.       for (i = 0; i < reload_n_operands; i++)
  4284.     if (TEST_HARD_REG_BIT (reload_reg_used_in_input_addr[i], regno)
  4285.         || TEST_HARD_REG_BIT (reload_reg_used_in_output_addr[i], regno)
  4286.         || TEST_HARD_REG_BIT (reload_reg_used_in_input[i], regno)
  4287.         || TEST_HARD_REG_BIT (reload_reg_used_in_output[i], regno))
  4288.       return 0;
  4289.  
  4290.       return 1;
  4291.  
  4292.     case RELOAD_FOR_INPUT:
  4293.       if (TEST_HARD_REG_BIT (reload_reg_used_in_insn, regno)
  4294.       || TEST_HARD_REG_BIT (reload_reg_used_in_op_addr, regno))
  4295.     return 0;
  4296.  
  4297.       if (TEST_HARD_REG_BIT (reload_reg_used_in_op_addr_reload, regno))
  4298.     return 0;
  4299.  
  4300.       /* If it is used for some other input, can't use it.  */
  4301.       for (i = 0; i < reload_n_operands; i++)
  4302.     if (TEST_HARD_REG_BIT (reload_reg_used_in_input[i], regno))
  4303.       return 0;
  4304.  
  4305.       /* If it is used in a later operand's address, can't use it.  */
  4306.       for (i = opnum + 1; i < reload_n_operands; i++)
  4307.     if (TEST_HARD_REG_BIT (reload_reg_used_in_input_addr[i], regno))
  4308.       return 0;
  4309.  
  4310.       return 1;
  4311.  
  4312.     case RELOAD_FOR_INPUT_ADDRESS:
  4313.       /* Can't use a register if it is used for an input address for this
  4314.      operand or used as an input in an earlier one.  */
  4315.       if (TEST_HARD_REG_BIT (reload_reg_used_in_input_addr[opnum], regno))
  4316.     return 0;
  4317.  
  4318.       for (i = 0; i < opnum; i++)
  4319.     if (TEST_HARD_REG_BIT (reload_reg_used_in_input[i], regno))
  4320.       return 0;
  4321.  
  4322.       return 1;
  4323.  
  4324.     case RELOAD_FOR_OUTPUT_ADDRESS:
  4325.       /* Can't use a register if it is used for an output address for this
  4326.      operand or used as an output in this or a later operand.  */
  4327.       if (TEST_HARD_REG_BIT (reload_reg_used_in_output_addr[opnum], regno))
  4328.     return 0;
  4329.  
  4330.       for (i = opnum; i < reload_n_operands; i++)
  4331.     if (TEST_HARD_REG_BIT (reload_reg_used_in_output[i], regno))
  4332.       return 0;
  4333.  
  4334.       return 1;
  4335.  
  4336.     case RELOAD_FOR_OPERAND_ADDRESS:
  4337.       for (i = 0; i < reload_n_operands; i++)
  4338.     if (TEST_HARD_REG_BIT (reload_reg_used_in_input[i], regno))
  4339.       return 0;
  4340.  
  4341.       return (! TEST_HARD_REG_BIT (reload_reg_used_in_insn, regno)
  4342.           && ! TEST_HARD_REG_BIT (reload_reg_used_in_op_addr, regno));
  4343.  
  4344.     case RELOAD_FOR_OPADDR_ADDR:
  4345.       for (i = 0; i < reload_n_operands; i++)
  4346.         if (TEST_HARD_REG_BIT (reload_reg_used_in_input[i], regno))
  4347.           return 0;
  4348.  
  4349.       return (!TEST_HARD_REG_BIT (reload_reg_used_in_op_addr_reload, regno));
  4350.  
  4351.     case RELOAD_FOR_OUTPUT:
  4352.       /* This cannot share a register with RELOAD_FOR_INSN reloads, other
  4353.      outputs, or an operand address for this or an earlier output.  */
  4354.       if (TEST_HARD_REG_BIT (reload_reg_used_in_insn, regno))
  4355.     return 0;
  4356.  
  4357.       for (i = 0; i < reload_n_operands; i++)
  4358.     if (TEST_HARD_REG_BIT (reload_reg_used_in_output[i], regno))
  4359.       return 0;
  4360.  
  4361.       for (i = 0; i <= opnum; i++)
  4362.     if (TEST_HARD_REG_BIT (reload_reg_used_in_output_addr[i], regno))
  4363.       return 0;
  4364.  
  4365.       return 1;
  4366.  
  4367.     case RELOAD_FOR_INSN:
  4368.       for (i = 0; i < reload_n_operands; i++)
  4369.     if (TEST_HARD_REG_BIT (reload_reg_used_in_input[i], regno)
  4370.         || TEST_HARD_REG_BIT (reload_reg_used_in_output[i], regno))
  4371.       return 0;
  4372.  
  4373.       return (! TEST_HARD_REG_BIT (reload_reg_used_in_insn, regno)
  4374.           && ! TEST_HARD_REG_BIT (reload_reg_used_in_op_addr, regno));
  4375.  
  4376.     case RELOAD_FOR_OTHER_ADDRESS:
  4377.       return ! TEST_HARD_REG_BIT (reload_reg_used_in_other_addr, regno);
  4378.     }
  4379.   abort ();
  4380. }
  4381.  
  4382. /* Return 1 if the value in reload reg REGNO, as used by a reload
  4383.    needed for the part of the insn specified by OPNUM and TYPE,
  4384.    is not in use for a reload in any prior part of the insn.
  4385.  
  4386.    We can assume that the reload reg was already tested for availability
  4387.    at the time it is needed, and we should not check this again,
  4388.    in case the reg has already been marked in use.  */
  4389.  
  4390. static int
  4391. reload_reg_free_before_p (regno, opnum, type)
  4392.      int regno;
  4393.      int opnum;
  4394.      enum reload_type type;
  4395. {
  4396.   int i;
  4397.  
  4398.   switch (type)
  4399.     {
  4400.     case RELOAD_FOR_OTHER_ADDRESS:
  4401.       /* These always come first.  */
  4402.       return 1;
  4403.  
  4404.     case RELOAD_OTHER:
  4405.       return ! TEST_HARD_REG_BIT (reload_reg_used_in_other_addr, regno);
  4406.  
  4407.       /* If this use is for part of the insn,
  4408.      check the reg is not in use for any prior part.  It is tempting
  4409.      to try to do this by falling through from objecs that occur
  4410.      later in the insn to ones that occur earlier, but that will not
  4411.      correctly take into account the fact that here we MUST ignore
  4412.      things that would prevent the register from being allocated in
  4413.      the first place, since we know that it was allocated.  */
  4414.  
  4415.     case RELOAD_FOR_OUTPUT_ADDRESS:
  4416.       /* Earlier reloads are for earlier outputs or their addresses,
  4417.      any RELOAD_FOR_INSN reloads, any inputs or their addresses, or any
  4418.      RELOAD_FOR_OTHER_ADDRESS reloads (we know it can't conflict with
  4419.      RELOAD_OTHER)..  */
  4420.       for (i = 0; i < opnum; i++)
  4421.     if (TEST_HARD_REG_BIT (reload_reg_used_in_output_addr[i], regno)
  4422.         || TEST_HARD_REG_BIT (reload_reg_used_in_output[i], regno))
  4423.       return 0;
  4424.  
  4425.       if (TEST_HARD_REG_BIT (reload_reg_used_in_insn, regno))
  4426.     return 0;
  4427.  
  4428.       for (i = 0; i < reload_n_operands; i++)
  4429.     if (TEST_HARD_REG_BIT (reload_reg_used_in_input_addr[i], regno)
  4430.         || TEST_HARD_REG_BIT (reload_reg_used_in_input[i], regno))
  4431.       return 0;
  4432.  
  4433.       return (! TEST_HARD_REG_BIT (reload_reg_used_in_other_addr, regno)
  4434.           && ! TEST_HARD_REG_BIT (reload_reg_used_in_insn, regno)
  4435.           && ! TEST_HARD_REG_BIT (reload_reg_used_in_op_addr, regno));
  4436.                    
  4437.     case RELOAD_FOR_OUTPUT:
  4438.       /* This can't be used in the output address for this operand and
  4439.      anything that can't be used for it, except that we've already
  4440.      tested for RELOAD_FOR_INSN objects.  */
  4441.  
  4442.       if (TEST_HARD_REG_BIT (reload_reg_used_in_output_addr[opnum], regno))
  4443.     return 0;
  4444.  
  4445.       for (i = 0; i < opnum; i++)
  4446.     if (TEST_HARD_REG_BIT (reload_reg_used_in_output_addr[i], regno)
  4447.         || TEST_HARD_REG_BIT (reload_reg_used_in_output[i], regno))
  4448.       return 0;
  4449.  
  4450.       for (i = 0; i < reload_n_operands; i++)
  4451.     if (TEST_HARD_REG_BIT (reload_reg_used_in_input_addr[i], regno)
  4452.         || TEST_HARD_REG_BIT (reload_reg_used_in_input[i], regno)
  4453.         || TEST_HARD_REG_BIT (reload_reg_used_in_op_addr, regno))
  4454.       return 0;
  4455.  
  4456.       return ! TEST_HARD_REG_BIT (reload_reg_used_in_other_addr, regno);
  4457.  
  4458.     case RELOAD_FOR_OPERAND_ADDRESS:
  4459.     case RELOAD_FOR_OPADDR_ADDR:
  4460.     case RELOAD_FOR_INSN:
  4461.       /* These can't conflict with inputs, or each other, so all we have to
  4462.      test is input addresses and the addresses of OTHER items.  */
  4463.  
  4464.       for (i = 0; i < reload_n_operands; i++)
  4465.     if (TEST_HARD_REG_BIT (reload_reg_used_in_input_addr[i], regno))
  4466.       return 0;
  4467.  
  4468.       return ! TEST_HARD_REG_BIT (reload_reg_used_in_other_addr, regno);
  4469.  
  4470.     case RELOAD_FOR_INPUT:
  4471.       /* The only things earlier are the address for this and
  4472.      earlier inputs, other inputs (which we know we don't conflict
  4473.      with), and addresses of RELOAD_OTHER objects.  */
  4474.  
  4475.       for (i = 0; i <= opnum; i++)
  4476.     if (TEST_HARD_REG_BIT (reload_reg_used_in_input_addr[i], regno))
  4477.       return 0;
  4478.  
  4479.       return ! TEST_HARD_REG_BIT (reload_reg_used_in_other_addr, regno);
  4480.  
  4481.     case RELOAD_FOR_INPUT_ADDRESS:
  4482.       /* Similarly, all we have to check is for use in earlier inputs'
  4483.      addresses.  */
  4484.       for (i = 0; i < opnum; i++)
  4485.     if (TEST_HARD_REG_BIT (reload_reg_used_in_input_addr[i], regno))
  4486.       return 0;
  4487.  
  4488.       return ! TEST_HARD_REG_BIT (reload_reg_used_in_other_addr, regno);
  4489.     }
  4490.   abort ();
  4491. }
  4492.  
  4493. /* Return 1 if the value in reload reg REGNO, as used by a reload
  4494.    needed for the part of the insn specified by OPNUM and TYPE,
  4495.    is still available in REGNO at the end of the insn.
  4496.  
  4497.    We can assume that the reload reg was already tested for availability
  4498.    at the time it is needed, and we should not check this again,
  4499.    in case the reg has already been marked in use.  */
  4500.  
  4501. static int
  4502. reload_reg_reaches_end_p (regno, opnum, type)
  4503.      int regno;
  4504.      int opnum;
  4505.      enum reload_type type;
  4506. {
  4507.   int i;
  4508.  
  4509.   switch (type)
  4510.     {
  4511.     case RELOAD_OTHER:
  4512.       /* Since a RELOAD_OTHER reload claims the reg for the entire insn,
  4513.      its value must reach the end.  */
  4514.       return 1;
  4515.  
  4516.       /* If this use is for part of the insn,
  4517.      its value reaches if no subsequent part uses the same register. 
  4518.      Just like the above function, don't try to do this with lots
  4519.      of fallthroughs.  */
  4520.  
  4521.     case RELOAD_FOR_OTHER_ADDRESS:
  4522.       /* Here we check for everything else, since these don't conflict
  4523.      with anything else and everything comes later.  */
  4524.  
  4525.       for (i = 0; i < reload_n_operands; i++)
  4526.     if (TEST_HARD_REG_BIT (reload_reg_used_in_output_addr[i], regno)
  4527.         || TEST_HARD_REG_BIT (reload_reg_used_in_output[i], regno)
  4528.         || TEST_HARD_REG_BIT (reload_reg_used_in_input_addr[i], regno)
  4529.         || TEST_HARD_REG_BIT (reload_reg_used_in_input[i], regno))
  4530.       return 0;
  4531.  
  4532.       return (! TEST_HARD_REG_BIT (reload_reg_used_in_op_addr, regno)
  4533.           && ! TEST_HARD_REG_BIT (reload_reg_used_in_insn, regno)
  4534.           && ! TEST_HARD_REG_BIT (reload_reg_used, regno));
  4535.  
  4536.     case RELOAD_FOR_INPUT_ADDRESS:
  4537.       /* Similar, except that we check only for this and subsequent inputs
  4538.      and the address of only subsequent inputs and we do not need
  4539.      to check for RELOAD_OTHER objects since they are known not to
  4540.      conflict.  */
  4541.  
  4542.       for (i = opnum; i < reload_n_operands; i++)
  4543.     if (TEST_HARD_REG_BIT (reload_reg_used_in_input[i], regno))
  4544.       return 0;
  4545.  
  4546.       for (i = opnum + 1; i < reload_n_operands; i++)
  4547.     if (TEST_HARD_REG_BIT (reload_reg_used_in_input_addr[i], regno))
  4548.       return 0;
  4549.  
  4550.       for (i = 0; i < reload_n_operands; i++)
  4551.     if (TEST_HARD_REG_BIT (reload_reg_used_in_output_addr[i], regno)
  4552.         || TEST_HARD_REG_BIT (reload_reg_used_in_output[i], regno))
  4553.       return 0;
  4554.  
  4555.       if (TEST_HARD_REG_BIT (reload_reg_used_in_op_addr_reload, regno))
  4556.     return 0;
  4557.  
  4558.       return (! TEST_HARD_REG_BIT (reload_reg_used_in_op_addr, regno)
  4559.           && ! TEST_HARD_REG_BIT (reload_reg_used_in_insn, regno));
  4560.  
  4561.     case RELOAD_FOR_INPUT:
  4562.       /* Similar to input address, except we start at the next operand for
  4563.      both input and input address and we do not check for 
  4564.      RELOAD_FOR_OPERAND_ADDRESS and RELOAD_FOR_INSN since these
  4565.      would conflict.  */
  4566.  
  4567.       for (i = opnum + 1; i < reload_n_operands; i++)
  4568.     if (TEST_HARD_REG_BIT (reload_reg_used_in_input_addr[i], regno)
  4569.         || TEST_HARD_REG_BIT (reload_reg_used_in_input[i], regno))
  4570.       return 0;
  4571.  
  4572.       /* ... fall through ... */
  4573.  
  4574.     case RELOAD_FOR_OPERAND_ADDRESS:
  4575.       /* Check outputs and their addresses.  */
  4576.  
  4577.       for (i = 0; i < reload_n_operands; i++)
  4578.     if (TEST_HARD_REG_BIT (reload_reg_used_in_output_addr[i], regno)
  4579.         || TEST_HARD_REG_BIT (reload_reg_used_in_output[i], regno))
  4580.       return 0;
  4581.  
  4582.       return 1;
  4583.  
  4584.     case RELOAD_FOR_OPADDR_ADDR:
  4585.       for (i = 0; i < reload_n_operands; i++)
  4586.     if (TEST_HARD_REG_BIT (reload_reg_used_in_output_addr[i], regno)
  4587.         || TEST_HARD_REG_BIT (reload_reg_used_in_output[i], regno))
  4588.       return 0;
  4589.  
  4590.       return (! TEST_HARD_REG_BIT (reload_reg_used_in_op_addr, regno)
  4591.           && !TEST_HARD_REG_BIT (reload_reg_used_in_insn, regno));
  4592.  
  4593.     case RELOAD_FOR_INSN:
  4594.       /* These conflict with other outputs with RELOAD_OTHER.  So
  4595.      we need only check for output addresses.  */
  4596.  
  4597.       opnum = -1;
  4598.  
  4599.       /* ... fall through ... */
  4600.  
  4601.     case RELOAD_FOR_OUTPUT:
  4602.     case RELOAD_FOR_OUTPUT_ADDRESS:
  4603.       /* We already know these can't conflict with a later output.  So the
  4604.      only thing to check are later output addresses.  */
  4605.       for (i = opnum + 1; i < reload_n_operands; i++)
  4606.     if (TEST_HARD_REG_BIT (reload_reg_used_in_output_addr[i], regno))
  4607.       return 0;
  4608.  
  4609.       return 1;
  4610.     }
  4611.  
  4612.   abort ();
  4613. }
  4614.  
  4615. /* Return 1 if the reloads denoted by R1 and R2 cannot share a register.
  4616.    Return 0 otherwise.
  4617.  
  4618.    This function uses the same algorithm as reload_reg_free_p above.  */
  4619.  
  4620. static int
  4621. reloads_conflict (r1, r2)
  4622.      int r1, r2;
  4623. {
  4624.   enum reload_type r1_type = reload_when_needed[r1];
  4625.   enum reload_type r2_type = reload_when_needed[r2];
  4626.   int r1_opnum = reload_opnum[r1];
  4627.   int r2_opnum = reload_opnum[r2];
  4628.  
  4629.   /* RELOAD_OTHER conflicts with everything except RELOAD_FOR_OTHER_ADDRESS. */
  4630.   
  4631.   if (r2_type == RELOAD_OTHER && r1_type != RELOAD_FOR_OTHER_ADDRESS)
  4632.     return 1;
  4633.  
  4634.   /* Otherwise, check conflicts differently for each type.  */
  4635.  
  4636.   switch (r1_type)
  4637.     {
  4638.     case RELOAD_FOR_INPUT:
  4639.       return (r2_type == RELOAD_FOR_INSN 
  4640.           || r2_type == RELOAD_FOR_OPERAND_ADDRESS
  4641.           || r2_type == RELOAD_FOR_OPADDR_ADDR
  4642.           || r2_type == RELOAD_FOR_INPUT
  4643.           || (r2_type == RELOAD_FOR_INPUT_ADDRESS && r2_opnum > r1_opnum));
  4644.  
  4645.     case RELOAD_FOR_INPUT_ADDRESS:
  4646.       return ((r2_type == RELOAD_FOR_INPUT_ADDRESS && r1_opnum == r2_opnum)
  4647.           || (r2_type == RELOAD_FOR_INPUT && r2_opnum < r1_opnum));
  4648.  
  4649.     case RELOAD_FOR_OUTPUT_ADDRESS:
  4650.       return ((r2_type == RELOAD_FOR_OUTPUT_ADDRESS && r2_opnum == r1_opnum)
  4651.           || (r2_type == RELOAD_FOR_OUTPUT && r2_opnum >= r1_opnum));
  4652.  
  4653.     case RELOAD_FOR_OPERAND_ADDRESS:
  4654.       return (r2_type == RELOAD_FOR_INPUT || r2_type == RELOAD_FOR_INSN
  4655.           || r2_type == RELOAD_FOR_OPERAND_ADDRESS);
  4656.  
  4657.     case RELOAD_FOR_OPADDR_ADDR:
  4658.       return (r2_type == RELOAD_FOR_INPUT 
  4659.           || r2_type == RELOAD_FOR_OPADDR_ADDR);
  4660.  
  4661.     case RELOAD_FOR_OUTPUT:
  4662.       return (r2_type == RELOAD_FOR_INSN || r2_type == RELOAD_FOR_OUTPUT
  4663.           || (r2_type == RELOAD_FOR_OUTPUT_ADDRESS
  4664.           && r2_opnum >= r1_opnum));
  4665.  
  4666.     case RELOAD_FOR_INSN:
  4667.       return (r2_type == RELOAD_FOR_INPUT || r2_type == RELOAD_FOR_OUTPUT
  4668.           || r2_type == RELOAD_FOR_INSN
  4669.           || r2_type == RELOAD_FOR_OPERAND_ADDRESS);
  4670.  
  4671.     case RELOAD_FOR_OTHER_ADDRESS:
  4672.       return r2_type == RELOAD_FOR_OTHER_ADDRESS;
  4673.  
  4674.     case RELOAD_OTHER:
  4675.       return r2_type != RELOAD_FOR_OTHER_ADDRESS;
  4676.  
  4677.     default:
  4678.       abort ();
  4679.     }
  4680. }
  4681.  
  4682. /* Vector of reload-numbers showing the order in which the reloads should
  4683.    be processed.  */
  4684. short reload_order[MAX_RELOADS];
  4685.  
  4686. /* Indexed by reload number, 1 if incoming value
  4687.    inherited from previous insns.  */
  4688. char reload_inherited[MAX_RELOADS];
  4689.  
  4690. /* For an inherited reload, this is the insn the reload was inherited from,
  4691.    if we know it.  Otherwise, this is 0.  */
  4692. rtx reload_inheritance_insn[MAX_RELOADS];
  4693.  
  4694. /* If non-zero, this is a place to get the value of the reload,
  4695.    rather than using reload_in.  */
  4696. rtx reload_override_in[MAX_RELOADS];
  4697.  
  4698. /* For each reload, the index in spill_regs of the spill register used,
  4699.    or -1 if we did not need one of the spill registers for this reload.  */
  4700. int reload_spill_index[MAX_RELOADS];
  4701.  
  4702. /* Find a spill register to use as a reload register for reload R.
  4703.    LAST_RELOAD is non-zero if this is the last reload for the insn being
  4704.    processed.
  4705.  
  4706.    Set reload_reg_rtx[R] to the register allocated.
  4707.  
  4708.    If NOERROR is nonzero, we return 1 if successful,
  4709.    or 0 if we couldn't find a spill reg and we didn't change anything.  */
  4710.  
  4711. static int
  4712. allocate_reload_reg (r, insn, last_reload, noerror)
  4713.      int r;
  4714.      rtx insn;
  4715.      int last_reload;
  4716.      int noerror;
  4717. {
  4718.   int i;
  4719.   int pass;
  4720.   int count;
  4721.   rtx new;
  4722.   int regno;
  4723.  
  4724.   /* If we put this reload ahead, thinking it is a group,
  4725.      then insist on finding a group.  Otherwise we can grab a
  4726.      reg that some other reload needs.
  4727.      (That can happen when we have a 68000 DATA_OR_FP_REG
  4728.      which is a group of data regs or one fp reg.)
  4729.      We need not be so restrictive if there are no more reloads
  4730.      for this insn.
  4731.  
  4732.      ??? Really it would be nicer to have smarter handling
  4733.      for that kind of reg class, where a problem like this is normal.
  4734.      Perhaps those classes should be avoided for reloading
  4735.      by use of more alternatives.  */
  4736.  
  4737.   int force_group = reload_nregs[r] > 1 && ! last_reload;
  4738.  
  4739.   /* If we want a single register and haven't yet found one,
  4740.      take any reg in the right class and not in use.
  4741.      If we want a consecutive group, here is where we look for it.
  4742.  
  4743.      We use two passes so we can first look for reload regs to
  4744.      reuse, which are already in use for other reloads in this insn,
  4745.      and only then use additional registers.
  4746.      I think that maximizing reuse is needed to make sure we don't
  4747.      run out of reload regs.  Suppose we have three reloads, and
  4748.      reloads A and B can share regs.  These need two regs.
  4749.      Suppose A and B are given different regs.
  4750.      That leaves none for C.  */
  4751.   for (pass = 0; pass < 2; pass++)
  4752.     {
  4753.       /* I is the index in spill_regs.
  4754.      We advance it round-robin between insns to use all spill regs
  4755.      equally, so that inherited reloads have a chance
  4756.      of leapfrogging each other.  Don't do this, however, when we have
  4757.      group needs and failure would be fatal; if we only have a relatively
  4758.      small number of spill registers, and more than one of them has
  4759.      group needs, then by starting in the middle, we may end up 
  4760.      allocating the first one in such a way that we are not left with
  4761.      sufficient groups to handle the rest.  */
  4762.  
  4763.       if (noerror || ! force_group)
  4764.     i = last_spill_reg;
  4765.       else
  4766.     i = -1;
  4767.       
  4768.       for (count = 0; count < n_spills; count++)
  4769.     {
  4770.       int class = (int) reload_reg_class[r];
  4771.  
  4772.       i = (i + 1) % n_spills;
  4773.  
  4774.       if (reload_reg_free_p (spill_regs[i], reload_opnum[r],
  4775.                  reload_when_needed[r])
  4776.           && TEST_HARD_REG_BIT (reg_class_contents[class], spill_regs[i])
  4777.           && HARD_REGNO_MODE_OK (spill_regs[i], reload_mode[r])
  4778.           /* Look first for regs to share, then for unshared.  But
  4779.          don't share regs used for inherited reloads; they are
  4780.          the ones we want to preserve.  */
  4781.           && (pass
  4782.           || (TEST_HARD_REG_BIT (reload_reg_used_at_all,
  4783.                      spill_regs[i])
  4784.               && ! TEST_HARD_REG_BIT (reload_reg_used_for_inherit,
  4785.                           spill_regs[i]))))
  4786.         {
  4787.           int nr = HARD_REGNO_NREGS (spill_regs[i], reload_mode[r]);
  4788.           /* Avoid the problem where spilling a GENERAL_OR_FP_REG
  4789.          (on 68000) got us two FP regs.  If NR is 1,
  4790.          we would reject both of them.  */
  4791.           if (force_group)
  4792.         nr = CLASS_MAX_NREGS (reload_reg_class[r], reload_mode[r]);
  4793.           /* If we need only one reg, we have already won.  */
  4794.           if (nr == 1)
  4795.         {
  4796.           /* But reject a single reg if we demand a group.  */
  4797.           if (force_group)
  4798.             continue;
  4799.           break;
  4800.         }
  4801.           /* Otherwise check that as many consecutive regs as we need
  4802.          are available here.
  4803.          Also, don't use for a group registers that are
  4804.          needed for nongroups.  */
  4805.           if (! TEST_HARD_REG_BIT (counted_for_nongroups, spill_regs[i]))
  4806.         while (nr > 1)
  4807.           {
  4808.             regno = spill_regs[i] + nr - 1;
  4809.             if (!(TEST_HARD_REG_BIT (reg_class_contents[class], regno)
  4810.               && spill_reg_order[regno] >= 0
  4811.               && reload_reg_free_p (regno, reload_opnum[r],
  4812.                         reload_when_needed[r])
  4813.               && ! TEST_HARD_REG_BIT (counted_for_nongroups,
  4814.                           regno)))
  4815.               break;
  4816.             nr--;
  4817.           }
  4818.           if (nr == 1)
  4819.         break;
  4820.         }
  4821.     }
  4822.  
  4823.       /* If we found something on pass 1, omit pass 2.  */
  4824.       if (count < n_spills)
  4825.     break;
  4826.     }
  4827.  
  4828.   /* We should have found a spill register by now.  */
  4829.   if (count == n_spills)
  4830.     {
  4831.       if (noerror)
  4832.     return 0;
  4833.       goto failure;
  4834.     }
  4835.  
  4836.   /* I is the index in SPILL_REG_RTX of the reload register we are to
  4837.      allocate.  Get an rtx for it and find its register number.  */
  4838.  
  4839.   new = spill_reg_rtx[i];
  4840.  
  4841.   if (new == 0 || GET_MODE (new) != reload_mode[r])
  4842.     spill_reg_rtx[i] = new
  4843.       = gen_rtx (REG, reload_mode[r], spill_regs[i]);
  4844.         
  4845.   regno = true_regnum (new);
  4846.  
  4847.   /* Detect when the reload reg can't hold the reload mode.
  4848.      This used to be one `if', but Sequent compiler can't handle that.  */
  4849.   if (HARD_REGNO_MODE_OK (regno, reload_mode[r]))
  4850.     {
  4851.       enum machine_mode test_mode = VOIDmode;
  4852.       if (reload_in[r])
  4853.     test_mode = GET_MODE (reload_in[r]);
  4854.       /* If reload_in[r] has VOIDmode, it means we will load it
  4855.      in whatever mode the reload reg has: to wit, reload_mode[r].
  4856.      We have already tested that for validity.  */
  4857.       /* Aside from that, we need to test that the expressions
  4858.      to reload from or into have modes which are valid for this
  4859.      reload register.  Otherwise the reload insns would be invalid.  */
  4860.       if (! (reload_in[r] != 0 && test_mode != VOIDmode
  4861.          && ! HARD_REGNO_MODE_OK (regno, test_mode)))
  4862.     if (! (reload_out[r] != 0
  4863.            && ! HARD_REGNO_MODE_OK (regno, GET_MODE (reload_out[r]))))
  4864.       {
  4865.         /* The reg is OK.  */
  4866.         last_spill_reg = i;
  4867.  
  4868.         /* Mark as in use for this insn the reload regs we use
  4869.            for this.  */
  4870.         mark_reload_reg_in_use (spill_regs[i], reload_opnum[r],
  4871.                     reload_when_needed[r], reload_mode[r]);
  4872.  
  4873.         reload_reg_rtx[r] = new;
  4874.         reload_spill_index[r] = i;
  4875.         return 1;
  4876.       }
  4877.     }
  4878.  
  4879.   /* The reg is not OK.  */
  4880.   if (noerror)
  4881.     return 0;
  4882.  
  4883.  failure:
  4884.   if (asm_noperands (PATTERN (insn)) < 0)
  4885.     /* It's the compiler's fault.  */
  4886.     fatal_insn ("Could not find a spill register", insn);
  4887.  
  4888.   /* It's the user's fault; the operand's mode and constraint
  4889.      don't match.  Disable this reload so we don't crash in final.  */
  4890.   error_for_asm (insn,
  4891.          "`asm' operand constraint incompatible with operand size");
  4892.   reload_in[r] = 0;
  4893.   reload_out[r] = 0;
  4894.   reload_reg_rtx[r] = 0;
  4895.   reload_optional[r] = 1;
  4896.   reload_secondary_p[r] = 1;
  4897.  
  4898.   return 1;
  4899. }
  4900.  
  4901. /* Assign hard reg targets for the pseudo-registers we must reload
  4902.    into hard regs for this insn.
  4903.    Also output the instructions to copy them in and out of the hard regs.
  4904.  
  4905.    For machines with register classes, we are responsible for
  4906.    finding a reload reg in the proper class.  */
  4907.  
  4908. static void
  4909. choose_reload_regs (insn, avoid_return_reg)
  4910.      rtx insn;
  4911.      rtx avoid_return_reg;
  4912. {
  4913.   register int i, j;
  4914.   int max_group_size = 1;
  4915.   enum reg_class group_class = NO_REGS;
  4916.   int inheritance;
  4917.  
  4918.   rtx save_reload_reg_rtx[MAX_RELOADS];
  4919.   char save_reload_inherited[MAX_RELOADS];
  4920.   rtx save_reload_inheritance_insn[MAX_RELOADS];
  4921.   rtx save_reload_override_in[MAX_RELOADS];
  4922.   int save_reload_spill_index[MAX_RELOADS];
  4923.   HARD_REG_SET save_reload_reg_used;
  4924.   HARD_REG_SET save_reload_reg_used_in_input_addr[MAX_RECOG_OPERANDS];
  4925.   HARD_REG_SET save_reload_reg_used_in_output_addr[MAX_RECOG_OPERANDS];
  4926.   HARD_REG_SET save_reload_reg_used_in_input[MAX_RECOG_OPERANDS];
  4927.   HARD_REG_SET save_reload_reg_used_in_output[MAX_RECOG_OPERANDS];
  4928.   HARD_REG_SET save_reload_reg_used_in_op_addr;
  4929.   HARD_REG_SET save_reload_reg_used_in_op_addr_reload;
  4930.   HARD_REG_SET save_reload_reg_used_in_insn;
  4931.   HARD_REG_SET save_reload_reg_used_in_other_addr;
  4932.   HARD_REG_SET save_reload_reg_used_at_all;
  4933.  
  4934.   bzero (reload_inherited, MAX_RELOADS);
  4935.   bzero ((char *) reload_inheritance_insn, MAX_RELOADS * sizeof (rtx));
  4936.   bzero ((char *) reload_override_in, MAX_RELOADS * sizeof (rtx));
  4937.  
  4938.   CLEAR_HARD_REG_SET (reload_reg_used);
  4939.   CLEAR_HARD_REG_SET (reload_reg_used_at_all);
  4940.   CLEAR_HARD_REG_SET (reload_reg_used_in_op_addr);
  4941.   CLEAR_HARD_REG_SET (reload_reg_used_in_op_addr_reload);
  4942.   CLEAR_HARD_REG_SET (reload_reg_used_in_insn);
  4943.   CLEAR_HARD_REG_SET (reload_reg_used_in_other_addr);
  4944.  
  4945.   for (i = 0; i < reload_n_operands; i++)
  4946.     {
  4947.       CLEAR_HARD_REG_SET (reload_reg_used_in_output[i]);
  4948.       CLEAR_HARD_REG_SET (reload_reg_used_in_input[i]);
  4949.       CLEAR_HARD_REG_SET (reload_reg_used_in_input_addr[i]);
  4950.       CLEAR_HARD_REG_SET (reload_reg_used_in_output_addr[i]);
  4951.     }
  4952.  
  4953. #ifdef SMALL_REGISTER_CLASSES
  4954.   /* Don't bother with avoiding the return reg
  4955.      if we have no mandatory reload that could use it.  */
  4956.   if (avoid_return_reg)
  4957.     {
  4958.       int do_avoid = 0;
  4959.       int regno = REGNO (avoid_return_reg);
  4960.       int nregs
  4961.     = HARD_REGNO_NREGS (regno, GET_MODE (avoid_return_reg));
  4962.       int r;
  4963.  
  4964.       for (r = regno; r < regno + nregs; r++)
  4965.     if (spill_reg_order[r] >= 0)
  4966.       for (j = 0; j < n_reloads; j++)
  4967.         if (!reload_optional[j] && reload_reg_rtx[j] == 0
  4968.         && (reload_in[j] != 0 || reload_out[j] != 0
  4969.             || reload_secondary_p[j])
  4970.         &&
  4971.         TEST_HARD_REG_BIT (reg_class_contents[(int) reload_reg_class[j]], r))
  4972.           do_avoid = 1;
  4973.       if (!do_avoid)
  4974.     avoid_return_reg = 0;
  4975.     }
  4976. #endif /* SMALL_REGISTER_CLASSES */
  4977.  
  4978. #if 0  /* Not needed, now that we can always retry without inheritance.  */
  4979.   /* See if we have more mandatory reloads than spill regs.
  4980.      If so, then we cannot risk optimizations that could prevent
  4981.      reloads from sharing one spill register.
  4982.  
  4983.      Since we will try finding a better register than reload_reg_rtx
  4984.      unless it is equal to reload_in or reload_out, count such reloads.  */
  4985.  
  4986.   {
  4987.     int tem = 0;
  4988. #ifdef SMALL_REGISTER_CLASSES
  4989.     int tem = (avoid_return_reg != 0);
  4990. #endif
  4991.     for (j = 0; j < n_reloads; j++)
  4992.       if (! reload_optional[j]
  4993.       && (reload_in[j] != 0 || reload_out[j] != 0 || reload_secondary_p[j])
  4994.       && (reload_reg_rtx[j] == 0
  4995.           || (! rtx_equal_p (reload_reg_rtx[j], reload_in[j])
  4996.           && ! rtx_equal_p (reload_reg_rtx[j], reload_out[j]))))
  4997.     tem++;
  4998.     if (tem > n_spills)
  4999.       must_reuse = 1;
  5000.   }
  5001. #endif
  5002.  
  5003. #ifdef SMALL_REGISTER_CLASSES
  5004.   /* Don't use the subroutine call return reg for a reload
  5005.      if we are supposed to avoid it.  */
  5006.   if (avoid_return_reg)
  5007.     {
  5008.       int regno = REGNO (avoid_return_reg);
  5009.       int nregs
  5010.     = HARD_REGNO_NREGS (regno, GET_MODE (avoid_return_reg));
  5011.       int r;
  5012.  
  5013.       for (r = regno; r < regno + nregs; r++)
  5014.     if (spill_reg_order[r] >= 0)
  5015.       SET_HARD_REG_BIT (reload_reg_used, r);
  5016.     }
  5017. #endif /* SMALL_REGISTER_CLASSES */
  5018.  
  5019.   /* In order to be certain of getting the registers we need,
  5020.      we must sort the reloads into order of increasing register class.
  5021.      Then our grabbing of reload registers will parallel the process
  5022.      that provided the reload registers.
  5023.  
  5024.      Also note whether any of the reloads wants a consecutive group of regs.
  5025.      If so, record the maximum size of the group desired and what
  5026.      register class contains all the groups needed by this insn.  */
  5027.  
  5028.   for (j = 0; j < n_reloads; j++)
  5029.     {
  5030.       reload_order[j] = j;
  5031.       reload_spill_index[j] = -1;
  5032.  
  5033.       reload_mode[j]
  5034.     = (reload_inmode[j] == VOIDmode
  5035.        || (GET_MODE_SIZE (reload_outmode[j])
  5036.            > GET_MODE_SIZE (reload_inmode[j])))
  5037.       ? reload_outmode[j] : reload_inmode[j];
  5038.  
  5039.       reload_nregs[j] = CLASS_MAX_NREGS (reload_reg_class[j], reload_mode[j]);
  5040.  
  5041.       if (reload_nregs[j] > 1)
  5042.     {
  5043.       max_group_size = MAX (reload_nregs[j], max_group_size);
  5044.       group_class = reg_class_superunion[(int)reload_reg_class[j]][(int)group_class];
  5045.     }
  5046.  
  5047.       /* If we have already decided to use a certain register,
  5048.      don't use it in another way.  */
  5049.       if (reload_reg_rtx[j])
  5050.     mark_reload_reg_in_use (REGNO (reload_reg_rtx[j]), reload_opnum[j],
  5051.                 reload_when_needed[j], reload_mode[j]);
  5052.     }
  5053.  
  5054.   if (n_reloads > 1)
  5055.     qsort (reload_order, n_reloads, sizeof (short), reload_reg_class_lower);
  5056.  
  5057.   bcopy ((char *) reload_reg_rtx, (char *) save_reload_reg_rtx,
  5058.      sizeof reload_reg_rtx);
  5059.   bcopy (reload_inherited, save_reload_inherited, sizeof reload_inherited);
  5060.   bcopy ((char *) reload_inheritance_insn,
  5061.      (char *) save_reload_inheritance_insn,
  5062.      sizeof reload_inheritance_insn);
  5063.   bcopy ((char *) reload_override_in, (char *) save_reload_override_in,
  5064.      sizeof reload_override_in);
  5065.   bcopy ((char *) reload_spill_index, (char *) save_reload_spill_index,
  5066.      sizeof reload_spill_index);
  5067.   COPY_HARD_REG_SET (save_reload_reg_used, reload_reg_used);
  5068.   COPY_HARD_REG_SET (save_reload_reg_used_at_all, reload_reg_used_at_all);
  5069.   COPY_HARD_REG_SET (save_reload_reg_used_in_op_addr,
  5070.              reload_reg_used_in_op_addr);
  5071.  
  5072.   COPY_HARD_REG_SET (save_reload_reg_used_in_op_addr_reload,
  5073.              reload_reg_used_in_op_addr_reload);
  5074.  
  5075.   COPY_HARD_REG_SET (save_reload_reg_used_in_insn,
  5076.              reload_reg_used_in_insn);
  5077.   COPY_HARD_REG_SET (save_reload_reg_used_in_other_addr,
  5078.              reload_reg_used_in_other_addr);
  5079.  
  5080.   for (i = 0; i < reload_n_operands; i++)
  5081.     {
  5082.       COPY_HARD_REG_SET (save_reload_reg_used_in_output[i],
  5083.              reload_reg_used_in_output[i]);
  5084.       COPY_HARD_REG_SET (save_reload_reg_used_in_input[i],
  5085.              reload_reg_used_in_input[i]);
  5086.       COPY_HARD_REG_SET (save_reload_reg_used_in_input_addr[i],
  5087.              reload_reg_used_in_input_addr[i]);
  5088.       COPY_HARD_REG_SET (save_reload_reg_used_in_output_addr[i],
  5089.              reload_reg_used_in_output_addr[i]);
  5090.     }
  5091.  
  5092.   /* If -O, try first with inheritance, then turning it off.
  5093.      If not -O, don't do inheritance.
  5094.      Using inheritance when not optimizing leads to paradoxes
  5095.      with fp on the 68k: fp numbers (not NaNs) fail to be equal to themselves
  5096.      because one side of the comparison might be inherited.  */
  5097.  
  5098.   for (inheritance = optimize > 0; inheritance >= 0; inheritance--)
  5099.     {
  5100.       /* Process the reloads in order of preference just found.
  5101.      Beyond this point, subregs can be found in reload_reg_rtx.
  5102.  
  5103.      This used to look for an existing reloaded home for all
  5104.      of the reloads, and only then perform any new reloads.
  5105.      But that could lose if the reloads were done out of reg-class order
  5106.      because a later reload with a looser constraint might have an old
  5107.      home in a register needed by an earlier reload with a tighter constraint.
  5108.  
  5109.      To solve this, we make two passes over the reloads, in the order
  5110.      described above.  In the first pass we try to inherit a reload
  5111.      from a previous insn.  If there is a later reload that needs a
  5112.      class that is a proper subset of the class being processed, we must
  5113.      also allocate a spill register during the first pass.
  5114.  
  5115.      Then make a second pass over the reloads to allocate any reloads
  5116.      that haven't been given registers yet.  */
  5117.  
  5118.       CLEAR_HARD_REG_SET (reload_reg_used_for_inherit);
  5119.  
  5120.       for (j = 0; j < n_reloads; j++)
  5121.     {
  5122.       register int r = reload_order[j];
  5123.  
  5124.       /* Ignore reloads that got marked inoperative.  */
  5125.       if (reload_out[r] == 0 && reload_in[r] == 0 && ! reload_secondary_p[r])
  5126.         continue;
  5127.  
  5128.       /* If find_reloads chose a to use reload_in or reload_out as a reload
  5129.          register, we don't need to chose one.  Otherwise, try even if it found
  5130.          one since we might save an insn if we find the value lying around.  */
  5131.       if (reload_in[r] != 0 && reload_reg_rtx[r] != 0
  5132.           && (rtx_equal_p (reload_in[r], reload_reg_rtx[r])
  5133.           || rtx_equal_p (reload_out[r], reload_reg_rtx[r])))
  5134.         continue;
  5135.  
  5136. #if 0 /* No longer needed for correct operation.
  5137.      It might give better code, or might not; worth an experiment?  */
  5138.       /* If this is an optional reload, we can't inherit from earlier insns
  5139.          until we are sure that any non-optional reloads have been allocated.
  5140.          The following code takes advantage of the fact that optional reloads
  5141.          are at the end of reload_order.  */
  5142.       if (reload_optional[r] != 0)
  5143.         for (i = 0; i < j; i++)
  5144.           if ((reload_out[reload_order[i]] != 0
  5145.            || reload_in[reload_order[i]] != 0
  5146.            || reload_secondary_p[reload_order[i]])
  5147.           && ! reload_optional[reload_order[i]]
  5148.           && reload_reg_rtx[reload_order[i]] == 0)
  5149.         allocate_reload_reg (reload_order[i], insn, 0, inheritance);
  5150. #endif
  5151.  
  5152.       /* First see if this pseudo is already available as reloaded
  5153.          for a previous insn.  We cannot try to inherit for reloads
  5154.          that are smaller than the maximum number of registers needed
  5155.          for groups unless the register we would allocate cannot be used
  5156.          for the groups.
  5157.  
  5158.          We could check here to see if this is a secondary reload for
  5159.          an object that is already in a register of the desired class.
  5160.          This would avoid the need for the secondary reload register.
  5161.          But this is complex because we can't easily determine what
  5162.          objects might want to be loaded via this reload.  So let a register
  5163.          be allocated here.  In `emit_reload_insns' we suppress one of the
  5164.          loads in the case described above.  */
  5165.  
  5166.       if (inheritance)
  5167.         {
  5168.           register int regno = -1;
  5169.           enum machine_mode mode;
  5170.  
  5171.           if (reload_in[r] == 0)
  5172.         ;
  5173.           else if (GET_CODE (reload_in[r]) == REG)
  5174.         {
  5175.           regno = REGNO (reload_in[r]);
  5176.           mode = GET_MODE (reload_in[r]);
  5177.         }
  5178.           else if (GET_CODE (reload_in_reg[r]) == REG)
  5179.         {
  5180.           regno = REGNO (reload_in_reg[r]);
  5181.           mode = GET_MODE (reload_in_reg[r]);
  5182.         }
  5183. #if 0
  5184.           /* This won't work, since REGNO can be a pseudo reg number.
  5185.          Also, it takes much more hair to keep track of all the things
  5186.          that can invalidate an inherited reload of part of a pseudoreg.  */
  5187.           else if (GET_CODE (reload_in[r]) == SUBREG
  5188.                && GET_CODE (SUBREG_REG (reload_in[r])) == REG)
  5189.         regno = REGNO (SUBREG_REG (reload_in[r])) + SUBREG_WORD (reload_in[r]);
  5190. #endif
  5191.  
  5192.           if (regno >= 0 && reg_last_reload_reg[regno] != 0)
  5193.         {
  5194.           i = spill_reg_order[REGNO (reg_last_reload_reg[regno])];
  5195.  
  5196.           if (reg_reloaded_contents[i] == regno
  5197.               && (GET_MODE_SIZE (GET_MODE (reg_last_reload_reg[regno]))
  5198.               >= GET_MODE_SIZE (mode))
  5199.               && HARD_REGNO_MODE_OK (spill_regs[i], reload_mode[r])
  5200.               && TEST_HARD_REG_BIT (reg_class_contents[(int) reload_reg_class[r]],
  5201.                         spill_regs[i])
  5202.               && (reload_nregs[r] == max_group_size
  5203.               || ! TEST_HARD_REG_BIT (reg_class_contents[(int) group_class],
  5204.                           spill_regs[i]))
  5205.               && reload_reg_free_p (spill_regs[i], reload_opnum[r],
  5206.                         reload_when_needed[r])
  5207.               && reload_reg_free_before_p (spill_regs[i],
  5208.                            reload_opnum[r],
  5209.                            reload_when_needed[r]))
  5210.             {
  5211.               /* If a group is needed, verify that all the subsequent
  5212.              registers still have their values intact. */
  5213.               int nr
  5214.             = HARD_REGNO_NREGS (spill_regs[i], reload_mode[r]);
  5215.               int k;
  5216.  
  5217.               for (k = 1; k < nr; k++)
  5218.             if (reg_reloaded_contents[spill_reg_order[spill_regs[i] + k]]
  5219.                 != regno)
  5220.               break;
  5221.  
  5222.               if (k == nr)
  5223.             {
  5224.               int i1;
  5225.  
  5226.               /* We found a register that contains the
  5227.                  value we need.  If this register is the
  5228.                  same as an `earlyclobber' operand of the
  5229.                  current insn, just mark it as a place to
  5230.                  reload from since we can't use it as the
  5231.                  reload register itself.  */
  5232.  
  5233.               for (i1 = 0; i1 < n_earlyclobbers; i1++)
  5234.                 if (reg_overlap_mentioned_for_reload_p
  5235.                 (reg_last_reload_reg[regno],
  5236.                  reload_earlyclobbers[i1]))
  5237.                   break;
  5238.  
  5239.               if (i1 != n_earlyclobbers
  5240.                   /* Don't really use the inherited spill reg
  5241.                  if we need it wider than we've got it.  */
  5242.                   || (GET_MODE_SIZE (reload_mode[r])
  5243.                   > GET_MODE_SIZE (mode)))
  5244.                 reload_override_in[r] = reg_last_reload_reg[regno];
  5245.               else
  5246.                 {
  5247.                   int k;
  5248.                   /* We can use this as a reload reg.  */
  5249.                   /* Mark the register as in use for this part of
  5250.                  the insn.  */
  5251.                   mark_reload_reg_in_use (spill_regs[i],
  5252.                               reload_opnum[r],
  5253.                               reload_when_needed[r],
  5254.                               reload_mode[r]);
  5255.                   reload_reg_rtx[r] = reg_last_reload_reg[regno];
  5256.                   reload_inherited[r] = 1;
  5257.                   reload_inheritance_insn[r]
  5258.                 = reg_reloaded_insn[i];
  5259.                   reload_spill_index[r] = i;
  5260.                   for (k = 0; k < nr; k++)
  5261.                 SET_HARD_REG_BIT (reload_reg_used_for_inherit,
  5262.                           spill_regs[i + k]);
  5263.                 }
  5264.             }
  5265.             }
  5266.         }
  5267.         }
  5268.  
  5269.       /* Here's another way to see if the value is already lying around.  */
  5270.       if (inheritance
  5271.           && reload_in[r] != 0
  5272.           && ! reload_inherited[r]
  5273.           && reload_out[r] == 0
  5274.           && (CONSTANT_P (reload_in[r])
  5275.           || GET_CODE (reload_in[r]) == PLUS
  5276.           || GET_CODE (reload_in[r]) == REG
  5277.           || GET_CODE (reload_in[r]) == MEM)
  5278.           && (reload_nregs[r] == max_group_size
  5279.           || ! reg_classes_intersect_p (reload_reg_class[r], group_class)))
  5280.         {
  5281.           register rtx equiv
  5282.         = find_equiv_reg (reload_in[r], insn, reload_reg_class[r],
  5283.                   -1, NULL_PTR, 0, reload_mode[r]);
  5284.           int regno;
  5285.  
  5286.           if (equiv != 0)
  5287.         {
  5288.           if (GET_CODE (equiv) == REG)
  5289.             regno = REGNO (equiv);
  5290.           else if (GET_CODE (equiv) == SUBREG)
  5291.             {
  5292.               /* This must be a SUBREG of a hard register.
  5293.              Make a new REG since this might be used in an
  5294.              address and not all machines support SUBREGs
  5295.              there.  */
  5296.               regno = REGNO (SUBREG_REG (equiv)) + SUBREG_WORD (equiv);
  5297.               equiv = gen_rtx (REG, reload_mode[r], regno);
  5298.             }
  5299.           else
  5300.             abort ();
  5301.         }
  5302.  
  5303.           /* If we found a spill reg, reject it unless it is free
  5304.          and of the desired class.  */
  5305.           if (equiv != 0
  5306.           && ((spill_reg_order[regno] >= 0
  5307.                && ! reload_reg_free_before_p (regno, reload_opnum[r],
  5308.                               reload_when_needed[r]))
  5309.               || ! TEST_HARD_REG_BIT (reg_class_contents[(int) reload_reg_class[r]],
  5310.                           regno)))
  5311.         equiv = 0;
  5312.  
  5313.           if (equiv != 0 && TEST_HARD_REG_BIT (reload_reg_used_at_all, regno))
  5314.         equiv = 0;
  5315.  
  5316.           if (equiv != 0 && ! HARD_REGNO_MODE_OK (regno, reload_mode[r]))
  5317.         equiv = 0;
  5318.  
  5319.           /* We found a register that contains the value we need.
  5320.          If this register is the same as an `earlyclobber' operand
  5321.          of the current insn, just mark it as a place to reload from
  5322.          since we can't use it as the reload register itself.  */
  5323.  
  5324.           if (equiv != 0)
  5325.         for (i = 0; i < n_earlyclobbers; i++)
  5326.           if (reg_overlap_mentioned_for_reload_p (equiv,
  5327.                               reload_earlyclobbers[i]))
  5328.             {
  5329.               reload_override_in[r] = equiv;
  5330.               equiv = 0;
  5331.               break;
  5332.             }
  5333.  
  5334.           /* JRV: If the equiv register we have found is explicitly
  5335.          clobbered in the current insn, mark but don't use, as above. */
  5336.  
  5337.           if (equiv != 0 && regno_clobbered_p (regno, insn))
  5338.         {
  5339.           reload_override_in[r] = equiv;
  5340.           equiv = 0;
  5341.         }
  5342.  
  5343.           /* If we found an equivalent reg, say no code need be generated
  5344.          to load it, and use it as our reload reg.  */
  5345.           if (equiv != 0 && regno != HARD_FRAME_POINTER_REGNUM)
  5346.         {
  5347.           reload_reg_rtx[r] = equiv;
  5348.           reload_inherited[r] = 1;
  5349.           /* If it is a spill reg,
  5350.              mark the spill reg as in use for this insn.  */
  5351.           i = spill_reg_order[regno];
  5352.           if (i >= 0)
  5353.             {
  5354.               int nr = HARD_REGNO_NREGS (regno, reload_mode[r]);
  5355.               int k;
  5356.               mark_reload_reg_in_use (regno, reload_opnum[r],
  5357.                           reload_when_needed[r],
  5358.                           reload_mode[r]);
  5359.               for (k = 0; k < nr; k++)
  5360.             SET_HARD_REG_BIT (reload_reg_used_for_inherit, regno + k);
  5361.             }
  5362.         }
  5363.         }
  5364.  
  5365.       /* If we found a register to use already, or if this is an optional
  5366.          reload, we are done.  */
  5367.       if (reload_reg_rtx[r] != 0 || reload_optional[r] != 0)
  5368.         continue;
  5369.  
  5370. #if 0 /* No longer needed for correct operation.  Might or might not
  5371.      give better code on the average.  Want to experiment?  */
  5372.  
  5373.       /* See if there is a later reload that has a class different from our
  5374.          class that intersects our class or that requires less register
  5375.          than our reload.  If so, we must allocate a register to this
  5376.          reload now, since that reload might inherit a previous reload
  5377.          and take the only available register in our class.  Don't do this
  5378.          for optional reloads since they will force all previous reloads
  5379.          to be allocated.  Also don't do this for reloads that have been
  5380.          turned off.  */
  5381.  
  5382.       for (i = j + 1; i < n_reloads; i++)
  5383.         {
  5384.           int s = reload_order[i];
  5385.  
  5386.           if ((reload_in[s] == 0 && reload_out[s] == 0
  5387.            && ! reload_secondary_p[s])
  5388.           || reload_optional[s])
  5389.         continue;
  5390.  
  5391.           if ((reload_reg_class[s] != reload_reg_class[r]
  5392.            && reg_classes_intersect_p (reload_reg_class[r],
  5393.                            reload_reg_class[s]))
  5394.           || reload_nregs[s] < reload_nregs[r])
  5395.           break;
  5396.         }
  5397.  
  5398.       if (i == n_reloads)
  5399.         continue;
  5400.  
  5401.       allocate_reload_reg (r, insn, j == n_reloads - 1, inheritance);
  5402. #endif
  5403.     }
  5404.  
  5405.       /* Now allocate reload registers for anything non-optional that
  5406.      didn't get one yet.  */
  5407.       for (j = 0; j < n_reloads; j++)
  5408.     {
  5409.       register int r = reload_order[j];
  5410.  
  5411.       /* Ignore reloads that got marked inoperative.  */
  5412.       if (reload_out[r] == 0 && reload_in[r] == 0 && ! reload_secondary_p[r])
  5413.         continue;
  5414.  
  5415.       /* Skip reloads that already have a register allocated or are
  5416.          optional. */
  5417.       if (reload_reg_rtx[r] != 0 || reload_optional[r])
  5418.         continue;
  5419.  
  5420.       if (! allocate_reload_reg (r, insn, j == n_reloads - 1, inheritance))
  5421.         break;
  5422.     }
  5423.  
  5424.       /* If that loop got all the way, we have won.  */
  5425.       if (j == n_reloads)
  5426.     break;
  5427.  
  5428.     fail:
  5429.       /* Loop around and try without any inheritance.  */
  5430.       /* First undo everything done by the failed attempt
  5431.      to allocate with inheritance.  */
  5432.       bcopy ((char *) save_reload_reg_rtx, (char *) reload_reg_rtx,
  5433.          sizeof reload_reg_rtx);
  5434.       bcopy ((char *) save_reload_inherited, (char *) reload_inherited,
  5435.          sizeof reload_inherited);
  5436.       bcopy ((char *) save_reload_inheritance_insn,
  5437.          (char *) reload_inheritance_insn,
  5438.          sizeof reload_inheritance_insn);
  5439.       bcopy ((char *) save_reload_override_in, (char *) reload_override_in,
  5440.          sizeof reload_override_in);
  5441.       bcopy ((char *) save_reload_spill_index, (char *) reload_spill_index,
  5442.          sizeof reload_spill_index);
  5443.       COPY_HARD_REG_SET (reload_reg_used, save_reload_reg_used);
  5444.       COPY_HARD_REG_SET (reload_reg_used_at_all, save_reload_reg_used_at_all);
  5445.       COPY_HARD_REG_SET (reload_reg_used_in_op_addr,
  5446.              save_reload_reg_used_in_op_addr);
  5447.       COPY_HARD_REG_SET (reload_reg_used_in_op_addr_reload,
  5448.              save_reload_reg_used_in_op_addr_reload);
  5449.       COPY_HARD_REG_SET (reload_reg_used_in_insn,
  5450.              save_reload_reg_used_in_insn);
  5451.       COPY_HARD_REG_SET (reload_reg_used_in_other_addr,
  5452.              save_reload_reg_used_in_other_addr);
  5453.  
  5454.       for (i = 0; i < reload_n_operands; i++)
  5455.     {
  5456.       COPY_HARD_REG_SET (reload_reg_used_in_input[i],
  5457.                  save_reload_reg_used_in_input[i]);
  5458.       COPY_HARD_REG_SET (reload_reg_used_in_output[i],
  5459.                  save_reload_reg_used_in_output[i]);
  5460.       COPY_HARD_REG_SET (reload_reg_used_in_input_addr[i],
  5461.                  save_reload_reg_used_in_input_addr[i]);
  5462.       COPY_HARD_REG_SET (reload_reg_used_in_output_addr[i],
  5463.                  save_reload_reg_used_in_output_addr[i]);
  5464.     }
  5465.     }
  5466.  
  5467.   /* If we thought we could inherit a reload, because it seemed that
  5468.      nothing else wanted the same reload register earlier in the insn,
  5469.      verify that assumption, now that all reloads have been assigned.  */
  5470.  
  5471.   for (j = 0; j < n_reloads; j++)
  5472.     {
  5473.       register int r = reload_order[j];
  5474.  
  5475.       if (reload_inherited[r] && reload_reg_rtx[r] != 0
  5476.       && ! reload_reg_free_before_p (true_regnum (reload_reg_rtx[r]),
  5477.                      reload_opnum[r],
  5478.                      reload_when_needed[r]))
  5479.     reload_inherited[r] = 0;
  5480.  
  5481.       /* If we found a better place to reload from,
  5482.      validate it in the same fashion, if it is a reload reg.  */
  5483.       if (reload_override_in[r]
  5484.       && (GET_CODE (reload_override_in[r]) == REG
  5485.           || GET_CODE (reload_override_in[r]) == SUBREG))
  5486.     {
  5487.       int regno = true_regnum (reload_override_in[r]);
  5488.       if (spill_reg_order[regno] >= 0
  5489.           && ! reload_reg_free_before_p (regno, reload_opnum[r],
  5490.                          reload_when_needed[r]))
  5491.         reload_override_in[r] = 0;
  5492.     }
  5493.     }
  5494.  
  5495.   /* Now that reload_override_in is known valid,
  5496.      actually override reload_in.  */
  5497.   for (j = 0; j < n_reloads; j++)
  5498.     if (reload_override_in[j])
  5499.       reload_in[j] = reload_override_in[j];
  5500.  
  5501.   /* If this reload won't be done because it has been cancelled or is
  5502.      optional and not inherited, clear reload_reg_rtx so other
  5503.      routines (such as subst_reloads) don't get confused.  */
  5504.   for (j = 0; j < n_reloads; j++)
  5505.     if (reload_reg_rtx[j] != 0
  5506.     && ((reload_optional[j] && ! reload_inherited[j])
  5507.         || (reload_in[j] == 0 && reload_out[j] == 0
  5508.         && ! reload_secondary_p[j])))
  5509.       {
  5510.     int regno = true_regnum (reload_reg_rtx[j]);
  5511.  
  5512.     if (spill_reg_order[regno] >= 0)
  5513.       clear_reload_reg_in_use (regno, reload_opnum[j],
  5514.                    reload_when_needed[j], reload_mode[j]);
  5515.     reload_reg_rtx[j] = 0;
  5516.       }
  5517.  
  5518.   /* Record which pseudos and which spill regs have output reloads.  */
  5519.   for (j = 0; j < n_reloads; j++)
  5520.     {
  5521.       register int r = reload_order[j];
  5522.  
  5523.       i = reload_spill_index[r];
  5524.  
  5525.       /* I is nonneg if this reload used one of the spill regs.
  5526.      If reload_reg_rtx[r] is 0, this is an optional reload
  5527.      that we opted to ignore.  */
  5528.       if (reload_out[r] != 0 && GET_CODE (reload_out[r]) == REG
  5529.       && reload_reg_rtx[r] != 0)
  5530.     {
  5531.       register int nregno = REGNO (reload_out[r]);
  5532.       int nr = 1;
  5533.  
  5534.       if (nregno < FIRST_PSEUDO_REGISTER)
  5535.         nr = HARD_REGNO_NREGS (nregno, reload_mode[r]);
  5536.  
  5537.       while (--nr >= 0)
  5538.         reg_has_output_reload[nregno + nr] = 1;
  5539.  
  5540.       if (i >= 0)
  5541.         {
  5542.           nr = HARD_REGNO_NREGS (spill_regs[i], reload_mode[r]);
  5543.           while (--nr >= 0)
  5544.         SET_HARD_REG_BIT (reg_is_output_reload, spill_regs[i] + nr);
  5545.         }
  5546.  
  5547.       if (reload_when_needed[r] != RELOAD_OTHER
  5548.           && reload_when_needed[r] != RELOAD_FOR_OUTPUT
  5549.           && reload_when_needed[r] != RELOAD_FOR_INSN)
  5550.         abort ();
  5551.     }
  5552.     }
  5553. }
  5554.  
  5555. /* If SMALL_REGISTER_CLASSES are defined, we may not have merged two
  5556.    reloads of the same item for fear that we might not have enough reload
  5557.    registers. However, normally they will get the same reload register
  5558.    and hence actually need not be loaded twice.  
  5559.  
  5560.    Here we check for the most common case of this phenomenon: when we have
  5561.    a number of reloads for the same object, each of which were allocated
  5562.    the same reload_reg_rtx, that reload_reg_rtx is not used for any other
  5563.    reload, and is not modified in the insn itself.  If we find such,
  5564.    merge all the reloads and set the resulting reload to RELOAD_OTHER.
  5565.    This will not increase the number of spill registers needed and will
  5566.    prevent redundant code.  */
  5567.  
  5568. #ifdef SMALL_REGISTER_CLASSES
  5569.  
  5570. static void
  5571. merge_assigned_reloads (insn)
  5572.      rtx insn;
  5573. {
  5574.   int i, j;
  5575.  
  5576.   /* Scan all the reloads looking for ones that only load values and
  5577.      are not already RELOAD_OTHER and ones whose reload_reg_rtx are
  5578.      assigned and not modified by INSN.  */
  5579.  
  5580.   for (i = 0; i < n_reloads; i++)
  5581.     {
  5582.       if (reload_in[i] == 0 || reload_when_needed[i] == RELOAD_OTHER
  5583.       || reload_out[i] != 0 || reload_reg_rtx[i] == 0
  5584.       || reg_set_p (reload_reg_rtx[i], insn))
  5585.     continue;
  5586.  
  5587.       /* Look at all other reloads.  Ensure that the only use of this
  5588.      reload_reg_rtx is in a reload that just loads the same value
  5589.      as we do.  Note that any secondary reloads must be of the identical
  5590.      class since the values, modes, and result registers are the
  5591.      same, so we need not do anything with any secondary reloads.  */
  5592.  
  5593.       for (j = 0; j < n_reloads; j++)
  5594.     {
  5595.       if (i == j || reload_reg_rtx[j] == 0
  5596.           || ! reg_overlap_mentioned_p (reload_reg_rtx[j],
  5597.                         reload_reg_rtx[i]))
  5598.         continue;
  5599.  
  5600.       /* If the reload regs aren't exactly the same (e.g, different modes)
  5601.          or if the values are different, we can't merge anything with this
  5602.          reload register.  */
  5603.  
  5604.       if (! rtx_equal_p (reload_reg_rtx[i], reload_reg_rtx[j])
  5605.           || reload_out[j] != 0 || reload_in[j] == 0
  5606.           || ! rtx_equal_p (reload_in[i], reload_in[j]))
  5607.         break;
  5608.     }
  5609.  
  5610.       /* If all is OK, merge the reloads.  Only set this to RELOAD_OTHER if
  5611.      we, in fact, found any matching reloads.  */
  5612.  
  5613.       if (j == n_reloads)
  5614.     {
  5615.       for (j = 0; j < n_reloads; j++)
  5616.         if (i != j && reload_reg_rtx[j] != 0
  5617.         && rtx_equal_p (reload_reg_rtx[i], reload_reg_rtx[j]))
  5618.           {
  5619.         reload_when_needed[i] = RELOAD_OTHER;
  5620.         reload_in[j] = 0;
  5621.         transfer_replacements (i, j);
  5622.           }
  5623.  
  5624.       /* If this is now RELOAD_OTHER, look for any reloads that load
  5625.          parts of this operand and set them to RELOAD_FOR_OTHER_ADDRESS
  5626.          if they were for inputs, RELOAD_OTHER for outputs.  Note that
  5627.          this test is equivalent to looking for reloads for this operand
  5628.          number.  */
  5629.  
  5630.       if (reload_when_needed[i] == RELOAD_OTHER)
  5631.         for (j = 0; j < n_reloads; j++)
  5632.           if (reload_in[j] != 0
  5633.           && reload_when_needed[i] != RELOAD_OTHER
  5634.           && reg_overlap_mentioned_for_reload_p (reload_in[j],
  5635.                              reload_in[i]))
  5636.         reload_when_needed[j]
  5637.           = reload_when_needed[i] == RELOAD_FOR_INPUT_ADDRESS
  5638.             ? RELOAD_FOR_OTHER_ADDRESS : RELOAD_OTHER;
  5639.     }
  5640.     }
  5641. }        
  5642. #endif /* SMALL_RELOAD_CLASSES */
  5643.  
  5644. /* Output insns to reload values in and out of the chosen reload regs.  */
  5645.  
  5646. static void
  5647. emit_reload_insns (insn)
  5648.      rtx insn;
  5649. {
  5650.   register int j;
  5651.   rtx input_reload_insns[MAX_RECOG_OPERANDS];
  5652.   rtx other_input_address_reload_insns = 0;
  5653.   rtx other_input_reload_insns = 0;
  5654.   rtx input_address_reload_insns[MAX_RECOG_OPERANDS];
  5655.   rtx output_reload_insns[MAX_RECOG_OPERANDS];
  5656.   rtx output_address_reload_insns[MAX_RECOG_OPERANDS];
  5657.   rtx operand_reload_insns = 0;
  5658.   rtx other_operand_reload_insns = 0;
  5659.   rtx other_output_reload_insns = 0;
  5660.   rtx following_insn = NEXT_INSN (insn);
  5661.   rtx before_insn = insn;
  5662.   int special;
  5663.   /* Values to be put in spill_reg_store are put here first.  */
  5664.   rtx new_spill_reg_store[FIRST_PSEUDO_REGISTER];
  5665.  
  5666.   for (j = 0; j < reload_n_operands; j++)
  5667.     input_reload_insns[j] = input_address_reload_insns[j]
  5668.       = output_reload_insns[j] = output_address_reload_insns[j] = 0;
  5669.  
  5670.   /* Now output the instructions to copy the data into and out of the
  5671.      reload registers.  Do these in the order that the reloads were reported,
  5672.      since reloads of base and index registers precede reloads of operands
  5673.      and the operands may need the base and index registers reloaded.  */
  5674.  
  5675.   for (j = 0; j < n_reloads; j++)
  5676.     {
  5677.       register rtx old;
  5678.       rtx oldequiv_reg = 0;
  5679.  
  5680.       if (reload_spill_index[j] >= 0)
  5681.     new_spill_reg_store[reload_spill_index[j]] = 0;
  5682.  
  5683.       old = reload_in[j];
  5684.       if (old != 0 && ! reload_inherited[j]
  5685.       && ! rtx_equal_p (reload_reg_rtx[j], old)
  5686.       && reload_reg_rtx[j] != 0)
  5687.     {
  5688.       register rtx reloadreg = reload_reg_rtx[j];
  5689.       rtx oldequiv = 0;
  5690.       enum machine_mode mode;
  5691.       rtx *where;
  5692.  
  5693.       /* Determine the mode to reload in.
  5694.          This is very tricky because we have three to choose from.
  5695.          There is the mode the insn operand wants (reload_inmode[J]).
  5696.          There is the mode of the reload register RELOADREG.
  5697.          There is the intrinsic mode of the operand, which we could find
  5698.          by stripping some SUBREGs.
  5699.          It turns out that RELOADREG's mode is irrelevant:
  5700.          we can change that arbitrarily.
  5701.  
  5702.          Consider (SUBREG:SI foo:QI) as an operand that must be SImode;
  5703.          then the reload reg may not support QImode moves, so use SImode.
  5704.          If foo is in memory due to spilling a pseudo reg, this is safe,
  5705.          because the QImode value is in the least significant part of a
  5706.          slot big enough for a SImode.  If foo is some other sort of
  5707.          memory reference, then it is impossible to reload this case,
  5708.          so previous passes had better make sure this never happens.
  5709.  
  5710.          Then consider a one-word union which has SImode and one of its
  5711.          members is a float, being fetched as (SUBREG:SF union:SI).
  5712.          We must fetch that as SFmode because we could be loading into
  5713.          a float-only register.  In this case OLD's mode is correct.
  5714.  
  5715.          Consider an immediate integer: it has VOIDmode.  Here we need
  5716.          to get a mode from something else.
  5717.  
  5718.          In some cases, there is a fourth mode, the operand's
  5719.          containing mode.  If the insn specifies a containing mode for
  5720.          this operand, it overrides all others.
  5721.  
  5722.          I am not sure whether the algorithm here is always right,
  5723.          but it does the right things in those cases.  */
  5724.  
  5725.       mode = GET_MODE (old);
  5726.       if (mode == VOIDmode)
  5727.         mode = reload_inmode[j];
  5728.  
  5729. #ifdef SECONDARY_INPUT_RELOAD_CLASS
  5730.       /* If we need a secondary register for this operation, see if
  5731.          the value is already in a register in that class.  Don't
  5732.          do this if the secondary register will be used as a scratch
  5733.          register.  */
  5734.  
  5735.       if (reload_secondary_in_reload[j] >= 0
  5736.           && reload_secondary_in_icode[j] == CODE_FOR_nothing
  5737.           && optimize)
  5738.         oldequiv
  5739.           = find_equiv_reg (old, insn,
  5740.                 reload_reg_class[reload_secondary_in_reload[j]],
  5741.                 -1, NULL_PTR, 0, mode);
  5742. #endif
  5743.  
  5744.       /* If reloading from memory, see if there is a register
  5745.          that already holds the same value.  If so, reload from there.
  5746.          We can pass 0 as the reload_reg_p argument because
  5747.          any other reload has either already been emitted,
  5748.          in which case find_equiv_reg will see the reload-insn,
  5749.          or has yet to be emitted, in which case it doesn't matter
  5750.          because we will use this equiv reg right away.  */
  5751.  
  5752.       if (oldequiv == 0 && optimize
  5753.           && (GET_CODE (old) == MEM
  5754.           || (GET_CODE (old) == REG
  5755.               && REGNO (old) >= FIRST_PSEUDO_REGISTER
  5756.               && reg_renumber[REGNO (old)] < 0)))
  5757.         oldequiv = find_equiv_reg (old, insn, ALL_REGS,
  5758.                        -1, NULL_PTR, 0, mode);
  5759.  
  5760.       if (oldequiv)
  5761.         {
  5762.           int regno = true_regnum (oldequiv);
  5763.  
  5764.           /* If OLDEQUIV is a spill register, don't use it for this
  5765.          if any other reload needs it at an earlier stage of this insn
  5766.          or at this stage.  */
  5767.           if (spill_reg_order[regno] >= 0
  5768.           && (! reload_reg_free_p (regno, reload_opnum[j],
  5769.                        reload_when_needed[j])
  5770.               || ! reload_reg_free_before_p (regno, reload_opnum[j],
  5771.                              reload_when_needed[j])))
  5772.         oldequiv = 0;
  5773.  
  5774.           /* If OLDEQUIV is not a spill register,
  5775.          don't use it if any other reload wants it.  */
  5776.           if (spill_reg_order[regno] < 0)
  5777.         {
  5778.           int k;
  5779.           for (k = 0; k < n_reloads; k++)
  5780.             if (reload_reg_rtx[k] != 0 && k != j
  5781.             && reg_overlap_mentioned_for_reload_p (reload_reg_rtx[k],
  5782.                                    oldequiv))
  5783.               {
  5784.             oldequiv = 0;
  5785.             break;
  5786.               }
  5787.         }
  5788.  
  5789.           /* If it is no cheaper to copy from OLDEQUIV into the
  5790.          reload register than it would be to move from memory,
  5791.          don't use it. Likewise, if we need a secondary register
  5792.          or memory.   */
  5793.  
  5794.           if (oldequiv != 0
  5795.           && ((REGNO_REG_CLASS (regno) != reload_reg_class[j]
  5796.                && (REGISTER_MOVE_COST (REGNO_REG_CLASS (regno),
  5797.                            reload_reg_class[j])
  5798.                >= MEMORY_MOVE_COST (mode)))
  5799. #ifdef SECONDARY_INPUT_RELOAD_CLASS
  5800.               || (SECONDARY_INPUT_RELOAD_CLASS (reload_reg_class[j],
  5801.                             mode, oldequiv)
  5802.               != NO_REGS)
  5803. #endif
  5804. #ifdef SECONDARY_MEMORY_NEEDED
  5805.               || SECONDARY_MEMORY_NEEDED (reload_reg_class[j],
  5806.                           REGNO_REG_CLASS (regno),
  5807.                           mode)
  5808. #endif
  5809.               ))
  5810.         oldequiv = 0;
  5811.         }
  5812.  
  5813.       if (oldequiv == 0)
  5814.         oldequiv = old;
  5815.       else if (GET_CODE (oldequiv) == REG)
  5816.         oldequiv_reg = oldequiv;
  5817.       else if (GET_CODE (oldequiv) == SUBREG)
  5818.         oldequiv_reg = SUBREG_REG (oldequiv);
  5819.  
  5820.       /* If we are reloading from a register that was recently stored in
  5821.          with an output-reload, see if we can prove there was
  5822.          actually no need to store the old value in it.  */
  5823.  
  5824.       if (optimize && GET_CODE (oldequiv) == REG
  5825.           && REGNO (oldequiv) < FIRST_PSEUDO_REGISTER
  5826.           && spill_reg_order[REGNO (oldequiv)] >= 0
  5827.           && spill_reg_store[spill_reg_order[REGNO (oldequiv)]] != 0
  5828.           && find_reg_note (insn, REG_DEAD, reload_in[j])
  5829.           /* This is unsafe if operand occurs more than once in current
  5830.          insn.  Perhaps some occurrences weren't reloaded.  */
  5831.           && count_occurrences (PATTERN (insn), reload_in[j]) == 1)
  5832.         delete_output_reload
  5833.           (insn, j, spill_reg_store[spill_reg_order[REGNO (oldequiv)]]);
  5834.  
  5835.       /* Encapsulate both RELOADREG and OLDEQUIV into that mode,
  5836.          then load RELOADREG from OLDEQUIV.  Note that we cannot use
  5837.          gen_lowpart_common since it can do the wrong thing when
  5838.          RELOADREG has a multi-word mode.  Note that RELOADREG
  5839.          must always be a REG here.  */
  5840.  
  5841.       if (GET_MODE (reloadreg) != mode)
  5842.         reloadreg = gen_rtx (REG, mode, REGNO (reloadreg));
  5843.       while (GET_CODE (oldequiv) == SUBREG && GET_MODE (oldequiv) != mode)
  5844.         oldequiv = SUBREG_REG (oldequiv);
  5845.       if (GET_MODE (oldequiv) != VOIDmode
  5846.           && mode != GET_MODE (oldequiv))
  5847.         oldequiv = gen_rtx (SUBREG, mode, oldequiv, 0);
  5848.  
  5849.       /* Switch to the right place to emit the reload insns.  */
  5850.       switch (reload_when_needed[j])
  5851.         {
  5852.         case RELOAD_OTHER:
  5853.           where = &other_input_reload_insns;
  5854.           break;
  5855.         case RELOAD_FOR_INPUT:
  5856.           where = &input_reload_insns[reload_opnum[j]];
  5857.           break;
  5858.         case RELOAD_FOR_INPUT_ADDRESS:
  5859.           where = &input_address_reload_insns[reload_opnum[j]];
  5860.           break;
  5861.         case RELOAD_FOR_OUTPUT_ADDRESS:
  5862.           where = &output_address_reload_insns[reload_opnum[j]];
  5863.           break;
  5864.         case RELOAD_FOR_OPERAND_ADDRESS:
  5865.           where = &operand_reload_insns;
  5866.           break;
  5867.         case RELOAD_FOR_OPADDR_ADDR:
  5868.           where = &other_operand_reload_insns;
  5869.           break;
  5870.         case RELOAD_FOR_OTHER_ADDRESS:
  5871.           where = &other_input_address_reload_insns;
  5872.           break;
  5873.         default:
  5874.           abort ();
  5875.         }
  5876.  
  5877.       push_to_sequence (*where);
  5878.       special = 0;
  5879.  
  5880.       /* Auto-increment addresses must be reloaded in a special way.  */
  5881.       if (GET_CODE (oldequiv) == POST_INC
  5882.           || GET_CODE (oldequiv) == POST_DEC
  5883.           || GET_CODE (oldequiv) == PRE_INC
  5884.           || GET_CODE (oldequiv) == PRE_DEC)
  5885.         {
  5886.           /* We are not going to bother supporting the case where a
  5887.          incremented register can't be copied directly from
  5888.          OLDEQUIV since this seems highly unlikely.  */
  5889.           if (reload_secondary_in_reload[j] >= 0)
  5890.         abort ();
  5891.           /* Prevent normal processing of this reload.  */
  5892.           special = 1;
  5893.           /* Output a special code sequence for this case.  */
  5894.           inc_for_reload (reloadreg, oldequiv, reload_inc[j]);
  5895.         }
  5896.  
  5897.       /* If we are reloading a pseudo-register that was set by the previous
  5898.          insn, see if we can get rid of that pseudo-register entirely
  5899.          by redirecting the previous insn into our reload register.  */
  5900.  
  5901.       else if (optimize && GET_CODE (old) == REG
  5902.            && REGNO (old) >= FIRST_PSEUDO_REGISTER
  5903.            && dead_or_set_p (insn, old)
  5904.            /* This is unsafe if some other reload
  5905.               uses the same reg first.  */
  5906.            && reload_reg_free_before_p (REGNO (reloadreg),
  5907.                         reload_opnum[j],
  5908.                         reload_when_needed[j]))
  5909.         {
  5910.           rtx temp = PREV_INSN (insn);
  5911.           while (temp && GET_CODE (temp) == NOTE)
  5912.         temp = PREV_INSN (temp);
  5913.           if (temp
  5914.           && GET_CODE (temp) == INSN
  5915.           && GET_CODE (PATTERN (temp)) == SET
  5916.           && SET_DEST (PATTERN (temp)) == old
  5917.           /* Make sure we can access insn_operand_constraint.  */
  5918.           && asm_noperands (PATTERN (temp)) < 0
  5919.           /* This is unsafe if prev insn rejects our reload reg.  */
  5920.           && constraint_accepts_reg_p (insn_operand_constraint[recog_memoized (temp)][0],
  5921.                            reloadreg)
  5922.           /* This is unsafe if operand occurs more than once in current
  5923.              insn.  Perhaps some occurrences aren't reloaded.  */
  5924.           && count_occurrences (PATTERN (insn), old) == 1
  5925.           /* Don't risk splitting a matching pair of operands.  */
  5926.           && ! reg_mentioned_p (old, SET_SRC (PATTERN (temp))))
  5927.         {
  5928.           /* Store into the reload register instead of the pseudo.  */
  5929.           SET_DEST (PATTERN (temp)) = reloadreg;
  5930.           /* If these are the only uses of the pseudo reg,
  5931.              pretend for GDB it lives in the reload reg we used.  */
  5932.           if (reg_n_deaths[REGNO (old)] == 1
  5933.               && reg_n_sets[REGNO (old)] == 1)
  5934.             {
  5935.               reg_renumber[REGNO (old)] = REGNO (reload_reg_rtx[j]);
  5936.               alter_reg (REGNO (old), -1);
  5937.             }
  5938.           special = 1;
  5939.         }
  5940.         }
  5941.  
  5942.       /* We can't do that, so output an insn to load RELOADREG.  */
  5943.  
  5944.       if (! special)
  5945.         {
  5946. #ifdef SECONDARY_INPUT_RELOAD_CLASS
  5947.           rtx second_reload_reg = 0;
  5948.           enum insn_code icode;
  5949.  
  5950.           /* If we have a secondary reload, pick up the secondary register
  5951.          and icode, if any.  If OLDEQUIV and OLD are different or
  5952.          if this is an in-out reload, recompute whether or not we
  5953.          still need a secondary register and what the icode should
  5954.          be.  If we still need a secondary register and the class or
  5955.          icode is different, go back to reloading from OLD if using
  5956.          OLDEQUIV means that we got the wrong type of register.  We
  5957.          cannot have different class or icode due to an in-out reload
  5958.          because we don't make such reloads when both the input and
  5959.          output need secondary reload registers.  */
  5960.  
  5961.           if (reload_secondary_in_reload[j] >= 0)
  5962.         {
  5963.           int secondary_reload = reload_secondary_in_reload[j];
  5964.           rtx real_oldequiv = oldequiv;
  5965.           rtx real_old = old;
  5966.  
  5967.           /* If OLDEQUIV is a pseudo with a MEM, get the real MEM
  5968.              and similarly for OLD.
  5969.              See comments in get_secondary_reload in reload.c.  */
  5970.           if (GET_CODE (oldequiv) == REG
  5971.               && REGNO (oldequiv) >= FIRST_PSEUDO_REGISTER
  5972.               && reg_equiv_mem[REGNO (oldequiv)] != 0)
  5973.             real_oldequiv = reg_equiv_mem[REGNO (oldequiv)];
  5974.  
  5975.           if (GET_CODE (old) == REG
  5976.               && REGNO (old) >= FIRST_PSEUDO_REGISTER
  5977.               && reg_equiv_mem[REGNO (old)] != 0)
  5978.             real_old = reg_equiv_mem[REGNO (old)];
  5979.  
  5980.           second_reload_reg = reload_reg_rtx[secondary_reload];
  5981.           icode = reload_secondary_in_icode[j];
  5982.  
  5983.           if ((old != oldequiv && ! rtx_equal_p (old, oldequiv))
  5984.               || (reload_in[j] != 0 && reload_out[j] != 0))
  5985.             {
  5986.               enum reg_class new_class
  5987.             = SECONDARY_INPUT_RELOAD_CLASS (reload_reg_class[j],
  5988.                             mode, real_oldequiv);
  5989.  
  5990.               if (new_class == NO_REGS)
  5991.             second_reload_reg = 0;
  5992.               else
  5993.             {
  5994.               enum insn_code new_icode;
  5995.               enum machine_mode new_mode;
  5996.  
  5997.               if (! TEST_HARD_REG_BIT (reg_class_contents[(int) new_class],
  5998.                            REGNO (second_reload_reg)))
  5999.                 oldequiv = old, real_oldequiv = real_old;
  6000.               else
  6001.                 {
  6002.                   new_icode = reload_in_optab[(int) mode];
  6003.                   if (new_icode != CODE_FOR_nothing
  6004.                   && ((insn_operand_predicate[(int) new_icode][0]
  6005.                        && ! ((*insn_operand_predicate[(int) new_icode][0])
  6006.                          (reloadreg, mode)))
  6007.                       || (insn_operand_predicate[(int) new_icode][1]
  6008.                       && ! ((*insn_operand_predicate[(int) new_icode][1])
  6009.                         (real_oldequiv, mode)))))
  6010.                 new_icode = CODE_FOR_nothing;
  6011.  
  6012.                   if (new_icode == CODE_FOR_nothing)
  6013.                 new_mode = mode;
  6014.                   else
  6015.                 new_mode = insn_operand_mode[(int) new_icode][2];
  6016.  
  6017.                   if (GET_MODE (second_reload_reg) != new_mode)
  6018.                 {
  6019.                   if (!HARD_REGNO_MODE_OK (REGNO (second_reload_reg),
  6020.                                new_mode))
  6021.                     oldequiv = old, real_oldequiv = real_old;
  6022.                   else
  6023.                     second_reload_reg
  6024.                       = gen_rtx (REG, new_mode,
  6025.                          REGNO (second_reload_reg));
  6026.                 }
  6027.                 }
  6028.             }
  6029.             }
  6030.  
  6031.           /* If we still need a secondary reload register, check
  6032.              to see if it is being used as a scratch or intermediate
  6033.              register and generate code appropriately.  If we need
  6034.              a scratch register, use REAL_OLDEQUIV since the form of
  6035.              the insn may depend on the actual address if it is 
  6036.              a MEM.  */
  6037.  
  6038.           if (second_reload_reg)
  6039.             {
  6040.               if (icode != CODE_FOR_nothing)
  6041.             {
  6042.               emit_insn (GEN_FCN (icode) (reloadreg, real_oldequiv,
  6043.                               second_reload_reg));
  6044.               special = 1;
  6045.             }
  6046.               else
  6047.             {
  6048.               /* See if we need a scratch register to load the
  6049.                  intermediate register (a tertiary reload).  */
  6050.               enum insn_code tertiary_icode
  6051.                 = reload_secondary_in_icode[secondary_reload];
  6052.  
  6053.               if (tertiary_icode != CODE_FOR_nothing)
  6054.                 {
  6055.                   rtx third_reload_reg
  6056.                     = reload_reg_rtx[reload_secondary_in_reload[secondary_reload]];
  6057.  
  6058.                   emit_insn ((GEN_FCN (tertiary_icode)
  6059.                       (second_reload_reg, real_oldequiv,
  6060.                        third_reload_reg)));
  6061.                 }
  6062.               else
  6063.                 gen_reload (second_reload_reg, oldequiv,
  6064.                     reload_opnum[j],
  6065.                     reload_when_needed[j]);
  6066.  
  6067.               oldequiv = second_reload_reg;
  6068.             }
  6069.             }
  6070.         }
  6071. #endif
  6072.  
  6073.           if (! special && ! rtx_equal_p (reloadreg, oldequiv))
  6074.         gen_reload (reloadreg, oldequiv, reload_opnum[j],
  6075.                 reload_when_needed[j]);
  6076.  
  6077. #if defined(SECONDARY_INPUT_RELOAD_CLASS) && defined(PRESERVE_DEATH_INFO_REGNO_P)
  6078.           /* We may have to make a REG_DEAD note for the secondary reload
  6079.          register in the insns we just made.  Find the last insn that
  6080.          mentioned the register.  */
  6081.           if (! special && second_reload_reg
  6082.           && PRESERVE_DEATH_INFO_REGNO_P (REGNO (second_reload_reg)))
  6083.         {
  6084.           rtx prev;
  6085.  
  6086.           for (prev = get_last_insn (); prev;
  6087.                prev = PREV_INSN (prev))
  6088.             if (GET_RTX_CLASS (GET_CODE (prev) == 'i')
  6089.             && reg_overlap_mentioned_for_reload_p (second_reload_reg,
  6090.                                    PATTERN (prev)))
  6091.               {
  6092.             REG_NOTES (prev) = gen_rtx (EXPR_LIST, REG_DEAD,
  6093.                             second_reload_reg,
  6094.                             REG_NOTES (prev));
  6095.             break;
  6096.               }
  6097.         }
  6098. #endif
  6099.         }
  6100.  
  6101.       /* End this sequence.  */
  6102.       *where = get_insns ();
  6103.       end_sequence ();
  6104.     }
  6105.  
  6106.       /* Add a note saying the input reload reg
  6107.      dies in this insn, if anyone cares.  */
  6108. #ifdef PRESERVE_DEATH_INFO_REGNO_P
  6109.       if (old != 0
  6110.       && reload_reg_rtx[j] != old
  6111.       && reload_reg_rtx[j] != 0
  6112.       && reload_out[j] == 0
  6113.       && ! reload_inherited[j]
  6114.       && PRESERVE_DEATH_INFO_REGNO_P (REGNO (reload_reg_rtx[j])))
  6115.     {
  6116.       register rtx reloadreg = reload_reg_rtx[j];
  6117.  
  6118. #if 0
  6119.       /* We can't abort here because we need to support this for sched.c.
  6120.          It's not terrible to miss a REG_DEAD note, but we should try
  6121.          to figure out how to do this correctly.  */
  6122.       /* The code below is incorrect for address-only reloads.  */
  6123.       if (reload_when_needed[j] != RELOAD_OTHER
  6124.           && reload_when_needed[j] != RELOAD_FOR_INPUT)
  6125.         abort ();
  6126. #endif
  6127.  
  6128.       /* Add a death note to this insn, for an input reload.  */
  6129.  
  6130.       if ((reload_when_needed[j] == RELOAD_OTHER
  6131.            || reload_when_needed[j] == RELOAD_FOR_INPUT)
  6132.           && ! dead_or_set_p (insn, reloadreg))
  6133.         REG_NOTES (insn)
  6134.           = gen_rtx (EXPR_LIST, REG_DEAD,
  6135.              reloadreg, REG_NOTES (insn));
  6136.     }
  6137.  
  6138.       /* When we inherit a reload, the last marked death of the reload reg
  6139.      may no longer really be a death.  */
  6140.       if (reload_reg_rtx[j] != 0
  6141.       && PRESERVE_DEATH_INFO_REGNO_P (REGNO (reload_reg_rtx[j]))
  6142.       && reload_inherited[j])
  6143.     {
  6144.       /* Handle inheriting an output reload.
  6145.          Remove the death note from the output reload insn.  */
  6146.       if (reload_spill_index[j] >= 0
  6147.           && GET_CODE (reload_in[j]) == REG
  6148.           && spill_reg_store[reload_spill_index[j]] != 0
  6149.           && find_regno_note (spill_reg_store[reload_spill_index[j]],
  6150.                   REG_DEAD, REGNO (reload_reg_rtx[j])))
  6151.         remove_death (REGNO (reload_reg_rtx[j]),
  6152.               spill_reg_store[reload_spill_index[j]]);
  6153.       /* Likewise for input reloads that were inherited.  */
  6154.       else if (reload_spill_index[j] >= 0
  6155.            && GET_CODE (reload_in[j]) == REG
  6156.            && spill_reg_store[reload_spill_index[j]] == 0
  6157.            && reload_inheritance_insn[j] != 0
  6158.            && find_regno_note (reload_inheritance_insn[j], REG_DEAD,
  6159.                        REGNO (reload_reg_rtx[j])))
  6160.         remove_death (REGNO (reload_reg_rtx[j]),
  6161.               reload_inheritance_insn[j]);
  6162.       else
  6163.         {
  6164.           rtx prev;
  6165.  
  6166.           /* We got this register from find_equiv_reg.
  6167.          Search back for its last death note and get rid of it.
  6168.          But don't search back too far.
  6169.          Don't go past a place where this reg is set,
  6170.          since a death note before that remains valid.  */
  6171.           for (prev = PREV_INSN (insn);
  6172.            prev && GET_CODE (prev) != CODE_LABEL;
  6173.            prev = PREV_INSN (prev))
  6174.         if (GET_RTX_CLASS (GET_CODE (prev)) == 'i'
  6175.             && dead_or_set_p (prev, reload_reg_rtx[j]))
  6176.           {
  6177.             if (find_regno_note (prev, REG_DEAD,
  6178.                      REGNO (reload_reg_rtx[j])))
  6179.               remove_death (REGNO (reload_reg_rtx[j]), prev);
  6180.             break;
  6181.           }
  6182.         }
  6183.     }
  6184.  
  6185.       /* We might have used find_equiv_reg above to choose an alternate
  6186.      place from which to reload.  If so, and it died, we need to remove
  6187.      that death and move it to one of the insns we just made.  */
  6188.  
  6189.       if (oldequiv_reg != 0
  6190.       && PRESERVE_DEATH_INFO_REGNO_P (true_regnum (oldequiv_reg)))
  6191.     {
  6192.       rtx prev, prev1;
  6193.  
  6194.       for (prev = PREV_INSN (insn); prev && GET_CODE (prev) != CODE_LABEL;
  6195.            prev = PREV_INSN (prev))
  6196.         if (GET_RTX_CLASS (GET_CODE (prev)) == 'i'
  6197.         && dead_or_set_p (prev, oldequiv_reg))
  6198.           {
  6199.         if (find_regno_note (prev, REG_DEAD, REGNO (oldequiv_reg)))
  6200.           {
  6201.             for (prev1 = this_reload_insn;
  6202.              prev1; prev1 = PREV_INSN (prev1))
  6203.               if (GET_RTX_CLASS (GET_CODE (prev1) == 'i')
  6204.             && reg_overlap_mentioned_for_reload_p (oldequiv_reg,
  6205.                                    PATTERN (prev1)))
  6206.               {
  6207.             REG_NOTES (prev1) = gen_rtx (EXPR_LIST, REG_DEAD,
  6208.                              oldequiv_reg,
  6209.                              REG_NOTES (prev1));
  6210.             break;
  6211.               }
  6212.             remove_death (REGNO (oldequiv_reg), prev);
  6213.           }
  6214.         break;
  6215.           }
  6216.     }
  6217. #endif
  6218.  
  6219.       /* If we are reloading a register that was recently stored in with an
  6220.      output-reload, see if we can prove there was
  6221.      actually no need to store the old value in it.  */
  6222.  
  6223.       if (optimize && reload_inherited[j] && reload_spill_index[j] >= 0
  6224.       && reload_in[j] != 0
  6225.       && GET_CODE (reload_in[j]) == REG
  6226. #if 0
  6227.       /* There doesn't seem to be any reason to restrict this to pseudos
  6228.          and doing so loses in the case where we are copying from a
  6229.          register of the wrong class.  */
  6230.       && REGNO (reload_in[j]) >= FIRST_PSEUDO_REGISTER
  6231. #endif
  6232.       && spill_reg_store[reload_spill_index[j]] != 0
  6233.       /* This is unsafe if some other reload uses the same reg first.  */
  6234.       && reload_reg_free_before_p (spill_regs[reload_spill_index[j]],
  6235.                        reload_opnum[j], reload_when_needed[j])
  6236.       && dead_or_set_p (insn, reload_in[j])
  6237.       /* This is unsafe if operand occurs more than once in current
  6238.          insn.  Perhaps some occurrences weren't reloaded.  */
  6239.       && count_occurrences (PATTERN (insn), reload_in[j]) == 1)
  6240.     delete_output_reload (insn, j,
  6241.                   spill_reg_store[reload_spill_index[j]]);
  6242.  
  6243.       /* Input-reloading is done.  Now do output-reloading,
  6244.      storing the value from the reload-register after the main insn
  6245.      if reload_out[j] is nonzero.
  6246.  
  6247.      ??? At some point we need to support handling output reloads of
  6248.      JUMP_INSNs or insns that set cc0.  */
  6249.       old = reload_out[j];
  6250.       if (old != 0
  6251.       && reload_reg_rtx[j] != old
  6252.       && reload_reg_rtx[j] != 0)
  6253.     {
  6254.       register rtx reloadreg = reload_reg_rtx[j];
  6255.       register rtx second_reloadreg = 0;
  6256.       rtx note, p;
  6257.       enum machine_mode mode;
  6258.       int special = 0;
  6259.  
  6260.       /* An output operand that dies right away does need a reload,
  6261.          but need not be copied from it.  Show the new location in the
  6262.          REG_UNUSED note.  */
  6263.       if ((GET_CODE (old) == REG || GET_CODE (old) == SCRATCH)
  6264.           && (note = find_reg_note (insn, REG_UNUSED, old)) != 0)
  6265.         {
  6266.           XEXP (note, 0) = reload_reg_rtx[j];
  6267.           continue;
  6268.         }
  6269.       /* Likewise for a SUBREG of an operand that dies.  */
  6270.       else if (GET_CODE (old) == SUBREG
  6271.            && GET_CODE (SUBREG_REG (old)) == REG
  6272.            && 0 != (note = find_reg_note (insn, REG_UNUSED,
  6273.                           SUBREG_REG (old))))
  6274.         {
  6275.           XEXP (note, 0) = gen_lowpart_common (GET_MODE (old),
  6276.                            reload_reg_rtx[j]);
  6277.           continue;
  6278.         }
  6279.       else if (GET_CODE (old) == SCRATCH)
  6280.         /* If we aren't optimizing, there won't be a REG_UNUSED note,
  6281.            but we don't want to make an output reload.  */
  6282.         continue;
  6283.  
  6284. #if 0
  6285.       /* Strip off of OLD any size-increasing SUBREGs such as
  6286.          (SUBREG:SI foo:QI 0).  */
  6287.  
  6288.       while (GET_CODE (old) == SUBREG && SUBREG_WORD (old) == 0
  6289.          && (GET_MODE_SIZE (GET_MODE (old))
  6290.              > GET_MODE_SIZE (GET_MODE (SUBREG_REG (old)))))
  6291.         old = SUBREG_REG (old);
  6292. #endif
  6293.  
  6294.       /* If is a JUMP_INSN, we can't support output reloads yet.  */
  6295.       if (GET_CODE (insn) == JUMP_INSN)
  6296.         abort ();
  6297.  
  6298.       if (reload_when_needed[j] == RELOAD_OTHER)
  6299.         start_sequence ();
  6300.       else
  6301.         push_to_sequence (output_reload_insns[reload_opnum[j]]);
  6302.  
  6303.       /* Determine the mode to reload in.
  6304.          See comments above (for input reloading).  */
  6305.  
  6306.       mode = GET_MODE (old);
  6307.       if (mode == VOIDmode)
  6308.         {
  6309.           /* VOIDmode should never happen for an output.  */
  6310.           if (asm_noperands (PATTERN (insn)) < 0)
  6311.         /* It's the compiler's fault.  */
  6312.         fatal_insn ("VOIDmode on an output", insn);
  6313.           error_for_asm (insn, "output operand is constant in `asm'");
  6314.           /* Prevent crash--use something we know is valid.  */
  6315.           mode = word_mode;
  6316.           old = gen_rtx (REG, mode, REGNO (reloadreg));
  6317.         }
  6318.  
  6319.       if (GET_MODE (reloadreg) != mode)
  6320.         reloadreg = gen_rtx (REG, mode, REGNO (reloadreg));
  6321.  
  6322. #ifdef SECONDARY_OUTPUT_RELOAD_CLASS
  6323.  
  6324.       /* If we need two reload regs, set RELOADREG to the intermediate
  6325.          one, since it will be stored into OLD.  We might need a secondary
  6326.          register only for an input reload, so check again here.  */
  6327.  
  6328.       if (reload_secondary_out_reload[j] >= 0)
  6329.         {
  6330.           rtx real_old = old;
  6331.  
  6332.           if (GET_CODE (old) == REG && REGNO (old) >= FIRST_PSEUDO_REGISTER
  6333.           && reg_equiv_mem[REGNO (old)] != 0)
  6334.         real_old = reg_equiv_mem[REGNO (old)];
  6335.  
  6336.           if((SECONDARY_OUTPUT_RELOAD_CLASS (reload_reg_class[j],
  6337.                          mode, real_old)
  6338.           != NO_REGS))
  6339.         {
  6340.           second_reloadreg = reloadreg;
  6341.           reloadreg = reload_reg_rtx[reload_secondary_out_reload[j]];
  6342.  
  6343.           /* See if RELOADREG is to be used as a scratch register
  6344.              or as an intermediate register.  */
  6345.           if (reload_secondary_out_icode[j] != CODE_FOR_nothing)
  6346.             {
  6347.               emit_insn ((GEN_FCN (reload_secondary_out_icode[j])
  6348.                   (real_old, second_reloadreg, reloadreg)));
  6349.               special = 1;
  6350.             }
  6351.           else
  6352.             {
  6353.               /* See if we need both a scratch and intermediate reload
  6354.              register.  */
  6355.  
  6356.               int secondary_reload = reload_secondary_out_reload[j];
  6357.               enum insn_code tertiary_icode
  6358.             = reload_secondary_out_icode[secondary_reload];
  6359.  
  6360.               if (GET_MODE (reloadreg) != mode)
  6361.             reloadreg = gen_rtx (REG, mode, REGNO (reloadreg));
  6362.  
  6363.               if (tertiary_icode != CODE_FOR_nothing)
  6364.             {
  6365.               rtx third_reloadreg
  6366.                 = reload_reg_rtx[reload_secondary_out_reload[secondary_reload]];
  6367.               rtx tem;
  6368.  
  6369.               /* Copy primary reload reg to secondary reload reg.
  6370.                  (Note that these have been swapped above, then
  6371.                  secondary reload reg to OLD using our insn.  */
  6372.  
  6373.               /* If REAL_OLD is a paradoxical SUBREG, remove it
  6374.                  and try to put the opposite SUBREG on
  6375.                  RELOADREG.  */
  6376.               if (GET_CODE (real_old) == SUBREG
  6377.                   && (GET_MODE_SIZE (GET_MODE (real_old))
  6378.                   > GET_MODE_SIZE (GET_MODE (SUBREG_REG (real_old))))
  6379.                   && 0 != (tem = gen_lowpart_common
  6380.                        (GET_MODE (SUBREG_REG (real_old)),
  6381.                     reloadreg)))
  6382.                 real_old = SUBREG_REG (real_old), reloadreg = tem;
  6383.  
  6384.               gen_reload (reloadreg, second_reloadreg,
  6385.                       reload_opnum[j], reload_when_needed[j]);
  6386.               emit_insn ((GEN_FCN (tertiary_icode)
  6387.                       (real_old, reloadreg, third_reloadreg)));
  6388.               special = 1;
  6389.             }
  6390.  
  6391.               else
  6392.             /* Copy between the reload regs here and then to
  6393.                OUT later.  */
  6394.  
  6395.             gen_reload (reloadreg, second_reloadreg,
  6396.                     reload_opnum[j], reload_when_needed[j]);
  6397.             }
  6398.         }
  6399.         }
  6400. #endif
  6401.  
  6402.       /* Output the last reload insn.  */
  6403.       if (! special)
  6404.         gen_reload (old, reloadreg, reload_opnum[j],
  6405.             reload_when_needed[j]);
  6406.  
  6407. #ifdef PRESERVE_DEATH_INFO_REGNO_P
  6408.       /* If final will look at death notes for this reg,
  6409.          put one on the last output-reload insn to use it.  Similarly
  6410.          for any secondary register.  */
  6411.       if (PRESERVE_DEATH_INFO_REGNO_P (REGNO (reloadreg)))
  6412.         for (p = get_last_insn (); p; p = PREV_INSN (p))
  6413.           if (GET_RTX_CLASS (GET_CODE (p)) == 'i'
  6414.           && reg_overlap_mentioned_for_reload_p (reloadreg,
  6415.                              PATTERN (p)))
  6416.         REG_NOTES (p) = gen_rtx (EXPR_LIST, REG_DEAD,
  6417.                      reloadreg, REG_NOTES (p));
  6418.  
  6419. #ifdef SECONDARY_OUTPUT_RELOAD_CLASS
  6420.       if (! special
  6421.           && PRESERVE_DEATH_INFO_REGNO_P (REGNO (second_reloadreg)))
  6422.         for (p = get_last_insn (); p; p = PREV_INSN (p))
  6423.           if (GET_RTX_CLASS (GET_CODE (p)) == 'i'
  6424.           && reg_overlap_mentioned_for_reload_p (second_reloadreg,
  6425.                              PATTERN (p)))
  6426.         REG_NOTES (p) = gen_rtx (EXPR_LIST, REG_DEAD,
  6427.                      second_reloadreg, REG_NOTES (p));
  6428. #endif
  6429. #endif
  6430.       /* Look at all insns we emitted, just to be safe.  */
  6431.       for (p = get_insns (); p; p = NEXT_INSN (p))
  6432.         if (GET_RTX_CLASS (GET_CODE (p)) == 'i')
  6433.           {
  6434.         /* If this output reload doesn't come from a spill reg,
  6435.            clear any memory of reloaded copies of the pseudo reg.
  6436.            If this output reload comes from a spill reg,
  6437.            reg_has_output_reload will make this do nothing.  */
  6438.         note_stores (PATTERN (p), forget_old_reloads_1);
  6439.  
  6440.         if (reg_mentioned_p (reload_reg_rtx[j], PATTERN (p))
  6441.             && reload_spill_index[j] >= 0)
  6442.           new_spill_reg_store[reload_spill_index[j]] = p;
  6443.           }
  6444.  
  6445.       if (reload_when_needed[j] == RELOAD_OTHER)
  6446.         {
  6447.           if (other_output_reload_insns)
  6448.         emit_insns (other_output_reload_insns);
  6449.           other_output_reload_insns = get_insns ();
  6450.         }
  6451.       else
  6452.         output_reload_insns[reload_opnum[j]] = get_insns ();
  6453.  
  6454.       end_sequence ();
  6455.     }
  6456.     }
  6457.  
  6458.   /* Now write all the insns we made for reloads in the order expected by
  6459.      the allocation functions.  Prior to the insn being reloaded, we write
  6460.      the following reloads:
  6461.  
  6462.      RELOAD_FOR_OTHER_ADDRESS reloads for input addresses.
  6463.  
  6464.      RELOAD_OTHER reloads, output in ascending order by reload number.
  6465.  
  6466.      For each operand, any RELOAD_FOR_INPUT_ADDRESS reloads followed by
  6467.      the RELOAD_FOR_INPUT reload for the operand.
  6468.  
  6469.      RELOAD_FOR_OPADDR_ADDRS reloads.
  6470.  
  6471.      RELOAD_FOR_OPERAND_ADDRESS reloads.
  6472.  
  6473.      After the insn being reloaded, we write the following:
  6474.  
  6475.      For each operand, any RELOAD_FOR_OUTPUT_ADDRESS reload followed by
  6476.      the RELOAD_FOR_OUTPUT reload for that operand.
  6477.  
  6478.      Any RELOAD_OTHER output reloads, output in descending order by
  6479.      reload number.  */
  6480.  
  6481.   emit_insns_before (other_input_address_reload_insns, before_insn);
  6482.   emit_insns_before (other_input_reload_insns, before_insn);
  6483.  
  6484.   for (j = 0; j < reload_n_operands; j++)
  6485.     {
  6486.       emit_insns_before (input_address_reload_insns[j], before_insn);
  6487.       emit_insns_before (input_reload_insns[j], before_insn);
  6488.     }
  6489.  
  6490.   emit_insns_before (other_operand_reload_insns, before_insn);
  6491.   emit_insns_before (operand_reload_insns, before_insn);
  6492.  
  6493.   for (j = 0; j < reload_n_operands; j++)
  6494.     {
  6495.       emit_insns_before (output_address_reload_insns[j], following_insn);
  6496.       emit_insns_before (output_reload_insns[j], following_insn);
  6497.     }
  6498.  
  6499.   emit_insns_before (other_output_reload_insns, following_insn);
  6500.  
  6501.   /* Move death notes from INSN
  6502.      to output-operand-address and output reload insns.  */
  6503. #ifdef PRESERVE_DEATH_INFO_REGNO_P
  6504.   {
  6505.     rtx insn1;
  6506.     /* Loop over those insns, last ones first.  */
  6507.     for (insn1 = PREV_INSN (following_insn); insn1 != insn;
  6508.      insn1 = PREV_INSN (insn1))
  6509.       if (GET_CODE (insn1) == INSN && GET_CODE (PATTERN (insn1)) == SET)
  6510.     {
  6511.       rtx source = SET_SRC (PATTERN (insn1));
  6512.       rtx dest = SET_DEST (PATTERN (insn1));
  6513.  
  6514.       /* The note we will examine next.  */
  6515.       rtx reg_notes = REG_NOTES (insn);
  6516.       /* The place that pointed to this note.  */
  6517.       rtx *prev_reg_note = ®_NOTES (insn);
  6518.  
  6519.       /* If the note is for something used in the source of this
  6520.          reload insn, or in the output address, move the note.  */
  6521.       while (reg_notes)
  6522.         {
  6523.           rtx next_reg_notes = XEXP (reg_notes, 1);
  6524.           if (REG_NOTE_KIND (reg_notes) == REG_DEAD
  6525.           && GET_CODE (XEXP (reg_notes, 0)) == REG
  6526.           && ((GET_CODE (dest) != REG
  6527.                && reg_overlap_mentioned_for_reload_p (XEXP (reg_notes, 0),
  6528.                                   dest))
  6529.               || reg_overlap_mentioned_for_reload_p (XEXP (reg_notes, 0),
  6530.                                  source)))
  6531.         {
  6532.           *prev_reg_note = next_reg_notes;
  6533.           XEXP (reg_notes, 1) = REG_NOTES (insn1);
  6534.           REG_NOTES (insn1) = reg_notes;
  6535.         }
  6536.           else
  6537.         prev_reg_note = &XEXP (reg_notes, 1);
  6538.  
  6539.           reg_notes = next_reg_notes;
  6540.         }
  6541.     }
  6542.   }
  6543. #endif
  6544.  
  6545.   /* For all the spill regs newly reloaded in this instruction,
  6546.      record what they were reloaded from, so subsequent instructions
  6547.      can inherit the reloads.
  6548.  
  6549.      Update spill_reg_store for the reloads of this insn.
  6550.      Copy the elements that were updated in the loop above.  */
  6551.  
  6552.   for (j = 0; j < n_reloads; j++)
  6553.     {
  6554.       register int r = reload_order[j];
  6555.       register int i = reload_spill_index[r];
  6556.  
  6557.       /* I is nonneg if this reload used one of the spill regs.
  6558.      If reload_reg_rtx[r] is 0, this is an optional reload
  6559.      that we opted to ignore.
  6560.  
  6561.      Also ignore reloads that don't reach the end of the insn,
  6562.      since we will eventually see the one that does.  */
  6563.  
  6564.       if (i >= 0 && reload_reg_rtx[r] != 0
  6565.       && reload_reg_reaches_end_p (spill_regs[i], reload_opnum[r],
  6566.                        reload_when_needed[r]))
  6567.     {
  6568.       /* First, clear out memory of what used to be in this spill reg.
  6569.          If consecutive registers are used, clear them all.  */
  6570.       int nr
  6571.         = HARD_REGNO_NREGS (spill_regs[i], GET_MODE (reload_reg_rtx[r]));
  6572.       int k;
  6573.  
  6574.       for (k = 0; k < nr; k++)
  6575.         {
  6576.           reg_reloaded_contents[spill_reg_order[spill_regs[i] + k]] = -1;
  6577.           reg_reloaded_insn[spill_reg_order[spill_regs[i] + k]] = 0;
  6578.         }
  6579.  
  6580.       /* Maybe the spill reg contains a copy of reload_out.  */
  6581.       if (reload_out[r] != 0 && GET_CODE (reload_out[r]) == REG)
  6582.         {
  6583.           register int nregno = REGNO (reload_out[r]);
  6584.           int nnr = (nregno >= FIRST_PSEUDO_REGISTER ? 1
  6585.              : HARD_REGNO_NREGS (nregno,
  6586.                          GET_MODE (reload_reg_rtx[r])));
  6587.  
  6588.           spill_reg_store[i] = new_spill_reg_store[i];
  6589.           reg_last_reload_reg[nregno] = reload_reg_rtx[r];
  6590.  
  6591.           /* If NREGNO is a hard register, it may occupy more than
  6592.          one register.  If it does, say what is in the 
  6593.          rest of the registers assuming that both registers
  6594.          agree on how many words the object takes.  If not,
  6595.          invalidate the subsequent registers.  */
  6596.  
  6597.           if (nregno < FIRST_PSEUDO_REGISTER)
  6598.         for (k = 1; k < nnr; k++)
  6599.           reg_last_reload_reg[nregno + k]
  6600.             = (nr == nnr ? gen_rtx (REG,
  6601.                         reg_raw_mode[REGNO (reload_reg_rtx[r]) + k],
  6602.                         REGNO (reload_reg_rtx[r]) + k)
  6603.                : 0);
  6604.  
  6605.           /* Now do the inverse operation.  */
  6606.           for (k = 0; k < nr; k++)
  6607.         {
  6608.           reg_reloaded_contents[spill_reg_order[spill_regs[i] + k]]
  6609.             = (nregno >= FIRST_PSEUDO_REGISTER || nr != nnr ? nregno
  6610.                : nregno + k);
  6611.           reg_reloaded_insn[spill_reg_order[spill_regs[i] + k]] = insn;
  6612.         }
  6613.         }
  6614.  
  6615.       /* Maybe the spill reg contains a copy of reload_in.  Only do
  6616.          something if there will not be an output reload for
  6617.          the register being reloaded.  */
  6618.       else if (reload_out[r] == 0
  6619.            && reload_in[r] != 0
  6620.            && ((GET_CODE (reload_in[r]) == REG
  6621.             && ! reg_has_output_reload[REGNO (reload_in[r])]
  6622.                || (GET_CODE (reload_in_reg[r]) == REG
  6623.                && ! reg_has_output_reload[REGNO (reload_in_reg[r])]))))
  6624.         {
  6625.           register int nregno;
  6626.           int nnr;
  6627.  
  6628.           if (GET_CODE (reload_in[r]) == REG)
  6629.         nregno = REGNO (reload_in[r]);
  6630.           else
  6631.         nregno = REGNO (reload_in_reg[r]);
  6632.  
  6633.           nnr = (nregno >= FIRST_PSEUDO_REGISTER ? 1
  6634.              : HARD_REGNO_NREGS (nregno,
  6635.                      GET_MODE (reload_reg_rtx[r])));
  6636.  
  6637.           reg_last_reload_reg[nregno] = reload_reg_rtx[r];
  6638.  
  6639.           if (nregno < FIRST_PSEUDO_REGISTER)
  6640.         for (k = 1; k < nnr; k++)
  6641.           reg_last_reload_reg[nregno + k]
  6642.             = (nr == nnr ? gen_rtx (REG,
  6643.                         reg_raw_mode[REGNO (reload_reg_rtx[r]) + k],
  6644.                         REGNO (reload_reg_rtx[r]) + k)
  6645.                : 0);
  6646.  
  6647.           /* Unless we inherited this reload, show we haven't
  6648.          recently done a store.  */
  6649.           if (! reload_inherited[r])
  6650.         spill_reg_store[i] = 0;
  6651.  
  6652.           for (k = 0; k < nr; k++)
  6653.         {
  6654.           reg_reloaded_contents[spill_reg_order[spill_regs[i] + k]]
  6655.             = (nregno >= FIRST_PSEUDO_REGISTER || nr != nnr ? nregno
  6656.                : nregno + k);
  6657.           reg_reloaded_insn[spill_reg_order[spill_regs[i] + k]]
  6658.             = insn;
  6659.         }
  6660.         }
  6661.     }
  6662.  
  6663.       /* The following if-statement was #if 0'd in 1.34 (or before...).
  6664.      It's reenabled in 1.35 because supposedly nothing else
  6665.      deals with this problem.  */
  6666.  
  6667.       /* If a register gets output-reloaded from a non-spill register,
  6668.      that invalidates any previous reloaded copy of it.
  6669.      But forget_old_reloads_1 won't get to see it, because
  6670.      it thinks only about the original insn.  So invalidate it here.  */
  6671.       if (i < 0 && reload_out[r] != 0 && GET_CODE (reload_out[r]) == REG)
  6672.     {
  6673.       register int nregno = REGNO (reload_out[r]);
  6674.       if (nregno >= FIRST_PSEUDO_REGISTER)
  6675.         reg_last_reload_reg[nregno] = 0;
  6676.       else
  6677.         {
  6678.           int num_regs = HARD_REGNO_NREGS (nregno,GET_MODE (reload_out[r]));
  6679.  
  6680.           while (num_regs-- > 0)
  6681.         reg_last_reload_reg[nregno + num_regs] = 0;
  6682.         }
  6683.     }
  6684.     }
  6685. }
  6686.  
  6687. /* Emit code to perform a reload from IN (which may be a reload register) to
  6688.    OUT (which may also be a reload register).  IN or OUT is from operand
  6689.    OPNUM with reload type TYPE. 
  6690.  
  6691.    Returns first insn emitted.  */
  6692.  
  6693. rtx
  6694. gen_reload (out, in, opnum, type)
  6695.      rtx out;
  6696.      rtx in;
  6697.      int opnum;
  6698.      enum reload_type type;
  6699. {
  6700.   rtx last = get_last_insn ();
  6701.   rtx tem;
  6702.  
  6703.   /* If IN is a paradoxical SUBREG, remove it and try to put the
  6704.      opposite SUBREG on OUT.  Likewise for a paradoxical SUBREG on OUT.  */
  6705.   if (GET_CODE (in) == SUBREG
  6706.       && (GET_MODE_SIZE (GET_MODE (in))
  6707.       > GET_MODE_SIZE (GET_MODE (SUBREG_REG (in))))
  6708.       && (tem = gen_lowpart_common (GET_MODE (SUBREG_REG (in)), out)) != 0)
  6709.     in = SUBREG_REG (in), out = tem;
  6710.   else if (GET_CODE (out) == SUBREG
  6711.       && (GET_MODE_SIZE (GET_MODE (out))
  6712.       > GET_MODE_SIZE (GET_MODE (SUBREG_REG (out))))
  6713.       && (tem = gen_lowpart_common (GET_MODE (SUBREG_REG (out)), in)) != 0)
  6714.     out = SUBREG_REG (out), in = tem;
  6715.  
  6716.   /* How to do this reload can get quite tricky.  Normally, we are being
  6717.      asked to reload a simple operand, such as a MEM, a constant, or a pseudo
  6718.      register that didn't get a hard register.  In that case we can just
  6719.      call emit_move_insn.
  6720.  
  6721.      We can also be asked to reload a PLUS that adds a register or a MEM to
  6722.      another register, constant or MEM.  This can occur during frame pointer
  6723.      elimination and while reloading addresses.  This case is handled by
  6724.      trying to emit a single insn to perform the add.  If it is not valid,
  6725.      we use a two insn sequence.
  6726.  
  6727.      Finally, we could be called to handle an 'o' constraint by putting
  6728.      an address into a register.  In that case, we first try to do this
  6729.      with a named pattern of "reload_load_address".  If no such pattern
  6730.      exists, we just emit a SET insn and hope for the best (it will normally
  6731.      be valid on machines that use 'o').
  6732.  
  6733.      This entire process is made complex because reload will never
  6734.      process the insns we generate here and so we must ensure that
  6735.      they will fit their constraints and also by the fact that parts of
  6736.      IN might be being reloaded separately and replaced with spill registers.
  6737.      Because of this, we are, in some sense, just guessing the right approach
  6738.      here.  The one listed above seems to work.
  6739.  
  6740.      ??? At some point, this whole thing needs to be rethought.  */
  6741.  
  6742.   if (GET_CODE (in) == PLUS
  6743.       && (GET_CODE (XEXP (in, 0)) == REG
  6744.       || GET_CODE (XEXP (in, 0)) == MEM)
  6745.       && (GET_CODE (XEXP (in, 1)) == REG
  6746.       || CONSTANT_P (XEXP (in, 1))
  6747.       || GET_CODE (XEXP (in, 1)) == MEM))
  6748.     {
  6749.       /* We need to compute the sum of a register or a MEM and another
  6750.      register, constant, or MEM, and put it into the reload
  6751.      register.  The best possible way of doing this is if the machine
  6752.      has a three-operand ADD insn that accepts the required operands.
  6753.  
  6754.      The simplest approach is to try to generate such an insn and see if it
  6755.      is recognized and matches its constraints.  If so, it can be used.
  6756.  
  6757.      It might be better not to actually emit the insn unless it is valid,
  6758.      but we need to pass the insn as an operand to `recog' and
  6759.      `insn_extract' and it is simpler to emit and then delete the insn if
  6760.      not valid than to dummy things up.  */
  6761.  
  6762.       rtx op0, op1, tem, insn;
  6763.       int code;
  6764.  
  6765.       op0 = find_replacement (&XEXP (in, 0));
  6766.       op1 = find_replacement (&XEXP (in, 1));
  6767.  
  6768.       /* Since constraint checking is strict, commutativity won't be
  6769.      checked, so we need to do that here to avoid spurious failure
  6770.      if the add instruction is two-address and the second operand
  6771.      of the add is the same as the reload reg, which is frequently
  6772.      the case.  If the insn would be A = B + A, rearrange it so
  6773.      it will be A = A + B as constrain_operands expects. */
  6774.  
  6775.       if (GET_CODE (XEXP (in, 1)) == REG
  6776.       && REGNO (out) == REGNO (XEXP (in, 1)))
  6777.     tem = op0, op0 = op1, op1 = tem;
  6778.  
  6779.       if (op0 != XEXP (in, 0) || op1 != XEXP (in, 1))
  6780.     in = gen_rtx (PLUS, GET_MODE (in), op0, op1);
  6781.  
  6782.       insn = emit_insn (gen_rtx (SET, VOIDmode, out, in));
  6783.       code = recog_memoized (insn);
  6784.  
  6785.       if (code >= 0)
  6786.     {
  6787.       insn_extract (insn);
  6788.       /* We want constrain operands to treat this insn strictly in
  6789.          its validity determination, i.e., the way it would after reload
  6790.          has completed.  */
  6791.       if (constrain_operands (code, 1))
  6792.         return insn;
  6793.     }
  6794.  
  6795.       delete_insns_since (last);
  6796.  
  6797.       /* If that failed, we must use a conservative two-insn sequence.
  6798.      use move to copy constant, MEM, or pseudo register to the reload
  6799.      register since "move" will be able to handle an arbitrary operand,
  6800.      unlike add which can't, in general.  Then add the registers.
  6801.  
  6802.      If there is another way to do this for a specific machine, a
  6803.      DEFINE_PEEPHOLE should be specified that recognizes the sequence
  6804.      we emit below.  */
  6805.  
  6806.       if (CONSTANT_P (op1) || GET_CODE (op1) == MEM
  6807.       || (GET_CODE (op1) == REG
  6808.           && REGNO (op1) >= FIRST_PSEUDO_REGISTER))
  6809.     tem = op0, op0 = op1, op1 = tem;
  6810.  
  6811.       emit_insn (gen_move_insn (out, op0));
  6812.  
  6813.       /* If OP0 and OP1 are the same, we can use OUT for OP1.
  6814.      This fixes a problem on the 32K where the stack pointer cannot
  6815.      be used as an operand of an add insn.  */
  6816.  
  6817.       if (rtx_equal_p (op0, op1))
  6818.     op1 = out;
  6819.  
  6820.       insn = emit_insn (gen_add2_insn (out, op1));
  6821.  
  6822.       /* If that failed, copy the address register to the reload register.
  6823.      Then add the constant to the reload register. */
  6824.  
  6825.       code = recog_memoized (insn);
  6826.  
  6827.       if (code >= 0)
  6828.     {
  6829.       insn_extract (insn);
  6830.       /* We want constrain operands to treat this insn strictly in
  6831.          its validity determination, i.e., the way it would after reload
  6832.          has completed.  */
  6833.       if (constrain_operands (code, 1))
  6834.         return insn;
  6835.     }
  6836.  
  6837.       delete_insns_since (last);
  6838.  
  6839.       emit_insn (gen_move_insn (out, op1));
  6840.       emit_insn (gen_add2_insn (out, op0));
  6841.     }
  6842.  
  6843. #ifdef SECONDARY_MEMORY_NEEDED
  6844.   /* If we need a memory location to do the move, do it that way.  */
  6845.   else if (GET_CODE (in) == REG && REGNO (in) < FIRST_PSEUDO_REGISTER
  6846.        && GET_CODE (out) == REG && REGNO (out) < FIRST_PSEUDO_REGISTER
  6847.        && SECONDARY_MEMORY_NEEDED (REGNO_REG_CLASS (REGNO (in)),
  6848.                        REGNO_REG_CLASS (REGNO (out)),
  6849.                        GET_MODE (out)))
  6850.     {
  6851.       /* Get the memory to use and rewrite both registers to its mode.  */
  6852.       rtx loc = get_secondary_mem (in, GET_MODE (out), opnum, type);
  6853.  
  6854.       if (GET_MODE (loc) != GET_MODE (out))
  6855.     out = gen_rtx (REG, GET_MODE (loc), REGNO (out));
  6856.  
  6857.       if (GET_MODE (loc) != GET_MODE (in))
  6858.     in = gen_rtx (REG, GET_MODE (loc), REGNO (in));
  6859.  
  6860.       emit_insn (gen_move_insn (loc, in));
  6861.       emit_insn (gen_move_insn (out, loc));
  6862.     }
  6863. #endif
  6864.  
  6865.   /* If IN is a simple operand, use gen_move_insn.  */
  6866.   else if (GET_RTX_CLASS (GET_CODE (in)) == 'o' || GET_CODE (in) == SUBREG)
  6867.     emit_insn (gen_move_insn (out, in));
  6868.  
  6869. #ifdef HAVE_reload_load_address
  6870.   else if (HAVE_reload_load_address)
  6871.     emit_insn (gen_reload_load_address (out, in));
  6872. #endif
  6873.  
  6874.   /* Otherwise, just write (set OUT IN) and hope for the best.  */
  6875.   else
  6876.     emit_insn (gen_rtx (SET, VOIDmode, out, in));
  6877.  
  6878.   /* Return the first insn emitted.
  6879.      We can not just return get_last_insn, because there may have
  6880.      been multiple instructions emitted.  Also note that gen_move_insn may
  6881.      emit more than one insn itself, so we can not assume that there is one
  6882.      insn emitted per emit_insn_before call.  */
  6883.  
  6884.   return last ? NEXT_INSN (last) : get_insns ();
  6885. }
  6886.  
  6887. /* Delete a previously made output-reload
  6888.    whose result we now believe is not needed.
  6889.    First we double-check.
  6890.  
  6891.    INSN is the insn now being processed.
  6892.    OUTPUT_RELOAD_INSN is the insn of the output reload.
  6893.    J is the reload-number for this insn.  */
  6894.  
  6895. static void
  6896. delete_output_reload (insn, j, output_reload_insn)
  6897.      rtx insn;
  6898.      int j;
  6899.      rtx output_reload_insn;
  6900. {
  6901.   register rtx i1;
  6902.  
  6903.   /* Get the raw pseudo-register referred to.  */
  6904.  
  6905.   rtx reg = reload_in[j];
  6906.   while (GET_CODE (reg) == SUBREG)
  6907.     reg = SUBREG_REG (reg);
  6908.  
  6909.   /* If the pseudo-reg we are reloading is no longer referenced
  6910.      anywhere between the store into it and here,
  6911.      and no jumps or labels intervene, then the value can get
  6912.      here through the reload reg alone.
  6913.      Otherwise, give up--return.  */
  6914.   for (i1 = NEXT_INSN (output_reload_insn);
  6915.        i1 != insn; i1 = NEXT_INSN (i1))
  6916.     {
  6917.       if (GET_CODE (i1) == CODE_LABEL || GET_CODE (i1) == JUMP_INSN)
  6918.     return;
  6919.       if ((GET_CODE (i1) == INSN || GET_CODE (i1) == CALL_INSN)
  6920.       && reg_mentioned_p (reg, PATTERN (i1)))
  6921.     return;
  6922.     }
  6923.  
  6924.   if (cannot_omit_stores[REGNO (reg)])
  6925.     return;
  6926.  
  6927.   /* If this insn will store in the pseudo again,
  6928.      the previous store can be removed.  */
  6929.   if (reload_out[j] == reload_in[j])
  6930.     delete_insn (output_reload_insn);
  6931.  
  6932.   /* See if the pseudo reg has been completely replaced
  6933.      with reload regs.  If so, delete the store insn
  6934.      and forget we had a stack slot for the pseudo.  */
  6935.   else if (reg_n_deaths[REGNO (reg)] == 1
  6936.        && reg_basic_block[REGNO (reg)] >= 0
  6937.        && find_regno_note (insn, REG_DEAD, REGNO (reg)))
  6938.     {
  6939.       rtx i2;
  6940.  
  6941.       /* We know that it was used only between here
  6942.      and the beginning of the current basic block.
  6943.      (We also know that the last use before INSN was
  6944.      the output reload we are thinking of deleting, but never mind that.)
  6945.      Search that range; see if any ref remains.  */
  6946.       for (i2 = PREV_INSN (insn); i2; i2 = PREV_INSN (i2))
  6947.     {
  6948.       rtx set = single_set (i2);
  6949.  
  6950.       /* Uses which just store in the pseudo don't count,
  6951.          since if they are the only uses, they are dead.  */
  6952.       if (set != 0 && SET_DEST (set) == reg)
  6953.         continue;
  6954.       if (GET_CODE (i2) == CODE_LABEL
  6955.           || GET_CODE (i2) == JUMP_INSN)
  6956.         break;
  6957.       if ((GET_CODE (i2) == INSN || GET_CODE (i2) == CALL_INSN)
  6958.           && reg_mentioned_p (reg, PATTERN (i2)))
  6959.         /* Some other ref remains;
  6960.            we can't do anything.  */
  6961.         return;
  6962.     }
  6963.  
  6964.       /* Delete the now-dead stores into this pseudo.  */
  6965.       for (i2 = PREV_INSN (insn); i2; i2 = PREV_INSN (i2))
  6966.     {
  6967.       rtx set = single_set (i2);
  6968.  
  6969.       if (set != 0 && SET_DEST (set) == reg)
  6970.         delete_insn (i2);
  6971.       if (GET_CODE (i2) == CODE_LABEL
  6972.           || GET_CODE (i2) == JUMP_INSN)
  6973.         break;
  6974.     }
  6975.  
  6976.       /* For the debugging info,
  6977.      say the pseudo lives in this reload reg.  */
  6978.       reg_renumber[REGNO (reg)] = REGNO (reload_reg_rtx[j]);
  6979.       alter_reg (REGNO (reg), -1);
  6980.     }
  6981. }
  6982.  
  6983. /* Output reload-insns to reload VALUE into RELOADREG.
  6984.    VALUE is an autoincrement or autodecrement RTX whose operand
  6985.    is a register or memory location;
  6986.    so reloading involves incrementing that location.
  6987.  
  6988.    INC_AMOUNT is the number to increment or decrement by (always positive).
  6989.    This cannot be deduced from VALUE.  */
  6990.  
  6991. static void
  6992. inc_for_reload (reloadreg, value, inc_amount)
  6993.      rtx reloadreg;
  6994.      rtx value;
  6995.      int inc_amount;
  6996. {
  6997.   /* REG or MEM to be copied and incremented.  */
  6998.   rtx incloc = XEXP (value, 0);
  6999.   /* Nonzero if increment after copying.  */
  7000.   int post = (GET_CODE (value) == POST_DEC || GET_CODE (value) == POST_INC);
  7001.   rtx last;
  7002.   rtx inc;
  7003.   rtx add_insn;
  7004.   int code;
  7005.  
  7006.   /* No hard register is equivalent to this register after
  7007.      inc/dec operation.  If REG_LAST_RELOAD_REG were non-zero,
  7008.      we could inc/dec that register as well (maybe even using it for
  7009.      the source), but I'm not sure it's worth worrying about.  */
  7010.   if (GET_CODE (incloc) == REG)
  7011.     reg_last_reload_reg[REGNO (incloc)] = 0;
  7012.  
  7013.   if (GET_CODE (value) == PRE_DEC || GET_CODE (value) == POST_DEC)
  7014.     inc_amount = - inc_amount;
  7015.  
  7016.   inc = GEN_INT (inc_amount);
  7017.  
  7018.   /* If this is post-increment, first copy the location to the reload reg.  */
  7019.   if (post)
  7020.     emit_insn (gen_move_insn (reloadreg, incloc));
  7021.  
  7022.   /* See if we can directly increment INCLOC.  Use a method similar to that
  7023.      in gen_reload.  */
  7024.  
  7025.   last = get_last_insn ();
  7026.   add_insn = emit_insn (gen_rtx (SET, VOIDmode, incloc,
  7027.                  gen_rtx (PLUS, GET_MODE (incloc),
  7028.                       incloc, inc)));
  7029.                               
  7030.   code = recog_memoized (add_insn);
  7031.   if (code >= 0)
  7032.     {
  7033.       insn_extract (add_insn);
  7034.       if (constrain_operands (code, 1))
  7035.     {
  7036.       /* If this is a pre-increment and we have incremented the value
  7037.          where it lives, copy the incremented value to RELOADREG to
  7038.          be used as an address.  */
  7039.  
  7040.       if (! post)
  7041.         emit_insn (gen_move_insn (reloadreg, incloc));
  7042.  
  7043.       return;
  7044.     }
  7045.     }
  7046.  
  7047.   delete_insns_since (last);
  7048.  
  7049.   /* If couldn't do the increment directly, must increment in RELOADREG.
  7050.      The way we do this depends on whether this is pre- or post-increment.
  7051.      For pre-increment, copy INCLOC to the reload register, increment it
  7052.      there, then save back.  */
  7053.  
  7054.   if (! post)
  7055.     {
  7056.       emit_insn (gen_move_insn (reloadreg, incloc));
  7057.       emit_insn (gen_add2_insn (reloadreg, inc));
  7058.       emit_insn (gen_move_insn (incloc, reloadreg));
  7059.     }
  7060.   else
  7061.     {
  7062.       /* Postincrement.
  7063.      Because this might be a jump insn or a compare, and because RELOADREG
  7064.      may not be available after the insn in an input reload, we must do
  7065.      the incrementation before the insn being reloaded for.
  7066.  
  7067.      We have already copied INCLOC to RELOADREG.  Increment the copy in
  7068.      RELOADREG, save that back, then decrement RELOADREG so it has
  7069.      the original value.  */
  7070.  
  7071.       emit_insn (gen_add2_insn (reloadreg, inc));
  7072.       emit_insn (gen_move_insn (incloc, reloadreg));
  7073.       emit_insn (gen_add2_insn (reloadreg, GEN_INT (-inc_amount)));
  7074.     }
  7075.  
  7076.   return;
  7077. }
  7078.  
  7079. /* Return 1 if we are certain that the constraint-string STRING allows
  7080.    the hard register REG.  Return 0 if we can't be sure of this.  */
  7081.  
  7082. static int
  7083. constraint_accepts_reg_p (string, reg)
  7084.      char *string;
  7085.      rtx reg;
  7086. {
  7087.   int value = 0;
  7088.   int regno = true_regnum (reg);
  7089.   int c;
  7090.  
  7091.   /* Initialize for first alternative.  */
  7092.   value = 0;
  7093.   /* Check that each alternative contains `g' or `r'.  */
  7094.   while (1)
  7095.     switch (c = *string++)
  7096.       {
  7097.       case 0:
  7098.     /* If an alternative lacks `g' or `r', we lose.  */
  7099.     return value;
  7100.       case ',':
  7101.     /* If an alternative lacks `g' or `r', we lose.  */
  7102.     if (value == 0)
  7103.       return 0;
  7104.     /* Initialize for next alternative.  */
  7105.     value = 0;
  7106.     break;
  7107.       case 'g':
  7108.       case 'r':
  7109.     /* Any general reg wins for this alternative.  */
  7110.     if (TEST_HARD_REG_BIT (reg_class_contents[(int) GENERAL_REGS], regno))
  7111.       value = 1;
  7112.     break;
  7113.       default:
  7114.     /* Any reg in specified class wins for this alternative.  */
  7115.     {
  7116.       enum reg_class class = REG_CLASS_FROM_LETTER (c);
  7117.  
  7118.       if (TEST_HARD_REG_BIT (reg_class_contents[(int) class], regno))
  7119.         value = 1;
  7120.     }
  7121.       }
  7122. }
  7123.  
  7124. /* Return the number of places FIND appears within X, but don't count
  7125.    an occurrence if some SET_DEST is FIND.  */
  7126.  
  7127. static int
  7128. count_occurrences (x, find)
  7129.      register rtx x, find;
  7130. {
  7131.   register int i, j;
  7132.   register enum rtx_code code;
  7133.   register char *format_ptr;
  7134.   int count;
  7135.  
  7136.   if (x == find)
  7137.     return 1;
  7138.   if (x == 0)
  7139.     return 0;
  7140.  
  7141.   code = GET_CODE (x);
  7142.  
  7143.   switch (code)
  7144.     {
  7145.     case REG:
  7146.     case QUEUED:
  7147.     case CONST_INT:
  7148.     case CONST_DOUBLE:
  7149.     case SYMBOL_REF:
  7150.     case CODE_LABEL:
  7151.     case PC:
  7152.     case CC0:
  7153.       return 0;
  7154.  
  7155.     case SET:
  7156.       if (SET_DEST (x) == find)
  7157.     return count_occurrences (SET_SRC (x), find);
  7158.       break;
  7159.     }
  7160.  
  7161.   format_ptr = GET_RTX_FORMAT (code);
  7162.   count = 0;
  7163.  
  7164.   for (i = 0; i < GET_RTX_LENGTH (code); i++)
  7165.     {
  7166.       switch (*format_ptr++)
  7167.     {
  7168.     case 'e':
  7169.       count += count_occurrences (XEXP (x, i), find);
  7170.       break;
  7171.  
  7172.     case 'E':
  7173.       if (XVEC (x, i) != NULL)
  7174.         {
  7175.           for (j = 0; j < XVECLEN (x, i); j++)
  7176.         count += count_occurrences (XVECEXP (x, i, j), find);
  7177.         }
  7178.       break;
  7179.     }
  7180.     }
  7181.   return count;
  7182. }
  7183.