1 /* Compute different info about registers.
2 Copyright (C) 1987-2015 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"
36 #include "double-int.h"
47 #include "statistics.h"
49 #include "fixed-value.h"
50 #include "insn-config.h"
61 #include "dominance.h"
63 #include "basic-block.h"
65 #include "addresses.h"
68 #include "diagnostic-core.h"
71 #include "tree-pass.h"
75 /* Maximum register number used in this function, plus one. */
79 /* Used to cache the results of simplifiable_subregs. SHAPE is the input
80 parameter and SIMPLIFIABLE_REGS is the result. */
81 struct simplifiable_subreg
83 simplifiable_subreg (const subreg_shape
&);
86 HARD_REG_SET simplifiable_regs
;
89 struct target_hard_regs default_target_hard_regs
;
90 struct target_regs default_target_regs
;
92 struct target_hard_regs
*this_target_hard_regs
= &default_target_hard_regs
;
93 struct target_regs
*this_target_regs
= &default_target_regs
;
96 /* Data for initializing fixed_regs. */
97 static const char initial_fixed_regs
[] = FIXED_REGISTERS
;
99 /* Data for initializing call_used_regs. */
100 static const char initial_call_used_regs
[] = CALL_USED_REGISTERS
;
102 #ifdef CALL_REALLY_USED_REGISTERS
103 /* Data for initializing call_really_used_regs. */
104 static const char initial_call_really_used_regs
[] = CALL_REALLY_USED_REGISTERS
;
107 #ifdef CALL_REALLY_USED_REGISTERS
108 #define CALL_REALLY_USED_REGNO_P(X) call_really_used_regs[X]
110 #define CALL_REALLY_USED_REGNO_P(X) call_used_regs[X]
113 /* Indexed by hard register number, contains 1 for registers
114 that are being used for global register decls.
115 These must be exempt from ordinary flow analysis
116 and are also considered fixed. */
117 char global_regs
[FIRST_PSEUDO_REGISTER
];
119 /* Declaration for the global register. */
120 tree global_regs_decl
[FIRST_PSEUDO_REGISTER
];
122 /* Same information as REGS_INVALIDATED_BY_CALL but in regset form to be used
123 in dataflow more conveniently. */
124 regset regs_invalidated_by_call_regset
;
126 /* Same information as FIXED_REG_SET but in regset form. */
127 regset fixed_reg_set_regset
;
129 /* The bitmap_obstack is used to hold some static variables that
130 should not be reset after each function is compiled. */
131 static bitmap_obstack persistent_obstack
;
133 /* Used to initialize reg_alloc_order. */
134 #ifdef REG_ALLOC_ORDER
135 static int initial_reg_alloc_order
[FIRST_PSEUDO_REGISTER
] = REG_ALLOC_ORDER
;
138 /* The same information, but as an array of unsigned ints. We copy from
139 these unsigned ints to the table above. We do this so the tm.h files
140 do not have to be aware of the wordsize for machines with <= 64 regs.
141 Note that we hard-code 32 here, not HOST_BITS_PER_INT. */
143 ((FIRST_PSEUDO_REGISTER + (32 - 1)) / 32)
145 static const unsigned int_reg_class_contents
[N_REG_CLASSES
][N_REG_INTS
]
146 = REG_CLASS_CONTENTS
;
148 /* Array containing all of the register names. */
149 static const char *const initial_reg_names
[] = REGISTER_NAMES
;
151 /* Array containing all of the register class names. */
152 const char * reg_class_names
[] = REG_CLASS_NAMES
;
154 /* No more global register variables may be declared; true once
155 reginfo has been initialized. */
156 static int no_global_reg_vars
= 0;
158 /* Given a register bitmap, turn on the bits in a HARD_REG_SET that
159 correspond to the hard registers, if any, set in that map. This
160 could be done far more efficiently by having all sorts of special-cases
161 with moving single words, but probably isn't worth the trouble. */
163 reg_set_to_hard_reg_set (HARD_REG_SET
*to
, const_bitmap from
)
168 EXECUTE_IF_SET_IN_BITMAP (from
, 0, i
, bi
)
170 if (i
>= FIRST_PSEUDO_REGISTER
)
172 SET_HARD_REG_BIT (*to
, i
);
176 /* Function called only once per target_globals to initialize the
177 target_hard_regs structure. Once this is done, various switches
184 /* First copy the register information from the initial int form into
187 for (i
= 0; i
< N_REG_CLASSES
; i
++)
189 CLEAR_HARD_REG_SET (reg_class_contents
[i
]);
191 /* Note that we hard-code 32 here, not HOST_BITS_PER_INT. */
192 for (j
= 0; j
< FIRST_PSEUDO_REGISTER
; j
++)
193 if (int_reg_class_contents
[i
][j
/ 32]
194 & ((unsigned) 1 << (j
% 32)))
195 SET_HARD_REG_BIT (reg_class_contents
[i
], j
);
198 /* Sanity check: make sure the target macros FIXED_REGISTERS and
199 CALL_USED_REGISTERS had the right number of initializers. */
200 gcc_assert (sizeof fixed_regs
== sizeof initial_fixed_regs
);
201 gcc_assert (sizeof call_used_regs
== sizeof initial_call_used_regs
);
202 #ifdef CALL_REALLY_USED_REGISTERS
203 gcc_assert (sizeof call_really_used_regs
204 == sizeof initial_call_really_used_regs
);
206 #ifdef REG_ALLOC_ORDER
207 gcc_assert (sizeof reg_alloc_order
== sizeof initial_reg_alloc_order
);
209 gcc_assert (sizeof reg_names
== sizeof initial_reg_names
);
211 memcpy (fixed_regs
, initial_fixed_regs
, sizeof fixed_regs
);
212 memcpy (call_used_regs
, initial_call_used_regs
, sizeof call_used_regs
);
213 #ifdef CALL_REALLY_USED_REGISTERS
214 memcpy (call_really_used_regs
, initial_call_really_used_regs
,
215 sizeof call_really_used_regs
);
217 #ifdef REG_ALLOC_ORDER
218 memcpy (reg_alloc_order
, initial_reg_alloc_order
, sizeof reg_alloc_order
);
220 memcpy (reg_names
, initial_reg_names
, sizeof reg_names
);
222 SET_HARD_REG_SET (accessible_reg_set
);
223 SET_HARD_REG_SET (operand_reg_set
);
226 /* We need to save copies of some of the register information which
227 can be munged by command-line switches so we can restore it during
228 subsequent back-end reinitialization. */
229 static char saved_fixed_regs
[FIRST_PSEUDO_REGISTER
];
230 static char saved_call_used_regs
[FIRST_PSEUDO_REGISTER
];
231 #ifdef CALL_REALLY_USED_REGISTERS
232 static char saved_call_really_used_regs
[FIRST_PSEUDO_REGISTER
];
234 static const char *saved_reg_names
[FIRST_PSEUDO_REGISTER
];
235 static HARD_REG_SET saved_accessible_reg_set
;
236 static HARD_REG_SET saved_operand_reg_set
;
238 /* Save the register information. */
240 save_register_info (void)
242 /* Sanity check: make sure the target macros FIXED_REGISTERS and
243 CALL_USED_REGISTERS had the right number of initializers. */
244 gcc_assert (sizeof fixed_regs
== sizeof saved_fixed_regs
);
245 gcc_assert (sizeof call_used_regs
== sizeof saved_call_used_regs
);
246 memcpy (saved_fixed_regs
, fixed_regs
, sizeof fixed_regs
);
247 memcpy (saved_call_used_regs
, call_used_regs
, sizeof call_used_regs
);
249 /* Likewise for call_really_used_regs. */
250 #ifdef CALL_REALLY_USED_REGISTERS
251 gcc_assert (sizeof call_really_used_regs
252 == sizeof saved_call_really_used_regs
);
253 memcpy (saved_call_really_used_regs
, call_really_used_regs
,
254 sizeof call_really_used_regs
);
257 /* And similarly for reg_names. */
258 gcc_assert (sizeof reg_names
== sizeof saved_reg_names
);
259 memcpy (saved_reg_names
, reg_names
, sizeof reg_names
);
260 COPY_HARD_REG_SET (saved_accessible_reg_set
, accessible_reg_set
);
261 COPY_HARD_REG_SET (saved_operand_reg_set
, operand_reg_set
);
264 /* Restore the register information. */
266 restore_register_info (void)
268 memcpy (fixed_regs
, saved_fixed_regs
, sizeof fixed_regs
);
269 memcpy (call_used_regs
, saved_call_used_regs
, sizeof call_used_regs
);
271 #ifdef CALL_REALLY_USED_REGISTERS
272 memcpy (call_really_used_regs
, saved_call_really_used_regs
,
273 sizeof call_really_used_regs
);
276 memcpy (reg_names
, saved_reg_names
, sizeof reg_names
);
277 COPY_HARD_REG_SET (accessible_reg_set
, saved_accessible_reg_set
);
278 COPY_HARD_REG_SET (operand_reg_set
, saved_operand_reg_set
);
281 /* After switches have been processed, which perhaps alter
282 `fixed_regs' and `call_used_regs', convert them to HARD_REG_SETs. */
284 init_reg_sets_1 (void)
287 unsigned int /* machine_mode */ m
;
289 restore_register_info ();
291 #ifdef REG_ALLOC_ORDER
292 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
293 inv_reg_alloc_order
[reg_alloc_order
[i
]] = i
;
296 /* Let the target tweak things if necessary. */
298 targetm
.conditional_register_usage ();
300 /* Compute number of hard regs in each class. */
302 memset (reg_class_size
, 0, sizeof reg_class_size
);
303 for (i
= 0; i
< N_REG_CLASSES
; i
++)
305 bool any_nonfixed
= false;
306 for (j
= 0; j
< FIRST_PSEUDO_REGISTER
; j
++)
307 if (TEST_HARD_REG_BIT (reg_class_contents
[i
], j
))
313 class_only_fixed_regs
[i
] = !any_nonfixed
;
316 /* Initialize the table of subunions.
317 reg_class_subunion[I][J] gets the largest-numbered reg-class
318 that is contained in the union of classes I and J. */
320 memset (reg_class_subunion
, 0, sizeof reg_class_subunion
);
321 for (i
= 0; i
< N_REG_CLASSES
; i
++)
323 for (j
= 0; j
< N_REG_CLASSES
; j
++)
328 COPY_HARD_REG_SET (c
, reg_class_contents
[i
]);
329 IOR_HARD_REG_SET (c
, reg_class_contents
[j
]);
330 for (k
= 0; k
< N_REG_CLASSES
; k
++)
331 if (hard_reg_set_subset_p (reg_class_contents
[k
], c
)
332 && !hard_reg_set_subset_p (reg_class_contents
[k
],
334 [(int) reg_class_subunion
[i
][j
]]))
335 reg_class_subunion
[i
][j
] = (enum reg_class
) k
;
339 /* Initialize the table of superunions.
340 reg_class_superunion[I][J] gets the smallest-numbered reg-class
341 containing the union of classes I and J. */
343 memset (reg_class_superunion
, 0, sizeof reg_class_superunion
);
344 for (i
= 0; i
< N_REG_CLASSES
; i
++)
346 for (j
= 0; j
< N_REG_CLASSES
; j
++)
351 COPY_HARD_REG_SET (c
, reg_class_contents
[i
]);
352 IOR_HARD_REG_SET (c
, reg_class_contents
[j
]);
353 for (k
= 0; k
< N_REG_CLASSES
; k
++)
354 if (hard_reg_set_subset_p (c
, reg_class_contents
[k
]))
357 reg_class_superunion
[i
][j
] = (enum reg_class
) k
;
361 /* Initialize the tables of subclasses and superclasses of each reg class.
362 First clear the whole table, then add the elements as they are found. */
364 for (i
= 0; i
< N_REG_CLASSES
; i
++)
366 for (j
= 0; j
< N_REG_CLASSES
; j
++)
367 reg_class_subclasses
[i
][j
] = LIM_REG_CLASSES
;
370 for (i
= 0; i
< N_REG_CLASSES
; i
++)
372 if (i
== (int) NO_REGS
)
375 for (j
= i
+ 1; j
< N_REG_CLASSES
; j
++)
376 if (hard_reg_set_subset_p (reg_class_contents
[i
],
377 reg_class_contents
[j
]))
379 /* Reg class I is a subclass of J.
380 Add J to the table of superclasses of I. */
383 /* Add I to the table of superclasses of J. */
384 p
= ®_class_subclasses
[j
][0];
385 while (*p
!= LIM_REG_CLASSES
) p
++;
386 *p
= (enum reg_class
) i
;
390 /* Initialize "constant" tables. */
392 CLEAR_HARD_REG_SET (fixed_reg_set
);
393 CLEAR_HARD_REG_SET (call_used_reg_set
);
394 CLEAR_HARD_REG_SET (call_fixed_reg_set
);
395 CLEAR_HARD_REG_SET (regs_invalidated_by_call
);
396 if (!regs_invalidated_by_call_regset
)
398 bitmap_obstack_initialize (&persistent_obstack
);
399 regs_invalidated_by_call_regset
= ALLOC_REG_SET (&persistent_obstack
);
402 CLEAR_REG_SET (regs_invalidated_by_call_regset
);
403 if (!fixed_reg_set_regset
)
404 fixed_reg_set_regset
= ALLOC_REG_SET (&persistent_obstack
);
406 CLEAR_REG_SET (fixed_reg_set_regset
);
408 AND_HARD_REG_SET (operand_reg_set
, accessible_reg_set
);
409 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
411 /* As a special exception, registers whose class is NO_REGS are
412 not accepted by `register_operand'. The reason for this change
413 is to allow the representation of special architecture artifacts
414 (such as a condition code register) without extending the rtl
415 definitions. Since registers of class NO_REGS cannot be used
416 as registers in any case where register classes are examined,
417 it is better to apply this exception in a target-independent way. */
418 if (REGNO_REG_CLASS (i
) == NO_REGS
)
419 CLEAR_HARD_REG_BIT (operand_reg_set
, i
);
421 /* If a register is too limited to be treated as a register operand,
422 then it should never be allocated to a pseudo. */
423 if (!TEST_HARD_REG_BIT (operand_reg_set
, i
))
426 call_used_regs
[i
] = 1;
429 /* call_used_regs must include fixed_regs. */
430 gcc_assert (!fixed_regs
[i
] || call_used_regs
[i
]);
431 #ifdef CALL_REALLY_USED_REGISTERS
432 /* call_used_regs must include call_really_used_regs. */
433 gcc_assert (!call_really_used_regs
[i
] || call_used_regs
[i
]);
438 SET_HARD_REG_BIT (fixed_reg_set
, i
);
439 SET_REGNO_REG_SET (fixed_reg_set_regset
, i
);
442 if (call_used_regs
[i
])
443 SET_HARD_REG_BIT (call_used_reg_set
, i
);
445 /* There are a couple of fixed registers that we know are safe to
446 exclude from being clobbered by calls:
448 The frame pointer is always preserved across calls. The arg
449 pointer is if it is fixed. The stack pointer usually is,
450 unless TARGET_RETURN_POPS_ARGS, in which case an explicit
451 CLOBBER will be present. If we are generating PIC code, the
452 PIC offset table register is preserved across calls, though the
453 target can override that. */
455 if (i
== STACK_POINTER_REGNUM
)
457 else if (global_regs
[i
])
459 SET_HARD_REG_BIT (regs_invalidated_by_call
, i
);
460 SET_REGNO_REG_SET (regs_invalidated_by_call_regset
, i
);
462 else if (i
== FRAME_POINTER_REGNUM
)
464 else if (!HARD_FRAME_POINTER_IS_FRAME_POINTER
465 && i
== HARD_FRAME_POINTER_REGNUM
)
467 else if (FRAME_POINTER_REGNUM
!= ARG_POINTER_REGNUM
468 && i
== ARG_POINTER_REGNUM
&& fixed_regs
[i
])
470 else if (!PIC_OFFSET_TABLE_REG_CALL_CLOBBERED
471 && i
== (unsigned) PIC_OFFSET_TABLE_REGNUM
&& fixed_regs
[i
])
473 else if (CALL_REALLY_USED_REGNO_P (i
))
475 SET_HARD_REG_BIT (regs_invalidated_by_call
, i
);
476 SET_REGNO_REG_SET (regs_invalidated_by_call_regset
, i
);
480 COPY_HARD_REG_SET (call_fixed_reg_set
, fixed_reg_set
);
482 /* Preserve global registers if called more than once. */
483 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
487 fixed_regs
[i
] = call_used_regs
[i
] = 1;
488 SET_HARD_REG_BIT (fixed_reg_set
, i
);
489 SET_HARD_REG_BIT (call_used_reg_set
, i
);
490 SET_HARD_REG_BIT (call_fixed_reg_set
, i
);
494 memset (have_regs_of_mode
, 0, sizeof (have_regs_of_mode
));
495 memset (contains_reg_of_mode
, 0, sizeof (contains_reg_of_mode
));
496 for (m
= 0; m
< (unsigned int) MAX_MACHINE_MODE
; m
++)
498 HARD_REG_SET ok_regs
;
499 CLEAR_HARD_REG_SET (ok_regs
);
500 for (j
= 0; j
< FIRST_PSEUDO_REGISTER
; j
++)
501 if (!fixed_regs
[j
] && HARD_REGNO_MODE_OK (j
, (machine_mode
) m
))
502 SET_HARD_REG_BIT (ok_regs
, j
);
504 for (i
= 0; i
< N_REG_CLASSES
; i
++)
505 if ((targetm
.class_max_nregs ((reg_class_t
) i
, (machine_mode
) m
)
506 <= reg_class_size
[i
])
507 && hard_reg_set_intersect_p (ok_regs
, reg_class_contents
[i
]))
509 contains_reg_of_mode
[i
][m
] = 1;
510 have_regs_of_mode
[m
] = 1;
515 /* Compute the table of register modes.
516 These values are used to record death information for individual registers
517 (as opposed to a multi-register mode).
518 This function might be invoked more than once, if the target has support
519 for changing register usage conventions on a per-function basis.
522 init_reg_modes_target (void)
526 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
527 for (j
= 0; j
< MAX_MACHINE_MODE
; j
++)
528 hard_regno_nregs
[i
][j
] = HARD_REGNO_NREGS (i
, (machine_mode
)j
);
530 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
532 reg_raw_mode
[i
] = choose_hard_reg_mode (i
, 1, false);
534 /* If we couldn't find a valid mode, just use the previous mode
535 if it is suitable, otherwise fall back on word_mode. */
536 if (reg_raw_mode
[i
] == VOIDmode
)
538 if (i
> 0 && hard_regno_nregs
[i
][reg_raw_mode
[i
- 1]] == 1)
539 reg_raw_mode
[i
] = reg_raw_mode
[i
- 1];
541 reg_raw_mode
[i
] = word_mode
;
546 /* Finish initializing the register sets and initialize the register modes.
547 This function might be invoked more than once, if the target has support
548 for changing register usage conventions on a per-function basis.
553 /* This finishes what was started by init_reg_sets, but couldn't be done
554 until after register usage was specified. */
558 /* The same as previous function plus initializing IRA. */
563 /* caller_save needs to be re-initialized. */
564 caller_save_initialized_p
= false;
565 if (this_target_rtl
->target_specific_initialized
)
572 /* Initialize some fake stack-frame MEM references for use in
573 memory_move_secondary_cost. */
575 init_fake_stack_mems (void)
579 for (i
= 0; i
< MAX_MACHINE_MODE
; i
++)
580 top_of_stack
[i
] = gen_rtx_MEM ((machine_mode
) i
, stack_pointer_rtx
);
584 /* Compute cost of moving data from a register of class FROM to one of
588 register_move_cost (machine_mode mode
, reg_class_t from
, reg_class_t to
)
590 return targetm
.register_move_cost (mode
, from
, to
);
593 /* Compute cost of moving registers to/from memory. */
596 memory_move_cost (machine_mode mode
, reg_class_t rclass
, bool in
)
598 return targetm
.memory_move_cost (mode
, rclass
, in
);
601 /* Compute extra cost of moving registers to/from memory due to reloads.
602 Only needed if secondary reloads are required for memory moves. */
604 memory_move_secondary_cost (machine_mode mode
, reg_class_t rclass
,
607 reg_class_t altclass
;
608 int partial_cost
= 0;
609 /* We need a memory reference to feed to SECONDARY... macros. */
610 /* mem may be unused even if the SECONDARY_ macros are defined. */
611 rtx mem ATTRIBUTE_UNUSED
= top_of_stack
[(int) mode
];
613 altclass
= secondary_reload_class (in
? 1 : 0, rclass
, mode
, mem
);
615 if (altclass
== NO_REGS
)
619 partial_cost
= register_move_cost (mode
, altclass
, rclass
);
621 partial_cost
= register_move_cost (mode
, rclass
, altclass
);
623 if (rclass
== altclass
)
624 /* This isn't simply a copy-to-temporary situation. Can't guess
625 what it is, so TARGET_MEMORY_MOVE_COST really ought not to be
626 calling here in that case.
628 I'm tempted to put in an assert here, but returning this will
629 probably only give poor estimates, which is what we would've
630 had before this code anyways. */
633 /* Check if the secondary reload register will also need a
635 return memory_move_secondary_cost (mode
, altclass
, in
) + partial_cost
;
638 /* Return a machine mode that is legitimate for hard reg REGNO and large
639 enough to save nregs. If we can't find one, return VOIDmode.
640 If CALL_SAVED is true, only consider modes that are call saved. */
642 choose_hard_reg_mode (unsigned int regno ATTRIBUTE_UNUSED
,
643 unsigned int nregs
, bool call_saved
)
645 unsigned int /* machine_mode */ m
;
646 machine_mode found_mode
= VOIDmode
, mode
;
648 /* We first look for the largest integer mode that can be validly
649 held in REGNO. If none, we look for the largest floating-point mode.
650 If we still didn't find a valid mode, try CCmode. */
652 for (mode
= GET_CLASS_NARROWEST_MODE (MODE_INT
);
654 mode
= GET_MODE_WIDER_MODE (mode
))
655 if ((unsigned) hard_regno_nregs
[regno
][mode
] == nregs
656 && HARD_REGNO_MODE_OK (regno
, mode
)
657 && (! call_saved
|| ! HARD_REGNO_CALL_PART_CLOBBERED (regno
, mode
))
658 && GET_MODE_SIZE (mode
) > GET_MODE_SIZE (found_mode
))
661 for (mode
= GET_CLASS_NARROWEST_MODE (MODE_FLOAT
);
663 mode
= GET_MODE_WIDER_MODE (mode
))
664 if ((unsigned) hard_regno_nregs
[regno
][mode
] == nregs
665 && HARD_REGNO_MODE_OK (regno
, mode
)
666 && (! call_saved
|| ! HARD_REGNO_CALL_PART_CLOBBERED (regno
, mode
))
667 && GET_MODE_SIZE (mode
) > GET_MODE_SIZE (found_mode
))
670 for (mode
= GET_CLASS_NARROWEST_MODE (MODE_VECTOR_FLOAT
);
672 mode
= GET_MODE_WIDER_MODE (mode
))
673 if ((unsigned) hard_regno_nregs
[regno
][mode
] == nregs
674 && HARD_REGNO_MODE_OK (regno
, mode
)
675 && (! call_saved
|| ! HARD_REGNO_CALL_PART_CLOBBERED (regno
, mode
))
676 && GET_MODE_SIZE (mode
) > GET_MODE_SIZE (found_mode
))
679 for (mode
= GET_CLASS_NARROWEST_MODE (MODE_VECTOR_INT
);
681 mode
= GET_MODE_WIDER_MODE (mode
))
682 if ((unsigned) hard_regno_nregs
[regno
][mode
] == nregs
683 && HARD_REGNO_MODE_OK (regno
, mode
)
684 && (! call_saved
|| ! HARD_REGNO_CALL_PART_CLOBBERED (regno
, mode
))
685 && GET_MODE_SIZE (mode
) > GET_MODE_SIZE (found_mode
))
688 if (found_mode
!= VOIDmode
)
691 /* Iterate over all of the CCmodes. */
692 for (m
= (unsigned int) CCmode
; m
< (unsigned int) NUM_MACHINE_MODES
; ++m
)
694 mode
= (machine_mode
) m
;
695 if ((unsigned) hard_regno_nregs
[regno
][mode
] == nregs
696 && HARD_REGNO_MODE_OK (regno
, mode
)
697 && (! call_saved
|| ! HARD_REGNO_CALL_PART_CLOBBERED (regno
, mode
)))
701 /* We can't find a mode valid for this register. */
705 /* Specify the usage characteristics of the register named NAME.
706 It should be a fixed register if FIXED and a
707 call-used register if CALL_USED. */
709 fix_register (const char *name
, int fixed
, int call_used
)
714 /* Decode the name and update the primary form of
715 the register info. */
717 if ((reg
= decode_reg_name_and_count (name
, &nregs
)) >= 0)
719 gcc_assert (nregs
>= 1);
720 for (i
= reg
; i
< reg
+ nregs
; i
++)
722 if ((i
== STACK_POINTER_REGNUM
723 #ifdef HARD_FRAME_POINTER_REGNUM
724 || i
== HARD_FRAME_POINTER_REGNUM
726 || i
== FRAME_POINTER_REGNUM
729 && (fixed
== 0 || call_used
== 0))
737 error ("can%'t use %qs as a call-saved register", name
);
741 error ("can%'t use %qs as a call-used register", name
);
753 error ("can%'t use %qs as a fixed register", name
);
768 fixed_regs
[i
] = fixed
;
769 call_used_regs
[i
] = call_used
;
770 #ifdef CALL_REALLY_USED_REGISTERS
772 call_really_used_regs
[i
] = call_used
;
779 warning (0, "unknown register name: %s", name
);
783 /* Mark register number I as global. */
785 globalize_reg (tree decl
, int i
)
787 location_t loc
= DECL_SOURCE_LOCATION (decl
);
790 if (IN_RANGE (i
, FIRST_STACK_REG
, LAST_STACK_REG
))
792 error ("stack register used for global register variable");
797 if (fixed_regs
[i
] == 0 && no_global_reg_vars
)
798 error_at (loc
, "global register variable follows a function definition");
803 "register of %qD used for multiple global register variables",
805 inform (DECL_SOURCE_LOCATION (global_regs_decl
[i
]),
806 "conflicts with %qD", global_regs_decl
[i
]);
810 if (call_used_regs
[i
] && ! fixed_regs
[i
])
811 warning_at (loc
, 0, "call-clobbered register used for global register variable");
814 global_regs_decl
[i
] = decl
;
816 /* If we're globalizing the frame pointer, we need to set the
817 appropriate regs_invalidated_by_call bit, even if it's already
818 set in fixed_regs. */
819 if (i
!= STACK_POINTER_REGNUM
)
821 SET_HARD_REG_BIT (regs_invalidated_by_call
, i
);
822 SET_REGNO_REG_SET (regs_invalidated_by_call_regset
, i
);
825 /* If already fixed, nothing else to do. */
829 fixed_regs
[i
] = call_used_regs
[i
] = 1;
830 #ifdef CALL_REALLY_USED_REGISTERS
831 call_really_used_regs
[i
] = 1;
834 SET_HARD_REG_BIT (fixed_reg_set
, i
);
835 SET_HARD_REG_BIT (call_used_reg_set
, i
);
836 SET_HARD_REG_BIT (call_fixed_reg_set
, i
);
842 /* Structure used to record preferences of given pseudo. */
845 /* (enum reg_class) prefclass is the preferred class. May be
846 NO_REGS if no class is better than memory. */
849 /* altclass is a register class that we should use for allocating
850 pseudo if no register in the preferred class is available.
851 If no register in this class is available, memory is preferred.
853 It might appear to be more general to have a bitmask of classes here,
854 but since it is recommended that there be a class corresponding to the
855 union of most major pair of classes, that generality is not required. */
858 /* allocnoclass is a register class that IRA uses for allocating
863 /* Record preferences of each pseudo. This is available after RA is
865 static struct reg_pref
*reg_pref
;
867 /* Current size of reg_info. */
868 static int reg_info_size
;
869 /* Max_reg_num still last resize_reg_info call. */
870 static int max_regno_since_last_resize
;
872 /* Return the reg_class in which pseudo reg number REGNO is best allocated.
873 This function is sometimes called before the info has been computed.
874 When that happens, just return GENERAL_REGS, which is innocuous. */
876 reg_preferred_class (int regno
)
881 gcc_assert (regno
< reg_info_size
);
882 return (enum reg_class
) reg_pref
[regno
].prefclass
;
886 reg_alternate_class (int regno
)
891 gcc_assert (regno
< reg_info_size
);
892 return (enum reg_class
) reg_pref
[regno
].altclass
;
895 /* Return the reg_class which is used by IRA for its allocation. */
897 reg_allocno_class (int regno
)
902 gcc_assert (regno
< reg_info_size
);
903 return (enum reg_class
) reg_pref
[regno
].allocnoclass
;
908 /* Allocate space for reg info and initilize it. */
910 allocate_reg_info (void)
914 max_regno_since_last_resize
= max_reg_num ();
915 reg_info_size
= max_regno_since_last_resize
* 3 / 2 + 1;
916 gcc_assert (! reg_pref
&& ! reg_renumber
);
917 reg_renumber
= XNEWVEC (short, reg_info_size
);
918 reg_pref
= XCNEWVEC (struct reg_pref
, reg_info_size
);
919 memset (reg_renumber
, -1, reg_info_size
* sizeof (short));
920 for (i
= 0; i
< reg_info_size
; i
++)
922 reg_pref
[i
].prefclass
= GENERAL_REGS
;
923 reg_pref
[i
].altclass
= ALL_REGS
;
924 reg_pref
[i
].allocnoclass
= GENERAL_REGS
;
929 /* Resize reg info. The new elements will be initialized. Return TRUE
930 if new pseudos were added since the last call. */
932 resize_reg_info (void)
937 if (reg_pref
== NULL
)
939 allocate_reg_info ();
942 change_p
= max_regno_since_last_resize
!= max_reg_num ();
943 max_regno_since_last_resize
= max_reg_num ();
944 if (reg_info_size
>= max_reg_num ())
947 reg_info_size
= max_reg_num () * 3 / 2 + 1;
948 gcc_assert (reg_pref
&& reg_renumber
);
949 reg_renumber
= XRESIZEVEC (short, reg_renumber
, reg_info_size
);
950 reg_pref
= XRESIZEVEC (struct reg_pref
, reg_pref
, reg_info_size
);
951 memset (reg_pref
+ old
, -1,
952 (reg_info_size
- old
) * sizeof (struct reg_pref
));
953 memset (reg_renumber
+ old
, -1, (reg_info_size
- old
) * sizeof (short));
954 for (i
= old
; i
< reg_info_size
; i
++)
956 reg_pref
[i
].prefclass
= GENERAL_REGS
;
957 reg_pref
[i
].altclass
= ALL_REGS
;
958 reg_pref
[i
].allocnoclass
= GENERAL_REGS
;
964 /* Free up the space allocated by allocate_reg_info. */
981 /* Initialize some global data for this pass. */
986 df_compute_regs_ever_live (true);
988 /* This prevents dump_reg_info from losing if called
989 before reginfo is run. */
991 reg_info_size
= max_regno_since_last_resize
= 0;
992 /* No more global register variables may be declared. */
993 no_global_reg_vars
= 1;
999 const pass_data pass_data_reginfo_init
=
1001 RTL_PASS
, /* type */
1002 "reginfo", /* name */
1003 OPTGROUP_NONE
, /* optinfo_flags */
1004 TV_NONE
, /* tv_id */
1005 0, /* properties_required */
1006 0, /* properties_provided */
1007 0, /* properties_destroyed */
1008 0, /* todo_flags_start */
1009 0, /* todo_flags_finish */
1012 class pass_reginfo_init
: public rtl_opt_pass
1015 pass_reginfo_init (gcc::context
*ctxt
)
1016 : rtl_opt_pass (pass_data_reginfo_init
, ctxt
)
1019 /* opt_pass methods: */
1020 virtual unsigned int execute (function
*) { return reginfo_init (); }
1022 }; // class pass_reginfo_init
1027 make_pass_reginfo_init (gcc::context
*ctxt
)
1029 return new pass_reginfo_init (ctxt
);
1034 /* Set up preferred, alternate, and allocno classes for REGNO as
1035 PREFCLASS, ALTCLASS, and ALLOCNOCLASS. */
1037 setup_reg_classes (int regno
,
1038 enum reg_class prefclass
, enum reg_class altclass
,
1039 enum reg_class allocnoclass
)
1041 if (reg_pref
== NULL
)
1043 gcc_assert (reg_info_size
>= max_reg_num ());
1044 reg_pref
[regno
].prefclass
= prefclass
;
1045 reg_pref
[regno
].altclass
= altclass
;
1046 reg_pref
[regno
].allocnoclass
= allocnoclass
;
1050 /* This is the `regscan' pass of the compiler, run just before cse and
1051 again just before loop. It finds the first and last use of each
1054 static void reg_scan_mark_refs (rtx
, rtx_insn
*);
1057 reg_scan (rtx_insn
*f
, unsigned int nregs ATTRIBUTE_UNUSED
)
1061 timevar_push (TV_REG_SCAN
);
1063 for (insn
= f
; insn
; insn
= NEXT_INSN (insn
))
1066 reg_scan_mark_refs (PATTERN (insn
), insn
);
1067 if (REG_NOTES (insn
))
1068 reg_scan_mark_refs (REG_NOTES (insn
), insn
);
1071 timevar_pop (TV_REG_SCAN
);
1075 /* X is the expression to scan. INSN is the insn it appears in.
1076 NOTE_FLAG is nonzero if X is from INSN's notes rather than its body.
1077 We should only record information for REGs with numbers
1078 greater than or equal to MIN_REGNO. */
1080 reg_scan_mark_refs (rtx x
, rtx_insn
*insn
)
1088 code
= GET_CODE (x
);
1104 reg_scan_mark_refs (XEXP (x
, 0), insn
);
1106 reg_scan_mark_refs (XEXP (x
, 1), insn
);
1112 reg_scan_mark_refs (XEXP (x
, 1), insn
);
1116 if (MEM_P (XEXP (x
, 0)))
1117 reg_scan_mark_refs (XEXP (XEXP (x
, 0), 0), insn
);
1121 /* Count a set of the destination if it is a register. */
1122 for (dest
= SET_DEST (x
);
1123 GET_CODE (dest
) == SUBREG
|| GET_CODE (dest
) == STRICT_LOW_PART
1124 || GET_CODE (dest
) == ZERO_EXTRACT
;
1125 dest
= XEXP (dest
, 0))
1128 /* If this is setting a pseudo from another pseudo or the sum of a
1129 pseudo and a constant integer and the other pseudo is known to be
1130 a pointer, set the destination to be a pointer as well.
1132 Likewise if it is setting the destination from an address or from a
1133 value equivalent to an address or to the sum of an address and
1136 But don't do any of this if the pseudo corresponds to a user
1137 variable since it should have already been set as a pointer based
1140 if (REG_P (SET_DEST (x
))
1141 && REGNO (SET_DEST (x
)) >= FIRST_PSEUDO_REGISTER
1142 /* If the destination pseudo is set more than once, then other
1143 sets might not be to a pointer value (consider access to a
1144 union in two threads of control in the presence of global
1145 optimizations). So only set REG_POINTER on the destination
1146 pseudo if this is the only set of that pseudo. */
1147 && DF_REG_DEF_COUNT (REGNO (SET_DEST (x
))) == 1
1148 && ! REG_USERVAR_P (SET_DEST (x
))
1149 && ! REG_POINTER (SET_DEST (x
))
1150 && ((REG_P (SET_SRC (x
))
1151 && REG_POINTER (SET_SRC (x
)))
1152 || ((GET_CODE (SET_SRC (x
)) == PLUS
1153 || GET_CODE (SET_SRC (x
)) == LO_SUM
)
1154 && CONST_INT_P (XEXP (SET_SRC (x
), 1))
1155 && REG_P (XEXP (SET_SRC (x
), 0))
1156 && REG_POINTER (XEXP (SET_SRC (x
), 0)))
1157 || GET_CODE (SET_SRC (x
)) == CONST
1158 || GET_CODE (SET_SRC (x
)) == SYMBOL_REF
1159 || GET_CODE (SET_SRC (x
)) == LABEL_REF
1160 || (GET_CODE (SET_SRC (x
)) == HIGH
1161 && (GET_CODE (XEXP (SET_SRC (x
), 0)) == CONST
1162 || GET_CODE (XEXP (SET_SRC (x
), 0)) == SYMBOL_REF
1163 || GET_CODE (XEXP (SET_SRC (x
), 0)) == LABEL_REF
))
1164 || ((GET_CODE (SET_SRC (x
)) == PLUS
1165 || GET_CODE (SET_SRC (x
)) == LO_SUM
)
1166 && (GET_CODE (XEXP (SET_SRC (x
), 1)) == CONST
1167 || GET_CODE (XEXP (SET_SRC (x
), 1)) == SYMBOL_REF
1168 || GET_CODE (XEXP (SET_SRC (x
), 1)) == LABEL_REF
))
1169 || ((note
= find_reg_note (insn
, REG_EQUAL
, 0)) != 0
1170 && (GET_CODE (XEXP (note
, 0)) == CONST
1171 || GET_CODE (XEXP (note
, 0)) == SYMBOL_REF
1172 || GET_CODE (XEXP (note
, 0)) == LABEL_REF
))))
1173 REG_POINTER (SET_DEST (x
)) = 1;
1175 /* If this is setting a register from a register or from a simple
1176 conversion of a register, propagate REG_EXPR. */
1177 if (REG_P (dest
) && !REG_ATTRS (dest
))
1178 set_reg_attrs_from_value (dest
, SET_SRC (x
));
1180 /* ... fall through ... */
1184 const char *fmt
= GET_RTX_FORMAT (code
);
1186 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
1189 reg_scan_mark_refs (XEXP (x
, i
), insn
);
1190 else if (fmt
[i
] == 'E' && XVEC (x
, i
) != 0)
1193 for (j
= XVECLEN (x
, i
) - 1; j
>= 0; j
--)
1194 reg_scan_mark_refs (XVECEXP (x
, i
, j
), insn
);
1202 /* Return nonzero if C1 is a subset of C2, i.e., if every register in C1
1205 reg_class_subset_p (reg_class_t c1
, reg_class_t c2
)
1209 || hard_reg_set_subset_p (reg_class_contents
[(int) c1
],
1210 reg_class_contents
[(int) c2
]));
1213 /* Return nonzero if there is a register that is in both C1 and C2. */
1215 reg_classes_intersect_p (reg_class_t c1
, reg_class_t c2
)
1220 || hard_reg_set_intersect_p (reg_class_contents
[(int) c1
],
1221 reg_class_contents
[(int) c2
]));
1226 simplifiable_subregs_hasher::hash (const simplifiable_subreg
*value
)
1228 return value
->shape
.unique_id ();
1232 simplifiable_subregs_hasher::equal (const simplifiable_subreg
*value
,
1233 const subreg_shape
*compare
)
1235 return value
->shape
== *compare
;
1238 inline simplifiable_subreg::simplifiable_subreg (const subreg_shape
&shape_in
)
1241 CLEAR_HARD_REG_SET (simplifiable_regs
);
1244 /* Return the set of hard registers that are able to form the subreg
1245 described by SHAPE. */
1247 const HARD_REG_SET
&
1248 simplifiable_subregs (const subreg_shape
&shape
)
1250 if (!this_target_hard_regs
->x_simplifiable_subregs
)
1251 this_target_hard_regs
->x_simplifiable_subregs
1252 = new hash_table
<simplifiable_subregs_hasher
> (30);
1253 simplifiable_subreg
**slot
1254 = (this_target_hard_regs
->x_simplifiable_subregs
1255 ->find_slot_with_hash (&shape
, shape
.unique_id (), INSERT
));
1259 simplifiable_subreg
*info
= new simplifiable_subreg (shape
);
1260 for (unsigned int i
= 0; i
< FIRST_PSEUDO_REGISTER
; ++i
)
1261 if (HARD_REGNO_MODE_OK (i
, shape
.inner_mode
)
1262 && simplify_subreg_regno (i
, shape
.inner_mode
, shape
.offset
,
1263 shape
.outer_mode
) >= 0)
1264 SET_HARD_REG_BIT (info
->simplifiable_regs
, i
);
1267 return (*slot
)->simplifiable_regs
;
1270 /* Passes for keeping and updating info about modes of registers
1271 inside subregisters. */
1273 static HARD_REG_SET
**valid_mode_changes
;
1274 static obstack valid_mode_changes_obstack
;
1277 record_subregs_of_mode (rtx subreg
)
1281 if (!REG_P (SUBREG_REG (subreg
)))
1284 regno
= REGNO (SUBREG_REG (subreg
));
1285 if (regno
< FIRST_PSEUDO_REGISTER
)
1288 if (valid_mode_changes
[regno
])
1289 AND_HARD_REG_SET (*valid_mode_changes
[regno
],
1290 simplifiable_subregs (shape_of_subreg (subreg
)));
1293 valid_mode_changes
[regno
]
1294 = XOBNEW (&valid_mode_changes_obstack
, HARD_REG_SET
);
1295 COPY_HARD_REG_SET (*valid_mode_changes
[regno
],
1296 simplifiable_subregs (shape_of_subreg (subreg
)));
1300 /* Call record_subregs_of_mode for all the subregs in X. */
1302 find_subregs_of_mode (rtx x
)
1304 enum rtx_code code
= GET_CODE (x
);
1305 const char * const fmt
= GET_RTX_FORMAT (code
);
1309 record_subregs_of_mode (x
);
1311 /* Time for some deep diving. */
1312 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
1315 find_subregs_of_mode (XEXP (x
, i
));
1316 else if (fmt
[i
] == 'E')
1319 for (j
= XVECLEN (x
, i
) - 1; j
>= 0; j
--)
1320 find_subregs_of_mode (XVECEXP (x
, i
, j
));
1326 init_subregs_of_mode (void)
1331 gcc_obstack_init (&valid_mode_changes_obstack
);
1332 valid_mode_changes
= XCNEWVEC (HARD_REG_SET
*, max_reg_num ());
1334 FOR_EACH_BB_FN (bb
, cfun
)
1335 FOR_BB_INSNS (bb
, insn
)
1336 if (NONDEBUG_INSN_P (insn
))
1337 find_subregs_of_mode (PATTERN (insn
));
1340 const HARD_REG_SET
*
1341 valid_mode_changes_for_regno (unsigned int regno
)
1343 return valid_mode_changes
[regno
];
1347 finish_subregs_of_mode (void)
1349 XDELETEVEC (valid_mode_changes
);
1350 obstack_free (&valid_mode_changes_obstack
, NULL
);
1353 /* Free all data attached to the structure. This isn't a destructor because
1354 we don't want to run on exit. */
1357 target_hard_regs::finalize ()
1359 delete x_simplifiable_subregs
;