1 /* Reload pseudo regs into hard regs for insns that require hard regs.
2 Copyright (C) 1987, 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
4 2011, 2012 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/>. */
24 #include "coretypes.h"
28 #include "hard-reg-set.h"
29 #include "rtl-error.h"
32 #include "insn-config.h"
39 #include "addresses.h"
40 #include "basic-block.h"
51 /* This file contains the reload pass of the compiler, which is
52 run after register allocation has been done. It checks that
53 each insn is valid (operands required to be in registers really
54 are in registers of the proper class) and fixes up invalid ones
55 by copying values temporarily into registers for the insns
58 The results of register allocation are described by the vector
59 reg_renumber; the insns still contain pseudo regs, but reg_renumber
60 can be used to find which hard reg, if any, a pseudo reg is in.
62 The technique we always use is to free up a few hard regs that are
63 called ``reload regs'', and for each place where a pseudo reg
64 must be in a hard reg, copy it temporarily into one of the reload regs.
66 Reload regs are allocated locally for every instruction that needs
67 reloads. When there are pseudos which are allocated to a register that
68 has been chosen as a reload reg, such pseudos must be ``spilled''.
69 This means that they go to other hard regs, or to stack slots if no other
70 available hard regs can be found. Spilling can invalidate more
71 insns, requiring additional need for reloads, so we must keep checking
72 until the process stabilizes.
74 For machines with different classes of registers, we must keep track
75 of the register class needed for each reload, and make sure that
76 we allocate enough reload registers of each class.
78 The file reload.c contains the code that checks one insn for
79 validity and reports the reloads that it needs. This file
80 is in charge of scanning the entire rtl code, accumulating the
81 reload needs, spilling, assigning reload registers to use for
82 fixing up each insn, and generating the new insns to copy values
83 into the reload registers. */
85 struct target_reload default_target_reload
;
87 struct target_reload
*this_target_reload
= &default_target_reload
;
90 #define spill_indirect_levels \
91 (this_target_reload->x_spill_indirect_levels)
93 /* During reload_as_needed, element N contains a REG rtx for the hard reg
94 into which reg N has been reloaded (perhaps for a previous insn). */
95 static rtx
*reg_last_reload_reg
;
97 /* Elt N nonzero if reg_last_reload_reg[N] has been set in this insn
98 for an output reload that stores into reg N. */
99 static regset_head reg_has_output_reload
;
101 /* Indicates which hard regs are reload-registers for an output reload
102 in the current insn. */
103 static HARD_REG_SET reg_is_output_reload
;
105 /* Widest width in which each pseudo reg is referred to (via subreg). */
106 static unsigned int *reg_max_ref_width
;
108 /* Vector to remember old contents of reg_renumber before spilling. */
109 static short *reg_old_renumber
;
111 /* During reload_as_needed, element N contains the last pseudo regno reloaded
112 into hard register N. If that pseudo reg occupied more than one register,
113 reg_reloaded_contents points to that pseudo for each spill register in
114 use; all of these must remain set for an inheritance to occur. */
115 static int reg_reloaded_contents
[FIRST_PSEUDO_REGISTER
];
117 /* During reload_as_needed, element N contains the insn for which
118 hard register N was last used. Its contents are significant only
119 when reg_reloaded_valid is set for this register. */
120 static rtx reg_reloaded_insn
[FIRST_PSEUDO_REGISTER
];
122 /* Indicate if reg_reloaded_insn / reg_reloaded_contents is valid. */
123 static HARD_REG_SET reg_reloaded_valid
;
124 /* Indicate if the register was dead at the end of the reload.
125 This is only valid if reg_reloaded_contents is set and valid. */
126 static HARD_REG_SET reg_reloaded_dead
;
128 /* Indicate whether the register's current value is one that is not
129 safe to retain across a call, even for registers that are normally
130 call-saved. This is only meaningful for members of reg_reloaded_valid. */
131 static HARD_REG_SET reg_reloaded_call_part_clobbered
;
133 /* Number of spill-regs so far; number of valid elements of spill_regs. */
136 /* In parallel with spill_regs, contains REG rtx's for those regs.
137 Holds the last rtx used for any given reg, or 0 if it has never
138 been used for spilling yet. This rtx is reused, provided it has
140 static rtx spill_reg_rtx
[FIRST_PSEUDO_REGISTER
];
142 /* In parallel with spill_regs, contains nonzero for a spill reg
143 that was stored after the last time it was used.
144 The precise value is the insn generated to do the store. */
145 static rtx spill_reg_store
[FIRST_PSEUDO_REGISTER
];
147 /* This is the register that was stored with spill_reg_store. This is a
148 copy of reload_out / reload_out_reg when the value was stored; if
149 reload_out is a MEM, spill_reg_stored_to will be set to reload_out_reg. */
150 static rtx spill_reg_stored_to
[FIRST_PSEUDO_REGISTER
];
152 /* This table is the inverse mapping of spill_regs:
153 indexed by hard reg number,
154 it contains the position of that reg in spill_regs,
155 or -1 for something that is not in spill_regs.
157 ?!? This is no longer accurate. */
158 static short spill_reg_order
[FIRST_PSEUDO_REGISTER
];
160 /* This reg set indicates registers that can't be used as spill registers for
161 the currently processed insn. These are the hard registers which are live
162 during the insn, but not allocated to pseudos, as well as fixed
164 static HARD_REG_SET bad_spill_regs
;
166 /* These are the hard registers that can't be used as spill register for any
167 insn. This includes registers used for user variables and registers that
168 we can't eliminate. A register that appears in this set also can't be used
169 to retry register allocation. */
170 static HARD_REG_SET bad_spill_regs_global
;
172 /* Describes order of use of registers for reloading
173 of spilled pseudo-registers. `n_spills' is the number of
174 elements that are actually valid; new ones are added at the end.
176 Both spill_regs and spill_reg_order are used on two occasions:
177 once during find_reload_regs, where they keep track of the spill registers
178 for a single insn, but also during reload_as_needed where they show all
179 the registers ever used by reload. For the latter case, the information
180 is calculated during finish_spills. */
181 static short spill_regs
[FIRST_PSEUDO_REGISTER
];
183 /* This vector of reg sets indicates, for each pseudo, which hard registers
184 may not be used for retrying global allocation because the register was
185 formerly spilled from one of them. If we allowed reallocating a pseudo to
186 a register that it was already allocated to, reload might not
188 static HARD_REG_SET
*pseudo_previous_regs
;
190 /* This vector of reg sets indicates, for each pseudo, which hard
191 registers may not be used for retrying global allocation because they
192 are used as spill registers during one of the insns in which the
194 static HARD_REG_SET
*pseudo_forbidden_regs
;
196 /* All hard regs that have been used as spill registers for any insn are
197 marked in this set. */
198 static HARD_REG_SET used_spill_regs
;
200 /* Index of last register assigned as a spill register. We allocate in
201 a round-robin fashion. */
202 static int last_spill_reg
;
204 /* Record the stack slot for each spilled hard register. */
205 static rtx spill_stack_slot
[FIRST_PSEUDO_REGISTER
];
207 /* Width allocated so far for that stack slot. */
208 static unsigned int spill_stack_slot_width
[FIRST_PSEUDO_REGISTER
];
210 /* Record which pseudos needed to be spilled. */
211 static regset_head spilled_pseudos
;
213 /* Record which pseudos changed their allocation in finish_spills. */
214 static regset_head changed_allocation_pseudos
;
216 /* Used for communication between order_regs_for_reload and count_pseudo.
217 Used to avoid counting one pseudo twice. */
218 static regset_head pseudos_counted
;
220 /* First uid used by insns created by reload in this function.
221 Used in find_equiv_reg. */
222 int reload_first_uid
;
224 /* Flag set by local-alloc or global-alloc if anything is live in
225 a call-clobbered reg across calls. */
226 int caller_save_needed
;
228 /* Set to 1 while reload_as_needed is operating.
229 Required by some machines to handle any generated moves differently. */
230 int reload_in_progress
= 0;
232 /* This obstack is used for allocation of rtl during register elimination.
233 The allocated storage can be freed once find_reloads has processed the
235 static struct obstack reload_obstack
;
237 /* Points to the beginning of the reload_obstack. All insn_chain structures
238 are allocated first. */
239 static char *reload_startobj
;
241 /* The point after all insn_chain structures. Used to quickly deallocate
242 memory allocated in copy_reloads during calculate_needs_all_insns. */
243 static char *reload_firstobj
;
245 /* This points before all local rtl generated by register elimination.
246 Used to quickly free all memory after processing one insn. */
247 static char *reload_insn_firstobj
;
249 /* List of insn_chain instructions, one for every insn that reload needs to
251 struct insn_chain
*reload_insn_chain
;
253 /* TRUE if we potentially left dead insns in the insn stream and want to
254 run DCE immediately after reload, FALSE otherwise. */
255 static bool need_dce
;
257 /* List of all insns needing reloads. */
258 static struct insn_chain
*insns_need_reload
;
260 /* This structure is used to record information about register eliminations.
261 Each array entry describes one possible way of eliminating a register
262 in favor of another. If there is more than one way of eliminating a
263 particular register, the most preferred should be specified first. */
267 int from
; /* Register number to be eliminated. */
268 int to
; /* Register number used as replacement. */
269 HOST_WIDE_INT initial_offset
; /* Initial difference between values. */
270 int can_eliminate
; /* Nonzero if this elimination can be done. */
271 int can_eliminate_previous
; /* Value returned by TARGET_CAN_ELIMINATE
272 target hook in previous scan over insns
274 HOST_WIDE_INT offset
; /* Current offset between the two regs. */
275 HOST_WIDE_INT previous_offset
;/* Offset at end of previous insn. */
276 int ref_outside_mem
; /* "to" has been referenced outside a MEM. */
277 rtx from_rtx
; /* REG rtx for the register to be eliminated.
278 We cannot simply compare the number since
279 we might then spuriously replace a hard
280 register corresponding to a pseudo
281 assigned to the reg to be eliminated. */
282 rtx to_rtx
; /* REG rtx for the replacement. */
285 static struct elim_table
*reg_eliminate
= 0;
287 /* This is an intermediate structure to initialize the table. It has
288 exactly the members provided by ELIMINABLE_REGS. */
289 static const struct elim_table_1
293 } reg_eliminate_1
[] =
295 /* If a set of eliminable registers was specified, define the table from it.
296 Otherwise, default to the normal case of the frame pointer being
297 replaced by the stack pointer. */
299 #ifdef ELIMINABLE_REGS
302 {{ FRAME_POINTER_REGNUM
, STACK_POINTER_REGNUM
}};
305 #define NUM_ELIMINABLE_REGS ARRAY_SIZE (reg_eliminate_1)
307 /* Record the number of pending eliminations that have an offset not equal
308 to their initial offset. If nonzero, we use a new copy of each
309 replacement result in any insns encountered. */
310 int num_not_at_initial_offset
;
312 /* Count the number of registers that we may be able to eliminate. */
313 static int num_eliminable
;
314 /* And the number of registers that are equivalent to a constant that
315 can be eliminated to frame_pointer / arg_pointer + constant. */
316 static int num_eliminable_invariants
;
318 /* For each label, we record the offset of each elimination. If we reach
319 a label by more than one path and an offset differs, we cannot do the
320 elimination. This information is indexed by the difference of the
321 number of the label and the first label number. We can't offset the
322 pointer itself as this can cause problems on machines with segmented
323 memory. The first table is an array of flags that records whether we
324 have yet encountered a label and the second table is an array of arrays,
325 one entry in the latter array for each elimination. */
327 static int first_label_num
;
328 static char *offsets_known_at
;
329 static HOST_WIDE_INT (*offsets_at
)[NUM_ELIMINABLE_REGS
];
331 VEC(reg_equivs_t
,gc
) *reg_equivs
;
333 /* Stack of addresses where an rtx has been changed. We can undo the
334 changes by popping items off the stack and restoring the original
335 value at each location.
337 We use this simplistic undo capability rather than copy_rtx as copy_rtx
338 will not make a deep copy of a normally sharable rtx, such as
339 (const (plus (symbol_ref) (const_int))). If such an expression appears
340 as R1 in gen_reload_chain_without_interm_reg_p, then a shared
341 rtx expression would be changed. See PR 42431. */
345 DEF_VEC_ALLOC_P(rtx_p
,heap
);
346 static VEC(rtx_p
,heap
) *substitute_stack
;
348 /* Number of labels in the current function. */
350 static int num_labels
;
352 static void replace_pseudos_in (rtx
*, enum machine_mode
, rtx
);
353 static void maybe_fix_stack_asms (void);
354 static void copy_reloads (struct insn_chain
*);
355 static void calculate_needs_all_insns (int);
356 static int find_reg (struct insn_chain
*, int);
357 static void find_reload_regs (struct insn_chain
*);
358 static void select_reload_regs (void);
359 static void delete_caller_save_insns (void);
361 static void spill_failure (rtx
, enum reg_class
);
362 static void count_spilled_pseudo (int, int, int);
363 static void delete_dead_insn (rtx
);
364 static void alter_reg (int, int, bool);
365 static void set_label_offsets (rtx
, rtx
, int);
366 static void check_eliminable_occurrences (rtx
);
367 static void elimination_effects (rtx
, enum machine_mode
);
368 static rtx
eliminate_regs_1 (rtx
, enum machine_mode
, rtx
, bool, bool);
369 static int eliminate_regs_in_insn (rtx
, int);
370 static void update_eliminable_offsets (void);
371 static void mark_not_eliminable (rtx
, const_rtx
, void *);
372 static void set_initial_elim_offsets (void);
373 static bool verify_initial_elim_offsets (void);
374 static void set_initial_label_offsets (void);
375 static void set_offsets_for_label (rtx
);
376 static void init_eliminable_invariants (rtx
, bool);
377 static void init_elim_table (void);
378 static void free_reg_equiv (void);
379 static void update_eliminables (HARD_REG_SET
*);
380 static void elimination_costs_in_insn (rtx
);
381 static void spill_hard_reg (unsigned int, int);
382 static int finish_spills (int);
383 static void scan_paradoxical_subregs (rtx
);
384 static void count_pseudo (int);
385 static void order_regs_for_reload (struct insn_chain
*);
386 static void reload_as_needed (int);
387 static void forget_old_reloads_1 (rtx
, const_rtx
, void *);
388 static void forget_marked_reloads (regset
);
389 static int reload_reg_class_lower (const void *, const void *);
390 static void mark_reload_reg_in_use (unsigned int, int, enum reload_type
,
392 static void clear_reload_reg_in_use (unsigned int, int, enum reload_type
,
394 static int reload_reg_free_p (unsigned int, int, enum reload_type
);
395 static int reload_reg_free_for_value_p (int, int, int, enum reload_type
,
397 static int free_for_value_p (int, enum machine_mode
, int, enum reload_type
,
399 static int allocate_reload_reg (struct insn_chain
*, int, int);
400 static int conflicts_with_override (rtx
);
401 static void failed_reload (rtx
, int);
402 static int set_reload_reg (int, int);
403 static void choose_reload_regs_init (struct insn_chain
*, rtx
*);
404 static void choose_reload_regs (struct insn_chain
*);
405 static void emit_input_reload_insns (struct insn_chain
*, struct reload
*,
407 static void emit_output_reload_insns (struct insn_chain
*, struct reload
*,
409 static void do_input_reload (struct insn_chain
*, struct reload
*, int);
410 static void do_output_reload (struct insn_chain
*, struct reload
*, int);
411 static void emit_reload_insns (struct insn_chain
*);
412 static void delete_output_reload (rtx
, int, int, rtx
);
413 static void delete_address_reloads (rtx
, rtx
);
414 static void delete_address_reloads_1 (rtx
, rtx
, rtx
);
415 static void inc_for_reload (rtx
, rtx
, rtx
, int);
417 static void add_auto_inc_notes (rtx
, rtx
);
419 static void substitute (rtx
*, const_rtx
, rtx
);
420 static bool gen_reload_chain_without_interm_reg_p (int, int);
421 static int reloads_conflict (int, int);
422 static rtx
gen_reload (rtx
, rtx
, int, enum reload_type
);
423 static rtx
emit_insn_if_valid_for_reload (rtx
);
425 /* Initialize the reload pass. This is called at the beginning of compilation
426 and may be called again if the target is reinitialized. */
433 /* Often (MEM (REG n)) is still valid even if (REG n) is put on the stack.
434 Set spill_indirect_levels to the number of levels such addressing is
435 permitted, zero if it is not permitted at all. */
438 = gen_rtx_MEM (Pmode
,
441 LAST_VIRTUAL_REGISTER
+ 1),
443 spill_indirect_levels
= 0;
445 while (memory_address_p (QImode
, tem
))
447 spill_indirect_levels
++;
448 tem
= gen_rtx_MEM (Pmode
, tem
);
451 /* See if indirect addressing is valid for (MEM (SYMBOL_REF ...)). */
453 tem
= gen_rtx_MEM (Pmode
, gen_rtx_SYMBOL_REF (Pmode
, "foo"));
454 indirect_symref_ok
= memory_address_p (QImode
, tem
);
456 /* See if reg+reg is a valid (and offsettable) address. */
458 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
460 tem
= gen_rtx_PLUS (Pmode
,
461 gen_rtx_REG (Pmode
, HARD_FRAME_POINTER_REGNUM
),
462 gen_rtx_REG (Pmode
, i
));
464 /* This way, we make sure that reg+reg is an offsettable address. */
465 tem
= plus_constant (Pmode
, tem
, 4);
467 if (memory_address_p (QImode
, tem
))
469 double_reg_address_ok
= 1;
474 /* Initialize obstack for our rtl allocation. */
475 gcc_obstack_init (&reload_obstack
);
476 reload_startobj
= XOBNEWVAR (&reload_obstack
, char, 0);
478 INIT_REG_SET (&spilled_pseudos
);
479 INIT_REG_SET (&changed_allocation_pseudos
);
480 INIT_REG_SET (&pseudos_counted
);
483 /* List of insn chains that are currently unused. */
484 static struct insn_chain
*unused_insn_chains
= 0;
486 /* Allocate an empty insn_chain structure. */
488 new_insn_chain (void)
490 struct insn_chain
*c
;
492 if (unused_insn_chains
== 0)
494 c
= XOBNEW (&reload_obstack
, struct insn_chain
);
495 INIT_REG_SET (&c
->live_throughout
);
496 INIT_REG_SET (&c
->dead_or_set
);
500 c
= unused_insn_chains
;
501 unused_insn_chains
= c
->next
;
503 c
->is_caller_save_insn
= 0;
504 c
->need_operand_change
= 0;
510 /* Small utility function to set all regs in hard reg set TO which are
511 allocated to pseudos in regset FROM. */
514 compute_use_by_pseudos (HARD_REG_SET
*to
, regset from
)
517 reg_set_iterator rsi
;
519 EXECUTE_IF_SET_IN_REG_SET (from
, FIRST_PSEUDO_REGISTER
, regno
, rsi
)
521 int r
= reg_renumber
[regno
];
525 /* reload_combine uses the information from DF_LIVE_IN,
526 which might still contain registers that have not
527 actually been allocated since they have an
529 gcc_assert (ira_conflicts_p
|| reload_completed
);
532 add_to_hard_reg_set (to
, PSEUDO_REGNO_MODE (regno
), r
);
536 /* Replace all pseudos found in LOC with their corresponding
540 replace_pseudos_in (rtx
*loc
, enum machine_mode mem_mode
, rtx usage
)
553 unsigned int regno
= REGNO (x
);
555 if (regno
< FIRST_PSEUDO_REGISTER
)
558 x
= eliminate_regs_1 (x
, mem_mode
, usage
, true, false);
562 replace_pseudos_in (loc
, mem_mode
, usage
);
566 if (reg_equiv_constant (regno
))
567 *loc
= reg_equiv_constant (regno
);
568 else if (reg_equiv_invariant (regno
))
569 *loc
= reg_equiv_invariant (regno
);
570 else if (reg_equiv_mem (regno
))
571 *loc
= reg_equiv_mem (regno
);
572 else if (reg_equiv_address (regno
))
573 *loc
= gen_rtx_MEM (GET_MODE (x
), reg_equiv_address (regno
));
576 gcc_assert (!REG_P (regno_reg_rtx
[regno
])
577 || REGNO (regno_reg_rtx
[regno
]) != regno
);
578 *loc
= regno_reg_rtx
[regno
];
583 else if (code
== MEM
)
585 replace_pseudos_in (& XEXP (x
, 0), GET_MODE (x
), usage
);
589 /* Process each of our operands recursively. */
590 fmt
= GET_RTX_FORMAT (code
);
591 for (i
= 0; i
< GET_RTX_LENGTH (code
); i
++, fmt
++)
593 replace_pseudos_in (&XEXP (x
, i
), mem_mode
, usage
);
594 else if (*fmt
== 'E')
595 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
596 replace_pseudos_in (& XVECEXP (x
, i
, j
), mem_mode
, usage
);
599 /* Determine if the current function has an exception receiver block
600 that reaches the exit block via non-exceptional edges */
603 has_nonexceptional_receiver (void)
607 basic_block
*tos
, *worklist
, bb
;
609 /* If we're not optimizing, then just err on the safe side. */
613 /* First determine which blocks can reach exit via normal paths. */
614 tos
= worklist
= XNEWVEC (basic_block
, n_basic_blocks
+ 1);
617 bb
->flags
&= ~BB_REACHABLE
;
619 /* Place the exit block on our worklist. */
620 EXIT_BLOCK_PTR
->flags
|= BB_REACHABLE
;
621 *tos
++ = EXIT_BLOCK_PTR
;
623 /* Iterate: find everything reachable from what we've already seen. */
624 while (tos
!= worklist
)
628 FOR_EACH_EDGE (e
, ei
, bb
->preds
)
629 if (!(e
->flags
& EDGE_ABNORMAL
))
631 basic_block src
= e
->src
;
633 if (!(src
->flags
& BB_REACHABLE
))
635 src
->flags
|= BB_REACHABLE
;
642 /* Now see if there's a reachable block with an exceptional incoming
645 if (bb
->flags
& BB_REACHABLE
&& bb_has_abnormal_pred (bb
))
648 /* No exceptional block reached exit unexceptionally. */
652 /* Grow (or allocate) the REG_EQUIVS array from its current size (which may be
653 zero elements) to MAX_REG_NUM elements.
655 Initialize all new fields to NULL and update REG_EQUIVS_SIZE. */
657 grow_reg_equivs (void)
659 int old_size
= VEC_length (reg_equivs_t
, reg_equivs
);
660 int max_regno
= max_reg_num ();
664 memset (&ze
, 0, sizeof (reg_equivs_t
));
665 VEC_reserve (reg_equivs_t
, gc
, reg_equivs
, max_regno
);
666 for (i
= old_size
; i
< max_regno
; i
++)
667 VEC_quick_insert (reg_equivs_t
, reg_equivs
, i
, ze
);
671 /* Global variables used by reload and its subroutines. */
673 /* The current basic block while in calculate_elim_costs_all_insns. */
674 static basic_block elim_bb
;
676 /* Set during calculate_needs if an insn needs register elimination. */
677 static int something_needs_elimination
;
678 /* Set during calculate_needs if an insn needs an operand changed. */
679 static int something_needs_operands_changed
;
680 /* Set by alter_regs if we spilled a register to the stack. */
681 static bool something_was_spilled
;
683 /* Nonzero means we couldn't get enough spill regs. */
686 /* Temporary array of pseudo-register number. */
687 static int *temp_pseudo_reg_arr
;
689 /* Main entry point for the reload pass.
691 FIRST is the first insn of the function being compiled.
693 GLOBAL nonzero means we were called from global_alloc
694 and should attempt to reallocate any pseudoregs that we
695 displace from hard regs we will use for reloads.
696 If GLOBAL is zero, we do not have enough information to do that,
697 so any pseudo reg that is spilled must go to the stack.
699 Return value is TRUE if reload likely left dead insns in the
700 stream and a DCE pass should be run to elimiante them. Else the
701 return value is FALSE. */
704 reload (rtx first
, int global
)
708 struct elim_table
*ep
;
712 /* Make sure even insns with volatile mem refs are recognizable. */
717 reload_firstobj
= XOBNEWVAR (&reload_obstack
, char, 0);
719 /* Make sure that the last insn in the chain
720 is not something that needs reloading. */
721 emit_note (NOTE_INSN_DELETED
);
723 /* Enable find_equiv_reg to distinguish insns made by reload. */
724 reload_first_uid
= get_max_uid ();
726 #ifdef SECONDARY_MEMORY_NEEDED
727 /* Initialize the secondary memory table. */
728 clear_secondary_mem ();
731 /* We don't have a stack slot for any spill reg yet. */
732 memset (spill_stack_slot
, 0, sizeof spill_stack_slot
);
733 memset (spill_stack_slot_width
, 0, sizeof spill_stack_slot_width
);
735 /* Initialize the save area information for caller-save, in case some
739 /* Compute which hard registers are now in use
740 as homes for pseudo registers.
741 This is done here rather than (eg) in global_alloc
742 because this point is reached even if not optimizing. */
743 for (i
= FIRST_PSEUDO_REGISTER
; i
< max_regno
; i
++)
746 /* A function that has a nonlocal label that can reach the exit
747 block via non-exceptional paths must save all call-saved
749 if (cfun
->has_nonlocal_label
750 && has_nonexceptional_receiver ())
751 crtl
->saves_all_registers
= 1;
753 if (crtl
->saves_all_registers
)
754 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
755 if (! call_used_regs
[i
] && ! fixed_regs
[i
] && ! LOCAL_REGNO (i
))
756 df_set_regs_ever_live (i
, true);
758 /* Find all the pseudo registers that didn't get hard regs
759 but do have known equivalent constants or memory slots.
760 These include parameters (known equivalent to parameter slots)
761 and cse'd or loop-moved constant memory addresses.
763 Record constant equivalents in reg_equiv_constant
764 so they will be substituted by find_reloads.
765 Record memory equivalents in reg_mem_equiv so they can
766 be substituted eventually by altering the REG-rtx's. */
769 reg_old_renumber
= XCNEWVEC (short, max_regno
);
770 memcpy (reg_old_renumber
, reg_renumber
, max_regno
* sizeof (short));
771 pseudo_forbidden_regs
= XNEWVEC (HARD_REG_SET
, max_regno
);
772 pseudo_previous_regs
= XCNEWVEC (HARD_REG_SET
, max_regno
);
774 CLEAR_HARD_REG_SET (bad_spill_regs_global
);
776 init_eliminable_invariants (first
, true);
779 /* Alter each pseudo-reg rtx to contain its hard reg number. Assign
780 stack slots to the pseudos that lack hard regs or equivalents.
781 Do not touch virtual registers. */
783 temp_pseudo_reg_arr
= XNEWVEC (int, max_regno
- LAST_VIRTUAL_REGISTER
- 1);
784 for (n
= 0, i
= LAST_VIRTUAL_REGISTER
+ 1; i
< max_regno
; i
++)
785 temp_pseudo_reg_arr
[n
++] = i
;
788 /* Ask IRA to order pseudo-registers for better stack slot
790 ira_sort_regnos_for_alter_reg (temp_pseudo_reg_arr
, n
, reg_max_ref_width
);
792 for (i
= 0; i
< n
; i
++)
793 alter_reg (temp_pseudo_reg_arr
[i
], -1, false);
795 /* If we have some registers we think can be eliminated, scan all insns to
796 see if there is an insn that sets one of these registers to something
797 other than itself plus a constant. If so, the register cannot be
798 eliminated. Doing this scan here eliminates an extra pass through the
799 main reload loop in the most common case where register elimination
801 for (insn
= first
; insn
&& num_eliminable
; insn
= NEXT_INSN (insn
))
803 note_stores (PATTERN (insn
), mark_not_eliminable
, NULL
);
805 maybe_fix_stack_asms ();
807 insns_need_reload
= 0;
808 something_needs_elimination
= 0;
810 /* Initialize to -1, which means take the first spill register. */
813 /* Spill any hard regs that we know we can't eliminate. */
814 CLEAR_HARD_REG_SET (used_spill_regs
);
815 /* There can be multiple ways to eliminate a register;
816 they should be listed adjacently.
817 Elimination for any register fails only if all possible ways fail. */
818 for (ep
= reg_eliminate
; ep
< ®_eliminate
[NUM_ELIMINABLE_REGS
]; )
821 int can_eliminate
= 0;
824 can_eliminate
|= ep
->can_eliminate
;
827 while (ep
< ®_eliminate
[NUM_ELIMINABLE_REGS
] && ep
->from
== from
);
829 spill_hard_reg (from
, 1);
832 #if !HARD_FRAME_POINTER_IS_FRAME_POINTER
833 if (frame_pointer_needed
)
834 spill_hard_reg (HARD_FRAME_POINTER_REGNUM
, 1);
836 finish_spills (global
);
838 /* From now on, we may need to generate moves differently. We may also
839 allow modifications of insns which cause them to not be recognized.
840 Any such modifications will be cleaned up during reload itself. */
841 reload_in_progress
= 1;
843 /* This loop scans the entire function each go-round
844 and repeats until one repetition spills no additional hard regs. */
847 int something_changed
;
849 HOST_WIDE_INT starting_frame_size
;
851 starting_frame_size
= get_frame_size ();
852 something_was_spilled
= false;
854 set_initial_elim_offsets ();
855 set_initial_label_offsets ();
857 /* For each pseudo register that has an equivalent location defined,
858 try to eliminate any eliminable registers (such as the frame pointer)
859 assuming initial offsets for the replacement register, which
862 If the resulting location is directly addressable, substitute
863 the MEM we just got directly for the old REG.
865 If it is not addressable but is a constant or the sum of a hard reg
866 and constant, it is probably not addressable because the constant is
867 out of range, in that case record the address; we will generate
868 hairy code to compute the address in a register each time it is
869 needed. Similarly if it is a hard register, but one that is not
870 valid as an address register.
872 If the location is not addressable, but does not have one of the
873 above forms, assign a stack slot. We have to do this to avoid the
874 potential of producing lots of reloads if, e.g., a location involves
875 a pseudo that didn't get a hard register and has an equivalent memory
876 location that also involves a pseudo that didn't get a hard register.
878 Perhaps at some point we will improve reload_when_needed handling
879 so this problem goes away. But that's very hairy. */
881 for (i
= FIRST_PSEUDO_REGISTER
; i
< max_regno
; i
++)
882 if (reg_renumber
[i
] < 0 && reg_equiv_memory_loc (i
))
884 rtx x
= eliminate_regs (reg_equiv_memory_loc (i
), VOIDmode
,
887 if (strict_memory_address_addr_space_p
888 (GET_MODE (regno_reg_rtx
[i
]), XEXP (x
, 0),
890 reg_equiv_mem (i
) = x
, reg_equiv_address (i
) = 0;
891 else if (CONSTANT_P (XEXP (x
, 0))
892 || (REG_P (XEXP (x
, 0))
893 && REGNO (XEXP (x
, 0)) < FIRST_PSEUDO_REGISTER
)
894 || (GET_CODE (XEXP (x
, 0)) == PLUS
895 && REG_P (XEXP (XEXP (x
, 0), 0))
896 && (REGNO (XEXP (XEXP (x
, 0), 0))
897 < FIRST_PSEUDO_REGISTER
)
898 && CONSTANT_P (XEXP (XEXP (x
, 0), 1))))
899 reg_equiv_address (i
) = XEXP (x
, 0), reg_equiv_mem (i
) = 0;
902 /* Make a new stack slot. Then indicate that something
903 changed so we go back and recompute offsets for
904 eliminable registers because the allocation of memory
905 below might change some offset. reg_equiv_{mem,address}
906 will be set up for this pseudo on the next pass around
908 reg_equiv_memory_loc (i
) = 0;
909 reg_equiv_init (i
) = 0;
910 alter_reg (i
, -1, true);
914 if (caller_save_needed
)
917 /* If we allocated another stack slot, redo elimination bookkeeping. */
918 if (something_was_spilled
|| starting_frame_size
!= get_frame_size ())
920 if (starting_frame_size
&& crtl
->stack_alignment_needed
)
922 /* If we have a stack frame, we must align it now. The
923 stack size may be a part of the offset computation for
924 register elimination. So if this changes the stack size,
925 then repeat the elimination bookkeeping. We don't
926 realign when there is no stack, as that will cause a
927 stack frame when none is needed should
928 STARTING_FRAME_OFFSET not be already aligned to
930 assign_stack_local (BLKmode
, 0, crtl
->stack_alignment_needed
);
931 if (starting_frame_size
!= get_frame_size ())
935 if (caller_save_needed
)
937 save_call_clobbered_regs ();
938 /* That might have allocated new insn_chain structures. */
939 reload_firstobj
= XOBNEWVAR (&reload_obstack
, char, 0);
942 calculate_needs_all_insns (global
);
944 if (! ira_conflicts_p
)
945 /* Don't do it for IRA. We need this info because we don't
946 change live_throughout and dead_or_set for chains when IRA
948 CLEAR_REG_SET (&spilled_pseudos
);
952 something_changed
= 0;
954 /* If we allocated any new memory locations, make another pass
955 since it might have changed elimination offsets. */
956 if (something_was_spilled
|| starting_frame_size
!= get_frame_size ())
957 something_changed
= 1;
959 /* Even if the frame size remained the same, we might still have
960 changed elimination offsets, e.g. if find_reloads called
961 force_const_mem requiring the back end to allocate a constant
962 pool base register that needs to be saved on the stack. */
963 else if (!verify_initial_elim_offsets ())
964 something_changed
= 1;
967 HARD_REG_SET to_spill
;
968 CLEAR_HARD_REG_SET (to_spill
);
969 update_eliminables (&to_spill
);
970 AND_COMPL_HARD_REG_SET (used_spill_regs
, to_spill
);
972 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
973 if (TEST_HARD_REG_BIT (to_spill
, i
))
975 spill_hard_reg (i
, 1);
978 /* Regardless of the state of spills, if we previously had
979 a register that we thought we could eliminate, but now can
980 not eliminate, we must run another pass.
982 Consider pseudos which have an entry in reg_equiv_* which
983 reference an eliminable register. We must make another pass
984 to update reg_equiv_* so that we do not substitute in the
985 old value from when we thought the elimination could be
987 something_changed
= 1;
991 select_reload_regs ();
995 if (insns_need_reload
!= 0 || did_spill
)
996 something_changed
|= finish_spills (global
);
998 if (! something_changed
)
1001 if (caller_save_needed
)
1002 delete_caller_save_insns ();
1004 obstack_free (&reload_obstack
, reload_firstobj
);
1007 /* If global-alloc was run, notify it of any register eliminations we have
1010 for (ep
= reg_eliminate
; ep
< ®_eliminate
[NUM_ELIMINABLE_REGS
]; ep
++)
1011 if (ep
->can_eliminate
)
1012 mark_elimination (ep
->from
, ep
->to
);
1014 /* If a pseudo has no hard reg, delete the insns that made the equivalence.
1015 If that insn didn't set the register (i.e., it copied the register to
1016 memory), just delete that insn instead of the equivalencing insn plus
1017 anything now dead. If we call delete_dead_insn on that insn, we may
1018 delete the insn that actually sets the register if the register dies
1019 there and that is incorrect. */
1021 for (i
= FIRST_PSEUDO_REGISTER
; i
< max_regno
; i
++)
1023 if (reg_renumber
[i
] < 0 && reg_equiv_init (i
) != 0)
1026 for (list
= reg_equiv_init (i
); list
; list
= XEXP (list
, 1))
1028 rtx equiv_insn
= XEXP (list
, 0);
1030 /* If we already deleted the insn or if it may trap, we can't
1031 delete it. The latter case shouldn't happen, but can
1032 if an insn has a variable address, gets a REG_EH_REGION
1033 note added to it, and then gets converted into a load
1034 from a constant address. */
1035 if (NOTE_P (equiv_insn
)
1036 || can_throw_internal (equiv_insn
))
1038 else if (reg_set_p (regno_reg_rtx
[i
], PATTERN (equiv_insn
)))
1039 delete_dead_insn (equiv_insn
);
1041 SET_INSN_DELETED (equiv_insn
);
1046 /* Use the reload registers where necessary
1047 by generating move instructions to move the must-be-register
1048 values into or out of the reload registers. */
1050 if (insns_need_reload
!= 0 || something_needs_elimination
1051 || something_needs_operands_changed
)
1053 HOST_WIDE_INT old_frame_size
= get_frame_size ();
1055 reload_as_needed (global
);
1057 gcc_assert (old_frame_size
== get_frame_size ());
1059 gcc_assert (verify_initial_elim_offsets ());
1062 /* If we were able to eliminate the frame pointer, show that it is no
1063 longer live at the start of any basic block. If it ls live by
1064 virtue of being in a pseudo, that pseudo will be marked live
1065 and hence the frame pointer will be known to be live via that
1068 if (! frame_pointer_needed
)
1070 bitmap_clear_bit (df_get_live_in (bb
), HARD_FRAME_POINTER_REGNUM
);
1072 /* Come here (with failure set nonzero) if we can't get enough spill
1076 CLEAR_REG_SET (&changed_allocation_pseudos
);
1077 CLEAR_REG_SET (&spilled_pseudos
);
1078 reload_in_progress
= 0;
1080 /* Now eliminate all pseudo regs by modifying them into
1081 their equivalent memory references.
1082 The REG-rtx's for the pseudos are modified in place,
1083 so all insns that used to refer to them now refer to memory.
1085 For a reg that has a reg_equiv_address, all those insns
1086 were changed by reloading so that no insns refer to it any longer;
1087 but the DECL_RTL of a variable decl may refer to it,
1088 and if so this causes the debugging info to mention the variable. */
1090 for (i
= FIRST_PSEUDO_REGISTER
; i
< max_regno
; i
++)
1094 if (reg_equiv_mem (i
))
1095 addr
= XEXP (reg_equiv_mem (i
), 0);
1097 if (reg_equiv_address (i
))
1098 addr
= reg_equiv_address (i
);
1102 if (reg_renumber
[i
] < 0)
1104 rtx reg
= regno_reg_rtx
[i
];
1106 REG_USERVAR_P (reg
) = 0;
1107 PUT_CODE (reg
, MEM
);
1108 XEXP (reg
, 0) = addr
;
1109 if (reg_equiv_memory_loc (i
))
1110 MEM_COPY_ATTRIBUTES (reg
, reg_equiv_memory_loc (i
));
1112 MEM_ATTRS (reg
) = 0;
1113 MEM_NOTRAP_P (reg
) = 1;
1115 else if (reg_equiv_mem (i
))
1116 XEXP (reg_equiv_mem (i
), 0) = addr
;
1119 /* We don't want complex addressing modes in debug insns
1120 if simpler ones will do, so delegitimize equivalences
1122 if (MAY_HAVE_DEBUG_INSNS
&& reg_renumber
[i
] < 0)
1124 rtx reg
= regno_reg_rtx
[i
];
1128 if (reg_equiv_constant (i
))
1129 equiv
= reg_equiv_constant (i
);
1130 else if (reg_equiv_invariant (i
))
1131 equiv
= reg_equiv_invariant (i
);
1132 else if (reg
&& MEM_P (reg
))
1133 equiv
= targetm
.delegitimize_address (reg
);
1134 else if (reg
&& REG_P (reg
) && (int)REGNO (reg
) != i
)
1140 for (use
= DF_REG_USE_CHAIN (i
); use
; use
= next
)
1142 insn
= DF_REF_INSN (use
);
1144 /* Make sure the next ref is for a different instruction,
1145 so that we're not affected by the rescan. */
1146 next
= DF_REF_NEXT_REG (use
);
1147 while (next
&& DF_REF_INSN (next
) == insn
)
1148 next
= DF_REF_NEXT_REG (next
);
1150 if (DEBUG_INSN_P (insn
))
1154 INSN_VAR_LOCATION_LOC (insn
) = gen_rtx_UNKNOWN_VAR_LOC ();
1155 df_insn_rescan_debug_internal (insn
);
1158 INSN_VAR_LOCATION_LOC (insn
)
1159 = simplify_replace_rtx (INSN_VAR_LOCATION_LOC (insn
),
1166 /* We must set reload_completed now since the cleanup_subreg_operands call
1167 below will re-recognize each insn and reload may have generated insns
1168 which are only valid during and after reload. */
1169 reload_completed
= 1;
1171 /* Make a pass over all the insns and delete all USEs which we inserted
1172 only to tag a REG_EQUAL note on them. Remove all REG_DEAD and REG_UNUSED
1173 notes. Delete all CLOBBER insns, except those that refer to the return
1174 value and the special mem:BLK CLOBBERs added to prevent the scheduler
1175 from misarranging variable-array code, and simplify (subreg (reg))
1176 operands. Strip and regenerate REG_INC notes that may have been moved
1179 for (insn
= first
; insn
; insn
= NEXT_INSN (insn
))
1185 replace_pseudos_in (& CALL_INSN_FUNCTION_USAGE (insn
),
1186 VOIDmode
, CALL_INSN_FUNCTION_USAGE (insn
));
1188 if ((GET_CODE (PATTERN (insn
)) == USE
1189 /* We mark with QImode USEs introduced by reload itself. */
1190 && (GET_MODE (insn
) == QImode
1191 || find_reg_note (insn
, REG_EQUAL
, NULL_RTX
)))
1192 || (GET_CODE (PATTERN (insn
)) == CLOBBER
1193 && (!MEM_P (XEXP (PATTERN (insn
), 0))
1194 || GET_MODE (XEXP (PATTERN (insn
), 0)) != BLKmode
1195 || (GET_CODE (XEXP (XEXP (PATTERN (insn
), 0), 0)) != SCRATCH
1196 && XEXP (XEXP (PATTERN (insn
), 0), 0)
1197 != stack_pointer_rtx
))
1198 && (!REG_P (XEXP (PATTERN (insn
), 0))
1199 || ! REG_FUNCTION_VALUE_P (XEXP (PATTERN (insn
), 0)))))
1205 /* Some CLOBBERs may survive until here and still reference unassigned
1206 pseudos with const equivalent, which may in turn cause ICE in later
1207 passes if the reference remains in place. */
1208 if (GET_CODE (PATTERN (insn
)) == CLOBBER
)
1209 replace_pseudos_in (& XEXP (PATTERN (insn
), 0),
1210 VOIDmode
, PATTERN (insn
));
1212 /* Discard obvious no-ops, even without -O. This optimization
1213 is fast and doesn't interfere with debugging. */
1214 if (NONJUMP_INSN_P (insn
)
1215 && GET_CODE (PATTERN (insn
)) == SET
1216 && REG_P (SET_SRC (PATTERN (insn
)))
1217 && REG_P (SET_DEST (PATTERN (insn
)))
1218 && (REGNO (SET_SRC (PATTERN (insn
)))
1219 == REGNO (SET_DEST (PATTERN (insn
)))))
1225 pnote
= ®_NOTES (insn
);
1228 if (REG_NOTE_KIND (*pnote
) == REG_DEAD
1229 || REG_NOTE_KIND (*pnote
) == REG_UNUSED
1230 || REG_NOTE_KIND (*pnote
) == REG_INC
)
1231 *pnote
= XEXP (*pnote
, 1);
1233 pnote
= &XEXP (*pnote
, 1);
1237 add_auto_inc_notes (insn
, PATTERN (insn
));
1240 /* Simplify (subreg (reg)) if it appears as an operand. */
1241 cleanup_subreg_operands (insn
);
1243 /* Clean up invalid ASMs so that they don't confuse later passes.
1245 if (asm_noperands (PATTERN (insn
)) >= 0)
1247 extract_insn (insn
);
1248 if (!constrain_operands (1))
1250 error_for_asm (insn
,
1251 "%<asm%> operand has impossible constraints");
1258 /* If we are doing generic stack checking, give a warning if this
1259 function's frame size is larger than we expect. */
1260 if (flag_stack_check
== GENERIC_STACK_CHECK
)
1262 HOST_WIDE_INT size
= get_frame_size () + STACK_CHECK_FIXED_FRAME_SIZE
;
1263 static int verbose_warned
= 0;
1265 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
1266 if (df_regs_ever_live_p (i
) && ! fixed_regs
[i
] && call_used_regs
[i
])
1267 size
+= UNITS_PER_WORD
;
1269 if (size
> STACK_CHECK_MAX_FRAME_SIZE
)
1271 warning (0, "frame size too large for reliable stack checking");
1272 if (! verbose_warned
)
1274 warning (0, "try reducing the number of local variables");
1280 free (temp_pseudo_reg_arr
);
1282 /* Indicate that we no longer have known memory locations or constants. */
1285 free (reg_max_ref_width
);
1286 free (reg_old_renumber
);
1287 free (pseudo_previous_regs
);
1288 free (pseudo_forbidden_regs
);
1290 CLEAR_HARD_REG_SET (used_spill_regs
);
1291 for (i
= 0; i
< n_spills
; i
++)
1292 SET_HARD_REG_BIT (used_spill_regs
, spill_regs
[i
]);
1294 /* Free all the insn_chain structures at once. */
1295 obstack_free (&reload_obstack
, reload_startobj
);
1296 unused_insn_chains
= 0;
1298 inserted
= fixup_abnormal_edges ();
1300 /* We've possibly turned single trapping insn into multiple ones. */
1301 if (cfun
->can_throw_non_call_exceptions
)
1304 blocks
= sbitmap_alloc (last_basic_block
);
1305 sbitmap_ones (blocks
);
1306 find_many_sub_basic_blocks (blocks
);
1307 sbitmap_free (blocks
);
1311 commit_edge_insertions ();
1313 /* Replacing pseudos with their memory equivalents might have
1314 created shared rtx. Subsequent passes would get confused
1315 by this, so unshare everything here. */
1316 unshare_all_rtl_again (first
);
1318 #ifdef STACK_BOUNDARY
1319 /* init_emit has set the alignment of the hard frame pointer
1320 to STACK_BOUNDARY. It is very likely no longer valid if
1321 the hard frame pointer was used for register allocation. */
1322 if (!frame_pointer_needed
)
1323 REGNO_POINTER_ALIGN (HARD_FRAME_POINTER_REGNUM
) = BITS_PER_UNIT
;
1326 VEC_free (rtx_p
, heap
, substitute_stack
);
1328 gcc_assert (bitmap_empty_p (&spilled_pseudos
));
1330 reload_completed
= !failure
;
1335 /* Yet another special case. Unfortunately, reg-stack forces people to
1336 write incorrect clobbers in asm statements. These clobbers must not
1337 cause the register to appear in bad_spill_regs, otherwise we'll call
1338 fatal_insn later. We clear the corresponding regnos in the live
1339 register sets to avoid this.
1340 The whole thing is rather sick, I'm afraid. */
1343 maybe_fix_stack_asms (void)
1346 const char *constraints
[MAX_RECOG_OPERANDS
];
1347 enum machine_mode operand_mode
[MAX_RECOG_OPERANDS
];
1348 struct insn_chain
*chain
;
1350 for (chain
= reload_insn_chain
; chain
!= 0; chain
= chain
->next
)
1353 HARD_REG_SET clobbered
, allowed
;
1356 if (! INSN_P (chain
->insn
)
1357 || (noperands
= asm_noperands (PATTERN (chain
->insn
))) < 0)
1359 pat
= PATTERN (chain
->insn
);
1360 if (GET_CODE (pat
) != PARALLEL
)
1363 CLEAR_HARD_REG_SET (clobbered
);
1364 CLEAR_HARD_REG_SET (allowed
);
1366 /* First, make a mask of all stack regs that are clobbered. */
1367 for (i
= 0; i
< XVECLEN (pat
, 0); i
++)
1369 rtx t
= XVECEXP (pat
, 0, i
);
1370 if (GET_CODE (t
) == CLOBBER
&& STACK_REG_P (XEXP (t
, 0)))
1371 SET_HARD_REG_BIT (clobbered
, REGNO (XEXP (t
, 0)));
1374 /* Get the operand values and constraints out of the insn. */
1375 decode_asm_operands (pat
, recog_data
.operand
, recog_data
.operand_loc
,
1376 constraints
, operand_mode
, NULL
);
1378 /* For every operand, see what registers are allowed. */
1379 for (i
= 0; i
< noperands
; i
++)
1381 const char *p
= constraints
[i
];
1382 /* For every alternative, we compute the class of registers allowed
1383 for reloading in CLS, and merge its contents into the reg set
1385 int cls
= (int) NO_REGS
;
1391 if (c
== '\0' || c
== ',' || c
== '#')
1393 /* End of one alternative - mark the regs in the current
1394 class, and reset the class. */
1395 IOR_HARD_REG_SET (allowed
, reg_class_contents
[cls
]);
1401 } while (c
!= '\0' && c
!= ',');
1409 case '=': case '+': case '*': case '%': case '?': case '!':
1410 case '0': case '1': case '2': case '3': case '4': case '<':
1411 case '>': case 'V': case 'o': case '&': case 'E': case 'F':
1412 case 's': case 'i': case 'n': case 'X': case 'I': case 'J':
1413 case 'K': case 'L': case 'M': case 'N': case 'O': case 'P':
1414 case TARGET_MEM_CONSTRAINT
:
1418 cls
= (int) reg_class_subunion
[cls
]
1419 [(int) base_reg_class (VOIDmode
, ADDR_SPACE_GENERIC
,
1425 cls
= (int) reg_class_subunion
[cls
][(int) GENERAL_REGS
];
1429 if (EXTRA_ADDRESS_CONSTRAINT (c
, p
))
1430 cls
= (int) reg_class_subunion
[cls
]
1431 [(int) base_reg_class (VOIDmode
, ADDR_SPACE_GENERIC
,
1434 cls
= (int) reg_class_subunion
[cls
]
1435 [(int) REG_CLASS_FROM_CONSTRAINT (c
, p
)];
1437 p
+= CONSTRAINT_LEN (c
, p
);
1440 /* Those of the registers which are clobbered, but allowed by the
1441 constraints, must be usable as reload registers. So clear them
1442 out of the life information. */
1443 AND_HARD_REG_SET (allowed
, clobbered
);
1444 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
1445 if (TEST_HARD_REG_BIT (allowed
, i
))
1447 CLEAR_REGNO_REG_SET (&chain
->live_throughout
, i
);
1448 CLEAR_REGNO_REG_SET (&chain
->dead_or_set
, i
);
1455 /* Copy the global variables n_reloads and rld into the corresponding elts
1458 copy_reloads (struct insn_chain
*chain
)
1460 chain
->n_reloads
= n_reloads
;
1461 chain
->rld
= XOBNEWVEC (&reload_obstack
, struct reload
, n_reloads
);
1462 memcpy (chain
->rld
, rld
, n_reloads
* sizeof (struct reload
));
1463 reload_insn_firstobj
= XOBNEWVAR (&reload_obstack
, char, 0);
1466 /* Walk the chain of insns, and determine for each whether it needs reloads
1467 and/or eliminations. Build the corresponding insns_need_reload list, and
1468 set something_needs_elimination as appropriate. */
1470 calculate_needs_all_insns (int global
)
1472 struct insn_chain
**pprev_reload
= &insns_need_reload
;
1473 struct insn_chain
*chain
, *next
= 0;
1475 something_needs_elimination
= 0;
1477 reload_insn_firstobj
= XOBNEWVAR (&reload_obstack
, char, 0);
1478 for (chain
= reload_insn_chain
; chain
!= 0; chain
= next
)
1480 rtx insn
= chain
->insn
;
1484 /* Clear out the shortcuts. */
1485 chain
->n_reloads
= 0;
1486 chain
->need_elim
= 0;
1487 chain
->need_reload
= 0;
1488 chain
->need_operand_change
= 0;
1490 /* If this is a label, a JUMP_INSN, or has REG_NOTES (which might
1491 include REG_LABEL_OPERAND and REG_LABEL_TARGET), we need to see
1492 what effects this has on the known offsets at labels. */
1494 if (LABEL_P (insn
) || JUMP_P (insn
)
1495 || (INSN_P (insn
) && REG_NOTES (insn
) != 0))
1496 set_label_offsets (insn
, insn
, 0);
1500 rtx old_body
= PATTERN (insn
);
1501 int old_code
= INSN_CODE (insn
);
1502 rtx old_notes
= REG_NOTES (insn
);
1503 int did_elimination
= 0;
1504 int operands_changed
= 0;
1505 rtx set
= single_set (insn
);
1507 /* Skip insns that only set an equivalence. */
1508 if (set
&& REG_P (SET_DEST (set
))
1509 && reg_renumber
[REGNO (SET_DEST (set
))] < 0
1510 && (reg_equiv_constant (REGNO (SET_DEST (set
)))
1511 || (reg_equiv_invariant (REGNO (SET_DEST (set
)))))
1512 && reg_equiv_init (REGNO (SET_DEST (set
))))
1515 /* If needed, eliminate any eliminable registers. */
1516 if (num_eliminable
|| num_eliminable_invariants
)
1517 did_elimination
= eliminate_regs_in_insn (insn
, 0);
1519 /* Analyze the instruction. */
1520 operands_changed
= find_reloads (insn
, 0, spill_indirect_levels
,
1521 global
, spill_reg_order
);
1523 /* If a no-op set needs more than one reload, this is likely
1524 to be something that needs input address reloads. We
1525 can't get rid of this cleanly later, and it is of no use
1526 anyway, so discard it now.
1527 We only do this when expensive_optimizations is enabled,
1528 since this complements reload inheritance / output
1529 reload deletion, and it can make debugging harder. */
1530 if (flag_expensive_optimizations
&& n_reloads
> 1)
1532 rtx set
= single_set (insn
);
1535 ((SET_SRC (set
) == SET_DEST (set
)
1536 && REG_P (SET_SRC (set
))
1537 && REGNO (SET_SRC (set
)) >= FIRST_PSEUDO_REGISTER
)
1538 || (REG_P (SET_SRC (set
)) && REG_P (SET_DEST (set
))
1539 && reg_renumber
[REGNO (SET_SRC (set
))] < 0
1540 && reg_renumber
[REGNO (SET_DEST (set
))] < 0
1541 && reg_equiv_memory_loc (REGNO (SET_SRC (set
))) != NULL
1542 && reg_equiv_memory_loc (REGNO (SET_DEST (set
))) != NULL
1543 && rtx_equal_p (reg_equiv_memory_loc (REGNO (SET_SRC (set
))),
1544 reg_equiv_memory_loc (REGNO (SET_DEST (set
)))))))
1546 if (ira_conflicts_p
)
1547 /* Inform IRA about the insn deletion. */
1548 ira_mark_memory_move_deletion (REGNO (SET_DEST (set
)),
1549 REGNO (SET_SRC (set
)));
1551 /* Delete it from the reload chain. */
1553 chain
->prev
->next
= next
;
1555 reload_insn_chain
= next
;
1557 next
->prev
= chain
->prev
;
1558 chain
->next
= unused_insn_chains
;
1559 unused_insn_chains
= chain
;
1564 update_eliminable_offsets ();
1566 /* Remember for later shortcuts which insns had any reloads or
1567 register eliminations. */
1568 chain
->need_elim
= did_elimination
;
1569 chain
->need_reload
= n_reloads
> 0;
1570 chain
->need_operand_change
= operands_changed
;
1572 /* Discard any register replacements done. */
1573 if (did_elimination
)
1575 obstack_free (&reload_obstack
, reload_insn_firstobj
);
1576 PATTERN (insn
) = old_body
;
1577 INSN_CODE (insn
) = old_code
;
1578 REG_NOTES (insn
) = old_notes
;
1579 something_needs_elimination
= 1;
1582 something_needs_operands_changed
|= operands_changed
;
1586 copy_reloads (chain
);
1587 *pprev_reload
= chain
;
1588 pprev_reload
= &chain
->next_need_reload
;
1595 /* This function is called from the register allocator to set up estimates
1596 for the cost of eliminating pseudos which have REG_EQUIV equivalences to
1597 an invariant. The structure is similar to calculate_needs_all_insns. */
1600 calculate_elim_costs_all_insns (void)
1602 int *reg_equiv_init_cost
;
1606 reg_equiv_init_cost
= XCNEWVEC (int, max_regno
);
1608 init_eliminable_invariants (get_insns (), false);
1610 set_initial_elim_offsets ();
1611 set_initial_label_offsets ();
1618 FOR_BB_INSNS (bb
, insn
)
1620 /* If this is a label, a JUMP_INSN, or has REG_NOTES (which might
1621 include REG_LABEL_OPERAND and REG_LABEL_TARGET), we need to see
1622 what effects this has on the known offsets at labels. */
1624 if (LABEL_P (insn
) || JUMP_P (insn
)
1625 || (INSN_P (insn
) && REG_NOTES (insn
) != 0))
1626 set_label_offsets (insn
, insn
, 0);
1630 rtx set
= single_set (insn
);
1632 /* Skip insns that only set an equivalence. */
1633 if (set
&& REG_P (SET_DEST (set
))
1634 && reg_renumber
[REGNO (SET_DEST (set
))] < 0
1635 && (reg_equiv_constant (REGNO (SET_DEST (set
)))
1636 || reg_equiv_invariant (REGNO (SET_DEST (set
)))))
1638 unsigned regno
= REGNO (SET_DEST (set
));
1639 rtx init
= reg_equiv_init (regno
);
1642 rtx t
= eliminate_regs_1 (SET_SRC (set
), VOIDmode
, insn
,
1644 int cost
= set_src_cost (t
, optimize_bb_for_speed_p (bb
));
1645 int freq
= REG_FREQ_FROM_BB (bb
);
1647 reg_equiv_init_cost
[regno
] = cost
* freq
;
1651 /* If needed, eliminate any eliminable registers. */
1652 if (num_eliminable
|| num_eliminable_invariants
)
1653 elimination_costs_in_insn (insn
);
1656 update_eliminable_offsets ();
1660 for (i
= FIRST_PSEUDO_REGISTER
; i
< max_regno
; i
++)
1662 if (reg_equiv_invariant (i
))
1664 if (reg_equiv_init (i
))
1666 int cost
= reg_equiv_init_cost
[i
];
1669 "Reg %d has equivalence, initial gains %d\n", i
, cost
);
1671 ira_adjust_equiv_reg_cost (i
, cost
);
1677 "Reg %d had equivalence, but can't be eliminated\n",
1679 ira_adjust_equiv_reg_cost (i
, 0);
1684 free (reg_equiv_init_cost
);
1685 free (offsets_known_at
);
1688 offsets_known_at
= NULL
;
1691 /* Comparison function for qsort to decide which of two reloads
1692 should be handled first. *P1 and *P2 are the reload numbers. */
1695 reload_reg_class_lower (const void *r1p
, const void *r2p
)
1697 int r1
= *(const short *) r1p
, r2
= *(const short *) r2p
;
1700 /* Consider required reloads before optional ones. */
1701 t
= rld
[r1
].optional
- rld
[r2
].optional
;
1705 /* Count all solitary classes before non-solitary ones. */
1706 t
= ((reg_class_size
[(int) rld
[r2
].rclass
] == 1)
1707 - (reg_class_size
[(int) rld
[r1
].rclass
] == 1));
1711 /* Aside from solitaires, consider all multi-reg groups first. */
1712 t
= rld
[r2
].nregs
- rld
[r1
].nregs
;
1716 /* Consider reloads in order of increasing reg-class number. */
1717 t
= (int) rld
[r1
].rclass
- (int) rld
[r2
].rclass
;
1721 /* If reloads are equally urgent, sort by reload number,
1722 so that the results of qsort leave nothing to chance. */
1726 /* The cost of spilling each hard reg. */
1727 static int spill_cost
[FIRST_PSEUDO_REGISTER
];
1729 /* When spilling multiple hard registers, we use SPILL_COST for the first
1730 spilled hard reg and SPILL_ADD_COST for subsequent regs. SPILL_ADD_COST
1731 only the first hard reg for a multi-reg pseudo. */
1732 static int spill_add_cost
[FIRST_PSEUDO_REGISTER
];
1734 /* Map of hard regno to pseudo regno currently occupying the hard
1736 static int hard_regno_to_pseudo_regno
[FIRST_PSEUDO_REGISTER
];
1738 /* Update the spill cost arrays, considering that pseudo REG is live. */
1741 count_pseudo (int reg
)
1743 int freq
= REG_FREQ (reg
);
1744 int r
= reg_renumber
[reg
];
1747 /* Ignore spilled pseudo-registers which can be here only if IRA is used. */
1748 if (ira_conflicts_p
&& r
< 0)
1751 if (REGNO_REG_SET_P (&pseudos_counted
, reg
)
1752 || REGNO_REG_SET_P (&spilled_pseudos
, reg
))
1755 SET_REGNO_REG_SET (&pseudos_counted
, reg
);
1757 gcc_assert (r
>= 0);
1759 spill_add_cost
[r
] += freq
;
1760 nregs
= hard_regno_nregs
[r
][PSEUDO_REGNO_MODE (reg
)];
1763 hard_regno_to_pseudo_regno
[r
+ nregs
] = reg
;
1764 spill_cost
[r
+ nregs
] += freq
;
1768 /* Calculate the SPILL_COST and SPILL_ADD_COST arrays and determine the
1769 contents of BAD_SPILL_REGS for the insn described by CHAIN. */
1772 order_regs_for_reload (struct insn_chain
*chain
)
1775 HARD_REG_SET used_by_pseudos
;
1776 HARD_REG_SET used_by_pseudos2
;
1777 reg_set_iterator rsi
;
1779 COPY_HARD_REG_SET (bad_spill_regs
, fixed_reg_set
);
1781 memset (spill_cost
, 0, sizeof spill_cost
);
1782 memset (spill_add_cost
, 0, sizeof spill_add_cost
);
1783 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
1784 hard_regno_to_pseudo_regno
[i
] = -1;
1786 /* Count number of uses of each hard reg by pseudo regs allocated to it
1787 and then order them by decreasing use. First exclude hard registers
1788 that are live in or across this insn. */
1790 REG_SET_TO_HARD_REG_SET (used_by_pseudos
, &chain
->live_throughout
);
1791 REG_SET_TO_HARD_REG_SET (used_by_pseudos2
, &chain
->dead_or_set
);
1792 IOR_HARD_REG_SET (bad_spill_regs
, used_by_pseudos
);
1793 IOR_HARD_REG_SET (bad_spill_regs
, used_by_pseudos2
);
1795 /* Now find out which pseudos are allocated to it, and update
1797 CLEAR_REG_SET (&pseudos_counted
);
1799 EXECUTE_IF_SET_IN_REG_SET
1800 (&chain
->live_throughout
, FIRST_PSEUDO_REGISTER
, i
, rsi
)
1804 EXECUTE_IF_SET_IN_REG_SET
1805 (&chain
->dead_or_set
, FIRST_PSEUDO_REGISTER
, i
, rsi
)
1809 CLEAR_REG_SET (&pseudos_counted
);
1812 /* Vector of reload-numbers showing the order in which the reloads should
1814 static short reload_order
[MAX_RELOADS
];
1816 /* This is used to keep track of the spill regs used in one insn. */
1817 static HARD_REG_SET used_spill_regs_local
;
1819 /* We decided to spill hard register SPILLED, which has a size of
1820 SPILLED_NREGS. Determine how pseudo REG, which is live during the insn,
1821 is affected. We will add it to SPILLED_PSEUDOS if necessary, and we will
1822 update SPILL_COST/SPILL_ADD_COST. */
1825 count_spilled_pseudo (int spilled
, int spilled_nregs
, int reg
)
1827 int freq
= REG_FREQ (reg
);
1828 int r
= reg_renumber
[reg
];
1831 /* Ignore spilled pseudo-registers which can be here only if IRA is used. */
1832 if (ira_conflicts_p
&& r
< 0)
1835 gcc_assert (r
>= 0);
1837 nregs
= hard_regno_nregs
[r
][PSEUDO_REGNO_MODE (reg
)];
1839 if (REGNO_REG_SET_P (&spilled_pseudos
, reg
)
1840 || spilled
+ spilled_nregs
<= r
|| r
+ nregs
<= spilled
)
1843 SET_REGNO_REG_SET (&spilled_pseudos
, reg
);
1845 spill_add_cost
[r
] -= freq
;
1848 hard_regno_to_pseudo_regno
[r
+ nregs
] = -1;
1849 spill_cost
[r
+ nregs
] -= freq
;
1853 /* Find reload register to use for reload number ORDER. */
1856 find_reg (struct insn_chain
*chain
, int order
)
1858 int rnum
= reload_order
[order
];
1859 struct reload
*rl
= rld
+ rnum
;
1860 int best_cost
= INT_MAX
;
1862 unsigned int i
, j
, n
;
1864 HARD_REG_SET not_usable
;
1865 HARD_REG_SET used_by_other_reload
;
1866 reg_set_iterator rsi
;
1867 static int regno_pseudo_regs
[FIRST_PSEUDO_REGISTER
];
1868 static int best_regno_pseudo_regs
[FIRST_PSEUDO_REGISTER
];
1870 COPY_HARD_REG_SET (not_usable
, bad_spill_regs
);
1871 IOR_HARD_REG_SET (not_usable
, bad_spill_regs_global
);
1872 IOR_COMPL_HARD_REG_SET (not_usable
, reg_class_contents
[rl
->rclass
]);
1874 CLEAR_HARD_REG_SET (used_by_other_reload
);
1875 for (k
= 0; k
< order
; k
++)
1877 int other
= reload_order
[k
];
1879 if (rld
[other
].regno
>= 0 && reloads_conflict (other
, rnum
))
1880 for (j
= 0; j
< rld
[other
].nregs
; j
++)
1881 SET_HARD_REG_BIT (used_by_other_reload
, rld
[other
].regno
+ j
);
1884 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
1886 #ifdef REG_ALLOC_ORDER
1887 unsigned int regno
= reg_alloc_order
[i
];
1889 unsigned int regno
= i
;
1892 if (! TEST_HARD_REG_BIT (not_usable
, regno
)
1893 && ! TEST_HARD_REG_BIT (used_by_other_reload
, regno
)
1894 && HARD_REGNO_MODE_OK (regno
, rl
->mode
))
1896 int this_cost
= spill_cost
[regno
];
1898 unsigned int this_nregs
= hard_regno_nregs
[regno
][rl
->mode
];
1900 for (j
= 1; j
< this_nregs
; j
++)
1902 this_cost
+= spill_add_cost
[regno
+ j
];
1903 if ((TEST_HARD_REG_BIT (not_usable
, regno
+ j
))
1904 || TEST_HARD_REG_BIT (used_by_other_reload
, regno
+ j
))
1910 if (ira_conflicts_p
)
1912 /* Ask IRA to find a better pseudo-register for
1914 for (n
= j
= 0; j
< this_nregs
; j
++)
1916 int r
= hard_regno_to_pseudo_regno
[regno
+ j
];
1920 if (n
== 0 || regno_pseudo_regs
[n
- 1] != r
)
1921 regno_pseudo_regs
[n
++] = r
;
1923 regno_pseudo_regs
[n
++] = -1;
1925 || ira_better_spill_reload_regno_p (regno_pseudo_regs
,
1926 best_regno_pseudo_regs
,
1933 best_regno_pseudo_regs
[j
] = regno_pseudo_regs
[j
];
1934 if (regno_pseudo_regs
[j
] < 0)
1941 if (rl
->in
&& REG_P (rl
->in
) && REGNO (rl
->in
) == regno
)
1943 if (rl
->out
&& REG_P (rl
->out
) && REGNO (rl
->out
) == regno
)
1945 if (this_cost
< best_cost
1946 /* Among registers with equal cost, prefer caller-saved ones, or
1947 use REG_ALLOC_ORDER if it is defined. */
1948 || (this_cost
== best_cost
1949 #ifdef REG_ALLOC_ORDER
1950 && (inv_reg_alloc_order
[regno
]
1951 < inv_reg_alloc_order
[best_reg
])
1953 && call_used_regs
[regno
]
1954 && ! call_used_regs
[best_reg
]
1959 best_cost
= this_cost
;
1967 fprintf (dump_file
, "Using reg %d for reload %d\n", best_reg
, rnum
);
1969 rl
->nregs
= hard_regno_nregs
[best_reg
][rl
->mode
];
1970 rl
->regno
= best_reg
;
1972 EXECUTE_IF_SET_IN_REG_SET
1973 (&chain
->live_throughout
, FIRST_PSEUDO_REGISTER
, j
, rsi
)
1975 count_spilled_pseudo (best_reg
, rl
->nregs
, j
);
1978 EXECUTE_IF_SET_IN_REG_SET
1979 (&chain
->dead_or_set
, FIRST_PSEUDO_REGISTER
, j
, rsi
)
1981 count_spilled_pseudo (best_reg
, rl
->nregs
, j
);
1984 for (i
= 0; i
< rl
->nregs
; i
++)
1986 gcc_assert (spill_cost
[best_reg
+ i
] == 0);
1987 gcc_assert (spill_add_cost
[best_reg
+ i
] == 0);
1988 gcc_assert (hard_regno_to_pseudo_regno
[best_reg
+ i
] == -1);
1989 SET_HARD_REG_BIT (used_spill_regs_local
, best_reg
+ i
);
1994 /* Find more reload regs to satisfy the remaining need of an insn, which
1996 Do it by ascending class number, since otherwise a reg
1997 might be spilled for a big class and might fail to count
1998 for a smaller class even though it belongs to that class. */
2001 find_reload_regs (struct insn_chain
*chain
)
2005 /* In order to be certain of getting the registers we need,
2006 we must sort the reloads into order of increasing register class.
2007 Then our grabbing of reload registers will parallel the process
2008 that provided the reload registers. */
2009 for (i
= 0; i
< chain
->n_reloads
; i
++)
2011 /* Show whether this reload already has a hard reg. */
2012 if (chain
->rld
[i
].reg_rtx
)
2014 int regno
= REGNO (chain
->rld
[i
].reg_rtx
);
2015 chain
->rld
[i
].regno
= regno
;
2017 = hard_regno_nregs
[regno
][GET_MODE (chain
->rld
[i
].reg_rtx
)];
2020 chain
->rld
[i
].regno
= -1;
2021 reload_order
[i
] = i
;
2024 n_reloads
= chain
->n_reloads
;
2025 memcpy (rld
, chain
->rld
, n_reloads
* sizeof (struct reload
));
2027 CLEAR_HARD_REG_SET (used_spill_regs_local
);
2030 fprintf (dump_file
, "Spilling for insn %d.\n", INSN_UID (chain
->insn
));
2032 qsort (reload_order
, n_reloads
, sizeof (short), reload_reg_class_lower
);
2034 /* Compute the order of preference for hard registers to spill. */
2036 order_regs_for_reload (chain
);
2038 for (i
= 0; i
< n_reloads
; i
++)
2040 int r
= reload_order
[i
];
2042 /* Ignore reloads that got marked inoperative. */
2043 if ((rld
[r
].out
!= 0 || rld
[r
].in
!= 0 || rld
[r
].secondary_p
)
2044 && ! rld
[r
].optional
2045 && rld
[r
].regno
== -1)
2046 if (! find_reg (chain
, i
))
2049 fprintf (dump_file
, "reload failure for reload %d\n", r
);
2050 spill_failure (chain
->insn
, rld
[r
].rclass
);
2056 COPY_HARD_REG_SET (chain
->used_spill_regs
, used_spill_regs_local
);
2057 IOR_HARD_REG_SET (used_spill_regs
, used_spill_regs_local
);
2059 memcpy (chain
->rld
, rld
, n_reloads
* sizeof (struct reload
));
2063 select_reload_regs (void)
2065 struct insn_chain
*chain
;
2067 /* Try to satisfy the needs for each insn. */
2068 for (chain
= insns_need_reload
; chain
!= 0;
2069 chain
= chain
->next_need_reload
)
2070 find_reload_regs (chain
);
2073 /* Delete all insns that were inserted by emit_caller_save_insns during
2076 delete_caller_save_insns (void)
2078 struct insn_chain
*c
= reload_insn_chain
;
2082 while (c
!= 0 && c
->is_caller_save_insn
)
2084 struct insn_chain
*next
= c
->next
;
2087 if (c
== reload_insn_chain
)
2088 reload_insn_chain
= next
;
2092 next
->prev
= c
->prev
;
2094 c
->prev
->next
= next
;
2095 c
->next
= unused_insn_chains
;
2096 unused_insn_chains
= c
;
2104 /* Handle the failure to find a register to spill.
2105 INSN should be one of the insns which needed this particular spill reg. */
2108 spill_failure (rtx insn
, enum reg_class rclass
)
2110 if (asm_noperands (PATTERN (insn
)) >= 0)
2111 error_for_asm (insn
, "can%'t find a register in class %qs while "
2112 "reloading %<asm%>",
2113 reg_class_names
[rclass
]);
2116 error ("unable to find a register to spill in class %qs",
2117 reg_class_names
[rclass
]);
2121 fprintf (dump_file
, "\nReloads for insn # %d\n", INSN_UID (insn
));
2122 debug_reload_to_stream (dump_file
);
2124 fatal_insn ("this is the insn:", insn
);
2128 /* Delete an unneeded INSN and any previous insns who sole purpose is loading
2129 data that is dead in INSN. */
2132 delete_dead_insn (rtx insn
)
2134 rtx prev
= prev_active_insn (insn
);
2137 /* If the previous insn sets a register that dies in our insn make
2138 a note that we want to run DCE immediately after reload.
2140 We used to delete the previous insn & recurse, but that's wrong for
2141 block local equivalences. Instead of trying to figure out the exact
2142 circumstances where we can delete the potentially dead insns, just
2143 let DCE do the job. */
2144 if (prev
&& GET_CODE (PATTERN (prev
)) == SET
2145 && (prev_dest
= SET_DEST (PATTERN (prev
)), REG_P (prev_dest
))
2146 && reg_mentioned_p (prev_dest
, PATTERN (insn
))
2147 && find_regno_note (insn
, REG_DEAD
, REGNO (prev_dest
))
2148 && ! side_effects_p (SET_SRC (PATTERN (prev
))))
2151 SET_INSN_DELETED (insn
);
2154 /* Modify the home of pseudo-reg I.
2155 The new home is present in reg_renumber[I].
2157 FROM_REG may be the hard reg that the pseudo-reg is being spilled from;
2158 or it may be -1, meaning there is none or it is not relevant.
2159 This is used so that all pseudos spilled from a given hard reg
2160 can share one stack slot. */
2163 alter_reg (int i
, int from_reg
, bool dont_share_p
)
2165 /* When outputting an inline function, this can happen
2166 for a reg that isn't actually used. */
2167 if (regno_reg_rtx
[i
] == 0)
2170 /* If the reg got changed to a MEM at rtl-generation time,
2172 if (!REG_P (regno_reg_rtx
[i
]))
2175 /* Modify the reg-rtx to contain the new hard reg
2176 number or else to contain its pseudo reg number. */
2177 SET_REGNO (regno_reg_rtx
[i
],
2178 reg_renumber
[i
] >= 0 ? reg_renumber
[i
] : i
);
2180 /* If we have a pseudo that is needed but has no hard reg or equivalent,
2181 allocate a stack slot for it. */
2183 if (reg_renumber
[i
] < 0
2184 && REG_N_REFS (i
) > 0
2185 && reg_equiv_constant (i
) == 0
2186 && (reg_equiv_invariant (i
) == 0
2187 || reg_equiv_init (i
) == 0)
2188 && reg_equiv_memory_loc (i
) == 0)
2191 enum machine_mode mode
= GET_MODE (regno_reg_rtx
[i
]);
2192 unsigned int inherent_size
= PSEUDO_REGNO_BYTES (i
);
2193 unsigned int inherent_align
= GET_MODE_ALIGNMENT (mode
);
2194 unsigned int total_size
= MAX (inherent_size
, reg_max_ref_width
[i
]);
2195 unsigned int min_align
= reg_max_ref_width
[i
] * BITS_PER_UNIT
;
2198 something_was_spilled
= true;
2200 if (ira_conflicts_p
)
2202 /* Mark the spill for IRA. */
2203 SET_REGNO_REG_SET (&spilled_pseudos
, i
);
2205 x
= ira_reuse_stack_slot (i
, inherent_size
, total_size
);
2211 /* Each pseudo reg has an inherent size which comes from its own mode,
2212 and a total size which provides room for paradoxical subregs
2213 which refer to the pseudo reg in wider modes.
2215 We can use a slot already allocated if it provides both
2216 enough inherent space and enough total space.
2217 Otherwise, we allocate a new slot, making sure that it has no less
2218 inherent space, and no less total space, then the previous slot. */
2219 else if (from_reg
== -1 || (!dont_share_p
&& ira_conflicts_p
))
2223 /* No known place to spill from => no slot to reuse. */
2224 x
= assign_stack_local (mode
, total_size
,
2225 min_align
> inherent_align
2226 || total_size
> inherent_size
? -1 : 0);
2230 /* Cancel the big-endian correction done in assign_stack_local.
2231 Get the address of the beginning of the slot. This is so we
2232 can do a big-endian correction unconditionally below. */
2233 if (BYTES_BIG_ENDIAN
)
2235 adjust
= inherent_size
- total_size
;
2238 = adjust_address_nv (x
, mode_for_size (total_size
2244 if (! dont_share_p
&& ira_conflicts_p
)
2245 /* Inform IRA about allocation a new stack slot. */
2246 ira_mark_new_stack_slot (stack_slot
, i
, total_size
);
2249 /* Reuse a stack slot if possible. */
2250 else if (spill_stack_slot
[from_reg
] != 0
2251 && spill_stack_slot_width
[from_reg
] >= total_size
2252 && (GET_MODE_SIZE (GET_MODE (spill_stack_slot
[from_reg
]))
2254 && MEM_ALIGN (spill_stack_slot
[from_reg
]) >= min_align
)
2255 x
= spill_stack_slot
[from_reg
];
2257 /* Allocate a bigger slot. */
2260 /* Compute maximum size needed, both for inherent size
2261 and for total size. */
2264 if (spill_stack_slot
[from_reg
])
2266 if (GET_MODE_SIZE (GET_MODE (spill_stack_slot
[from_reg
]))
2268 mode
= GET_MODE (spill_stack_slot
[from_reg
]);
2269 if (spill_stack_slot_width
[from_reg
] > total_size
)
2270 total_size
= spill_stack_slot_width
[from_reg
];
2271 if (MEM_ALIGN (spill_stack_slot
[from_reg
]) > min_align
)
2272 min_align
= MEM_ALIGN (spill_stack_slot
[from_reg
]);
2275 /* Make a slot with that size. */
2276 x
= assign_stack_local (mode
, total_size
,
2277 min_align
> inherent_align
2278 || total_size
> inherent_size
? -1 : 0);
2281 /* Cancel the big-endian correction done in assign_stack_local.
2282 Get the address of the beginning of the slot. This is so we
2283 can do a big-endian correction unconditionally below. */
2284 if (BYTES_BIG_ENDIAN
)
2286 adjust
= GET_MODE_SIZE (mode
) - total_size
;
2289 = adjust_address_nv (x
, mode_for_size (total_size
2295 spill_stack_slot
[from_reg
] = stack_slot
;
2296 spill_stack_slot_width
[from_reg
] = total_size
;
2299 /* On a big endian machine, the "address" of the slot
2300 is the address of the low part that fits its inherent mode. */
2301 if (BYTES_BIG_ENDIAN
&& inherent_size
< total_size
)
2302 adjust
+= (total_size
- inherent_size
);
2304 /* If we have any adjustment to make, or if the stack slot is the
2305 wrong mode, make a new stack slot. */
2306 x
= adjust_address_nv (x
, GET_MODE (regno_reg_rtx
[i
]), adjust
);
2308 /* Set all of the memory attributes as appropriate for a spill. */
2309 set_mem_attrs_for_spill (x
);
2311 /* Save the stack slot for later. */
2312 reg_equiv_memory_loc (i
) = x
;
2316 /* Mark the slots in regs_ever_live for the hard regs used by
2317 pseudo-reg number REGNO, accessed in MODE. */
2320 mark_home_live_1 (int regno
, enum machine_mode mode
)
2324 i
= reg_renumber
[regno
];
2327 lim
= end_hard_regno (mode
, i
);
2329 df_set_regs_ever_live(i
++, true);
2332 /* Mark the slots in regs_ever_live for the hard regs
2333 used by pseudo-reg number REGNO. */
2336 mark_home_live (int regno
)
2338 if (reg_renumber
[regno
] >= 0)
2339 mark_home_live_1 (regno
, PSEUDO_REGNO_MODE (regno
));
2342 /* This function handles the tracking of elimination offsets around branches.
2344 X is a piece of RTL being scanned.
2346 INSN is the insn that it came from, if any.
2348 INITIAL_P is nonzero if we are to set the offset to be the initial
2349 offset and zero if we are setting the offset of the label to be the
2353 set_label_offsets (rtx x
, rtx insn
, int initial_p
)
2355 enum rtx_code code
= GET_CODE (x
);
2358 struct elim_table
*p
;
2363 if (LABEL_REF_NONLOCAL_P (x
))
2368 /* ... fall through ... */
2371 /* If we know nothing about this label, set the desired offsets. Note
2372 that this sets the offset at a label to be the offset before a label
2373 if we don't know anything about the label. This is not correct for
2374 the label after a BARRIER, but is the best guess we can make. If
2375 we guessed wrong, we will suppress an elimination that might have
2376 been possible had we been able to guess correctly. */
2378 if (! offsets_known_at
[CODE_LABEL_NUMBER (x
) - first_label_num
])
2380 for (i
= 0; i
< NUM_ELIMINABLE_REGS
; i
++)
2381 offsets_at
[CODE_LABEL_NUMBER (x
) - first_label_num
][i
]
2382 = (initial_p
? reg_eliminate
[i
].initial_offset
2383 : reg_eliminate
[i
].offset
);
2384 offsets_known_at
[CODE_LABEL_NUMBER (x
) - first_label_num
] = 1;
2387 /* Otherwise, if this is the definition of a label and it is
2388 preceded by a BARRIER, set our offsets to the known offset of
2392 && (tem
= prev_nonnote_insn (insn
)) != 0
2394 set_offsets_for_label (insn
);
2396 /* If neither of the above cases is true, compare each offset
2397 with those previously recorded and suppress any eliminations
2398 where the offsets disagree. */
2400 for (i
= 0; i
< NUM_ELIMINABLE_REGS
; i
++)
2401 if (offsets_at
[CODE_LABEL_NUMBER (x
) - first_label_num
][i
]
2402 != (initial_p
? reg_eliminate
[i
].initial_offset
2403 : reg_eliminate
[i
].offset
))
2404 reg_eliminate
[i
].can_eliminate
= 0;
2409 set_label_offsets (PATTERN (insn
), insn
, initial_p
);
2411 /* ... fall through ... */
2415 /* Any labels mentioned in REG_LABEL_OPERAND notes can be branched
2416 to indirectly and hence must have all eliminations at their
2418 for (tem
= REG_NOTES (x
); tem
; tem
= XEXP (tem
, 1))
2419 if (REG_NOTE_KIND (tem
) == REG_LABEL_OPERAND
)
2420 set_label_offsets (XEXP (tem
, 0), insn
, 1);
2426 /* Each of the labels in the parallel or address vector must be
2427 at their initial offsets. We want the first field for PARALLEL
2428 and ADDR_VEC and the second field for ADDR_DIFF_VEC. */
2430 for (i
= 0; i
< (unsigned) XVECLEN (x
, code
== ADDR_DIFF_VEC
); i
++)
2431 set_label_offsets (XVECEXP (x
, code
== ADDR_DIFF_VEC
, i
),
2436 /* We only care about setting PC. If the source is not RETURN,
2437 IF_THEN_ELSE, or a label, disable any eliminations not at
2438 their initial offsets. Similarly if any arm of the IF_THEN_ELSE
2439 isn't one of those possibilities. For branches to a label,
2440 call ourselves recursively.
2442 Note that this can disable elimination unnecessarily when we have
2443 a non-local goto since it will look like a non-constant jump to
2444 someplace in the current function. This isn't a significant
2445 problem since such jumps will normally be when all elimination
2446 pairs are back to their initial offsets. */
2448 if (SET_DEST (x
) != pc_rtx
)
2451 switch (GET_CODE (SET_SRC (x
)))
2458 set_label_offsets (SET_SRC (x
), insn
, initial_p
);
2462 tem
= XEXP (SET_SRC (x
), 1);
2463 if (GET_CODE (tem
) == LABEL_REF
)
2464 set_label_offsets (XEXP (tem
, 0), insn
, initial_p
);
2465 else if (GET_CODE (tem
) != PC
&& GET_CODE (tem
) != RETURN
)
2468 tem
= XEXP (SET_SRC (x
), 2);
2469 if (GET_CODE (tem
) == LABEL_REF
)
2470 set_label_offsets (XEXP (tem
, 0), insn
, initial_p
);
2471 else if (GET_CODE (tem
) != PC
&& GET_CODE (tem
) != RETURN
)
2479 /* If we reach here, all eliminations must be at their initial
2480 offset because we are doing a jump to a variable address. */
2481 for (p
= reg_eliminate
; p
< ®_eliminate
[NUM_ELIMINABLE_REGS
]; p
++)
2482 if (p
->offset
!= p
->initial_offset
)
2483 p
->can_eliminate
= 0;
2491 /* Called through for_each_rtx, this function examines every reg that occurs
2492 in PX and adjusts the costs for its elimination which are gathered by IRA.
2493 DATA is the insn in which PX occurs. We do not recurse into MEM
2497 note_reg_elim_costly (rtx
*px
, void *data
)
2499 rtx insn
= (rtx
)data
;
2506 && REGNO (x
) >= FIRST_PSEUDO_REGISTER
2507 && reg_equiv_init (REGNO (x
))
2508 && reg_equiv_invariant (REGNO (x
)))
2510 rtx t
= reg_equiv_invariant (REGNO (x
));
2511 rtx new_rtx
= eliminate_regs_1 (t
, Pmode
, insn
, true, true);
2512 int cost
= set_src_cost (new_rtx
, optimize_bb_for_speed_p (elim_bb
));
2513 int freq
= REG_FREQ_FROM_BB (elim_bb
);
2516 ira_adjust_equiv_reg_cost (REGNO (x
), -cost
* freq
);
2521 /* Scan X and replace any eliminable registers (such as fp) with a
2522 replacement (such as sp), plus an offset.
2524 MEM_MODE is the mode of an enclosing MEM. We need this to know how
2525 much to adjust a register for, e.g., PRE_DEC. Also, if we are inside a
2526 MEM, we are allowed to replace a sum of a register and the constant zero
2527 with the register, which we cannot do outside a MEM. In addition, we need
2528 to record the fact that a register is referenced outside a MEM.
2530 If INSN is an insn, it is the insn containing X. If we replace a REG
2531 in a SET_DEST with an equivalent MEM and INSN is nonzero, write a
2532 CLOBBER of the pseudo after INSN so find_equiv_regs will know that
2533 the REG is being modified.
2535 Alternatively, INSN may be a note (an EXPR_LIST or INSN_LIST).
2536 That's used when we eliminate in expressions stored in notes.
2537 This means, do not set ref_outside_mem even if the reference
2540 If FOR_COSTS is true, we are being called before reload in order to
2541 estimate the costs of keeping registers with an equivalence unallocated.
2543 REG_EQUIV_MEM and REG_EQUIV_ADDRESS contain address that have had
2544 replacements done assuming all offsets are at their initial values. If
2545 they are not, or if REG_EQUIV_ADDRESS is nonzero for a pseudo we
2546 encounter, return the actual location so that find_reloads will do
2547 the proper thing. */
2550 eliminate_regs_1 (rtx x
, enum machine_mode mem_mode
, rtx insn
,
2551 bool may_use_invariant
, bool for_costs
)
2553 enum rtx_code code
= GET_CODE (x
);
2554 struct elim_table
*ep
;
2561 if (! current_function_decl
)
2581 /* First handle the case where we encounter a bare register that
2582 is eliminable. Replace it with a PLUS. */
2583 if (regno
< FIRST_PSEUDO_REGISTER
)
2585 for (ep
= reg_eliminate
; ep
< ®_eliminate
[NUM_ELIMINABLE_REGS
];
2587 if (ep
->from_rtx
== x
&& ep
->can_eliminate
)
2588 return plus_constant (Pmode
, ep
->to_rtx
, ep
->previous_offset
);
2591 else if (reg_renumber
&& reg_renumber
[regno
] < 0
2593 && reg_equiv_invariant (regno
))
2595 if (may_use_invariant
|| (insn
&& DEBUG_INSN_P (insn
)))
2596 return eliminate_regs_1 (copy_rtx (reg_equiv_invariant (regno
)),
2597 mem_mode
, insn
, true, for_costs
);
2598 /* There exists at least one use of REGNO that cannot be
2599 eliminated. Prevent the defining insn from being deleted. */
2600 reg_equiv_init (regno
) = NULL_RTX
;
2602 alter_reg (regno
, -1, true);
2606 /* You might think handling MINUS in a manner similar to PLUS is a
2607 good idea. It is not. It has been tried multiple times and every
2608 time the change has had to have been reverted.
2610 Other parts of reload know a PLUS is special (gen_reload for example)
2611 and require special code to handle code a reloaded PLUS operand.
2613 Also consider backends where the flags register is clobbered by a
2614 MINUS, but we can emit a PLUS that does not clobber flags (IA-32,
2615 lea instruction comes to mind). If we try to reload a MINUS, we
2616 may kill the flags register that was holding a useful value.
2618 So, please before trying to handle MINUS, consider reload as a
2619 whole instead of this little section as well as the backend issues. */
2621 /* If this is the sum of an eliminable register and a constant, rework
2623 if (REG_P (XEXP (x
, 0))
2624 && REGNO (XEXP (x
, 0)) < FIRST_PSEUDO_REGISTER
2625 && CONSTANT_P (XEXP (x
, 1)))
2627 for (ep
= reg_eliminate
; ep
< ®_eliminate
[NUM_ELIMINABLE_REGS
];
2629 if (ep
->from_rtx
== XEXP (x
, 0) && ep
->can_eliminate
)
2631 /* The only time we want to replace a PLUS with a REG (this
2632 occurs when the constant operand of the PLUS is the negative
2633 of the offset) is when we are inside a MEM. We won't want
2634 to do so at other times because that would change the
2635 structure of the insn in a way that reload can't handle.
2636 We special-case the commonest situation in
2637 eliminate_regs_in_insn, so just replace a PLUS with a
2638 PLUS here, unless inside a MEM. */
2639 if (mem_mode
!= 0 && CONST_INT_P (XEXP (x
, 1))
2640 && INTVAL (XEXP (x
, 1)) == - ep
->previous_offset
)
2643 return gen_rtx_PLUS (Pmode
, ep
->to_rtx
,
2644 plus_constant (Pmode
, XEXP (x
, 1),
2645 ep
->previous_offset
));
2648 /* If the register is not eliminable, we are done since the other
2649 operand is a constant. */
2653 /* If this is part of an address, we want to bring any constant to the
2654 outermost PLUS. We will do this by doing register replacement in
2655 our operands and seeing if a constant shows up in one of them.
2657 Note that there is no risk of modifying the structure of the insn,
2658 since we only get called for its operands, thus we are either
2659 modifying the address inside a MEM, or something like an address
2660 operand of a load-address insn. */
2663 rtx new0
= eliminate_regs_1 (XEXP (x
, 0), mem_mode
, insn
, true,
2665 rtx new1
= eliminate_regs_1 (XEXP (x
, 1), mem_mode
, insn
, true,
2668 if (reg_renumber
&& (new0
!= XEXP (x
, 0) || new1
!= XEXP (x
, 1)))
2670 /* If one side is a PLUS and the other side is a pseudo that
2671 didn't get a hard register but has a reg_equiv_constant,
2672 we must replace the constant here since it may no longer
2673 be in the position of any operand. */
2674 if (GET_CODE (new0
) == PLUS
&& REG_P (new1
)
2675 && REGNO (new1
) >= FIRST_PSEUDO_REGISTER
2676 && reg_renumber
[REGNO (new1
)] < 0
2678 && reg_equiv_constant (REGNO (new1
)) != 0)
2679 new1
= reg_equiv_constant (REGNO (new1
));
2680 else if (GET_CODE (new1
) == PLUS
&& REG_P (new0
)
2681 && REGNO (new0
) >= FIRST_PSEUDO_REGISTER
2682 && reg_renumber
[REGNO (new0
)] < 0
2683 && reg_equiv_constant (REGNO (new0
)) != 0)
2684 new0
= reg_equiv_constant (REGNO (new0
));
2686 new_rtx
= form_sum (GET_MODE (x
), new0
, new1
);
2688 /* As above, if we are not inside a MEM we do not want to
2689 turn a PLUS into something else. We might try to do so here
2690 for an addition of 0 if we aren't optimizing. */
2691 if (! mem_mode
&& GET_CODE (new_rtx
) != PLUS
)
2692 return gen_rtx_PLUS (GET_MODE (x
), new_rtx
, const0_rtx
);
2700 /* If this is the product of an eliminable register and a
2701 constant, apply the distribute law and move the constant out
2702 so that we have (plus (mult ..) ..). This is needed in order
2703 to keep load-address insns valid. This case is pathological.
2704 We ignore the possibility of overflow here. */
2705 if (REG_P (XEXP (x
, 0))
2706 && REGNO (XEXP (x
, 0)) < FIRST_PSEUDO_REGISTER
2707 && CONST_INT_P (XEXP (x
, 1)))
2708 for (ep
= reg_eliminate
; ep
< ®_eliminate
[NUM_ELIMINABLE_REGS
];
2710 if (ep
->from_rtx
== XEXP (x
, 0) && ep
->can_eliminate
)
2713 /* Refs inside notes or in DEBUG_INSNs don't count for
2715 && ! (insn
!= 0 && (GET_CODE (insn
) == EXPR_LIST
2716 || GET_CODE (insn
) == INSN_LIST
2717 || DEBUG_INSN_P (insn
))))
2718 ep
->ref_outside_mem
= 1;
2721 plus_constant (Pmode
,
2722 gen_rtx_MULT (Pmode
, ep
->to_rtx
, XEXP (x
, 1)),
2723 ep
->previous_offset
* INTVAL (XEXP (x
, 1)));
2726 /* ... fall through ... */
2730 /* See comments before PLUS about handling MINUS. */
2732 case DIV
: case UDIV
:
2733 case MOD
: case UMOD
:
2734 case AND
: case IOR
: case XOR
:
2735 case ROTATERT
: case ROTATE
:
2736 case ASHIFTRT
: case LSHIFTRT
: case ASHIFT
:
2738 case GE
: case GT
: case GEU
: case GTU
:
2739 case LE
: case LT
: case LEU
: case LTU
:
2741 rtx new0
= eliminate_regs_1 (XEXP (x
, 0), mem_mode
, insn
, false,
2743 rtx new1
= XEXP (x
, 1)
2744 ? eliminate_regs_1 (XEXP (x
, 1), mem_mode
, insn
, false,
2747 if (new0
!= XEXP (x
, 0) || new1
!= XEXP (x
, 1))
2748 return gen_rtx_fmt_ee (code
, GET_MODE (x
), new0
, new1
);
2753 /* If we have something in XEXP (x, 0), the usual case, eliminate it. */
2756 new_rtx
= eliminate_regs_1 (XEXP (x
, 0), mem_mode
, insn
, true,
2758 if (new_rtx
!= XEXP (x
, 0))
2760 /* If this is a REG_DEAD note, it is not valid anymore.
2761 Using the eliminated version could result in creating a
2762 REG_DEAD note for the stack or frame pointer. */
2763 if (REG_NOTE_KIND (x
) == REG_DEAD
)
2765 ? eliminate_regs_1 (XEXP (x
, 1), mem_mode
, insn
, true,
2769 x
= alloc_reg_note (REG_NOTE_KIND (x
), new_rtx
, XEXP (x
, 1));
2773 /* ... fall through ... */
2776 /* Now do eliminations in the rest of the chain. If this was
2777 an EXPR_LIST, this might result in allocating more memory than is
2778 strictly needed, but it simplifies the code. */
2781 new_rtx
= eliminate_regs_1 (XEXP (x
, 1), mem_mode
, insn
, true,
2783 if (new_rtx
!= XEXP (x
, 1))
2785 gen_rtx_fmt_ee (GET_CODE (x
), GET_MODE (x
), XEXP (x
, 0), new_rtx
);
2793 /* We do not support elimination of a register that is modified.
2794 elimination_effects has already make sure that this does not
2800 /* We do not support elimination of a register that is modified.
2801 elimination_effects has already make sure that this does not
2802 happen. The only remaining case we need to consider here is
2803 that the increment value may be an eliminable register. */
2804 if (GET_CODE (XEXP (x
, 1)) == PLUS
2805 && XEXP (XEXP (x
, 1), 0) == XEXP (x
, 0))
2807 rtx new_rtx
= eliminate_regs_1 (XEXP (XEXP (x
, 1), 1), mem_mode
,
2808 insn
, true, for_costs
);
2810 if (new_rtx
!= XEXP (XEXP (x
, 1), 1))
2811 return gen_rtx_fmt_ee (code
, GET_MODE (x
), XEXP (x
, 0),
2812 gen_rtx_PLUS (GET_MODE (x
),
2813 XEXP (x
, 0), new_rtx
));
2817 case STRICT_LOW_PART
:
2819 case SIGN_EXTEND
: case ZERO_EXTEND
:
2820 case TRUNCATE
: case FLOAT_EXTEND
: case FLOAT_TRUNCATE
:
2821 case FLOAT
: case FIX
:
2822 case UNSIGNED_FIX
: case UNSIGNED_FLOAT
:
2831 new_rtx
= eliminate_regs_1 (XEXP (x
, 0), mem_mode
, insn
, false,
2833 if (new_rtx
!= XEXP (x
, 0))
2834 return gen_rtx_fmt_e (code
, GET_MODE (x
), new_rtx
);
2838 /* Similar to above processing, but preserve SUBREG_BYTE.
2839 Convert (subreg (mem)) to (mem) if not paradoxical.
2840 Also, if we have a non-paradoxical (subreg (pseudo)) and the
2841 pseudo didn't get a hard reg, we must replace this with the
2842 eliminated version of the memory location because push_reload
2843 may do the replacement in certain circumstances. */
2844 if (REG_P (SUBREG_REG (x
))
2845 && !paradoxical_subreg_p (x
)
2847 && reg_equiv_memory_loc (REGNO (SUBREG_REG (x
))) != 0)
2849 new_rtx
= SUBREG_REG (x
);
2852 new_rtx
= eliminate_regs_1 (SUBREG_REG (x
), mem_mode
, insn
, false, for_costs
);
2854 if (new_rtx
!= SUBREG_REG (x
))
2856 int x_size
= GET_MODE_SIZE (GET_MODE (x
));
2857 int new_size
= GET_MODE_SIZE (GET_MODE (new_rtx
));
2860 && ((x_size
< new_size
2861 #ifdef WORD_REGISTER_OPERATIONS
2862 /* On these machines, combine can create rtl of the form
2863 (set (subreg:m1 (reg:m2 R) 0) ...)
2864 where m1 < m2, and expects something interesting to
2865 happen to the entire word. Moreover, it will use the
2866 (reg:m2 R) later, expecting all bits to be preserved.
2867 So if the number of words is the same, preserve the
2868 subreg so that push_reload can see it. */
2869 && ! ((x_size
- 1) / UNITS_PER_WORD
2870 == (new_size
-1 ) / UNITS_PER_WORD
)
2873 || x_size
== new_size
)
2875 return adjust_address_nv (new_rtx
, GET_MODE (x
), SUBREG_BYTE (x
));
2877 return gen_rtx_SUBREG (GET_MODE (x
), new_rtx
, SUBREG_BYTE (x
));
2883 /* Our only special processing is to pass the mode of the MEM to our
2884 recursive call and copy the flags. While we are here, handle this
2885 case more efficiently. */
2887 new_rtx
= eliminate_regs_1 (XEXP (x
, 0), GET_MODE (x
), insn
, true,
2890 && memory_address_p (GET_MODE (x
), XEXP (x
, 0))
2891 && !memory_address_p (GET_MODE (x
), new_rtx
))
2892 for_each_rtx (&XEXP (x
, 0), note_reg_elim_costly
, insn
);
2894 return replace_equiv_address_nv (x
, new_rtx
);
2897 /* Handle insn_list USE that a call to a pure function may generate. */
2898 new_rtx
= eliminate_regs_1 (XEXP (x
, 0), VOIDmode
, insn
, false,
2900 if (new_rtx
!= XEXP (x
, 0))
2901 return gen_rtx_USE (GET_MODE (x
), new_rtx
);
2906 gcc_assert (insn
&& DEBUG_INSN_P (insn
));
2916 /* Process each of our operands recursively. If any have changed, make a
2918 fmt
= GET_RTX_FORMAT (code
);
2919 for (i
= 0; i
< GET_RTX_LENGTH (code
); i
++, fmt
++)
2923 new_rtx
= eliminate_regs_1 (XEXP (x
, i
), mem_mode
, insn
, false,
2925 if (new_rtx
!= XEXP (x
, i
) && ! copied
)
2927 x
= shallow_copy_rtx (x
);
2930 XEXP (x
, i
) = new_rtx
;
2932 else if (*fmt
== 'E')
2935 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
2937 new_rtx
= eliminate_regs_1 (XVECEXP (x
, i
, j
), mem_mode
, insn
, false,
2939 if (new_rtx
!= XVECEXP (x
, i
, j
) && ! copied_vec
)
2941 rtvec new_v
= gen_rtvec_v (XVECLEN (x
, i
),
2945 x
= shallow_copy_rtx (x
);
2948 XVEC (x
, i
) = new_v
;
2951 XVECEXP (x
, i
, j
) = new_rtx
;
2960 eliminate_regs (rtx x
, enum machine_mode mem_mode
, rtx insn
)
2962 return eliminate_regs_1 (x
, mem_mode
, insn
, false, false);
2965 /* Scan rtx X for modifications of elimination target registers. Update
2966 the table of eliminables to reflect the changed state. MEM_MODE is
2967 the mode of an enclosing MEM rtx, or VOIDmode if not within a MEM. */
2970 elimination_effects (rtx x
, enum machine_mode mem_mode
)
2972 enum rtx_code code
= GET_CODE (x
);
2973 struct elim_table
*ep
;
2995 /* First handle the case where we encounter a bare register that
2996 is eliminable. Replace it with a PLUS. */
2997 if (regno
< FIRST_PSEUDO_REGISTER
)
2999 for (ep
= reg_eliminate
; ep
< ®_eliminate
[NUM_ELIMINABLE_REGS
];
3001 if (ep
->from_rtx
== x
&& ep
->can_eliminate
)
3004 ep
->ref_outside_mem
= 1;
3009 else if (reg_renumber
[regno
] < 0
3011 && reg_equiv_constant (regno
)
3012 && ! function_invariant_p (reg_equiv_constant (regno
)))
3013 elimination_effects (reg_equiv_constant (regno
), mem_mode
);
3022 /* If we modify the source of an elimination rule, disable it. */
3023 for (ep
= reg_eliminate
; ep
< ®_eliminate
[NUM_ELIMINABLE_REGS
]; ep
++)
3024 if (ep
->from_rtx
== XEXP (x
, 0))
3025 ep
->can_eliminate
= 0;
3027 /* If we modify the target of an elimination rule by adding a constant,
3028 update its offset. If we modify the target in any other way, we'll
3029 have to disable the rule as well. */
3030 for (ep
= reg_eliminate
; ep
< ®_eliminate
[NUM_ELIMINABLE_REGS
]; ep
++)
3031 if (ep
->to_rtx
== XEXP (x
, 0))
3033 int size
= GET_MODE_SIZE (mem_mode
);
3035 /* If more bytes than MEM_MODE are pushed, account for them. */
3036 #ifdef PUSH_ROUNDING
3037 if (ep
->to_rtx
== stack_pointer_rtx
)
3038 size
= PUSH_ROUNDING (size
);
3040 if (code
== PRE_DEC
|| code
== POST_DEC
)
3042 else if (code
== PRE_INC
|| code
== POST_INC
)
3044 else if (code
== PRE_MODIFY
|| code
== POST_MODIFY
)
3046 if (GET_CODE (XEXP (x
, 1)) == PLUS
3047 && XEXP (x
, 0) == XEXP (XEXP (x
, 1), 0)
3048 && CONST_INT_P (XEXP (XEXP (x
, 1), 1)))
3049 ep
->offset
-= INTVAL (XEXP (XEXP (x
, 1), 1));
3051 ep
->can_eliminate
= 0;
3055 /* These two aren't unary operators. */
3056 if (code
== POST_MODIFY
|| code
== PRE_MODIFY
)
3059 /* Fall through to generic unary operation case. */
3060 case STRICT_LOW_PART
:
3062 case SIGN_EXTEND
: case ZERO_EXTEND
:
3063 case TRUNCATE
: case FLOAT_EXTEND
: case FLOAT_TRUNCATE
:
3064 case FLOAT
: case FIX
:
3065 case UNSIGNED_FIX
: case UNSIGNED_FLOAT
:
3074 elimination_effects (XEXP (x
, 0), mem_mode
);
3078 if (REG_P (SUBREG_REG (x
))
3079 && (GET_MODE_SIZE (GET_MODE (x
))
3080 <= GET_MODE_SIZE (GET_MODE (SUBREG_REG (x
))))
3082 && reg_equiv_memory_loc (REGNO (SUBREG_REG (x
))) != 0)
3085 elimination_effects (SUBREG_REG (x
), mem_mode
);
3089 /* If using a register that is the source of an eliminate we still
3090 think can be performed, note it cannot be performed since we don't
3091 know how this register is used. */
3092 for (ep
= reg_eliminate
; ep
< ®_eliminate
[NUM_ELIMINABLE_REGS
]; ep
++)
3093 if (ep
->from_rtx
== XEXP (x
, 0))
3094 ep
->can_eliminate
= 0;
3096 elimination_effects (XEXP (x
, 0), mem_mode
);
3100 /* If clobbering a register that is the replacement register for an
3101 elimination we still think can be performed, note that it cannot
3102 be performed. Otherwise, we need not be concerned about it. */
3103 for (ep
= reg_eliminate
; ep
< ®_eliminate
[NUM_ELIMINABLE_REGS
]; ep
++)
3104 if (ep
->to_rtx
== XEXP (x
, 0))
3105 ep
->can_eliminate
= 0;
3107 elimination_effects (XEXP (x
, 0), mem_mode
);
3111 /* Check for setting a register that we know about. */
3112 if (REG_P (SET_DEST (x
)))
3114 /* See if this is setting the replacement register for an
3117 If DEST is the hard frame pointer, we do nothing because we
3118 assume that all assignments to the frame pointer are for
3119 non-local gotos and are being done at a time when they are valid
3120 and do not disturb anything else. Some machines want to
3121 eliminate a fake argument pointer (or even a fake frame pointer)
3122 with either the real frame or the stack pointer. Assignments to
3123 the hard frame pointer must not prevent this elimination. */
3125 for (ep
= reg_eliminate
; ep
< ®_eliminate
[NUM_ELIMINABLE_REGS
];
3127 if (ep
->to_rtx
== SET_DEST (x
)
3128 && SET_DEST (x
) != hard_frame_pointer_rtx
)
3130 /* If it is being incremented, adjust the offset. Otherwise,
3131 this elimination can't be done. */
3132 rtx src
= SET_SRC (x
);
3134 if (GET_CODE (src
) == PLUS
3135 && XEXP (src
, 0) == SET_DEST (x
)
3136 && CONST_INT_P (XEXP (src
, 1)))
3137 ep
->offset
-= INTVAL (XEXP (src
, 1));
3139 ep
->can_eliminate
= 0;
3143 elimination_effects (SET_DEST (x
), VOIDmode
);
3144 elimination_effects (SET_SRC (x
), VOIDmode
);
3148 /* Our only special processing is to pass the mode of the MEM to our
3150 elimination_effects (XEXP (x
, 0), GET_MODE (x
));
3157 fmt
= GET_RTX_FORMAT (code
);
3158 for (i
= 0; i
< GET_RTX_LENGTH (code
); i
++, fmt
++)
3161 elimination_effects (XEXP (x
, i
), mem_mode
);
3162 else if (*fmt
== 'E')
3163 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
3164 elimination_effects (XVECEXP (x
, i
, j
), mem_mode
);
3168 /* Descend through rtx X and verify that no references to eliminable registers
3169 remain. If any do remain, mark the involved register as not
3173 check_eliminable_occurrences (rtx x
)
3182 code
= GET_CODE (x
);
3184 if (code
== REG
&& REGNO (x
) < FIRST_PSEUDO_REGISTER
)
3186 struct elim_table
*ep
;
3188 for (ep
= reg_eliminate
; ep
< ®_eliminate
[NUM_ELIMINABLE_REGS
]; ep
++)
3189 if (ep
->from_rtx
== x
)
3190 ep
->can_eliminate
= 0;
3194 fmt
= GET_RTX_FORMAT (code
);
3195 for (i
= 0; i
< GET_RTX_LENGTH (code
); i
++, fmt
++)
3198 check_eliminable_occurrences (XEXP (x
, i
));
3199 else if (*fmt
== 'E')
3202 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
3203 check_eliminable_occurrences (XVECEXP (x
, i
, j
));
3208 /* Scan INSN and eliminate all eliminable registers in it.
3210 If REPLACE is nonzero, do the replacement destructively. Also
3211 delete the insn as dead it if it is setting an eliminable register.
3213 If REPLACE is zero, do all our allocations in reload_obstack.
3215 If no eliminations were done and this insn doesn't require any elimination
3216 processing (these are not identical conditions: it might be updating sp,
3217 but not referencing fp; this needs to be seen during reload_as_needed so
3218 that the offset between fp and sp can be taken into consideration), zero
3219 is returned. Otherwise, 1 is returned. */
3222 eliminate_regs_in_insn (rtx insn
, int replace
)
3224 int icode
= recog_memoized (insn
);
3225 rtx old_body
= PATTERN (insn
);
3226 int insn_is_asm
= asm_noperands (old_body
) >= 0;
3227 rtx old_set
= single_set (insn
);
3231 rtx substed_operand
[MAX_RECOG_OPERANDS
];
3232 rtx orig_operand
[MAX_RECOG_OPERANDS
];
3233 struct elim_table
*ep
;
3234 rtx plus_src
, plus_cst_src
;
3236 if (! insn_is_asm
&& icode
< 0)
3238 gcc_assert (GET_CODE (PATTERN (insn
)) == USE
3239 || GET_CODE (PATTERN (insn
)) == CLOBBER
3240 || GET_CODE (PATTERN (insn
)) == ADDR_VEC
3241 || GET_CODE (PATTERN (insn
)) == ADDR_DIFF_VEC
3242 || GET_CODE (PATTERN (insn
)) == ASM_INPUT
3243 || DEBUG_INSN_P (insn
));
3244 if (DEBUG_INSN_P (insn
))
3245 INSN_VAR_LOCATION_LOC (insn
)
3246 = eliminate_regs (INSN_VAR_LOCATION_LOC (insn
), VOIDmode
, insn
);
3250 if (old_set
!= 0 && REG_P (SET_DEST (old_set
))
3251 && REGNO (SET_DEST (old_set
)) < FIRST_PSEUDO_REGISTER
)
3253 /* Check for setting an eliminable register. */
3254 for (ep
= reg_eliminate
; ep
< ®_eliminate
[NUM_ELIMINABLE_REGS
]; ep
++)
3255 if (ep
->from_rtx
== SET_DEST (old_set
) && ep
->can_eliminate
)
3257 #if !HARD_FRAME_POINTER_IS_FRAME_POINTER
3258 /* If this is setting the frame pointer register to the
3259 hardware frame pointer register and this is an elimination
3260 that will be done (tested above), this insn is really
3261 adjusting the frame pointer downward to compensate for
3262 the adjustment done before a nonlocal goto. */
3263 if (ep
->from
== FRAME_POINTER_REGNUM
3264 && ep
->to
== HARD_FRAME_POINTER_REGNUM
)
3266 rtx base
= SET_SRC (old_set
);
3267 rtx base_insn
= insn
;
3268 HOST_WIDE_INT offset
= 0;
3270 while (base
!= ep
->to_rtx
)
3272 rtx prev_insn
, prev_set
;
3274 if (GET_CODE (base
) == PLUS
3275 && CONST_INT_P (XEXP (base
, 1)))
3277 offset
+= INTVAL (XEXP (base
, 1));
3278 base
= XEXP (base
, 0);
3280 else if ((prev_insn
= prev_nonnote_insn (base_insn
)) != 0
3281 && (prev_set
= single_set (prev_insn
)) != 0
3282 && rtx_equal_p (SET_DEST (prev_set
), base
))
3284 base
= SET_SRC (prev_set
);
3285 base_insn
= prev_insn
;
3291 if (base
== ep
->to_rtx
)
3293 rtx src
= plus_constant (Pmode
, ep
->to_rtx
,
3294 offset
- ep
->offset
);
3296 new_body
= old_body
;
3299 new_body
= copy_insn (old_body
);
3300 if (REG_NOTES (insn
))
3301 REG_NOTES (insn
) = copy_insn_1 (REG_NOTES (insn
));
3303 PATTERN (insn
) = new_body
;
3304 old_set
= single_set (insn
);
3306 /* First see if this insn remains valid when we
3307 make the change. If not, keep the INSN_CODE
3308 the same and let reload fit it up. */
3309 validate_change (insn
, &SET_SRC (old_set
), src
, 1);
3310 validate_change (insn
, &SET_DEST (old_set
),
3312 if (! apply_change_group ())
3314 SET_SRC (old_set
) = src
;
3315 SET_DEST (old_set
) = ep
->to_rtx
;
3324 /* In this case this insn isn't serving a useful purpose. We
3325 will delete it in reload_as_needed once we know that this
3326 elimination is, in fact, being done.
3328 If REPLACE isn't set, we can't delete this insn, but needn't
3329 process it since it won't be used unless something changes. */
3332 delete_dead_insn (insn
);
3340 /* We allow one special case which happens to work on all machines we
3341 currently support: a single set with the source or a REG_EQUAL
3342 note being a PLUS of an eliminable register and a constant. */
3343 plus_src
= plus_cst_src
= 0;
3344 if (old_set
&& REG_P (SET_DEST (old_set
)))
3346 if (GET_CODE (SET_SRC (old_set
)) == PLUS
)
3347 plus_src
= SET_SRC (old_set
);
3348 /* First see if the source is of the form (plus (...) CST). */
3350 && CONST_INT_P (XEXP (plus_src
, 1)))
3351 plus_cst_src
= plus_src
;
3352 else if (REG_P (SET_SRC (old_set
))
3355 /* Otherwise, see if we have a REG_EQUAL note of the form
3356 (plus (...) CST). */
3358 for (links
= REG_NOTES (insn
); links
; links
= XEXP (links
, 1))
3360 if ((REG_NOTE_KIND (links
) == REG_EQUAL
3361 || REG_NOTE_KIND (links
) == REG_EQUIV
)
3362 && GET_CODE (XEXP (links
, 0)) == PLUS
3363 && CONST_INT_P (XEXP (XEXP (links
, 0), 1)))
3365 plus_cst_src
= XEXP (links
, 0);
3371 /* Check that the first operand of the PLUS is a hard reg or
3372 the lowpart subreg of one. */
3375 rtx reg
= XEXP (plus_cst_src
, 0);
3376 if (GET_CODE (reg
) == SUBREG
&& subreg_lowpart_p (reg
))
3377 reg
= SUBREG_REG (reg
);
3379 if (!REG_P (reg
) || REGNO (reg
) >= FIRST_PSEUDO_REGISTER
)
3385 rtx reg
= XEXP (plus_cst_src
, 0);
3386 HOST_WIDE_INT offset
= INTVAL (XEXP (plus_cst_src
, 1));
3388 if (GET_CODE (reg
) == SUBREG
)
3389 reg
= SUBREG_REG (reg
);
3391 for (ep
= reg_eliminate
; ep
< ®_eliminate
[NUM_ELIMINABLE_REGS
]; ep
++)
3392 if (ep
->from_rtx
== reg
&& ep
->can_eliminate
)
3394 rtx to_rtx
= ep
->to_rtx
;
3395 offset
+= ep
->offset
;
3396 offset
= trunc_int_for_mode (offset
, GET_MODE (plus_cst_src
));
3398 if (GET_CODE (XEXP (plus_cst_src
, 0)) == SUBREG
)
3399 to_rtx
= gen_lowpart (GET_MODE (XEXP (plus_cst_src
, 0)),
3401 /* If we have a nonzero offset, and the source is already
3402 a simple REG, the following transformation would
3403 increase the cost of the insn by replacing a simple REG
3404 with (plus (reg sp) CST). So try only when we already
3405 had a PLUS before. */
3406 if (offset
== 0 || plus_src
)
3408 rtx new_src
= plus_constant (GET_MODE (to_rtx
),
3411 new_body
= old_body
;
3414 new_body
= copy_insn (old_body
);
3415 if (REG_NOTES (insn
))
3416 REG_NOTES (insn
) = copy_insn_1 (REG_NOTES (insn
));
3418 PATTERN (insn
) = new_body
;
3419 old_set
= single_set (insn
);
3421 /* First see if this insn remains valid when we make the
3422 change. If not, try to replace the whole pattern with
3423 a simple set (this may help if the original insn was a
3424 PARALLEL that was only recognized as single_set due to
3425 REG_UNUSED notes). If this isn't valid either, keep
3426 the INSN_CODE the same and let reload fix it up. */
3427 if (!validate_change (insn
, &SET_SRC (old_set
), new_src
, 0))
3429 rtx new_pat
= gen_rtx_SET (VOIDmode
,
3430 SET_DEST (old_set
), new_src
);
3432 if (!validate_change (insn
, &PATTERN (insn
), new_pat
, 0))
3433 SET_SRC (old_set
) = new_src
;
3440 /* This can't have an effect on elimination offsets, so skip right
3446 /* Determine the effects of this insn on elimination offsets. */
3447 elimination_effects (old_body
, VOIDmode
);
3449 /* Eliminate all eliminable registers occurring in operands that
3450 can be handled by reload. */
3451 extract_insn (insn
);
3452 for (i
= 0; i
< recog_data
.n_operands
; i
++)
3454 orig_operand
[i
] = recog_data
.operand
[i
];
3455 substed_operand
[i
] = recog_data
.operand
[i
];
3457 /* For an asm statement, every operand is eliminable. */
3458 if (insn_is_asm
|| insn_data
[icode
].operand
[i
].eliminable
)
3460 bool is_set_src
, in_plus
;
3462 /* Check for setting a register that we know about. */
3463 if (recog_data
.operand_type
[i
] != OP_IN
3464 && REG_P (orig_operand
[i
]))
3466 /* If we are assigning to a register that can be eliminated, it
3467 must be as part of a PARALLEL, since the code above handles
3468 single SETs. We must indicate that we can no longer
3469 eliminate this reg. */
3470 for (ep
= reg_eliminate
; ep
< ®_eliminate
[NUM_ELIMINABLE_REGS
];
3472 if (ep
->from_rtx
== orig_operand
[i
])
3473 ep
->can_eliminate
= 0;
3476 /* Companion to the above plus substitution, we can allow
3477 invariants as the source of a plain move. */
3480 && recog_data
.operand_loc
[i
] == &SET_SRC (old_set
))
3484 && (recog_data
.operand_loc
[i
] == &XEXP (plus_src
, 0)
3485 || recog_data
.operand_loc
[i
] == &XEXP (plus_src
, 1)))
3489 = eliminate_regs_1 (recog_data
.operand
[i
], VOIDmode
,
3490 replace
? insn
: NULL_RTX
,
3491 is_set_src
|| in_plus
, false);
3492 if (substed_operand
[i
] != orig_operand
[i
])
3494 /* Terminate the search in check_eliminable_occurrences at
3496 *recog_data
.operand_loc
[i
] = 0;
3498 /* If an output operand changed from a REG to a MEM and INSN is an
3499 insn, write a CLOBBER insn. */
3500 if (recog_data
.operand_type
[i
] != OP_IN
3501 && REG_P (orig_operand
[i
])
3502 && MEM_P (substed_operand
[i
])
3504 emit_insn_after (gen_clobber (orig_operand
[i
]), insn
);
3508 for (i
= 0; i
< recog_data
.n_dups
; i
++)
3509 *recog_data
.dup_loc
[i
]
3510 = *recog_data
.operand_loc
[(int) recog_data
.dup_num
[i
]];
3512 /* If any eliminable remain, they aren't eliminable anymore. */
3513 check_eliminable_occurrences (old_body
);
3515 /* Substitute the operands; the new values are in the substed_operand
3517 for (i
= 0; i
< recog_data
.n_operands
; i
++)
3518 *recog_data
.operand_loc
[i
] = substed_operand
[i
];
3519 for (i
= 0; i
< recog_data
.n_dups
; i
++)
3520 *recog_data
.dup_loc
[i
] = substed_operand
[(int) recog_data
.dup_num
[i
]];
3522 /* If we are replacing a body that was a (set X (plus Y Z)), try to
3523 re-recognize the insn. We do this in case we had a simple addition
3524 but now can do this as a load-address. This saves an insn in this
3526 If re-recognition fails, the old insn code number will still be used,
3527 and some register operands may have changed into PLUS expressions.
3528 These will be handled by find_reloads by loading them into a register
3533 /* If we aren't replacing things permanently and we changed something,
3534 make another copy to ensure that all the RTL is new. Otherwise
3535 things can go wrong if find_reload swaps commutative operands
3536 and one is inside RTL that has been copied while the other is not. */
3537 new_body
= old_body
;
3540 new_body
= copy_insn (old_body
);
3541 if (REG_NOTES (insn
))
3542 REG_NOTES (insn
) = copy_insn_1 (REG_NOTES (insn
));
3544 PATTERN (insn
) = new_body
;
3546 /* If we had a move insn but now we don't, rerecognize it. This will
3547 cause spurious re-recognition if the old move had a PARALLEL since
3548 the new one still will, but we can't call single_set without
3549 having put NEW_BODY into the insn and the re-recognition won't
3550 hurt in this rare case. */
3551 /* ??? Why this huge if statement - why don't we just rerecognize the
3555 && ((REG_P (SET_SRC (old_set
))
3556 && (GET_CODE (new_body
) != SET
3557 || !REG_P (SET_SRC (new_body
))))
3558 /* If this was a load from or store to memory, compare
3559 the MEM in recog_data.operand to the one in the insn.
3560 If they are not equal, then rerecognize the insn. */
3562 && ((MEM_P (SET_SRC (old_set
))
3563 && SET_SRC (old_set
) != recog_data
.operand
[1])
3564 || (MEM_P (SET_DEST (old_set
))
3565 && SET_DEST (old_set
) != recog_data
.operand
[0])))
3566 /* If this was an add insn before, rerecognize. */
3567 || GET_CODE (SET_SRC (old_set
)) == PLUS
))
3569 int new_icode
= recog (PATTERN (insn
), insn
, 0);
3571 INSN_CODE (insn
) = new_icode
;
3575 /* Restore the old body. If there were any changes to it, we made a copy
3576 of it while the changes were still in place, so we'll correctly return
3577 a modified insn below. */
3580 /* Restore the old body. */
3581 for (i
= 0; i
< recog_data
.n_operands
; i
++)
3582 /* Restoring a top-level match_parallel would clobber the new_body
3583 we installed in the insn. */
3584 if (recog_data
.operand_loc
[i
] != &PATTERN (insn
))
3585 *recog_data
.operand_loc
[i
] = orig_operand
[i
];
3586 for (i
= 0; i
< recog_data
.n_dups
; i
++)
3587 *recog_data
.dup_loc
[i
] = orig_operand
[(int) recog_data
.dup_num
[i
]];
3590 /* Update all elimination pairs to reflect the status after the current
3591 insn. The changes we make were determined by the earlier call to
3592 elimination_effects.
3594 We also detect cases where register elimination cannot be done,
3595 namely, if a register would be both changed and referenced outside a MEM
3596 in the resulting insn since such an insn is often undefined and, even if
3597 not, we cannot know what meaning will be given to it. Note that it is
3598 valid to have a register used in an address in an insn that changes it
3599 (presumably with a pre- or post-increment or decrement).
3601 If anything changes, return nonzero. */
3603 for (ep
= reg_eliminate
; ep
< ®_eliminate
[NUM_ELIMINABLE_REGS
]; ep
++)
3605 if (ep
->previous_offset
!= ep
->offset
&& ep
->ref_outside_mem
)
3606 ep
->can_eliminate
= 0;
3608 ep
->ref_outside_mem
= 0;
3610 if (ep
->previous_offset
!= ep
->offset
)
3615 /* If we changed something, perform elimination in REG_NOTES. This is
3616 needed even when REPLACE is zero because a REG_DEAD note might refer
3617 to a register that we eliminate and could cause a different number
3618 of spill registers to be needed in the final reload pass than in
3620 if (val
&& REG_NOTES (insn
) != 0)
3622 = eliminate_regs_1 (REG_NOTES (insn
), VOIDmode
, REG_NOTES (insn
), true,
3628 /* Like eliminate_regs_in_insn, but only estimate costs for the use of the
3629 register allocator. INSN is the instruction we need to examine, we perform
3630 eliminations in its operands and record cases where eliminating a reg with
3631 an invariant equivalence would add extra cost. */
3634 elimination_costs_in_insn (rtx insn
)
3636 int icode
= recog_memoized (insn
);
3637 rtx old_body
= PATTERN (insn
);
3638 int insn_is_asm
= asm_noperands (old_body
) >= 0;
3639 rtx old_set
= single_set (insn
);
3641 rtx orig_operand
[MAX_RECOG_OPERANDS
];
3642 rtx orig_dup
[MAX_RECOG_OPERANDS
];
3643 struct elim_table
*ep
;
3644 rtx plus_src
, plus_cst_src
;
3647 if (! insn_is_asm
&& icode
< 0)
3649 gcc_assert (GET_CODE (PATTERN (insn
)) == USE
3650 || GET_CODE (PATTERN (insn
)) == CLOBBER
3651 || GET_CODE (PATTERN (insn
)) == ADDR_VEC
3652 || GET_CODE (PATTERN (insn
)) == ADDR_DIFF_VEC
3653 || GET_CODE (PATTERN (insn
)) == ASM_INPUT
3654 || DEBUG_INSN_P (insn
));
3658 if (old_set
!= 0 && REG_P (SET_DEST (old_set
))
3659 && REGNO (SET_DEST (old_set
)) < FIRST_PSEUDO_REGISTER
)
3661 /* Check for setting an eliminable register. */
3662 for (ep
= reg_eliminate
; ep
< ®_eliminate
[NUM_ELIMINABLE_REGS
]; ep
++)
3663 if (ep
->from_rtx
== SET_DEST (old_set
) && ep
->can_eliminate
)
3667 /* We allow one special case which happens to work on all machines we
3668 currently support: a single set with the source or a REG_EQUAL
3669 note being a PLUS of an eliminable register and a constant. */
3670 plus_src
= plus_cst_src
= 0;
3672 if (old_set
&& REG_P (SET_DEST (old_set
)))
3675 if (GET_CODE (SET_SRC (old_set
)) == PLUS
)
3676 plus_src
= SET_SRC (old_set
);
3677 /* First see if the source is of the form (plus (...) CST). */
3679 && CONST_INT_P (XEXP (plus_src
, 1)))
3680 plus_cst_src
= plus_src
;
3681 else if (REG_P (SET_SRC (old_set
))
3684 /* Otherwise, see if we have a REG_EQUAL note of the form
3685 (plus (...) CST). */
3687 for (links
= REG_NOTES (insn
); links
; links
= XEXP (links
, 1))
3689 if ((REG_NOTE_KIND (links
) == REG_EQUAL
3690 || REG_NOTE_KIND (links
) == REG_EQUIV
)
3691 && GET_CODE (XEXP (links
, 0)) == PLUS
3692 && CONST_INT_P (XEXP (XEXP (links
, 0), 1)))
3694 plus_cst_src
= XEXP (links
, 0);
3701 /* Determine the effects of this insn on elimination offsets. */
3702 elimination_effects (old_body
, VOIDmode
);
3704 /* Eliminate all eliminable registers occurring in operands that
3705 can be handled by reload. */
3706 extract_insn (insn
);
3707 for (i
= 0; i
< recog_data
.n_dups
; i
++)
3708 orig_dup
[i
] = *recog_data
.dup_loc
[i
];
3710 for (i
= 0; i
< recog_data
.n_operands
; i
++)
3712 orig_operand
[i
] = recog_data
.operand
[i
];
3714 /* For an asm statement, every operand is eliminable. */
3715 if (insn_is_asm
|| insn_data
[icode
].operand
[i
].eliminable
)
3717 bool is_set_src
, in_plus
;
3719 /* Check for setting a register that we know about. */
3720 if (recog_data
.operand_type
[i
] != OP_IN
3721 && REG_P (orig_operand
[i
]))
3723 /* If we are assigning to a register that can be eliminated, it
3724 must be as part of a PARALLEL, since the code above handles
3725 single SETs. We must indicate that we can no longer
3726 eliminate this reg. */
3727 for (ep
= reg_eliminate
; ep
< ®_eliminate
[NUM_ELIMINABLE_REGS
];
3729 if (ep
->from_rtx
== orig_operand
[i
])
3730 ep
->can_eliminate
= 0;
3733 /* Companion to the above plus substitution, we can allow
3734 invariants as the source of a plain move. */
3736 if (old_set
&& recog_data
.operand_loc
[i
] == &SET_SRC (old_set
))
3738 if (is_set_src
&& !sets_reg_p
)
3739 note_reg_elim_costly (&SET_SRC (old_set
), insn
);
3741 if (plus_src
&& sets_reg_p
3742 && (recog_data
.operand_loc
[i
] == &XEXP (plus_src
, 0)
3743 || recog_data
.operand_loc
[i
] == &XEXP (plus_src
, 1)))
3746 eliminate_regs_1 (recog_data
.operand
[i
], VOIDmode
,
3748 is_set_src
|| in_plus
, true);
3749 /* Terminate the search in check_eliminable_occurrences at
3751 *recog_data
.operand_loc
[i
] = 0;
3755 for (i
= 0; i
< recog_data
.n_dups
; i
++)
3756 *recog_data
.dup_loc
[i
]
3757 = *recog_data
.operand_loc
[(int) recog_data
.dup_num
[i
]];
3759 /* If any eliminable remain, they aren't eliminable anymore. */
3760 check_eliminable_occurrences (old_body
);
3762 /* Restore the old body. */
3763 for (i
= 0; i
< recog_data
.n_operands
; i
++)
3764 *recog_data
.operand_loc
[i
] = orig_operand
[i
];
3765 for (i
= 0; i
< recog_data
.n_dups
; i
++)
3766 *recog_data
.dup_loc
[i
] = orig_dup
[i
];
3768 /* Update all elimination pairs to reflect the status after the current
3769 insn. The changes we make were determined by the earlier call to
3770 elimination_effects. */
3772 for (ep
= reg_eliminate
; ep
< ®_eliminate
[NUM_ELIMINABLE_REGS
]; ep
++)
3774 if (ep
->previous_offset
!= ep
->offset
&& ep
->ref_outside_mem
)
3775 ep
->can_eliminate
= 0;
3777 ep
->ref_outside_mem
= 0;
3783 /* Loop through all elimination pairs.
3784 Recalculate the number not at initial offset.
3786 Compute the maximum offset (minimum offset if the stack does not
3787 grow downward) for each elimination pair. */
3790 update_eliminable_offsets (void)
3792 struct elim_table
*ep
;
3794 num_not_at_initial_offset
= 0;
3795 for (ep
= reg_eliminate
; ep
< ®_eliminate
[NUM_ELIMINABLE_REGS
]; ep
++)
3797 ep
->previous_offset
= ep
->offset
;
3798 if (ep
->can_eliminate
&& ep
->offset
!= ep
->initial_offset
)
3799 num_not_at_initial_offset
++;
3803 /* Given X, a SET or CLOBBER of DEST, if DEST is the target of a register
3804 replacement we currently believe is valid, mark it as not eliminable if X
3805 modifies DEST in any way other than by adding a constant integer to it.
3807 If DEST is the frame pointer, we do nothing because we assume that
3808 all assignments to the hard frame pointer are nonlocal gotos and are being
3809 done at a time when they are valid and do not disturb anything else.
3810 Some machines want to eliminate a fake argument pointer with either the
3811 frame or stack pointer. Assignments to the hard frame pointer must not
3812 prevent this elimination.
3814 Called via note_stores from reload before starting its passes to scan
3815 the insns of the function. */
3818 mark_not_eliminable (rtx dest
, const_rtx x
, void *data ATTRIBUTE_UNUSED
)
3822 /* A SUBREG of a hard register here is just changing its mode. We should
3823 not see a SUBREG of an eliminable hard register, but check just in
3825 if (GET_CODE (dest
) == SUBREG
)
3826 dest
= SUBREG_REG (dest
);
3828 if (dest
== hard_frame_pointer_rtx
)
3831 for (i
= 0; i
< NUM_ELIMINABLE_REGS
; i
++)
3832 if (reg_eliminate
[i
].can_eliminate
&& dest
== reg_eliminate
[i
].to_rtx
3833 && (GET_CODE (x
) != SET
3834 || GET_CODE (SET_SRC (x
)) != PLUS
3835 || XEXP (SET_SRC (x
), 0) != dest
3836 || !CONST_INT_P (XEXP (SET_SRC (x
), 1))))
3838 reg_eliminate
[i
].can_eliminate_previous
3839 = reg_eliminate
[i
].can_eliminate
= 0;
3844 /* Verify that the initial elimination offsets did not change since the
3845 last call to set_initial_elim_offsets. This is used to catch cases
3846 where something illegal happened during reload_as_needed that could
3847 cause incorrect code to be generated if we did not check for it. */
3850 verify_initial_elim_offsets (void)
3854 if (!num_eliminable
)
3857 #ifdef ELIMINABLE_REGS
3859 struct elim_table
*ep
;
3861 for (ep
= reg_eliminate
; ep
< ®_eliminate
[NUM_ELIMINABLE_REGS
]; ep
++)
3863 INITIAL_ELIMINATION_OFFSET (ep
->from
, ep
->to
, t
);
3864 if (t
!= ep
->initial_offset
)
3869 INITIAL_FRAME_POINTER_OFFSET (t
);
3870 if (t
!= reg_eliminate
[0].initial_offset
)
3877 /* Reset all offsets on eliminable registers to their initial values. */
3880 set_initial_elim_offsets (void)
3882 struct elim_table
*ep
= reg_eliminate
;
3884 #ifdef ELIMINABLE_REGS
3885 for (; ep
< ®_eliminate
[NUM_ELIMINABLE_REGS
]; ep
++)
3887 INITIAL_ELIMINATION_OFFSET (ep
->from
, ep
->to
, ep
->initial_offset
);
3888 ep
->previous_offset
= ep
->offset
= ep
->initial_offset
;
3891 INITIAL_FRAME_POINTER_OFFSET (ep
->initial_offset
);
3892 ep
->previous_offset
= ep
->offset
= ep
->initial_offset
;
3895 num_not_at_initial_offset
= 0;
3898 /* Subroutine of set_initial_label_offsets called via for_each_eh_label. */
3901 set_initial_eh_label_offset (rtx label
)
3903 set_label_offsets (label
, NULL_RTX
, 1);
3906 /* Initialize the known label offsets.
3907 Set a known offset for each forced label to be at the initial offset
3908 of each elimination. We do this because we assume that all
3909 computed jumps occur from a location where each elimination is
3910 at its initial offset.
3911 For all other labels, show that we don't know the offsets. */
3914 set_initial_label_offsets (void)
3917 memset (offsets_known_at
, 0, num_labels
);
3919 for (x
= forced_labels
; x
; x
= XEXP (x
, 1))
3921 set_label_offsets (XEXP (x
, 0), NULL_RTX
, 1);
3923 for (x
= nonlocal_goto_handler_labels
; x
; x
= XEXP (x
, 1))
3925 set_label_offsets (XEXP (x
, 0), NULL_RTX
, 1);
3927 for_each_eh_label (set_initial_eh_label_offset
);
3930 /* Set all elimination offsets to the known values for the code label given
3934 set_offsets_for_label (rtx insn
)
3937 int label_nr
= CODE_LABEL_NUMBER (insn
);
3938 struct elim_table
*ep
;
3940 num_not_at_initial_offset
= 0;
3941 for (i
= 0, ep
= reg_eliminate
; i
< NUM_ELIMINABLE_REGS
; ep
++, i
++)
3943 ep
->offset
= ep
->previous_offset
3944 = offsets_at
[label_nr
- first_label_num
][i
];
3945 if (ep
->can_eliminate
&& ep
->offset
!= ep
->initial_offset
)
3946 num_not_at_initial_offset
++;
3950 /* See if anything that happened changes which eliminations are valid.
3951 For example, on the SPARC, whether or not the frame pointer can
3952 be eliminated can depend on what registers have been used. We need
3953 not check some conditions again (such as flag_omit_frame_pointer)
3954 since they can't have changed. */
3957 update_eliminables (HARD_REG_SET
*pset
)
3959 int previous_frame_pointer_needed
= frame_pointer_needed
;
3960 struct elim_table
*ep
;
3962 for (ep
= reg_eliminate
; ep
< ®_eliminate
[NUM_ELIMINABLE_REGS
]; ep
++)
3963 if ((ep
->from
== HARD_FRAME_POINTER_REGNUM
3964 && targetm
.frame_pointer_required ())
3965 #ifdef ELIMINABLE_REGS
3966 || ! targetm
.can_eliminate (ep
->from
, ep
->to
)
3969 ep
->can_eliminate
= 0;
3971 /* Look for the case where we have discovered that we can't replace
3972 register A with register B and that means that we will now be
3973 trying to replace register A with register C. This means we can
3974 no longer replace register C with register B and we need to disable
3975 such an elimination, if it exists. This occurs often with A == ap,
3976 B == sp, and C == fp. */
3978 for (ep
= reg_eliminate
; ep
< ®_eliminate
[NUM_ELIMINABLE_REGS
]; ep
++)
3980 struct elim_table
*op
;
3983 if (! ep
->can_eliminate
&& ep
->can_eliminate_previous
)
3985 /* Find the current elimination for ep->from, if there is a
3987 for (op
= reg_eliminate
;
3988 op
< ®_eliminate
[NUM_ELIMINABLE_REGS
]; op
++)
3989 if (op
->from
== ep
->from
&& op
->can_eliminate
)
3995 /* See if there is an elimination of NEW_TO -> EP->TO. If so,
3997 for (op
= reg_eliminate
;
3998 op
< ®_eliminate
[NUM_ELIMINABLE_REGS
]; op
++)
3999 if (op
->from
== new_to
&& op
->to
== ep
->to
)
4000 op
->can_eliminate
= 0;
4004 /* See if any registers that we thought we could eliminate the previous
4005 time are no longer eliminable. If so, something has changed and we
4006 must spill the register. Also, recompute the number of eliminable
4007 registers and see if the frame pointer is needed; it is if there is
4008 no elimination of the frame pointer that we can perform. */
4010 frame_pointer_needed
= 1;
4011 for (ep
= reg_eliminate
; ep
< ®_eliminate
[NUM_ELIMINABLE_REGS
]; ep
++)
4013 if (ep
->can_eliminate
4014 && ep
->from
== FRAME_POINTER_REGNUM
4015 && ep
->to
!= HARD_FRAME_POINTER_REGNUM
4016 && (! SUPPORTS_STACK_ALIGNMENT
4017 || ! crtl
->stack_realign_needed
))
4018 frame_pointer_needed
= 0;
4020 if (! ep
->can_eliminate
&& ep
->can_eliminate_previous
)
4022 ep
->can_eliminate_previous
= 0;
4023 SET_HARD_REG_BIT (*pset
, ep
->from
);
4028 /* If we didn't need a frame pointer last time, but we do now, spill
4029 the hard frame pointer. */
4030 if (frame_pointer_needed
&& ! previous_frame_pointer_needed
)
4031 SET_HARD_REG_BIT (*pset
, HARD_FRAME_POINTER_REGNUM
);
4034 /* Return true if X is used as the target register of an elimination. */
4037 elimination_target_reg_p (rtx x
)
4039 struct elim_table
*ep
;
4041 for (ep
= reg_eliminate
; ep
< ®_eliminate
[NUM_ELIMINABLE_REGS
]; ep
++)
4042 if (ep
->to_rtx
== x
&& ep
->can_eliminate
)
4048 /* Initialize the table of registers to eliminate.
4049 Pre-condition: global flag frame_pointer_needed has been set before
4050 calling this function. */
4053 init_elim_table (void)
4055 struct elim_table
*ep
;
4056 #ifdef ELIMINABLE_REGS
4057 const struct elim_table_1
*ep1
;
4061 reg_eliminate
= XCNEWVEC (struct elim_table
, NUM_ELIMINABLE_REGS
);
4065 #ifdef ELIMINABLE_REGS
4066 for (ep
= reg_eliminate
, ep1
= reg_eliminate_1
;
4067 ep
< ®_eliminate
[NUM_ELIMINABLE_REGS
]; ep
++, ep1
++)
4069 ep
->from
= ep1
->from
;
4071 ep
->can_eliminate
= ep
->can_eliminate_previous
4072 = (targetm
.can_eliminate (ep
->from
, ep
->to
)
4073 && ! (ep
->to
== STACK_POINTER_REGNUM
4074 && frame_pointer_needed
4075 && (! SUPPORTS_STACK_ALIGNMENT
4076 || ! stack_realign_fp
)));
4079 reg_eliminate
[0].from
= reg_eliminate_1
[0].from
;
4080 reg_eliminate
[0].to
= reg_eliminate_1
[0].to
;
4081 reg_eliminate
[0].can_eliminate
= reg_eliminate
[0].can_eliminate_previous
4082 = ! frame_pointer_needed
;
4085 /* Count the number of eliminable registers and build the FROM and TO
4086 REG rtx's. Note that code in gen_rtx_REG will cause, e.g.,
4087 gen_rtx_REG (Pmode, STACK_POINTER_REGNUM) to equal stack_pointer_rtx.
4088 We depend on this. */
4089 for (ep
= reg_eliminate
; ep
< ®_eliminate
[NUM_ELIMINABLE_REGS
]; ep
++)
4091 num_eliminable
+= ep
->can_eliminate
;
4092 ep
->from_rtx
= gen_rtx_REG (Pmode
, ep
->from
);
4093 ep
->to_rtx
= gen_rtx_REG (Pmode
, ep
->to
);
4097 /* Find all the pseudo registers that didn't get hard regs
4098 but do have known equivalent constants or memory slots.
4099 These include parameters (known equivalent to parameter slots)
4100 and cse'd or loop-moved constant memory addresses.
4102 Record constant equivalents in reg_equiv_constant
4103 so they will be substituted by find_reloads.
4104 Record memory equivalents in reg_mem_equiv so they can
4105 be substituted eventually by altering the REG-rtx's. */
4108 init_eliminable_invariants (rtx first
, bool do_subregs
)
4115 reg_max_ref_width
= XCNEWVEC (unsigned int, max_regno
);
4117 reg_max_ref_width
= NULL
;
4119 num_eliminable_invariants
= 0;
4121 first_label_num
= get_first_label_num ();
4122 num_labels
= max_label_num () - first_label_num
;
4124 /* Allocate the tables used to store offset information at labels. */
4125 offsets_known_at
= XNEWVEC (char, num_labels
);
4126 offsets_at
= (HOST_WIDE_INT (*)[NUM_ELIMINABLE_REGS
]) xmalloc (num_labels
* NUM_ELIMINABLE_REGS
* sizeof (HOST_WIDE_INT
));
4128 /* Look for REG_EQUIV notes; record what each pseudo is equivalent
4129 to. If DO_SUBREGS is true, also find all paradoxical subregs and
4130 find largest such for each pseudo. FIRST is the head of the insn
4133 for (insn
= first
; insn
; insn
= NEXT_INSN (insn
))
4135 rtx set
= single_set (insn
);
4137 /* We may introduce USEs that we want to remove at the end, so
4138 we'll mark them with QImode. Make sure there are no
4139 previously-marked insns left by say regmove. */
4140 if (INSN_P (insn
) && GET_CODE (PATTERN (insn
)) == USE
4141 && GET_MODE (insn
) != VOIDmode
)
4142 PUT_MODE (insn
, VOIDmode
);
4144 if (do_subregs
&& NONDEBUG_INSN_P (insn
))
4145 scan_paradoxical_subregs (PATTERN (insn
));
4147 if (set
!= 0 && REG_P (SET_DEST (set
)))
4149 rtx note
= find_reg_note (insn
, REG_EQUIV
, NULL_RTX
);
4155 i
= REGNO (SET_DEST (set
));
4158 if (i
<= LAST_VIRTUAL_REGISTER
)
4161 /* If flag_pic and we have constant, verify it's legitimate. */
4163 || !flag_pic
|| LEGITIMATE_PIC_OPERAND_P (x
))
4165 /* It can happen that a REG_EQUIV note contains a MEM
4166 that is not a legitimate memory operand. As later
4167 stages of reload assume that all addresses found
4168 in the reg_equiv_* arrays were originally legitimate,
4169 we ignore such REG_EQUIV notes. */
4170 if (memory_operand (x
, VOIDmode
))
4172 /* Always unshare the equivalence, so we can
4173 substitute into this insn without touching the
4175 reg_equiv_memory_loc (i
) = copy_rtx (x
);
4177 else if (function_invariant_p (x
))
4179 enum machine_mode mode
;
4181 mode
= GET_MODE (SET_DEST (set
));
4182 if (GET_CODE (x
) == PLUS
)
4184 /* This is PLUS of frame pointer and a constant,
4185 and might be shared. Unshare it. */
4186 reg_equiv_invariant (i
) = copy_rtx (x
);
4187 num_eliminable_invariants
++;
4189 else if (x
== frame_pointer_rtx
|| x
== arg_pointer_rtx
)
4191 reg_equiv_invariant (i
) = x
;
4192 num_eliminable_invariants
++;
4194 else if (targetm
.legitimate_constant_p (mode
, x
))
4195 reg_equiv_constant (i
) = x
;
4198 reg_equiv_memory_loc (i
) = force_const_mem (mode
, x
);
4199 if (! reg_equiv_memory_loc (i
))
4200 reg_equiv_init (i
) = NULL_RTX
;
4205 reg_equiv_init (i
) = NULL_RTX
;
4210 reg_equiv_init (i
) = NULL_RTX
;
4215 for (i
= FIRST_PSEUDO_REGISTER
; i
< max_regno
; i
++)
4216 if (reg_equiv_init (i
))
4218 fprintf (dump_file
, "init_insns for %u: ", i
);
4219 print_inline_rtx (dump_file
, reg_equiv_init (i
), 20);
4220 fprintf (dump_file
, "\n");
4224 /* Indicate that we no longer have known memory locations or constants.
4225 Free all data involved in tracking these. */
4228 free_reg_equiv (void)
4233 free (offsets_known_at
);
4236 offsets_known_at
= 0;
4238 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
4239 if (reg_equiv_alt_mem_list (i
))
4240 free_EXPR_LIST_list (®_equiv_alt_mem_list (i
));
4241 VEC_free (reg_equivs_t
, gc
, reg_equivs
);
4246 /* Kick all pseudos out of hard register REGNO.
4248 If CANT_ELIMINATE is nonzero, it means that we are doing this spill
4249 because we found we can't eliminate some register. In the case, no pseudos
4250 are allowed to be in the register, even if they are only in a block that
4251 doesn't require spill registers, unlike the case when we are spilling this
4252 hard reg to produce another spill register.
4254 Return nonzero if any pseudos needed to be kicked out. */
4257 spill_hard_reg (unsigned int regno
, int cant_eliminate
)
4263 SET_HARD_REG_BIT (bad_spill_regs_global
, regno
);
4264 df_set_regs_ever_live (regno
, true);
4267 /* Spill every pseudo reg that was allocated to this reg
4268 or to something that overlaps this reg. */
4270 for (i
= FIRST_PSEUDO_REGISTER
; i
< max_regno
; i
++)
4271 if (reg_renumber
[i
] >= 0
4272 && (unsigned int) reg_renumber
[i
] <= regno
4273 && end_hard_regno (PSEUDO_REGNO_MODE (i
), reg_renumber
[i
]) > regno
)
4274 SET_REGNO_REG_SET (&spilled_pseudos
, i
);
4277 /* After find_reload_regs has been run for all insn that need reloads,
4278 and/or spill_hard_regs was called, this function is used to actually
4279 spill pseudo registers and try to reallocate them. It also sets up the
4280 spill_regs array for use by choose_reload_regs. */
4283 finish_spills (int global
)
4285 struct insn_chain
*chain
;
4286 int something_changed
= 0;
4288 reg_set_iterator rsi
;
4290 /* Build the spill_regs array for the function. */
4291 /* If there are some registers still to eliminate and one of the spill regs
4292 wasn't ever used before, additional stack space may have to be
4293 allocated to store this register. Thus, we may have changed the offset
4294 between the stack and frame pointers, so mark that something has changed.
4296 One might think that we need only set VAL to 1 if this is a call-used
4297 register. However, the set of registers that must be saved by the
4298 prologue is not identical to the call-used set. For example, the
4299 register used by the call insn for the return PC is a call-used register,
4300 but must be saved by the prologue. */
4303 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
4304 if (TEST_HARD_REG_BIT (used_spill_regs
, i
))
4306 spill_reg_order
[i
] = n_spills
;
4307 spill_regs
[n_spills
++] = i
;
4308 if (num_eliminable
&& ! df_regs_ever_live_p (i
))
4309 something_changed
= 1;
4310 df_set_regs_ever_live (i
, true);
4313 spill_reg_order
[i
] = -1;
4315 EXECUTE_IF_SET_IN_REG_SET (&spilled_pseudos
, FIRST_PSEUDO_REGISTER
, i
, rsi
)
4316 if (! ira_conflicts_p
|| reg_renumber
[i
] >= 0)
4318 /* Record the current hard register the pseudo is allocated to
4319 in pseudo_previous_regs so we avoid reallocating it to the
4320 same hard reg in a later pass. */
4321 gcc_assert (reg_renumber
[i
] >= 0);
4323 SET_HARD_REG_BIT (pseudo_previous_regs
[i
], reg_renumber
[i
]);
4324 /* Mark it as no longer having a hard register home. */
4325 reg_renumber
[i
] = -1;
4326 if (ira_conflicts_p
)
4327 /* Inform IRA about the change. */
4328 ira_mark_allocation_change (i
);
4329 /* We will need to scan everything again. */
4330 something_changed
= 1;
4333 /* Retry global register allocation if possible. */
4334 if (global
&& ira_conflicts_p
)
4338 memset (pseudo_forbidden_regs
, 0, max_regno
* sizeof (HARD_REG_SET
));
4339 /* For every insn that needs reloads, set the registers used as spill
4340 regs in pseudo_forbidden_regs for every pseudo live across the
4342 for (chain
= insns_need_reload
; chain
; chain
= chain
->next_need_reload
)
4344 EXECUTE_IF_SET_IN_REG_SET
4345 (&chain
->live_throughout
, FIRST_PSEUDO_REGISTER
, i
, rsi
)
4347 IOR_HARD_REG_SET (pseudo_forbidden_regs
[i
],
4348 chain
->used_spill_regs
);
4350 EXECUTE_IF_SET_IN_REG_SET
4351 (&chain
->dead_or_set
, FIRST_PSEUDO_REGISTER
, i
, rsi
)
4353 IOR_HARD_REG_SET (pseudo_forbidden_regs
[i
],
4354 chain
->used_spill_regs
);
4358 /* Retry allocating the pseudos spilled in IRA and the
4359 reload. For each reg, merge the various reg sets that
4360 indicate which hard regs can't be used, and call
4361 ira_reassign_pseudos. */
4362 for (n
= 0, i
= FIRST_PSEUDO_REGISTER
; i
< (unsigned) max_regno
; i
++)
4363 if (reg_old_renumber
[i
] != reg_renumber
[i
])
4365 if (reg_renumber
[i
] < 0)
4366 temp_pseudo_reg_arr
[n
++] = i
;
4368 CLEAR_REGNO_REG_SET (&spilled_pseudos
, i
);
4370 if (ira_reassign_pseudos (temp_pseudo_reg_arr
, n
,
4371 bad_spill_regs_global
,
4372 pseudo_forbidden_regs
, pseudo_previous_regs
,
4374 something_changed
= 1;
4376 /* Fix up the register information in the insn chain.
4377 This involves deleting those of the spilled pseudos which did not get
4378 a new hard register home from the live_{before,after} sets. */
4379 for (chain
= reload_insn_chain
; chain
; chain
= chain
->next
)
4381 HARD_REG_SET used_by_pseudos
;
4382 HARD_REG_SET used_by_pseudos2
;
4384 if (! ira_conflicts_p
)
4386 /* Don't do it for IRA because IRA and the reload still can
4387 assign hard registers to the spilled pseudos on next
4388 reload iterations. */
4389 AND_COMPL_REG_SET (&chain
->live_throughout
, &spilled_pseudos
);
4390 AND_COMPL_REG_SET (&chain
->dead_or_set
, &spilled_pseudos
);
4392 /* Mark any unallocated hard regs as available for spills. That
4393 makes inheritance work somewhat better. */
4394 if (chain
->need_reload
)
4396 REG_SET_TO_HARD_REG_SET (used_by_pseudos
, &chain
->live_throughout
);
4397 REG_SET_TO_HARD_REG_SET (used_by_pseudos2
, &chain
->dead_or_set
);
4398 IOR_HARD_REG_SET (used_by_pseudos
, used_by_pseudos2
);
4400 compute_use_by_pseudos (&used_by_pseudos
, &chain
->live_throughout
);
4401 compute_use_by_pseudos (&used_by_pseudos
, &chain
->dead_or_set
);
4402 /* Value of chain->used_spill_regs from previous iteration
4403 may be not included in the value calculated here because
4404 of possible removing caller-saves insns (see function
4405 delete_caller_save_insns. */
4406 COMPL_HARD_REG_SET (chain
->used_spill_regs
, used_by_pseudos
);
4407 AND_HARD_REG_SET (chain
->used_spill_regs
, used_spill_regs
);
4411 CLEAR_REG_SET (&changed_allocation_pseudos
);
4412 /* Let alter_reg modify the reg rtx's for the modified pseudos. */
4413 for (i
= FIRST_PSEUDO_REGISTER
; i
< (unsigned)max_regno
; i
++)
4415 int regno
= reg_renumber
[i
];
4416 if (reg_old_renumber
[i
] == regno
)
4419 SET_REGNO_REG_SET (&changed_allocation_pseudos
, i
);
4421 alter_reg (i
, reg_old_renumber
[i
], false);
4422 reg_old_renumber
[i
] = regno
;
4426 fprintf (dump_file
, " Register %d now on stack.\n\n", i
);
4428 fprintf (dump_file
, " Register %d now in %d.\n\n",
4429 i
, reg_renumber
[i
]);
4433 return something_changed
;
4436 /* Find all paradoxical subregs within X and update reg_max_ref_width. */
4439 scan_paradoxical_subregs (rtx x
)
4443 enum rtx_code code
= GET_CODE (x
);
4459 if (REG_P (SUBREG_REG (x
))
4460 && (GET_MODE_SIZE (GET_MODE (x
))
4461 > reg_max_ref_width
[REGNO (SUBREG_REG (x
))]))
4463 reg_max_ref_width
[REGNO (SUBREG_REG (x
))]
4464 = GET_MODE_SIZE (GET_MODE (x
));
4465 mark_home_live_1 (REGNO (SUBREG_REG (x
)), GET_MODE (x
));
4473 fmt
= GET_RTX_FORMAT (code
);
4474 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
4477 scan_paradoxical_subregs (XEXP (x
, i
));
4478 else if (fmt
[i
] == 'E')
4481 for (j
= XVECLEN (x
, i
) - 1; j
>= 0; j
--)
4482 scan_paradoxical_subregs (XVECEXP (x
, i
, j
));
4487 /* *OP_PTR and *OTHER_PTR are two operands to a conceptual reload.
4488 If *OP_PTR is a paradoxical subreg, try to remove that subreg
4489 and apply the corresponding narrowing subreg to *OTHER_PTR.
4490 Return true if the operands were changed, false otherwise. */
4493 strip_paradoxical_subreg (rtx
*op_ptr
, rtx
*other_ptr
)
4495 rtx op
, inner
, other
, tem
;
4498 if (!paradoxical_subreg_p (op
))
4500 inner
= SUBREG_REG (op
);
4503 tem
= gen_lowpart_common (GET_MODE (inner
), other
);
4507 /* If the lowpart operation turned a hard register into a subreg,
4508 rather than simplifying it to another hard register, then the
4509 mode change cannot be properly represented. For example, OTHER
4510 might be valid in its current mode, but not in the new one. */
4511 if (GET_CODE (tem
) == SUBREG
4513 && HARD_REGISTER_P (other
))
4521 /* A subroutine of reload_as_needed. If INSN has a REG_EH_REGION note,
4522 examine all of the reload insns between PREV and NEXT exclusive, and
4523 annotate all that may trap. */
4526 fixup_eh_region_note (rtx insn
, rtx prev
, rtx next
)
4528 rtx note
= find_reg_note (insn
, REG_EH_REGION
, NULL_RTX
);
4531 if (!insn_could_throw_p (insn
))
4532 remove_note (insn
, note
);
4533 copy_reg_eh_region_note_forward (note
, NEXT_INSN (prev
), next
);
4536 /* Reload pseudo-registers into hard regs around each insn as needed.
4537 Additional register load insns are output before the insn that needs it
4538 and perhaps store insns after insns that modify the reloaded pseudo reg.
4540 reg_last_reload_reg and reg_reloaded_contents keep track of
4541 which registers are already available in reload registers.
4542 We update these for the reloads that we perform,
4543 as the insns are scanned. */
4546 reload_as_needed (int live_known
)
4548 struct insn_chain
*chain
;
4549 #if defined (AUTO_INC_DEC)
4554 memset (spill_reg_rtx
, 0, sizeof spill_reg_rtx
);
4555 memset (spill_reg_store
, 0, sizeof spill_reg_store
);
4556 reg_last_reload_reg
= XCNEWVEC (rtx
, max_regno
);
4557 INIT_REG_SET (®_has_output_reload
);
4558 CLEAR_HARD_REG_SET (reg_reloaded_valid
);
4559 CLEAR_HARD_REG_SET (reg_reloaded_call_part_clobbered
);
4561 set_initial_elim_offsets ();
4563 /* Generate a marker insn that we will move around. */
4564 marker
= emit_note (NOTE_INSN_DELETED
);
4565 unlink_insn_chain (marker
, marker
);
4567 for (chain
= reload_insn_chain
; chain
; chain
= chain
->next
)
4570 rtx insn
= chain
->insn
;
4571 rtx old_next
= NEXT_INSN (insn
);
4573 rtx old_prev
= PREV_INSN (insn
);
4576 /* If we pass a label, copy the offsets from the label information
4577 into the current offsets of each elimination. */
4579 set_offsets_for_label (insn
);
4581 else if (INSN_P (insn
))
4583 regset_head regs_to_forget
;
4584 INIT_REG_SET (®s_to_forget
);
4585 note_stores (PATTERN (insn
), forget_old_reloads_1
, ®s_to_forget
);
4587 /* If this is a USE and CLOBBER of a MEM, ensure that any
4588 references to eliminable registers have been removed. */
4590 if ((GET_CODE (PATTERN (insn
)) == USE
4591 || GET_CODE (PATTERN (insn
)) == CLOBBER
)
4592 && MEM_P (XEXP (PATTERN (insn
), 0)))
4593 XEXP (XEXP (PATTERN (insn
), 0), 0)
4594 = eliminate_regs (XEXP (XEXP (PATTERN (insn
), 0), 0),
4595 GET_MODE (XEXP (PATTERN (insn
), 0)),
4598 /* If we need to do register elimination processing, do so.
4599 This might delete the insn, in which case we are done. */
4600 if ((num_eliminable
|| num_eliminable_invariants
) && chain
->need_elim
)
4602 eliminate_regs_in_insn (insn
, 1);
4605 update_eliminable_offsets ();
4606 CLEAR_REG_SET (®s_to_forget
);
4611 /* If need_elim is nonzero but need_reload is zero, one might think
4612 that we could simply set n_reloads to 0. However, find_reloads
4613 could have done some manipulation of the insn (such as swapping
4614 commutative operands), and these manipulations are lost during
4615 the first pass for every insn that needs register elimination.
4616 So the actions of find_reloads must be redone here. */
4618 if (! chain
->need_elim
&& ! chain
->need_reload
4619 && ! chain
->need_operand_change
)
4621 /* First find the pseudo regs that must be reloaded for this insn.
4622 This info is returned in the tables reload_... (see reload.h).
4623 Also modify the body of INSN by substituting RELOAD
4624 rtx's for those pseudo regs. */
4627 CLEAR_REG_SET (®_has_output_reload
);
4628 CLEAR_HARD_REG_SET (reg_is_output_reload
);
4630 find_reloads (insn
, 1, spill_indirect_levels
, live_known
,
4636 rtx next
= NEXT_INSN (insn
);
4639 /* ??? PREV can get deleted by reload inheritance.
4640 Work around this by emitting a marker note. */
4641 prev
= PREV_INSN (insn
);
4642 reorder_insns_nobb (marker
, marker
, prev
);
4644 /* Now compute which reload regs to reload them into. Perhaps
4645 reusing reload regs from previous insns, or else output
4646 load insns to reload them. Maybe output store insns too.
4647 Record the choices of reload reg in reload_reg_rtx. */
4648 choose_reload_regs (chain
);
4650 /* Generate the insns to reload operands into or out of
4651 their reload regs. */
4652 emit_reload_insns (chain
);
4654 /* Substitute the chosen reload regs from reload_reg_rtx
4655 into the insn's body (or perhaps into the bodies of other
4656 load and store insn that we just made for reloading
4657 and that we moved the structure into). */
4658 subst_reloads (insn
);
4660 prev
= PREV_INSN (marker
);
4661 unlink_insn_chain (marker
, marker
);
4663 /* Adjust the exception region notes for loads and stores. */
4664 if (cfun
->can_throw_non_call_exceptions
&& !CALL_P (insn
))
4665 fixup_eh_region_note (insn
, prev
, next
);
4667 /* Adjust the location of REG_ARGS_SIZE. */
4668 p
= find_reg_note (insn
, REG_ARGS_SIZE
, NULL_RTX
);
4671 remove_note (insn
, p
);
4672 fixup_args_size_notes (prev
, PREV_INSN (next
),
4673 INTVAL (XEXP (p
, 0)));
4676 /* If this was an ASM, make sure that all the reload insns
4677 we have generated are valid. If not, give an error
4679 if (asm_noperands (PATTERN (insn
)) >= 0)
4680 for (p
= NEXT_INSN (prev
); p
!= next
; p
= NEXT_INSN (p
))
4681 if (p
!= insn
&& INSN_P (p
)
4682 && GET_CODE (PATTERN (p
)) != USE
4683 && (recog_memoized (p
) < 0
4684 || (extract_insn (p
), ! constrain_operands (1))))
4686 error_for_asm (insn
,
4687 "%<asm%> operand requires "
4688 "impossible reload");
4693 if (num_eliminable
&& chain
->need_elim
)
4694 update_eliminable_offsets ();
4696 /* Any previously reloaded spilled pseudo reg, stored in this insn,
4697 is no longer validly lying around to save a future reload.
4698 Note that this does not detect pseudos that were reloaded
4699 for this insn in order to be stored in
4700 (obeying register constraints). That is correct; such reload
4701 registers ARE still valid. */
4702 forget_marked_reloads (®s_to_forget
);
4703 CLEAR_REG_SET (®s_to_forget
);
4705 /* There may have been CLOBBER insns placed after INSN. So scan
4706 between INSN and NEXT and use them to forget old reloads. */
4707 for (x
= NEXT_INSN (insn
); x
!= old_next
; x
= NEXT_INSN (x
))
4708 if (NONJUMP_INSN_P (x
) && GET_CODE (PATTERN (x
)) == CLOBBER
)
4709 note_stores (PATTERN (x
), forget_old_reloads_1
, NULL
);
4712 /* Likewise for regs altered by auto-increment in this insn.
4713 REG_INC notes have been changed by reloading:
4714 find_reloads_address_1 records substitutions for them,
4715 which have been performed by subst_reloads above. */
4716 for (i
= n_reloads
- 1; i
>= 0; i
--)
4718 rtx in_reg
= rld
[i
].in_reg
;
4721 enum rtx_code code
= GET_CODE (in_reg
);
4722 /* PRE_INC / PRE_DEC will have the reload register ending up
4723 with the same value as the stack slot, but that doesn't
4724 hold true for POST_INC / POST_DEC. Either we have to
4725 convert the memory access to a true POST_INC / POST_DEC,
4726 or we can't use the reload register for inheritance. */
4727 if ((code
== POST_INC
|| code
== POST_DEC
)
4728 && TEST_HARD_REG_BIT (reg_reloaded_valid
,
4729 REGNO (rld
[i
].reg_rtx
))
4730 /* Make sure it is the inc/dec pseudo, and not
4731 some other (e.g. output operand) pseudo. */
4732 && ((unsigned) reg_reloaded_contents
[REGNO (rld
[i
].reg_rtx
)]
4733 == REGNO (XEXP (in_reg
, 0))))
4736 rtx reload_reg
= rld
[i
].reg_rtx
;
4737 enum machine_mode mode
= GET_MODE (reload_reg
);
4741 for (p
= PREV_INSN (old_next
); p
!= prev
; p
= PREV_INSN (p
))
4743 /* We really want to ignore REG_INC notes here, so
4744 use PATTERN (p) as argument to reg_set_p . */
4745 if (reg_set_p (reload_reg
, PATTERN (p
)))
4747 n
= count_occurrences (PATTERN (p
), reload_reg
, 0);
4753 = gen_rtx_fmt_e (code
, mode
, reload_reg
);
4755 validate_replace_rtx_group (reload_reg
,
4757 n
= verify_changes (0);
4759 /* We must also verify that the constraints
4760 are met after the replacement. Make sure
4761 extract_insn is only called for an insn
4762 where the replacements were found to be
4767 n
= constrain_operands (1);
4770 /* If the constraints were not met, then
4771 undo the replacement, else confirm it. */
4775 confirm_change_group ();
4781 add_reg_note (p
, REG_INC
, reload_reg
);
4782 /* Mark this as having an output reload so that the
4783 REG_INC processing code below won't invalidate
4784 the reload for inheritance. */
4785 SET_HARD_REG_BIT (reg_is_output_reload
,
4786 REGNO (reload_reg
));
4787 SET_REGNO_REG_SET (®_has_output_reload
,
4788 REGNO (XEXP (in_reg
, 0)));
4791 forget_old_reloads_1 (XEXP (in_reg
, 0), NULL_RTX
,
4794 else if ((code
== PRE_INC
|| code
== PRE_DEC
)
4795 && TEST_HARD_REG_BIT (reg_reloaded_valid
,
4796 REGNO (rld
[i
].reg_rtx
))
4797 /* Make sure it is the inc/dec pseudo, and not
4798 some other (e.g. output operand) pseudo. */
4799 && ((unsigned) reg_reloaded_contents
[REGNO (rld
[i
].reg_rtx
)]
4800 == REGNO (XEXP (in_reg
, 0))))
4802 SET_HARD_REG_BIT (reg_is_output_reload
,
4803 REGNO (rld
[i
].reg_rtx
));
4804 SET_REGNO_REG_SET (®_has_output_reload
,
4805 REGNO (XEXP (in_reg
, 0)));
4807 else if (code
== PRE_INC
|| code
== PRE_DEC
4808 || code
== POST_INC
|| code
== POST_DEC
)
4810 int in_regno
= REGNO (XEXP (in_reg
, 0));
4812 if (reg_last_reload_reg
[in_regno
] != NULL_RTX
)
4815 bool forget_p
= true;
4817 in_hard_regno
= REGNO (reg_last_reload_reg
[in_regno
]);
4818 if (TEST_HARD_REG_BIT (reg_reloaded_valid
,
4821 for (x
= old_prev
? NEXT_INSN (old_prev
) : insn
;
4824 if (x
== reg_reloaded_insn
[in_hard_regno
])
4830 /* If for some reasons, we didn't set up
4831 reg_last_reload_reg in this insn,
4832 invalidate inheritance from previous
4833 insns for the incremented/decremented
4834 register. Such registers will be not in
4835 reg_has_output_reload. Invalidate it
4836 also if the corresponding element in
4837 reg_reloaded_insn is also
4840 forget_old_reloads_1 (XEXP (in_reg
, 0),
4846 /* If a pseudo that got a hard register is auto-incremented,
4847 we must purge records of copying it into pseudos without
4849 for (x
= REG_NOTES (insn
); x
; x
= XEXP (x
, 1))
4850 if (REG_NOTE_KIND (x
) == REG_INC
)
4852 /* See if this pseudo reg was reloaded in this insn.
4853 If so, its last-reload info is still valid
4854 because it is based on this insn's reload. */
4855 for (i
= 0; i
< n_reloads
; i
++)
4856 if (rld
[i
].out
== XEXP (x
, 0))
4860 forget_old_reloads_1 (XEXP (x
, 0), NULL_RTX
, NULL
);
4864 /* A reload reg's contents are unknown after a label. */
4866 CLEAR_HARD_REG_SET (reg_reloaded_valid
);
4868 /* Don't assume a reload reg is still good after a call insn
4869 if it is a call-used reg, or if it contains a value that will
4870 be partially clobbered by the call. */
4871 else if (CALL_P (insn
))
4873 AND_COMPL_HARD_REG_SET (reg_reloaded_valid
, call_used_reg_set
);
4874 AND_COMPL_HARD_REG_SET (reg_reloaded_valid
, reg_reloaded_call_part_clobbered
);
4876 /* If this is a call to a setjmp-type function, we must not
4877 reuse any reload reg contents across the call; that will
4878 just be clobbered by other uses of the register in later
4879 code, before the longjmp. */
4880 if (find_reg_note (insn
, REG_SETJMP
, NULL_RTX
))
4881 CLEAR_HARD_REG_SET (reg_reloaded_valid
);
4886 free (reg_last_reload_reg
);
4887 CLEAR_REG_SET (®_has_output_reload
);
4890 /* Discard all record of any value reloaded from X,
4891 or reloaded in X from someplace else;
4892 unless X is an output reload reg of the current insn.
4894 X may be a hard reg (the reload reg)
4895 or it may be a pseudo reg that was reloaded from.
4897 When DATA is non-NULL just mark the registers in regset
4898 to be forgotten later. */
4901 forget_old_reloads_1 (rtx x
, const_rtx ignored ATTRIBUTE_UNUSED
,
4906 regset regs
= (regset
) data
;
4908 /* note_stores does give us subregs of hard regs,
4909 subreg_regno_offset requires a hard reg. */
4910 while (GET_CODE (x
) == SUBREG
)
4912 /* We ignore the subreg offset when calculating the regno,
4913 because we are using the entire underlying hard register
4923 if (regno
>= FIRST_PSEUDO_REGISTER
)
4929 nr
= hard_regno_nregs
[regno
][GET_MODE (x
)];
4930 /* Storing into a spilled-reg invalidates its contents.
4931 This can happen if a block-local pseudo is allocated to that reg
4932 and it wasn't spilled because this block's total need is 0.
4933 Then some insn might have an optional reload and use this reg. */
4935 for (i
= 0; i
< nr
; i
++)
4936 /* But don't do this if the reg actually serves as an output
4937 reload reg in the current instruction. */
4939 || ! TEST_HARD_REG_BIT (reg_is_output_reload
, regno
+ i
))
4941 CLEAR_HARD_REG_BIT (reg_reloaded_valid
, regno
+ i
);
4942 spill_reg_store
[regno
+ i
] = 0;
4948 SET_REGNO_REG_SET (regs
, regno
+ nr
);
4951 /* Since value of X has changed,
4952 forget any value previously copied from it. */
4955 /* But don't forget a copy if this is the output reload
4956 that establishes the copy's validity. */
4958 || !REGNO_REG_SET_P (®_has_output_reload
, regno
+ nr
))
4959 reg_last_reload_reg
[regno
+ nr
] = 0;
4963 /* Forget the reloads marked in regset by previous function. */
4965 forget_marked_reloads (regset regs
)
4968 reg_set_iterator rsi
;
4969 EXECUTE_IF_SET_IN_REG_SET (regs
, 0, reg
, rsi
)
4971 if (reg
< FIRST_PSEUDO_REGISTER
4972 /* But don't do this if the reg actually serves as an output
4973 reload reg in the current instruction. */
4975 || ! TEST_HARD_REG_BIT (reg_is_output_reload
, reg
)))
4977 CLEAR_HARD_REG_BIT (reg_reloaded_valid
, reg
);
4978 spill_reg_store
[reg
] = 0;
4981 || !REGNO_REG_SET_P (®_has_output_reload
, reg
))
4982 reg_last_reload_reg
[reg
] = 0;
4986 /* The following HARD_REG_SETs indicate when each hard register is
4987 used for a reload of various parts of the current insn. */
4989 /* If reg is unavailable for all reloads. */
4990 static HARD_REG_SET reload_reg_unavailable
;
4991 /* If reg is in use as a reload reg for a RELOAD_OTHER reload. */
4992 static HARD_REG_SET reload_reg_used
;
4993 /* If reg is in use for a RELOAD_FOR_INPUT_ADDRESS reload for operand I. */
4994 static HARD_REG_SET reload_reg_used_in_input_addr
[MAX_RECOG_OPERANDS
];
4995 /* If reg is in use for a RELOAD_FOR_INPADDR_ADDRESS reload for operand I. */
4996 static HARD_REG_SET reload_reg_used_in_inpaddr_addr
[MAX_RECOG_OPERANDS
];
4997 /* If reg is in use for a RELOAD_FOR_OUTPUT_ADDRESS reload for operand I. */
4998 static HARD_REG_SET reload_reg_used_in_output_addr
[MAX_RECOG_OPERANDS
];
4999 /* If reg is in use for a RELOAD_FOR_OUTADDR_ADDRESS reload for operand I. */
5000 static HARD_REG_SET reload_reg_used_in_outaddr_addr
[MAX_RECOG_OPERANDS
];
5001 /* If reg is in use for a RELOAD_FOR_INPUT reload for operand I. */
5002 static HARD_REG_SET reload_reg_used_in_input
[MAX_RECOG_OPERANDS
];
5003 /* If reg is in use for a RELOAD_FOR_OUTPUT reload for operand I. */
5004 static HARD_REG_SET reload_reg_used_in_output
[MAX_RECOG_OPERANDS
];
5005 /* If reg is in use for a RELOAD_FOR_OPERAND_ADDRESS reload. */
5006 static HARD_REG_SET reload_reg_used_in_op_addr
;
5007 /* If reg is in use for a RELOAD_FOR_OPADDR_ADDR reload. */
5008 static HARD_REG_SET reload_reg_used_in_op_addr_reload
;
5009 /* If reg is in use for a RELOAD_FOR_INSN reload. */
5010 static HARD_REG_SET reload_reg_used_in_insn
;
5011 /* If reg is in use for a RELOAD_FOR_OTHER_ADDRESS reload. */
5012 static HARD_REG_SET reload_reg_used_in_other_addr
;
5014 /* If reg is in use as a reload reg for any sort of reload. */
5015 static HARD_REG_SET reload_reg_used_at_all
;
5017 /* If reg is use as an inherited reload. We just mark the first register
5019 static HARD_REG_SET reload_reg_used_for_inherit
;
5021 /* Records which hard regs are used in any way, either as explicit use or
5022 by being allocated to a pseudo during any point of the current insn. */
5023 static HARD_REG_SET reg_used_in_insn
;
5025 /* Mark reg REGNO as in use for a reload of the sort spec'd by OPNUM and
5026 TYPE. MODE is used to indicate how many consecutive regs are
5030 mark_reload_reg_in_use (unsigned int regno
, int opnum
, enum reload_type type
,
5031 enum machine_mode mode
)
5036 add_to_hard_reg_set (&reload_reg_used
, mode
, regno
);
5039 case RELOAD_FOR_INPUT_ADDRESS
:
5040 add_to_hard_reg_set (&reload_reg_used_in_input_addr
[opnum
], mode
, regno
);
5043 case RELOAD_FOR_INPADDR_ADDRESS
:
5044 add_to_hard_reg_set (&reload_reg_used_in_inpaddr_addr
[opnum
], mode
, regno
);
5047 case RELOAD_FOR_OUTPUT_ADDRESS
:
5048 add_to_hard_reg_set (&reload_reg_used_in_output_addr
[opnum
], mode
, regno
);
5051 case RELOAD_FOR_OUTADDR_ADDRESS
:
5052 add_to_hard_reg_set (&reload_reg_used_in_outaddr_addr
[opnum
], mode
, regno
);
5055 case RELOAD_FOR_OPERAND_ADDRESS
:
5056 add_to_hard_reg_set (&reload_reg_used_in_op_addr
, mode
, regno
);
5059 case RELOAD_FOR_OPADDR_ADDR
:
5060 add_to_hard_reg_set (&reload_reg_used_in_op_addr_reload
, mode
, regno
);
5063 case RELOAD_FOR_OTHER_ADDRESS
:
5064 add_to_hard_reg_set (&reload_reg_used_in_other_addr
, mode
, regno
);
5067 case RELOAD_FOR_INPUT
:
5068 add_to_hard_reg_set (&reload_reg_used_in_input
[opnum
], mode
, regno
);
5071 case RELOAD_FOR_OUTPUT
:
5072 add_to_hard_reg_set (&reload_reg_used_in_output
[opnum
], mode
, regno
);
5075 case RELOAD_FOR_INSN
:
5076 add_to_hard_reg_set (&reload_reg_used_in_insn
, mode
, regno
);
5080 add_to_hard_reg_set (&reload_reg_used_at_all
, mode
, regno
);
5083 /* Similarly, but show REGNO is no longer in use for a reload. */
5086 clear_reload_reg_in_use (unsigned int regno
, int opnum
,
5087 enum reload_type type
, enum machine_mode mode
)
5089 unsigned int nregs
= hard_regno_nregs
[regno
][mode
];
5090 unsigned int start_regno
, end_regno
, r
;
5092 /* A complication is that for some reload types, inheritance might
5093 allow multiple reloads of the same types to share a reload register.
5094 We set check_opnum if we have to check only reloads with the same
5095 operand number, and check_any if we have to check all reloads. */
5096 int check_opnum
= 0;
5098 HARD_REG_SET
*used_in_set
;
5103 used_in_set
= &reload_reg_used
;
5106 case RELOAD_FOR_INPUT_ADDRESS
:
5107 used_in_set
= &reload_reg_used_in_input_addr
[opnum
];
5110 case RELOAD_FOR_INPADDR_ADDRESS
:
5112 used_in_set
= &reload_reg_used_in_inpaddr_addr
[opnum
];
5115 case RELOAD_FOR_OUTPUT_ADDRESS
:
5116 used_in_set
= &reload_reg_used_in_output_addr
[opnum
];
5119 case RELOAD_FOR_OUTADDR_ADDRESS
:
5121 used_in_set
= &reload_reg_used_in_outaddr_addr
[opnum
];
5124 case RELOAD_FOR_OPERAND_ADDRESS
:
5125 used_in_set
= &reload_reg_used_in_op_addr
;
5128 case RELOAD_FOR_OPADDR_ADDR
:
5130 used_in_set
= &reload_reg_used_in_op_addr_reload
;
5133 case RELOAD_FOR_OTHER_ADDRESS
:
5134 used_in_set
= &reload_reg_used_in_other_addr
;
5138 case RELOAD_FOR_INPUT
:
5139 used_in_set
= &reload_reg_used_in_input
[opnum
];
5142 case RELOAD_FOR_OUTPUT
:
5143 used_in_set
= &reload_reg_used_in_output
[opnum
];
5146 case RELOAD_FOR_INSN
:
5147 used_in_set
= &reload_reg_used_in_insn
;
5152 /* We resolve conflicts with remaining reloads of the same type by
5153 excluding the intervals of reload registers by them from the
5154 interval of freed reload registers. Since we only keep track of
5155 one set of interval bounds, we might have to exclude somewhat
5156 more than what would be necessary if we used a HARD_REG_SET here.
5157 But this should only happen very infrequently, so there should
5158 be no reason to worry about it. */
5160 start_regno
= regno
;
5161 end_regno
= regno
+ nregs
;
5162 if (check_opnum
|| check_any
)
5164 for (i
= n_reloads
- 1; i
>= 0; i
--)
5166 if (rld
[i
].when_needed
== type
5167 && (check_any
|| rld
[i
].opnum
== opnum
)
5170 unsigned int conflict_start
= true_regnum (rld
[i
].reg_rtx
);
5171 unsigned int conflict_end
5172 = end_hard_regno (rld
[i
].mode
, conflict_start
);
5174 /* If there is an overlap with the first to-be-freed register,
5175 adjust the interval start. */
5176 if (conflict_start
<= start_regno
&& conflict_end
> start_regno
)
5177 start_regno
= conflict_end
;
5178 /* Otherwise, if there is a conflict with one of the other
5179 to-be-freed registers, adjust the interval end. */
5180 if (conflict_start
> start_regno
&& conflict_start
< end_regno
)
5181 end_regno
= conflict_start
;
5186 for (r
= start_regno
; r
< end_regno
; r
++)
5187 CLEAR_HARD_REG_BIT (*used_in_set
, r
);
5190 /* 1 if reg REGNO is free as a reload reg for a reload of the sort
5191 specified by OPNUM and TYPE. */
5194 reload_reg_free_p (unsigned int regno
, int opnum
, enum reload_type type
)
5198 /* In use for a RELOAD_OTHER means it's not available for anything. */
5199 if (TEST_HARD_REG_BIT (reload_reg_used
, regno
)
5200 || TEST_HARD_REG_BIT (reload_reg_unavailable
, regno
))
5206 /* In use for anything means we can't use it for RELOAD_OTHER. */
5207 if (TEST_HARD_REG_BIT (reload_reg_used_in_other_addr
, regno
)
5208 || TEST_HARD_REG_BIT (reload_reg_used_in_op_addr
, regno
)
5209 || TEST_HARD_REG_BIT (reload_reg_used_in_op_addr_reload
, regno
)
5210 || TEST_HARD_REG_BIT (reload_reg_used_in_insn
, regno
))
5213 for (i
= 0; i
< reload_n_operands
; i
++)
5214 if (TEST_HARD_REG_BIT (reload_reg_used_in_input_addr
[i
], regno
)
5215 || TEST_HARD_REG_BIT (reload_reg_used_in_inpaddr_addr
[i
], regno
)
5216 || TEST_HARD_REG_BIT (reload_reg_used_in_output_addr
[i
], regno
)
5217 || TEST_HARD_REG_BIT (reload_reg_used_in_outaddr_addr
[i
], regno
)
5218 || TEST_HARD_REG_BIT (reload_reg_used_in_input
[i
], regno
)
5219 || TEST_HARD_REG_BIT (reload_reg_used_in_output
[i
], regno
))
5224 case RELOAD_FOR_INPUT
:
5225 if (TEST_HARD_REG_BIT (reload_reg_used_in_insn
, regno
)
5226 || TEST_HARD_REG_BIT (reload_reg_used_in_op_addr
, regno
))
5229 if (TEST_HARD_REG_BIT (reload_reg_used_in_op_addr_reload
, regno
))
5232 /* If it is used for some other input, can't use it. */
5233 for (i
= 0; i
< reload_n_operands
; i
++)
5234 if (TEST_HARD_REG_BIT (reload_reg_used_in_input
[i
], regno
))
5237 /* If it is used in a later operand's address, can't use it. */
5238 for (i
= opnum
+ 1; i
< reload_n_operands
; i
++)
5239 if (TEST_HARD_REG_BIT (reload_reg_used_in_input_addr
[i
], regno
)
5240 || TEST_HARD_REG_BIT (reload_reg_used_in_inpaddr_addr
[i
], regno
))
5245 case RELOAD_FOR_INPUT_ADDRESS
:
5246 /* Can't use a register if it is used for an input address for this
5247 operand or used as an input in an earlier one. */
5248 if (TEST_HARD_REG_BIT (reload_reg_used_in_input_addr
[opnum
], regno
)
5249 || TEST_HARD_REG_BIT (reload_reg_used_in_inpaddr_addr
[opnum
], regno
))
5252 for (i
= 0; i
< opnum
; i
++)
5253 if (TEST_HARD_REG_BIT (reload_reg_used_in_input
[i
], regno
))
5258 case RELOAD_FOR_INPADDR_ADDRESS
:
5259 /* Can't use a register if it is used for an input address
5260 for this operand or used as an input in an earlier
5262 if (TEST_HARD_REG_BIT (reload_reg_used_in_inpaddr_addr
[opnum
], regno
))
5265 for (i
= 0; i
< opnum
; i
++)
5266 if (TEST_HARD_REG_BIT (reload_reg_used_in_input
[i
], regno
))
5271 case RELOAD_FOR_OUTPUT_ADDRESS
:
5272 /* Can't use a register if it is used for an output address for this
5273 operand or used as an output in this or a later operand. Note
5274 that multiple output operands are emitted in reverse order, so
5275 the conflicting ones are those with lower indices. */
5276 if (TEST_HARD_REG_BIT (reload_reg_used_in_output_addr
[opnum
], regno
))
5279 for (i
= 0; i
<= opnum
; i
++)
5280 if (TEST_HARD_REG_BIT (reload_reg_used_in_output
[i
], regno
))
5285 case RELOAD_FOR_OUTADDR_ADDRESS
:
5286 /* Can't use a register if it is used for an output address
5287 for this operand or used as an output in this or a
5288 later operand. Note that multiple output operands are
5289 emitted in reverse order, so the conflicting ones are
5290 those with lower indices. */
5291 if (TEST_HARD_REG_BIT (reload_reg_used_in_outaddr_addr
[opnum
], regno
))
5294 for (i
= 0; i
<= opnum
; i
++)
5295 if (TEST_HARD_REG_BIT (reload_reg_used_in_output
[i
], regno
))
5300 case RELOAD_FOR_OPERAND_ADDRESS
:
5301 for (i
= 0; i
< reload_n_operands
; i
++)
5302 if (TEST_HARD_REG_BIT (reload_reg_used_in_input
[i
], regno
))
5305 return (! TEST_HARD_REG_BIT (reload_reg_used_in_insn
, regno
)
5306 && ! TEST_HARD_REG_BIT (reload_reg_used_in_op_addr
, regno
));
5308 case RELOAD_FOR_OPADDR_ADDR
:
5309 for (i
= 0; i
< reload_n_operands
; i
++)
5310 if (TEST_HARD_REG_BIT (reload_reg_used_in_input
[i
], regno
))
5313 return (!TEST_HARD_REG_BIT (reload_reg_used_in_op_addr_reload
, regno
));
5315 case RELOAD_FOR_OUTPUT
:
5316 /* This cannot share a register with RELOAD_FOR_INSN reloads, other
5317 outputs, or an operand address for this or an earlier output.
5318 Note that multiple output operands are emitted in reverse order,
5319 so the conflicting ones are those with higher indices. */
5320 if (TEST_HARD_REG_BIT (reload_reg_used_in_insn
, regno
))
5323 for (i
= 0; i
< reload_n_operands
; i
++)
5324 if (TEST_HARD_REG_BIT (reload_reg_used_in_output
[i
], regno
))
5327 for (i
= opnum
; i
< reload_n_operands
; i
++)
5328 if (TEST_HARD_REG_BIT (reload_reg_used_in_output_addr
[i
], regno
)
5329 || TEST_HARD_REG_BIT (reload_reg_used_in_outaddr_addr
[i
], regno
))
5334 case RELOAD_FOR_INSN
:
5335 for (i
= 0; i
< reload_n_operands
; i
++)
5336 if (TEST_HARD_REG_BIT (reload_reg_used_in_input
[i
], regno
)
5337 || TEST_HARD_REG_BIT (reload_reg_used_in_output
[i
], regno
))
5340 return (! TEST_HARD_REG_BIT (reload_reg_used_in_insn
, regno
)
5341 && ! TEST_HARD_REG_BIT (reload_reg_used_in_op_addr
, regno
));
5343 case RELOAD_FOR_OTHER_ADDRESS
:
5344 return ! TEST_HARD_REG_BIT (reload_reg_used_in_other_addr
, regno
);
5351 /* Return 1 if the value in reload reg REGNO, as used by the reload with
5352 the number RELOADNUM, is still available in REGNO at the end of the insn.
5354 We can assume that the reload reg was already tested for availability
5355 at the time it is needed, and we should not check this again,
5356 in case the reg has already been marked in use. */
5359 reload_reg_reaches_end_p (unsigned int regno
, int reloadnum
)
5361 int opnum
= rld
[reloadnum
].opnum
;
5362 enum reload_type type
= rld
[reloadnum
].when_needed
;
5365 /* See if there is a reload with the same type for this operand, using
5366 the same register. This case is not handled by the code below. */
5367 for (i
= reloadnum
+ 1; i
< n_reloads
; i
++)
5372 if (rld
[i
].opnum
!= opnum
|| rld
[i
].when_needed
!= type
)
5374 reg
= rld
[i
].reg_rtx
;
5375 if (reg
== NULL_RTX
)
5377 nregs
= hard_regno_nregs
[REGNO (reg
)][GET_MODE (reg
)];
5378 if (regno
>= REGNO (reg
) && regno
< REGNO (reg
) + nregs
)
5385 /* Since a RELOAD_OTHER reload claims the reg for the entire insn,
5386 its value must reach the end. */
5389 /* If this use is for part of the insn,
5390 its value reaches if no subsequent part uses the same register.
5391 Just like the above function, don't try to do this with lots
5394 case RELOAD_FOR_OTHER_ADDRESS
:
5395 /* Here we check for everything else, since these don't conflict
5396 with anything else and everything comes later. */
5398 for (i
= 0; i
< reload_n_operands
; i
++)
5399 if (TEST_HARD_REG_BIT (reload_reg_used_in_output_addr
[i
], regno
)
5400 || TEST_HARD_REG_BIT (reload_reg_used_in_outaddr_addr
[i
], regno
)
5401 || TEST_HARD_REG_BIT (reload_reg_used_in_output
[i
], regno
)
5402 || TEST_HARD_REG_BIT (reload_reg_used_in_input_addr
[i
], regno
)
5403 || TEST_HARD_REG_BIT (reload_reg_used_in_inpaddr_addr
[i
], regno
)
5404 || TEST_HARD_REG_BIT (reload_reg_used_in_input
[i
], regno
))
5407 return (! TEST_HARD_REG_BIT (reload_reg_used_in_op_addr
, regno
)
5408 && ! TEST_HARD_REG_BIT (reload_reg_used_in_op_addr_reload
, regno
)
5409 && ! TEST_HARD_REG_BIT (reload_reg_used_in_insn
, regno
)
5410 && ! TEST_HARD_REG_BIT (reload_reg_used
, regno
));
5412 case RELOAD_FOR_INPUT_ADDRESS
:
5413 case RELOAD_FOR_INPADDR_ADDRESS
:
5414 /* Similar, except that we check only for this and subsequent inputs
5415 and the address of only subsequent inputs and we do not need
5416 to check for RELOAD_OTHER objects since they are known not to
5419 for (i
= opnum
; i
< reload_n_operands
; i
++)
5420 if (TEST_HARD_REG_BIT (reload_reg_used_in_input
[i
], regno
))
5423 /* Reload register of reload with type RELOAD_FOR_INPADDR_ADDRESS
5424 could be killed if the register is also used by reload with type
5425 RELOAD_FOR_INPUT_ADDRESS, so check it. */
5426 if (type
== RELOAD_FOR_INPADDR_ADDRESS
5427 && TEST_HARD_REG_BIT (reload_reg_used_in_input_addr
[opnum
], regno
))
5430 for (i
= opnum
+ 1; i
< reload_n_operands
; i
++)
5431 if (TEST_HARD_REG_BIT (reload_reg_used_in_input_addr
[i
], regno
)
5432 || TEST_HARD_REG_BIT (reload_reg_used_in_inpaddr_addr
[i
], regno
))
5435 for (i
= 0; i
< reload_n_operands
; i
++)
5436 if (TEST_HARD_REG_BIT (reload_reg_used_in_output_addr
[i
], regno
)
5437 || TEST_HARD_REG_BIT (reload_reg_used_in_outaddr_addr
[i
], regno
)
5438 || TEST_HARD_REG_BIT (reload_reg_used_in_output
[i
], regno
))
5441 if (TEST_HARD_REG_BIT (reload_reg_used_in_op_addr_reload
, regno
))
5444 return (!TEST_HARD_REG_BIT (reload_reg_used_in_op_addr
, regno
)
5445 && !TEST_HARD_REG_BIT (reload_reg_used_in_insn
, regno
)
5446 && !TEST_HARD_REG_BIT (reload_reg_used
, regno
));
5448 case RELOAD_FOR_INPUT
:
5449 /* Similar to input address, except we start at the next operand for
5450 both input and input address and we do not check for
5451 RELOAD_FOR_OPERAND_ADDRESS and RELOAD_FOR_INSN since these
5454 for (i
= opnum
+ 1; i
< reload_n_operands
; i
++)
5455 if (TEST_HARD_REG_BIT (reload_reg_used_in_input_addr
[i
], regno
)
5456 || TEST_HARD_REG_BIT (reload_reg_used_in_inpaddr_addr
[i
], regno
)
5457 || TEST_HARD_REG_BIT (reload_reg_used_in_input
[i
], regno
))
5460 /* ... fall through ... */
5462 case RELOAD_FOR_OPERAND_ADDRESS
:
5463 /* Check outputs and their addresses. */
5465 for (i
= 0; i
< reload_n_operands
; i
++)
5466 if (TEST_HARD_REG_BIT (reload_reg_used_in_output_addr
[i
], regno
)
5467 || TEST_HARD_REG_BIT (reload_reg_used_in_outaddr_addr
[i
], regno
)
5468 || TEST_HARD_REG_BIT (reload_reg_used_in_output
[i
], regno
))
5471 return (!TEST_HARD_REG_BIT (reload_reg_used
, regno
));
5473 case RELOAD_FOR_OPADDR_ADDR
:
5474 for (i
= 0; i
< reload_n_operands
; i
++)
5475 if (TEST_HARD_REG_BIT (reload_reg_used_in_output_addr
[i
], regno
)
5476 || TEST_HARD_REG_BIT (reload_reg_used_in_outaddr_addr
[i
], regno
)
5477 || TEST_HARD_REG_BIT (reload_reg_used_in_output
[i
], regno
))
5480 return (!TEST_HARD_REG_BIT (reload_reg_used_in_op_addr
, regno
)
5481 && !TEST_HARD_REG_BIT (reload_reg_used_in_insn
, regno
)
5482 && !TEST_HARD_REG_BIT (reload_reg_used
, regno
));
5484 case RELOAD_FOR_INSN
:
5485 /* These conflict with other outputs with RELOAD_OTHER. So
5486 we need only check for output addresses. */
5488 opnum
= reload_n_operands
;
5490 /* ... fall through ... */
5492 case RELOAD_FOR_OUTPUT
:
5493 case RELOAD_FOR_OUTPUT_ADDRESS
:
5494 case RELOAD_FOR_OUTADDR_ADDRESS
:
5495 /* We already know these can't conflict with a later output. So the
5496 only thing to check are later output addresses.
5497 Note that multiple output operands are emitted in reverse order,
5498 so the conflicting ones are those with lower indices. */
5499 for (i
= 0; i
< opnum
; i
++)
5500 if (TEST_HARD_REG_BIT (reload_reg_used_in_output_addr
[i
], regno
)
5501 || TEST_HARD_REG_BIT (reload_reg_used_in_outaddr_addr
[i
], regno
))
5504 /* Reload register of reload with type RELOAD_FOR_OUTADDR_ADDRESS
5505 could be killed if the register is also used by reload with type
5506 RELOAD_FOR_OUTPUT_ADDRESS, so check it. */
5507 if (type
== RELOAD_FOR_OUTADDR_ADDRESS
5508 && TEST_HARD_REG_BIT (reload_reg_used_in_outaddr_addr
[opnum
], regno
))
5518 /* Like reload_reg_reaches_end_p, but check that the condition holds for
5519 every register in REG. */
5522 reload_reg_rtx_reaches_end_p (rtx reg
, int reloadnum
)
5526 for (i
= REGNO (reg
); i
< END_REGNO (reg
); i
++)
5527 if (!reload_reg_reaches_end_p (i
, reloadnum
))
5533 /* Returns whether R1 and R2 are uniquely chained: the value of one
5534 is used by the other, and that value is not used by any other
5535 reload for this insn. This is used to partially undo the decision
5536 made in find_reloads when in the case of multiple
5537 RELOAD_FOR_OPERAND_ADDRESS reloads it converts all
5538 RELOAD_FOR_OPADDR_ADDR reloads into RELOAD_FOR_OPERAND_ADDRESS
5539 reloads. This code tries to avoid the conflict created by that
5540 change. It might be cleaner to explicitly keep track of which
5541 RELOAD_FOR_OPADDR_ADDR reload is associated with which
5542 RELOAD_FOR_OPERAND_ADDRESS reload, rather than to try to detect
5543 this after the fact. */
5545 reloads_unique_chain_p (int r1
, int r2
)
5549 /* We only check input reloads. */
5550 if (! rld
[r1
].in
|| ! rld
[r2
].in
)
5553 /* Avoid anything with output reloads. */
5554 if (rld
[r1
].out
|| rld
[r2
].out
)
5557 /* "chained" means one reload is a component of the other reload,
5558 not the same as the other reload. */
5559 if (rld
[r1
].opnum
!= rld
[r2
].opnum
5560 || rtx_equal_p (rld
[r1
].in
, rld
[r2
].in
)
5561 || rld
[r1
].optional
|| rld
[r2
].optional
5562 || ! (reg_mentioned_p (rld
[r1
].in
, rld
[r2
].in
)
5563 || reg_mentioned_p (rld
[r2
].in
, rld
[r1
].in
)))
5566 for (i
= 0; i
< n_reloads
; i
++)
5567 /* Look for input reloads that aren't our two */
5568 if (i
!= r1
&& i
!= r2
&& rld
[i
].in
)
5570 /* If our reload is mentioned at all, it isn't a simple chain. */
5571 if (reg_mentioned_p (rld
[r1
].in
, rld
[i
].in
))
5577 /* The recursive function change all occurrences of WHAT in *WHERE
5580 substitute (rtx
*where
, const_rtx what
, rtx repl
)
5589 if (*where
== what
|| rtx_equal_p (*where
, what
))
5591 /* Record the location of the changed rtx. */
5592 VEC_safe_push (rtx_p
, heap
, substitute_stack
, where
);
5597 code
= GET_CODE (*where
);
5598 fmt
= GET_RTX_FORMAT (code
);
5599 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
5605 for (j
= XVECLEN (*where
, i
) - 1; j
>= 0; j
--)
5606 substitute (&XVECEXP (*where
, i
, j
), what
, repl
);
5608 else if (fmt
[i
] == 'e')
5609 substitute (&XEXP (*where
, i
), what
, repl
);
5613 /* The function returns TRUE if chain of reload R1 and R2 (in any
5614 order) can be evaluated without usage of intermediate register for
5615 the reload containing another reload. It is important to see
5616 gen_reload to understand what the function is trying to do. As an
5617 example, let us have reload chain
5620 r1: <something> + const
5622 and reload R2 got reload reg HR. The function returns true if
5623 there is a correct insn HR = HR + <something>. Otherwise,
5624 gen_reload will use intermediate register (and this is the reload
5625 reg for R1) to reload <something>.
5627 We need this function to find a conflict for chain reloads. In our
5628 example, if HR = HR + <something> is incorrect insn, then we cannot
5629 use HR as a reload register for R2. If we do use it then we get a
5638 gen_reload_chain_without_interm_reg_p (int r1
, int r2
)
5640 /* Assume other cases in gen_reload are not possible for
5641 chain reloads or do need an intermediate hard registers. */
5645 rtx last
= get_last_insn ();
5647 /* Make r2 a component of r1. */
5648 if (reg_mentioned_p (rld
[r1
].in
, rld
[r2
].in
))
5654 gcc_assert (reg_mentioned_p (rld
[r2
].in
, rld
[r1
].in
));
5655 regno
= rld
[r1
].regno
>= 0 ? rld
[r1
].regno
: rld
[r2
].regno
;
5656 gcc_assert (regno
>= 0);
5657 out
= gen_rtx_REG (rld
[r1
].mode
, regno
);
5659 substitute (&in
, rld
[r2
].in
, gen_rtx_REG (rld
[r2
].mode
, regno
));
5661 /* If IN is a paradoxical SUBREG, remove it and try to put the
5662 opposite SUBREG on OUT. Likewise for a paradoxical SUBREG on OUT. */
5663 strip_paradoxical_subreg (&in
, &out
);
5665 if (GET_CODE (in
) == PLUS
5666 && (REG_P (XEXP (in
, 0))
5667 || GET_CODE (XEXP (in
, 0)) == SUBREG
5668 || MEM_P (XEXP (in
, 0)))
5669 && (REG_P (XEXP (in
, 1))
5670 || GET_CODE (XEXP (in
, 1)) == SUBREG
5671 || CONSTANT_P (XEXP (in
, 1))
5672 || MEM_P (XEXP (in
, 1))))
5674 insn
= emit_insn (gen_rtx_SET (VOIDmode
, out
, in
));
5675 code
= recog_memoized (insn
);
5680 extract_insn (insn
);
5681 /* We want constrain operands to treat this insn strictly in
5682 its validity determination, i.e., the way it would after
5683 reload has completed. */
5684 result
= constrain_operands (1);
5687 delete_insns_since (last
);
5690 /* Restore the original value at each changed address within R1. */
5691 while (!VEC_empty (rtx_p
, substitute_stack
))
5693 rtx
*where
= VEC_pop (rtx_p
, substitute_stack
);
5694 *where
= rld
[r2
].in
;
5700 /* Return 1 if the reloads denoted by R1 and R2 cannot share a register.
5703 This function uses the same algorithm as reload_reg_free_p above. */
5706 reloads_conflict (int r1
, int r2
)
5708 enum reload_type r1_type
= rld
[r1
].when_needed
;
5709 enum reload_type r2_type
= rld
[r2
].when_needed
;
5710 int r1_opnum
= rld
[r1
].opnum
;
5711 int r2_opnum
= rld
[r2
].opnum
;
5713 /* RELOAD_OTHER conflicts with everything. */
5714 if (r2_type
== RELOAD_OTHER
)
5717 /* Otherwise, check conflicts differently for each type. */
5721 case RELOAD_FOR_INPUT
:
5722 return (r2_type
== RELOAD_FOR_INSN
5723 || r2_type
== RELOAD_FOR_OPERAND_ADDRESS
5724 || r2_type
== RELOAD_FOR_OPADDR_ADDR
5725 || r2_type
== RELOAD_FOR_INPUT
5726 || ((r2_type
== RELOAD_FOR_INPUT_ADDRESS
5727 || r2_type
== RELOAD_FOR_INPADDR_ADDRESS
)
5728 && r2_opnum
> r1_opnum
));
5730 case RELOAD_FOR_INPUT_ADDRESS
:
5731 return ((r2_type
== RELOAD_FOR_INPUT_ADDRESS
&& r1_opnum
== r2_opnum
)
5732 || (r2_type
== RELOAD_FOR_INPUT
&& r2_opnum
< r1_opnum
));
5734 case RELOAD_FOR_INPADDR_ADDRESS
:
5735 return ((r2_type
== RELOAD_FOR_INPADDR_ADDRESS
&& r1_opnum
== r2_opnum
)
5736 || (r2_type
== RELOAD_FOR_INPUT
&& r2_opnum
< r1_opnum
));
5738 case RELOAD_FOR_OUTPUT_ADDRESS
:
5739 return ((r2_type
== RELOAD_FOR_OUTPUT_ADDRESS
&& r2_opnum
== r1_opnum
)
5740 || (r2_type
== RELOAD_FOR_OUTPUT
&& r2_opnum
<= r1_opnum
));
5742 case RELOAD_FOR_OUTADDR_ADDRESS
:
5743 return ((r2_type
== RELOAD_FOR_OUTADDR_ADDRESS
&& r2_opnum
== r1_opnum
)
5744 || (r2_type
== RELOAD_FOR_OUTPUT
&& r2_opnum
<= r1_opnum
));
5746 case RELOAD_FOR_OPERAND_ADDRESS
:
5747 return (r2_type
== RELOAD_FOR_INPUT
|| r2_type
== RELOAD_FOR_INSN
5748 || (r2_type
== RELOAD_FOR_OPERAND_ADDRESS
5749 && (!reloads_unique_chain_p (r1
, r2
)
5750 || !gen_reload_chain_without_interm_reg_p (r1
, r2
))));
5752 case RELOAD_FOR_OPADDR_ADDR
:
5753 return (r2_type
== RELOAD_FOR_INPUT
5754 || r2_type
== RELOAD_FOR_OPADDR_ADDR
);
5756 case RELOAD_FOR_OUTPUT
:
5757 return (r2_type
== RELOAD_FOR_INSN
|| r2_type
== RELOAD_FOR_OUTPUT
5758 || ((r2_type
== RELOAD_FOR_OUTPUT_ADDRESS
5759 || r2_type
== RELOAD_FOR_OUTADDR_ADDRESS
)
5760 && r2_opnum
>= r1_opnum
));
5762 case RELOAD_FOR_INSN
:
5763 return (r2_type
== RELOAD_FOR_INPUT
|| r2_type
== RELOAD_FOR_OUTPUT
5764 || r2_type
== RELOAD_FOR_INSN
5765 || r2_type
== RELOAD_FOR_OPERAND_ADDRESS
);
5767 case RELOAD_FOR_OTHER_ADDRESS
:
5768 return r2_type
== RELOAD_FOR_OTHER_ADDRESS
;
5778 /* Indexed by reload number, 1 if incoming value
5779 inherited from previous insns. */
5780 static char reload_inherited
[MAX_RELOADS
];
5782 /* For an inherited reload, this is the insn the reload was inherited from,
5783 if we know it. Otherwise, this is 0. */
5784 static rtx reload_inheritance_insn
[MAX_RELOADS
];
5786 /* If nonzero, this is a place to get the value of the reload,
5787 rather than using reload_in. */
5788 static rtx reload_override_in
[MAX_RELOADS
];
5790 /* For each reload, the hard register number of the register used,
5791 or -1 if we did not need a register for this reload. */
5792 static int reload_spill_index
[MAX_RELOADS
];
5794 /* Index X is the value of rld[X].reg_rtx, adjusted for the input mode. */
5795 static rtx reload_reg_rtx_for_input
[MAX_RELOADS
];
5797 /* Index X is the value of rld[X].reg_rtx, adjusted for the output mode. */
5798 static rtx reload_reg_rtx_for_output
[MAX_RELOADS
];
5800 /* Subroutine of free_for_value_p, used to check a single register.
5801 START_REGNO is the starting regno of the full reload register
5802 (possibly comprising multiple hard registers) that we are considering. */
5805 reload_reg_free_for_value_p (int start_regno
, int regno
, int opnum
,
5806 enum reload_type type
, rtx value
, rtx out
,
5807 int reloadnum
, int ignore_address_reloads
)
5810 /* Set if we see an input reload that must not share its reload register
5811 with any new earlyclobber, but might otherwise share the reload
5812 register with an output or input-output reload. */
5813 int check_earlyclobber
= 0;
5817 if (TEST_HARD_REG_BIT (reload_reg_unavailable
, regno
))
5820 if (out
== const0_rtx
)
5826 /* We use some pseudo 'time' value to check if the lifetimes of the
5827 new register use would overlap with the one of a previous reload
5828 that is not read-only or uses a different value.
5829 The 'time' used doesn't have to be linear in any shape or form, just
5831 Some reload types use different 'buckets' for each operand.
5832 So there are MAX_RECOG_OPERANDS different time values for each
5834 We compute TIME1 as the time when the register for the prospective
5835 new reload ceases to be live, and TIME2 for each existing
5836 reload as the time when that the reload register of that reload
5838 Where there is little to be gained by exact lifetime calculations,
5839 we just make conservative assumptions, i.e. a longer lifetime;
5840 this is done in the 'default:' cases. */
5843 case RELOAD_FOR_OTHER_ADDRESS
:
5844 /* RELOAD_FOR_OTHER_ADDRESS conflicts with RELOAD_OTHER reloads. */
5845 time1
= copy
? 0 : 1;
5848 time1
= copy
? 1 : MAX_RECOG_OPERANDS
* 5 + 5;
5850 /* For each input, we may have a sequence of RELOAD_FOR_INPADDR_ADDRESS,
5851 RELOAD_FOR_INPUT_ADDRESS and RELOAD_FOR_INPUT. By adding 0 / 1 / 2 ,
5852 respectively, to the time values for these, we get distinct time
5853 values. To get distinct time values for each operand, we have to
5854 multiply opnum by at least three. We round that up to four because
5855 multiply by four is often cheaper. */
5856 case RELOAD_FOR_INPADDR_ADDRESS
:
5857 time1
= opnum
* 4 + 2;
5859 case RELOAD_FOR_INPUT_ADDRESS
:
5860 time1
= opnum
* 4 + 3;
5862 case RELOAD_FOR_INPUT
:
5863 /* All RELOAD_FOR_INPUT reloads remain live till the instruction
5864 executes (inclusive). */
5865 time1
= copy
? opnum
* 4 + 4 : MAX_RECOG_OPERANDS
* 4 + 3;
5867 case RELOAD_FOR_OPADDR_ADDR
:
5869 <= (MAX_RECOG_OPERANDS - 1) * 4 + 4 == MAX_RECOG_OPERANDS * 4 */
5870 time1
= MAX_RECOG_OPERANDS
* 4 + 1;
5872 case RELOAD_FOR_OPERAND_ADDRESS
:
5873 /* RELOAD_FOR_OPERAND_ADDRESS reloads are live even while the insn
5875 time1
= copy
? MAX_RECOG_OPERANDS
* 4 + 2 : MAX_RECOG_OPERANDS
* 4 + 3;
5877 case RELOAD_FOR_OUTADDR_ADDRESS
:
5878 time1
= MAX_RECOG_OPERANDS
* 4 + 4 + opnum
;
5880 case RELOAD_FOR_OUTPUT_ADDRESS
:
5881 time1
= MAX_RECOG_OPERANDS
* 4 + 5 + opnum
;
5884 time1
= MAX_RECOG_OPERANDS
* 5 + 5;
5887 for (i
= 0; i
< n_reloads
; i
++)
5889 rtx reg
= rld
[i
].reg_rtx
;
5890 if (reg
&& REG_P (reg
)
5891 && ((unsigned) regno
- true_regnum (reg
)
5892 <= hard_regno_nregs
[REGNO (reg
)][GET_MODE (reg
)] - (unsigned) 1)
5895 rtx other_input
= rld
[i
].in
;
5897 /* If the other reload loads the same input value, that
5898 will not cause a conflict only if it's loading it into
5899 the same register. */
5900 if (true_regnum (reg
) != start_regno
)
5901 other_input
= NULL_RTX
;
5902 if (! other_input
|| ! rtx_equal_p (other_input
, value
)
5903 || rld
[i
].out
|| out
)
5906 switch (rld
[i
].when_needed
)
5908 case RELOAD_FOR_OTHER_ADDRESS
:
5911 case RELOAD_FOR_INPADDR_ADDRESS
:
5912 /* find_reloads makes sure that a
5913 RELOAD_FOR_{INP,OP,OUT}ADDR_ADDRESS reload is only used
5914 by at most one - the first -
5915 RELOAD_FOR_{INPUT,OPERAND,OUTPUT}_ADDRESS . If the
5916 address reload is inherited, the address address reload
5917 goes away, so we can ignore this conflict. */
5918 if (type
== RELOAD_FOR_INPUT_ADDRESS
&& reloadnum
== i
+ 1
5919 && ignore_address_reloads
5920 /* Unless the RELOAD_FOR_INPUT is an auto_inc expression.
5921 Then the address address is still needed to store
5922 back the new address. */
5923 && ! rld
[reloadnum
].out
)
5925 /* Likewise, if a RELOAD_FOR_INPUT can inherit a value, its
5926 RELOAD_FOR_INPUT_ADDRESS / RELOAD_FOR_INPADDR_ADDRESS
5928 if (type
== RELOAD_FOR_INPUT
&& opnum
== rld
[i
].opnum
5929 && ignore_address_reloads
5930 /* Unless we are reloading an auto_inc expression. */
5931 && ! rld
[reloadnum
].out
)
5933 time2
= rld
[i
].opnum
* 4 + 2;
5935 case RELOAD_FOR_INPUT_ADDRESS
:
5936 if (type
== RELOAD_FOR_INPUT
&& opnum
== rld
[i
].opnum
5937 && ignore_address_reloads
5938 && ! rld
[reloadnum
].out
)
5940 time2
= rld
[i
].opnum
* 4 + 3;
5942 case RELOAD_FOR_INPUT
:
5943 time2
= rld
[i
].opnum
* 4 + 4;
5944 check_earlyclobber
= 1;
5946 /* rld[i].opnum * 4 + 4 <= (MAX_RECOG_OPERAND - 1) * 4 + 4
5947 == MAX_RECOG_OPERAND * 4 */
5948 case RELOAD_FOR_OPADDR_ADDR
:
5949 if (type
== RELOAD_FOR_OPERAND_ADDRESS
&& reloadnum
== i
+ 1
5950 && ignore_address_reloads
5951 && ! rld
[reloadnum
].out
)
5953 time2
= MAX_RECOG_OPERANDS
* 4 + 1;
5955 case RELOAD_FOR_OPERAND_ADDRESS
:
5956 time2
= MAX_RECOG_OPERANDS
* 4 + 2;
5957 check_earlyclobber
= 1;
5959 case RELOAD_FOR_INSN
:
5960 time2
= MAX_RECOG_OPERANDS
* 4 + 3;
5962 case RELOAD_FOR_OUTPUT
:
5963 /* All RELOAD_FOR_OUTPUT reloads become live just after the
5964 instruction is executed. */
5965 time2
= MAX_RECOG_OPERANDS
* 4 + 4;
5967 /* The first RELOAD_FOR_OUTADDR_ADDRESS reload conflicts with
5968 the RELOAD_FOR_OUTPUT reloads, so assign it the same time
5970 case RELOAD_FOR_OUTADDR_ADDRESS
:
5971 if (type
== RELOAD_FOR_OUTPUT_ADDRESS
&& reloadnum
== i
+ 1
5972 && ignore_address_reloads
5973 && ! rld
[reloadnum
].out
)
5975 time2
= MAX_RECOG_OPERANDS
* 4 + 4 + rld
[i
].opnum
;
5977 case RELOAD_FOR_OUTPUT_ADDRESS
:
5978 time2
= MAX_RECOG_OPERANDS
* 4 + 5 + rld
[i
].opnum
;
5981 /* If there is no conflict in the input part, handle this
5982 like an output reload. */
5983 if (! rld
[i
].in
|| rtx_equal_p (other_input
, value
))
5985 time2
= MAX_RECOG_OPERANDS
* 4 + 4;
5986 /* Earlyclobbered outputs must conflict with inputs. */
5987 if (earlyclobber_operand_p (rld
[i
].out
))
5988 time2
= MAX_RECOG_OPERANDS
* 4 + 3;
5993 /* RELOAD_OTHER might be live beyond instruction execution,
5994 but this is not obvious when we set time2 = 1. So check
5995 here if there might be a problem with the new reload
5996 clobbering the register used by the RELOAD_OTHER. */
6004 && (! rld
[i
].in
|| rld
[i
].out
6005 || ! rtx_equal_p (other_input
, value
)))
6006 || (out
&& rld
[reloadnum
].out_reg
6007 && time2
>= MAX_RECOG_OPERANDS
* 4 + 3))
6013 /* Earlyclobbered outputs must conflict with inputs. */
6014 if (check_earlyclobber
&& out
&& earlyclobber_operand_p (out
))
6020 /* Return 1 if the value in reload reg REGNO, as used by a reload
6021 needed for the part of the insn specified by OPNUM and TYPE,
6022 may be used to load VALUE into it.
6024 MODE is the mode in which the register is used, this is needed to
6025 determine how many hard regs to test.
6027 Other read-only reloads with the same value do not conflict
6028 unless OUT is nonzero and these other reloads have to live while
6029 output reloads live.
6030 If OUT is CONST0_RTX, this is a special case: it means that the
6031 test should not be for using register REGNO as reload register, but
6032 for copying from register REGNO into the reload register.
6034 RELOADNUM is the number of the reload we want to load this value for;
6035 a reload does not conflict with itself.
6037 When IGNORE_ADDRESS_RELOADS is set, we can not have conflicts with
6038 reloads that load an address for the very reload we are considering.
6040 The caller has to make sure that there is no conflict with the return
6044 free_for_value_p (int regno
, enum machine_mode mode
, int opnum
,
6045 enum reload_type type
, rtx value
, rtx out
, int reloadnum
,
6046 int ignore_address_reloads
)
6048 int nregs
= hard_regno_nregs
[regno
][mode
];
6050 if (! reload_reg_free_for_value_p (regno
, regno
+ nregs
, opnum
, type
,
6051 value
, out
, reloadnum
,
6052 ignore_address_reloads
))
6057 /* Return nonzero if the rtx X is invariant over the current function. */
6058 /* ??? Actually, the places where we use this expect exactly what is
6059 tested here, and not everything that is function invariant. In
6060 particular, the frame pointer and arg pointer are special cased;
6061 pic_offset_table_rtx is not, and we must not spill these things to
6065 function_invariant_p (const_rtx x
)
6069 if (x
== frame_pointer_rtx
|| x
== arg_pointer_rtx
)
6071 if (GET_CODE (x
) == PLUS
6072 && (XEXP (x
, 0) == frame_pointer_rtx
|| XEXP (x
, 0) == arg_pointer_rtx
)
6073 && GET_CODE (XEXP (x
, 1)) == CONST_INT
)
6078 /* Determine whether the reload reg X overlaps any rtx'es used for
6079 overriding inheritance. Return nonzero if so. */
6082 conflicts_with_override (rtx x
)
6085 for (i
= 0; i
< n_reloads
; i
++)
6086 if (reload_override_in
[i
]
6087 && reg_overlap_mentioned_p (x
, reload_override_in
[i
]))
6092 /* Give an error message saying we failed to find a reload for INSN,
6093 and clear out reload R. */
6095 failed_reload (rtx insn
, int r
)
6097 if (asm_noperands (PATTERN (insn
)) < 0)
6098 /* It's the compiler's fault. */
6099 fatal_insn ("could not find a spill register", insn
);
6101 /* It's the user's fault; the operand's mode and constraint
6102 don't match. Disable this reload so we don't crash in final. */
6103 error_for_asm (insn
,
6104 "%<asm%> operand constraint incompatible with operand size");
6108 rld
[r
].optional
= 1;
6109 rld
[r
].secondary_p
= 1;
6112 /* I is the index in SPILL_REG_RTX of the reload register we are to allocate
6113 for reload R. If it's valid, get an rtx for it. Return nonzero if
6116 set_reload_reg (int i
, int r
)
6118 /* regno is 'set but not used' if HARD_REGNO_MODE_OK doesn't use its first
6120 int regno ATTRIBUTE_UNUSED
;
6121 rtx reg
= spill_reg_rtx
[i
];
6123 if (reg
== 0 || GET_MODE (reg
) != rld
[r
].mode
)
6124 spill_reg_rtx
[i
] = reg
6125 = gen_rtx_REG (rld
[r
].mode
, spill_regs
[i
]);
6127 regno
= true_regnum (reg
);
6129 /* Detect when the reload reg can't hold the reload mode.
6130 This used to be one `if', but Sequent compiler can't handle that. */
6131 if (HARD_REGNO_MODE_OK (regno
, rld
[r
].mode
))
6133 enum machine_mode test_mode
= VOIDmode
;
6135 test_mode
= GET_MODE (rld
[r
].in
);
6136 /* If rld[r].in has VOIDmode, it means we will load it
6137 in whatever mode the reload reg has: to wit, rld[r].mode.
6138 We have already tested that for validity. */
6139 /* Aside from that, we need to test that the expressions
6140 to reload from or into have modes which are valid for this
6141 reload register. Otherwise the reload insns would be invalid. */
6142 if (! (rld
[r
].in
!= 0 && test_mode
!= VOIDmode
6143 && ! HARD_REGNO_MODE_OK (regno
, test_mode
)))
6144 if (! (rld
[r
].out
!= 0
6145 && ! HARD_REGNO_MODE_OK (regno
, GET_MODE (rld
[r
].out
))))
6147 /* The reg is OK. */
6150 /* Mark as in use for this insn the reload regs we use
6152 mark_reload_reg_in_use (spill_regs
[i
], rld
[r
].opnum
,
6153 rld
[r
].when_needed
, rld
[r
].mode
);
6155 rld
[r
].reg_rtx
= reg
;
6156 reload_spill_index
[r
] = spill_regs
[i
];
6163 /* Find a spill register to use as a reload register for reload R.
6164 LAST_RELOAD is nonzero if this is the last reload for the insn being
6167 Set rld[R].reg_rtx to the register allocated.
6169 We return 1 if successful, or 0 if we couldn't find a spill reg and
6170 we didn't change anything. */
6173 allocate_reload_reg (struct insn_chain
*chain ATTRIBUTE_UNUSED
, int r
,
6178 /* If we put this reload ahead, thinking it is a group,
6179 then insist on finding a group. Otherwise we can grab a
6180 reg that some other reload needs.
6181 (That can happen when we have a 68000 DATA_OR_FP_REG
6182 which is a group of data regs or one fp reg.)
6183 We need not be so restrictive if there are no more reloads
6186 ??? Really it would be nicer to have smarter handling
6187 for that kind of reg class, where a problem like this is normal.
6188 Perhaps those classes should be avoided for reloading
6189 by use of more alternatives. */
6191 int force_group
= rld
[r
].nregs
> 1 && ! last_reload
;
6193 /* If we want a single register and haven't yet found one,
6194 take any reg in the right class and not in use.
6195 If we want a consecutive group, here is where we look for it.
6197 We use three passes so we can first look for reload regs to
6198 reuse, which are already in use for other reloads in this insn,
6199 and only then use additional registers which are not "bad", then
6200 finally any register.
6202 I think that maximizing reuse is needed to make sure we don't
6203 run out of reload regs. Suppose we have three reloads, and
6204 reloads A and B can share regs. These need two regs.
6205 Suppose A and B are given different regs.
6206 That leaves none for C. */
6207 for (pass
= 0; pass
< 3; pass
++)
6209 /* I is the index in spill_regs.
6210 We advance it round-robin between insns to use all spill regs
6211 equally, so that inherited reloads have a chance
6212 of leapfrogging each other. */
6216 for (count
= 0; count
< n_spills
; count
++)
6218 int rclass
= (int) rld
[r
].rclass
;
6224 regnum
= spill_regs
[i
];
6226 if ((reload_reg_free_p (regnum
, rld
[r
].opnum
,
6229 /* We check reload_reg_used to make sure we
6230 don't clobber the return register. */
6231 && ! TEST_HARD_REG_BIT (reload_reg_used
, regnum
)
6232 && free_for_value_p (regnum
, rld
[r
].mode
, rld
[r
].opnum
,
6233 rld
[r
].when_needed
, rld
[r
].in
,
6235 && TEST_HARD_REG_BIT (reg_class_contents
[rclass
], regnum
)
6236 && HARD_REGNO_MODE_OK (regnum
, rld
[r
].mode
)
6237 /* Look first for regs to share, then for unshared. But
6238 don't share regs used for inherited reloads; they are
6239 the ones we want to preserve. */
6241 || (TEST_HARD_REG_BIT (reload_reg_used_at_all
,
6243 && ! TEST_HARD_REG_BIT (reload_reg_used_for_inherit
,
6246 int nr
= hard_regno_nregs
[regnum
][rld
[r
].mode
];
6248 /* During the second pass we want to avoid reload registers
6249 which are "bad" for this reload. */
6251 && ira_bad_reload_regno (regnum
, rld
[r
].in
, rld
[r
].out
))
6254 /* Avoid the problem where spilling a GENERAL_OR_FP_REG
6255 (on 68000) got us two FP regs. If NR is 1,
6256 we would reject both of them. */
6259 /* If we need only one reg, we have already won. */
6262 /* But reject a single reg if we demand a group. */
6267 /* Otherwise check that as many consecutive regs as we need
6268 are available here. */
6271 int regno
= regnum
+ nr
- 1;
6272 if (!(TEST_HARD_REG_BIT (reg_class_contents
[rclass
], regno
)
6273 && spill_reg_order
[regno
] >= 0
6274 && reload_reg_free_p (regno
, rld
[r
].opnum
,
6275 rld
[r
].when_needed
)))
6284 /* If we found something on the current pass, omit later passes. */
6285 if (count
< n_spills
)
6289 /* We should have found a spill register by now. */
6290 if (count
>= n_spills
)
6293 /* I is the index in SPILL_REG_RTX of the reload register we are to
6294 allocate. Get an rtx for it and find its register number. */
6296 return set_reload_reg (i
, r
);
6299 /* Initialize all the tables needed to allocate reload registers.
6300 CHAIN is the insn currently being processed; SAVE_RELOAD_REG_RTX
6301 is the array we use to restore the reg_rtx field for every reload. */
6304 choose_reload_regs_init (struct insn_chain
*chain
, rtx
*save_reload_reg_rtx
)
6308 for (i
= 0; i
< n_reloads
; i
++)
6309 rld
[i
].reg_rtx
= save_reload_reg_rtx
[i
];
6311 memset (reload_inherited
, 0, MAX_RELOADS
);
6312 memset (reload_inheritance_insn
, 0, MAX_RELOADS
* sizeof (rtx
));
6313 memset (reload_override_in
, 0, MAX_RELOADS
* sizeof (rtx
));
6315 CLEAR_HARD_REG_SET (reload_reg_used
);
6316 CLEAR_HARD_REG_SET (reload_reg_used_at_all
);
6317 CLEAR_HARD_REG_SET (reload_reg_used_in_op_addr
);
6318 CLEAR_HARD_REG_SET (reload_reg_used_in_op_addr_reload
);
6319 CLEAR_HARD_REG_SET (reload_reg_used_in_insn
);
6320 CLEAR_HARD_REG_SET (reload_reg_used_in_other_addr
);
6322 CLEAR_HARD_REG_SET (reg_used_in_insn
);
6325 REG_SET_TO_HARD_REG_SET (tmp
, &chain
->live_throughout
);
6326 IOR_HARD_REG_SET (reg_used_in_insn
, tmp
);
6327 REG_SET_TO_HARD_REG_SET (tmp
, &chain
->dead_or_set
);
6328 IOR_HARD_REG_SET (reg_used_in_insn
, tmp
);
6329 compute_use_by_pseudos (®_used_in_insn
, &chain
->live_throughout
);
6330 compute_use_by_pseudos (®_used_in_insn
, &chain
->dead_or_set
);
6333 for (i
= 0; i
< reload_n_operands
; i
++)
6335 CLEAR_HARD_REG_SET (reload_reg_used_in_output
[i
]);
6336 CLEAR_HARD_REG_SET (reload_reg_used_in_input
[i
]);
6337 CLEAR_HARD_REG_SET (reload_reg_used_in_input_addr
[i
]);
6338 CLEAR_HARD_REG_SET (reload_reg_used_in_inpaddr_addr
[i
]);
6339 CLEAR_HARD_REG_SET (reload_reg_used_in_output_addr
[i
]);
6340 CLEAR_HARD_REG_SET (reload_reg_used_in_outaddr_addr
[i
]);
6343 COMPL_HARD_REG_SET (reload_reg_unavailable
, chain
->used_spill_regs
);
6345 CLEAR_HARD_REG_SET (reload_reg_used_for_inherit
);
6347 for (i
= 0; i
< n_reloads
; i
++)
6348 /* If we have already decided to use a certain register,
6349 don't use it in another way. */
6351 mark_reload_reg_in_use (REGNO (rld
[i
].reg_rtx
), rld
[i
].opnum
,
6352 rld
[i
].when_needed
, rld
[i
].mode
);
6355 #ifdef SECONDARY_MEMORY_NEEDED
6356 /* If X is not a subreg, return it unmodified. If it is a subreg,
6357 look up whether we made a replacement for the SUBREG_REG. Return
6358 either the replacement or the SUBREG_REG. */
6361 replaced_subreg (rtx x
)
6363 if (GET_CODE (x
) == SUBREG
)
6364 return find_replacement (&SUBREG_REG (x
));
6369 /* Assign hard reg targets for the pseudo-registers we must reload
6370 into hard regs for this insn.
6371 Also output the instructions to copy them in and out of the hard regs.
6373 For machines with register classes, we are responsible for
6374 finding a reload reg in the proper class. */
6377 choose_reload_regs (struct insn_chain
*chain
)
6379 rtx insn
= chain
->insn
;
6381 unsigned int max_group_size
= 1;
6382 enum reg_class group_class
= NO_REGS
;
6383 int pass
, win
, inheritance
;
6385 rtx save_reload_reg_rtx
[MAX_RELOADS
];
6387 /* In order to be certain of getting the registers we need,
6388 we must sort the reloads into order of increasing register class.
6389 Then our grabbing of reload registers will parallel the process
6390 that provided the reload registers.
6392 Also note whether any of the reloads wants a consecutive group of regs.
6393 If so, record the maximum size of the group desired and what
6394 register class contains all the groups needed by this insn. */
6396 for (j
= 0; j
< n_reloads
; j
++)
6398 reload_order
[j
] = j
;
6399 if (rld
[j
].reg_rtx
!= NULL_RTX
)
6401 gcc_assert (REG_P (rld
[j
].reg_rtx
)
6402 && HARD_REGISTER_P (rld
[j
].reg_rtx
));
6403 reload_spill_index
[j
] = REGNO (rld
[j
].reg_rtx
);
6406 reload_spill_index
[j
] = -1;
6408 if (rld
[j
].nregs
> 1)
6410 max_group_size
= MAX (rld
[j
].nregs
, max_group_size
);
6412 = reg_class_superunion
[(int) rld
[j
].rclass
][(int) group_class
];
6415 save_reload_reg_rtx
[j
] = rld
[j
].reg_rtx
;
6419 qsort (reload_order
, n_reloads
, sizeof (short), reload_reg_class_lower
);
6421 /* If -O, try first with inheritance, then turning it off.
6422 If not -O, don't do inheritance.
6423 Using inheritance when not optimizing leads to paradoxes
6424 with fp on the 68k: fp numbers (not NaNs) fail to be equal to themselves
6425 because one side of the comparison might be inherited. */
6427 for (inheritance
= optimize
> 0; inheritance
>= 0; inheritance
--)
6429 choose_reload_regs_init (chain
, save_reload_reg_rtx
);
6431 /* Process the reloads in order of preference just found.
6432 Beyond this point, subregs can be found in reload_reg_rtx.
6434 This used to look for an existing reloaded home for all of the
6435 reloads, and only then perform any new reloads. But that could lose
6436 if the reloads were done out of reg-class order because a later
6437 reload with a looser constraint might have an old home in a register
6438 needed by an earlier reload with a tighter constraint.
6440 To solve this, we make two passes over the reloads, in the order
6441 described above. In the first pass we try to inherit a reload
6442 from a previous insn. If there is a later reload that needs a
6443 class that is a proper subset of the class being processed, we must
6444 also allocate a spill register during the first pass.
6446 Then make a second pass over the reloads to allocate any reloads
6447 that haven't been given registers yet. */
6449 for (j
= 0; j
< n_reloads
; j
++)
6451 int r
= reload_order
[j
];
6452 rtx search_equiv
= NULL_RTX
;
6454 /* Ignore reloads that got marked inoperative. */
6455 if (rld
[r
].out
== 0 && rld
[r
].in
== 0
6456 && ! rld
[r
].secondary_p
)
6459 /* If find_reloads chose to use reload_in or reload_out as a reload
6460 register, we don't need to chose one. Otherwise, try even if it
6461 found one since we might save an insn if we find the value lying
6463 Try also when reload_in is a pseudo without a hard reg. */
6464 if (rld
[r
].in
!= 0 && rld
[r
].reg_rtx
!= 0
6465 && (rtx_equal_p (rld
[r
].in
, rld
[r
].reg_rtx
)
6466 || (rtx_equal_p (rld
[r
].out
, rld
[r
].reg_rtx
)
6467 && !MEM_P (rld
[r
].in
)
6468 && true_regnum (rld
[r
].in
) < FIRST_PSEUDO_REGISTER
)))
6471 #if 0 /* No longer needed for correct operation.
6472 It might give better code, or might not; worth an experiment? */
6473 /* If this is an optional reload, we can't inherit from earlier insns
6474 until we are sure that any non-optional reloads have been allocated.
6475 The following code takes advantage of the fact that optional reloads
6476 are at the end of reload_order. */
6477 if (rld
[r
].optional
!= 0)
6478 for (i
= 0; i
< j
; i
++)
6479 if ((rld
[reload_order
[i
]].out
!= 0
6480 || rld
[reload_order
[i
]].in
!= 0
6481 || rld
[reload_order
[i
]].secondary_p
)
6482 && ! rld
[reload_order
[i
]].optional
6483 && rld
[reload_order
[i
]].reg_rtx
== 0)
6484 allocate_reload_reg (chain
, reload_order
[i
], 0);
6487 /* First see if this pseudo is already available as reloaded
6488 for a previous insn. We cannot try to inherit for reloads
6489 that are smaller than the maximum number of registers needed
6490 for groups unless the register we would allocate cannot be used
6493 We could check here to see if this is a secondary reload for
6494 an object that is already in a register of the desired class.
6495 This would avoid the need for the secondary reload register.
6496 But this is complex because we can't easily determine what
6497 objects might want to be loaded via this reload. So let a
6498 register be allocated here. In `emit_reload_insns' we suppress
6499 one of the loads in the case described above. */
6505 enum machine_mode mode
= VOIDmode
;
6509 else if (REG_P (rld
[r
].in
))
6511 regno
= REGNO (rld
[r
].in
);
6512 mode
= GET_MODE (rld
[r
].in
);
6514 else if (REG_P (rld
[r
].in_reg
))
6516 regno
= REGNO (rld
[r
].in_reg
);
6517 mode
= GET_MODE (rld
[r
].in_reg
);
6519 else if (GET_CODE (rld
[r
].in_reg
) == SUBREG
6520 && REG_P (SUBREG_REG (rld
[r
].in_reg
)))
6522 regno
= REGNO (SUBREG_REG (rld
[r
].in_reg
));
6523 if (regno
< FIRST_PSEUDO_REGISTER
)
6524 regno
= subreg_regno (rld
[r
].in_reg
);
6526 byte
= SUBREG_BYTE (rld
[r
].in_reg
);
6527 mode
= GET_MODE (rld
[r
].in_reg
);
6530 else if (GET_RTX_CLASS (GET_CODE (rld
[r
].in_reg
)) == RTX_AUTOINC
6531 && REG_P (XEXP (rld
[r
].in_reg
, 0)))
6533 regno
= REGNO (XEXP (rld
[r
].in_reg
, 0));
6534 mode
= GET_MODE (XEXP (rld
[r
].in_reg
, 0));
6535 rld
[r
].out
= rld
[r
].in
;
6539 /* This won't work, since REGNO can be a pseudo reg number.
6540 Also, it takes much more hair to keep track of all the things
6541 that can invalidate an inherited reload of part of a pseudoreg. */
6542 else if (GET_CODE (rld
[r
].in
) == SUBREG
6543 && REG_P (SUBREG_REG (rld
[r
].in
)))
6544 regno
= subreg_regno (rld
[r
].in
);
6548 && reg_last_reload_reg
[regno
] != 0
6549 && (GET_MODE_SIZE (GET_MODE (reg_last_reload_reg
[regno
]))
6550 >= GET_MODE_SIZE (mode
) + byte
)
6551 #ifdef CANNOT_CHANGE_MODE_CLASS
6552 /* Verify that the register it's in can be used in
6554 && !REG_CANNOT_CHANGE_MODE_P (REGNO (reg_last_reload_reg
[regno
]),
6555 GET_MODE (reg_last_reload_reg
[regno
]),
6560 enum reg_class rclass
= rld
[r
].rclass
, last_class
;
6561 rtx last_reg
= reg_last_reload_reg
[regno
];
6563 i
= REGNO (last_reg
);
6564 i
+= subreg_regno_offset (i
, GET_MODE (last_reg
), byte
, mode
);
6565 last_class
= REGNO_REG_CLASS (i
);
6567 if (reg_reloaded_contents
[i
] == regno
6568 && TEST_HARD_REG_BIT (reg_reloaded_valid
, i
)
6569 && HARD_REGNO_MODE_OK (i
, rld
[r
].mode
)
6570 && (TEST_HARD_REG_BIT (reg_class_contents
[(int) rclass
], i
)
6571 /* Even if we can't use this register as a reload
6572 register, we might use it for reload_override_in,
6573 if copying it to the desired class is cheap
6575 || ((register_move_cost (mode
, last_class
, rclass
)
6576 < memory_move_cost (mode
, rclass
, true))
6577 && (secondary_reload_class (1, rclass
, mode
,
6580 #ifdef SECONDARY_MEMORY_NEEDED
6581 && ! SECONDARY_MEMORY_NEEDED (last_class
, rclass
,
6586 && (rld
[r
].nregs
== max_group_size
6587 || ! TEST_HARD_REG_BIT (reg_class_contents
[(int) group_class
],
6589 && free_for_value_p (i
, rld
[r
].mode
, rld
[r
].opnum
,
6590 rld
[r
].when_needed
, rld
[r
].in
,
6593 /* If a group is needed, verify that all the subsequent
6594 registers still have their values intact. */
6595 int nr
= hard_regno_nregs
[i
][rld
[r
].mode
];
6598 for (k
= 1; k
< nr
; k
++)
6599 if (reg_reloaded_contents
[i
+ k
] != regno
6600 || ! TEST_HARD_REG_BIT (reg_reloaded_valid
, i
+ k
))
6608 last_reg
= (GET_MODE (last_reg
) == mode
6609 ? last_reg
: gen_rtx_REG (mode
, i
));
6612 for (k
= 0; k
< nr
; k
++)
6613 bad_for_class
|= ! TEST_HARD_REG_BIT (reg_class_contents
[(int) rld
[r
].rclass
],
6616 /* We found a register that contains the
6617 value we need. If this register is the
6618 same as an `earlyclobber' operand of the
6619 current insn, just mark it as a place to
6620 reload from since we can't use it as the
6621 reload register itself. */
6623 for (i1
= 0; i1
< n_earlyclobbers
; i1
++)
6624 if (reg_overlap_mentioned_for_reload_p
6625 (reg_last_reload_reg
[regno
],
6626 reload_earlyclobbers
[i1
]))
6629 if (i1
!= n_earlyclobbers
6630 || ! (free_for_value_p (i
, rld
[r
].mode
,
6632 rld
[r
].when_needed
, rld
[r
].in
,
6634 /* Don't use it if we'd clobber a pseudo reg. */
6635 || (TEST_HARD_REG_BIT (reg_used_in_insn
, i
)
6637 && ! TEST_HARD_REG_BIT (reg_reloaded_dead
, i
))
6638 /* Don't clobber the frame pointer. */
6639 || (i
== HARD_FRAME_POINTER_REGNUM
6640 && frame_pointer_needed
6642 /* Don't really use the inherited spill reg
6643 if we need it wider than we've got it. */
6644 || (GET_MODE_SIZE (rld
[r
].mode
)
6645 > GET_MODE_SIZE (mode
))
6648 /* If find_reloads chose reload_out as reload
6649 register, stay with it - that leaves the
6650 inherited register for subsequent reloads. */
6651 || (rld
[r
].out
&& rld
[r
].reg_rtx
6652 && rtx_equal_p (rld
[r
].out
, rld
[r
].reg_rtx
)))
6654 if (! rld
[r
].optional
)
6656 reload_override_in
[r
] = last_reg
;
6657 reload_inheritance_insn
[r
]
6658 = reg_reloaded_insn
[i
];
6664 /* We can use this as a reload reg. */
6665 /* Mark the register as in use for this part of
6667 mark_reload_reg_in_use (i
,
6671 rld
[r
].reg_rtx
= last_reg
;
6672 reload_inherited
[r
] = 1;
6673 reload_inheritance_insn
[r
]
6674 = reg_reloaded_insn
[i
];
6675 reload_spill_index
[r
] = i
;
6676 for (k
= 0; k
< nr
; k
++)
6677 SET_HARD_REG_BIT (reload_reg_used_for_inherit
,
6685 /* Here's another way to see if the value is already lying around. */
6688 && ! reload_inherited
[r
]
6690 && (CONSTANT_P (rld
[r
].in
)
6691 || GET_CODE (rld
[r
].in
) == PLUS
6692 || REG_P (rld
[r
].in
)
6693 || MEM_P (rld
[r
].in
))
6694 && (rld
[r
].nregs
== max_group_size
6695 || ! reg_classes_intersect_p (rld
[r
].rclass
, group_class
)))
6696 search_equiv
= rld
[r
].in
;
6701 = find_equiv_reg (search_equiv
, insn
, rld
[r
].rclass
,
6702 -1, NULL
, 0, rld
[r
].mode
);
6708 regno
= REGNO (equiv
);
6711 /* This must be a SUBREG of a hard register.
6712 Make a new REG since this might be used in an
6713 address and not all machines support SUBREGs
6715 gcc_assert (GET_CODE (equiv
) == SUBREG
);
6716 regno
= subreg_regno (equiv
);
6717 equiv
= gen_rtx_REG (rld
[r
].mode
, regno
);
6718 /* If we choose EQUIV as the reload register, but the
6719 loop below decides to cancel the inheritance, we'll
6720 end up reloading EQUIV in rld[r].mode, not the mode
6721 it had originally. That isn't safe when EQUIV isn't
6722 available as a spill register since its value might
6723 still be live at this point. */
6724 for (i
= regno
; i
< regno
+ (int) rld
[r
].nregs
; i
++)
6725 if (TEST_HARD_REG_BIT (reload_reg_unavailable
, i
))
6730 /* If we found a spill reg, reject it unless it is free
6731 and of the desired class. */
6735 int bad_for_class
= 0;
6736 int max_regno
= regno
+ rld
[r
].nregs
;
6738 for (i
= regno
; i
< max_regno
; i
++)
6740 regs_used
|= TEST_HARD_REG_BIT (reload_reg_used_at_all
,
6742 bad_for_class
|= ! TEST_HARD_REG_BIT (reg_class_contents
[(int) rld
[r
].rclass
],
6747 && ! free_for_value_p (regno
, rld
[r
].mode
,
6748 rld
[r
].opnum
, rld
[r
].when_needed
,
6749 rld
[r
].in
, rld
[r
].out
, r
, 1))
6754 if (equiv
!= 0 && ! HARD_REGNO_MODE_OK (regno
, rld
[r
].mode
))
6757 /* We found a register that contains the value we need.
6758 If this register is the same as an `earlyclobber' operand
6759 of the current insn, just mark it as a place to reload from
6760 since we can't use it as the reload register itself. */
6763 for (i
= 0; i
< n_earlyclobbers
; i
++)
6764 if (reg_overlap_mentioned_for_reload_p (equiv
,
6765 reload_earlyclobbers
[i
]))
6767 if (! rld
[r
].optional
)
6768 reload_override_in
[r
] = equiv
;
6773 /* If the equiv register we have found is explicitly clobbered
6774 in the current insn, it depends on the reload type if we
6775 can use it, use it for reload_override_in, or not at all.
6776 In particular, we then can't use EQUIV for a
6777 RELOAD_FOR_OUTPUT_ADDRESS reload. */
6781 if (regno_clobbered_p (regno
, insn
, rld
[r
].mode
, 2))
6782 switch (rld
[r
].when_needed
)
6784 case RELOAD_FOR_OTHER_ADDRESS
:
6785 case RELOAD_FOR_INPADDR_ADDRESS
:
6786 case RELOAD_FOR_INPUT_ADDRESS
:
6787 case RELOAD_FOR_OPADDR_ADDR
:
6790 case RELOAD_FOR_INPUT
:
6791 case RELOAD_FOR_OPERAND_ADDRESS
:
6792 if (! rld
[r
].optional
)
6793 reload_override_in
[r
] = equiv
;
6799 else if (regno_clobbered_p (regno
, insn
, rld
[r
].mode
, 1))
6800 switch (rld
[r
].when_needed
)
6802 case RELOAD_FOR_OTHER_ADDRESS
:
6803 case RELOAD_FOR_INPADDR_ADDRESS
:
6804 case RELOAD_FOR_INPUT_ADDRESS
:
6805 case RELOAD_FOR_OPADDR_ADDR
:
6806 case RELOAD_FOR_OPERAND_ADDRESS
:
6807 case RELOAD_FOR_INPUT
:
6810 if (! rld
[r
].optional
)
6811 reload_override_in
[r
] = equiv
;
6819 /* If we found an equivalent reg, say no code need be generated
6820 to load it, and use it as our reload reg. */
6822 && (regno
!= HARD_FRAME_POINTER_REGNUM
6823 || !frame_pointer_needed
))
6825 int nr
= hard_regno_nregs
[regno
][rld
[r
].mode
];
6827 rld
[r
].reg_rtx
= equiv
;
6828 reload_spill_index
[r
] = regno
;
6829 reload_inherited
[r
] = 1;
6831 /* If reg_reloaded_valid is not set for this register,
6832 there might be a stale spill_reg_store lying around.
6833 We must clear it, since otherwise emit_reload_insns
6834 might delete the store. */
6835 if (! TEST_HARD_REG_BIT (reg_reloaded_valid
, regno
))
6836 spill_reg_store
[regno
] = NULL_RTX
;
6837 /* If any of the hard registers in EQUIV are spill
6838 registers, mark them as in use for this insn. */
6839 for (k
= 0; k
< nr
; k
++)
6841 i
= spill_reg_order
[regno
+ k
];
6844 mark_reload_reg_in_use (regno
, rld
[r
].opnum
,
6847 SET_HARD_REG_BIT (reload_reg_used_for_inherit
,
6854 /* If we found a register to use already, or if this is an optional
6855 reload, we are done. */
6856 if (rld
[r
].reg_rtx
!= 0 || rld
[r
].optional
!= 0)
6860 /* No longer needed for correct operation. Might or might
6861 not give better code on the average. Want to experiment? */
6863 /* See if there is a later reload that has a class different from our
6864 class that intersects our class or that requires less register
6865 than our reload. If so, we must allocate a register to this
6866 reload now, since that reload might inherit a previous reload
6867 and take the only available register in our class. Don't do this
6868 for optional reloads since they will force all previous reloads
6869 to be allocated. Also don't do this for reloads that have been
6872 for (i
= j
+ 1; i
< n_reloads
; i
++)
6874 int s
= reload_order
[i
];
6876 if ((rld
[s
].in
== 0 && rld
[s
].out
== 0
6877 && ! rld
[s
].secondary_p
)
6881 if ((rld
[s
].rclass
!= rld
[r
].rclass
6882 && reg_classes_intersect_p (rld
[r
].rclass
,
6884 || rld
[s
].nregs
< rld
[r
].nregs
)
6891 allocate_reload_reg (chain
, r
, j
== n_reloads
- 1);
6895 /* Now allocate reload registers for anything non-optional that
6896 didn't get one yet. */
6897 for (j
= 0; j
< n_reloads
; j
++)
6899 int r
= reload_order
[j
];
6901 /* Ignore reloads that got marked inoperative. */
6902 if (rld
[r
].out
== 0 && rld
[r
].in
== 0 && ! rld
[r
].secondary_p
)
6905 /* Skip reloads that already have a register allocated or are
6907 if (rld
[r
].reg_rtx
!= 0 || rld
[r
].optional
)
6910 if (! allocate_reload_reg (chain
, r
, j
== n_reloads
- 1))
6914 /* If that loop got all the way, we have won. */
6921 /* Loop around and try without any inheritance. */
6926 /* First undo everything done by the failed attempt
6927 to allocate with inheritance. */
6928 choose_reload_regs_init (chain
, save_reload_reg_rtx
);
6930 /* Some sanity tests to verify that the reloads found in the first
6931 pass are identical to the ones we have now. */
6932 gcc_assert (chain
->n_reloads
== n_reloads
);
6934 for (i
= 0; i
< n_reloads
; i
++)
6936 if (chain
->rld
[i
].regno
< 0 || chain
->rld
[i
].reg_rtx
!= 0)
6938 gcc_assert (chain
->rld
[i
].when_needed
== rld
[i
].when_needed
);
6939 for (j
= 0; j
< n_spills
; j
++)
6940 if (spill_regs
[j
] == chain
->rld
[i
].regno
)
6941 if (! set_reload_reg (j
, i
))
6942 failed_reload (chain
->insn
, i
);
6946 /* If we thought we could inherit a reload, because it seemed that
6947 nothing else wanted the same reload register earlier in the insn,
6948 verify that assumption, now that all reloads have been assigned.
6949 Likewise for reloads where reload_override_in has been set. */
6951 /* If doing expensive optimizations, do one preliminary pass that doesn't
6952 cancel any inheritance, but removes reloads that have been needed only
6953 for reloads that we know can be inherited. */
6954 for (pass
= flag_expensive_optimizations
; pass
>= 0; pass
--)
6956 for (j
= 0; j
< n_reloads
; j
++)
6958 int r
= reload_order
[j
];
6960 #ifdef SECONDARY_MEMORY_NEEDED
6963 if (reload_inherited
[r
] && rld
[r
].reg_rtx
)
6964 check_reg
= rld
[r
].reg_rtx
;
6965 else if (reload_override_in
[r
]
6966 && (REG_P (reload_override_in
[r
])
6967 || GET_CODE (reload_override_in
[r
]) == SUBREG
))
6968 check_reg
= reload_override_in
[r
];
6971 if (! free_for_value_p (true_regnum (check_reg
), rld
[r
].mode
,
6972 rld
[r
].opnum
, rld
[r
].when_needed
, rld
[r
].in
,
6973 (reload_inherited
[r
]
6974 ? rld
[r
].out
: const0_rtx
),
6979 reload_inherited
[r
] = 0;
6980 reload_override_in
[r
] = 0;
6982 /* If we can inherit a RELOAD_FOR_INPUT, or can use a
6983 reload_override_in, then we do not need its related
6984 RELOAD_FOR_INPUT_ADDRESS / RELOAD_FOR_INPADDR_ADDRESS reloads;
6985 likewise for other reload types.
6986 We handle this by removing a reload when its only replacement
6987 is mentioned in reload_in of the reload we are going to inherit.
6988 A special case are auto_inc expressions; even if the input is
6989 inherited, we still need the address for the output. We can
6990 recognize them because they have RELOAD_OUT set to RELOAD_IN.
6991 If we succeeded removing some reload and we are doing a preliminary
6992 pass just to remove such reloads, make another pass, since the
6993 removal of one reload might allow us to inherit another one. */
6995 && rld
[r
].out
!= rld
[r
].in
6996 && remove_address_replacements (rld
[r
].in
))
7001 #ifdef SECONDARY_MEMORY_NEEDED
7002 /* If we needed a memory location for the reload, we also have to
7003 remove its related reloads. */
7005 && rld
[r
].out
!= rld
[r
].in
7006 && (tem
= replaced_subreg (rld
[r
].in
), REG_P (tem
))
7007 && REGNO (tem
) < FIRST_PSEUDO_REGISTER
7008 && SECONDARY_MEMORY_NEEDED (REGNO_REG_CLASS (REGNO (tem
)),
7009 rld
[r
].rclass
, rld
[r
].inmode
)
7010 && remove_address_replacements
7011 (get_secondary_mem (tem
, rld
[r
].inmode
, rld
[r
].opnum
,
7012 rld
[r
].when_needed
)))
7021 /* Now that reload_override_in is known valid,
7022 actually override reload_in. */
7023 for (j
= 0; j
< n_reloads
; j
++)
7024 if (reload_override_in
[j
])
7025 rld
[j
].in
= reload_override_in
[j
];
7027 /* If this reload won't be done because it has been canceled or is
7028 optional and not inherited, clear reload_reg_rtx so other
7029 routines (such as subst_reloads) don't get confused. */
7030 for (j
= 0; j
< n_reloads
; j
++)
7031 if (rld
[j
].reg_rtx
!= 0
7032 && ((rld
[j
].optional
&& ! reload_inherited
[j
])
7033 || (rld
[j
].in
== 0 && rld
[j
].out
== 0
7034 && ! rld
[j
].secondary_p
)))
7036 int regno
= true_regnum (rld
[j
].reg_rtx
);
7038 if (spill_reg_order
[regno
] >= 0)
7039 clear_reload_reg_in_use (regno
, rld
[j
].opnum
,
7040 rld
[j
].when_needed
, rld
[j
].mode
);
7042 reload_spill_index
[j
] = -1;
7045 /* Record which pseudos and which spill regs have output reloads. */
7046 for (j
= 0; j
< n_reloads
; j
++)
7048 int r
= reload_order
[j
];
7050 i
= reload_spill_index
[r
];
7052 /* I is nonneg if this reload uses a register.
7053 If rld[r].reg_rtx is 0, this is an optional reload
7054 that we opted to ignore. */
7055 if (rld
[r
].out_reg
!= 0 && REG_P (rld
[r
].out_reg
)
7056 && rld
[r
].reg_rtx
!= 0)
7058 int nregno
= REGNO (rld
[r
].out_reg
);
7061 if (nregno
< FIRST_PSEUDO_REGISTER
)
7062 nr
= hard_regno_nregs
[nregno
][rld
[r
].mode
];
7065 SET_REGNO_REG_SET (®_has_output_reload
,
7069 add_to_hard_reg_set (®_is_output_reload
, rld
[r
].mode
, i
);
7071 gcc_assert (rld
[r
].when_needed
== RELOAD_OTHER
7072 || rld
[r
].when_needed
== RELOAD_FOR_OUTPUT
7073 || rld
[r
].when_needed
== RELOAD_FOR_INSN
);
7078 /* Deallocate the reload register for reload R. This is called from
7079 remove_address_replacements. */
7082 deallocate_reload_reg (int r
)
7086 if (! rld
[r
].reg_rtx
)
7088 regno
= true_regnum (rld
[r
].reg_rtx
);
7090 if (spill_reg_order
[regno
] >= 0)
7091 clear_reload_reg_in_use (regno
, rld
[r
].opnum
, rld
[r
].when_needed
,
7093 reload_spill_index
[r
] = -1;
7096 /* These arrays are filled by emit_reload_insns and its subroutines. */
7097 static rtx input_reload_insns
[MAX_RECOG_OPERANDS
];
7098 static rtx other_input_address_reload_insns
= 0;
7099 static rtx other_input_reload_insns
= 0;
7100 static rtx input_address_reload_insns
[MAX_RECOG_OPERANDS
];
7101 static rtx inpaddr_address_reload_insns
[MAX_RECOG_OPERANDS
];
7102 static rtx output_reload_insns
[MAX_RECOG_OPERANDS
];
7103 static rtx output_address_reload_insns
[MAX_RECOG_OPERANDS
];
7104 static rtx outaddr_address_reload_insns
[MAX_RECOG_OPERANDS
];
7105 static rtx operand_reload_insns
= 0;
7106 static rtx other_operand_reload_insns
= 0;
7107 static rtx other_output_reload_insns
[MAX_RECOG_OPERANDS
];
7109 /* Values to be put in spill_reg_store are put here first. Instructions
7110 must only be placed here if the associated reload register reaches
7111 the end of the instruction's reload sequence. */
7112 static rtx new_spill_reg_store
[FIRST_PSEUDO_REGISTER
];
7113 static HARD_REG_SET reg_reloaded_died
;
7115 /* Check if *RELOAD_REG is suitable as an intermediate or scratch register
7116 of class NEW_CLASS with mode NEW_MODE. Or alternatively, if alt_reload_reg
7117 is nonzero, if that is suitable. On success, change *RELOAD_REG to the
7118 adjusted register, and return true. Otherwise, return false. */
7120 reload_adjust_reg_for_temp (rtx
*reload_reg
, rtx alt_reload_reg
,
7121 enum reg_class new_class
,
7122 enum machine_mode new_mode
)
7127 for (reg
= *reload_reg
; reg
; reg
= alt_reload_reg
, alt_reload_reg
= 0)
7129 unsigned regno
= REGNO (reg
);
7131 if (!TEST_HARD_REG_BIT (reg_class_contents
[(int) new_class
], regno
))
7133 if (GET_MODE (reg
) != new_mode
)
7135 if (!HARD_REGNO_MODE_OK (regno
, new_mode
))
7137 if (hard_regno_nregs
[regno
][new_mode
]
7138 > hard_regno_nregs
[regno
][GET_MODE (reg
)])
7140 reg
= reload_adjust_reg_for_mode (reg
, new_mode
);
7148 /* Check if *RELOAD_REG is suitable as a scratch register for the reload
7149 pattern with insn_code ICODE, or alternatively, if alt_reload_reg is
7150 nonzero, if that is suitable. On success, change *RELOAD_REG to the
7151 adjusted register, and return true. Otherwise, return false. */
7153 reload_adjust_reg_for_icode (rtx
*reload_reg
, rtx alt_reload_reg
,
7154 enum insn_code icode
)
7157 enum reg_class new_class
= scratch_reload_class (icode
);
7158 enum machine_mode new_mode
= insn_data
[(int) icode
].operand
[2].mode
;
7160 return reload_adjust_reg_for_temp (reload_reg
, alt_reload_reg
,
7161 new_class
, new_mode
);
7164 /* Generate insns to perform reload RL, which is for the insn in CHAIN and
7165 has the number J. OLD contains the value to be used as input. */
7168 emit_input_reload_insns (struct insn_chain
*chain
, struct reload
*rl
,
7171 rtx insn
= chain
->insn
;
7173 rtx oldequiv_reg
= 0;
7176 enum machine_mode mode
;
7179 /* delete_output_reload is only invoked properly if old contains
7180 the original pseudo register. Since this is replaced with a
7181 hard reg when RELOAD_OVERRIDE_IN is set, see if we can
7182 find the pseudo in RELOAD_IN_REG. */
7183 if (reload_override_in
[j
]
7184 && REG_P (rl
->in_reg
))
7191 else if (REG_P (oldequiv
))
7192 oldequiv_reg
= oldequiv
;
7193 else if (GET_CODE (oldequiv
) == SUBREG
)
7194 oldequiv_reg
= SUBREG_REG (oldequiv
);
7196 reloadreg
= reload_reg_rtx_for_input
[j
];
7197 mode
= GET_MODE (reloadreg
);
7199 /* If we are reloading from a register that was recently stored in
7200 with an output-reload, see if we can prove there was
7201 actually no need to store the old value in it. */
7203 if (optimize
&& REG_P (oldequiv
)
7204 && REGNO (oldequiv
) < FIRST_PSEUDO_REGISTER
7205 && spill_reg_store
[REGNO (oldequiv
)]
7207 && (dead_or_set_p (insn
, spill_reg_stored_to
[REGNO (oldequiv
)])
7208 || rtx_equal_p (spill_reg_stored_to
[REGNO (oldequiv
)],
7210 delete_output_reload (insn
, j
, REGNO (oldequiv
), reloadreg
);
7212 /* Encapsulate OLDEQUIV into the reload mode, then load RELOADREG from
7215 while (GET_CODE (oldequiv
) == SUBREG
&& GET_MODE (oldequiv
) != mode
)
7216 oldequiv
= SUBREG_REG (oldequiv
);
7217 if (GET_MODE (oldequiv
) != VOIDmode
7218 && mode
!= GET_MODE (oldequiv
))
7219 oldequiv
= gen_lowpart_SUBREG (mode
, oldequiv
);
7221 /* Switch to the right place to emit the reload insns. */
7222 switch (rl
->when_needed
)
7225 where
= &other_input_reload_insns
;
7227 case RELOAD_FOR_INPUT
:
7228 where
= &input_reload_insns
[rl
->opnum
];
7230 case RELOAD_FOR_INPUT_ADDRESS
:
7231 where
= &input_address_reload_insns
[rl
->opnum
];
7233 case RELOAD_FOR_INPADDR_ADDRESS
:
7234 where
= &inpaddr_address_reload_insns
[rl
->opnum
];
7236 case RELOAD_FOR_OUTPUT_ADDRESS
:
7237 where
= &output_address_reload_insns
[rl
->opnum
];
7239 case RELOAD_FOR_OUTADDR_ADDRESS
:
7240 where
= &outaddr_address_reload_insns
[rl
->opnum
];
7242 case RELOAD_FOR_OPERAND_ADDRESS
:
7243 where
= &operand_reload_insns
;
7245 case RELOAD_FOR_OPADDR_ADDR
:
7246 where
= &other_operand_reload_insns
;
7248 case RELOAD_FOR_OTHER_ADDRESS
:
7249 where
= &other_input_address_reload_insns
;
7255 push_to_sequence (*where
);
7257 /* Auto-increment addresses must be reloaded in a special way. */
7258 if (rl
->out
&& ! rl
->out_reg
)
7260 /* We are not going to bother supporting the case where a
7261 incremented register can't be copied directly from
7262 OLDEQUIV since this seems highly unlikely. */
7263 gcc_assert (rl
->secondary_in_reload
< 0);
7265 if (reload_inherited
[j
])
7266 oldequiv
= reloadreg
;
7268 old
= XEXP (rl
->in_reg
, 0);
7270 /* Prevent normal processing of this reload. */
7272 /* Output a special code sequence for this case. */
7273 inc_for_reload (reloadreg
, oldequiv
, rl
->out
, rl
->inc
);
7276 /* If we are reloading a pseudo-register that was set by the previous
7277 insn, see if we can get rid of that pseudo-register entirely
7278 by redirecting the previous insn into our reload register. */
7280 else if (optimize
&& REG_P (old
)
7281 && REGNO (old
) >= FIRST_PSEUDO_REGISTER
7282 && dead_or_set_p (insn
, old
)
7283 /* This is unsafe if some other reload
7284 uses the same reg first. */
7285 && ! conflicts_with_override (reloadreg
)
7286 && free_for_value_p (REGNO (reloadreg
), rl
->mode
, rl
->opnum
,
7287 rl
->when_needed
, old
, rl
->out
, j
, 0))
7289 rtx temp
= PREV_INSN (insn
);
7290 while (temp
&& (NOTE_P (temp
) || DEBUG_INSN_P (temp
)))
7291 temp
= PREV_INSN (temp
);
7293 && NONJUMP_INSN_P (temp
)
7294 && GET_CODE (PATTERN (temp
)) == SET
7295 && SET_DEST (PATTERN (temp
)) == old
7296 /* Make sure we can access insn_operand_constraint. */
7297 && asm_noperands (PATTERN (temp
)) < 0
7298 /* This is unsafe if operand occurs more than once in current
7299 insn. Perhaps some occurrences aren't reloaded. */
7300 && count_occurrences (PATTERN (insn
), old
, 0) == 1)
7302 rtx old
= SET_DEST (PATTERN (temp
));
7303 /* Store into the reload register instead of the pseudo. */
7304 SET_DEST (PATTERN (temp
)) = reloadreg
;
7306 /* Verify that resulting insn is valid. */
7307 extract_insn (temp
);
7308 if (constrain_operands (1))
7310 /* If the previous insn is an output reload, the source is
7311 a reload register, and its spill_reg_store entry will
7312 contain the previous destination. This is now
7314 if (REG_P (SET_SRC (PATTERN (temp
)))
7315 && REGNO (SET_SRC (PATTERN (temp
))) < FIRST_PSEUDO_REGISTER
)
7317 spill_reg_store
[REGNO (SET_SRC (PATTERN (temp
)))] = 0;
7318 spill_reg_stored_to
[REGNO (SET_SRC (PATTERN (temp
)))] = 0;
7321 /* If these are the only uses of the pseudo reg,
7322 pretend for GDB it lives in the reload reg we used. */
7323 if (REG_N_DEATHS (REGNO (old
)) == 1
7324 && REG_N_SETS (REGNO (old
)) == 1)
7326 reg_renumber
[REGNO (old
)] = REGNO (reloadreg
);
7327 if (ira_conflicts_p
)
7328 /* Inform IRA about the change. */
7329 ira_mark_allocation_change (REGNO (old
));
7330 alter_reg (REGNO (old
), -1, false);
7334 /* Adjust any debug insns between temp and insn. */
7335 while ((temp
= NEXT_INSN (temp
)) != insn
)
7336 if (DEBUG_INSN_P (temp
))
7337 replace_rtx (PATTERN (temp
), old
, reloadreg
);
7339 gcc_assert (NOTE_P (temp
));
7343 SET_DEST (PATTERN (temp
)) = old
;
7348 /* We can't do that, so output an insn to load RELOADREG. */
7350 /* If we have a secondary reload, pick up the secondary register
7351 and icode, if any. If OLDEQUIV and OLD are different or
7352 if this is an in-out reload, recompute whether or not we
7353 still need a secondary register and what the icode should
7354 be. If we still need a secondary register and the class or
7355 icode is different, go back to reloading from OLD if using
7356 OLDEQUIV means that we got the wrong type of register. We
7357 cannot have different class or icode due to an in-out reload
7358 because we don't make such reloads when both the input and
7359 output need secondary reload registers. */
7361 if (! special
&& rl
->secondary_in_reload
>= 0)
7363 rtx second_reload_reg
= 0;
7364 rtx third_reload_reg
= 0;
7365 int secondary_reload
= rl
->secondary_in_reload
;
7366 rtx real_oldequiv
= oldequiv
;
7369 enum insn_code icode
;
7370 enum insn_code tertiary_icode
= CODE_FOR_nothing
;
7372 /* If OLDEQUIV is a pseudo with a MEM, get the real MEM
7373 and similarly for OLD.
7374 See comments in get_secondary_reload in reload.c. */
7375 /* If it is a pseudo that cannot be replaced with its
7376 equivalent MEM, we must fall back to reload_in, which
7377 will have all the necessary substitutions registered.
7378 Likewise for a pseudo that can't be replaced with its
7379 equivalent constant.
7381 Take extra care for subregs of such pseudos. Note that
7382 we cannot use reg_equiv_mem in this case because it is
7383 not in the right mode. */
7386 if (GET_CODE (tmp
) == SUBREG
)
7387 tmp
= SUBREG_REG (tmp
);
7389 && REGNO (tmp
) >= FIRST_PSEUDO_REGISTER
7390 && (reg_equiv_memory_loc (REGNO (tmp
)) != 0
7391 || reg_equiv_constant (REGNO (tmp
)) != 0))
7393 if (! reg_equiv_mem (REGNO (tmp
))
7394 || num_not_at_initial_offset
7395 || GET_CODE (oldequiv
) == SUBREG
)
7396 real_oldequiv
= rl
->in
;
7398 real_oldequiv
= reg_equiv_mem (REGNO (tmp
));
7402 if (GET_CODE (tmp
) == SUBREG
)
7403 tmp
= SUBREG_REG (tmp
);
7405 && REGNO (tmp
) >= FIRST_PSEUDO_REGISTER
7406 && (reg_equiv_memory_loc (REGNO (tmp
)) != 0
7407 || reg_equiv_constant (REGNO (tmp
)) != 0))
7409 if (! reg_equiv_mem (REGNO (tmp
))
7410 || num_not_at_initial_offset
7411 || GET_CODE (old
) == SUBREG
)
7414 real_old
= reg_equiv_mem (REGNO (tmp
));
7417 second_reload_reg
= rld
[secondary_reload
].reg_rtx
;
7418 if (rld
[secondary_reload
].secondary_in_reload
>= 0)
7420 int tertiary_reload
= rld
[secondary_reload
].secondary_in_reload
;
7422 third_reload_reg
= rld
[tertiary_reload
].reg_rtx
;
7423 tertiary_icode
= rld
[secondary_reload
].secondary_in_icode
;
7424 /* We'd have to add more code for quartary reloads. */
7425 gcc_assert (rld
[tertiary_reload
].secondary_in_reload
< 0);
7427 icode
= rl
->secondary_in_icode
;
7429 if ((old
!= oldequiv
&& ! rtx_equal_p (old
, oldequiv
))
7430 || (rl
->in
!= 0 && rl
->out
!= 0))
7432 secondary_reload_info sri
, sri2
;
7433 enum reg_class new_class
, new_t_class
;
7435 sri
.icode
= CODE_FOR_nothing
;
7436 sri
.prev_sri
= NULL
;
7438 = (enum reg_class
) targetm
.secondary_reload (1, real_oldequiv
,
7442 if (new_class
== NO_REGS
&& sri
.icode
== CODE_FOR_nothing
)
7443 second_reload_reg
= 0;
7444 else if (new_class
== NO_REGS
)
7446 if (reload_adjust_reg_for_icode (&second_reload_reg
,
7448 (enum insn_code
) sri
.icode
))
7450 icode
= (enum insn_code
) sri
.icode
;
7451 third_reload_reg
= 0;
7456 real_oldequiv
= real_old
;
7459 else if (sri
.icode
!= CODE_FOR_nothing
)
7460 /* We currently lack a way to express this in reloads. */
7464 sri2
.icode
= CODE_FOR_nothing
;
7465 sri2
.prev_sri
= &sri
;
7467 = (enum reg_class
) targetm
.secondary_reload (1, real_oldequiv
,
7470 if (new_t_class
== NO_REGS
&& sri2
.icode
== CODE_FOR_nothing
)
7472 if (reload_adjust_reg_for_temp (&second_reload_reg
,
7476 third_reload_reg
= 0;
7477 tertiary_icode
= (enum insn_code
) sri2
.icode
;
7482 real_oldequiv
= real_old
;
7485 else if (new_t_class
== NO_REGS
&& sri2
.icode
!= CODE_FOR_nothing
)
7487 rtx intermediate
= second_reload_reg
;
7489 if (reload_adjust_reg_for_temp (&intermediate
, NULL
,
7491 && reload_adjust_reg_for_icode (&third_reload_reg
, NULL
,
7495 second_reload_reg
= intermediate
;
7496 tertiary_icode
= (enum insn_code
) sri2
.icode
;
7501 real_oldequiv
= real_old
;
7504 else if (new_t_class
!= NO_REGS
&& sri2
.icode
== CODE_FOR_nothing
)
7506 rtx intermediate
= second_reload_reg
;
7508 if (reload_adjust_reg_for_temp (&intermediate
, NULL
,
7510 && reload_adjust_reg_for_temp (&third_reload_reg
, NULL
,
7513 second_reload_reg
= intermediate
;
7514 tertiary_icode
= (enum insn_code
) sri2
.icode
;
7519 real_oldequiv
= real_old
;
7524 /* This could be handled more intelligently too. */
7526 real_oldequiv
= real_old
;
7531 /* If we still need a secondary reload register, check
7532 to see if it is being used as a scratch or intermediate
7533 register and generate code appropriately. If we need
7534 a scratch register, use REAL_OLDEQUIV since the form of
7535 the insn may depend on the actual address if it is
7538 if (second_reload_reg
)
7540 if (icode
!= CODE_FOR_nothing
)
7542 /* We'd have to add extra code to handle this case. */
7543 gcc_assert (!third_reload_reg
);
7545 emit_insn (GEN_FCN (icode
) (reloadreg
, real_oldequiv
,
7546 second_reload_reg
));
7551 /* See if we need a scratch register to load the
7552 intermediate register (a tertiary reload). */
7553 if (tertiary_icode
!= CODE_FOR_nothing
)
7555 emit_insn ((GEN_FCN (tertiary_icode
)
7556 (second_reload_reg
, real_oldequiv
,
7557 third_reload_reg
)));
7559 else if (third_reload_reg
)
7561 gen_reload (third_reload_reg
, real_oldequiv
,
7564 gen_reload (second_reload_reg
, third_reload_reg
,
7569 gen_reload (second_reload_reg
, real_oldequiv
,
7573 oldequiv
= second_reload_reg
;
7578 if (! special
&& ! rtx_equal_p (reloadreg
, oldequiv
))
7580 rtx real_oldequiv
= oldequiv
;
7582 if ((REG_P (oldequiv
)
7583 && REGNO (oldequiv
) >= FIRST_PSEUDO_REGISTER
7584 && (reg_equiv_memory_loc (REGNO (oldequiv
)) != 0
7585 || reg_equiv_constant (REGNO (oldequiv
)) != 0))
7586 || (GET_CODE (oldequiv
) == SUBREG
7587 && REG_P (SUBREG_REG (oldequiv
))
7588 && (REGNO (SUBREG_REG (oldequiv
))
7589 >= FIRST_PSEUDO_REGISTER
)
7590 && ((reg_equiv_memory_loc (REGNO (SUBREG_REG (oldequiv
))) != 0)
7591 || (reg_equiv_constant (REGNO (SUBREG_REG (oldequiv
))) != 0)))
7592 || (CONSTANT_P (oldequiv
)
7593 && (targetm
.preferred_reload_class (oldequiv
,
7594 REGNO_REG_CLASS (REGNO (reloadreg
)))
7596 real_oldequiv
= rl
->in
;
7597 gen_reload (reloadreg
, real_oldequiv
, rl
->opnum
,
7601 if (cfun
->can_throw_non_call_exceptions
)
7602 copy_reg_eh_region_note_forward (insn
, get_insns (), NULL
);
7604 /* End this sequence. */
7605 *where
= get_insns ();
7608 /* Update reload_override_in so that delete_address_reloads_1
7609 can see the actual register usage. */
7611 reload_override_in
[j
] = oldequiv
;
7614 /* Generate insns to for the output reload RL, which is for the insn described
7615 by CHAIN and has the number J. */
7617 emit_output_reload_insns (struct insn_chain
*chain
, struct reload
*rl
,
7621 rtx insn
= chain
->insn
;
7624 enum machine_mode mode
;
7628 if (rl
->when_needed
== RELOAD_OTHER
)
7631 push_to_sequence (output_reload_insns
[rl
->opnum
]);
7633 rl_reg_rtx
= reload_reg_rtx_for_output
[j
];
7634 mode
= GET_MODE (rl_reg_rtx
);
7636 reloadreg
= rl_reg_rtx
;
7638 /* If we need two reload regs, set RELOADREG to the intermediate
7639 one, since it will be stored into OLD. We might need a secondary
7640 register only for an input reload, so check again here. */
7642 if (rl
->secondary_out_reload
>= 0)
7645 int secondary_reload
= rl
->secondary_out_reload
;
7646 int tertiary_reload
= rld
[secondary_reload
].secondary_out_reload
;
7648 if (REG_P (old
) && REGNO (old
) >= FIRST_PSEUDO_REGISTER
7649 && reg_equiv_mem (REGNO (old
)) != 0)
7650 real_old
= reg_equiv_mem (REGNO (old
));
7652 if (secondary_reload_class (0, rl
->rclass
, mode
, real_old
) != NO_REGS
)
7654 rtx second_reloadreg
= reloadreg
;
7655 reloadreg
= rld
[secondary_reload
].reg_rtx
;
7657 /* See if RELOADREG is to be used as a scratch register
7658 or as an intermediate register. */
7659 if (rl
->secondary_out_icode
!= CODE_FOR_nothing
)
7661 /* We'd have to add extra code to handle this case. */
7662 gcc_assert (tertiary_reload
< 0);
7664 emit_insn ((GEN_FCN (rl
->secondary_out_icode
)
7665 (real_old
, second_reloadreg
, reloadreg
)));
7670 /* See if we need both a scratch and intermediate reload
7673 enum insn_code tertiary_icode
7674 = rld
[secondary_reload
].secondary_out_icode
;
7676 /* We'd have to add more code for quartary reloads. */
7677 gcc_assert (tertiary_reload
< 0
7678 || rld
[tertiary_reload
].secondary_out_reload
< 0);
7680 if (GET_MODE (reloadreg
) != mode
)
7681 reloadreg
= reload_adjust_reg_for_mode (reloadreg
, mode
);
7683 if (tertiary_icode
!= CODE_FOR_nothing
)
7685 rtx third_reloadreg
= rld
[tertiary_reload
].reg_rtx
;
7687 /* Copy primary reload reg to secondary reload reg.
7688 (Note that these have been swapped above, then
7689 secondary reload reg to OLD using our insn.) */
7691 /* If REAL_OLD is a paradoxical SUBREG, remove it
7692 and try to put the opposite SUBREG on
7694 strip_paradoxical_subreg (&real_old
, &reloadreg
);
7696 gen_reload (reloadreg
, second_reloadreg
,
7697 rl
->opnum
, rl
->when_needed
);
7698 emit_insn ((GEN_FCN (tertiary_icode
)
7699 (real_old
, reloadreg
, third_reloadreg
)));
7705 /* Copy between the reload regs here and then to
7708 gen_reload (reloadreg
, second_reloadreg
,
7709 rl
->opnum
, rl
->when_needed
);
7710 if (tertiary_reload
>= 0)
7712 rtx third_reloadreg
= rld
[tertiary_reload
].reg_rtx
;
7714 gen_reload (third_reloadreg
, reloadreg
,
7715 rl
->opnum
, rl
->when_needed
);
7716 reloadreg
= third_reloadreg
;
7723 /* Output the last reload insn. */
7728 /* Don't output the last reload if OLD is not the dest of
7729 INSN and is in the src and is clobbered by INSN. */
7730 if (! flag_expensive_optimizations
7732 || !(set
= single_set (insn
))
7733 || rtx_equal_p (old
, SET_DEST (set
))
7734 || !reg_mentioned_p (old
, SET_SRC (set
))
7735 || !((REGNO (old
) < FIRST_PSEUDO_REGISTER
)
7736 && regno_clobbered_p (REGNO (old
), insn
, rl
->mode
, 0)))
7737 gen_reload (old
, reloadreg
, rl
->opnum
,
7741 /* Look at all insns we emitted, just to be safe. */
7742 for (p
= get_insns (); p
; p
= NEXT_INSN (p
))
7745 rtx pat
= PATTERN (p
);
7747 /* If this output reload doesn't come from a spill reg,
7748 clear any memory of reloaded copies of the pseudo reg.
7749 If this output reload comes from a spill reg,
7750 reg_has_output_reload will make this do nothing. */
7751 note_stores (pat
, forget_old_reloads_1
, NULL
);
7753 if (reg_mentioned_p (rl_reg_rtx
, pat
))
7755 rtx set
= single_set (insn
);
7756 if (reload_spill_index
[j
] < 0
7758 && SET_SRC (set
) == rl_reg_rtx
)
7760 int src
= REGNO (SET_SRC (set
));
7762 reload_spill_index
[j
] = src
;
7763 SET_HARD_REG_BIT (reg_is_output_reload
, src
);
7764 if (find_regno_note (insn
, REG_DEAD
, src
))
7765 SET_HARD_REG_BIT (reg_reloaded_died
, src
);
7767 if (HARD_REGISTER_P (rl_reg_rtx
))
7769 int s
= rl
->secondary_out_reload
;
7770 set
= single_set (p
);
7771 /* If this reload copies only to the secondary reload
7772 register, the secondary reload does the actual
7774 if (s
>= 0 && set
== NULL_RTX
)
7775 /* We can't tell what function the secondary reload
7776 has and where the actual store to the pseudo is
7777 made; leave new_spill_reg_store alone. */
7780 && SET_SRC (set
) == rl_reg_rtx
7781 && SET_DEST (set
) == rld
[s
].reg_rtx
)
7783 /* Usually the next instruction will be the
7784 secondary reload insn; if we can confirm
7785 that it is, setting new_spill_reg_store to
7786 that insn will allow an extra optimization. */
7787 rtx s_reg
= rld
[s
].reg_rtx
;
7788 rtx next
= NEXT_INSN (p
);
7789 rld
[s
].out
= rl
->out
;
7790 rld
[s
].out_reg
= rl
->out_reg
;
7791 set
= single_set (next
);
7792 if (set
&& SET_SRC (set
) == s_reg
7793 && reload_reg_rtx_reaches_end_p (s_reg
, s
))
7795 SET_HARD_REG_BIT (reg_is_output_reload
,
7797 new_spill_reg_store
[REGNO (s_reg
)] = next
;
7800 else if (reload_reg_rtx_reaches_end_p (rl_reg_rtx
, j
))
7801 new_spill_reg_store
[REGNO (rl_reg_rtx
)] = p
;
7806 if (rl
->when_needed
== RELOAD_OTHER
)
7808 emit_insn (other_output_reload_insns
[rl
->opnum
]);
7809 other_output_reload_insns
[rl
->opnum
] = get_insns ();
7812 output_reload_insns
[rl
->opnum
] = get_insns ();
7814 if (cfun
->can_throw_non_call_exceptions
)
7815 copy_reg_eh_region_note_forward (insn
, get_insns (), NULL
);
7820 /* Do input reloading for reload RL, which is for the insn described by CHAIN
7821 and has the number J. */
7823 do_input_reload (struct insn_chain
*chain
, struct reload
*rl
, int j
)
7825 rtx insn
= chain
->insn
;
7826 rtx old
= (rl
->in
&& MEM_P (rl
->in
)
7827 ? rl
->in_reg
: rl
->in
);
7828 rtx reg_rtx
= rl
->reg_rtx
;
7832 enum machine_mode mode
;
7834 /* Determine the mode to reload in.
7835 This is very tricky because we have three to choose from.
7836 There is the mode the insn operand wants (rl->inmode).
7837 There is the mode of the reload register RELOADREG.
7838 There is the intrinsic mode of the operand, which we could find
7839 by stripping some SUBREGs.
7840 It turns out that RELOADREG's mode is irrelevant:
7841 we can change that arbitrarily.
7843 Consider (SUBREG:SI foo:QI) as an operand that must be SImode;
7844 then the reload reg may not support QImode moves, so use SImode.
7845 If foo is in memory due to spilling a pseudo reg, this is safe,
7846 because the QImode value is in the least significant part of a
7847 slot big enough for a SImode. If foo is some other sort of
7848 memory reference, then it is impossible to reload this case,
7849 so previous passes had better make sure this never happens.
7851 Then consider a one-word union which has SImode and one of its
7852 members is a float, being fetched as (SUBREG:SF union:SI).
7853 We must fetch that as SFmode because we could be loading into
7854 a float-only register. In this case OLD's mode is correct.
7856 Consider an immediate integer: it has VOIDmode. Here we need
7857 to get a mode from something else.
7859 In some cases, there is a fourth mode, the operand's
7860 containing mode. If the insn specifies a containing mode for
7861 this operand, it overrides all others.
7863 I am not sure whether the algorithm here is always right,
7864 but it does the right things in those cases. */
7866 mode
= GET_MODE (old
);
7867 if (mode
== VOIDmode
)
7870 /* We cannot use gen_lowpart_common since it can do the wrong thing
7871 when REG_RTX has a multi-word mode. Note that REG_RTX must
7872 always be a REG here. */
7873 if (GET_MODE (reg_rtx
) != mode
)
7874 reg_rtx
= reload_adjust_reg_for_mode (reg_rtx
, mode
);
7876 reload_reg_rtx_for_input
[j
] = reg_rtx
;
7879 /* AUTO_INC reloads need to be handled even if inherited. We got an
7880 AUTO_INC reload if reload_out is set but reload_out_reg isn't. */
7881 && (! reload_inherited
[j
] || (rl
->out
&& ! rl
->out_reg
))
7882 && ! rtx_equal_p (reg_rtx
, old
)
7884 emit_input_reload_insns (chain
, rld
+ j
, old
, j
);
7886 /* When inheriting a wider reload, we have a MEM in rl->in,
7887 e.g. inheriting a SImode output reload for
7888 (mem:HI (plus:SI (reg:SI 14 fp) (const_int 10))) */
7889 if (optimize
&& reload_inherited
[j
] && rl
->in
7891 && MEM_P (rl
->in_reg
)
7892 && reload_spill_index
[j
] >= 0
7893 && TEST_HARD_REG_BIT (reg_reloaded_valid
, reload_spill_index
[j
]))
7894 rl
->in
= regno_reg_rtx
[reg_reloaded_contents
[reload_spill_index
[j
]]];
7896 /* If we are reloading a register that was recently stored in with an
7897 output-reload, see if we can prove there was
7898 actually no need to store the old value in it. */
7901 && (reload_inherited
[j
] || reload_override_in
[j
])
7904 && spill_reg_store
[REGNO (reg_rtx
)] != 0
7906 /* There doesn't seem to be any reason to restrict this to pseudos
7907 and doing so loses in the case where we are copying from a
7908 register of the wrong class. */
7909 && !HARD_REGISTER_P (spill_reg_stored_to
[REGNO (reg_rtx
)])
7911 /* The insn might have already some references to stackslots
7912 replaced by MEMs, while reload_out_reg still names the
7914 && (dead_or_set_p (insn
, spill_reg_stored_to
[REGNO (reg_rtx
)])
7915 || rtx_equal_p (spill_reg_stored_to
[REGNO (reg_rtx
)], rl
->out_reg
)))
7916 delete_output_reload (insn
, j
, REGNO (reg_rtx
), reg_rtx
);
7919 /* Do output reloading for reload RL, which is for the insn described by
7920 CHAIN and has the number J.
7921 ??? At some point we need to support handling output reloads of
7922 JUMP_INSNs or insns that set cc0. */
7924 do_output_reload (struct insn_chain
*chain
, struct reload
*rl
, int j
)
7927 rtx insn
= chain
->insn
;
7928 /* If this is an output reload that stores something that is
7929 not loaded in this same reload, see if we can eliminate a previous
7931 rtx pseudo
= rl
->out_reg
;
7932 rtx reg_rtx
= rl
->reg_rtx
;
7934 if (rl
->out
&& reg_rtx
)
7936 enum machine_mode mode
;
7938 /* Determine the mode to reload in.
7939 See comments above (for input reloading). */
7940 mode
= GET_MODE (rl
->out
);
7941 if (mode
== VOIDmode
)
7943 /* VOIDmode should never happen for an output. */
7944 if (asm_noperands (PATTERN (insn
)) < 0)
7945 /* It's the compiler's fault. */
7946 fatal_insn ("VOIDmode on an output", insn
);
7947 error_for_asm (insn
, "output operand is constant in %<asm%>");
7948 /* Prevent crash--use something we know is valid. */
7950 rl
->out
= gen_rtx_REG (mode
, REGNO (reg_rtx
));
7952 if (GET_MODE (reg_rtx
) != mode
)
7953 reg_rtx
= reload_adjust_reg_for_mode (reg_rtx
, mode
);
7955 reload_reg_rtx_for_output
[j
] = reg_rtx
;
7960 && ! rtx_equal_p (rl
->in_reg
, pseudo
)
7961 && REGNO (pseudo
) >= FIRST_PSEUDO_REGISTER
7962 && reg_last_reload_reg
[REGNO (pseudo
)])
7964 int pseudo_no
= REGNO (pseudo
);
7965 int last_regno
= REGNO (reg_last_reload_reg
[pseudo_no
]);
7967 /* We don't need to test full validity of last_regno for
7968 inherit here; we only want to know if the store actually
7969 matches the pseudo. */
7970 if (TEST_HARD_REG_BIT (reg_reloaded_valid
, last_regno
)
7971 && reg_reloaded_contents
[last_regno
] == pseudo_no
7972 && spill_reg_store
[last_regno
]
7973 && rtx_equal_p (pseudo
, spill_reg_stored_to
[last_regno
]))
7974 delete_output_reload (insn
, j
, last_regno
, reg_rtx
);
7980 || rtx_equal_p (old
, reg_rtx
))
7983 /* An output operand that dies right away does need a reload,
7984 but need not be copied from it. Show the new location in the
7986 if ((REG_P (old
) || GET_CODE (old
) == SCRATCH
)
7987 && (note
= find_reg_note (insn
, REG_UNUSED
, old
)) != 0)
7989 XEXP (note
, 0) = reg_rtx
;
7992 /* Likewise for a SUBREG of an operand that dies. */
7993 else if (GET_CODE (old
) == SUBREG
7994 && REG_P (SUBREG_REG (old
))
7995 && 0 != (note
= find_reg_note (insn
, REG_UNUSED
,
7998 XEXP (note
, 0) = gen_lowpart_common (GET_MODE (old
), reg_rtx
);
8001 else if (GET_CODE (old
) == SCRATCH
)
8002 /* If we aren't optimizing, there won't be a REG_UNUSED note,
8003 but we don't want to make an output reload. */
8006 /* If is a JUMP_INSN, we can't support output reloads yet. */
8007 gcc_assert (NONJUMP_INSN_P (insn
));
8009 emit_output_reload_insns (chain
, rld
+ j
, j
);
8012 /* A reload copies values of MODE from register SRC to register DEST.
8013 Return true if it can be treated for inheritance purposes like a
8014 group of reloads, each one reloading a single hard register. The
8015 caller has already checked that (reg:MODE SRC) and (reg:MODE DEST)
8016 occupy the same number of hard registers. */
8019 inherit_piecemeal_p (int dest ATTRIBUTE_UNUSED
,
8020 int src ATTRIBUTE_UNUSED
,
8021 enum machine_mode mode ATTRIBUTE_UNUSED
)
8023 #ifdef CANNOT_CHANGE_MODE_CLASS
8024 return (!REG_CANNOT_CHANGE_MODE_P (dest
, mode
, reg_raw_mode
[dest
])
8025 && !REG_CANNOT_CHANGE_MODE_P (src
, mode
, reg_raw_mode
[src
]));
8031 /* Output insns to reload values in and out of the chosen reload regs. */
8034 emit_reload_insns (struct insn_chain
*chain
)
8036 rtx insn
= chain
->insn
;
8040 CLEAR_HARD_REG_SET (reg_reloaded_died
);
8042 for (j
= 0; j
< reload_n_operands
; j
++)
8043 input_reload_insns
[j
] = input_address_reload_insns
[j
]
8044 = inpaddr_address_reload_insns
[j
]
8045 = output_reload_insns
[j
] = output_address_reload_insns
[j
]
8046 = outaddr_address_reload_insns
[j
]
8047 = other_output_reload_insns
[j
] = 0;
8048 other_input_address_reload_insns
= 0;
8049 other_input_reload_insns
= 0;
8050 operand_reload_insns
= 0;
8051 other_operand_reload_insns
= 0;
8053 /* Dump reloads into the dump file. */
8056 fprintf (dump_file
, "\nReloads for insn # %d\n", INSN_UID (insn
));
8057 debug_reload_to_stream (dump_file
);
8060 for (j
= 0; j
< n_reloads
; j
++)
8061 if (rld
[j
].reg_rtx
&& HARD_REGISTER_P (rld
[j
].reg_rtx
))
8065 for (i
= REGNO (rld
[j
].reg_rtx
); i
< END_REGNO (rld
[j
].reg_rtx
); i
++)
8066 new_spill_reg_store
[i
] = 0;
8069 /* Now output the instructions to copy the data into and out of the
8070 reload registers. Do these in the order that the reloads were reported,
8071 since reloads of base and index registers precede reloads of operands
8072 and the operands may need the base and index registers reloaded. */
8074 for (j
= 0; j
< n_reloads
; j
++)
8076 do_input_reload (chain
, rld
+ j
, j
);
8077 do_output_reload (chain
, rld
+ j
, j
);
8080 /* Now write all the insns we made for reloads in the order expected by
8081 the allocation functions. Prior to the insn being reloaded, we write
8082 the following reloads:
8084 RELOAD_FOR_OTHER_ADDRESS reloads for input addresses.
8086 RELOAD_OTHER reloads.
8088 For each operand, any RELOAD_FOR_INPADDR_ADDRESS reloads followed
8089 by any RELOAD_FOR_INPUT_ADDRESS reloads followed by the
8090 RELOAD_FOR_INPUT reload for the operand.
8092 RELOAD_FOR_OPADDR_ADDRS reloads.
8094 RELOAD_FOR_OPERAND_ADDRESS reloads.
8096 After the insn being reloaded, we write the following:
8098 For each operand, any RELOAD_FOR_OUTADDR_ADDRESS reloads followed
8099 by any RELOAD_FOR_OUTPUT_ADDRESS reload followed by the
8100 RELOAD_FOR_OUTPUT reload, followed by any RELOAD_OTHER output
8101 reloads for the operand. The RELOAD_OTHER output reloads are
8102 output in descending order by reload number. */
8104 emit_insn_before (other_input_address_reload_insns
, insn
);
8105 emit_insn_before (other_input_reload_insns
, insn
);
8107 for (j
= 0; j
< reload_n_operands
; j
++)
8109 emit_insn_before (inpaddr_address_reload_insns
[j
], insn
);
8110 emit_insn_before (input_address_reload_insns
[j
], insn
);
8111 emit_insn_before (input_reload_insns
[j
], insn
);
8114 emit_insn_before (other_operand_reload_insns
, insn
);
8115 emit_insn_before (operand_reload_insns
, insn
);
8117 for (j
= 0; j
< reload_n_operands
; j
++)
8119 rtx x
= emit_insn_after (outaddr_address_reload_insns
[j
], insn
);
8120 x
= emit_insn_after (output_address_reload_insns
[j
], x
);
8121 x
= emit_insn_after (output_reload_insns
[j
], x
);
8122 emit_insn_after (other_output_reload_insns
[j
], x
);
8125 /* For all the spill regs newly reloaded in this instruction,
8126 record what they were reloaded from, so subsequent instructions
8127 can inherit the reloads.
8129 Update spill_reg_store for the reloads of this insn.
8130 Copy the elements that were updated in the loop above. */
8132 for (j
= 0; j
< n_reloads
; j
++)
8134 int r
= reload_order
[j
];
8135 int i
= reload_spill_index
[r
];
8137 /* If this is a non-inherited input reload from a pseudo, we must
8138 clear any memory of a previous store to the same pseudo. Only do
8139 something if there will not be an output reload for the pseudo
8141 if (rld
[r
].in_reg
!= 0
8142 && ! (reload_inherited
[r
] || reload_override_in
[r
]))
8144 rtx reg
= rld
[r
].in_reg
;
8146 if (GET_CODE (reg
) == SUBREG
)
8147 reg
= SUBREG_REG (reg
);
8150 && REGNO (reg
) >= FIRST_PSEUDO_REGISTER
8151 && !REGNO_REG_SET_P (®_has_output_reload
, REGNO (reg
)))
8153 int nregno
= REGNO (reg
);
8155 if (reg_last_reload_reg
[nregno
])
8157 int last_regno
= REGNO (reg_last_reload_reg
[nregno
]);
8159 if (reg_reloaded_contents
[last_regno
] == nregno
)
8160 spill_reg_store
[last_regno
] = 0;
8165 /* I is nonneg if this reload used a register.
8166 If rld[r].reg_rtx is 0, this is an optional reload
8167 that we opted to ignore. */
8169 if (i
>= 0 && rld
[r
].reg_rtx
!= 0)
8171 int nr
= hard_regno_nregs
[i
][GET_MODE (rld
[r
].reg_rtx
)];
8174 /* For a multi register reload, we need to check if all or part
8175 of the value lives to the end. */
8176 for (k
= 0; k
< nr
; k
++)
8177 if (reload_reg_reaches_end_p (i
+ k
, r
))
8178 CLEAR_HARD_REG_BIT (reg_reloaded_valid
, i
+ k
);
8180 /* Maybe the spill reg contains a copy of reload_out. */
8182 && (REG_P (rld
[r
].out
)
8184 ? REG_P (rld
[r
].out_reg
)
8185 /* The reload value is an auto-modification of
8186 some kind. For PRE_INC, POST_INC, PRE_DEC
8187 and POST_DEC, we record an equivalence
8188 between the reload register and the operand
8189 on the optimistic assumption that we can make
8190 the equivalence hold. reload_as_needed must
8191 then either make it hold or invalidate the
8194 PRE_MODIFY and POST_MODIFY addresses are reloaded
8195 somewhat differently, and allowing them here leads
8197 : (GET_CODE (rld
[r
].out
) != POST_MODIFY
8198 && GET_CODE (rld
[r
].out
) != PRE_MODIFY
))))
8202 reg
= reload_reg_rtx_for_output
[r
];
8203 if (reload_reg_rtx_reaches_end_p (reg
, r
))
8205 enum machine_mode mode
= GET_MODE (reg
);
8206 int regno
= REGNO (reg
);
8207 int nregs
= hard_regno_nregs
[regno
][mode
];
8208 rtx out
= (REG_P (rld
[r
].out
)
8212 /* AUTO_INC */ : XEXP (rld
[r
].in_reg
, 0));
8213 int out_regno
= REGNO (out
);
8214 int out_nregs
= (!HARD_REGISTER_NUM_P (out_regno
) ? 1
8215 : hard_regno_nregs
[out_regno
][mode
]);
8218 spill_reg_store
[regno
] = new_spill_reg_store
[regno
];
8219 spill_reg_stored_to
[regno
] = out
;
8220 reg_last_reload_reg
[out_regno
] = reg
;
8222 piecemeal
= (HARD_REGISTER_NUM_P (out_regno
)
8223 && nregs
== out_nregs
8224 && inherit_piecemeal_p (out_regno
, regno
, mode
));
8226 /* If OUT_REGNO is a hard register, it may occupy more than
8227 one register. If it does, say what is in the
8228 rest of the registers assuming that both registers
8229 agree on how many words the object takes. If not,
8230 invalidate the subsequent registers. */
8232 if (HARD_REGISTER_NUM_P (out_regno
))
8233 for (k
= 1; k
< out_nregs
; k
++)
8234 reg_last_reload_reg
[out_regno
+ k
]
8235 = (piecemeal
? regno_reg_rtx
[regno
+ k
] : 0);
8237 /* Now do the inverse operation. */
8238 for (k
= 0; k
< nregs
; k
++)
8240 CLEAR_HARD_REG_BIT (reg_reloaded_dead
, regno
+ k
);
8241 reg_reloaded_contents
[regno
+ k
]
8242 = (!HARD_REGISTER_NUM_P (out_regno
) || !piecemeal
8245 reg_reloaded_insn
[regno
+ k
] = insn
;
8246 SET_HARD_REG_BIT (reg_reloaded_valid
, regno
+ k
);
8247 if (HARD_REGNO_CALL_PART_CLOBBERED (regno
+ k
, mode
))
8248 SET_HARD_REG_BIT (reg_reloaded_call_part_clobbered
,
8251 CLEAR_HARD_REG_BIT (reg_reloaded_call_part_clobbered
,
8256 /* Maybe the spill reg contains a copy of reload_in. Only do
8257 something if there will not be an output reload for
8258 the register being reloaded. */
8259 else if (rld
[r
].out_reg
== 0
8261 && ((REG_P (rld
[r
].in
)
8262 && !HARD_REGISTER_P (rld
[r
].in
)
8263 && !REGNO_REG_SET_P (®_has_output_reload
,
8265 || (REG_P (rld
[r
].in_reg
)
8266 && !REGNO_REG_SET_P (®_has_output_reload
,
8267 REGNO (rld
[r
].in_reg
))))
8268 && !reg_set_p (reload_reg_rtx_for_input
[r
], PATTERN (insn
)))
8272 reg
= reload_reg_rtx_for_input
[r
];
8273 if (reload_reg_rtx_reaches_end_p (reg
, r
))
8275 enum machine_mode mode
;
8283 mode
= GET_MODE (reg
);
8284 regno
= REGNO (reg
);
8285 nregs
= hard_regno_nregs
[regno
][mode
];
8286 if (REG_P (rld
[r
].in
)
8287 && REGNO (rld
[r
].in
) >= FIRST_PSEUDO_REGISTER
)
8289 else if (REG_P (rld
[r
].in_reg
))
8292 in
= XEXP (rld
[r
].in_reg
, 0);
8293 in_regno
= REGNO (in
);
8295 in_nregs
= (!HARD_REGISTER_NUM_P (in_regno
) ? 1
8296 : hard_regno_nregs
[in_regno
][mode
]);
8298 reg_last_reload_reg
[in_regno
] = reg
;
8300 piecemeal
= (HARD_REGISTER_NUM_P (in_regno
)
8301 && nregs
== in_nregs
8302 && inherit_piecemeal_p (regno
, in_regno
, mode
));
8304 if (HARD_REGISTER_NUM_P (in_regno
))
8305 for (k
= 1; k
< in_nregs
; k
++)
8306 reg_last_reload_reg
[in_regno
+ k
]
8307 = (piecemeal
? regno_reg_rtx
[regno
+ k
] : 0);
8309 /* Unless we inherited this reload, show we haven't
8310 recently done a store.
8311 Previous stores of inherited auto_inc expressions
8312 also have to be discarded. */
8313 if (! reload_inherited
[r
]
8314 || (rld
[r
].out
&& ! rld
[r
].out_reg
))
8315 spill_reg_store
[regno
] = 0;
8317 for (k
= 0; k
< nregs
; k
++)
8319 CLEAR_HARD_REG_BIT (reg_reloaded_dead
, regno
+ k
);
8320 reg_reloaded_contents
[regno
+ k
]
8321 = (!HARD_REGISTER_NUM_P (in_regno
) || !piecemeal
8324 reg_reloaded_insn
[regno
+ k
] = insn
;
8325 SET_HARD_REG_BIT (reg_reloaded_valid
, regno
+ k
);
8326 if (HARD_REGNO_CALL_PART_CLOBBERED (regno
+ k
, mode
))
8327 SET_HARD_REG_BIT (reg_reloaded_call_part_clobbered
,
8330 CLEAR_HARD_REG_BIT (reg_reloaded_call_part_clobbered
,
8337 /* The following if-statement was #if 0'd in 1.34 (or before...).
8338 It's reenabled in 1.35 because supposedly nothing else
8339 deals with this problem. */
8341 /* If a register gets output-reloaded from a non-spill register,
8342 that invalidates any previous reloaded copy of it.
8343 But forget_old_reloads_1 won't get to see it, because
8344 it thinks only about the original insn. So invalidate it here.
8345 Also do the same thing for RELOAD_OTHER constraints where the
8346 output is discarded. */
8348 && ((rld
[r
].out
!= 0
8349 && (REG_P (rld
[r
].out
)
8350 || (MEM_P (rld
[r
].out
)
8351 && REG_P (rld
[r
].out_reg
))))
8352 || (rld
[r
].out
== 0 && rld
[r
].out_reg
8353 && REG_P (rld
[r
].out_reg
))))
8355 rtx out
= ((rld
[r
].out
&& REG_P (rld
[r
].out
))
8356 ? rld
[r
].out
: rld
[r
].out_reg
);
8357 int out_regno
= REGNO (out
);
8358 enum machine_mode mode
= GET_MODE (out
);
8360 /* REG_RTX is now set or clobbered by the main instruction.
8361 As the comment above explains, forget_old_reloads_1 only
8362 sees the original instruction, and there is no guarantee
8363 that the original instruction also clobbered REG_RTX.
8364 For example, if find_reloads sees that the input side of
8365 a matched operand pair dies in this instruction, it may
8366 use the input register as the reload register.
8368 Calling forget_old_reloads_1 is a waste of effort if
8369 REG_RTX is also the output register.
8371 If we know that REG_RTX holds the value of a pseudo
8372 register, the code after the call will record that fact. */
8373 if (rld
[r
].reg_rtx
&& rld
[r
].reg_rtx
!= out
)
8374 forget_old_reloads_1 (rld
[r
].reg_rtx
, NULL_RTX
, NULL
);
8376 if (!HARD_REGISTER_NUM_P (out_regno
))
8378 rtx src_reg
, store_insn
= NULL_RTX
;
8380 reg_last_reload_reg
[out_regno
] = 0;
8382 /* If we can find a hard register that is stored, record
8383 the storing insn so that we may delete this insn with
8384 delete_output_reload. */
8385 src_reg
= reload_reg_rtx_for_output
[r
];
8389 if (reload_reg_rtx_reaches_end_p (src_reg
, r
))
8390 store_insn
= new_spill_reg_store
[REGNO (src_reg
)];
8396 /* If this is an optional reload, try to find the
8397 source reg from an input reload. */
8398 rtx set
= single_set (insn
);
8399 if (set
&& SET_DEST (set
) == rld
[r
].out
)
8403 src_reg
= SET_SRC (set
);
8405 for (k
= 0; k
< n_reloads
; k
++)
8407 if (rld
[k
].in
== src_reg
)
8409 src_reg
= reload_reg_rtx_for_input
[k
];
8415 if (src_reg
&& REG_P (src_reg
)
8416 && REGNO (src_reg
) < FIRST_PSEUDO_REGISTER
)
8418 int src_regno
, src_nregs
, k
;
8421 gcc_assert (GET_MODE (src_reg
) == mode
);
8422 src_regno
= REGNO (src_reg
);
8423 src_nregs
= hard_regno_nregs
[src_regno
][mode
];
8424 /* The place where to find a death note varies with
8425 PRESERVE_DEATH_INFO_REGNO_P . The condition is not
8426 necessarily checked exactly in the code that moves
8427 notes, so just check both locations. */
8428 note
= find_regno_note (insn
, REG_DEAD
, src_regno
);
8429 if (! note
&& store_insn
)
8430 note
= find_regno_note (store_insn
, REG_DEAD
, src_regno
);
8431 for (k
= 0; k
< src_nregs
; k
++)
8433 spill_reg_store
[src_regno
+ k
] = store_insn
;
8434 spill_reg_stored_to
[src_regno
+ k
] = out
;
8435 reg_reloaded_contents
[src_regno
+ k
] = out_regno
;
8436 reg_reloaded_insn
[src_regno
+ k
] = store_insn
;
8437 CLEAR_HARD_REG_BIT (reg_reloaded_dead
, src_regno
+ k
);
8438 SET_HARD_REG_BIT (reg_reloaded_valid
, src_regno
+ k
);
8439 if (HARD_REGNO_CALL_PART_CLOBBERED (src_regno
+ k
,
8441 SET_HARD_REG_BIT (reg_reloaded_call_part_clobbered
,
8444 CLEAR_HARD_REG_BIT (reg_reloaded_call_part_clobbered
,
8446 SET_HARD_REG_BIT (reg_is_output_reload
, src_regno
+ k
);
8448 SET_HARD_REG_BIT (reg_reloaded_died
, src_regno
);
8450 CLEAR_HARD_REG_BIT (reg_reloaded_died
, src_regno
);
8452 reg_last_reload_reg
[out_regno
] = src_reg
;
8453 /* We have to set reg_has_output_reload here, or else
8454 forget_old_reloads_1 will clear reg_last_reload_reg
8456 SET_REGNO_REG_SET (®_has_output_reload
,
8462 int k
, out_nregs
= hard_regno_nregs
[out_regno
][mode
];
8464 for (k
= 0; k
< out_nregs
; k
++)
8465 reg_last_reload_reg
[out_regno
+ k
] = 0;
8469 IOR_HARD_REG_SET (reg_reloaded_dead
, reg_reloaded_died
);
8472 /* Go through the motions to emit INSN and test if it is strictly valid.
8473 Return the emitted insn if valid, else return NULL. */
8476 emit_insn_if_valid_for_reload (rtx insn
)
8478 rtx last
= get_last_insn ();
8481 insn
= emit_insn (insn
);
8482 code
= recog_memoized (insn
);
8486 extract_insn (insn
);
8487 /* We want constrain operands to treat this insn strictly in its
8488 validity determination, i.e., the way it would after reload has
8490 if (constrain_operands (1))
8494 delete_insns_since (last
);
8498 /* Emit code to perform a reload from IN (which may be a reload register) to
8499 OUT (which may also be a reload register). IN or OUT is from operand
8500 OPNUM with reload type TYPE.
8502 Returns first insn emitted. */
8505 gen_reload (rtx out
, rtx in
, int opnum
, enum reload_type type
)
8507 rtx last
= get_last_insn ();
8509 #ifdef SECONDARY_MEMORY_NEEDED
8513 /* If IN is a paradoxical SUBREG, remove it and try to put the
8514 opposite SUBREG on OUT. Likewise for a paradoxical SUBREG on OUT. */
8515 if (!strip_paradoxical_subreg (&in
, &out
))
8516 strip_paradoxical_subreg (&out
, &in
);
8518 /* How to do this reload can get quite tricky. Normally, we are being
8519 asked to reload a simple operand, such as a MEM, a constant, or a pseudo
8520 register that didn't get a hard register. In that case we can just
8521 call emit_move_insn.
8523 We can also be asked to reload a PLUS that adds a register or a MEM to
8524 another register, constant or MEM. This can occur during frame pointer
8525 elimination and while reloading addresses. This case is handled by
8526 trying to emit a single insn to perform the add. If it is not valid,
8527 we use a two insn sequence.
8529 Or we can be asked to reload an unary operand that was a fragment of
8530 an addressing mode, into a register. If it isn't recognized as-is,
8531 we try making the unop operand and the reload-register the same:
8532 (set reg:X (unop:X expr:Y))
8533 -> (set reg:Y expr:Y) (set reg:X (unop:X reg:Y)).
8535 Finally, we could be called to handle an 'o' constraint by putting
8536 an address into a register. In that case, we first try to do this
8537 with a named pattern of "reload_load_address". If no such pattern
8538 exists, we just emit a SET insn and hope for the best (it will normally
8539 be valid on machines that use 'o').
8541 This entire process is made complex because reload will never
8542 process the insns we generate here and so we must ensure that
8543 they will fit their constraints and also by the fact that parts of
8544 IN might be being reloaded separately and replaced with spill registers.
8545 Because of this, we are, in some sense, just guessing the right approach
8546 here. The one listed above seems to work.
8548 ??? At some point, this whole thing needs to be rethought. */
8550 if (GET_CODE (in
) == PLUS
8551 && (REG_P (XEXP (in
, 0))
8552 || GET_CODE (XEXP (in
, 0)) == SUBREG
8553 || MEM_P (XEXP (in
, 0)))
8554 && (REG_P (XEXP (in
, 1))
8555 || GET_CODE (XEXP (in
, 1)) == SUBREG
8556 || CONSTANT_P (XEXP (in
, 1))
8557 || MEM_P (XEXP (in
, 1))))
8559 /* We need to compute the sum of a register or a MEM and another
8560 register, constant, or MEM, and put it into the reload
8561 register. The best possible way of doing this is if the machine
8562 has a three-operand ADD insn that accepts the required operands.
8564 The simplest approach is to try to generate such an insn and see if it
8565 is recognized and matches its constraints. If so, it can be used.
8567 It might be better not to actually emit the insn unless it is valid,
8568 but we need to pass the insn as an operand to `recog' and
8569 `extract_insn' and it is simpler to emit and then delete the insn if
8570 not valid than to dummy things up. */
8572 rtx op0
, op1
, tem
, insn
;
8573 enum insn_code code
;
8575 op0
= find_replacement (&XEXP (in
, 0));
8576 op1
= find_replacement (&XEXP (in
, 1));
8578 /* Since constraint checking is strict, commutativity won't be
8579 checked, so we need to do that here to avoid spurious failure
8580 if the add instruction is two-address and the second operand
8581 of the add is the same as the reload reg, which is frequently
8582 the case. If the insn would be A = B + A, rearrange it so
8583 it will be A = A + B as constrain_operands expects. */
8585 if (REG_P (XEXP (in
, 1))
8586 && REGNO (out
) == REGNO (XEXP (in
, 1)))
8587 tem
= op0
, op0
= op1
, op1
= tem
;
8589 if (op0
!= XEXP (in
, 0) || op1
!= XEXP (in
, 1))
8590 in
= gen_rtx_PLUS (GET_MODE (in
), op0
, op1
);
8592 insn
= emit_insn_if_valid_for_reload (gen_rtx_SET (VOIDmode
, out
, in
));
8596 /* If that failed, we must use a conservative two-insn sequence.
8598 Use a move to copy one operand into the reload register. Prefer
8599 to reload a constant, MEM or pseudo since the move patterns can
8600 handle an arbitrary operand. If OP1 is not a constant, MEM or
8601 pseudo and OP1 is not a valid operand for an add instruction, then
8604 After reloading one of the operands into the reload register, add
8605 the reload register to the output register.
8607 If there is another way to do this for a specific machine, a
8608 DEFINE_PEEPHOLE should be specified that recognizes the sequence
8611 code
= optab_handler (add_optab
, GET_MODE (out
));
8613 if (CONSTANT_P (op1
) || MEM_P (op1
) || GET_CODE (op1
) == SUBREG
8615 && REGNO (op1
) >= FIRST_PSEUDO_REGISTER
)
8616 || (code
!= CODE_FOR_nothing
8617 && !insn_operand_matches (code
, 2, op1
)))
8618 tem
= op0
, op0
= op1
, op1
= tem
;
8620 gen_reload (out
, op0
, opnum
, type
);
8622 /* If OP0 and OP1 are the same, we can use OUT for OP1.
8623 This fixes a problem on the 32K where the stack pointer cannot
8624 be used as an operand of an add insn. */
8626 if (rtx_equal_p (op0
, op1
))
8629 insn
= emit_insn_if_valid_for_reload (gen_add2_insn (out
, op1
));
8632 /* Add a REG_EQUIV note so that find_equiv_reg can find it. */
8633 set_dst_reg_note (insn
, REG_EQUIV
, in
, out
);
8637 /* If that failed, copy the address register to the reload register.
8638 Then add the constant to the reload register. */
8640 gcc_assert (!reg_overlap_mentioned_p (out
, op0
));
8641 gen_reload (out
, op1
, opnum
, type
);
8642 insn
= emit_insn (gen_add2_insn (out
, op0
));
8643 set_dst_reg_note (insn
, REG_EQUIV
, in
, out
);
8646 #ifdef SECONDARY_MEMORY_NEEDED
8647 /* If we need a memory location to do the move, do it that way. */
8648 else if ((tem1
= replaced_subreg (in
), tem2
= replaced_subreg (out
),
8649 (REG_P (tem1
) && REG_P (tem2
)))
8650 && REGNO (tem1
) < FIRST_PSEUDO_REGISTER
8651 && REGNO (tem2
) < FIRST_PSEUDO_REGISTER
8652 && SECONDARY_MEMORY_NEEDED (REGNO_REG_CLASS (REGNO (tem1
)),
8653 REGNO_REG_CLASS (REGNO (tem2
)),
8656 /* Get the memory to use and rewrite both registers to its mode. */
8657 rtx loc
= get_secondary_mem (in
, GET_MODE (out
), opnum
, type
);
8659 if (GET_MODE (loc
) != GET_MODE (out
))
8660 out
= gen_rtx_REG (GET_MODE (loc
), reg_or_subregno (out
));
8662 if (GET_MODE (loc
) != GET_MODE (in
))
8663 in
= gen_rtx_REG (GET_MODE (loc
), reg_or_subregno (in
));
8665 gen_reload (loc
, in
, opnum
, type
);
8666 gen_reload (out
, loc
, opnum
, type
);
8669 else if (REG_P (out
) && UNARY_P (in
))
8676 op1
= find_replacement (&XEXP (in
, 0));
8677 if (op1
!= XEXP (in
, 0))
8678 in
= gen_rtx_fmt_e (GET_CODE (in
), GET_MODE (in
), op1
);
8680 /* First, try a plain SET. */
8681 set
= emit_insn_if_valid_for_reload (gen_rtx_SET (VOIDmode
, out
, in
));
8685 /* If that failed, move the inner operand to the reload
8686 register, and try the same unop with the inner expression
8687 replaced with the reload register. */
8689 if (GET_MODE (op1
) != GET_MODE (out
))
8690 out_moded
= gen_rtx_REG (GET_MODE (op1
), REGNO (out
));
8694 gen_reload (out_moded
, op1
, opnum
, type
);
8697 = gen_rtx_SET (VOIDmode
, out
,
8698 gen_rtx_fmt_e (GET_CODE (in
), GET_MODE (in
),
8700 insn
= emit_insn_if_valid_for_reload (insn
);
8703 set_unique_reg_note (insn
, REG_EQUIV
, in
);
8707 fatal_insn ("failure trying to reload:", set
);
8709 /* If IN is a simple operand, use gen_move_insn. */
8710 else if (OBJECT_P (in
) || GET_CODE (in
) == SUBREG
)
8712 tem
= emit_insn (gen_move_insn (out
, in
));
8713 /* IN may contain a LABEL_REF, if so add a REG_LABEL_OPERAND note. */
8714 mark_jump_label (in
, tem
, 0);
8717 #ifdef HAVE_reload_load_address
8718 else if (HAVE_reload_load_address
)
8719 emit_insn (gen_reload_load_address (out
, in
));
8722 /* Otherwise, just write (set OUT IN) and hope for the best. */
8724 emit_insn (gen_rtx_SET (VOIDmode
, out
, in
));
8726 /* Return the first insn emitted.
8727 We can not just return get_last_insn, because there may have
8728 been multiple instructions emitted. Also note that gen_move_insn may
8729 emit more than one insn itself, so we can not assume that there is one
8730 insn emitted per emit_insn_before call. */
8732 return last
? NEXT_INSN (last
) : get_insns ();
8735 /* Delete a previously made output-reload whose result we now believe
8736 is not needed. First we double-check.
8738 INSN is the insn now being processed.
8739 LAST_RELOAD_REG is the hard register number for which we want to delete
8740 the last output reload.
8741 J is the reload-number that originally used REG. The caller has made
8742 certain that reload J doesn't use REG any longer for input.
8743 NEW_RELOAD_REG is reload register that reload J is using for REG. */
8746 delete_output_reload (rtx insn
, int j
, int last_reload_reg
, rtx new_reload_reg
)
8748 rtx output_reload_insn
= spill_reg_store
[last_reload_reg
];
8749 rtx reg
= spill_reg_stored_to
[last_reload_reg
];
8752 int n_inherited
= 0;
8758 /* It is possible that this reload has been only used to set another reload
8759 we eliminated earlier and thus deleted this instruction too. */
8760 if (INSN_DELETED_P (output_reload_insn
))
8763 /* Get the raw pseudo-register referred to. */
8765 while (GET_CODE (reg
) == SUBREG
)
8766 reg
= SUBREG_REG (reg
);
8767 substed
= reg_equiv_memory_loc (REGNO (reg
));
8769 /* This is unsafe if the operand occurs more often in the current
8770 insn than it is inherited. */
8771 for (k
= n_reloads
- 1; k
>= 0; k
--)
8773 rtx reg2
= rld
[k
].in
;
8776 if (MEM_P (reg2
) || reload_override_in
[k
])
8777 reg2
= rld
[k
].in_reg
;
8779 if (rld
[k
].out
&& ! rld
[k
].out_reg
)
8780 reg2
= XEXP (rld
[k
].in_reg
, 0);
8782 while (GET_CODE (reg2
) == SUBREG
)
8783 reg2
= SUBREG_REG (reg2
);
8784 if (rtx_equal_p (reg2
, reg
))
8786 if (reload_inherited
[k
] || reload_override_in
[k
] || k
== j
)
8792 n_occurrences
= count_occurrences (PATTERN (insn
), reg
, 0);
8793 if (CALL_P (insn
) && CALL_INSN_FUNCTION_USAGE (insn
))
8794 n_occurrences
+= count_occurrences (CALL_INSN_FUNCTION_USAGE (insn
),
8797 n_occurrences
+= count_occurrences (PATTERN (insn
),
8798 eliminate_regs (substed
, VOIDmode
,
8800 for (i1
= reg_equiv_alt_mem_list (REGNO (reg
)); i1
; i1
= XEXP (i1
, 1))
8802 gcc_assert (!rtx_equal_p (XEXP (i1
, 0), substed
));
8803 n_occurrences
+= count_occurrences (PATTERN (insn
), XEXP (i1
, 0), 0);
8805 if (n_occurrences
> n_inherited
)
8808 regno
= REGNO (reg
);
8809 if (regno
>= FIRST_PSEUDO_REGISTER
)
8812 nregs
= hard_regno_nregs
[regno
][GET_MODE (reg
)];
8814 /* If the pseudo-reg we are reloading is no longer referenced
8815 anywhere between the store into it and here,
8816 and we're within the same basic block, then the value can only
8817 pass through the reload reg and end up here.
8818 Otherwise, give up--return. */
8819 for (i1
= NEXT_INSN (output_reload_insn
);
8820 i1
!= insn
; i1
= NEXT_INSN (i1
))
8822 if (NOTE_INSN_BASIC_BLOCK_P (i1
))
8824 if ((NONJUMP_INSN_P (i1
) || CALL_P (i1
))
8825 && refers_to_regno_p (regno
, regno
+ nregs
, PATTERN (i1
), NULL
))
8827 /* If this is USE in front of INSN, we only have to check that
8828 there are no more references than accounted for by inheritance. */
8829 while (NONJUMP_INSN_P (i1
) && GET_CODE (PATTERN (i1
)) == USE
)
8831 n_occurrences
+= rtx_equal_p (reg
, XEXP (PATTERN (i1
), 0)) != 0;
8832 i1
= NEXT_INSN (i1
);
8834 if (n_occurrences
<= n_inherited
&& i1
== insn
)
8840 /* We will be deleting the insn. Remove the spill reg information. */
8841 for (k
= hard_regno_nregs
[last_reload_reg
][GET_MODE (reg
)]; k
-- > 0; )
8843 spill_reg_store
[last_reload_reg
+ k
] = 0;
8844 spill_reg_stored_to
[last_reload_reg
+ k
] = 0;
8847 /* The caller has already checked that REG dies or is set in INSN.
8848 It has also checked that we are optimizing, and thus some
8849 inaccuracies in the debugging information are acceptable.
8850 So we could just delete output_reload_insn. But in some cases
8851 we can improve the debugging information without sacrificing
8852 optimization - maybe even improving the code: See if the pseudo
8853 reg has been completely replaced with reload regs. If so, delete
8854 the store insn and forget we had a stack slot for the pseudo. */
8855 if (rld
[j
].out
!= rld
[j
].in
8856 && REG_N_DEATHS (REGNO (reg
)) == 1
8857 && REG_N_SETS (REGNO (reg
)) == 1
8858 && REG_BASIC_BLOCK (REGNO (reg
)) >= NUM_FIXED_BLOCKS
8859 && find_regno_note (insn
, REG_DEAD
, REGNO (reg
)))
8863 /* We know that it was used only between here and the beginning of
8864 the current basic block. (We also know that the last use before
8865 INSN was the output reload we are thinking of deleting, but never
8866 mind that.) Search that range; see if any ref remains. */
8867 for (i2
= PREV_INSN (insn
); i2
; i2
= PREV_INSN (i2
))
8869 rtx set
= single_set (i2
);
8871 /* Uses which just store in the pseudo don't count,
8872 since if they are the only uses, they are dead. */
8873 if (set
!= 0 && SET_DEST (set
) == reg
)
8878 if ((NONJUMP_INSN_P (i2
) || CALL_P (i2
))
8879 && reg_mentioned_p (reg
, PATTERN (i2
)))
8881 /* Some other ref remains; just delete the output reload we
8883 delete_address_reloads (output_reload_insn
, insn
);
8884 delete_insn (output_reload_insn
);
8889 /* Delete the now-dead stores into this pseudo. Note that this
8890 loop also takes care of deleting output_reload_insn. */
8891 for (i2
= PREV_INSN (insn
); i2
; i2
= PREV_INSN (i2
))
8893 rtx set
= single_set (i2
);
8895 if (set
!= 0 && SET_DEST (set
) == reg
)
8897 delete_address_reloads (i2
, insn
);
8905 /* For the debugging info, say the pseudo lives in this reload reg. */
8906 reg_renumber
[REGNO (reg
)] = REGNO (new_reload_reg
);
8907 if (ira_conflicts_p
)
8908 /* Inform IRA about the change. */
8909 ira_mark_allocation_change (REGNO (reg
));
8910 alter_reg (REGNO (reg
), -1, false);
8914 delete_address_reloads (output_reload_insn
, insn
);
8915 delete_insn (output_reload_insn
);
8919 /* We are going to delete DEAD_INSN. Recursively delete loads of
8920 reload registers used in DEAD_INSN that are not used till CURRENT_INSN.
8921 CURRENT_INSN is being reloaded, so we have to check its reloads too. */
8923 delete_address_reloads (rtx dead_insn
, rtx current_insn
)
8925 rtx set
= single_set (dead_insn
);
8926 rtx set2
, dst
, prev
, next
;
8929 rtx dst
= SET_DEST (set
);
8931 delete_address_reloads_1 (dead_insn
, XEXP (dst
, 0), current_insn
);
8933 /* If we deleted the store from a reloaded post_{in,de}c expression,
8934 we can delete the matching adds. */
8935 prev
= PREV_INSN (dead_insn
);
8936 next
= NEXT_INSN (dead_insn
);
8937 if (! prev
|| ! next
)
8939 set
= single_set (next
);
8940 set2
= single_set (prev
);
8942 || GET_CODE (SET_SRC (set
)) != PLUS
|| GET_CODE (SET_SRC (set2
)) != PLUS
8943 || !CONST_INT_P (XEXP (SET_SRC (set
), 1))
8944 || !CONST_INT_P (XEXP (SET_SRC (set2
), 1)))
8946 dst
= SET_DEST (set
);
8947 if (! rtx_equal_p (dst
, SET_DEST (set2
))
8948 || ! rtx_equal_p (dst
, XEXP (SET_SRC (set
), 0))
8949 || ! rtx_equal_p (dst
, XEXP (SET_SRC (set2
), 0))
8950 || (INTVAL (XEXP (SET_SRC (set
), 1))
8951 != -INTVAL (XEXP (SET_SRC (set2
), 1))))
8953 delete_related_insns (prev
);
8954 delete_related_insns (next
);
8957 /* Subfunction of delete_address_reloads: process registers found in X. */
8959 delete_address_reloads_1 (rtx dead_insn
, rtx x
, rtx current_insn
)
8961 rtx prev
, set
, dst
, i2
;
8963 enum rtx_code code
= GET_CODE (x
);
8967 const char *fmt
= GET_RTX_FORMAT (code
);
8968 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
8971 delete_address_reloads_1 (dead_insn
, XEXP (x
, i
), current_insn
);
8972 else if (fmt
[i
] == 'E')
8974 for (j
= XVECLEN (x
, i
) - 1; j
>= 0; j
--)
8975 delete_address_reloads_1 (dead_insn
, XVECEXP (x
, i
, j
),
8982 if (spill_reg_order
[REGNO (x
)] < 0)
8985 /* Scan backwards for the insn that sets x. This might be a way back due
8987 for (prev
= PREV_INSN (dead_insn
); prev
; prev
= PREV_INSN (prev
))
8989 code
= GET_CODE (prev
);
8990 if (code
== CODE_LABEL
|| code
== JUMP_INSN
)
8994 if (reg_set_p (x
, PATTERN (prev
)))
8996 if (reg_referenced_p (x
, PATTERN (prev
)))
8999 if (! prev
|| INSN_UID (prev
) < reload_first_uid
)
9001 /* Check that PREV only sets the reload register. */
9002 set
= single_set (prev
);
9005 dst
= SET_DEST (set
);
9007 || ! rtx_equal_p (dst
, x
))
9009 if (! reg_set_p (dst
, PATTERN (dead_insn
)))
9011 /* Check if DST was used in a later insn -
9012 it might have been inherited. */
9013 for (i2
= NEXT_INSN (dead_insn
); i2
; i2
= NEXT_INSN (i2
))
9019 if (reg_referenced_p (dst
, PATTERN (i2
)))
9021 /* If there is a reference to the register in the current insn,
9022 it might be loaded in a non-inherited reload. If no other
9023 reload uses it, that means the register is set before
9025 if (i2
== current_insn
)
9027 for (j
= n_reloads
- 1; j
>= 0; j
--)
9028 if ((rld
[j
].reg_rtx
== dst
&& reload_inherited
[j
])
9029 || reload_override_in
[j
] == dst
)
9031 for (j
= n_reloads
- 1; j
>= 0; j
--)
9032 if (rld
[j
].in
&& rld
[j
].reg_rtx
== dst
)
9041 /* If DST is still live at CURRENT_INSN, check if it is used for
9042 any reload. Note that even if CURRENT_INSN sets DST, we still
9043 have to check the reloads. */
9044 if (i2
== current_insn
)
9046 for (j
= n_reloads
- 1; j
>= 0; j
--)
9047 if ((rld
[j
].reg_rtx
== dst
&& reload_inherited
[j
])
9048 || reload_override_in
[j
] == dst
)
9050 /* ??? We can't finish the loop here, because dst might be
9051 allocated to a pseudo in this block if no reload in this
9052 block needs any of the classes containing DST - see
9053 spill_hard_reg. There is no easy way to tell this, so we
9054 have to scan till the end of the basic block. */
9056 if (reg_set_p (dst
, PATTERN (i2
)))
9060 delete_address_reloads_1 (prev
, SET_SRC (set
), current_insn
);
9061 reg_reloaded_contents
[REGNO (dst
)] = -1;
9065 /* Output reload-insns to reload VALUE into RELOADREG.
9066 VALUE is an autoincrement or autodecrement RTX whose operand
9067 is a register or memory location;
9068 so reloading involves incrementing that location.
9069 IN is either identical to VALUE, or some cheaper place to reload from.
9071 INC_AMOUNT is the number to increment or decrement by (always positive).
9072 This cannot be deduced from VALUE. */
9075 inc_for_reload (rtx reloadreg
, rtx in
, rtx value
, int inc_amount
)
9077 /* REG or MEM to be copied and incremented. */
9078 rtx incloc
= find_replacement (&XEXP (value
, 0));
9079 /* Nonzero if increment after copying. */
9080 int post
= (GET_CODE (value
) == POST_DEC
|| GET_CODE (value
) == POST_INC
9081 || GET_CODE (value
) == POST_MODIFY
);
9086 rtx real_in
= in
== value
? incloc
: in
;
9088 /* No hard register is equivalent to this register after
9089 inc/dec operation. If REG_LAST_RELOAD_REG were nonzero,
9090 we could inc/dec that register as well (maybe even using it for
9091 the source), but I'm not sure it's worth worrying about. */
9093 reg_last_reload_reg
[REGNO (incloc
)] = 0;
9095 if (GET_CODE (value
) == PRE_MODIFY
|| GET_CODE (value
) == POST_MODIFY
)
9097 gcc_assert (GET_CODE (XEXP (value
, 1)) == PLUS
);
9098 inc
= find_replacement (&XEXP (XEXP (value
, 1), 1));
9102 if (GET_CODE (value
) == PRE_DEC
|| GET_CODE (value
) == POST_DEC
)
9103 inc_amount
= -inc_amount
;
9105 inc
= GEN_INT (inc_amount
);
9108 /* If this is post-increment, first copy the location to the reload reg. */
9109 if (post
&& real_in
!= reloadreg
)
9110 emit_insn (gen_move_insn (reloadreg
, real_in
));
9114 /* See if we can directly increment INCLOC. Use a method similar to
9115 that in gen_reload. */
9117 last
= get_last_insn ();
9118 add_insn
= emit_insn (gen_rtx_SET (VOIDmode
, incloc
,
9119 gen_rtx_PLUS (GET_MODE (incloc
),
9122 code
= recog_memoized (add_insn
);
9125 extract_insn (add_insn
);
9126 if (constrain_operands (1))
9128 /* If this is a pre-increment and we have incremented the value
9129 where it lives, copy the incremented value to RELOADREG to
9130 be used as an address. */
9133 emit_insn (gen_move_insn (reloadreg
, incloc
));
9137 delete_insns_since (last
);
9140 /* If couldn't do the increment directly, must increment in RELOADREG.
9141 The way we do this depends on whether this is pre- or post-increment.
9142 For pre-increment, copy INCLOC to the reload register, increment it
9143 there, then save back. */
9147 if (in
!= reloadreg
)
9148 emit_insn (gen_move_insn (reloadreg
, real_in
));
9149 emit_insn (gen_add2_insn (reloadreg
, inc
));
9150 emit_insn (gen_move_insn (incloc
, reloadreg
));
9155 Because this might be a jump insn or a compare, and because RELOADREG
9156 may not be available after the insn in an input reload, we must do
9157 the incrementation before the insn being reloaded for.
9159 We have already copied IN to RELOADREG. Increment the copy in
9160 RELOADREG, save that back, then decrement RELOADREG so it has
9161 the original value. */
9163 emit_insn (gen_add2_insn (reloadreg
, inc
));
9164 emit_insn (gen_move_insn (incloc
, reloadreg
));
9165 if (CONST_INT_P (inc
))
9166 emit_insn (gen_add2_insn (reloadreg
, GEN_INT (-INTVAL (inc
))));
9168 emit_insn (gen_sub2_insn (reloadreg
, inc
));
9174 add_auto_inc_notes (rtx insn
, rtx x
)
9176 enum rtx_code code
= GET_CODE (x
);
9180 if (code
== MEM
&& auto_inc_p (XEXP (x
, 0)))
9182 add_reg_note (insn
, REG_INC
, XEXP (XEXP (x
, 0), 0));
9186 /* Scan all the operand sub-expressions. */
9187 fmt
= GET_RTX_FORMAT (code
);
9188 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
9191 add_auto_inc_notes (insn
, XEXP (x
, i
));
9192 else if (fmt
[i
] == 'E')
9193 for (j
= XVECLEN (x
, i
) - 1; j
>= 0; j
--)
9194 add_auto_inc_notes (insn
, XVECEXP (x
, i
, j
));