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