OSDN Git Service

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