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"
50 /* This file contains the reload pass of the compiler, which is
51 run after register allocation has been done. It checks that
52 each insn is valid (operands required to be in registers really
53 are in registers of the proper class) and fixes up invalid ones
54 by copying values temporarily into registers for the insns
57 The results of register allocation are described by the vector
58 reg_renumber; the insns still contain pseudo regs, but reg_renumber
59 can be used to find which hard reg, if any, a pseudo reg is in.
61 The technique we always use is to free up a few hard regs that are
62 called ``reload regs'', and for each place where a pseudo reg
63 must be in a hard reg, copy it temporarily into one of the reload regs.
65 Reload regs are allocated locally for every instruction that needs
66 reloads. When there are pseudos which are allocated to a register that
67 has been chosen as a reload reg, such pseudos must be ``spilled''.
68 This means that they go to other hard regs, or to stack slots if no other
69 available hard regs can be found. Spilling can invalidate more
70 insns, requiring additional need for reloads, so we must keep checking
71 until the process stabilizes.
73 For machines with different classes of registers, we must keep track
74 of the register class needed for each reload, and make sure that
75 we allocate enough reload registers of each class.
77 The file reload.c contains the code that checks one insn for
78 validity and reports the reloads that it needs. This file
79 is in charge of scanning the entire rtl code, accumulating the
80 reload needs, spilling, assigning reload registers to use for
81 fixing up each insn, and generating the new insns to copy values
82 into the reload registers. */
84 struct target_reload default_target_reload
;
86 struct target_reload
*this_target_reload
= &default_target_reload
;
89 #define spill_indirect_levels \
90 (this_target_reload->x_spill_indirect_levels)
92 /* During reload_as_needed, element N contains a REG rtx for the hard reg
93 into which reg N has been reloaded (perhaps for a previous insn). */
94 static rtx
*reg_last_reload_reg
;
96 /* Elt N nonzero if reg_last_reload_reg[N] has been set in this insn
97 for an output reload that stores into reg N. */
98 static regset_head reg_has_output_reload
;
100 /* Indicates which hard regs are reload-registers for an output reload
101 in the current insn. */
102 static HARD_REG_SET reg_is_output_reload
;
104 /* Widest width in which each pseudo reg is referred to (via subreg). */
105 static unsigned int *reg_max_ref_width
;
107 /* Vector to remember old contents of reg_renumber before spilling. */
108 static short *reg_old_renumber
;
110 /* During reload_as_needed, element N contains the last pseudo regno reloaded
111 into hard register N. If that pseudo reg occupied more than one register,
112 reg_reloaded_contents points to that pseudo for each spill register in
113 use; all of these must remain set for an inheritance to occur. */
114 static int reg_reloaded_contents
[FIRST_PSEUDO_REGISTER
];
116 /* During reload_as_needed, element N contains the insn for which
117 hard register N was last used. Its contents are significant only
118 when reg_reloaded_valid is set for this register. */
119 static rtx reg_reloaded_insn
[FIRST_PSEUDO_REGISTER
];
121 /* Indicate if reg_reloaded_insn / reg_reloaded_contents is valid. */
122 static HARD_REG_SET reg_reloaded_valid
;
123 /* Indicate if the register was dead at the end of the reload.
124 This is only valid if reg_reloaded_contents is set and valid. */
125 static HARD_REG_SET reg_reloaded_dead
;
127 /* Indicate whether the register's current value is one that is not
128 safe to retain across a call, even for registers that are normally
129 call-saved. This is only meaningful for members of reg_reloaded_valid. */
130 static HARD_REG_SET reg_reloaded_call_part_clobbered
;
132 /* Number of spill-regs so far; number of valid elements of spill_regs. */
135 /* In parallel with spill_regs, contains REG rtx's for those regs.
136 Holds the last rtx used for any given reg, or 0 if it has never
137 been used for spilling yet. This rtx is reused, provided it has
139 static rtx spill_reg_rtx
[FIRST_PSEUDO_REGISTER
];
141 /* In parallel with spill_regs, contains nonzero for a spill reg
142 that was stored after the last time it was used.
143 The precise value is the insn generated to do the store. */
144 static rtx spill_reg_store
[FIRST_PSEUDO_REGISTER
];
146 /* This is the register that was stored with spill_reg_store. This is a
147 copy of reload_out / reload_out_reg when the value was stored; if
148 reload_out is a MEM, spill_reg_stored_to will be set to reload_out_reg. */
149 static rtx spill_reg_stored_to
[FIRST_PSEUDO_REGISTER
];
151 /* This table is the inverse mapping of spill_regs:
152 indexed by hard reg number,
153 it contains the position of that reg in spill_regs,
154 or -1 for something that is not in spill_regs.
156 ?!? This is no longer accurate. */
157 static short spill_reg_order
[FIRST_PSEUDO_REGISTER
];
159 /* This reg set indicates registers that can't be used as spill registers for
160 the currently processed insn. These are the hard registers which are live
161 during the insn, but not allocated to pseudos, as well as fixed
163 static HARD_REG_SET bad_spill_regs
;
165 /* These are the hard registers that can't be used as spill register for any
166 insn. This includes registers used for user variables and registers that
167 we can't eliminate. A register that appears in this set also can't be used
168 to retry register allocation. */
169 static HARD_REG_SET bad_spill_regs_global
;
171 /* Describes order of use of registers for reloading
172 of spilled pseudo-registers. `n_spills' is the number of
173 elements that are actually valid; new ones are added at the end.
175 Both spill_regs and spill_reg_order are used on two occasions:
176 once during find_reload_regs, where they keep track of the spill registers
177 for a single insn, but also during reload_as_needed where they show all
178 the registers ever used by reload. For the latter case, the information
179 is calculated during finish_spills. */
180 static short spill_regs
[FIRST_PSEUDO_REGISTER
];
182 /* This vector of reg sets indicates, for each pseudo, which hard registers
183 may not be used for retrying global allocation because the register was
184 formerly spilled from one of them. If we allowed reallocating a pseudo to
185 a register that it was already allocated to, reload might not
187 static HARD_REG_SET
*pseudo_previous_regs
;
189 /* This vector of reg sets indicates, for each pseudo, which hard
190 registers may not be used for retrying global allocation because they
191 are used as spill registers during one of the insns in which the
193 static HARD_REG_SET
*pseudo_forbidden_regs
;
195 /* All hard regs that have been used as spill registers for any insn are
196 marked in this set. */
197 static HARD_REG_SET used_spill_regs
;
199 /* Index of last register assigned as a spill register. We allocate in
200 a round-robin fashion. */
201 static int last_spill_reg
;
203 /* Record the stack slot for each spilled hard register. */
204 static rtx spill_stack_slot
[FIRST_PSEUDO_REGISTER
];
206 /* Width allocated so far for that stack slot. */
207 static unsigned int spill_stack_slot_width
[FIRST_PSEUDO_REGISTER
];
209 /* Record which pseudos needed to be spilled. */
210 static regset_head spilled_pseudos
;
212 /* Record which pseudos changed their allocation in finish_spills. */
213 static regset_head changed_allocation_pseudos
;
215 /* Used for communication between order_regs_for_reload and count_pseudo.
216 Used to avoid counting one pseudo twice. */
217 static regset_head pseudos_counted
;
219 /* First uid used by insns created by reload in this function.
220 Used in find_equiv_reg. */
221 int reload_first_uid
;
223 /* Flag set by local-alloc or global-alloc if anything is live in
224 a call-clobbered reg across calls. */
225 int caller_save_needed
;
227 /* Set to 1 while reload_as_needed is operating.
228 Required by some machines to handle any generated moves differently. */
229 int reload_in_progress
= 0;
231 /* This obstack is used for allocation of rtl during register elimination.
232 The allocated storage can be freed once find_reloads has processed the
234 static struct obstack reload_obstack
;
236 /* Points to the beginning of the reload_obstack. All insn_chain structures
237 are allocated first. */
238 static char *reload_startobj
;
240 /* The point after all insn_chain structures. Used to quickly deallocate
241 memory allocated in copy_reloads during calculate_needs_all_insns. */
242 static char *reload_firstobj
;
244 /* This points before all local rtl generated by register elimination.
245 Used to quickly free all memory after processing one insn. */
246 static char *reload_insn_firstobj
;
248 /* List of insn_chain instructions, one for every insn that reload needs to
250 struct insn_chain
*reload_insn_chain
;
252 /* TRUE if we potentially left dead insns in the insn stream and want to
253 run DCE immediately after reload, FALSE otherwise. */
254 static bool need_dce
;
256 /* List of all insns needing reloads. */
257 static struct insn_chain
*insns_need_reload
;
259 /* This structure is used to record information about register eliminations.
260 Each array entry describes one possible way of eliminating a register
261 in favor of another. If there is more than one way of eliminating a
262 particular register, the most preferred should be specified first. */
266 int from
; /* Register number to be eliminated. */
267 int to
; /* Register number used as replacement. */
268 HOST_WIDE_INT initial_offset
; /* Initial difference between values. */
269 int can_eliminate
; /* Nonzero if this elimination can be done. */
270 int can_eliminate_previous
; /* Value returned by TARGET_CAN_ELIMINATE
271 target hook in previous scan over insns
273 HOST_WIDE_INT offset
; /* Current offset between the two regs. */
274 HOST_WIDE_INT previous_offset
;/* Offset at end of previous insn. */
275 int ref_outside_mem
; /* "to" has been referenced outside a MEM. */
276 rtx from_rtx
; /* REG rtx for the register to be eliminated.
277 We cannot simply compare the number since
278 we might then spuriously replace a hard
279 register corresponding to a pseudo
280 assigned to the reg to be eliminated. */
281 rtx to_rtx
; /* REG rtx for the replacement. */
284 static struct elim_table
*reg_eliminate
= 0;
286 /* This is an intermediate structure to initialize the table. It has
287 exactly the members provided by ELIMINABLE_REGS. */
288 static const struct elim_table_1
292 } reg_eliminate_1
[] =
294 /* If a set of eliminable registers was specified, define the table from it.
295 Otherwise, default to the normal case of the frame pointer being
296 replaced by the stack pointer. */
298 #ifdef ELIMINABLE_REGS
301 {{ FRAME_POINTER_REGNUM
, STACK_POINTER_REGNUM
}};
304 #define NUM_ELIMINABLE_REGS ARRAY_SIZE (reg_eliminate_1)
306 /* Record the number of pending eliminations that have an offset not equal
307 to their initial offset. If nonzero, we use a new copy of each
308 replacement result in any insns encountered. */
309 int num_not_at_initial_offset
;
311 /* Count the number of registers that we may be able to eliminate. */
312 static int num_eliminable
;
313 /* And the number of registers that are equivalent to a constant that
314 can be eliminated to frame_pointer / arg_pointer + constant. */
315 static int num_eliminable_invariants
;
317 /* For each label, we record the offset of each elimination. If we reach
318 a label by more than one path and an offset differs, we cannot do the
319 elimination. This information is indexed by the difference of the
320 number of the label and the first label number. We can't offset the
321 pointer itself as this can cause problems on machines with segmented
322 memory. The first table is an array of flags that records whether we
323 have yet encountered a label and the second table is an array of arrays,
324 one entry in the latter array for each elimination. */
326 static int first_label_num
;
327 static char *offsets_known_at
;
328 static HOST_WIDE_INT (*offsets_at
)[NUM_ELIMINABLE_REGS
];
330 VEC(reg_equivs_t
,gc
) *reg_equivs
;
332 /* Stack of addresses where an rtx has been changed. We can undo the
333 changes by popping items off the stack and restoring the original
334 value at each location.
336 We use this simplistic undo capability rather than copy_rtx as copy_rtx
337 will not make a deep copy of a normally sharable rtx, such as
338 (const (plus (symbol_ref) (const_int))). If such an expression appears
339 as R1 in gen_reload_chain_without_interm_reg_p, then a shared
340 rtx expression would be changed. See PR 42431. */
344 DEF_VEC_ALLOC_P(rtx_p
,heap
);
345 static VEC(rtx_p
,heap
) *substitute_stack
;
347 /* Number of labels in the current function. */
349 static int num_labels
;
351 static void replace_pseudos_in (rtx
*, enum machine_mode
, rtx
);
352 static void maybe_fix_stack_asms (void);
353 static void copy_reloads (struct insn_chain
*);
354 static void calculate_needs_all_insns (int);
355 static int find_reg (struct insn_chain
*, int);
356 static void find_reload_regs (struct insn_chain
*);
357 static void select_reload_regs (void);
358 static void delete_caller_save_insns (void);
360 static void spill_failure (rtx
, enum reg_class
);
361 static void count_spilled_pseudo (int, int, int);
362 static void delete_dead_insn (rtx
);
363 static void alter_reg (int, int, bool);
364 static void set_label_offsets (rtx
, rtx
, int);
365 static void check_eliminable_occurrences (rtx
);
366 static void elimination_effects (rtx
, enum machine_mode
);
367 static rtx
eliminate_regs_1 (rtx
, enum machine_mode
, rtx
, bool, bool);
368 static int eliminate_regs_in_insn (rtx
, int);
369 static void update_eliminable_offsets (void);
370 static void mark_not_eliminable (rtx
, const_rtx
, void *);
371 static void set_initial_elim_offsets (void);
372 static bool verify_initial_elim_offsets (void);
373 static void set_initial_label_offsets (void);
374 static void set_offsets_for_label (rtx
);
375 static void init_eliminable_invariants (rtx
, bool);
376 static void init_elim_table (void);
377 static void free_reg_equiv (void);
378 static void update_eliminables (HARD_REG_SET
*);
379 static void elimination_costs_in_insn (rtx
);
380 static void spill_hard_reg (unsigned int, int);
381 static int finish_spills (int);
382 static void scan_paradoxical_subregs (rtx
);
383 static void count_pseudo (int);
384 static void order_regs_for_reload (struct insn_chain
*);
385 static void reload_as_needed (int);
386 static void forget_old_reloads_1 (rtx
, const_rtx
, void *);
387 static void forget_marked_reloads (regset
);
388 static int reload_reg_class_lower (const void *, const void *);
389 static void mark_reload_reg_in_use (unsigned int, int, enum reload_type
,
391 static void clear_reload_reg_in_use (unsigned int, int, enum reload_type
,
393 static int reload_reg_free_p (unsigned int, int, enum reload_type
);
394 static int reload_reg_free_for_value_p (int, int, int, enum reload_type
,
396 static int free_for_value_p (int, enum machine_mode
, int, enum reload_type
,
398 static int allocate_reload_reg (struct insn_chain
*, int, int);
399 static int conflicts_with_override (rtx
);
400 static void failed_reload (rtx
, int);
401 static int set_reload_reg (int, int);
402 static void choose_reload_regs_init (struct insn_chain
*, rtx
*);
403 static void choose_reload_regs (struct insn_chain
*);
404 static void emit_input_reload_insns (struct insn_chain
*, struct reload
*,
406 static void emit_output_reload_insns (struct insn_chain
*, struct reload
*,
408 static void do_input_reload (struct insn_chain
*, struct reload
*, int);
409 static void do_output_reload (struct insn_chain
*, struct reload
*, int);
410 static void emit_reload_insns (struct insn_chain
*);
411 static void delete_output_reload (rtx
, int, int, rtx
);
412 static void delete_address_reloads (rtx
, rtx
);
413 static void delete_address_reloads_1 (rtx
, rtx
, rtx
);
414 static void inc_for_reload (rtx
, rtx
, rtx
, int);
416 static void add_auto_inc_notes (rtx
, rtx
);
418 static void substitute (rtx
*, const_rtx
, rtx
);
419 static bool gen_reload_chain_without_interm_reg_p (int, int);
420 static int reloads_conflict (int, int);
421 static rtx
gen_reload (rtx
, rtx
, int, enum reload_type
);
422 static rtx
emit_insn_if_valid_for_reload (rtx
);
424 /* Initialize the reload pass. This is called at the beginning of compilation
425 and may be called again if the target is reinitialized. */
432 /* Often (MEM (REG n)) is still valid even if (REG n) is put on the stack.
433 Set spill_indirect_levels to the number of levels such addressing is
434 permitted, zero if it is not permitted at all. */
437 = gen_rtx_MEM (Pmode
,
440 LAST_VIRTUAL_REGISTER
+ 1),
442 spill_indirect_levels
= 0;
444 while (memory_address_p (QImode
, tem
))
446 spill_indirect_levels
++;
447 tem
= gen_rtx_MEM (Pmode
, tem
);
450 /* See if indirect addressing is valid for (MEM (SYMBOL_REF ...)). */
452 tem
= gen_rtx_MEM (Pmode
, gen_rtx_SYMBOL_REF (Pmode
, "foo"));
453 indirect_symref_ok
= memory_address_p (QImode
, tem
);
455 /* See if reg+reg is a valid (and offsettable) address. */
457 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
459 tem
= gen_rtx_PLUS (Pmode
,
460 gen_rtx_REG (Pmode
, HARD_FRAME_POINTER_REGNUM
),
461 gen_rtx_REG (Pmode
, i
));
463 /* This way, we make sure that reg+reg is an offsettable address. */
464 tem
= plus_constant (Pmode
, tem
, 4);
466 if (memory_address_p (QImode
, tem
))
468 double_reg_address_ok
= 1;
473 /* Initialize obstack for our rtl allocation. */
474 gcc_obstack_init (&reload_obstack
);
475 reload_startobj
= XOBNEWVAR (&reload_obstack
, char, 0);
477 INIT_REG_SET (&spilled_pseudos
);
478 INIT_REG_SET (&changed_allocation_pseudos
);
479 INIT_REG_SET (&pseudos_counted
);
482 /* List of insn chains that are currently unused. */
483 static struct insn_chain
*unused_insn_chains
= 0;
485 /* Allocate an empty insn_chain structure. */
487 new_insn_chain (void)
489 struct insn_chain
*c
;
491 if (unused_insn_chains
== 0)
493 c
= XOBNEW (&reload_obstack
, struct insn_chain
);
494 INIT_REG_SET (&c
->live_throughout
);
495 INIT_REG_SET (&c
->dead_or_set
);
499 c
= unused_insn_chains
;
500 unused_insn_chains
= c
->next
;
502 c
->is_caller_save_insn
= 0;
503 c
->need_operand_change
= 0;
509 /* Small utility function to set all regs in hard reg set TO which are
510 allocated to pseudos in regset FROM. */
513 compute_use_by_pseudos (HARD_REG_SET
*to
, regset from
)
516 reg_set_iterator rsi
;
518 EXECUTE_IF_SET_IN_REG_SET (from
, FIRST_PSEUDO_REGISTER
, regno
, rsi
)
520 int r
= reg_renumber
[regno
];
524 /* reload_combine uses the information from DF_LIVE_IN,
525 which might still contain registers that have not
526 actually been allocated since they have an
528 gcc_assert (ira_conflicts_p
|| reload_completed
);
531 add_to_hard_reg_set (to
, PSEUDO_REGNO_MODE (regno
), r
);
535 /* Replace all pseudos found in LOC with their corresponding
539 replace_pseudos_in (rtx
*loc
, enum machine_mode mem_mode
, rtx usage
)
552 unsigned int regno
= REGNO (x
);
554 if (regno
< FIRST_PSEUDO_REGISTER
)
557 x
= eliminate_regs_1 (x
, mem_mode
, usage
, true, false);
561 replace_pseudos_in (loc
, mem_mode
, usage
);
565 if (reg_equiv_constant (regno
))
566 *loc
= reg_equiv_constant (regno
);
567 else if (reg_equiv_invariant (regno
))
568 *loc
= reg_equiv_invariant (regno
);
569 else if (reg_equiv_mem (regno
))
570 *loc
= reg_equiv_mem (regno
);
571 else if (reg_equiv_address (regno
))
572 *loc
= gen_rtx_MEM (GET_MODE (x
), reg_equiv_address (regno
));
575 gcc_assert (!REG_P (regno_reg_rtx
[regno
])
576 || REGNO (regno_reg_rtx
[regno
]) != regno
);
577 *loc
= regno_reg_rtx
[regno
];
582 else if (code
== MEM
)
584 replace_pseudos_in (& XEXP (x
, 0), GET_MODE (x
), usage
);
588 /* Process each of our operands recursively. */
589 fmt
= GET_RTX_FORMAT (code
);
590 for (i
= 0; i
< GET_RTX_LENGTH (code
); i
++, fmt
++)
592 replace_pseudos_in (&XEXP (x
, i
), mem_mode
, usage
);
593 else if (*fmt
== 'E')
594 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
595 replace_pseudos_in (& XVECEXP (x
, i
, j
), mem_mode
, usage
);
598 /* Determine if the current function has an exception receiver block
599 that reaches the exit block via non-exceptional edges */
602 has_nonexceptional_receiver (void)
606 basic_block
*tos
, *worklist
, bb
;
608 /* If we're not optimizing, then just err on the safe side. */
612 /* First determine which blocks can reach exit via normal paths. */
613 tos
= worklist
= XNEWVEC (basic_block
, n_basic_blocks
+ 1);
616 bb
->flags
&= ~BB_REACHABLE
;
618 /* Place the exit block on our worklist. */
619 EXIT_BLOCK_PTR
->flags
|= BB_REACHABLE
;
620 *tos
++ = EXIT_BLOCK_PTR
;
622 /* Iterate: find everything reachable from what we've already seen. */
623 while (tos
!= worklist
)
627 FOR_EACH_EDGE (e
, ei
, bb
->preds
)
628 if (!(e
->flags
& EDGE_ABNORMAL
))
630 basic_block src
= e
->src
;
632 if (!(src
->flags
& BB_REACHABLE
))
634 src
->flags
|= BB_REACHABLE
;
641 /* Now see if there's a reachable block with an exceptional incoming
644 if (bb
->flags
& BB_REACHABLE
&& bb_has_abnormal_pred (bb
))
647 /* No exceptional block reached exit unexceptionally. */
651 /* Grow (or allocate) the REG_EQUIVS array from its current size (which may be
652 zero elements) to MAX_REG_NUM elements.
654 Initialize all new fields to NULL and update REG_EQUIVS_SIZE. */
656 grow_reg_equivs (void)
658 int old_size
= VEC_length (reg_equivs_t
, reg_equivs
);
659 int max_regno
= max_reg_num ();
662 VEC_reserve (reg_equivs_t
, gc
, reg_equivs
, max_regno
);
663 for (i
= old_size
; i
< max_regno
; i
++)
665 VEC_quick_insert (reg_equivs_t
, reg_equivs
, i
, 0);
666 memset (VEC_index (reg_equivs_t
, reg_equivs
, i
), 0, sizeof (reg_equivs_t
));
672 /* Global variables used by reload and its subroutines. */
674 /* The current basic block while in calculate_elim_costs_all_insns. */
675 static basic_block elim_bb
;
677 /* Set during calculate_needs if an insn needs register elimination. */
678 static int something_needs_elimination
;
679 /* Set during calculate_needs if an insn needs an operand changed. */
680 static int something_needs_operands_changed
;
681 /* Set by alter_regs if we spilled a register to the stack. */
682 static bool something_was_spilled
;
684 /* Nonzero means we couldn't get enough spill regs. */
687 /* Temporary array of pseudo-register number. */
688 static int *temp_pseudo_reg_arr
;
690 /* Main entry point for the reload pass.
692 FIRST is the first insn of the function being compiled.
694 GLOBAL nonzero means we were called from global_alloc
695 and should attempt to reallocate any pseudoregs that we
696 displace from hard regs we will use for reloads.
697 If GLOBAL is zero, we do not have enough information to do that,
698 so any pseudo reg that is spilled must go to the stack.
700 Return value is TRUE if reload likely left dead insns in the
701 stream and a DCE pass should be run to elimiante them. Else the
702 return value is FALSE. */
705 reload (rtx first
, int global
)
709 struct elim_table
*ep
;
713 /* Make sure even insns with volatile mem refs are recognizable. */
718 reload_firstobj
= XOBNEWVAR (&reload_obstack
, char, 0);
720 /* Make sure that the last insn in the chain
721 is not something that needs reloading. */
722 emit_note (NOTE_INSN_DELETED
);
724 /* Enable find_equiv_reg to distinguish insns made by reload. */
725 reload_first_uid
= get_max_uid ();
727 #ifdef SECONDARY_MEMORY_NEEDED
728 /* Initialize the secondary memory table. */
729 clear_secondary_mem ();
732 /* We don't have a stack slot for any spill reg yet. */
733 memset (spill_stack_slot
, 0, sizeof spill_stack_slot
);
734 memset (spill_stack_slot_width
, 0, sizeof spill_stack_slot_width
);
736 /* Initialize the save area information for caller-save, in case some
740 /* Compute which hard registers are now in use
741 as homes for pseudo registers.
742 This is done here rather than (eg) in global_alloc
743 because this point is reached even if not optimizing. */
744 for (i
= FIRST_PSEUDO_REGISTER
; i
< max_regno
; i
++)
747 /* A function that has a nonlocal label that can reach the exit
748 block via non-exceptional paths must save all call-saved
750 if (cfun
->has_nonlocal_label
751 && has_nonexceptional_receiver ())
752 crtl
->saves_all_registers
= 1;
754 if (crtl
->saves_all_registers
)
755 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
756 if (! call_used_regs
[i
] && ! fixed_regs
[i
] && ! LOCAL_REGNO (i
))
757 df_set_regs_ever_live (i
, true);
759 /* Find all the pseudo registers that didn't get hard regs
760 but do have known equivalent constants or memory slots.
761 These include parameters (known equivalent to parameter slots)
762 and cse'd or loop-moved constant memory addresses.
764 Record constant equivalents in reg_equiv_constant
765 so they will be substituted by find_reloads.
766 Record memory equivalents in reg_mem_equiv so they can
767 be substituted eventually by altering the REG-rtx's. */
770 reg_old_renumber
= XCNEWVEC (short, max_regno
);
771 memcpy (reg_old_renumber
, reg_renumber
, max_regno
* sizeof (short));
772 pseudo_forbidden_regs
= XNEWVEC (HARD_REG_SET
, max_regno
);
773 pseudo_previous_regs
= XCNEWVEC (HARD_REG_SET
, max_regno
);
775 CLEAR_HARD_REG_SET (bad_spill_regs_global
);
777 init_eliminable_invariants (first
, true);
780 /* Alter each pseudo-reg rtx to contain its hard reg number. Assign
781 stack slots to the pseudos that lack hard regs or equivalents.
782 Do not touch virtual registers. */
784 temp_pseudo_reg_arr
= XNEWVEC (int, max_regno
- LAST_VIRTUAL_REGISTER
- 1);
785 for (n
= 0, i
= LAST_VIRTUAL_REGISTER
+ 1; i
< max_regno
; i
++)
786 temp_pseudo_reg_arr
[n
++] = i
;
789 /* Ask IRA to order pseudo-registers for better stack slot
791 ira_sort_regnos_for_alter_reg (temp_pseudo_reg_arr
, n
, reg_max_ref_width
);
793 for (i
= 0; i
< n
; i
++)
794 alter_reg (temp_pseudo_reg_arr
[i
], -1, false);
796 /* If we have some registers we think can be eliminated, scan all insns to
797 see if there is an insn that sets one of these registers to something
798 other than itself plus a constant. If so, the register cannot be
799 eliminated. Doing this scan here eliminates an extra pass through the
800 main reload loop in the most common case where register elimination
802 for (insn
= first
; insn
&& num_eliminable
; insn
= NEXT_INSN (insn
))
804 note_stores (PATTERN (insn
), mark_not_eliminable
, NULL
);
806 maybe_fix_stack_asms ();
808 insns_need_reload
= 0;
809 something_needs_elimination
= 0;
811 /* Initialize to -1, which means take the first spill register. */
814 /* Spill any hard regs that we know we can't eliminate. */
815 CLEAR_HARD_REG_SET (used_spill_regs
);
816 /* There can be multiple ways to eliminate a register;
817 they should be listed adjacently.
818 Elimination for any register fails only if all possible ways fail. */
819 for (ep
= reg_eliminate
; ep
< ®_eliminate
[NUM_ELIMINABLE_REGS
]; )
822 int can_eliminate
= 0;
825 can_eliminate
|= ep
->can_eliminate
;
828 while (ep
< ®_eliminate
[NUM_ELIMINABLE_REGS
] && ep
->from
== from
);
830 spill_hard_reg (from
, 1);
833 #if !HARD_FRAME_POINTER_IS_FRAME_POINTER
834 if (frame_pointer_needed
)
835 spill_hard_reg (HARD_FRAME_POINTER_REGNUM
, 1);
837 finish_spills (global
);
839 /* From now on, we may need to generate moves differently. We may also
840 allow modifications of insns which cause them to not be recognized.
841 Any such modifications will be cleaned up during reload itself. */
842 reload_in_progress
= 1;
844 /* This loop scans the entire function each go-round
845 and repeats until one repetition spills no additional hard regs. */
848 int something_changed
;
850 HOST_WIDE_INT starting_frame_size
;
852 starting_frame_size
= get_frame_size ();
853 something_was_spilled
= false;
855 set_initial_elim_offsets ();
856 set_initial_label_offsets ();
858 /* For each pseudo register that has an equivalent location defined,
859 try to eliminate any eliminable registers (such as the frame pointer)
860 assuming initial offsets for the replacement register, which
863 If the resulting location is directly addressable, substitute
864 the MEM we just got directly for the old REG.
866 If it is not addressable but is a constant or the sum of a hard reg
867 and constant, it is probably not addressable because the constant is
868 out of range, in that case record the address; we will generate
869 hairy code to compute the address in a register each time it is
870 needed. Similarly if it is a hard register, but one that is not
871 valid as an address register.
873 If the location is not addressable, but does not have one of the
874 above forms, assign a stack slot. We have to do this to avoid the
875 potential of producing lots of reloads if, e.g., a location involves
876 a pseudo that didn't get a hard register and has an equivalent memory
877 location that also involves a pseudo that didn't get a hard register.
879 Perhaps at some point we will improve reload_when_needed handling
880 so this problem goes away. But that's very hairy. */
882 for (i
= FIRST_PSEUDO_REGISTER
; i
< max_regno
; i
++)
883 if (reg_renumber
[i
] < 0 && reg_equiv_memory_loc (i
))
885 rtx x
= eliminate_regs (reg_equiv_memory_loc (i
), VOIDmode
,
888 if (strict_memory_address_addr_space_p
889 (GET_MODE (regno_reg_rtx
[i
]), XEXP (x
, 0),
891 reg_equiv_mem (i
) = x
, reg_equiv_address (i
) = 0;
892 else if (CONSTANT_P (XEXP (x
, 0))
893 || (REG_P (XEXP (x
, 0))
894 && REGNO (XEXP (x
, 0)) < FIRST_PSEUDO_REGISTER
)
895 || (GET_CODE (XEXP (x
, 0)) == PLUS
896 && REG_P (XEXP (XEXP (x
, 0), 0))
897 && (REGNO (XEXP (XEXP (x
, 0), 0))
898 < FIRST_PSEUDO_REGISTER
)
899 && CONSTANT_P (XEXP (XEXP (x
, 0), 1))))
900 reg_equiv_address (i
) = XEXP (x
, 0), reg_equiv_mem (i
) = 0;
903 /* Make a new stack slot. Then indicate that something
904 changed so we go back and recompute offsets for
905 eliminable registers because the allocation of memory
906 below might change some offset. reg_equiv_{mem,address}
907 will be set up for this pseudo on the next pass around
909 reg_equiv_memory_loc (i
) = 0;
910 reg_equiv_init (i
) = 0;
911 alter_reg (i
, -1, true);
915 if (caller_save_needed
)
918 /* If we allocated another stack slot, redo elimination bookkeeping. */
919 if (something_was_spilled
|| starting_frame_size
!= get_frame_size ())
921 if (starting_frame_size
&& crtl
->stack_alignment_needed
)
923 /* If we have a stack frame, we must align it now. The
924 stack size may be a part of the offset computation for
925 register elimination. So if this changes the stack size,
926 then repeat the elimination bookkeeping. We don't
927 realign when there is no stack, as that will cause a
928 stack frame when none is needed should
929 STARTING_FRAME_OFFSET not be already aligned to
931 assign_stack_local (BLKmode
, 0, crtl
->stack_alignment_needed
);
932 if (starting_frame_size
!= get_frame_size ())
936 if (caller_save_needed
)
938 save_call_clobbered_regs ();
939 /* That might have allocated new insn_chain structures. */
940 reload_firstobj
= XOBNEWVAR (&reload_obstack
, char, 0);
943 calculate_needs_all_insns (global
);
945 if (! ira_conflicts_p
)
946 /* Don't do it for IRA. We need this info because we don't
947 change live_throughout and dead_or_set for chains when IRA
949 CLEAR_REG_SET (&spilled_pseudos
);
953 something_changed
= 0;
955 /* If we allocated any new memory locations, make another pass
956 since it might have changed elimination offsets. */
957 if (something_was_spilled
|| starting_frame_size
!= get_frame_size ())
958 something_changed
= 1;
960 /* Even if the frame size remained the same, we might still have
961 changed elimination offsets, e.g. if find_reloads called
962 force_const_mem requiring the back end to allocate a constant
963 pool base register that needs to be saved on the stack. */
964 else if (!verify_initial_elim_offsets ())
965 something_changed
= 1;
968 HARD_REG_SET to_spill
;
969 CLEAR_HARD_REG_SET (to_spill
);
970 update_eliminables (&to_spill
);
971 AND_COMPL_HARD_REG_SET (used_spill_regs
, to_spill
);
973 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
974 if (TEST_HARD_REG_BIT (to_spill
, i
))
976 spill_hard_reg (i
, 1);
979 /* Regardless of the state of spills, if we previously had
980 a register that we thought we could eliminate, but now can
981 not eliminate, we must run another pass.
983 Consider pseudos which have an entry in reg_equiv_* which
984 reference an eliminable register. We must make another pass
985 to update reg_equiv_* so that we do not substitute in the
986 old value from when we thought the elimination could be
988 something_changed
= 1;
992 select_reload_regs ();
996 if (insns_need_reload
!= 0 || did_spill
)
997 something_changed
|= finish_spills (global
);
999 if (! something_changed
)
1002 if (caller_save_needed
)
1003 delete_caller_save_insns ();
1005 obstack_free (&reload_obstack
, reload_firstobj
);
1008 /* If global-alloc was run, notify it of any register eliminations we have
1011 for (ep
= reg_eliminate
; ep
< ®_eliminate
[NUM_ELIMINABLE_REGS
]; ep
++)
1012 if (ep
->can_eliminate
)
1013 mark_elimination (ep
->from
, ep
->to
);
1015 /* If a pseudo has no hard reg, delete the insns that made the equivalence.
1016 If that insn didn't set the register (i.e., it copied the register to
1017 memory), just delete that insn instead of the equivalencing insn plus
1018 anything now dead. If we call delete_dead_insn on that insn, we may
1019 delete the insn that actually sets the register if the register dies
1020 there and that is incorrect. */
1022 for (i
= FIRST_PSEUDO_REGISTER
; i
< max_regno
; i
++)
1024 if (reg_renumber
[i
] < 0 && reg_equiv_init (i
) != 0)
1027 for (list
= reg_equiv_init (i
); list
; list
= XEXP (list
, 1))
1029 rtx equiv_insn
= XEXP (list
, 0);
1031 /* If we already deleted the insn or if it may trap, we can't
1032 delete it. The latter case shouldn't happen, but can
1033 if an insn has a variable address, gets a REG_EH_REGION
1034 note added to it, and then gets converted into a load
1035 from a constant address. */
1036 if (NOTE_P (equiv_insn
)
1037 || can_throw_internal (equiv_insn
))
1039 else if (reg_set_p (regno_reg_rtx
[i
], PATTERN (equiv_insn
)))
1040 delete_dead_insn (equiv_insn
);
1042 SET_INSN_DELETED (equiv_insn
);
1047 /* Use the reload registers where necessary
1048 by generating move instructions to move the must-be-register
1049 values into or out of the reload registers. */
1051 if (insns_need_reload
!= 0 || something_needs_elimination
1052 || something_needs_operands_changed
)
1054 HOST_WIDE_INT old_frame_size
= get_frame_size ();
1056 reload_as_needed (global
);
1058 gcc_assert (old_frame_size
== get_frame_size ());
1060 gcc_assert (verify_initial_elim_offsets ());
1063 /* If we were able to eliminate the frame pointer, show that it is no
1064 longer live at the start of any basic block. If it ls live by
1065 virtue of being in a pseudo, that pseudo will be marked live
1066 and hence the frame pointer will be known to be live via that
1069 if (! frame_pointer_needed
)
1071 bitmap_clear_bit (df_get_live_in (bb
), HARD_FRAME_POINTER_REGNUM
);
1073 /* Come here (with failure set nonzero) if we can't get enough spill
1077 CLEAR_REG_SET (&changed_allocation_pseudos
);
1078 CLEAR_REG_SET (&spilled_pseudos
);
1079 reload_in_progress
= 0;
1081 /* Now eliminate all pseudo regs by modifying them into
1082 their equivalent memory references.
1083 The REG-rtx's for the pseudos are modified in place,
1084 so all insns that used to refer to them now refer to memory.
1086 For a reg that has a reg_equiv_address, all those insns
1087 were changed by reloading so that no insns refer to it any longer;
1088 but the DECL_RTL of a variable decl may refer to it,
1089 and if so this causes the debugging info to mention the variable. */
1091 for (i
= FIRST_PSEUDO_REGISTER
; i
< max_regno
; i
++)
1095 if (reg_equiv_mem (i
))
1096 addr
= XEXP (reg_equiv_mem (i
), 0);
1098 if (reg_equiv_address (i
))
1099 addr
= reg_equiv_address (i
);
1103 if (reg_renumber
[i
] < 0)
1105 rtx reg
= regno_reg_rtx
[i
];
1107 REG_USERVAR_P (reg
) = 0;
1108 PUT_CODE (reg
, MEM
);
1109 XEXP (reg
, 0) = addr
;
1110 if (reg_equiv_memory_loc (i
))
1111 MEM_COPY_ATTRIBUTES (reg
, reg_equiv_memory_loc (i
));
1113 MEM_ATTRS (reg
) = 0;
1114 MEM_NOTRAP_P (reg
) = 1;
1116 else if (reg_equiv_mem (i
))
1117 XEXP (reg_equiv_mem (i
), 0) = addr
;
1120 /* We don't want complex addressing modes in debug insns
1121 if simpler ones will do, so delegitimize equivalences
1123 if (MAY_HAVE_DEBUG_INSNS
&& reg_renumber
[i
] < 0)
1125 rtx reg
= regno_reg_rtx
[i
];
1129 if (reg_equiv_constant (i
))
1130 equiv
= reg_equiv_constant (i
);
1131 else if (reg_equiv_invariant (i
))
1132 equiv
= reg_equiv_invariant (i
);
1133 else if (reg
&& MEM_P (reg
))
1134 equiv
= targetm
.delegitimize_address (reg
);
1135 else if (reg
&& REG_P (reg
) && (int)REGNO (reg
) != i
)
1141 for (use
= DF_REG_USE_CHAIN (i
); use
; use
= next
)
1143 insn
= DF_REF_INSN (use
);
1145 /* Make sure the next ref is for a different instruction,
1146 so that we're not affected by the rescan. */
1147 next
= DF_REF_NEXT_REG (use
);
1148 while (next
&& DF_REF_INSN (next
) == insn
)
1149 next
= DF_REF_NEXT_REG (next
);
1151 if (DEBUG_INSN_P (insn
))
1155 INSN_VAR_LOCATION_LOC (insn
) = gen_rtx_UNKNOWN_VAR_LOC ();
1156 df_insn_rescan_debug_internal (insn
);
1159 INSN_VAR_LOCATION_LOC (insn
)
1160 = simplify_replace_rtx (INSN_VAR_LOCATION_LOC (insn
),
1167 /* We must set reload_completed now since the cleanup_subreg_operands call
1168 below will re-recognize each insn and reload may have generated insns
1169 which are only valid during and after reload. */
1170 reload_completed
= 1;
1172 /* Make a pass over all the insns and delete all USEs which we inserted
1173 only to tag a REG_EQUAL note on them. Remove all REG_DEAD and REG_UNUSED
1174 notes. Delete all CLOBBER insns, except those that refer to the return
1175 value and the special mem:BLK CLOBBERs added to prevent the scheduler
1176 from misarranging variable-array code, and simplify (subreg (reg))
1177 operands. Strip and regenerate REG_INC notes that may have been moved
1180 for (insn
= first
; insn
; insn
= NEXT_INSN (insn
))
1186 replace_pseudos_in (& CALL_INSN_FUNCTION_USAGE (insn
),
1187 VOIDmode
, CALL_INSN_FUNCTION_USAGE (insn
));
1189 if ((GET_CODE (PATTERN (insn
)) == USE
1190 /* We mark with QImode USEs introduced by reload itself. */
1191 && (GET_MODE (insn
) == QImode
1192 || find_reg_note (insn
, REG_EQUAL
, NULL_RTX
)))
1193 || (GET_CODE (PATTERN (insn
)) == CLOBBER
1194 && (!MEM_P (XEXP (PATTERN (insn
), 0))
1195 || GET_MODE (XEXP (PATTERN (insn
), 0)) != BLKmode
1196 || (GET_CODE (XEXP (XEXP (PATTERN (insn
), 0), 0)) != SCRATCH
1197 && XEXP (XEXP (PATTERN (insn
), 0), 0)
1198 != stack_pointer_rtx
))
1199 && (!REG_P (XEXP (PATTERN (insn
), 0))
1200 || ! REG_FUNCTION_VALUE_P (XEXP (PATTERN (insn
), 0)))))
1206 /* Some CLOBBERs may survive until here and still reference unassigned
1207 pseudos with const equivalent, which may in turn cause ICE in later
1208 passes if the reference remains in place. */
1209 if (GET_CODE (PATTERN (insn
)) == CLOBBER
)
1210 replace_pseudos_in (& XEXP (PATTERN (insn
), 0),
1211 VOIDmode
, PATTERN (insn
));
1213 /* Discard obvious no-ops, even without -O. This optimization
1214 is fast and doesn't interfere with debugging. */
1215 if (NONJUMP_INSN_P (insn
)
1216 && GET_CODE (PATTERN (insn
)) == SET
1217 && REG_P (SET_SRC (PATTERN (insn
)))
1218 && REG_P (SET_DEST (PATTERN (insn
)))
1219 && (REGNO (SET_SRC (PATTERN (insn
)))
1220 == REGNO (SET_DEST (PATTERN (insn
)))))
1226 pnote
= ®_NOTES (insn
);
1229 if (REG_NOTE_KIND (*pnote
) == REG_DEAD
1230 || REG_NOTE_KIND (*pnote
) == REG_UNUSED
1231 || REG_NOTE_KIND (*pnote
) == REG_INC
)
1232 *pnote
= XEXP (*pnote
, 1);
1234 pnote
= &XEXP (*pnote
, 1);
1238 add_auto_inc_notes (insn
, PATTERN (insn
));
1241 /* Simplify (subreg (reg)) if it appears as an operand. */
1242 cleanup_subreg_operands (insn
);
1244 /* Clean up invalid ASMs so that they don't confuse later passes.
1246 if (asm_noperands (PATTERN (insn
)) >= 0)
1248 extract_insn (insn
);
1249 if (!constrain_operands (1))
1251 error_for_asm (insn
,
1252 "%<asm%> operand has impossible constraints");
1259 /* If we are doing generic stack checking, give a warning if this
1260 function's frame size is larger than we expect. */
1261 if (flag_stack_check
== GENERIC_STACK_CHECK
)
1263 HOST_WIDE_INT size
= get_frame_size () + STACK_CHECK_FIXED_FRAME_SIZE
;
1264 static int verbose_warned
= 0;
1266 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
1267 if (df_regs_ever_live_p (i
) && ! fixed_regs
[i
] && call_used_regs
[i
])
1268 size
+= UNITS_PER_WORD
;
1270 if (size
> STACK_CHECK_MAX_FRAME_SIZE
)
1272 warning (0, "frame size too large for reliable stack checking");
1273 if (! verbose_warned
)
1275 warning (0, "try reducing the number of local variables");
1281 free (temp_pseudo_reg_arr
);
1283 /* Indicate that we no longer have known memory locations or constants. */
1286 free (reg_max_ref_width
);
1287 free (reg_old_renumber
);
1288 free (pseudo_previous_regs
);
1289 free (pseudo_forbidden_regs
);
1291 CLEAR_HARD_REG_SET (used_spill_regs
);
1292 for (i
= 0; i
< n_spills
; i
++)
1293 SET_HARD_REG_BIT (used_spill_regs
, spill_regs
[i
]);
1295 /* Free all the insn_chain structures at once. */
1296 obstack_free (&reload_obstack
, reload_startobj
);
1297 unused_insn_chains
= 0;
1299 inserted
= fixup_abnormal_edges ();
1301 /* We've possibly turned single trapping insn into multiple ones. */
1302 if (cfun
->can_throw_non_call_exceptions
)
1305 blocks
= sbitmap_alloc (last_basic_block
);
1306 sbitmap_ones (blocks
);
1307 find_many_sub_basic_blocks (blocks
);
1308 sbitmap_free (blocks
);
1312 commit_edge_insertions ();
1314 /* Replacing pseudos with their memory equivalents might have
1315 created shared rtx. Subsequent passes would get confused
1316 by this, so unshare everything here. */
1317 unshare_all_rtl_again (first
);
1319 #ifdef STACK_BOUNDARY
1320 /* init_emit has set the alignment of the hard frame pointer
1321 to STACK_BOUNDARY. It is very likely no longer valid if
1322 the hard frame pointer was used for register allocation. */
1323 if (!frame_pointer_needed
)
1324 REGNO_POINTER_ALIGN (HARD_FRAME_POINTER_REGNUM
) = BITS_PER_UNIT
;
1327 VEC_free (rtx_p
, heap
, substitute_stack
);
1329 gcc_assert (bitmap_empty_p (&spilled_pseudos
));
1331 reload_completed
= !failure
;
1336 /* Yet another special case. Unfortunately, reg-stack forces people to
1337 write incorrect clobbers in asm statements. These clobbers must not
1338 cause the register to appear in bad_spill_regs, otherwise we'll call
1339 fatal_insn later. We clear the corresponding regnos in the live
1340 register sets to avoid this.
1341 The whole thing is rather sick, I'm afraid. */
1344 maybe_fix_stack_asms (void)
1347 const char *constraints
[MAX_RECOG_OPERANDS
];
1348 enum machine_mode operand_mode
[MAX_RECOG_OPERANDS
];
1349 struct insn_chain
*chain
;
1351 for (chain
= reload_insn_chain
; chain
!= 0; chain
= chain
->next
)
1354 HARD_REG_SET clobbered
, allowed
;
1357 if (! INSN_P (chain
->insn
)
1358 || (noperands
= asm_noperands (PATTERN (chain
->insn
))) < 0)
1360 pat
= PATTERN (chain
->insn
);
1361 if (GET_CODE (pat
) != PARALLEL
)
1364 CLEAR_HARD_REG_SET (clobbered
);
1365 CLEAR_HARD_REG_SET (allowed
);
1367 /* First, make a mask of all stack regs that are clobbered. */
1368 for (i
= 0; i
< XVECLEN (pat
, 0); i
++)
1370 rtx t
= XVECEXP (pat
, 0, i
);
1371 if (GET_CODE (t
) == CLOBBER
&& STACK_REG_P (XEXP (t
, 0)))
1372 SET_HARD_REG_BIT (clobbered
, REGNO (XEXP (t
, 0)));
1375 /* Get the operand values and constraints out of the insn. */
1376 decode_asm_operands (pat
, recog_data
.operand
, recog_data
.operand_loc
,
1377 constraints
, operand_mode
, NULL
);
1379 /* For every operand, see what registers are allowed. */
1380 for (i
= 0; i
< noperands
; i
++)
1382 const char *p
= constraints
[i
];
1383 /* For every alternative, we compute the class of registers allowed
1384 for reloading in CLS, and merge its contents into the reg set
1386 int cls
= (int) NO_REGS
;
1392 if (c
== '\0' || c
== ',' || c
== '#')
1394 /* End of one alternative - mark the regs in the current
1395 class, and reset the class. */
1396 IOR_HARD_REG_SET (allowed
, reg_class_contents
[cls
]);
1402 } while (c
!= '\0' && c
!= ',');
1410 case '=': case '+': case '*': case '%': case '?': case '!':
1411 case '0': case '1': case '2': case '3': case '4': case '<':
1412 case '>': case 'V': case 'o': case '&': case 'E': case 'F':
1413 case 's': case 'i': case 'n': case 'X': case 'I': case 'J':
1414 case 'K': case 'L': case 'M': case 'N': case 'O': case 'P':
1415 case TARGET_MEM_CONSTRAINT
:
1419 cls
= (int) reg_class_subunion
[cls
]
1420 [(int) base_reg_class (VOIDmode
, ADDR_SPACE_GENERIC
,
1426 cls
= (int) reg_class_subunion
[cls
][(int) GENERAL_REGS
];
1430 if (EXTRA_ADDRESS_CONSTRAINT (c
, p
))
1431 cls
= (int) reg_class_subunion
[cls
]
1432 [(int) base_reg_class (VOIDmode
, ADDR_SPACE_GENERIC
,
1435 cls
= (int) reg_class_subunion
[cls
]
1436 [(int) REG_CLASS_FROM_CONSTRAINT (c
, p
)];
1438 p
+= CONSTRAINT_LEN (c
, p
);
1441 /* Those of the registers which are clobbered, but allowed by the
1442 constraints, must be usable as reload registers. So clear them
1443 out of the life information. */
1444 AND_HARD_REG_SET (allowed
, clobbered
);
1445 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
1446 if (TEST_HARD_REG_BIT (allowed
, i
))
1448 CLEAR_REGNO_REG_SET (&chain
->live_throughout
, i
);
1449 CLEAR_REGNO_REG_SET (&chain
->dead_or_set
, i
);
1456 /* Copy the global variables n_reloads and rld into the corresponding elts
1459 copy_reloads (struct insn_chain
*chain
)
1461 chain
->n_reloads
= n_reloads
;
1462 chain
->rld
= XOBNEWVEC (&reload_obstack
, struct reload
, n_reloads
);
1463 memcpy (chain
->rld
, rld
, n_reloads
* sizeof (struct reload
));
1464 reload_insn_firstobj
= XOBNEWVAR (&reload_obstack
, char, 0);
1467 /* Walk the chain of insns, and determine for each whether it needs reloads
1468 and/or eliminations. Build the corresponding insns_need_reload list, and
1469 set something_needs_elimination as appropriate. */
1471 calculate_needs_all_insns (int global
)
1473 struct insn_chain
**pprev_reload
= &insns_need_reload
;
1474 struct insn_chain
*chain
, *next
= 0;
1476 something_needs_elimination
= 0;
1478 reload_insn_firstobj
= XOBNEWVAR (&reload_obstack
, char, 0);
1479 for (chain
= reload_insn_chain
; chain
!= 0; chain
= next
)
1481 rtx insn
= chain
->insn
;
1485 /* Clear out the shortcuts. */
1486 chain
->n_reloads
= 0;
1487 chain
->need_elim
= 0;
1488 chain
->need_reload
= 0;
1489 chain
->need_operand_change
= 0;
1491 /* If this is a label, a JUMP_INSN, or has REG_NOTES (which might
1492 include REG_LABEL_OPERAND and REG_LABEL_TARGET), we need to see
1493 what effects this has on the known offsets at labels. */
1495 if (LABEL_P (insn
) || JUMP_P (insn
)
1496 || (INSN_P (insn
) && REG_NOTES (insn
) != 0))
1497 set_label_offsets (insn
, insn
, 0);
1501 rtx old_body
= PATTERN (insn
);
1502 int old_code
= INSN_CODE (insn
);
1503 rtx old_notes
= REG_NOTES (insn
);
1504 int did_elimination
= 0;
1505 int operands_changed
= 0;
1506 rtx set
= single_set (insn
);
1508 /* Skip insns that only set an equivalence. */
1509 if (set
&& REG_P (SET_DEST (set
))
1510 && reg_renumber
[REGNO (SET_DEST (set
))] < 0
1511 && (reg_equiv_constant (REGNO (SET_DEST (set
)))
1512 || (reg_equiv_invariant (REGNO (SET_DEST (set
)))))
1513 && reg_equiv_init (REGNO (SET_DEST (set
))))
1516 /* If needed, eliminate any eliminable registers. */
1517 if (num_eliminable
|| num_eliminable_invariants
)
1518 did_elimination
= eliminate_regs_in_insn (insn
, 0);
1520 /* Analyze the instruction. */
1521 operands_changed
= find_reloads (insn
, 0, spill_indirect_levels
,
1522 global
, spill_reg_order
);
1524 /* If a no-op set needs more than one reload, this is likely
1525 to be something that needs input address reloads. We
1526 can't get rid of this cleanly later, and it is of no use
1527 anyway, so discard it now.
1528 We only do this when expensive_optimizations is enabled,
1529 since this complements reload inheritance / output
1530 reload deletion, and it can make debugging harder. */
1531 if (flag_expensive_optimizations
&& n_reloads
> 1)
1533 rtx set
= single_set (insn
);
1536 ((SET_SRC (set
) == SET_DEST (set
)
1537 && REG_P (SET_SRC (set
))
1538 && REGNO (SET_SRC (set
)) >= FIRST_PSEUDO_REGISTER
)
1539 || (REG_P (SET_SRC (set
)) && REG_P (SET_DEST (set
))
1540 && reg_renumber
[REGNO (SET_SRC (set
))] < 0
1541 && reg_renumber
[REGNO (SET_DEST (set
))] < 0
1542 && reg_equiv_memory_loc (REGNO (SET_SRC (set
))) != NULL
1543 && reg_equiv_memory_loc (REGNO (SET_DEST (set
))) != NULL
1544 && rtx_equal_p (reg_equiv_memory_loc (REGNO (SET_SRC (set
))),
1545 reg_equiv_memory_loc (REGNO (SET_DEST (set
)))))))
1547 if (ira_conflicts_p
)
1548 /* Inform IRA about the insn deletion. */
1549 ira_mark_memory_move_deletion (REGNO (SET_DEST (set
)),
1550 REGNO (SET_SRC (set
)));
1552 /* Delete it from the reload chain. */
1554 chain
->prev
->next
= next
;
1556 reload_insn_chain
= next
;
1558 next
->prev
= chain
->prev
;
1559 chain
->next
= unused_insn_chains
;
1560 unused_insn_chains
= chain
;
1565 update_eliminable_offsets ();
1567 /* Remember for later shortcuts which insns had any reloads or
1568 register eliminations. */
1569 chain
->need_elim
= did_elimination
;
1570 chain
->need_reload
= n_reloads
> 0;
1571 chain
->need_operand_change
= operands_changed
;
1573 /* Discard any register replacements done. */
1574 if (did_elimination
)
1576 obstack_free (&reload_obstack
, reload_insn_firstobj
);
1577 PATTERN (insn
) = old_body
;
1578 INSN_CODE (insn
) = old_code
;
1579 REG_NOTES (insn
) = old_notes
;
1580 something_needs_elimination
= 1;
1583 something_needs_operands_changed
|= operands_changed
;
1587 copy_reloads (chain
);
1588 *pprev_reload
= chain
;
1589 pprev_reload
= &chain
->next_need_reload
;
1596 /* This function is called from the register allocator to set up estimates
1597 for the cost of eliminating pseudos which have REG_EQUIV equivalences to
1598 an invariant. The structure is similar to calculate_needs_all_insns. */
1601 calculate_elim_costs_all_insns (void)
1603 int *reg_equiv_init_cost
;
1607 reg_equiv_init_cost
= XCNEWVEC (int, max_regno
);
1609 init_eliminable_invariants (get_insns (), false);
1611 set_initial_elim_offsets ();
1612 set_initial_label_offsets ();
1619 FOR_BB_INSNS (bb
, insn
)
1621 /* If this is a label, a JUMP_INSN, or has REG_NOTES (which might
1622 include REG_LABEL_OPERAND and REG_LABEL_TARGET), we need to see
1623 what effects this has on the known offsets at labels. */
1625 if (LABEL_P (insn
) || JUMP_P (insn
)
1626 || (INSN_P (insn
) && REG_NOTES (insn
) != 0))
1627 set_label_offsets (insn
, insn
, 0);
1631 rtx set
= single_set (insn
);
1633 /* Skip insns that only set an equivalence. */
1634 if (set
&& REG_P (SET_DEST (set
))
1635 && reg_renumber
[REGNO (SET_DEST (set
))] < 0
1636 && (reg_equiv_constant (REGNO (SET_DEST (set
)))
1637 || reg_equiv_invariant (REGNO (SET_DEST (set
)))))
1639 unsigned regno
= REGNO (SET_DEST (set
));
1640 rtx init
= reg_equiv_init (regno
);
1643 rtx t
= eliminate_regs_1 (SET_SRC (set
), VOIDmode
, insn
,
1645 int cost
= set_src_cost (t
, optimize_bb_for_speed_p (bb
));
1646 int freq
= REG_FREQ_FROM_BB (bb
);
1648 reg_equiv_init_cost
[regno
] = cost
* freq
;
1652 /* If needed, eliminate any eliminable registers. */
1653 if (num_eliminable
|| num_eliminable_invariants
)
1654 elimination_costs_in_insn (insn
);
1657 update_eliminable_offsets ();
1661 for (i
= FIRST_PSEUDO_REGISTER
; i
< max_regno
; i
++)
1663 if (reg_equiv_invariant (i
))
1665 if (reg_equiv_init (i
))
1667 int cost
= reg_equiv_init_cost
[i
];
1670 "Reg %d has equivalence, initial gains %d\n", i
, cost
);
1672 ira_adjust_equiv_reg_cost (i
, cost
);
1678 "Reg %d had equivalence, but can't be eliminated\n",
1680 ira_adjust_equiv_reg_cost (i
, 0);
1685 free (reg_equiv_init_cost
);
1686 free (offsets_known_at
);
1689 offsets_known_at
= NULL
;
1692 /* Comparison function for qsort to decide which of two reloads
1693 should be handled first. *P1 and *P2 are the reload numbers. */
1696 reload_reg_class_lower (const void *r1p
, const void *r2p
)
1698 int r1
= *(const short *) r1p
, r2
= *(const short *) r2p
;
1701 /* Consider required reloads before optional ones. */
1702 t
= rld
[r1
].optional
- rld
[r2
].optional
;
1706 /* Count all solitary classes before non-solitary ones. */
1707 t
= ((reg_class_size
[(int) rld
[r2
].rclass
] == 1)
1708 - (reg_class_size
[(int) rld
[r1
].rclass
] == 1));
1712 /* Aside from solitaires, consider all multi-reg groups first. */
1713 t
= rld
[r2
].nregs
- rld
[r1
].nregs
;
1717 /* Consider reloads in order of increasing reg-class number. */
1718 t
= (int) rld
[r1
].rclass
- (int) rld
[r2
].rclass
;
1722 /* If reloads are equally urgent, sort by reload number,
1723 so that the results of qsort leave nothing to chance. */
1727 /* The cost of spilling each hard reg. */
1728 static int spill_cost
[FIRST_PSEUDO_REGISTER
];
1730 /* When spilling multiple hard registers, we use SPILL_COST for the first
1731 spilled hard reg and SPILL_ADD_COST for subsequent regs. SPILL_ADD_COST
1732 only the first hard reg for a multi-reg pseudo. */
1733 static int spill_add_cost
[FIRST_PSEUDO_REGISTER
];
1735 /* Map of hard regno to pseudo regno currently occupying the hard
1737 static int hard_regno_to_pseudo_regno
[FIRST_PSEUDO_REGISTER
];
1739 /* Update the spill cost arrays, considering that pseudo REG is live. */
1742 count_pseudo (int reg
)
1744 int freq
= REG_FREQ (reg
);
1745 int r
= reg_renumber
[reg
];
1748 /* Ignore spilled pseudo-registers which can be here only if IRA is used. */
1749 if (ira_conflicts_p
&& r
< 0)
1752 if (REGNO_REG_SET_P (&pseudos_counted
, reg
)
1753 || REGNO_REG_SET_P (&spilled_pseudos
, reg
))
1756 SET_REGNO_REG_SET (&pseudos_counted
, reg
);
1758 gcc_assert (r
>= 0);
1760 spill_add_cost
[r
] += freq
;
1761 nregs
= hard_regno_nregs
[r
][PSEUDO_REGNO_MODE (reg
)];
1764 hard_regno_to_pseudo_regno
[r
+ nregs
] = reg
;
1765 spill_cost
[r
+ nregs
] += freq
;
1769 /* Calculate the SPILL_COST and SPILL_ADD_COST arrays and determine the
1770 contents of BAD_SPILL_REGS for the insn described by CHAIN. */
1773 order_regs_for_reload (struct insn_chain
*chain
)
1776 HARD_REG_SET used_by_pseudos
;
1777 HARD_REG_SET used_by_pseudos2
;
1778 reg_set_iterator rsi
;
1780 COPY_HARD_REG_SET (bad_spill_regs
, fixed_reg_set
);
1782 memset (spill_cost
, 0, sizeof spill_cost
);
1783 memset (spill_add_cost
, 0, sizeof spill_add_cost
);
1784 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
1785 hard_regno_to_pseudo_regno
[i
] = -1;
1787 /* Count number of uses of each hard reg by pseudo regs allocated to it
1788 and then order them by decreasing use. First exclude hard registers
1789 that are live in or across this insn. */
1791 REG_SET_TO_HARD_REG_SET (used_by_pseudos
, &chain
->live_throughout
);
1792 REG_SET_TO_HARD_REG_SET (used_by_pseudos2
, &chain
->dead_or_set
);
1793 IOR_HARD_REG_SET (bad_spill_regs
, used_by_pseudos
);
1794 IOR_HARD_REG_SET (bad_spill_regs
, used_by_pseudos2
);
1796 /* Now find out which pseudos are allocated to it, and update
1798 CLEAR_REG_SET (&pseudos_counted
);
1800 EXECUTE_IF_SET_IN_REG_SET
1801 (&chain
->live_throughout
, FIRST_PSEUDO_REGISTER
, i
, rsi
)
1805 EXECUTE_IF_SET_IN_REG_SET
1806 (&chain
->dead_or_set
, FIRST_PSEUDO_REGISTER
, i
, rsi
)
1810 CLEAR_REG_SET (&pseudos_counted
);
1813 /* Vector of reload-numbers showing the order in which the reloads should
1815 static short reload_order
[MAX_RELOADS
];
1817 /* This is used to keep track of the spill regs used in one insn. */
1818 static HARD_REG_SET used_spill_regs_local
;
1820 /* We decided to spill hard register SPILLED, which has a size of
1821 SPILLED_NREGS. Determine how pseudo REG, which is live during the insn,
1822 is affected. We will add it to SPILLED_PSEUDOS if necessary, and we will
1823 update SPILL_COST/SPILL_ADD_COST. */
1826 count_spilled_pseudo (int spilled
, int spilled_nregs
, int reg
)
1828 int freq
= REG_FREQ (reg
);
1829 int r
= reg_renumber
[reg
];
1832 /* Ignore spilled pseudo-registers which can be here only if IRA is used. */
1833 if (ira_conflicts_p
&& r
< 0)
1836 gcc_assert (r
>= 0);
1838 nregs
= hard_regno_nregs
[r
][PSEUDO_REGNO_MODE (reg
)];
1840 if (REGNO_REG_SET_P (&spilled_pseudos
, reg
)
1841 || spilled
+ spilled_nregs
<= r
|| r
+ nregs
<= spilled
)
1844 SET_REGNO_REG_SET (&spilled_pseudos
, reg
);
1846 spill_add_cost
[r
] -= freq
;
1849 hard_regno_to_pseudo_regno
[r
+ nregs
] = -1;
1850 spill_cost
[r
+ nregs
] -= freq
;
1854 /* Find reload register to use for reload number ORDER. */
1857 find_reg (struct insn_chain
*chain
, int order
)
1859 int rnum
= reload_order
[order
];
1860 struct reload
*rl
= rld
+ rnum
;
1861 int best_cost
= INT_MAX
;
1863 unsigned int i
, j
, n
;
1865 HARD_REG_SET not_usable
;
1866 HARD_REG_SET used_by_other_reload
;
1867 reg_set_iterator rsi
;
1868 static int regno_pseudo_regs
[FIRST_PSEUDO_REGISTER
];
1869 static int best_regno_pseudo_regs
[FIRST_PSEUDO_REGISTER
];
1871 COPY_HARD_REG_SET (not_usable
, bad_spill_regs
);
1872 IOR_HARD_REG_SET (not_usable
, bad_spill_regs_global
);
1873 IOR_COMPL_HARD_REG_SET (not_usable
, reg_class_contents
[rl
->rclass
]);
1875 CLEAR_HARD_REG_SET (used_by_other_reload
);
1876 for (k
= 0; k
< order
; k
++)
1878 int other
= reload_order
[k
];
1880 if (rld
[other
].regno
>= 0 && reloads_conflict (other
, rnum
))
1881 for (j
= 0; j
< rld
[other
].nregs
; j
++)
1882 SET_HARD_REG_BIT (used_by_other_reload
, rld
[other
].regno
+ j
);
1885 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
1887 #ifdef REG_ALLOC_ORDER
1888 unsigned int regno
= reg_alloc_order
[i
];
1890 unsigned int regno
= i
;
1893 if (! TEST_HARD_REG_BIT (not_usable
, regno
)
1894 && ! TEST_HARD_REG_BIT (used_by_other_reload
, regno
)
1895 && HARD_REGNO_MODE_OK (regno
, rl
->mode
))
1897 int this_cost
= spill_cost
[regno
];
1899 unsigned int this_nregs
= hard_regno_nregs
[regno
][rl
->mode
];
1901 for (j
= 1; j
< this_nregs
; j
++)
1903 this_cost
+= spill_add_cost
[regno
+ j
];
1904 if ((TEST_HARD_REG_BIT (not_usable
, regno
+ j
))
1905 || TEST_HARD_REG_BIT (used_by_other_reload
, regno
+ j
))
1911 if (ira_conflicts_p
)
1913 /* Ask IRA to find a better pseudo-register for
1915 for (n
= j
= 0; j
< this_nregs
; j
++)
1917 int r
= hard_regno_to_pseudo_regno
[regno
+ j
];
1921 if (n
== 0 || regno_pseudo_regs
[n
- 1] != r
)
1922 regno_pseudo_regs
[n
++] = r
;
1924 regno_pseudo_regs
[n
++] = -1;
1926 || ira_better_spill_reload_regno_p (regno_pseudo_regs
,
1927 best_regno_pseudo_regs
,
1934 best_regno_pseudo_regs
[j
] = regno_pseudo_regs
[j
];
1935 if (regno_pseudo_regs
[j
] < 0)
1942 if (rl
->in
&& REG_P (rl
->in
) && REGNO (rl
->in
) == regno
)
1944 if (rl
->out
&& REG_P (rl
->out
) && REGNO (rl
->out
) == regno
)
1946 if (this_cost
< best_cost
1947 /* Among registers with equal cost, prefer caller-saved ones, or
1948 use REG_ALLOC_ORDER if it is defined. */
1949 || (this_cost
== best_cost
1950 #ifdef REG_ALLOC_ORDER
1951 && (inv_reg_alloc_order
[regno
]
1952 < inv_reg_alloc_order
[best_reg
])
1954 && call_used_regs
[regno
]
1955 && ! call_used_regs
[best_reg
]
1960 best_cost
= this_cost
;
1968 fprintf (dump_file
, "Using reg %d for reload %d\n", best_reg
, rnum
);
1970 rl
->nregs
= hard_regno_nregs
[best_reg
][rl
->mode
];
1971 rl
->regno
= best_reg
;
1973 EXECUTE_IF_SET_IN_REG_SET
1974 (&chain
->live_throughout
, FIRST_PSEUDO_REGISTER
, j
, rsi
)
1976 count_spilled_pseudo (best_reg
, rl
->nregs
, j
);
1979 EXECUTE_IF_SET_IN_REG_SET
1980 (&chain
->dead_or_set
, FIRST_PSEUDO_REGISTER
, j
, rsi
)
1982 count_spilled_pseudo (best_reg
, rl
->nregs
, j
);
1985 for (i
= 0; i
< rl
->nregs
; i
++)
1987 gcc_assert (spill_cost
[best_reg
+ i
] == 0);
1988 gcc_assert (spill_add_cost
[best_reg
+ i
] == 0);
1989 gcc_assert (hard_regno_to_pseudo_regno
[best_reg
+ i
] == -1);
1990 SET_HARD_REG_BIT (used_spill_regs_local
, best_reg
+ i
);
1995 /* Find more reload regs to satisfy the remaining need of an insn, which
1997 Do it by ascending class number, since otherwise a reg
1998 might be spilled for a big class and might fail to count
1999 for a smaller class even though it belongs to that class. */
2002 find_reload_regs (struct insn_chain
*chain
)
2006 /* In order to be certain of getting the registers we need,
2007 we must sort the reloads into order of increasing register class.
2008 Then our grabbing of reload registers will parallel the process
2009 that provided the reload registers. */
2010 for (i
= 0; i
< chain
->n_reloads
; i
++)
2012 /* Show whether this reload already has a hard reg. */
2013 if (chain
->rld
[i
].reg_rtx
)
2015 int regno
= REGNO (chain
->rld
[i
].reg_rtx
);
2016 chain
->rld
[i
].regno
= regno
;
2018 = hard_regno_nregs
[regno
][GET_MODE (chain
->rld
[i
].reg_rtx
)];
2021 chain
->rld
[i
].regno
= -1;
2022 reload_order
[i
] = i
;
2025 n_reloads
= chain
->n_reloads
;
2026 memcpy (rld
, chain
->rld
, n_reloads
* sizeof (struct reload
));
2028 CLEAR_HARD_REG_SET (used_spill_regs_local
);
2031 fprintf (dump_file
, "Spilling for insn %d.\n", INSN_UID (chain
->insn
));
2033 qsort (reload_order
, n_reloads
, sizeof (short), reload_reg_class_lower
);
2035 /* Compute the order of preference for hard registers to spill. */
2037 order_regs_for_reload (chain
);
2039 for (i
= 0; i
< n_reloads
; i
++)
2041 int r
= reload_order
[i
];
2043 /* Ignore reloads that got marked inoperative. */
2044 if ((rld
[r
].out
!= 0 || rld
[r
].in
!= 0 || rld
[r
].secondary_p
)
2045 && ! rld
[r
].optional
2046 && rld
[r
].regno
== -1)
2047 if (! find_reg (chain
, i
))
2050 fprintf (dump_file
, "reload failure for reload %d\n", r
);
2051 spill_failure (chain
->insn
, rld
[r
].rclass
);
2057 COPY_HARD_REG_SET (chain
->used_spill_regs
, used_spill_regs_local
);
2058 IOR_HARD_REG_SET (used_spill_regs
, used_spill_regs_local
);
2060 memcpy (chain
->rld
, rld
, n_reloads
* sizeof (struct reload
));
2064 select_reload_regs (void)
2066 struct insn_chain
*chain
;
2068 /* Try to satisfy the needs for each insn. */
2069 for (chain
= insns_need_reload
; chain
!= 0;
2070 chain
= chain
->next_need_reload
)
2071 find_reload_regs (chain
);
2074 /* Delete all insns that were inserted by emit_caller_save_insns during
2077 delete_caller_save_insns (void)
2079 struct insn_chain
*c
= reload_insn_chain
;
2083 while (c
!= 0 && c
->is_caller_save_insn
)
2085 struct insn_chain
*next
= c
->next
;
2088 if (c
== reload_insn_chain
)
2089 reload_insn_chain
= next
;
2093 next
->prev
= c
->prev
;
2095 c
->prev
->next
= next
;
2096 c
->next
= unused_insn_chains
;
2097 unused_insn_chains
= c
;
2105 /* Handle the failure to find a register to spill.
2106 INSN should be one of the insns which needed this particular spill reg. */
2109 spill_failure (rtx insn
, enum reg_class rclass
)
2111 if (asm_noperands (PATTERN (insn
)) >= 0)
2112 error_for_asm (insn
, "can%'t find a register in class %qs while "
2113 "reloading %<asm%>",
2114 reg_class_names
[rclass
]);
2117 error ("unable to find a register to spill in class %qs",
2118 reg_class_names
[rclass
]);
2122 fprintf (dump_file
, "\nReloads for insn # %d\n", INSN_UID (insn
));
2123 debug_reload_to_stream (dump_file
);
2125 fatal_insn ("this is the insn:", insn
);
2129 /* Delete an unneeded INSN and any previous insns who sole purpose is loading
2130 data that is dead in INSN. */
2133 delete_dead_insn (rtx insn
)
2135 rtx prev
= prev_active_insn (insn
);
2138 /* If the previous insn sets a register that dies in our insn make
2139 a note that we want to run DCE immediately after reload.
2141 We used to delete the previous insn & recurse, but that's wrong for
2142 block local equivalences. Instead of trying to figure out the exact
2143 circumstances where we can delete the potentially dead insns, just
2144 let DCE do the job. */
2145 if (prev
&& GET_CODE (PATTERN (prev
)) == SET
2146 && (prev_dest
= SET_DEST (PATTERN (prev
)), REG_P (prev_dest
))
2147 && reg_mentioned_p (prev_dest
, PATTERN (insn
))
2148 && find_regno_note (insn
, REG_DEAD
, REGNO (prev_dest
))
2149 && ! side_effects_p (SET_SRC (PATTERN (prev
))))
2152 SET_INSN_DELETED (insn
);
2155 /* Modify the home of pseudo-reg I.
2156 The new home is present in reg_renumber[I].
2158 FROM_REG may be the hard reg that the pseudo-reg is being spilled from;
2159 or it may be -1, meaning there is none or it is not relevant.
2160 This is used so that all pseudos spilled from a given hard reg
2161 can share one stack slot. */
2164 alter_reg (int i
, int from_reg
, bool dont_share_p
)
2166 /* When outputting an inline function, this can happen
2167 for a reg that isn't actually used. */
2168 if (regno_reg_rtx
[i
] == 0)
2171 /* If the reg got changed to a MEM at rtl-generation time,
2173 if (!REG_P (regno_reg_rtx
[i
]))
2176 /* Modify the reg-rtx to contain the new hard reg
2177 number or else to contain its pseudo reg number. */
2178 SET_REGNO (regno_reg_rtx
[i
],
2179 reg_renumber
[i
] >= 0 ? reg_renumber
[i
] : i
);
2181 /* If we have a pseudo that is needed but has no hard reg or equivalent,
2182 allocate a stack slot for it. */
2184 if (reg_renumber
[i
] < 0
2185 && REG_N_REFS (i
) > 0
2186 && reg_equiv_constant (i
) == 0
2187 && (reg_equiv_invariant (i
) == 0
2188 || reg_equiv_init (i
) == 0)
2189 && reg_equiv_memory_loc (i
) == 0)
2192 enum machine_mode mode
= GET_MODE (regno_reg_rtx
[i
]);
2193 unsigned int inherent_size
= PSEUDO_REGNO_BYTES (i
);
2194 unsigned int inherent_align
= GET_MODE_ALIGNMENT (mode
);
2195 unsigned int total_size
= MAX (inherent_size
, reg_max_ref_width
[i
]);
2196 unsigned int min_align
= reg_max_ref_width
[i
] * BITS_PER_UNIT
;
2199 something_was_spilled
= true;
2201 if (ira_conflicts_p
)
2203 /* Mark the spill for IRA. */
2204 SET_REGNO_REG_SET (&spilled_pseudos
, i
);
2206 x
= ira_reuse_stack_slot (i
, inherent_size
, total_size
);
2212 /* Each pseudo reg has an inherent size which comes from its own mode,
2213 and a total size which provides room for paradoxical subregs
2214 which refer to the pseudo reg in wider modes.
2216 We can use a slot already allocated if it provides both
2217 enough inherent space and enough total space.
2218 Otherwise, we allocate a new slot, making sure that it has no less
2219 inherent space, and no less total space, then the previous slot. */
2220 else if (from_reg
== -1 || (!dont_share_p
&& ira_conflicts_p
))
2224 /* No known place to spill from => no slot to reuse. */
2225 x
= assign_stack_local (mode
, total_size
,
2226 min_align
> inherent_align
2227 || total_size
> inherent_size
? -1 : 0);
2231 /* Cancel the big-endian correction done in assign_stack_local.
2232 Get the address of the beginning of the slot. This is so we
2233 can do a big-endian correction unconditionally below. */
2234 if (BYTES_BIG_ENDIAN
)
2236 adjust
= inherent_size
- total_size
;
2239 = adjust_address_nv (x
, mode_for_size (total_size
2245 if (! dont_share_p
&& ira_conflicts_p
)
2246 /* Inform IRA about allocation a new stack slot. */
2247 ira_mark_new_stack_slot (stack_slot
, i
, total_size
);
2250 /* Reuse a stack slot if possible. */
2251 else if (spill_stack_slot
[from_reg
] != 0
2252 && spill_stack_slot_width
[from_reg
] >= total_size
2253 && (GET_MODE_SIZE (GET_MODE (spill_stack_slot
[from_reg
]))
2255 && MEM_ALIGN (spill_stack_slot
[from_reg
]) >= min_align
)
2256 x
= spill_stack_slot
[from_reg
];
2258 /* Allocate a bigger slot. */
2261 /* Compute maximum size needed, both for inherent size
2262 and for total size. */
2265 if (spill_stack_slot
[from_reg
])
2267 if (GET_MODE_SIZE (GET_MODE (spill_stack_slot
[from_reg
]))
2269 mode
= GET_MODE (spill_stack_slot
[from_reg
]);
2270 if (spill_stack_slot_width
[from_reg
] > total_size
)
2271 total_size
= spill_stack_slot_width
[from_reg
];
2272 if (MEM_ALIGN (spill_stack_slot
[from_reg
]) > min_align
)
2273 min_align
= MEM_ALIGN (spill_stack_slot
[from_reg
]);
2276 /* Make a slot with that size. */
2277 x
= assign_stack_local (mode
, total_size
,
2278 min_align
> inherent_align
2279 || total_size
> inherent_size
? -1 : 0);
2282 /* Cancel the big-endian correction done in assign_stack_local.
2283 Get the address of the beginning of the slot. This is so we
2284 can do a big-endian correction unconditionally below. */
2285 if (BYTES_BIG_ENDIAN
)
2287 adjust
= GET_MODE_SIZE (mode
) - total_size
;
2290 = adjust_address_nv (x
, mode_for_size (total_size
2296 spill_stack_slot
[from_reg
] = stack_slot
;
2297 spill_stack_slot_width
[from_reg
] = total_size
;
2300 /* On a big endian machine, the "address" of the slot
2301 is the address of the low part that fits its inherent mode. */
2302 if (BYTES_BIG_ENDIAN
&& inherent_size
< total_size
)
2303 adjust
+= (total_size
- inherent_size
);
2305 /* If we have any adjustment to make, or if the stack slot is the
2306 wrong mode, make a new stack slot. */
2307 x
= adjust_address_nv (x
, GET_MODE (regno_reg_rtx
[i
]), adjust
);
2309 /* Set all of the memory attributes as appropriate for a spill. */
2310 set_mem_attrs_for_spill (x
);
2312 /* Save the stack slot for later. */
2313 reg_equiv_memory_loc (i
) = x
;
2317 /* Mark the slots in regs_ever_live for the hard regs used by
2318 pseudo-reg number REGNO, accessed in MODE. */
2321 mark_home_live_1 (int regno
, enum machine_mode mode
)
2325 i
= reg_renumber
[regno
];
2328 lim
= end_hard_regno (mode
, i
);
2330 df_set_regs_ever_live(i
++, true);
2333 /* Mark the slots in regs_ever_live for the hard regs
2334 used by pseudo-reg number REGNO. */
2337 mark_home_live (int regno
)
2339 if (reg_renumber
[regno
] >= 0)
2340 mark_home_live_1 (regno
, PSEUDO_REGNO_MODE (regno
));
2343 /* This function handles the tracking of elimination offsets around branches.
2345 X is a piece of RTL being scanned.
2347 INSN is the insn that it came from, if any.
2349 INITIAL_P is nonzero if we are to set the offset to be the initial
2350 offset and zero if we are setting the offset of the label to be the
2354 set_label_offsets (rtx x
, rtx insn
, int initial_p
)
2356 enum rtx_code code
= GET_CODE (x
);
2359 struct elim_table
*p
;
2364 if (LABEL_REF_NONLOCAL_P (x
))
2369 /* ... fall through ... */
2372 /* If we know nothing about this label, set the desired offsets. Note
2373 that this sets the offset at a label to be the offset before a label
2374 if we don't know anything about the label. This is not correct for
2375 the label after a BARRIER, but is the best guess we can make. If
2376 we guessed wrong, we will suppress an elimination that might have
2377 been possible had we been able to guess correctly. */
2379 if (! offsets_known_at
[CODE_LABEL_NUMBER (x
) - first_label_num
])
2381 for (i
= 0; i
< NUM_ELIMINABLE_REGS
; i
++)
2382 offsets_at
[CODE_LABEL_NUMBER (x
) - first_label_num
][i
]
2383 = (initial_p
? reg_eliminate
[i
].initial_offset
2384 : reg_eliminate
[i
].offset
);
2385 offsets_known_at
[CODE_LABEL_NUMBER (x
) - first_label_num
] = 1;
2388 /* Otherwise, if this is the definition of a label and it is
2389 preceded by a BARRIER, set our offsets to the known offset of
2393 && (tem
= prev_nonnote_insn (insn
)) != 0
2395 set_offsets_for_label (insn
);
2397 /* If neither of the above cases is true, compare each offset
2398 with those previously recorded and suppress any eliminations
2399 where the offsets disagree. */
2401 for (i
= 0; i
< NUM_ELIMINABLE_REGS
; i
++)
2402 if (offsets_at
[CODE_LABEL_NUMBER (x
) - first_label_num
][i
]
2403 != (initial_p
? reg_eliminate
[i
].initial_offset
2404 : reg_eliminate
[i
].offset
))
2405 reg_eliminate
[i
].can_eliminate
= 0;
2410 set_label_offsets (PATTERN (insn
), insn
, initial_p
);
2412 /* ... fall through ... */
2416 /* Any labels mentioned in REG_LABEL_OPERAND notes can be branched
2417 to indirectly and hence must have all eliminations at their
2419 for (tem
= REG_NOTES (x
); tem
; tem
= XEXP (tem
, 1))
2420 if (REG_NOTE_KIND (tem
) == REG_LABEL_OPERAND
)
2421 set_label_offsets (XEXP (tem
, 0), insn
, 1);
2427 /* Each of the labels in the parallel or address vector must be
2428 at their initial offsets. We want the first field for PARALLEL
2429 and ADDR_VEC and the second field for ADDR_DIFF_VEC. */
2431 for (i
= 0; i
< (unsigned) XVECLEN (x
, code
== ADDR_DIFF_VEC
); i
++)
2432 set_label_offsets (XVECEXP (x
, code
== ADDR_DIFF_VEC
, i
),
2437 /* We only care about setting PC. If the source is not RETURN,
2438 IF_THEN_ELSE, or a label, disable any eliminations not at
2439 their initial offsets. Similarly if any arm of the IF_THEN_ELSE
2440 isn't one of those possibilities. For branches to a label,
2441 call ourselves recursively.
2443 Note that this can disable elimination unnecessarily when we have
2444 a non-local goto since it will look like a non-constant jump to
2445 someplace in the current function. This isn't a significant
2446 problem since such jumps will normally be when all elimination
2447 pairs are back to their initial offsets. */
2449 if (SET_DEST (x
) != pc_rtx
)
2452 switch (GET_CODE (SET_SRC (x
)))
2459 set_label_offsets (SET_SRC (x
), insn
, initial_p
);
2463 tem
= XEXP (SET_SRC (x
), 1);
2464 if (GET_CODE (tem
) == LABEL_REF
)
2465 set_label_offsets (XEXP (tem
, 0), insn
, initial_p
);
2466 else if (GET_CODE (tem
) != PC
&& GET_CODE (tem
) != RETURN
)
2469 tem
= XEXP (SET_SRC (x
), 2);
2470 if (GET_CODE (tem
) == LABEL_REF
)
2471 set_label_offsets (XEXP (tem
, 0), insn
, initial_p
);
2472 else if (GET_CODE (tem
) != PC
&& GET_CODE (tem
) != RETURN
)
2480 /* If we reach here, all eliminations must be at their initial
2481 offset because we are doing a jump to a variable address. */
2482 for (p
= reg_eliminate
; p
< ®_eliminate
[NUM_ELIMINABLE_REGS
]; p
++)
2483 if (p
->offset
!= p
->initial_offset
)
2484 p
->can_eliminate
= 0;
2492 /* Called through for_each_rtx, this function examines every reg that occurs
2493 in PX and adjusts the costs for its elimination which are gathered by IRA.
2494 DATA is the insn in which PX occurs. We do not recurse into MEM
2498 note_reg_elim_costly (rtx
*px
, void *data
)
2500 rtx insn
= (rtx
)data
;
2507 && REGNO (x
) >= FIRST_PSEUDO_REGISTER
2508 && reg_equiv_init (REGNO (x
))
2509 && reg_equiv_invariant (REGNO (x
)))
2511 rtx t
= reg_equiv_invariant (REGNO (x
));
2512 rtx new_rtx
= eliminate_regs_1 (t
, Pmode
, insn
, true, true);
2513 int cost
= set_src_cost (new_rtx
, optimize_bb_for_speed_p (elim_bb
));
2514 int freq
= REG_FREQ_FROM_BB (elim_bb
);
2517 ira_adjust_equiv_reg_cost (REGNO (x
), -cost
* freq
);
2522 /* Scan X and replace any eliminable registers (such as fp) with a
2523 replacement (such as sp), plus an offset.
2525 MEM_MODE is the mode of an enclosing MEM. We need this to know how
2526 much to adjust a register for, e.g., PRE_DEC. Also, if we are inside a
2527 MEM, we are allowed to replace a sum of a register and the constant zero
2528 with the register, which we cannot do outside a MEM. In addition, we need
2529 to record the fact that a register is referenced outside a MEM.
2531 If INSN is an insn, it is the insn containing X. If we replace a REG
2532 in a SET_DEST with an equivalent MEM and INSN is nonzero, write a
2533 CLOBBER of the pseudo after INSN so find_equiv_regs will know that
2534 the REG is being modified.
2536 Alternatively, INSN may be a note (an EXPR_LIST or INSN_LIST).
2537 That's used when we eliminate in expressions stored in notes.
2538 This means, do not set ref_outside_mem even if the reference
2541 If FOR_COSTS is true, we are being called before reload in order to
2542 estimate the costs of keeping registers with an equivalence unallocated.
2544 REG_EQUIV_MEM and REG_EQUIV_ADDRESS contain address that have had
2545 replacements done assuming all offsets are at their initial values. If
2546 they are not, or if REG_EQUIV_ADDRESS is nonzero for a pseudo we
2547 encounter, return the actual location so that find_reloads will do
2548 the proper thing. */
2551 eliminate_regs_1 (rtx x
, enum machine_mode mem_mode
, rtx insn
,
2552 bool may_use_invariant
, bool for_costs
)
2554 enum rtx_code code
= GET_CODE (x
);
2555 struct elim_table
*ep
;
2562 if (! current_function_decl
)
2585 /* First handle the case where we encounter a bare register that
2586 is eliminable. Replace it with a PLUS. */
2587 if (regno
< FIRST_PSEUDO_REGISTER
)
2589 for (ep
= reg_eliminate
; ep
< ®_eliminate
[NUM_ELIMINABLE_REGS
];
2591 if (ep
->from_rtx
== x
&& ep
->can_eliminate
)
2592 return plus_constant (Pmode
, ep
->to_rtx
, ep
->previous_offset
);
2595 else if (reg_renumber
&& reg_renumber
[regno
] < 0
2597 && reg_equiv_invariant (regno
))
2599 if (may_use_invariant
|| (insn
&& DEBUG_INSN_P (insn
)))
2600 return eliminate_regs_1 (copy_rtx (reg_equiv_invariant (regno
)),
2601 mem_mode
, insn
, true, for_costs
);
2602 /* There exists at least one use of REGNO that cannot be
2603 eliminated. Prevent the defining insn from being deleted. */
2604 reg_equiv_init (regno
) = NULL_RTX
;
2606 alter_reg (regno
, -1, true);
2610 /* You might think handling MINUS in a manner similar to PLUS is a
2611 good idea. It is not. It has been tried multiple times and every
2612 time the change has had to have been reverted.
2614 Other parts of reload know a PLUS is special (gen_reload for example)
2615 and require special code to handle code a reloaded PLUS operand.
2617 Also consider backends where the flags register is clobbered by a
2618 MINUS, but we can emit a PLUS that does not clobber flags (IA-32,
2619 lea instruction comes to mind). If we try to reload a MINUS, we
2620 may kill the flags register that was holding a useful value.
2622 So, please before trying to handle MINUS, consider reload as a
2623 whole instead of this little section as well as the backend issues. */
2625 /* If this is the sum of an eliminable register and a constant, rework
2627 if (REG_P (XEXP (x
, 0))
2628 && REGNO (XEXP (x
, 0)) < FIRST_PSEUDO_REGISTER
2629 && CONSTANT_P (XEXP (x
, 1)))
2631 for (ep
= reg_eliminate
; ep
< ®_eliminate
[NUM_ELIMINABLE_REGS
];
2633 if (ep
->from_rtx
== XEXP (x
, 0) && ep
->can_eliminate
)
2635 /* The only time we want to replace a PLUS with a REG (this
2636 occurs when the constant operand of the PLUS is the negative
2637 of the offset) is when we are inside a MEM. We won't want
2638 to do so at other times because that would change the
2639 structure of the insn in a way that reload can't handle.
2640 We special-case the commonest situation in
2641 eliminate_regs_in_insn, so just replace a PLUS with a
2642 PLUS here, unless inside a MEM. */
2643 if (mem_mode
!= 0 && CONST_INT_P (XEXP (x
, 1))
2644 && INTVAL (XEXP (x
, 1)) == - ep
->previous_offset
)
2647 return gen_rtx_PLUS (Pmode
, ep
->to_rtx
,
2648 plus_constant (Pmode
, XEXP (x
, 1),
2649 ep
->previous_offset
));
2652 /* If the register is not eliminable, we are done since the other
2653 operand is a constant. */
2657 /* If this is part of an address, we want to bring any constant to the
2658 outermost PLUS. We will do this by doing register replacement in
2659 our operands and seeing if a constant shows up in one of them.
2661 Note that there is no risk of modifying the structure of the insn,
2662 since we only get called for its operands, thus we are either
2663 modifying the address inside a MEM, or something like an address
2664 operand of a load-address insn. */
2667 rtx new0
= eliminate_regs_1 (XEXP (x
, 0), mem_mode
, insn
, true,
2669 rtx new1
= eliminate_regs_1 (XEXP (x
, 1), mem_mode
, insn
, true,
2672 if (reg_renumber
&& (new0
!= XEXP (x
, 0) || new1
!= XEXP (x
, 1)))
2674 /* If one side is a PLUS and the other side is a pseudo that
2675 didn't get a hard register but has a reg_equiv_constant,
2676 we must replace the constant here since it may no longer
2677 be in the position of any operand. */
2678 if (GET_CODE (new0
) == PLUS
&& REG_P (new1
)
2679 && REGNO (new1
) >= FIRST_PSEUDO_REGISTER
2680 && reg_renumber
[REGNO (new1
)] < 0
2682 && reg_equiv_constant (REGNO (new1
)) != 0)
2683 new1
= reg_equiv_constant (REGNO (new1
));
2684 else if (GET_CODE (new1
) == PLUS
&& REG_P (new0
)
2685 && REGNO (new0
) >= FIRST_PSEUDO_REGISTER
2686 && reg_renumber
[REGNO (new0
)] < 0
2687 && reg_equiv_constant (REGNO (new0
)) != 0)
2688 new0
= reg_equiv_constant (REGNO (new0
));
2690 new_rtx
= form_sum (GET_MODE (x
), new0
, new1
);
2692 /* As above, if we are not inside a MEM we do not want to
2693 turn a PLUS into something else. We might try to do so here
2694 for an addition of 0 if we aren't optimizing. */
2695 if (! mem_mode
&& GET_CODE (new_rtx
) != PLUS
)
2696 return gen_rtx_PLUS (GET_MODE (x
), new_rtx
, const0_rtx
);
2704 /* If this is the product of an eliminable register and a
2705 constant, apply the distribute law and move the constant out
2706 so that we have (plus (mult ..) ..). This is needed in order
2707 to keep load-address insns valid. This case is pathological.
2708 We ignore the possibility of overflow here. */
2709 if (REG_P (XEXP (x
, 0))
2710 && REGNO (XEXP (x
, 0)) < FIRST_PSEUDO_REGISTER
2711 && CONST_INT_P (XEXP (x
, 1)))
2712 for (ep
= reg_eliminate
; ep
< ®_eliminate
[NUM_ELIMINABLE_REGS
];
2714 if (ep
->from_rtx
== XEXP (x
, 0) && ep
->can_eliminate
)
2717 /* Refs inside notes or in DEBUG_INSNs don't count for
2719 && ! (insn
!= 0 && (GET_CODE (insn
) == EXPR_LIST
2720 || GET_CODE (insn
) == INSN_LIST
2721 || DEBUG_INSN_P (insn
))))
2722 ep
->ref_outside_mem
= 1;
2725 plus_constant (Pmode
,
2726 gen_rtx_MULT (Pmode
, ep
->to_rtx
, XEXP (x
, 1)),
2727 ep
->previous_offset
* INTVAL (XEXP (x
, 1)));
2730 /* ... fall through ... */
2734 /* See comments before PLUS about handling MINUS. */
2736 case DIV
: case UDIV
:
2737 case MOD
: case UMOD
:
2738 case AND
: case IOR
: case XOR
:
2739 case ROTATERT
: case ROTATE
:
2740 case ASHIFTRT
: case LSHIFTRT
: case ASHIFT
:
2742 case GE
: case GT
: case GEU
: case GTU
:
2743 case LE
: case LT
: case LEU
: case LTU
:
2745 rtx new0
= eliminate_regs_1 (XEXP (x
, 0), mem_mode
, insn
, false,
2747 rtx new1
= XEXP (x
, 1)
2748 ? eliminate_regs_1 (XEXP (x
, 1), mem_mode
, insn
, false,
2751 if (new0
!= XEXP (x
, 0) || new1
!= XEXP (x
, 1))
2752 return gen_rtx_fmt_ee (code
, GET_MODE (x
), new0
, new1
);
2757 /* If we have something in XEXP (x, 0), the usual case, eliminate it. */
2760 new_rtx
= eliminate_regs_1 (XEXP (x
, 0), mem_mode
, insn
, true,
2762 if (new_rtx
!= XEXP (x
, 0))
2764 /* If this is a REG_DEAD note, it is not valid anymore.
2765 Using the eliminated version could result in creating a
2766 REG_DEAD note for the stack or frame pointer. */
2767 if (REG_NOTE_KIND (x
) == REG_DEAD
)
2769 ? eliminate_regs_1 (XEXP (x
, 1), mem_mode
, insn
, true,
2773 x
= alloc_reg_note (REG_NOTE_KIND (x
), new_rtx
, XEXP (x
, 1));
2777 /* ... fall through ... */
2780 /* Now do eliminations in the rest of the chain. If this was
2781 an EXPR_LIST, this might result in allocating more memory than is
2782 strictly needed, but it simplifies the code. */
2785 new_rtx
= eliminate_regs_1 (XEXP (x
, 1), mem_mode
, insn
, true,
2787 if (new_rtx
!= XEXP (x
, 1))
2789 gen_rtx_fmt_ee (GET_CODE (x
), GET_MODE (x
), XEXP (x
, 0), new_rtx
);
2797 /* We do not support elimination of a register that is modified.
2798 elimination_effects has already make sure that this does not
2804 /* We do not support elimination of a register that is modified.
2805 elimination_effects has already make sure that this does not
2806 happen. The only remaining case we need to consider here is
2807 that the increment value may be an eliminable register. */
2808 if (GET_CODE (XEXP (x
, 1)) == PLUS
2809 && XEXP (XEXP (x
, 1), 0) == XEXP (x
, 0))
2811 rtx new_rtx
= eliminate_regs_1 (XEXP (XEXP (x
, 1), 1), mem_mode
,
2812 insn
, true, for_costs
);
2814 if (new_rtx
!= XEXP (XEXP (x
, 1), 1))
2815 return gen_rtx_fmt_ee (code
, GET_MODE (x
), XEXP (x
, 0),
2816 gen_rtx_PLUS (GET_MODE (x
),
2817 XEXP (x
, 0), new_rtx
));
2821 case STRICT_LOW_PART
:
2823 case SIGN_EXTEND
: case ZERO_EXTEND
:
2824 case TRUNCATE
: case FLOAT_EXTEND
: case FLOAT_TRUNCATE
:
2825 case FLOAT
: case FIX
:
2826 case UNSIGNED_FIX
: case UNSIGNED_FLOAT
:
2835 new_rtx
= eliminate_regs_1 (XEXP (x
, 0), mem_mode
, insn
, false,
2837 if (new_rtx
!= XEXP (x
, 0))
2838 return gen_rtx_fmt_e (code
, GET_MODE (x
), new_rtx
);
2842 /* Similar to above processing, but preserve SUBREG_BYTE.
2843 Convert (subreg (mem)) to (mem) if not paradoxical.
2844 Also, if we have a non-paradoxical (subreg (pseudo)) and the
2845 pseudo didn't get a hard reg, we must replace this with the
2846 eliminated version of the memory location because push_reload
2847 may do the replacement in certain circumstances. */
2848 if (REG_P (SUBREG_REG (x
))
2849 && !paradoxical_subreg_p (x
)
2851 && reg_equiv_memory_loc (REGNO (SUBREG_REG (x
))) != 0)
2853 new_rtx
= SUBREG_REG (x
);
2856 new_rtx
= eliminate_regs_1 (SUBREG_REG (x
), mem_mode
, insn
, false, for_costs
);
2858 if (new_rtx
!= SUBREG_REG (x
))
2860 int x_size
= GET_MODE_SIZE (GET_MODE (x
));
2861 int new_size
= GET_MODE_SIZE (GET_MODE (new_rtx
));
2864 && ((x_size
< new_size
2865 #ifdef WORD_REGISTER_OPERATIONS
2866 /* On these machines, combine can create rtl of the form
2867 (set (subreg:m1 (reg:m2 R) 0) ...)
2868 where m1 < m2, and expects something interesting to
2869 happen to the entire word. Moreover, it will use the
2870 (reg:m2 R) later, expecting all bits to be preserved.
2871 So if the number of words is the same, preserve the
2872 subreg so that push_reload can see it. */
2873 && ! ((x_size
- 1) / UNITS_PER_WORD
2874 == (new_size
-1 ) / UNITS_PER_WORD
)
2877 || x_size
== new_size
)
2879 return adjust_address_nv (new_rtx
, GET_MODE (x
), SUBREG_BYTE (x
));
2881 return gen_rtx_SUBREG (GET_MODE (x
), new_rtx
, SUBREG_BYTE (x
));
2887 /* Our only special processing is to pass the mode of the MEM to our
2888 recursive call and copy the flags. While we are here, handle this
2889 case more efficiently. */
2891 new_rtx
= eliminate_regs_1 (XEXP (x
, 0), GET_MODE (x
), insn
, true,
2894 && memory_address_p (GET_MODE (x
), XEXP (x
, 0))
2895 && !memory_address_p (GET_MODE (x
), new_rtx
))
2896 for_each_rtx (&XEXP (x
, 0), note_reg_elim_costly
, insn
);
2898 return replace_equiv_address_nv (x
, new_rtx
);
2901 /* Handle insn_list USE that a call to a pure function may generate. */
2902 new_rtx
= eliminate_regs_1 (XEXP (x
, 0), VOIDmode
, insn
, false,
2904 if (new_rtx
!= XEXP (x
, 0))
2905 return gen_rtx_USE (GET_MODE (x
), new_rtx
);
2910 gcc_assert (insn
&& DEBUG_INSN_P (insn
));
2920 /* Process each of our operands recursively. If any have changed, make a
2922 fmt
= GET_RTX_FORMAT (code
);
2923 for (i
= 0; i
< GET_RTX_LENGTH (code
); i
++, fmt
++)
2927 new_rtx
= eliminate_regs_1 (XEXP (x
, i
), mem_mode
, insn
, false,
2929 if (new_rtx
!= XEXP (x
, i
) && ! copied
)
2931 x
= shallow_copy_rtx (x
);
2934 XEXP (x
, i
) = new_rtx
;
2936 else if (*fmt
== 'E')
2939 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
2941 new_rtx
= eliminate_regs_1 (XVECEXP (x
, i
, j
), mem_mode
, insn
, false,
2943 if (new_rtx
!= XVECEXP (x
, i
, j
) && ! copied_vec
)
2945 rtvec new_v
= gen_rtvec_v (XVECLEN (x
, i
),
2949 x
= shallow_copy_rtx (x
);
2952 XVEC (x
, i
) = new_v
;
2955 XVECEXP (x
, i
, j
) = new_rtx
;
2964 eliminate_regs (rtx x
, enum machine_mode mem_mode
, rtx insn
)
2966 return eliminate_regs_1 (x
, mem_mode
, insn
, false, false);
2969 /* Scan rtx X for modifications of elimination target registers. Update
2970 the table of eliminables to reflect the changed state. MEM_MODE is
2971 the mode of an enclosing MEM rtx, or VOIDmode if not within a MEM. */
2974 elimination_effects (rtx x
, enum machine_mode mem_mode
)
2976 enum rtx_code code
= GET_CODE (x
);
2977 struct elim_table
*ep
;
3002 /* First handle the case where we encounter a bare register that
3003 is eliminable. Replace it with a PLUS. */
3004 if (regno
< FIRST_PSEUDO_REGISTER
)
3006 for (ep
= reg_eliminate
; ep
< ®_eliminate
[NUM_ELIMINABLE_REGS
];
3008 if (ep
->from_rtx
== x
&& ep
->can_eliminate
)
3011 ep
->ref_outside_mem
= 1;
3016 else if (reg_renumber
[regno
] < 0
3018 && reg_equiv_constant (regno
)
3019 && ! function_invariant_p (reg_equiv_constant (regno
)))
3020 elimination_effects (reg_equiv_constant (regno
), mem_mode
);
3029 /* If we modify the source of an elimination rule, disable it. */
3030 for (ep
= reg_eliminate
; ep
< ®_eliminate
[NUM_ELIMINABLE_REGS
]; ep
++)
3031 if (ep
->from_rtx
== XEXP (x
, 0))
3032 ep
->can_eliminate
= 0;
3034 /* If we modify the target of an elimination rule by adding a constant,
3035 update its offset. If we modify the target in any other way, we'll
3036 have to disable the rule as well. */
3037 for (ep
= reg_eliminate
; ep
< ®_eliminate
[NUM_ELIMINABLE_REGS
]; ep
++)
3038 if (ep
->to_rtx
== XEXP (x
, 0))
3040 int size
= GET_MODE_SIZE (mem_mode
);
3042 /* If more bytes than MEM_MODE are pushed, account for them. */
3043 #ifdef PUSH_ROUNDING
3044 if (ep
->to_rtx
== stack_pointer_rtx
)
3045 size
= PUSH_ROUNDING (size
);
3047 if (code
== PRE_DEC
|| code
== POST_DEC
)
3049 else if (code
== PRE_INC
|| code
== POST_INC
)
3051 else if (code
== PRE_MODIFY
|| code
== POST_MODIFY
)
3053 if (GET_CODE (XEXP (x
, 1)) == PLUS
3054 && XEXP (x
, 0) == XEXP (XEXP (x
, 1), 0)
3055 && CONST_INT_P (XEXP (XEXP (x
, 1), 1)))
3056 ep
->offset
-= INTVAL (XEXP (XEXP (x
, 1), 1));
3058 ep
->can_eliminate
= 0;
3062 /* These two aren't unary operators. */
3063 if (code
== POST_MODIFY
|| code
== PRE_MODIFY
)
3066 /* Fall through to generic unary operation case. */
3067 case STRICT_LOW_PART
:
3069 case SIGN_EXTEND
: case ZERO_EXTEND
:
3070 case TRUNCATE
: case FLOAT_EXTEND
: case FLOAT_TRUNCATE
:
3071 case FLOAT
: case FIX
:
3072 case UNSIGNED_FIX
: case UNSIGNED_FLOAT
:
3081 elimination_effects (XEXP (x
, 0), mem_mode
);
3085 if (REG_P (SUBREG_REG (x
))
3086 && (GET_MODE_SIZE (GET_MODE (x
))
3087 <= GET_MODE_SIZE (GET_MODE (SUBREG_REG (x
))))
3089 && reg_equiv_memory_loc (REGNO (SUBREG_REG (x
))) != 0)
3092 elimination_effects (SUBREG_REG (x
), mem_mode
);
3096 /* If using a register that is the source of an eliminate we still
3097 think can be performed, note it cannot be performed since we don't
3098 know how this register is used. */
3099 for (ep
= reg_eliminate
; ep
< ®_eliminate
[NUM_ELIMINABLE_REGS
]; ep
++)
3100 if (ep
->from_rtx
== XEXP (x
, 0))
3101 ep
->can_eliminate
= 0;
3103 elimination_effects (XEXP (x
, 0), mem_mode
);
3107 /* If clobbering a register that is the replacement register for an
3108 elimination we still think can be performed, note that it cannot
3109 be performed. Otherwise, we need not be concerned about it. */
3110 for (ep
= reg_eliminate
; ep
< ®_eliminate
[NUM_ELIMINABLE_REGS
]; ep
++)
3111 if (ep
->to_rtx
== XEXP (x
, 0))
3112 ep
->can_eliminate
= 0;
3114 elimination_effects (XEXP (x
, 0), mem_mode
);
3118 /* Check for setting a register that we know about. */
3119 if (REG_P (SET_DEST (x
)))
3121 /* See if this is setting the replacement register for an
3124 If DEST is the hard frame pointer, we do nothing because we
3125 assume that all assignments to the frame pointer are for
3126 non-local gotos and are being done at a time when they are valid
3127 and do not disturb anything else. Some machines want to
3128 eliminate a fake argument pointer (or even a fake frame pointer)
3129 with either the real frame or the stack pointer. Assignments to
3130 the hard frame pointer must not prevent this elimination. */
3132 for (ep
= reg_eliminate
; ep
< ®_eliminate
[NUM_ELIMINABLE_REGS
];
3134 if (ep
->to_rtx
== SET_DEST (x
)
3135 && SET_DEST (x
) != hard_frame_pointer_rtx
)
3137 /* If it is being incremented, adjust the offset. Otherwise,
3138 this elimination can't be done. */
3139 rtx src
= SET_SRC (x
);
3141 if (GET_CODE (src
) == PLUS
3142 && XEXP (src
, 0) == SET_DEST (x
)
3143 && CONST_INT_P (XEXP (src
, 1)))
3144 ep
->offset
-= INTVAL (XEXP (src
, 1));
3146 ep
->can_eliminate
= 0;
3150 elimination_effects (SET_DEST (x
), VOIDmode
);
3151 elimination_effects (SET_SRC (x
), VOIDmode
);
3155 /* Our only special processing is to pass the mode of the MEM to our
3157 elimination_effects (XEXP (x
, 0), GET_MODE (x
));
3164 fmt
= GET_RTX_FORMAT (code
);
3165 for (i
= 0; i
< GET_RTX_LENGTH (code
); i
++, fmt
++)
3168 elimination_effects (XEXP (x
, i
), mem_mode
);
3169 else if (*fmt
== 'E')
3170 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
3171 elimination_effects (XVECEXP (x
, i
, j
), mem_mode
);
3175 /* Descend through rtx X and verify that no references to eliminable registers
3176 remain. If any do remain, mark the involved register as not
3180 check_eliminable_occurrences (rtx x
)
3189 code
= GET_CODE (x
);
3191 if (code
== REG
&& REGNO (x
) < FIRST_PSEUDO_REGISTER
)
3193 struct elim_table
*ep
;
3195 for (ep
= reg_eliminate
; ep
< ®_eliminate
[NUM_ELIMINABLE_REGS
]; ep
++)
3196 if (ep
->from_rtx
== x
)
3197 ep
->can_eliminate
= 0;
3201 fmt
= GET_RTX_FORMAT (code
);
3202 for (i
= 0; i
< GET_RTX_LENGTH (code
); i
++, fmt
++)
3205 check_eliminable_occurrences (XEXP (x
, i
));
3206 else if (*fmt
== 'E')
3209 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
3210 check_eliminable_occurrences (XVECEXP (x
, i
, j
));
3215 /* Scan INSN and eliminate all eliminable registers in it.
3217 If REPLACE is nonzero, do the replacement destructively. Also
3218 delete the insn as dead it if it is setting an eliminable register.
3220 If REPLACE is zero, do all our allocations in reload_obstack.
3222 If no eliminations were done and this insn doesn't require any elimination
3223 processing (these are not identical conditions: it might be updating sp,
3224 but not referencing fp; this needs to be seen during reload_as_needed so
3225 that the offset between fp and sp can be taken into consideration), zero
3226 is returned. Otherwise, 1 is returned. */
3229 eliminate_regs_in_insn (rtx insn
, int replace
)
3231 int icode
= recog_memoized (insn
);
3232 rtx old_body
= PATTERN (insn
);
3233 int insn_is_asm
= asm_noperands (old_body
) >= 0;
3234 rtx old_set
= single_set (insn
);
3238 rtx substed_operand
[MAX_RECOG_OPERANDS
];
3239 rtx orig_operand
[MAX_RECOG_OPERANDS
];
3240 struct elim_table
*ep
;
3241 rtx plus_src
, plus_cst_src
;
3243 if (! insn_is_asm
&& icode
< 0)
3245 gcc_assert (GET_CODE (PATTERN (insn
)) == USE
3246 || GET_CODE (PATTERN (insn
)) == CLOBBER
3247 || GET_CODE (PATTERN (insn
)) == ADDR_VEC
3248 || GET_CODE (PATTERN (insn
)) == ADDR_DIFF_VEC
3249 || GET_CODE (PATTERN (insn
)) == ASM_INPUT
3250 || DEBUG_INSN_P (insn
));
3251 if (DEBUG_INSN_P (insn
))
3252 INSN_VAR_LOCATION_LOC (insn
)
3253 = eliminate_regs (INSN_VAR_LOCATION_LOC (insn
), VOIDmode
, insn
);
3257 if (old_set
!= 0 && REG_P (SET_DEST (old_set
))
3258 && REGNO (SET_DEST (old_set
)) < FIRST_PSEUDO_REGISTER
)
3260 /* Check for setting an eliminable register. */
3261 for (ep
= reg_eliminate
; ep
< ®_eliminate
[NUM_ELIMINABLE_REGS
]; ep
++)
3262 if (ep
->from_rtx
== SET_DEST (old_set
) && ep
->can_eliminate
)
3264 #if !HARD_FRAME_POINTER_IS_FRAME_POINTER
3265 /* If this is setting the frame pointer register to the
3266 hardware frame pointer register and this is an elimination
3267 that will be done (tested above), this insn is really
3268 adjusting the frame pointer downward to compensate for
3269 the adjustment done before a nonlocal goto. */
3270 if (ep
->from
== FRAME_POINTER_REGNUM
3271 && ep
->to
== HARD_FRAME_POINTER_REGNUM
)
3273 rtx base
= SET_SRC (old_set
);
3274 rtx base_insn
= insn
;
3275 HOST_WIDE_INT offset
= 0;
3277 while (base
!= ep
->to_rtx
)
3279 rtx prev_insn
, prev_set
;
3281 if (GET_CODE (base
) == PLUS
3282 && CONST_INT_P (XEXP (base
, 1)))
3284 offset
+= INTVAL (XEXP (base
, 1));
3285 base
= XEXP (base
, 0);
3287 else if ((prev_insn
= prev_nonnote_insn (base_insn
)) != 0
3288 && (prev_set
= single_set (prev_insn
)) != 0
3289 && rtx_equal_p (SET_DEST (prev_set
), base
))
3291 base
= SET_SRC (prev_set
);
3292 base_insn
= prev_insn
;
3298 if (base
== ep
->to_rtx
)
3300 rtx src
= plus_constant (Pmode
, ep
->to_rtx
,
3301 offset
- ep
->offset
);
3303 new_body
= old_body
;
3306 new_body
= copy_insn (old_body
);
3307 if (REG_NOTES (insn
))
3308 REG_NOTES (insn
) = copy_insn_1 (REG_NOTES (insn
));
3310 PATTERN (insn
) = new_body
;
3311 old_set
= single_set (insn
);
3313 /* First see if this insn remains valid when we
3314 make the change. If not, keep the INSN_CODE
3315 the same and let reload fit it up. */
3316 validate_change (insn
, &SET_SRC (old_set
), src
, 1);
3317 validate_change (insn
, &SET_DEST (old_set
),
3319 if (! apply_change_group ())
3321 SET_SRC (old_set
) = src
;
3322 SET_DEST (old_set
) = ep
->to_rtx
;
3331 /* In this case this insn isn't serving a useful purpose. We
3332 will delete it in reload_as_needed once we know that this
3333 elimination is, in fact, being done.
3335 If REPLACE isn't set, we can't delete this insn, but needn't
3336 process it since it won't be used unless something changes. */
3339 delete_dead_insn (insn
);
3347 /* We allow one special case which happens to work on all machines we
3348 currently support: a single set with the source or a REG_EQUAL
3349 note being a PLUS of an eliminable register and a constant. */
3350 plus_src
= plus_cst_src
= 0;
3351 if (old_set
&& REG_P (SET_DEST (old_set
)))
3353 if (GET_CODE (SET_SRC (old_set
)) == PLUS
)
3354 plus_src
= SET_SRC (old_set
);
3355 /* First see if the source is of the form (plus (...) CST). */
3357 && CONST_INT_P (XEXP (plus_src
, 1)))
3358 plus_cst_src
= plus_src
;
3359 else if (REG_P (SET_SRC (old_set
))
3362 /* Otherwise, see if we have a REG_EQUAL note of the form
3363 (plus (...) CST). */
3365 for (links
= REG_NOTES (insn
); links
; links
= XEXP (links
, 1))
3367 if ((REG_NOTE_KIND (links
) == REG_EQUAL
3368 || REG_NOTE_KIND (links
) == REG_EQUIV
)
3369 && GET_CODE (XEXP (links
, 0)) == PLUS
3370 && CONST_INT_P (XEXP (XEXP (links
, 0), 1)))
3372 plus_cst_src
= XEXP (links
, 0);
3378 /* Check that the first operand of the PLUS is a hard reg or
3379 the lowpart subreg of one. */
3382 rtx reg
= XEXP (plus_cst_src
, 0);
3383 if (GET_CODE (reg
) == SUBREG
&& subreg_lowpart_p (reg
))
3384 reg
= SUBREG_REG (reg
);
3386 if (!REG_P (reg
) || REGNO (reg
) >= FIRST_PSEUDO_REGISTER
)
3392 rtx reg
= XEXP (plus_cst_src
, 0);
3393 HOST_WIDE_INT offset
= INTVAL (XEXP (plus_cst_src
, 1));
3395 if (GET_CODE (reg
) == SUBREG
)
3396 reg
= SUBREG_REG (reg
);
3398 for (ep
= reg_eliminate
; ep
< ®_eliminate
[NUM_ELIMINABLE_REGS
]; ep
++)
3399 if (ep
->from_rtx
== reg
&& ep
->can_eliminate
)
3401 rtx to_rtx
= ep
->to_rtx
;
3402 offset
+= ep
->offset
;
3403 offset
= trunc_int_for_mode (offset
, GET_MODE (plus_cst_src
));
3405 if (GET_CODE (XEXP (plus_cst_src
, 0)) == SUBREG
)
3406 to_rtx
= gen_lowpart (GET_MODE (XEXP (plus_cst_src
, 0)),
3408 /* If we have a nonzero offset, and the source is already
3409 a simple REG, the following transformation would
3410 increase the cost of the insn by replacing a simple REG
3411 with (plus (reg sp) CST). So try only when we already
3412 had a PLUS before. */
3413 if (offset
== 0 || plus_src
)
3415 rtx new_src
= plus_constant (GET_MODE (to_rtx
),
3418 new_body
= old_body
;
3421 new_body
= copy_insn (old_body
);
3422 if (REG_NOTES (insn
))
3423 REG_NOTES (insn
) = copy_insn_1 (REG_NOTES (insn
));
3425 PATTERN (insn
) = new_body
;
3426 old_set
= single_set (insn
);
3428 /* First see if this insn remains valid when we make the
3429 change. If not, try to replace the whole pattern with
3430 a simple set (this may help if the original insn was a
3431 PARALLEL that was only recognized as single_set due to
3432 REG_UNUSED notes). If this isn't valid either, keep
3433 the INSN_CODE the same and let reload fix it up. */
3434 if (!validate_change (insn
, &SET_SRC (old_set
), new_src
, 0))
3436 rtx new_pat
= gen_rtx_SET (VOIDmode
,
3437 SET_DEST (old_set
), new_src
);
3439 if (!validate_change (insn
, &PATTERN (insn
), new_pat
, 0))
3440 SET_SRC (old_set
) = new_src
;
3447 /* This can't have an effect on elimination offsets, so skip right
3453 /* Determine the effects of this insn on elimination offsets. */
3454 elimination_effects (old_body
, VOIDmode
);
3456 /* Eliminate all eliminable registers occurring in operands that
3457 can be handled by reload. */
3458 extract_insn (insn
);
3459 for (i
= 0; i
< recog_data
.n_operands
; i
++)
3461 orig_operand
[i
] = recog_data
.operand
[i
];
3462 substed_operand
[i
] = recog_data
.operand
[i
];
3464 /* For an asm statement, every operand is eliminable. */
3465 if (insn_is_asm
|| insn_data
[icode
].operand
[i
].eliminable
)
3467 bool is_set_src
, in_plus
;
3469 /* Check for setting a register that we know about. */
3470 if (recog_data
.operand_type
[i
] != OP_IN
3471 && REG_P (orig_operand
[i
]))
3473 /* If we are assigning to a register that can be eliminated, it
3474 must be as part of a PARALLEL, since the code above handles
3475 single SETs. We must indicate that we can no longer
3476 eliminate this reg. */
3477 for (ep
= reg_eliminate
; ep
< ®_eliminate
[NUM_ELIMINABLE_REGS
];
3479 if (ep
->from_rtx
== orig_operand
[i
])
3480 ep
->can_eliminate
= 0;
3483 /* Companion to the above plus substitution, we can allow
3484 invariants as the source of a plain move. */
3487 && recog_data
.operand_loc
[i
] == &SET_SRC (old_set
))
3491 && (recog_data
.operand_loc
[i
] == &XEXP (plus_src
, 0)
3492 || recog_data
.operand_loc
[i
] == &XEXP (plus_src
, 1)))
3496 = eliminate_regs_1 (recog_data
.operand
[i
], VOIDmode
,
3497 replace
? insn
: NULL_RTX
,
3498 is_set_src
|| in_plus
, false);
3499 if (substed_operand
[i
] != orig_operand
[i
])
3501 /* Terminate the search in check_eliminable_occurrences at
3503 *recog_data
.operand_loc
[i
] = 0;
3505 /* If an output operand changed from a REG to a MEM and INSN is an
3506 insn, write a CLOBBER insn. */
3507 if (recog_data
.operand_type
[i
] != OP_IN
3508 && REG_P (orig_operand
[i
])
3509 && MEM_P (substed_operand
[i
])
3511 emit_insn_after (gen_clobber (orig_operand
[i
]), insn
);
3515 for (i
= 0; i
< recog_data
.n_dups
; i
++)
3516 *recog_data
.dup_loc
[i
]
3517 = *recog_data
.operand_loc
[(int) recog_data
.dup_num
[i
]];
3519 /* If any eliminable remain, they aren't eliminable anymore. */
3520 check_eliminable_occurrences (old_body
);
3522 /* Substitute the operands; the new values are in the substed_operand
3524 for (i
= 0; i
< recog_data
.n_operands
; i
++)
3525 *recog_data
.operand_loc
[i
] = substed_operand
[i
];
3526 for (i
= 0; i
< recog_data
.n_dups
; i
++)
3527 *recog_data
.dup_loc
[i
] = substed_operand
[(int) recog_data
.dup_num
[i
]];
3529 /* If we are replacing a body that was a (set X (plus Y Z)), try to
3530 re-recognize the insn. We do this in case we had a simple addition
3531 but now can do this as a load-address. This saves an insn in this
3533 If re-recognition fails, the old insn code number will still be used,
3534 and some register operands may have changed into PLUS expressions.
3535 These will be handled by find_reloads by loading them into a register
3540 /* If we aren't replacing things permanently and we changed something,
3541 make another copy to ensure that all the RTL is new. Otherwise
3542 things can go wrong if find_reload swaps commutative operands
3543 and one is inside RTL that has been copied while the other is not. */
3544 new_body
= old_body
;
3547 new_body
= copy_insn (old_body
);
3548 if (REG_NOTES (insn
))
3549 REG_NOTES (insn
) = copy_insn_1 (REG_NOTES (insn
));
3551 PATTERN (insn
) = new_body
;
3553 /* If we had a move insn but now we don't, rerecognize it. This will
3554 cause spurious re-recognition if the old move had a PARALLEL since
3555 the new one still will, but we can't call single_set without
3556 having put NEW_BODY into the insn and the re-recognition won't
3557 hurt in this rare case. */
3558 /* ??? Why this huge if statement - why don't we just rerecognize the
3562 && ((REG_P (SET_SRC (old_set
))
3563 && (GET_CODE (new_body
) != SET
3564 || !REG_P (SET_SRC (new_body
))))
3565 /* If this was a load from or store to memory, compare
3566 the MEM in recog_data.operand to the one in the insn.
3567 If they are not equal, then rerecognize the insn. */
3569 && ((MEM_P (SET_SRC (old_set
))
3570 && SET_SRC (old_set
) != recog_data
.operand
[1])
3571 || (MEM_P (SET_DEST (old_set
))
3572 && SET_DEST (old_set
) != recog_data
.operand
[0])))
3573 /* If this was an add insn before, rerecognize. */
3574 || GET_CODE (SET_SRC (old_set
)) == PLUS
))
3576 int new_icode
= recog (PATTERN (insn
), insn
, 0);
3578 INSN_CODE (insn
) = new_icode
;
3582 /* Restore the old body. If there were any changes to it, we made a copy
3583 of it while the changes were still in place, so we'll correctly return
3584 a modified insn below. */
3587 /* Restore the old body. */
3588 for (i
= 0; i
< recog_data
.n_operands
; i
++)
3589 /* Restoring a top-level match_parallel would clobber the new_body
3590 we installed in the insn. */
3591 if (recog_data
.operand_loc
[i
] != &PATTERN (insn
))
3592 *recog_data
.operand_loc
[i
] = orig_operand
[i
];
3593 for (i
= 0; i
< recog_data
.n_dups
; i
++)
3594 *recog_data
.dup_loc
[i
] = orig_operand
[(int) recog_data
.dup_num
[i
]];
3597 /* Update all elimination pairs to reflect the status after the current
3598 insn. The changes we make were determined by the earlier call to
3599 elimination_effects.
3601 We also detect cases where register elimination cannot be done,
3602 namely, if a register would be both changed and referenced outside a MEM
3603 in the resulting insn since such an insn is often undefined and, even if
3604 not, we cannot know what meaning will be given to it. Note that it is
3605 valid to have a register used in an address in an insn that changes it
3606 (presumably with a pre- or post-increment or decrement).
3608 If anything changes, return nonzero. */
3610 for (ep
= reg_eliminate
; ep
< ®_eliminate
[NUM_ELIMINABLE_REGS
]; ep
++)
3612 if (ep
->previous_offset
!= ep
->offset
&& ep
->ref_outside_mem
)
3613 ep
->can_eliminate
= 0;
3615 ep
->ref_outside_mem
= 0;
3617 if (ep
->previous_offset
!= ep
->offset
)
3622 /* If we changed something, perform elimination in REG_NOTES. This is
3623 needed even when REPLACE is zero because a REG_DEAD note might refer
3624 to a register that we eliminate and could cause a different number
3625 of spill registers to be needed in the final reload pass than in
3627 if (val
&& REG_NOTES (insn
) != 0)
3629 = eliminate_regs_1 (REG_NOTES (insn
), VOIDmode
, REG_NOTES (insn
), true,
3635 /* Like eliminate_regs_in_insn, but only estimate costs for the use of the
3636 register allocator. INSN is the instruction we need to examine, we perform
3637 eliminations in its operands and record cases where eliminating a reg with
3638 an invariant equivalence would add extra cost. */
3641 elimination_costs_in_insn (rtx insn
)
3643 int icode
= recog_memoized (insn
);
3644 rtx old_body
= PATTERN (insn
);
3645 int insn_is_asm
= asm_noperands (old_body
) >= 0;
3646 rtx old_set
= single_set (insn
);
3648 rtx orig_operand
[MAX_RECOG_OPERANDS
];
3649 rtx orig_dup
[MAX_RECOG_OPERANDS
];
3650 struct elim_table
*ep
;
3651 rtx plus_src
, plus_cst_src
;
3654 if (! insn_is_asm
&& icode
< 0)
3656 gcc_assert (GET_CODE (PATTERN (insn
)) == USE
3657 || GET_CODE (PATTERN (insn
)) == CLOBBER
3658 || GET_CODE (PATTERN (insn
)) == ADDR_VEC
3659 || GET_CODE (PATTERN (insn
)) == ADDR_DIFF_VEC
3660 || GET_CODE (PATTERN (insn
)) == ASM_INPUT
3661 || DEBUG_INSN_P (insn
));
3665 if (old_set
!= 0 && REG_P (SET_DEST (old_set
))
3666 && REGNO (SET_DEST (old_set
)) < FIRST_PSEUDO_REGISTER
)
3668 /* Check for setting an eliminable register. */
3669 for (ep
= reg_eliminate
; ep
< ®_eliminate
[NUM_ELIMINABLE_REGS
]; ep
++)
3670 if (ep
->from_rtx
== SET_DEST (old_set
) && ep
->can_eliminate
)
3674 /* We allow one special case which happens to work on all machines we
3675 currently support: a single set with the source or a REG_EQUAL
3676 note being a PLUS of an eliminable register and a constant. */
3677 plus_src
= plus_cst_src
= 0;
3679 if (old_set
&& REG_P (SET_DEST (old_set
)))
3682 if (GET_CODE (SET_SRC (old_set
)) == PLUS
)
3683 plus_src
= SET_SRC (old_set
);
3684 /* First see if the source is of the form (plus (...) CST). */
3686 && CONST_INT_P (XEXP (plus_src
, 1)))
3687 plus_cst_src
= plus_src
;
3688 else if (REG_P (SET_SRC (old_set
))
3691 /* Otherwise, see if we have a REG_EQUAL note of the form
3692 (plus (...) CST). */
3694 for (links
= REG_NOTES (insn
); links
; links
= XEXP (links
, 1))
3696 if ((REG_NOTE_KIND (links
) == REG_EQUAL
3697 || REG_NOTE_KIND (links
) == REG_EQUIV
)
3698 && GET_CODE (XEXP (links
, 0)) == PLUS
3699 && CONST_INT_P (XEXP (XEXP (links
, 0), 1)))
3701 plus_cst_src
= XEXP (links
, 0);
3708 /* Determine the effects of this insn on elimination offsets. */
3709 elimination_effects (old_body
, VOIDmode
);
3711 /* Eliminate all eliminable registers occurring in operands that
3712 can be handled by reload. */
3713 extract_insn (insn
);
3714 for (i
= 0; i
< recog_data
.n_dups
; i
++)
3715 orig_dup
[i
] = *recog_data
.dup_loc
[i
];
3717 for (i
= 0; i
< recog_data
.n_operands
; i
++)
3719 orig_operand
[i
] = recog_data
.operand
[i
];
3721 /* For an asm statement, every operand is eliminable. */
3722 if (insn_is_asm
|| insn_data
[icode
].operand
[i
].eliminable
)
3724 bool is_set_src
, in_plus
;
3726 /* Check for setting a register that we know about. */
3727 if (recog_data
.operand_type
[i
] != OP_IN
3728 && REG_P (orig_operand
[i
]))
3730 /* If we are assigning to a register that can be eliminated, it
3731 must be as part of a PARALLEL, since the code above handles
3732 single SETs. We must indicate that we can no longer
3733 eliminate this reg. */
3734 for (ep
= reg_eliminate
; ep
< ®_eliminate
[NUM_ELIMINABLE_REGS
];
3736 if (ep
->from_rtx
== orig_operand
[i
])
3737 ep
->can_eliminate
= 0;
3740 /* Companion to the above plus substitution, we can allow
3741 invariants as the source of a plain move. */
3743 if (old_set
&& recog_data
.operand_loc
[i
] == &SET_SRC (old_set
))
3745 if (is_set_src
&& !sets_reg_p
)
3746 note_reg_elim_costly (&SET_SRC (old_set
), insn
);
3748 if (plus_src
&& sets_reg_p
3749 && (recog_data
.operand_loc
[i
] == &XEXP (plus_src
, 0)
3750 || recog_data
.operand_loc
[i
] == &XEXP (plus_src
, 1)))
3753 eliminate_regs_1 (recog_data
.operand
[i
], VOIDmode
,
3755 is_set_src
|| in_plus
, true);
3756 /* Terminate the search in check_eliminable_occurrences at
3758 *recog_data
.operand_loc
[i
] = 0;
3762 for (i
= 0; i
< recog_data
.n_dups
; i
++)
3763 *recog_data
.dup_loc
[i
]
3764 = *recog_data
.operand_loc
[(int) recog_data
.dup_num
[i
]];
3766 /* If any eliminable remain, they aren't eliminable anymore. */
3767 check_eliminable_occurrences (old_body
);
3769 /* Restore the old body. */
3770 for (i
= 0; i
< recog_data
.n_operands
; i
++)
3771 *recog_data
.operand_loc
[i
] = orig_operand
[i
];
3772 for (i
= 0; i
< recog_data
.n_dups
; i
++)
3773 *recog_data
.dup_loc
[i
] = orig_dup
[i
];
3775 /* Update all elimination pairs to reflect the status after the current
3776 insn. The changes we make were determined by the earlier call to
3777 elimination_effects. */
3779 for (ep
= reg_eliminate
; ep
< ®_eliminate
[NUM_ELIMINABLE_REGS
]; ep
++)
3781 if (ep
->previous_offset
!= ep
->offset
&& ep
->ref_outside_mem
)
3782 ep
->can_eliminate
= 0;
3784 ep
->ref_outside_mem
= 0;
3790 /* Loop through all elimination pairs.
3791 Recalculate the number not at initial offset.
3793 Compute the maximum offset (minimum offset if the stack does not
3794 grow downward) for each elimination pair. */
3797 update_eliminable_offsets (void)
3799 struct elim_table
*ep
;
3801 num_not_at_initial_offset
= 0;
3802 for (ep
= reg_eliminate
; ep
< ®_eliminate
[NUM_ELIMINABLE_REGS
]; ep
++)
3804 ep
->previous_offset
= ep
->offset
;
3805 if (ep
->can_eliminate
&& ep
->offset
!= ep
->initial_offset
)
3806 num_not_at_initial_offset
++;
3810 /* Given X, a SET or CLOBBER of DEST, if DEST is the target of a register
3811 replacement we currently believe is valid, mark it as not eliminable if X
3812 modifies DEST in any way other than by adding a constant integer to it.
3814 If DEST is the frame pointer, we do nothing because we assume that
3815 all assignments to the hard frame pointer are nonlocal gotos and are being
3816 done at a time when they are valid and do not disturb anything else.
3817 Some machines want to eliminate a fake argument pointer with either the
3818 frame or stack pointer. Assignments to the hard frame pointer must not
3819 prevent this elimination.
3821 Called via note_stores from reload before starting its passes to scan
3822 the insns of the function. */
3825 mark_not_eliminable (rtx dest
, const_rtx x
, void *data ATTRIBUTE_UNUSED
)
3829 /* A SUBREG of a hard register here is just changing its mode. We should
3830 not see a SUBREG of an eliminable hard register, but check just in
3832 if (GET_CODE (dest
) == SUBREG
)
3833 dest
= SUBREG_REG (dest
);
3835 if (dest
== hard_frame_pointer_rtx
)
3838 for (i
= 0; i
< NUM_ELIMINABLE_REGS
; i
++)
3839 if (reg_eliminate
[i
].can_eliminate
&& dest
== reg_eliminate
[i
].to_rtx
3840 && (GET_CODE (x
) != SET
3841 || GET_CODE (SET_SRC (x
)) != PLUS
3842 || XEXP (SET_SRC (x
), 0) != dest
3843 || !CONST_INT_P (XEXP (SET_SRC (x
), 1))))
3845 reg_eliminate
[i
].can_eliminate_previous
3846 = reg_eliminate
[i
].can_eliminate
= 0;
3851 /* Verify that the initial elimination offsets did not change since the
3852 last call to set_initial_elim_offsets. This is used to catch cases
3853 where something illegal happened during reload_as_needed that could
3854 cause incorrect code to be generated if we did not check for it. */
3857 verify_initial_elim_offsets (void)
3861 if (!num_eliminable
)
3864 #ifdef ELIMINABLE_REGS
3866 struct elim_table
*ep
;
3868 for (ep
= reg_eliminate
; ep
< ®_eliminate
[NUM_ELIMINABLE_REGS
]; ep
++)
3870 INITIAL_ELIMINATION_OFFSET (ep
->from
, ep
->to
, t
);
3871 if (t
!= ep
->initial_offset
)
3876 INITIAL_FRAME_POINTER_OFFSET (t
);
3877 if (t
!= reg_eliminate
[0].initial_offset
)
3884 /* Reset all offsets on eliminable registers to their initial values. */
3887 set_initial_elim_offsets (void)
3889 struct elim_table
*ep
= reg_eliminate
;
3891 #ifdef ELIMINABLE_REGS
3892 for (; ep
< ®_eliminate
[NUM_ELIMINABLE_REGS
]; ep
++)
3894 INITIAL_ELIMINATION_OFFSET (ep
->from
, ep
->to
, ep
->initial_offset
);
3895 ep
->previous_offset
= ep
->offset
= ep
->initial_offset
;
3898 INITIAL_FRAME_POINTER_OFFSET (ep
->initial_offset
);
3899 ep
->previous_offset
= ep
->offset
= ep
->initial_offset
;
3902 num_not_at_initial_offset
= 0;
3905 /* Subroutine of set_initial_label_offsets called via for_each_eh_label. */
3908 set_initial_eh_label_offset (rtx label
)
3910 set_label_offsets (label
, NULL_RTX
, 1);
3913 /* Initialize the known label offsets.
3914 Set a known offset for each forced label to be at the initial offset
3915 of each elimination. We do this because we assume that all
3916 computed jumps occur from a location where each elimination is
3917 at its initial offset.
3918 For all other labels, show that we don't know the offsets. */
3921 set_initial_label_offsets (void)
3924 memset (offsets_known_at
, 0, num_labels
);
3926 for (x
= forced_labels
; x
; x
= XEXP (x
, 1))
3928 set_label_offsets (XEXP (x
, 0), NULL_RTX
, 1);
3930 for (x
= nonlocal_goto_handler_labels
; x
; x
= XEXP (x
, 1))
3932 set_label_offsets (XEXP (x
, 0), NULL_RTX
, 1);
3934 for_each_eh_label (set_initial_eh_label_offset
);
3937 /* Set all elimination offsets to the known values for the code label given
3941 set_offsets_for_label (rtx insn
)
3944 int label_nr
= CODE_LABEL_NUMBER (insn
);
3945 struct elim_table
*ep
;
3947 num_not_at_initial_offset
= 0;
3948 for (i
= 0, ep
= reg_eliminate
; i
< NUM_ELIMINABLE_REGS
; ep
++, i
++)
3950 ep
->offset
= ep
->previous_offset
3951 = offsets_at
[label_nr
- first_label_num
][i
];
3952 if (ep
->can_eliminate
&& ep
->offset
!= ep
->initial_offset
)
3953 num_not_at_initial_offset
++;
3957 /* See if anything that happened changes which eliminations are valid.
3958 For example, on the SPARC, whether or not the frame pointer can
3959 be eliminated can depend on what registers have been used. We need
3960 not check some conditions again (such as flag_omit_frame_pointer)
3961 since they can't have changed. */
3964 update_eliminables (HARD_REG_SET
*pset
)
3966 int previous_frame_pointer_needed
= frame_pointer_needed
;
3967 struct elim_table
*ep
;
3969 for (ep
= reg_eliminate
; ep
< ®_eliminate
[NUM_ELIMINABLE_REGS
]; ep
++)
3970 if ((ep
->from
== HARD_FRAME_POINTER_REGNUM
3971 && targetm
.frame_pointer_required ())
3972 #ifdef ELIMINABLE_REGS
3973 || ! targetm
.can_eliminate (ep
->from
, ep
->to
)
3976 ep
->can_eliminate
= 0;
3978 /* Look for the case where we have discovered that we can't replace
3979 register A with register B and that means that we will now be
3980 trying to replace register A with register C. This means we can
3981 no longer replace register C with register B and we need to disable
3982 such an elimination, if it exists. This occurs often with A == ap,
3983 B == sp, and C == fp. */
3985 for (ep
= reg_eliminate
; ep
< ®_eliminate
[NUM_ELIMINABLE_REGS
]; ep
++)
3987 struct elim_table
*op
;
3990 if (! ep
->can_eliminate
&& ep
->can_eliminate_previous
)
3992 /* Find the current elimination for ep->from, if there is a
3994 for (op
= reg_eliminate
;
3995 op
< ®_eliminate
[NUM_ELIMINABLE_REGS
]; op
++)
3996 if (op
->from
== ep
->from
&& op
->can_eliminate
)
4002 /* See if there is an elimination of NEW_TO -> EP->TO. If so,
4004 for (op
= reg_eliminate
;
4005 op
< ®_eliminate
[NUM_ELIMINABLE_REGS
]; op
++)
4006 if (op
->from
== new_to
&& op
->to
== ep
->to
)
4007 op
->can_eliminate
= 0;
4011 /* See if any registers that we thought we could eliminate the previous
4012 time are no longer eliminable. If so, something has changed and we
4013 must spill the register. Also, recompute the number of eliminable
4014 registers and see if the frame pointer is needed; it is if there is
4015 no elimination of the frame pointer that we can perform. */
4017 frame_pointer_needed
= 1;
4018 for (ep
= reg_eliminate
; ep
< ®_eliminate
[NUM_ELIMINABLE_REGS
]; ep
++)
4020 if (ep
->can_eliminate
4021 && ep
->from
== FRAME_POINTER_REGNUM
4022 && ep
->to
!= HARD_FRAME_POINTER_REGNUM
4023 && (! SUPPORTS_STACK_ALIGNMENT
4024 || ! crtl
->stack_realign_needed
))
4025 frame_pointer_needed
= 0;
4027 if (! ep
->can_eliminate
&& ep
->can_eliminate_previous
)
4029 ep
->can_eliminate_previous
= 0;
4030 SET_HARD_REG_BIT (*pset
, ep
->from
);
4035 /* If we didn't need a frame pointer last time, but we do now, spill
4036 the hard frame pointer. */
4037 if (frame_pointer_needed
&& ! previous_frame_pointer_needed
)
4038 SET_HARD_REG_BIT (*pset
, HARD_FRAME_POINTER_REGNUM
);
4041 /* Return true if X is used as the target register of an elimination. */
4044 elimination_target_reg_p (rtx x
)
4046 struct elim_table
*ep
;
4048 for (ep
= reg_eliminate
; ep
< ®_eliminate
[NUM_ELIMINABLE_REGS
]; ep
++)
4049 if (ep
->to_rtx
== x
&& ep
->can_eliminate
)
4055 /* Initialize the table of registers to eliminate.
4056 Pre-condition: global flag frame_pointer_needed has been set before
4057 calling this function. */
4060 init_elim_table (void)
4062 struct elim_table
*ep
;
4063 #ifdef ELIMINABLE_REGS
4064 const struct elim_table_1
*ep1
;
4068 reg_eliminate
= XCNEWVEC (struct elim_table
, NUM_ELIMINABLE_REGS
);
4072 #ifdef ELIMINABLE_REGS
4073 for (ep
= reg_eliminate
, ep1
= reg_eliminate_1
;
4074 ep
< ®_eliminate
[NUM_ELIMINABLE_REGS
]; ep
++, ep1
++)
4076 ep
->from
= ep1
->from
;
4078 ep
->can_eliminate
= ep
->can_eliminate_previous
4079 = (targetm
.can_eliminate (ep
->from
, ep
->to
)
4080 && ! (ep
->to
== STACK_POINTER_REGNUM
4081 && frame_pointer_needed
4082 && (! SUPPORTS_STACK_ALIGNMENT
4083 || ! stack_realign_fp
)));
4086 reg_eliminate
[0].from
= reg_eliminate_1
[0].from
;
4087 reg_eliminate
[0].to
= reg_eliminate_1
[0].to
;
4088 reg_eliminate
[0].can_eliminate
= reg_eliminate
[0].can_eliminate_previous
4089 = ! frame_pointer_needed
;
4092 /* Count the number of eliminable registers and build the FROM and TO
4093 REG rtx's. Note that code in gen_rtx_REG will cause, e.g.,
4094 gen_rtx_REG (Pmode, STACK_POINTER_REGNUM) to equal stack_pointer_rtx.
4095 We depend on this. */
4096 for (ep
= reg_eliminate
; ep
< ®_eliminate
[NUM_ELIMINABLE_REGS
]; ep
++)
4098 num_eliminable
+= ep
->can_eliminate
;
4099 ep
->from_rtx
= gen_rtx_REG (Pmode
, ep
->from
);
4100 ep
->to_rtx
= gen_rtx_REG (Pmode
, ep
->to
);
4104 /* Find all the pseudo registers that didn't get hard regs
4105 but do have known equivalent constants or memory slots.
4106 These include parameters (known equivalent to parameter slots)
4107 and cse'd or loop-moved constant memory addresses.
4109 Record constant equivalents in reg_equiv_constant
4110 so they will be substituted by find_reloads.
4111 Record memory equivalents in reg_mem_equiv so they can
4112 be substituted eventually by altering the REG-rtx's. */
4115 init_eliminable_invariants (rtx first
, bool do_subregs
)
4122 reg_max_ref_width
= XCNEWVEC (unsigned int, max_regno
);
4124 reg_max_ref_width
= NULL
;
4126 num_eliminable_invariants
= 0;
4128 first_label_num
= get_first_label_num ();
4129 num_labels
= max_label_num () - first_label_num
;
4131 /* Allocate the tables used to store offset information at labels. */
4132 offsets_known_at
= XNEWVEC (char, num_labels
);
4133 offsets_at
= (HOST_WIDE_INT (*)[NUM_ELIMINABLE_REGS
]) xmalloc (num_labels
* NUM_ELIMINABLE_REGS
* sizeof (HOST_WIDE_INT
));
4135 /* Look for REG_EQUIV notes; record what each pseudo is equivalent
4136 to. If DO_SUBREGS is true, also find all paradoxical subregs and
4137 find largest such for each pseudo. FIRST is the head of the insn
4140 for (insn
= first
; insn
; insn
= NEXT_INSN (insn
))
4142 rtx set
= single_set (insn
);
4144 /* We may introduce USEs that we want to remove at the end, so
4145 we'll mark them with QImode. Make sure there are no
4146 previously-marked insns left by say regmove. */
4147 if (INSN_P (insn
) && GET_CODE (PATTERN (insn
)) == USE
4148 && GET_MODE (insn
) != VOIDmode
)
4149 PUT_MODE (insn
, VOIDmode
);
4151 if (do_subregs
&& NONDEBUG_INSN_P (insn
))
4152 scan_paradoxical_subregs (PATTERN (insn
));
4154 if (set
!= 0 && REG_P (SET_DEST (set
)))
4156 rtx note
= find_reg_note (insn
, REG_EQUIV
, NULL_RTX
);
4162 i
= REGNO (SET_DEST (set
));
4165 if (i
<= LAST_VIRTUAL_REGISTER
)
4168 /* If flag_pic and we have constant, verify it's legitimate. */
4170 || !flag_pic
|| LEGITIMATE_PIC_OPERAND_P (x
))
4172 /* It can happen that a REG_EQUIV note contains a MEM
4173 that is not a legitimate memory operand. As later
4174 stages of reload assume that all addresses found
4175 in the reg_equiv_* arrays were originally legitimate,
4176 we ignore such REG_EQUIV notes. */
4177 if (memory_operand (x
, VOIDmode
))
4179 /* Always unshare the equivalence, so we can
4180 substitute into this insn without touching the
4182 reg_equiv_memory_loc (i
) = copy_rtx (x
);
4184 else if (function_invariant_p (x
))
4186 enum machine_mode mode
;
4188 mode
= GET_MODE (SET_DEST (set
));
4189 if (GET_CODE (x
) == PLUS
)
4191 /* This is PLUS of frame pointer and a constant,
4192 and might be shared. Unshare it. */
4193 reg_equiv_invariant (i
) = copy_rtx (x
);
4194 num_eliminable_invariants
++;
4196 else if (x
== frame_pointer_rtx
|| x
== arg_pointer_rtx
)
4198 reg_equiv_invariant (i
) = x
;
4199 num_eliminable_invariants
++;
4201 else if (targetm
.legitimate_constant_p (mode
, x
))
4202 reg_equiv_constant (i
) = x
;
4205 reg_equiv_memory_loc (i
) = force_const_mem (mode
, x
);
4206 if (! reg_equiv_memory_loc (i
))
4207 reg_equiv_init (i
) = NULL_RTX
;
4212 reg_equiv_init (i
) = NULL_RTX
;
4217 reg_equiv_init (i
) = NULL_RTX
;
4222 for (i
= FIRST_PSEUDO_REGISTER
; i
< max_regno
; i
++)
4223 if (reg_equiv_init (i
))
4225 fprintf (dump_file
, "init_insns for %u: ", i
);
4226 print_inline_rtx (dump_file
, reg_equiv_init (i
), 20);
4227 fprintf (dump_file
, "\n");
4231 /* Indicate that we no longer have known memory locations or constants.
4232 Free all data involved in tracking these. */
4235 free_reg_equiv (void)
4240 free (offsets_known_at
);
4243 offsets_known_at
= 0;
4245 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
4246 if (reg_equiv_alt_mem_list (i
))
4247 free_EXPR_LIST_list (®_equiv_alt_mem_list (i
));
4248 VEC_free (reg_equivs_t
, gc
, reg_equivs
);
4253 /* Kick all pseudos out of hard register REGNO.
4255 If CANT_ELIMINATE is nonzero, it means that we are doing this spill
4256 because we found we can't eliminate some register. In the case, no pseudos
4257 are allowed to be in the register, even if they are only in a block that
4258 doesn't require spill registers, unlike the case when we are spilling this
4259 hard reg to produce another spill register.
4261 Return nonzero if any pseudos needed to be kicked out. */
4264 spill_hard_reg (unsigned int regno
, int cant_eliminate
)
4270 SET_HARD_REG_BIT (bad_spill_regs_global
, regno
);
4271 df_set_regs_ever_live (regno
, true);
4274 /* Spill every pseudo reg that was allocated to this reg
4275 or to something that overlaps this reg. */
4277 for (i
= FIRST_PSEUDO_REGISTER
; i
< max_regno
; i
++)
4278 if (reg_renumber
[i
] >= 0
4279 && (unsigned int) reg_renumber
[i
] <= regno
4280 && end_hard_regno (PSEUDO_REGNO_MODE (i
), reg_renumber
[i
]) > regno
)
4281 SET_REGNO_REG_SET (&spilled_pseudos
, i
);
4284 /* After find_reload_regs has been run for all insn that need reloads,
4285 and/or spill_hard_regs was called, this function is used to actually
4286 spill pseudo registers and try to reallocate them. It also sets up the
4287 spill_regs array for use by choose_reload_regs. */
4290 finish_spills (int global
)
4292 struct insn_chain
*chain
;
4293 int something_changed
= 0;
4295 reg_set_iterator rsi
;
4297 /* Build the spill_regs array for the function. */
4298 /* If there are some registers still to eliminate and one of the spill regs
4299 wasn't ever used before, additional stack space may have to be
4300 allocated to store this register. Thus, we may have changed the offset
4301 between the stack and frame pointers, so mark that something has changed.
4303 One might think that we need only set VAL to 1 if this is a call-used
4304 register. However, the set of registers that must be saved by the
4305 prologue is not identical to the call-used set. For example, the
4306 register used by the call insn for the return PC is a call-used register,
4307 but must be saved by the prologue. */
4310 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
4311 if (TEST_HARD_REG_BIT (used_spill_regs
, i
))
4313 spill_reg_order
[i
] = n_spills
;
4314 spill_regs
[n_spills
++] = i
;
4315 if (num_eliminable
&& ! df_regs_ever_live_p (i
))
4316 something_changed
= 1;
4317 df_set_regs_ever_live (i
, true);
4320 spill_reg_order
[i
] = -1;
4322 EXECUTE_IF_SET_IN_REG_SET (&spilled_pseudos
, FIRST_PSEUDO_REGISTER
, i
, rsi
)
4323 if (! ira_conflicts_p
|| reg_renumber
[i
] >= 0)
4325 /* Record the current hard register the pseudo is allocated to
4326 in pseudo_previous_regs so we avoid reallocating it to the
4327 same hard reg in a later pass. */
4328 gcc_assert (reg_renumber
[i
] >= 0);
4330 SET_HARD_REG_BIT (pseudo_previous_regs
[i
], reg_renumber
[i
]);
4331 /* Mark it as no longer having a hard register home. */
4332 reg_renumber
[i
] = -1;
4333 if (ira_conflicts_p
)
4334 /* Inform IRA about the change. */
4335 ira_mark_allocation_change (i
);
4336 /* We will need to scan everything again. */
4337 something_changed
= 1;
4340 /* Retry global register allocation if possible. */
4341 if (global
&& ira_conflicts_p
)
4345 memset (pseudo_forbidden_regs
, 0, max_regno
* sizeof (HARD_REG_SET
));
4346 /* For every insn that needs reloads, set the registers used as spill
4347 regs in pseudo_forbidden_regs for every pseudo live across the
4349 for (chain
= insns_need_reload
; chain
; chain
= chain
->next_need_reload
)
4351 EXECUTE_IF_SET_IN_REG_SET
4352 (&chain
->live_throughout
, FIRST_PSEUDO_REGISTER
, i
, rsi
)
4354 IOR_HARD_REG_SET (pseudo_forbidden_regs
[i
],
4355 chain
->used_spill_regs
);
4357 EXECUTE_IF_SET_IN_REG_SET
4358 (&chain
->dead_or_set
, FIRST_PSEUDO_REGISTER
, i
, rsi
)
4360 IOR_HARD_REG_SET (pseudo_forbidden_regs
[i
],
4361 chain
->used_spill_regs
);
4365 /* Retry allocating the pseudos spilled in IRA and the
4366 reload. For each reg, merge the various reg sets that
4367 indicate which hard regs can't be used, and call
4368 ira_reassign_pseudos. */
4369 for (n
= 0, i
= FIRST_PSEUDO_REGISTER
; i
< (unsigned) max_regno
; i
++)
4370 if (reg_old_renumber
[i
] != reg_renumber
[i
])
4372 if (reg_renumber
[i
] < 0)
4373 temp_pseudo_reg_arr
[n
++] = i
;
4375 CLEAR_REGNO_REG_SET (&spilled_pseudos
, i
);
4377 if (ira_reassign_pseudos (temp_pseudo_reg_arr
, n
,
4378 bad_spill_regs_global
,
4379 pseudo_forbidden_regs
, pseudo_previous_regs
,
4381 something_changed
= 1;
4383 /* Fix up the register information in the insn chain.
4384 This involves deleting those of the spilled pseudos which did not get
4385 a new hard register home from the live_{before,after} sets. */
4386 for (chain
= reload_insn_chain
; chain
; chain
= chain
->next
)
4388 HARD_REG_SET used_by_pseudos
;
4389 HARD_REG_SET used_by_pseudos2
;
4391 if (! ira_conflicts_p
)
4393 /* Don't do it for IRA because IRA and the reload still can
4394 assign hard registers to the spilled pseudos on next
4395 reload iterations. */
4396 AND_COMPL_REG_SET (&chain
->live_throughout
, &spilled_pseudos
);
4397 AND_COMPL_REG_SET (&chain
->dead_or_set
, &spilled_pseudos
);
4399 /* Mark any unallocated hard regs as available for spills. That
4400 makes inheritance work somewhat better. */
4401 if (chain
->need_reload
)
4403 REG_SET_TO_HARD_REG_SET (used_by_pseudos
, &chain
->live_throughout
);
4404 REG_SET_TO_HARD_REG_SET (used_by_pseudos2
, &chain
->dead_or_set
);
4405 IOR_HARD_REG_SET (used_by_pseudos
, used_by_pseudos2
);
4407 compute_use_by_pseudos (&used_by_pseudos
, &chain
->live_throughout
);
4408 compute_use_by_pseudos (&used_by_pseudos
, &chain
->dead_or_set
);
4409 /* Value of chain->used_spill_regs from previous iteration
4410 may be not included in the value calculated here because
4411 of possible removing caller-saves insns (see function
4412 delete_caller_save_insns. */
4413 COMPL_HARD_REG_SET (chain
->used_spill_regs
, used_by_pseudos
);
4414 AND_HARD_REG_SET (chain
->used_spill_regs
, used_spill_regs
);
4418 CLEAR_REG_SET (&changed_allocation_pseudos
);
4419 /* Let alter_reg modify the reg rtx's for the modified pseudos. */
4420 for (i
= FIRST_PSEUDO_REGISTER
; i
< (unsigned)max_regno
; i
++)
4422 int regno
= reg_renumber
[i
];
4423 if (reg_old_renumber
[i
] == regno
)
4426 SET_REGNO_REG_SET (&changed_allocation_pseudos
, i
);
4428 alter_reg (i
, reg_old_renumber
[i
], false);
4429 reg_old_renumber
[i
] = regno
;
4433 fprintf (dump_file
, " Register %d now on stack.\n\n", i
);
4435 fprintf (dump_file
, " Register %d now in %d.\n\n",
4436 i
, reg_renumber
[i
]);
4440 return something_changed
;
4443 /* Find all paradoxical subregs within X and update reg_max_ref_width. */
4446 scan_paradoxical_subregs (rtx x
)
4450 enum rtx_code code
= GET_CODE (x
);
4461 case CONST_VECTOR
: /* shouldn't happen, but just in case. */
4469 if (REG_P (SUBREG_REG (x
))
4470 && (GET_MODE_SIZE (GET_MODE (x
))
4471 > reg_max_ref_width
[REGNO (SUBREG_REG (x
))]))
4473 reg_max_ref_width
[REGNO (SUBREG_REG (x
))]
4474 = GET_MODE_SIZE (GET_MODE (x
));
4475 mark_home_live_1 (REGNO (SUBREG_REG (x
)), GET_MODE (x
));
4483 fmt
= GET_RTX_FORMAT (code
);
4484 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
4487 scan_paradoxical_subregs (XEXP (x
, i
));
4488 else if (fmt
[i
] == 'E')
4491 for (j
= XVECLEN (x
, i
) - 1; j
>= 0; j
--)
4492 scan_paradoxical_subregs (XVECEXP (x
, i
, j
));
4497 /* *OP_PTR and *OTHER_PTR are two operands to a conceptual reload.
4498 If *OP_PTR is a paradoxical subreg, try to remove that subreg
4499 and apply the corresponding narrowing subreg to *OTHER_PTR.
4500 Return true if the operands were changed, false otherwise. */
4503 strip_paradoxical_subreg (rtx
*op_ptr
, rtx
*other_ptr
)
4505 rtx op
, inner
, other
, tem
;
4508 if (!paradoxical_subreg_p (op
))
4510 inner
= SUBREG_REG (op
);
4513 tem
= gen_lowpart_common (GET_MODE (inner
), other
);
4517 /* If the lowpart operation turned a hard register into a subreg,
4518 rather than simplifying it to another hard register, then the
4519 mode change cannot be properly represented. For example, OTHER
4520 might be valid in its current mode, but not in the new one. */
4521 if (GET_CODE (tem
) == SUBREG
4523 && HARD_REGISTER_P (other
))
4531 /* A subroutine of reload_as_needed. If INSN has a REG_EH_REGION note,
4532 examine all of the reload insns between PREV and NEXT exclusive, and
4533 annotate all that may trap. */
4536 fixup_eh_region_note (rtx insn
, rtx prev
, rtx next
)
4538 rtx note
= find_reg_note (insn
, REG_EH_REGION
, NULL_RTX
);
4541 if (!insn_could_throw_p (insn
))
4542 remove_note (insn
, note
);
4543 copy_reg_eh_region_note_forward (note
, NEXT_INSN (prev
), next
);
4546 /* Reload pseudo-registers into hard regs around each insn as needed.
4547 Additional register load insns are output before the insn that needs it
4548 and perhaps store insns after insns that modify the reloaded pseudo reg.
4550 reg_last_reload_reg and reg_reloaded_contents keep track of
4551 which registers are already available in reload registers.
4552 We update these for the reloads that we perform,
4553 as the insns are scanned. */
4556 reload_as_needed (int live_known
)
4558 struct insn_chain
*chain
;
4559 #if defined (AUTO_INC_DEC)
4564 memset (spill_reg_rtx
, 0, sizeof spill_reg_rtx
);
4565 memset (spill_reg_store
, 0, sizeof spill_reg_store
);
4566 reg_last_reload_reg
= XCNEWVEC (rtx
, max_regno
);
4567 INIT_REG_SET (®_has_output_reload
);
4568 CLEAR_HARD_REG_SET (reg_reloaded_valid
);
4569 CLEAR_HARD_REG_SET (reg_reloaded_call_part_clobbered
);
4571 set_initial_elim_offsets ();
4573 /* Generate a marker insn that we will move around. */
4574 marker
= emit_note (NOTE_INSN_DELETED
);
4575 unlink_insn_chain (marker
, marker
);
4577 for (chain
= reload_insn_chain
; chain
; chain
= chain
->next
)
4580 rtx insn
= chain
->insn
;
4581 rtx old_next
= NEXT_INSN (insn
);
4583 rtx old_prev
= PREV_INSN (insn
);
4586 /* If we pass a label, copy the offsets from the label information
4587 into the current offsets of each elimination. */
4589 set_offsets_for_label (insn
);
4591 else if (INSN_P (insn
))
4593 regset_head regs_to_forget
;
4594 INIT_REG_SET (®s_to_forget
);
4595 note_stores (PATTERN (insn
), forget_old_reloads_1
, ®s_to_forget
);
4597 /* If this is a USE and CLOBBER of a MEM, ensure that any
4598 references to eliminable registers have been removed. */
4600 if ((GET_CODE (PATTERN (insn
)) == USE
4601 || GET_CODE (PATTERN (insn
)) == CLOBBER
)
4602 && MEM_P (XEXP (PATTERN (insn
), 0)))
4603 XEXP (XEXP (PATTERN (insn
), 0), 0)
4604 = eliminate_regs (XEXP (XEXP (PATTERN (insn
), 0), 0),
4605 GET_MODE (XEXP (PATTERN (insn
), 0)),
4608 /* If we need to do register elimination processing, do so.
4609 This might delete the insn, in which case we are done. */
4610 if ((num_eliminable
|| num_eliminable_invariants
) && chain
->need_elim
)
4612 eliminate_regs_in_insn (insn
, 1);
4615 update_eliminable_offsets ();
4616 CLEAR_REG_SET (®s_to_forget
);
4621 /* If need_elim is nonzero but need_reload is zero, one might think
4622 that we could simply set n_reloads to 0. However, find_reloads
4623 could have done some manipulation of the insn (such as swapping
4624 commutative operands), and these manipulations are lost during
4625 the first pass for every insn that needs register elimination.
4626 So the actions of find_reloads must be redone here. */
4628 if (! chain
->need_elim
&& ! chain
->need_reload
4629 && ! chain
->need_operand_change
)
4631 /* First find the pseudo regs that must be reloaded for this insn.
4632 This info is returned in the tables reload_... (see reload.h).
4633 Also modify the body of INSN by substituting RELOAD
4634 rtx's for those pseudo regs. */
4637 CLEAR_REG_SET (®_has_output_reload
);
4638 CLEAR_HARD_REG_SET (reg_is_output_reload
);
4640 find_reloads (insn
, 1, spill_indirect_levels
, live_known
,
4646 rtx next
= NEXT_INSN (insn
);
4649 /* ??? PREV can get deleted by reload inheritance.
4650 Work around this by emitting a marker note. */
4651 prev
= PREV_INSN (insn
);
4652 reorder_insns_nobb (marker
, marker
, prev
);
4654 /* Now compute which reload regs to reload them into. Perhaps
4655 reusing reload regs from previous insns, or else output
4656 load insns to reload them. Maybe output store insns too.
4657 Record the choices of reload reg in reload_reg_rtx. */
4658 choose_reload_regs (chain
);
4660 /* Generate the insns to reload operands into or out of
4661 their reload regs. */
4662 emit_reload_insns (chain
);
4664 /* Substitute the chosen reload regs from reload_reg_rtx
4665 into the insn's body (or perhaps into the bodies of other
4666 load and store insn that we just made for reloading
4667 and that we moved the structure into). */
4668 subst_reloads (insn
);
4670 prev
= PREV_INSN (marker
);
4671 unlink_insn_chain (marker
, marker
);
4673 /* Adjust the exception region notes for loads and stores. */
4674 if (cfun
->can_throw_non_call_exceptions
&& !CALL_P (insn
))
4675 fixup_eh_region_note (insn
, prev
, next
);
4677 /* Adjust the location of REG_ARGS_SIZE. */
4678 p
= find_reg_note (insn
, REG_ARGS_SIZE
, NULL_RTX
);
4681 remove_note (insn
, p
);
4682 fixup_args_size_notes (prev
, PREV_INSN (next
),
4683 INTVAL (XEXP (p
, 0)));
4686 /* If this was an ASM, make sure that all the reload insns
4687 we have generated are valid. If not, give an error
4689 if (asm_noperands (PATTERN (insn
)) >= 0)
4690 for (p
= NEXT_INSN (prev
); p
!= next
; p
= NEXT_INSN (p
))
4691 if (p
!= insn
&& INSN_P (p
)
4692 && GET_CODE (PATTERN (p
)) != USE
4693 && (recog_memoized (p
) < 0
4694 || (extract_insn (p
), ! constrain_operands (1))))
4696 error_for_asm (insn
,
4697 "%<asm%> operand requires "
4698 "impossible reload");
4703 if (num_eliminable
&& chain
->need_elim
)
4704 update_eliminable_offsets ();
4706 /* Any previously reloaded spilled pseudo reg, stored in this insn,
4707 is no longer validly lying around to save a future reload.
4708 Note that this does not detect pseudos that were reloaded
4709 for this insn in order to be stored in
4710 (obeying register constraints). That is correct; such reload
4711 registers ARE still valid. */
4712 forget_marked_reloads (®s_to_forget
);
4713 CLEAR_REG_SET (®s_to_forget
);
4715 /* There may have been CLOBBER insns placed after INSN. So scan
4716 between INSN and NEXT and use them to forget old reloads. */
4717 for (x
= NEXT_INSN (insn
); x
!= old_next
; x
= NEXT_INSN (x
))
4718 if (NONJUMP_INSN_P (x
) && GET_CODE (PATTERN (x
)) == CLOBBER
)
4719 note_stores (PATTERN (x
), forget_old_reloads_1
, NULL
);
4722 /* Likewise for regs altered by auto-increment in this insn.
4723 REG_INC notes have been changed by reloading:
4724 find_reloads_address_1 records substitutions for them,
4725 which have been performed by subst_reloads above. */
4726 for (i
= n_reloads
- 1; i
>= 0; i
--)
4728 rtx in_reg
= rld
[i
].in_reg
;
4731 enum rtx_code code
= GET_CODE (in_reg
);
4732 /* PRE_INC / PRE_DEC will have the reload register ending up
4733 with the same value as the stack slot, but that doesn't
4734 hold true for POST_INC / POST_DEC. Either we have to
4735 convert the memory access to a true POST_INC / POST_DEC,
4736 or we can't use the reload register for inheritance. */
4737 if ((code
== POST_INC
|| code
== POST_DEC
)
4738 && TEST_HARD_REG_BIT (reg_reloaded_valid
,
4739 REGNO (rld
[i
].reg_rtx
))
4740 /* Make sure it is the inc/dec pseudo, and not
4741 some other (e.g. output operand) pseudo. */
4742 && ((unsigned) reg_reloaded_contents
[REGNO (rld
[i
].reg_rtx
)]
4743 == REGNO (XEXP (in_reg
, 0))))
4746 rtx reload_reg
= rld
[i
].reg_rtx
;
4747 enum machine_mode mode
= GET_MODE (reload_reg
);
4751 for (p
= PREV_INSN (old_next
); p
!= prev
; p
= PREV_INSN (p
))
4753 /* We really want to ignore REG_INC notes here, so
4754 use PATTERN (p) as argument to reg_set_p . */
4755 if (reg_set_p (reload_reg
, PATTERN (p
)))
4757 n
= count_occurrences (PATTERN (p
), reload_reg
, 0);
4763 = gen_rtx_fmt_e (code
, mode
, reload_reg
);
4765 validate_replace_rtx_group (reload_reg
,
4767 n
= verify_changes (0);
4769 /* We must also verify that the constraints
4770 are met after the replacement. Make sure
4771 extract_insn is only called for an insn
4772 where the replacements were found to be
4777 n
= constrain_operands (1);
4780 /* If the constraints were not met, then
4781 undo the replacement, else confirm it. */
4785 confirm_change_group ();
4791 add_reg_note (p
, REG_INC
, reload_reg
);
4792 /* Mark this as having an output reload so that the
4793 REG_INC processing code below won't invalidate
4794 the reload for inheritance. */
4795 SET_HARD_REG_BIT (reg_is_output_reload
,
4796 REGNO (reload_reg
));
4797 SET_REGNO_REG_SET (®_has_output_reload
,
4798 REGNO (XEXP (in_reg
, 0)));
4801 forget_old_reloads_1 (XEXP (in_reg
, 0), NULL_RTX
,
4804 else if ((code
== PRE_INC
|| code
== PRE_DEC
)
4805 && TEST_HARD_REG_BIT (reg_reloaded_valid
,
4806 REGNO (rld
[i
].reg_rtx
))
4807 /* Make sure it is the inc/dec pseudo, and not
4808 some other (e.g. output operand) pseudo. */
4809 && ((unsigned) reg_reloaded_contents
[REGNO (rld
[i
].reg_rtx
)]
4810 == REGNO (XEXP (in_reg
, 0))))
4812 SET_HARD_REG_BIT (reg_is_output_reload
,
4813 REGNO (rld
[i
].reg_rtx
));
4814 SET_REGNO_REG_SET (®_has_output_reload
,
4815 REGNO (XEXP (in_reg
, 0)));
4817 else if (code
== PRE_INC
|| code
== PRE_DEC
4818 || code
== POST_INC
|| code
== POST_DEC
)
4820 int in_regno
= REGNO (XEXP (in_reg
, 0));
4822 if (reg_last_reload_reg
[in_regno
] != NULL_RTX
)
4825 bool forget_p
= true;
4827 in_hard_regno
= REGNO (reg_last_reload_reg
[in_regno
]);
4828 if (TEST_HARD_REG_BIT (reg_reloaded_valid
,
4831 for (x
= old_prev
? NEXT_INSN (old_prev
) : insn
;
4834 if (x
== reg_reloaded_insn
[in_hard_regno
])
4840 /* If for some reasons, we didn't set up
4841 reg_last_reload_reg in this insn,
4842 invalidate inheritance from previous
4843 insns for the incremented/decremented
4844 register. Such registers will be not in
4845 reg_has_output_reload. Invalidate it
4846 also if the corresponding element in
4847 reg_reloaded_insn is also
4850 forget_old_reloads_1 (XEXP (in_reg
, 0),
4856 /* If a pseudo that got a hard register is auto-incremented,
4857 we must purge records of copying it into pseudos without
4859 for (x
= REG_NOTES (insn
); x
; x
= XEXP (x
, 1))
4860 if (REG_NOTE_KIND (x
) == REG_INC
)
4862 /* See if this pseudo reg was reloaded in this insn.
4863 If so, its last-reload info is still valid
4864 because it is based on this insn's reload. */
4865 for (i
= 0; i
< n_reloads
; i
++)
4866 if (rld
[i
].out
== XEXP (x
, 0))
4870 forget_old_reloads_1 (XEXP (x
, 0), NULL_RTX
, NULL
);
4874 /* A reload reg's contents are unknown after a label. */
4876 CLEAR_HARD_REG_SET (reg_reloaded_valid
);
4878 /* Don't assume a reload reg is still good after a call insn
4879 if it is a call-used reg, or if it contains a value that will
4880 be partially clobbered by the call. */
4881 else if (CALL_P (insn
))
4883 AND_COMPL_HARD_REG_SET (reg_reloaded_valid
, call_used_reg_set
);
4884 AND_COMPL_HARD_REG_SET (reg_reloaded_valid
, reg_reloaded_call_part_clobbered
);
4886 /* If this is a call to a setjmp-type function, we must not
4887 reuse any reload reg contents across the call; that will
4888 just be clobbered by other uses of the register in later
4889 code, before the longjmp. */
4890 if (find_reg_note (insn
, REG_SETJMP
, NULL_RTX
))
4891 CLEAR_HARD_REG_SET (reg_reloaded_valid
);
4896 free (reg_last_reload_reg
);
4897 CLEAR_REG_SET (®_has_output_reload
);
4900 /* Discard all record of any value reloaded from X,
4901 or reloaded in X from someplace else;
4902 unless X is an output reload reg of the current insn.
4904 X may be a hard reg (the reload reg)
4905 or it may be a pseudo reg that was reloaded from.
4907 When DATA is non-NULL just mark the registers in regset
4908 to be forgotten later. */
4911 forget_old_reloads_1 (rtx x
, const_rtx ignored ATTRIBUTE_UNUSED
,
4916 regset regs
= (regset
) data
;
4918 /* note_stores does give us subregs of hard regs,
4919 subreg_regno_offset requires a hard reg. */
4920 while (GET_CODE (x
) == SUBREG
)
4922 /* We ignore the subreg offset when calculating the regno,
4923 because we are using the entire underlying hard register
4933 if (regno
>= FIRST_PSEUDO_REGISTER
)
4939 nr
= hard_regno_nregs
[regno
][GET_MODE (x
)];
4940 /* Storing into a spilled-reg invalidates its contents.
4941 This can happen if a block-local pseudo is allocated to that reg
4942 and it wasn't spilled because this block's total need is 0.
4943 Then some insn might have an optional reload and use this reg. */
4945 for (i
= 0; i
< nr
; i
++)
4946 /* But don't do this if the reg actually serves as an output
4947 reload reg in the current instruction. */
4949 || ! TEST_HARD_REG_BIT (reg_is_output_reload
, regno
+ i
))
4951 CLEAR_HARD_REG_BIT (reg_reloaded_valid
, regno
+ i
);
4952 spill_reg_store
[regno
+ i
] = 0;
4958 SET_REGNO_REG_SET (regs
, regno
+ nr
);
4961 /* Since value of X has changed,
4962 forget any value previously copied from it. */
4965 /* But don't forget a copy if this is the output reload
4966 that establishes the copy's validity. */
4968 || !REGNO_REG_SET_P (®_has_output_reload
, regno
+ nr
))
4969 reg_last_reload_reg
[regno
+ nr
] = 0;
4973 /* Forget the reloads marked in regset by previous function. */
4975 forget_marked_reloads (regset regs
)
4978 reg_set_iterator rsi
;
4979 EXECUTE_IF_SET_IN_REG_SET (regs
, 0, reg
, rsi
)
4981 if (reg
< FIRST_PSEUDO_REGISTER
4982 /* But don't do this if the reg actually serves as an output
4983 reload reg in the current instruction. */
4985 || ! TEST_HARD_REG_BIT (reg_is_output_reload
, reg
)))
4987 CLEAR_HARD_REG_BIT (reg_reloaded_valid
, reg
);
4988 spill_reg_store
[reg
] = 0;
4991 || !REGNO_REG_SET_P (®_has_output_reload
, reg
))
4992 reg_last_reload_reg
[reg
] = 0;
4996 /* The following HARD_REG_SETs indicate when each hard register is
4997 used for a reload of various parts of the current insn. */
4999 /* If reg is unavailable for all reloads. */
5000 static HARD_REG_SET reload_reg_unavailable
;
5001 /* If reg is in use as a reload reg for a RELOAD_OTHER reload. */
5002 static HARD_REG_SET reload_reg_used
;
5003 /* If reg is in use for a RELOAD_FOR_INPUT_ADDRESS reload for operand I. */
5004 static HARD_REG_SET reload_reg_used_in_input_addr
[MAX_RECOG_OPERANDS
];
5005 /* If reg is in use for a RELOAD_FOR_INPADDR_ADDRESS reload for operand I. */
5006 static HARD_REG_SET reload_reg_used_in_inpaddr_addr
[MAX_RECOG_OPERANDS
];
5007 /* If reg is in use for a RELOAD_FOR_OUTPUT_ADDRESS reload for operand I. */
5008 static HARD_REG_SET reload_reg_used_in_output_addr
[MAX_RECOG_OPERANDS
];
5009 /* If reg is in use for a RELOAD_FOR_OUTADDR_ADDRESS reload for operand I. */
5010 static HARD_REG_SET reload_reg_used_in_outaddr_addr
[MAX_RECOG_OPERANDS
];
5011 /* If reg is in use for a RELOAD_FOR_INPUT reload for operand I. */
5012 static HARD_REG_SET reload_reg_used_in_input
[MAX_RECOG_OPERANDS
];
5013 /* If reg is in use for a RELOAD_FOR_OUTPUT reload for operand I. */
5014 static HARD_REG_SET reload_reg_used_in_output
[MAX_RECOG_OPERANDS
];
5015 /* If reg is in use for a RELOAD_FOR_OPERAND_ADDRESS reload. */
5016 static HARD_REG_SET reload_reg_used_in_op_addr
;
5017 /* If reg is in use for a RELOAD_FOR_OPADDR_ADDR reload. */
5018 static HARD_REG_SET reload_reg_used_in_op_addr_reload
;
5019 /* If reg is in use for a RELOAD_FOR_INSN reload. */
5020 static HARD_REG_SET reload_reg_used_in_insn
;
5021 /* If reg is in use for a RELOAD_FOR_OTHER_ADDRESS reload. */
5022 static HARD_REG_SET reload_reg_used_in_other_addr
;
5024 /* If reg is in use as a reload reg for any sort of reload. */
5025 static HARD_REG_SET reload_reg_used_at_all
;
5027 /* If reg is use as an inherited reload. We just mark the first register
5029 static HARD_REG_SET reload_reg_used_for_inherit
;
5031 /* Records which hard regs are used in any way, either as explicit use or
5032 by being allocated to a pseudo during any point of the current insn. */
5033 static HARD_REG_SET reg_used_in_insn
;
5035 /* Mark reg REGNO as in use for a reload of the sort spec'd by OPNUM and
5036 TYPE. MODE is used to indicate how many consecutive regs are
5040 mark_reload_reg_in_use (unsigned int regno
, int opnum
, enum reload_type type
,
5041 enum machine_mode mode
)
5046 add_to_hard_reg_set (&reload_reg_used
, mode
, regno
);
5049 case RELOAD_FOR_INPUT_ADDRESS
:
5050 add_to_hard_reg_set (&reload_reg_used_in_input_addr
[opnum
], mode
, regno
);
5053 case RELOAD_FOR_INPADDR_ADDRESS
:
5054 add_to_hard_reg_set (&reload_reg_used_in_inpaddr_addr
[opnum
], mode
, regno
);
5057 case RELOAD_FOR_OUTPUT_ADDRESS
:
5058 add_to_hard_reg_set (&reload_reg_used_in_output_addr
[opnum
], mode
, regno
);
5061 case RELOAD_FOR_OUTADDR_ADDRESS
:
5062 add_to_hard_reg_set (&reload_reg_used_in_outaddr_addr
[opnum
], mode
, regno
);
5065 case RELOAD_FOR_OPERAND_ADDRESS
:
5066 add_to_hard_reg_set (&reload_reg_used_in_op_addr
, mode
, regno
);
5069 case RELOAD_FOR_OPADDR_ADDR
:
5070 add_to_hard_reg_set (&reload_reg_used_in_op_addr_reload
, mode
, regno
);
5073 case RELOAD_FOR_OTHER_ADDRESS
:
5074 add_to_hard_reg_set (&reload_reg_used_in_other_addr
, mode
, regno
);
5077 case RELOAD_FOR_INPUT
:
5078 add_to_hard_reg_set (&reload_reg_used_in_input
[opnum
], mode
, regno
);
5081 case RELOAD_FOR_OUTPUT
:
5082 add_to_hard_reg_set (&reload_reg_used_in_output
[opnum
], mode
, regno
);
5085 case RELOAD_FOR_INSN
:
5086 add_to_hard_reg_set (&reload_reg_used_in_insn
, mode
, regno
);
5090 add_to_hard_reg_set (&reload_reg_used_at_all
, mode
, regno
);
5093 /* Similarly, but show REGNO is no longer in use for a reload. */
5096 clear_reload_reg_in_use (unsigned int regno
, int opnum
,
5097 enum reload_type type
, enum machine_mode mode
)
5099 unsigned int nregs
= hard_regno_nregs
[regno
][mode
];
5100 unsigned int start_regno
, end_regno
, r
;
5102 /* A complication is that for some reload types, inheritance might
5103 allow multiple reloads of the same types to share a reload register.
5104 We set check_opnum if we have to check only reloads with the same
5105 operand number, and check_any if we have to check all reloads. */
5106 int check_opnum
= 0;
5108 HARD_REG_SET
*used_in_set
;
5113 used_in_set
= &reload_reg_used
;
5116 case RELOAD_FOR_INPUT_ADDRESS
:
5117 used_in_set
= &reload_reg_used_in_input_addr
[opnum
];
5120 case RELOAD_FOR_INPADDR_ADDRESS
:
5122 used_in_set
= &reload_reg_used_in_inpaddr_addr
[opnum
];
5125 case RELOAD_FOR_OUTPUT_ADDRESS
:
5126 used_in_set
= &reload_reg_used_in_output_addr
[opnum
];
5129 case RELOAD_FOR_OUTADDR_ADDRESS
:
5131 used_in_set
= &reload_reg_used_in_outaddr_addr
[opnum
];
5134 case RELOAD_FOR_OPERAND_ADDRESS
:
5135 used_in_set
= &reload_reg_used_in_op_addr
;
5138 case RELOAD_FOR_OPADDR_ADDR
:
5140 used_in_set
= &reload_reg_used_in_op_addr_reload
;
5143 case RELOAD_FOR_OTHER_ADDRESS
:
5144 used_in_set
= &reload_reg_used_in_other_addr
;
5148 case RELOAD_FOR_INPUT
:
5149 used_in_set
= &reload_reg_used_in_input
[opnum
];
5152 case RELOAD_FOR_OUTPUT
:
5153 used_in_set
= &reload_reg_used_in_output
[opnum
];
5156 case RELOAD_FOR_INSN
:
5157 used_in_set
= &reload_reg_used_in_insn
;
5162 /* We resolve conflicts with remaining reloads of the same type by
5163 excluding the intervals of reload registers by them from the
5164 interval of freed reload registers. Since we only keep track of
5165 one set of interval bounds, we might have to exclude somewhat
5166 more than what would be necessary if we used a HARD_REG_SET here.
5167 But this should only happen very infrequently, so there should
5168 be no reason to worry about it. */
5170 start_regno
= regno
;
5171 end_regno
= regno
+ nregs
;
5172 if (check_opnum
|| check_any
)
5174 for (i
= n_reloads
- 1; i
>= 0; i
--)
5176 if (rld
[i
].when_needed
== type
5177 && (check_any
|| rld
[i
].opnum
== opnum
)
5180 unsigned int conflict_start
= true_regnum (rld
[i
].reg_rtx
);
5181 unsigned int conflict_end
5182 = end_hard_regno (rld
[i
].mode
, conflict_start
);
5184 /* If there is an overlap with the first to-be-freed register,
5185 adjust the interval start. */
5186 if (conflict_start
<= start_regno
&& conflict_end
> start_regno
)
5187 start_regno
= conflict_end
;
5188 /* Otherwise, if there is a conflict with one of the other
5189 to-be-freed registers, adjust the interval end. */
5190 if (conflict_start
> start_regno
&& conflict_start
< end_regno
)
5191 end_regno
= conflict_start
;
5196 for (r
= start_regno
; r
< end_regno
; r
++)
5197 CLEAR_HARD_REG_BIT (*used_in_set
, r
);
5200 /* 1 if reg REGNO is free as a reload reg for a reload of the sort
5201 specified by OPNUM and TYPE. */
5204 reload_reg_free_p (unsigned int regno
, int opnum
, enum reload_type type
)
5208 /* In use for a RELOAD_OTHER means it's not available for anything. */
5209 if (TEST_HARD_REG_BIT (reload_reg_used
, regno
)
5210 || TEST_HARD_REG_BIT (reload_reg_unavailable
, regno
))
5216 /* In use for anything means we can't use it for RELOAD_OTHER. */
5217 if (TEST_HARD_REG_BIT (reload_reg_used_in_other_addr
, regno
)
5218 || TEST_HARD_REG_BIT (reload_reg_used_in_op_addr
, regno
)
5219 || TEST_HARD_REG_BIT (reload_reg_used_in_op_addr_reload
, regno
)
5220 || TEST_HARD_REG_BIT (reload_reg_used_in_insn
, regno
))
5223 for (i
= 0; i
< reload_n_operands
; i
++)
5224 if (TEST_HARD_REG_BIT (reload_reg_used_in_input_addr
[i
], regno
)
5225 || TEST_HARD_REG_BIT (reload_reg_used_in_inpaddr_addr
[i
], regno
)
5226 || TEST_HARD_REG_BIT (reload_reg_used_in_output_addr
[i
], regno
)
5227 || TEST_HARD_REG_BIT (reload_reg_used_in_outaddr_addr
[i
], regno
)
5228 || TEST_HARD_REG_BIT (reload_reg_used_in_input
[i
], regno
)
5229 || TEST_HARD_REG_BIT (reload_reg_used_in_output
[i
], regno
))
5234 case RELOAD_FOR_INPUT
:
5235 if (TEST_HARD_REG_BIT (reload_reg_used_in_insn
, regno
)
5236 || TEST_HARD_REG_BIT (reload_reg_used_in_op_addr
, regno
))
5239 if (TEST_HARD_REG_BIT (reload_reg_used_in_op_addr_reload
, regno
))
5242 /* If it is used for some other input, can't use it. */
5243 for (i
= 0; i
< reload_n_operands
; i
++)
5244 if (TEST_HARD_REG_BIT (reload_reg_used_in_input
[i
], regno
))
5247 /* If it is used in a later operand's address, can't use it. */
5248 for (i
= opnum
+ 1; i
< reload_n_operands
; i
++)
5249 if (TEST_HARD_REG_BIT (reload_reg_used_in_input_addr
[i
], regno
)
5250 || TEST_HARD_REG_BIT (reload_reg_used_in_inpaddr_addr
[i
], regno
))
5255 case RELOAD_FOR_INPUT_ADDRESS
:
5256 /* Can't use a register if it is used for an input address for this
5257 operand or used as an input in an earlier one. */
5258 if (TEST_HARD_REG_BIT (reload_reg_used_in_input_addr
[opnum
], regno
)
5259 || TEST_HARD_REG_BIT (reload_reg_used_in_inpaddr_addr
[opnum
], regno
))
5262 for (i
= 0; i
< opnum
; i
++)
5263 if (TEST_HARD_REG_BIT (reload_reg_used_in_input
[i
], regno
))
5268 case RELOAD_FOR_INPADDR_ADDRESS
:
5269 /* Can't use a register if it is used for an input address
5270 for this operand or used as an input in an earlier
5272 if (TEST_HARD_REG_BIT (reload_reg_used_in_inpaddr_addr
[opnum
], regno
))
5275 for (i
= 0; i
< opnum
; i
++)
5276 if (TEST_HARD_REG_BIT (reload_reg_used_in_input
[i
], regno
))
5281 case RELOAD_FOR_OUTPUT_ADDRESS
:
5282 /* Can't use a register if it is used for an output address for this
5283 operand or used as an output in this or a later operand. Note
5284 that multiple output operands are emitted in reverse order, so
5285 the conflicting ones are those with lower indices. */
5286 if (TEST_HARD_REG_BIT (reload_reg_used_in_output_addr
[opnum
], regno
))
5289 for (i
= 0; i
<= opnum
; i
++)
5290 if (TEST_HARD_REG_BIT (reload_reg_used_in_output
[i
], regno
))
5295 case RELOAD_FOR_OUTADDR_ADDRESS
:
5296 /* Can't use a register if it is used for an output address
5297 for this operand or used as an output in this or a
5298 later operand. Note that multiple output operands are
5299 emitted in reverse order, so the conflicting ones are
5300 those with lower indices. */
5301 if (TEST_HARD_REG_BIT (reload_reg_used_in_outaddr_addr
[opnum
], regno
))
5304 for (i
= 0; i
<= opnum
; i
++)
5305 if (TEST_HARD_REG_BIT (reload_reg_used_in_output
[i
], regno
))
5310 case RELOAD_FOR_OPERAND_ADDRESS
:
5311 for (i
= 0; i
< reload_n_operands
; i
++)
5312 if (TEST_HARD_REG_BIT (reload_reg_used_in_input
[i
], regno
))
5315 return (! TEST_HARD_REG_BIT (reload_reg_used_in_insn
, regno
)
5316 && ! TEST_HARD_REG_BIT (reload_reg_used_in_op_addr
, regno
));
5318 case RELOAD_FOR_OPADDR_ADDR
:
5319 for (i
= 0; i
< reload_n_operands
; i
++)
5320 if (TEST_HARD_REG_BIT (reload_reg_used_in_input
[i
], regno
))
5323 return (!TEST_HARD_REG_BIT (reload_reg_used_in_op_addr_reload
, regno
));
5325 case RELOAD_FOR_OUTPUT
:
5326 /* This cannot share a register with RELOAD_FOR_INSN reloads, other
5327 outputs, or an operand address for this or an earlier output.
5328 Note that multiple output operands are emitted in reverse order,
5329 so the conflicting ones are those with higher indices. */
5330 if (TEST_HARD_REG_BIT (reload_reg_used_in_insn
, regno
))
5333 for (i
= 0; i
< reload_n_operands
; i
++)
5334 if (TEST_HARD_REG_BIT (reload_reg_used_in_output
[i
], regno
))
5337 for (i
= opnum
; i
< reload_n_operands
; i
++)
5338 if (TEST_HARD_REG_BIT (reload_reg_used_in_output_addr
[i
], regno
)
5339 || TEST_HARD_REG_BIT (reload_reg_used_in_outaddr_addr
[i
], regno
))
5344 case RELOAD_FOR_INSN
:
5345 for (i
= 0; i
< reload_n_operands
; i
++)
5346 if (TEST_HARD_REG_BIT (reload_reg_used_in_input
[i
], regno
)
5347 || TEST_HARD_REG_BIT (reload_reg_used_in_output
[i
], regno
))
5350 return (! TEST_HARD_REG_BIT (reload_reg_used_in_insn
, regno
)
5351 && ! TEST_HARD_REG_BIT (reload_reg_used_in_op_addr
, regno
));
5353 case RELOAD_FOR_OTHER_ADDRESS
:
5354 return ! TEST_HARD_REG_BIT (reload_reg_used_in_other_addr
, regno
);
5361 /* Return 1 if the value in reload reg REGNO, as used by the reload with
5362 the number RELOADNUM, is still available in REGNO at the end of the insn.
5364 We can assume that the reload reg was already tested for availability
5365 at the time it is needed, and we should not check this again,
5366 in case the reg has already been marked in use. */
5369 reload_reg_reaches_end_p (unsigned int regno
, int reloadnum
)
5371 int opnum
= rld
[reloadnum
].opnum
;
5372 enum reload_type type
= rld
[reloadnum
].when_needed
;
5375 /* See if there is a reload with the same type for this operand, using
5376 the same register. This case is not handled by the code below. */
5377 for (i
= reloadnum
+ 1; i
< n_reloads
; i
++)
5382 if (rld
[i
].opnum
!= opnum
|| rld
[i
].when_needed
!= type
)
5384 reg
= rld
[i
].reg_rtx
;
5385 if (reg
== NULL_RTX
)
5387 nregs
= hard_regno_nregs
[REGNO (reg
)][GET_MODE (reg
)];
5388 if (regno
>= REGNO (reg
) && regno
< REGNO (reg
) + nregs
)
5395 /* Since a RELOAD_OTHER reload claims the reg for the entire insn,
5396 its value must reach the end. */
5399 /* If this use is for part of the insn,
5400 its value reaches if no subsequent part uses the same register.
5401 Just like the above function, don't try to do this with lots
5404 case RELOAD_FOR_OTHER_ADDRESS
:
5405 /* Here we check for everything else, since these don't conflict
5406 with anything else and everything comes later. */
5408 for (i
= 0; i
< reload_n_operands
; i
++)
5409 if (TEST_HARD_REG_BIT (reload_reg_used_in_output_addr
[i
], regno
)
5410 || TEST_HARD_REG_BIT (reload_reg_used_in_outaddr_addr
[i
], regno
)
5411 || TEST_HARD_REG_BIT (reload_reg_used_in_output
[i
], regno
)
5412 || TEST_HARD_REG_BIT (reload_reg_used_in_input_addr
[i
], regno
)
5413 || TEST_HARD_REG_BIT (reload_reg_used_in_inpaddr_addr
[i
], regno
)
5414 || TEST_HARD_REG_BIT (reload_reg_used_in_input
[i
], regno
))
5417 return (! TEST_HARD_REG_BIT (reload_reg_used_in_op_addr
, regno
)
5418 && ! TEST_HARD_REG_BIT (reload_reg_used_in_op_addr_reload
, regno
)
5419 && ! TEST_HARD_REG_BIT (reload_reg_used_in_insn
, regno
)
5420 && ! TEST_HARD_REG_BIT (reload_reg_used
, regno
));
5422 case RELOAD_FOR_INPUT_ADDRESS
:
5423 case RELOAD_FOR_INPADDR_ADDRESS
:
5424 /* Similar, except that we check only for this and subsequent inputs
5425 and the address of only subsequent inputs and we do not need
5426 to check for RELOAD_OTHER objects since they are known not to
5429 for (i
= opnum
; i
< reload_n_operands
; i
++)
5430 if (TEST_HARD_REG_BIT (reload_reg_used_in_input
[i
], regno
))
5433 /* Reload register of reload with type RELOAD_FOR_INPADDR_ADDRESS
5434 could be killed if the register is also used by reload with type
5435 RELOAD_FOR_INPUT_ADDRESS, so check it. */
5436 if (type
== RELOAD_FOR_INPADDR_ADDRESS
5437 && TEST_HARD_REG_BIT (reload_reg_used_in_input_addr
[opnum
], regno
))
5440 for (i
= opnum
+ 1; i
< reload_n_operands
; i
++)
5441 if (TEST_HARD_REG_BIT (reload_reg_used_in_input_addr
[i
], regno
)
5442 || TEST_HARD_REG_BIT (reload_reg_used_in_inpaddr_addr
[i
], regno
))
5445 for (i
= 0; i
< reload_n_operands
; i
++)
5446 if (TEST_HARD_REG_BIT (reload_reg_used_in_output_addr
[i
], regno
)
5447 || TEST_HARD_REG_BIT (reload_reg_used_in_outaddr_addr
[i
], regno
)
5448 || TEST_HARD_REG_BIT (reload_reg_used_in_output
[i
], regno
))
5451 if (TEST_HARD_REG_BIT (reload_reg_used_in_op_addr_reload
, regno
))
5454 return (!TEST_HARD_REG_BIT (reload_reg_used_in_op_addr
, regno
)
5455 && !TEST_HARD_REG_BIT (reload_reg_used_in_insn
, regno
)
5456 && !TEST_HARD_REG_BIT (reload_reg_used
, regno
));
5458 case RELOAD_FOR_INPUT
:
5459 /* Similar to input address, except we start at the next operand for
5460 both input and input address and we do not check for
5461 RELOAD_FOR_OPERAND_ADDRESS and RELOAD_FOR_INSN since these
5464 for (i
= opnum
+ 1; i
< reload_n_operands
; i
++)
5465 if (TEST_HARD_REG_BIT (reload_reg_used_in_input_addr
[i
], regno
)
5466 || TEST_HARD_REG_BIT (reload_reg_used_in_inpaddr_addr
[i
], regno
)
5467 || TEST_HARD_REG_BIT (reload_reg_used_in_input
[i
], regno
))
5470 /* ... fall through ... */
5472 case RELOAD_FOR_OPERAND_ADDRESS
:
5473 /* Check outputs and their addresses. */
5475 for (i
= 0; i
< reload_n_operands
; i
++)
5476 if (TEST_HARD_REG_BIT (reload_reg_used_in_output_addr
[i
], regno
)
5477 || TEST_HARD_REG_BIT (reload_reg_used_in_outaddr_addr
[i
], regno
)
5478 || TEST_HARD_REG_BIT (reload_reg_used_in_output
[i
], regno
))
5481 return (!TEST_HARD_REG_BIT (reload_reg_used
, regno
));
5483 case RELOAD_FOR_OPADDR_ADDR
:
5484 for (i
= 0; i
< reload_n_operands
; i
++)
5485 if (TEST_HARD_REG_BIT (reload_reg_used_in_output_addr
[i
], regno
)
5486 || TEST_HARD_REG_BIT (reload_reg_used_in_outaddr_addr
[i
], regno
)
5487 || TEST_HARD_REG_BIT (reload_reg_used_in_output
[i
], regno
))
5490 return (!TEST_HARD_REG_BIT (reload_reg_used_in_op_addr
, regno
)
5491 && !TEST_HARD_REG_BIT (reload_reg_used_in_insn
, regno
)
5492 && !TEST_HARD_REG_BIT (reload_reg_used
, regno
));
5494 case RELOAD_FOR_INSN
:
5495 /* These conflict with other outputs with RELOAD_OTHER. So
5496 we need only check for output addresses. */
5498 opnum
= reload_n_operands
;
5500 /* ... fall through ... */
5502 case RELOAD_FOR_OUTPUT
:
5503 case RELOAD_FOR_OUTPUT_ADDRESS
:
5504 case RELOAD_FOR_OUTADDR_ADDRESS
:
5505 /* We already know these can't conflict with a later output. So the
5506 only thing to check are later output addresses.
5507 Note that multiple output operands are emitted in reverse order,
5508 so the conflicting ones are those with lower indices. */
5509 for (i
= 0; i
< opnum
; i
++)
5510 if (TEST_HARD_REG_BIT (reload_reg_used_in_output_addr
[i
], regno
)
5511 || TEST_HARD_REG_BIT (reload_reg_used_in_outaddr_addr
[i
], regno
))
5514 /* Reload register of reload with type RELOAD_FOR_OUTADDR_ADDRESS
5515 could be killed if the register is also used by reload with type
5516 RELOAD_FOR_OUTPUT_ADDRESS, so check it. */
5517 if (type
== RELOAD_FOR_OUTADDR_ADDRESS
5518 && TEST_HARD_REG_BIT (reload_reg_used_in_outaddr_addr
[opnum
], regno
))
5528 /* Like reload_reg_reaches_end_p, but check that the condition holds for
5529 every register in REG. */
5532 reload_reg_rtx_reaches_end_p (rtx reg
, int reloadnum
)
5536 for (i
= REGNO (reg
); i
< END_REGNO (reg
); i
++)
5537 if (!reload_reg_reaches_end_p (i
, reloadnum
))
5543 /* Returns whether R1 and R2 are uniquely chained: the value of one
5544 is used by the other, and that value is not used by any other
5545 reload for this insn. This is used to partially undo the decision
5546 made in find_reloads when in the case of multiple
5547 RELOAD_FOR_OPERAND_ADDRESS reloads it converts all
5548 RELOAD_FOR_OPADDR_ADDR reloads into RELOAD_FOR_OPERAND_ADDRESS
5549 reloads. This code tries to avoid the conflict created by that
5550 change. It might be cleaner to explicitly keep track of which
5551 RELOAD_FOR_OPADDR_ADDR reload is associated with which
5552 RELOAD_FOR_OPERAND_ADDRESS reload, rather than to try to detect
5553 this after the fact. */
5555 reloads_unique_chain_p (int r1
, int r2
)
5559 /* We only check input reloads. */
5560 if (! rld
[r1
].in
|| ! rld
[r2
].in
)
5563 /* Avoid anything with output reloads. */
5564 if (rld
[r1
].out
|| rld
[r2
].out
)
5567 /* "chained" means one reload is a component of the other reload,
5568 not the same as the other reload. */
5569 if (rld
[r1
].opnum
!= rld
[r2
].opnum
5570 || rtx_equal_p (rld
[r1
].in
, rld
[r2
].in
)
5571 || rld
[r1
].optional
|| rld
[r2
].optional
5572 || ! (reg_mentioned_p (rld
[r1
].in
, rld
[r2
].in
)
5573 || reg_mentioned_p (rld
[r2
].in
, rld
[r1
].in
)))
5576 for (i
= 0; i
< n_reloads
; i
++)
5577 /* Look for input reloads that aren't our two */
5578 if (i
!= r1
&& i
!= r2
&& rld
[i
].in
)
5580 /* If our reload is mentioned at all, it isn't a simple chain. */
5581 if (reg_mentioned_p (rld
[r1
].in
, rld
[i
].in
))
5587 /* The recursive function change all occurrences of WHAT in *WHERE
5590 substitute (rtx
*where
, const_rtx what
, rtx repl
)
5599 if (*where
== what
|| rtx_equal_p (*where
, what
))
5601 /* Record the location of the changed rtx. */
5602 VEC_safe_push (rtx_p
, heap
, substitute_stack
, where
);
5607 code
= GET_CODE (*where
);
5608 fmt
= GET_RTX_FORMAT (code
);
5609 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
5615 for (j
= XVECLEN (*where
, i
) - 1; j
>= 0; j
--)
5616 substitute (&XVECEXP (*where
, i
, j
), what
, repl
);
5618 else if (fmt
[i
] == 'e')
5619 substitute (&XEXP (*where
, i
), what
, repl
);
5623 /* The function returns TRUE if chain of reload R1 and R2 (in any
5624 order) can be evaluated without usage of intermediate register for
5625 the reload containing another reload. It is important to see
5626 gen_reload to understand what the function is trying to do. As an
5627 example, let us have reload chain
5630 r1: <something> + const
5632 and reload R2 got reload reg HR. The function returns true if
5633 there is a correct insn HR = HR + <something>. Otherwise,
5634 gen_reload will use intermediate register (and this is the reload
5635 reg for R1) to reload <something>.
5637 We need this function to find a conflict for chain reloads. In our
5638 example, if HR = HR + <something> is incorrect insn, then we cannot
5639 use HR as a reload register for R2. If we do use it then we get a
5648 gen_reload_chain_without_interm_reg_p (int r1
, int r2
)
5650 /* Assume other cases in gen_reload are not possible for
5651 chain reloads or do need an intermediate hard registers. */
5655 rtx last
= get_last_insn ();
5657 /* Make r2 a component of r1. */
5658 if (reg_mentioned_p (rld
[r1
].in
, rld
[r2
].in
))
5664 gcc_assert (reg_mentioned_p (rld
[r2
].in
, rld
[r1
].in
));
5665 regno
= rld
[r1
].regno
>= 0 ? rld
[r1
].regno
: rld
[r2
].regno
;
5666 gcc_assert (regno
>= 0);
5667 out
= gen_rtx_REG (rld
[r1
].mode
, regno
);
5669 substitute (&in
, rld
[r2
].in
, gen_rtx_REG (rld
[r2
].mode
, regno
));
5671 /* If IN is a paradoxical SUBREG, remove it and try to put the
5672 opposite SUBREG on OUT. Likewise for a paradoxical SUBREG on OUT. */
5673 strip_paradoxical_subreg (&in
, &out
);
5675 if (GET_CODE (in
) == PLUS
5676 && (REG_P (XEXP (in
, 0))
5677 || GET_CODE (XEXP (in
, 0)) == SUBREG
5678 || MEM_P (XEXP (in
, 0)))
5679 && (REG_P (XEXP (in
, 1))
5680 || GET_CODE (XEXP (in
, 1)) == SUBREG
5681 || CONSTANT_P (XEXP (in
, 1))
5682 || MEM_P (XEXP (in
, 1))))
5684 insn
= emit_insn (gen_rtx_SET (VOIDmode
, out
, in
));
5685 code
= recog_memoized (insn
);
5690 extract_insn (insn
);
5691 /* We want constrain operands to treat this insn strictly in
5692 its validity determination, i.e., the way it would after
5693 reload has completed. */
5694 result
= constrain_operands (1);
5697 delete_insns_since (last
);
5700 /* Restore the original value at each changed address within R1. */
5701 while (!VEC_empty (rtx_p
, substitute_stack
))
5703 rtx
*where
= VEC_pop (rtx_p
, substitute_stack
);
5704 *where
= rld
[r2
].in
;
5710 /* Return 1 if the reloads denoted by R1 and R2 cannot share a register.
5713 This function uses the same algorithm as reload_reg_free_p above. */
5716 reloads_conflict (int r1
, int r2
)
5718 enum reload_type r1_type
= rld
[r1
].when_needed
;
5719 enum reload_type r2_type
= rld
[r2
].when_needed
;
5720 int r1_opnum
= rld
[r1
].opnum
;
5721 int r2_opnum
= rld
[r2
].opnum
;
5723 /* RELOAD_OTHER conflicts with everything. */
5724 if (r2_type
== RELOAD_OTHER
)
5727 /* Otherwise, check conflicts differently for each type. */
5731 case RELOAD_FOR_INPUT
:
5732 return (r2_type
== RELOAD_FOR_INSN
5733 || r2_type
== RELOAD_FOR_OPERAND_ADDRESS
5734 || r2_type
== RELOAD_FOR_OPADDR_ADDR
5735 || r2_type
== RELOAD_FOR_INPUT
5736 || ((r2_type
== RELOAD_FOR_INPUT_ADDRESS
5737 || r2_type
== RELOAD_FOR_INPADDR_ADDRESS
)
5738 && r2_opnum
> r1_opnum
));
5740 case RELOAD_FOR_INPUT_ADDRESS
:
5741 return ((r2_type
== RELOAD_FOR_INPUT_ADDRESS
&& r1_opnum
== r2_opnum
)
5742 || (r2_type
== RELOAD_FOR_INPUT
&& r2_opnum
< r1_opnum
));
5744 case RELOAD_FOR_INPADDR_ADDRESS
:
5745 return ((r2_type
== RELOAD_FOR_INPADDR_ADDRESS
&& r1_opnum
== r2_opnum
)
5746 || (r2_type
== RELOAD_FOR_INPUT
&& r2_opnum
< r1_opnum
));
5748 case RELOAD_FOR_OUTPUT_ADDRESS
:
5749 return ((r2_type
== RELOAD_FOR_OUTPUT_ADDRESS
&& r2_opnum
== r1_opnum
)
5750 || (r2_type
== RELOAD_FOR_OUTPUT
&& r2_opnum
<= r1_opnum
));
5752 case RELOAD_FOR_OUTADDR_ADDRESS
:
5753 return ((r2_type
== RELOAD_FOR_OUTADDR_ADDRESS
&& r2_opnum
== r1_opnum
)
5754 || (r2_type
== RELOAD_FOR_OUTPUT
&& r2_opnum
<= r1_opnum
));
5756 case RELOAD_FOR_OPERAND_ADDRESS
:
5757 return (r2_type
== RELOAD_FOR_INPUT
|| r2_type
== RELOAD_FOR_INSN
5758 || (r2_type
== RELOAD_FOR_OPERAND_ADDRESS
5759 && (!reloads_unique_chain_p (r1
, r2
)
5760 || !gen_reload_chain_without_interm_reg_p (r1
, r2
))));
5762 case RELOAD_FOR_OPADDR_ADDR
:
5763 return (r2_type
== RELOAD_FOR_INPUT
5764 || r2_type
== RELOAD_FOR_OPADDR_ADDR
);
5766 case RELOAD_FOR_OUTPUT
:
5767 return (r2_type
== RELOAD_FOR_INSN
|| r2_type
== RELOAD_FOR_OUTPUT
5768 || ((r2_type
== RELOAD_FOR_OUTPUT_ADDRESS
5769 || r2_type
== RELOAD_FOR_OUTADDR_ADDRESS
)
5770 && r2_opnum
>= r1_opnum
));
5772 case RELOAD_FOR_INSN
:
5773 return (r2_type
== RELOAD_FOR_INPUT
|| r2_type
== RELOAD_FOR_OUTPUT
5774 || r2_type
== RELOAD_FOR_INSN
5775 || r2_type
== RELOAD_FOR_OPERAND_ADDRESS
);
5777 case RELOAD_FOR_OTHER_ADDRESS
:
5778 return r2_type
== RELOAD_FOR_OTHER_ADDRESS
;
5788 /* Indexed by reload number, 1 if incoming value
5789 inherited from previous insns. */
5790 static char reload_inherited
[MAX_RELOADS
];
5792 /* For an inherited reload, this is the insn the reload was inherited from,
5793 if we know it. Otherwise, this is 0. */
5794 static rtx reload_inheritance_insn
[MAX_RELOADS
];
5796 /* If nonzero, this is a place to get the value of the reload,
5797 rather than using reload_in. */
5798 static rtx reload_override_in
[MAX_RELOADS
];
5800 /* For each reload, the hard register number of the register used,
5801 or -1 if we did not need a register for this reload. */
5802 static int reload_spill_index
[MAX_RELOADS
];
5804 /* Index X is the value of rld[X].reg_rtx, adjusted for the input mode. */
5805 static rtx reload_reg_rtx_for_input
[MAX_RELOADS
];
5807 /* Index X is the value of rld[X].reg_rtx, adjusted for the output mode. */
5808 static rtx reload_reg_rtx_for_output
[MAX_RELOADS
];
5810 /* Subroutine of free_for_value_p, used to check a single register.
5811 START_REGNO is the starting regno of the full reload register
5812 (possibly comprising multiple hard registers) that we are considering. */
5815 reload_reg_free_for_value_p (int start_regno
, int regno
, int opnum
,
5816 enum reload_type type
, rtx value
, rtx out
,
5817 int reloadnum
, int ignore_address_reloads
)
5820 /* Set if we see an input reload that must not share its reload register
5821 with any new earlyclobber, but might otherwise share the reload
5822 register with an output or input-output reload. */
5823 int check_earlyclobber
= 0;
5827 if (TEST_HARD_REG_BIT (reload_reg_unavailable
, regno
))
5830 if (out
== const0_rtx
)
5836 /* We use some pseudo 'time' value to check if the lifetimes of the
5837 new register use would overlap with the one of a previous reload
5838 that is not read-only or uses a different value.
5839 The 'time' used doesn't have to be linear in any shape or form, just
5841 Some reload types use different 'buckets' for each operand.
5842 So there are MAX_RECOG_OPERANDS different time values for each
5844 We compute TIME1 as the time when the register for the prospective
5845 new reload ceases to be live, and TIME2 for each existing
5846 reload as the time when that the reload register of that reload
5848 Where there is little to be gained by exact lifetime calculations,
5849 we just make conservative assumptions, i.e. a longer lifetime;
5850 this is done in the 'default:' cases. */
5853 case RELOAD_FOR_OTHER_ADDRESS
:
5854 /* RELOAD_FOR_OTHER_ADDRESS conflicts with RELOAD_OTHER reloads. */
5855 time1
= copy
? 0 : 1;
5858 time1
= copy
? 1 : MAX_RECOG_OPERANDS
* 5 + 5;
5860 /* For each input, we may have a sequence of RELOAD_FOR_INPADDR_ADDRESS,
5861 RELOAD_FOR_INPUT_ADDRESS and RELOAD_FOR_INPUT. By adding 0 / 1 / 2 ,
5862 respectively, to the time values for these, we get distinct time
5863 values. To get distinct time values for each operand, we have to
5864 multiply opnum by at least three. We round that up to four because
5865 multiply by four is often cheaper. */
5866 case RELOAD_FOR_INPADDR_ADDRESS
:
5867 time1
= opnum
* 4 + 2;
5869 case RELOAD_FOR_INPUT_ADDRESS
:
5870 time1
= opnum
* 4 + 3;
5872 case RELOAD_FOR_INPUT
:
5873 /* All RELOAD_FOR_INPUT reloads remain live till the instruction
5874 executes (inclusive). */
5875 time1
= copy
? opnum
* 4 + 4 : MAX_RECOG_OPERANDS
* 4 + 3;
5877 case RELOAD_FOR_OPADDR_ADDR
:
5879 <= (MAX_RECOG_OPERANDS - 1) * 4 + 4 == MAX_RECOG_OPERANDS * 4 */
5880 time1
= MAX_RECOG_OPERANDS
* 4 + 1;
5882 case RELOAD_FOR_OPERAND_ADDRESS
:
5883 /* RELOAD_FOR_OPERAND_ADDRESS reloads are live even while the insn
5885 time1
= copy
? MAX_RECOG_OPERANDS
* 4 + 2 : MAX_RECOG_OPERANDS
* 4 + 3;
5887 case RELOAD_FOR_OUTADDR_ADDRESS
:
5888 time1
= MAX_RECOG_OPERANDS
* 4 + 4 + opnum
;
5890 case RELOAD_FOR_OUTPUT_ADDRESS
:
5891 time1
= MAX_RECOG_OPERANDS
* 4 + 5 + opnum
;
5894 time1
= MAX_RECOG_OPERANDS
* 5 + 5;
5897 for (i
= 0; i
< n_reloads
; i
++)
5899 rtx reg
= rld
[i
].reg_rtx
;
5900 if (reg
&& REG_P (reg
)
5901 && ((unsigned) regno
- true_regnum (reg
)
5902 <= hard_regno_nregs
[REGNO (reg
)][GET_MODE (reg
)] - (unsigned) 1)
5905 rtx other_input
= rld
[i
].in
;
5907 /* If the other reload loads the same input value, that
5908 will not cause a conflict only if it's loading it into
5909 the same register. */
5910 if (true_regnum (reg
) != start_regno
)
5911 other_input
= NULL_RTX
;
5912 if (! other_input
|| ! rtx_equal_p (other_input
, value
)
5913 || rld
[i
].out
|| out
)
5916 switch (rld
[i
].when_needed
)
5918 case RELOAD_FOR_OTHER_ADDRESS
:
5921 case RELOAD_FOR_INPADDR_ADDRESS
:
5922 /* find_reloads makes sure that a
5923 RELOAD_FOR_{INP,OP,OUT}ADDR_ADDRESS reload is only used
5924 by at most one - the first -
5925 RELOAD_FOR_{INPUT,OPERAND,OUTPUT}_ADDRESS . If the
5926 address reload is inherited, the address address reload
5927 goes away, so we can ignore this conflict. */
5928 if (type
== RELOAD_FOR_INPUT_ADDRESS
&& reloadnum
== i
+ 1
5929 && ignore_address_reloads
5930 /* Unless the RELOAD_FOR_INPUT is an auto_inc expression.
5931 Then the address address is still needed to store
5932 back the new address. */
5933 && ! rld
[reloadnum
].out
)
5935 /* Likewise, if a RELOAD_FOR_INPUT can inherit a value, its
5936 RELOAD_FOR_INPUT_ADDRESS / RELOAD_FOR_INPADDR_ADDRESS
5938 if (type
== RELOAD_FOR_INPUT
&& opnum
== rld
[i
].opnum
5939 && ignore_address_reloads
5940 /* Unless we are reloading an auto_inc expression. */
5941 && ! rld
[reloadnum
].out
)
5943 time2
= rld
[i
].opnum
* 4 + 2;
5945 case RELOAD_FOR_INPUT_ADDRESS
:
5946 if (type
== RELOAD_FOR_INPUT
&& opnum
== rld
[i
].opnum
5947 && ignore_address_reloads
5948 && ! rld
[reloadnum
].out
)
5950 time2
= rld
[i
].opnum
* 4 + 3;
5952 case RELOAD_FOR_INPUT
:
5953 time2
= rld
[i
].opnum
* 4 + 4;
5954 check_earlyclobber
= 1;
5956 /* rld[i].opnum * 4 + 4 <= (MAX_RECOG_OPERAND - 1) * 4 + 4
5957 == MAX_RECOG_OPERAND * 4 */
5958 case RELOAD_FOR_OPADDR_ADDR
:
5959 if (type
== RELOAD_FOR_OPERAND_ADDRESS
&& reloadnum
== i
+ 1
5960 && ignore_address_reloads
5961 && ! rld
[reloadnum
].out
)
5963 time2
= MAX_RECOG_OPERANDS
* 4 + 1;
5965 case RELOAD_FOR_OPERAND_ADDRESS
:
5966 time2
= MAX_RECOG_OPERANDS
* 4 + 2;
5967 check_earlyclobber
= 1;
5969 case RELOAD_FOR_INSN
:
5970 time2
= MAX_RECOG_OPERANDS
* 4 + 3;
5972 case RELOAD_FOR_OUTPUT
:
5973 /* All RELOAD_FOR_OUTPUT reloads become live just after the
5974 instruction is executed. */
5975 time2
= MAX_RECOG_OPERANDS
* 4 + 4;
5977 /* The first RELOAD_FOR_OUTADDR_ADDRESS reload conflicts with
5978 the RELOAD_FOR_OUTPUT reloads, so assign it the same time
5980 case RELOAD_FOR_OUTADDR_ADDRESS
:
5981 if (type
== RELOAD_FOR_OUTPUT_ADDRESS
&& reloadnum
== i
+ 1
5982 && ignore_address_reloads
5983 && ! rld
[reloadnum
].out
)
5985 time2
= MAX_RECOG_OPERANDS
* 4 + 4 + rld
[i
].opnum
;
5987 case RELOAD_FOR_OUTPUT_ADDRESS
:
5988 time2
= MAX_RECOG_OPERANDS
* 4 + 5 + rld
[i
].opnum
;
5991 /* If there is no conflict in the input part, handle this
5992 like an output reload. */
5993 if (! rld
[i
].in
|| rtx_equal_p (other_input
, value
))
5995 time2
= MAX_RECOG_OPERANDS
* 4 + 4;
5996 /* Earlyclobbered outputs must conflict with inputs. */
5997 if (earlyclobber_operand_p (rld
[i
].out
))
5998 time2
= MAX_RECOG_OPERANDS
* 4 + 3;
6003 /* RELOAD_OTHER might be live beyond instruction execution,
6004 but this is not obvious when we set time2 = 1. So check
6005 here if there might be a problem with the new reload
6006 clobbering the register used by the RELOAD_OTHER. */
6014 && (! rld
[i
].in
|| rld
[i
].out
6015 || ! rtx_equal_p (other_input
, value
)))
6016 || (out
&& rld
[reloadnum
].out_reg
6017 && time2
>= MAX_RECOG_OPERANDS
* 4 + 3))
6023 /* Earlyclobbered outputs must conflict with inputs. */
6024 if (check_earlyclobber
&& out
&& earlyclobber_operand_p (out
))
6030 /* Return 1 if the value in reload reg REGNO, as used by a reload
6031 needed for the part of the insn specified by OPNUM and TYPE,
6032 may be used to load VALUE into it.
6034 MODE is the mode in which the register is used, this is needed to
6035 determine how many hard regs to test.
6037 Other read-only reloads with the same value do not conflict
6038 unless OUT is nonzero and these other reloads have to live while
6039 output reloads live.
6040 If OUT is CONST0_RTX, this is a special case: it means that the
6041 test should not be for using register REGNO as reload register, but
6042 for copying from register REGNO into the reload register.
6044 RELOADNUM is the number of the reload we want to load this value for;
6045 a reload does not conflict with itself.
6047 When IGNORE_ADDRESS_RELOADS is set, we can not have conflicts with
6048 reloads that load an address for the very reload we are considering.
6050 The caller has to make sure that there is no conflict with the return
6054 free_for_value_p (int regno
, enum machine_mode mode
, int opnum
,
6055 enum reload_type type
, rtx value
, rtx out
, int reloadnum
,
6056 int ignore_address_reloads
)
6058 int nregs
= hard_regno_nregs
[regno
][mode
];
6060 if (! reload_reg_free_for_value_p (regno
, regno
+ nregs
, opnum
, type
,
6061 value
, out
, reloadnum
,
6062 ignore_address_reloads
))
6067 /* Return nonzero if the rtx X is invariant over the current function. */
6068 /* ??? Actually, the places where we use this expect exactly what is
6069 tested here, and not everything that is function invariant. In
6070 particular, the frame pointer and arg pointer are special cased;
6071 pic_offset_table_rtx is not, and we must not spill these things to
6075 function_invariant_p (const_rtx x
)
6079 if (x
== frame_pointer_rtx
|| x
== arg_pointer_rtx
)
6081 if (GET_CODE (x
) == PLUS
6082 && (XEXP (x
, 0) == frame_pointer_rtx
|| XEXP (x
, 0) == arg_pointer_rtx
)
6083 && GET_CODE (XEXP (x
, 1)) == CONST_INT
)
6088 /* Determine whether the reload reg X overlaps any rtx'es used for
6089 overriding inheritance. Return nonzero if so. */
6092 conflicts_with_override (rtx x
)
6095 for (i
= 0; i
< n_reloads
; i
++)
6096 if (reload_override_in
[i
]
6097 && reg_overlap_mentioned_p (x
, reload_override_in
[i
]))
6102 /* Give an error message saying we failed to find a reload for INSN,
6103 and clear out reload R. */
6105 failed_reload (rtx insn
, int r
)
6107 if (asm_noperands (PATTERN (insn
)) < 0)
6108 /* It's the compiler's fault. */
6109 fatal_insn ("could not find a spill register", insn
);
6111 /* It's the user's fault; the operand's mode and constraint
6112 don't match. Disable this reload so we don't crash in final. */
6113 error_for_asm (insn
,
6114 "%<asm%> operand constraint incompatible with operand size");
6118 rld
[r
].optional
= 1;
6119 rld
[r
].secondary_p
= 1;
6122 /* I is the index in SPILL_REG_RTX of the reload register we are to allocate
6123 for reload R. If it's valid, get an rtx for it. Return nonzero if
6126 set_reload_reg (int i
, int r
)
6128 /* regno is 'set but not used' if HARD_REGNO_MODE_OK doesn't use its first
6130 int regno ATTRIBUTE_UNUSED
;
6131 rtx reg
= spill_reg_rtx
[i
];
6133 if (reg
== 0 || GET_MODE (reg
) != rld
[r
].mode
)
6134 spill_reg_rtx
[i
] = reg
6135 = gen_rtx_REG (rld
[r
].mode
, spill_regs
[i
]);
6137 regno
= true_regnum (reg
);
6139 /* Detect when the reload reg can't hold the reload mode.
6140 This used to be one `if', but Sequent compiler can't handle that. */
6141 if (HARD_REGNO_MODE_OK (regno
, rld
[r
].mode
))
6143 enum machine_mode test_mode
= VOIDmode
;
6145 test_mode
= GET_MODE (rld
[r
].in
);
6146 /* If rld[r].in has VOIDmode, it means we will load it
6147 in whatever mode the reload reg has: to wit, rld[r].mode.
6148 We have already tested that for validity. */
6149 /* Aside from that, we need to test that the expressions
6150 to reload from or into have modes which are valid for this
6151 reload register. Otherwise the reload insns would be invalid. */
6152 if (! (rld
[r
].in
!= 0 && test_mode
!= VOIDmode
6153 && ! HARD_REGNO_MODE_OK (regno
, test_mode
)))
6154 if (! (rld
[r
].out
!= 0
6155 && ! HARD_REGNO_MODE_OK (regno
, GET_MODE (rld
[r
].out
))))
6157 /* The reg is OK. */
6160 /* Mark as in use for this insn the reload regs we use
6162 mark_reload_reg_in_use (spill_regs
[i
], rld
[r
].opnum
,
6163 rld
[r
].when_needed
, rld
[r
].mode
);
6165 rld
[r
].reg_rtx
= reg
;
6166 reload_spill_index
[r
] = spill_regs
[i
];
6173 /* Find a spill register to use as a reload register for reload R.
6174 LAST_RELOAD is nonzero if this is the last reload for the insn being
6177 Set rld[R].reg_rtx to the register allocated.
6179 We return 1 if successful, or 0 if we couldn't find a spill reg and
6180 we didn't change anything. */
6183 allocate_reload_reg (struct insn_chain
*chain ATTRIBUTE_UNUSED
, int r
,
6188 /* If we put this reload ahead, thinking it is a group,
6189 then insist on finding a group. Otherwise we can grab a
6190 reg that some other reload needs.
6191 (That can happen when we have a 68000 DATA_OR_FP_REG
6192 which is a group of data regs or one fp reg.)
6193 We need not be so restrictive if there are no more reloads
6196 ??? Really it would be nicer to have smarter handling
6197 for that kind of reg class, where a problem like this is normal.
6198 Perhaps those classes should be avoided for reloading
6199 by use of more alternatives. */
6201 int force_group
= rld
[r
].nregs
> 1 && ! last_reload
;
6203 /* If we want a single register and haven't yet found one,
6204 take any reg in the right class and not in use.
6205 If we want a consecutive group, here is where we look for it.
6207 We use three passes so we can first look for reload regs to
6208 reuse, which are already in use for other reloads in this insn,
6209 and only then use additional registers which are not "bad", then
6210 finally any register.
6212 I think that maximizing reuse is needed to make sure we don't
6213 run out of reload regs. Suppose we have three reloads, and
6214 reloads A and B can share regs. These need two regs.
6215 Suppose A and B are given different regs.
6216 That leaves none for C. */
6217 for (pass
= 0; pass
< 3; pass
++)
6219 /* I is the index in spill_regs.
6220 We advance it round-robin between insns to use all spill regs
6221 equally, so that inherited reloads have a chance
6222 of leapfrogging each other. */
6226 for (count
= 0; count
< n_spills
; count
++)
6228 int rclass
= (int) rld
[r
].rclass
;
6234 regnum
= spill_regs
[i
];
6236 if ((reload_reg_free_p (regnum
, rld
[r
].opnum
,
6239 /* We check reload_reg_used to make sure we
6240 don't clobber the return register. */
6241 && ! TEST_HARD_REG_BIT (reload_reg_used
, regnum
)
6242 && free_for_value_p (regnum
, rld
[r
].mode
, rld
[r
].opnum
,
6243 rld
[r
].when_needed
, rld
[r
].in
,
6245 && TEST_HARD_REG_BIT (reg_class_contents
[rclass
], regnum
)
6246 && HARD_REGNO_MODE_OK (regnum
, rld
[r
].mode
)
6247 /* Look first for regs to share, then for unshared. But
6248 don't share regs used for inherited reloads; they are
6249 the ones we want to preserve. */
6251 || (TEST_HARD_REG_BIT (reload_reg_used_at_all
,
6253 && ! TEST_HARD_REG_BIT (reload_reg_used_for_inherit
,
6256 int nr
= hard_regno_nregs
[regnum
][rld
[r
].mode
];
6258 /* During the second pass we want to avoid reload registers
6259 which are "bad" for this reload. */
6261 && ira_bad_reload_regno (regnum
, rld
[r
].in
, rld
[r
].out
))
6264 /* Avoid the problem where spilling a GENERAL_OR_FP_REG
6265 (on 68000) got us two FP regs. If NR is 1,
6266 we would reject both of them. */
6269 /* If we need only one reg, we have already won. */
6272 /* But reject a single reg if we demand a group. */
6277 /* Otherwise check that as many consecutive regs as we need
6278 are available here. */
6281 int regno
= regnum
+ nr
- 1;
6282 if (!(TEST_HARD_REG_BIT (reg_class_contents
[rclass
], regno
)
6283 && spill_reg_order
[regno
] >= 0
6284 && reload_reg_free_p (regno
, rld
[r
].opnum
,
6285 rld
[r
].when_needed
)))
6294 /* If we found something on the current pass, omit later passes. */
6295 if (count
< n_spills
)
6299 /* We should have found a spill register by now. */
6300 if (count
>= n_spills
)
6303 /* I is the index in SPILL_REG_RTX of the reload register we are to
6304 allocate. Get an rtx for it and find its register number. */
6306 return set_reload_reg (i
, r
);
6309 /* Initialize all the tables needed to allocate reload registers.
6310 CHAIN is the insn currently being processed; SAVE_RELOAD_REG_RTX
6311 is the array we use to restore the reg_rtx field for every reload. */
6314 choose_reload_regs_init (struct insn_chain
*chain
, rtx
*save_reload_reg_rtx
)
6318 for (i
= 0; i
< n_reloads
; i
++)
6319 rld
[i
].reg_rtx
= save_reload_reg_rtx
[i
];
6321 memset (reload_inherited
, 0, MAX_RELOADS
);
6322 memset (reload_inheritance_insn
, 0, MAX_RELOADS
* sizeof (rtx
));
6323 memset (reload_override_in
, 0, MAX_RELOADS
* sizeof (rtx
));
6325 CLEAR_HARD_REG_SET (reload_reg_used
);
6326 CLEAR_HARD_REG_SET (reload_reg_used_at_all
);
6327 CLEAR_HARD_REG_SET (reload_reg_used_in_op_addr
);
6328 CLEAR_HARD_REG_SET (reload_reg_used_in_op_addr_reload
);
6329 CLEAR_HARD_REG_SET (reload_reg_used_in_insn
);
6330 CLEAR_HARD_REG_SET (reload_reg_used_in_other_addr
);
6332 CLEAR_HARD_REG_SET (reg_used_in_insn
);
6335 REG_SET_TO_HARD_REG_SET (tmp
, &chain
->live_throughout
);
6336 IOR_HARD_REG_SET (reg_used_in_insn
, tmp
);
6337 REG_SET_TO_HARD_REG_SET (tmp
, &chain
->dead_or_set
);
6338 IOR_HARD_REG_SET (reg_used_in_insn
, tmp
);
6339 compute_use_by_pseudos (®_used_in_insn
, &chain
->live_throughout
);
6340 compute_use_by_pseudos (®_used_in_insn
, &chain
->dead_or_set
);
6343 for (i
= 0; i
< reload_n_operands
; i
++)
6345 CLEAR_HARD_REG_SET (reload_reg_used_in_output
[i
]);
6346 CLEAR_HARD_REG_SET (reload_reg_used_in_input
[i
]);
6347 CLEAR_HARD_REG_SET (reload_reg_used_in_input_addr
[i
]);
6348 CLEAR_HARD_REG_SET (reload_reg_used_in_inpaddr_addr
[i
]);
6349 CLEAR_HARD_REG_SET (reload_reg_used_in_output_addr
[i
]);
6350 CLEAR_HARD_REG_SET (reload_reg_used_in_outaddr_addr
[i
]);
6353 COMPL_HARD_REG_SET (reload_reg_unavailable
, chain
->used_spill_regs
);
6355 CLEAR_HARD_REG_SET (reload_reg_used_for_inherit
);
6357 for (i
= 0; i
< n_reloads
; i
++)
6358 /* If we have already decided to use a certain register,
6359 don't use it in another way. */
6361 mark_reload_reg_in_use (REGNO (rld
[i
].reg_rtx
), rld
[i
].opnum
,
6362 rld
[i
].when_needed
, rld
[i
].mode
);
6365 /* Assign hard reg targets for the pseudo-registers we must reload
6366 into hard regs for this insn.
6367 Also output the instructions to copy them in and out of the hard regs.
6369 For machines with register classes, we are responsible for
6370 finding a reload reg in the proper class. */
6373 choose_reload_regs (struct insn_chain
*chain
)
6375 rtx insn
= chain
->insn
;
6377 unsigned int max_group_size
= 1;
6378 enum reg_class group_class
= NO_REGS
;
6379 int pass
, win
, inheritance
;
6381 rtx save_reload_reg_rtx
[MAX_RELOADS
];
6383 /* In order to be certain of getting the registers we need,
6384 we must sort the reloads into order of increasing register class.
6385 Then our grabbing of reload registers will parallel the process
6386 that provided the reload registers.
6388 Also note whether any of the reloads wants a consecutive group of regs.
6389 If so, record the maximum size of the group desired and what
6390 register class contains all the groups needed by this insn. */
6392 for (j
= 0; j
< n_reloads
; j
++)
6394 reload_order
[j
] = j
;
6395 if (rld
[j
].reg_rtx
!= NULL_RTX
)
6397 gcc_assert (REG_P (rld
[j
].reg_rtx
)
6398 && HARD_REGISTER_P (rld
[j
].reg_rtx
));
6399 reload_spill_index
[j
] = REGNO (rld
[j
].reg_rtx
);
6402 reload_spill_index
[j
] = -1;
6404 if (rld
[j
].nregs
> 1)
6406 max_group_size
= MAX (rld
[j
].nregs
, max_group_size
);
6408 = reg_class_superunion
[(int) rld
[j
].rclass
][(int) group_class
];
6411 save_reload_reg_rtx
[j
] = rld
[j
].reg_rtx
;
6415 qsort (reload_order
, n_reloads
, sizeof (short), reload_reg_class_lower
);
6417 /* If -O, try first with inheritance, then turning it off.
6418 If not -O, don't do inheritance.
6419 Using inheritance when not optimizing leads to paradoxes
6420 with fp on the 68k: fp numbers (not NaNs) fail to be equal to themselves
6421 because one side of the comparison might be inherited. */
6423 for (inheritance
= optimize
> 0; inheritance
>= 0; inheritance
--)
6425 choose_reload_regs_init (chain
, save_reload_reg_rtx
);
6427 /* Process the reloads in order of preference just found.
6428 Beyond this point, subregs can be found in reload_reg_rtx.
6430 This used to look for an existing reloaded home for all of the
6431 reloads, and only then perform any new reloads. But that could lose
6432 if the reloads were done out of reg-class order because a later
6433 reload with a looser constraint might have an old home in a register
6434 needed by an earlier reload with a tighter constraint.
6436 To solve this, we make two passes over the reloads, in the order
6437 described above. In the first pass we try to inherit a reload
6438 from a previous insn. If there is a later reload that needs a
6439 class that is a proper subset of the class being processed, we must
6440 also allocate a spill register during the first pass.
6442 Then make a second pass over the reloads to allocate any reloads
6443 that haven't been given registers yet. */
6445 for (j
= 0; j
< n_reloads
; j
++)
6447 int r
= reload_order
[j
];
6448 rtx search_equiv
= NULL_RTX
;
6450 /* Ignore reloads that got marked inoperative. */
6451 if (rld
[r
].out
== 0 && rld
[r
].in
== 0
6452 && ! rld
[r
].secondary_p
)
6455 /* If find_reloads chose to use reload_in or reload_out as a reload
6456 register, we don't need to chose one. Otherwise, try even if it
6457 found one since we might save an insn if we find the value lying
6459 Try also when reload_in is a pseudo without a hard reg. */
6460 if (rld
[r
].in
!= 0 && rld
[r
].reg_rtx
!= 0
6461 && (rtx_equal_p (rld
[r
].in
, rld
[r
].reg_rtx
)
6462 || (rtx_equal_p (rld
[r
].out
, rld
[r
].reg_rtx
)
6463 && !MEM_P (rld
[r
].in
)
6464 && true_regnum (rld
[r
].in
) < FIRST_PSEUDO_REGISTER
)))
6467 #if 0 /* No longer needed for correct operation.
6468 It might give better code, or might not; worth an experiment? */
6469 /* If this is an optional reload, we can't inherit from earlier insns
6470 until we are sure that any non-optional reloads have been allocated.
6471 The following code takes advantage of the fact that optional reloads
6472 are at the end of reload_order. */
6473 if (rld
[r
].optional
!= 0)
6474 for (i
= 0; i
< j
; i
++)
6475 if ((rld
[reload_order
[i
]].out
!= 0
6476 || rld
[reload_order
[i
]].in
!= 0
6477 || rld
[reload_order
[i
]].secondary_p
)
6478 && ! rld
[reload_order
[i
]].optional
6479 && rld
[reload_order
[i
]].reg_rtx
== 0)
6480 allocate_reload_reg (chain
, reload_order
[i
], 0);
6483 /* First see if this pseudo is already available as reloaded
6484 for a previous insn. We cannot try to inherit for reloads
6485 that are smaller than the maximum number of registers needed
6486 for groups unless the register we would allocate cannot be used
6489 We could check here to see if this is a secondary reload for
6490 an object that is already in a register of the desired class.
6491 This would avoid the need for the secondary reload register.
6492 But this is complex because we can't easily determine what
6493 objects might want to be loaded via this reload. So let a
6494 register be allocated here. In `emit_reload_insns' we suppress
6495 one of the loads in the case described above. */
6501 enum machine_mode mode
= VOIDmode
;
6505 else if (REG_P (rld
[r
].in
))
6507 regno
= REGNO (rld
[r
].in
);
6508 mode
= GET_MODE (rld
[r
].in
);
6510 else if (REG_P (rld
[r
].in_reg
))
6512 regno
= REGNO (rld
[r
].in_reg
);
6513 mode
= GET_MODE (rld
[r
].in_reg
);
6515 else if (GET_CODE (rld
[r
].in_reg
) == SUBREG
6516 && REG_P (SUBREG_REG (rld
[r
].in_reg
)))
6518 regno
= REGNO (SUBREG_REG (rld
[r
].in_reg
));
6519 if (regno
< FIRST_PSEUDO_REGISTER
)
6520 regno
= subreg_regno (rld
[r
].in_reg
);
6522 byte
= SUBREG_BYTE (rld
[r
].in_reg
);
6523 mode
= GET_MODE (rld
[r
].in_reg
);
6526 else if (GET_RTX_CLASS (GET_CODE (rld
[r
].in_reg
)) == RTX_AUTOINC
6527 && REG_P (XEXP (rld
[r
].in_reg
, 0)))
6529 regno
= REGNO (XEXP (rld
[r
].in_reg
, 0));
6530 mode
= GET_MODE (XEXP (rld
[r
].in_reg
, 0));
6531 rld
[r
].out
= rld
[r
].in
;
6535 /* This won't work, since REGNO can be a pseudo reg number.
6536 Also, it takes much more hair to keep track of all the things
6537 that can invalidate an inherited reload of part of a pseudoreg. */
6538 else if (GET_CODE (rld
[r
].in
) == SUBREG
6539 && REG_P (SUBREG_REG (rld
[r
].in
)))
6540 regno
= subreg_regno (rld
[r
].in
);
6544 && reg_last_reload_reg
[regno
] != 0
6545 && (GET_MODE_SIZE (GET_MODE (reg_last_reload_reg
[regno
]))
6546 >= GET_MODE_SIZE (mode
) + byte
)
6547 #ifdef CANNOT_CHANGE_MODE_CLASS
6548 /* Verify that the register it's in can be used in
6550 && !REG_CANNOT_CHANGE_MODE_P (REGNO (reg_last_reload_reg
[regno
]),
6551 GET_MODE (reg_last_reload_reg
[regno
]),
6556 enum reg_class rclass
= rld
[r
].rclass
, last_class
;
6557 rtx last_reg
= reg_last_reload_reg
[regno
];
6559 i
= REGNO (last_reg
);
6560 i
+= subreg_regno_offset (i
, GET_MODE (last_reg
), byte
, mode
);
6561 last_class
= REGNO_REG_CLASS (i
);
6563 if (reg_reloaded_contents
[i
] == regno
6564 && TEST_HARD_REG_BIT (reg_reloaded_valid
, i
)
6565 && HARD_REGNO_MODE_OK (i
, rld
[r
].mode
)
6566 && (TEST_HARD_REG_BIT (reg_class_contents
[(int) rclass
], i
)
6567 /* Even if we can't use this register as a reload
6568 register, we might use it for reload_override_in,
6569 if copying it to the desired class is cheap
6571 || ((register_move_cost (mode
, last_class
, rclass
)
6572 < memory_move_cost (mode
, rclass
, true))
6573 && (secondary_reload_class (1, rclass
, mode
,
6576 #ifdef SECONDARY_MEMORY_NEEDED
6577 && ! SECONDARY_MEMORY_NEEDED (last_class
, rclass
,
6582 && (rld
[r
].nregs
== max_group_size
6583 || ! TEST_HARD_REG_BIT (reg_class_contents
[(int) group_class
],
6585 && free_for_value_p (i
, rld
[r
].mode
, rld
[r
].opnum
,
6586 rld
[r
].when_needed
, rld
[r
].in
,
6589 /* If a group is needed, verify that all the subsequent
6590 registers still have their values intact. */
6591 int nr
= hard_regno_nregs
[i
][rld
[r
].mode
];
6594 for (k
= 1; k
< nr
; k
++)
6595 if (reg_reloaded_contents
[i
+ k
] != regno
6596 || ! TEST_HARD_REG_BIT (reg_reloaded_valid
, i
+ k
))
6604 last_reg
= (GET_MODE (last_reg
) == mode
6605 ? last_reg
: gen_rtx_REG (mode
, i
));
6608 for (k
= 0; k
< nr
; k
++)
6609 bad_for_class
|= ! TEST_HARD_REG_BIT (reg_class_contents
[(int) rld
[r
].rclass
],
6612 /* We found a register that contains the
6613 value we need. If this register is the
6614 same as an `earlyclobber' operand of the
6615 current insn, just mark it as a place to
6616 reload from since we can't use it as the
6617 reload register itself. */
6619 for (i1
= 0; i1
< n_earlyclobbers
; i1
++)
6620 if (reg_overlap_mentioned_for_reload_p
6621 (reg_last_reload_reg
[regno
],
6622 reload_earlyclobbers
[i1
]))
6625 if (i1
!= n_earlyclobbers
6626 || ! (free_for_value_p (i
, rld
[r
].mode
,
6628 rld
[r
].when_needed
, rld
[r
].in
,
6630 /* Don't use it if we'd clobber a pseudo reg. */
6631 || (TEST_HARD_REG_BIT (reg_used_in_insn
, i
)
6633 && ! TEST_HARD_REG_BIT (reg_reloaded_dead
, i
))
6634 /* Don't clobber the frame pointer. */
6635 || (i
== HARD_FRAME_POINTER_REGNUM
6636 && frame_pointer_needed
6638 /* Don't really use the inherited spill reg
6639 if we need it wider than we've got it. */
6640 || (GET_MODE_SIZE (rld
[r
].mode
)
6641 > GET_MODE_SIZE (mode
))
6644 /* If find_reloads chose reload_out as reload
6645 register, stay with it - that leaves the
6646 inherited register for subsequent reloads. */
6647 || (rld
[r
].out
&& rld
[r
].reg_rtx
6648 && rtx_equal_p (rld
[r
].out
, rld
[r
].reg_rtx
)))
6650 if (! rld
[r
].optional
)
6652 reload_override_in
[r
] = last_reg
;
6653 reload_inheritance_insn
[r
]
6654 = reg_reloaded_insn
[i
];
6660 /* We can use this as a reload reg. */
6661 /* Mark the register as in use for this part of
6663 mark_reload_reg_in_use (i
,
6667 rld
[r
].reg_rtx
= last_reg
;
6668 reload_inherited
[r
] = 1;
6669 reload_inheritance_insn
[r
]
6670 = reg_reloaded_insn
[i
];
6671 reload_spill_index
[r
] = i
;
6672 for (k
= 0; k
< nr
; k
++)
6673 SET_HARD_REG_BIT (reload_reg_used_for_inherit
,
6681 /* Here's another way to see if the value is already lying around. */
6684 && ! reload_inherited
[r
]
6686 && (CONSTANT_P (rld
[r
].in
)
6687 || GET_CODE (rld
[r
].in
) == PLUS
6688 || REG_P (rld
[r
].in
)
6689 || MEM_P (rld
[r
].in
))
6690 && (rld
[r
].nregs
== max_group_size
6691 || ! reg_classes_intersect_p (rld
[r
].rclass
, group_class
)))
6692 search_equiv
= rld
[r
].in
;
6697 = find_equiv_reg (search_equiv
, insn
, rld
[r
].rclass
,
6698 -1, NULL
, 0, rld
[r
].mode
);
6704 regno
= REGNO (equiv
);
6707 /* This must be a SUBREG of a hard register.
6708 Make a new REG since this might be used in an
6709 address and not all machines support SUBREGs
6711 gcc_assert (GET_CODE (equiv
) == SUBREG
);
6712 regno
= subreg_regno (equiv
);
6713 equiv
= gen_rtx_REG (rld
[r
].mode
, regno
);
6714 /* If we choose EQUIV as the reload register, but the
6715 loop below decides to cancel the inheritance, we'll
6716 end up reloading EQUIV in rld[r].mode, not the mode
6717 it had originally. That isn't safe when EQUIV isn't
6718 available as a spill register since its value might
6719 still be live at this point. */
6720 for (i
= regno
; i
< regno
+ (int) rld
[r
].nregs
; i
++)
6721 if (TEST_HARD_REG_BIT (reload_reg_unavailable
, i
))
6726 /* If we found a spill reg, reject it unless it is free
6727 and of the desired class. */
6731 int bad_for_class
= 0;
6732 int max_regno
= regno
+ rld
[r
].nregs
;
6734 for (i
= regno
; i
< max_regno
; i
++)
6736 regs_used
|= TEST_HARD_REG_BIT (reload_reg_used_at_all
,
6738 bad_for_class
|= ! TEST_HARD_REG_BIT (reg_class_contents
[(int) rld
[r
].rclass
],
6743 && ! free_for_value_p (regno
, rld
[r
].mode
,
6744 rld
[r
].opnum
, rld
[r
].when_needed
,
6745 rld
[r
].in
, rld
[r
].out
, r
, 1))
6750 if (equiv
!= 0 && ! HARD_REGNO_MODE_OK (regno
, rld
[r
].mode
))
6753 /* We found a register that contains the value we need.
6754 If this register is the same as an `earlyclobber' operand
6755 of the current insn, just mark it as a place to reload from
6756 since we can't use it as the reload register itself. */
6759 for (i
= 0; i
< n_earlyclobbers
; i
++)
6760 if (reg_overlap_mentioned_for_reload_p (equiv
,
6761 reload_earlyclobbers
[i
]))
6763 if (! rld
[r
].optional
)
6764 reload_override_in
[r
] = equiv
;
6769 /* If the equiv register we have found is explicitly clobbered
6770 in the current insn, it depends on the reload type if we
6771 can use it, use it for reload_override_in, or not at all.
6772 In particular, we then can't use EQUIV for a
6773 RELOAD_FOR_OUTPUT_ADDRESS reload. */
6777 if (regno_clobbered_p (regno
, insn
, rld
[r
].mode
, 2))
6778 switch (rld
[r
].when_needed
)
6780 case RELOAD_FOR_OTHER_ADDRESS
:
6781 case RELOAD_FOR_INPADDR_ADDRESS
:
6782 case RELOAD_FOR_INPUT_ADDRESS
:
6783 case RELOAD_FOR_OPADDR_ADDR
:
6786 case RELOAD_FOR_INPUT
:
6787 case RELOAD_FOR_OPERAND_ADDRESS
:
6788 if (! rld
[r
].optional
)
6789 reload_override_in
[r
] = equiv
;
6795 else if (regno_clobbered_p (regno
, insn
, rld
[r
].mode
, 1))
6796 switch (rld
[r
].when_needed
)
6798 case RELOAD_FOR_OTHER_ADDRESS
:
6799 case RELOAD_FOR_INPADDR_ADDRESS
:
6800 case RELOAD_FOR_INPUT_ADDRESS
:
6801 case RELOAD_FOR_OPADDR_ADDR
:
6802 case RELOAD_FOR_OPERAND_ADDRESS
:
6803 case RELOAD_FOR_INPUT
:
6806 if (! rld
[r
].optional
)
6807 reload_override_in
[r
] = equiv
;
6815 /* If we found an equivalent reg, say no code need be generated
6816 to load it, and use it as our reload reg. */
6818 && (regno
!= HARD_FRAME_POINTER_REGNUM
6819 || !frame_pointer_needed
))
6821 int nr
= hard_regno_nregs
[regno
][rld
[r
].mode
];
6823 rld
[r
].reg_rtx
= equiv
;
6824 reload_spill_index
[r
] = regno
;
6825 reload_inherited
[r
] = 1;
6827 /* If reg_reloaded_valid is not set for this register,
6828 there might be a stale spill_reg_store lying around.
6829 We must clear it, since otherwise emit_reload_insns
6830 might delete the store. */
6831 if (! TEST_HARD_REG_BIT (reg_reloaded_valid
, regno
))
6832 spill_reg_store
[regno
] = NULL_RTX
;
6833 /* If any of the hard registers in EQUIV are spill
6834 registers, mark them as in use for this insn. */
6835 for (k
= 0; k
< nr
; k
++)
6837 i
= spill_reg_order
[regno
+ k
];
6840 mark_reload_reg_in_use (regno
, rld
[r
].opnum
,
6843 SET_HARD_REG_BIT (reload_reg_used_for_inherit
,
6850 /* If we found a register to use already, or if this is an optional
6851 reload, we are done. */
6852 if (rld
[r
].reg_rtx
!= 0 || rld
[r
].optional
!= 0)
6856 /* No longer needed for correct operation. Might or might
6857 not give better code on the average. Want to experiment? */
6859 /* See if there is a later reload that has a class different from our
6860 class that intersects our class or that requires less register
6861 than our reload. If so, we must allocate a register to this
6862 reload now, since that reload might inherit a previous reload
6863 and take the only available register in our class. Don't do this
6864 for optional reloads since they will force all previous reloads
6865 to be allocated. Also don't do this for reloads that have been
6868 for (i
= j
+ 1; i
< n_reloads
; i
++)
6870 int s
= reload_order
[i
];
6872 if ((rld
[s
].in
== 0 && rld
[s
].out
== 0
6873 && ! rld
[s
].secondary_p
)
6877 if ((rld
[s
].rclass
!= rld
[r
].rclass
6878 && reg_classes_intersect_p (rld
[r
].rclass
,
6880 || rld
[s
].nregs
< rld
[r
].nregs
)
6887 allocate_reload_reg (chain
, r
, j
== n_reloads
- 1);
6891 /* Now allocate reload registers for anything non-optional that
6892 didn't get one yet. */
6893 for (j
= 0; j
< n_reloads
; j
++)
6895 int r
= reload_order
[j
];
6897 /* Ignore reloads that got marked inoperative. */
6898 if (rld
[r
].out
== 0 && rld
[r
].in
== 0 && ! rld
[r
].secondary_p
)
6901 /* Skip reloads that already have a register allocated or are
6903 if (rld
[r
].reg_rtx
!= 0 || rld
[r
].optional
)
6906 if (! allocate_reload_reg (chain
, r
, j
== n_reloads
- 1))
6910 /* If that loop got all the way, we have won. */
6917 /* Loop around and try without any inheritance. */
6922 /* First undo everything done by the failed attempt
6923 to allocate with inheritance. */
6924 choose_reload_regs_init (chain
, save_reload_reg_rtx
);
6926 /* Some sanity tests to verify that the reloads found in the first
6927 pass are identical to the ones we have now. */
6928 gcc_assert (chain
->n_reloads
== n_reloads
);
6930 for (i
= 0; i
< n_reloads
; i
++)
6932 if (chain
->rld
[i
].regno
< 0 || chain
->rld
[i
].reg_rtx
!= 0)
6934 gcc_assert (chain
->rld
[i
].when_needed
== rld
[i
].when_needed
);
6935 for (j
= 0; j
< n_spills
; j
++)
6936 if (spill_regs
[j
] == chain
->rld
[i
].regno
)
6937 if (! set_reload_reg (j
, i
))
6938 failed_reload (chain
->insn
, i
);
6942 /* If we thought we could inherit a reload, because it seemed that
6943 nothing else wanted the same reload register earlier in the insn,
6944 verify that assumption, now that all reloads have been assigned.
6945 Likewise for reloads where reload_override_in has been set. */
6947 /* If doing expensive optimizations, do one preliminary pass that doesn't
6948 cancel any inheritance, but removes reloads that have been needed only
6949 for reloads that we know can be inherited. */
6950 for (pass
= flag_expensive_optimizations
; pass
>= 0; pass
--)
6952 for (j
= 0; j
< n_reloads
; j
++)
6954 int r
= reload_order
[j
];
6956 if (reload_inherited
[r
] && rld
[r
].reg_rtx
)
6957 check_reg
= rld
[r
].reg_rtx
;
6958 else if (reload_override_in
[r
]
6959 && (REG_P (reload_override_in
[r
])
6960 || GET_CODE (reload_override_in
[r
]) == SUBREG
))
6961 check_reg
= reload_override_in
[r
];
6964 if (! free_for_value_p (true_regnum (check_reg
), rld
[r
].mode
,
6965 rld
[r
].opnum
, rld
[r
].when_needed
, rld
[r
].in
,
6966 (reload_inherited
[r
]
6967 ? rld
[r
].out
: const0_rtx
),
6972 reload_inherited
[r
] = 0;
6973 reload_override_in
[r
] = 0;
6975 /* If we can inherit a RELOAD_FOR_INPUT, or can use a
6976 reload_override_in, then we do not need its related
6977 RELOAD_FOR_INPUT_ADDRESS / RELOAD_FOR_INPADDR_ADDRESS reloads;
6978 likewise for other reload types.
6979 We handle this by removing a reload when its only replacement
6980 is mentioned in reload_in of the reload we are going to inherit.
6981 A special case are auto_inc expressions; even if the input is
6982 inherited, we still need the address for the output. We can
6983 recognize them because they have RELOAD_OUT set to RELOAD_IN.
6984 If we succeeded removing some reload and we are doing a preliminary
6985 pass just to remove such reloads, make another pass, since the
6986 removal of one reload might allow us to inherit another one. */
6988 && rld
[r
].out
!= rld
[r
].in
6989 && remove_address_replacements (rld
[r
].in
) && pass
)
6994 /* Now that reload_override_in is known valid,
6995 actually override reload_in. */
6996 for (j
= 0; j
< n_reloads
; j
++)
6997 if (reload_override_in
[j
])
6998 rld
[j
].in
= reload_override_in
[j
];
7000 /* If this reload won't be done because it has been canceled or is
7001 optional and not inherited, clear reload_reg_rtx so other
7002 routines (such as subst_reloads) don't get confused. */
7003 for (j
= 0; j
< n_reloads
; j
++)
7004 if (rld
[j
].reg_rtx
!= 0
7005 && ((rld
[j
].optional
&& ! reload_inherited
[j
])
7006 || (rld
[j
].in
== 0 && rld
[j
].out
== 0
7007 && ! rld
[j
].secondary_p
)))
7009 int regno
= true_regnum (rld
[j
].reg_rtx
);
7011 if (spill_reg_order
[regno
] >= 0)
7012 clear_reload_reg_in_use (regno
, rld
[j
].opnum
,
7013 rld
[j
].when_needed
, rld
[j
].mode
);
7015 reload_spill_index
[j
] = -1;
7018 /* Record which pseudos and which spill regs have output reloads. */
7019 for (j
= 0; j
< n_reloads
; j
++)
7021 int r
= reload_order
[j
];
7023 i
= reload_spill_index
[r
];
7025 /* I is nonneg if this reload uses a register.
7026 If rld[r].reg_rtx is 0, this is an optional reload
7027 that we opted to ignore. */
7028 if (rld
[r
].out_reg
!= 0 && REG_P (rld
[r
].out_reg
)
7029 && rld
[r
].reg_rtx
!= 0)
7031 int nregno
= REGNO (rld
[r
].out_reg
);
7034 if (nregno
< FIRST_PSEUDO_REGISTER
)
7035 nr
= hard_regno_nregs
[nregno
][rld
[r
].mode
];
7038 SET_REGNO_REG_SET (®_has_output_reload
,
7042 add_to_hard_reg_set (®_is_output_reload
, rld
[r
].mode
, i
);
7044 gcc_assert (rld
[r
].when_needed
== RELOAD_OTHER
7045 || rld
[r
].when_needed
== RELOAD_FOR_OUTPUT
7046 || rld
[r
].when_needed
== RELOAD_FOR_INSN
);
7051 /* Deallocate the reload register for reload R. This is called from
7052 remove_address_replacements. */
7055 deallocate_reload_reg (int r
)
7059 if (! rld
[r
].reg_rtx
)
7061 regno
= true_regnum (rld
[r
].reg_rtx
);
7063 if (spill_reg_order
[regno
] >= 0)
7064 clear_reload_reg_in_use (regno
, rld
[r
].opnum
, rld
[r
].when_needed
,
7066 reload_spill_index
[r
] = -1;
7069 /* These arrays are filled by emit_reload_insns and its subroutines. */
7070 static rtx input_reload_insns
[MAX_RECOG_OPERANDS
];
7071 static rtx other_input_address_reload_insns
= 0;
7072 static rtx other_input_reload_insns
= 0;
7073 static rtx input_address_reload_insns
[MAX_RECOG_OPERANDS
];
7074 static rtx inpaddr_address_reload_insns
[MAX_RECOG_OPERANDS
];
7075 static rtx output_reload_insns
[MAX_RECOG_OPERANDS
];
7076 static rtx output_address_reload_insns
[MAX_RECOG_OPERANDS
];
7077 static rtx outaddr_address_reload_insns
[MAX_RECOG_OPERANDS
];
7078 static rtx operand_reload_insns
= 0;
7079 static rtx other_operand_reload_insns
= 0;
7080 static rtx other_output_reload_insns
[MAX_RECOG_OPERANDS
];
7082 /* Values to be put in spill_reg_store are put here first. Instructions
7083 must only be placed here if the associated reload register reaches
7084 the end of the instruction's reload sequence. */
7085 static rtx new_spill_reg_store
[FIRST_PSEUDO_REGISTER
];
7086 static HARD_REG_SET reg_reloaded_died
;
7088 /* Check if *RELOAD_REG is suitable as an intermediate or scratch register
7089 of class NEW_CLASS with mode NEW_MODE. Or alternatively, if alt_reload_reg
7090 is nonzero, if that is suitable. On success, change *RELOAD_REG to the
7091 adjusted register, and return true. Otherwise, return false. */
7093 reload_adjust_reg_for_temp (rtx
*reload_reg
, rtx alt_reload_reg
,
7094 enum reg_class new_class
,
7095 enum machine_mode new_mode
)
7100 for (reg
= *reload_reg
; reg
; reg
= alt_reload_reg
, alt_reload_reg
= 0)
7102 unsigned regno
= REGNO (reg
);
7104 if (!TEST_HARD_REG_BIT (reg_class_contents
[(int) new_class
], regno
))
7106 if (GET_MODE (reg
) != new_mode
)
7108 if (!HARD_REGNO_MODE_OK (regno
, new_mode
))
7110 if (hard_regno_nregs
[regno
][new_mode
]
7111 > hard_regno_nregs
[regno
][GET_MODE (reg
)])
7113 reg
= reload_adjust_reg_for_mode (reg
, new_mode
);
7121 /* Check if *RELOAD_REG is suitable as a scratch register for the reload
7122 pattern with insn_code ICODE, or alternatively, if alt_reload_reg is
7123 nonzero, if that is suitable. On success, change *RELOAD_REG to the
7124 adjusted register, and return true. Otherwise, return false. */
7126 reload_adjust_reg_for_icode (rtx
*reload_reg
, rtx alt_reload_reg
,
7127 enum insn_code icode
)
7130 enum reg_class new_class
= scratch_reload_class (icode
);
7131 enum machine_mode new_mode
= insn_data
[(int) icode
].operand
[2].mode
;
7133 return reload_adjust_reg_for_temp (reload_reg
, alt_reload_reg
,
7134 new_class
, new_mode
);
7137 /* Generate insns to perform reload RL, which is for the insn in CHAIN and
7138 has the number J. OLD contains the value to be used as input. */
7141 emit_input_reload_insns (struct insn_chain
*chain
, struct reload
*rl
,
7144 rtx insn
= chain
->insn
;
7146 rtx oldequiv_reg
= 0;
7149 enum machine_mode mode
;
7152 /* delete_output_reload is only invoked properly if old contains
7153 the original pseudo register. Since this is replaced with a
7154 hard reg when RELOAD_OVERRIDE_IN is set, see if we can
7155 find the pseudo in RELOAD_IN_REG. */
7156 if (reload_override_in
[j
]
7157 && REG_P (rl
->in_reg
))
7164 else if (REG_P (oldequiv
))
7165 oldequiv_reg
= oldequiv
;
7166 else if (GET_CODE (oldequiv
) == SUBREG
)
7167 oldequiv_reg
= SUBREG_REG (oldequiv
);
7169 reloadreg
= reload_reg_rtx_for_input
[j
];
7170 mode
= GET_MODE (reloadreg
);
7172 /* If we are reloading from a register that was recently stored in
7173 with an output-reload, see if we can prove there was
7174 actually no need to store the old value in it. */
7176 if (optimize
&& REG_P (oldequiv
)
7177 && REGNO (oldequiv
) < FIRST_PSEUDO_REGISTER
7178 && spill_reg_store
[REGNO (oldequiv
)]
7180 && (dead_or_set_p (insn
, spill_reg_stored_to
[REGNO (oldequiv
)])
7181 || rtx_equal_p (spill_reg_stored_to
[REGNO (oldequiv
)],
7183 delete_output_reload (insn
, j
, REGNO (oldequiv
), reloadreg
);
7185 /* Encapsulate OLDEQUIV into the reload mode, then load RELOADREG from
7188 while (GET_CODE (oldequiv
) == SUBREG
&& GET_MODE (oldequiv
) != mode
)
7189 oldequiv
= SUBREG_REG (oldequiv
);
7190 if (GET_MODE (oldequiv
) != VOIDmode
7191 && mode
!= GET_MODE (oldequiv
))
7192 oldequiv
= gen_lowpart_SUBREG (mode
, oldequiv
);
7194 /* Switch to the right place to emit the reload insns. */
7195 switch (rl
->when_needed
)
7198 where
= &other_input_reload_insns
;
7200 case RELOAD_FOR_INPUT
:
7201 where
= &input_reload_insns
[rl
->opnum
];
7203 case RELOAD_FOR_INPUT_ADDRESS
:
7204 where
= &input_address_reload_insns
[rl
->opnum
];
7206 case RELOAD_FOR_INPADDR_ADDRESS
:
7207 where
= &inpaddr_address_reload_insns
[rl
->opnum
];
7209 case RELOAD_FOR_OUTPUT_ADDRESS
:
7210 where
= &output_address_reload_insns
[rl
->opnum
];
7212 case RELOAD_FOR_OUTADDR_ADDRESS
:
7213 where
= &outaddr_address_reload_insns
[rl
->opnum
];
7215 case RELOAD_FOR_OPERAND_ADDRESS
:
7216 where
= &operand_reload_insns
;
7218 case RELOAD_FOR_OPADDR_ADDR
:
7219 where
= &other_operand_reload_insns
;
7221 case RELOAD_FOR_OTHER_ADDRESS
:
7222 where
= &other_input_address_reload_insns
;
7228 push_to_sequence (*where
);
7230 /* Auto-increment addresses must be reloaded in a special way. */
7231 if (rl
->out
&& ! rl
->out_reg
)
7233 /* We are not going to bother supporting the case where a
7234 incremented register can't be copied directly from
7235 OLDEQUIV since this seems highly unlikely. */
7236 gcc_assert (rl
->secondary_in_reload
< 0);
7238 if (reload_inherited
[j
])
7239 oldequiv
= reloadreg
;
7241 old
= XEXP (rl
->in_reg
, 0);
7243 /* Prevent normal processing of this reload. */
7245 /* Output a special code sequence for this case. */
7246 inc_for_reload (reloadreg
, oldequiv
, rl
->out
, rl
->inc
);
7249 /* If we are reloading a pseudo-register that was set by the previous
7250 insn, see if we can get rid of that pseudo-register entirely
7251 by redirecting the previous insn into our reload register. */
7253 else if (optimize
&& REG_P (old
)
7254 && REGNO (old
) >= FIRST_PSEUDO_REGISTER
7255 && dead_or_set_p (insn
, old
)
7256 /* This is unsafe if some other reload
7257 uses the same reg first. */
7258 && ! conflicts_with_override (reloadreg
)
7259 && free_for_value_p (REGNO (reloadreg
), rl
->mode
, rl
->opnum
,
7260 rl
->when_needed
, old
, rl
->out
, j
, 0))
7262 rtx temp
= PREV_INSN (insn
);
7263 while (temp
&& (NOTE_P (temp
) || DEBUG_INSN_P (temp
)))
7264 temp
= PREV_INSN (temp
);
7266 && NONJUMP_INSN_P (temp
)
7267 && GET_CODE (PATTERN (temp
)) == SET
7268 && SET_DEST (PATTERN (temp
)) == old
7269 /* Make sure we can access insn_operand_constraint. */
7270 && asm_noperands (PATTERN (temp
)) < 0
7271 /* This is unsafe if operand occurs more than once in current
7272 insn. Perhaps some occurrences aren't reloaded. */
7273 && count_occurrences (PATTERN (insn
), old
, 0) == 1)
7275 rtx old
= SET_DEST (PATTERN (temp
));
7276 /* Store into the reload register instead of the pseudo. */
7277 SET_DEST (PATTERN (temp
)) = reloadreg
;
7279 /* Verify that resulting insn is valid. */
7280 extract_insn (temp
);
7281 if (constrain_operands (1))
7283 /* If the previous insn is an output reload, the source is
7284 a reload register, and its spill_reg_store entry will
7285 contain the previous destination. This is now
7287 if (REG_P (SET_SRC (PATTERN (temp
)))
7288 && REGNO (SET_SRC (PATTERN (temp
))) < FIRST_PSEUDO_REGISTER
)
7290 spill_reg_store
[REGNO (SET_SRC (PATTERN (temp
)))] = 0;
7291 spill_reg_stored_to
[REGNO (SET_SRC (PATTERN (temp
)))] = 0;
7294 /* If these are the only uses of the pseudo reg,
7295 pretend for GDB it lives in the reload reg we used. */
7296 if (REG_N_DEATHS (REGNO (old
)) == 1
7297 && REG_N_SETS (REGNO (old
)) == 1)
7299 reg_renumber
[REGNO (old
)] = REGNO (reloadreg
);
7300 if (ira_conflicts_p
)
7301 /* Inform IRA about the change. */
7302 ira_mark_allocation_change (REGNO (old
));
7303 alter_reg (REGNO (old
), -1, false);
7307 /* Adjust any debug insns between temp and insn. */
7308 while ((temp
= NEXT_INSN (temp
)) != insn
)
7309 if (DEBUG_INSN_P (temp
))
7310 replace_rtx (PATTERN (temp
), old
, reloadreg
);
7312 gcc_assert (NOTE_P (temp
));
7316 SET_DEST (PATTERN (temp
)) = old
;
7321 /* We can't do that, so output an insn to load RELOADREG. */
7323 /* If we have a secondary reload, pick up the secondary register
7324 and icode, if any. If OLDEQUIV and OLD are different or
7325 if this is an in-out reload, recompute whether or not we
7326 still need a secondary register and what the icode should
7327 be. If we still need a secondary register and the class or
7328 icode is different, go back to reloading from OLD if using
7329 OLDEQUIV means that we got the wrong type of register. We
7330 cannot have different class or icode due to an in-out reload
7331 because we don't make such reloads when both the input and
7332 output need secondary reload registers. */
7334 if (! special
&& rl
->secondary_in_reload
>= 0)
7336 rtx second_reload_reg
= 0;
7337 rtx third_reload_reg
= 0;
7338 int secondary_reload
= rl
->secondary_in_reload
;
7339 rtx real_oldequiv
= oldequiv
;
7342 enum insn_code icode
;
7343 enum insn_code tertiary_icode
= CODE_FOR_nothing
;
7345 /* If OLDEQUIV is a pseudo with a MEM, get the real MEM
7346 and similarly for OLD.
7347 See comments in get_secondary_reload in reload.c. */
7348 /* If it is a pseudo that cannot be replaced with its
7349 equivalent MEM, we must fall back to reload_in, which
7350 will have all the necessary substitutions registered.
7351 Likewise for a pseudo that can't be replaced with its
7352 equivalent constant.
7354 Take extra care for subregs of such pseudos. Note that
7355 we cannot use reg_equiv_mem in this case because it is
7356 not in the right mode. */
7359 if (GET_CODE (tmp
) == SUBREG
)
7360 tmp
= SUBREG_REG (tmp
);
7362 && REGNO (tmp
) >= FIRST_PSEUDO_REGISTER
7363 && (reg_equiv_memory_loc (REGNO (tmp
)) != 0
7364 || reg_equiv_constant (REGNO (tmp
)) != 0))
7366 if (! reg_equiv_mem (REGNO (tmp
))
7367 || num_not_at_initial_offset
7368 || GET_CODE (oldequiv
) == SUBREG
)
7369 real_oldequiv
= rl
->in
;
7371 real_oldequiv
= reg_equiv_mem (REGNO (tmp
));
7375 if (GET_CODE (tmp
) == SUBREG
)
7376 tmp
= SUBREG_REG (tmp
);
7378 && REGNO (tmp
) >= FIRST_PSEUDO_REGISTER
7379 && (reg_equiv_memory_loc (REGNO (tmp
)) != 0
7380 || reg_equiv_constant (REGNO (tmp
)) != 0))
7382 if (! reg_equiv_mem (REGNO (tmp
))
7383 || num_not_at_initial_offset
7384 || GET_CODE (old
) == SUBREG
)
7387 real_old
= reg_equiv_mem (REGNO (tmp
));
7390 second_reload_reg
= rld
[secondary_reload
].reg_rtx
;
7391 if (rld
[secondary_reload
].secondary_in_reload
>= 0)
7393 int tertiary_reload
= rld
[secondary_reload
].secondary_in_reload
;
7395 third_reload_reg
= rld
[tertiary_reload
].reg_rtx
;
7396 tertiary_icode
= rld
[secondary_reload
].secondary_in_icode
;
7397 /* We'd have to add more code for quartary reloads. */
7398 gcc_assert (rld
[tertiary_reload
].secondary_in_reload
< 0);
7400 icode
= rl
->secondary_in_icode
;
7402 if ((old
!= oldequiv
&& ! rtx_equal_p (old
, oldequiv
))
7403 || (rl
->in
!= 0 && rl
->out
!= 0))
7405 secondary_reload_info sri
, sri2
;
7406 enum reg_class new_class
, new_t_class
;
7408 sri
.icode
= CODE_FOR_nothing
;
7409 sri
.prev_sri
= NULL
;
7411 = (enum reg_class
) targetm
.secondary_reload (1, real_oldequiv
,
7415 if (new_class
== NO_REGS
&& sri
.icode
== CODE_FOR_nothing
)
7416 second_reload_reg
= 0;
7417 else if (new_class
== NO_REGS
)
7419 if (reload_adjust_reg_for_icode (&second_reload_reg
,
7421 (enum insn_code
) sri
.icode
))
7423 icode
= (enum insn_code
) sri
.icode
;
7424 third_reload_reg
= 0;
7429 real_oldequiv
= real_old
;
7432 else if (sri
.icode
!= CODE_FOR_nothing
)
7433 /* We currently lack a way to express this in reloads. */
7437 sri2
.icode
= CODE_FOR_nothing
;
7438 sri2
.prev_sri
= &sri
;
7440 = (enum reg_class
) targetm
.secondary_reload (1, real_oldequiv
,
7443 if (new_t_class
== NO_REGS
&& sri2
.icode
== CODE_FOR_nothing
)
7445 if (reload_adjust_reg_for_temp (&second_reload_reg
,
7449 third_reload_reg
= 0;
7450 tertiary_icode
= (enum insn_code
) sri2
.icode
;
7455 real_oldequiv
= real_old
;
7458 else if (new_t_class
== NO_REGS
&& sri2
.icode
!= CODE_FOR_nothing
)
7460 rtx intermediate
= second_reload_reg
;
7462 if (reload_adjust_reg_for_temp (&intermediate
, NULL
,
7464 && reload_adjust_reg_for_icode (&third_reload_reg
, NULL
,
7468 second_reload_reg
= intermediate
;
7469 tertiary_icode
= (enum insn_code
) sri2
.icode
;
7474 real_oldequiv
= real_old
;
7477 else if (new_t_class
!= NO_REGS
&& sri2
.icode
== CODE_FOR_nothing
)
7479 rtx intermediate
= second_reload_reg
;
7481 if (reload_adjust_reg_for_temp (&intermediate
, NULL
,
7483 && reload_adjust_reg_for_temp (&third_reload_reg
, NULL
,
7486 second_reload_reg
= intermediate
;
7487 tertiary_icode
= (enum insn_code
) sri2
.icode
;
7492 real_oldequiv
= real_old
;
7497 /* This could be handled more intelligently too. */
7499 real_oldequiv
= real_old
;
7504 /* If we still need a secondary reload register, check
7505 to see if it is being used as a scratch or intermediate
7506 register and generate code appropriately. If we need
7507 a scratch register, use REAL_OLDEQUIV since the form of
7508 the insn may depend on the actual address if it is
7511 if (second_reload_reg
)
7513 if (icode
!= CODE_FOR_nothing
)
7515 /* We'd have to add extra code to handle this case. */
7516 gcc_assert (!third_reload_reg
);
7518 emit_insn (GEN_FCN (icode
) (reloadreg
, real_oldequiv
,
7519 second_reload_reg
));
7524 /* See if we need a scratch register to load the
7525 intermediate register (a tertiary reload). */
7526 if (tertiary_icode
!= CODE_FOR_nothing
)
7528 emit_insn ((GEN_FCN (tertiary_icode
)
7529 (second_reload_reg
, real_oldequiv
,
7530 third_reload_reg
)));
7532 else if (third_reload_reg
)
7534 gen_reload (third_reload_reg
, real_oldequiv
,
7537 gen_reload (second_reload_reg
, third_reload_reg
,
7542 gen_reload (second_reload_reg
, real_oldequiv
,
7546 oldequiv
= second_reload_reg
;
7551 if (! special
&& ! rtx_equal_p (reloadreg
, oldequiv
))
7553 rtx real_oldequiv
= oldequiv
;
7555 if ((REG_P (oldequiv
)
7556 && REGNO (oldequiv
) >= FIRST_PSEUDO_REGISTER
7557 && (reg_equiv_memory_loc (REGNO (oldequiv
)) != 0
7558 || reg_equiv_constant (REGNO (oldequiv
)) != 0))
7559 || (GET_CODE (oldequiv
) == SUBREG
7560 && REG_P (SUBREG_REG (oldequiv
))
7561 && (REGNO (SUBREG_REG (oldequiv
))
7562 >= FIRST_PSEUDO_REGISTER
)
7563 && ((reg_equiv_memory_loc (REGNO (SUBREG_REG (oldequiv
))) != 0)
7564 || (reg_equiv_constant (REGNO (SUBREG_REG (oldequiv
))) != 0)))
7565 || (CONSTANT_P (oldequiv
)
7566 && (targetm
.preferred_reload_class (oldequiv
,
7567 REGNO_REG_CLASS (REGNO (reloadreg
)))
7569 real_oldequiv
= rl
->in
;
7570 gen_reload (reloadreg
, real_oldequiv
, rl
->opnum
,
7574 if (cfun
->can_throw_non_call_exceptions
)
7575 copy_reg_eh_region_note_forward (insn
, get_insns (), NULL
);
7577 /* End this sequence. */
7578 *where
= get_insns ();
7581 /* Update reload_override_in so that delete_address_reloads_1
7582 can see the actual register usage. */
7584 reload_override_in
[j
] = oldequiv
;
7587 /* Generate insns to for the output reload RL, which is for the insn described
7588 by CHAIN and has the number J. */
7590 emit_output_reload_insns (struct insn_chain
*chain
, struct reload
*rl
,
7594 rtx insn
= chain
->insn
;
7597 enum machine_mode mode
;
7601 if (rl
->when_needed
== RELOAD_OTHER
)
7604 push_to_sequence (output_reload_insns
[rl
->opnum
]);
7606 rl_reg_rtx
= reload_reg_rtx_for_output
[j
];
7607 mode
= GET_MODE (rl_reg_rtx
);
7609 reloadreg
= rl_reg_rtx
;
7611 /* If we need two reload regs, set RELOADREG to the intermediate
7612 one, since it will be stored into OLD. We might need a secondary
7613 register only for an input reload, so check again here. */
7615 if (rl
->secondary_out_reload
>= 0)
7618 int secondary_reload
= rl
->secondary_out_reload
;
7619 int tertiary_reload
= rld
[secondary_reload
].secondary_out_reload
;
7621 if (REG_P (old
) && REGNO (old
) >= FIRST_PSEUDO_REGISTER
7622 && reg_equiv_mem (REGNO (old
)) != 0)
7623 real_old
= reg_equiv_mem (REGNO (old
));
7625 if (secondary_reload_class (0, rl
->rclass
, mode
, real_old
) != NO_REGS
)
7627 rtx second_reloadreg
= reloadreg
;
7628 reloadreg
= rld
[secondary_reload
].reg_rtx
;
7630 /* See if RELOADREG is to be used as a scratch register
7631 or as an intermediate register. */
7632 if (rl
->secondary_out_icode
!= CODE_FOR_nothing
)
7634 /* We'd have to add extra code to handle this case. */
7635 gcc_assert (tertiary_reload
< 0);
7637 emit_insn ((GEN_FCN (rl
->secondary_out_icode
)
7638 (real_old
, second_reloadreg
, reloadreg
)));
7643 /* See if we need both a scratch and intermediate reload
7646 enum insn_code tertiary_icode
7647 = rld
[secondary_reload
].secondary_out_icode
;
7649 /* We'd have to add more code for quartary reloads. */
7650 gcc_assert (tertiary_reload
< 0
7651 || rld
[tertiary_reload
].secondary_out_reload
< 0);
7653 if (GET_MODE (reloadreg
) != mode
)
7654 reloadreg
= reload_adjust_reg_for_mode (reloadreg
, mode
);
7656 if (tertiary_icode
!= CODE_FOR_nothing
)
7658 rtx third_reloadreg
= rld
[tertiary_reload
].reg_rtx
;
7660 /* Copy primary reload reg to secondary reload reg.
7661 (Note that these have been swapped above, then
7662 secondary reload reg to OLD using our insn.) */
7664 /* If REAL_OLD is a paradoxical SUBREG, remove it
7665 and try to put the opposite SUBREG on
7667 strip_paradoxical_subreg (&real_old
, &reloadreg
);
7669 gen_reload (reloadreg
, second_reloadreg
,
7670 rl
->opnum
, rl
->when_needed
);
7671 emit_insn ((GEN_FCN (tertiary_icode
)
7672 (real_old
, reloadreg
, third_reloadreg
)));
7678 /* Copy between the reload regs here and then to
7681 gen_reload (reloadreg
, second_reloadreg
,
7682 rl
->opnum
, rl
->when_needed
);
7683 if (tertiary_reload
>= 0)
7685 rtx third_reloadreg
= rld
[tertiary_reload
].reg_rtx
;
7687 gen_reload (third_reloadreg
, reloadreg
,
7688 rl
->opnum
, rl
->when_needed
);
7689 reloadreg
= third_reloadreg
;
7696 /* Output the last reload insn. */
7701 /* Don't output the last reload if OLD is not the dest of
7702 INSN and is in the src and is clobbered by INSN. */
7703 if (! flag_expensive_optimizations
7705 || !(set
= single_set (insn
))
7706 || rtx_equal_p (old
, SET_DEST (set
))
7707 || !reg_mentioned_p (old
, SET_SRC (set
))
7708 || !((REGNO (old
) < FIRST_PSEUDO_REGISTER
)
7709 && regno_clobbered_p (REGNO (old
), insn
, rl
->mode
, 0)))
7710 gen_reload (old
, reloadreg
, rl
->opnum
,
7714 /* Look at all insns we emitted, just to be safe. */
7715 for (p
= get_insns (); p
; p
= NEXT_INSN (p
))
7718 rtx pat
= PATTERN (p
);
7720 /* If this output reload doesn't come from a spill reg,
7721 clear any memory of reloaded copies of the pseudo reg.
7722 If this output reload comes from a spill reg,
7723 reg_has_output_reload will make this do nothing. */
7724 note_stores (pat
, forget_old_reloads_1
, NULL
);
7726 if (reg_mentioned_p (rl_reg_rtx
, pat
))
7728 rtx set
= single_set (insn
);
7729 if (reload_spill_index
[j
] < 0
7731 && SET_SRC (set
) == rl_reg_rtx
)
7733 int src
= REGNO (SET_SRC (set
));
7735 reload_spill_index
[j
] = src
;
7736 SET_HARD_REG_BIT (reg_is_output_reload
, src
);
7737 if (find_regno_note (insn
, REG_DEAD
, src
))
7738 SET_HARD_REG_BIT (reg_reloaded_died
, src
);
7740 if (HARD_REGISTER_P (rl_reg_rtx
))
7742 int s
= rl
->secondary_out_reload
;
7743 set
= single_set (p
);
7744 /* If this reload copies only to the secondary reload
7745 register, the secondary reload does the actual
7747 if (s
>= 0 && set
== NULL_RTX
)
7748 /* We can't tell what function the secondary reload
7749 has and where the actual store to the pseudo is
7750 made; leave new_spill_reg_store alone. */
7753 && SET_SRC (set
) == rl_reg_rtx
7754 && SET_DEST (set
) == rld
[s
].reg_rtx
)
7756 /* Usually the next instruction will be the
7757 secondary reload insn; if we can confirm
7758 that it is, setting new_spill_reg_store to
7759 that insn will allow an extra optimization. */
7760 rtx s_reg
= rld
[s
].reg_rtx
;
7761 rtx next
= NEXT_INSN (p
);
7762 rld
[s
].out
= rl
->out
;
7763 rld
[s
].out_reg
= rl
->out_reg
;
7764 set
= single_set (next
);
7765 if (set
&& SET_SRC (set
) == s_reg
7766 && reload_reg_rtx_reaches_end_p (s_reg
, s
))
7768 SET_HARD_REG_BIT (reg_is_output_reload
,
7770 new_spill_reg_store
[REGNO (s_reg
)] = next
;
7773 else if (reload_reg_rtx_reaches_end_p (rl_reg_rtx
, j
))
7774 new_spill_reg_store
[REGNO (rl_reg_rtx
)] = p
;
7779 if (rl
->when_needed
== RELOAD_OTHER
)
7781 emit_insn (other_output_reload_insns
[rl
->opnum
]);
7782 other_output_reload_insns
[rl
->opnum
] = get_insns ();
7785 output_reload_insns
[rl
->opnum
] = get_insns ();
7787 if (cfun
->can_throw_non_call_exceptions
)
7788 copy_reg_eh_region_note_forward (insn
, get_insns (), NULL
);
7793 /* Do input reloading for reload RL, which is for the insn described by CHAIN
7794 and has the number J. */
7796 do_input_reload (struct insn_chain
*chain
, struct reload
*rl
, int j
)
7798 rtx insn
= chain
->insn
;
7799 rtx old
= (rl
->in
&& MEM_P (rl
->in
)
7800 ? rl
->in_reg
: rl
->in
);
7801 rtx reg_rtx
= rl
->reg_rtx
;
7805 enum machine_mode mode
;
7807 /* Determine the mode to reload in.
7808 This is very tricky because we have three to choose from.
7809 There is the mode the insn operand wants (rl->inmode).
7810 There is the mode of the reload register RELOADREG.
7811 There is the intrinsic mode of the operand, which we could find
7812 by stripping some SUBREGs.
7813 It turns out that RELOADREG's mode is irrelevant:
7814 we can change that arbitrarily.
7816 Consider (SUBREG:SI foo:QI) as an operand that must be SImode;
7817 then the reload reg may not support QImode moves, so use SImode.
7818 If foo is in memory due to spilling a pseudo reg, this is safe,
7819 because the QImode value is in the least significant part of a
7820 slot big enough for a SImode. If foo is some other sort of
7821 memory reference, then it is impossible to reload this case,
7822 so previous passes had better make sure this never happens.
7824 Then consider a one-word union which has SImode and one of its
7825 members is a float, being fetched as (SUBREG:SF union:SI).
7826 We must fetch that as SFmode because we could be loading into
7827 a float-only register. In this case OLD's mode is correct.
7829 Consider an immediate integer: it has VOIDmode. Here we need
7830 to get a mode from something else.
7832 In some cases, there is a fourth mode, the operand's
7833 containing mode. If the insn specifies a containing mode for
7834 this operand, it overrides all others.
7836 I am not sure whether the algorithm here is always right,
7837 but it does the right things in those cases. */
7839 mode
= GET_MODE (old
);
7840 if (mode
== VOIDmode
)
7843 /* We cannot use gen_lowpart_common since it can do the wrong thing
7844 when REG_RTX has a multi-word mode. Note that REG_RTX must
7845 always be a REG here. */
7846 if (GET_MODE (reg_rtx
) != mode
)
7847 reg_rtx
= reload_adjust_reg_for_mode (reg_rtx
, mode
);
7849 reload_reg_rtx_for_input
[j
] = reg_rtx
;
7852 /* AUTO_INC reloads need to be handled even if inherited. We got an
7853 AUTO_INC reload if reload_out is set but reload_out_reg isn't. */
7854 && (! reload_inherited
[j
] || (rl
->out
&& ! rl
->out_reg
))
7855 && ! rtx_equal_p (reg_rtx
, old
)
7857 emit_input_reload_insns (chain
, rld
+ j
, old
, j
);
7859 /* When inheriting a wider reload, we have a MEM in rl->in,
7860 e.g. inheriting a SImode output reload for
7861 (mem:HI (plus:SI (reg:SI 14 fp) (const_int 10))) */
7862 if (optimize
&& reload_inherited
[j
] && rl
->in
7864 && MEM_P (rl
->in_reg
)
7865 && reload_spill_index
[j
] >= 0
7866 && TEST_HARD_REG_BIT (reg_reloaded_valid
, reload_spill_index
[j
]))
7867 rl
->in
= regno_reg_rtx
[reg_reloaded_contents
[reload_spill_index
[j
]]];
7869 /* If we are reloading a register that was recently stored in with an
7870 output-reload, see if we can prove there was
7871 actually no need to store the old value in it. */
7874 && (reload_inherited
[j
] || reload_override_in
[j
])
7877 && spill_reg_store
[REGNO (reg_rtx
)] != 0
7879 /* There doesn't seem to be any reason to restrict this to pseudos
7880 and doing so loses in the case where we are copying from a
7881 register of the wrong class. */
7882 && !HARD_REGISTER_P (spill_reg_stored_to
[REGNO (reg_rtx
)])
7884 /* The insn might have already some references to stackslots
7885 replaced by MEMs, while reload_out_reg still names the
7887 && (dead_or_set_p (insn
, spill_reg_stored_to
[REGNO (reg_rtx
)])
7888 || rtx_equal_p (spill_reg_stored_to
[REGNO (reg_rtx
)], rl
->out_reg
)))
7889 delete_output_reload (insn
, j
, REGNO (reg_rtx
), reg_rtx
);
7892 /* Do output reloading for reload RL, which is for the insn described by
7893 CHAIN and has the number J.
7894 ??? At some point we need to support handling output reloads of
7895 JUMP_INSNs or insns that set cc0. */
7897 do_output_reload (struct insn_chain
*chain
, struct reload
*rl
, int j
)
7900 rtx insn
= chain
->insn
;
7901 /* If this is an output reload that stores something that is
7902 not loaded in this same reload, see if we can eliminate a previous
7904 rtx pseudo
= rl
->out_reg
;
7905 rtx reg_rtx
= rl
->reg_rtx
;
7907 if (rl
->out
&& reg_rtx
)
7909 enum machine_mode mode
;
7911 /* Determine the mode to reload in.
7912 See comments above (for input reloading). */
7913 mode
= GET_MODE (rl
->out
);
7914 if (mode
== VOIDmode
)
7916 /* VOIDmode should never happen for an output. */
7917 if (asm_noperands (PATTERN (insn
)) < 0)
7918 /* It's the compiler's fault. */
7919 fatal_insn ("VOIDmode on an output", insn
);
7920 error_for_asm (insn
, "output operand is constant in %<asm%>");
7921 /* Prevent crash--use something we know is valid. */
7923 rl
->out
= gen_rtx_REG (mode
, REGNO (reg_rtx
));
7925 if (GET_MODE (reg_rtx
) != mode
)
7926 reg_rtx
= reload_adjust_reg_for_mode (reg_rtx
, mode
);
7928 reload_reg_rtx_for_output
[j
] = reg_rtx
;
7933 && ! rtx_equal_p (rl
->in_reg
, pseudo
)
7934 && REGNO (pseudo
) >= FIRST_PSEUDO_REGISTER
7935 && reg_last_reload_reg
[REGNO (pseudo
)])
7937 int pseudo_no
= REGNO (pseudo
);
7938 int last_regno
= REGNO (reg_last_reload_reg
[pseudo_no
]);
7940 /* We don't need to test full validity of last_regno for
7941 inherit here; we only want to know if the store actually
7942 matches the pseudo. */
7943 if (TEST_HARD_REG_BIT (reg_reloaded_valid
, last_regno
)
7944 && reg_reloaded_contents
[last_regno
] == pseudo_no
7945 && spill_reg_store
[last_regno
]
7946 && rtx_equal_p (pseudo
, spill_reg_stored_to
[last_regno
]))
7947 delete_output_reload (insn
, j
, last_regno
, reg_rtx
);
7953 || rtx_equal_p (old
, reg_rtx
))
7956 /* An output operand that dies right away does need a reload,
7957 but need not be copied from it. Show the new location in the
7959 if ((REG_P (old
) || GET_CODE (old
) == SCRATCH
)
7960 && (note
= find_reg_note (insn
, REG_UNUSED
, old
)) != 0)
7962 XEXP (note
, 0) = reg_rtx
;
7965 /* Likewise for a SUBREG of an operand that dies. */
7966 else if (GET_CODE (old
) == SUBREG
7967 && REG_P (SUBREG_REG (old
))
7968 && 0 != (note
= find_reg_note (insn
, REG_UNUSED
,
7971 XEXP (note
, 0) = gen_lowpart_common (GET_MODE (old
), reg_rtx
);
7974 else if (GET_CODE (old
) == SCRATCH
)
7975 /* If we aren't optimizing, there won't be a REG_UNUSED note,
7976 but we don't want to make an output reload. */
7979 /* If is a JUMP_INSN, we can't support output reloads yet. */
7980 gcc_assert (NONJUMP_INSN_P (insn
));
7982 emit_output_reload_insns (chain
, rld
+ j
, j
);
7985 /* A reload copies values of MODE from register SRC to register DEST.
7986 Return true if it can be treated for inheritance purposes like a
7987 group of reloads, each one reloading a single hard register. The
7988 caller has already checked that (reg:MODE SRC) and (reg:MODE DEST)
7989 occupy the same number of hard registers. */
7992 inherit_piecemeal_p (int dest ATTRIBUTE_UNUSED
,
7993 int src ATTRIBUTE_UNUSED
,
7994 enum machine_mode mode ATTRIBUTE_UNUSED
)
7996 #ifdef CANNOT_CHANGE_MODE_CLASS
7997 return (!REG_CANNOT_CHANGE_MODE_P (dest
, mode
, reg_raw_mode
[dest
])
7998 && !REG_CANNOT_CHANGE_MODE_P (src
, mode
, reg_raw_mode
[src
]));
8004 /* Output insns to reload values in and out of the chosen reload regs. */
8007 emit_reload_insns (struct insn_chain
*chain
)
8009 rtx insn
= chain
->insn
;
8013 CLEAR_HARD_REG_SET (reg_reloaded_died
);
8015 for (j
= 0; j
< reload_n_operands
; j
++)
8016 input_reload_insns
[j
] = input_address_reload_insns
[j
]
8017 = inpaddr_address_reload_insns
[j
]
8018 = output_reload_insns
[j
] = output_address_reload_insns
[j
]
8019 = outaddr_address_reload_insns
[j
]
8020 = other_output_reload_insns
[j
] = 0;
8021 other_input_address_reload_insns
= 0;
8022 other_input_reload_insns
= 0;
8023 operand_reload_insns
= 0;
8024 other_operand_reload_insns
= 0;
8026 /* Dump reloads into the dump file. */
8029 fprintf (dump_file
, "\nReloads for insn # %d\n", INSN_UID (insn
));
8030 debug_reload_to_stream (dump_file
);
8033 for (j
= 0; j
< n_reloads
; j
++)
8034 if (rld
[j
].reg_rtx
&& HARD_REGISTER_P (rld
[j
].reg_rtx
))
8038 for (i
= REGNO (rld
[j
].reg_rtx
); i
< END_REGNO (rld
[j
].reg_rtx
); i
++)
8039 new_spill_reg_store
[i
] = 0;
8042 /* Now output the instructions to copy the data into and out of the
8043 reload registers. Do these in the order that the reloads were reported,
8044 since reloads of base and index registers precede reloads of operands
8045 and the operands may need the base and index registers reloaded. */
8047 for (j
= 0; j
< n_reloads
; j
++)
8049 do_input_reload (chain
, rld
+ j
, j
);
8050 do_output_reload (chain
, rld
+ j
, j
);
8053 /* Now write all the insns we made for reloads in the order expected by
8054 the allocation functions. Prior to the insn being reloaded, we write
8055 the following reloads:
8057 RELOAD_FOR_OTHER_ADDRESS reloads for input addresses.
8059 RELOAD_OTHER reloads.
8061 For each operand, any RELOAD_FOR_INPADDR_ADDRESS reloads followed
8062 by any RELOAD_FOR_INPUT_ADDRESS reloads followed by the
8063 RELOAD_FOR_INPUT reload for the operand.
8065 RELOAD_FOR_OPADDR_ADDRS reloads.
8067 RELOAD_FOR_OPERAND_ADDRESS reloads.
8069 After the insn being reloaded, we write the following:
8071 For each operand, any RELOAD_FOR_OUTADDR_ADDRESS reloads followed
8072 by any RELOAD_FOR_OUTPUT_ADDRESS reload followed by the
8073 RELOAD_FOR_OUTPUT reload, followed by any RELOAD_OTHER output
8074 reloads for the operand. The RELOAD_OTHER output reloads are
8075 output in descending order by reload number. */
8077 emit_insn_before (other_input_address_reload_insns
, insn
);
8078 emit_insn_before (other_input_reload_insns
, insn
);
8080 for (j
= 0; j
< reload_n_operands
; j
++)
8082 emit_insn_before (inpaddr_address_reload_insns
[j
], insn
);
8083 emit_insn_before (input_address_reload_insns
[j
], insn
);
8084 emit_insn_before (input_reload_insns
[j
], insn
);
8087 emit_insn_before (other_operand_reload_insns
, insn
);
8088 emit_insn_before (operand_reload_insns
, insn
);
8090 for (j
= 0; j
< reload_n_operands
; j
++)
8092 rtx x
= emit_insn_after (outaddr_address_reload_insns
[j
], insn
);
8093 x
= emit_insn_after (output_address_reload_insns
[j
], x
);
8094 x
= emit_insn_after (output_reload_insns
[j
], x
);
8095 emit_insn_after (other_output_reload_insns
[j
], x
);
8098 /* For all the spill regs newly reloaded in this instruction,
8099 record what they were reloaded from, so subsequent instructions
8100 can inherit the reloads.
8102 Update spill_reg_store for the reloads of this insn.
8103 Copy the elements that were updated in the loop above. */
8105 for (j
= 0; j
< n_reloads
; j
++)
8107 int r
= reload_order
[j
];
8108 int i
= reload_spill_index
[r
];
8110 /* If this is a non-inherited input reload from a pseudo, we must
8111 clear any memory of a previous store to the same pseudo. Only do
8112 something if there will not be an output reload for the pseudo
8114 if (rld
[r
].in_reg
!= 0
8115 && ! (reload_inherited
[r
] || reload_override_in
[r
]))
8117 rtx reg
= rld
[r
].in_reg
;
8119 if (GET_CODE (reg
) == SUBREG
)
8120 reg
= SUBREG_REG (reg
);
8123 && REGNO (reg
) >= FIRST_PSEUDO_REGISTER
8124 && !REGNO_REG_SET_P (®_has_output_reload
, REGNO (reg
)))
8126 int nregno
= REGNO (reg
);
8128 if (reg_last_reload_reg
[nregno
])
8130 int last_regno
= REGNO (reg_last_reload_reg
[nregno
]);
8132 if (reg_reloaded_contents
[last_regno
] == nregno
)
8133 spill_reg_store
[last_regno
] = 0;
8138 /* I is nonneg if this reload used a register.
8139 If rld[r].reg_rtx is 0, this is an optional reload
8140 that we opted to ignore. */
8142 if (i
>= 0 && rld
[r
].reg_rtx
!= 0)
8144 int nr
= hard_regno_nregs
[i
][GET_MODE (rld
[r
].reg_rtx
)];
8147 /* For a multi register reload, we need to check if all or part
8148 of the value lives to the end. */
8149 for (k
= 0; k
< nr
; k
++)
8150 if (reload_reg_reaches_end_p (i
+ k
, r
))
8151 CLEAR_HARD_REG_BIT (reg_reloaded_valid
, i
+ k
);
8153 /* Maybe the spill reg contains a copy of reload_out. */
8155 && (REG_P (rld
[r
].out
)
8157 ? REG_P (rld
[r
].out_reg
)
8158 /* The reload value is an auto-modification of
8159 some kind. For PRE_INC, POST_INC, PRE_DEC
8160 and POST_DEC, we record an equivalence
8161 between the reload register and the operand
8162 on the optimistic assumption that we can make
8163 the equivalence hold. reload_as_needed must
8164 then either make it hold or invalidate the
8167 PRE_MODIFY and POST_MODIFY addresses are reloaded
8168 somewhat differently, and allowing them here leads
8170 : (GET_CODE (rld
[r
].out
) != POST_MODIFY
8171 && GET_CODE (rld
[r
].out
) != PRE_MODIFY
))))
8175 reg
= reload_reg_rtx_for_output
[r
];
8176 if (reload_reg_rtx_reaches_end_p (reg
, r
))
8178 enum machine_mode mode
= GET_MODE (reg
);
8179 int regno
= REGNO (reg
);
8180 int nregs
= hard_regno_nregs
[regno
][mode
];
8181 rtx out
= (REG_P (rld
[r
].out
)
8185 /* AUTO_INC */ : XEXP (rld
[r
].in_reg
, 0));
8186 int out_regno
= REGNO (out
);
8187 int out_nregs
= (!HARD_REGISTER_NUM_P (out_regno
) ? 1
8188 : hard_regno_nregs
[out_regno
][mode
]);
8191 spill_reg_store
[regno
] = new_spill_reg_store
[regno
];
8192 spill_reg_stored_to
[regno
] = out
;
8193 reg_last_reload_reg
[out_regno
] = reg
;
8195 piecemeal
= (HARD_REGISTER_NUM_P (out_regno
)
8196 && nregs
== out_nregs
8197 && inherit_piecemeal_p (out_regno
, regno
, mode
));
8199 /* If OUT_REGNO is a hard register, it may occupy more than
8200 one register. If it does, say what is in the
8201 rest of the registers assuming that both registers
8202 agree on how many words the object takes. If not,
8203 invalidate the subsequent registers. */
8205 if (HARD_REGISTER_NUM_P (out_regno
))
8206 for (k
= 1; k
< out_nregs
; k
++)
8207 reg_last_reload_reg
[out_regno
+ k
]
8208 = (piecemeal
? regno_reg_rtx
[regno
+ k
] : 0);
8210 /* Now do the inverse operation. */
8211 for (k
= 0; k
< nregs
; k
++)
8213 CLEAR_HARD_REG_BIT (reg_reloaded_dead
, regno
+ k
);
8214 reg_reloaded_contents
[regno
+ k
]
8215 = (!HARD_REGISTER_NUM_P (out_regno
) || !piecemeal
8218 reg_reloaded_insn
[regno
+ k
] = insn
;
8219 SET_HARD_REG_BIT (reg_reloaded_valid
, regno
+ k
);
8220 if (HARD_REGNO_CALL_PART_CLOBBERED (regno
+ k
, mode
))
8221 SET_HARD_REG_BIT (reg_reloaded_call_part_clobbered
,
8224 CLEAR_HARD_REG_BIT (reg_reloaded_call_part_clobbered
,
8229 /* Maybe the spill reg contains a copy of reload_in. Only do
8230 something if there will not be an output reload for
8231 the register being reloaded. */
8232 else if (rld
[r
].out_reg
== 0
8234 && ((REG_P (rld
[r
].in
)
8235 && !HARD_REGISTER_P (rld
[r
].in
)
8236 && !REGNO_REG_SET_P (®_has_output_reload
,
8238 || (REG_P (rld
[r
].in_reg
)
8239 && !REGNO_REG_SET_P (®_has_output_reload
,
8240 REGNO (rld
[r
].in_reg
))))
8241 && !reg_set_p (reload_reg_rtx_for_input
[r
], PATTERN (insn
)))
8245 reg
= reload_reg_rtx_for_input
[r
];
8246 if (reload_reg_rtx_reaches_end_p (reg
, r
))
8248 enum machine_mode mode
;
8256 mode
= GET_MODE (reg
);
8257 regno
= REGNO (reg
);
8258 nregs
= hard_regno_nregs
[regno
][mode
];
8259 if (REG_P (rld
[r
].in
)
8260 && REGNO (rld
[r
].in
) >= FIRST_PSEUDO_REGISTER
)
8262 else if (REG_P (rld
[r
].in_reg
))
8265 in
= XEXP (rld
[r
].in_reg
, 0);
8266 in_regno
= REGNO (in
);
8268 in_nregs
= (!HARD_REGISTER_NUM_P (in_regno
) ? 1
8269 : hard_regno_nregs
[in_regno
][mode
]);
8271 reg_last_reload_reg
[in_regno
] = reg
;
8273 piecemeal
= (HARD_REGISTER_NUM_P (in_regno
)
8274 && nregs
== in_nregs
8275 && inherit_piecemeal_p (regno
, in_regno
, mode
));
8277 if (HARD_REGISTER_NUM_P (in_regno
))
8278 for (k
= 1; k
< in_nregs
; k
++)
8279 reg_last_reload_reg
[in_regno
+ k
]
8280 = (piecemeal
? regno_reg_rtx
[regno
+ k
] : 0);
8282 /* Unless we inherited this reload, show we haven't
8283 recently done a store.
8284 Previous stores of inherited auto_inc expressions
8285 also have to be discarded. */
8286 if (! reload_inherited
[r
]
8287 || (rld
[r
].out
&& ! rld
[r
].out_reg
))
8288 spill_reg_store
[regno
] = 0;
8290 for (k
= 0; k
< nregs
; k
++)
8292 CLEAR_HARD_REG_BIT (reg_reloaded_dead
, regno
+ k
);
8293 reg_reloaded_contents
[regno
+ k
]
8294 = (!HARD_REGISTER_NUM_P (in_regno
) || !piecemeal
8297 reg_reloaded_insn
[regno
+ k
] = insn
;
8298 SET_HARD_REG_BIT (reg_reloaded_valid
, regno
+ k
);
8299 if (HARD_REGNO_CALL_PART_CLOBBERED (regno
+ k
, mode
))
8300 SET_HARD_REG_BIT (reg_reloaded_call_part_clobbered
,
8303 CLEAR_HARD_REG_BIT (reg_reloaded_call_part_clobbered
,
8310 /* The following if-statement was #if 0'd in 1.34 (or before...).
8311 It's reenabled in 1.35 because supposedly nothing else
8312 deals with this problem. */
8314 /* If a register gets output-reloaded from a non-spill register,
8315 that invalidates any previous reloaded copy of it.
8316 But forget_old_reloads_1 won't get to see it, because
8317 it thinks only about the original insn. So invalidate it here.
8318 Also do the same thing for RELOAD_OTHER constraints where the
8319 output is discarded. */
8321 && ((rld
[r
].out
!= 0
8322 && (REG_P (rld
[r
].out
)
8323 || (MEM_P (rld
[r
].out
)
8324 && REG_P (rld
[r
].out_reg
))))
8325 || (rld
[r
].out
== 0 && rld
[r
].out_reg
8326 && REG_P (rld
[r
].out_reg
))))
8328 rtx out
= ((rld
[r
].out
&& REG_P (rld
[r
].out
))
8329 ? rld
[r
].out
: rld
[r
].out_reg
);
8330 int out_regno
= REGNO (out
);
8331 enum machine_mode mode
= GET_MODE (out
);
8333 /* REG_RTX is now set or clobbered by the main instruction.
8334 As the comment above explains, forget_old_reloads_1 only
8335 sees the original instruction, and there is no guarantee
8336 that the original instruction also clobbered REG_RTX.
8337 For example, if find_reloads sees that the input side of
8338 a matched operand pair dies in this instruction, it may
8339 use the input register as the reload register.
8341 Calling forget_old_reloads_1 is a waste of effort if
8342 REG_RTX is also the output register.
8344 If we know that REG_RTX holds the value of a pseudo
8345 register, the code after the call will record that fact. */
8346 if (rld
[r
].reg_rtx
&& rld
[r
].reg_rtx
!= out
)
8347 forget_old_reloads_1 (rld
[r
].reg_rtx
, NULL_RTX
, NULL
);
8349 if (!HARD_REGISTER_NUM_P (out_regno
))
8351 rtx src_reg
, store_insn
= NULL_RTX
;
8353 reg_last_reload_reg
[out_regno
] = 0;
8355 /* If we can find a hard register that is stored, record
8356 the storing insn so that we may delete this insn with
8357 delete_output_reload. */
8358 src_reg
= reload_reg_rtx_for_output
[r
];
8362 if (reload_reg_rtx_reaches_end_p (src_reg
, r
))
8363 store_insn
= new_spill_reg_store
[REGNO (src_reg
)];
8369 /* If this is an optional reload, try to find the
8370 source reg from an input reload. */
8371 rtx set
= single_set (insn
);
8372 if (set
&& SET_DEST (set
) == rld
[r
].out
)
8376 src_reg
= SET_SRC (set
);
8378 for (k
= 0; k
< n_reloads
; k
++)
8380 if (rld
[k
].in
== src_reg
)
8382 src_reg
= reload_reg_rtx_for_input
[k
];
8388 if (src_reg
&& REG_P (src_reg
)
8389 && REGNO (src_reg
) < FIRST_PSEUDO_REGISTER
)
8391 int src_regno
, src_nregs
, k
;
8394 gcc_assert (GET_MODE (src_reg
) == mode
);
8395 src_regno
= REGNO (src_reg
);
8396 src_nregs
= hard_regno_nregs
[src_regno
][mode
];
8397 /* The place where to find a death note varies with
8398 PRESERVE_DEATH_INFO_REGNO_P . The condition is not
8399 necessarily checked exactly in the code that moves
8400 notes, so just check both locations. */
8401 note
= find_regno_note (insn
, REG_DEAD
, src_regno
);
8402 if (! note
&& store_insn
)
8403 note
= find_regno_note (store_insn
, REG_DEAD
, src_regno
);
8404 for (k
= 0; k
< src_nregs
; k
++)
8406 spill_reg_store
[src_regno
+ k
] = store_insn
;
8407 spill_reg_stored_to
[src_regno
+ k
] = out
;
8408 reg_reloaded_contents
[src_regno
+ k
] = out_regno
;
8409 reg_reloaded_insn
[src_regno
+ k
] = store_insn
;
8410 CLEAR_HARD_REG_BIT (reg_reloaded_dead
, src_regno
+ k
);
8411 SET_HARD_REG_BIT (reg_reloaded_valid
, src_regno
+ k
);
8412 if (HARD_REGNO_CALL_PART_CLOBBERED (src_regno
+ k
,
8414 SET_HARD_REG_BIT (reg_reloaded_call_part_clobbered
,
8417 CLEAR_HARD_REG_BIT (reg_reloaded_call_part_clobbered
,
8419 SET_HARD_REG_BIT (reg_is_output_reload
, src_regno
+ k
);
8421 SET_HARD_REG_BIT (reg_reloaded_died
, src_regno
);
8423 CLEAR_HARD_REG_BIT (reg_reloaded_died
, src_regno
);
8425 reg_last_reload_reg
[out_regno
] = src_reg
;
8426 /* We have to set reg_has_output_reload here, or else
8427 forget_old_reloads_1 will clear reg_last_reload_reg
8429 SET_REGNO_REG_SET (®_has_output_reload
,
8435 int k
, out_nregs
= hard_regno_nregs
[out_regno
][mode
];
8437 for (k
= 0; k
< out_nregs
; k
++)
8438 reg_last_reload_reg
[out_regno
+ k
] = 0;
8442 IOR_HARD_REG_SET (reg_reloaded_dead
, reg_reloaded_died
);
8445 /* Go through the motions to emit INSN and test if it is strictly valid.
8446 Return the emitted insn if valid, else return NULL. */
8449 emit_insn_if_valid_for_reload (rtx insn
)
8451 rtx last
= get_last_insn ();
8454 insn
= emit_insn (insn
);
8455 code
= recog_memoized (insn
);
8459 extract_insn (insn
);
8460 /* We want constrain operands to treat this insn strictly in its
8461 validity determination, i.e., the way it would after reload has
8463 if (constrain_operands (1))
8467 delete_insns_since (last
);
8471 /* Emit code to perform a reload from IN (which may be a reload register) to
8472 OUT (which may also be a reload register). IN or OUT is from operand
8473 OPNUM with reload type TYPE.
8475 Returns first insn emitted. */
8478 gen_reload (rtx out
, rtx in
, int opnum
, enum reload_type type
)
8480 rtx last
= get_last_insn ();
8483 /* If IN is a paradoxical SUBREG, remove it and try to put the
8484 opposite SUBREG on OUT. Likewise for a paradoxical SUBREG on OUT. */
8485 if (!strip_paradoxical_subreg (&in
, &out
))
8486 strip_paradoxical_subreg (&out
, &in
);
8488 /* How to do this reload can get quite tricky. Normally, we are being
8489 asked to reload a simple operand, such as a MEM, a constant, or a pseudo
8490 register that didn't get a hard register. In that case we can just
8491 call emit_move_insn.
8493 We can also be asked to reload a PLUS that adds a register or a MEM to
8494 another register, constant or MEM. This can occur during frame pointer
8495 elimination and while reloading addresses. This case is handled by
8496 trying to emit a single insn to perform the add. If it is not valid,
8497 we use a two insn sequence.
8499 Or we can be asked to reload an unary operand that was a fragment of
8500 an addressing mode, into a register. If it isn't recognized as-is,
8501 we try making the unop operand and the reload-register the same:
8502 (set reg:X (unop:X expr:Y))
8503 -> (set reg:Y expr:Y) (set reg:X (unop:X reg:Y)).
8505 Finally, we could be called to handle an 'o' constraint by putting
8506 an address into a register. In that case, we first try to do this
8507 with a named pattern of "reload_load_address". If no such pattern
8508 exists, we just emit a SET insn and hope for the best (it will normally
8509 be valid on machines that use 'o').
8511 This entire process is made complex because reload will never
8512 process the insns we generate here and so we must ensure that
8513 they will fit their constraints and also by the fact that parts of
8514 IN might be being reloaded separately and replaced with spill registers.
8515 Because of this, we are, in some sense, just guessing the right approach
8516 here. The one listed above seems to work.
8518 ??? At some point, this whole thing needs to be rethought. */
8520 if (GET_CODE (in
) == PLUS
8521 && (REG_P (XEXP (in
, 0))
8522 || GET_CODE (XEXP (in
, 0)) == SUBREG
8523 || MEM_P (XEXP (in
, 0)))
8524 && (REG_P (XEXP (in
, 1))
8525 || GET_CODE (XEXP (in
, 1)) == SUBREG
8526 || CONSTANT_P (XEXP (in
, 1))
8527 || MEM_P (XEXP (in
, 1))))
8529 /* We need to compute the sum of a register or a MEM and another
8530 register, constant, or MEM, and put it into the reload
8531 register. The best possible way of doing this is if the machine
8532 has a three-operand ADD insn that accepts the required operands.
8534 The simplest approach is to try to generate such an insn and see if it
8535 is recognized and matches its constraints. If so, it can be used.
8537 It might be better not to actually emit the insn unless it is valid,
8538 but we need to pass the insn as an operand to `recog' and
8539 `extract_insn' and it is simpler to emit and then delete the insn if
8540 not valid than to dummy things up. */
8542 rtx op0
, op1
, tem
, insn
;
8543 enum insn_code code
;
8545 op0
= find_replacement (&XEXP (in
, 0));
8546 op1
= find_replacement (&XEXP (in
, 1));
8548 /* Since constraint checking is strict, commutativity won't be
8549 checked, so we need to do that here to avoid spurious failure
8550 if the add instruction is two-address and the second operand
8551 of the add is the same as the reload reg, which is frequently
8552 the case. If the insn would be A = B + A, rearrange it so
8553 it will be A = A + B as constrain_operands expects. */
8555 if (REG_P (XEXP (in
, 1))
8556 && REGNO (out
) == REGNO (XEXP (in
, 1)))
8557 tem
= op0
, op0
= op1
, op1
= tem
;
8559 if (op0
!= XEXP (in
, 0) || op1
!= XEXP (in
, 1))
8560 in
= gen_rtx_PLUS (GET_MODE (in
), op0
, op1
);
8562 insn
= emit_insn_if_valid_for_reload (gen_rtx_SET (VOIDmode
, out
, in
));
8566 /* If that failed, we must use a conservative two-insn sequence.
8568 Use a move to copy one operand into the reload register. Prefer
8569 to reload a constant, MEM or pseudo since the move patterns can
8570 handle an arbitrary operand. If OP1 is not a constant, MEM or
8571 pseudo and OP1 is not a valid operand for an add instruction, then
8574 After reloading one of the operands into the reload register, add
8575 the reload register to the output register.
8577 If there is another way to do this for a specific machine, a
8578 DEFINE_PEEPHOLE should be specified that recognizes the sequence
8581 code
= optab_handler (add_optab
, GET_MODE (out
));
8583 if (CONSTANT_P (op1
) || MEM_P (op1
) || GET_CODE (op1
) == SUBREG
8585 && REGNO (op1
) >= FIRST_PSEUDO_REGISTER
)
8586 || (code
!= CODE_FOR_nothing
8587 && !insn_operand_matches (code
, 2, op1
)))
8588 tem
= op0
, op0
= op1
, op1
= tem
;
8590 gen_reload (out
, op0
, opnum
, type
);
8592 /* If OP0 and OP1 are the same, we can use OUT for OP1.
8593 This fixes a problem on the 32K where the stack pointer cannot
8594 be used as an operand of an add insn. */
8596 if (rtx_equal_p (op0
, op1
))
8599 insn
= emit_insn_if_valid_for_reload (gen_add2_insn (out
, op1
));
8602 /* Add a REG_EQUIV note so that find_equiv_reg can find it. */
8603 set_dst_reg_note (insn
, REG_EQUIV
, in
, out
);
8607 /* If that failed, copy the address register to the reload register.
8608 Then add the constant to the reload register. */
8610 gcc_assert (!reg_overlap_mentioned_p (out
, op0
));
8611 gen_reload (out
, op1
, opnum
, type
);
8612 insn
= emit_insn (gen_add2_insn (out
, op0
));
8613 set_dst_reg_note (insn
, REG_EQUIV
, in
, out
);
8616 #ifdef SECONDARY_MEMORY_NEEDED
8617 /* If we need a memory location to do the move, do it that way. */
8618 else if ((REG_P (in
)
8619 || (GET_CODE (in
) == SUBREG
&& REG_P (SUBREG_REG (in
))))
8620 && reg_or_subregno (in
) < FIRST_PSEUDO_REGISTER
8622 || (GET_CODE (out
) == SUBREG
&& REG_P (SUBREG_REG (out
))))
8623 && reg_or_subregno (out
) < FIRST_PSEUDO_REGISTER
8624 && SECONDARY_MEMORY_NEEDED (REGNO_REG_CLASS (reg_or_subregno (in
)),
8625 REGNO_REG_CLASS (reg_or_subregno (out
)),
8628 /* Get the memory to use and rewrite both registers to its mode. */
8629 rtx loc
= get_secondary_mem (in
, GET_MODE (out
), opnum
, type
);
8631 if (GET_MODE (loc
) != GET_MODE (out
))
8632 out
= gen_rtx_REG (GET_MODE (loc
), reg_or_subregno (out
));
8634 if (GET_MODE (loc
) != GET_MODE (in
))
8635 in
= gen_rtx_REG (GET_MODE (loc
), reg_or_subregno (in
));
8637 gen_reload (loc
, in
, opnum
, type
);
8638 gen_reload (out
, loc
, opnum
, type
);
8641 else if (REG_P (out
) && UNARY_P (in
))
8648 op1
= find_replacement (&XEXP (in
, 0));
8649 if (op1
!= XEXP (in
, 0))
8650 in
= gen_rtx_fmt_e (GET_CODE (in
), GET_MODE (in
), op1
);
8652 /* First, try a plain SET. */
8653 set
= emit_insn_if_valid_for_reload (gen_rtx_SET (VOIDmode
, out
, in
));
8657 /* If that failed, move the inner operand to the reload
8658 register, and try the same unop with the inner expression
8659 replaced with the reload register. */
8661 if (GET_MODE (op1
) != GET_MODE (out
))
8662 out_moded
= gen_rtx_REG (GET_MODE (op1
), REGNO (out
));
8666 gen_reload (out_moded
, op1
, opnum
, type
);
8669 = gen_rtx_SET (VOIDmode
, out
,
8670 gen_rtx_fmt_e (GET_CODE (in
), GET_MODE (in
),
8672 insn
= emit_insn_if_valid_for_reload (insn
);
8675 set_unique_reg_note (insn
, REG_EQUIV
, in
);
8679 fatal_insn ("failure trying to reload:", set
);
8681 /* If IN is a simple operand, use gen_move_insn. */
8682 else if (OBJECT_P (in
) || GET_CODE (in
) == SUBREG
)
8684 tem
= emit_insn (gen_move_insn (out
, in
));
8685 /* IN may contain a LABEL_REF, if so add a REG_LABEL_OPERAND note. */
8686 mark_jump_label (in
, tem
, 0);
8689 #ifdef HAVE_reload_load_address
8690 else if (HAVE_reload_load_address
)
8691 emit_insn (gen_reload_load_address (out
, in
));
8694 /* Otherwise, just write (set OUT IN) and hope for the best. */
8696 emit_insn (gen_rtx_SET (VOIDmode
, out
, in
));
8698 /* Return the first insn emitted.
8699 We can not just return get_last_insn, because there may have
8700 been multiple instructions emitted. Also note that gen_move_insn may
8701 emit more than one insn itself, so we can not assume that there is one
8702 insn emitted per emit_insn_before call. */
8704 return last
? NEXT_INSN (last
) : get_insns ();
8707 /* Delete a previously made output-reload whose result we now believe
8708 is not needed. First we double-check.
8710 INSN is the insn now being processed.
8711 LAST_RELOAD_REG is the hard register number for which we want to delete
8712 the last output reload.
8713 J is the reload-number that originally used REG. The caller has made
8714 certain that reload J doesn't use REG any longer for input.
8715 NEW_RELOAD_REG is reload register that reload J is using for REG. */
8718 delete_output_reload (rtx insn
, int j
, int last_reload_reg
, rtx new_reload_reg
)
8720 rtx output_reload_insn
= spill_reg_store
[last_reload_reg
];
8721 rtx reg
= spill_reg_stored_to
[last_reload_reg
];
8724 int n_inherited
= 0;
8730 /* It is possible that this reload has been only used to set another reload
8731 we eliminated earlier and thus deleted this instruction too. */
8732 if (INSN_DELETED_P (output_reload_insn
))
8735 /* Get the raw pseudo-register referred to. */
8737 while (GET_CODE (reg
) == SUBREG
)
8738 reg
= SUBREG_REG (reg
);
8739 substed
= reg_equiv_memory_loc (REGNO (reg
));
8741 /* This is unsafe if the operand occurs more often in the current
8742 insn than it is inherited. */
8743 for (k
= n_reloads
- 1; k
>= 0; k
--)
8745 rtx reg2
= rld
[k
].in
;
8748 if (MEM_P (reg2
) || reload_override_in
[k
])
8749 reg2
= rld
[k
].in_reg
;
8751 if (rld
[k
].out
&& ! rld
[k
].out_reg
)
8752 reg2
= XEXP (rld
[k
].in_reg
, 0);
8754 while (GET_CODE (reg2
) == SUBREG
)
8755 reg2
= SUBREG_REG (reg2
);
8756 if (rtx_equal_p (reg2
, reg
))
8758 if (reload_inherited
[k
] || reload_override_in
[k
] || k
== j
)
8764 n_occurrences
= count_occurrences (PATTERN (insn
), reg
, 0);
8765 if (CALL_P (insn
) && CALL_INSN_FUNCTION_USAGE (insn
))
8766 n_occurrences
+= count_occurrences (CALL_INSN_FUNCTION_USAGE (insn
),
8769 n_occurrences
+= count_occurrences (PATTERN (insn
),
8770 eliminate_regs (substed
, VOIDmode
,
8772 for (i1
= reg_equiv_alt_mem_list (REGNO (reg
)); i1
; i1
= XEXP (i1
, 1))
8774 gcc_assert (!rtx_equal_p (XEXP (i1
, 0), substed
));
8775 n_occurrences
+= count_occurrences (PATTERN (insn
), XEXP (i1
, 0), 0);
8777 if (n_occurrences
> n_inherited
)
8780 regno
= REGNO (reg
);
8781 if (regno
>= FIRST_PSEUDO_REGISTER
)
8784 nregs
= hard_regno_nregs
[regno
][GET_MODE (reg
)];
8786 /* If the pseudo-reg we are reloading is no longer referenced
8787 anywhere between the store into it and here,
8788 and we're within the same basic block, then the value can only
8789 pass through the reload reg and end up here.
8790 Otherwise, give up--return. */
8791 for (i1
= NEXT_INSN (output_reload_insn
);
8792 i1
!= insn
; i1
= NEXT_INSN (i1
))
8794 if (NOTE_INSN_BASIC_BLOCK_P (i1
))
8796 if ((NONJUMP_INSN_P (i1
) || CALL_P (i1
))
8797 && refers_to_regno_p (regno
, regno
+ nregs
, PATTERN (i1
), NULL
))
8799 /* If this is USE in front of INSN, we only have to check that
8800 there are no more references than accounted for by inheritance. */
8801 while (NONJUMP_INSN_P (i1
) && GET_CODE (PATTERN (i1
)) == USE
)
8803 n_occurrences
+= rtx_equal_p (reg
, XEXP (PATTERN (i1
), 0)) != 0;
8804 i1
= NEXT_INSN (i1
);
8806 if (n_occurrences
<= n_inherited
&& i1
== insn
)
8812 /* We will be deleting the insn. Remove the spill reg information. */
8813 for (k
= hard_regno_nregs
[last_reload_reg
][GET_MODE (reg
)]; k
-- > 0; )
8815 spill_reg_store
[last_reload_reg
+ k
] = 0;
8816 spill_reg_stored_to
[last_reload_reg
+ k
] = 0;
8819 /* The caller has already checked that REG dies or is set in INSN.
8820 It has also checked that we are optimizing, and thus some
8821 inaccuracies in the debugging information are acceptable.
8822 So we could just delete output_reload_insn. But in some cases
8823 we can improve the debugging information without sacrificing
8824 optimization - maybe even improving the code: See if the pseudo
8825 reg has been completely replaced with reload regs. If so, delete
8826 the store insn and forget we had a stack slot for the pseudo. */
8827 if (rld
[j
].out
!= rld
[j
].in
8828 && REG_N_DEATHS (REGNO (reg
)) == 1
8829 && REG_N_SETS (REGNO (reg
)) == 1
8830 && REG_BASIC_BLOCK (REGNO (reg
)) >= NUM_FIXED_BLOCKS
8831 && find_regno_note (insn
, REG_DEAD
, REGNO (reg
)))
8835 /* We know that it was used only between here and the beginning of
8836 the current basic block. (We also know that the last use before
8837 INSN was the output reload we are thinking of deleting, but never
8838 mind that.) Search that range; see if any ref remains. */
8839 for (i2
= PREV_INSN (insn
); i2
; i2
= PREV_INSN (i2
))
8841 rtx set
= single_set (i2
);
8843 /* Uses which just store in the pseudo don't count,
8844 since if they are the only uses, they are dead. */
8845 if (set
!= 0 && SET_DEST (set
) == reg
)
8850 if ((NONJUMP_INSN_P (i2
) || CALL_P (i2
))
8851 && reg_mentioned_p (reg
, PATTERN (i2
)))
8853 /* Some other ref remains; just delete the output reload we
8855 delete_address_reloads (output_reload_insn
, insn
);
8856 delete_insn (output_reload_insn
);
8861 /* Delete the now-dead stores into this pseudo. Note that this
8862 loop also takes care of deleting output_reload_insn. */
8863 for (i2
= PREV_INSN (insn
); i2
; i2
= PREV_INSN (i2
))
8865 rtx set
= single_set (i2
);
8867 if (set
!= 0 && SET_DEST (set
) == reg
)
8869 delete_address_reloads (i2
, insn
);
8877 /* For the debugging info, say the pseudo lives in this reload reg. */
8878 reg_renumber
[REGNO (reg
)] = REGNO (new_reload_reg
);
8879 if (ira_conflicts_p
)
8880 /* Inform IRA about the change. */
8881 ira_mark_allocation_change (REGNO (reg
));
8882 alter_reg (REGNO (reg
), -1, false);
8886 delete_address_reloads (output_reload_insn
, insn
);
8887 delete_insn (output_reload_insn
);
8891 /* We are going to delete DEAD_INSN. Recursively delete loads of
8892 reload registers used in DEAD_INSN that are not used till CURRENT_INSN.
8893 CURRENT_INSN is being reloaded, so we have to check its reloads too. */
8895 delete_address_reloads (rtx dead_insn
, rtx current_insn
)
8897 rtx set
= single_set (dead_insn
);
8898 rtx set2
, dst
, prev
, next
;
8901 rtx dst
= SET_DEST (set
);
8903 delete_address_reloads_1 (dead_insn
, XEXP (dst
, 0), current_insn
);
8905 /* If we deleted the store from a reloaded post_{in,de}c expression,
8906 we can delete the matching adds. */
8907 prev
= PREV_INSN (dead_insn
);
8908 next
= NEXT_INSN (dead_insn
);
8909 if (! prev
|| ! next
)
8911 set
= single_set (next
);
8912 set2
= single_set (prev
);
8914 || GET_CODE (SET_SRC (set
)) != PLUS
|| GET_CODE (SET_SRC (set2
)) != PLUS
8915 || !CONST_INT_P (XEXP (SET_SRC (set
), 1))
8916 || !CONST_INT_P (XEXP (SET_SRC (set2
), 1)))
8918 dst
= SET_DEST (set
);
8919 if (! rtx_equal_p (dst
, SET_DEST (set2
))
8920 || ! rtx_equal_p (dst
, XEXP (SET_SRC (set
), 0))
8921 || ! rtx_equal_p (dst
, XEXP (SET_SRC (set2
), 0))
8922 || (INTVAL (XEXP (SET_SRC (set
), 1))
8923 != -INTVAL (XEXP (SET_SRC (set2
), 1))))
8925 delete_related_insns (prev
);
8926 delete_related_insns (next
);
8929 /* Subfunction of delete_address_reloads: process registers found in X. */
8931 delete_address_reloads_1 (rtx dead_insn
, rtx x
, rtx current_insn
)
8933 rtx prev
, set
, dst
, i2
;
8935 enum rtx_code code
= GET_CODE (x
);
8939 const char *fmt
= GET_RTX_FORMAT (code
);
8940 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
8943 delete_address_reloads_1 (dead_insn
, XEXP (x
, i
), current_insn
);
8944 else if (fmt
[i
] == 'E')
8946 for (j
= XVECLEN (x
, i
) - 1; j
>= 0; j
--)
8947 delete_address_reloads_1 (dead_insn
, XVECEXP (x
, i
, j
),
8954 if (spill_reg_order
[REGNO (x
)] < 0)
8957 /* Scan backwards for the insn that sets x. This might be a way back due
8959 for (prev
= PREV_INSN (dead_insn
); prev
; prev
= PREV_INSN (prev
))
8961 code
= GET_CODE (prev
);
8962 if (code
== CODE_LABEL
|| code
== JUMP_INSN
)
8966 if (reg_set_p (x
, PATTERN (prev
)))
8968 if (reg_referenced_p (x
, PATTERN (prev
)))
8971 if (! prev
|| INSN_UID (prev
) < reload_first_uid
)
8973 /* Check that PREV only sets the reload register. */
8974 set
= single_set (prev
);
8977 dst
= SET_DEST (set
);
8979 || ! rtx_equal_p (dst
, x
))
8981 if (! reg_set_p (dst
, PATTERN (dead_insn
)))
8983 /* Check if DST was used in a later insn -
8984 it might have been inherited. */
8985 for (i2
= NEXT_INSN (dead_insn
); i2
; i2
= NEXT_INSN (i2
))
8991 if (reg_referenced_p (dst
, PATTERN (i2
)))
8993 /* If there is a reference to the register in the current insn,
8994 it might be loaded in a non-inherited reload. If no other
8995 reload uses it, that means the register is set before
8997 if (i2
== current_insn
)
8999 for (j
= n_reloads
- 1; j
>= 0; j
--)
9000 if ((rld
[j
].reg_rtx
== dst
&& reload_inherited
[j
])
9001 || reload_override_in
[j
] == dst
)
9003 for (j
= n_reloads
- 1; j
>= 0; j
--)
9004 if (rld
[j
].in
&& rld
[j
].reg_rtx
== dst
)
9013 /* If DST is still live at CURRENT_INSN, check if it is used for
9014 any reload. Note that even if CURRENT_INSN sets DST, we still
9015 have to check the reloads. */
9016 if (i2
== current_insn
)
9018 for (j
= n_reloads
- 1; j
>= 0; j
--)
9019 if ((rld
[j
].reg_rtx
== dst
&& reload_inherited
[j
])
9020 || reload_override_in
[j
] == dst
)
9022 /* ??? We can't finish the loop here, because dst might be
9023 allocated to a pseudo in this block if no reload in this
9024 block needs any of the classes containing DST - see
9025 spill_hard_reg. There is no easy way to tell this, so we
9026 have to scan till the end of the basic block. */
9028 if (reg_set_p (dst
, PATTERN (i2
)))
9032 delete_address_reloads_1 (prev
, SET_SRC (set
), current_insn
);
9033 reg_reloaded_contents
[REGNO (dst
)] = -1;
9037 /* Output reload-insns to reload VALUE into RELOADREG.
9038 VALUE is an autoincrement or autodecrement RTX whose operand
9039 is a register or memory location;
9040 so reloading involves incrementing that location.
9041 IN is either identical to VALUE, or some cheaper place to reload from.
9043 INC_AMOUNT is the number to increment or decrement by (always positive).
9044 This cannot be deduced from VALUE. */
9047 inc_for_reload (rtx reloadreg
, rtx in
, rtx value
, int inc_amount
)
9049 /* REG or MEM to be copied and incremented. */
9050 rtx incloc
= find_replacement (&XEXP (value
, 0));
9051 /* Nonzero if increment after copying. */
9052 int post
= (GET_CODE (value
) == POST_DEC
|| GET_CODE (value
) == POST_INC
9053 || GET_CODE (value
) == POST_MODIFY
);
9058 rtx real_in
= in
== value
? incloc
: in
;
9060 /* No hard register is equivalent to this register after
9061 inc/dec operation. If REG_LAST_RELOAD_REG were nonzero,
9062 we could inc/dec that register as well (maybe even using it for
9063 the source), but I'm not sure it's worth worrying about. */
9065 reg_last_reload_reg
[REGNO (incloc
)] = 0;
9067 if (GET_CODE (value
) == PRE_MODIFY
|| GET_CODE (value
) == POST_MODIFY
)
9069 gcc_assert (GET_CODE (XEXP (value
, 1)) == PLUS
);
9070 inc
= find_replacement (&XEXP (XEXP (value
, 1), 1));
9074 if (GET_CODE (value
) == PRE_DEC
|| GET_CODE (value
) == POST_DEC
)
9075 inc_amount
= -inc_amount
;
9077 inc
= GEN_INT (inc_amount
);
9080 /* If this is post-increment, first copy the location to the reload reg. */
9081 if (post
&& real_in
!= reloadreg
)
9082 emit_insn (gen_move_insn (reloadreg
, real_in
));
9086 /* See if we can directly increment INCLOC. Use a method similar to
9087 that in gen_reload. */
9089 last
= get_last_insn ();
9090 add_insn
= emit_insn (gen_rtx_SET (VOIDmode
, incloc
,
9091 gen_rtx_PLUS (GET_MODE (incloc
),
9094 code
= recog_memoized (add_insn
);
9097 extract_insn (add_insn
);
9098 if (constrain_operands (1))
9100 /* If this is a pre-increment and we have incremented the value
9101 where it lives, copy the incremented value to RELOADREG to
9102 be used as an address. */
9105 emit_insn (gen_move_insn (reloadreg
, incloc
));
9109 delete_insns_since (last
);
9112 /* If couldn't do the increment directly, must increment in RELOADREG.
9113 The way we do this depends on whether this is pre- or post-increment.
9114 For pre-increment, copy INCLOC to the reload register, increment it
9115 there, then save back. */
9119 if (in
!= reloadreg
)
9120 emit_insn (gen_move_insn (reloadreg
, real_in
));
9121 emit_insn (gen_add2_insn (reloadreg
, inc
));
9122 emit_insn (gen_move_insn (incloc
, reloadreg
));
9127 Because this might be a jump insn or a compare, and because RELOADREG
9128 may not be available after the insn in an input reload, we must do
9129 the incrementation before the insn being reloaded for.
9131 We have already copied IN to RELOADREG. Increment the copy in
9132 RELOADREG, save that back, then decrement RELOADREG so it has
9133 the original value. */
9135 emit_insn (gen_add2_insn (reloadreg
, inc
));
9136 emit_insn (gen_move_insn (incloc
, reloadreg
));
9137 if (CONST_INT_P (inc
))
9138 emit_insn (gen_add2_insn (reloadreg
, GEN_INT (-INTVAL (inc
))));
9140 emit_insn (gen_sub2_insn (reloadreg
, inc
));
9146 add_auto_inc_notes (rtx insn
, rtx x
)
9148 enum rtx_code code
= GET_CODE (x
);
9152 if (code
== MEM
&& auto_inc_p (XEXP (x
, 0)))
9154 add_reg_note (insn
, REG_INC
, XEXP (XEXP (x
, 0), 0));
9158 /* Scan all the operand sub-expressions. */
9159 fmt
= GET_RTX_FORMAT (code
);
9160 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
9163 add_auto_inc_notes (insn
, XEXP (x
, i
));
9164 else if (fmt
[i
] == 'E')
9165 for (j
= XVECLEN (x
, i
) - 1; j
>= 0; j
--)
9166 add_auto_inc_notes (insn
, XVECEXP (x
, i
, j
));