OSDN Git Service

2007-08-27 Sandra Loosemore <sandra@codesourcery.com>
[pf3gnuchains/gcc-fork.git] / gcc / regclass.c
1 /* Compute register class preferences for pseudo-registers.
2    Copyright (C) 1987, 1988, 1991, 1992, 1993, 1994, 1995, 1996
3    1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007
4    Free Software Foundation, Inc.
5
6 This file is part of GCC.
7
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 3, or (at your option) any later
11 version.
12
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
16 for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3.  If not see
20 <http://www.gnu.org/licenses/>.  */
21
22
23 /* This file contains two passes of the compiler: reg_scan and reg_class.
24    It also defines some tables of information about the hardware registers
25    and a function init_reg_sets to initialize the tables.  */
26
27 #include "config.h"
28 #include "system.h"
29 #include "coretypes.h"
30 #include "tm.h"
31 #include "hard-reg-set.h"
32 #include "rtl.h"
33 #include "expr.h"
34 #include "tm_p.h"
35 #include "flags.h"
36 #include "basic-block.h"
37 #include "regs.h"
38 #include "addresses.h"
39 #include "function.h"
40 #include "insn-config.h"
41 #include "recog.h"
42 #include "reload.h"
43 #include "real.h"
44 #include "toplev.h"
45 #include "output.h"
46 #include "ggc.h"
47 #include "timevar.h"
48 #include "hashtab.h"
49 #include "target.h"
50 #include "tree-pass.h"
51 #include "df.h"
52
53 /* Maximum register number used in this function, plus one.  */
54
55 int max_regno;
56
57 static void init_reg_sets_1 (void);
58 static void init_reg_autoinc (void);
59
60 /* If we have auto-increment or auto-decrement and we can have secondary
61    reloads, we are not allowed to use classes requiring secondary
62    reloads for pseudos auto-incremented since reload can't handle it.  */
63 /* We leave it to target hooks to decide if we have secondary reloads, so
64    assume that we might have them.  */
65 #if defined(AUTO_INC_DEC) /* */
66 #define FORBIDDEN_INC_DEC_CLASSES
67 #endif
68 \f
69 /* Register tables used by many passes.  */
70
71 /* Indexed by hard register number, contains 1 for registers
72    that are fixed use (stack pointer, pc, frame pointer, etc.).
73    These are the registers that cannot be used to allocate
74    a pseudo reg for general use.  */
75
76 char fixed_regs[FIRST_PSEUDO_REGISTER];
77
78 /* Same info as a HARD_REG_SET.  */
79
80 HARD_REG_SET fixed_reg_set;
81
82 /* Data for initializing the above.  */
83
84 static char initial_fixed_regs[] = FIXED_REGISTERS;
85
86 /* Indexed by hard register number, contains 1 for registers
87    that are fixed use or are clobbered by function calls.
88    These are the registers that cannot be used to allocate
89    a pseudo reg whose life crosses calls unless we are able
90    to save/restore them across the calls.  */
91
92 char call_used_regs[FIRST_PSEUDO_REGISTER];
93
94 /* Same info as a HARD_REG_SET.  */
95
96 HARD_REG_SET call_used_reg_set;
97
98 /* HARD_REG_SET of registers we want to avoid caller saving.  */
99 HARD_REG_SET losing_caller_save_reg_set;
100
101 /* Data for initializing the above.  */
102
103 static char initial_call_used_regs[] = CALL_USED_REGISTERS;
104
105 /* This is much like call_used_regs, except it doesn't have to
106    be a superset of FIXED_REGISTERS. This vector indicates
107    what is really call clobbered, and is used when defining
108    regs_invalidated_by_call.  */
109
110 #ifdef CALL_REALLY_USED_REGISTERS
111 static char initial_call_really_used_regs[] = CALL_REALLY_USED_REGISTERS;
112 char call_really_used_regs[FIRST_PSEUDO_REGISTER];
113 #endif
114
115 #ifdef CALL_REALLY_USED_REGISTERS
116 #define CALL_REALLY_USED_REGNO_P(X)  call_really_used_regs[X]
117 #else
118 #define CALL_REALLY_USED_REGNO_P(X)  call_used_regs[X]
119 #endif
120
121
122 /* Indexed by hard register number, contains 1 for registers that are
123    fixed use or call used registers that cannot hold quantities across
124    calls even if we are willing to save and restore them.  call fixed
125    registers are a subset of call used registers.  */
126
127 char call_fixed_regs[FIRST_PSEUDO_REGISTER];
128
129 /* The same info as a HARD_REG_SET.  */
130
131 HARD_REG_SET call_fixed_reg_set;
132
133 /* Indexed by hard register number, contains 1 for registers
134    that are being used for global register decls.
135    These must be exempt from ordinary flow analysis
136    and are also considered fixed.  */
137
138 char global_regs[FIRST_PSEUDO_REGISTER];
139
140 /* Contains 1 for registers that are set or clobbered by calls.  */
141 /* ??? Ideally, this would be just call_used_regs plus global_regs, but
142    for someone's bright idea to have call_used_regs strictly include
143    fixed_regs.  Which leaves us guessing as to the set of fixed_regs
144    that are actually preserved.  We know for sure that those associated
145    with the local stack frame are safe, but scant others.  */
146
147 HARD_REG_SET regs_invalidated_by_call;
148
149 /* Table of register numbers in the order in which to try to use them.  */
150 #ifdef REG_ALLOC_ORDER
151 int reg_alloc_order[FIRST_PSEUDO_REGISTER] = REG_ALLOC_ORDER;
152
153 /* The inverse of reg_alloc_order.  */
154 int inv_reg_alloc_order[FIRST_PSEUDO_REGISTER];
155 #endif
156
157 /* For each reg class, a HARD_REG_SET saying which registers are in it.  */
158
159 HARD_REG_SET reg_class_contents[N_REG_CLASSES];
160
161 /* The same information, but as an array of unsigned ints.  We copy from
162    these unsigned ints to the table above.  We do this so the tm.h files
163    do not have to be aware of the wordsize for machines with <= 64 regs.
164    Note that we hard-code 32 here, not HOST_BITS_PER_INT.  */
165
166 #define N_REG_INTS  \
167   ((FIRST_PSEUDO_REGISTER + (32 - 1)) / 32)
168
169 static const unsigned int_reg_class_contents[N_REG_CLASSES][N_REG_INTS]
170   = REG_CLASS_CONTENTS;
171
172 /* For each reg class, number of regs it contains.  */
173
174 unsigned int reg_class_size[N_REG_CLASSES];
175
176 /* For each reg class, table listing all the containing classes.  */
177
178 static enum reg_class reg_class_superclasses[N_REG_CLASSES][N_REG_CLASSES];
179
180 /* For each reg class, table listing all the classes contained in it.  */
181
182 static enum reg_class reg_class_subclasses[N_REG_CLASSES][N_REG_CLASSES];
183
184 /* For each pair of reg classes,
185    a largest reg class contained in their union.  */
186
187 enum reg_class reg_class_subunion[N_REG_CLASSES][N_REG_CLASSES];
188
189 /* For each pair of reg classes,
190    the smallest reg class containing their union.  */
191
192 enum reg_class reg_class_superunion[N_REG_CLASSES][N_REG_CLASSES];
193
194 /* Array containing all of the register names.  */
195
196 const char * reg_names[FIRST_PSEUDO_REGISTER];
197
198 /* Data for initializing the above.  */
199
200 const char * initial_reg_names[] = REGISTER_NAMES;
201
202 /* Array containing all of the register class names.  */
203
204 const char * reg_class_names[] = REG_CLASS_NAMES;
205
206 /* For each hard register, the widest mode object that it can contain.
207    This will be a MODE_INT mode if the register can hold integers.  Otherwise
208    it will be a MODE_FLOAT or a MODE_CC mode, whichever is valid for the
209    register.  */
210
211 enum machine_mode reg_raw_mode[FIRST_PSEUDO_REGISTER];
212
213 /* 1 if there is a register of given mode.  */
214
215 bool have_regs_of_mode [MAX_MACHINE_MODE];
216
217 /* 1 if class does contain register of given mode.  */
218
219 static char contains_reg_of_mode [N_REG_CLASSES] [MAX_MACHINE_MODE];
220
221 typedef unsigned short move_table[N_REG_CLASSES];
222
223 /* Maximum cost of moving from a register in one class to a register in
224    another class.  Based on REGISTER_MOVE_COST.  */
225
226 static move_table *move_cost[MAX_MACHINE_MODE];
227
228 /* Similar, but here we don't have to move if the first index is a subset
229    of the second so in that case the cost is zero.  */
230
231 static move_table *may_move_in_cost[MAX_MACHINE_MODE];
232
233 /* Similar, but here we don't have to move if the first index is a superset
234    of the second so in that case the cost is zero.  */
235
236 static move_table *may_move_out_cost[MAX_MACHINE_MODE];
237
238 /* Keep track of the last mode we initialized move costs for.  */
239 static int last_mode_for_init_move_cost;
240
241 #ifdef FORBIDDEN_INC_DEC_CLASSES
242
243 /* These are the classes that regs which are auto-incremented or decremented
244    cannot be put in.  */
245
246 static int forbidden_inc_dec_class[N_REG_CLASSES];
247
248 /* Indexed by n, is nonzero if (REG n) is used in an auto-inc or auto-dec
249    context.  */
250
251 static char *in_inc_dec;
252
253 #endif /* FORBIDDEN_INC_DEC_CLASSES */
254
255 /* Sample MEM values for use by memory_move_secondary_cost.  */
256
257 static GTY(()) rtx top_of_stack[MAX_MACHINE_MODE];
258
259 /* No more global register variables may be declared; true once
260    regclass has been initialized.  */
261
262 static int no_global_reg_vars = 0;
263
264 /* Specify number of hard registers given machine mode occupy.  */
265 unsigned char hard_regno_nregs[FIRST_PSEUDO_REGISTER][MAX_MACHINE_MODE];
266
267 /* Given a register bitmap, turn on the bits in a HARD_REG_SET that
268    correspond to the hard registers, if any, set in that map.  This
269    could be done far more efficiently by having all sorts of special-cases
270    with moving single words, but probably isn't worth the trouble.  */
271
272 void
273 reg_set_to_hard_reg_set (HARD_REG_SET *to, const_bitmap from)
274 {
275   unsigned i;
276   bitmap_iterator bi;
277
278   EXECUTE_IF_SET_IN_BITMAP (from, 0, i, bi)
279     {
280       if (i >= FIRST_PSEUDO_REGISTER)
281         return;
282       SET_HARD_REG_BIT (*to, i);
283     }
284 }
285
286
287 /* Function called only once to initialize the above data on reg usage.
288    Once this is done, various switches may override.  */
289
290 void
291 init_reg_sets (void)
292 {
293   int i, j;
294
295   /* First copy the register information from the initial int form into
296      the regsets.  */
297
298   for (i = 0; i < N_REG_CLASSES; i++)
299     {
300       CLEAR_HARD_REG_SET (reg_class_contents[i]);
301
302       /* Note that we hard-code 32 here, not HOST_BITS_PER_INT.  */
303       for (j = 0; j < FIRST_PSEUDO_REGISTER; j++)
304         if (int_reg_class_contents[i][j / 32]
305             & ((unsigned) 1 << (j % 32)))
306           SET_HARD_REG_BIT (reg_class_contents[i], j);
307     }
308
309   memset (global_regs, 0, sizeof global_regs);
310
311   /* Processing of command-line options like -ffixed needs to know the
312      initial set of register names, so initialize that now.  */
313   gcc_assert (sizeof reg_names == sizeof initial_reg_names);
314   memcpy (reg_names, initial_reg_names, sizeof reg_names);
315 }
316
317 /* Initialize may_move_cost and friends for mode M.  */
318
319 static void
320 init_move_cost (enum machine_mode m)
321 {
322   static unsigned short last_move_cost[N_REG_CLASSES][N_REG_CLASSES];
323   bool all_match = true;
324   unsigned int i, j;
325
326   gcc_assert (have_regs_of_mode[m]);
327   for (i = 0; i < N_REG_CLASSES; i++)
328     if (contains_reg_of_mode[i][m])
329       for (j = 0; j < N_REG_CLASSES; j++)
330         {
331           int cost;
332           if (!contains_reg_of_mode[j][m])
333             cost = 65535;
334           else
335             {
336               cost = REGISTER_MOVE_COST (m, i, j);
337               gcc_assert (cost < 65535);
338             }
339           all_match &= (last_move_cost[i][j] == cost);
340           last_move_cost[i][j] = cost;
341         }
342   if (all_match && last_mode_for_init_move_cost != -1)
343     {
344       move_cost[m] = move_cost[last_mode_for_init_move_cost];
345       may_move_in_cost[m] = may_move_in_cost[last_mode_for_init_move_cost];
346       may_move_out_cost[m] = may_move_out_cost[last_mode_for_init_move_cost];
347       return;
348     }
349   last_mode_for_init_move_cost = m;
350   move_cost[m] = (move_table *)xmalloc (sizeof (move_table)
351                                         * N_REG_CLASSES);
352   may_move_in_cost[m] = (move_table *)xmalloc (sizeof (move_table)
353                                                * N_REG_CLASSES);
354   may_move_out_cost[m] = (move_table *)xmalloc (sizeof (move_table)
355                                                 * N_REG_CLASSES);
356   for (i = 0; i < N_REG_CLASSES; i++)
357     if (contains_reg_of_mode[i][m])
358       for (j = 0; j < N_REG_CLASSES; j++)
359         {
360           int cost;
361           enum reg_class *p1, *p2;
362
363           if (last_move_cost[i][j] == 65535)
364             {
365               move_cost[m][i][j] = 65535;
366               may_move_in_cost[m][i][j] = 65535;
367               may_move_out_cost[m][i][j] = 65535;
368             }
369           else
370             {
371               cost = last_move_cost[i][j];
372
373               for (p2 = &reg_class_subclasses[j][0];
374                    *p2 != LIM_REG_CLASSES; p2++)
375                 if (*p2 != i && contains_reg_of_mode[*p2][m])
376                   cost = MAX (cost, move_cost[m][i][*p2]);
377
378               for (p1 = &reg_class_subclasses[i][0];
379                    *p1 != LIM_REG_CLASSES; p1++)
380                 if (*p1 != j && contains_reg_of_mode[*p1][m])
381                   cost = MAX (cost, move_cost[m][*p1][j]);
382
383               gcc_assert (cost <= 65535);
384               move_cost[m][i][j] = cost;
385
386               if (reg_class_subset_p (i, j))
387                 may_move_in_cost[m][i][j] = 0;
388               else
389                 may_move_in_cost[m][i][j] = cost;
390
391               if (reg_class_subset_p (j, i))
392                 may_move_out_cost[m][i][j] = 0;
393               else
394                 may_move_out_cost[m][i][j] = cost;
395             }
396         }
397     else
398       for (j = 0; j < N_REG_CLASSES; j++)
399         {
400           move_cost[m][i][j] = 65535;
401           may_move_in_cost[m][i][j] = 65535;
402           may_move_out_cost[m][i][j] = 65535;
403         }
404 }
405
406 /* After switches have been processed, which perhaps alter
407    `fixed_regs' and `call_used_regs', convert them to HARD_REG_SETs.  */
408
409 static void
410 init_reg_sets_1 (void)
411 {
412   unsigned int i, j;
413   unsigned int /* enum machine_mode */ m;
414
415   /* Sanity check:  make sure the target macros FIXED_REGISTERS and
416      CALL_USED_REGISTERS had the right number of initializers.  */
417   gcc_assert (sizeof fixed_regs == sizeof initial_fixed_regs);
418   gcc_assert (sizeof call_used_regs == sizeof initial_call_used_regs);
419
420   memcpy (fixed_regs, initial_fixed_regs, sizeof fixed_regs);
421   memcpy (call_used_regs, initial_call_used_regs, sizeof call_used_regs);
422
423   /* Likewise for call_really_used_regs.  */
424 #ifdef CALL_REALLY_USED_REGISTERS
425   gcc_assert (sizeof call_really_used_regs
426               == sizeof initial_call_really_used_regs);
427   memcpy (call_really_used_regs, initial_call_really_used_regs,
428           sizeof call_really_used_regs);
429 #endif
430
431   /* And similarly for reg_names.  */
432   gcc_assert (sizeof reg_names == sizeof initial_reg_names);
433   memcpy (reg_names, initial_reg_names, sizeof reg_names);
434
435 #ifdef REG_ALLOC_ORDER
436   for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
437     inv_reg_alloc_order[reg_alloc_order[i]] = i;
438 #endif
439
440   /* This macro allows the fixed or call-used registers
441      and the register classes to depend on target flags.  */
442
443 #ifdef CONDITIONAL_REGISTER_USAGE
444   CONDITIONAL_REGISTER_USAGE;
445 #endif
446
447   /* Compute number of hard regs in each class.  */
448
449   memset (reg_class_size, 0, sizeof reg_class_size);
450   for (i = 0; i < N_REG_CLASSES; i++)
451     for (j = 0; j < FIRST_PSEUDO_REGISTER; j++)
452       if (TEST_HARD_REG_BIT (reg_class_contents[i], j))
453         reg_class_size[i]++;
454
455   /* Initialize the table of subunions.
456      reg_class_subunion[I][J] gets the largest-numbered reg-class
457      that is contained in the union of classes I and J.  */
458
459   memset (reg_class_subunion, 0, sizeof reg_class_subunion);
460   for (i = 0; i < N_REG_CLASSES; i++)
461     {
462       for (j = 0; j < N_REG_CLASSES; j++)
463         {
464           HARD_REG_SET c;
465           int k;
466
467           COPY_HARD_REG_SET (c, reg_class_contents[i]);
468           IOR_HARD_REG_SET (c, reg_class_contents[j]);
469           for (k = 0; k < N_REG_CLASSES; k++)
470             if (hard_reg_set_subset_p (reg_class_contents[k], c)
471                 && !hard_reg_set_subset_p (reg_class_contents[k],
472                                           reg_class_contents
473                                           [(int) reg_class_subunion[i][j]]))
474               reg_class_subunion[i][j] = (enum reg_class) k;
475         }
476     }
477
478   /* Initialize the table of superunions.
479      reg_class_superunion[I][J] gets the smallest-numbered reg-class
480      containing the union of classes I and J.  */
481
482   memset (reg_class_superunion, 0, sizeof reg_class_superunion);
483   for (i = 0; i < N_REG_CLASSES; i++)
484     {
485       for (j = 0; j < N_REG_CLASSES; j++)
486         {
487           HARD_REG_SET c;
488           int k;
489
490           COPY_HARD_REG_SET (c, reg_class_contents[i]);
491           IOR_HARD_REG_SET (c, reg_class_contents[j]);
492           for (k = 0; k < N_REG_CLASSES; k++)
493             if (hard_reg_set_subset_p (c, reg_class_contents[k]))
494               break;
495
496           reg_class_superunion[i][j] = (enum reg_class) k;
497         }
498     }
499
500   /* Initialize the tables of subclasses and superclasses of each reg class.
501      First clear the whole table, then add the elements as they are found.  */
502
503   for (i = 0; i < N_REG_CLASSES; i++)
504     {
505       for (j = 0; j < N_REG_CLASSES; j++)
506         {
507           reg_class_superclasses[i][j] = LIM_REG_CLASSES;
508           reg_class_subclasses[i][j] = LIM_REG_CLASSES;
509         }
510     }
511
512   for (i = 0; i < N_REG_CLASSES; i++)
513     {
514       if (i == (int) NO_REGS)
515         continue;
516
517       for (j = i + 1; j < N_REG_CLASSES; j++)
518         if (hard_reg_set_subset_p (reg_class_contents[i],
519                                   reg_class_contents[j]))
520           {
521             /* Reg class I is a subclass of J.
522                Add J to the table of superclasses of I.  */
523             enum reg_class *p;
524
525             p = &reg_class_superclasses[i][0];
526             while (*p != LIM_REG_CLASSES) p++;
527             *p = (enum reg_class) j;
528             /* Add I to the table of superclasses of J.  */
529             p = &reg_class_subclasses[j][0];
530             while (*p != LIM_REG_CLASSES) p++;
531             *p = (enum reg_class) i;
532           }
533     }
534
535   /* Initialize "constant" tables.  */
536
537   CLEAR_HARD_REG_SET (fixed_reg_set);
538   CLEAR_HARD_REG_SET (call_used_reg_set);
539   CLEAR_HARD_REG_SET (call_fixed_reg_set);
540   CLEAR_HARD_REG_SET (regs_invalidated_by_call);
541   CLEAR_HARD_REG_SET (losing_caller_save_reg_set);
542
543   memcpy (call_fixed_regs, fixed_regs, sizeof call_fixed_regs);
544
545   for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
546     {
547       /* call_used_regs must include fixed_regs.  */
548       gcc_assert (!fixed_regs[i] || call_used_regs[i]);
549 #ifdef CALL_REALLY_USED_REGISTERS
550       /* call_used_regs must include call_really_used_regs.  */
551       gcc_assert (!call_really_used_regs[i] || call_used_regs[i]);
552 #endif
553
554       if (fixed_regs[i])
555         SET_HARD_REG_BIT (fixed_reg_set, i);
556
557       if (call_used_regs[i])
558         SET_HARD_REG_BIT (call_used_reg_set, i);
559       if (call_fixed_regs[i])
560         SET_HARD_REG_BIT (call_fixed_reg_set, i);
561       if (CLASS_LIKELY_SPILLED_P (REGNO_REG_CLASS (i)))
562         SET_HARD_REG_BIT (losing_caller_save_reg_set, i);
563
564       /* There are a couple of fixed registers that we know are safe to
565          exclude from being clobbered by calls:
566
567          The frame pointer is always preserved across calls.  The arg pointer
568          is if it is fixed.  The stack pointer usually is, unless
569          RETURN_POPS_ARGS, in which case an explicit CLOBBER will be present.
570          If we are generating PIC code, the PIC offset table register is
571          preserved across calls, though the target can override that.  */
572
573       if (i == STACK_POINTER_REGNUM)
574         ;
575       else if (global_regs[i])
576         SET_HARD_REG_BIT (regs_invalidated_by_call, i);
577       else if (i == FRAME_POINTER_REGNUM)
578         ;
579 #if HARD_FRAME_POINTER_REGNUM != FRAME_POINTER_REGNUM
580       else if (i == HARD_FRAME_POINTER_REGNUM)
581         ;
582 #endif
583 #if ARG_POINTER_REGNUM != FRAME_POINTER_REGNUM
584       else if (i == ARG_POINTER_REGNUM && fixed_regs[i])
585         ;
586 #endif
587 #ifndef PIC_OFFSET_TABLE_REG_CALL_CLOBBERED
588       else if (i == (unsigned) PIC_OFFSET_TABLE_REGNUM && fixed_regs[i])
589         ;
590 #endif
591       else if (CALL_REALLY_USED_REGNO_P (i))
592         SET_HARD_REG_BIT (regs_invalidated_by_call, i);
593     }
594
595   /* Preserve global registers if called more than once.  */
596   for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
597     {
598       if (global_regs[i])
599         {
600           fixed_regs[i] = call_used_regs[i] = call_fixed_regs[i] = 1;
601           SET_HARD_REG_BIT (fixed_reg_set, i);
602           SET_HARD_REG_BIT (call_used_reg_set, i);
603           SET_HARD_REG_BIT (call_fixed_reg_set, i);
604         }
605     }
606
607   memset (have_regs_of_mode, 0, sizeof (have_regs_of_mode));
608   memset (contains_reg_of_mode, 0, sizeof (contains_reg_of_mode));
609   for (m = 0; m < (unsigned int) MAX_MACHINE_MODE; m++)
610     {
611       HARD_REG_SET ok_regs;
612       CLEAR_HARD_REG_SET (ok_regs);
613       for (j = 0; j < FIRST_PSEUDO_REGISTER; j++)
614         if (!fixed_regs [j] && HARD_REGNO_MODE_OK (j, m))
615           SET_HARD_REG_BIT (ok_regs, j);
616       
617       for (i = 0; i < N_REG_CLASSES; i++)
618         if ((unsigned) CLASS_MAX_NREGS (i, m) <= reg_class_size[i]
619             && hard_reg_set_intersect_p (ok_regs, reg_class_contents[i]))
620           {
621              contains_reg_of_mode [i][m] = 1;
622              have_regs_of_mode [m] = 1;
623           }
624      }
625
626   /* Reset move_cost and friends, making sure we only free shared
627      table entries once.  */
628   for (i = 0; i < MAX_MACHINE_MODE; i++)
629     if (move_cost[i])
630       {
631         for (j = 0; j < i && move_cost[i] != move_cost[j]; j++)
632           ;
633         if (i == j)
634           {
635             free (move_cost[i]);
636             free (may_move_in_cost[i]);
637             free (may_move_out_cost[i]);
638           }
639       }
640   memset (move_cost, 0, sizeof move_cost);
641   memset (may_move_in_cost, 0, sizeof may_move_in_cost);
642   memset (may_move_out_cost, 0, sizeof may_move_out_cost);
643   last_mode_for_init_move_cost = -1;
644 }
645
646 /* Compute the table of register modes.
647    These values are used to record death information for individual registers
648    (as opposed to a multi-register mode).
649    This function might be invoked more than once, if the target has support
650    for changing register usage conventions on a per-function basis.
651 */
652
653 void
654 init_reg_modes_target (void)
655 {
656   int i, j;
657
658   for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
659     for (j = 0; j < MAX_MACHINE_MODE; j++)
660       hard_regno_nregs[i][j] = HARD_REGNO_NREGS(i, (enum machine_mode)j);
661
662   for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
663     {
664       reg_raw_mode[i] = choose_hard_reg_mode (i, 1, false);
665
666       /* If we couldn't find a valid mode, just use the previous mode.
667          ??? One situation in which we need to do this is on the mips where
668          HARD_REGNO_NREGS (fpreg, [SD]Fmode) returns 2.  Ideally we'd like
669          to use DF mode for the even registers and VOIDmode for the odd
670          (for the cpu models where the odd ones are inaccessible).  */
671       if (reg_raw_mode[i] == VOIDmode)
672         reg_raw_mode[i] = i == 0 ? word_mode : reg_raw_mode[i-1];
673     }
674 }
675
676 /* Finish initializing the register sets and initialize the register modes.
677    This function might be invoked more than once, if the target has support
678    for changing register usage conventions on a per-function basis.
679 */
680
681 void
682 init_regs (void)
683 {
684   /* This finishes what was started by init_reg_sets, but couldn't be done
685      until after register usage was specified.  */
686   init_reg_sets_1 ();
687
688   init_reg_autoinc ();
689 }
690
691 /* Initialize some fake stack-frame MEM references for use in
692    memory_move_secondary_cost.  */
693
694 void
695 init_fake_stack_mems (void)
696 {
697   {
698     int i;
699
700     for (i = 0; i < MAX_MACHINE_MODE; i++)
701       top_of_stack[i] = gen_rtx_MEM (i, stack_pointer_rtx);
702   }
703 }
704
705
706 /* Compute extra cost of moving registers to/from memory due to reloads.
707    Only needed if secondary reloads are required for memory moves.  */
708
709 int
710 memory_move_secondary_cost (enum machine_mode mode, enum reg_class class, int in)
711 {
712   enum reg_class altclass;
713   int partial_cost = 0;
714   /* We need a memory reference to feed to SECONDARY... macros.  */
715   /* mem may be unused even if the SECONDARY_ macros are defined.  */
716   rtx mem ATTRIBUTE_UNUSED = top_of_stack[(int) mode];
717
718
719   altclass = secondary_reload_class (in ? 1 : 0, class, mode, mem);
720
721   if (altclass == NO_REGS)
722     return 0;
723
724   if (in)
725     partial_cost = REGISTER_MOVE_COST (mode, altclass, class);
726   else
727     partial_cost = REGISTER_MOVE_COST (mode, class, altclass);
728
729   if (class == altclass)
730     /* This isn't simply a copy-to-temporary situation.  Can't guess
731        what it is, so MEMORY_MOVE_COST really ought not to be calling
732        here in that case.
733
734        I'm tempted to put in an assert here, but returning this will
735        probably only give poor estimates, which is what we would've
736        had before this code anyways.  */
737     return partial_cost;
738
739   /* Check if the secondary reload register will also need a
740      secondary reload.  */
741   return memory_move_secondary_cost (mode, altclass, in) + partial_cost;
742 }
743
744 /* Return a machine mode that is legitimate for hard reg REGNO and large
745    enough to save nregs.  If we can't find one, return VOIDmode.
746    If CALL_SAVED is true, only consider modes that are call saved.  */
747
748 enum machine_mode
749 choose_hard_reg_mode (unsigned int regno ATTRIBUTE_UNUSED,
750                       unsigned int nregs, bool call_saved)
751 {
752   unsigned int /* enum machine_mode */ m;
753   enum machine_mode found_mode = VOIDmode, mode;
754
755   /* We first look for the largest integer mode that can be validly
756      held in REGNO.  If none, we look for the largest floating-point mode.
757      If we still didn't find a valid mode, try CCmode.  */
758
759   for (mode = GET_CLASS_NARROWEST_MODE (MODE_INT);
760        mode != VOIDmode;
761        mode = GET_MODE_WIDER_MODE (mode))
762     if ((unsigned) hard_regno_nregs[regno][mode] == nregs
763         && HARD_REGNO_MODE_OK (regno, mode)
764         && (! call_saved || ! HARD_REGNO_CALL_PART_CLOBBERED (regno, mode)))
765       found_mode = mode;
766
767   if (found_mode != VOIDmode)
768     return found_mode;
769
770   for (mode = GET_CLASS_NARROWEST_MODE (MODE_FLOAT);
771        mode != VOIDmode;
772        mode = GET_MODE_WIDER_MODE (mode))
773     if ((unsigned) hard_regno_nregs[regno][mode] == nregs
774         && HARD_REGNO_MODE_OK (regno, mode)
775         && (! call_saved || ! HARD_REGNO_CALL_PART_CLOBBERED (regno, mode)))
776       found_mode = mode;
777
778   if (found_mode != VOIDmode)
779     return found_mode;
780
781   for (mode = GET_CLASS_NARROWEST_MODE (MODE_VECTOR_FLOAT);
782        mode != VOIDmode;
783        mode = GET_MODE_WIDER_MODE (mode))
784     if ((unsigned) hard_regno_nregs[regno][mode] == nregs
785         && HARD_REGNO_MODE_OK (regno, mode)
786         && (! call_saved || ! HARD_REGNO_CALL_PART_CLOBBERED (regno, mode)))
787       found_mode = mode;
788
789   if (found_mode != VOIDmode)
790     return found_mode;
791
792   for (mode = GET_CLASS_NARROWEST_MODE (MODE_VECTOR_INT);
793        mode != VOIDmode;
794        mode = GET_MODE_WIDER_MODE (mode))
795     if ((unsigned) hard_regno_nregs[regno][mode] == nregs
796         && HARD_REGNO_MODE_OK (regno, mode)
797         && (! call_saved || ! HARD_REGNO_CALL_PART_CLOBBERED (regno, mode)))
798       found_mode = mode;
799
800   if (found_mode != VOIDmode)
801     return found_mode;
802
803   /* Iterate over all of the CCmodes.  */
804   for (m = (unsigned int) CCmode; m < (unsigned int) NUM_MACHINE_MODES; ++m)
805     {
806       mode = (enum machine_mode) m;
807       if ((unsigned) hard_regno_nregs[regno][mode] == nregs
808           && HARD_REGNO_MODE_OK (regno, mode)
809           && (! call_saved || ! HARD_REGNO_CALL_PART_CLOBBERED (regno, mode)))
810         return mode;
811     }
812
813   /* We can't find a mode valid for this register.  */
814   return VOIDmode;
815 }
816
817 /* Specify the usage characteristics of the register named NAME.
818    It should be a fixed register if FIXED and a
819    call-used register if CALL_USED.  */
820
821 void
822 fix_register (const char *name, int fixed, int call_used)
823 {
824   int i;
825
826   /* Decode the name and update the primary form of
827      the register info.  */
828
829   if ((i = decode_reg_name (name)) >= 0)
830     {
831       if ((i == STACK_POINTER_REGNUM
832 #ifdef HARD_FRAME_POINTER_REGNUM
833            || i == HARD_FRAME_POINTER_REGNUM
834 #else
835            || i == FRAME_POINTER_REGNUM
836 #endif
837            )
838           && (fixed == 0 || call_used == 0))
839         {
840           static const char * const what_option[2][2] = {
841             { "call-saved", "call-used" },
842             { "no-such-option", "fixed" }};
843
844           error ("can't use '%s' as a %s register", name,
845                  what_option[fixed][call_used]);
846         }
847       else
848         {
849           initial_fixed_regs[i] = fixed;
850           initial_call_used_regs[i] = call_used;
851 #ifdef CALL_REALLY_USED_REGISTERS
852           if (fixed == 0)
853             initial_call_really_used_regs[i] = call_used;
854 #endif
855         }
856     }
857   else
858     {
859       warning (0, "unknown register name: %s", name);
860     }
861 }
862
863 /* Mark register number I as global.  */
864
865 void
866 globalize_reg (int i)
867 {
868   if (fixed_regs[i] == 0 && no_global_reg_vars)
869     error ("global register variable follows a function definition");
870
871   if (global_regs[i])
872     {
873       warning (0, "register used for two global register variables");
874       return;
875     }
876
877   if (call_used_regs[i] && ! fixed_regs[i])
878     warning (0, "call-clobbered register used for global register variable");
879
880   global_regs[i] = 1;
881
882   /* If we're globalizing the frame pointer, we need to set the
883      appropriate regs_invalidated_by_call bit, even if it's already
884      set in fixed_regs.  */
885   if (i != STACK_POINTER_REGNUM)
886     SET_HARD_REG_BIT (regs_invalidated_by_call, i);
887
888   /* If already fixed, nothing else to do.  */
889   if (fixed_regs[i])
890     return;
891
892   fixed_regs[i] = call_used_regs[i] = call_fixed_regs[i] = 1;
893 #ifdef CALL_REALLY_USED_REGISTERS
894   call_really_used_regs[i] = 1;
895 #endif
896
897   SET_HARD_REG_BIT (fixed_reg_set, i);
898   SET_HARD_REG_BIT (call_used_reg_set, i);
899   SET_HARD_REG_BIT (call_fixed_reg_set, i);
900 }
901 \f
902 /* Now the data and code for the `regclass' pass, which happens
903    just before local-alloc.  */
904
905 /* The `costs' struct records the cost of using a hard register of each class
906    and of using memory for each pseudo.  We use this data to set up
907    register class preferences.  */
908
909 struct costs
910 {
911   int cost[N_REG_CLASSES];
912   int mem_cost;
913 };
914
915 /* Structure used to record preferences of given pseudo.  */
916 struct reg_pref
917 {
918   /* (enum reg_class) prefclass is the preferred class.  May be
919      NO_REGS if no class is better than memory.  */
920   char prefclass;
921
922   /* altclass is a register class that we should use for allocating
923      pseudo if no register in the preferred class is available.
924      If no register in this class is available, memory is preferred.
925
926      It might appear to be more general to have a bitmask of classes here,
927      but since it is recommended that there be a class corresponding to the
928      union of most major pair of classes, that generality is not required.  */
929   char altclass;
930 };
931
932 /* Record the cost of each class for each pseudo.  */
933
934 static struct costs *costs;
935
936 /* Initialized once, and used to initialize cost values for each insn.  */
937
938 static struct costs init_cost;
939
940 /* Record preferences of each pseudo.
941    This is available after `regclass' is run.  */
942
943 static struct reg_pref *reg_pref;
944
945 /* Frequency of executions of current insn.  */
946
947 static int frequency;
948
949 static rtx scan_one_insn (rtx, int);
950 static void record_operand_costs (rtx, struct costs *, struct reg_pref *);
951 static void dump_regclass (FILE *);
952 static void record_reg_classes (int, int, rtx *, enum machine_mode *,
953                                 const char **, rtx, struct costs *,
954                                 struct reg_pref *);
955 static int copy_cost (rtx, enum machine_mode, enum reg_class, int,
956                       secondary_reload_info *);
957 static void record_address_regs (enum machine_mode, rtx, int, enum rtx_code,
958                                  enum rtx_code, int);
959 #ifdef FORBIDDEN_INC_DEC_CLASSES
960 static int auto_inc_dec_reg_p (rtx, enum machine_mode);
961 #endif
962 static void reg_scan_mark_refs (rtx, rtx);
963
964 /* Wrapper around REGNO_OK_FOR_INDEX_P, to allow pseudo registers.  */
965
966 static inline bool
967 ok_for_index_p_nonstrict (rtx reg)
968 {
969   unsigned regno = REGNO (reg);
970   return regno >= FIRST_PSEUDO_REGISTER || REGNO_OK_FOR_INDEX_P (regno);
971 }
972
973 /* A version of regno_ok_for_base_p for use during regclass, when all pseudos
974    should count as OK.  Arguments as for regno_ok_for_base_p.  */
975
976 static inline bool
977 ok_for_base_p_nonstrict (rtx reg, enum machine_mode mode,
978                          enum rtx_code outer_code, enum rtx_code index_code)
979 {
980   unsigned regno = REGNO (reg);
981   if (regno >= FIRST_PSEUDO_REGISTER)
982     return true;
983
984   return ok_for_base_p_1 (regno, mode, outer_code, index_code);
985 }
986
987 /* Return the reg_class in which pseudo reg number REGNO is best allocated.
988    This function is sometimes called before the info has been computed.
989    When that happens, just return GENERAL_REGS, which is innocuous.  */
990
991 enum reg_class
992 reg_preferred_class (int regno)
993 {
994   if (reg_pref == 0)
995     return GENERAL_REGS;
996   return (enum reg_class) reg_pref[regno].prefclass;
997 }
998
999 enum reg_class
1000 reg_alternate_class (int regno)
1001 {
1002   if (reg_pref == 0)
1003     return ALL_REGS;
1004
1005   return (enum reg_class) reg_pref[regno].altclass;
1006 }
1007
1008 /* Initialize some global data for this pass.  */
1009
1010 static unsigned int 
1011 regclass_init (void)
1012 {
1013   int i;
1014
1015   if (df)
1016     df_compute_regs_ever_live (true);
1017
1018   init_cost.mem_cost = 10000;
1019   for (i = 0; i < N_REG_CLASSES; i++)
1020     init_cost.cost[i] = 10000;
1021
1022   /* This prevents dump_flow_info from losing if called
1023      before regclass is run.  */
1024   reg_pref = NULL;
1025
1026   /* No more global register variables may be declared.  */
1027   no_global_reg_vars = 1;
1028   return 1;
1029 }
1030
1031 struct tree_opt_pass pass_regclass_init =
1032 {
1033   "regclass",                           /* name */
1034   NULL,                                 /* gate */
1035   regclass_init,                        /* execute */
1036   NULL,                                 /* sub */
1037   NULL,                                 /* next */
1038   0,                                    /* static_pass_number */
1039   0,                                    /* tv_id */
1040   0,                                    /* properties_required */
1041   0,                                    /* properties_provided */
1042   0,                                    /* properties_destroyed */
1043   0,                                    /* todo_flags_start */
1044   0,                                    /* todo_flags_finish */
1045   'k'                                   /* letter */
1046 };
1047
1048
1049 \f
1050 /* Dump register costs.  */
1051 static void
1052 dump_regclass (FILE *dump)
1053 {
1054   int i;
1055   for (i = FIRST_PSEUDO_REGISTER; i < max_regno; i++)
1056     {
1057       int /* enum reg_class */ class;
1058       if (REG_N_REFS (i))
1059         {
1060           fprintf (dump, "  Register %i costs:", i);
1061           for (class = 0; class < (int) N_REG_CLASSES; class++)
1062             if (contains_reg_of_mode [(enum reg_class) class][PSEUDO_REGNO_MODE (i)]
1063 #ifdef FORBIDDEN_INC_DEC_CLASSES
1064                 && (!in_inc_dec[i]
1065                     || !forbidden_inc_dec_class[(enum reg_class) class])
1066 #endif
1067 #ifdef CANNOT_CHANGE_MODE_CLASS
1068                 && ! invalid_mode_change_p (i, (enum reg_class) class,
1069                                             PSEUDO_REGNO_MODE (i))
1070 #endif
1071                 )
1072             fprintf (dump, " %s:%i", reg_class_names[class],
1073                      costs[i].cost[(enum reg_class) class]);
1074           fprintf (dump, " MEM:%i\n", costs[i].mem_cost);
1075         }
1076     }
1077 }
1078 \f
1079
1080 /* Calculate the costs of insn operands.  */
1081
1082 static void
1083 record_operand_costs (rtx insn, struct costs *op_costs,
1084                       struct reg_pref *reg_pref)
1085 {
1086   const char *constraints[MAX_RECOG_OPERANDS];
1087   enum machine_mode modes[MAX_RECOG_OPERANDS];
1088   int i;
1089
1090   for (i = 0; i < recog_data.n_operands; i++)
1091     {
1092       constraints[i] = recog_data.constraints[i];
1093       modes[i] = recog_data.operand_mode[i];
1094     }
1095
1096   /* If we get here, we are set up to record the costs of all the
1097      operands for this insn.  Start by initializing the costs.
1098      Then handle any address registers.  Finally record the desired
1099      classes for any pseudos, doing it twice if some pair of
1100      operands are commutative.  */
1101
1102   for (i = 0; i < recog_data.n_operands; i++)
1103     {
1104       op_costs[i] = init_cost;
1105
1106       if (GET_CODE (recog_data.operand[i]) == SUBREG)
1107         recog_data.operand[i] = SUBREG_REG (recog_data.operand[i]);
1108
1109       if (MEM_P (recog_data.operand[i]))
1110         record_address_regs (GET_MODE (recog_data.operand[i]),
1111                              XEXP (recog_data.operand[i], 0),
1112                              0, MEM, SCRATCH, frequency * 2);
1113       else if (constraints[i][0] == 'p'
1114                || EXTRA_ADDRESS_CONSTRAINT (constraints[i][0], constraints[i]))
1115         record_address_regs (VOIDmode, recog_data.operand[i], 0, ADDRESS,
1116                              SCRATCH, frequency * 2);
1117     }
1118
1119   /* Check for commutative in a separate loop so everything will
1120      have been initialized.  We must do this even if one operand
1121      is a constant--see addsi3 in m68k.md.  */
1122
1123   for (i = 0; i < (int) recog_data.n_operands - 1; i++)
1124     if (constraints[i][0] == '%')
1125       {
1126         const char *xconstraints[MAX_RECOG_OPERANDS];
1127         int j;
1128
1129         /* Handle commutative operands by swapping the constraints.
1130            We assume the modes are the same.  */
1131
1132         for (j = 0; j < recog_data.n_operands; j++)
1133           xconstraints[j] = constraints[j];
1134
1135         xconstraints[i] = constraints[i+1];
1136         xconstraints[i+1] = constraints[i];
1137         record_reg_classes (recog_data.n_alternatives, recog_data.n_operands,
1138                             recog_data.operand, modes,
1139                             xconstraints, insn, op_costs, reg_pref);
1140       }
1141
1142   record_reg_classes (recog_data.n_alternatives, recog_data.n_operands,
1143                       recog_data.operand, modes,
1144                       constraints, insn, op_costs, reg_pref);
1145 }
1146 \f
1147 /* Subroutine of regclass, processes one insn INSN.  Scan it and record each
1148    time it would save code to put a certain register in a certain class.
1149    PASS, when nonzero, inhibits some optimizations which need only be done
1150    once.
1151    Return the last insn processed, so that the scan can be continued from
1152    there.  */
1153
1154 static rtx
1155 scan_one_insn (rtx insn, int pass ATTRIBUTE_UNUSED)
1156 {
1157   enum rtx_code pat_code;
1158   rtx set, note;
1159   int i, j;
1160   struct costs op_costs[MAX_RECOG_OPERANDS];
1161
1162   if (!INSN_P (insn))
1163     return insn;
1164
1165   pat_code = GET_CODE (PATTERN (insn));
1166   if (pat_code == USE
1167       || pat_code == CLOBBER
1168       || pat_code == ASM_INPUT
1169       || pat_code == ADDR_VEC
1170       || pat_code == ADDR_DIFF_VEC)
1171     return insn;
1172
1173   set = single_set (insn);
1174   extract_insn (insn);
1175
1176   /* If this insn loads a parameter from its stack slot, then
1177      it represents a savings, rather than a cost, if the
1178      parameter is stored in memory.  Record this fact.  */
1179
1180   if (set != 0 && REG_P (SET_DEST (set))
1181       && MEM_P (SET_SRC (set))
1182       && (note = find_reg_note (insn, REG_EQUIV,
1183                                 NULL_RTX)) != 0
1184       && MEM_P (XEXP (note, 0)))
1185     {
1186       costs[REGNO (SET_DEST (set))].mem_cost
1187         -= (MEMORY_MOVE_COST (GET_MODE (SET_DEST (set)),
1188                               GENERAL_REGS, 1)
1189             * frequency);
1190       record_address_regs (GET_MODE (SET_SRC (set)), XEXP (SET_SRC (set), 0),
1191                            0, MEM, SCRATCH, frequency * 2);
1192       return insn;
1193     }
1194
1195   record_operand_costs (insn, op_costs, reg_pref);
1196
1197   /* Now add the cost for each operand to the total costs for
1198      its register.  */
1199
1200   for (i = 0; i < recog_data.n_operands; i++)
1201     if (REG_P (recog_data.operand[i])
1202         && REGNO (recog_data.operand[i]) >= FIRST_PSEUDO_REGISTER)
1203       {
1204         int regno = REGNO (recog_data.operand[i]);
1205         struct costs *p = &costs[regno], *q = &op_costs[i];
1206
1207         p->mem_cost += q->mem_cost * frequency;
1208         for (j = 0; j < N_REG_CLASSES; j++)
1209           p->cost[j] += q->cost[j] * frequency;
1210       }
1211
1212   return insn;
1213 }
1214
1215 /* Initialize information about which register classes can be used for
1216    pseudos that are auto-incremented or auto-decremented.  */
1217
1218 static void
1219 init_reg_autoinc (void)
1220 {
1221 #ifdef FORBIDDEN_INC_DEC_CLASSES
1222   int i;
1223
1224   memset (forbidden_inc_dec_class, 0, sizeof forbidden_inc_dec_class);
1225   for (i = 0; i < N_REG_CLASSES; i++)
1226     {
1227       rtx r = gen_rtx_raw_REG (VOIDmode, 0);
1228       enum machine_mode m;
1229       int j;
1230
1231       for (j = 0; j < FIRST_PSEUDO_REGISTER; j++)
1232         if (TEST_HARD_REG_BIT (reg_class_contents[i], j))
1233           {
1234             SET_REGNO (r, j);
1235
1236             for (m = VOIDmode; (int) m < (int) MAX_MACHINE_MODE;
1237                  m = (enum machine_mode) ((int) m + 1))
1238               if (HARD_REGNO_MODE_OK (j, m))
1239                 {
1240                   /* ??? There are two assumptions here; that the base class does not
1241                      depend on the exact outer code (POST_INC vs. PRE_INC etc.), and
1242                      that it does not depend on the machine mode of the memory
1243                      reference.  */
1244                   enum reg_class base_class
1245                     = base_reg_class (VOIDmode, POST_INC, SCRATCH);
1246
1247                   PUT_MODE (r, m);
1248
1249                   /* If a register is not directly suitable for an
1250                      auto-increment or decrement addressing mode and
1251                      requires secondary reloads, disallow its class from
1252                      being used in such addresses.  */
1253
1254                   if ((secondary_reload_class (1, base_class, m, r)
1255                        || secondary_reload_class (1, base_class, m, r))
1256                       && ! auto_inc_dec_reg_p (r, m))
1257                     forbidden_inc_dec_class[i] = 1;
1258                 }
1259           }
1260     }
1261 #endif /* FORBIDDEN_INC_DEC_CLASSES */
1262 }
1263
1264 /* This is a pass of the compiler that scans all instructions
1265    and calculates the preferred class for each pseudo-register.
1266    This information can be accessed later by calling `reg_preferred_class'.
1267    This pass comes just before local register allocation.  */
1268
1269 void
1270 regclass (rtx f, int nregs)
1271 {
1272   rtx insn;
1273   int i;
1274   int pass;
1275   max_regno = max_reg_num ();
1276
1277   init_recog ();
1278
1279   reg_renumber = xmalloc (max_regno * sizeof (short));
1280   reg_pref = XCNEWVEC (struct reg_pref, max_regno);
1281   memset (reg_renumber, -1, max_regno * sizeof (short));
1282
1283   costs = XNEWVEC (struct costs, nregs);
1284
1285 #ifdef FORBIDDEN_INC_DEC_CLASSES
1286
1287   in_inc_dec = XNEWVEC (char, nregs);
1288
1289 #endif /* FORBIDDEN_INC_DEC_CLASSES */
1290
1291   /* Normally we scan the insns once and determine the best class to use for
1292      each register.  However, if -fexpensive_optimizations are on, we do so
1293      twice, the second time using the tentative best classes to guide the
1294      selection.  */
1295
1296   for (pass = 0; pass <= flag_expensive_optimizations; pass++)
1297     {
1298       basic_block bb;
1299
1300       if (dump_file)
1301         fprintf (dump_file, "\n\nPass %i\n\n",pass);
1302       /* Zero out our accumulation of the cost of each class for each reg.  */
1303
1304       memset (costs, 0, nregs * sizeof (struct costs));
1305
1306 #ifdef FORBIDDEN_INC_DEC_CLASSES
1307       memset (in_inc_dec, 0, nregs);
1308 #endif
1309
1310       /* Scan the instructions and record each time it would
1311          save code to put a certain register in a certain class.  */
1312
1313       if (!optimize)
1314         {
1315           frequency = REG_FREQ_MAX;
1316           for (insn = f; insn; insn = NEXT_INSN (insn))
1317             insn = scan_one_insn (insn, pass);
1318         }
1319       else
1320         FOR_EACH_BB (bb)
1321           {
1322             /* Show that an insn inside a loop is likely to be executed three
1323                times more than insns outside a loop.  This is much more
1324                aggressive than the assumptions made elsewhere and is being
1325                tried as an experiment.  */
1326             frequency = REG_FREQ_FROM_BB (bb);
1327             for (insn = BB_HEAD (bb); ; insn = NEXT_INSN (insn))
1328               {
1329                 insn = scan_one_insn (insn, pass);
1330                 if (insn == BB_END (bb))
1331                   break;
1332               }
1333           }
1334
1335       /* Now for each register look at how desirable each class is
1336          and find which class is preferred.  Store that in
1337          `prefclass'.  Record in `altclass' the largest register
1338          class any of whose registers is better than memory.  */
1339
1340       if (dump_file)
1341         {
1342           dump_regclass (dump_file);
1343           fprintf (dump_file,"\n");
1344         }
1345       for (i = FIRST_PSEUDO_REGISTER; i < nregs; i++)
1346         {
1347           int best_cost = (1 << (HOST_BITS_PER_INT - 2)) - 1;
1348           enum reg_class best = ALL_REGS, alt = NO_REGS;
1349           /* This is an enum reg_class, but we call it an int
1350              to save lots of casts.  */
1351           int class;
1352           struct costs *p = &costs[i];
1353
1354           if (regno_reg_rtx[i] == NULL)
1355             continue;
1356
1357           /* In non-optimizing compilation REG_N_REFS is not initialized
1358              yet.  */
1359           if (optimize && !REG_N_REFS (i) && !REG_N_SETS (i))
1360             continue;
1361
1362           for (class = (int) ALL_REGS - 1; class > 0; class--)
1363             {
1364               /* Ignore classes that are too small for this operand or
1365                  invalid for an operand that was auto-incremented.  */
1366               if (!contains_reg_of_mode [class][PSEUDO_REGNO_MODE (i)]
1367 #ifdef FORBIDDEN_INC_DEC_CLASSES
1368                   || (in_inc_dec[i] && forbidden_inc_dec_class[class])
1369 #endif
1370 #ifdef CANNOT_CHANGE_MODE_CLASS
1371                   || invalid_mode_change_p (i, (enum reg_class) class,
1372                                             PSEUDO_REGNO_MODE (i))
1373 #endif
1374                   )
1375                 ;
1376               else if (p->cost[class] < best_cost)
1377                 {
1378                   best_cost = p->cost[class];
1379                   best = (enum reg_class) class;
1380                 }
1381               else if (p->cost[class] == best_cost)
1382                 best = reg_class_subunion[(int) best][class];
1383             }
1384
1385           /* If no register class is better than memory, use memory. */
1386           if (p->mem_cost < best_cost)
1387             best = NO_REGS;
1388
1389           /* Record the alternate register class; i.e., a class for which
1390              every register in it is better than using memory.  If adding a
1391              class would make a smaller class (i.e., no union of just those
1392              classes exists), skip that class.  The major unions of classes
1393              should be provided as a register class.  Don't do this if we
1394              will be doing it again later.  */
1395
1396           if ((pass == 1  || dump_file) || ! flag_expensive_optimizations)
1397             for (class = 0; class < N_REG_CLASSES; class++)
1398               if (p->cost[class] < p->mem_cost
1399                   && (reg_class_size[(int) reg_class_subunion[(int) alt][class]]
1400                       > reg_class_size[(int) alt])
1401 #ifdef FORBIDDEN_INC_DEC_CLASSES
1402                   && ! (in_inc_dec[i] && forbidden_inc_dec_class[class])
1403 #endif
1404 #ifdef CANNOT_CHANGE_MODE_CLASS
1405                   && ! invalid_mode_change_p (i, (enum reg_class) class,
1406                                               PSEUDO_REGNO_MODE (i))
1407 #endif
1408                   )
1409                 alt = reg_class_subunion[(int) alt][class];
1410
1411           /* If we don't add any classes, nothing to try.  */
1412           if (alt == best)
1413             alt = NO_REGS;
1414
1415           if (dump_file
1416               && (reg_pref[i].prefclass != (int) best
1417                   || reg_pref[i].altclass != (int) alt))
1418             {
1419               fprintf (dump_file, "  Register %i", i);
1420               if (alt == ALL_REGS || best == ALL_REGS)
1421                 fprintf (dump_file, " pref %s\n", reg_class_names[(int) best]);
1422               else if (alt == NO_REGS)
1423                 fprintf (dump_file, " pref %s or none\n", reg_class_names[(int) best]);
1424               else
1425                 fprintf (dump_file, " pref %s, else %s\n",
1426                          reg_class_names[(int) best],
1427                          reg_class_names[(int) alt]);
1428             }
1429
1430           /* We cast to (int) because (char) hits bugs in some compilers.  */
1431           reg_pref[i].prefclass = (int) best;
1432           reg_pref[i].altclass = (int) alt;
1433         }
1434     }
1435
1436 #ifdef FORBIDDEN_INC_DEC_CLASSES
1437   free (in_inc_dec);
1438 #endif
1439   free (costs);
1440 }
1441 \f
1442 /* Record the cost of using memory or registers of various classes for
1443    the operands in INSN.
1444
1445    N_ALTS is the number of alternatives.
1446
1447    N_OPS is the number of operands.
1448
1449    OPS is an array of the operands.
1450
1451    MODES are the modes of the operands, in case any are VOIDmode.
1452
1453    CONSTRAINTS are the constraints to use for the operands.  This array
1454    is modified by this procedure.
1455
1456    This procedure works alternative by alternative.  For each alternative
1457    we assume that we will be able to allocate all pseudos to their ideal
1458    register class and calculate the cost of using that alternative.  Then
1459    we compute for each operand that is a pseudo-register, the cost of
1460    having the pseudo allocated to each register class and using it in that
1461    alternative.  To this cost is added the cost of the alternative.
1462
1463    The cost of each class for this insn is its lowest cost among all the
1464    alternatives.  */
1465
1466 static void
1467 record_reg_classes (int n_alts, int n_ops, rtx *ops,
1468                     enum machine_mode *modes, const char **constraints,
1469                     rtx insn, struct costs *op_costs,
1470                     struct reg_pref *reg_pref)
1471 {
1472   int alt;
1473   int i, j;
1474   rtx set;
1475
1476   /* Process each alternative, each time minimizing an operand's cost with
1477      the cost for each operand in that alternative.  */
1478
1479   for (alt = 0; alt < n_alts; alt++)
1480     {
1481       struct costs this_op_costs[MAX_RECOG_OPERANDS];
1482       int alt_fail = 0;
1483       int alt_cost = 0;
1484       enum reg_class classes[MAX_RECOG_OPERANDS];
1485       int allows_mem[MAX_RECOG_OPERANDS];
1486       int class;
1487
1488       for (i = 0; i < n_ops; i++)
1489         {
1490           const char *p = constraints[i];
1491           rtx op = ops[i];
1492           enum machine_mode mode = modes[i];
1493           int allows_addr = 0;
1494           int win = 0;
1495           unsigned char c;
1496
1497           /* Initially show we know nothing about the register class.  */
1498           classes[i] = NO_REGS;
1499           allows_mem[i] = 0;
1500
1501           /* If this operand has no constraints at all, we can conclude
1502              nothing about it since anything is valid.  */
1503
1504           if (*p == 0)
1505             {
1506               if (REG_P (op) && REGNO (op) >= FIRST_PSEUDO_REGISTER)
1507                 memset (&this_op_costs[i], 0, sizeof this_op_costs[i]);
1508
1509               continue;
1510             }
1511
1512           /* If this alternative is only relevant when this operand
1513              matches a previous operand, we do different things depending
1514              on whether this operand is a pseudo-reg or not.  We must process
1515              any modifiers for the operand before we can make this test.  */
1516
1517           while (*p == '%' || *p == '=' || *p == '+' || *p == '&')
1518             p++;
1519
1520           if (p[0] >= '0' && p[0] <= '0' + i && (p[1] == ',' || p[1] == 0))
1521             {
1522               /* Copy class and whether memory is allowed from the matching
1523                  alternative.  Then perform any needed cost computations
1524                  and/or adjustments.  */
1525               j = p[0] - '0';
1526               classes[i] = classes[j];
1527               allows_mem[i] = allows_mem[j];
1528
1529               if (!REG_P (op) || REGNO (op) < FIRST_PSEUDO_REGISTER)
1530                 {
1531                   /* If this matches the other operand, we have no added
1532                      cost and we win.  */
1533                   if (rtx_equal_p (ops[j], op))
1534                     win = 1;
1535
1536                   /* If we can put the other operand into a register, add to
1537                      the cost of this alternative the cost to copy this
1538                      operand to the register used for the other operand.  */
1539
1540                   else if (classes[j] != NO_REGS)
1541                     {
1542                       alt_cost += copy_cost (op, mode, classes[j], 1, NULL);
1543                       win = 1;
1544                     }
1545                 }
1546               else if (!REG_P (ops[j])
1547                        || REGNO (ops[j]) < FIRST_PSEUDO_REGISTER)
1548                 {
1549                   /* This op is a pseudo but the one it matches is not.  */
1550
1551                   /* If we can't put the other operand into a register, this
1552                      alternative can't be used.  */
1553
1554                   if (classes[j] == NO_REGS)
1555                     alt_fail = 1;
1556
1557                   /* Otherwise, add to the cost of this alternative the cost
1558                      to copy the other operand to the register used for this
1559                      operand.  */
1560
1561                   else
1562                     alt_cost += copy_cost (ops[j], mode, classes[j], 1, NULL);
1563                 }
1564               else
1565                 {
1566                   /* The costs of this operand are not the same as the other
1567                      operand since move costs are not symmetric.  Moreover,
1568                      if we cannot tie them, this alternative needs to do a
1569                      copy, which is one instruction.  */
1570
1571                   struct costs *pp = &this_op_costs[i];
1572                   move_table *intable = NULL;
1573                   move_table *outtable = NULL;
1574                   int op_class = (int) classes[i];
1575
1576                   if (!move_cost[mode])
1577                     init_move_cost (mode);
1578                   intable = may_move_in_cost[mode];
1579                   outtable = may_move_out_cost[mode];
1580
1581                   /* The loop is performance critical, so unswitch it manually.
1582                    */
1583                   switch (recog_data.operand_type[i])
1584                     {
1585                     case OP_INOUT:
1586                       for (class = 0; class < N_REG_CLASSES; class++)
1587                         pp->cost[class] = (intable[class][op_class]
1588                                            + outtable[op_class][class]);
1589                       break;
1590                     case OP_IN:
1591                       for (class = 0; class < N_REG_CLASSES; class++)
1592                         pp->cost[class] = intable[class][op_class];
1593                       break;
1594                     case OP_OUT:
1595                       for (class = 0; class < N_REG_CLASSES; class++)
1596                         pp->cost[class] = outtable[op_class][class];
1597                       break;
1598                     }
1599
1600                   /* If the alternative actually allows memory, make things
1601                      a bit cheaper since we won't need an extra insn to
1602                      load it.  */
1603
1604                   pp->mem_cost
1605                     = ((recog_data.operand_type[i] != OP_IN
1606                         ? MEMORY_MOVE_COST (mode, classes[i], 0)
1607                         : 0)
1608                        + (recog_data.operand_type[i] != OP_OUT
1609                           ? MEMORY_MOVE_COST (mode, classes[i], 1)
1610                           : 0) - allows_mem[i]);
1611
1612                   /* If we have assigned a class to this register in our
1613                      first pass, add a cost to this alternative corresponding
1614                      to what we would add if this register were not in the
1615                      appropriate class.  */
1616
1617                   if (reg_pref && reg_pref[REGNO (op)].prefclass != NO_REGS)
1618                     alt_cost
1619                       += (may_move_in_cost[mode]
1620                           [(unsigned char) reg_pref[REGNO (op)].prefclass]
1621                           [(int) classes[i]]);
1622
1623                   if (REGNO (ops[i]) != REGNO (ops[j])
1624                       && ! find_reg_note (insn, REG_DEAD, op))
1625                     alt_cost += 2;
1626
1627                   /* This is in place of ordinary cost computation
1628                      for this operand, so skip to the end of the
1629                      alternative (should be just one character).  */
1630                   while (*p && *p++ != ',')
1631                     ;
1632
1633                   constraints[i] = p;
1634                   continue;
1635                 }
1636             }
1637
1638           /* Scan all the constraint letters.  See if the operand matches
1639              any of the constraints.  Collect the valid register classes
1640              and see if this operand accepts memory.  */
1641
1642           while ((c = *p))
1643             {
1644               switch (c)
1645                 {
1646                 case ',':
1647                   break;
1648                 case '*':
1649                   /* Ignore the next letter for this pass.  */
1650                   c = *++p;
1651                   break;
1652
1653                 case '?':
1654                   alt_cost += 2;
1655                 case '!':  case '#':  case '&':
1656                 case '0':  case '1':  case '2':  case '3':  case '4':
1657                 case '5':  case '6':  case '7':  case '8':  case '9':
1658                   break;
1659
1660                 case 'p':
1661                   allows_addr = 1;
1662                   win = address_operand (op, GET_MODE (op));
1663                   /* We know this operand is an address, so we want it to be
1664                      allocated to a register that can be the base of an
1665                      address, i.e. BASE_REG_CLASS.  */
1666                   classes[i]
1667                     = reg_class_subunion[(int) classes[i]]
1668                     [(int) base_reg_class (VOIDmode, ADDRESS, SCRATCH)];
1669                   break;
1670
1671                 case 'm':  case 'o':  case 'V':
1672                   /* It doesn't seem worth distinguishing between offsettable
1673                      and non-offsettable addresses here.  */
1674                   allows_mem[i] = 1;
1675                   if (MEM_P (op))
1676                     win = 1;
1677                   break;
1678
1679                 case '<':
1680                   if (MEM_P (op)
1681                       && (GET_CODE (XEXP (op, 0)) == PRE_DEC
1682                           || GET_CODE (XEXP (op, 0)) == POST_DEC))
1683                     win = 1;
1684                   break;
1685
1686                 case '>':
1687                   if (MEM_P (op)
1688                       && (GET_CODE (XEXP (op, 0)) == PRE_INC
1689                           || GET_CODE (XEXP (op, 0)) == POST_INC))
1690                     win = 1;
1691                   break;
1692
1693                 case 'E':
1694                 case 'F':
1695                   if (GET_CODE (op) == CONST_DOUBLE
1696                       || (GET_CODE (op) == CONST_VECTOR
1697                           && (GET_MODE_CLASS (GET_MODE (op))
1698                               == MODE_VECTOR_FLOAT)))
1699                     win = 1;
1700                   break;
1701
1702                 case 'G':
1703                 case 'H':
1704                   if (GET_CODE (op) == CONST_DOUBLE
1705                       && CONST_DOUBLE_OK_FOR_CONSTRAINT_P (op, c, p))
1706                     win = 1;
1707                   break;
1708
1709                 case 's':
1710                   if (GET_CODE (op) == CONST_INT
1711                       || (GET_CODE (op) == CONST_DOUBLE
1712                           && GET_MODE (op) == VOIDmode))
1713                     break;
1714                 case 'i':
1715                   if (CONSTANT_P (op)
1716                       && (! flag_pic || LEGITIMATE_PIC_OPERAND_P (op)))
1717                     win = 1;
1718                   break;
1719
1720                 case 'n':
1721                   if (GET_CODE (op) == CONST_INT
1722                       || (GET_CODE (op) == CONST_DOUBLE
1723                           && GET_MODE (op) == VOIDmode))
1724                     win = 1;
1725                   break;
1726
1727                 case 'I':
1728                 case 'J':
1729                 case 'K':
1730                 case 'L':
1731                 case 'M':
1732                 case 'N':
1733                 case 'O':
1734                 case 'P':
1735                   if (GET_CODE (op) == CONST_INT
1736                       && CONST_OK_FOR_CONSTRAINT_P (INTVAL (op), c, p))
1737                     win = 1;
1738                   break;
1739
1740                 case 'X':
1741                   win = 1;
1742                   break;
1743
1744                 case 'g':
1745                   if (MEM_P (op)
1746                       || (CONSTANT_P (op)
1747                           && (! flag_pic || LEGITIMATE_PIC_OPERAND_P (op))))
1748                     win = 1;
1749                   allows_mem[i] = 1;
1750                 case 'r':
1751                   classes[i]
1752                     = reg_class_subunion[(int) classes[i]][(int) GENERAL_REGS];
1753                   break;
1754
1755                 default:
1756                   if (REG_CLASS_FROM_CONSTRAINT (c, p) != NO_REGS)
1757                     classes[i]
1758                       = reg_class_subunion[(int) classes[i]]
1759                         [(int) REG_CLASS_FROM_CONSTRAINT (c, p)];
1760 #ifdef EXTRA_CONSTRAINT_STR
1761                   else if (EXTRA_CONSTRAINT_STR (op, c, p))
1762                     win = 1;
1763
1764                   if (EXTRA_MEMORY_CONSTRAINT (c, p))
1765                     {
1766                       /* Every MEM can be reloaded to fit.  */
1767                       allows_mem[i] = 1;
1768                       if (MEM_P (op))
1769                         win = 1;
1770                     }
1771                   if (EXTRA_ADDRESS_CONSTRAINT (c, p))
1772                     {
1773                       /* Every address can be reloaded to fit.  */
1774                       allows_addr = 1;
1775                       if (address_operand (op, GET_MODE (op)))
1776                         win = 1;
1777                       /* We know this operand is an address, so we want it to
1778                          be allocated to a register that can be the base of an
1779                          address, i.e. BASE_REG_CLASS.  */
1780                       classes[i]
1781                         = reg_class_subunion[(int) classes[i]]
1782                         [(int) base_reg_class (VOIDmode, ADDRESS, SCRATCH)];
1783                     }
1784 #endif
1785                   break;
1786                 }
1787               p += CONSTRAINT_LEN (c, p);
1788               if (c == ',')
1789                 break;
1790             }
1791
1792           constraints[i] = p;
1793
1794           /* How we account for this operand now depends on whether it is  a
1795              pseudo register or not.  If it is, we first check if any
1796              register classes are valid.  If not, we ignore this alternative,
1797              since we want to assume that all pseudos get allocated for
1798              register preferencing.  If some register class is valid, compute
1799              the costs of moving the pseudo into that class.  */
1800
1801           if (REG_P (op) && REGNO (op) >= FIRST_PSEUDO_REGISTER)
1802             {
1803               if (classes[i] == NO_REGS)
1804                 {
1805                   /* We must always fail if the operand is a REG, but
1806                      we did not find a suitable class.
1807
1808                      Otherwise we may perform an uninitialized read
1809                      from this_op_costs after the `continue' statement
1810                      below.  */
1811                   alt_fail = 1;
1812                 }
1813               else
1814                 {
1815                   struct costs *pp = &this_op_costs[i];
1816                   move_table *intable = NULL;
1817                   move_table *outtable = NULL;
1818                   int op_class = (int) classes[i];
1819
1820                   if (!move_cost[mode])
1821                     init_move_cost (mode);
1822                   intable = may_move_in_cost[mode];
1823                   outtable = may_move_out_cost[mode];
1824
1825                   /* The loop is performance critical, so unswitch it manually.
1826                    */
1827                   switch (recog_data.operand_type[i])
1828                     {
1829                     case OP_INOUT:
1830                       for (class = 0; class < N_REG_CLASSES; class++)
1831                         pp->cost[class] = (intable[class][op_class]
1832                                            + outtable[op_class][class]);
1833                       break;
1834                     case OP_IN:
1835                       for (class = 0; class < N_REG_CLASSES; class++)
1836                         pp->cost[class] = intable[class][op_class];
1837                       break;
1838                     case OP_OUT:
1839                       for (class = 0; class < N_REG_CLASSES; class++)
1840                         pp->cost[class] = outtable[op_class][class];
1841                       break;
1842                     }
1843
1844                   /* If the alternative actually allows memory, make things
1845                      a bit cheaper since we won't need an extra insn to
1846                      load it.  */
1847
1848                   pp->mem_cost
1849                     = ((recog_data.operand_type[i] != OP_IN
1850                         ? MEMORY_MOVE_COST (mode, classes[i], 0)
1851                         : 0)
1852                        + (recog_data.operand_type[i] != OP_OUT
1853                           ? MEMORY_MOVE_COST (mode, classes[i], 1)
1854                           : 0) - allows_mem[i]);
1855
1856                   /* If we have assigned a class to this register in our
1857                      first pass, add a cost to this alternative corresponding
1858                      to what we would add if this register were not in the
1859                      appropriate class.  */
1860
1861                   if (reg_pref && reg_pref[REGNO (op)].prefclass != NO_REGS)
1862                     alt_cost
1863                       += (may_move_in_cost[mode]
1864                           [(unsigned char) reg_pref[REGNO (op)].prefclass]
1865                           [(int) classes[i]]);
1866                 }
1867             }
1868
1869           /* Otherwise, if this alternative wins, either because we
1870              have already determined that or if we have a hard register of
1871              the proper class, there is no cost for this alternative.  */
1872
1873           else if (win
1874                    || (REG_P (op)
1875                        && reg_fits_class_p (op, classes[i], 0, GET_MODE (op))))
1876             ;
1877
1878           /* If registers are valid, the cost of this alternative includes
1879              copying the object to and/or from a register.  */
1880
1881           else if (classes[i] != NO_REGS)
1882             {
1883               if (recog_data.operand_type[i] != OP_OUT)
1884                 alt_cost += copy_cost (op, mode, classes[i], 1, NULL);
1885
1886               if (recog_data.operand_type[i] != OP_IN)
1887                 alt_cost += copy_cost (op, mode, classes[i], 0, NULL);
1888             }
1889
1890           /* The only other way this alternative can be used is if this is a
1891              constant that could be placed into memory.  */
1892
1893           else if (CONSTANT_P (op) && (allows_addr || allows_mem[i]))
1894             alt_cost += MEMORY_MOVE_COST (mode, classes[i], 1);
1895           else
1896             alt_fail = 1;
1897         }
1898
1899       if (alt_fail)
1900         continue;
1901
1902       /* Finally, update the costs with the information we've calculated
1903          about this alternative.  */
1904
1905       for (i = 0; i < n_ops; i++)
1906         if (REG_P (ops[i])
1907             && REGNO (ops[i]) >= FIRST_PSEUDO_REGISTER)
1908           {
1909             struct costs *pp = &op_costs[i], *qq = &this_op_costs[i];
1910             int scale = 1 + (recog_data.operand_type[i] == OP_INOUT);
1911
1912             pp->mem_cost = MIN (pp->mem_cost,
1913                                 (qq->mem_cost + alt_cost) * scale);
1914
1915             for (class = 0; class < N_REG_CLASSES; class++)
1916               pp->cost[class] = MIN (pp->cost[class],
1917                                      (qq->cost[class] + alt_cost) * scale);
1918           }
1919     }
1920
1921   /* If this insn is a single set copying operand 1 to operand 0
1922      and one operand is a pseudo with the other a hard reg or a pseudo
1923      that prefers a register that is in its own register class then
1924      we may want to adjust the cost of that register class to -1.
1925
1926      Avoid the adjustment if the source does not die to avoid stressing of
1927      register allocator by preferrencing two colliding registers into single
1928      class.
1929
1930      Also avoid the adjustment if a copy between registers of the class
1931      is expensive (ten times the cost of a default copy is considered
1932      arbitrarily expensive).  This avoids losing when the preferred class
1933      is very expensive as the source of a copy instruction.  */
1934
1935   if ((set = single_set (insn)) != 0
1936       && ops[0] == SET_DEST (set) && ops[1] == SET_SRC (set)
1937       && REG_P (ops[0]) && REG_P (ops[1])
1938       && find_regno_note (insn, REG_DEAD, REGNO (ops[1])))
1939     for (i = 0; i <= 1; i++)
1940       if (REGNO (ops[i]) >= FIRST_PSEUDO_REGISTER)
1941         {
1942           unsigned int regno = REGNO (ops[!i]);
1943           enum machine_mode mode = GET_MODE (ops[!i]);
1944           int class;
1945
1946           if (regno >= FIRST_PSEUDO_REGISTER && reg_pref != 0
1947               && reg_pref[regno].prefclass != NO_REGS)
1948             {
1949               enum reg_class pref = reg_pref[regno].prefclass;
1950
1951               if ((reg_class_size[(unsigned char) pref]
1952                    == (unsigned) CLASS_MAX_NREGS (pref, mode))
1953                   && REGISTER_MOVE_COST (mode, pref, pref) < 10 * 2)
1954                 op_costs[i].cost[(unsigned char) pref] = -1;
1955             }
1956           else if (regno < FIRST_PSEUDO_REGISTER)
1957             for (class = 0; class < N_REG_CLASSES; class++)
1958               if (TEST_HARD_REG_BIT (reg_class_contents[class], regno)
1959                   && reg_class_size[class] == (unsigned) CLASS_MAX_NREGS (class, mode))
1960                 {
1961                   if (reg_class_size[class] == 1)
1962                     op_costs[i].cost[class] = -1;
1963                   else if (in_hard_reg_set_p (reg_class_contents[class],
1964                                              mode, regno))
1965                     op_costs[i].cost[class] = -1;
1966                 }
1967         }
1968 }
1969 \f
1970 /* Compute the cost of loading X into (if TO_P is nonzero) or from (if
1971    TO_P is zero) a register of class CLASS in mode MODE.
1972
1973    X must not be a pseudo.  */
1974
1975 static int
1976 copy_cost (rtx x, enum machine_mode mode, enum reg_class class, int to_p,
1977            secondary_reload_info *prev_sri)
1978 {
1979   enum reg_class secondary_class = NO_REGS;
1980   secondary_reload_info sri;
1981
1982   /* If X is a SCRATCH, there is actually nothing to move since we are
1983      assuming optimal allocation.  */
1984
1985   if (GET_CODE (x) == SCRATCH)
1986     return 0;
1987
1988   /* Get the class we will actually use for a reload.  */
1989   class = PREFERRED_RELOAD_CLASS (x, class);
1990
1991   /* If we need a secondary reload for an intermediate, the
1992      cost is that to load the input into the intermediate register, then
1993      to copy it.  */
1994
1995   sri.prev_sri = prev_sri;
1996   sri.extra_cost = 0;
1997   secondary_class = targetm.secondary_reload (to_p, x, class, mode, &sri);
1998
1999   if (!move_cost[mode])
2000     init_move_cost (mode);
2001
2002   if (secondary_class != NO_REGS)
2003     return (move_cost[mode][(int) secondary_class][(int) class]
2004             + sri.extra_cost
2005             + copy_cost (x, mode, secondary_class, to_p, &sri));
2006
2007   /* For memory, use the memory move cost, for (hard) registers, use the
2008      cost to move between the register classes, and use 2 for everything
2009      else (constants).  */
2010
2011   if (MEM_P (x) || class == NO_REGS)
2012     return sri.extra_cost + MEMORY_MOVE_COST (mode, class, to_p);
2013
2014   else if (REG_P (x))
2015     return (sri.extra_cost
2016             + move_cost[mode][(int) REGNO_REG_CLASS (REGNO (x))][(int) class]);
2017
2018   else
2019     /* If this is a constant, we may eventually want to call rtx_cost here.  */
2020     return sri.extra_cost + COSTS_N_INSNS (1);
2021 }
2022 \f
2023 /* Record the pseudo registers we must reload into hard registers
2024    in a subexpression of a memory address, X.
2025
2026    If CONTEXT is 0, we are looking at the base part of an address, otherwise we
2027    are looking at the index part.
2028
2029    MODE is the mode of the memory reference; OUTER_CODE and INDEX_CODE
2030    give the context that the rtx appears in.  These three arguments are
2031    passed down to base_reg_class.
2032
2033    SCALE is twice the amount to multiply the cost by (it is twice so we
2034    can represent half-cost adjustments).  */
2035
2036 static void
2037 record_address_regs (enum machine_mode mode, rtx x, int context,
2038                      enum rtx_code outer_code, enum rtx_code index_code,
2039                      int scale)
2040 {
2041   enum rtx_code code = GET_CODE (x);
2042   enum reg_class class;
2043
2044   if (context == 1)
2045     class = INDEX_REG_CLASS;
2046   else
2047     class = base_reg_class (mode, outer_code, index_code);
2048
2049   switch (code)
2050     {
2051     case CONST_INT:
2052     case CONST:
2053     case CC0:
2054     case PC:
2055     case SYMBOL_REF:
2056     case LABEL_REF:
2057       return;
2058
2059     case PLUS:
2060       /* When we have an address that is a sum,
2061          we must determine whether registers are "base" or "index" regs.
2062          If there is a sum of two registers, we must choose one to be
2063          the "base".  Luckily, we can use the REG_POINTER to make a good
2064          choice most of the time.  We only need to do this on machines
2065          that can have two registers in an address and where the base
2066          and index register classes are different.
2067
2068          ??? This code used to set REGNO_POINTER_FLAG in some cases, but
2069          that seems bogus since it should only be set when we are sure
2070          the register is being used as a pointer.  */
2071
2072       {
2073         rtx arg0 = XEXP (x, 0);
2074         rtx arg1 = XEXP (x, 1);
2075         enum rtx_code code0 = GET_CODE (arg0);
2076         enum rtx_code code1 = GET_CODE (arg1);
2077
2078         /* Look inside subregs.  */
2079         if (code0 == SUBREG)
2080           arg0 = SUBREG_REG (arg0), code0 = GET_CODE (arg0);
2081         if (code1 == SUBREG)
2082           arg1 = SUBREG_REG (arg1), code1 = GET_CODE (arg1);
2083
2084         /* If this machine only allows one register per address, it must
2085            be in the first operand.  */
2086
2087         if (MAX_REGS_PER_ADDRESS == 1)
2088           record_address_regs (mode, arg0, 0, PLUS, code1, scale);
2089
2090         /* If index and base registers are the same on this machine, just
2091            record registers in any non-constant operands.  We assume here,
2092            as well as in the tests below, that all addresses are in
2093            canonical form.  */
2094
2095         else if (INDEX_REG_CLASS == base_reg_class (VOIDmode, PLUS, SCRATCH))
2096           {
2097             record_address_regs (mode, arg0, context, PLUS, code1, scale);
2098             if (! CONSTANT_P (arg1))
2099               record_address_regs (mode, arg1, context, PLUS, code0, scale);
2100           }
2101
2102         /* If the second operand is a constant integer, it doesn't change
2103            what class the first operand must be.  */
2104
2105         else if (code1 == CONST_INT || code1 == CONST_DOUBLE)
2106           record_address_regs (mode, arg0, context, PLUS, code1, scale);
2107
2108         /* If the second operand is a symbolic constant, the first operand
2109            must be an index register.  */
2110
2111         else if (code1 == SYMBOL_REF || code1 == CONST || code1 == LABEL_REF)
2112           record_address_regs (mode, arg0, 1, PLUS, code1, scale);
2113
2114         /* If both operands are registers but one is already a hard register
2115            of index or reg-base class, give the other the class that the
2116            hard register is not.  */
2117
2118         else if (code0 == REG && code1 == REG
2119                  && REGNO (arg0) < FIRST_PSEUDO_REGISTER
2120                  && (ok_for_base_p_nonstrict (arg0, mode, PLUS, REG)
2121                      || ok_for_index_p_nonstrict (arg0)))
2122           record_address_regs (mode, arg1,
2123                                ok_for_base_p_nonstrict (arg0, mode, PLUS, REG)
2124                                ? 1 : 0,
2125                                PLUS, REG, scale);
2126         else if (code0 == REG && code1 == REG
2127                  && REGNO (arg1) < FIRST_PSEUDO_REGISTER
2128                  && (ok_for_base_p_nonstrict (arg1, mode, PLUS, REG)
2129                      || ok_for_index_p_nonstrict (arg1)))
2130           record_address_regs (mode, arg0,
2131                                ok_for_base_p_nonstrict (arg1, mode, PLUS, REG)
2132                                ? 1 : 0,
2133                                PLUS, REG, scale);
2134
2135         /* If one operand is known to be a pointer, it must be the base
2136            with the other operand the index.  Likewise if the other operand
2137            is a MULT.  */
2138
2139         else if ((code0 == REG && REG_POINTER (arg0))
2140                  || code1 == MULT)
2141           {
2142             record_address_regs (mode, arg0, 0, PLUS, code1, scale);
2143             record_address_regs (mode, arg1, 1, PLUS, code0, scale);
2144           }
2145         else if ((code1 == REG && REG_POINTER (arg1))
2146                  || code0 == MULT)
2147           {
2148             record_address_regs (mode, arg0, 1, PLUS, code1, scale);
2149             record_address_regs (mode, arg1, 0, PLUS, code0, scale);
2150           }
2151
2152         /* Otherwise, count equal chances that each might be a base
2153            or index register.  This case should be rare.  */
2154
2155         else
2156           {
2157             record_address_regs (mode, arg0, 0, PLUS, code1, scale / 2);
2158             record_address_regs (mode, arg0, 1, PLUS, code1, scale / 2);
2159             record_address_regs (mode, arg1, 0, PLUS, code0, scale / 2);
2160             record_address_regs (mode, arg1, 1, PLUS, code0, scale / 2);
2161           }
2162       }
2163       break;
2164
2165       /* Double the importance of a pseudo register that is incremented
2166          or decremented, since it would take two extra insns
2167          if it ends up in the wrong place.  */
2168     case POST_MODIFY:
2169     case PRE_MODIFY:
2170       record_address_regs (mode, XEXP (x, 0), 0, code,
2171                            GET_CODE (XEXP (XEXP (x, 1), 1)), 2 * scale);
2172       if (REG_P (XEXP (XEXP (x, 1), 1)))
2173         record_address_regs (mode, XEXP (XEXP (x, 1), 1), 1, code, REG,
2174                              2 * scale);
2175       break;
2176
2177     case POST_INC:
2178     case PRE_INC:
2179     case POST_DEC:
2180     case PRE_DEC:
2181       /* Double the importance of a pseudo register that is incremented
2182          or decremented, since it would take two extra insns
2183          if it ends up in the wrong place.  If the operand is a pseudo,
2184          show it is being used in an INC_DEC context.  */
2185
2186 #ifdef FORBIDDEN_INC_DEC_CLASSES
2187       if (REG_P (XEXP (x, 0))
2188           && REGNO (XEXP (x, 0)) >= FIRST_PSEUDO_REGISTER)
2189         in_inc_dec[REGNO (XEXP (x, 0))] = 1;
2190 #endif
2191
2192       record_address_regs (mode, XEXP (x, 0), 0, code, SCRATCH, 2 * scale);
2193       break;
2194
2195     case REG:
2196       {
2197         struct costs *pp = &costs[REGNO (x)];
2198         int i;
2199
2200         pp->mem_cost += (MEMORY_MOVE_COST (Pmode, class, 1) * scale) / 2;
2201
2202         if (!move_cost[Pmode])
2203           init_move_cost (Pmode);
2204         for (i = 0; i < N_REG_CLASSES; i++)
2205           pp->cost[i] += (may_move_in_cost[Pmode][i][(int) class] * scale) / 2;
2206       }
2207       break;
2208
2209     default:
2210       {
2211         const char *fmt = GET_RTX_FORMAT (code);
2212         int i;
2213         for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
2214           if (fmt[i] == 'e')
2215             record_address_regs (mode, XEXP (x, i), context, code, SCRATCH,
2216                                  scale);
2217       }
2218     }
2219 }
2220 \f
2221 #ifdef FORBIDDEN_INC_DEC_CLASSES
2222
2223 /* Return 1 if REG is valid as an auto-increment memory reference
2224    to an object of MODE.  */
2225
2226 static int
2227 auto_inc_dec_reg_p (rtx reg, enum machine_mode mode)
2228 {
2229   if (HAVE_POST_INCREMENT
2230       && memory_address_p (mode, gen_rtx_POST_INC (Pmode, reg)))
2231     return 1;
2232
2233   if (HAVE_POST_DECREMENT
2234       && memory_address_p (mode, gen_rtx_POST_DEC (Pmode, reg)))
2235     return 1;
2236
2237   if (HAVE_PRE_INCREMENT
2238       && memory_address_p (mode, gen_rtx_PRE_INC (Pmode, reg)))
2239     return 1;
2240
2241   if (HAVE_PRE_DECREMENT
2242       && memory_address_p (mode, gen_rtx_PRE_DEC (Pmode, reg)))
2243     return 1;
2244
2245   return 0;
2246 }
2247 #endif
2248 \f
2249 /* Free up the space allocated by allocate_reg_info.  */
2250 void
2251 free_reg_info (void)
2252 {
2253   if (reg_pref)
2254     {
2255       free (reg_pref);
2256       reg_pref = NULL;
2257     }
2258
2259   if (reg_renumber)
2260     {
2261       free (reg_renumber);
2262       reg_renumber = NULL;
2263     }
2264 }
2265
2266 \f
2267 /* This is the `regscan' pass of the compiler, run just before cse and
2268    again just before loop.  It finds the first and last use of each
2269    pseudo-register.  */
2270
2271 void
2272 reg_scan (rtx f, unsigned int nregs ATTRIBUTE_UNUSED)
2273 {
2274   rtx insn;
2275
2276   timevar_push (TV_REG_SCAN);
2277
2278   for (insn = f; insn; insn = NEXT_INSN (insn))
2279     if (INSN_P (insn))
2280       {
2281         reg_scan_mark_refs (PATTERN (insn), insn);
2282         if (REG_NOTES (insn))
2283           reg_scan_mark_refs (REG_NOTES (insn), insn);
2284       }
2285
2286   timevar_pop (TV_REG_SCAN);
2287 }
2288
2289
2290 /* X is the expression to scan.  INSN is the insn it appears in.
2291    NOTE_FLAG is nonzero if X is from INSN's notes rather than its body.
2292    We should only record information for REGs with numbers
2293    greater than or equal to MIN_REGNO.  */
2294
2295 extern struct tree_opt_pass *current_pass;
2296
2297 static void
2298 reg_scan_mark_refs (rtx x, rtx insn)
2299 {
2300   enum rtx_code code;
2301   rtx dest;
2302   rtx note;
2303
2304   if (!x)
2305     return;
2306   code = GET_CODE (x);
2307   switch (code)
2308     {
2309     case CONST:
2310     case CONST_INT:
2311     case CONST_DOUBLE:
2312     case CONST_FIXED:
2313     case CONST_VECTOR:
2314     case CC0:
2315     case PC:
2316     case SYMBOL_REF:
2317     case LABEL_REF:
2318     case ADDR_VEC:
2319     case ADDR_DIFF_VEC:
2320     case REG:
2321       return;
2322
2323     case EXPR_LIST:
2324       if (XEXP (x, 0))
2325         reg_scan_mark_refs (XEXP (x, 0), insn);
2326       if (XEXP (x, 1))
2327         reg_scan_mark_refs (XEXP (x, 1), insn);
2328       break;
2329
2330     case INSN_LIST:
2331       if (XEXP (x, 1))
2332         reg_scan_mark_refs (XEXP (x, 1), insn);
2333       break;
2334
2335     case CLOBBER:
2336       if (MEM_P (XEXP (x, 0)))
2337         reg_scan_mark_refs (XEXP (XEXP (x, 0), 0), insn);
2338       break;
2339
2340     case SET:
2341       /* Count a set of the destination if it is a register.  */
2342       for (dest = SET_DEST (x);
2343            GET_CODE (dest) == SUBREG || GET_CODE (dest) == STRICT_LOW_PART
2344            || GET_CODE (dest) == ZERO_EXTEND;
2345            dest = XEXP (dest, 0))
2346         ;
2347
2348       /* If this is setting a pseudo from another pseudo or the sum of a
2349          pseudo and a constant integer and the other pseudo is known to be
2350          a pointer, set the destination to be a pointer as well.
2351
2352          Likewise if it is setting the destination from an address or from a
2353          value equivalent to an address or to the sum of an address and
2354          something else.
2355
2356          But don't do any of this if the pseudo corresponds to a user
2357          variable since it should have already been set as a pointer based
2358          on the type.  */
2359
2360       if (REG_P (SET_DEST (x))
2361           && REGNO (SET_DEST (x)) >= FIRST_PSEUDO_REGISTER
2362           /* If the destination pseudo is set more than once, then other
2363              sets might not be to a pointer value (consider access to a
2364              union in two threads of control in the presence of global
2365              optimizations).  So only set REG_POINTER on the destination
2366              pseudo if this is the only set of that pseudo.  */
2367           && DF_REG_DEF_COUNT (REGNO (SET_DEST (x))) == 1
2368           && ! REG_USERVAR_P (SET_DEST (x))
2369           && ! REG_POINTER (SET_DEST (x))
2370           && ((REG_P (SET_SRC (x))
2371                && REG_POINTER (SET_SRC (x)))
2372               || ((GET_CODE (SET_SRC (x)) == PLUS
2373                    || GET_CODE (SET_SRC (x)) == LO_SUM)
2374                   && GET_CODE (XEXP (SET_SRC (x), 1)) == CONST_INT
2375                   && REG_P (XEXP (SET_SRC (x), 0))
2376                   && REG_POINTER (XEXP (SET_SRC (x), 0)))
2377               || GET_CODE (SET_SRC (x)) == CONST
2378               || GET_CODE (SET_SRC (x)) == SYMBOL_REF
2379               || GET_CODE (SET_SRC (x)) == LABEL_REF
2380               || (GET_CODE (SET_SRC (x)) == HIGH
2381                   && (GET_CODE (XEXP (SET_SRC (x), 0)) == CONST
2382                       || GET_CODE (XEXP (SET_SRC (x), 0)) == SYMBOL_REF
2383                       || GET_CODE (XEXP (SET_SRC (x), 0)) == LABEL_REF))
2384               || ((GET_CODE (SET_SRC (x)) == PLUS
2385                    || GET_CODE (SET_SRC (x)) == LO_SUM)
2386                   && (GET_CODE (XEXP (SET_SRC (x), 1)) == CONST
2387                       || GET_CODE (XEXP (SET_SRC (x), 1)) == SYMBOL_REF
2388                       || GET_CODE (XEXP (SET_SRC (x), 1)) == LABEL_REF))
2389               || ((note = find_reg_note (insn, REG_EQUAL, 0)) != 0
2390                   && (GET_CODE (XEXP (note, 0)) == CONST
2391                       || GET_CODE (XEXP (note, 0)) == SYMBOL_REF
2392                       || GET_CODE (XEXP (note, 0)) == LABEL_REF))))
2393         REG_POINTER (SET_DEST (x)) = 1;
2394
2395       /* If this is setting a register from a register or from a simple
2396          conversion of a register, propagate REG_EXPR.  */
2397       if (REG_P (dest) && !REG_ATTRS (dest))
2398         {
2399           rtx src = SET_SRC (x);
2400
2401           while (GET_CODE (src) == SIGN_EXTEND
2402                  || GET_CODE (src) == ZERO_EXTEND
2403                  || GET_CODE (src) == TRUNCATE
2404                  || (GET_CODE (src) == SUBREG && subreg_lowpart_p (src)))
2405             src = XEXP (src, 0);
2406
2407           if (REG_P (src))
2408             REG_ATTRS (dest) = REG_ATTRS (src);
2409           if (MEM_P (src))
2410             set_reg_attrs_from_mem (dest, src);
2411         }
2412
2413       /* ... fall through ...  */
2414
2415     default:
2416       {
2417         const char *fmt = GET_RTX_FORMAT (code);
2418         int i;
2419         for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
2420           {
2421             if (fmt[i] == 'e')
2422               reg_scan_mark_refs (XEXP (x, i), insn);
2423             else if (fmt[i] == 'E' && XVEC (x, i) != 0)
2424               {
2425                 int j;
2426                 for (j = XVECLEN (x, i) - 1; j >= 0; j--)
2427                   reg_scan_mark_refs (XVECEXP (x, i, j), insn);
2428               }
2429           }
2430       }
2431     }
2432 }
2433 \f
2434 /* Return nonzero if C1 is a subset of C2, i.e., if every register in C1
2435    is also in C2.  */
2436
2437 int
2438 reg_class_subset_p (enum reg_class c1, enum reg_class c2)
2439 {
2440   return (c1 == c2
2441           || c2 == ALL_REGS
2442           || hard_reg_set_subset_p (reg_class_contents[(int) c1],
2443                                    reg_class_contents[(int) c2]));
2444 }
2445
2446 /* Return nonzero if there is a register that is in both C1 and C2.  */
2447
2448 int
2449 reg_classes_intersect_p (enum reg_class c1, enum reg_class c2)
2450 {
2451   return (c1 == c2
2452           || c1 == ALL_REGS
2453           || c2 == ALL_REGS
2454           || hard_reg_set_intersect_p (reg_class_contents[(int) c1],
2455                                       reg_class_contents[(int) c2]));
2456 }
2457
2458 #ifdef CANNOT_CHANGE_MODE_CLASS
2459
2460 struct subregs_of_mode_node
2461 {
2462   unsigned int block;
2463   unsigned char modes[MAX_MACHINE_MODE];
2464 };
2465
2466 static htab_t subregs_of_mode;
2467
2468 static hashval_t
2469 som_hash (const void *x)
2470 {
2471   const struct subregs_of_mode_node *a = x;
2472   return a->block;
2473 }
2474
2475 static int
2476 som_eq (const void *x, const void *y)
2477 {
2478   const struct subregs_of_mode_node *a = x;
2479   const struct subregs_of_mode_node *b = y;
2480   return a->block == b->block;
2481 }
2482
2483
2484 static void
2485 record_subregs_of_mode (rtx subreg)
2486 {
2487   struct subregs_of_mode_node dummy, *node;
2488   enum machine_mode mode;
2489   unsigned int regno;
2490   void **slot;
2491
2492   if (!REG_P (SUBREG_REG (subreg)))
2493     return;
2494
2495   regno = REGNO (SUBREG_REG (subreg));
2496   mode = GET_MODE (subreg);
2497
2498   if (regno < FIRST_PSEUDO_REGISTER)
2499     return;
2500
2501   dummy.block = regno & -8;
2502   slot = htab_find_slot_with_hash (subregs_of_mode, &dummy,
2503                                    dummy.block, INSERT);
2504   node = *slot;
2505   if (node == NULL)
2506     {
2507       node = XCNEW (struct subregs_of_mode_node);
2508       node->block = regno & -8;
2509       *slot = node;
2510     }
2511
2512   node->modes[mode] |= 1 << (regno & 7);
2513 }
2514
2515
2516 /* Call record_subregs_of_mode for all the subregs in X.  */
2517
2518 static void 
2519 find_subregs_of_mode (rtx x)
2520 {
2521   enum rtx_code code = GET_CODE (x);
2522   const char * const fmt = GET_RTX_FORMAT (code);
2523   int i;
2524
2525   if (code == SUBREG)
2526     record_subregs_of_mode (x);
2527     
2528   /* Time for some deep diving.  */
2529   for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
2530     {
2531       if (fmt[i] == 'e')
2532         find_subregs_of_mode (XEXP (x, i));
2533       else if (fmt[i] == 'E')
2534         {
2535           int j;
2536           for (j = XVECLEN (x, i) - 1; j >= 0; j--)
2537             find_subregs_of_mode (XVECEXP (x, i, j));
2538         }
2539     }
2540 }
2541
2542 static unsigned int
2543 init_subregs_of_mode (void)
2544 {
2545   basic_block bb;
2546   rtx insn;
2547
2548   if (subregs_of_mode)
2549     htab_empty (subregs_of_mode);
2550   else
2551     subregs_of_mode = htab_create (100, som_hash, som_eq, free);
2552
2553   FOR_EACH_BB (bb)
2554     FOR_BB_INSNS (bb, insn)
2555     if (INSN_P (insn))
2556       find_subregs_of_mode (PATTERN (insn));
2557
2558   return 0;
2559 }
2560
2561
2562 /* Set bits in *USED which correspond to registers which can't change
2563    their mode from FROM to any mode in which REGNO was encountered.  */
2564
2565 void
2566 cannot_change_mode_set_regs (HARD_REG_SET *used, enum machine_mode from,
2567                              unsigned int regno)
2568 {
2569   struct subregs_of_mode_node dummy, *node;
2570   enum machine_mode to;
2571   unsigned char mask;
2572   unsigned int i;
2573
2574   gcc_assert (subregs_of_mode);
2575   dummy.block = regno & -8;
2576   node = htab_find_with_hash (subregs_of_mode, &dummy, dummy.block);
2577   if (node == NULL)
2578     return;
2579
2580   mask = 1 << (regno & 7);
2581   for (to = VOIDmode; to < NUM_MACHINE_MODES; to++)
2582     if (node->modes[to] & mask)
2583       for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
2584         if (!TEST_HARD_REG_BIT (*used, i)
2585             && REG_CANNOT_CHANGE_MODE_P (i, from, to))
2586           SET_HARD_REG_BIT (*used, i);
2587 }
2588
2589 /* Return 1 if REGNO has had an invalid mode change in CLASS from FROM
2590    mode.  */
2591
2592 bool
2593 invalid_mode_change_p (unsigned int regno,
2594                        enum reg_class class ATTRIBUTE_UNUSED,
2595                        enum machine_mode from)
2596 {
2597   struct subregs_of_mode_node dummy, *node;
2598   enum machine_mode to;
2599   unsigned char mask;
2600
2601   gcc_assert (subregs_of_mode);
2602   dummy.block = regno & -8;
2603   node = htab_find_with_hash (subregs_of_mode, &dummy, dummy.block);
2604   if (node == NULL)
2605     return false;
2606
2607   mask = 1 << (regno & 7);
2608   for (to = VOIDmode; to < NUM_MACHINE_MODES; to++)
2609     if (node->modes[to] & mask)
2610       if (CANNOT_CHANGE_MODE_CLASS (from, to, class))
2611         return true;
2612
2613   return false;
2614 }
2615
2616 static unsigned int
2617 finish_subregs_of_mode (void)
2618 {
2619   htab_delete (subregs_of_mode);
2620   subregs_of_mode = 0;
2621   return 0;
2622 }
2623 #else
2624 static unsigned int
2625 init_subregs_of_mode (void)
2626 {
2627   return 0;
2628 }
2629 static unsigned int
2630 finish_subregs_of_mode (void)
2631 {
2632   return 0;
2633 }
2634
2635 #endif /* CANNOT_CHANGE_MODE_CLASS */
2636
2637 static bool
2638 gate_subregs_of_mode_init (void)
2639 {
2640 #ifdef CANNOT_CHANGE_MODE_CLASS
2641   return true;
2642 #else
2643   return false;
2644 #endif
2645 }
2646
2647 struct tree_opt_pass pass_subregs_of_mode_init =
2648 {
2649   "subregs_of_mode_init",               /* name */
2650   gate_subregs_of_mode_init,            /* gate */
2651   init_subregs_of_mode,                 /* execute */
2652   NULL,                                 /* sub */
2653   NULL,                                 /* next */
2654   0,                                    /* static_pass_number */
2655   0,                                    /* tv_id */
2656   0,                                    /* properties_required */
2657   0,                                    /* properties_provided */
2658   0,                                    /* properties_destroyed */
2659   0,                                    /* todo_flags_start */
2660   0,                                    /* todo_flags_finish */
2661   0                                     /* letter */
2662 };
2663
2664 struct tree_opt_pass pass_subregs_of_mode_finish =
2665 {
2666   "subregs_of_mode_finish",               /* name */
2667   gate_subregs_of_mode_init,            /* gate */
2668   finish_subregs_of_mode,               /* execute */
2669   NULL,                                 /* sub */
2670   NULL,                                 /* next */
2671   0,                                    /* static_pass_number */
2672   0,                                    /* tv_id */
2673   0,                                    /* properties_required */
2674   0,                                    /* properties_provided */
2675   0,                                    /* properties_destroyed */
2676   0,                                    /* todo_flags_start */
2677   0,                                    /* todo_flags_finish */
2678   0                                     /* letter */
2679 };
2680
2681
2682
2683 #include "gt-regclass.h"