1 /* Compute different info about registers.
2 Copyright (C) 1987, 1988, 1991, 1992, 1993, 1994, 1995, 1996
3 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
4 2009, 2010 Free Software Foundation, Inc.
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 3, or (at your option) any later
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
23 /* This file contains regscan pass of the compiler and passes for
24 dealing with info about modes of pseudo-registers inside
25 subregisters. It also defines some tables of information about the
26 hardware registers, function init_reg_sets to initialize the
27 tables, and other auxiliary functions to deal with info about
28 registers and their classes. */
32 #include "coretypes.h"
34 #include "hard-reg-set.h"
39 #include "basic-block.h"
41 #include "addresses.h"
43 #include "insn-config.h"
46 #include "diagnostic-core.h"
51 #include "tree-pass.h"
55 /* Maximum register number used in this function, plus one. */
60 struct target_hard_regs default_target_hard_regs;
61 struct target_regs default_target_regs;
63 struct target_hard_regs *this_target_hard_regs = &default_target_hard_regs;
64 struct target_regs *this_target_regs = &default_target_regs;
67 /* Data for initializing fixed_regs. */
68 static const char initial_fixed_regs[] = FIXED_REGISTERS;
70 /* Data for initializing call_used_regs. */
71 static const char initial_call_used_regs[] = CALL_USED_REGISTERS;
73 #ifdef CALL_REALLY_USED_REGISTERS
74 /* Data for initializing call_really_used_regs. */
75 static const char initial_call_really_used_regs[] = CALL_REALLY_USED_REGISTERS;
78 #ifdef CALL_REALLY_USED_REGISTERS
79 #define CALL_REALLY_USED_REGNO_P(X) call_really_used_regs[X]
81 #define CALL_REALLY_USED_REGNO_P(X) call_used_regs[X]
84 /* Indexed by hard register number, contains 1 for registers
85 that are being used for global register decls.
86 These must be exempt from ordinary flow analysis
87 and are also considered fixed. */
88 char global_regs[FIRST_PSEUDO_REGISTER];
90 /* Declaration for the global register. */
91 static tree GTY(()) global_regs_decl[FIRST_PSEUDO_REGISTER];
93 /* Same information as REGS_INVALIDATED_BY_CALL but in regset form to be used
94 in dataflow more conveniently. */
95 regset regs_invalidated_by_call_regset;
97 /* The bitmap_obstack is used to hold some static variables that
98 should not be reset after each function is compiled. */
99 static bitmap_obstack persistent_obstack;
101 /* Used to initialize reg_alloc_order. */
102 #ifdef REG_ALLOC_ORDER
103 static int initial_reg_alloc_order[FIRST_PSEUDO_REGISTER] = REG_ALLOC_ORDER;
106 /* The same information, but as an array of unsigned ints. We copy from
107 these unsigned ints to the table above. We do this so the tm.h files
108 do not have to be aware of the wordsize for machines with <= 64 regs.
109 Note that we hard-code 32 here, not HOST_BITS_PER_INT. */
111 ((FIRST_PSEUDO_REGISTER + (32 - 1)) / 32)
113 static const unsigned int_reg_class_contents[N_REG_CLASSES][N_REG_INTS]
114 = REG_CLASS_CONTENTS;
116 /* Array containing all of the register names. */
117 static const char *const initial_reg_names[] = REGISTER_NAMES;
119 /* Array containing all of the register class names. */
120 const char * reg_class_names[] = REG_CLASS_NAMES;
122 #define last_mode_for_init_move_cost \
123 (this_target_regs->x_last_mode_for_init_move_cost)
125 /* No more global register variables may be declared; true once
126 reginfo has been initialized. */
127 static int no_global_reg_vars = 0;
129 /* Given a register bitmap, turn on the bits in a HARD_REG_SET that
130 correspond to the hard registers, if any, set in that map. This
131 could be done far more efficiently by having all sorts of special-cases
132 with moving single words, but probably isn't worth the trouble. */
134 reg_set_to_hard_reg_set (HARD_REG_SET *to, const_bitmap from)
139 EXECUTE_IF_SET_IN_BITMAP (from, 0, i, bi)
141 if (i >= FIRST_PSEUDO_REGISTER)
143 SET_HARD_REG_BIT (*to, i);
147 /* Function called only once per target_globals to initialize the
148 target_hard_regs structure. Once this is done, various switches
155 /* First copy the register information from the initial int form into
158 for (i = 0; i < N_REG_CLASSES; i++)
160 CLEAR_HARD_REG_SET (reg_class_contents[i]);
162 /* Note that we hard-code 32 here, not HOST_BITS_PER_INT. */
163 for (j = 0; j < FIRST_PSEUDO_REGISTER; j++)
164 if (int_reg_class_contents[i][j / 32]
165 & ((unsigned) 1 << (j % 32)))
166 SET_HARD_REG_BIT (reg_class_contents[i], j);
169 /* Sanity check: make sure the target macros FIXED_REGISTERS and
170 CALL_USED_REGISTERS had the right number of initializers. */
171 gcc_assert (sizeof fixed_regs == sizeof initial_fixed_regs);
172 gcc_assert (sizeof call_used_regs == sizeof initial_call_used_regs);
173 #ifdef CALL_REALLY_USED_REGISTERS
174 gcc_assert (sizeof call_really_used_regs
175 == sizeof initial_call_really_used_regs);
177 #ifdef REG_ALLOC_ORDER
178 gcc_assert (sizeof reg_alloc_order == sizeof initial_reg_alloc_order);
180 gcc_assert (sizeof reg_names == sizeof initial_reg_names);
182 memcpy (fixed_regs, initial_fixed_regs, sizeof fixed_regs);
183 memcpy (call_used_regs, initial_call_used_regs, sizeof call_used_regs);
184 #ifdef CALL_REALLY_USED_REGISTERS
185 memcpy (call_really_used_regs, initial_call_really_used_regs,
186 sizeof call_really_used_regs);
188 #ifdef REG_ALLOC_ORDER
189 memcpy (reg_alloc_order, initial_reg_alloc_order, sizeof reg_alloc_order);
191 memcpy (reg_names, initial_reg_names, sizeof reg_names);
194 /* Initialize may_move_cost and friends for mode M. */
196 init_move_cost (enum machine_mode m)
198 static unsigned short last_move_cost[N_REG_CLASSES][N_REG_CLASSES];
199 bool all_match = true;
202 gcc_assert (have_regs_of_mode[m]);
203 for (i = 0; i < N_REG_CLASSES; i++)
204 if (contains_reg_of_mode[i][m])
205 for (j = 0; j < N_REG_CLASSES; j++)
208 if (!contains_reg_of_mode[j][m])
212 cost = register_move_cost (m, (enum reg_class) i,
214 gcc_assert (cost < 65535);
216 all_match &= (last_move_cost[i][j] == cost);
217 last_move_cost[i][j] = cost;
219 if (all_match && last_mode_for_init_move_cost != -1)
221 move_cost[m] = move_cost[last_mode_for_init_move_cost];
222 may_move_in_cost[m] = may_move_in_cost[last_mode_for_init_move_cost];
223 may_move_out_cost[m] = may_move_out_cost[last_mode_for_init_move_cost];
226 last_mode_for_init_move_cost = m;
227 move_cost[m] = (move_table *)xmalloc (sizeof (move_table)
229 may_move_in_cost[m] = (move_table *)xmalloc (sizeof (move_table)
231 may_move_out_cost[m] = (move_table *)xmalloc (sizeof (move_table)
233 for (i = 0; i < N_REG_CLASSES; i++)
234 if (contains_reg_of_mode[i][m])
235 for (j = 0; j < N_REG_CLASSES; j++)
238 enum reg_class *p1, *p2;
240 if (last_move_cost[i][j] == 65535)
242 move_cost[m][i][j] = 65535;
243 may_move_in_cost[m][i][j] = 65535;
244 may_move_out_cost[m][i][j] = 65535;
248 cost = last_move_cost[i][j];
250 for (p2 = ®_class_subclasses[j][0];
251 *p2 != LIM_REG_CLASSES; p2++)
252 if (*p2 != i && contains_reg_of_mode[*p2][m])
253 cost = MAX (cost, move_cost[m][i][*p2]);
255 for (p1 = ®_class_subclasses[i][0];
256 *p1 != LIM_REG_CLASSES; p1++)
257 if (*p1 != j && contains_reg_of_mode[*p1][m])
258 cost = MAX (cost, move_cost[m][*p1][j]);
260 gcc_assert (cost <= 65535);
261 move_cost[m][i][j] = cost;
263 if (reg_class_subset_p ((enum reg_class) i, (enum reg_class) j))
264 may_move_in_cost[m][i][j] = 0;
266 may_move_in_cost[m][i][j] = cost;
268 if (reg_class_subset_p ((enum reg_class) j, (enum reg_class) i))
269 may_move_out_cost[m][i][j] = 0;
271 may_move_out_cost[m][i][j] = cost;
275 for (j = 0; j < N_REG_CLASSES; j++)
277 move_cost[m][i][j] = 65535;
278 may_move_in_cost[m][i][j] = 65535;
279 may_move_out_cost[m][i][j] = 65535;
283 /* We need to save copies of some of the register information which
284 can be munged by command-line switches so we can restore it during
285 subsequent back-end reinitialization. */
286 static char saved_fixed_regs[FIRST_PSEUDO_REGISTER];
287 static char saved_call_used_regs[FIRST_PSEUDO_REGISTER];
288 #ifdef CALL_REALLY_USED_REGISTERS
289 static char saved_call_really_used_regs[FIRST_PSEUDO_REGISTER];
291 static const char *saved_reg_names[FIRST_PSEUDO_REGISTER];
293 /* Save the register information. */
295 save_register_info (void)
297 /* Sanity check: make sure the target macros FIXED_REGISTERS and
298 CALL_USED_REGISTERS had the right number of initializers. */
299 gcc_assert (sizeof fixed_regs == sizeof saved_fixed_regs);
300 gcc_assert (sizeof call_used_regs == sizeof saved_call_used_regs);
301 memcpy (saved_fixed_regs, fixed_regs, sizeof fixed_regs);
302 memcpy (saved_call_used_regs, call_used_regs, sizeof call_used_regs);
304 /* Likewise for call_really_used_regs. */
305 #ifdef CALL_REALLY_USED_REGISTERS
306 gcc_assert (sizeof call_really_used_regs
307 == sizeof saved_call_really_used_regs);
308 memcpy (saved_call_really_used_regs, call_really_used_regs,
309 sizeof call_really_used_regs);
312 /* And similarly for reg_names. */
313 gcc_assert (sizeof reg_names == sizeof saved_reg_names);
314 memcpy (saved_reg_names, reg_names, sizeof reg_names);
317 /* Restore the register information. */
319 restore_register_info (void)
321 memcpy (fixed_regs, saved_fixed_regs, sizeof fixed_regs);
322 memcpy (call_used_regs, saved_call_used_regs, sizeof call_used_regs);
324 #ifdef CALL_REALLY_USED_REGISTERS
325 memcpy (call_really_used_regs, saved_call_really_used_regs,
326 sizeof call_really_used_regs);
329 memcpy (reg_names, saved_reg_names, sizeof reg_names);
332 /* After switches have been processed, which perhaps alter
333 `fixed_regs' and `call_used_regs', convert them to HARD_REG_SETs. */
335 init_reg_sets_1 (void)
338 unsigned int /* enum machine_mode */ m;
340 restore_register_info ();
342 #ifdef REG_ALLOC_ORDER
343 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
344 inv_reg_alloc_order[reg_alloc_order[i]] = i;
347 /* Let the target tweak things if necessary. */
349 targetm.conditional_register_usage ();
351 /* Compute number of hard regs in each class. */
353 memset (reg_class_size, 0, sizeof reg_class_size);
354 for (i = 0; i < N_REG_CLASSES; i++)
356 bool any_nonfixed = false;
357 for (j = 0; j < FIRST_PSEUDO_REGISTER; j++)
358 if (TEST_HARD_REG_BIT (reg_class_contents[i], j))
364 class_only_fixed_regs[i] = !any_nonfixed;
367 /* Initialize the table of subunions.
368 reg_class_subunion[I][J] gets the largest-numbered reg-class
369 that is contained in the union of classes I and J. */
371 memset (reg_class_subunion, 0, sizeof reg_class_subunion);
372 for (i = 0; i < N_REG_CLASSES; i++)
374 for (j = 0; j < N_REG_CLASSES; j++)
379 COPY_HARD_REG_SET (c, reg_class_contents[i]);
380 IOR_HARD_REG_SET (c, reg_class_contents[j]);
381 for (k = 0; k < N_REG_CLASSES; k++)
382 if (hard_reg_set_subset_p (reg_class_contents[k], c)
383 && !hard_reg_set_subset_p (reg_class_contents[k],
385 [(int) reg_class_subunion[i][j]]))
386 reg_class_subunion[i][j] = (enum reg_class) k;
390 /* Initialize the table of superunions.
391 reg_class_superunion[I][J] gets the smallest-numbered reg-class
392 containing the union of classes I and J. */
394 memset (reg_class_superunion, 0, sizeof reg_class_superunion);
395 for (i = 0; i < N_REG_CLASSES; i++)
397 for (j = 0; j < N_REG_CLASSES; j++)
402 COPY_HARD_REG_SET (c, reg_class_contents[i]);
403 IOR_HARD_REG_SET (c, reg_class_contents[j]);
404 for (k = 0; k < N_REG_CLASSES; k++)
405 if (hard_reg_set_subset_p (c, reg_class_contents[k]))
408 reg_class_superunion[i][j] = (enum reg_class) k;
412 /* Initialize the tables of subclasses and superclasses of each reg class.
413 First clear the whole table, then add the elements as they are found. */
415 for (i = 0; i < N_REG_CLASSES; i++)
417 for (j = 0; j < N_REG_CLASSES; j++)
418 reg_class_subclasses[i][j] = LIM_REG_CLASSES;
421 for (i = 0; i < N_REG_CLASSES; i++)
423 if (i == (int) NO_REGS)
426 for (j = i + 1; j < N_REG_CLASSES; j++)
427 if (hard_reg_set_subset_p (reg_class_contents[i],
428 reg_class_contents[j]))
430 /* Reg class I is a subclass of J.
431 Add J to the table of superclasses of I. */
434 /* Add I to the table of superclasses of J. */
435 p = ®_class_subclasses[j][0];
436 while (*p != LIM_REG_CLASSES) p++;
437 *p = (enum reg_class) i;
441 /* Initialize "constant" tables. */
443 CLEAR_HARD_REG_SET (fixed_reg_set);
444 CLEAR_HARD_REG_SET (call_used_reg_set);
445 CLEAR_HARD_REG_SET (call_fixed_reg_set);
446 CLEAR_HARD_REG_SET (regs_invalidated_by_call);
447 if (!regs_invalidated_by_call_regset)
449 bitmap_obstack_initialize (&persistent_obstack);
450 regs_invalidated_by_call_regset = ALLOC_REG_SET (&persistent_obstack);
453 CLEAR_REG_SET (regs_invalidated_by_call_regset);
455 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
457 /* call_used_regs must include fixed_regs. */
458 gcc_assert (!fixed_regs[i] || call_used_regs[i]);
459 #ifdef CALL_REALLY_USED_REGISTERS
460 /* call_used_regs must include call_really_used_regs. */
461 gcc_assert (!call_really_used_regs[i] || call_used_regs[i]);
465 SET_HARD_REG_BIT (fixed_reg_set, i);
467 if (call_used_regs[i])
468 SET_HARD_REG_BIT (call_used_reg_set, i);
470 /* There are a couple of fixed registers that we know are safe to
471 exclude from being clobbered by calls:
473 The frame pointer is always preserved across calls. The arg
474 pointer is if it is fixed. The stack pointer usually is,
475 unless TARGET_RETURN_POPS_ARGS, in which case an explicit
476 CLOBBER will be present. If we are generating PIC code, the
477 PIC offset table register is preserved across calls, though the
478 target can override that. */
480 if (i == STACK_POINTER_REGNUM)
482 else if (global_regs[i])
484 SET_HARD_REG_BIT (regs_invalidated_by_call, i);
485 SET_REGNO_REG_SET (regs_invalidated_by_call_regset, i);
487 else if (i == FRAME_POINTER_REGNUM)
489 #if !HARD_FRAME_POINTER_IS_FRAME_POINTER
490 else if (i == HARD_FRAME_POINTER_REGNUM)
493 #if ARG_POINTER_REGNUM != FRAME_POINTER_REGNUM
494 else if (i == ARG_POINTER_REGNUM && fixed_regs[i])
497 else if (!PIC_OFFSET_TABLE_REG_CALL_CLOBBERED
498 && i == (unsigned) PIC_OFFSET_TABLE_REGNUM && fixed_regs[i])
500 else if (CALL_REALLY_USED_REGNO_P (i))
502 SET_HARD_REG_BIT (regs_invalidated_by_call, i);
503 SET_REGNO_REG_SET (regs_invalidated_by_call_regset, i);
507 COPY_HARD_REG_SET(call_fixed_reg_set, fixed_reg_set);
509 /* Preserve global registers if called more than once. */
510 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
514 fixed_regs[i] = call_used_regs[i] = 1;
515 SET_HARD_REG_BIT (fixed_reg_set, i);
516 SET_HARD_REG_BIT (call_used_reg_set, i);
517 SET_HARD_REG_BIT (call_fixed_reg_set, i);
521 memset (have_regs_of_mode, 0, sizeof (have_regs_of_mode));
522 memset (contains_reg_of_mode, 0, sizeof (contains_reg_of_mode));
523 for (m = 0; m < (unsigned int) MAX_MACHINE_MODE; m++)
525 HARD_REG_SET ok_regs;
526 CLEAR_HARD_REG_SET (ok_regs);
527 for (j = 0; j < FIRST_PSEUDO_REGISTER; j++)
528 if (!fixed_regs [j] && HARD_REGNO_MODE_OK (j, (enum machine_mode) m))
529 SET_HARD_REG_BIT (ok_regs, j);
531 for (i = 0; i < N_REG_CLASSES; i++)
532 if (((unsigned) CLASS_MAX_NREGS ((enum reg_class) i,
533 (enum machine_mode) m)
534 <= reg_class_size[i])
535 && hard_reg_set_intersect_p (ok_regs, reg_class_contents[i]))
537 contains_reg_of_mode [i][m] = 1;
538 have_regs_of_mode [m] = 1;
542 /* Reset move_cost and friends, making sure we only free shared
543 table entries once. */
544 for (i = 0; i < MAX_MACHINE_MODE; i++)
547 for (j = 0; j < i && move_cost[i] != move_cost[j]; j++)
552 free (may_move_in_cost[i]);
553 free (may_move_out_cost[i]);
556 memset (move_cost, 0, sizeof move_cost);
557 memset (may_move_in_cost, 0, sizeof may_move_in_cost);
558 memset (may_move_out_cost, 0, sizeof may_move_out_cost);
559 last_mode_for_init_move_cost = -1;
562 /* Compute the table of register modes.
563 These values are used to record death information for individual registers
564 (as opposed to a multi-register mode).
565 This function might be invoked more than once, if the target has support
566 for changing register usage conventions on a per-function basis.
569 init_reg_modes_target (void)
573 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
574 for (j = 0; j < MAX_MACHINE_MODE; j++)
575 hard_regno_nregs[i][j] = HARD_REGNO_NREGS(i, (enum machine_mode)j);
577 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
579 reg_raw_mode[i] = choose_hard_reg_mode (i, 1, false);
581 /* If we couldn't find a valid mode, just use the previous mode.
582 ??? One situation in which we need to do this is on the mips where
583 HARD_REGNO_NREGS (fpreg, [SD]Fmode) returns 2. Ideally we'd like
584 to use DF mode for the even registers and VOIDmode for the odd
585 (for the cpu models where the odd ones are inaccessible). */
586 if (reg_raw_mode[i] == VOIDmode)
587 reg_raw_mode[i] = i == 0 ? word_mode : reg_raw_mode[i-1];
591 /* Finish initializing the register sets and initialize the register modes.
592 This function might be invoked more than once, if the target has support
593 for changing register usage conventions on a per-function basis.
598 /* This finishes what was started by init_reg_sets, but couldn't be done
599 until after register usage was specified. */
603 /* The same as previous function plus initializing IRA. */
608 /* caller_save needs to be re-initialized. */
609 caller_save_initialized_p = false;
613 /* Initialize some fake stack-frame MEM references for use in
614 memory_move_secondary_cost. */
616 init_fake_stack_mems (void)
620 for (i = 0; i < MAX_MACHINE_MODE; i++)
621 top_of_stack[i] = gen_rtx_MEM ((enum machine_mode) i, stack_pointer_rtx);
625 /* Compute cost of moving data from a register of class FROM to one of
629 register_move_cost (enum machine_mode mode, reg_class_t from, reg_class_t to)
631 return targetm.register_move_cost (mode, from, to);
634 /* Compute cost of moving registers to/from memory. */
637 memory_move_cost (enum machine_mode mode, reg_class_t rclass, bool in)
639 return targetm.memory_move_cost (mode, rclass, in);
642 /* Compute extra cost of moving registers to/from memory due to reloads.
643 Only needed if secondary reloads are required for memory moves. */
645 memory_move_secondary_cost (enum machine_mode mode, reg_class_t rclass,
648 reg_class_t altclass;
649 int partial_cost = 0;
650 /* We need a memory reference to feed to SECONDARY... macros. */
651 /* mem may be unused even if the SECONDARY_ macros are defined. */
652 rtx mem ATTRIBUTE_UNUSED = top_of_stack[(int) mode];
654 altclass = secondary_reload_class (in ? 1 : 0, rclass, mode, mem);
656 if (altclass == NO_REGS)
660 partial_cost = register_move_cost (mode, altclass, rclass);
662 partial_cost = register_move_cost (mode, rclass, altclass);
664 if (rclass == altclass)
665 /* This isn't simply a copy-to-temporary situation. Can't guess
666 what it is, so TARGET_MEMORY_MOVE_COST really ought not to be
667 calling here in that case.
669 I'm tempted to put in an assert here, but returning this will
670 probably only give poor estimates, which is what we would've
671 had before this code anyways. */
674 /* Check if the secondary reload register will also need a
676 return memory_move_secondary_cost (mode, altclass, in) + partial_cost;
679 /* Return a machine mode that is legitimate for hard reg REGNO and large
680 enough to save nregs. If we can't find one, return VOIDmode.
681 If CALL_SAVED is true, only consider modes that are call saved. */
683 choose_hard_reg_mode (unsigned int regno ATTRIBUTE_UNUSED,
684 unsigned int nregs, bool call_saved)
686 unsigned int /* enum machine_mode */ m;
687 enum machine_mode found_mode = VOIDmode, mode;
689 /* We first look for the largest integer mode that can be validly
690 held in REGNO. If none, we look for the largest floating-point mode.
691 If we still didn't find a valid mode, try CCmode. */
693 for (mode = GET_CLASS_NARROWEST_MODE (MODE_INT);
695 mode = GET_MODE_WIDER_MODE (mode))
696 if ((unsigned) hard_regno_nregs[regno][mode] == nregs
697 && HARD_REGNO_MODE_OK (regno, mode)
698 && (! call_saved || ! HARD_REGNO_CALL_PART_CLOBBERED (regno, mode)))
701 if (found_mode != VOIDmode)
704 for (mode = GET_CLASS_NARROWEST_MODE (MODE_FLOAT);
706 mode = GET_MODE_WIDER_MODE (mode))
707 if ((unsigned) hard_regno_nregs[regno][mode] == nregs
708 && HARD_REGNO_MODE_OK (regno, mode)
709 && (! call_saved || ! HARD_REGNO_CALL_PART_CLOBBERED (regno, mode)))
712 if (found_mode != VOIDmode)
715 for (mode = GET_CLASS_NARROWEST_MODE (MODE_VECTOR_FLOAT);
717 mode = GET_MODE_WIDER_MODE (mode))
718 if ((unsigned) hard_regno_nregs[regno][mode] == nregs
719 && HARD_REGNO_MODE_OK (regno, mode)
720 && (! call_saved || ! HARD_REGNO_CALL_PART_CLOBBERED (regno, mode)))
723 if (found_mode != VOIDmode)
726 for (mode = GET_CLASS_NARROWEST_MODE (MODE_VECTOR_INT);
728 mode = GET_MODE_WIDER_MODE (mode))
729 if ((unsigned) hard_regno_nregs[regno][mode] == nregs
730 && HARD_REGNO_MODE_OK (regno, mode)
731 && (! call_saved || ! HARD_REGNO_CALL_PART_CLOBBERED (regno, mode)))
734 if (found_mode != VOIDmode)
737 /* Iterate over all of the CCmodes. */
738 for (m = (unsigned int) CCmode; m < (unsigned int) NUM_MACHINE_MODES; ++m)
740 mode = (enum machine_mode) m;
741 if ((unsigned) hard_regno_nregs[regno][mode] == nregs
742 && HARD_REGNO_MODE_OK (regno, mode)
743 && (! call_saved || ! HARD_REGNO_CALL_PART_CLOBBERED (regno, mode)))
747 /* We can't find a mode valid for this register. */
751 /* Specify the usage characteristics of the register named NAME.
752 It should be a fixed register if FIXED and a
753 call-used register if CALL_USED. */
755 fix_register (const char *name, int fixed, int call_used)
760 /* Decode the name and update the primary form of
761 the register info. */
763 if ((reg = decode_reg_name_and_count (name, &nregs)) >= 0)
765 gcc_assert (nregs >= 1);
766 for (i = reg; i < reg + nregs; i++)
768 if ((i == STACK_POINTER_REGNUM
769 #ifdef HARD_FRAME_POINTER_REGNUM
770 || i == HARD_FRAME_POINTER_REGNUM
772 || i == FRAME_POINTER_REGNUM
775 && (fixed == 0 || call_used == 0))
783 error ("can%'t use %qs as a call-saved register", name);
787 error ("can%'t use %qs as a call-used register", name);
799 error ("can%'t use %qs as a fixed register", name);
814 fixed_regs[i] = fixed;
815 call_used_regs[i] = call_used;
816 #ifdef CALL_REALLY_USED_REGISTERS
818 call_really_used_regs[i] = call_used;
825 warning (0, "unknown register name: %s", name);
829 /* Mark register number I as global. */
831 globalize_reg (tree decl, int i)
833 location_t loc = DECL_SOURCE_LOCATION (decl);
836 if (IN_RANGE (i, FIRST_STACK_REG, LAST_STACK_REG))
838 error ("stack register used for global register variable");
843 if (fixed_regs[i] == 0 && no_global_reg_vars)
844 error_at (loc, "global register variable follows a function definition");
849 "register of %qD used for multiple global register variables",
851 inform (DECL_SOURCE_LOCATION (global_regs_decl[i]),
852 "conflicts with %qD", global_regs_decl[i]);
856 if (call_used_regs[i] && ! fixed_regs[i])
857 warning_at (loc, 0, "call-clobbered register used for global register variable");
860 global_regs_decl[i] = decl;
862 /* If we're globalizing the frame pointer, we need to set the
863 appropriate regs_invalidated_by_call bit, even if it's already
864 set in fixed_regs. */
865 if (i != STACK_POINTER_REGNUM)
867 SET_HARD_REG_BIT (regs_invalidated_by_call, i);
868 SET_REGNO_REG_SET (regs_invalidated_by_call_regset, i);
871 /* If already fixed, nothing else to do. */
875 fixed_regs[i] = call_used_regs[i] = 1;
876 #ifdef CALL_REALLY_USED_REGISTERS
877 call_really_used_regs[i] = 1;
880 SET_HARD_REG_BIT (fixed_reg_set, i);
881 SET_HARD_REG_BIT (call_used_reg_set, i);
882 SET_HARD_REG_BIT (call_fixed_reg_set, i);
888 /* Structure used to record preferences of given pseudo. */
891 /* (enum reg_class) prefclass is the preferred class. May be
892 NO_REGS if no class is better than memory. */
895 /* altclass is a register class that we should use for allocating
896 pseudo if no register in the preferred class is available.
897 If no register in this class is available, memory is preferred.
899 It might appear to be more general to have a bitmask of classes here,
900 but since it is recommended that there be a class corresponding to the
901 union of most major pair of classes, that generality is not required. */
904 /* allocnoclass is a register class that IRA uses for allocating
909 /* Record preferences of each pseudo. This is available after RA is
911 static struct reg_pref *reg_pref;
913 /* Current size of reg_info. */
914 static int reg_info_size;
916 /* Return the reg_class in which pseudo reg number REGNO is best allocated.
917 This function is sometimes called before the info has been computed.
918 When that happens, just return GENERAL_REGS, which is innocuous. */
920 reg_preferred_class (int regno)
925 return (enum reg_class) reg_pref[regno].prefclass;
929 reg_alternate_class (int regno)
934 return (enum reg_class) reg_pref[regno].altclass;
937 /* Return the reg_class which is used by IRA for its allocation. */
939 reg_allocno_class (int regno)
944 return (enum reg_class) reg_pref[regno].allocnoclass;
949 /* Allocate space for reg info. */
951 allocate_reg_info (void)
953 reg_info_size = max_reg_num ();
954 gcc_assert (! reg_pref && ! reg_renumber);
955 reg_renumber = XNEWVEC (short, reg_info_size);
956 reg_pref = XCNEWVEC (struct reg_pref, reg_info_size);
957 memset (reg_renumber, -1, reg_info_size * sizeof (short));
961 /* Resize reg info. The new elements will be uninitialized. Return
962 TRUE if new elements (for new pseudos) were added. */
964 resize_reg_info (void)
968 if (reg_pref == NULL)
970 allocate_reg_info ();
973 if (reg_info_size == max_reg_num ())
976 reg_info_size = max_reg_num ();
977 gcc_assert (reg_pref && reg_renumber);
978 reg_renumber = XRESIZEVEC (short, reg_renumber, reg_info_size);
979 reg_pref = XRESIZEVEC (struct reg_pref, reg_pref, reg_info_size);
980 memset (reg_pref + old, -1,
981 (reg_info_size - old) * sizeof (struct reg_pref));
982 memset (reg_renumber + old, -1, (reg_info_size - old) * sizeof (short));
987 /* Free up the space allocated by allocate_reg_info. */
1000 reg_renumber = NULL;
1004 /* Initialize some global data for this pass. */
1009 df_compute_regs_ever_live (true);
1011 /* This prevents dump_flow_info from losing if called
1012 before reginfo is run. */
1014 /* No more global register variables may be declared. */
1015 no_global_reg_vars = 1;
1019 struct rtl_opt_pass pass_reginfo_init =
1023 "reginfo", /* name */
1025 reginfo_init, /* execute */
1028 0, /* static_pass_number */
1029 TV_NONE, /* tv_id */
1030 0, /* properties_required */
1031 0, /* properties_provided */
1032 0, /* properties_destroyed */
1033 0, /* todo_flags_start */
1034 0 /* todo_flags_finish */
1040 /* Set up preferred, alternate, and cover classes for REGNO as
1041 PREFCLASS, ALTCLASS, and ALLOCNOCLASS. */
1043 setup_reg_classes (int regno,
1044 enum reg_class prefclass, enum reg_class altclass,
1045 enum reg_class allocnoclass)
1047 if (reg_pref == NULL)
1049 gcc_assert (reg_info_size == max_reg_num ());
1050 reg_pref[regno].prefclass = prefclass;
1051 reg_pref[regno].altclass = altclass;
1052 reg_pref[regno].allocnoclass = allocnoclass;
1056 /* This is the `regscan' pass of the compiler, run just before cse and
1057 again just before loop. It finds the first and last use of each
1060 static void reg_scan_mark_refs (rtx, rtx);
1063 reg_scan (rtx f, unsigned int nregs ATTRIBUTE_UNUSED)
1067 timevar_push (TV_REG_SCAN);
1069 for (insn = f; insn; insn = NEXT_INSN (insn))
1072 reg_scan_mark_refs (PATTERN (insn), insn);
1073 if (REG_NOTES (insn))
1074 reg_scan_mark_refs (REG_NOTES (insn), insn);
1077 timevar_pop (TV_REG_SCAN);
1081 /* X is the expression to scan. INSN is the insn it appears in.
1082 NOTE_FLAG is nonzero if X is from INSN's notes rather than its body.
1083 We should only record information for REGs with numbers
1084 greater than or equal to MIN_REGNO. */
1086 reg_scan_mark_refs (rtx x, rtx insn)
1094 code = GET_CODE (x);
1113 reg_scan_mark_refs (XEXP (x, 0), insn);
1115 reg_scan_mark_refs (XEXP (x, 1), insn);
1120 reg_scan_mark_refs (XEXP (x, 1), insn);
1124 if (MEM_P (XEXP (x, 0)))
1125 reg_scan_mark_refs (XEXP (XEXP (x, 0), 0), insn);
1129 /* Count a set of the destination if it is a register. */
1130 for (dest = SET_DEST (x);
1131 GET_CODE (dest) == SUBREG || GET_CODE (dest) == STRICT_LOW_PART
1132 || GET_CODE (dest) == ZERO_EXTEND;
1133 dest = XEXP (dest, 0))
1136 /* If this is setting a pseudo from another pseudo or the sum of a
1137 pseudo and a constant integer and the other pseudo is known to be
1138 a pointer, set the destination to be a pointer as well.
1140 Likewise if it is setting the destination from an address or from a
1141 value equivalent to an address or to the sum of an address and
1144 But don't do any of this if the pseudo corresponds to a user
1145 variable since it should have already been set as a pointer based
1148 if (REG_P (SET_DEST (x))
1149 && REGNO (SET_DEST (x)) >= FIRST_PSEUDO_REGISTER
1150 /* If the destination pseudo is set more than once, then other
1151 sets might not be to a pointer value (consider access to a
1152 union in two threads of control in the presence of global
1153 optimizations). So only set REG_POINTER on the destination
1154 pseudo if this is the only set of that pseudo. */
1155 && DF_REG_DEF_COUNT (REGNO (SET_DEST (x))) == 1
1156 && ! REG_USERVAR_P (SET_DEST (x))
1157 && ! REG_POINTER (SET_DEST (x))
1158 && ((REG_P (SET_SRC (x))
1159 && REG_POINTER (SET_SRC (x)))
1160 || ((GET_CODE (SET_SRC (x)) == PLUS
1161 || GET_CODE (SET_SRC (x)) == LO_SUM)
1162 && CONST_INT_P (XEXP (SET_SRC (x), 1))
1163 && REG_P (XEXP (SET_SRC (x), 0))
1164 && REG_POINTER (XEXP (SET_SRC (x), 0)))
1165 || GET_CODE (SET_SRC (x)) == CONST
1166 || GET_CODE (SET_SRC (x)) == SYMBOL_REF
1167 || GET_CODE (SET_SRC (x)) == LABEL_REF
1168 || (GET_CODE (SET_SRC (x)) == HIGH
1169 && (GET_CODE (XEXP (SET_SRC (x), 0)) == CONST
1170 || GET_CODE (XEXP (SET_SRC (x), 0)) == SYMBOL_REF
1171 || GET_CODE (XEXP (SET_SRC (x), 0)) == LABEL_REF))
1172 || ((GET_CODE (SET_SRC (x)) == PLUS
1173 || GET_CODE (SET_SRC (x)) == LO_SUM)
1174 && (GET_CODE (XEXP (SET_SRC (x), 1)) == CONST
1175 || GET_CODE (XEXP (SET_SRC (x), 1)) == SYMBOL_REF
1176 || GET_CODE (XEXP (SET_SRC (x), 1)) == LABEL_REF))
1177 || ((note = find_reg_note (insn, REG_EQUAL, 0)) != 0
1178 && (GET_CODE (XEXP (note, 0)) == CONST
1179 || GET_CODE (XEXP (note, 0)) == SYMBOL_REF
1180 || GET_CODE (XEXP (note, 0)) == LABEL_REF))))
1181 REG_POINTER (SET_DEST (x)) = 1;
1183 /* If this is setting a register from a register or from a simple
1184 conversion of a register, propagate REG_EXPR. */
1185 if (REG_P (dest) && !REG_ATTRS (dest))
1187 rtx src = SET_SRC (x);
1189 while (GET_CODE (src) == SIGN_EXTEND
1190 || GET_CODE (src) == ZERO_EXTEND
1191 || GET_CODE (src) == TRUNCATE
1192 || (GET_CODE (src) == SUBREG && subreg_lowpart_p (src)))
1193 src = XEXP (src, 0);
1195 set_reg_attrs_from_value (dest, src);
1198 /* ... fall through ... */
1202 const char *fmt = GET_RTX_FORMAT (code);
1204 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
1207 reg_scan_mark_refs (XEXP (x, i), insn);
1208 else if (fmt[i] == 'E' && XVEC (x, i) != 0)
1211 for (j = XVECLEN (x, i) - 1; j >= 0; j--)
1212 reg_scan_mark_refs (XVECEXP (x, i, j), insn);
1220 /* Return nonzero if C1 is a subset of C2, i.e., if every register in C1
1223 reg_class_subset_p (reg_class_t c1, reg_class_t c2)
1227 || hard_reg_set_subset_p (reg_class_contents[(int) c1],
1228 reg_class_contents[(int) c2]));
1231 /* Return nonzero if there is a register that is in both C1 and C2. */
1233 reg_classes_intersect_p (reg_class_t c1, reg_class_t c2)
1238 || hard_reg_set_intersect_p (reg_class_contents[(int) c1],
1239 reg_class_contents[(int) c2]));
1244 /* Passes for keeping and updating info about modes of registers
1245 inside subregisters. */
1247 #ifdef CANNOT_CHANGE_MODE_CLASS
1249 static bitmap invalid_mode_changes;
1252 record_subregs_of_mode (rtx subreg, bitmap subregs_of_mode)
1254 enum machine_mode mode;
1257 if (!REG_P (SUBREG_REG (subreg)))
1260 regno = REGNO (SUBREG_REG (subreg));
1261 mode = GET_MODE (subreg);
1263 if (regno < FIRST_PSEUDO_REGISTER)
1266 if (bitmap_set_bit (subregs_of_mode,
1267 regno * NUM_MACHINE_MODES + (unsigned int) mode))
1269 unsigned int rclass;
1270 for (rclass = 0; rclass < N_REG_CLASSES; rclass++)
1271 if (!bitmap_bit_p (invalid_mode_changes,
1272 regno * N_REG_CLASSES + rclass)
1273 && CANNOT_CHANGE_MODE_CLASS (PSEUDO_REGNO_MODE (regno),
1274 mode, (enum reg_class) rclass))
1275 bitmap_set_bit (invalid_mode_changes,
1276 regno * N_REG_CLASSES + rclass);
1280 /* Call record_subregs_of_mode for all the subregs in X. */
1282 find_subregs_of_mode (rtx x, bitmap subregs_of_mode)
1284 enum rtx_code code = GET_CODE (x);
1285 const char * const fmt = GET_RTX_FORMAT (code);
1289 record_subregs_of_mode (x, subregs_of_mode);
1291 /* Time for some deep diving. */
1292 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
1295 find_subregs_of_mode (XEXP (x, i), subregs_of_mode);
1296 else if (fmt[i] == 'E')
1299 for (j = XVECLEN (x, i) - 1; j >= 0; j--)
1300 find_subregs_of_mode (XVECEXP (x, i, j), subregs_of_mode);
1306 init_subregs_of_mode (void)
1310 bitmap_obstack srom_obstack;
1311 bitmap subregs_of_mode;
1313 gcc_assert (invalid_mode_changes == NULL);
1314 invalid_mode_changes = BITMAP_ALLOC (NULL);
1315 bitmap_obstack_initialize (&srom_obstack);
1316 subregs_of_mode = BITMAP_ALLOC (&srom_obstack);
1319 FOR_BB_INSNS (bb, insn)
1320 if (NONDEBUG_INSN_P (insn))
1321 find_subregs_of_mode (PATTERN (insn), subregs_of_mode);
1323 BITMAP_FREE (subregs_of_mode);
1324 bitmap_obstack_release (&srom_obstack);
1327 /* Return 1 if REGNO has had an invalid mode change in CLASS from FROM
1330 invalid_mode_change_p (unsigned int regno,
1331 enum reg_class rclass)
1333 return bitmap_bit_p (invalid_mode_changes,
1334 regno * N_REG_CLASSES + (unsigned) rclass);
1338 finish_subregs_of_mode (void)
1340 BITMAP_FREE (invalid_mode_changes);
1344 init_subregs_of_mode (void)
1348 finish_subregs_of_mode (void)
1352 #endif /* CANNOT_CHANGE_MODE_CLASS */