OSDN Git Service

* flow.c (mark_set_1): Use REG_FREQ_FROM_BB.
[pf3gnuchains/gcc-fork.git] / gcc / global.c
1 /* Allocate registers for pseudo-registers that span basic blocks.
2    Copyright (C) 1987, 1988, 1991, 1994, 1996, 1997, 1998,
3    1999, 2000 Free Software Foundation, Inc.
4
5 This file is part of GNU CC.
6
7 GNU CC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
11
12 GNU CC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GNU CC; see the file COPYING.  If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA.  */
21
22
23 #include "config.h"
24 #include "system.h"
25
26 #include "machmode.h"
27 #include "hard-reg-set.h"
28 #include "rtl.h"
29 #include "tm_p.h"
30 #include "flags.h"
31 #include "basic-block.h"
32 #include "regs.h"
33 #include "function.h"
34 #include "insn-config.h"
35 #include "reload.h"
36 #include "output.h"
37 #include "toplev.h"
38
39 /* This pass of the compiler performs global register allocation.
40    It assigns hard register numbers to all the pseudo registers
41    that were not handled in local_alloc.  Assignments are recorded
42    in the vector reg_renumber, not by changing the rtl code.
43    (Such changes are made by final).  The entry point is
44    the function global_alloc.
45
46    After allocation is complete, the reload pass is run as a subroutine
47    of this pass, so that when a pseudo reg loses its hard reg due to
48    spilling it is possible to make a second attempt to find a hard
49    reg for it.  The reload pass is independent in other respects
50    and it is run even when stupid register allocation is in use.
51
52    1. Assign allocation-numbers (allocnos) to the pseudo-registers
53    still needing allocations and to the pseudo-registers currently
54    allocated by local-alloc which may be spilled by reload.
55    Set up tables reg_allocno and allocno_reg to map 
56    reg numbers to allocnos and vice versa.
57    max_allocno gets the number of allocnos in use.
58
59    2. Allocate a max_allocno by max_allocno conflict bit matrix and clear it.
60    Allocate a max_allocno by FIRST_PSEUDO_REGISTER conflict matrix
61    for conflicts between allocnos and explicit hard register use
62    (which includes use of pseudo-registers allocated by local_alloc).
63
64    3. For each basic block
65     walk forward through the block, recording which
66     pseudo-registers and which hardware registers are live.
67     Build the conflict matrix between the pseudo-registers
68     and another of pseudo-registers versus hardware registers.
69     Also record the preferred hardware registers
70     for each pseudo-register.
71
72    4. Sort a table of the allocnos into order of
73    desirability of the variables.
74
75    5. Allocate the variables in that order; each if possible into
76    a preferred register, else into another register.  */
77 \f
78 /* Number of pseudo-registers which are candidates for allocation. */
79
80 static int max_allocno;
81
82 /* Indexed by (pseudo) reg number, gives the allocno, or -1
83    for pseudo registers which are not to be allocated.  */
84
85 static int *reg_allocno;
86
87 struct allocno
88 {
89   int reg;
90   /* Gives the number of consecutive hard registers needed by that
91      pseudo reg.  */
92   int size;
93
94   /* Number of calls crossed by each allocno.  */
95   int calls_crossed;
96
97   /* Number of refs to each allocno.  */
98   int n_refs;
99
100   /* Frequency of uses of each allocno.  */
101   int freq;
102
103   /* Guess at live length of each allocno.
104      This is actually the max of the live lengths of the regs.  */
105   int live_length;
106
107   /* Set of hard regs conflicting with allocno N.  */
108
109   HARD_REG_SET hard_reg_conflicts;
110
111   /* Set of hard regs preferred by allocno N.
112      This is used to make allocnos go into regs that are copied to or from them,
113      when possible, to reduce register shuffling.  */
114
115   HARD_REG_SET hard_reg_preferences;
116
117   /* Similar, but just counts register preferences made in simple copy
118      operations, rather than arithmetic.  These are given priority because
119      we can always eliminate an insn by using these, but using a register
120      in the above list won't always eliminate an insn.  */
121
122   HARD_REG_SET hard_reg_copy_preferences;
123
124   /* Similar to hard_reg_preferences, but includes bits for subsequent
125      registers when an allocno is multi-word.  The above variable is used for
126      allocation while this is used to build reg_someone_prefers, below.  */
127
128   HARD_REG_SET hard_reg_full_preferences;
129
130   /* Set of hard registers that some later allocno has a preference for.  */
131
132   HARD_REG_SET regs_someone_prefers;
133 };
134
135 static struct allocno *allocno;
136
137 /* A vector of the integers from 0 to max_allocno-1,
138    sorted in the order of first-to-be-allocated first.  */
139
140 static int *allocno_order;
141
142 /* Indexed by (pseudo) reg number, gives the number of another
143    lower-numbered pseudo reg which can share a hard reg with this pseudo
144    *even if the two pseudos would otherwise appear to conflict*.  */
145
146 static int *reg_may_share;
147
148 /* Define the number of bits in each element of `conflicts' and what
149    type that element has.  We use the largest integer format on the
150    host machine.  */
151
152 #define INT_BITS HOST_BITS_PER_WIDE_INT
153 #define INT_TYPE HOST_WIDE_INT
154
155 /* max_allocno by max_allocno array of bits,
156    recording whether two allocno's conflict (can't go in the same
157    hardware register).
158
159    `conflicts' is symmetric after the call to mirror_conflicts.  */
160
161 static INT_TYPE *conflicts;
162
163 /* Number of ints require to hold max_allocno bits.
164    This is the length of a row in `conflicts'.  */
165
166 static int allocno_row_words;
167
168 /* Two macros to test or store 1 in an element of `conflicts'.  */
169
170 #define CONFLICTP(I, J) \
171  (conflicts[(I) * allocno_row_words + (unsigned)(J) / INT_BITS] \
172   & ((INT_TYPE) 1 << ((unsigned)(J) % INT_BITS)))
173
174 #define SET_CONFLICT(I, J) \
175  (conflicts[(I) * allocno_row_words + (unsigned)(J) / INT_BITS] \
176   |= ((INT_TYPE) 1 << ((unsigned)(J) % INT_BITS)))
177
178 /* For any allocno set in ALLOCNO_SET, set ALLOCNO to that allocno,
179    and execute CODE.  */
180 #define EXECUTE_IF_SET_IN_ALLOCNO_SET(ALLOCNO_SET, ALLOCNO, CODE)       \
181 do {                                                                    \
182   int i_;                                                               \
183   int allocno_;                                                         \
184   INT_TYPE *p_ = (ALLOCNO_SET);                                         \
185                                                                         \
186   for (i_ = allocno_row_words - 1, allocno_ = 0; i_ >= 0;               \
187        i_--, allocno_ += INT_BITS)                                      \
188     {                                                                   \
189       unsigned INT_TYPE word_ = (unsigned INT_TYPE) *p_++;              \
190                                                                         \
191       for ((ALLOCNO) = allocno_; word_; word_ >>= 1, (ALLOCNO)++)       \
192         {                                                               \
193           if (word_ & 1)                                                \
194             {CODE;}                                                     \
195         }                                                               \
196     }                                                                   \
197 } while (0)
198
199 /* This doesn't work for non-GNU C due to the way CODE is macro expanded.  */
200 #if 0
201 /* For any allocno that conflicts with IN_ALLOCNO, set OUT_ALLOCNO to
202    the conflicting allocno, and execute CODE.  This macro assumes that
203    mirror_conflicts has been run.  */
204 #define EXECUTE_IF_CONFLICT(IN_ALLOCNO, OUT_ALLOCNO, CODE)\
205   EXECUTE_IF_SET_IN_ALLOCNO_SET (conflicts + (IN_ALLOCNO) * allocno_row_words,\
206                                  OUT_ALLOCNO, (CODE))
207 #endif
208
209 /* Set of hard regs currently live (during scan of all insns).  */
210
211 static HARD_REG_SET hard_regs_live;
212
213 /* Set of registers that global-alloc isn't supposed to use.  */
214
215 static HARD_REG_SET no_global_alloc_regs;
216
217 /* Set of registers used so far.  */
218
219 static HARD_REG_SET regs_used_so_far;
220
221 /* Number of refs to each hard reg, as used by local alloc.
222    It is zero for a reg that contains global pseudos or is explicitly used.  */
223
224 static int local_reg_n_refs[FIRST_PSEUDO_REGISTER];
225
226 /* Frequency of uses of given hard reg.  */
227 static int local_reg_freq[FIRST_PSEUDO_REGISTER];
228
229 /* Guess at live length of each hard reg, as used by local alloc.
230    This is actually the sum of the live lengths of the specific regs.  */
231
232 static int local_reg_live_length[FIRST_PSEUDO_REGISTER];
233
234 /* Test a bit in TABLE, a vector of HARD_REG_SETs,
235    for vector element I, and hard register number J.  */
236
237 #define REGBITP(TABLE, I, J)     TEST_HARD_REG_BIT (allocno[I].TABLE, J)
238
239 /* Set to 1 a bit in a vector of HARD_REG_SETs.  Works like REGBITP.  */
240
241 #define SET_REGBIT(TABLE, I, J)  SET_HARD_REG_BIT (allocno[I].TABLE, J)
242
243 /* Bit mask for allocnos live at current point in the scan.  */
244
245 static INT_TYPE *allocnos_live;
246
247 /* Test, set or clear bit number I in allocnos_live,
248    a bit vector indexed by allocno.  */
249
250 #define ALLOCNO_LIVE_P(I)                               \
251   (allocnos_live[(unsigned)(I) / INT_BITS]              \
252    & ((INT_TYPE) 1 << ((unsigned)(I) % INT_BITS)))
253
254 #define SET_ALLOCNO_LIVE(I)                             \
255   (allocnos_live[(unsigned)(I) / INT_BITS]              \
256      |= ((INT_TYPE) 1 << ((unsigned)(I) % INT_BITS)))
257
258 #define CLEAR_ALLOCNO_LIVE(I)                           \
259   (allocnos_live[(unsigned)(I) / INT_BITS]              \
260      &= ~((INT_TYPE) 1 << ((unsigned)(I) % INT_BITS)))
261
262 /* This is turned off because it doesn't work right for DImode.
263    (And it is only used for DImode, so the other cases are worthless.)
264    The problem is that it isn't true that there is NO possibility of conflict;
265    only that there is no conflict if the two pseudos get the exact same regs.
266    If they were allocated with a partial overlap, there would be a conflict.
267    We can't safely turn off the conflict unless we have another way to
268    prevent the partial overlap.
269
270    Idea: change hard_reg_conflicts so that instead of recording which
271    hard regs the allocno may not overlap, it records where the allocno
272    may not start.  Change both where it is used and where it is updated.
273    Then there is a way to record that (reg:DI 108) may start at 10
274    but not at 9 or 11.  There is still the question of how to record
275    this semi-conflict between two pseudos.  */
276 #if 0
277 /* Reg pairs for which conflict after the current insn
278    is inhibited by a REG_NO_CONFLICT note.
279    If the table gets full, we ignore any other notes--that is conservative.  */
280 #define NUM_NO_CONFLICT_PAIRS 4
281 /* Number of pairs in use in this insn.  */
282 int n_no_conflict_pairs;
283 static struct { int allocno1, allocno2;}
284   no_conflict_pairs[NUM_NO_CONFLICT_PAIRS];
285 #endif /* 0 */
286
287 /* Record all regs that are set in any one insn.
288    Communication from mark_reg_{store,clobber} and global_conflicts.  */
289
290 static rtx *regs_set;
291 static int n_regs_set;
292
293 /* All registers that can be eliminated.  */
294
295 static HARD_REG_SET eliminable_regset;
296
297 static int allocno_compare      PARAMS ((const PTR, const PTR));
298 static void global_conflicts    PARAMS ((void));
299 static void mirror_conflicts    PARAMS ((void));
300 static void expand_preferences  PARAMS ((void));
301 static void prune_preferences   PARAMS ((void));
302 static void find_reg            PARAMS ((int, HARD_REG_SET, int, int, int));
303 static void record_one_conflict PARAMS ((int));
304 static void record_conflicts    PARAMS ((int *, int));
305 static void mark_reg_store      PARAMS ((rtx, rtx, void *));
306 static void mark_reg_clobber    PARAMS ((rtx, rtx, void *));
307 static void mark_reg_conflicts  PARAMS ((rtx));
308 static void mark_reg_death      PARAMS ((rtx));
309 static void mark_reg_live_nc    PARAMS ((int, enum machine_mode));
310 static void set_preference      PARAMS ((rtx, rtx));
311 static void dump_conflicts      PARAMS ((FILE *));
312 static void reg_becomes_live    PARAMS ((rtx, rtx, void *));
313 static void reg_dies            PARAMS ((int, enum machine_mode,
314                                        struct insn_chain *));
315 \f
316 /* Perform allocation of pseudo-registers not allocated by local_alloc.
317    FILE is a file to output debugging information on,
318    or zero if such output is not desired.
319
320    Return value is nonzero if reload failed
321    and we must not do any more for this function.  */
322
323 int
324 global_alloc (file)
325      FILE *file;
326 {
327   int retval;
328 #ifdef ELIMINABLE_REGS
329   static struct {int from, to; } eliminables[] = ELIMINABLE_REGS;
330 #endif
331   int need_fp
332     = (! flag_omit_frame_pointer
333 #ifdef EXIT_IGNORE_STACK
334        || (current_function_calls_alloca && EXIT_IGNORE_STACK)
335 #endif
336        || FRAME_POINTER_REQUIRED);
337
338   register size_t i;
339   rtx x;
340
341   max_allocno = 0;
342
343   /* A machine may have certain hard registers that
344      are safe to use only within a basic block.  */
345
346   CLEAR_HARD_REG_SET (no_global_alloc_regs);
347
348   /* Build the regset of all eliminable registers and show we can't use those
349      that we already know won't be eliminated.  */
350 #ifdef ELIMINABLE_REGS
351   for (i = 0; i < ARRAY_SIZE (eliminables); i++)
352     {
353       SET_HARD_REG_BIT (eliminable_regset, eliminables[i].from);
354
355       if (! CAN_ELIMINATE (eliminables[i].from, eliminables[i].to)
356           || (eliminables[i].to == STACK_POINTER_REGNUM && need_fp))
357         SET_HARD_REG_BIT (no_global_alloc_regs, eliminables[i].from);
358     }
359 #if FRAME_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
360   SET_HARD_REG_BIT (eliminable_regset, HARD_FRAME_POINTER_REGNUM);
361   if (need_fp)
362     SET_HARD_REG_BIT (no_global_alloc_regs, HARD_FRAME_POINTER_REGNUM);
363 #endif
364
365 #else
366   SET_HARD_REG_BIT (eliminable_regset, FRAME_POINTER_REGNUM);
367   if (need_fp)
368     SET_HARD_REG_BIT (no_global_alloc_regs, FRAME_POINTER_REGNUM);
369 #endif
370
371   /* Track which registers have already been used.  Start with registers
372      explicitly in the rtl, then registers allocated by local register
373      allocation.  */
374
375   CLEAR_HARD_REG_SET (regs_used_so_far);
376 #ifdef LEAF_REGISTERS
377   /* If we are doing the leaf function optimization, and this is a leaf
378      function, it means that the registers that take work to save are those
379      that need a register window.  So prefer the ones that can be used in
380      a leaf function.  */
381   {
382     char *cheap_regs;
383     char *leaf_regs = LEAF_REGISTERS;
384
385     if (only_leaf_regs_used () && leaf_function_p ())
386       cheap_regs = leaf_regs;
387     else
388       cheap_regs = call_used_regs;
389     for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
390       if (regs_ever_live[i] || cheap_regs[i])
391         SET_HARD_REG_BIT (regs_used_so_far, i);
392   }
393 #else
394   /* We consider registers that do not have to be saved over calls as if
395      they were already used since there is no cost in using them.  */
396   for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
397     if (regs_ever_live[i] || call_used_regs[i])
398       SET_HARD_REG_BIT (regs_used_so_far, i);
399 #endif
400
401   for (i = FIRST_PSEUDO_REGISTER; i < (size_t) max_regno; i++)
402     if (reg_renumber[i] >= 0)
403       SET_HARD_REG_BIT (regs_used_so_far, reg_renumber[i]);
404
405   /* Establish mappings from register number to allocation number
406      and vice versa.  In the process, count the allocnos.  */
407
408   reg_allocno = (int *) xmalloc (max_regno * sizeof (int));
409
410   for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
411     reg_allocno[i] = -1;
412
413   /* Initialize the shared-hard-reg mapping
414      from the list of pairs that may share.  */
415   reg_may_share = (int *) xcalloc (max_regno, sizeof (int));
416   for (x = regs_may_share; x; x = XEXP (XEXP (x, 1), 1))
417     {
418       int r1 = REGNO (XEXP (x, 0));
419       int r2 = REGNO (XEXP (XEXP (x, 1), 0));
420       if (r1 > r2)
421         reg_may_share[r1] = r2;
422       else
423         reg_may_share[r2] = r1;
424     }
425
426   for (i = FIRST_PSEUDO_REGISTER; i < (size_t) max_regno; i++)
427     /* Note that reg_live_length[i] < 0 indicates a "constant" reg
428        that we are supposed to refrain from putting in a hard reg.
429        -2 means do make an allocno but don't allocate it.  */
430     if (REG_N_REFS (i) != 0 && REG_LIVE_LENGTH (i) != -1
431         /* Don't allocate pseudos that cross calls,
432            if this function receives a nonlocal goto.  */
433         && (! current_function_has_nonlocal_label
434             || REG_N_CALLS_CROSSED (i) == 0))
435       {
436         if (reg_renumber[i] < 0 && reg_may_share[i] && reg_allocno[reg_may_share[i]] >= 0)
437           reg_allocno[i] = reg_allocno[reg_may_share[i]];
438         else
439           reg_allocno[i] = max_allocno++;
440         if (REG_LIVE_LENGTH (i) == 0)
441           abort ();
442       }
443     else
444       reg_allocno[i] = -1;
445
446   allocno = (struct allocno *) xcalloc (max_allocno, sizeof (struct allocno));
447
448   for (i = FIRST_PSEUDO_REGISTER; i < (size_t) max_regno; i++)
449     if (reg_allocno[i] >= 0)
450       {
451         int num = reg_allocno[i];
452         allocno[num].reg = i;
453         allocno[num].size = PSEUDO_REGNO_SIZE (i);
454         allocno[num].calls_crossed += REG_N_CALLS_CROSSED (i);
455         allocno[num].n_refs += REG_N_REFS (i);
456         allocno[num].freq += REG_FREQ (i);
457         if (allocno[num].live_length < REG_LIVE_LENGTH (i))
458           allocno[num].live_length = REG_LIVE_LENGTH (i);
459       }
460
461   /* Calculate amount of usage of each hard reg by pseudos
462      allocated by local-alloc.  This is to see if we want to
463      override it.  */
464   memset ((char *) local_reg_live_length, 0, sizeof local_reg_live_length);
465   memset ((char *) local_reg_n_refs, 0, sizeof local_reg_n_refs);
466   memset ((char *) local_reg_freq, 0, sizeof local_reg_freq);
467   for (i = FIRST_PSEUDO_REGISTER; i < (size_t) max_regno; i++)
468     if (reg_renumber[i] >= 0)
469       {
470         int regno = reg_renumber[i];
471         int endregno = regno + HARD_REGNO_NREGS (regno, PSEUDO_REGNO_MODE (i));
472         int j;
473
474         for (j = regno; j < endregno; j++)
475           {
476             local_reg_n_refs[j] += REG_N_REFS (i);
477             local_reg_freq[j] += REG_FREQ (i);
478             local_reg_live_length[j] += REG_LIVE_LENGTH (i);
479           }
480       }
481
482   /* We can't override local-alloc for a reg used not just by local-alloc.  */
483   for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
484     if (regs_ever_live[i])
485       local_reg_n_refs[i] = 0, local_reg_freq[i] = 0;
486         
487   allocno_row_words = (max_allocno + INT_BITS - 1) / INT_BITS;
488
489   /* We used to use alloca here, but the size of what it would try to
490      allocate would occasionally cause it to exceed the stack limit and
491      cause unpredictable core dumps.  Some examples were > 2Mb in size.  */
492   conflicts = (INT_TYPE *) xcalloc (max_allocno * allocno_row_words,
493                                     sizeof (INT_TYPE));
494
495   allocnos_live = (INT_TYPE *) xmalloc (allocno_row_words * sizeof (INT_TYPE));
496
497   /* If there is work to be done (at least one reg to allocate),
498      perform global conflict analysis and allocate the regs.  */
499
500   if (max_allocno > 0)
501     {
502       /* Scan all the insns and compute the conflicts among allocnos
503          and between allocnos and hard regs.  */
504
505       global_conflicts ();
506
507       mirror_conflicts ();
508
509       /* Eliminate conflicts between pseudos and eliminable registers.  If
510          the register is not eliminated, the pseudo won't really be able to
511          live in the eliminable register, so the conflict doesn't matter.
512          If we do eliminate the register, the conflict will no longer exist.
513          So in either case, we can ignore the conflict.  Likewise for
514          preferences.  */
515
516       for (i = 0; i < (size_t) max_allocno; i++)
517         {
518           AND_COMPL_HARD_REG_SET (allocno[i].hard_reg_conflicts,
519                                   eliminable_regset);
520           AND_COMPL_HARD_REG_SET (allocno[i].hard_reg_copy_preferences,
521                                   eliminable_regset);
522           AND_COMPL_HARD_REG_SET (allocno[i].hard_reg_preferences,
523                                   eliminable_regset);
524         }
525
526       /* Try to expand the preferences by merging them between allocnos.  */
527
528       expand_preferences ();
529
530       /* Determine the order to allocate the remaining pseudo registers.  */
531
532       allocno_order = (int *) xmalloc (max_allocno * sizeof (int));
533       for (i = 0; i < (size_t) max_allocno; i++)
534         allocno_order[i] = i;
535
536       /* Default the size to 1, since allocno_compare uses it to divide by.
537          Also convert allocno_live_length of zero to -1.  A length of zero
538          can occur when all the registers for that allocno have reg_live_length
539          equal to -2.  In this case, we want to make an allocno, but not
540          allocate it.  So avoid the divide-by-zero and set it to a low
541          priority.  */
542
543       for (i = 0; i < (size_t) max_allocno; i++)
544         {
545           if (allocno[i].size == 0)
546             allocno[i].size = 1;
547           if (allocno[i].live_length == 0)
548             allocno[i].live_length = -1;
549         }
550
551       qsort (allocno_order, max_allocno, sizeof (int), allocno_compare);
552       
553       prune_preferences ();
554
555       if (file)
556         dump_conflicts (file);
557
558       /* Try allocating them, one by one, in that order,
559          except for parameters marked with reg_live_length[regno] == -2.  */
560
561       for (i = 0; i < (size_t) max_allocno; i++)
562         if (reg_renumber[allocno[allocno_order[i]].reg] < 0
563             && REG_LIVE_LENGTH (allocno[allocno_order[i]].reg) >= 0)
564           {
565             /* If we have more than one register class,
566                first try allocating in the class that is cheapest
567                for this pseudo-reg.  If that fails, try any reg.  */
568             if (N_REG_CLASSES > 1)
569               {
570                 find_reg (allocno_order[i], 0, 0, 0, 0);
571                 if (reg_renumber[allocno[allocno_order[i]].reg] >= 0)
572                   continue;
573               }
574             if (reg_alternate_class (allocno[allocno_order[i]].reg) != NO_REGS)
575               find_reg (allocno_order[i], 0, 1, 0, 0);
576           }
577
578       free (allocno_order);
579     }
580
581   /* Do the reloads now while the allocno data still exist, so that we can
582      try to assign new hard regs to any pseudo regs that are spilled.  */
583
584 #if 0 /* We need to eliminate regs even if there is no rtl code,
585          for the sake of debugging information.  */
586   if (n_basic_blocks > 0)
587 #endif
588     {
589       build_insn_chain (get_insns ());
590       retval = reload (get_insns (), 1);
591     }
592
593   /* Clean up.  */
594   free (reg_allocno);
595   free (reg_may_share);
596   free (allocno);
597   free (conflicts);
598   free (allocnos_live);
599
600   return retval;
601 }
602
603 /* Sort predicate for ordering the allocnos.
604    Returns -1 (1) if *v1 should be allocated before (after) *v2.  */
605
606 static int
607 allocno_compare (v1p, v2p)
608      const PTR v1p;
609      const PTR v2p;
610 {
611   int v1 = *(const int *)v1p, v2 = *(const int *)v2p;
612   /* Note that the quotient will never be bigger than
613      the value of floor_log2 times the maximum number of
614      times a register can occur in one insn (surely less than 100)
615      weighted by the frequency (maximally REG_FREQ_MAX).
616      Multiplying this by 10000/REG_FREQ_MAX can't overflow.  */
617   register int pri1
618     = (((double) (floor_log2 (allocno[v1].n_refs) * allocno[v1].freq)
619         / allocno[v1].live_length)
620        * (10000 / REG_FREQ_MAX) * allocno[v1].size);
621   register int pri2
622     = (((double) (floor_log2 (allocno[v2].n_refs) * allocno[v2].freq)
623         / allocno[v2].live_length)
624        * (10000 / REG_FREQ_MAX) * allocno[v2].size);
625   if (pri2 - pri1)
626     return pri2 - pri1;
627
628   /* If regs are equally good, sort by allocno,
629      so that the results of qsort leave nothing to chance.  */
630   return v1 - v2;
631 }
632 \f
633 /* Scan the rtl code and record all conflicts and register preferences in the
634    conflict matrices and preference tables.  */
635
636 static void
637 global_conflicts ()
638 {
639   register int b, i;
640   register rtx insn;
641   int *block_start_allocnos;
642
643   /* Make a vector that mark_reg_{store,clobber} will store in.  */
644   regs_set = (rtx *) xmalloc (max_parallel * sizeof (rtx) * 2);
645
646   block_start_allocnos = (int *) xmalloc (max_allocno * sizeof (int));
647
648   for (b = 0; b < n_basic_blocks; b++)
649     {
650       memset ((char *) allocnos_live, 0, allocno_row_words * sizeof (INT_TYPE));
651
652       /* Initialize table of registers currently live
653          to the state at the beginning of this basic block.
654          This also marks the conflicts among hard registers
655          and any allocnos that are live.
656
657          For pseudo-regs, there is only one bit for each one
658          no matter how many hard regs it occupies.
659          This is ok; we know the size from PSEUDO_REGNO_SIZE.
660          For explicit hard regs, we cannot know the size that way
661          since one hard reg can be used with various sizes.
662          Therefore, we must require that all the hard regs
663          implicitly live as part of a multi-word hard reg
664          are explicitly marked in basic_block_live_at_start.  */
665
666       {
667         register regset old = BASIC_BLOCK (b)->global_live_at_start;
668         int ax = 0;
669
670         REG_SET_TO_HARD_REG_SET (hard_regs_live, old);
671         EXECUTE_IF_SET_IN_REG_SET (old, FIRST_PSEUDO_REGISTER, i,
672                                    {
673                                      register int a = reg_allocno[i];
674                                      if (a >= 0)
675                                        {
676                                          SET_ALLOCNO_LIVE (a);
677                                          block_start_allocnos[ax++] = a;
678                                        }
679                                      else if ((a = reg_renumber[i]) >= 0)
680                                        mark_reg_live_nc
681                                          (a, PSEUDO_REGNO_MODE (i));
682                                    });
683
684         /* Record that each allocno now live conflicts with each hard reg
685            now live.
686
687            It is not necessary to mark any conflicts between pseudos as
688            this point, even for pseudos which are live at the start of
689            the basic block.
690
691              Given two pseudos X and Y and any point in the CFG P.
692
693              On any path to point P where X and Y are live one of the
694              following conditions must be true:
695
696                 1. X is live at some instruction on the path that
697                    evaluates Y.
698
699                 2. Y is live at some instruction on the path that
700                    evaluates X.
701
702                 3. Either X or Y is not evaluted on the path to P
703                    (ie it is used uninitialized) and thus the
704                    conflict can be ignored.
705
706             In cases #1 and #2 the conflict will be recorded when we
707             scan the instruction that makes either X or Y become live.  */
708         record_conflicts (block_start_allocnos, ax);
709
710 #ifdef STACK_REGS
711         {
712           /* Pseudos can't go in stack regs at the start of a basic block
713              that is reached by an abnormal edge.  */
714
715           edge e;
716           for (e = BASIC_BLOCK (b)->pred; e ; e = e->pred_next)
717             if (e->flags & EDGE_ABNORMAL)
718               break;
719           if (e != NULL)
720             for (ax = FIRST_STACK_REG; ax <= LAST_STACK_REG; ax++)
721               record_one_conflict (ax);
722         }
723 #endif
724       }
725
726       insn = BLOCK_HEAD (b);
727
728       /* Scan the code of this basic block, noting which allocnos
729          and hard regs are born or die.  When one is born,
730          record a conflict with all others currently live.  */
731
732       while (1)
733         {
734           register RTX_CODE code = GET_CODE (insn);
735           register rtx link;
736
737           /* Make regs_set an empty set.  */
738
739           n_regs_set = 0;
740
741           if (code == INSN || code == CALL_INSN || code == JUMP_INSN)
742             {
743
744 #if 0
745               int i = 0;
746               for (link = REG_NOTES (insn);
747                    link && i < NUM_NO_CONFLICT_PAIRS;
748                    link = XEXP (link, 1))
749                 if (REG_NOTE_KIND (link) == REG_NO_CONFLICT)
750                   {
751                     no_conflict_pairs[i].allocno1
752                       = reg_allocno[REGNO (SET_DEST (PATTERN (insn)))];
753                     no_conflict_pairs[i].allocno2
754                       = reg_allocno[REGNO (XEXP (link, 0))];
755                     i++;
756                   }
757 #endif /* 0 */
758
759               /* Mark any registers clobbered by INSN as live,
760                  so they conflict with the inputs.  */
761
762               note_stores (PATTERN (insn), mark_reg_clobber, NULL);
763
764               /* Mark any registers dead after INSN as dead now.  */
765
766               for (link = REG_NOTES (insn); link; link = XEXP (link, 1))
767                 if (REG_NOTE_KIND (link) == REG_DEAD)
768                   mark_reg_death (XEXP (link, 0));
769
770               /* Mark any registers set in INSN as live,
771                  and mark them as conflicting with all other live regs.
772                  Clobbers are processed again, so they conflict with
773                  the registers that are set.  */
774
775               note_stores (PATTERN (insn), mark_reg_store, NULL);
776
777 #ifdef AUTO_INC_DEC
778               for (link = REG_NOTES (insn); link; link = XEXP (link, 1))
779                 if (REG_NOTE_KIND (link) == REG_INC)
780                   mark_reg_store (XEXP (link, 0), NULL_RTX, NULL);
781 #endif
782
783               /* If INSN has multiple outputs, then any reg that dies here
784                  and is used inside of an output
785                  must conflict with the other outputs.
786
787                  It is unsafe to use !single_set here since it will ignore an
788                  unused output.  Just because an output is unused does not mean
789                  the compiler can assume the side effect will not occur.
790                  Consider if REG appears in the address of an output and we
791                  reload the output.  If we allocate REG to the same hard
792                  register as an unused output we could set the hard register
793                  before the output reload insn.  */
794               if (GET_CODE (PATTERN (insn)) == PARALLEL && multiple_sets (insn))
795                 for (link = REG_NOTES (insn); link; link = XEXP (link, 1))
796                   if (REG_NOTE_KIND (link) == REG_DEAD)
797                     {
798                       int used_in_output = 0;
799                       int i;
800                       rtx reg = XEXP (link, 0);
801
802                       for (i = XVECLEN (PATTERN (insn), 0) - 1; i >= 0; i--)
803                         {
804                           rtx set = XVECEXP (PATTERN (insn), 0, i);
805                           if (GET_CODE (set) == SET
806                               && GET_CODE (SET_DEST (set)) != REG
807                               && !rtx_equal_p (reg, SET_DEST (set))
808                               && reg_overlap_mentioned_p (reg, SET_DEST (set)))
809                             used_in_output = 1;
810                         }
811                       if (used_in_output)
812                         mark_reg_conflicts (reg);
813                     }
814
815               /* Mark any registers set in INSN and then never used.  */
816
817               while (n_regs_set-- > 0)
818                 {
819                   rtx note = find_regno_note (insn, REG_UNUSED,
820                                               REGNO (regs_set[n_regs_set]));
821                   if (note)
822                     mark_reg_death (XEXP (note, 0));
823                 }
824             }
825
826           if (insn == BLOCK_END (b))
827             break;
828           insn = NEXT_INSN (insn);
829         }
830     }
831
832   /* Clean up.  */
833   free (block_start_allocnos);
834   free (regs_set);
835 }
836 /* Expand the preference information by looking for cases where one allocno
837    dies in an insn that sets an allocno.  If those two allocnos don't conflict,
838    merge any preferences between those allocnos.  */
839
840 static void
841 expand_preferences ()
842 {
843   rtx insn;
844   rtx link;
845   rtx set;
846
847   /* We only try to handle the most common cases here.  Most of the cases
848      where this wins are reg-reg copies.  */
849
850   for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
851     if (INSN_P (insn)
852         && (set = single_set (insn)) != 0
853         && GET_CODE (SET_DEST (set)) == REG
854         && reg_allocno[REGNO (SET_DEST (set))] >= 0)
855       for (link = REG_NOTES (insn); link; link = XEXP (link, 1))
856         if (REG_NOTE_KIND (link) == REG_DEAD
857             && GET_CODE (XEXP (link, 0)) == REG
858             && reg_allocno[REGNO (XEXP (link, 0))] >= 0
859             && ! CONFLICTP (reg_allocno[REGNO (SET_DEST (set))],
860                             reg_allocno[REGNO (XEXP (link, 0))]))
861           {
862             int a1 = reg_allocno[REGNO (SET_DEST (set))];
863             int a2 = reg_allocno[REGNO (XEXP (link, 0))];
864
865             if (XEXP (link, 0) == SET_SRC (set))
866               {
867                 IOR_HARD_REG_SET (allocno[a1].hard_reg_copy_preferences,
868                                   allocno[a2].hard_reg_copy_preferences);
869                 IOR_HARD_REG_SET (allocno[a2].hard_reg_copy_preferences,
870                                   allocno[a1].hard_reg_copy_preferences);
871               }
872
873             IOR_HARD_REG_SET (allocno[a1].hard_reg_preferences,
874                               allocno[a2].hard_reg_preferences);
875             IOR_HARD_REG_SET (allocno[a2].hard_reg_preferences,
876                               allocno[a1].hard_reg_preferences);
877             IOR_HARD_REG_SET (allocno[a1].hard_reg_full_preferences,
878                               allocno[a2].hard_reg_full_preferences);
879             IOR_HARD_REG_SET (allocno[a2].hard_reg_full_preferences,
880                               allocno[a1].hard_reg_full_preferences);
881           }
882 }
883 \f
884 /* Prune the preferences for global registers to exclude registers that cannot
885    be used.
886    
887    Compute `regs_someone_prefers', which is a bitmask of the hard registers
888    that are preferred by conflicting registers of lower priority.  If possible,
889    we will avoid using these registers.  */
890    
891 static void
892 prune_preferences ()
893 {
894   int i;
895   int num;
896   int *allocno_to_order = (int *) xmalloc (max_allocno * sizeof (int));
897   
898   /* Scan least most important to most important.
899      For each allocno, remove from preferences registers that cannot be used,
900      either because of conflicts or register type.  Then compute all registers
901      preferred by each lower-priority register that conflicts.  */
902
903   for (i = max_allocno - 1; i >= 0; i--)
904     {
905       HARD_REG_SET temp;
906
907       num = allocno_order[i];
908       allocno_to_order[num] = i;
909       COPY_HARD_REG_SET (temp, allocno[num].hard_reg_conflicts);
910
911       if (allocno[num].calls_crossed == 0)
912         IOR_HARD_REG_SET (temp, fixed_reg_set);
913       else
914         IOR_HARD_REG_SET (temp, call_used_reg_set);
915
916       IOR_COMPL_HARD_REG_SET
917         (temp,
918          reg_class_contents[(int) reg_preferred_class (allocno[num].reg)]);
919
920       AND_COMPL_HARD_REG_SET (allocno[num].hard_reg_preferences, temp);
921       AND_COMPL_HARD_REG_SET (allocno[num].hard_reg_copy_preferences, temp);
922       AND_COMPL_HARD_REG_SET (allocno[num].hard_reg_full_preferences, temp);
923     }
924
925   for (i = max_allocno - 1; i >= 0; i--)
926     {
927       /* Merge in the preferences of lower-priority registers (they have
928          already been pruned).  If we also prefer some of those registers,
929          don't exclude them unless we are of a smaller size (in which case
930          we want to give the lower-priority allocno the first chance for
931          these registers).  */
932       HARD_REG_SET temp, temp2;
933       int allocno2;
934
935       num = allocno_order[i];
936
937       CLEAR_HARD_REG_SET (temp);
938       CLEAR_HARD_REG_SET (temp2);
939
940       EXECUTE_IF_SET_IN_ALLOCNO_SET (conflicts + num * allocno_row_words,
941                                      allocno2,
942         {
943           if (allocno_to_order[allocno2] > i)
944             {
945               if (allocno[allocno2].size <= allocno[num].size)
946                 IOR_HARD_REG_SET (temp,
947                                   allocno[allocno2].hard_reg_full_preferences);
948               else
949                 IOR_HARD_REG_SET (temp2,
950                                   allocno[allocno2].hard_reg_full_preferences);
951             }
952         });
953
954       AND_COMPL_HARD_REG_SET (temp, allocno[num].hard_reg_full_preferences);
955       IOR_HARD_REG_SET (temp, temp2);
956       COPY_HARD_REG_SET (allocno[num].regs_someone_prefers, temp);
957     }
958   free (allocno_to_order);
959 }
960 \f
961 /* Assign a hard register to allocno NUM; look for one that is the beginning
962    of a long enough stretch of hard regs none of which conflicts with ALLOCNO.
963    The registers marked in PREFREGS are tried first.
964
965    LOSERS, if non-zero, is a HARD_REG_SET indicating registers that cannot
966    be used for this allocation.
967
968    If ALT_REGS_P is zero, consider only the preferred class of ALLOCNO's reg.
969    Otherwise ignore that preferred class and use the alternate class.
970
971    If ACCEPT_CALL_CLOBBERED is nonzero, accept a call-clobbered hard reg that
972    will have to be saved and restored at calls.
973
974    RETRYING is nonzero if this is called from retry_global_alloc.
975
976    If we find one, record it in reg_renumber.
977    If not, do nothing.  */
978
979 static void
980 find_reg (num, losers, alt_regs_p, accept_call_clobbered, retrying)
981      int num;
982      HARD_REG_SET losers;
983      int alt_regs_p;
984      int accept_call_clobbered;
985      int retrying;
986 {
987   register int i, best_reg, pass;
988 #ifdef HARD_REG_SET
989   register              /* Declare it register if it's a scalar.  */
990 #endif
991     HARD_REG_SET used, used1, used2;
992
993   enum reg_class class = (alt_regs_p
994                           ? reg_alternate_class (allocno[num].reg)
995                           : reg_preferred_class (allocno[num].reg));
996   enum machine_mode mode = PSEUDO_REGNO_MODE (allocno[num].reg);
997
998   if (accept_call_clobbered)
999     COPY_HARD_REG_SET (used1, call_fixed_reg_set);
1000   else if (allocno[num].calls_crossed == 0)
1001     COPY_HARD_REG_SET (used1, fixed_reg_set);
1002   else
1003     COPY_HARD_REG_SET (used1, call_used_reg_set);
1004
1005   /* Some registers should not be allocated in global-alloc.  */
1006   IOR_HARD_REG_SET (used1, no_global_alloc_regs);
1007   if (losers)
1008     IOR_HARD_REG_SET (used1, losers);
1009
1010   IOR_COMPL_HARD_REG_SET (used1, reg_class_contents[(int) class]);
1011   COPY_HARD_REG_SET (used2, used1);
1012
1013   IOR_HARD_REG_SET (used1, allocno[num].hard_reg_conflicts);
1014
1015 #ifdef CLASS_CANNOT_CHANGE_MODE
1016   if (REG_CHANGES_MODE (allocno[num].reg))
1017     IOR_HARD_REG_SET (used1,
1018                       reg_class_contents[(int) CLASS_CANNOT_CHANGE_MODE]);
1019 #endif
1020
1021   /* Try each hard reg to see if it fits.  Do this in two passes.
1022      In the first pass, skip registers that are preferred by some other pseudo
1023      to give it a better chance of getting one of those registers.  Only if
1024      we can't get a register when excluding those do we take one of them.
1025      However, we never allocate a register for the first time in pass 0.  */
1026
1027   COPY_HARD_REG_SET (used, used1);
1028   IOR_COMPL_HARD_REG_SET (used, regs_used_so_far);
1029   IOR_HARD_REG_SET (used, allocno[num].regs_someone_prefers);
1030   
1031   best_reg = -1;
1032   for (i = FIRST_PSEUDO_REGISTER, pass = 0;
1033        pass <= 1 && i >= FIRST_PSEUDO_REGISTER;
1034        pass++)
1035     {
1036       if (pass == 1)
1037         COPY_HARD_REG_SET (used, used1);
1038       for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
1039         {
1040 #ifdef REG_ALLOC_ORDER
1041           int regno = reg_alloc_order[i];
1042 #else
1043           int regno = i;
1044 #endif
1045           if (! TEST_HARD_REG_BIT (used, regno)
1046               && HARD_REGNO_MODE_OK (regno, mode)
1047               && (allocno[num].calls_crossed == 0
1048                   || accept_call_clobbered
1049                   || ! HARD_REGNO_CALL_PART_CLOBBERED (regno, mode)))
1050             {
1051               register int j;
1052               register int lim = regno + HARD_REGNO_NREGS (regno, mode);
1053               for (j = regno + 1;
1054                    (j < lim
1055                     && ! TEST_HARD_REG_BIT (used, j));
1056                    j++);
1057               if (j == lim)
1058                 {
1059                   best_reg = regno;
1060                   break;
1061                 }
1062 #ifndef REG_ALLOC_ORDER
1063               i = j;                    /* Skip starting points we know will lose */
1064 #endif
1065             }
1066           }
1067       }
1068
1069   /* See if there is a preferred register with the same class as the register
1070      we allocated above.  Making this restriction prevents register
1071      preferencing from creating worse register allocation.
1072
1073      Remove from the preferred registers and conflicting registers.  Note that
1074      additional conflicts may have been added after `prune_preferences' was
1075      called. 
1076
1077      First do this for those register with copy preferences, then all
1078      preferred registers.  */
1079
1080   AND_COMPL_HARD_REG_SET (allocno[num].hard_reg_copy_preferences, used);
1081   GO_IF_HARD_REG_SUBSET (allocno[num].hard_reg_copy_preferences,
1082                          reg_class_contents[(int) NO_REGS], no_copy_prefs);
1083
1084   if (best_reg >= 0)
1085     {
1086       for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
1087         if (TEST_HARD_REG_BIT (allocno[num].hard_reg_copy_preferences, i)
1088             && HARD_REGNO_MODE_OK (i, mode)
1089             && (REGNO_REG_CLASS (i) == REGNO_REG_CLASS (best_reg)
1090                 || reg_class_subset_p (REGNO_REG_CLASS (i),
1091                                        REGNO_REG_CLASS (best_reg))
1092                 || reg_class_subset_p (REGNO_REG_CLASS (best_reg),
1093                                        REGNO_REG_CLASS (i))))
1094             {
1095               register int j;
1096               register int lim = i + HARD_REGNO_NREGS (i, mode);
1097               for (j = i + 1;
1098                    (j < lim
1099                     && ! TEST_HARD_REG_BIT (used, j)
1100                     && (REGNO_REG_CLASS (j)
1101                         == REGNO_REG_CLASS (best_reg + (j - i))
1102                         || reg_class_subset_p (REGNO_REG_CLASS (j),
1103                                                REGNO_REG_CLASS (best_reg + (j - i)))
1104                         || reg_class_subset_p (REGNO_REG_CLASS (best_reg + (j - i)),
1105                                                REGNO_REG_CLASS (j))));
1106                    j++);
1107               if (j == lim)
1108                 {
1109                   best_reg = i;
1110                   goto no_prefs;
1111                 }
1112             }
1113     }
1114  no_copy_prefs:
1115
1116   AND_COMPL_HARD_REG_SET (allocno[num].hard_reg_preferences, used);
1117   GO_IF_HARD_REG_SUBSET (allocno[num].hard_reg_preferences,
1118                          reg_class_contents[(int) NO_REGS], no_prefs);
1119
1120   if (best_reg >= 0)
1121     {
1122       for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
1123         if (TEST_HARD_REG_BIT (allocno[num].hard_reg_preferences, i)
1124             && HARD_REGNO_MODE_OK (i, mode)
1125             && (REGNO_REG_CLASS (i) == REGNO_REG_CLASS (best_reg)
1126                 || reg_class_subset_p (REGNO_REG_CLASS (i),
1127                                        REGNO_REG_CLASS (best_reg))
1128                 || reg_class_subset_p (REGNO_REG_CLASS (best_reg),
1129                                        REGNO_REG_CLASS (i))))
1130             {
1131               register int j;
1132               register int lim = i + HARD_REGNO_NREGS (i, mode);
1133               for (j = i + 1;
1134                    (j < lim
1135                     && ! TEST_HARD_REG_BIT (used, j)
1136                     && (REGNO_REG_CLASS (j)
1137                         == REGNO_REG_CLASS (best_reg + (j - i))
1138                         || reg_class_subset_p (REGNO_REG_CLASS (j),
1139                                                REGNO_REG_CLASS (best_reg + (j - i)))
1140                         || reg_class_subset_p (REGNO_REG_CLASS (best_reg + (j - i)),
1141                                                REGNO_REG_CLASS (j))));
1142                    j++);
1143               if (j == lim)
1144                 {
1145                   best_reg = i;
1146                   break;
1147                 }
1148             }
1149     }
1150  no_prefs:
1151
1152   /* If we haven't succeeded yet, try with caller-saves. 
1153      We need not check to see if the current function has nonlocal
1154      labels because we don't put any pseudos that are live over calls in
1155      registers in that case.  */
1156
1157   if (flag_caller_saves && best_reg < 0)
1158     {
1159       /* Did not find a register.  If it would be profitable to
1160          allocate a call-clobbered register and save and restore it
1161          around calls, do that.  */
1162       if (! accept_call_clobbered
1163           && allocno[num].calls_crossed != 0
1164           && CALLER_SAVE_PROFITABLE (allocno[num].n_refs,
1165                                      allocno[num].calls_crossed))
1166         {
1167           HARD_REG_SET new_losers;
1168           if (! losers)
1169             CLEAR_HARD_REG_SET (new_losers);
1170           else
1171             COPY_HARD_REG_SET (new_losers, losers);
1172             
1173           IOR_HARD_REG_SET(new_losers, losing_caller_save_reg_set);
1174           find_reg (num, new_losers, alt_regs_p, 1, retrying);
1175           if (reg_renumber[allocno[num].reg] >= 0)
1176             {
1177               caller_save_needed = 1;
1178               return;
1179             }
1180         }
1181     }
1182
1183   /* If we haven't succeeded yet,
1184      see if some hard reg that conflicts with us
1185      was utilized poorly by local-alloc.
1186      If so, kick out the regs that were put there by local-alloc
1187      so we can use it instead.  */
1188   if (best_reg < 0 && !retrying
1189       /* Let's not bother with multi-reg allocnos.  */
1190       && allocno[num].size == 1)
1191     {
1192       /* Count from the end, to find the least-used ones first.  */
1193       for (i = FIRST_PSEUDO_REGISTER - 1; i >= 0; i--)
1194         {
1195 #ifdef REG_ALLOC_ORDER
1196           int regno = reg_alloc_order[i];
1197 #else
1198           int regno = i;
1199 #endif
1200
1201           if (local_reg_n_refs[regno] != 0
1202               /* Don't use a reg no good for this pseudo.  */
1203               && ! TEST_HARD_REG_BIT (used2, regno)
1204               && HARD_REGNO_MODE_OK (regno, mode)
1205 #ifdef CLASS_CANNOT_CHANGE_MODE
1206               && ! (REG_CHANGES_MODE (allocno[num].reg)
1207                     && (TEST_HARD_REG_BIT
1208                         (reg_class_contents[(int) CLASS_CANNOT_CHANGE_MODE],
1209                          regno)))
1210 #endif
1211               )
1212             {
1213               /* We explicitly evaluate the divide results into temporary
1214                  variables so as to avoid excess precision problems that occur
1215                  on a i386-unknown-sysv4.2 (unixware) host.  */
1216                  
1217               double tmp1 = ((double) local_reg_freq[regno]
1218                             / local_reg_live_length[regno]);
1219               double tmp2 = ((double) allocno[num].freq
1220                              / allocno[num].live_length);
1221
1222               if (tmp1 < tmp2)
1223                 {
1224                   /* Hard reg REGNO was used less in total by local regs
1225                      than it would be used by this one allocno!  */
1226                   int k;
1227                   for (k = 0; k < max_regno; k++)
1228                     if (reg_renumber[k] >= 0)
1229                       {
1230                         int r = reg_renumber[k];
1231                         int endregno
1232                           = r + HARD_REGNO_NREGS (r, PSEUDO_REGNO_MODE (k));
1233
1234                         if (regno >= r && regno < endregno)
1235                           reg_renumber[k] = -1;
1236                       }
1237
1238                   best_reg = regno;
1239                   break;
1240                 }
1241             }
1242         }
1243     }
1244
1245   /* Did we find a register?  */
1246
1247   if (best_reg >= 0)
1248     {
1249       register int lim, j;
1250       HARD_REG_SET this_reg;
1251
1252       /* Yes.  Record it as the hard register of this pseudo-reg.  */
1253       reg_renumber[allocno[num].reg] = best_reg;
1254       /* Also of any pseudo-regs that share with it.  */
1255       if (reg_may_share[allocno[num].reg])
1256         for (j = FIRST_PSEUDO_REGISTER; j < max_regno; j++)
1257           if (reg_allocno[j] == num)
1258             reg_renumber[j] = best_reg;
1259
1260       /* Make a set of the hard regs being allocated.  */
1261       CLEAR_HARD_REG_SET (this_reg);
1262       lim = best_reg + HARD_REGNO_NREGS (best_reg, mode);
1263       for (j = best_reg; j < lim; j++)
1264         {
1265           SET_HARD_REG_BIT (this_reg, j);
1266           SET_HARD_REG_BIT (regs_used_so_far, j);
1267           /* This is no longer a reg used just by local regs.  */
1268           local_reg_n_refs[j] = 0;
1269           local_reg_freq[j] = 0;
1270         }
1271       /* For each other pseudo-reg conflicting with this one,
1272          mark it as conflicting with the hard regs this one occupies.  */
1273       lim = num;
1274       EXECUTE_IF_SET_IN_ALLOCNO_SET (conflicts + lim * allocno_row_words, j,
1275         {
1276           IOR_HARD_REG_SET (allocno[j].hard_reg_conflicts, this_reg);
1277         });
1278     }
1279 }
1280 \f
1281 /* Called from `reload' to look for a hard reg to put pseudo reg REGNO in.
1282    Perhaps it had previously seemed not worth a hard reg,
1283    or perhaps its old hard reg has been commandeered for reloads.
1284    FORBIDDEN_REGS indicates certain hard regs that may not be used, even if
1285    they do not appear to be allocated.
1286    If FORBIDDEN_REGS is zero, no regs are forbidden.  */
1287
1288 void
1289 retry_global_alloc (regno, forbidden_regs)
1290      int regno;
1291      HARD_REG_SET forbidden_regs;
1292 {
1293   int allocno = reg_allocno[regno];
1294   if (allocno >= 0)
1295     {
1296       /* If we have more than one register class,
1297          first try allocating in the class that is cheapest
1298          for this pseudo-reg.  If that fails, try any reg.  */
1299       if (N_REG_CLASSES > 1)
1300         find_reg (allocno, forbidden_regs, 0, 0, 1);
1301       if (reg_renumber[regno] < 0
1302           && reg_alternate_class (regno) != NO_REGS)
1303         find_reg (allocno, forbidden_regs, 1, 0, 1);
1304
1305       /* If we found a register, modify the RTL for the register to
1306          show the hard register, and mark that register live.  */
1307       if (reg_renumber[regno] >= 0)
1308         {
1309           REGNO (regno_reg_rtx[regno]) = reg_renumber[regno];
1310           mark_home_live (regno);
1311         }
1312     }
1313 }
1314 \f
1315 /* Record a conflict between register REGNO
1316    and everything currently live.
1317    REGNO must not be a pseudo reg that was allocated
1318    by local_alloc; such numbers must be translated through
1319    reg_renumber before calling here.  */
1320
1321 static void
1322 record_one_conflict (regno)
1323      int regno;
1324 {
1325   register int j;
1326
1327   if (regno < FIRST_PSEUDO_REGISTER)
1328     /* When a hard register becomes live,
1329        record conflicts with live pseudo regs.  */
1330     EXECUTE_IF_SET_IN_ALLOCNO_SET (allocnos_live, j,
1331       {
1332         SET_HARD_REG_BIT (allocno[j].hard_reg_conflicts, regno);
1333       });
1334   else
1335     /* When a pseudo-register becomes live,
1336        record conflicts first with hard regs,
1337        then with other pseudo regs.  */
1338     {
1339       register int ialloc = reg_allocno[regno];
1340       register int ialloc_prod = ialloc * allocno_row_words;
1341       IOR_HARD_REG_SET (allocno[ialloc].hard_reg_conflicts, hard_regs_live);
1342       for (j = allocno_row_words - 1; j >= 0; j--)
1343         {
1344 #if 0
1345           int k;
1346           for (k = 0; k < n_no_conflict_pairs; k++)
1347             if (! ((j == no_conflict_pairs[k].allocno1
1348                     && ialloc == no_conflict_pairs[k].allocno2)
1349                    ||
1350                    (j == no_conflict_pairs[k].allocno2
1351                     && ialloc == no_conflict_pairs[k].allocno1)))
1352 #endif /* 0 */
1353               conflicts[ialloc_prod + j] |= allocnos_live[j];
1354         }
1355     }
1356 }
1357
1358 /* Record all allocnos currently live as conflicting
1359    with all hard regs currently live.
1360
1361    ALLOCNO_VEC is a vector of LEN allocnos, all allocnos that
1362    are currently live.  Their bits are also flagged in allocnos_live.  */
1363
1364 static void
1365 record_conflicts (allocno_vec, len)
1366      register int *allocno_vec;
1367      register int len;
1368 {
1369   register int num;
1370   register int ialloc_prod;
1371
1372   while (--len >= 0)
1373     {
1374       num = allocno_vec[len];
1375       ialloc_prod = num * allocno_row_words;
1376       IOR_HARD_REG_SET (allocno[num].hard_reg_conflicts, hard_regs_live);
1377     }
1378 }
1379
1380 /* If CONFLICTP (i, j) is true, make sure CONFLICTP (j, i) is also true.  */
1381 static void
1382 mirror_conflicts ()
1383 {
1384   register int i, j;
1385   int rw = allocno_row_words;
1386   int rwb = rw * INT_BITS;
1387   INT_TYPE *p = conflicts;
1388   INT_TYPE *q0 = conflicts, *q1, *q2;
1389   unsigned INT_TYPE mask;
1390
1391   for (i = max_allocno - 1, mask = 1; i >= 0; i--, mask <<= 1)
1392     {
1393       if (! mask)
1394         {
1395           mask = 1;
1396           q0++;
1397         }
1398       for (j = allocno_row_words - 1, q1 = q0; j >= 0; j--, q1 += rwb)
1399         {
1400           unsigned INT_TYPE word;
1401
1402           for (word = (unsigned INT_TYPE) *p++, q2 = q1; word;
1403                word >>= 1, q2 += rw)
1404             {
1405               if (word & 1)
1406                 *q2 |= mask;
1407             }
1408         }
1409     }
1410 }
1411 \f
1412 /* Handle the case where REG is set by the insn being scanned,
1413    during the forward scan to accumulate conflicts.
1414    Store a 1 in regs_live or allocnos_live for this register, record how many
1415    consecutive hardware registers it actually needs,
1416    and record a conflict with all other registers already live.
1417
1418    Note that even if REG does not remain alive after this insn,
1419    we must mark it here as live, to ensure a conflict between
1420    REG and any other regs set in this insn that really do live.
1421    This is because those other regs could be considered after this.
1422
1423    REG might actually be something other than a register;
1424    if so, we do nothing.
1425
1426    SETTER is 0 if this register was modified by an auto-increment (i.e.,
1427    a REG_INC note was found for it).  */
1428
1429 static void
1430 mark_reg_store (reg, setter, data)
1431      rtx reg, setter;
1432      void *data ATTRIBUTE_UNUSED;
1433 {
1434   register int regno;
1435
1436   if (GET_CODE (reg) == SUBREG)
1437     reg = SUBREG_REG (reg);
1438
1439   if (GET_CODE (reg) != REG)
1440     return;
1441
1442   regs_set[n_regs_set++] = reg;
1443
1444   if (setter && GET_CODE (setter) != CLOBBER)
1445     set_preference (reg, SET_SRC (setter));
1446
1447   regno = REGNO (reg);
1448
1449   /* Either this is one of the max_allocno pseudo regs not allocated,
1450      or it is or has a hardware reg.  First handle the pseudo-regs.  */
1451   if (regno >= FIRST_PSEUDO_REGISTER)
1452     {
1453       if (reg_allocno[regno] >= 0)
1454         {
1455           SET_ALLOCNO_LIVE (reg_allocno[regno]);
1456           record_one_conflict (regno);
1457         }
1458     }
1459
1460   if (reg_renumber[regno] >= 0)
1461     regno = reg_renumber[regno];
1462
1463   /* Handle hardware regs (and pseudos allocated to hard regs).  */
1464   if (regno < FIRST_PSEUDO_REGISTER && ! fixed_regs[regno])
1465     {
1466       register int last = regno + HARD_REGNO_NREGS (regno, GET_MODE (reg));
1467       while (regno < last)
1468         {
1469           record_one_conflict (regno);
1470           SET_HARD_REG_BIT (hard_regs_live, regno);
1471           regno++;
1472         }
1473     }
1474 }
1475 \f
1476 /* Like mark_reg_set except notice just CLOBBERs; ignore SETs.  */
1477
1478 static void
1479 mark_reg_clobber (reg, setter, data)
1480      rtx reg, setter;
1481      void *data ATTRIBUTE_UNUSED;
1482 {
1483   if (GET_CODE (setter) == CLOBBER)
1484     mark_reg_store (reg, setter, data);
1485 }
1486
1487 /* Record that REG has conflicts with all the regs currently live.
1488    Do not mark REG itself as live.  */
1489
1490 static void
1491 mark_reg_conflicts (reg)
1492      rtx reg;
1493 {
1494   register int regno;
1495
1496   if (GET_CODE (reg) == SUBREG)
1497     reg = SUBREG_REG (reg);
1498
1499   if (GET_CODE (reg) != REG)
1500     return;
1501
1502   regno = REGNO (reg);
1503
1504   /* Either this is one of the max_allocno pseudo regs not allocated,
1505      or it is or has a hardware reg.  First handle the pseudo-regs.  */
1506   if (regno >= FIRST_PSEUDO_REGISTER)
1507     {
1508       if (reg_allocno[regno] >= 0)
1509         record_one_conflict (regno);
1510     }
1511
1512   if (reg_renumber[regno] >= 0)
1513     regno = reg_renumber[regno];
1514
1515   /* Handle hardware regs (and pseudos allocated to hard regs).  */
1516   if (regno < FIRST_PSEUDO_REGISTER && ! fixed_regs[regno])
1517     {
1518       register int last = regno + HARD_REGNO_NREGS (regno, GET_MODE (reg));
1519       while (regno < last)
1520         {
1521           record_one_conflict (regno);
1522           regno++;
1523         }
1524     }
1525 }
1526 \f
1527 /* Mark REG as being dead (following the insn being scanned now).
1528    Store a 0 in regs_live or allocnos_live for this register.  */
1529
1530 static void
1531 mark_reg_death (reg)
1532      rtx reg;
1533 {
1534   register int regno = REGNO (reg);
1535
1536   /* Either this is one of the max_allocno pseudo regs not allocated,
1537      or it is a hardware reg.  First handle the pseudo-regs.  */
1538   if (regno >= FIRST_PSEUDO_REGISTER)
1539     {
1540       if (reg_allocno[regno] >= 0)
1541         CLEAR_ALLOCNO_LIVE (reg_allocno[regno]);
1542     }
1543
1544   /* For pseudo reg, see if it has been assigned a hardware reg.  */
1545   if (reg_renumber[regno] >= 0)
1546     regno = reg_renumber[regno];
1547
1548   /* Handle hardware regs (and pseudos allocated to hard regs).  */
1549   if (regno < FIRST_PSEUDO_REGISTER && ! fixed_regs[regno])
1550     {
1551       /* Pseudo regs already assigned hardware regs are treated
1552          almost the same as explicit hardware regs.  */
1553       register int last = regno + HARD_REGNO_NREGS (regno, GET_MODE (reg));
1554       while (regno < last)
1555         {
1556           CLEAR_HARD_REG_BIT (hard_regs_live, regno);
1557           regno++;
1558         }
1559     }
1560 }
1561
1562 /* Mark hard reg REGNO as currently live, assuming machine mode MODE
1563    for the value stored in it.  MODE determines how many consecutive
1564    registers are actually in use.  Do not record conflicts;
1565    it is assumed that the caller will do that.  */
1566
1567 static void
1568 mark_reg_live_nc (regno, mode)
1569      register int regno;
1570      enum machine_mode mode;
1571 {
1572   register int last = regno + HARD_REGNO_NREGS (regno, mode);
1573   while (regno < last)
1574     {
1575       SET_HARD_REG_BIT (hard_regs_live, regno);
1576       regno++;
1577     }
1578 }
1579 \f
1580 /* Try to set a preference for an allocno to a hard register.
1581    We are passed DEST and SRC which are the operands of a SET.  It is known
1582    that SRC is a register.  If SRC or the first operand of SRC is a register,
1583    try to set a preference.  If one of the two is a hard register and the other
1584    is a pseudo-register, mark the preference.
1585    
1586    Note that we are not as aggressive as local-alloc in trying to tie a
1587    pseudo-register to a hard register.  */
1588
1589 static void
1590 set_preference (dest, src)
1591      rtx dest, src;
1592 {
1593   unsigned int src_regno, dest_regno;
1594   /* Amount to add to the hard regno for SRC, or subtract from that for DEST,
1595      to compensate for subregs in SRC or DEST.  */
1596   int offset = 0;
1597   unsigned int i;
1598   int copy = 1;
1599
1600   if (GET_RTX_FORMAT (GET_CODE (src))[0] == 'e')
1601     src = XEXP (src, 0), copy = 0;
1602
1603   /* Get the reg number for both SRC and DEST.
1604      If neither is a reg, give up.  */
1605
1606   if (GET_CODE (src) == REG)
1607     src_regno = REGNO (src);
1608   else if (GET_CODE (src) == SUBREG && GET_CODE (SUBREG_REG (src)) == REG)
1609     {
1610       src_regno = REGNO (SUBREG_REG (src));
1611
1612       if (REGNO (SUBREG_REG (src)) < FIRST_PSEUDO_REGISTER)
1613         offset += subreg_regno_offset (REGNO (SUBREG_REG (src)),
1614                                        GET_MODE (SUBREG_REG (src)),
1615                                        SUBREG_BYTE (src),
1616                                        GET_MODE (src));
1617       else
1618         offset += (SUBREG_BYTE (src)
1619                    / REGMODE_NATURAL_SIZE (GET_MODE (src)));
1620     }
1621   else
1622     return;
1623
1624   if (GET_CODE (dest) == REG)
1625     dest_regno = REGNO (dest);
1626   else if (GET_CODE (dest) == SUBREG && GET_CODE (SUBREG_REG (dest)) == REG)
1627     {
1628       dest_regno = REGNO (SUBREG_REG (dest));
1629
1630       if (REGNO (SUBREG_REG (dest)) < FIRST_PSEUDO_REGISTER)
1631         offset -= subreg_regno_offset (REGNO (SUBREG_REG (dest)),
1632                                        GET_MODE (SUBREG_REG (dest)),
1633                                        SUBREG_BYTE (dest),
1634                                        GET_MODE (dest));
1635       else
1636         offset -= (SUBREG_BYTE (dest)
1637                    / REGMODE_NATURAL_SIZE (GET_MODE (dest)));
1638     }
1639   else
1640     return;
1641
1642   /* Convert either or both to hard reg numbers.  */
1643
1644   if (reg_renumber[src_regno] >= 0)
1645     src_regno = reg_renumber[src_regno];
1646
1647   if (reg_renumber[dest_regno] >= 0)
1648     dest_regno = reg_renumber[dest_regno];
1649
1650   /* Now if one is a hard reg and the other is a global pseudo
1651      then give the other a preference.  */
1652
1653   if (dest_regno < FIRST_PSEUDO_REGISTER && src_regno >= FIRST_PSEUDO_REGISTER
1654       && reg_allocno[src_regno] >= 0)
1655     {
1656       dest_regno -= offset;
1657       if (dest_regno < FIRST_PSEUDO_REGISTER)
1658         {
1659           if (copy)
1660             SET_REGBIT (hard_reg_copy_preferences,
1661                         reg_allocno[src_regno], dest_regno);
1662
1663           SET_REGBIT (hard_reg_preferences,
1664                       reg_allocno[src_regno], dest_regno);
1665           for (i = dest_regno;
1666                i < dest_regno + HARD_REGNO_NREGS (dest_regno, GET_MODE (dest));
1667                i++)
1668             SET_REGBIT (hard_reg_full_preferences, reg_allocno[src_regno], i);
1669         }
1670     }
1671
1672   if (src_regno < FIRST_PSEUDO_REGISTER && dest_regno >= FIRST_PSEUDO_REGISTER
1673       && reg_allocno[dest_regno] >= 0)
1674     {
1675       src_regno += offset;
1676       if (src_regno < FIRST_PSEUDO_REGISTER)
1677         {
1678           if (copy)
1679             SET_REGBIT (hard_reg_copy_preferences,
1680                         reg_allocno[dest_regno], src_regno);
1681
1682           SET_REGBIT (hard_reg_preferences,
1683                       reg_allocno[dest_regno], src_regno);
1684           for (i = src_regno;
1685                i < src_regno + HARD_REGNO_NREGS (src_regno, GET_MODE (src));
1686                i++)
1687             SET_REGBIT (hard_reg_full_preferences, reg_allocno[dest_regno], i);
1688         }
1689     }
1690 }
1691 \f
1692 /* Indicate that hard register number FROM was eliminated and replaced with
1693    an offset from hard register number TO.  The status of hard registers live
1694    at the start of a basic block is updated by replacing a use of FROM with
1695    a use of TO.  */
1696
1697 void
1698 mark_elimination (from, to)
1699      int from, to;
1700 {
1701   int i;
1702
1703   for (i = 0; i < n_basic_blocks; i++)
1704     {
1705       register regset r = BASIC_BLOCK (i)->global_live_at_start; 
1706       if (REGNO_REG_SET_P (r, from))
1707         {
1708           CLEAR_REGNO_REG_SET (r, from);
1709           SET_REGNO_REG_SET (r, to);
1710         }
1711     }
1712 }
1713 \f
1714 /* Used for communication between the following functions.  Holds the
1715    current life information.  */
1716 static regset live_relevant_regs;
1717
1718 /* Record in live_relevant_regs and REGS_SET that register REG became live.
1719    This is called via note_stores.  */
1720 static void
1721 reg_becomes_live (reg, setter, regs_set)
1722      rtx reg;
1723      rtx setter ATTRIBUTE_UNUSED;
1724      void *regs_set;
1725 {
1726   int regno;
1727
1728   if (GET_CODE (reg) == SUBREG)
1729     reg = SUBREG_REG (reg);
1730
1731   if (GET_CODE (reg) != REG)
1732     return;
1733   
1734   regno = REGNO (reg);
1735   if (regno < FIRST_PSEUDO_REGISTER)
1736     {
1737       int nregs = HARD_REGNO_NREGS (regno, GET_MODE (reg));
1738       while (nregs-- > 0)
1739         {
1740           SET_REGNO_REG_SET (live_relevant_regs, regno);
1741           if (! fixed_regs[regno])
1742             SET_REGNO_REG_SET ((regset) regs_set, regno);
1743           regno++;
1744         }
1745     }
1746   else if (reg_renumber[regno] >= 0)
1747     {
1748       SET_REGNO_REG_SET (live_relevant_regs, regno);
1749       SET_REGNO_REG_SET ((regset) regs_set, regno);
1750     }
1751 }
1752
1753 /* Record in live_relevant_regs that register REGNO died.  */
1754 static void
1755 reg_dies (regno, mode, chain)
1756      int regno;
1757      enum machine_mode mode;
1758      struct insn_chain *chain;
1759 {
1760   if (regno < FIRST_PSEUDO_REGISTER)
1761     {
1762       int nregs = HARD_REGNO_NREGS (regno, mode);
1763       while (nregs-- > 0)
1764         {
1765           CLEAR_REGNO_REG_SET (live_relevant_regs, regno);
1766           if (! fixed_regs[regno])
1767             SET_REGNO_REG_SET (&chain->dead_or_set, regno);
1768           regno++;
1769         }
1770     }
1771   else
1772     {
1773       CLEAR_REGNO_REG_SET (live_relevant_regs, regno);
1774       if (reg_renumber[regno] >= 0)
1775         SET_REGNO_REG_SET (&chain->dead_or_set, regno);
1776     }
1777 }
1778
1779 /* Walk the insns of the current function and build reload_insn_chain,
1780    and record register life information.  */
1781 void
1782 build_insn_chain (first)
1783      rtx first;
1784 {
1785   struct insn_chain **p = &reload_insn_chain;
1786   struct insn_chain *prev = 0;
1787   int b = 0;
1788   regset_head live_relevant_regs_head;
1789
1790   live_relevant_regs = INITIALIZE_REG_SET (live_relevant_regs_head);
1791
1792   for (; first; first = NEXT_INSN (first))
1793     {
1794       struct insn_chain *c;
1795
1796       if (first == BLOCK_HEAD (b))
1797         {
1798           int i;
1799
1800           CLEAR_REG_SET (live_relevant_regs);
1801
1802           EXECUTE_IF_SET_IN_BITMAP
1803             (BASIC_BLOCK (b)->global_live_at_start, 0, i,
1804              {
1805                if (i < FIRST_PSEUDO_REGISTER
1806                    ? ! TEST_HARD_REG_BIT (eliminable_regset, i)
1807                    : reg_renumber[i] >= 0)
1808                  SET_REGNO_REG_SET (live_relevant_regs, i);
1809              });
1810         }
1811
1812       if (GET_CODE (first) != NOTE && GET_CODE (first) != BARRIER)
1813         {
1814           c = new_insn_chain ();
1815           c->prev = prev;
1816           prev = c;
1817           *p = c;
1818           p = &c->next;
1819           c->insn = first;
1820           c->block = b;
1821
1822           if (INSN_P (first))
1823             {
1824               rtx link;
1825
1826               /* Mark the death of everything that dies in this instruction.  */
1827
1828               for (link = REG_NOTES (first); link; link = XEXP (link, 1))
1829                 if (REG_NOTE_KIND (link) == REG_DEAD
1830                     && GET_CODE (XEXP (link, 0)) == REG)
1831                   reg_dies (REGNO (XEXP (link, 0)), GET_MODE (XEXP (link, 0)),
1832                             c);
1833
1834               COPY_REG_SET (&c->live_throughout, live_relevant_regs);
1835
1836               /* Mark everything born in this instruction as live.  */
1837
1838               note_stores (PATTERN (first), reg_becomes_live,
1839                            &c->dead_or_set);
1840             }
1841           else
1842             COPY_REG_SET (&c->live_throughout, live_relevant_regs);
1843
1844           if (INSN_P (first))
1845             {
1846               rtx link;
1847
1848               /* Mark anything that is set in this insn and then unused as dying.  */
1849
1850               for (link = REG_NOTES (first); link; link = XEXP (link, 1))
1851                 if (REG_NOTE_KIND (link) == REG_UNUSED
1852                     && GET_CODE (XEXP (link, 0)) == REG)
1853                   reg_dies (REGNO (XEXP (link, 0)), GET_MODE (XEXP (link, 0)),
1854                             c);
1855             }
1856         }
1857
1858       if (first == BLOCK_END (b))
1859         b++;
1860
1861       /* Stop after we pass the end of the last basic block.  Verify that
1862          no real insns are after the end of the last basic block.
1863
1864          We may want to reorganize the loop somewhat since this test should
1865          always be the right exit test.  Allow an ADDR_VEC or ADDR_DIF_VEC if
1866          the previous real insn is a JUMP_INSN.  */
1867       if (b == n_basic_blocks)
1868         {
1869           for (first = NEXT_INSN (first) ; first; first = NEXT_INSN (first))
1870             if (INSN_P (first)
1871                 && GET_CODE (PATTERN (first)) != USE
1872                 && ! ((GET_CODE (PATTERN (first)) == ADDR_VEC
1873                        || GET_CODE (PATTERN (first)) == ADDR_DIFF_VEC)
1874                       && prev_real_insn (first) != 0
1875                       && GET_CODE (prev_real_insn (first)) == JUMP_INSN))
1876               abort ();
1877           break;
1878         }
1879     }
1880   FREE_REG_SET (live_relevant_regs);
1881   *p = 0;
1882 }
1883 \f
1884 /* Print debugging trace information if -dg switch is given,
1885    showing the information on which the allocation decisions are based.  */
1886
1887 static void
1888 dump_conflicts (file)
1889      FILE *file;
1890 {
1891   register int i;
1892   register int has_preferences;
1893   register int nregs;
1894   nregs = 0;
1895   for (i = 0; i < max_allocno; i++)
1896     {
1897       if (reg_renumber[allocno[allocno_order[i]].reg] >= 0)
1898         continue;
1899       nregs++;
1900     }
1901   fprintf (file, ";; %d regs to allocate:", nregs);
1902   for (i = 0; i < max_allocno; i++)
1903     {
1904       int j;
1905       if (reg_renumber[allocno[allocno_order[i]].reg] >= 0)
1906         continue;
1907       fprintf (file, " %d", allocno[allocno_order[i]].reg);
1908       for (j = 0; j < max_regno; j++)
1909         if (reg_allocno[j] == allocno_order[i]
1910             && j != allocno[allocno_order[i]].reg)
1911           fprintf (file, "+%d", j);
1912       if (allocno[allocno_order[i]].size != 1)
1913         fprintf (file, " (%d)", allocno[allocno_order[i]].size);
1914     }
1915   fprintf (file, "\n");
1916
1917   for (i = 0; i < max_allocno; i++)
1918     {
1919       register int j;
1920       fprintf (file, ";; %d conflicts:", allocno[i].reg);
1921       for (j = 0; j < max_allocno; j++)
1922         if (CONFLICTP (j, i))
1923           fprintf (file, " %d", allocno[j].reg);
1924       for (j = 0; j < FIRST_PSEUDO_REGISTER; j++)
1925         if (TEST_HARD_REG_BIT (allocno[i].hard_reg_conflicts, j))
1926           fprintf (file, " %d", j);
1927       fprintf (file, "\n");
1928
1929       has_preferences = 0;
1930       for (j = 0; j < FIRST_PSEUDO_REGISTER; j++)
1931         if (TEST_HARD_REG_BIT (allocno[i].hard_reg_preferences, j))
1932           has_preferences = 1;
1933
1934       if (! has_preferences)
1935         continue;
1936       fprintf (file, ";; %d preferences:", allocno[i].reg);
1937       for (j = 0; j < FIRST_PSEUDO_REGISTER; j++)
1938         if (TEST_HARD_REG_BIT (allocno[i].hard_reg_preferences, j))
1939           fprintf (file, " %d", j);
1940       fprintf (file, "\n");
1941     }
1942   fprintf (file, "\n");
1943 }
1944
1945 void
1946 dump_global_regs (file)
1947      FILE *file;
1948 {
1949   register int i, j;
1950   
1951   fprintf (file, ";; Register dispositions:\n");
1952   for (i = FIRST_PSEUDO_REGISTER, j = 0; i < max_regno; i++)
1953     if (reg_renumber[i] >= 0)
1954       {
1955         fprintf (file, "%d in %d  ", i, reg_renumber[i]);
1956         if (++j % 6 == 0)
1957           fprintf (file, "\n");
1958       }
1959
1960   fprintf (file, "\n\n;; Hard regs used: ");
1961   for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
1962     if (regs_ever_live[i])
1963       fprintf (file, " %d", i);
1964   fprintf (file, "\n\n");
1965 }