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

  1. /* Reload pseudo regs into hard regs for insns that require hard regs.
  2.    Copyright (C) 1987, 1988, 1989 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 1, or (at your option)
  9. any later version.
  10.  
  11. GNU CC is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with GNU CC; see the file COPYING.  If not, write to
  18. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20.  
  21. #include "config.h"
  22. #include "rtl.h"
  23. #include "insn-config.h"
  24. #include "flags.h"
  25. #include "regs.h"
  26. #include "hard-reg-set.h"
  27. #include "reload.h"
  28. #include "recog.h"
  29. #include "basic-block.h"
  30. #include <stdio.h>
  31.  
  32. #ifdef MPW
  33. #include <CursorCtl.h>
  34. #endif
  35.  
  36. #define min(A,B) ((A) < (B) ? (A) : (B))
  37. #define max(A,B) ((A) > (B) ? (A) : (B))
  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. /* During reload_as_needed, element N contains a REG rtx for the hard reg
  73.    into which pseudo reg N has been reloaded (perhaps for a previous insn). */
  74. static rtx *reg_last_reload_reg;
  75.  
  76. /* Elt N nonzero if reg_last_reload_reg[N] has been set in this insn
  77.    for an output reload that stores into reg N.  */
  78. static char *reg_has_output_reload;
  79.  
  80. /* Elt N nonzero if hard reg N is a reload-register for an output reload
  81.    in the current insn.  */
  82. static char reg_is_output_reload[FIRST_PSEUDO_REGISTER];
  83.  
  84. /* Element N is the constant value to which pseudo reg N is equivalent,
  85.    or zero if pseudo reg N is not equivalent to a constant.
  86.    find_reloads looks at this in order to replace pseudo reg N
  87.    with the constant it stands for.  */
  88. rtx *reg_equiv_constant;
  89.  
  90. /* Element N is the address of stack slot to which pseudo reg N is equivalent.
  91.    This is used when the address is not valid as a memory address
  92.    (because its displacement is too big for the machine.)  */
  93. rtx *reg_equiv_address;
  94.  
  95. /* Element N is the memory slot to which pseudo reg N is equivalent,
  96.    or zero if pseudo reg N is not equivalent to a memory slot.  */
  97. rtx *reg_equiv_mem;
  98.  
  99. /* Widest width in which each pseudo reg is referred to (via subreg).  */
  100. static int *reg_max_ref_width;
  101.  
  102. /* Element N is the insn that initialized reg N from its equivalent
  103.    constant or memory slot.  */
  104. static rtx *reg_equiv_init;
  105.  
  106. /* During reload_as_needed, element N contains the last pseudo regno
  107.    reloaded into the Nth reload register.  This vector is in parallel
  108.    with spill_regs.  */
  109. static int reg_reloaded_contents[FIRST_PSEUDO_REGISTER];
  110.  
  111. /* Number of spill-regs so far; number of valid elements of spill_regs.  */
  112. static int n_spills;
  113.  
  114. /* In parallel with spill_regs, contains REG rtx's for those regs.
  115.    Holds the last rtx used for any given reg, or 0 if it has never
  116.    been used for spilling yet.  This rtx is reused, provided it has
  117.    the proper mode.  */
  118. static rtx spill_reg_rtx[FIRST_PSEUDO_REGISTER];
  119.  
  120. /* In parallel with spill_regs, contains nonzero for a spill reg
  121.    that was stored after the last time it was used.
  122.    The precise value is the insn generated to do the store.  */
  123. static rtx spill_reg_store[FIRST_PSEUDO_REGISTER];
  124.  
  125. /* This table is the inverse mapping of spill_regs:
  126.    indexed by hard reg number,
  127.    it contains the position of that reg in spill_regs,
  128.    or -1 for something that is not in spill_regs.  */
  129. static short spill_reg_order[FIRST_PSEUDO_REGISTER];
  130.  
  131. /* This table contains 1 for a register that may not be used
  132.    for retrying global allocation, or -1 for a register that may be used.
  133.    The registers that may not be used include all spill registers
  134.    and the frame pointer (if we are using one).  */
  135. static short forbidden_regs[FIRST_PSEUDO_REGISTER];
  136.  
  137. /* Describes order of use of registers for reloading
  138.    of spilled pseudo-registers.  `spills' is the number of
  139.    elements that are actually valid; new ones are added at the end.  */
  140. static char spill_regs[FIRST_PSEUDO_REGISTER];
  141.  
  142. /* Describes order of preference for putting regs into spill_regs.
  143.    Contains the numbers of all the hard regs, in order most preferred first.
  144.    This order is different for each function.
  145.    It is set up by order_regs_for_reload.
  146.    Empty elements at the end contain -1.  */
  147. static short potential_reload_regs[FIRST_PSEUDO_REGISTER];
  148.  
  149. /* 1 for a hard register that appears explicitly in the rtl
  150.    (for example, function value registers, special registers
  151.    used by insns, structure value pointer registers).  */
  152. static char regs_explicitly_used[FIRST_PSEUDO_REGISTER];
  153.  
  154. /* For each register, 1 if it was counted against the need for
  155.    groups.  0 means it can count against max_nongroup instead.  */
  156. static char counted_for_groups[FIRST_PSEUDO_REGISTER];
  157.  
  158. /* For each register, 1 if it was counted against the need for
  159.    non-groups.  0 means it can become part of a new group.
  160.    During choose_reload_regs, 1 here means don't use this reg
  161.    as part of a group, even if it seems to be otherwise ok.  */
  162. static char counted_for_nongroups[FIRST_PSEUDO_REGISTER];
  163.  
  164. /* Nonzero if spilling (REG n) does not require reloading it into
  165.    a register in order to do (MEM (REG n)).  */
  166.  
  167. static char spill_indirect_ok;
  168.  
  169. /* Nonzero if an address (plus (reg frame_pointer) (reg ...)) is valid.  */
  170.  
  171. char double_reg_address_ok;
  172.  
  173. /* Record the stack slot for each spilled hard register.  */
  174.  
  175. static rtx spill_stack_slot[FIRST_PSEUDO_REGISTER];
  176.  
  177. /* Width allocated so far for that stack slot.  */
  178.  
  179. static int spill_stack_slot_width[FIRST_PSEUDO_REGISTER];
  180.  
  181. /* Indexed by basic block number, nonzero if there is any need
  182.    for a spill register in that basic block.
  183.    The pointer is 0 if we did stupid allocation and don't know
  184.    the structure of basic blocks.  */
  185.  
  186. char *basic_block_needs;
  187.  
  188. /* First uid used by insns created by reload in this function.
  189.    Used in find_equiv_reg.  */
  190. int reload_first_uid;
  191.  
  192. /* Flag set by local-alloc or global-alloc if anything is live in
  193.    a call-clobbered reg across calls.  */
  194.  
  195. int caller_save_needed;
  196.  
  197. /* Set to 1 by alter_frame_pointer_addresses if it changes anything.  */
  198.  
  199. static int frame_pointer_address_altered;
  200.  
  201. void mark_home_live ();
  202. static rtx scan_paradoxical_subregs ();
  203. static void reload_as_needed ();
  204. static int modes_equiv_for_class_p ();
  205. static rtx alter_frame_pointer_addresses ();
  206. static void alter_reg ();
  207. static int new_spill_reg();
  208. static int spill_hard_reg ();
  209. static void choose_reload_regs ();
  210. static void emit_reload_insns ();
  211. static void delete_output_reload ();
  212. static void forget_old_reloads_1 ();
  213. static void order_regs_for_reload ();
  214. static void eliminate_frame_pointer ();
  215. static rtx inc_for_reload ();
  216. static int constraint_accepts_reg_p ();
  217. static int count_occurrences ();
  218. static rtx gen_input_reload ();
  219.  
  220. extern void remove_death ();
  221. extern rtx adj_offsettable_operand ();
  222.  
  223. /* Main entry point for the reload pass, and only entry point
  224.    in this file.
  225.  
  226.    FIRST is the first insn of the function being compiled.
  227.  
  228.    GLOBAL nonzero means we were called from global_alloc
  229.    and should attempt to reallocate any pseudoregs that we
  230.    displace from hard regs we will use for reloads.
  231.    If GLOBAL is zero, we do not have enough information to do that,
  232.    so any pseudo reg that is spilled must go to the stack.
  233.  
  234.    DUMPFILE is the global-reg debugging dump file stream, or 0.
  235.    If it is nonzero, messages are written to it to describe
  236.    which registers are seized as reload regs, which pseudo regs
  237.    are spilled from them, and where the pseudo regs are reallocated to.  */
  238.  
  239. void
  240. reload (first, global, dumpfile)
  241.      rtx first;
  242.      int global;
  243.      FILE *dumpfile;
  244. {
  245.   register int class;
  246.   register int i;
  247.   register rtx insn;
  248.  
  249.   int something_changed;
  250.   int something_needs_reloads;
  251.   int new_basic_block_needs;
  252.  
  253.   /* The basic block number currently being processed for INSN.  */
  254.   int this_block;
  255.  
  256.   /* Often (MEM (REG n)) is still valid even if (REG n) is put on the stack.
  257.      Set spill_indirect_ok if so.  */
  258.   register rtx tem
  259.     = gen_rtx (MEM, Pmode,
  260.            gen_rtx (PLUS, Pmode,
  261.             gen_rtx (REG, Pmode, FRAME_POINTER_REGNUM),
  262.             gen_rtx (CONST_INT, VOIDmode, 4)));
  263.  
  264.   spill_indirect_ok = memory_address_p (QImode, tem);
  265.  
  266.   tem = gen_rtx (PLUS, Pmode, 
  267.          gen_rtx (REG, Pmode, FRAME_POINTER_REGNUM),
  268.          gen_rtx (REG, Pmode, FRAME_POINTER_REGNUM));
  269.   /* This way, we make sure that reg+reg is an offsettable address.  */
  270.   tem = plus_constant (tem, 4);
  271.  
  272.   double_reg_address_ok = memory_address_p (QImode, tem);
  273.  
  274.   /* Enable find_equiv_reg to distinguish insns made by reload.  */
  275.   reload_first_uid = get_max_uid ();
  276.  
  277.   basic_block_needs = 0;
  278.  
  279.   /* Remember which hard regs appear explicitly
  280.      before we merge into `regs_ever_live' the ones in which
  281.      pseudo regs have been allocated.  */
  282.   bcopy (regs_ever_live, regs_explicitly_used, sizeof regs_ever_live);
  283.  
  284.   /* We don't have a stack slot for any spill reg yet.  */
  285.   bzero (spill_stack_slot, sizeof spill_stack_slot);
  286.   bzero (spill_stack_slot_width, sizeof spill_stack_slot_width);
  287.  
  288.   /* Compute which hard registers are now in use
  289.      as homes for pseudo registers.
  290.      This is done here rather than (eg) in global_alloc
  291.      because this point is reached even if not optimizing.  */
  292.  
  293.   for (i = FIRST_PSEUDO_REGISTER; i < max_regno; i++)
  294.     mark_home_live (i);
  295.  
  296.   /* Make sure that the last insn in the chain
  297.      is not something that needs reloading.  */
  298.   emit_note (0, NOTE_INSN_DELETED);
  299.  
  300.   /* Find all the pseudo registers that didn't get hard regs
  301.      but do have known equivalent constants or memory slots.
  302.      These include parameters (known equivalent to parameter slots)
  303.      and cse'd or loop-moved constant memory addresses.
  304.  
  305.      Record constant equivalents in reg_equiv_constant
  306.      so they will be substituted by find_reloads.
  307.      Record memory equivalents in reg_mem_equiv so they can
  308.      be substituted eventually by altering the REG-rtx's.  */
  309.  
  310.   reg_equiv_constant = (rtx *) alloca (max_regno * sizeof (rtx));
  311.   bzero (reg_equiv_constant, max_regno * sizeof (rtx));
  312.   reg_equiv_mem = (rtx *) alloca (max_regno * sizeof (rtx));
  313.   bzero (reg_equiv_mem, max_regno * sizeof (rtx));
  314.   reg_equiv_init = (rtx *) alloca (max_regno * sizeof (rtx));
  315.   bzero (reg_equiv_init, max_regno * sizeof (rtx));
  316.   reg_equiv_address = (rtx *) alloca (max_regno * sizeof (rtx));
  317.   bzero (reg_equiv_address, max_regno * sizeof (rtx));
  318.   reg_max_ref_width = (int *) alloca (max_regno * sizeof (int));
  319.   bzero (reg_max_ref_width, max_regno * sizeof (int));
  320.  
  321.   /* Look for REG_EQUIV notes; record what each pseudo is equivalent to.
  322.      Also find all paradoxical subregs
  323.      and find largest such for each pseudo.  */
  324.  
  325.   for (insn = first; insn; insn = NEXT_INSN (insn))
  326.     {
  327.       if (GET_CODE (insn) == INSN
  328.       && GET_CODE (PATTERN (insn)) == SET
  329.       && GET_CODE (SET_DEST (PATTERN (insn))) == REG)
  330.     {
  331.       rtx note = find_reg_note (insn, REG_EQUIV, 0);
  332.       if (note)
  333.         {
  334.           rtx x = XEXP (note, 0);
  335.           i = REGNO (SET_DEST (PATTERN (insn)));
  336.           if (i >= FIRST_PSEUDO_REGISTER)
  337.         {
  338.           if (GET_CODE (x) == MEM)
  339.             {
  340.               if (memory_address_p (GET_MODE (x), XEXP (x, 0)))
  341.             reg_equiv_mem[i] = x;
  342.               else
  343.             reg_equiv_address[i] = XEXP (x, 0);
  344.             }
  345.           else if (immediate_operand (x, VOIDmode))
  346.             reg_equiv_constant[i] = x;
  347.           else
  348.             continue;
  349.           reg_equiv_init[i] = insn;
  350.         }
  351.         }
  352.     }
  353.       if (GET_CODE (insn) == INSN || GET_CODE (insn) == CALL_INSN
  354.       || GET_CODE (insn) == JUMP_INSN)
  355.     scan_paradoxical_subregs (PATTERN (insn));
  356.     }
  357.  
  358.   /* Does this function require a frame pointer?  */
  359.  
  360.   frame_pointer_needed
  361.     |= (! global || FRAME_POINTER_REQUIRED);
  362.  
  363.   if (! frame_pointer_needed)
  364.     frame_pointer_needed
  365.       = check_frame_pointer_required (reg_equiv_constant,
  366.                       reg_equiv_mem, reg_equiv_address);
  367.  
  368.   /* Alter each pseudo-reg rtx to contain its hard reg number.
  369.      Delete initializations of pseudos that don't have hard regs
  370.      and do have equivalents.
  371.      Assign stack slots to the pseudos that lack hard regs or equivalents.  */
  372.  
  373.   for (i = FIRST_PSEUDO_REGISTER; i < max_regno; i++)
  374.     alter_reg (i, -1);
  375.  
  376. #ifndef REGISTER_CONSTRAINTS
  377.   /* If all the pseudo regs have hard regs,
  378.      except for those that are never referenced,
  379.      we know that no reloads are needed.  */
  380.   /* But that is not true if there are register constraints, since
  381.      in that case some pseudos might be in the wrong kind of hard reg.  */
  382.  
  383.   for (i = FIRST_PSEUDO_REGISTER; i < max_regno; i++)
  384.     if (reg_renumber[i] == -1 && reg_n_refs[i] != 0)
  385.       break;
  386.  
  387.   if (i == max_regno && frame_pointer_needed && ! caller_save_needed)
  388.     return;
  389. #endif
  390.  
  391.   /* Compute the order of preference for hard registers to spill.
  392.      Store them by decreasing preference in potential_reload_regs.  */
  393.  
  394.   order_regs_for_reload ();
  395.  
  396.   /* So far, no hard regs have been spilled.  */
  397.   n_spills = 0;
  398.   for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
  399.     {
  400.       spill_reg_order[i] = -1;
  401.       forbidden_regs[i] = -1;
  402.     }
  403.  
  404.   if (caller_save_needed)
  405.     frame_pointer_needed = 1;
  406.  
  407.   if (frame_pointer_needed)
  408.     {
  409.       forbidden_regs[FRAME_POINTER_REGNUM] = 1;
  410.       spill_hard_reg (FRAME_POINTER_REGNUM, global, dumpfile);
  411.     }
  412.  
  413.   if (global)
  414.     {
  415.       basic_block_needs = (char *)alloca (n_basic_blocks);
  416.       bzero (basic_block_needs, n_basic_blocks);
  417.     }
  418.  
  419.   /* This loop scans the entire function each go-round
  420.      and repeats until one repetition spills no additional hard regs.  */
  421.  
  422.   /* This flag is set when a psuedo reg is spilled,
  423.      to require another pass.  Note that getting an additional reload
  424.      reg does not necessarily imply any pseudo reg was spilled;
  425.      sometimes we find a reload reg that no pseudo reg was allocated in.  */
  426.   something_changed = 1;
  427.   /* This flag is set if there are any insns that require reloading.  */
  428.   something_needs_reloads = 0;
  429.   while (something_changed)
  430.     {
  431.       /* For each class, number of reload regs needed in that class.
  432.      This is the maximum over all insns of the needs in that class
  433.      of the individual insn.  */
  434.       int max_needs[N_REG_CLASSES];
  435.       /* For each class, size of group of consecutive regs
  436.      that is needed for the reloads of this class.  */
  437.       int group_size[N_REG_CLASSES];
  438.       /* For each class, max number of consecutive groups needed.
  439.      (Each group contains max_needs_size[CLASS] consecutive registers.)  */
  440.       int max_groups[N_REG_CLASSES];
  441.       /* For each class, max number needed of regs that don't belong
  442.      to any of the groups.  */
  443.       int max_nongroups[N_REG_CLASSES];
  444.       /* For each class, the machine mode which requires consecutive
  445.      groups of regs of that class.
  446.      If two different modes ever require groups of one class,
  447.      they must be the same size and equally restrictive for that class,
  448.      otherwise we can't handle the complexity.  */
  449.       enum machine_mode group_mode[N_REG_CLASSES];
  450.  
  451. #ifdef MPW
  452.     SpinCursor (1);
  453. #endif
  454.  
  455.       something_changed = 0;
  456.       bzero (max_needs, sizeof max_needs);
  457.       bzero (max_groups, sizeof max_groups);
  458.       bzero (max_nongroups, sizeof max_nongroups);
  459.       bzero (group_size, sizeof group_size);
  460.       for (i = 0; i < N_REG_CLASSES; i++)
  461.     group_mode[i] = VOIDmode;
  462.  
  463.       /* Keep track of which basic blocks are needing the reloads.  */
  464.       this_block = 0;
  465.  
  466.       /* Remember whether any element of basic_block_needs
  467.      changes from 0 to 1 in this pass.  */
  468.       new_basic_block_needs = 0;
  469.  
  470.       /* Compute the most additional registers needed by any instruction.
  471.      Collect information separately for each class of regs.  */
  472.  
  473.       for (insn = first; insn; insn = NEXT_INSN (insn))
  474.     {
  475.       if (global && this_block + 1 < n_basic_blocks
  476.           && insn == basic_block_head[this_block+1])
  477.         ++this_block;
  478.  
  479.       if (GET_CODE (insn) == INSN || GET_CODE (insn) == JUMP_INSN
  480.           || GET_CODE (insn) == CALL_INSN)
  481.         {
  482.           /* Initially, count RELOAD_OTHER reloads.
  483.          Later, merge in the other kinds.  */
  484.           int insn_needs[N_REG_CLASSES];
  485.           int insn_groups[N_REG_CLASSES];
  486.           int insn_total_groups = 0;
  487.  
  488.           /* Count RELOAD_FOR_INPUT_RELOAD_ADDRESS reloads.  */
  489.           int insn_needs_for_inputs[N_REG_CLASSES];
  490.           int insn_groups_for_inputs[N_REG_CLASSES];
  491.           int insn_total_groups_for_inputs = 0;
  492.  
  493.           /* Count RELOAD_FOR_OUTPUT_RELOAD_ADDRESS reloads.  */
  494.           int insn_needs_for_outputs[N_REG_CLASSES];
  495.           int insn_groups_for_outputs[N_REG_CLASSES];
  496.           int insn_total_groups_for_outputs = 0;
  497.  
  498.           /* Count RELOAD_FOR_OPERAND_ADDRESS reloads.  */
  499.           int insn_needs_for_operands[N_REG_CLASSES];
  500.           int insn_groups_for_operands[N_REG_CLASSES];
  501.           int insn_total_groups_for_operands = 0;
  502.  
  503.           for (i = 0; i < N_REG_CLASSES; i++)
  504.         {
  505.           insn_needs[i] = 0, insn_groups[i] = 0;
  506.           insn_needs_for_inputs[i] = 0, insn_groups_for_inputs[i] = 0;
  507.           insn_needs_for_outputs[i] = 0, insn_groups_for_outputs[i] = 0;
  508.           insn_needs_for_operands[i] = 0, insn_groups_for_operands[i] = 0;
  509.         }
  510.  
  511. #if 0  /* This wouldn't work nowadays, since optimize_bit_field
  512.       looks for non-strict memory addresses.  */
  513.           /* Optimization: a bit-field instruction whose field
  514.          happens to be a byte or halfword in memory
  515.          can be changed to a move instruction.  */
  516.  
  517.           if (GET_CODE (PATTERN (insn)) == SET)
  518.         {
  519.           rtx dest = SET_DEST (PATTERN (insn));
  520.           rtx src = SET_SRC (PATTERN (insn));
  521.  
  522.           if (GET_CODE (dest) == ZERO_EXTRACT
  523.               || GET_CODE (dest) == SIGN_EXTRACT)
  524.             optimize_bit_field (PATTERN (insn), insn, reg_equiv_mem);
  525.           if (GET_CODE (src) == ZERO_EXTRACT
  526.               || GET_CODE (src) == SIGN_EXTRACT)
  527.             optimize_bit_field (PATTERN (insn), insn, reg_equiv_mem);
  528.         }
  529. #endif
  530.  
  531.           /* Analyze the instruction.  */
  532.  
  533.           find_reloads (insn, 0, spill_indirect_ok, global, spill_reg_order);
  534.  
  535.           if (n_reloads == 0)
  536.         continue;
  537.  
  538.           something_needs_reloads = 1;
  539.  
  540.           /* Count each reload once in every class
  541.          containing the reload's own class.  */
  542.  
  543.           for (i = 0; i < n_reloads; i++)
  544.         {
  545.           register enum reg_class *p;
  546.           int size;
  547.           enum machine_mode mode;
  548.           int *this_groups;
  549.           int *this_needs;
  550.           int *this_total_groups;
  551.  
  552.           /* Don't use dummy reloads in regs
  553.              being spilled in this block.  */
  554.           if (reload_reg_rtx[i] != 0
  555.               && (!global || basic_block_needs[this_block])
  556.               && spill_reg_order[REGNO (reload_reg_rtx[i])] >= 0)
  557.             reload_reg_rtx[i] = 0;
  558.  
  559.           /* Don't count the dummy reloads, for which one of the
  560.              regs mentioned in the insn can be used for reloading.
  561.              Don't count optional reloads.
  562.              Don't count reloads that got combined with others.  */
  563.           if (reload_reg_rtx[i] != 0
  564.               || reload_optional[i] != 0
  565.               || (reload_out[i] == 0 && reload_in[i] == 0))
  566.             continue;
  567.  
  568.           /* Decide which time-of-use to count this reload for.  */
  569.           switch (reload_when_needed[i])
  570.             {
  571.             case RELOAD_OTHER:
  572.               this_needs = insn_needs;
  573.               this_groups = insn_groups;
  574.               this_total_groups = &insn_total_groups;
  575.               break;
  576.  
  577.             case RELOAD_FOR_INPUT_RELOAD_ADDRESS:
  578.               this_needs = insn_needs_for_inputs;
  579.               this_groups = insn_groups_for_inputs;
  580.               this_total_groups = &insn_total_groups_for_inputs;
  581.               break;
  582.  
  583.             case RELOAD_FOR_OUTPUT_RELOAD_ADDRESS:
  584.               this_needs = insn_needs_for_outputs;
  585.               this_groups = insn_groups_for_outputs;
  586.               this_total_groups = &insn_total_groups_for_outputs;
  587.               break;
  588.  
  589.             case RELOAD_FOR_OPERAND_ADDRESS:
  590.               this_needs = insn_needs_for_operands;
  591.               this_groups = insn_groups_for_operands;
  592.               this_total_groups = &insn_total_groups_for_operands;
  593.               break;
  594.             }
  595.  
  596.           mode = reload_inmode[i];
  597.           if (GET_MODE_SIZE (reload_outmode[i]) > GET_MODE_SIZE (mode))
  598.             mode = reload_outmode[i];
  599.           size = CLASS_MAX_NREGS (reload_reg_class[i], mode);
  600.           if (size > 1)
  601.             {
  602.               /* Count number of groups needed separately from
  603.              number of individual regs needed.  */
  604.               this_groups[(int) reload_reg_class[i]]++;
  605.               p = reg_class_superclasses[(int) reload_reg_class[i]];
  606.               while (*p != LIM_REG_CLASSES)
  607.             this_groups[(int) *p++]++;
  608.               (*this_total_groups)++;
  609.  
  610.               /* If a group of consecutive regs are needed,
  611.              record which machine mode needs them.
  612.              Crash if two dissimilar machine modes both need
  613.              groups of consecutive regs of the same class.  */
  614.  
  615.               if (group_mode[(int) reload_reg_class[i]] != VOIDmode
  616.               &&
  617.               (! modes_equiv_for_class_p (group_mode[(int) reload_reg_class[i]], mode, reload_reg_class[i])
  618.                ||
  619.                group_size[(int) reload_reg_class[i]] != size))
  620.                {
  621.                fprintf(stderr, "%s\n", GET_MODE_NAME(group_mode[(int) reload_reg_class[i]]));
  622.                fprintf(stderr, "%s\n",    GET_MODE_NAME(mode));
  623.                fprintf(stderr, "%d\n", reload_reg_class[i]);
  624.             abort ();
  625.                 }
  626.  
  627.               /* Record size and mode of a group of this class.  */
  628.               group_size[(int) reload_reg_class[i]] = size;
  629.               group_mode[(int) reload_reg_class[i]] = mode;
  630.             }
  631.           else if (size == 1)
  632.             {
  633.               this_needs[(int) reload_reg_class[i]] += 1;
  634.               p = reg_class_superclasses[(int) reload_reg_class[i]];
  635.               while (*p != LIM_REG_CLASSES)
  636.             this_needs[(int) *p++] += 1;
  637.             }
  638.           else
  639.             abort ();
  640.  
  641.           if (global)
  642.             {
  643.               if (! basic_block_needs[this_block])
  644.             new_basic_block_needs = 1;
  645.               basic_block_needs[this_block] = 1;
  646.             }
  647.         }
  648.  
  649.           /* All reloads have been counted for this insn;
  650.          now merge the various times of use.
  651.          This sets insn_needs, etc., to the maximum total number
  652.          of registers needed at any point in this insn.  */
  653.  
  654.           for (i = 0; i < N_REG_CLASSES; i++)
  655.         {
  656.           int this_max;
  657.           this_max = insn_needs_for_inputs[i];
  658.           if (insn_needs_for_outputs[i] > this_max)
  659.             this_max = insn_needs_for_outputs[i];
  660.           if (insn_needs_for_operands[i] > this_max)
  661.             this_max = insn_needs_for_operands[i];
  662.           insn_needs[i] += this_max;
  663.           this_max = insn_groups_for_inputs[i];
  664.           if (insn_groups_for_outputs[i] > this_max)
  665.             this_max = insn_groups_for_outputs[i];
  666.           if (insn_groups_for_operands[i] > this_max)
  667.             this_max = insn_groups_for_operands[i];
  668.           insn_groups[i] += this_max;
  669.         }
  670.           insn_total_groups += max (insn_total_groups_for_inputs,
  671.                     max (insn_total_groups_for_outputs,
  672.                          insn_total_groups_for_operands));
  673.  
  674.           /* Remember for later shortcuts which insns had any reloads.  */
  675.  
  676.           PUT_MODE (insn, n_reloads ? QImode : VOIDmode);
  677.  
  678.           /* For each class, collect maximum need of any insn.  */
  679.  
  680.           for (i = 0; i < N_REG_CLASSES; i++)
  681.         {
  682.           if (max_needs[i] < insn_needs[i])
  683.             max_needs[i] = insn_needs[i];
  684.           if (max_groups[i] < insn_groups[i])
  685.             max_groups[i] = insn_groups[i];
  686.           if (insn_total_groups > 0)
  687.             if (max_nongroups[i] < insn_needs[i])
  688.               max_nongroups[i] = insn_needs[i];
  689.         }
  690.         }
  691.       /* Note that there is a continue statement above.  */
  692.     }
  693.  
  694.       /* Now deduct from the needs for the registers already
  695.      available (already spilled).  */
  696.  
  697.       bzero (counted_for_groups, sizeof counted_for_groups);
  698.       bzero (counted_for_nongroups, sizeof counted_for_nongroups);
  699.  
  700.       /* Find all consecutive groups of spilled registers
  701.      and mark each group off against the need for such groups.  */
  702.  
  703.       for (i = 0; i < N_REG_CLASSES; i++)
  704.     if (group_size[i] > 1)
  705.       {
  706.         char regmask[FIRST_PSEUDO_REGISTER];
  707.         int j;
  708.  
  709.         bzero (regmask, sizeof regmask);
  710.         /* Make a mask of all the regs that are spill regs in class I.  */
  711.         for (j = 0; j < n_spills; j++)
  712.           if (TEST_HARD_REG_BIT (reg_class_contents[i], spill_regs[j])
  713.           && !counted_for_groups[spill_regs[j]])
  714.         regmask[spill_regs[j]] = 1;
  715.         /* Find each consecutive group of them.  */
  716.         for (j = 0; j < FIRST_PSEUDO_REGISTER && max_groups[i] > 0; j++)
  717.           if (regmask[j] && j + group_size[i] <= FIRST_PSEUDO_REGISTER
  718.           /* Next line in case group-mode for this class
  719.              demands an even-odd pair.  */
  720.           && HARD_REGNO_MODE_OK (j, group_mode[i]))
  721.         {
  722.           int k;
  723.           for (k = 1; k < group_size[i]; k++)
  724.             if (! regmask[j + k])
  725.               break;
  726.           if (k == group_size[i])
  727.             {
  728.               /* We found a group.  Mark it off against this class's
  729.              need for groups, and against each superclass too.  */
  730.               register enum reg_class *p;
  731.               max_groups[i]--;
  732.               p = reg_class_superclasses[i];
  733.               while (*p != LIM_REG_CLASSES)
  734.             max_groups[(int) *p++]--;
  735.               /* Don't count these registers again.  */ 
  736.               counted_for_groups[j] = 1;
  737.               for (k = 1; k < group_size[i]; k++)
  738.             counted_for_groups[j + k] = 1;
  739.             }
  740.           j += k;
  741.         }
  742.       }
  743.  
  744.       /* Now count all remaining spill regs against the individual need.
  745.      Those that weren't counted_for_groups in groups can also count against
  746.      the not-in-group need.  */
  747.  
  748.       for (i = 0; i < n_spills; i++)
  749.     {
  750.       register enum reg_class *p;
  751.       class = (int) REGNO_REG_CLASS (spill_regs[i]);
  752.  
  753.       max_needs[class]--;
  754.       p = reg_class_superclasses[class];
  755.       while (*p != LIM_REG_CLASSES)
  756.         max_needs[(int) *p++]--;
  757.  
  758.       if (! counted_for_groups[spill_regs[i]])
  759.         {
  760.           if (max_nongroups[class] > 0)
  761.         counted_for_nongroups[spill_regs[i]] = 1;
  762.           max_nongroups[class]--;
  763.           p = reg_class_superclasses[class];
  764.           while (*p != LIM_REG_CLASSES)
  765.         {
  766.           if (max_nongroups[(int) *p] > 0)
  767.             counted_for_nongroups[spill_regs[i]] = 1;
  768.           max_nongroups[(int) *p++]--;
  769.         }
  770.         }
  771.     }
  772.  
  773.       /* If all needs are met, we win.  */
  774.  
  775.       for (i = 0; i < N_REG_CLASSES; i++)
  776.     if (max_needs[i] > 0 || max_groups[i] > 0 || max_nongroups[i] > 0)
  777.       break;
  778.       if (i == N_REG_CLASSES && !new_basic_block_needs)
  779.     break;
  780.  
  781.       /* Not all needs are met; must spill more hard regs.  */
  782.  
  783.       /* If any element of basic_block_needs changed from 0 to 1,
  784.      re-spill all the regs already spilled.  This may spill
  785.      additional pseudos that didn't spill before.  */
  786.  
  787.       if (new_basic_block_needs)
  788.     for (i = 0; i < n_spills; i++)
  789.       something_changed
  790.         |= spill_hard_reg (spill_regs[i], global, dumpfile);
  791.  
  792.       /* Now find more reload regs to satisfy the remaining need
  793.      Do it by ascending class number, since otherwise a reg
  794.      might be spilled for a big class and might fail to count
  795.      for a smaller class even though it belongs to that class.
  796.  
  797.      Count spilled regs in `spills', and add entries to
  798.      `spill_regs' and `spill_reg_order'.  */
  799.  
  800.       for (class = 0; class < N_REG_CLASSES; class++)
  801.     {
  802.       /* First get the groups of registers.
  803.          If we got single registers first, we might fragment
  804.          possible groups.  */
  805.       while (max_groups[class] > 0)
  806.         {
  807.  
  808. #ifdef MPW
  809.     SpinCursor (1);
  810. #endif
  811.  
  812.           /* Groups of size 2 (the only groups used on most machines)
  813.          are treated specially.  */
  814.           if (group_size[class] == 2)
  815.         {
  816.           /* First, look for a register that will complete a group.  */
  817.           for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
  818.             {
  819.               int j = potential_reload_regs[i];
  820.               int other;
  821.               if (j >= 0 && !fixed_regs[j]
  822.               &&
  823.               ((j > 0 && (other = j - 1, spill_reg_order[other] >= 0)
  824.                 && TEST_HARD_REG_BIT (reg_class_contents[class], j)
  825.                 && TEST_HARD_REG_BIT (reg_class_contents[class], other)
  826.                 && HARD_REGNO_MODE_OK (other, group_mode[class])
  827.                 && ! counted_for_nongroups[other]
  828.                 /* We don't want one part of another group.
  829.                    We could get "two groups" that overlap!  */
  830.                 && ! counted_for_groups[other])
  831.  
  832.                ||
  833.                (j < FIRST_PSEUDO_REGISTER - 1
  834.                 && (other = j + 1, spill_reg_order[other] >= 0)
  835.                 && TEST_HARD_REG_BIT (reg_class_contents[class], j)
  836.                 && TEST_HARD_REG_BIT (reg_class_contents[class], other)
  837.                 && HARD_REGNO_MODE_OK (j, group_mode[class])
  838.                 && ! counted_for_nongroups[other]
  839.                 && ! counted_for_groups[other])))
  840.             {
  841.               register enum reg_class *p;
  842.  
  843.               /* We have found one that will complete a group,
  844.                  so count off one group as provided.  */
  845.               max_groups[class]--;
  846.               p = reg_class_superclasses[class];
  847.               while (*p != LIM_REG_CLASSES)
  848.                 max_groups[(int) *p++]--;
  849.  
  850.               /* Indicate both these regs are part of a group.  */
  851.               counted_for_groups[j] = 1;
  852.               counted_for_groups[other] = 1;
  853.  
  854.               break;
  855.             }
  856.             }
  857.           /* We can't complete a group, so start one.  */
  858.           if (i == FIRST_PSEUDO_REGISTER)
  859.             for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
  860.               {
  861.             int j = potential_reload_regs[i];
  862.             if (j >= 0 && j + 1 < FIRST_PSEUDO_REGISTER
  863.                 && spill_reg_order[j] < 0 && spill_reg_order[j + 1] < 0
  864.                 && TEST_HARD_REG_BIT (reg_class_contents[class], j)
  865.                 && TEST_HARD_REG_BIT (reg_class_contents[class], j + 1)
  866.                 && HARD_REGNO_MODE_OK (j, group_mode[class])
  867.                 && ! counted_for_nongroups[j + 1])
  868.               break;
  869.               }
  870.  
  871.           /* I should be the index in potential_reload_regs
  872.              of the new reload reg we have found.  */
  873.  
  874.           something_changed
  875.             |= new_spill_reg (i, class, max_needs, 0,
  876.                       global, dumpfile);
  877.         }
  878.           else
  879.         {
  880.           /* For groups of more than 2 registers,
  881.              look for a sufficient sequence of unspilled registers,
  882.              and spill them all at once.  */
  883.           for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
  884.             {
  885.               int j = potential_reload_regs[i];
  886.               int k;
  887.               if (j >= 0 && j + 1 < FIRST_PSEUDO_REGISTER
  888.               && HARD_REGNO_MODE_OK (j, group_mode[class]))
  889.             {
  890.               /* Check each reg in the sequence.  */
  891.               for (k = 0; k < group_size[class]; k++)
  892.                 if (! (spill_reg_order[j + k] < 0
  893.                    && !fixed_regs[j + k]
  894.                    && TEST_HARD_REG_BIT (reg_class_contents[class], j + k)))
  895.                   break;
  896.               /* We got a full sequence, so spill them all.  */
  897.               if (k == group_size[class])
  898.                 {
  899.                   register enum reg_class *p;
  900.                   for (k = 0; k < group_size[class]; k++)
  901.                 {
  902.                   int idx;
  903.                   counted_for_groups[j + k] = 1;
  904.                   for (idx = 0; idx < FIRST_PSEUDO_REGISTER; idx++)
  905.                     if (potential_reload_regs[idx] == j + k)
  906.                       break;
  907.                   something_changed
  908.                     |= new_spill_reg (idx, class, max_needs, 0,
  909.                               global, dumpfile);
  910.                 }
  911.  
  912.                   /* We have found one that will complete a group,
  913.                  so count off one group as provided.  */
  914.                   max_groups[class]--;
  915.                   p = reg_class_superclasses[class];
  916.                   while (*p != LIM_REG_CLASSES)
  917.                 max_groups[(int) *p++]--;
  918.  
  919.                   break;
  920.                 }
  921.             }
  922.             }
  923.         }
  924.         }
  925.  
  926.       /* Now similarly satisfy all need for single registers.  */
  927.  
  928.       while (max_needs[class] > 0 || max_nongroups[class] > 0)
  929.         {
  930.           /* Consider the potential reload regs that aren't
  931.          yet in use as reload regs, in order of preference.
  932.          Find the most preferred one that's in this class.  */
  933.  
  934.           for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
  935.         if (potential_reload_regs[i] >= 0
  936.             && TEST_HARD_REG_BIT (reg_class_contents[class],
  937.                       potential_reload_regs[i]))
  938.           break;
  939.  
  940.           /* I should be the index in potential_reload_regs
  941.          of the new reload reg we have found.  */
  942.  
  943.           something_changed
  944.         |= new_spill_reg (i, class, max_needs, max_nongroups,
  945.                   global, dumpfile);
  946.         }
  947.     }
  948.     }
  949.  
  950. #ifdef MPW
  951.     SpinCursor (1);
  952. #endif
  953.  
  954.   /* Insert code to save and restore call-clobbered hard regs
  955.      around calls.  */
  956.  
  957.   if (caller_save_needed)
  958.     save_call_clobbered_regs ();
  959.  
  960.   /* Now we know for certain whether we have a frame pointer.
  961.      If not, correct all references to go through the stack pointer.
  962.      This must be done before reloading, since reloading could generate
  963.      insns where sp+const cannot validly replace the frame pointer.
  964.      *This will lose if an insn might need more spill regs after
  965.      frame pointer elimination than it needed before.*  */
  966.  
  967.   if (! frame_pointer_needed)
  968.     eliminate_frame_pointer (first);
  969.  
  970.   /* Use the reload registers where necessary
  971.      by generating move instructions to move the must-be-register
  972.      values into or out of the reload registers.  */
  973.  
  974.   if (something_needs_reloads)
  975.     reload_as_needed (first, global);
  976.  
  977. #ifdef MPW
  978.     SpinCursor (1);
  979. #endif
  980.  
  981.   /* Now eliminate all pseudo regs by modifying them into
  982.      their equivalent memory references.
  983.      The REG-rtx's for the pseudos are modified in place,
  984.      so all insns that used to refer to them now refer to memory.
  985.  
  986.      For a reg that has a reg_equiv_address, all those insns
  987.      were changed by reloading so that no insns refer to it any longer;
  988.      but the DECL_RTL of a variable decl may refer to it,
  989.      and if so this causes the debugging info to mention the variable.  */
  990.  
  991.   for (i = FIRST_PSEUDO_REGISTER; i < max_regno; i++)
  992.     {
  993.       rtx addr = 0;
  994.       if (reg_equiv_mem[i])
  995.     addr = XEXP (reg_equiv_mem[i], 0);
  996.       if (reg_equiv_address[i])
  997.     addr = reg_equiv_address[i];
  998.       if (addr)
  999.     {
  1000.       if (! frame_pointer_needed)
  1001.         FIX_FRAME_POINTER_ADDRESS (addr, 0);
  1002.       if (reg_renumber[i] < 0)
  1003.         {
  1004.           rtx reg = regno_reg_rtx[i];
  1005.           XEXP (reg, 0) = addr;
  1006.           REG_USERVAR_P (reg) = 0;
  1007.           PUT_CODE (reg, MEM);
  1008.         }
  1009.       else if (reg_equiv_mem[i])
  1010.         XEXP (reg_equiv_mem[i], 0) = addr;
  1011.     }
  1012.     }
  1013. }
  1014.  
  1015. /* 1 if two machine modes MODE0 and MODE1 are equivalent
  1016.    as far as HARD_REGNO_MODE_OK is concerned
  1017.    for registers in class CLASS.  */
  1018.  
  1019. static int
  1020. modes_equiv_for_class_p (mode0, mode1, class)
  1021.      enum machine_mode mode0, mode1;
  1022.      enum reg_class class;
  1023. {
  1024.   register int regno;
  1025.   for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
  1026.     {
  1027.       /* If any reg in CLASS allows one mode but not the other, fail.
  1028.      Or if the two modes have different sizes in that reg, fail.  */
  1029.       if (TEST_HARD_REG_BIT (reg_class_contents[(int) class], regno)
  1030.       && (HARD_REGNO_MODE_OK (regno, mode0)
  1031.           != HARD_REGNO_MODE_OK (regno, mode1))
  1032.       && (HARD_REGNO_NREGS (regno, mode0)
  1033.           != HARD_REGNO_NREGS (regno, mode1)))
  1034.     return 0;
  1035.     }
  1036.   return 1;
  1037. }
  1038.  
  1039. /* Add a new register to the tables of available spill-registers
  1040.     (as well as spilling all pseudos allocated to the register).
  1041.    I is the index of this register in potential_reload_regs.
  1042.    CLASS is the regclass whose need is being satisfied.
  1043.    MAX_NEEDS and MAX_NONGROUPS are the vectors of needs,
  1044.     so that this register can count off against them.
  1045.     MAX_NONGROUPS is 0 if this register is part of a group.
  1046.    GLOBAL and DUMPFILE are the same as the args that `reload' got.  */
  1047.  
  1048. static int
  1049. new_spill_reg (i, class, max_needs, max_nongroups, global, dumpfile)
  1050.      int i;
  1051.      int class;
  1052.      int *max_needs;
  1053.      int *max_nongroups;
  1054.      int global;
  1055.      FILE *dumpfile;
  1056. {
  1057.   register enum reg_class *p;
  1058.   int val;
  1059.   int regno = potential_reload_regs[i];
  1060.  
  1061.   if (i >= FIRST_PSEUDO_REGISTER)
  1062.     abort ();    /* Caller failed to find any register.  */
  1063.  
  1064.   /* Make reg REGNO an additional reload reg.  */
  1065.  
  1066.   potential_reload_regs[i] = -1;
  1067.   spill_regs[n_spills] = regno;
  1068.   spill_reg_order[regno] = n_spills;
  1069.   forbidden_regs[regno] = 1;
  1070.   if (dumpfile)
  1071.     fprintf (dumpfile, "Spilling reg %d.\n", spill_regs[n_spills]);
  1072.  
  1073.   /* Clear off the needs we just satisfied.  */
  1074.  
  1075.   max_needs[class]--;
  1076.   p = reg_class_superclasses[class];
  1077.   while (*p != LIM_REG_CLASSES)
  1078.     max_needs[(int) *p++]--;
  1079.  
  1080.   if (max_nongroups && max_nongroups[class] > 0)
  1081.     {
  1082.       counted_for_nongroups[regno] = 1;
  1083.       max_nongroups[class]--;
  1084.       p = reg_class_superclasses[class];
  1085.       while (*p != LIM_REG_CLASSES)
  1086.     max_nongroups[(int) *p++]--;
  1087.     }
  1088.  
  1089.   /* Spill every pseudo reg that was allocated to this reg
  1090.      or to something that overlaps this reg.  */
  1091.  
  1092.   val = spill_hard_reg (spill_regs[n_spills], global, dumpfile);
  1093.  
  1094.   regs_ever_live[spill_regs[n_spills]] = 1;
  1095.   n_spills++;
  1096.  
  1097.   return val;
  1098. }
  1099.  
  1100. /* Scan all insns, computing the stack depth, and convert all
  1101.    frame-pointer-relative references to stack-pointer-relative references.  */
  1102.  
  1103. static void
  1104. eliminate_frame_pointer (first)
  1105.      rtx first;
  1106. {
  1107.   int depth = 0;
  1108.   int max_uid = get_max_uid ();
  1109.   int *label_depth = (int *) alloca ((max_uid + 1) * sizeof (int));
  1110.   int i;
  1111.   rtx insn;
  1112.  
  1113.   for (i = 0; i <= max_uid; i++)
  1114.     label_depth[i] = -1;
  1115.  
  1116.   /* In this loop, for each forward branch we record the stack
  1117.      depth of the label it jumps to.  We take advantage of the fact
  1118.      that the stack depth at a label reached by a backward branch
  1119.      is always, in GCC output, equal to the stack depth of the preceding
  1120.      unconditional jump, because it was either a loop statement or
  1121.      statement label.  */
  1122.  
  1123.   for (insn = first; insn; insn = NEXT_INSN (insn))
  1124.     {
  1125.       rtx pattern = PATTERN (insn);
  1126.       switch (GET_CODE (insn))
  1127.     {
  1128.     case INSN:
  1129.       frame_pointer_address_altered = 0;
  1130.       alter_frame_pointer_addresses (pattern, depth);
  1131.       /* Rerecognize insn if changed.  */
  1132.       if (frame_pointer_address_altered)
  1133.         INSN_CODE (insn) = -1;
  1134.  
  1135.       /* Notice pushes and pops; update DEPTH.  */
  1136.       if (GET_CODE (pattern) == SET)
  1137.         {
  1138. #ifdef PUSH_ROUNDING
  1139.           if (push_operand (SET_DEST (pattern),
  1140.                 GET_MODE (SET_DEST (pattern))))
  1141.         depth += PUSH_ROUNDING (GET_MODE_SIZE (GET_MODE (SET_DEST (pattern))));
  1142. #endif
  1143.           if (GET_CODE (SET_DEST (pattern)) == REG
  1144.           && REGNO (SET_DEST (pattern)) == STACK_POINTER_REGNUM)
  1145.         {
  1146.           int delta;
  1147.           if (GET_CODE (SET_SRC (pattern)) == PLUS
  1148.               && GET_CODE (XEXP (SET_SRC (pattern), 0)) == REG
  1149.               && REGNO (XEXP (SET_SRC (pattern), 0)) == STACK_POINTER_REGNUM)
  1150.             delta = INTVAL (XEXP (SET_SRC (pattern), 1));
  1151.           else if (GET_CODE (SET_SRC (pattern)) == MINUS
  1152.                && GET_CODE (XEXP (SET_SRC (pattern), 0)) == REG
  1153.                && REGNO (XEXP (SET_SRC (pattern), 0)) == STACK_POINTER_REGNUM)
  1154.             delta = -INTVAL (XEXP (SET_SRC (pattern), 1));
  1155.           else abort ();
  1156. #ifdef STACK_GROWS_DOWNWARD
  1157.           depth -= delta;
  1158. #else
  1159.           depth += delta;
  1160. #endif
  1161.         }
  1162.         }
  1163.       break;
  1164.  
  1165.     case JUMP_INSN:
  1166.       frame_pointer_address_altered = 0;
  1167.       alter_frame_pointer_addresses (pattern, depth);
  1168.       /* Rerecognize insn if changed.  */
  1169.       if (frame_pointer_address_altered)
  1170.         INSN_CODE (insn) = -1;
  1171.  
  1172.       if (GET_CODE (pattern) == ADDR_VEC)
  1173.         for (i = 0; i < XVECLEN (pattern, 0); i++)
  1174.           label_depth[INSN_UID (XEXP (XVECEXP (pattern, 0, i), 0))] = depth;
  1175.       else if (GET_CODE (pattern) == ADDR_DIFF_VEC)
  1176.         {
  1177.           label_depth[INSN_UID (XEXP (XEXP (pattern, 0), 0))] = depth;
  1178.           for (i = 0; i < XVECLEN (pattern, 1); i++)
  1179.         label_depth[INSN_UID (XEXP (XVECEXP (pattern, 1, i), 0))] = depth;
  1180.         }
  1181.       else if (JUMP_LABEL (insn))
  1182.         label_depth[INSN_UID (JUMP_LABEL (insn))] = depth;
  1183.       else
  1184.       break;
  1185.  
  1186.     case CODE_LABEL:
  1187.       if (label_depth [INSN_UID (insn)] >= 0)
  1188.         depth = label_depth [INSN_UID (insn)];
  1189.       break;
  1190.  
  1191.     case CALL_INSN:
  1192.       frame_pointer_address_altered = 0;
  1193.       alter_frame_pointer_addresses (pattern, depth);
  1194.       /* Rerecognize insn if changed.  */
  1195.       if (frame_pointer_address_altered)
  1196.         INSN_CODE (insn) = -1;
  1197. #ifdef APPLE_C
  1198.       /* Pascal call insns magically change the stack, so account for this,
  1199.          using the second parameter in the call rtx. */
  1200. /*      fprintf(stderr, "Apparent stack depth before call is %d\n", depth);
  1201.       debug_rtx(insn);  */
  1202.       if (insn->call) {
  1203.         depth -= (GET_CODE (pattern) == SET
  1204.                   ? INTVAL (XEXP (SET_SRC (pattern), 1))
  1205.                   : INTVAL (XEXP (pattern, 1)));
  1206.       }
  1207. /*      fprintf(stderr, "Apparent stack depth after call is %d\n", depth); */
  1208. #endif /* APPLE_C */
  1209.       break;
  1210.     }
  1211.     }
  1212. }
  1213.  
  1214. /* Walk the rtx X, converting all frame-pointer refs to stack-pointer refs
  1215.    on the assumption that the current temporary stack depth is DEPTH.
  1216.    (The size of saved registers must be added to DEPTH
  1217.    to get the actual offset between the logical frame-pointer and the
  1218.    stack pointer.  FIX_FRAME_POINTER_ADDRESS takes care of that.)  */
  1219.  
  1220. static rtx
  1221. alter_frame_pointer_addresses (x, depth)
  1222.      register rtx x;
  1223.      int depth;
  1224. {
  1225.   register int i;
  1226.   register char *fmt;
  1227.   register enum rtx_code code = GET_CODE (x);
  1228.  
  1229.   switch (code)
  1230.     {
  1231.     case CONST_INT:
  1232.     case CONST:
  1233.     case SYMBOL_REF:
  1234.     case LABEL_REF:
  1235.     case CONST_DOUBLE:
  1236.     case CC0:
  1237.     case PC:
  1238.       return x;
  1239.  
  1240.     case REG:
  1241.       /* Frame ptr can occur outside a PLUS if a stack slot
  1242.      can occur with offset 0.  */
  1243.       if (x == frame_pointer_rtx)
  1244.     {
  1245.       rtx oldx = x;
  1246.       FIX_FRAME_POINTER_ADDRESS (x, depth);
  1247.       if (x != oldx)
  1248.         frame_pointer_address_altered = 1;
  1249.     }
  1250.       return x;
  1251.  
  1252.     case MEM:
  1253.       {
  1254.     rtx addr = XEXP (x, 0);
  1255.     rtx mem;
  1256.     rtx old_addr = addr;
  1257.     FIX_FRAME_POINTER_ADDRESS (addr, depth);
  1258.     if (addr != old_addr)
  1259.       frame_pointer_address_altered = 1;
  1260.     /* These MEMs are normally shared.  Make a changed copy;
  1261.        don't alter the shared MEM, since it needs to be altered
  1262.        differently each time it occurs (since DEPTH varies).  */
  1263.     mem = gen_rtx (MEM, GET_MODE (x), addr);
  1264.     MEM_VOLATILE_P (mem) = MEM_VOLATILE_P (x);
  1265.     return mem;
  1266.       }
  1267.  
  1268.     case PLUS:
  1269.       {
  1270.     rtx oldx = x;
  1271.     /* Handle addresses being loaded or pushed, etc.,
  1272.        rather than referenced.  */
  1273.     FIX_FRAME_POINTER_ADDRESS (x, depth);
  1274.     if (x != oldx)
  1275.       frame_pointer_address_altered = 1;
  1276.     code = GET_CODE (x);
  1277.     break;
  1278.       }
  1279.     }
  1280.  
  1281.   fmt = GET_RTX_FORMAT (code);
  1282.   for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
  1283.     {
  1284.       if (fmt[i] == 'e')
  1285.     XEXP (x, i) = alter_frame_pointer_addresses (XEXP (x, i), depth);
  1286.       else if (fmt[i] == 'E')
  1287.     {
  1288.       register int j;
  1289.       for (j = XVECLEN (x, i) - 1; j >=0; j--)
  1290.         XVECEXP (x, i, j)
  1291.           = alter_frame_pointer_addresses (XVECEXP (x, i, j), depth);
  1292.     }
  1293.     }
  1294.   return x;
  1295. }
  1296.  
  1297. /* Modify the home of pseudo-reg I.
  1298.    The new home is present in reg_renumber[I].
  1299.  
  1300.    FROM_REG may be the hard reg that the pseudo-reg is being spilled from;
  1301.    or it may be -1, meaning there is none or it is not relevant.
  1302.    This is used so that all pseudos spilled from a given hard reg
  1303.    can share one stack slot.  */
  1304.  
  1305. static void
  1306. alter_reg (i, from_reg)
  1307.      register int i;
  1308.      int from_reg;
  1309. {
  1310.   /* When outputting an inline function, this can happen
  1311.      for a reg that isn't actually used.  */
  1312.   if (regno_reg_rtx[i] == 0)
  1313.     return;
  1314.  
  1315.   /* If the reg got changed to a MEM at rtl-generation time,
  1316.      ignore it.  */
  1317.   if (GET_CODE (regno_reg_rtx[i]) != REG)
  1318.     return;
  1319.  
  1320.   /* Modify the reg-rtx to contain the new hard reg
  1321.      number or else to contain its pseudo reg number.  */
  1322.   REGNO (regno_reg_rtx[i])
  1323.     = reg_renumber[i] >= 0 ? reg_renumber[i] : i;
  1324.  
  1325.   if (reg_renumber[i] < 0 && reg_equiv_init[i])
  1326.     {
  1327.       /* Delete the insn that loads the pseudo register.  */
  1328.       PUT_CODE (reg_equiv_init[i], NOTE);
  1329.       NOTE_LINE_NUMBER (reg_equiv_init[i])
  1330.     = NOTE_INSN_DELETED;
  1331.       NOTE_SOURCE_FILE (reg_equiv_init[i]) = 0;
  1332.     }
  1333.  
  1334.   /* If we have a pseudo that is needed but has no hard reg or equivalent,
  1335.      allocate a stack slot for it.  */
  1336.  
  1337.   if (reg_renumber[i] < 0
  1338.       && reg_n_refs[i] > 0
  1339.       && reg_equiv_constant[i] == 0
  1340.       && reg_equiv_mem[i] == 0
  1341.       && reg_equiv_address[i] == 0)
  1342.     {
  1343.       register rtx x, addr;
  1344.       int inherent_size = PSEUDO_REGNO_BYTES (i);
  1345.       int total_size = max (inherent_size, reg_max_ref_width[i]);
  1346.  
  1347.       /* Each pseudo reg has an inherent size which comes from its own mode,
  1348.      and a total size which provides room for paradoxical subregs
  1349.      which refer to the pseudo reg in wider modes.
  1350.  
  1351.      We can use a slot already allocated if it provides both
  1352.      enough inherent space and enough total space.
  1353.      Otherwise, we allocate a new slot, making sure that it has no less
  1354.      inherent space, and no less total space, then the previous slot.  */
  1355.       if (from_reg == -1)
  1356.     {
  1357.       /* No known place to spill from => no slot to reuse.  */
  1358.       x = assign_stack_local (GET_MODE (regno_reg_rtx[i]), total_size);
  1359. #ifdef BYTES_BIG_ENDIAN
  1360.       /* Cancel the  big-endian correction done in assign_stack_local.
  1361.          Get the address of the beginning of the slot.
  1362.          This is so we can do a big-endian correction unconditionally
  1363.          below.  */
  1364.       x = gen_rtx (MEM, GET_MODE (regno_reg_rtx[i]),
  1365.                plus_constant (XEXP (x, 0),
  1366.                       inherent_size - total_size));
  1367. #endif
  1368.     }
  1369.       /* Reuse a stack slot if possible.  */
  1370.       else if (spill_stack_slot[from_reg] != 0
  1371.            && spill_stack_slot_width[from_reg] >= total_size
  1372.            && (GET_MODE_SIZE (GET_MODE (spill_stack_slot[from_reg]))
  1373.            >= inherent_size))
  1374.     x = spill_stack_slot[from_reg];
  1375.       /* Allocate a new or bigger slot.  */
  1376.       else
  1377.     {
  1378.       /* Compute maximum size needed, both for inherent size
  1379.          and for total size.  */
  1380.       enum machine_mode mode = GET_MODE (regno_reg_rtx[i]);
  1381.       if (spill_stack_slot[from_reg])
  1382.         {
  1383.           if (GET_MODE_SIZE (GET_MODE (spill_stack_slot[from_reg]))
  1384.           > inherent_size)
  1385.         mode = GET_MODE (spill_stack_slot[from_reg]);
  1386.           if (spill_stack_slot_width[from_reg] > total_size)
  1387.         total_size = spill_stack_slot_width[from_reg];
  1388.         }
  1389.       /* Make a slot with that size.  */
  1390.       x = assign_stack_local (mode, total_size);
  1391. #ifdef BYTES_BIG_ENDIAN
  1392.       /* Cancel the  big-endian correction done in assign_stack_local.
  1393.          Get the address of the beginning of the slot.
  1394.          This is so we can do a big-endian correction unconditionally
  1395.          below.  */
  1396.       x = gen_rtx (MEM, mode,
  1397.                plus_constant (XEXP (x, 0),
  1398.                       GET_MODE_SIZE (mode) - total_size));
  1399. #endif
  1400.       spill_stack_slot[from_reg] = x;
  1401.       spill_stack_slot_width[from_reg] = total_size;
  1402.     }
  1403.  
  1404. #ifdef BYTES_BIG_ENDIAN
  1405.       /* On a big endian machine, the "address" of the slot
  1406.      is the address of the low part that fits its inherent mode.  */
  1407.       if (inherent_size < total_size)
  1408.     x = gen_rtx (MEM, GET_MODE (regno_reg_rtx[i]),
  1409.              plus_constant (XEXP (x, 0),
  1410.                     total_size - inherent_size));
  1411. #endif /* BYTES_BIG_ENDIAN */
  1412.  
  1413.       addr = XEXP (x, 0);
  1414.  
  1415.       /* If the stack slot is directly addressable, substitute
  1416.      the MEM we just got directly for the old REG.
  1417.      Otherwise, record the address; we will generate hairy code
  1418.      to compute the address in a register each time it is needed.  */
  1419.       if (memory_address_p (GET_MODE (regno_reg_rtx[i]), addr))
  1420.     reg_equiv_mem[i] = x;
  1421.       else
  1422.     reg_equiv_address[i] = XEXP (x, 0);
  1423.     }
  1424. }
  1425.  
  1426. /* Mark the slots in regs_ever_live for the hard regs
  1427.    used by pseudo-reg number REGNO.  */
  1428.  
  1429. void
  1430. mark_home_live (regno)
  1431.      int regno;
  1432. {
  1433.   register int i, lim;
  1434.   i = reg_renumber[regno];
  1435.   if (i < 0)
  1436.     return;
  1437.   lim = i + HARD_REGNO_NREGS (i, PSEUDO_REGNO_MODE (regno));
  1438.   while (i < lim)
  1439.     regs_ever_live[i++] = 1;
  1440. }
  1441.  
  1442. /* Kick all pseudos out of hard register REGNO.
  1443.    If GLOBAL is nonzero, try to find someplace else to put them.
  1444.    If DUMPFILE is nonzero, log actions taken on that file.
  1445.  
  1446.    Return nonzero if any pseudos needed to be kicked out
  1447.    or if this hard reg may appear explicitly in some instructions.  */
  1448.  
  1449. static int
  1450. spill_hard_reg (regno, global, dumpfile)
  1451.      register int regno;
  1452.      int global;
  1453.      FILE *dumpfile;
  1454. {
  1455.   int something_changed = 0;
  1456.   register int i;
  1457.  
  1458.   /* Spill every pseudo reg that was allocated to this reg
  1459.      or to something that overlaps this reg.  */
  1460.  
  1461.   for (i = FIRST_PSEUDO_REGISTER; i < max_regno; i++)
  1462.     if (reg_renumber[i] >= 0
  1463.     && reg_renumber[i] <= regno
  1464.     && (reg_renumber[i] 
  1465.         + HARD_REGNO_NREGS (reg_renumber[i],
  1466.                 PSEUDO_REGNO_MODE (i))
  1467.         > regno))
  1468.       {
  1469.     /* If this register belongs solely to a basic block
  1470.        which needed no spilling, leave it be.  */
  1471.     if (regno != FRAME_POINTER_REGNUM
  1472.         && basic_block_needs
  1473.         && reg_basic_block[i] >= 0
  1474.         && basic_block_needs[reg_basic_block[i]] == 0)
  1475.       continue;
  1476.  
  1477.     /* Mark it as no longer having a hard register home.  */
  1478.     reg_renumber[i] = -1;
  1479.     /* We will need to scan everything again.  */
  1480.     something_changed = 1;
  1481.     if (global)
  1482.       {
  1483.         retry_global_alloc (i, forbidden_regs);
  1484.         /* Update regs_ever_live for new home (if any).  */
  1485.         mark_home_live (i);
  1486.         /* If something gets spilled to the stack,
  1487.            we must have a frame pointer, so spill the frame pointer.  */
  1488.         if (reg_renumber[i] == -1 && ! frame_pointer_needed)
  1489.           {
  1490.         frame_pointer_needed = 1;
  1491.         forbidden_regs[FRAME_POINTER_REGNUM] = 1;
  1492.         spill_hard_reg (FRAME_POINTER_REGNUM, global, dumpfile);
  1493.           }
  1494.       }
  1495.     alter_reg (i, regno);
  1496.     if (dumpfile)
  1497.       {
  1498.         if (reg_renumber[i] == -1)
  1499.           fprintf (dumpfile, " Register %d now on stack.\n\n", i);
  1500.         else
  1501.           fprintf (dumpfile, " Register %d now in %d.\n\n",
  1502.                i, reg_renumber[i]);
  1503.       }
  1504.       }
  1505.  
  1506.   return something_changed || regs_explicitly_used[i];
  1507. }
  1508.  
  1509. /* Find all paradoxical subregs within X and update reg_max_ref_width.  */
  1510.  
  1511. static rtx
  1512. scan_paradoxical_subregs (x)
  1513.      register rtx x;
  1514. {
  1515.   register int i;
  1516.   register char *fmt;
  1517.   register enum rtx_code code = GET_CODE (x);
  1518.  
  1519.   switch (code)
  1520.     {
  1521.     case CONST_INT:
  1522.     case CONST:
  1523.     case SYMBOL_REF:
  1524.     case LABEL_REF:
  1525.     case CONST_DOUBLE:
  1526.     case CC0:
  1527.     case PC:
  1528.     case REG:
  1529.     case USE:
  1530.     case CLOBBER:
  1531.       return;
  1532.  
  1533.     case SUBREG:
  1534.       if (GET_CODE (SUBREG_REG (x)) == REG
  1535.       && GET_MODE_SIZE (GET_MODE (x)) > GET_MODE_SIZE (GET_MODE (SUBREG_REG (x))))
  1536.     reg_max_ref_width[REGNO (SUBREG_REG (x))]
  1537.       = GET_MODE_SIZE (GET_MODE (x));
  1538.       return;
  1539.     }
  1540.  
  1541.   fmt = GET_RTX_FORMAT (code);
  1542.   for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
  1543.     {
  1544.       if (fmt[i] == 'e')
  1545.     scan_paradoxical_subregs (XEXP (x, i));
  1546.       else if (fmt[i] == 'E')
  1547.     {
  1548.       register int j;
  1549.       for (j = XVECLEN (x, i) - 1; j >=0; j--)
  1550.         scan_paradoxical_subregs (XVECEXP (x, i, j));
  1551.     }
  1552.     }
  1553. }
  1554.  
  1555. struct hard_reg_n_uses { int regno; int uses; };
  1556.  
  1557. static int
  1558. hard_reg_use_compare (p1, p2)
  1559.      struct hard_reg_n_uses *p1, *p2;
  1560. {
  1561.   int tem = p1->uses - p2->uses;
  1562.   if (tem != 0) return tem;
  1563.   /* If regs are equally good, sort by regno,
  1564.      so that the results of qsort leave nothing to chance.  */
  1565.   return p1->regno - p2->regno;
  1566. }
  1567.  
  1568. /* Choose the order to consider regs for use as reload registers
  1569.    based on how much trouble would be caused by spilling one.
  1570.    Store them in order of decreasing preference in potential_reload_regs.  */
  1571.  
  1572. static void
  1573. order_regs_for_reload ()
  1574. {
  1575.   register int i;
  1576.   register int o = 0;
  1577.   int large = 0;
  1578.  
  1579.   struct hard_reg_n_uses hard_reg_n_uses[FIRST_PSEUDO_REGISTER];
  1580.  
  1581.   for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
  1582.     potential_reload_regs[i] = -1;
  1583.  
  1584.   /* Count number of uses of each hard reg by pseudo regs allocated to it
  1585.      and then order them by decreasing use.  */
  1586.  
  1587.   for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
  1588.     {
  1589.       hard_reg_n_uses[i].uses = 0;
  1590.       hard_reg_n_uses[i].regno = i;
  1591.     }
  1592.  
  1593.   for (i = FIRST_PSEUDO_REGISTER; i < max_regno; i++)
  1594.     {
  1595.       if (reg_renumber[i] >= 0)
  1596.     hard_reg_n_uses[reg_renumber[i]].uses += reg_n_refs[i];
  1597.       large += reg_n_refs[i];
  1598.     }
  1599.  
  1600.   /* Now fixed registers (which cannot safely be used for reloading)
  1601.      get a very high use count so they will be considered least desirable.
  1602.      Registers used explicitly in the rtl code are almost as bad.  */
  1603.  
  1604.   for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
  1605.     {
  1606.       if (fixed_regs[i])
  1607.     hard_reg_n_uses[i].uses += large + 2;
  1608.       else if (regs_explicitly_used[i])
  1609.     hard_reg_n_uses[i].uses += large + 1;
  1610.     }
  1611.   hard_reg_n_uses[FRAME_POINTER_REGNUM].uses += large + 2;
  1612.  
  1613.   qsort (hard_reg_n_uses, FIRST_PSEUDO_REGISTER,
  1614.      sizeof hard_reg_n_uses[0], hard_reg_use_compare);
  1615.  
  1616.   /* Prefer registers not so far used, for use in temporary loading.
  1617.      Among them, prefer registers not preserved by calls.  */
  1618.  
  1619.   for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
  1620.     {
  1621. #ifdef REG_ALLOC_ORDER
  1622.       int regno = reg_alloc_order[i];
  1623. #else
  1624.       int regno = i;
  1625. #endif
  1626.       if (regs_ever_live[regno] == 0 && call_used_regs[regno]
  1627.       && ! fixed_regs[regno])
  1628.     potential_reload_regs[o++] = regno;
  1629.     }
  1630.  
  1631.   for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
  1632.     {
  1633. #ifdef REG_ALLOC_ORDER
  1634.       int regno = reg_alloc_order[i];
  1635. #else
  1636.       int regno = i;
  1637. #endif
  1638.       if (regs_ever_live[regno] == 0 && ! call_used_regs[regno]
  1639.       && regno != FRAME_POINTER_REGNUM)
  1640.     potential_reload_regs[o++] = regno;
  1641.     }
  1642.  
  1643.   /* Now add the regs that are already used,
  1644.      preferring those used less often.  */
  1645.  
  1646.   for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
  1647.     if (regs_ever_live[hard_reg_n_uses[i].regno] != 0)
  1648.       potential_reload_regs[o++] = hard_reg_n_uses[i].regno;
  1649.  
  1650. #if 0
  1651.   /* For regs that are used, don't prefer those not preserved by calls
  1652.      because those are likely to contain high priority things
  1653.      that are live for short periods of time.  */
  1654.  
  1655.   for (i = FIRST_PSEUDO_REGISTER - 1; i >= 0; i--)
  1656.     if (regs_ever_live[i] != 0 && ! call_used_regs[i])
  1657.       potential_reload_regs[o++] = i;
  1658. #endif
  1659. }
  1660.  
  1661. /* Reload pseudo-registers into hard regs around each insn as needed.
  1662.    Additional register load insns are output before the insn that needs it
  1663.    and perhaps store insns after insns that modify the reloaded pseudo reg.
  1664.  
  1665.    reg_last_reload_reg and reg_reloaded_contents keep track of
  1666.    which pseudo-registers are already available in reload registers.
  1667.    We update these for the reloads that we perform,
  1668.    as the insns are scanned.  */
  1669.  
  1670. static void
  1671. reload_as_needed (first, live_known)
  1672.      rtx first;
  1673.      int live_known;
  1674. {
  1675.   register rtx insn;
  1676.   register int i;
  1677.   int this_block = 0;
  1678.   rtx x;
  1679.  
  1680.   bzero (spill_reg_rtx, sizeof spill_reg_rtx);
  1681.   reg_last_reload_reg = (rtx *) alloca (max_regno * sizeof (rtx));
  1682.   bzero (reg_last_reload_reg, max_regno * sizeof (rtx));
  1683.   reg_has_output_reload = (char *) alloca (max_regno);
  1684.   for (i = 0; i < n_spills; i++)
  1685.     reg_reloaded_contents[i] = -1;
  1686.  
  1687.   for (insn = first; insn;)
  1688.     {
  1689.       register rtx next = NEXT_INSN (insn);
  1690.  
  1691.       /* Notice when we move to a new basic block.  */
  1692.       if (basic_block_needs && this_block + 1 < n_basic_blocks
  1693.       && insn == basic_block_head[this_block+1])
  1694.     ++this_block;
  1695.  
  1696.       if (GET_CODE (insn) == INSN || GET_CODE (insn) == JUMP_INSN
  1697.       || GET_CODE (insn) == CALL_INSN)
  1698.     {
  1699.       /* If insn has no reloads, we want these to be zero, down below.  */
  1700.       bzero (reg_has_output_reload, max_regno);
  1701.       bzero (reg_is_output_reload, FIRST_PSEUDO_REGISTER);
  1702.  
  1703.       if (GET_MODE (insn) == VOIDmode)
  1704.         n_reloads = 0;
  1705.       /* First find the pseudo regs that must be reloaded for this insn.
  1706.          This info is returned in the tables reload_... (see reload.h).
  1707.          Also modify the body of INSN by substituting RELOAD
  1708.          rtx's for those pseudo regs.  */
  1709.       else
  1710.         find_reloads (insn, 1, spill_indirect_ok, live_known, spill_reg_order);
  1711.  
  1712.       if (n_reloads > 0)
  1713.         {
  1714.           /* If this block has not had spilling done,
  1715.          deactivate any optional reloads lest they
  1716.          try to use a spill-reg which isn't available here.
  1717.          If we have any non-optionals that need a spill reg, abort.  */
  1718.           if (basic_block_needs != 0
  1719.           && basic_block_needs[this_block] == 0)
  1720.         {
  1721.           for (i = 0; i < n_reloads; i++)
  1722.             {
  1723.               if (reload_optional[i])
  1724.             reload_in[i] = reload_out[i] = 0;
  1725.               else if (reload_reg_rtx[i] == 0)
  1726.             abort ();
  1727.             }
  1728.         }
  1729.  
  1730.           /* Now compute which reload regs to reload them into.  Perhaps
  1731.          reusing reload regs from previous insns, or else output
  1732.          load insns to reload them.  Maybe output store insns too.
  1733.          Record the choices of reload reg in reload_reg_rtx.  */
  1734.           choose_reload_regs (insn);
  1735.  
  1736.           /* Generate the insns to reload operands into or out of
  1737.          their reload regs.  */
  1738.           emit_reload_insns (insn);
  1739.  
  1740.           /* Substitute the chosen reload regs from reload_reg_rtx
  1741.          into the insn's body (or perhaps into the bodies of other
  1742.          load and store insn that we just made for reloading
  1743.          and that we moved the structure into).  */
  1744.           subst_reloads ();
  1745.         }
  1746.       /* Any previously reloaded spilled pseudo reg, stored in this insn,
  1747.          is no longer validly lying around to save a future reload.
  1748.          Note that this does not detect pseudos that were reloaded
  1749.          for this insn in order to be stored in
  1750.          (obeying register constraints).  That is correct; such reload
  1751.          registers ARE still valid.  */
  1752.       note_stores (PATTERN (insn), forget_old_reloads_1);
  1753.  
  1754.       /* Likewise for regs altered by auto-increment in this insn.
  1755.          But note that the reg-notes are not changed by reloading:
  1756.          they still contain the pseudo-regs, not the spill regs.  */
  1757.       for (x = REG_NOTES (insn); x; x = XEXP (x, 1))
  1758.         if (REG_NOTE_KIND (x) == REG_INC)
  1759.           {
  1760.         /* See if this pseudo reg was reloaded in this insn.
  1761.            If so, its last-reload info is still valid
  1762.            because it is based on this insn's reload.  */
  1763.         for (i = 0; i < n_reloads; i++)
  1764.           if (reload_out[i] == XEXP (x, 0))
  1765.             break;
  1766.  
  1767.         if (i != n_reloads)
  1768.           forget_old_reloads_1 (XEXP (x, 0));
  1769.           }
  1770.     }
  1771.       /* A reload reg's contents are unknown after a label.  */
  1772.       if (GET_CODE (insn) == CODE_LABEL)
  1773.     for (i = 0; i < n_spills; i++)
  1774.       reg_reloaded_contents[i] = -1;
  1775.  
  1776.       /* Don't assume a reload reg is still good after a call insn
  1777.      if it is a call-used reg.  */
  1778.       if (GET_CODE (insn) == CODE_LABEL || GET_CODE (insn) == CALL_INSN)
  1779.     for (i = 0; i < n_spills; i++)
  1780.       if (call_used_regs[spill_regs[i]])
  1781.         reg_reloaded_contents[i] = -1;
  1782.  
  1783.       /* In case registers overlap, allow certain insns to invalidate
  1784.      particular hard registers.  */
  1785.  
  1786. #ifdef INSN_CLOBBERS_REGNO_P
  1787.       for (i = 0 ; i < n_spills ; i++)
  1788.     if (INSN_CLOBBERS_REGNO_P (insn, spill_regs[i]))
  1789.       reg_reloaded_contents[i] = -1;
  1790. #endif
  1791.  
  1792.       insn = next;
  1793.  
  1794. #ifdef USE_C_ALLOCA
  1795.       alloca (0);
  1796. #endif
  1797.     }
  1798. }
  1799.  
  1800. /* Discard all record of any value reloaded from X,
  1801.    or reloaded in X from someplace else;
  1802.    unless X is an output reload reg of the current insn.
  1803.  
  1804.    X may be a hard reg (the reload reg)
  1805.    or it may be a pseudo reg that was reloaded from.
  1806.  
  1807.    This function is not called for instructions generated by reload.  */
  1808.  
  1809. static void
  1810. forget_old_reloads_1 (x)
  1811.      rtx x;
  1812. {
  1813.   register int regno;
  1814.   int nr;
  1815.  
  1816.   if (GET_CODE (x) != REG)
  1817.     return;
  1818.  
  1819.   regno = REGNO (x);
  1820.  
  1821.   if (regno >= FIRST_PSEUDO_REGISTER)
  1822.     nr = 1;
  1823.   else
  1824.     {
  1825.       int i;
  1826.       nr = HARD_REGNO_NREGS (regno, GET_MODE (x));
  1827.       /* Storing into a spilled-reg invalidates its contents.
  1828.      This can happen if a block-local pseudo is allocated to that reg
  1829.      and it wasn't spilled because this block's total need is 0.
  1830.      Then some insn might have an optional reload and use this reg.  */
  1831.       for (i = 0; i < nr; i++)
  1832.     if (spill_reg_order[regno + i] >= 0
  1833.         /* But don't do this if the reg actually serves as an output
  1834.            reload reg in the current instruction.  */
  1835.         && reg_is_output_reload[regno + i] == 0)
  1836.       reg_reloaded_contents[spill_reg_order[regno + i]] = -1;
  1837.     }
  1838.  
  1839.   /* Since value of X has changed,
  1840.      forget any value previously copied from it.  */
  1841.  
  1842.   while (nr-- > 0)
  1843.     /* But don't forget a copy if this is the output reload
  1844.        that establishes the copy's validity.  */
  1845.     if (reg_has_output_reload[regno + nr] == 0)
  1846.       reg_last_reload_reg[regno + nr] = 0;
  1847. }
  1848.  
  1849. /* Comparison function for qsort to decide which of two reloads
  1850.    should be handled first.  *P1 and *P2 are the reload numbers.  */
  1851.  
  1852. static int
  1853. reload_reg_class_lower (p1, p2)
  1854.      short *p1, *p2;
  1855. {
  1856.   register int r1 = *p1, r2 = *p2;
  1857.   register int t;
  1858.   register enum machine_mode mode1, mode2;
  1859.   
  1860.   /* Consider required reloads before optional ones.  */
  1861.   t = reload_optional[r1] - reload_optional[r2];
  1862.   if (t != 0)
  1863.     return t;
  1864.   /* Consider all multi-reg groups first.
  1865.      This is safe because `reload' fills all group-need before
  1866.      filling all non-group need.  */
  1867.   mode1 = (reload_inmode[r1] == VOIDmode ? reload_outmode[r1] : reload_inmode[r1]);
  1868.   mode2 = (reload_inmode[r2] == VOIDmode ? reload_outmode[r2] : reload_inmode[r2]);
  1869.   t = (CLASS_MAX_NREGS (reload_reg_class[r2], mode2)
  1870.        - CLASS_MAX_NREGS (reload_reg_class[r1], mode1));
  1871.   if (t != 0)
  1872.     return t;
  1873.   /* Consider reloads in order of increasing reg-class number.  */
  1874.   t = (int) reload_reg_class[r1] - (int) reload_reg_class[r2];
  1875.   if (t != 0) return t;
  1876.   /* If reloads are equally urgent, sort by reload number,
  1877.      so that the results of qsort leave nothing to chance.  */
  1878.   return r1 - r2;
  1879. }
  1880.  
  1881. /* The following tables are indexed by register number,
  1882.    not by spill_regs index.  */
  1883.  
  1884. /* 1 if reg is in use as a reload reg for a RELOAD_OTHER reload.  */
  1885. static char reload_reg_in_use[FIRST_PSEUDO_REGISTER];
  1886. /* 1 if reg is in use for a RELOAD_FOR_INPUT_RELOAD_ADDRESS reload.  */
  1887. static char reload_reg_in_use_for_inputs[FIRST_PSEUDO_REGISTER];
  1888. /* 1 if reg is in use for a RELOAD_FOR_OUTPUT_RELOAD_ADDRESS reload.  */
  1889. static char reload_reg_in_use_for_outputs[FIRST_PSEUDO_REGISTER];
  1890. /* 1 if reg is in use for a RELOAD_FOR_OPERAND_ADDRESS reload.  */
  1891. static char reload_reg_in_use_for_operands[FIRST_PSEUDO_REGISTER];
  1892.  
  1893. /* 1 if reg is in use as a reload reg for any sort of reload.  */
  1894. static char reload_reg_in_use_at_all[FIRST_PSEUDO_REGISTER];
  1895.  
  1896. /* Mark reg REGNO as in use for a reload of the sort spec'd by WHEN_NEEDED.  */
  1897.  
  1898. static void
  1899. mark_reload_reg_in_use (regno, when_needed)
  1900.      int regno;
  1901.      enum reload_when_needed when_needed;
  1902. {
  1903.   switch (when_needed)
  1904.     {
  1905.     case RELOAD_OTHER:
  1906.       reload_reg_in_use[regno] = 1;
  1907.       break;
  1908.  
  1909.     case RELOAD_FOR_INPUT_RELOAD_ADDRESS:
  1910.       reload_reg_in_use_for_inputs[regno] = 1;
  1911.       break;
  1912.  
  1913.     case RELOAD_FOR_OUTPUT_RELOAD_ADDRESS:
  1914.       reload_reg_in_use_for_outputs[regno] = 1;
  1915.       break;
  1916.  
  1917.     case RELOAD_FOR_OPERAND_ADDRESS:
  1918.       reload_reg_in_use_for_operands[regno] = 1;
  1919.       break;
  1920.     }
  1921.   reload_reg_in_use_at_all[regno] = 1;
  1922. }
  1923.  
  1924. /* 1 if reg REGNO is free as a reload reg for a reload of the sort
  1925.    specified by WHEN_NEEDED.  */
  1926.  
  1927. static int
  1928. reload_reg_free_p (regno, when_needed)
  1929.      int regno;
  1930.      enum reload_when_needed when_needed;
  1931. {
  1932.   /* In use for a RELOAD_OTHER means it's not available for anything.  */
  1933.   if (reload_reg_in_use[regno])
  1934.     return 0;
  1935.   switch (when_needed)
  1936.     {
  1937.     case RELOAD_OTHER:
  1938.       /* In use for anything means not available for a RELOAD_OTHER.  */
  1939.       return ! reload_reg_in_use_at_all[regno];
  1940.  
  1941.       /* The other three kinds of use can share a register.  */
  1942.     case RELOAD_FOR_INPUT_RELOAD_ADDRESS:
  1943.       return ! reload_reg_in_use_for_inputs[regno];
  1944.     case RELOAD_FOR_OUTPUT_RELOAD_ADDRESS:
  1945.       return ! reload_reg_in_use_for_outputs[regno];
  1946.     case RELOAD_FOR_OPERAND_ADDRESS:
  1947.       return ! reload_reg_in_use_for_operands[regno];
  1948.     }
  1949. }
  1950.  
  1951. /* Return 1 if the value in reload reg REGNO, as used by a reload
  1952.    needed for the part of the insn specified by WHEN_NEEDED,
  1953.    is not in use for a reload in any prior part of the insn.  */
  1954.  
  1955. static int
  1956. reload_reg_free_before_p (regno, when_needed)
  1957.      int regno;
  1958.      enum reload_when_needed when_needed;
  1959. {
  1960.   switch (when_needed)
  1961.     {
  1962.     case RELOAD_OTHER:
  1963.       /* Since a RELOAD_OTHER reload claims the reg for the entire insn,
  1964.      its use starts from the beginning, so nothing can use it earlier.  */
  1965.       return 1;
  1966.  
  1967.       /* If this use is for part of the insn,
  1968.      check the reg is not in use for any prior part.  */
  1969.     case RELOAD_FOR_OUTPUT_RELOAD_ADDRESS:
  1970.       if (reload_reg_in_use_for_operands[regno])
  1971.     return 0;
  1972.     case RELOAD_FOR_OPERAND_ADDRESS:
  1973.       if (reload_reg_in_use_for_inputs[regno])
  1974.     return 0;
  1975.     case RELOAD_FOR_INPUT_RELOAD_ADDRESS:
  1976.       return 1;
  1977.     }
  1978. }
  1979.  
  1980. /* Return 1 if the value in reload reg REGNO, as used by a reload
  1981.    needed for the part of the insn specified by WHEN_NEEDED,
  1982.    is still available in REGNO at the end of the insn.  */
  1983.  
  1984. static int
  1985. reload_reg_reaches_end_p (regno, when_needed)
  1986.      int regno;
  1987.      enum reload_when_needed when_needed;
  1988. {
  1989.   switch (when_needed)
  1990.     {
  1991.     case RELOAD_OTHER:
  1992.       /* Since a RELOAD_OTHER reload claims the reg for the entire insn,
  1993.      its value must reach the end.  */
  1994.       return 1;
  1995.  
  1996.       /* If this use is for part of the insn,
  1997.      its value reaches if no subsequent part uses the same register.  */
  1998.     case RELOAD_FOR_INPUT_RELOAD_ADDRESS:
  1999.       if (reload_reg_in_use_for_operands[regno])
  2000.     return 0;
  2001.     case RELOAD_FOR_OPERAND_ADDRESS:
  2002.       if (reload_reg_in_use_for_outputs[regno])
  2003.     return 0;
  2004.     case RELOAD_FOR_OUTPUT_RELOAD_ADDRESS:
  2005.       return 1;
  2006.     }
  2007. }
  2008.  
  2009. /* Vector of reload-numbers showing the order in which the reloads should
  2010.    be processed.  */
  2011. short reload_order[MAX_RELOADS];
  2012.  
  2013. /* Indexed by reload number, 1 if incoming value
  2014.    inherited from previous insns.  */
  2015. char reload_inherited[MAX_RELOADS];
  2016.  
  2017. /* If non-zero, this is a place to get the value of the reload,
  2018.    rather than using reload_in.  */
  2019. rtx reload_override_in[MAX_RELOADS];
  2020.  
  2021. /* For each reload, the index in spill_regs of the spill register used,
  2022.    or -1 if we did not need one of the spill registers for this reload.  */
  2023. int reload_spill_index[MAX_RELOADS];
  2024.  
  2025. /* Assign hard reg targets for the pseudo-registers we must reload
  2026.    into hard regs for this insn.
  2027.    Also output the instructions to copy them in and out of the hard regs.
  2028.  
  2029.    For machines with register classes, we are responsible for
  2030.    finding a reload reg in the proper class.  */
  2031.  
  2032. static void
  2033. choose_reload_regs (insn)
  2034.      rtx insn;
  2035. {
  2036.   register int j;
  2037.   int have_groups = 0;
  2038.   /* Non-zero means we must reuse spill regs for multiple reloads in this insn
  2039.      or we will not have enough spill regs.  */
  2040.   int must_reuse = 0;
  2041.   rtx original_reload_reg_rtx[MAX_RELOADS];
  2042.  
  2043.   /* See if we have more mandatory reloads than spill regs.
  2044.      If so, then we cannot risk optimizations that could prevent
  2045.      reloads from sharing one spill register.  */
  2046.  
  2047.   {
  2048.     int tem = 0;
  2049.     for (j = 0; j < n_reloads; j++)
  2050.       if (! reload_optional[j] && reload_reg_rtx[j] == 0)
  2051.     tem++;
  2052.     if (tem > n_spills)
  2053.       must_reuse = 1;
  2054.   }
  2055.  
  2056.   bcopy (reload_reg_rtx, original_reload_reg_rtx, sizeof (reload_reg_rtx));
  2057.  
  2058.   /* If we fail to get enough regs without must_reuse,
  2059.      set must_reuse and jump back here.  */
  2060.  retry:
  2061.   bzero (reload_inherited, MAX_RELOADS);
  2062.   bzero (reload_override_in, MAX_RELOADS * sizeof (rtx));
  2063.   bzero (reload_reg_in_use, FIRST_PSEUDO_REGISTER);
  2064.   bzero (reload_reg_in_use_at_all, FIRST_PSEUDO_REGISTER);
  2065.   bzero (reload_reg_in_use_for_inputs, FIRST_PSEUDO_REGISTER);
  2066.   bzero (reload_reg_in_use_for_outputs, FIRST_PSEUDO_REGISTER);
  2067.   bzero (reload_reg_in_use_for_operands, FIRST_PSEUDO_REGISTER);
  2068.  
  2069.   /* In order to be certain of getting the registers we need,
  2070.      we must sort the reloads into order of increasing register class.
  2071.      Then our grabbing of reload registers will parallel the process
  2072.      that provided the reload registers.  */
  2073.  
  2074.   /* Also note whether any of the reloads wants a consecutive group of regs.
  2075.      When that happens, we must when processing the non-group reloads
  2076.      avoid (when possible) using a reload reg that would break up a group.  */
  2077.  
  2078.   /* This used to look for an existing reloaded home for all
  2079.      of the reloads, and only then perform any new reloads.
  2080.      But that could lose if the reloads were done out of reg-class order
  2081.      because a later reload with a looser constraint might have an old
  2082.      home in a register needed by an earlier reload with a tighter constraint.
  2083.      It would be possible with even hairier code to detect such cases
  2084.      and handle them, but it doesn't seem worth while yet.  */
  2085.  
  2086.   for (j = 0; j < n_reloads; j++)
  2087.     {
  2088.       enum machine_mode mode;
  2089.       reload_order[j] = j;
  2090.       reload_spill_index[j] = -1;
  2091.       mode = (reload_inmode[j] == VOIDmode
  2092.           || GET_MODE_SIZE (reload_outmode[j]) > GET_MODE_SIZE (reload_inmode[j])
  2093.           ? reload_outmode[j] : reload_inmode[j]);
  2094.  
  2095.       if (CLASS_MAX_NREGS (reload_reg_class[j], mode) > 1)
  2096.     have_groups = 1;
  2097.       /* If we have already decided to use a certain register,
  2098.      don't use it in another way.  */
  2099.       if (reload_reg_rtx[j])
  2100.     mark_reload_reg_in_use (REGNO (reload_reg_rtx[j]), reload_when_needed[j]);
  2101.     }
  2102.  
  2103.   if (n_reloads > 1)
  2104.     qsort (reload_order, n_reloads, sizeof (short), reload_reg_class_lower);
  2105.  
  2106.   for (j = 0; j < n_reloads; j++)
  2107.     {
  2108.       register int r = reload_order[j];
  2109.       register int i;
  2110.       register rtx new;
  2111.       enum machine_mode reload_mode = reload_inmode[r];
  2112.       int h1_ok, h2_ok, h3_ok;
  2113.  
  2114.       /* Ignore reloads that got marked inoperative.  */
  2115.       if (reload_out[r] == 0 && reload_in[r] == 0)
  2116.     continue;
  2117.  
  2118.       if (GET_MODE_SIZE (reload_outmode[r]) > GET_MODE_SIZE (reload_mode))
  2119.     reload_mode = reload_outmode[r];
  2120.       if (reload_strict_low[r])
  2121.     reload_mode = GET_MODE (SUBREG_REG (reload_out[r]));
  2122.  
  2123.       /* No need to find a reload-register if find_reloads chose one.  */
  2124.  
  2125.       if (reload_reg_rtx[r] != 0)
  2126.     continue;
  2127.  
  2128.       /* First see if this pseudo is already available as reloaded
  2129.      for a previous insn.
  2130.      This feature is disabled for multi-register groups
  2131.      because we haven't yet any way to tell whether the entire
  2132.      value is properly preserved.
  2133.      It is also disabled when there are other reloads for mult-register
  2134.      groups, lest the inherited reload reg break up a needed group.  */
  2135.  
  2136.       {
  2137.     register int regno = -1;
  2138.  
  2139.     if (reload_in[r] == 0)
  2140.       ;
  2141.     else if (GET_CODE (reload_in[r]) == REG)
  2142.       regno = REGNO (reload_in[r]);
  2143.     else if (GET_CODE (reload_in_reg[r]) == REG)
  2144.       regno = REGNO (reload_in_reg[r]);
  2145. #if 0
  2146.     /* This won't work, since REGNO can be a pseudo reg number.
  2147.        Also, it takes much more hair to keep track of all the things
  2148.        that can invalidate an inherited reload of part of a pseudoreg.  */
  2149.     else if (GET_CODE (reload_in[r]) == SUBREG
  2150.          && GET_CODE (SUBREG_REG (reload_in[r])) == REG)
  2151.       regno = REGNO (SUBREG_REG (reload_in[r])) + SUBREG_WORD (reload_in[r]);
  2152. #endif
  2153.  
  2154.     if (regno >= 0
  2155.         && reg_last_reload_reg[regno] != 0
  2156.         && ! have_groups
  2157.         /* See comment at next use of must_reuse.  */
  2158.         && ! must_reuse)
  2159.       {
  2160.         i = spill_reg_order[REGNO (reg_last_reload_reg[regno])];
  2161.  
  2162.         if (reg_reloaded_contents[i] == regno
  2163.         && HARD_REGNO_MODE_OK (spill_regs[i], reload_mode)
  2164.         && TEST_HARD_REG_BIT (reg_class_contents[(int) reload_reg_class[r]],
  2165.                       spill_regs[i])
  2166.         && reload_reg_free_p (spill_regs[i], reload_when_needed[r])
  2167.         && reload_reg_free_before_p (spill_regs[i],
  2168.                          reload_when_needed[r]))
  2169.           {
  2170.         /* Mark the register as in use for this part of the insn.  */
  2171.         mark_reload_reg_in_use (spill_regs[i], reload_when_needed[r]);
  2172.         reload_reg_rtx[r] = reg_last_reload_reg[regno];
  2173.         reload_inherited[r] = 1;
  2174.         reload_spill_index[r] = i;
  2175.           }
  2176.       }
  2177.       }
  2178.  
  2179.       /* Here's another way to see if the value is already lying around.  */
  2180.       if (reload_in[r] != 0
  2181.       && reload_reg_rtx[r] == 0
  2182.       && reload_out[r] == 0
  2183.       && (CONSTANT_P (reload_in[r])
  2184.           || GET_CODE (reload_in[r]) == PLUS
  2185.           || GET_CODE (reload_in[r]) == REG
  2186.           || GET_CODE (reload_in[r]) == MEM)
  2187.       && ! have_groups
  2188.       /* This optimization can prevent this reload from reusing
  2189.          a spill reg used for another reload.  That could take away
  2190.          a spill reg that another reload will need.  If we cannot
  2191.          be sure there will still be enough spill regs,
  2192.          don't do this optimization.  */
  2193.       && ! must_reuse)
  2194.     {
  2195.       register rtx equiv
  2196.         = find_equiv_reg (reload_in[r], insn, reload_reg_class[r],
  2197.                   -1, 0, 0, reload_mode);
  2198.       int regno;
  2199.  
  2200.       if (equiv != 0)
  2201.         regno = REGNO (equiv);
  2202.  
  2203.       /* If we found a spill reg, reject it unless it is free
  2204.          and of the desired class.  */
  2205.       if (equiv != 0 && GET_CODE (equiv) == REG
  2206.           && spill_reg_order[regno] >= 0
  2207.           && reload_reg_free_before_p (regno, reload_when_needed[r]))
  2208.         {
  2209.           if (! TEST_HARD_REG_BIT (reg_class_contents[(int) reload_reg_class[r]],
  2210.                        regno))
  2211.         equiv = 0;
  2212.         }
  2213.  
  2214.       if (equiv != 0 && reload_reg_in_use_at_all[regno])
  2215.         equiv = 0;
  2216.  
  2217.       if (equiv != 0 && ! HARD_REGNO_MODE_OK (regno, reload_mode))
  2218.         equiv = 0;
  2219.  
  2220.       /* We found a register that contains the value we need.
  2221.          If this register is the same as an `earlyclobber' operand
  2222.          of the current insn, just mark it as a place to reload from
  2223.          since we can't use it as the reload register itself.  */
  2224.  
  2225.       if (equiv != 0)
  2226.         for (i = 0; i < n_earlyclobbers; i++)
  2227.           if (reg_overlap_mentioned_p (equiv, reload_earlyclobbers[i]))
  2228.         {
  2229.           reload_override_in[r] = equiv;
  2230.           equiv = 0;
  2231.           break;
  2232.         }
  2233.  
  2234.       /* If we found an equivalent reg, say no code need be generated
  2235.          to load it, and use it as our reload reg.  */
  2236.       if (equiv != 0
  2237.           && REGNO (equiv) != FRAME_POINTER_REGNUM)
  2238.         {
  2239.           reload_reg_rtx[r] = equiv;
  2240.           reload_inherited[r] = 1;
  2241.           /* If it is a spill reg,
  2242.          mark the spill reg as in use for this insn.  */
  2243.           i = spill_reg_order[REGNO (equiv)];
  2244.           if (i >= 0)
  2245.         {
  2246.           int nr = HARD_REGNO_NREGS (spill_regs[i], reload_mode);
  2247.           while (nr > 0)
  2248.             mark_reload_reg_in_use (REGNO (equiv) + --nr,
  2249.                         reload_when_needed[r]);
  2250.         }
  2251.         }
  2252.     }
  2253.  
  2254.       /* If it isn't lying around, and isn't optional,
  2255.      find a place to reload it into.  */
  2256.       if (reload_reg_rtx[r] != 0 || reload_optional[r] != 0)
  2257.     continue;
  2258.  
  2259.       /* Value not lying around; find a register to reload it into.
  2260.      Here I is not a regno, it is an index into spill_regs.  */
  2261.       i = n_spills;
  2262.  
  2263. #if 0
  2264.       /* The following is no longer needed now that all multi-register
  2265.      (group) reloads are processed before all solitary register reloads
  2266.      (due to changes in `reg_class_lower_p' and `reload'.  */
  2267.       /* The following also fails to test HARD_REGNO_MODE_OK appropriately,
  2268.      which was hard to fix because we don't know the mode that the
  2269.      group might have that would want this register.  */
  2270.  
  2271.       /* If we want just one reg, and other reloads want groups,
  2272.      first try to find a reg that can't be part of a group.  */
  2273.       if (have_groups
  2274.       && CLASS_MAX_NREGS (reload_reg_class[r], reload_mode) == 1)
  2275.     for (i = 0; i < n_spills; i++)
  2276.       {
  2277.         int regno = spill_regs[i];
  2278.         int class = (int) reload_reg_class[r];
  2279.         if (reload_reg_in_use_at_all[regno] == 0
  2280.         && TEST_HARD_REG_BIT (reg_class_contents[class],
  2281.                       regno)
  2282.         && !(regno + 1 < FIRST_PSEUDO_REGISTER
  2283.              && spill_reg_order[regno + 1] >= 0
  2284.              && reload_reg_in_use_at_all[regno + 1] == 0
  2285.              && TEST_HARD_REG_BIT (reg_class_contents[class],
  2286.                        regno + 1))
  2287.         && !(regno > 0
  2288.              && spill_reg_order[regno - 1] >= 0
  2289.              && reload_reg_in_use_at_all[regno - 1] == 0
  2290.              && TEST_HARD_REG_BIT (reg_class_contents[class],
  2291.                        regno - 1)))
  2292.           break;
  2293.       }
  2294.  
  2295.       /* If that didn't work, try to find a register that has only one
  2296.      neighbor that could make a group with it.  That way, if the
  2297.      available registers are three consecutive ones, we avoid taking
  2298.      the middle one (which would leave us with no possible groups).  */
  2299.  
  2300.       if (have_groups
  2301.       && CLASS_MAX_NREGS (reload_reg_class[r], reload_mode) == 1
  2302.       && i == n_spills)
  2303.     for (i = 0; i < n_spills; i++)
  2304.       {
  2305.         int regno = spill_regs[i];
  2306.         int class = (int) reload_reg_class[r];
  2307.         if (reload_reg_in_use_at_all[regno] == 0
  2308.         && TEST_HARD_REG_BIT (reg_class_contents[class],
  2309.                       regno)
  2310.         && (!(regno + 1 < FIRST_PSEUDO_REGISTER
  2311.               && spill_reg_order[regno + 1] >= 0
  2312.               && reload_reg_in_use_at_all[regno + 1] == 0
  2313.               && TEST_HARD_REG_BIT (reg_class_contents[class],
  2314.                         regno + 1))
  2315.             || !(regno > 0
  2316.              && spill_reg_order[regno - 1] >= 0
  2317.              && reload_reg_in_use_at_all[regno - 1] == 0
  2318.              && TEST_HARD_REG_BIT (reg_class_contents[class],
  2319.                            regno - 1))))
  2320.           break;
  2321.       }
  2322. #endif
  2323.  
  2324.       /* Now, if we want a single register and haven't yet found one,
  2325.      take any reg in the right class and not in use.
  2326.      If we want a consecutive group, here is where we look for it.  */
  2327.       if (i == n_spills)
  2328.     {
  2329.       int pass;
  2330.       /* If we put this reload ahead, thinking it is a group,
  2331.          then insist on finding a group.  Otherwise we can grab a
  2332.          reg that some other reload needs. 
  2333.          (That can happen when we have a 68000 DATA_OR_FP_REG
  2334.          which is a group of data regs or one fp reg.)
  2335.          ??? Really it would be nicer to have smarter handling
  2336.          for that kind of reg class, where a problem like this is normal.
  2337.          Perhaps those classes should be avoided for reloading
  2338.          by use of more alternatives.  */
  2339.       int force_group
  2340.         = (CLASS_MAX_NREGS (reload_reg_class[r], reload_mode) > 1);
  2341.       /* We need not be so restrictive if there are no more reloads
  2342.          for this insn.  */
  2343.       if (j + 1 == n_reloads)
  2344.         force_group = 0;
  2345.  
  2346.       for (pass = 0; pass < 2; pass++)
  2347.         {
  2348.           for (i = 0; i < n_spills; i++)
  2349.         {
  2350.           int class = (int) reload_reg_class[r];
  2351.           if (reload_reg_free_p (spill_regs[i], reload_when_needed[r])
  2352.               && TEST_HARD_REG_BIT (reg_class_contents[class],
  2353.                         spill_regs[i])
  2354.               /* Look first for regs to share, then for unshared.  */
  2355.               && (pass || reload_reg_in_use_at_all[spill_regs[i]]))
  2356.             {
  2357.               int nr = HARD_REGNO_NREGS (spill_regs[i], reload_mode);
  2358.               /* Avoid the problem where spilling a GENERAL_OR_FP_REG
  2359.              (on 68000) got us two FP regs.  If NR is 1,
  2360.              we would reject both of them.  */
  2361.               if (force_group)
  2362.             nr = CLASS_MAX_NREGS (reload_reg_class[r], reload_mode);
  2363.               /* If we need only one reg, we have already won.  */
  2364.               if (nr == 1)
  2365.             {
  2366.               /* But reject a single reg if we demand a group.  */
  2367.               if (force_group)
  2368.                 continue;
  2369.               break;
  2370.             }
  2371.               /* Otherwise check that as many consecutive regs as we need
  2372.              are available here.
  2373.              Also, don't use for a group registers that are
  2374.              needed for nongroups.  */
  2375.               if (HARD_REGNO_MODE_OK (spill_regs[i], reload_mode)
  2376.               && ! counted_for_nongroups[spill_regs[i]])
  2377.             while (nr > 1)
  2378.               {
  2379.                 int regno = spill_regs[i] + nr - 1;
  2380.                 if (!(TEST_HARD_REG_BIT (reg_class_contents[class],
  2381.                              regno)
  2382.                   && spill_reg_order[regno] >= 0
  2383.                   && reload_reg_free_p (regno, reload_when_needed[r])
  2384.                   && ! counted_for_nongroups[regno]))
  2385.                   break;
  2386.                 nr--;
  2387.               }
  2388.               if (nr == 1)
  2389.             break;
  2390.             }
  2391.         }
  2392.           /* If find something on pass 1, omit pass 2.  */
  2393.           if (i < n_spills)
  2394.         break;
  2395.         }
  2396.     }
  2397.  
  2398.       /* We should have found a spill register by now.  */
  2399.       if (i == n_spills)
  2400.     {
  2401.       if (must_reuse)
  2402.         abort ();
  2403.       bcopy (original_reload_reg_rtx, reload_reg_rtx, sizeof (reload_reg_rtx));
  2404.       must_reuse = 1;
  2405.       goto retry;
  2406.     }
  2407.  
  2408.       /* Mark as in use for this insn the reload regs we use for this.  */
  2409.       {
  2410.     int nr = HARD_REGNO_NREGS (spill_regs[i], reload_mode);
  2411.     while (nr > 0)
  2412.       {
  2413.         mark_reload_reg_in_use (spill_regs[i] + --nr,
  2414.                     reload_when_needed[r]);
  2415.         reg_reloaded_contents[spill_reg_order[spill_regs[i] + nr]] = -1;
  2416.       }
  2417.       }
  2418.  
  2419.       new = spill_reg_rtx[i];
  2420.  
  2421.       if (new == 0 || GET_MODE (new) != reload_mode)
  2422.     spill_reg_rtx[i] = new = gen_rtx (REG, reload_mode, spill_regs[i]);
  2423.  
  2424.       reload_reg_rtx[r] = new;
  2425.       reload_spill_index[r] = i;
  2426.  
  2427.       /* Detect when the reload reg can't hold the reload mode.
  2428.      This used to be one `if', but Sequent compiler can't handle that.  */
  2429.       if (HARD_REGNO_MODE_OK (REGNO (reload_reg_rtx[r]), reload_mode))
  2430.     if (! (reload_in[r] != 0
  2431.            && ! HARD_REGNO_MODE_OK (REGNO (reload_reg_rtx[r]),
  2432.                     GET_MODE (reload_in[r]))))
  2433.       if (! (reload_out[r] != 0
  2434.          && ! HARD_REGNO_MODE_OK (REGNO (reload_reg_rtx[r]),
  2435.                       GET_MODE (reload_out[r]))))
  2436.         /* The reg is OK.  */
  2437.         continue;
  2438.  
  2439.       /* The reg is not OK.  */
  2440.       {
  2441.     if (asm_noperands (PATTERN (insn)) < 0)
  2442.       /* It's the compiler's fault.  */
  2443.       abort ();
  2444.     /* It's the user's fault; the operand's mode and constraint
  2445.        don't match.  Disable this reload so we don't crash in final.  */
  2446.     error_for_asm (insn,
  2447.                "`asm' operand constraint incompatible with operand size");
  2448.     reload_in[r] = 0;
  2449.     reload_out[r] = 0;
  2450.     reload_reg_rtx[r] = 0;
  2451.     reload_optional[r] = 1;
  2452.       }
  2453.     }
  2454.  
  2455.   /* If we thought we could inherit a reload, because it seemed that
  2456.      nothing else wanted the same reload register earlier in the insn,
  2457.      verify that assumption, now that all reloads have been assigned.  */
  2458.  
  2459.   for (j = 0; j < n_reloads; j++)
  2460.     {
  2461.       register int r = reload_order[j];
  2462.  
  2463.       if (reload_inherited[r] && reload_reg_rtx[r] != 0
  2464.       && ! reload_reg_free_before_p (REGNO (reload_reg_rtx[r]),
  2465.                      reload_when_needed[r]))
  2466.     reload_inherited[r] = 0;
  2467.  
  2468.       /* If we found a better place to reload from,
  2469.      validate it in the same fashion, if it is a reload reg.  */
  2470.       if (reload_override_in[r]
  2471.       && GET_CODE (reload_override_in[r]) == REG
  2472.       && spill_reg_order[REGNO (reload_override_in[r])] >= 0
  2473.       && ! reload_reg_free_before_p (REGNO (reload_override_in[r]),
  2474.                      reload_when_needed[r]))
  2475.     reload_override_in[r] = 0;
  2476.     }
  2477.  
  2478.   /* Now that reload_override_in is known valid,
  2479.      actually override reload_in.  */
  2480.   for (j = 0; j < n_reloads; j++)
  2481.     if (reload_override_in[j])
  2482.       reload_in[j] = reload_override_in[j];
  2483.  
  2484.   /* For all the spill regs newly reloaded in this instruction,
  2485.      record what they were reloaded from, so subsequent instructions
  2486.      can inherit the reloads.  */
  2487.  
  2488.   for (j = 0; j < n_reloads; j++)
  2489.     {
  2490.       register int r = reload_order[j];
  2491.       register int i = reload_spill_index[r];
  2492.  
  2493.       /* I is nonneg if this reload used one of the spill regs.
  2494.      If reload_reg_rtx[r] is 0, this is an optional reload
  2495.      that we opted to ignore.  */
  2496.       if (i >= 0 && reload_reg_rtx[r] != 0)
  2497.     {
  2498.       /* Maybe the spill reg contains a copy of reload_out.  */
  2499.       if (reload_out[r] != 0 && GET_CODE (reload_out[r]) == REG)
  2500.         {
  2501.           register int nregno = REGNO (reload_out[r]);
  2502.           reg_last_reload_reg[nregno] = reload_reg_rtx[r];
  2503.           reg_reloaded_contents[i] = nregno;
  2504.           reg_has_output_reload[nregno] = 1;
  2505.           reg_is_output_reload[spill_regs[i]] = 1;
  2506.           if (reload_when_needed[r] != RELOAD_OTHER)
  2507.         abort ();
  2508.         }
  2509.       /* Maybe the spill reg contains a copy of reload_in.  */
  2510.       else if (reload_out[r] == 0
  2511.            && (GET_CODE (reload_in[r]) == REG
  2512.                || GET_CODE (reload_in_reg[r]) == REG))
  2513.         {
  2514.           register int nregno;
  2515.           if (GET_CODE (reload_in[r]) == REG)
  2516.         nregno = REGNO (reload_in[r]);
  2517.           else
  2518.         nregno = REGNO (reload_in_reg[r]);
  2519.  
  2520.           /* If there are two separate reloads (one in and one out)
  2521.          for the same (hard or pseudo) reg,
  2522.          leave reg_last_reload_reg set 
  2523.          based on the output reload.
  2524.          Otherwise, set it from this input reload.  */
  2525.           if (!reg_has_output_reload[nregno])
  2526.         {
  2527.           reg_last_reload_reg[nregno] = reload_reg_rtx[r];
  2528.           reg_reloaded_contents[i] = nregno;
  2529.  
  2530.           /* But don't do so if another input reload
  2531.              will clobber this one's value.  */
  2532.           if (! reload_reg_reaches_end_p (spill_regs[i],
  2533.                           reload_when_needed[r]))
  2534.             reg_reloaded_contents[i] = -1;
  2535.         }
  2536.         }
  2537.       /* Otherwise, the spill reg doesn't contain a copy of any reg.
  2538.          Clear out its records, lest it be taken for a copy
  2539.          of reload_in when that is no longer true.  */
  2540.       else
  2541.         reg_reloaded_contents[i] = -1;
  2542.     }
  2543.  
  2544.       /* The following if-statement was #if 0'd in 1.34 (or before...).
  2545.      It's reenabled in 1.35 because supposedly nothing else
  2546.      deals with this problem.  */
  2547.  
  2548.       /* If a register gets output-reloaded from a non-spill register,
  2549.      that invalidates any previous reloaded copy of it.
  2550.      But forget_old_reloads_1 won't get to see it, because
  2551.      it thinks only about the original insn.  So invalidate it here.  */
  2552.       if (i < 0 && reload_out[r] != 0 && GET_CODE (reload_out[r]) == REG)
  2553.     {
  2554.       register int nregno = REGNO (reload_out[r]);
  2555.       reg_last_reload_reg[nregno] = 0;
  2556.       reg_has_output_reload[nregno] = 1;
  2557.     }
  2558.     }
  2559. }
  2560.  
  2561. /* Output insns to reload values in and out of the chosen reload regs.  */
  2562.  
  2563. static void
  2564. emit_reload_insns (insn)
  2565.      rtx insn;
  2566. {
  2567.   register int j;
  2568.   rtx first_output_reload_insn = NEXT_INSN (insn);
  2569.   rtx first_other_reload_insn = insn;
  2570.   rtx first_operand_address_reload_insn = insn;
  2571.   int special;
  2572.  
  2573.   /* Now output the instructions to copy the data into and out of the
  2574.      reload registers.  Do these in the order that the reloads were reported,
  2575.      since reloads of base and index registers precede reloads of operands
  2576.      and the operands may need the base and index registers reloaded.  */
  2577.  
  2578.   for (j = 0; j < n_reloads; j++)
  2579.     {
  2580.       register rtx old;
  2581.       rtx store_insn;
  2582.  
  2583.       old = reload_in[j];
  2584.       if (old != 0 && ! reload_inherited[j]
  2585.       && reload_reg_rtx[j] != old
  2586.       && reload_reg_rtx[j] != 0)
  2587.     {
  2588.       register rtx reloadreg = reload_reg_rtx[j];
  2589.       rtx oldequiv = 0;
  2590.       enum machine_mode mode;
  2591.       rtx where;
  2592.       rtx this_reload_insn = 0;
  2593.  
  2594. #if 0
  2595.       /* No longer done because these paradoxical subregs now occur
  2596.          only for regs and for spilled stack slots, and in either case
  2597.          we can safely reload in the nominal machine mode.  */
  2598.  
  2599.       /* Strip off of OLD any size-increasing SUBREGs such as
  2600.          (SUBREG:SI foo:QI 0).  */
  2601.  
  2602.       while (GET_CODE (old) == SUBREG && SUBREG_WORD (old) == 0
  2603.          && (GET_MODE_SIZE (GET_MODE (old))
  2604.              > GET_MODE_SIZE (GET_MODE (SUBREG_REG (old)))))
  2605.         old = SUBREG_REG (old);
  2606. #endif
  2607.  
  2608.       /* Determine the mode to reload in.
  2609.          This is very tricky because we have three to choose from.
  2610.          There is the mode the insn operand wants (reload_inmode[J]).
  2611.          There is the mode of the reload register RELOADREG.
  2612.          There is the intrinsic mode of the operand, which we could find
  2613.          by stripping some SUBREGs.
  2614.          It turns out that RELOADREG's mode is irrelevant:
  2615.          we can change that arbitrarily.
  2616.  
  2617.          Consider (SUBREG:SI foo:QI) as an operand that must be SImode;
  2618.          then the reload reg may not support QImode moves, so use SImode.
  2619.          If foo is in memory due to spilling a pseudo reg, this is safe,
  2620.          because the QImode value is in the least significant part of a
  2621.          slot big enough for a SImode.  If foo is some other sort of
  2622.          memory reference, then it is impossible to reload this case,
  2623.          so previous passes had better make sure this never happens.
  2624.  
  2625.          Then consider a one-word union which has SImode and one of its
  2626.          members is a float, being fetched as (SUBREG:SF union:SI).
  2627.          We must fetch that as SFmode because we could be loading into
  2628.          a float-only register.  In this case OLD's mode is correct.
  2629.  
  2630.          Consider an immediate integer: it has VOIDmode.  Here we need
  2631.          to get a mode from something else.
  2632.  
  2633.          In some cases, there is a fourth mode, the operand's
  2634.          containing mode.  If the insn specifies a containing mode for
  2635.          this operand, it overrides all others.
  2636.  
  2637.          I am not sure whether the algorithm here is always right,
  2638.          but it does the right things in those cases.  */
  2639.  
  2640.       mode = GET_MODE (old);
  2641.       if (mode == VOIDmode)
  2642.         mode = reload_inmode[j];
  2643.       if (reload_strict_low[j])
  2644.         mode = GET_MODE (SUBREG_REG (reload_in[j]));
  2645.  
  2646.       /* If reloading from memory, see if there is a register
  2647.          that already holds the same value.  If so, reload from there.
  2648.          We can pass 0 as the reload_reg_p argument because
  2649.          any other reload has either already been emitted,
  2650.          in which case find_equiv_reg will see the reload-insn,
  2651.          or has yet to be emitted, in which case it doesn't matter
  2652.          because we will use this equiv reg right away.  */
  2653.  
  2654.       if (GET_CODE (old) == MEM
  2655.           || (GET_CODE (old) == REG
  2656.           && REGNO (old) >= FIRST_PSEUDO_REGISTER
  2657.           && reg_renumber[REGNO (old)] < 0))
  2658.         oldequiv = find_equiv_reg (old, insn, GENERAL_REGS,
  2659.                        -1, 0, 0, mode);
  2660.  
  2661.       /* If OLDEQUIV is a spill register, don't use it for this
  2662.          if any other reload needs it at an earlier stage of this insn
  2663.          or at this stage.  */       
  2664.       if (oldequiv && GET_CODE (oldequiv) == REG
  2665.           && spill_reg_order[REGNO (oldequiv)] >= 0
  2666.           && (! reload_reg_free_p (REGNO (oldequiv), reload_when_needed[j])
  2667.           || ! reload_reg_free_before_p (REGNO (oldequiv),
  2668.                          reload_when_needed[j])))
  2669.         oldequiv = 0;
  2670.  
  2671.       /* If OLDEQUIV is not a spill register,
  2672.          don't use it if any other reload wants it.  */
  2673.       if (oldequiv && GET_CODE (oldequiv) == REG
  2674.           && spill_reg_order[REGNO (oldequiv)] < 0)
  2675.         {
  2676.           int k;
  2677.           for (k = 0; k < n_reloads; k++)
  2678.         if (reload_reg_rtx[k] != 0 && k != j
  2679.             && reg_overlap_mentioned_p (reload_reg_rtx[k], oldequiv))
  2680.           {
  2681.             oldequiv = 0;
  2682.             break;
  2683.           }
  2684.         }
  2685.  
  2686.       if (oldequiv == 0)
  2687.         oldequiv = old;
  2688.  
  2689.       /* Encapsulate both RELOADREG and OLDEQUIV into that mode,
  2690.          then load RELOADREG from OLDEQUIV.  */
  2691.  
  2692.       if (GET_MODE (reloadreg) != mode)
  2693.         reloadreg = gen_rtx (SUBREG, mode, reloadreg, 0);
  2694.       while (GET_CODE (oldequiv) == SUBREG && GET_MODE (oldequiv) != mode)
  2695.         oldequiv = SUBREG_REG (oldequiv);
  2696.       if (GET_MODE (oldequiv) != VOIDmode
  2697.           && mode != GET_MODE (oldequiv))
  2698.         oldequiv = gen_rtx (SUBREG, mode, oldequiv, 0);
  2699.  
  2700.       /* Decide where to put reload insn for this reload.  */
  2701.       switch (reload_when_needed[j])
  2702.         {
  2703.         case RELOAD_OTHER:
  2704.           where = first_operand_address_reload_insn;
  2705.           break;
  2706.         case RELOAD_FOR_INPUT_RELOAD_ADDRESS:
  2707.           where = first_other_reload_insn;
  2708.           break;
  2709.         case RELOAD_FOR_OUTPUT_RELOAD_ADDRESS:
  2710.           where = first_output_reload_insn;
  2711.           break;
  2712.         case RELOAD_FOR_OPERAND_ADDRESS:
  2713.           where = insn;
  2714.         }
  2715.  
  2716.       special = 0;
  2717.  
  2718.       /* Auto-increment addresses must be reloaded in a special way.  */
  2719.       if (GET_CODE (oldequiv) == POST_INC
  2720.           || GET_CODE (oldequiv) == POST_DEC
  2721.           || GET_CODE (oldequiv) == PRE_INC
  2722.           || GET_CODE (oldequiv) == PRE_DEC)
  2723.         {
  2724.           /* Prevent normal processing of this reload.  */
  2725.           special = 1;
  2726.           /* Output a special code sequence for this case.  */
  2727.           this_reload_insn
  2728.         = inc_for_reload (reloadreg, oldequiv, reload_inc[j], where);
  2729.         }
  2730.  
  2731.       /* If we are reloading a pseudo-register that was set by the previous
  2732.          insn, see if we can get rid of that pseudo-register entirely
  2733.          by redirecting the previous insn into our reload register.  */
  2734.  
  2735.       else if (optimize && GET_CODE (old) == REG
  2736.            && REGNO (old) >= FIRST_PSEUDO_REGISTER
  2737.            && dead_or_set_p (insn, old)
  2738.            /* This is unsafe if some other reload
  2739.               uses the same reg first.  */
  2740.            && (reload_when_needed[j] == RELOAD_OTHER
  2741.                || reload_when_needed[j] == RELOAD_FOR_INPUT_RELOAD_ADDRESS))
  2742.         {
  2743.           rtx temp = PREV_INSN (insn);
  2744.           while (temp && GET_CODE (temp) == NOTE)
  2745.         temp = PREV_INSN (temp);
  2746.           if (temp
  2747.           && GET_CODE (temp) == INSN
  2748.           && GET_CODE (PATTERN (temp)) == SET
  2749.           && SET_DEST (PATTERN (temp)) == old
  2750.           /* Make sure we can access insn_operand_constraint.  */
  2751.           && asm_noperands (PATTERN (temp)) < 0
  2752.           /* This is unsafe if prev insn rejects our reload reg.  */
  2753.           && constraint_accepts_reg_p (insn_operand_constraint[recog_memoized (temp)][0],
  2754.                            reloadreg)
  2755.           /* This is unsafe if operand occurs more than once in current
  2756.              insn.  Perhaps some occurrences aren't reloaded.  */
  2757.           && count_occurrences (PATTERN (insn), old) == 1
  2758.           /* Don't risk splitting a matching pair of operands.  */
  2759.           && ! reg_mentioned_p (old, SET_SRC (PATTERN (temp))))
  2760.         {
  2761.           /* Store into the reload register instead of the pseudo.  */
  2762.           SET_DEST (PATTERN (temp)) = reloadreg;
  2763.           /* If these are the only uses of the pseudo reg,
  2764.              pretend for GDB it lives in the reload reg we used.  */
  2765.           if (reg_n_deaths[REGNO (old)] == 1
  2766.               && reg_n_sets[REGNO (old)] == 1)
  2767.             {
  2768.               reg_renumber[REGNO (old)] = REGNO (reload_reg_rtx[j]);
  2769.               alter_reg (REGNO (old), -1);
  2770.             }
  2771.           special = 1;
  2772.         }
  2773.         }
  2774.  
  2775.       /* We can't do that, so output an insn to load RELOADREG.
  2776.          Keep them in the following order:
  2777.          all reloads for input reload addresses,
  2778.          all reloads for ordinary input operands,
  2779.          all reloads for addresses of non-reloaded operands,
  2780.          the insn being reloaded,
  2781.          all reloads for addresses of output reloads,
  2782.          the output reloads.  */
  2783.       if (! special)
  2784.         this_reload_insn = gen_input_reload (reloadreg, oldequiv, where);
  2785.  
  2786.       /* Update where to put other reload insns.  */
  2787.       if (this_reload_insn)
  2788.         switch (reload_when_needed[j])
  2789.           {
  2790.           case RELOAD_OTHER:
  2791.         if (first_other_reload_insn == first_operand_address_reload_insn)
  2792.           first_other_reload_insn = this_reload_insn;
  2793.         break;
  2794.           case RELOAD_FOR_OPERAND_ADDRESS:
  2795.         if (first_operand_address_reload_insn == insn)
  2796.           first_operand_address_reload_insn = this_reload_insn;
  2797.         if (first_other_reload_insn == insn)
  2798.           first_other_reload_insn = this_reload_insn;
  2799.           }
  2800.  
  2801.       /* reload_inc[j] was formerly processed here.  */
  2802.     }
  2803.  
  2804.       /* Add a note saying the input reload reg
  2805.      dies in this insn, if anyone cares.  */
  2806. #ifdef PRESERVE_DEATH_INFO_REGNO_P
  2807.       if (old != 0
  2808.       && reload_reg_rtx[j] != old
  2809.       && reload_reg_rtx[j] != 0
  2810.       && reload_out[j] == 0
  2811.       && PRESERVE_DEATH_INFO_REGNO_P (REGNO (reload_reg_rtx[j])))
  2812.     {
  2813.       register rtx reloadreg = reload_reg_rtx[j];
  2814.  
  2815.       /* The code below is incorrect except for RELOAD_OTHER.  */
  2816.       if (reload_when_needed[j] != RELOAD_OTHER)
  2817.         abort ();
  2818.  
  2819.       /* Add a death note to this insn, for an input reload.  */
  2820.  
  2821.       if (! dead_or_set_p (insn, reloadreg))
  2822.         REG_NOTES (insn)
  2823.           = gen_rtx (EXPR_LIST, REG_DEAD,
  2824.              reloadreg, REG_NOTES (insn));
  2825.     }
  2826. #endif
  2827.  
  2828.       /* ??? The following code is inadequate.
  2829.      It handles regs inherited via reg_last_reloaded_contents
  2830.      but not those inherited via find_equiv_reg.
  2831.      Note that we can't expect spill_reg_store to contain anything
  2832.      useful in the case of find_equiv_reg.  */
  2833.  
  2834. #ifdef PRESERVE_DEATH_INFO_REGNO_P
  2835.       /* For some registers it is important to keep the REG_DEATH
  2836.      notes accurate for the final pass.
  2837.      If we are inheriting an old output-reload out of such a reg,
  2838.      the reg no longer dies there, so remove the death note.  */
  2839.  
  2840.       if (reload_reg_rtx[j] != 0
  2841.       && PRESERVE_DEATH_INFO_REGNO_P (REGNO (reload_reg_rtx[j]))
  2842.       && reload_inherited[j] && reload_spill_index[j] >= 0
  2843.       && GET_CODE (reload_in[j]) == REG
  2844.       && spill_reg_store[reload_spill_index[j]] != 0
  2845.       && regno_dead_p (REGNO (reload_reg_rtx[j]),
  2846.                spill_reg_store[reload_spill_index[j]]))
  2847.     {
  2848.       remove_death (REGNO (reload_reg_rtx[j]),
  2849.             spill_reg_store[reload_spill_index[j]]);
  2850.     }
  2851. #endif
  2852.  
  2853.       /* If we are reloading a register that was recently stored in with an
  2854.      output-reload, see if we can prove there was
  2855.      actually no need to store the old value in it.  */
  2856.  
  2857.       if (optimize && reload_inherited[j] && reload_spill_index[j] >= 0
  2858.       /* This is unsafe if some other reload uses the same reg first.  */
  2859.       && (reload_when_needed[j] == RELOAD_OTHER
  2860.           || reload_when_needed[j] == RELOAD_FOR_INPUT_RELOAD_ADDRESS)
  2861.       && GET_CODE (reload_in[j]) == REG
  2862.       && REGNO (reload_in[j]) >= FIRST_PSEUDO_REGISTER
  2863.       && spill_reg_store[reload_spill_index[j]] != 0
  2864.       && dead_or_set_p (insn, reload_in[j])
  2865.       /* This is unsafe if operand occurs more than once in current
  2866.          insn.  Perhaps some occurrences weren't reloaded.  */
  2867.       && count_occurrences (PATTERN (insn), reload_in[j]) == 1)
  2868.     delete_output_reload (insn, j, reload_spill_index[j]);
  2869.  
  2870.       /* Input-reloading is done.  Now do output-reloading,
  2871.      storing the value from the reload-register after the main insn
  2872.      if reload_out[j] is nonzero.  */
  2873.       old = reload_out[j];
  2874.       if (old != 0
  2875.       && reload_reg_rtx[j] != old
  2876.       && reload_reg_rtx[j] != 0
  2877.       /* An output operand that dies right away
  2878.          does need a reload reg, but need not
  2879.          be copied from it.  */
  2880.       && ! (GET_CODE (old) == REG
  2881.         && find_reg_note (insn, REG_DEAD, old)))
  2882.     {
  2883.       register rtx reloadreg = reload_reg_rtx[j];
  2884.       enum machine_mode mode;
  2885.  
  2886. #if 0
  2887.       /* Strip off of OLD any size-increasing SUBREGs such as
  2888.          (SUBREG:SI foo:QI 0).  */
  2889.  
  2890.       while (GET_CODE (old) == SUBREG && SUBREG_WORD (old) == 0
  2891.          && (GET_MODE_SIZE (GET_MODE (old))
  2892.              > GET_MODE_SIZE (GET_MODE (SUBREG_REG (old)))))
  2893.         old = SUBREG_REG (old);
  2894. #endif
  2895.  
  2896.       /* Determine the mode to reload in.
  2897.          See comments above (for input reloading).  */
  2898.  
  2899.       mode = GET_MODE (old);
  2900.       if (mode == VOIDmode)
  2901.         abort ();        /* Should never happen for an output.  */
  2902. #if 0
  2903.         mode = reload_inmode[j];
  2904. #endif
  2905.       if (reload_strict_low[j])
  2906.         mode = GET_MODE (SUBREG_REG (reload_out[j]));
  2907.  
  2908.       /* Encapsulate both RELOADREG and OLD into that mode,
  2909.          then load RELOADREG from OLD.  */
  2910.       if (GET_MODE (reloadreg) != mode)
  2911.         reloadreg = gen_rtx (SUBREG, mode, reloadreg, 0);
  2912.       /* If OLD is a subreg, then strip it, since the subreg will
  2913.          be altered by this very reload (if it's a strict_low_part).  */
  2914.       while (GET_CODE (old) == SUBREG && GET_MODE (old) != mode)
  2915.         old = SUBREG_REG (old);
  2916.       if (GET_MODE (old) != VOIDmode
  2917.           && mode != GET_MODE (old))
  2918.         old = gen_rtx (SUBREG, mode, old, 0);
  2919.       /* Output the reload insn.  */
  2920.       store_insn = emit_insn_before (gen_move_insn (old, reloadreg),
  2921.                      first_output_reload_insn);
  2922.       first_output_reload_insn = store_insn;
  2923.       /* If this output reload doesn't come from a spill reg,
  2924.          clear any memory of reloaded copies of the pseudo reg.
  2925.          If this output reload comes from a spill reg,
  2926.          reg_has_output_reload will make this do nothing.  */
  2927.       note_stores (PATTERN (store_insn), forget_old_reloads_1);
  2928.  
  2929. #ifdef PRESERVE_DEATH_INFO_REGNO_P
  2930.       /* If final will look at death notes for this reg,
  2931.          put one on the output-reload insn.  */
  2932.       if (PRESERVE_DEATH_INFO_REGNO_P (REGNO (reloadreg)))
  2933.         REG_NOTES (store_insn)
  2934.         = gen_rtx (EXPR_LIST, REG_DEAD,
  2935.                reloadreg, REG_NOTES (store_insn));
  2936.  
  2937.       /* Move all death-notes from the insn being reloaded
  2938.          to the output reload, if they are for things used
  2939.          as inputs in this output reload.  */
  2940.       if (GET_CODE (old) != REG)
  2941.         {
  2942.           /* The note we will examine next.  */
  2943.           rtx reg_notes = REG_NOTES (insn);
  2944.           /* The place that pointed to this note.  */
  2945.           rtx *prev_reg_note = ®_NOTES (insn);
  2946.  
  2947.           while (reg_notes)
  2948.         {
  2949.           rtx next_reg_notes = XEXP (reg_notes, 1);
  2950.           if (REG_NOTE_KIND (reg_notes) == REG_DEAD
  2951.               && reg_mentioned_p (XEXP (reg_notes, 0), old))
  2952.             {
  2953.               *prev_reg_note = next_reg_notes;
  2954.               XEXP (reg_notes, 1) = REG_NOTES (store_insn);
  2955.               REG_NOTES (store_insn) = reg_notes;
  2956.             }
  2957.           else
  2958.             prev_reg_note = &XEXP (reg_notes, 1);
  2959.  
  2960.           reg_notes = next_reg_notes;
  2961.         }
  2962.         }
  2963. #endif
  2964.     }
  2965.       else store_insn = 0;
  2966.  
  2967.       if (reload_spill_index[j] >= 0)
  2968.     spill_reg_store[reload_spill_index[j]] = store_insn;
  2969.     }
  2970.  
  2971.   /* Move death notes from INSN to output-operand-address reload insns.  */
  2972. #ifdef PRESERVE_DEATH_INFO_REGNO_P
  2973.   {
  2974.     rtx insn1;
  2975.     /* Loop over those insns, last ones first.  */
  2976.     for (insn1 = PREV_INSN (first_output_reload_insn); insn1 != insn;
  2977.      insn1 = PREV_INSN (insn1))
  2978.       if (GET_CODE (insn1) == INSN && GET_CODE (PATTERN (insn1)) == SET)
  2979.     {
  2980.       rtx source = SET_SRC (PATTERN (insn1));
  2981.  
  2982.       /* The note we will examine next.  */
  2983.       rtx reg_notes = REG_NOTES (insn);
  2984.       /* The place that pointed to this note.  */
  2985.       rtx *prev_reg_note = ®_NOTES (insn);
  2986.  
  2987.       /* If the note is for something used in the source of this
  2988.          output address reload insn, move the note.  */
  2989.       while (reg_notes)
  2990.         {
  2991.           rtx next_reg_notes = XEXP (reg_notes, 1);
  2992.           if (REG_NOTE_KIND (reg_notes) == REG_DEAD
  2993.           && reg_mentioned_p (XEXP (reg_notes, 0), source))
  2994.         {
  2995.           *prev_reg_note = next_reg_notes;
  2996.           XEXP (reg_notes, 1) = REG_NOTES (insn1);
  2997.           REG_NOTES (insn1) = reg_notes;
  2998.         }
  2999.           else
  3000.         prev_reg_note = &XEXP (reg_notes, 1);
  3001.  
  3002.           reg_notes = next_reg_notes;
  3003.         }
  3004.     }
  3005.   }
  3006. #endif
  3007. }
  3008.  
  3009. /* Emit code before BEFORE_INSN to perform an input reload of IN to RELOADREG.
  3010.    Handle case of reloading a PLUS expression (currently only happens for
  3011.    stack slots with out-of-range offset).
  3012.  
  3013.    Returns last insn emitted.  */
  3014.  
  3015. static rtx
  3016. gen_input_reload (reloadreg, in, before_insn)
  3017.      rtx reloadreg;
  3018.      rtx in;
  3019.      rtx before_insn;
  3020. {
  3021. #if 0  /* Install this in version 1.37.  Avoid risk for now.  */
  3022.   if (GET_CODE (in) == PLUS)
  3023.     {
  3024.       /* Don't use gen_move_insn to make what is actually an add insn.  */
  3025.       emit_insn_before (gen_move_insn (reloadreg, XEXP (in, 0)), before_insn);
  3026.       emit_insn_before (gen_add2_insn (reloadreg, XEXP (in, 1)), before_insn);
  3027.     }
  3028.   else
  3029. #endif
  3030.     emit_insn_before (gen_move_insn (reloadreg, in), before_insn);
  3031.  
  3032.   return PREV_INSN (before_insn);
  3033. }
  3034.  
  3035. /* Delete a previously made output-reload
  3036.    whose result we now believe is not needed.
  3037.    First we double-check.
  3038.  
  3039.    INSN is the insn now being processed.
  3040.    J is the reload-number for this insn,
  3041.    and SPILL_INDEX is the index in spill_regs of the reload-reg
  3042.    being used for the reload.  */
  3043.  
  3044. static void
  3045. delete_output_reload (insn, j, spill_index)
  3046.      rtx insn;
  3047.      int j;
  3048.      int spill_index;
  3049. {
  3050.   register rtx i1;
  3051.  
  3052.   /* Get the raw pseudo-register referred to.  */
  3053.  
  3054.   rtx reg = reload_in[j];
  3055.   while (GET_CODE (reg) == SUBREG)
  3056.     reg = SUBREG_REG (reg);
  3057.  
  3058.   /* If the pseudo-reg we are reloading is no longer referenced
  3059.      anywhere between the store into it and here,
  3060.      and no jumps or labels intervene, then the value can get
  3061.      here through the reload reg alone.
  3062.      Otherwise, give up--return.  */
  3063.   for (i1 = NEXT_INSN (spill_reg_store[spill_index]);
  3064.        i1 != insn; i1 = NEXT_INSN (i1))
  3065.     {
  3066.       if (GET_CODE (i1) == CODE_LABEL || GET_CODE (i1) == JUMP_INSN)
  3067.     return;
  3068.       if ((GET_CODE (i1) == INSN || GET_CODE (i1) == CALL_INSN)
  3069.       && reg_mentioned_p (reg, PATTERN (i1)))
  3070.     return;
  3071.     }
  3072.  
  3073.   /* If this insn will store in the pseudo again,
  3074.      the previous store can be removed.  */
  3075.   if (reload_out[j] == reload_in[j])
  3076.     delete_insn (spill_reg_store[spill_index]);
  3077.  
  3078.   /* See if the pseudo reg has been completely replaced
  3079.      with reload regs.  If so, delete the store insn
  3080.      and forget we had a stack slot for the pseudo.  */
  3081.   else if (reg_n_deaths[REGNO (reg)] == 1
  3082.        && reg_basic_block[REGNO (reg)] >= 0
  3083.        && find_regno_note (insn, REG_DEAD, REGNO (reg)))
  3084.     {
  3085.       rtx i2;
  3086.  
  3087.       /* We know that it was used only between here
  3088.      and the beginning of the current basic block.
  3089.      (We also know that the last use before INSN was
  3090.      the output reload we are thinking of deleting, but never mind that.)
  3091.      Search that range; see if any ref remains.  */
  3092.       for (i2 = PREV_INSN (insn); i2; i2 = PREV_INSN (i2))
  3093.     {
  3094.       /* Uses which just store in the pseudo don't count,
  3095.          since if they are the only uses, they are dead.  */
  3096.       if (GET_CODE (i2) == INSN
  3097.           && GET_CODE (PATTERN (i2)) == SET
  3098.           && SET_DEST (PATTERN (i2)) == reg)
  3099.         continue;
  3100.       if (GET_CODE (i2) == CODE_LABEL
  3101.           || GET_CODE (i2) == JUMP_INSN)
  3102.         break;
  3103.       if ((GET_CODE (i2) == INSN || GET_CODE (i2) == CALL_INSN)
  3104.           && reg_mentioned_p (reg, PATTERN (i2)))
  3105.         /* Some other ref remains;
  3106.            we can't do anything.  */
  3107.         return;
  3108.     }
  3109.  
  3110.       /* Delete the now-dead stores into this pseudo.  */
  3111.       for (i2 = PREV_INSN (insn); i2; i2 = PREV_INSN (i2))
  3112.     {
  3113.       /* Uses which just store in the pseudo don't count,
  3114.          since if they are the only uses, they are dead.  */
  3115.       if (GET_CODE (i2) == INSN
  3116.           && GET_CODE (PATTERN (i2)) == SET
  3117.           && SET_DEST (PATTERN (i2)) == reg)
  3118.         delete_insn (i2);
  3119.       if (GET_CODE (i2) == CODE_LABEL
  3120.           || GET_CODE (i2) == JUMP_INSN)
  3121.         break;
  3122.     }
  3123.  
  3124.       /* For the debugging info,
  3125.      say the pseudo lives in this reload reg.  */
  3126.       reg_renumber[REGNO (reg)] = REGNO (reload_reg_rtx[j]);
  3127.       alter_reg (REGNO (reg), -1);
  3128.     }
  3129. }
  3130.  
  3131.  
  3132. /* Output reload-insns to reload VALUE into RELOADREG. 
  3133.    VALUE is a autoincrement or autodecrement RTX whose operand
  3134.    is a register or memory location;
  3135.    so reloading involves incrementing that location.
  3136.  
  3137.    INC_AMOUNT is the number to increment or decrement by (always positive).
  3138.    This cannot be deduced from VALUE.
  3139.  
  3140.    INSN is the insn before which the new insns should be emitted.
  3141.  
  3142.    The return value is the first of the insns emitted.  */
  3143.  
  3144. static rtx
  3145. inc_for_reload (reloadreg, value, inc_amount, insn)
  3146.      rtx reloadreg;
  3147.      rtx value;
  3148.      int inc_amount;
  3149.      rtx insn;
  3150. {
  3151.   /* REG or MEM to be copied and incremented.  */
  3152.   rtx incloc = XEXP (value, 0);
  3153.   /* Nonzero if increment after copying.  */
  3154.   int post = (GET_CODE (value) == POST_DEC || GET_CODE (value) == POST_INC);
  3155.  
  3156.   /* No hard register is equivalent to this register after
  3157.      inc/dec operation.  If REG_LAST_RELOAD_REG were non-zero,
  3158.      we could inc/dec that register as well (maybe even using it for
  3159.      the source), but I'm not sure it's worth worrying about.  */
  3160.   if (GET_CODE (incloc) == REG)
  3161.     reg_last_reload_reg[REGNO (incloc)] = 0;
  3162.  
  3163.   if (GET_CODE (value) == PRE_DEC || GET_CODE (value) == POST_DEC)
  3164.     inc_amount = - inc_amount;
  3165.  
  3166.   /* First handle preincrement, which is simpler.  */
  3167.   if (! post)
  3168.     {
  3169.       /* If incrementing a register, assume we can
  3170.      output an insn to increment it directly.  */
  3171.       if (GET_CODE (incloc) == REG &&
  3172.       (REGNO (incloc) < FIRST_PSEUDO_REGISTER
  3173.        || reg_renumber[REGNO (incloc)] >= 0))
  3174.     {
  3175.       rtx first_new
  3176.         = emit_insn_before (gen_add2_insn (incloc,
  3177.                            gen_rtx (CONST_INT, VOIDmode,
  3178.                             inc_amount)),
  3179.                 insn);
  3180.       emit_insn_before (gen_move_insn (reloadreg, incloc), insn);
  3181.       return first_new;
  3182.     }
  3183.       else
  3184.     /* Else we must not assume we can increment the location directly
  3185.        (even though on many target machines we can);
  3186.        copy it to the reload register, increment there, then save back.  */
  3187.     {
  3188.       rtx first_new
  3189.         = emit_insn_before (gen_move_insn (reloadreg, incloc), insn);
  3190.       emit_insn_before (gen_add2_insn (reloadreg,
  3191.                        gen_rtx (CONST_INT, VOIDmode,
  3192.                             inc_amount)),
  3193.                 insn);
  3194.       emit_insn_before (gen_move_insn (incloc, reloadreg), insn);
  3195.       return first_new;
  3196.     }
  3197.     }
  3198.   /* Postincrement.
  3199.      Because this might be a jump insn or a compare, and because RELOADREG
  3200.      may not be available after the insn in an input reload,
  3201.      we must do the incrementation before the insn being reloaded for.  */
  3202.   else
  3203.     {
  3204.       /* Copy the value, then increment it.  */
  3205.       rtx first_new
  3206.     = emit_insn_before (gen_move_insn (reloadreg, incloc), insn);
  3207.  
  3208.       /* If incrementing a register, assume we can
  3209.      output an insn to increment it directly.  */
  3210.       if (GET_CODE (incloc) == REG &&
  3211.       (REGNO (incloc) < FIRST_PSEUDO_REGISTER
  3212.        || reg_renumber[REGNO (incloc)] >= 0))
  3213.     {
  3214.       emit_insn_before (gen_add2_insn (incloc,
  3215.                        gen_rtx (CONST_INT, VOIDmode,
  3216.                             inc_amount)),
  3217.                 insn);
  3218.     }
  3219.       else
  3220.     /* Else we must not assume we can increment INCLOC
  3221.        (even though on many target machines we can);
  3222.        increment the copy in the reload register,
  3223.        save that back, then decrement the reload register
  3224.        so it has the original value.  */
  3225.     {
  3226.       emit_insn_before (gen_add2_insn (reloadreg,
  3227.                        gen_rtx (CONST_INT, VOIDmode,
  3228.                             inc_amount)),
  3229.                 insn);
  3230.       emit_insn_before (gen_move_insn (incloc, reloadreg), insn);
  3231.       emit_insn_before (gen_sub2_insn (reloadreg,
  3232.                        gen_rtx (CONST_INT, VOIDmode,
  3233.                             inc_amount)),
  3234.                 insn);
  3235.     }
  3236.       return first_new;
  3237.     }
  3238. }
  3239.  
  3240. /* Return 1 if we are certain that the constraint-string STRING allows
  3241.    the hard register REG.  Return 0 if we can't be sure of this.  */
  3242.  
  3243. static int
  3244. constraint_accepts_reg_p (string, reg)
  3245.      char *string;
  3246.      rtx reg;
  3247. {
  3248.   int value = 0;
  3249.   int regno = true_regnum (reg);
  3250.  
  3251.   /* We win if this register is a general register
  3252.      and each alternative accepts all general registers.  */
  3253.   if (! TEST_HARD_REG_BIT (reg_class_contents[(int) GENERAL_REGS], regno))
  3254.     return 0;
  3255.  
  3256.   /* Initialize for first alternative.  */
  3257.   value = 0;
  3258.   /* Check that each alternative contains `g' or `r'.  */
  3259.   while (1)
  3260.     switch (*string++)
  3261.       {
  3262.       case 0:
  3263.     /* If an alternative lacks `g' or `r', we lose.  */
  3264.     return value;
  3265.       case ',':
  3266.     /* If an alternative lacks `g' or `r', we lose.  */
  3267.     if (value == 0)
  3268.       return 0;
  3269.     /* Initialize for next alternative.  */
  3270.     value = 0;
  3271.     break;
  3272.       case 'g':
  3273.       case 'r':
  3274.     value = 1;
  3275.       }
  3276. }
  3277.  
  3278. /* Return the number of places FIND appears within X.  */
  3279.  
  3280. static int
  3281. count_occurrences (x, find)
  3282.      register rtx x, find;
  3283. {
  3284.   register int i, j;
  3285.   register enum rtx_code code;
  3286.   register char *format_ptr;
  3287.   int count;
  3288.  
  3289.   if (x == find)
  3290.     return 1;
  3291.   if (x == 0)
  3292.     return 0;
  3293.  
  3294.   code = GET_CODE (x);
  3295.  
  3296.   switch (code)
  3297.     {
  3298.     case REG:
  3299.     case QUEUED:
  3300.     case CONST_INT:
  3301.     case CONST_DOUBLE:
  3302.     case SYMBOL_REF:
  3303.     case CODE_LABEL:
  3304.     case PC:
  3305.     case CC0:
  3306.       return 0;
  3307.     }
  3308.  
  3309.   format_ptr = GET_RTX_FORMAT (code);
  3310.   count = 0;
  3311.  
  3312.   for (i = 0; i < GET_RTX_LENGTH (code); i++)
  3313.     {
  3314.       switch (*format_ptr++)
  3315.     {
  3316.     case 'e':
  3317.       count += count_occurrences (XEXP (x, i), find);
  3318.       break;
  3319.  
  3320.     case 'E':
  3321.       if (XVEC (x, i) != NULL)
  3322.         {
  3323.           for (j = 0; j < XVECLEN (x, i); j++)
  3324.         count += count_occurrences (XVECEXP (x, i, j), find);
  3325.         }
  3326.       break;
  3327.     }
  3328.     }
  3329.   return count;
  3330. }
  3331.  
  3332.  
  3333. init_reload1()
  3334. {
  3335. #define INIT_RELOAD1
  3336. #include "init.c"
  3337. }
  3338.