OSDN Git Service

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