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