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