home *** CD-ROM | disk | FTP | other *** search
/ Education Sampler 1992 [NeXTSTEP] / Education_1992_Sampler.iso / NeXT / GnuSource / cc-61.0.1 / cc / global-alloc.c < prev    next >
C/C++ Source or Header  |  1991-08-01  |  43KB  |  1,354 lines

  1. /* Allocate registers for pseudo-registers that span basic blocks.
  2.    Copyright (C) 1987-1991 Free Software Foundation, Inc.
  3.  
  4. This file is part of GNU CC.
  5.  
  6. GNU CC is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2, or (at your option)
  9. any later version.
  10.  
  11. GNU CC is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with GNU CC; see the file COPYING.  If not, write to
  18. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20.  
  21. #include <stdio.h>
  22. #include "config.h"
  23. #include "rtl.h"
  24. #include "flags.h"
  25. #include "basic-block.h"
  26. #include "hard-reg-set.h"
  27. #include "regs.h"
  28. #include "insn-config.h"
  29. #include "output.h"
  30.  
  31. /* This pass of the compiler performs global register allocation.
  32.    It assigns hard register numbers to all the pseudo registers
  33.    that were not handled in local_alloc.  Assignments are recorded
  34.    in the vector reg_renumber, not by changing the rtl code.
  35.    (Such changes are made by final).  The entry point is
  36.    the function global_alloc.
  37.  
  38.    After allocation is complete, the reload pass is run as a subroutine
  39.    of this pass, so that when a pseudo reg loses its hard reg due to
  40.    spilling it is possible to make a second attempt to find a hard
  41.    reg for it.  The reload pass is independent in other respects
  42.    and it is run even when stupid register allocation is in use.
  43.  
  44.    1. count the pseudo-registers still needing allocation
  45.    and assign allocation-numbers (allocnos) to them.
  46.    Set up tables reg_allocno and allocno_reg to map 
  47.    reg numbers to allocnos and vice versa.
  48.    max_allocno gets the number of allocnos in use.
  49.  
  50.    2. Allocate a max_allocno by max_allocno conflict bit matrix and clear it.
  51.    Allocate a max_allocno by FIRST_PSEUDO_REGISTER conflict matrix
  52.    for conflicts between allocnos and explicit hard register use
  53.    (which includes use of pseudo-registers allocated by local_alloc).
  54.  
  55.    3. for each basic block
  56.     walk forward through the block, recording which
  57.     unallocated registers and which hardware registers are live.
  58.     Build the conflict matrix between the unallocated registers
  59.     and another of unallocated registers versus hardware registers.
  60.     Also record the preferred hardware registers
  61.     for each unallocated one.
  62.  
  63.    4. Sort a table of the allocnos into order of
  64.    desirability of the variables.
  65.  
  66.    5. Allocate the variables in that order; each if possible into
  67.    a preferred register, else into another register.  */
  68.  
  69. /* Number of pseudo-registers still requiring allocation
  70.    (not allocated by local_allocate).  */
  71.  
  72. static int max_allocno;
  73.  
  74. /* Indexed by (pseudo) reg number, gives the allocno, or -1
  75.    for pseudo registers already allocated by local_allocate.  */
  76.  
  77. static int *reg_allocno;
  78.  
  79. /* Indexed by allocno, gives the reg number.  */
  80.  
  81. static int *allocno_reg;
  82.  
  83. /* A vector of the integers from 0 to max_allocno-1,
  84.    sorted in the order of first-to-be-allocated first.  */
  85.  
  86. static int *allocno_order;
  87.  
  88. /* Indexed by an allocno, gives the number of consecutive
  89.    hard registers needed by that pseudo reg.  */
  90.  
  91. static int *allocno_size;
  92.  
  93. /* Indexed by (pseudo) reg number, gives the number of another
  94.    lower-numbered pseudo reg which can share a hard reg with this peudo
  95.    *even if the two pseudos would otherwise appear to conflict*.  */
  96.  
  97. static int *reg_may_share;
  98.  
  99. /* max_allocno by max_allocno array of bits,
  100.    recording whether two allocno's conflict (can't go in the same
  101.    hardware register).
  102.  
  103.    `conflicts' is not symmetric; a conflict between allocno's i and j
  104.    is recorded either in element i,j or in element j,i.  */
  105.  
  106. static int *conflicts;
  107.  
  108. /* Number of ints require to hold max_allocno bits.
  109.    This is the length of a row in `conflicts'.  */
  110.  
  111. static int allocno_row_words;
  112.  
  113. /* Two macros to test or store 1 in an element of `conflicts'.  */
  114.  
  115. #define CONFLICTP(I, J) \
  116.  (conflicts[(I) * allocno_row_words + (J) / INT_BITS]    \
  117.   & (1 << ((J) % INT_BITS)))
  118.  
  119. #define SET_CONFLICT(I, J) \
  120.  (conflicts[(I) * allocno_row_words + (J) / INT_BITS]    \
  121.   |= (1 << ((J) % INT_BITS)))
  122.  
  123. /* Set of hard regs currently live (during scan of all insns).  */
  124.  
  125. static HARD_REG_SET hard_regs_live;
  126.  
  127. /* Indexed by N, set of hard regs conflicting with allocno N.  */
  128.  
  129. static HARD_REG_SET *hard_reg_conflicts;
  130.  
  131. /* Indexed by N, set of hard regs preferred by allocno N.
  132.    This is used to make allocnos go into regs that are copied to or from them,
  133.    when possible, to reduce register shuffling.  */
  134.  
  135. static HARD_REG_SET *hard_reg_preferences;
  136.  
  137. /* Similar, but just counts register preferences made in simple copy
  138.    operations, rather than arithmetic.  These are given priority because
  139.    we can always eliminate an insn by using these, but using the a register
  140.    in the above list won't always eliminate an insn.  */
  141.  
  142. static HARD_REG_SET *hard_reg_copy_preferences;
  143.  
  144. /* Similar to hard_reg_preferences, but includes bits for subsequent
  145.    registers when an allocno is multi-word.  The above variable is used for
  146.    allocation while this is used to build reg_someone_prefers, below.  */
  147.  
  148. static HARD_REG_SET *hard_reg_full_preferences;
  149.  
  150. /* Indexed by N, set of hard registers that some later allocno has a
  151.    preference for.  */
  152.  
  153. static HARD_REG_SET *regs_someone_prefers;
  154.  
  155. /* Set of registers that global-alloc isn't supposed to use.  */
  156.  
  157. static HARD_REG_SET no_global_alloc_regs;
  158.  
  159. /* Set of registers used so far.  */
  160.  
  161. static HARD_REG_SET regs_used_so_far;
  162.  
  163. /* Number of calls crossed by each allocno.  */
  164.  
  165. static int *allocno_calls_crossed;
  166.  
  167. /* Number of refs (weighted) to each allocno.  */
  168.  
  169. static int *allocno_n_refs;
  170.  
  171. /* Guess at live length of each allocno.
  172.    This is actually the max of the live lengths of the regs.  */
  173.  
  174. static int *allocno_live_length;
  175.  
  176. /* Test a bit in TABLE, a vector of HARD_REG_SETs,
  177.    for vector element I, and hard register number J.  */
  178.  
  179. #define REGBITP(TABLE, I, J)     TEST_HARD_REG_BIT (TABLE[I], J)
  180.  
  181. /* Set to 1 a bit in a vector of HARD_REG_SETs.  Works like REGBITP.  */
  182.  
  183. #define SET_REGBIT(TABLE, I, J)  SET_HARD_REG_BIT (TABLE[I], J)
  184.  
  185. /* Bit mask for allocnos live at current point in the scan.  */
  186.  
  187. static int *allocnos_live;
  188.  
  189. #define INT_BITS HOST_BITS_PER_INT
  190.  
  191. /* Test, set or clear bit number I in allocnos_live,
  192.    a bit vector indexed by allocno.  */
  193.  
  194. #define ALLOCNO_LIVE_P(I) \
  195.   (allocnos_live[(I) / INT_BITS] & (1 << ((I) % INT_BITS)))
  196.  
  197. #define SET_ALLOCNO_LIVE(I) \
  198.   (allocnos_live[(I) / INT_BITS] |= (1 << ((I) % INT_BITS)))
  199.  
  200. #define CLEAR_ALLOCNO_LIVE(I) \
  201.   (allocnos_live[(I) / INT_BITS] &= ~(1 << ((I) % INT_BITS)))
  202.  
  203. /* This is turned off because it doesn't work right for DImode.
  204.    (And it is only used for DImode, so the other cases are worthless.)
  205.    The problem is that it isn't true that there is NO possibility of conflict;
  206.    only that there is no conflict if the two pseudos get the exact same regs.
  207.    If they were allocated with a partial overlap, there would be a conflict.
  208.    We can't safely turn off the conflict unless we have another way to
  209.    prevent the partial overlap.
  210.  
  211.    Idea: change hard_reg_conflicts so that instead of recording which
  212.    hard regs the allocno may not overlap, it records where the allocno
  213.    may not start.  Change both where it is used and where it is updated.
  214.    Then there is a way to record that (reg:DI 108) may start at 10
  215.    but not at 9 or 11.  There is still the question of how to record
  216.    this semi-conflict between two pseudos.  */
  217. #if 0
  218. /* Reg pairs for which conflict after the current insn
  219.    is inhibited by a REG_NO_CONFLICT note.
  220.    If the table gets full, we ignore any other notes--that is conservative.  */
  221. #define NUM_NO_CONFLICT_PAIRS 4
  222. /* Number of pairs in use in this insn.  */
  223. int n_no_conflict_pairs;
  224. static struct { int allocno1, allocno2;}
  225.   no_conflict_pairs[NUM_NO_CONFLICT_PAIRS];
  226. #endif /* 0 */
  227.  
  228. /* Record all regs that are set in any one insn.
  229.    Communication from mark_reg_{store,clobber} and global_conflicts.  */
  230.  
  231. static rtx *regs_set;
  232. static int n_regs_set;
  233.  
  234. static int allocno_compare ();
  235. static void mark_reg_store ();
  236. static void mark_reg_clobber ();
  237. static void mark_reg_live_nc ();
  238. static void mark_reg_death ();
  239. static void dump_conflicts ();
  240. void dump_global_regs ();
  241. static void find_reg ();
  242. static void global_conflicts ();
  243. static void prune_preferences ();
  244. static void record_conflicts ();
  245. static void set_preference ();
  246.  
  247. /* Perform allocation of pseudo-registers not allocated by local_alloc.
  248.    FILE is a file to output debugging information on,
  249.    or zero if such output is not desired.  */
  250.  
  251. void
  252. global_alloc (file)
  253.      FILE *file;
  254. {
  255.   register int i;
  256.   rtx x;
  257.  
  258.   max_allocno = 0;
  259.  
  260.   /* A machine may have certain hard registers that
  261.      are safe to use only within a basic block.  */
  262.  
  263.   CLEAR_HARD_REG_SET (no_global_alloc_regs);
  264. #ifdef OVERLAPPING_REGNO_P
  265.   for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
  266.     if (OVERLAPPING_REGNO_P (i))
  267.       SET_HARD_REG_BIT (no_global_alloc_regs, i);
  268. #endif
  269.  
  270.   /* If we know we will definitely not be eliminating the frame pointer,
  271.      don't allocate it.  */
  272.   if (! flag_omit_frame_pointer || FRAME_POINTER_REQUIRED
  273.       || caller_save_needed)
  274.     SET_HARD_REG_BIT (no_global_alloc_regs, FRAME_POINTER_REGNUM);
  275.  
  276.   /* Track which registers have already been used.  Start with registers
  277.      explicitly in the rtl, then registers allocated by local register
  278.      allocation.
  279.      
  280.      We consider registers that do not have to be saved over calls as if
  281.      they were already used since there is no cost in using them.  */
  282.  
  283.   CLEAR_HARD_REG_SET (regs_used_so_far);
  284.   for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
  285.     if (regs_ever_live[i] || call_used_regs[i])
  286.       SET_HARD_REG_BIT (regs_used_so_far, i);
  287.  
  288.   for (i = FIRST_PSEUDO_REGISTER; i < max_regno; i++)
  289.     if (reg_renumber[i] >= 0)
  290.       SET_HARD_REG_BIT (regs_used_so_far, reg_renumber[i]);
  291.  
  292.   /* Establish mappings from register number to allocation number
  293.      and vice versa.  In the process, count the allocnos.  */
  294.  
  295.   reg_allocno = (int *) alloca (max_regno * sizeof (int));
  296.  
  297.   for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
  298.     reg_allocno[i] = -1;
  299.  
  300.   /* Initialize the shared-hard-reg mapping
  301.      from the list of pairs that may share.  */
  302.   reg_may_share = (int *) alloca (max_regno * sizeof (int));
  303.   bzero (reg_may_share, max_regno * sizeof (int));
  304.   for (x = regs_may_share; x; x = XEXP (XEXP (x, 1), 1))
  305.     {
  306.       int r1 = REGNO (XEXP (x, 0));
  307.       int r2 = REGNO (XEXP (XEXP (x, 1), 0));
  308.       if (r1 > r2)
  309.     reg_may_share[r1] = r2;
  310.       else
  311.     reg_may_share[r2] = r1;
  312.     }
  313.  
  314.   for (i = FIRST_PSEUDO_REGISTER; i < max_regno; i++)
  315.     /* Note that reg_live_length[i] < 0 indicates a "constant" reg
  316.        that we are supposed to refrain from putting in a hard reg.
  317.        -2 means do make an allocno but don't allocate it.  */
  318.     if (reg_n_refs[i] != 0 && reg_renumber[i] < 0 && reg_live_length[i] != -1
  319.     /* Don't allocate pseudos that cross calls,
  320.        if this function receives a nonlocal goto.  */
  321.     && (! current_function_has_nonlocal_label
  322.         || reg_n_calls_crossed[i] == 0))
  323.       {
  324.     if (reg_may_share[i] && reg_allocno[reg_may_share[i]] >= 0)
  325.       reg_allocno[i] = reg_allocno[reg_may_share[i]];
  326.     else
  327.       reg_allocno[i] = max_allocno++;
  328.     if (reg_live_length[i] == 0)
  329.       abort ();
  330.       }
  331.     else
  332.       reg_allocno[i] = -1;
  333.  
  334.   allocno_reg = (int *) alloca (max_allocno * sizeof (int));
  335.   allocno_size = (int *) alloca (max_allocno * sizeof (int));
  336.   allocno_calls_crossed = (int *) alloca (max_allocno * sizeof (int));
  337.   allocno_n_refs = (int *) alloca (max_allocno * sizeof (int));
  338.   allocno_live_length = (int *) alloca (max_allocno * sizeof (int));
  339.   bzero (allocno_size, max_allocno * sizeof (int));
  340.   bzero (allocno_calls_crossed, max_allocno * sizeof (int));
  341.   bzero (allocno_n_refs, max_allocno * sizeof (int));
  342.   bzero (allocno_live_length, max_allocno * sizeof (int));
  343.  
  344.   for (i = FIRST_PSEUDO_REGISTER; i < max_regno; i++)
  345.     if (reg_allocno[i] >= 0)
  346.       {
  347.     int allocno = reg_allocno[i];
  348.     allocno_reg[allocno] = i;
  349.     allocno_size[allocno] = PSEUDO_REGNO_SIZE (i);
  350.     allocno_calls_crossed[allocno] += reg_n_calls_crossed[i];
  351.     allocno_n_refs[allocno] += reg_n_refs[i];
  352.     if (allocno_live_length[allocno] < reg_live_length[i])
  353.       allocno_live_length[allocno] = reg_live_length[i];
  354.       }
  355.  
  356.   /* Allocate the space for the conflict and preference tables and
  357.      initialize them.  */
  358.  
  359.   hard_reg_conflicts
  360.     = (HARD_REG_SET *) alloca (max_allocno * sizeof (HARD_REG_SET));
  361.   bzero (hard_reg_conflicts, max_allocno * sizeof (HARD_REG_SET));
  362.  
  363.   hard_reg_preferences
  364.     = (HARD_REG_SET *) alloca (max_allocno * sizeof (HARD_REG_SET));
  365.   bzero (hard_reg_preferences, max_allocno * sizeof (HARD_REG_SET));
  366.   
  367.   hard_reg_copy_preferences
  368.     = (HARD_REG_SET *) alloca (max_allocno * sizeof (HARD_REG_SET));
  369.   bzero (hard_reg_copy_preferences, max_allocno * sizeof (HARD_REG_SET));
  370.   
  371.   hard_reg_full_preferences
  372.     = (HARD_REG_SET *) alloca (max_allocno * sizeof (HARD_REG_SET));
  373.   bzero (hard_reg_full_preferences, max_allocno * sizeof (HARD_REG_SET));
  374.   
  375.   regs_someone_prefers
  376.     = (HARD_REG_SET *) alloca (max_allocno * sizeof (HARD_REG_SET));
  377.   bzero (regs_someone_prefers, max_allocno * sizeof (HARD_REG_SET));
  378.  
  379.   allocno_row_words = (max_allocno + INT_BITS - 1) / INT_BITS;
  380.  
  381.   conflicts = (int *) alloca (max_allocno * allocno_row_words * sizeof (int));
  382.   bzero (conflicts, max_allocno * allocno_row_words * sizeof (int));
  383.  
  384.   allocnos_live = (int *) alloca (allocno_row_words * sizeof (int));
  385.  
  386.   /* If there is work to be done (at least one reg to allocate),
  387.      perform global conflict analysis and allocate the regs.  */
  388.  
  389.   if (max_allocno > 0)
  390.     {
  391.       /* Scan all the insns and compute the conflicts among allocnos
  392.      and between allocnos and hard regs.  */
  393.  
  394.       global_conflicts ();
  395.  
  396.       /* Determine the order to allocate the remaining pseudo registers.  */
  397.  
  398.       allocno_order = (int *) alloca (max_allocno * sizeof (int));
  399.       for (i = 0; i < max_allocno; i++)
  400.     allocno_order[i] = i;
  401.  
  402.       /* Default the size to 1, since allocno_compare uses it to divide by.
  403.      Also convert allocno_live_length of zero to -1.  A length of zero
  404.      can occur when all the registers for that allocno have reg_live_length
  405.      equal to -2.  In this case, we want to make an allocno, but not
  406.      allocate it.  So avoid the divide-by-zero and set it to a low
  407.      priority.  */
  408.  
  409.       for (i = 0; i < max_allocno; i++)
  410.     {
  411.       if (allocno_size[i] == 0)
  412.         allocno_size[i] = 1;
  413.       if (allocno_live_length[i] == 0)
  414.         allocno_live_length[i] = -1;
  415.     }
  416.  
  417.       qsort (allocno_order, max_allocno, sizeof (int), allocno_compare);
  418.       
  419.       prune_preferences ();
  420.  
  421.       if (file)
  422.     dump_conflicts (file);
  423.  
  424.       /* Try allocating them, one by one, in that order,
  425.      except for parameters marked with reg_live_length[regno] == -2.  */
  426.  
  427.       for (i = 0; i < max_allocno; i++)
  428.     if (reg_live_length[allocno_reg[allocno_order[i]]] >= 0)
  429.       {
  430.         /* If we have more than one register class,
  431.            first try allocating in the class that is cheapest
  432.            for this pseudo-reg.  If that fails, try any reg.  */
  433.         if (N_REG_CLASSES > 1)
  434.           {
  435.         find_reg (allocno_order[i], HARD_CONST (0), 0, 0);
  436.         if (reg_renumber[allocno_reg[allocno_order[i]]] >= 0)
  437.           continue;
  438.           }
  439.         if (!reg_preferred_or_nothing (allocno_reg[allocno_order[i]]))
  440.           find_reg (allocno_order[i], HARD_CONST (0), 1, 0);
  441.       }
  442.     }
  443.  
  444.   /* Do the reloads now while the allocno data still exist, so that we can
  445.      try to assign new hard regs to any pseudo regs that are spilled.  */
  446.  
  447.   if (n_basic_blocks > 0)
  448.     reload (basic_block_head[0], 1, file);
  449. }
  450.  
  451. /* Sort predicate for ordering the allocnos.
  452.    Returns -1 (1) if *v1 should be allocated before (after) *v2.  */
  453.  
  454. static int
  455. allocno_compare (v1, v2)
  456.      int *v1, *v2;
  457. {
  458.   /* Note that the quotient will never be bigger than
  459.      the value of floor_log2 times the maximum number of
  460.      times a register can occur in one insn (surely less than 100).
  461.      Multiplying this by 10000 can't overflow.  */
  462.   register int pri1
  463.     = (((double) (floor_log2 (allocno_n_refs[*v1]) * allocno_n_refs[*v1])
  464.     / (allocno_live_length[*v1] * allocno_size[*v1]))
  465.        * 10000);
  466.   register int pri2
  467.     = (((double) (floor_log2 (allocno_n_refs[*v2]) * allocno_n_refs[*v2])
  468.     / (allocno_live_length[*v2] * allocno_size[*v2]))
  469.        * 10000);
  470.   if (pri2 - pri1)
  471.     return pri2 - pri1;
  472.  
  473.   /* If regs are equally good, sort by allocno,
  474.      so that the results of qsort leave nothing to chance.  */
  475.   return *v1 - *v2;
  476. }
  477.  
  478. /* Scan the rtl code and record all conflicts and register preferences in the
  479.    conflict matrices and preference tables.  */
  480.  
  481. static void
  482. global_conflicts ()
  483. {
  484.   register int b, i;
  485.   register rtx insn;
  486.   short *block_start_allocnos;
  487.  
  488.   /* Make a vector that mark_reg_{store,clobber} will store in.  */
  489.   regs_set = (rtx *) alloca (max_parallel * sizeof (rtx) * 2);
  490.  
  491.   block_start_allocnos = (short *) alloca (max_allocno * sizeof (short));
  492.  
  493.   for (b = 0; b < n_basic_blocks; b++)
  494.     {
  495.       bzero (allocnos_live, allocno_row_words * sizeof (int));
  496.  
  497.       /* Initialize table of registers currently live
  498.      to the state at the beginning of this basic block.
  499.      This also marks the conflicts among them.
  500.  
  501.      For pseudo-regs, there is only one bit for each one
  502.      no matter how many hard regs it occupies.
  503.      This is ok; we know the size from PSEUDO_REGNO_SIZE.
  504.      For explicit hard regs, we cannot know the size that way
  505.      since one hard reg can be used with various sizes.
  506.      Therefore, we must require that all the hard regs
  507.      implicitly live as part of a multi-word hard reg
  508.      are explicitly marked in basic_block_live_at_start.  */
  509.  
  510.       {
  511.     register int offset, bit;
  512.     register regset old = basic_block_live_at_start[b];
  513.     int ax = 0;
  514.  
  515. #ifdef HARD_REG_SET
  516.     hard_regs_live = old[0];
  517. #else
  518.     COPY_HARD_REG_SET (hard_regs_live, old);
  519. #endif
  520.     for (offset = 0, i = 0; offset < regset_size; offset++)
  521.       if (old[offset] == 0)
  522.         i += HOST_BITS_PER_INT;
  523.       else
  524.         for (bit = 1; bit; bit <<= 1, i++)
  525.           {
  526.         if (i >= max_regno)
  527.           break;
  528.         if (old[offset] & bit)
  529.           {
  530.             register int a = reg_allocno[i];
  531.             if (a >= 0)
  532.               {
  533.             SET_ALLOCNO_LIVE (a);
  534.             block_start_allocnos[ax++] = a;
  535.               }
  536.             else if ((a = reg_renumber[i]) >= 0)
  537.               mark_reg_live_nc (a, PSEUDO_REGNO_MODE (i));
  538.           }
  539.           }
  540.  
  541.     /* Record that each allocno now live conflicts with each other
  542.        allocno now live, and with each hard reg now live.  */
  543.  
  544.     record_conflicts (block_start_allocnos, ax);
  545.       }
  546.  
  547.       insn = basic_block_head[b];
  548.  
  549.       /* Scan the code of this basic block, noting which allocnos
  550.      and hard regs are born or die.  When one is born,
  551.      record a conflict with all others currently live.  */
  552.  
  553.       while (1)
  554.     {
  555.       register RTX_CODE code = GET_CODE (insn);
  556.       register rtx link;
  557.  
  558.       /* Make regs_set an empty set.  */
  559.  
  560.       n_regs_set = 0;
  561.  
  562.       if (code == INSN || code == CALL_INSN || code == JUMP_INSN)
  563.         {
  564.           int i = 0;
  565.  
  566. #if 0
  567.           for (link = REG_NOTES (insn);
  568.            link && i < NUM_NO_CONFLICT_PAIRS;
  569.            link = XEXP (link, 1))
  570.         if (REG_NOTE_KIND (link) == REG_NO_CONFLICT)
  571.           {
  572.             no_conflict_pairs[i].allocno1
  573.               = reg_allocno[REGNO (SET_DEST (PATTERN (insn)))];
  574.             no_conflict_pairs[i].allocno2
  575.               = reg_allocno[REGNO (XEXP (link, 0))];
  576.             i++;
  577.           }
  578. #endif /* 0 */
  579.  
  580.           /* Mark any registers clobbered by INSN as live,
  581.          so they conflict with the inputs.  */
  582.  
  583.           note_stores (PATTERN (insn), mark_reg_clobber);
  584.  
  585.           /* Mark any registers dead after INSN as dead now.  */
  586.  
  587.           for (link = REG_NOTES (insn); link; link = XEXP (link, 1))
  588.         if (REG_NOTE_KIND (link) == REG_DEAD)
  589.           mark_reg_death (XEXP (link, 0));
  590.  
  591.           /* Mark any registers set in INSN as live,
  592.          and mark them as conflicting with all other live regs.
  593.          Clobbers are processed again, so they conflict with
  594.          the registers that are set.  */
  595.  
  596.           note_stores (PATTERN (insn), mark_reg_store);
  597.  
  598. #ifdef AUTO_INC_DEC
  599.           for (link = REG_NOTES (insn); link; link = XEXP (link, 1))
  600.         if (REG_NOTE_KIND (link) == REG_INC)
  601.           mark_reg_store (XEXP (link, 0), 0);
  602. #endif
  603.  
  604.           /* Mark any registers set in INSN and then never used.  */
  605.  
  606.           while (n_regs_set > 0)
  607.         if (find_regno_note (insn, REG_UNUSED,
  608.                      REGNO (regs_set[--n_regs_set])))
  609.           mark_reg_death (regs_set[n_regs_set]);
  610.         }
  611.  
  612.       if (insn == basic_block_end[b])
  613.         break;
  614.       insn = NEXT_INSN (insn);
  615.     }
  616.     }
  617. }
  618.  
  619. /* Prune the preferences for global registers to exclude registers that cannot
  620.    be used.
  621.    
  622.    Compute `regs_someone_prefers', which is a bitmask of the hard registers
  623.    that are preferred by conflicting registers of lower priority.  If possible,
  624.    we will avoid using these registers.  */
  625.    
  626. static void
  627. prune_preferences ()
  628. {
  629.   int i, j;
  630.   int allocno;
  631.   
  632.   /* Scan least most important to most important.
  633.      For each allocno, remove from preferences registers that cannot be used,
  634.      either because of conflicts or register type.  Then compute all registers
  635.      prefered by each lower-priority register that conflicts.  */
  636.  
  637.   for (i = max_allocno - 1; i >= 0; i--)
  638.     {
  639.       HARD_REG_SET temp;
  640.  
  641.       allocno = allocno_order[i];
  642.       COPY_HARD_REG_SET (temp, hard_reg_conflicts[allocno]);
  643.  
  644.       if (allocno_calls_crossed[allocno] == 0)
  645.     IOR_HARD_REG_SET (temp, fixed_reg_set);
  646.       else
  647.     IOR_HARD_REG_SET (temp,    call_used_reg_set);
  648.  
  649.       IOR_COMPL_HARD_REG_SET
  650.     (temp,
  651.      reg_class_contents[(int) reg_preferred_class (allocno_reg[allocno])]);
  652.  
  653.       AND_COMPL_HARD_REG_SET (hard_reg_preferences[allocno], temp);
  654.       AND_COMPL_HARD_REG_SET (hard_reg_copy_preferences[allocno], temp);
  655.       AND_COMPL_HARD_REG_SET (hard_reg_full_preferences[allocno], temp);
  656.  
  657.       CLEAR_HARD_REG_SET (regs_someone_prefers[allocno]);
  658.  
  659.       /* Merge in the preferences of lower-priority registers (they have
  660.      already been pruned).  If we also prefer some of those registers,
  661.      don't exclude them unless we are of a smaller size (in which case
  662.      we want to give the lower-priority allocno the first chance for
  663.      these registers).  */
  664.       for (j = i + 1; j < max_allocno; j++)
  665.     if (CONFLICTP (allocno, allocno_order[j]))
  666.       {
  667.         COPY_HARD_REG_SET (temp,
  668.                    hard_reg_full_preferences[allocno_order[j]]);
  669.         if (allocno_size[allocno_order[j]] <= allocno_size[allocno])
  670.           AND_COMPL_HARD_REG_SET (temp,
  671.                       hard_reg_full_preferences[allocno]);
  672.                    
  673.         IOR_HARD_REG_SET (regs_someone_prefers[allocno], temp);
  674.       }
  675.     }
  676. }
  677.  
  678. /* Assign a hard register to ALLOCNO; look for one that is the beginning
  679.    of a long enough stretch of hard regs none of which conflicts with ALLOCNO.
  680.    The registers marked in PREFREGS are tried first.
  681.  
  682.    LOSERS, if non-zero, is a HARD_REG_SET indicating registers that cannot
  683.    be used for this allocation.
  684.  
  685.    If ALL_REGS_P is zero, consider only the preferred class of ALLOCNO's reg.
  686.    Otherwise ignore that preferred class.
  687.  
  688.    If ACCEPT_CALL_CLOBBERED is nonzero, accept a call-clobbered hard reg that
  689.    will have to be saved and restored at calls.
  690.  
  691.    If we find one, record it in reg_renumber.
  692.    If not, do nothing.  */
  693.  
  694. static void
  695. find_reg (allocno, losers, all_regs_p, accept_call_clobbered)
  696.      int allocno;
  697.      HARD_REG_SET losers;
  698.      int all_regs_p;
  699.      int accept_call_clobbered;
  700. {
  701.   register int i, best_reg, pass;
  702. #ifdef HARD_REG_SET
  703.   register        /* Declare it register if it's a scalar.  */
  704. #endif
  705.     HARD_REG_SET used, used1;
  706.  
  707.   enum reg_class class 
  708.     = all_regs_p ? GENERAL_REGS : reg_preferred_class (allocno_reg[allocno]);
  709.   enum machine_mode mode = PSEUDO_REGNO_MODE (allocno_reg[allocno]);
  710.  
  711.   if (accept_call_clobbered)
  712.     COPY_HARD_REG_SET (used1, call_fixed_reg_set);
  713.   else if (allocno_calls_crossed[allocno] == 0)
  714.     COPY_HARD_REG_SET (used1, fixed_reg_set);
  715.   else
  716.     COPY_HARD_REG_SET (used1, call_used_reg_set);
  717.  
  718.   /* Some registers should not be allocated in global-alloc.  */
  719.   IOR_HARD_REG_SET (used1, no_global_alloc_regs);
  720.   if (losers)
  721.     IOR_HARD_REG_SET (used1, losers);
  722.  
  723.   IOR_COMPL_HARD_REG_SET (used1, reg_class_contents[(int) class]);
  724.   IOR_HARD_REG_SET (used1, hard_reg_conflicts[allocno]);
  725.  
  726.   /* Try each hard reg to see if it fits.  Do this in two passes.
  727.      In the first pass, skip registers that are prefered by some other pseudo
  728.      to give it a better chance of getting one of those registers.  Only if
  729.      we can't get a register when excluding those do we take one of them.
  730.      However, we never allocate a register for the first time in pass 0.  */
  731.  
  732.   COPY_HARD_REG_SET (used, used1);
  733.   IOR_COMPL_HARD_REG_SET (used, regs_used_so_far);
  734.   IOR_HARD_REG_SET (used, regs_someone_prefers[allocno]);
  735.   
  736.   best_reg = -1;
  737.   for (i = FIRST_PSEUDO_REGISTER, pass = 0;
  738.        pass <= 1 && i >= FIRST_PSEUDO_REGISTER;
  739.        pass++)
  740.     {
  741.       if (pass == 1)
  742.     COPY_HARD_REG_SET (used, used1);
  743.       for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
  744.     {
  745. #ifdef REG_ALLOC_ORDER
  746.       int regno = reg_alloc_order[i];
  747. #else
  748.       int regno = i;
  749. #endif
  750.       if (! TEST_HARD_REG_BIT (used, regno)
  751.           && HARD_REGNO_MODE_OK (regno, mode))
  752.         {
  753.           register int j;
  754.           register int lim = regno + HARD_REGNO_NREGS (regno, mode);
  755.           for (j = regno + 1;
  756.            (j < lim
  757.             && ! TEST_HARD_REG_BIT (used, j));
  758.            j++);
  759.           if (j == lim)
  760.         {
  761.           best_reg = regno;
  762.           break;
  763.         }
  764. #ifndef REG_ALLOC_ORDER
  765.           i = j;            /* Skip starting points we know will lose */
  766. #endif
  767.         }
  768.       }
  769.       }
  770.  
  771.   /* See if there is a preferred register with the same class as the register
  772.      we allocated above.  Making this restriction prevents register
  773.      preferencing from creating worse register allocation.
  774.  
  775.      Remove from the preferred registers and conflicting registers.  Note that
  776.      additional conflicts may have been added after `prune_preferences' was
  777.      called. 
  778.  
  779.      First do this for those register with copy preferences, then all
  780.      preferred registers.  */
  781.  
  782.   AND_COMPL_HARD_REG_SET (hard_reg_copy_preferences[allocno], used);
  783.   GO_IF_HARD_REG_SUBSET (hard_reg_copy_preferences[allocno],
  784.              reg_class_contents[(int) NO_REGS], no_copy_prefs);
  785.  
  786.   if (best_reg >= 0)
  787.     {
  788.       for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
  789.     if (TEST_HARD_REG_BIT (hard_reg_copy_preferences[allocno], i)
  790.         && HARD_REGNO_MODE_OK (i, mode)
  791.         && (REGNO_REG_CLASS (i) == REGNO_REG_CLASS (best_reg)
  792.         || reg_class_subset_p (REGNO_REG_CLASS (i),
  793.                        REGNO_REG_CLASS (best_reg))
  794.         || reg_class_subset_p (REGNO_REG_CLASS (best_reg),
  795.                        REGNO_REG_CLASS (i))))
  796.         {
  797.           register int j;
  798.           register int lim = i + HARD_REGNO_NREGS (i, mode);
  799.           for (j = i + 1;
  800.            (j < lim
  801.             && ! TEST_HARD_REG_BIT (used, j)
  802.             && (REGNO_REG_CLASS (j)
  803.                 == REGNO_REG_CLASS (best_reg + (j - i))
  804.             || reg_class_subset_p (REGNO_REG_CLASS (j),
  805.                            REGNO_REG_CLASS (best_reg + (j - i)))
  806.             || reg_class_subset_p (REGNO_REG_CLASS (best_reg + (j - i)),
  807.                            REGNO_REG_CLASS (j))));
  808.            j++);
  809.           if (j == lim)
  810.         {
  811.           best_reg = i;
  812.           goto no_prefs;
  813.         }
  814.         }
  815.     }
  816.  no_copy_prefs:
  817.  
  818.   AND_COMPL_HARD_REG_SET (hard_reg_preferences[allocno], used);
  819.   GO_IF_HARD_REG_SUBSET (hard_reg_preferences[allocno],
  820.              reg_class_contents[(int) NO_REGS], no_prefs);
  821.  
  822.   if (best_reg >= 0)
  823.     {
  824.       for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
  825.     if (TEST_HARD_REG_BIT (hard_reg_preferences[allocno], i)
  826.         && HARD_REGNO_MODE_OK (i, mode)
  827.         && (REGNO_REG_CLASS (i) == REGNO_REG_CLASS (best_reg)
  828.         || reg_class_subset_p (REGNO_REG_CLASS (i),
  829.                        REGNO_REG_CLASS (best_reg))
  830.         || reg_class_subset_p (REGNO_REG_CLASS (best_reg),
  831.                        REGNO_REG_CLASS (i))))
  832.         {
  833.           register int j;
  834.           register int lim = i + HARD_REGNO_NREGS (i, mode);
  835.           for (j = i + 1;
  836.            (j < lim
  837.             && ! TEST_HARD_REG_BIT (used, j)
  838.             && (REGNO_REG_CLASS (j)
  839.                 == REGNO_REG_CLASS (best_reg + (j - i))
  840.             || reg_class_subset_p (REGNO_REG_CLASS (j),
  841.                            REGNO_REG_CLASS (best_reg + (j - i)))
  842.             || reg_class_subset_p (REGNO_REG_CLASS (best_reg + (j - i)),
  843.                            REGNO_REG_CLASS (j))));
  844.            j++);
  845.           if (j == lim)
  846.         {
  847.           best_reg = i;
  848.           break;
  849.         }
  850.         }
  851.     }
  852.  no_prefs:
  853.  
  854.   /* Did we find a register?  */
  855.  
  856.   if (best_reg >= 0)
  857.     {
  858.       register int lim, j;
  859.       HARD_REG_SET this_reg;
  860.  
  861.       /* Yes.  Record it as the hard register of this pseudo-reg.  */
  862.       reg_renumber[allocno_reg[allocno]] = best_reg;
  863.       /* Also of any pseudo-regs that share with it.  */
  864.       if (reg_may_share[allocno_reg[allocno]])
  865.     for (j = FIRST_PSEUDO_REGISTER; j < max_regno; j++)
  866.       if (reg_allocno[j] == allocno)
  867.         reg_renumber[j] = best_reg;
  868.  
  869.       /* Make a set of the hard regs being allocated.  */
  870.       CLEAR_HARD_REG_SET (this_reg);
  871.       lim = best_reg + HARD_REGNO_NREGS (best_reg, mode);
  872.       for (j = best_reg; j < lim; j++)
  873.     {
  874.       SET_HARD_REG_BIT (this_reg, j);
  875.       SET_HARD_REG_BIT (regs_used_so_far, j);
  876.     }
  877.       /* For each other pseudo-reg conflicting with this one,
  878.      mark it as conflicting with the hard regs this one occupies.  */
  879.       lim = allocno;
  880.       for (j = 0; j < max_allocno; j++)
  881.     if (CONFLICTP (lim, j) || CONFLICTP (j, lim))
  882.       {
  883.         IOR_HARD_REG_SET (hard_reg_conflicts[j], this_reg);
  884.       }
  885.     }
  886.   else if (flag_caller_saves)
  887.     {
  888.       /* Did not find a register.  If it would be profitable to
  889.      allocate a call-clobbered register and save and restore it
  890.      around calls, do that.  */
  891.       if (! accept_call_clobbered
  892.       && allocno_calls_crossed[allocno] != 0
  893.       && CALLER_SAVE_PROFITABLE (allocno_n_refs[allocno],
  894.                      allocno_calls_crossed[allocno]))
  895.     {
  896.       find_reg (allocno, losers, all_regs_p, 1);
  897.       if (reg_renumber[allocno_reg[allocno]] >= 0)
  898.         caller_save_needed = 1;
  899.     }
  900.     }
  901. }
  902.  
  903. /* Called from `reload' to look for a hard reg to put pseudo reg REGNO in.
  904.    Perhaps it had previously seemed not worth a hard reg,
  905.    or perhaps its old hard reg has been commandeered for reloads.
  906.    FORBIDDEN_REGS indicates certain hard regs that may not be used, even if
  907.    they do not appear to be allocated.
  908.    If FORBIDDEN_REGS is zero, no regs are forbidden.  */
  909.  
  910. void
  911. retry_global_alloc (regno, forbidden_regs)
  912.      int regno;
  913.      HARD_REG_SET forbidden_regs;
  914. {
  915.   int allocno = reg_allocno[regno];
  916.   if (allocno >= 0)
  917.     {
  918.       /* If we have more than one register class,
  919.      first try allocating in the class that is cheapest
  920.      for this pseudo-reg.  If that fails, try any reg.  */
  921.       if (N_REG_CLASSES > 1)
  922.     find_reg (allocno, forbidden_regs, 0, 0);
  923.       if (reg_renumber[regno] < 0
  924.       && !reg_preferred_or_nothing (regno))
  925.     find_reg (allocno, forbidden_regs, 1, 0);
  926.     }
  927. }
  928.  
  929. /* Record a conflict between register REGNO
  930.    and everything currently live.
  931.    REGNO must not be a pseudo reg that was allocated
  932.    by local_alloc; such numbers must be translated through
  933.    reg_renumber before calling here.  */
  934.  
  935. static void
  936. record_one_conflict (regno)
  937.      int regno;
  938. {
  939.   register int j;
  940.  
  941.   if (regno < FIRST_PSEUDO_REGISTER)
  942.     /* When a hard register becomes live,
  943.        record conflicts with live pseudo regs.  */
  944.     for (j = 0; j < max_allocno; j++)
  945.       {
  946.     if (ALLOCNO_LIVE_P (j))
  947.       SET_HARD_REG_BIT (hard_reg_conflicts[j], regno);
  948.       }
  949.   else
  950.     /* When a pseudo-register becomes live,
  951.        record conflicts first with hard regs,
  952.        then with other pseudo regs.  */
  953.     {
  954.       register int ialloc = reg_allocno[regno];
  955.       register int ialloc_prod = ialloc * allocno_row_words;
  956.       IOR_HARD_REG_SET (hard_reg_conflicts[ialloc], hard_regs_live);
  957.       for (j = allocno_row_words - 1; j >= 0; j--)
  958.     {
  959. #if 0
  960.       int k;
  961.       for (k = 0; k < n_no_conflict_pairs; k++)
  962.         if (! ((j == no_conflict_pairs[k].allocno1
  963.             && ialloc == no_conflict_pairs[k].allocno2)
  964.            ||
  965.            (j == no_conflict_pairs[k].allocno2
  966.             && ialloc == no_conflict_pairs[k].allocno1)))
  967. #endif /* 0 */
  968.           conflicts[ialloc_prod + j] |= allocnos_live[j];
  969.     }
  970.     }
  971. }
  972.  
  973. /* Record all allocnos currently live as conflicting
  974.    with each other and with all hard regs currently live.
  975.    ALLOCNO_VEC is a vector of LEN allocnos, all allocnos that
  976.    are currently live.  Their bits are also flagged in allocnos_live.  */
  977.  
  978. static void
  979. record_conflicts (allocno_vec, len)
  980.      register short *allocno_vec;
  981.      register int len;
  982. {
  983.   register int allocno;
  984.   register int j;
  985.   register int ialloc_prod;
  986.  
  987.   while (--len >= 0)
  988.     {
  989.       allocno = allocno_vec[len];
  990.       ialloc_prod = allocno * allocno_row_words;
  991.       IOR_HARD_REG_SET (hard_reg_conflicts[allocno], hard_regs_live);
  992.       for (j = allocno_row_words - 1; j >= 0; j--)
  993.     conflicts[ialloc_prod + j] |= allocnos_live[j];
  994.     }
  995. }
  996.  
  997. /* Handle the case where REG is set by the insn being scanned,
  998.    during the forward scan to accumulate conflicts.
  999.    Store a 1 in regs_live or allocnos_live for this register, record how many
  1000.    consecutive hardware registers it actually needs,
  1001.    and record a conflict with all other registers already live.
  1002.  
  1003.    Note that even if REG does not remain alive after this insn,
  1004.    we must mark it here as live, to ensure a conflict between
  1005.    REG and any other regs set in this insn that really do live.
  1006.    This is because those other regs could be considered after this.
  1007.  
  1008.    REG might actually be something other than a register;
  1009.    if so, we do nothing.
  1010.  
  1011.    SETTER is 0 if this register was modified by an auto-increment (i.e.,
  1012.    a REG_INC note was found for it).
  1013.  
  1014.    CLOBBERs are processed here by calling mark_reg_clobber.  */ 
  1015.  
  1016. static void
  1017. mark_reg_store (orig_reg, setter)
  1018.      rtx orig_reg, setter;
  1019. {
  1020.   register int regno;
  1021.   register rtx reg = orig_reg;
  1022.  
  1023.   /* WORD is which word of a multi-register group is being stored.
  1024.      For the case where the store is actually into a SUBREG of REG.
  1025.      Except we don't use it; I believe the entire REG needs to be
  1026.      made live.  */
  1027.   int word = 0;
  1028.  
  1029.   if (GET_CODE (reg) == SUBREG)
  1030.     {
  1031.       word = SUBREG_WORD (reg);
  1032.       reg = SUBREG_REG (reg);
  1033.     }
  1034.  
  1035.   if (GET_CODE (reg) != REG)
  1036.     return;
  1037.  
  1038.   if (setter && GET_CODE (setter) == CLOBBER)
  1039.     {
  1040.       /* A clobber of a register should be processed here too.  */
  1041.       mark_reg_clobber (orig_reg, setter);
  1042.       return;
  1043.     }
  1044.  
  1045.   regs_set[n_regs_set++] = reg;
  1046.  
  1047.   if (setter)
  1048.     set_preference (reg, SET_SRC (setter));
  1049.  
  1050.   regno = REGNO (reg);
  1051.  
  1052.   if (reg_renumber[regno] >= 0)
  1053.     regno = reg_renumber[regno] /* + word */;
  1054.  
  1055.   /* Either this is one of the max_allocno pseudo regs not allocated,
  1056.      or it is or has a hardware reg.  First handle the pseudo-regs.  */
  1057.   if (regno >= FIRST_PSEUDO_REGISTER)
  1058.     {
  1059.       if (reg_allocno[regno] >= 0)
  1060.     {
  1061.       SET_ALLOCNO_LIVE (reg_allocno[regno]);
  1062.       record_one_conflict (regno);
  1063.     }
  1064.     }
  1065.   /* Handle hardware regs (and pseudos allocated to hard regs).  */
  1066.   else if (! fixed_regs[regno])
  1067.     {
  1068.       register int last = regno + HARD_REGNO_NREGS (regno, GET_MODE (reg));
  1069.       while (regno < last)
  1070.     {
  1071.       record_one_conflict (regno);
  1072.       SET_HARD_REG_BIT (hard_regs_live, regno);
  1073.       regno++;
  1074.     }
  1075.     }
  1076. }
  1077.  
  1078. /* Like mark_reg_set except notice just CLOBBERs; ignore SETs.  */
  1079.  
  1080. static void
  1081. mark_reg_clobber (reg, setter)
  1082.      rtx reg, setter;
  1083. {
  1084.   register int regno;
  1085.  
  1086.   /* WORD is which word of a multi-register group is being stored.
  1087.      For the case where the store is actually into a SUBREG of REG.
  1088.      Except we don't use it; I believe the entire REG needs to be
  1089.      made live.  */
  1090.   int word = 0;
  1091.  
  1092.   if (GET_CODE (setter) != CLOBBER)
  1093.     return;
  1094.  
  1095.   if (GET_CODE (reg) == SUBREG)
  1096.     {
  1097.       word = SUBREG_WORD (reg);
  1098.       reg = SUBREG_REG (reg);
  1099.     }
  1100.  
  1101.   if (GET_CODE (reg) != REG)
  1102.     return;
  1103.  
  1104.   regs_set[n_regs_set++] = reg;
  1105.  
  1106.   regno = REGNO (reg);
  1107.  
  1108.   if (reg_renumber[regno] >= 0)
  1109.     regno = reg_renumber[regno] /* + word */;
  1110.  
  1111.   /* Either this is one of the max_allocno pseudo regs not allocated,
  1112.      or it is or has a hardware reg.  First handle the pseudo-regs.  */
  1113.   if (regno >= FIRST_PSEUDO_REGISTER)
  1114.     {
  1115.       if (reg_allocno[regno] >= 0)
  1116.     {
  1117.       SET_ALLOCNO_LIVE (reg_allocno[regno]);
  1118.       record_one_conflict (regno);
  1119.     }
  1120.     }
  1121.   /* Handle hardware regs (and pseudos allocated to hard regs).  */
  1122.   else if (! fixed_regs[regno])
  1123.     {
  1124.       register int last = regno + HARD_REGNO_NREGS (regno, GET_MODE (reg));
  1125.       while (regno < last)
  1126.     {
  1127.       record_one_conflict (regno);
  1128.       SET_HARD_REG_BIT (hard_regs_live, regno);
  1129.       regno++;
  1130.     }
  1131.     }
  1132. }
  1133.  
  1134. /* Mark REG as being dead (following the insn being scanned now).
  1135.    Store a 0 in regs_live or allocnos_live for this register.  */
  1136.  
  1137. static void
  1138. mark_reg_death (reg)
  1139.      rtx reg;
  1140. {
  1141.   register int regno = REGNO (reg);
  1142.  
  1143.   /* For pseudo reg, see if it has been assigned a hardware reg.  */
  1144.   if (reg_renumber[regno] >= 0)
  1145.     regno = reg_renumber[regno];
  1146.  
  1147.   /* Either this is one of the max_allocno pseudo regs not allocated,
  1148.      or it is a hardware reg.  First handle the pseudo-regs.  */
  1149.   if (regno >= FIRST_PSEUDO_REGISTER)
  1150.     {
  1151.       if (reg_allocno[regno] >= 0)
  1152.     CLEAR_ALLOCNO_LIVE (reg_allocno[regno]);
  1153.     }
  1154.   /* Handle hardware regs (and pseudos allocated to hard regs).  */
  1155.   else if (! fixed_regs[regno])
  1156.     {
  1157.       /* Pseudo regs already assigned hardware regs are treated
  1158.      almost the same as explicit hardware regs.  */
  1159.       register int last = regno + HARD_REGNO_NREGS (regno, GET_MODE (reg));
  1160.       while (regno < last)
  1161.     {
  1162.       CLEAR_HARD_REG_BIT (hard_regs_live, regno);
  1163.       regno++;
  1164.     }
  1165.     }
  1166. }
  1167.  
  1168. /* Mark hard reg REGNO as currently live, assuming machine mode MODE
  1169.    for the value stored in it.  MODE determines how many consecutive
  1170.    registers are actually in use.  Do not record conflicts;
  1171.    it is assumed that the caller will do that.  */
  1172.  
  1173. static void
  1174. mark_reg_live_nc (regno, mode)
  1175.      register int regno;
  1176.      enum machine_mode mode;
  1177. {
  1178.   register int last = regno + HARD_REGNO_NREGS (regno, mode);
  1179.   while (regno < last)
  1180.     {
  1181.       SET_HARD_REG_BIT (hard_regs_live, regno);
  1182.       regno++;
  1183.     }
  1184. }
  1185.  
  1186. /* Try to set a preference for an allocno to a hard register.
  1187.    We are passed DEST and SRC which are the operands of a SET.  It is known
  1188.    that SRC is a register.  If SRC or the first operand of SRC is a register,
  1189.    try to set a preference.  If one of the two is a hard register and the other
  1190.    is a pseudo-register, mark the preference.
  1191.    
  1192.    Note that we are not as agressive as local-alloc in trying to tie a
  1193.    pseudo-register to a hard register.  */
  1194.  
  1195. static void
  1196. set_preference (dest, src)
  1197.      rtx dest, src;
  1198. {
  1199.   int src_regno, dest_regno;
  1200.   /* Amount to add to the hard regno for SRC, or subtract from that for DEST,
  1201.      to compensate for subregs in SRC or DEST.  */
  1202.   int offset = 0;
  1203.   int i;
  1204.   int copy = 1;
  1205.  
  1206.   if (GET_RTX_FORMAT (GET_CODE (src))[0] == 'e')
  1207.     src = XEXP (src, 0), copy = 0;
  1208.  
  1209.   /* Get the reg number for both SRC and DEST.
  1210.      If neither is a reg, give up.  */
  1211.  
  1212.   if (GET_CODE (src) == REG)
  1213.     src_regno = REGNO (src);
  1214.   else if (GET_CODE (src) == SUBREG && GET_CODE (SUBREG_REG (src)) == REG)
  1215.     {
  1216.       src_regno = REGNO (SUBREG_REG (src));
  1217.       offset += SUBREG_WORD (src);
  1218.     }
  1219.   else
  1220.     return;
  1221.  
  1222.   if (GET_CODE (dest) == REG)
  1223.     dest_regno = REGNO (dest);
  1224.   else if (GET_CODE (dest) == SUBREG && GET_CODE (SUBREG_REG (dest)) == REG)
  1225.     {
  1226.       dest_regno = REGNO (SUBREG_REG (dest));
  1227.       offset -= SUBREG_WORD (dest);
  1228.     }
  1229.   else
  1230.     return;
  1231.  
  1232.   /* Convert either or both to hard reg numbers.  */
  1233.  
  1234.   if (reg_renumber[src_regno] >= 0)
  1235.     src_regno = reg_renumber[src_regno];
  1236.  
  1237.   if (reg_renumber[dest_regno] >= 0)
  1238.     dest_regno = reg_renumber[dest_regno];
  1239.  
  1240.   /* Now if one is a hard reg and the other is a global pseudo
  1241.      then give the other a preference.  */
  1242.  
  1243.   if (dest_regno < FIRST_PSEUDO_REGISTER && src_regno >= FIRST_PSEUDO_REGISTER
  1244.       && reg_allocno[src_regno] >= 0)
  1245.     {
  1246.       dest_regno -= offset;
  1247.       if (dest_regno >= 0 && dest_regno < FIRST_PSEUDO_REGISTER)
  1248.     {
  1249.       if (copy)
  1250.         SET_REGBIT (hard_reg_copy_preferences,
  1251.             reg_allocno[src_regno], dest_regno);
  1252.  
  1253.       SET_REGBIT (hard_reg_preferences,
  1254.               reg_allocno[src_regno], dest_regno);
  1255.       for (i = dest_regno;
  1256.            i < dest_regno + HARD_REGNO_NREGS (dest_regno, GET_MODE (dest));
  1257.            i++)
  1258.         SET_REGBIT (hard_reg_full_preferences, reg_allocno[src_regno], i);
  1259.     }
  1260.     }
  1261.  
  1262.   if (src_regno < FIRST_PSEUDO_REGISTER && dest_regno >= FIRST_PSEUDO_REGISTER
  1263.       && reg_allocno[dest_regno] >= 0)
  1264.     {
  1265.       src_regno += offset;
  1266.       if (src_regno >= 0 && src_regno < FIRST_PSEUDO_REGISTER)
  1267.     {
  1268.       if (copy)
  1269.         SET_REGBIT (hard_reg_copy_preferences,
  1270.             reg_allocno[dest_regno], src_regno);
  1271.  
  1272.       SET_REGBIT (hard_reg_preferences,
  1273.               reg_allocno[dest_regno], src_regno);
  1274.       for (i = src_regno;
  1275.            i < src_regno + HARD_REGNO_NREGS (src_regno, GET_MODE (src));
  1276.            i++)
  1277.         SET_REGBIT (hard_reg_full_preferences, reg_allocno[dest_regno], i);
  1278.     }
  1279.     }
  1280. }
  1281.  
  1282. /* Print debugging trace information if -greg switch is given,
  1283.    showing the information on which the allocation decisions are based.  */
  1284.  
  1285. static void
  1286. dump_conflicts (file)
  1287.      FILE *file;
  1288. {
  1289.   register int i;
  1290.   register int has_preferences;
  1291.   fprintf (file, ";; %d regs to allocate:", max_allocno);
  1292.   for (i = 0; i < max_allocno; i++)
  1293.     {
  1294.       int j;
  1295.       fprintf (file, " %d", allocno_reg[allocno_order[i]]);
  1296.       for (j = 0; j < max_regno; j++)
  1297.     if (reg_allocno[j] == allocno_order[i]
  1298.         && j != allocno_reg[allocno_order[i]])
  1299.       fprintf (file, "+%d", j);
  1300.       if (allocno_size[allocno_order[i]] != 1)
  1301.     fprintf (file, " (%d)", allocno_size[allocno_order[i]]);
  1302.     }
  1303.   fprintf (file, "\n");
  1304.  
  1305.   for (i = 0; i < max_allocno; i++)
  1306.     {
  1307.       register int j;
  1308.       fprintf (file, ";; %d conflicts:", allocno_reg[i]);
  1309.       for (j = 0; j < max_allocno; j++)
  1310.     if (CONFLICTP (i, j) || CONFLICTP (j, i))
  1311.       fprintf (file, " %d", allocno_reg[j]);
  1312.       for (j = 0; j < FIRST_PSEUDO_REGISTER; j++)
  1313.     if (TEST_HARD_REG_BIT (hard_reg_conflicts[i], j))
  1314.       fprintf (file, " %d", j);
  1315.       fprintf (file, "\n");
  1316.  
  1317.       has_preferences = 0;
  1318.       for (j = 0; j < FIRST_PSEUDO_REGISTER; j++)
  1319.     if (TEST_HARD_REG_BIT (hard_reg_preferences[i], j))
  1320.       has_preferences = 1;
  1321.  
  1322.       if (! has_preferences)
  1323.     continue;
  1324.       fprintf (file, ";; %d preferences:", allocno_reg[i]);
  1325.       for (j = 0; j < FIRST_PSEUDO_REGISTER; j++)
  1326.     if (TEST_HARD_REG_BIT (hard_reg_preferences[i], j))
  1327.       fprintf (file, " %d", j);
  1328.       fprintf (file, "\n");
  1329.     }
  1330.   fprintf (file, "\n");
  1331. }
  1332.  
  1333. void
  1334. dump_global_regs (file)
  1335.      FILE *file;
  1336. {
  1337.   register int i, j;
  1338.   
  1339.   fprintf (file, ";; Register dispositions:\n");
  1340.   for (i = FIRST_PSEUDO_REGISTER, j = 0; i < max_regno; i++)
  1341.     if (reg_renumber[i] >= 0)
  1342.       {
  1343.     fprintf (file, "%d in %d  ", i, reg_renumber[i]);
  1344.         if (++j % 6 == 0)
  1345.       fprintf (file, "\n");
  1346.       }
  1347.  
  1348.   fprintf (file, "\n\n;; Hard regs used: ");
  1349.   for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
  1350.     if (regs_ever_live[i])
  1351.       fprintf (file, " %d", i);
  1352.   fprintf (file, "\n\n");
  1353. }
  1354.