1 /* Compute different info about registers.
2 Copyright (C) 1987-2014 Free Software Foundation, Inc.
4 This file is part of GCC.
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
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
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/>. */
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. */
30 #include "coretypes.h"
32 #include "hard-reg-set.h"
45 #include "dominance.h"
47 #include "basic-block.h"
49 #include "addresses.h"
50 #include "insn-config.h"
53 #include "diagnostic-core.h"
56 #include "tree-pass.h"
60 /* Maximum register number used in this function, plus one. */
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
68 simplifiable_subreg (const subreg_shape
&);
71 HARD_REG_SET simplifiable_regs
;
74 struct simplifiable_subregs_hasher
: typed_noop_remove
<simplifiable_subreg
>
76 typedef simplifiable_subreg value_type
;
77 typedef subreg_shape compare_type
;
79 static inline hashval_t
hash (const value_type
*);
80 static inline bool equal (const value_type
*, const compare_type
*);
83 struct target_hard_regs default_target_hard_regs
;
84 struct target_regs default_target_regs
;
86 struct target_hard_regs
*this_target_hard_regs
= &default_target_hard_regs
;
87 struct target_regs
*this_target_regs
= &default_target_regs
;
90 /* Data for initializing fixed_regs. */
91 static const char initial_fixed_regs
[] = FIXED_REGISTERS
;
93 /* Data for initializing call_used_regs. */
94 static const char initial_call_used_regs
[] = CALL_USED_REGISTERS
;
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
;
101 #ifdef CALL_REALLY_USED_REGISTERS
102 #define CALL_REALLY_USED_REGNO_P(X) call_really_used_regs[X]
104 #define CALL_REALLY_USED_REGNO_P(X) call_used_regs[X]
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
];
113 /* Declaration for the global register. */
114 tree global_regs_decl
[FIRST_PSEUDO_REGISTER
];
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
;
120 /* Same information as FIXED_REG_SET but in regset form. */
121 regset fixed_reg_set_regset
;
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
;
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
;
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. */
137 ((FIRST_PSEUDO_REGISTER + (32 - 1)) / 32)
139 static const unsigned int_reg_class_contents
[N_REG_CLASSES
][N_REG_INTS
]
140 = REG_CLASS_CONTENTS
;
142 /* Array containing all of the register names. */
143 static const char *const initial_reg_names
[] = REGISTER_NAMES
;
145 /* Array containing all of the register class names. */
146 const char * reg_class_names
[] = REG_CLASS_NAMES
;
148 /* No more global register variables may be declared; true once
149 reginfo has been initialized. */
150 static int no_global_reg_vars
= 0;
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. */
157 reg_set_to_hard_reg_set (HARD_REG_SET
*to
, const_bitmap from
)
162 EXECUTE_IF_SET_IN_BITMAP (from
, 0, i
, bi
)
164 if (i
>= FIRST_PSEUDO_REGISTER
)
166 SET_HARD_REG_BIT (*to
, i
);
170 /* Function called only once per target_globals to initialize the
171 target_hard_regs structure. Once this is done, various switches
178 /* First copy the register information from the initial int form into
181 for (i
= 0; i
< N_REG_CLASSES
; i
++)
183 CLEAR_HARD_REG_SET (reg_class_contents
[i
]);
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
);
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
);
200 #ifdef REG_ALLOC_ORDER
201 gcc_assert (sizeof reg_alloc_order
== sizeof initial_reg_alloc_order
);
203 gcc_assert (sizeof reg_names
== sizeof initial_reg_names
);
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
);
211 #ifdef REG_ALLOC_ORDER
212 memcpy (reg_alloc_order
, initial_reg_alloc_order
, sizeof reg_alloc_order
);
214 memcpy (reg_names
, initial_reg_names
, sizeof reg_names
);
216 SET_HARD_REG_SET (accessible_reg_set
);
217 SET_HARD_REG_SET (operand_reg_set
);
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
];
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
;
232 /* Save the register information. */
234 save_register_info (void)
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
);
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
);
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
);
258 /* Restore the register information. */
260 restore_register_info (void)
262 memcpy (fixed_regs
, saved_fixed_regs
, sizeof fixed_regs
);
263 memcpy (call_used_regs
, saved_call_used_regs
, sizeof call_used_regs
);
265 #ifdef CALL_REALLY_USED_REGISTERS
266 memcpy (call_really_used_regs
, saved_call_really_used_regs
,
267 sizeof call_really_used_regs
);
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
);
275 /* After switches have been processed, which perhaps alter
276 `fixed_regs' and `call_used_regs', convert them to HARD_REG_SETs. */
278 init_reg_sets_1 (void)
281 unsigned int /* machine_mode */ m
;
283 restore_register_info ();
285 #ifdef REG_ALLOC_ORDER
286 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
287 inv_reg_alloc_order
[reg_alloc_order
[i
]] = i
;
290 /* Let the target tweak things if necessary. */
292 targetm
.conditional_register_usage ();
294 /* Compute number of hard regs in each class. */
296 memset (reg_class_size
, 0, sizeof reg_class_size
);
297 for (i
= 0; i
< N_REG_CLASSES
; i
++)
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
))
307 class_only_fixed_regs
[i
] = !any_nonfixed
;
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. */
314 memset (reg_class_subunion
, 0, sizeof reg_class_subunion
);
315 for (i
= 0; i
< N_REG_CLASSES
; i
++)
317 for (j
= 0; j
< N_REG_CLASSES
; j
++)
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
],
328 [(int) reg_class_subunion
[i
][j
]]))
329 reg_class_subunion
[i
][j
] = (enum reg_class
) k
;
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. */
337 memset (reg_class_superunion
, 0, sizeof reg_class_superunion
);
338 for (i
= 0; i
< N_REG_CLASSES
; i
++)
340 for (j
= 0; j
< N_REG_CLASSES
; j
++)
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
]))
351 reg_class_superunion
[i
][j
] = (enum reg_class
) k
;
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. */
358 for (i
= 0; i
< N_REG_CLASSES
; i
++)
360 for (j
= 0; j
< N_REG_CLASSES
; j
++)
361 reg_class_subclasses
[i
][j
] = LIM_REG_CLASSES
;
364 for (i
= 0; i
< N_REG_CLASSES
; i
++)
366 if (i
== (int) NO_REGS
)
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
]))
373 /* Reg class I is a subclass of J.
374 Add J to the table of superclasses of I. */
377 /* Add I to the table of superclasses of J. */
378 p
= ®_class_subclasses
[j
][0];
379 while (*p
!= LIM_REG_CLASSES
) p
++;
380 *p
= (enum reg_class
) i
;
384 /* Initialize "constant" tables. */
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
)
392 bitmap_obstack_initialize (&persistent_obstack
);
393 regs_invalidated_by_call_regset
= ALLOC_REG_SET (&persistent_obstack
);
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
);
400 CLEAR_REG_SET (fixed_reg_set_regset
);
402 AND_HARD_REG_SET (operand_reg_set
, accessible_reg_set
);
403 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
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
);
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
))
420 call_used_regs
[i
] = 1;
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
]);
432 SET_HARD_REG_BIT (fixed_reg_set
, i
);
433 SET_REGNO_REG_SET (fixed_reg_set_regset
, i
);
436 if (call_used_regs
[i
])
437 SET_HARD_REG_BIT (call_used_reg_set
, i
);
439 /* There are a couple of fixed registers that we know are safe to
440 exclude from being clobbered by calls:
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. */
449 if (i
== STACK_POINTER_REGNUM
)
451 else if (global_regs
[i
])
453 SET_HARD_REG_BIT (regs_invalidated_by_call
, i
);
454 SET_REGNO_REG_SET (regs_invalidated_by_call_regset
, i
);
456 else if (i
== FRAME_POINTER_REGNUM
)
458 #if !HARD_FRAME_POINTER_IS_FRAME_POINTER
459 else if (i
== HARD_FRAME_POINTER_REGNUM
)
462 #if ARG_POINTER_REGNUM != FRAME_POINTER_REGNUM
463 else if (i
== ARG_POINTER_REGNUM
&& fixed_regs
[i
])
466 else if (!PIC_OFFSET_TABLE_REG_CALL_CLOBBERED
467 && i
== (unsigned) PIC_OFFSET_TABLE_REGNUM
&& fixed_regs
[i
])
469 else if (CALL_REALLY_USED_REGNO_P (i
))
471 SET_HARD_REG_BIT (regs_invalidated_by_call
, i
);
472 SET_REGNO_REG_SET (regs_invalidated_by_call_regset
, i
);
476 COPY_HARD_REG_SET (call_fixed_reg_set
, fixed_reg_set
);
478 /* Preserve global registers if called more than once. */
479 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
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
);
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
++)
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
, (machine_mode
) m
))
498 SET_HARD_REG_BIT (ok_regs
, j
);
500 for (i
= 0; i
< N_REG_CLASSES
; i
++)
501 if ((targetm
.class_max_nregs ((reg_class_t
) i
, (machine_mode
) m
)
502 <= reg_class_size
[i
])
503 && hard_reg_set_intersect_p (ok_regs
, reg_class_contents
[i
]))
505 contains_reg_of_mode
[i
][m
] = 1;
506 have_regs_of_mode
[m
] = 1;
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.
518 init_reg_modes_target (void)
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
, (machine_mode
)j
);
526 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
528 reg_raw_mode
[i
] = choose_hard_reg_mode (i
, 1, false);
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
)
534 if (i
> 0 && hard_regno_nregs
[i
][reg_raw_mode
[i
- 1]] == 1)
535 reg_raw_mode
[i
] = reg_raw_mode
[i
- 1];
537 reg_raw_mode
[i
] = word_mode
;
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.
549 /* This finishes what was started by init_reg_sets, but couldn't be done
550 until after register usage was specified. */
554 /* The same as previous function plus initializing IRA. */
559 /* caller_save needs to be re-initialized. */
560 caller_save_initialized_p
= false;
561 if (this_target_rtl
->target_specific_initialized
)
568 /* Initialize some fake stack-frame MEM references for use in
569 memory_move_secondary_cost. */
571 init_fake_stack_mems (void)
575 for (i
= 0; i
< MAX_MACHINE_MODE
; i
++)
576 top_of_stack
[i
] = gen_rtx_MEM ((machine_mode
) i
, stack_pointer_rtx
);
580 /* Compute cost of moving data from a register of class FROM to one of
584 register_move_cost (machine_mode mode
, reg_class_t from
, reg_class_t to
)
586 return targetm
.register_move_cost (mode
, from
, to
);
589 /* Compute cost of moving registers to/from memory. */
592 memory_move_cost (machine_mode mode
, reg_class_t rclass
, bool in
)
594 return targetm
.memory_move_cost (mode
, rclass
, in
);
597 /* Compute extra cost of moving registers to/from memory due to reloads.
598 Only needed if secondary reloads are required for memory moves. */
600 memory_move_secondary_cost (machine_mode mode
, reg_class_t rclass
,
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
];
609 altclass
= secondary_reload_class (in
? 1 : 0, rclass
, mode
, mem
);
611 if (altclass
== NO_REGS
)
615 partial_cost
= register_move_cost (mode
, altclass
, rclass
);
617 partial_cost
= register_move_cost (mode
, rclass
, altclass
);
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.
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. */
629 /* Check if the secondary reload register will also need a
631 return memory_move_secondary_cost (mode
, altclass
, in
) + partial_cost
;
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. */
638 choose_hard_reg_mode (unsigned int regno ATTRIBUTE_UNUSED
,
639 unsigned int nregs
, bool call_saved
)
641 unsigned int /* machine_mode */ m
;
642 machine_mode found_mode
= VOIDmode
, mode
;
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. */
648 for (mode
= GET_CLASS_NARROWEST_MODE (MODE_INT
);
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
))
657 for (mode
= GET_CLASS_NARROWEST_MODE (MODE_FLOAT
);
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
))
666 for (mode
= GET_CLASS_NARROWEST_MODE (MODE_VECTOR_FLOAT
);
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
))
675 for (mode
= GET_CLASS_NARROWEST_MODE (MODE_VECTOR_INT
);
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
))
684 if (found_mode
!= VOIDmode
)
687 /* Iterate over all of the CCmodes. */
688 for (m
= (unsigned int) CCmode
; m
< (unsigned int) NUM_MACHINE_MODES
; ++m
)
690 mode
= (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
)))
697 /* We can't find a mode valid for this register. */
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. */
705 fix_register (const char *name
, int fixed
, int call_used
)
710 /* Decode the name and update the primary form of
711 the register info. */
713 if ((reg
= decode_reg_name_and_count (name
, &nregs
)) >= 0)
715 gcc_assert (nregs
>= 1);
716 for (i
= reg
; i
< reg
+ nregs
; i
++)
718 if ((i
== STACK_POINTER_REGNUM
719 #ifdef HARD_FRAME_POINTER_REGNUM
720 || i
== HARD_FRAME_POINTER_REGNUM
722 || i
== FRAME_POINTER_REGNUM
725 && (fixed
== 0 || call_used
== 0))
733 error ("can%'t use %qs as a call-saved register", name
);
737 error ("can%'t use %qs as a call-used register", name
);
749 error ("can%'t use %qs as a fixed register", name
);
764 fixed_regs
[i
] = fixed
;
765 call_used_regs
[i
] = call_used
;
766 #ifdef CALL_REALLY_USED_REGISTERS
768 call_really_used_regs
[i
] = call_used
;
775 warning (0, "unknown register name: %s", name
);
779 /* Mark register number I as global. */
781 globalize_reg (tree decl
, int i
)
783 location_t loc
= DECL_SOURCE_LOCATION (decl
);
786 if (IN_RANGE (i
, FIRST_STACK_REG
, LAST_STACK_REG
))
788 error ("stack register used for global register variable");
793 if (fixed_regs
[i
] == 0 && no_global_reg_vars
)
794 error_at (loc
, "global register variable follows a function definition");
799 "register of %qD used for multiple global register variables",
801 inform (DECL_SOURCE_LOCATION (global_regs_decl
[i
]),
802 "conflicts with %qD", global_regs_decl
[i
]);
806 if (call_used_regs
[i
] && ! fixed_regs
[i
])
807 warning_at (loc
, 0, "call-clobbered register used for global register variable");
810 global_regs_decl
[i
] = decl
;
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
)
817 SET_HARD_REG_BIT (regs_invalidated_by_call
, i
);
818 SET_REGNO_REG_SET (regs_invalidated_by_call_regset
, i
);
821 /* If already fixed, nothing else to do. */
825 fixed_regs
[i
] = call_used_regs
[i
] = 1;
826 #ifdef CALL_REALLY_USED_REGISTERS
827 call_really_used_regs
[i
] = 1;
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
);
838 /* Structure used to record preferences of given pseudo. */
841 /* (enum reg_class) prefclass is the preferred class. May be
842 NO_REGS if no class is better than memory. */
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.
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. */
854 /* allocnoclass is a register class that IRA uses for allocating
859 /* Record preferences of each pseudo. This is available after RA is
861 static struct reg_pref
*reg_pref
;
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
;
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. */
872 reg_preferred_class (int regno
)
877 gcc_assert (regno
< reg_info_size
);
878 return (enum reg_class
) reg_pref
[regno
].prefclass
;
882 reg_alternate_class (int regno
)
887 gcc_assert (regno
< reg_info_size
);
888 return (enum reg_class
) reg_pref
[regno
].altclass
;
891 /* Return the reg_class which is used by IRA for its allocation. */
893 reg_allocno_class (int regno
)
898 gcc_assert (regno
< reg_info_size
);
899 return (enum reg_class
) reg_pref
[regno
].allocnoclass
;
904 /* Allocate space for reg info and initilize it. */
906 allocate_reg_info (void)
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
++)
918 reg_pref
[i
].prefclass
= GENERAL_REGS
;
919 reg_pref
[i
].altclass
= ALL_REGS
;
920 reg_pref
[i
].allocnoclass
= GENERAL_REGS
;
925 /* Resize reg info. The new elements will be initialized. Return TRUE
926 if new pseudos were added since the last call. */
928 resize_reg_info (void)
933 if (reg_pref
== NULL
)
935 allocate_reg_info ();
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 ())
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
++)
952 reg_pref
[i
].prefclass
= GENERAL_REGS
;
953 reg_pref
[i
].altclass
= ALL_REGS
;
954 reg_pref
[i
].allocnoclass
= GENERAL_REGS
;
960 /* Free up the space allocated by allocate_reg_info. */
977 /* Initialize some global data for this pass. */
982 df_compute_regs_ever_live (true);
984 /* This prevents dump_reg_info from losing if called
985 before reginfo is run. */
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;
995 const pass_data pass_data_reginfo_init
=
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 */
1008 class pass_reginfo_init
: public rtl_opt_pass
1011 pass_reginfo_init (gcc::context
*ctxt
)
1012 : rtl_opt_pass (pass_data_reginfo_init
, ctxt
)
1015 /* opt_pass methods: */
1016 virtual unsigned int execute (function
*) { return reginfo_init (); }
1018 }; // class pass_reginfo_init
1023 make_pass_reginfo_init (gcc::context
*ctxt
)
1025 return new pass_reginfo_init (ctxt
);
1030 /* Set up preferred, alternate, and allocno classes for REGNO as
1031 PREFCLASS, ALTCLASS, and ALLOCNOCLASS. */
1033 setup_reg_classes (int regno
,
1034 enum reg_class prefclass
, enum reg_class altclass
,
1035 enum reg_class allocnoclass
)
1037 if (reg_pref
== NULL
)
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
;
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
1050 static void reg_scan_mark_refs (rtx
, rtx_insn
*);
1053 reg_scan (rtx_insn
*f
, unsigned int nregs ATTRIBUTE_UNUSED
)
1057 timevar_push (TV_REG_SCAN
);
1059 for (insn
= f
; insn
; insn
= NEXT_INSN (insn
))
1062 reg_scan_mark_refs (PATTERN (insn
), insn
);
1063 if (REG_NOTES (insn
))
1064 reg_scan_mark_refs (REG_NOTES (insn
), insn
);
1067 timevar_pop (TV_REG_SCAN
);
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. */
1076 reg_scan_mark_refs (rtx x
, rtx_insn
*insn
)
1084 code
= GET_CODE (x
);
1100 reg_scan_mark_refs (XEXP (x
, 0), insn
);
1102 reg_scan_mark_refs (XEXP (x
, 1), insn
);
1108 reg_scan_mark_refs (XEXP (x
, 1), insn
);
1112 if (MEM_P (XEXP (x
, 0)))
1113 reg_scan_mark_refs (XEXP (XEXP (x
, 0), 0), insn
);
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))
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.
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
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
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;
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
));
1176 /* ... fall through ... */
1180 const char *fmt
= GET_RTX_FORMAT (code
);
1182 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
1185 reg_scan_mark_refs (XEXP (x
, i
), insn
);
1186 else if (fmt
[i
] == 'E' && XVEC (x
, i
) != 0)
1189 for (j
= XVECLEN (x
, i
) - 1; j
>= 0; j
--)
1190 reg_scan_mark_refs (XVECEXP (x
, i
, j
), insn
);
1198 /* Return nonzero if C1 is a subset of C2, i.e., if every register in C1
1201 reg_class_subset_p (reg_class_t c1
, reg_class_t c2
)
1205 || hard_reg_set_subset_p (reg_class_contents
[(int) c1
],
1206 reg_class_contents
[(int) c2
]));
1209 /* Return nonzero if there is a register that is in both C1 and C2. */
1211 reg_classes_intersect_p (reg_class_t c1
, reg_class_t c2
)
1216 || hard_reg_set_intersect_p (reg_class_contents
[(int) c1
],
1217 reg_class_contents
[(int) c2
]));
1222 simplifiable_subregs_hasher::hash (const value_type
*value
)
1224 return value
->shape
.unique_id ();
1228 simplifiable_subregs_hasher::equal (const value_type
*value
,
1229 const compare_type
*compare
)
1231 return value
->shape
== *compare
;
1234 inline simplifiable_subreg::simplifiable_subreg (const subreg_shape
&shape_in
)
1237 CLEAR_HARD_REG_SET (simplifiable_regs
);
1240 /* Return the set of hard registers that are able to form the subreg
1241 described by SHAPE. */
1243 const HARD_REG_SET
&
1244 simplifiable_subregs (const subreg_shape
&shape
)
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
));
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
);
1263 return (*slot
)->simplifiable_regs
;
1266 /* Passes for keeping and updating info about modes of registers
1267 inside subregisters. */
1269 static HARD_REG_SET
**valid_mode_changes
;
1270 static obstack valid_mode_changes_obstack
;
1273 record_subregs_of_mode (rtx subreg
)
1277 if (!REG_P (SUBREG_REG (subreg
)))
1280 regno
= REGNO (SUBREG_REG (subreg
));
1281 if (regno
< FIRST_PSEUDO_REGISTER
)
1284 if (valid_mode_changes
[regno
])
1285 AND_HARD_REG_SET (*valid_mode_changes
[regno
],
1286 simplifiable_subregs (shape_of_subreg (subreg
)));
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
)));
1296 /* Call record_subregs_of_mode for all the subregs in X. */
1298 find_subregs_of_mode (rtx x
)
1300 enum rtx_code code
= GET_CODE (x
);
1301 const char * const fmt
= GET_RTX_FORMAT (code
);
1305 record_subregs_of_mode (x
);
1307 /* Time for some deep diving. */
1308 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
1311 find_subregs_of_mode (XEXP (x
, i
));
1312 else if (fmt
[i
] == 'E')
1315 for (j
= XVECLEN (x
, i
) - 1; j
>= 0; j
--)
1316 find_subregs_of_mode (XVECEXP (x
, i
, j
));
1322 init_subregs_of_mode (void)
1327 gcc_obstack_init (&valid_mode_changes_obstack
);
1328 valid_mode_changes
= XCNEWVEC (HARD_REG_SET
*, max_reg_num ());
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
));
1336 const HARD_REG_SET
*
1337 valid_mode_changes_for_regno (unsigned int regno
)
1339 return valid_mode_changes
[regno
];
1343 finish_subregs_of_mode (void)
1345 XDELETEVEC (valid_mode_changes
);
1346 obstack_finish (&valid_mode_changes_obstack
);
1349 /* Free all data attached to the structure. This isn't a destructor because
1350 we don't want to run on exit. */
1353 target_hard_regs::finalize ()
1355 delete x_simplifiable_subregs
;