OSDN Git Service

update darwin to use link_gcc_c_sequence.
[pf3gnuchains/gcc-fork.git] / gcc / reginfo.c
1 /* Compute different info about registers.
2    Copyright (C) 1987, 1988, 1991, 1992, 1993, 1994, 1995, 1996
3    1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
4    2009, 2010  Free Software Foundation, Inc.
5
6 This file is part of GCC.
7
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 3, or (at your option) any later
11 version.
12
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
16 for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3.  If not see
20 <http://www.gnu.org/licenses/>.  */
21
22
23 /* This file contains regscan pass of the compiler and passes for
24    dealing with info about modes of pseudo-registers inside
25    subregisters.  It also defines some tables of information about the
26    hardware registers, function init_reg_sets to initialize the
27    tables, and other auxiliary functions to deal with info about
28    registers and their classes.  */
29
30 #include "config.h"
31 #include "system.h"
32 #include "coretypes.h"
33 #include "tm.h"
34 #include "hard-reg-set.h"
35 #include "rtl.h"
36 #include "expr.h"
37 #include "tm_p.h"
38 #include "flags.h"
39 #include "basic-block.h"
40 #include "regs.h"
41 #include "addresses.h"
42 #include "function.h"
43 #include "insn-config.h"
44 #include "recog.h"
45 #include "reload.h"
46 #include "toplev.h"
47 #include "diagnostic-core.h"
48 #include "output.h"
49 #include "timevar.h"
50 #include "hashtab.h"
51 #include "target.h"
52 #include "tree-pass.h"
53 #include "df.h"
54 #include "ira.h"
55
56 /* Maximum register number used in this function, plus one.  */
57
58 int max_regno;
59
60 \f
61 struct target_hard_regs default_target_hard_regs;
62 struct target_regs default_target_regs;
63 #if SWITCHABLE_TARGET
64 struct target_hard_regs *this_target_hard_regs = &default_target_hard_regs;
65 struct target_regs *this_target_regs = &default_target_regs;
66 #endif
67
68 /* Data for initializing fixed_regs.  */
69 static const char initial_fixed_regs[] = FIXED_REGISTERS;
70
71 /* Data for initializing call_used_regs.  */
72 static const char initial_call_used_regs[] = CALL_USED_REGISTERS;
73
74 #ifdef CALL_REALLY_USED_REGISTERS
75 /* Data for initializing call_really_used_regs.  */
76 static const char initial_call_really_used_regs[] = CALL_REALLY_USED_REGISTERS;
77 #endif
78
79 #ifdef CALL_REALLY_USED_REGISTERS
80 #define CALL_REALLY_USED_REGNO_P(X)  call_really_used_regs[X]
81 #else
82 #define CALL_REALLY_USED_REGNO_P(X)  call_used_regs[X]
83 #endif
84
85 /* Indexed by hard register number, contains 1 for registers
86    that are being used for global register decls.
87    These must be exempt from ordinary flow analysis
88    and are also considered fixed.  */
89 char global_regs[FIRST_PSEUDO_REGISTER];
90
91 /* Same information as REGS_INVALIDATED_BY_CALL but in regset form to be used
92    in dataflow more conveniently.  */
93 regset regs_invalidated_by_call_regset;
94
95 /* The bitmap_obstack is used to hold some static variables that
96    should not be reset after each function is compiled.  */
97 static bitmap_obstack persistent_obstack;
98
99 /* Used to initialize reg_alloc_order.  */
100 #ifdef REG_ALLOC_ORDER
101 static int initial_reg_alloc_order[FIRST_PSEUDO_REGISTER] = REG_ALLOC_ORDER;
102 #endif
103
104 /* The same information, but as an array of unsigned ints.  We copy from
105    these unsigned ints to the table above.  We do this so the tm.h files
106    do not have to be aware of the wordsize for machines with <= 64 regs.
107    Note that we hard-code 32 here, not HOST_BITS_PER_INT.  */
108 #define N_REG_INTS  \
109   ((FIRST_PSEUDO_REGISTER + (32 - 1)) / 32)
110
111 static const unsigned int_reg_class_contents[N_REG_CLASSES][N_REG_INTS]
112   = REG_CLASS_CONTENTS;
113
114 /* Array containing all of the register names.  */
115 static const char *const initial_reg_names[] = REGISTER_NAMES;
116
117 /* Array containing all of the register class names.  */
118 const char * reg_class_names[] = REG_CLASS_NAMES;
119
120 #define last_mode_for_init_move_cost \
121   (this_target_regs->x_last_mode_for_init_move_cost)
122
123 /* No more global register variables may be declared; true once
124    reginfo has been initialized.  */
125 static int no_global_reg_vars = 0;
126
127 /* Given a register bitmap, turn on the bits in a HARD_REG_SET that
128    correspond to the hard registers, if any, set in that map.  This
129    could be done far more efficiently by having all sorts of special-cases
130    with moving single words, but probably isn't worth the trouble.  */
131 void
132 reg_set_to_hard_reg_set (HARD_REG_SET *to, const_bitmap from)
133 {
134   unsigned i;
135   bitmap_iterator bi;
136
137   EXECUTE_IF_SET_IN_BITMAP (from, 0, i, bi)
138     {
139       if (i >= FIRST_PSEUDO_REGISTER)
140         return;
141       SET_HARD_REG_BIT (*to, i);
142     }
143 }
144
145 /* Function called only once per target_globals to initialize the
146    target_hard_regs structure.  Once this is done, various switches
147    may override.  */
148 void
149 init_reg_sets (void)
150 {
151   int i, j;
152
153   /* First copy the register information from the initial int form into
154      the regsets.  */
155
156   for (i = 0; i < N_REG_CLASSES; i++)
157     {
158       CLEAR_HARD_REG_SET (reg_class_contents[i]);
159
160       /* Note that we hard-code 32 here, not HOST_BITS_PER_INT.  */
161       for (j = 0; j < FIRST_PSEUDO_REGISTER; j++)
162         if (int_reg_class_contents[i][j / 32]
163             & ((unsigned) 1 << (j % 32)))
164           SET_HARD_REG_BIT (reg_class_contents[i], j);
165     }
166
167   /* Sanity check: make sure the target macros FIXED_REGISTERS and
168      CALL_USED_REGISTERS had the right number of initializers.  */
169   gcc_assert (sizeof fixed_regs == sizeof initial_fixed_regs);
170   gcc_assert (sizeof call_used_regs == sizeof initial_call_used_regs);
171 #ifdef CALL_REALLY_USED_REGISTERS
172   gcc_assert (sizeof call_really_used_regs
173               == sizeof initial_call_really_used_regs);
174 #endif
175 #ifdef REG_ALLOC_ORDER
176   gcc_assert (sizeof reg_alloc_order == sizeof initial_reg_alloc_order);
177 #endif
178   gcc_assert (sizeof reg_names == sizeof initial_reg_names);
179
180   memcpy (fixed_regs, initial_fixed_regs, sizeof fixed_regs);
181   memcpy (call_used_regs, initial_call_used_regs, sizeof call_used_regs);
182 #ifdef CALL_REALLY_USED_REGISTERS
183   memcpy (call_really_used_regs, initial_call_really_used_regs,
184           sizeof call_really_used_regs);
185 #endif
186 #ifdef REG_ALLOC_ORDER
187   memcpy (reg_alloc_order, initial_reg_alloc_order, sizeof reg_alloc_order);
188 #endif
189   memcpy (reg_names, initial_reg_names, sizeof reg_names);
190 }
191
192 /* Initialize may_move_cost and friends for mode M.  */
193 void
194 init_move_cost (enum machine_mode m)
195 {
196   static unsigned short last_move_cost[N_REG_CLASSES][N_REG_CLASSES];
197   bool all_match = true;
198   unsigned int i, j;
199
200   gcc_assert (have_regs_of_mode[m]);
201   for (i = 0; i < N_REG_CLASSES; i++)
202     if (contains_reg_of_mode[i][m])
203       for (j = 0; j < N_REG_CLASSES; j++)
204         {
205           int cost;
206           if (!contains_reg_of_mode[j][m])
207             cost = 65535;
208           else
209             {
210               cost = register_move_cost (m, (enum reg_class) i,
211                                          (enum reg_class) j);
212               gcc_assert (cost < 65535);
213             }
214           all_match &= (last_move_cost[i][j] == cost);
215           last_move_cost[i][j] = cost;
216         }
217   if (all_match && last_mode_for_init_move_cost != -1)
218     {
219       move_cost[m] = move_cost[last_mode_for_init_move_cost];
220       may_move_in_cost[m] = may_move_in_cost[last_mode_for_init_move_cost];
221       may_move_out_cost[m] = may_move_out_cost[last_mode_for_init_move_cost];
222       return;
223     }
224   last_mode_for_init_move_cost = m;
225   move_cost[m] = (move_table *)xmalloc (sizeof (move_table)
226                                         * N_REG_CLASSES);
227   may_move_in_cost[m] = (move_table *)xmalloc (sizeof (move_table)
228                                                * N_REG_CLASSES);
229   may_move_out_cost[m] = (move_table *)xmalloc (sizeof (move_table)
230                                                 * N_REG_CLASSES);
231   for (i = 0; i < N_REG_CLASSES; i++)
232     if (contains_reg_of_mode[i][m])
233       for (j = 0; j < N_REG_CLASSES; j++)
234         {
235           int cost;
236           enum reg_class *p1, *p2;
237
238           if (last_move_cost[i][j] == 65535)
239             {
240               move_cost[m][i][j] = 65535;
241               may_move_in_cost[m][i][j] = 65535;
242               may_move_out_cost[m][i][j] = 65535;
243             }
244           else
245             {
246               cost = last_move_cost[i][j];
247
248               for (p2 = &reg_class_subclasses[j][0];
249                    *p2 != LIM_REG_CLASSES; p2++)
250                 if (*p2 != i && contains_reg_of_mode[*p2][m])
251                   cost = MAX (cost, move_cost[m][i][*p2]);
252
253               for (p1 = &reg_class_subclasses[i][0];
254                    *p1 != LIM_REG_CLASSES; p1++)
255                 if (*p1 != j && contains_reg_of_mode[*p1][m])
256                   cost = MAX (cost, move_cost[m][*p1][j]);
257
258               gcc_assert (cost <= 65535);
259               move_cost[m][i][j] = cost;
260
261               if (reg_class_subset_p ((enum reg_class) i, (enum reg_class) j))
262                 may_move_in_cost[m][i][j] = 0;
263               else
264                 may_move_in_cost[m][i][j] = cost;
265
266               if (reg_class_subset_p ((enum reg_class) j, (enum reg_class) i))
267                 may_move_out_cost[m][i][j] = 0;
268               else
269                 may_move_out_cost[m][i][j] = cost;
270             }
271         }
272     else
273       for (j = 0; j < N_REG_CLASSES; j++)
274         {
275           move_cost[m][i][j] = 65535;
276           may_move_in_cost[m][i][j] = 65535;
277           may_move_out_cost[m][i][j] = 65535;
278         }
279 }
280
281 /* We need to save copies of some of the register information which
282    can be munged by command-line switches so we can restore it during
283    subsequent back-end reinitialization.  */
284 static char saved_fixed_regs[FIRST_PSEUDO_REGISTER];
285 static char saved_call_used_regs[FIRST_PSEUDO_REGISTER];
286 #ifdef CALL_REALLY_USED_REGISTERS
287 static char saved_call_really_used_regs[FIRST_PSEUDO_REGISTER];
288 #endif
289 static const char *saved_reg_names[FIRST_PSEUDO_REGISTER];
290
291 /* Save the register information.  */
292 void
293 save_register_info (void)
294 {
295   /* Sanity check:  make sure the target macros FIXED_REGISTERS and
296      CALL_USED_REGISTERS had the right number of initializers.  */
297   gcc_assert (sizeof fixed_regs == sizeof saved_fixed_regs);
298   gcc_assert (sizeof call_used_regs == sizeof saved_call_used_regs);
299   memcpy (saved_fixed_regs, fixed_regs, sizeof fixed_regs);
300   memcpy (saved_call_used_regs, call_used_regs, sizeof call_used_regs);
301
302   /* Likewise for call_really_used_regs.  */
303 #ifdef CALL_REALLY_USED_REGISTERS
304   gcc_assert (sizeof call_really_used_regs
305               == sizeof saved_call_really_used_regs);
306   memcpy (saved_call_really_used_regs, call_really_used_regs,
307           sizeof call_really_used_regs);
308 #endif
309
310   /* And similarly for reg_names.  */
311   gcc_assert (sizeof reg_names == sizeof saved_reg_names);
312   memcpy (saved_reg_names, reg_names, sizeof reg_names);
313 }
314
315 /* Restore the register information.  */
316 static void
317 restore_register_info (void)
318 {
319   memcpy (fixed_regs, saved_fixed_regs, sizeof fixed_regs);
320   memcpy (call_used_regs, saved_call_used_regs, sizeof call_used_regs);
321
322 #ifdef CALL_REALLY_USED_REGISTERS
323   memcpy (call_really_used_regs, saved_call_really_used_regs,
324           sizeof call_really_used_regs);
325 #endif
326
327   memcpy (reg_names, saved_reg_names, sizeof reg_names);
328 }
329
330 /* After switches have been processed, which perhaps alter
331    `fixed_regs' and `call_used_regs', convert them to HARD_REG_SETs.  */
332 static void
333 init_reg_sets_1 (void)
334 {
335   unsigned int i, j;
336   unsigned int /* enum machine_mode */ m;
337
338   restore_register_info ();
339
340 #ifdef REG_ALLOC_ORDER
341   for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
342     inv_reg_alloc_order[reg_alloc_order[i]] = i;
343 #endif
344
345   /* Let the target tweak things if necessary.  */
346
347   targetm.conditional_register_usage ();
348
349   /* Compute number of hard regs in each class.  */
350
351   memset (reg_class_size, 0, sizeof reg_class_size);
352   for (i = 0; i < N_REG_CLASSES; i++)
353     {
354       bool any_nonfixed = false;
355       for (j = 0; j < FIRST_PSEUDO_REGISTER; j++)       
356         if (TEST_HARD_REG_BIT (reg_class_contents[i], j))
357           {
358             reg_class_size[i]++;
359             if (!fixed_regs[j])
360               any_nonfixed = true;
361           }
362       class_only_fixed_regs[i] = !any_nonfixed;
363     }
364
365   /* Initialize the table of subunions.
366      reg_class_subunion[I][J] gets the largest-numbered reg-class
367      that is contained in the union of classes I and J.  */
368
369   memset (reg_class_subunion, 0, sizeof reg_class_subunion);
370   for (i = 0; i < N_REG_CLASSES; i++)
371     {
372       for (j = 0; j < N_REG_CLASSES; j++)
373         {
374           HARD_REG_SET c;
375           int k;
376
377           COPY_HARD_REG_SET (c, reg_class_contents[i]);
378           IOR_HARD_REG_SET (c, reg_class_contents[j]);
379           for (k = 0; k < N_REG_CLASSES; k++)
380             if (hard_reg_set_subset_p (reg_class_contents[k], c)
381                 && !hard_reg_set_subset_p (reg_class_contents[k],
382                                           reg_class_contents
383                                           [(int) reg_class_subunion[i][j]]))
384               reg_class_subunion[i][j] = (enum reg_class) k;
385         }
386     }
387
388   /* Initialize the table of superunions.
389      reg_class_superunion[I][J] gets the smallest-numbered reg-class
390      containing the union of classes I and J.  */
391
392   memset (reg_class_superunion, 0, sizeof reg_class_superunion);
393   for (i = 0; i < N_REG_CLASSES; i++)
394     {
395       for (j = 0; j < N_REG_CLASSES; j++)
396         {
397           HARD_REG_SET c;
398           int k;
399
400           COPY_HARD_REG_SET (c, reg_class_contents[i]);
401           IOR_HARD_REG_SET (c, reg_class_contents[j]);
402           for (k = 0; k < N_REG_CLASSES; k++)
403             if (hard_reg_set_subset_p (c, reg_class_contents[k]))
404               break;
405
406           reg_class_superunion[i][j] = (enum reg_class) k;
407         }
408     }
409
410   /* Initialize the tables of subclasses and superclasses of each reg class.
411      First clear the whole table, then add the elements as they are found.  */
412
413   for (i = 0; i < N_REG_CLASSES; i++)
414     {
415       for (j = 0; j < N_REG_CLASSES; j++)
416         reg_class_subclasses[i][j] = LIM_REG_CLASSES;
417     }
418
419   for (i = 0; i < N_REG_CLASSES; i++)
420     {
421       if (i == (int) NO_REGS)
422         continue;
423
424       for (j = i + 1; j < N_REG_CLASSES; j++)
425         if (hard_reg_set_subset_p (reg_class_contents[i],
426                                   reg_class_contents[j]))
427           {
428             /* Reg class I is a subclass of J.
429                Add J to the table of superclasses of I.  */
430             enum reg_class *p;
431
432             /* Add I to the table of superclasses of J.  */
433             p = &reg_class_subclasses[j][0];
434             while (*p != LIM_REG_CLASSES) p++;
435             *p = (enum reg_class) i;
436           }
437     }
438
439   /* Initialize "constant" tables.  */
440
441   CLEAR_HARD_REG_SET (fixed_reg_set);
442   CLEAR_HARD_REG_SET (call_used_reg_set);
443   CLEAR_HARD_REG_SET (call_fixed_reg_set);
444   CLEAR_HARD_REG_SET (regs_invalidated_by_call);
445   if (!regs_invalidated_by_call_regset)
446     {
447       bitmap_obstack_initialize (&persistent_obstack);
448       regs_invalidated_by_call_regset = ALLOC_REG_SET (&persistent_obstack);
449     }
450   else
451     CLEAR_REG_SET (regs_invalidated_by_call_regset);
452
453   for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
454     {
455       /* call_used_regs must include fixed_regs.  */
456       gcc_assert (!fixed_regs[i] || call_used_regs[i]);
457 #ifdef CALL_REALLY_USED_REGISTERS
458       /* call_used_regs must include call_really_used_regs.  */
459       gcc_assert (!call_really_used_regs[i] || call_used_regs[i]);
460 #endif
461
462       if (fixed_regs[i])
463         SET_HARD_REG_BIT (fixed_reg_set, i);
464
465       if (call_used_regs[i])
466         SET_HARD_REG_BIT (call_used_reg_set, i);
467
468       /* There are a couple of fixed registers that we know are safe to
469          exclude from being clobbered by calls:
470
471          The frame pointer is always preserved across calls.  The arg
472          pointer is if it is fixed.  The stack pointer usually is,
473          unless TARGET_RETURN_POPS_ARGS, in which case an explicit
474          CLOBBER will be present.  If we are generating PIC code, the
475          PIC offset table register is preserved across calls, though the
476          target can override that.  */
477
478       if (i == STACK_POINTER_REGNUM)
479         ;
480       else if (global_regs[i])
481         {
482           SET_HARD_REG_BIT (regs_invalidated_by_call, i);
483           SET_REGNO_REG_SET (regs_invalidated_by_call_regset, i);
484         }
485       else if (i == FRAME_POINTER_REGNUM)
486         ;
487 #if !HARD_FRAME_POINTER_IS_FRAME_POINTER
488       else if (i == HARD_FRAME_POINTER_REGNUM)
489         ;
490 #endif
491 #if ARG_POINTER_REGNUM != FRAME_POINTER_REGNUM
492       else if (i == ARG_POINTER_REGNUM && fixed_regs[i])
493         ;
494 #endif
495       else if (!PIC_OFFSET_TABLE_REG_CALL_CLOBBERED
496                && i == (unsigned) PIC_OFFSET_TABLE_REGNUM && fixed_regs[i])
497         ;
498       else if (CALL_REALLY_USED_REGNO_P (i))
499         {
500           SET_HARD_REG_BIT (regs_invalidated_by_call, i);
501           SET_REGNO_REG_SET (regs_invalidated_by_call_regset, i);
502         }
503     }
504
505   COPY_HARD_REG_SET(call_fixed_reg_set, fixed_reg_set);
506
507   /* Preserve global registers if called more than once.  */
508   for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
509     {
510       if (global_regs[i])
511         {
512           fixed_regs[i] = call_used_regs[i] = 1;
513           SET_HARD_REG_BIT (fixed_reg_set, i);
514           SET_HARD_REG_BIT (call_used_reg_set, i);
515           SET_HARD_REG_BIT (call_fixed_reg_set, i);
516         }
517     }
518
519   memset (have_regs_of_mode, 0, sizeof (have_regs_of_mode));
520   memset (contains_reg_of_mode, 0, sizeof (contains_reg_of_mode));
521   for (m = 0; m < (unsigned int) MAX_MACHINE_MODE; m++)
522     {
523       HARD_REG_SET ok_regs;
524       CLEAR_HARD_REG_SET (ok_regs);
525       for (j = 0; j < FIRST_PSEUDO_REGISTER; j++)
526         if (!fixed_regs [j] && HARD_REGNO_MODE_OK (j, (enum machine_mode) m))
527           SET_HARD_REG_BIT (ok_regs, j);
528
529       for (i = 0; i < N_REG_CLASSES; i++)
530         if (((unsigned) CLASS_MAX_NREGS ((enum reg_class) i,
531                                          (enum machine_mode) m)
532              <= reg_class_size[i])
533             && hard_reg_set_intersect_p (ok_regs, reg_class_contents[i]))
534           {
535              contains_reg_of_mode [i][m] = 1;
536              have_regs_of_mode [m] = 1;
537           }
538      }
539
540   /* Reset move_cost and friends, making sure we only free shared
541      table entries once.  */
542   for (i = 0; i < MAX_MACHINE_MODE; i++)
543     if (move_cost[i])
544       {
545         for (j = 0; j < i && move_cost[i] != move_cost[j]; j++)
546           ;
547         if (i == j)
548           {
549             free (move_cost[i]);
550             free (may_move_in_cost[i]);
551             free (may_move_out_cost[i]);
552           }
553       }
554   memset (move_cost, 0, sizeof move_cost);
555   memset (may_move_in_cost, 0, sizeof may_move_in_cost);
556   memset (may_move_out_cost, 0, sizeof may_move_out_cost);
557   last_mode_for_init_move_cost = -1;
558 }
559
560 /* Compute the table of register modes.
561    These values are used to record death information for individual registers
562    (as opposed to a multi-register mode).
563    This function might be invoked more than once, if the target has support
564    for changing register usage conventions on a per-function basis.
565 */
566 void
567 init_reg_modes_target (void)
568 {
569   int i, j;
570
571   for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
572     for (j = 0; j < MAX_MACHINE_MODE; j++)
573       hard_regno_nregs[i][j] = HARD_REGNO_NREGS(i, (enum machine_mode)j);
574
575   for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
576     {
577       reg_raw_mode[i] = choose_hard_reg_mode (i, 1, false);
578
579       /* If we couldn't find a valid mode, just use the previous mode.
580          ??? One situation in which we need to do this is on the mips where
581          HARD_REGNO_NREGS (fpreg, [SD]Fmode) returns 2.  Ideally we'd like
582          to use DF mode for the even registers and VOIDmode for the odd
583          (for the cpu models where the odd ones are inaccessible).  */
584       if (reg_raw_mode[i] == VOIDmode)
585         reg_raw_mode[i] = i == 0 ? word_mode : reg_raw_mode[i-1];
586     }
587 }
588
589 /* Finish initializing the register sets and initialize the register modes.
590    This function might be invoked more than once, if the target has support
591    for changing register usage conventions on a per-function basis.
592 */
593 void
594 init_regs (void)
595 {
596   /* This finishes what was started by init_reg_sets, but couldn't be done
597      until after register usage was specified.  */
598   init_reg_sets_1 ();
599 }
600
601 /* The same as previous function plus initializing IRA.  */
602 void
603 reinit_regs (void)
604 {
605   init_regs ();
606   /* caller_save needs to be re-initialized.  */
607   caller_save_initialized_p = false;
608   ira_init ();
609 }
610
611 /* Initialize some fake stack-frame MEM references for use in
612    memory_move_secondary_cost.  */
613 void
614 init_fake_stack_mems (void)
615 {
616   int i;
617
618   for (i = 0; i < MAX_MACHINE_MODE; i++)
619     top_of_stack[i] = gen_rtx_MEM ((enum machine_mode) i, stack_pointer_rtx);
620 }
621
622
623 /* Compute cost of moving data from a register of class FROM to one of
624    TO, using MODE.  */
625
626 int
627 register_move_cost (enum machine_mode mode, reg_class_t from, reg_class_t to)
628 {
629   return targetm.register_move_cost (mode, from, to);
630 }
631
632 /* Compute cost of moving registers to/from memory.  */
633 int
634 memory_move_cost (enum machine_mode mode, enum reg_class rclass, bool in)
635 {
636   return targetm.memory_move_cost (mode, rclass, in);
637 }
638
639 /* Compute extra cost of moving registers to/from memory due to reloads.
640    Only needed if secondary reloads are required for memory moves.  */
641 int
642 memory_move_secondary_cost (enum machine_mode mode, reg_class_t rclass,
643                             bool in)
644 {
645   reg_class_t altclass;
646   int partial_cost = 0;
647   /* We need a memory reference to feed to SECONDARY... macros.  */
648   /* mem may be unused even if the SECONDARY_ macros are defined.  */
649   rtx mem ATTRIBUTE_UNUSED = top_of_stack[(int) mode];
650
651   altclass = secondary_reload_class (in ? 1 : 0, rclass, mode, mem);
652
653   if (altclass == NO_REGS)
654     return 0;
655
656   if (in)
657     partial_cost = register_move_cost (mode, altclass, rclass);
658   else
659     partial_cost = register_move_cost (mode, rclass, altclass);
660
661   if (rclass == altclass)
662     /* This isn't simply a copy-to-temporary situation.  Can't guess
663        what it is, so TARGET_MEMORY_MOVE_COST really ought not to be
664        calling here in that case.
665
666        I'm tempted to put in an assert here, but returning this will
667        probably only give poor estimates, which is what we would've
668        had before this code anyways.  */
669     return partial_cost;
670
671   /* Check if the secondary reload register will also need a
672      secondary reload.  */
673   return memory_move_secondary_cost (mode, altclass, in) + partial_cost;
674 }
675
676 /* Return a machine mode that is legitimate for hard reg REGNO and large
677    enough to save nregs.  If we can't find one, return VOIDmode.
678    If CALL_SAVED is true, only consider modes that are call saved.  */
679 enum machine_mode
680 choose_hard_reg_mode (unsigned int regno ATTRIBUTE_UNUSED,
681                       unsigned int nregs, bool call_saved)
682 {
683   unsigned int /* enum machine_mode */ m;
684   enum machine_mode found_mode = VOIDmode, mode;
685
686   /* We first look for the largest integer mode that can be validly
687      held in REGNO.  If none, we look for the largest floating-point mode.
688      If we still didn't find a valid mode, try CCmode.  */
689
690   for (mode = GET_CLASS_NARROWEST_MODE (MODE_INT);
691        mode != VOIDmode;
692        mode = GET_MODE_WIDER_MODE (mode))
693     if ((unsigned) hard_regno_nregs[regno][mode] == nregs
694         && HARD_REGNO_MODE_OK (regno, mode)
695         && (! call_saved || ! HARD_REGNO_CALL_PART_CLOBBERED (regno, mode)))
696       found_mode = mode;
697
698   if (found_mode != VOIDmode)
699     return found_mode;
700
701   for (mode = GET_CLASS_NARROWEST_MODE (MODE_FLOAT);
702        mode != VOIDmode;
703        mode = GET_MODE_WIDER_MODE (mode))
704     if ((unsigned) hard_regno_nregs[regno][mode] == nregs
705         && HARD_REGNO_MODE_OK (regno, mode)
706         && (! call_saved || ! HARD_REGNO_CALL_PART_CLOBBERED (regno, mode)))
707       found_mode = mode;
708
709   if (found_mode != VOIDmode)
710     return found_mode;
711
712   for (mode = GET_CLASS_NARROWEST_MODE (MODE_VECTOR_FLOAT);
713        mode != VOIDmode;
714        mode = GET_MODE_WIDER_MODE (mode))
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       found_mode = mode;
719
720   if (found_mode != VOIDmode)
721     return found_mode;
722
723   for (mode = GET_CLASS_NARROWEST_MODE (MODE_VECTOR_INT);
724        mode != VOIDmode;
725        mode = GET_MODE_WIDER_MODE (mode))
726     if ((unsigned) hard_regno_nregs[regno][mode] == nregs
727         && HARD_REGNO_MODE_OK (regno, mode)
728         && (! call_saved || ! HARD_REGNO_CALL_PART_CLOBBERED (regno, mode)))
729       found_mode = mode;
730
731   if (found_mode != VOIDmode)
732     return found_mode;
733
734   /* Iterate over all of the CCmodes.  */
735   for (m = (unsigned int) CCmode; m < (unsigned int) NUM_MACHINE_MODES; ++m)
736     {
737       mode = (enum machine_mode) m;
738       if ((unsigned) hard_regno_nregs[regno][mode] == nregs
739           && HARD_REGNO_MODE_OK (regno, mode)
740           && (! call_saved || ! HARD_REGNO_CALL_PART_CLOBBERED (regno, mode)))
741         return mode;
742     }
743
744   /* We can't find a mode valid for this register.  */
745   return VOIDmode;
746 }
747
748 /* Specify the usage characteristics of the register named NAME.
749    It should be a fixed register if FIXED and a
750    call-used register if CALL_USED.  */
751 void
752 fix_register (const char *name, int fixed, int call_used)
753 {
754   int i;
755   int reg, nregs;
756
757   /* Decode the name and update the primary form of
758      the register info.  */
759
760   if ((reg = decode_reg_name_and_count (name, &nregs)) >= 0)
761     {
762       gcc_assert (nregs >= 1);
763       for (i = reg; i < reg + nregs; i++)
764         {
765           if ((i == STACK_POINTER_REGNUM
766 #ifdef HARD_FRAME_POINTER_REGNUM
767                || i == HARD_FRAME_POINTER_REGNUM
768 #else
769                || i == FRAME_POINTER_REGNUM
770 #endif
771                )
772               && (fixed == 0 || call_used == 0))
773             {
774               switch (fixed)
775                 {
776                 case 0:
777                   switch (call_used)
778                     {
779                     case 0:
780                       error ("can%'t use %qs as a call-saved register", name);
781                       break;
782
783                     case 1:
784                       error ("can%'t use %qs as a call-used register", name);
785                       break;
786
787                     default:
788                       gcc_unreachable ();
789                     }
790                   break;
791
792                 case 1:
793                   switch (call_used)
794                     {
795                     case 1:
796                       error ("can%'t use %qs as a fixed register", name);
797                       break;
798
799                     case 0:
800                     default:
801                       gcc_unreachable ();
802                     }
803                   break;
804
805                 default:
806                   gcc_unreachable ();
807                 }
808             }
809           else
810             {
811               fixed_regs[i] = fixed;
812               call_used_regs[i] = call_used;
813 #ifdef CALL_REALLY_USED_REGISTERS
814               if (fixed == 0)
815                 call_really_used_regs[i] = call_used;
816 #endif
817             }
818         }
819     }
820   else
821     {
822       warning (0, "unknown register name: %s", name);
823     }
824 }
825
826 /* Mark register number I as global.  */
827 void
828 globalize_reg (int i)
829 {
830 #ifdef STACK_REGS
831   if (IN_RANGE (i, FIRST_STACK_REG, LAST_STACK_REG))
832     {
833       error ("stack register used for global register variable");
834       return;
835     }
836 #endif
837
838   if (fixed_regs[i] == 0 && no_global_reg_vars)
839     error ("global register variable follows a function definition");
840
841   if (global_regs[i])
842     {
843       warning (0, "register used for two global register variables");
844       return;
845     }
846
847   if (call_used_regs[i] && ! fixed_regs[i])
848     warning (0, "call-clobbered register used for global register variable");
849
850   global_regs[i] = 1;
851
852   /* If we're globalizing the frame pointer, we need to set the
853      appropriate regs_invalidated_by_call bit, even if it's already
854      set in fixed_regs.  */
855   if (i != STACK_POINTER_REGNUM)
856     {
857       SET_HARD_REG_BIT (regs_invalidated_by_call, i);
858       SET_REGNO_REG_SET (regs_invalidated_by_call_regset, i);
859     }
860
861   /* If already fixed, nothing else to do.  */
862   if (fixed_regs[i])
863     return;
864
865   fixed_regs[i] = call_used_regs[i] = 1;
866 #ifdef CALL_REALLY_USED_REGISTERS
867   call_really_used_regs[i] = 1;
868 #endif
869
870   SET_HARD_REG_BIT (fixed_reg_set, i);
871   SET_HARD_REG_BIT (call_used_reg_set, i);
872   SET_HARD_REG_BIT (call_fixed_reg_set, i);
873
874   reinit_regs ();
875 }
876 \f
877
878 /* Structure used to record preferences of given pseudo.  */
879 struct reg_pref
880 {
881   /* (enum reg_class) prefclass is the preferred class.  May be
882      NO_REGS if no class is better than memory.  */
883   char prefclass;
884
885   /* altclass is a register class that we should use for allocating
886      pseudo if no register in the preferred class is available.
887      If no register in this class is available, memory is preferred.
888
889      It might appear to be more general to have a bitmask of classes here,
890      but since it is recommended that there be a class corresponding to the
891      union of most major pair of classes, that generality is not required.  */
892   char altclass;
893
894   /* coverclass is a register class that IRA uses for allocating
895      the pseudo.  */
896   char coverclass;
897 };
898
899 /* Record preferences of each pseudo.  This is available after RA is
900    run.  */
901 static struct reg_pref *reg_pref;
902
903 /* Current size of reg_info.  */
904 static int reg_info_size;
905
906 /* Return the reg_class in which pseudo reg number REGNO is best allocated.
907    This function is sometimes called before the info has been computed.
908    When that happens, just return GENERAL_REGS, which is innocuous.  */
909 enum reg_class
910 reg_preferred_class (int regno)
911 {
912   if (reg_pref == 0)
913     return GENERAL_REGS;
914
915   return (enum reg_class) reg_pref[regno].prefclass;
916 }
917
918 enum reg_class
919 reg_alternate_class (int regno)
920 {
921   if (reg_pref == 0)
922     return ALL_REGS;
923
924   return (enum reg_class) reg_pref[regno].altclass;
925 }
926
927 /* Return the reg_class which is used by IRA for its allocation.  */
928 enum reg_class
929 reg_cover_class (int regno)
930 {
931   if (reg_pref == 0)
932     return NO_REGS;
933
934   return (enum reg_class) reg_pref[regno].coverclass;
935 }
936
937 \f
938
939 /* Allocate space for reg info.  */
940 static void
941 allocate_reg_info (void)
942 {
943   reg_info_size = max_reg_num ();
944   gcc_assert (! reg_pref && ! reg_renumber);
945   reg_renumber = XNEWVEC (short, reg_info_size);
946   reg_pref = XCNEWVEC (struct reg_pref, reg_info_size);
947   memset (reg_renumber, -1, reg_info_size * sizeof (short));
948 }
949
950
951 /* Resize reg info. The new elements will be uninitialized.  Return
952    TRUE if new elements (for new pseudos) were added.  */
953 bool
954 resize_reg_info (void)
955 {
956   int old;
957
958   if (reg_pref == NULL)
959     {
960       allocate_reg_info ();
961       return true;
962     }
963   if (reg_info_size == max_reg_num ())
964     return false;
965   old = reg_info_size;
966   reg_info_size = max_reg_num ();
967   gcc_assert (reg_pref && reg_renumber);
968   reg_renumber = XRESIZEVEC (short, reg_renumber, reg_info_size);
969   reg_pref = XRESIZEVEC (struct reg_pref, reg_pref, reg_info_size);
970   memset (reg_pref + old, -1,
971           (reg_info_size - old) * sizeof (struct reg_pref));
972   memset (reg_renumber + old, -1, (reg_info_size - old) * sizeof (short));
973   return true;
974 }
975
976
977 /* Free up the space allocated by allocate_reg_info.  */
978 void
979 free_reg_info (void)
980 {
981   if (reg_pref)
982     {
983       free (reg_pref);
984       reg_pref = NULL;
985     }
986
987   if (reg_renumber)
988     {
989       free (reg_renumber);
990       reg_renumber = NULL;
991     }
992 }
993
994 /* Initialize some global data for this pass.  */
995 static unsigned int
996 reginfo_init (void)
997 {
998   if (df)
999     df_compute_regs_ever_live (true);
1000
1001   /* This prevents dump_flow_info from losing if called
1002      before reginfo is run.  */
1003   reg_pref = NULL;
1004   /* No more global register variables may be declared.  */
1005   no_global_reg_vars = 1;
1006   return 1;
1007 }
1008
1009 struct rtl_opt_pass pass_reginfo_init =
1010 {
1011  {
1012   RTL_PASS,
1013   "reginfo",                            /* name */
1014   NULL,                                 /* gate */
1015   reginfo_init,                         /* execute */
1016   NULL,                                 /* sub */
1017   NULL,                                 /* next */
1018   0,                                    /* static_pass_number */
1019   TV_NONE,                              /* tv_id */
1020   0,                                    /* properties_required */
1021   0,                                    /* properties_provided */
1022   0,                                    /* properties_destroyed */
1023   0,                                    /* todo_flags_start */
1024   0                                     /* todo_flags_finish */
1025  }
1026 };
1027
1028 \f
1029
1030 /* Set up preferred, alternate, and cover classes for REGNO as
1031    PREFCLASS, ALTCLASS, and COVERCLASS.  */
1032 void
1033 setup_reg_classes (int regno,
1034                    enum reg_class prefclass, enum reg_class altclass,
1035                    enum reg_class coverclass)
1036 {
1037   if (reg_pref == NULL)
1038     return;
1039   gcc_assert (reg_info_size == max_reg_num ());
1040   reg_pref[regno].prefclass = prefclass;
1041   reg_pref[regno].altclass = altclass;
1042   reg_pref[regno].coverclass = coverclass;
1043 }
1044
1045 \f
1046 /* This is the `regscan' pass of the compiler, run just before cse and
1047    again just before loop.  It finds the first and last use of each
1048    pseudo-register.  */
1049
1050 static void reg_scan_mark_refs (rtx, rtx);
1051
1052 void
1053 reg_scan (rtx f, unsigned int nregs ATTRIBUTE_UNUSED)
1054 {
1055   rtx insn;
1056
1057   timevar_push (TV_REG_SCAN);
1058
1059   for (insn = f; insn; insn = NEXT_INSN (insn))
1060     if (INSN_P (insn))
1061       {
1062         reg_scan_mark_refs (PATTERN (insn), insn);
1063         if (REG_NOTES (insn))
1064           reg_scan_mark_refs (REG_NOTES (insn), insn);
1065       }
1066
1067   timevar_pop (TV_REG_SCAN);
1068 }
1069
1070
1071 /* X is the expression to scan.  INSN is the insn it appears in.
1072    NOTE_FLAG is nonzero if X is from INSN's notes rather than its body.
1073    We should only record information for REGs with numbers
1074    greater than or equal to MIN_REGNO.  */
1075 static void
1076 reg_scan_mark_refs (rtx x, rtx insn)
1077 {
1078   enum rtx_code code;
1079   rtx dest;
1080   rtx note;
1081
1082   if (!x)
1083     return;
1084   code = GET_CODE (x);
1085   switch (code)
1086     {
1087     case CONST:
1088     case CONST_INT:
1089     case CONST_DOUBLE:
1090     case CONST_FIXED:
1091     case CONST_VECTOR:
1092     case CC0:
1093     case PC:
1094     case SYMBOL_REF:
1095     case LABEL_REF:
1096     case ADDR_VEC:
1097     case ADDR_DIFF_VEC:
1098     case REG:
1099       return;
1100
1101     case EXPR_LIST:
1102       if (XEXP (x, 0))
1103         reg_scan_mark_refs (XEXP (x, 0), insn);
1104       if (XEXP (x, 1))
1105         reg_scan_mark_refs (XEXP (x, 1), insn);
1106       break;
1107
1108     case INSN_LIST:
1109       if (XEXP (x, 1))
1110         reg_scan_mark_refs (XEXP (x, 1), insn);
1111       break;
1112
1113     case CLOBBER:
1114       if (MEM_P (XEXP (x, 0)))
1115         reg_scan_mark_refs (XEXP (XEXP (x, 0), 0), insn);
1116       break;
1117
1118     case SET:
1119       /* Count a set of the destination if it is a register.  */
1120       for (dest = SET_DEST (x);
1121            GET_CODE (dest) == SUBREG || GET_CODE (dest) == STRICT_LOW_PART
1122            || GET_CODE (dest) == ZERO_EXTEND;
1123            dest = XEXP (dest, 0))
1124         ;
1125
1126       /* If this is setting a pseudo from another pseudo or the sum of a
1127          pseudo and a constant integer and the other pseudo is known to be
1128          a pointer, set the destination to be a pointer as well.
1129
1130          Likewise if it is setting the destination from an address or from a
1131          value equivalent to an address or to the sum of an address and
1132          something else.
1133
1134          But don't do any of this if the pseudo corresponds to a user
1135          variable since it should have already been set as a pointer based
1136          on the type.  */
1137
1138       if (REG_P (SET_DEST (x))
1139           && REGNO (SET_DEST (x)) >= FIRST_PSEUDO_REGISTER
1140           /* If the destination pseudo is set more than once, then other
1141              sets might not be to a pointer value (consider access to a
1142              union in two threads of control in the presence of global
1143              optimizations).  So only set REG_POINTER on the destination
1144              pseudo if this is the only set of that pseudo.  */
1145           && DF_REG_DEF_COUNT (REGNO (SET_DEST (x))) == 1
1146           && ! REG_USERVAR_P (SET_DEST (x))
1147           && ! REG_POINTER (SET_DEST (x))
1148           && ((REG_P (SET_SRC (x))
1149                && REG_POINTER (SET_SRC (x)))
1150               || ((GET_CODE (SET_SRC (x)) == PLUS
1151                    || GET_CODE (SET_SRC (x)) == LO_SUM)
1152                   && CONST_INT_P (XEXP (SET_SRC (x), 1))
1153                   && REG_P (XEXP (SET_SRC (x), 0))
1154                   && REG_POINTER (XEXP (SET_SRC (x), 0)))
1155               || GET_CODE (SET_SRC (x)) == CONST
1156               || GET_CODE (SET_SRC (x)) == SYMBOL_REF
1157               || GET_CODE (SET_SRC (x)) == LABEL_REF
1158               || (GET_CODE (SET_SRC (x)) == HIGH
1159                   && (GET_CODE (XEXP (SET_SRC (x), 0)) == CONST
1160                       || GET_CODE (XEXP (SET_SRC (x), 0)) == SYMBOL_REF
1161                       || GET_CODE (XEXP (SET_SRC (x), 0)) == LABEL_REF))
1162               || ((GET_CODE (SET_SRC (x)) == PLUS
1163                    || GET_CODE (SET_SRC (x)) == LO_SUM)
1164                   && (GET_CODE (XEXP (SET_SRC (x), 1)) == CONST
1165                       || GET_CODE (XEXP (SET_SRC (x), 1)) == SYMBOL_REF
1166                       || GET_CODE (XEXP (SET_SRC (x), 1)) == LABEL_REF))
1167               || ((note = find_reg_note (insn, REG_EQUAL, 0)) != 0
1168                   && (GET_CODE (XEXP (note, 0)) == CONST
1169                       || GET_CODE (XEXP (note, 0)) == SYMBOL_REF
1170                       || GET_CODE (XEXP (note, 0)) == LABEL_REF))))
1171         REG_POINTER (SET_DEST (x)) = 1;
1172
1173       /* If this is setting a register from a register or from a simple
1174          conversion of a register, propagate REG_EXPR.  */
1175       if (REG_P (dest) && !REG_ATTRS (dest))
1176         {
1177           rtx src = SET_SRC (x);
1178
1179           while (GET_CODE (src) == SIGN_EXTEND
1180                  || GET_CODE (src) == ZERO_EXTEND
1181                  || GET_CODE (src) == TRUNCATE
1182                  || (GET_CODE (src) == SUBREG && subreg_lowpart_p (src)))
1183             src = XEXP (src, 0);
1184
1185           set_reg_attrs_from_value (dest, src);
1186         }
1187
1188       /* ... fall through ...  */
1189
1190     default:
1191       {
1192         const char *fmt = GET_RTX_FORMAT (code);
1193         int i;
1194         for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
1195           {
1196             if (fmt[i] == 'e')
1197               reg_scan_mark_refs (XEXP (x, i), insn);
1198             else if (fmt[i] == 'E' && XVEC (x, i) != 0)
1199               {
1200                 int j;
1201                 for (j = XVECLEN (x, i) - 1; j >= 0; j--)
1202                   reg_scan_mark_refs (XVECEXP (x, i, j), insn);
1203               }
1204           }
1205       }
1206     }
1207 }
1208 \f
1209
1210 /* Return nonzero if C1 is a subset of C2, i.e., if every register in C1
1211    is also in C2.  */
1212 int
1213 reg_class_subset_p (reg_class_t c1, reg_class_t c2)
1214 {
1215   return (c1 == c2
1216           || c2 == ALL_REGS
1217           || hard_reg_set_subset_p (reg_class_contents[(int) c1],
1218                                    reg_class_contents[(int) c2]));
1219 }
1220
1221 /* Return nonzero if there is a register that is in both C1 and C2.  */
1222 int
1223 reg_classes_intersect_p (reg_class_t c1, reg_class_t c2)
1224 {
1225   return (c1 == c2
1226           || c1 == ALL_REGS
1227           || c2 == ALL_REGS
1228           || hard_reg_set_intersect_p (reg_class_contents[(int) c1],
1229                                       reg_class_contents[(int) c2]));
1230 }
1231
1232 \f
1233
1234 /* Passes for keeping and updating info about modes of registers
1235    inside subregisters.  */
1236
1237 #ifdef CANNOT_CHANGE_MODE_CLASS
1238
1239 struct subregs_of_mode_node
1240 {
1241   unsigned int block;
1242   unsigned char modes[MAX_MACHINE_MODE];
1243 };
1244
1245 static htab_t subregs_of_mode;
1246
1247 static hashval_t
1248 som_hash (const void *x)
1249 {
1250   const struct subregs_of_mode_node *const a =
1251     (const struct subregs_of_mode_node *) x;
1252   return a->block;
1253 }
1254
1255 static int
1256 som_eq (const void *x, const void *y)
1257 {
1258   const struct subregs_of_mode_node *const a =
1259     (const struct subregs_of_mode_node *) x;
1260   const struct subregs_of_mode_node *const b =
1261     (const struct subregs_of_mode_node *) y;
1262   return a->block == b->block;
1263 }
1264
1265 static void
1266 record_subregs_of_mode (rtx subreg)
1267 {
1268   struct subregs_of_mode_node dummy, *node;
1269   enum machine_mode mode;
1270   unsigned int regno;
1271   void **slot;
1272
1273   if (!REG_P (SUBREG_REG (subreg)))
1274     return;
1275
1276   regno = REGNO (SUBREG_REG (subreg));
1277   mode = GET_MODE (subreg);
1278
1279   if (regno < FIRST_PSEUDO_REGISTER)
1280     return;
1281
1282   dummy.block = regno & -8;
1283   slot = htab_find_slot_with_hash (subregs_of_mode, &dummy,
1284                                    dummy.block, INSERT);
1285   node = (struct subregs_of_mode_node *) *slot;
1286   if (node == NULL)
1287     {
1288       node = XCNEW (struct subregs_of_mode_node);
1289       node->block = regno & -8;
1290       *slot = node;
1291     }
1292
1293   node->modes[mode] |= 1 << (regno & 7);
1294 }
1295
1296 /* Call record_subregs_of_mode for all the subregs in X.  */
1297 static void
1298 find_subregs_of_mode (rtx x)
1299 {
1300   enum rtx_code code = GET_CODE (x);
1301   const char * const fmt = GET_RTX_FORMAT (code);
1302   int i;
1303
1304   if (code == SUBREG)
1305     record_subregs_of_mode (x);
1306
1307   /* Time for some deep diving.  */
1308   for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
1309     {
1310       if (fmt[i] == 'e')
1311         find_subregs_of_mode (XEXP (x, i));
1312       else if (fmt[i] == 'E')
1313         {
1314           int j;
1315           for (j = XVECLEN (x, i) - 1; j >= 0; j--)
1316             find_subregs_of_mode (XVECEXP (x, i, j));
1317         }
1318     }
1319 }
1320
1321 void
1322 init_subregs_of_mode (void)
1323 {
1324   basic_block bb;
1325   rtx insn;
1326
1327   if (subregs_of_mode)
1328     htab_empty (subregs_of_mode);
1329   else
1330     subregs_of_mode = htab_create (100, som_hash, som_eq, free);
1331
1332   FOR_EACH_BB (bb)
1333     FOR_BB_INSNS (bb, insn)
1334     if (INSN_P (insn))
1335       find_subregs_of_mode (PATTERN (insn));
1336 }
1337
1338 /* Return 1 if REGNO has had an invalid mode change in CLASS from FROM
1339    mode.  */
1340 bool
1341 invalid_mode_change_p (unsigned int regno,
1342                        enum reg_class rclass ATTRIBUTE_UNUSED,
1343                        enum machine_mode from)
1344 {
1345   struct subregs_of_mode_node dummy, *node;
1346   unsigned int to;
1347   unsigned char mask;
1348
1349   gcc_assert (subregs_of_mode);
1350   dummy.block = regno & -8;
1351   node = (struct subregs_of_mode_node *)
1352     htab_find_with_hash (subregs_of_mode, &dummy, dummy.block);
1353   if (node == NULL)
1354     return false;
1355
1356   mask = 1 << (regno & 7);
1357   for (to = VOIDmode; to < NUM_MACHINE_MODES; to++)
1358     if (node->modes[to] & mask)
1359       if (CANNOT_CHANGE_MODE_CLASS (from, (enum machine_mode) to, rclass))
1360         return true;
1361
1362   return false;
1363 }
1364
1365 void
1366 finish_subregs_of_mode (void)
1367 {
1368   htab_delete (subregs_of_mode);
1369   subregs_of_mode = 0;
1370 }
1371 #else
1372 void
1373 init_subregs_of_mode (void)
1374 {
1375 }
1376 void
1377 finish_subregs_of_mode (void)
1378 {
1379 }
1380
1381 #endif /* CANNOT_CHANGE_MODE_CLASS */