1 /* Code for RTL transformations to satisfy insn constraints.
2 Copyright (C) 2010-2016 Free Software Foundation, Inc.
3 Contributed by Vladimir Makarov <vmakarov@redhat.com>.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 3, or (at your option) any later
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
22 /* This file contains code for 3 passes: constraint pass,
23 inheritance/split pass, and pass for undoing failed inheritance and
26 The major goal of constraint pass is to transform RTL to satisfy
27 insn and address constraints by:
28 o choosing insn alternatives;
29 o generating *reload insns* (or reloads in brief) and *reload
30 pseudos* which will get necessary hard registers later;
31 o substituting pseudos with equivalent values and removing the
32 instructions that initialized those pseudos.
34 The constraint pass has biggest and most complicated code in LRA.
35 There are a lot of important details like:
36 o reuse of input reload pseudos to simplify reload pseudo
38 o some heuristics to choose insn alternative to improve the
42 The pass is mimicking former reload pass in alternative choosing
43 because the reload pass is oriented to current machine description
44 model. It might be changed if the machine description model is
47 There is special code for preventing all LRA and this pass cycling
50 On the first iteration of the pass we process every instruction and
51 choose an alternative for each one. On subsequent iterations we try
52 to avoid reprocessing instructions if we can be sure that the old
53 choice is still valid.
55 The inheritance/spilt pass is to transform code to achieve
56 ineheritance and live range splitting. It is done on backward
59 The inheritance optimization goal is to reuse values in hard
60 registers. There is analogous optimization in old reload pass. The
61 inheritance is achieved by following transformation:
63 reload_p1 <- p reload_p1 <- p
64 ... new_p <- reload_p1
66 reload_p2 <- p reload_p2 <- new_p
68 where p is spilled and not changed between the insns. Reload_p1 is
69 also called *original pseudo* and new_p is called *inheritance
72 The subsequent assignment pass will try to assign the same (or
73 another if it is not possible) hard register to new_p as to
74 reload_p1 or reload_p2.
76 If the assignment pass fails to assign a hard register to new_p,
77 this file will undo the inheritance and restore the original code.
78 This is because implementing the above sequence with a spilled
79 new_p would make the code much worse. The inheritance is done in
80 EBB scope. The above is just a simplified example to get an idea
81 of the inheritance as the inheritance is also done for non-reload
84 Splitting (transformation) is also done in EBB scope on the same
85 pass as the inheritance:
87 r <- ... or ... <- r r <- ... or ... <- r
88 ... s <- r (new insn -- save)
90 ... r <- s (new insn -- restore)
93 The *split pseudo* s is assigned to the hard register of the
94 original pseudo or hard register r.
97 o In EBBs with high register pressure for global pseudos (living
98 in at least 2 BBs) and assigned to hard registers when there
99 are more one reloads needing the hard registers;
100 o for pseudos needing save/restore code around calls.
102 If the split pseudo still has the same hard register as the
103 original pseudo after the subsequent assignment pass or the
104 original pseudo was split, the opposite transformation is done on
105 the same pass for undoing inheritance. */
111 #include "coretypes.h"
125 #include "addresses.h"
128 #include "rtl-error.h"
132 #include "print-rtl.h"
134 /* Value of LRA_CURR_RELOAD_NUM at the beginning of BB of the current
135 insn. Remember that LRA_CURR_RELOAD_NUM is the number of emitted
137 static int bb_reload_num
;
139 /* The current insn being processed and corresponding its single set
140 (NULL otherwise), its data (basic block, the insn data, the insn
141 static data, and the mode of each operand). */
142 static rtx_insn
*curr_insn
;
143 static rtx curr_insn_set
;
144 static basic_block curr_bb
;
145 static lra_insn_recog_data_t curr_id
;
146 static struct lra_static_insn_data
*curr_static_id
;
147 static machine_mode curr_operand_mode
[MAX_RECOG_OPERANDS
];
148 /* Mode of the register substituted by its equivalence with VOIDmode
149 (e.g. constant) and whose subreg is given operand of the current
150 insn. VOIDmode in all other cases. */
151 static machine_mode original_subreg_reg_mode
[MAX_RECOG_OPERANDS
];
155 /* Start numbers for new registers and insns at the current constraints
157 static int new_regno_start
;
158 static int new_insn_uid_start
;
160 /* If LOC is nonnull, strip any outer subreg from it. */
162 strip_subreg (rtx
*loc
)
164 return loc
&& GET_CODE (*loc
) == SUBREG
? &SUBREG_REG (*loc
) : loc
;
167 /* Return hard regno of REGNO or if it is was not assigned to a hard
168 register, use a hard register from its allocno class. */
170 get_try_hard_regno (int regno
)
173 enum reg_class rclass
;
175 if ((hard_regno
= regno
) >= FIRST_PSEUDO_REGISTER
)
176 hard_regno
= lra_get_regno_hard_regno (regno
);
179 rclass
= lra_get_allocno_class (regno
);
180 if (rclass
== NO_REGS
)
182 return ira_class_hard_regs
[rclass
][0];
185 /* Return final hard regno (plus offset) which will be after
186 elimination. We do this for matching constraints because the final
187 hard regno could have a different class. */
189 get_final_hard_regno (int hard_regno
, int offset
)
193 hard_regno
= lra_get_elimination_hard_regno (hard_regno
);
194 return hard_regno
+ offset
;
197 /* Return hard regno of X after removing subreg and making
198 elimination. If X is not a register or subreg of register, return
199 -1. For pseudo use its assignment. */
201 get_hard_regno (rtx x
)
204 int offset
, hard_regno
;
207 if (GET_CODE (x
) == SUBREG
)
208 reg
= SUBREG_REG (x
);
211 if ((hard_regno
= REGNO (reg
)) >= FIRST_PSEUDO_REGISTER
)
212 hard_regno
= lra_get_regno_hard_regno (hard_regno
);
216 if (GET_CODE (x
) == SUBREG
)
217 offset
+= subreg_regno_offset (hard_regno
, GET_MODE (reg
),
218 SUBREG_BYTE (x
), GET_MODE (x
));
219 return get_final_hard_regno (hard_regno
, offset
);
222 /* If REGNO is a hard register or has been allocated a hard register,
223 return the class of that register. If REGNO is a reload pseudo
224 created by the current constraints pass, return its allocno class.
225 Return NO_REGS otherwise. */
226 static enum reg_class
227 get_reg_class (int regno
)
231 if ((hard_regno
= regno
) >= FIRST_PSEUDO_REGISTER
)
232 hard_regno
= lra_get_regno_hard_regno (regno
);
235 hard_regno
= get_final_hard_regno (hard_regno
, 0);
236 return REGNO_REG_CLASS (hard_regno
);
238 if (regno
>= new_regno_start
)
239 return lra_get_allocno_class (regno
);
243 /* Return true if REG satisfies (or will satisfy) reg class constraint
244 CL. Use elimination first if REG is a hard register. If REG is a
245 reload pseudo created by this constraints pass, assume that it will
246 be allocated a hard register from its allocno class, but allow that
247 class to be narrowed to CL if it is currently a superset of CL.
249 If NEW_CLASS is nonnull, set *NEW_CLASS to the new allocno class of
250 REGNO (reg), or NO_REGS if no change in its class was needed. */
252 in_class_p (rtx reg
, enum reg_class cl
, enum reg_class
*new_class
)
254 enum reg_class rclass
, common_class
;
255 machine_mode reg_mode
;
256 int class_size
, hard_regno
, nregs
, i
, j
;
257 int regno
= REGNO (reg
);
259 if (new_class
!= NULL
)
260 *new_class
= NO_REGS
;
261 if (regno
< FIRST_PSEUDO_REGISTER
)
264 rtx
*final_loc
= &final_reg
;
266 lra_eliminate_reg_if_possible (final_loc
);
267 return TEST_HARD_REG_BIT (reg_class_contents
[cl
], REGNO (*final_loc
));
269 reg_mode
= GET_MODE (reg
);
270 rclass
= get_reg_class (regno
);
271 if (regno
< new_regno_start
272 /* Do not allow the constraints for reload instructions to
273 influence the classes of new pseudos. These reloads are
274 typically moves that have many alternatives, and restricting
275 reload pseudos for one alternative may lead to situations
276 where other reload pseudos are no longer allocatable. */
277 || (INSN_UID (curr_insn
) >= new_insn_uid_start
278 && curr_insn_set
!= NULL
279 && ((OBJECT_P (SET_SRC (curr_insn_set
))
280 && ! CONSTANT_P (SET_SRC (curr_insn_set
)))
281 || (GET_CODE (SET_SRC (curr_insn_set
)) == SUBREG
282 && OBJECT_P (SUBREG_REG (SET_SRC (curr_insn_set
)))
283 && ! CONSTANT_P (SUBREG_REG (SET_SRC (curr_insn_set
)))))))
284 /* When we don't know what class will be used finally for reload
285 pseudos, we use ALL_REGS. */
286 return ((regno
>= new_regno_start
&& rclass
== ALL_REGS
)
287 || (rclass
!= NO_REGS
&& ira_class_subset_p
[rclass
][cl
]
288 && ! hard_reg_set_subset_p (reg_class_contents
[cl
],
289 lra_no_alloc_regs
)));
292 common_class
= ira_reg_class_subset
[rclass
][cl
];
293 if (new_class
!= NULL
)
294 *new_class
= common_class
;
295 if (hard_reg_set_subset_p (reg_class_contents
[common_class
],
298 /* Check that there are enough allocatable regs. */
299 class_size
= ira_class_hard_regs_num
[common_class
];
300 for (i
= 0; i
< class_size
; i
++)
302 hard_regno
= ira_class_hard_regs
[common_class
][i
];
303 nregs
= hard_regno_nregs
[hard_regno
][reg_mode
];
306 for (j
= 0; j
< nregs
; j
++)
307 if (TEST_HARD_REG_BIT (lra_no_alloc_regs
, hard_regno
+ j
)
308 || ! TEST_HARD_REG_BIT (reg_class_contents
[common_class
],
318 /* Return true if REGNO satisfies a memory constraint. */
322 return get_reg_class (regno
) == NO_REGS
;
325 /* Return 1 if ADDR is a valid memory address for mode MODE in address
326 space AS, and check that each pseudo has the proper kind of hard
329 valid_address_p (machine_mode mode ATTRIBUTE_UNUSED
,
330 rtx addr
, addr_space_t as
)
332 #ifdef GO_IF_LEGITIMATE_ADDRESS
333 lra_assert (ADDR_SPACE_GENERIC_P (as
));
334 GO_IF_LEGITIMATE_ADDRESS (mode
, addr
, win
);
340 return targetm
.addr_space
.legitimate_address_p (mode
, addr
, 0, as
);
345 /* Temporarily eliminates registers in an address (for the lifetime of
347 class address_eliminator
{
349 address_eliminator (struct address_info
*ad
);
350 ~address_eliminator ();
353 struct address_info
*m_ad
;
361 address_eliminator::address_eliminator (struct address_info
*ad
)
363 m_base_loc (strip_subreg (ad
->base_term
)),
364 m_base_reg (NULL_RTX
),
365 m_index_loc (strip_subreg (ad
->index_term
)),
366 m_index_reg (NULL_RTX
)
368 if (m_base_loc
!= NULL
)
370 m_base_reg
= *m_base_loc
;
371 lra_eliminate_reg_if_possible (m_base_loc
);
372 if (m_ad
->base_term2
!= NULL
)
373 *m_ad
->base_term2
= *m_ad
->base_term
;
375 if (m_index_loc
!= NULL
)
377 m_index_reg
= *m_index_loc
;
378 lra_eliminate_reg_if_possible (m_index_loc
);
382 address_eliminator::~address_eliminator ()
384 if (m_base_loc
&& *m_base_loc
!= m_base_reg
)
386 *m_base_loc
= m_base_reg
;
387 if (m_ad
->base_term2
!= NULL
)
388 *m_ad
->base_term2
= *m_ad
->base_term
;
390 if (m_index_loc
&& *m_index_loc
!= m_index_reg
)
391 *m_index_loc
= m_index_reg
;
394 /* Return true if the eliminated form of AD is a legitimate target address. */
396 valid_address_p (struct address_info
*ad
)
398 address_eliminator
eliminator (ad
);
399 return valid_address_p (ad
->mode
, *ad
->outer
, ad
->as
);
402 /* Return true if the eliminated form of memory reference OP satisfies
403 extra (special) memory constraint CONSTRAINT. */
405 satisfies_memory_constraint_p (rtx op
, enum constraint_num constraint
)
407 struct address_info ad
;
409 decompose_mem_address (&ad
, op
);
410 address_eliminator
eliminator (&ad
);
411 return constraint_satisfied_p (op
, constraint
);
414 /* Return true if the eliminated form of address AD satisfies extra
415 address constraint CONSTRAINT. */
417 satisfies_address_constraint_p (struct address_info
*ad
,
418 enum constraint_num constraint
)
420 address_eliminator
eliminator (ad
);
421 return constraint_satisfied_p (*ad
->outer
, constraint
);
424 /* Return true if the eliminated form of address OP satisfies extra
425 address constraint CONSTRAINT. */
427 satisfies_address_constraint_p (rtx op
, enum constraint_num constraint
)
429 struct address_info ad
;
431 decompose_lea_address (&ad
, &op
);
432 return satisfies_address_constraint_p (&ad
, constraint
);
435 /* Initiate equivalences for LRA. As we keep original equivalences
436 before any elimination, we need to make copies otherwise any change
437 in insns might change the equivalences. */
439 lra_init_equiv (void)
441 ira_expand_reg_equiv ();
442 for (int i
= FIRST_PSEUDO_REGISTER
; i
< max_reg_num (); i
++)
446 if ((res
= ira_reg_equiv
[i
].memory
) != NULL_RTX
)
447 ira_reg_equiv
[i
].memory
= copy_rtx (res
);
448 if ((res
= ira_reg_equiv
[i
].invariant
) != NULL_RTX
)
449 ira_reg_equiv
[i
].invariant
= copy_rtx (res
);
453 static rtx
loc_equivalence_callback (rtx
, const_rtx
, void *);
455 /* Update equivalence for REGNO. We need to this as the equivalence
456 might contain other pseudos which are changed by their
459 update_equiv (int regno
)
463 if ((x
= ira_reg_equiv
[regno
].memory
) != NULL_RTX
)
464 ira_reg_equiv
[regno
].memory
465 = simplify_replace_fn_rtx (x
, NULL_RTX
, loc_equivalence_callback
,
467 if ((x
= ira_reg_equiv
[regno
].invariant
) != NULL_RTX
)
468 ira_reg_equiv
[regno
].invariant
469 = simplify_replace_fn_rtx (x
, NULL_RTX
, loc_equivalence_callback
,
473 /* If we have decided to substitute X with another value, return that
474 value, otherwise return X. */
481 if (! REG_P (x
) || (regno
= REGNO (x
)) < FIRST_PSEUDO_REGISTER
482 || ! ira_reg_equiv
[regno
].defined_p
483 || ! ira_reg_equiv
[regno
].profitable_p
484 || lra_get_regno_hard_regno (regno
) >= 0)
486 if ((res
= ira_reg_equiv
[regno
].memory
) != NULL_RTX
)
488 if (targetm
.cannot_substitute_mem_equiv_p (res
))
492 if ((res
= ira_reg_equiv
[regno
].constant
) != NULL_RTX
)
494 if ((res
= ira_reg_equiv
[regno
].invariant
) != NULL_RTX
)
499 /* If we have decided to substitute X with the equivalent value,
500 return that value after elimination for INSN, otherwise return
503 get_equiv_with_elimination (rtx x
, rtx_insn
*insn
)
505 rtx res
= get_equiv (x
);
507 if (x
== res
|| CONSTANT_P (res
))
509 return lra_eliminate_regs_1 (insn
, res
, GET_MODE (res
),
510 false, false, 0, true);
513 /* Set up curr_operand_mode. */
515 init_curr_operand_mode (void)
517 int nop
= curr_static_id
->n_operands
;
518 for (int i
= 0; i
< nop
; i
++)
520 machine_mode mode
= GET_MODE (*curr_id
->operand_loc
[i
]);
521 if (mode
== VOIDmode
)
523 /* The .md mode for address operands is the mode of the
524 addressed value rather than the mode of the address itself. */
525 if (curr_id
->icode
>= 0 && curr_static_id
->operand
[i
].is_address
)
528 mode
= curr_static_id
->operand
[i
].mode
;
530 curr_operand_mode
[i
] = mode
;
536 /* The page contains code to reuse input reloads. */
538 /* Structure describes input reload of the current insns. */
541 /* Reloaded value. */
543 /* Reload pseudo used. */
547 /* The number of elements in the following array. */
548 static int curr_insn_input_reloads_num
;
549 /* Array containing info about input reloads. It is used to find the
550 same input reload and reuse the reload pseudo in this case. */
551 static struct input_reload curr_insn_input_reloads
[LRA_MAX_INSN_RELOADS
];
553 /* Initiate data concerning reuse of input reloads for the current
556 init_curr_insn_input_reloads (void)
558 curr_insn_input_reloads_num
= 0;
561 /* Create a new pseudo using MODE, RCLASS, ORIGINAL or reuse already
562 created input reload pseudo (only if TYPE is not OP_OUT). Don't
563 reuse pseudo if IN_SUBREG_P is true and the reused pseudo should be
564 wrapped up in SUBREG. The result pseudo is returned through
565 RESULT_REG. Return TRUE if we created a new pseudo, FALSE if we
566 reused the already created input reload pseudo. Use TITLE to
567 describe new registers for debug purposes. */
569 get_reload_reg (enum op_type type
, machine_mode mode
, rtx original
,
570 enum reg_class rclass
, bool in_subreg_p
,
571 const char *title
, rtx
*result_reg
)
574 enum reg_class new_class
;
579 = lra_create_new_reg_with_unique_value (mode
, original
, rclass
, title
);
582 /* Prevent reuse value of expression with side effects,
583 e.g. volatile memory. */
584 if (! side_effects_p (original
))
585 for (i
= 0; i
< curr_insn_input_reloads_num
; i
++)
586 if (rtx_equal_p (curr_insn_input_reloads
[i
].input
, original
)
587 && in_class_p (curr_insn_input_reloads
[i
].reg
, rclass
, &new_class
))
589 rtx reg
= curr_insn_input_reloads
[i
].reg
;
591 /* If input is equal to original and both are VOIDmode,
592 GET_MODE (reg) might be still different from mode.
593 Ensure we don't return *result_reg with wrong mode. */
594 if (GET_MODE (reg
) != mode
)
598 if (GET_MODE_SIZE (GET_MODE (reg
)) < GET_MODE_SIZE (mode
))
600 reg
= lowpart_subreg (mode
, reg
, GET_MODE (reg
));
601 if (reg
== NULL_RTX
|| GET_CODE (reg
) != SUBREG
)
605 if (lra_dump_file
!= NULL
)
607 fprintf (lra_dump_file
, " Reuse r%d for reload ", regno
);
608 dump_value_slim (lra_dump_file
, original
, 1);
610 if (new_class
!= lra_get_allocno_class (regno
))
611 lra_change_class (regno
, new_class
, ", change to", false);
612 if (lra_dump_file
!= NULL
)
613 fprintf (lra_dump_file
, "\n");
616 *result_reg
= lra_create_new_reg (mode
, original
, rclass
, title
);
617 lra_assert (curr_insn_input_reloads_num
< LRA_MAX_INSN_RELOADS
);
618 curr_insn_input_reloads
[curr_insn_input_reloads_num
].input
= original
;
619 curr_insn_input_reloads
[curr_insn_input_reloads_num
++].reg
= *result_reg
;
625 /* The page contains code to extract memory address parts. */
627 /* Wrapper around REGNO_OK_FOR_INDEX_P, to allow pseudos. */
629 ok_for_index_p_nonstrict (rtx reg
)
631 unsigned regno
= REGNO (reg
);
633 return regno
>= FIRST_PSEUDO_REGISTER
|| REGNO_OK_FOR_INDEX_P (regno
);
636 /* A version of regno_ok_for_base_p for use here, when all pseudos
637 should count as OK. Arguments as for regno_ok_for_base_p. */
639 ok_for_base_p_nonstrict (rtx reg
, machine_mode mode
, addr_space_t as
,
640 enum rtx_code outer_code
, enum rtx_code index_code
)
642 unsigned regno
= REGNO (reg
);
644 if (regno
>= FIRST_PSEUDO_REGISTER
)
646 return ok_for_base_p_1 (regno
, mode
, as
, outer_code
, index_code
);
651 /* The page contains major code to choose the current insn alternative
652 and generate reloads for it. */
654 /* Return the offset from REGNO of the least significant register
657 This function is used to tell whether two registers satisfy
658 a matching constraint. (reg:MODE1 REGNO1) matches (reg:MODE2 REGNO2) if:
660 REGNO1 + lra_constraint_offset (REGNO1, MODE1)
661 == REGNO2 + lra_constraint_offset (REGNO2, MODE2) */
663 lra_constraint_offset (int regno
, machine_mode mode
)
665 lra_assert (regno
< FIRST_PSEUDO_REGISTER
);
666 if (WORDS_BIG_ENDIAN
&& GET_MODE_SIZE (mode
) > UNITS_PER_WORD
667 && SCALAR_INT_MODE_P (mode
))
668 return hard_regno_nregs
[regno
][mode
] - 1;
672 /* Like rtx_equal_p except that it allows a REG and a SUBREG to match
673 if they are the same hard reg, and has special hacks for
674 auto-increment and auto-decrement. This is specifically intended for
675 process_alt_operands to use in determining whether two operands
676 match. X is the operand whose number is the lower of the two.
678 It is supposed that X is the output operand and Y is the input
679 operand. Y_HARD_REGNO is the final hard regno of register Y or
680 register in subreg Y as we know it now. Otherwise, it is a
683 operands_match_p (rtx x
, rtx y
, int y_hard_regno
)
686 RTX_CODE code
= GET_CODE (x
);
691 if ((code
== REG
|| (code
== SUBREG
&& REG_P (SUBREG_REG (x
))))
692 && (REG_P (y
) || (GET_CODE (y
) == SUBREG
&& REG_P (SUBREG_REG (y
)))))
696 i
= get_hard_regno (x
);
700 if ((j
= y_hard_regno
) < 0)
703 i
+= lra_constraint_offset (i
, GET_MODE (x
));
704 j
+= lra_constraint_offset (j
, GET_MODE (y
));
709 /* If two operands must match, because they are really a single
710 operand of an assembler insn, then two post-increments are invalid
711 because the assembler insn would increment only once. On the
712 other hand, a post-increment matches ordinary indexing if the
713 post-increment is the output operand. */
714 if (code
== POST_DEC
|| code
== POST_INC
|| code
== POST_MODIFY
)
715 return operands_match_p (XEXP (x
, 0), y
, y_hard_regno
);
717 /* Two pre-increments are invalid because the assembler insn would
718 increment only once. On the other hand, a pre-increment matches
719 ordinary indexing if the pre-increment is the input operand. */
720 if (GET_CODE (y
) == PRE_DEC
|| GET_CODE (y
) == PRE_INC
721 || GET_CODE (y
) == PRE_MODIFY
)
722 return operands_match_p (x
, XEXP (y
, 0), -1);
726 if (code
== REG
&& REG_P (y
))
727 return REGNO (x
) == REGNO (y
);
729 if (code
== REG
&& GET_CODE (y
) == SUBREG
&& REG_P (SUBREG_REG (y
))
730 && x
== SUBREG_REG (y
))
732 if (GET_CODE (y
) == REG
&& code
== SUBREG
&& REG_P (SUBREG_REG (x
))
733 && SUBREG_REG (x
) == y
)
736 /* Now we have disposed of all the cases in which different rtx
738 if (code
!= GET_CODE (y
))
741 /* (MULT:SI x y) and (MULT:HI x y) are NOT equivalent. */
742 if (GET_MODE (x
) != GET_MODE (y
))
751 return LABEL_REF_LABEL (x
) == LABEL_REF_LABEL (y
);
753 return XSTR (x
, 0) == XSTR (y
, 0);
759 /* Compare the elements. If any pair of corresponding elements fail
760 to match, return false for the whole things. */
762 fmt
= GET_RTX_FORMAT (code
);
763 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
769 if (XWINT (x
, i
) != XWINT (y
, i
))
774 if (XINT (x
, i
) != XINT (y
, i
))
779 val
= operands_match_p (XEXP (x
, i
), XEXP (y
, i
), -1);
788 if (XVECLEN (x
, i
) != XVECLEN (y
, i
))
790 for (j
= XVECLEN (x
, i
) - 1; j
>= 0; --j
)
792 val
= operands_match_p (XVECEXP (x
, i
, j
), XVECEXP (y
, i
, j
), -1);
798 /* It is believed that rtx's at this level will never
799 contain anything but integers and other rtx's, except for
800 within LABEL_REFs and SYMBOL_REFs. */
808 /* True if X is a constant that can be forced into the constant pool.
809 MODE is the mode of the operand, or VOIDmode if not known. */
810 #define CONST_POOL_OK_P(MODE, X) \
811 ((MODE) != VOIDmode \
813 && GET_CODE (X) != HIGH \
814 && !targetm.cannot_force_const_mem (MODE, X))
816 /* True if C is a non-empty register class that has too few registers
817 to be safely used as a reload target class. */
818 #define SMALL_REGISTER_CLASS_P(C) \
819 (ira_class_hard_regs_num [(C)] == 1 \
820 || (ira_class_hard_regs_num [(C)] >= 1 \
821 && targetm.class_likely_spilled_p (C)))
823 /* If REG is a reload pseudo, try to make its class satisfying CL. */
825 narrow_reload_pseudo_class (rtx reg
, enum reg_class cl
)
827 enum reg_class rclass
;
829 /* Do not make more accurate class from reloads generated. They are
830 mostly moves with a lot of constraints. Making more accurate
831 class may results in very narrow class and impossibility of find
832 registers for several reloads of one insn. */
833 if (INSN_UID (curr_insn
) >= new_insn_uid_start
)
835 if (GET_CODE (reg
) == SUBREG
)
836 reg
= SUBREG_REG (reg
);
837 if (! REG_P (reg
) || (int) REGNO (reg
) < new_regno_start
)
839 if (in_class_p (reg
, cl
, &rclass
) && rclass
!= cl
)
840 lra_change_class (REGNO (reg
), rclass
, " Change to", true);
843 /* Searches X for any reference to a reg with the same value as REGNO,
844 returning the rtx of the reference found if any. Otherwise,
847 regno_val_use_in (unsigned int regno
, rtx x
)
853 if (REG_P (x
) && lra_reg_info
[REGNO (x
)].val
== lra_reg_info
[regno
].val
)
856 fmt
= GET_RTX_FORMAT (GET_CODE (x
));
857 for (i
= GET_RTX_LENGTH (GET_CODE (x
)) - 1; i
>= 0; i
--)
861 if ((tem
= regno_val_use_in (regno
, XEXP (x
, i
))))
864 else if (fmt
[i
] == 'E')
865 for (j
= XVECLEN (x
, i
) - 1; j
>= 0; j
--)
866 if ((tem
= regno_val_use_in (regno
, XVECEXP (x
, i
, j
))))
873 /* Generate reloads for matching OUT and INS (array of input operand
874 numbers with end marker -1) with reg class GOAL_CLASS, considering
875 output operands OUTS (similar array to INS) needing to be in different
876 registers. Add input and output reloads correspondingly to the lists
877 *BEFORE and *AFTER. OUT might be negative. In this case we generate
878 input reloads for matched input operands INS. EARLY_CLOBBER_P is a flag
879 that the output operand is early clobbered for chosen alternative. */
881 match_reload (signed char out
, signed char *ins
, signed char *outs
,
882 enum reg_class goal_class
, rtx_insn
**before
,
883 rtx_insn
**after
, bool early_clobber_p
)
887 rtx new_in_reg
, new_out_reg
, reg
;
888 machine_mode inmode
, outmode
;
889 rtx in_rtx
= *curr_id
->operand_loc
[ins
[0]];
890 rtx out_rtx
= out
< 0 ? in_rtx
: *curr_id
->operand_loc
[out
];
892 inmode
= curr_operand_mode
[ins
[0]];
893 outmode
= out
< 0 ? inmode
: curr_operand_mode
[out
];
894 push_to_sequence (*before
);
895 if (inmode
!= outmode
)
897 if (GET_MODE_SIZE (inmode
) > GET_MODE_SIZE (outmode
))
900 = lra_create_new_reg_with_unique_value (inmode
, in_rtx
,
902 if (SCALAR_INT_MODE_P (inmode
))
903 new_out_reg
= gen_lowpart_SUBREG (outmode
, reg
);
905 new_out_reg
= gen_rtx_SUBREG (outmode
, reg
, 0);
906 LRA_SUBREG_P (new_out_reg
) = 1;
907 /* If the input reg is dying here, we can use the same hard
908 register for REG and IN_RTX. We do it only for original
909 pseudos as reload pseudos can die although original
910 pseudos still live where reload pseudos dies. */
911 if (REG_P (in_rtx
) && (int) REGNO (in_rtx
) < lra_new_regno_start
912 && find_regno_note (curr_insn
, REG_DEAD
, REGNO (in_rtx
)))
913 lra_assign_reg_val (REGNO (in_rtx
), REGNO (reg
));
918 = lra_create_new_reg_with_unique_value (outmode
, out_rtx
,
920 if (SCALAR_INT_MODE_P (outmode
))
921 new_in_reg
= gen_lowpart_SUBREG (inmode
, reg
);
923 new_in_reg
= gen_rtx_SUBREG (inmode
, reg
, 0);
924 /* NEW_IN_REG is non-paradoxical subreg. We don't want
925 NEW_OUT_REG living above. We add clobber clause for
926 this. This is just a temporary clobber. We can remove
927 it at the end of LRA work. */
928 rtx_insn
*clobber
= emit_clobber (new_out_reg
);
929 LRA_TEMP_CLOBBER_P (PATTERN (clobber
)) = 1;
930 LRA_SUBREG_P (new_in_reg
) = 1;
931 if (GET_CODE (in_rtx
) == SUBREG
)
933 rtx subreg_reg
= SUBREG_REG (in_rtx
);
935 /* If SUBREG_REG is dying here and sub-registers IN_RTX
936 and NEW_IN_REG are similar, we can use the same hard
937 register for REG and SUBREG_REG. */
938 if (REG_P (subreg_reg
)
939 && (int) REGNO (subreg_reg
) < lra_new_regno_start
940 && GET_MODE (subreg_reg
) == outmode
941 && SUBREG_BYTE (in_rtx
) == SUBREG_BYTE (new_in_reg
)
942 && find_regno_note (curr_insn
, REG_DEAD
, REGNO (subreg_reg
)))
943 lra_assign_reg_val (REGNO (subreg_reg
), REGNO (reg
));
949 /* Pseudos have values -- see comments for lra_reg_info.
950 Different pseudos with the same value do not conflict even if
951 they live in the same place. When we create a pseudo we
952 assign value of original pseudo (if any) from which we
953 created the new pseudo. If we create the pseudo from the
954 input pseudo, the new pseudo will have no conflict with the
955 input pseudo which is wrong when the input pseudo lives after
956 the insn and as the new pseudo value is changed by the insn
957 output. Therefore we create the new pseudo from the output
958 except the case when we have single matched dying input
961 We cannot reuse the current output register because we might
962 have a situation like "a <- a op b", where the constraints
963 force the second input operand ("b") to match the output
964 operand ("a"). "b" must then be copied into a new register
965 so that it doesn't clobber the current value of "a".
967 We can not use the same value if the output pseudo is
968 early clobbered or the input pseudo is mentioned in the
969 output, e.g. as an address part in memory, because
970 output reload will actually extend the pseudo liveness.
971 We don't care about eliminable hard regs here as we are
972 interesting only in pseudos. */
974 /* Matching input's register value is the same as one of the other
975 output operand. Output operands in a parallel insn must be in
976 different registers. */
977 out_conflict
= false;
980 for (i
= 0; outs
[i
] >= 0; i
++)
982 rtx other_out_rtx
= *curr_id
->operand_loc
[outs
[i
]];
983 if (REG_P (other_out_rtx
)
984 && (regno_val_use_in (REGNO (in_rtx
), other_out_rtx
)
993 new_in_reg
= new_out_reg
994 = (! early_clobber_p
&& ins
[1] < 0 && REG_P (in_rtx
)
995 && (int) REGNO (in_rtx
) < lra_new_regno_start
996 && find_regno_note (curr_insn
, REG_DEAD
, REGNO (in_rtx
))
998 || regno_val_use_in (REGNO (in_rtx
), out_rtx
) == NULL_RTX
)
1000 ? lra_create_new_reg (inmode
, in_rtx
, goal_class
, "")
1001 : lra_create_new_reg_with_unique_value (outmode
, out_rtx
,
1004 /* In operand can be got from transformations before processing insn
1005 constraints. One example of such transformations is subreg
1006 reloading (see function simplify_operand_subreg). The new
1007 pseudos created by the transformations might have inaccurate
1008 class (ALL_REGS) and we should make their classes more
1010 narrow_reload_pseudo_class (in_rtx
, goal_class
);
1011 lra_emit_move (copy_rtx (new_in_reg
), in_rtx
);
1012 *before
= get_insns ();
1014 for (i
= 0; (in
= ins
[i
]) >= 0; i
++)
1017 (GET_MODE (*curr_id
->operand_loc
[in
]) == VOIDmode
1018 || GET_MODE (new_in_reg
) == GET_MODE (*curr_id
->operand_loc
[in
]));
1019 *curr_id
->operand_loc
[in
] = new_in_reg
;
1021 lra_update_dups (curr_id
, ins
);
1024 /* See a comment for the input operand above. */
1025 narrow_reload_pseudo_class (out_rtx
, goal_class
);
1026 if (find_reg_note (curr_insn
, REG_UNUSED
, out_rtx
) == NULL_RTX
)
1029 lra_emit_move (out_rtx
, copy_rtx (new_out_reg
));
1031 *after
= get_insns ();
1034 *curr_id
->operand_loc
[out
] = new_out_reg
;
1035 lra_update_dup (curr_id
, out
);
1038 /* Return register class which is union of all reg classes in insn
1039 constraint alternative string starting with P. */
1040 static enum reg_class
1041 reg_class_from_constraints (const char *p
)
1044 enum reg_class op_class
= NO_REGS
;
1047 switch ((c
= *p
, len
= CONSTRAINT_LEN (c
, p
)), c
)
1054 op_class
= reg_class_subunion
[op_class
][GENERAL_REGS
];
1058 enum constraint_num cn
= lookup_constraint (p
);
1059 enum reg_class cl
= reg_class_for_constraint (cn
);
1062 if (insn_extra_address_constraint (cn
))
1064 = (reg_class_subunion
1065 [op_class
][base_reg_class (VOIDmode
, ADDR_SPACE_GENERIC
,
1066 ADDRESS
, SCRATCH
)]);
1070 op_class
= reg_class_subunion
[op_class
][cl
];
1073 while ((p
+= len
), c
);
1077 /* If OP is a register, return the class of the register as per
1078 get_reg_class, otherwise return NO_REGS. */
1079 static inline enum reg_class
1080 get_op_class (rtx op
)
1082 return REG_P (op
) ? get_reg_class (REGNO (op
)) : NO_REGS
;
1085 /* Return generated insn mem_pseudo:=val if TO_P or val:=mem_pseudo
1086 otherwise. If modes of MEM_PSEUDO and VAL are different, use
1087 SUBREG for VAL to make them equal. */
1089 emit_spill_move (bool to_p
, rtx mem_pseudo
, rtx val
)
1091 if (GET_MODE (mem_pseudo
) != GET_MODE (val
))
1093 /* Usually size of mem_pseudo is greater than val size but in
1094 rare cases it can be less as it can be defined by target
1095 dependent macro HARD_REGNO_CALLER_SAVE_MODE. */
1098 val
= gen_rtx_SUBREG (GET_MODE (mem_pseudo
),
1099 GET_CODE (val
) == SUBREG
? SUBREG_REG (val
) : val
,
1101 LRA_SUBREG_P (val
) = 1;
1105 mem_pseudo
= gen_lowpart_SUBREG (GET_MODE (val
), mem_pseudo
);
1106 LRA_SUBREG_P (mem_pseudo
) = 1;
1109 return to_p
? gen_move_insn (mem_pseudo
, val
)
1110 : gen_move_insn (val
, mem_pseudo
);
1113 /* Process a special case insn (register move), return true if we
1114 don't need to process it anymore. INSN should be a single set
1115 insn. Set up that RTL was changed through CHANGE_P and macro
1116 SECONDARY_MEMORY_NEEDED says to use secondary memory through
1119 check_and_process_move (bool *change_p
, bool *sec_mem_p ATTRIBUTE_UNUSED
)
1122 rtx dest
, src
, dreg
, sreg
, new_reg
, scratch_reg
;
1124 enum reg_class dclass
, sclass
, secondary_class
;
1125 secondary_reload_info sri
;
1127 lra_assert (curr_insn_set
!= NULL_RTX
);
1128 dreg
= dest
= SET_DEST (curr_insn_set
);
1129 sreg
= src
= SET_SRC (curr_insn_set
);
1130 if (GET_CODE (dest
) == SUBREG
)
1131 dreg
= SUBREG_REG (dest
);
1132 if (GET_CODE (src
) == SUBREG
)
1133 sreg
= SUBREG_REG (src
);
1134 if (! (REG_P (dreg
) || MEM_P (dreg
)) || ! (REG_P (sreg
) || MEM_P (sreg
)))
1136 sclass
= dclass
= NO_REGS
;
1138 dclass
= get_reg_class (REGNO (dreg
));
1139 if (dclass
== ALL_REGS
)
1140 /* ALL_REGS is used for new pseudos created by transformations
1141 like reload of SUBREG_REG (see function
1142 simplify_operand_subreg). We don't know their class yet. We
1143 should figure out the class from processing the insn
1144 constraints not in this fast path function. Even if ALL_REGS
1145 were a right class for the pseudo, secondary_... hooks usually
1146 are not define for ALL_REGS. */
1149 sclass
= get_reg_class (REGNO (sreg
));
1150 if (sclass
== ALL_REGS
)
1151 /* See comments above. */
1153 if (sclass
== NO_REGS
&& dclass
== NO_REGS
)
1155 #ifdef SECONDARY_MEMORY_NEEDED
1156 if (SECONDARY_MEMORY_NEEDED (sclass
, dclass
, GET_MODE (src
))
1157 #ifdef SECONDARY_MEMORY_NEEDED_MODE
1158 && ((sclass
!= NO_REGS
&& dclass
!= NO_REGS
)
1159 || GET_MODE (src
) != SECONDARY_MEMORY_NEEDED_MODE (GET_MODE (src
)))
1167 if (! REG_P (dreg
) || ! REG_P (sreg
))
1169 sri
.prev_sri
= NULL
;
1170 sri
.icode
= CODE_FOR_nothing
;
1172 secondary_class
= NO_REGS
;
1173 /* Set up hard register for a reload pseudo for hook
1174 secondary_reload because some targets just ignore unassigned
1175 pseudos in the hook. */
1176 if (dclass
!= NO_REGS
&& lra_get_regno_hard_regno (REGNO (dreg
)) < 0)
1178 dregno
= REGNO (dreg
);
1179 reg_renumber
[dregno
] = ira_class_hard_regs
[dclass
][0];
1183 if (sclass
!= NO_REGS
&& lra_get_regno_hard_regno (REGNO (sreg
)) < 0)
1185 sregno
= REGNO (sreg
);
1186 reg_renumber
[sregno
] = ira_class_hard_regs
[sclass
][0];
1190 if (sclass
!= NO_REGS
)
1192 = (enum reg_class
) targetm
.secondary_reload (false, dest
,
1193 (reg_class_t
) sclass
,
1194 GET_MODE (src
), &sri
);
1195 if (sclass
== NO_REGS
1196 || ((secondary_class
!= NO_REGS
|| sri
.icode
!= CODE_FOR_nothing
)
1197 && dclass
!= NO_REGS
))
1199 enum reg_class old_sclass
= secondary_class
;
1200 secondary_reload_info old_sri
= sri
;
1202 sri
.prev_sri
= NULL
;
1203 sri
.icode
= CODE_FOR_nothing
;
1206 = (enum reg_class
) targetm
.secondary_reload (true, src
,
1207 (reg_class_t
) dclass
,
1208 GET_MODE (src
), &sri
);
1209 /* Check the target hook consistency. */
1211 ((secondary_class
== NO_REGS
&& sri
.icode
== CODE_FOR_nothing
)
1212 || (old_sclass
== NO_REGS
&& old_sri
.icode
== CODE_FOR_nothing
)
1213 || (secondary_class
== old_sclass
&& sri
.icode
== old_sri
.icode
));
1216 reg_renumber
[sregno
] = -1;
1218 reg_renumber
[dregno
] = -1;
1219 if (secondary_class
== NO_REGS
&& sri
.icode
== CODE_FOR_nothing
)
1223 if (secondary_class
!= NO_REGS
)
1224 new_reg
= lra_create_new_reg_with_unique_value (GET_MODE (src
), NULL_RTX
,
1228 if (sri
.icode
== CODE_FOR_nothing
)
1229 lra_emit_move (new_reg
, src
);
1232 enum reg_class scratch_class
;
1234 scratch_class
= (reg_class_from_constraints
1235 (insn_data
[sri
.icode
].operand
[2].constraint
));
1236 scratch_reg
= (lra_create_new_reg_with_unique_value
1237 (insn_data
[sri
.icode
].operand
[2].mode
, NULL_RTX
,
1238 scratch_class
, "scratch"));
1239 emit_insn (GEN_FCN (sri
.icode
) (new_reg
!= NULL_RTX
? new_reg
: dest
,
1242 before
= get_insns ();
1244 lra_process_new_insns (curr_insn
, before
, NULL
, "Inserting the move");
1245 if (new_reg
!= NULL_RTX
)
1246 SET_SRC (curr_insn_set
) = new_reg
;
1249 if (lra_dump_file
!= NULL
)
1251 fprintf (lra_dump_file
, "Deleting move %u\n", INSN_UID (curr_insn
));
1252 dump_insn_slim (lra_dump_file
, curr_insn
);
1254 lra_set_insn_deleted (curr_insn
);
1260 /* The following data describe the result of process_alt_operands.
1261 The data are used in curr_insn_transform to generate reloads. */
1263 /* The chosen reg classes which should be used for the corresponding
1265 static enum reg_class goal_alt
[MAX_RECOG_OPERANDS
];
1266 /* True if the operand should be the same as another operand and that
1267 other operand does not need a reload. */
1268 static bool goal_alt_match_win
[MAX_RECOG_OPERANDS
];
1269 /* True if the operand does not need a reload. */
1270 static bool goal_alt_win
[MAX_RECOG_OPERANDS
];
1271 /* True if the operand can be offsetable memory. */
1272 static bool goal_alt_offmemok
[MAX_RECOG_OPERANDS
];
1273 /* The number of an operand to which given operand can be matched to. */
1274 static int goal_alt_matches
[MAX_RECOG_OPERANDS
];
1275 /* The number of elements in the following array. */
1276 static int goal_alt_dont_inherit_ops_num
;
1277 /* Numbers of operands whose reload pseudos should not be inherited. */
1278 static int goal_alt_dont_inherit_ops
[MAX_RECOG_OPERANDS
];
1279 /* True if the insn commutative operands should be swapped. */
1280 static bool goal_alt_swapped
;
1281 /* The chosen insn alternative. */
1282 static int goal_alt_number
;
1284 /* True if the corresponding operand is the result of an equivalence
1286 static bool equiv_substition_p
[MAX_RECOG_OPERANDS
];
1288 /* The following five variables are used to choose the best insn
1289 alternative. They reflect final characteristics of the best
1292 /* Number of necessary reloads and overall cost reflecting the
1293 previous value and other unpleasantness of the best alternative. */
1294 static int best_losers
, best_overall
;
1295 /* Overall number hard registers used for reloads. For example, on
1296 some targets we need 2 general registers to reload DFmode and only
1297 one floating point register. */
1298 static int best_reload_nregs
;
1299 /* Overall number reflecting distances of previous reloading the same
1300 value. The distances are counted from the current BB start. It is
1301 used to improve inheritance chances. */
1302 static int best_reload_sum
;
1304 /* True if the current insn should have no correspondingly input or
1306 static bool no_input_reloads_p
, no_output_reloads_p
;
1308 /* True if we swapped the commutative operands in the current
1310 static int curr_swapped
;
1312 /* if CHECK_ONLY_P is false, arrange for address element *LOC to be a
1313 register of class CL. Add any input reloads to list BEFORE. AFTER
1314 is nonnull if *LOC is an automodified value; handle that case by
1315 adding the required output reloads to list AFTER. Return true if
1316 the RTL was changed.
1318 if CHECK_ONLY_P is true, check that the *LOC is a correct address
1319 register. Return false if the address register is correct. */
1321 process_addr_reg (rtx
*loc
, bool check_only_p
, rtx_insn
**before
, rtx_insn
**after
,
1325 enum reg_class rclass
, new_class
;
1329 bool subreg_p
, before_p
= false;
1331 subreg_p
= GET_CODE (*loc
) == SUBREG
;
1334 reg
= SUBREG_REG (*loc
);
1335 mode
= GET_MODE (reg
);
1337 /* For mode with size bigger than ptr_mode, there unlikely to be "mov"
1338 between two registers with different classes, but there normally will
1339 be "mov" which transfers element of vector register into the general
1340 register, and this normally will be a subreg which should be reloaded
1341 as a whole. This is particularly likely to be triggered when
1342 -fno-split-wide-types specified. */
1344 || in_class_p (reg
, cl
, &new_class
)
1345 || GET_MODE_SIZE (mode
) <= GET_MODE_SIZE (ptr_mode
))
1346 loc
= &SUBREG_REG (*loc
);
1350 mode
= GET_MODE (reg
);
1355 /* Always reload memory in an address even if the target supports
1357 new_reg
= lra_create_new_reg_with_unique_value (mode
, reg
, cl
, "address");
1362 regno
= REGNO (reg
);
1363 rclass
= get_reg_class (regno
);
1365 && (*loc
= get_equiv_with_elimination (reg
, curr_insn
)) != reg
)
1367 if (lra_dump_file
!= NULL
)
1369 fprintf (lra_dump_file
,
1370 "Changing pseudo %d in address of insn %u on equiv ",
1371 REGNO (reg
), INSN_UID (curr_insn
));
1372 dump_value_slim (lra_dump_file
, *loc
, 1);
1373 fprintf (lra_dump_file
, "\n");
1375 *loc
= copy_rtx (*loc
);
1377 if (*loc
!= reg
|| ! in_class_p (reg
, cl
, &new_class
))
1382 if (get_reload_reg (after
== NULL
? OP_IN
: OP_INOUT
,
1383 mode
, reg
, cl
, subreg_p
, "address", &new_reg
))
1386 else if (new_class
!= NO_REGS
&& rclass
!= new_class
)
1390 lra_change_class (regno
, new_class
, " Change to", true);
1398 push_to_sequence (*before
);
1399 lra_emit_move (new_reg
, reg
);
1400 *before
= get_insns ();
1407 lra_emit_move (before_p
? copy_rtx (reg
) : reg
, new_reg
);
1409 *after
= get_insns ();
1415 /* Insert move insn in simplify_operand_subreg. BEFORE returns
1416 the insn to be inserted before curr insn. AFTER returns the
1417 the insn to be inserted after curr insn. ORIGREG and NEWREG
1418 are the original reg and new reg for reload. */
1420 insert_move_for_subreg (rtx_insn
**before
, rtx_insn
**after
, rtx origreg
,
1425 push_to_sequence (*before
);
1426 lra_emit_move (newreg
, origreg
);
1427 *before
= get_insns ();
1433 lra_emit_move (origreg
, newreg
);
1435 *after
= get_insns ();
1440 static int valid_address_p (machine_mode mode
, rtx addr
, addr_space_t as
);
1442 /* Make reloads for subreg in operand NOP with internal subreg mode
1443 REG_MODE, add new reloads for further processing. Return true if
1444 any change was done. */
1446 simplify_operand_subreg (int nop
, machine_mode reg_mode
)
1449 rtx_insn
*before
, *after
;
1450 machine_mode mode
, innermode
;
1452 rtx operand
= *curr_id
->operand_loc
[nop
];
1453 enum reg_class regclass
;
1456 before
= after
= NULL
;
1458 if (GET_CODE (operand
) != SUBREG
)
1461 mode
= GET_MODE (operand
);
1462 reg
= SUBREG_REG (operand
);
1463 innermode
= GET_MODE (reg
);
1464 type
= curr_static_id
->operand
[nop
].type
;
1465 /* If we change address for paradoxical subreg of memory, the
1466 address might violate the necessary alignment or the access might
1467 be slow. So take this into consideration. We should not worry
1468 about access beyond allocated memory for paradoxical memory
1469 subregs as we don't substitute such equiv memory (see processing
1470 equivalences in function lra_constraints) and because for spilled
1471 pseudos we allocate stack memory enough for the biggest
1472 corresponding paradoxical subreg. */
1474 && (! SLOW_UNALIGNED_ACCESS (mode
, MEM_ALIGN (reg
))
1475 || MEM_ALIGN (reg
) >= GET_MODE_ALIGNMENT (mode
)))
1477 rtx subst
, old
= *curr_id
->operand_loc
[nop
];
1479 alter_subreg (curr_id
->operand_loc
[nop
], false);
1480 subst
= *curr_id
->operand_loc
[nop
];
1481 lra_assert (MEM_P (subst
));
1482 if (! valid_address_p (innermode
, XEXP (reg
, 0),
1483 MEM_ADDR_SPACE (reg
))
1484 || valid_address_p (GET_MODE (subst
), XEXP (subst
, 0),
1485 MEM_ADDR_SPACE (subst
)))
1487 else if ((get_constraint_type (lookup_constraint
1488 (curr_static_id
->operand
[nop
].constraint
))
1489 != CT_SPECIAL_MEMORY
)
1490 /* We still can reload address and if the address is
1491 valid, we can remove subreg without reloading its
1493 && valid_address_p (GET_MODE (subst
),
1495 [ira_class_hard_regs
1496 [base_reg_class (GET_MODE (subst
),
1497 MEM_ADDR_SPACE (subst
),
1498 ADDRESS
, SCRATCH
)][0]],
1499 MEM_ADDR_SPACE (subst
)))
1502 /* If the address was valid and became invalid, prefer to reload
1503 the memory. Typical case is when the index scale should
1504 correspond the memory. */
1505 *curr_id
->operand_loc
[nop
] = old
;
1507 else if (REG_P (reg
) && REGNO (reg
) < FIRST_PSEUDO_REGISTER
)
1509 alter_subreg (curr_id
->operand_loc
[nop
], false);
1512 else if (CONSTANT_P (reg
))
1514 /* Try to simplify subreg of constant. It is usually result of
1515 equivalence substitution. */
1516 if (innermode
== VOIDmode
1517 && (innermode
= original_subreg_reg_mode
[nop
]) == VOIDmode
)
1518 innermode
= curr_static_id
->operand
[nop
].mode
;
1519 if ((new_reg
= simplify_subreg (mode
, reg
, innermode
,
1520 SUBREG_BYTE (operand
))) != NULL_RTX
)
1522 *curr_id
->operand_loc
[nop
] = new_reg
;
1526 /* Put constant into memory when we have mixed modes. It generates
1527 a better code in most cases as it does not need a secondary
1528 reload memory. It also prevents LRA looping when LRA is using
1529 secondary reload memory again and again. */
1530 if (CONSTANT_P (reg
) && CONST_POOL_OK_P (reg_mode
, reg
)
1531 && SCALAR_INT_MODE_P (reg_mode
) != SCALAR_INT_MODE_P (mode
))
1533 SUBREG_REG (operand
) = force_const_mem (reg_mode
, reg
);
1534 alter_subreg (curr_id
->operand_loc
[nop
], false);
1537 /* Force a reload of the SUBREG_REG if this is a constant or PLUS or
1538 if there may be a problem accessing OPERAND in the outer
1541 && REGNO (reg
) >= FIRST_PSEUDO_REGISTER
1542 && (hard_regno
= lra_get_regno_hard_regno (REGNO (reg
))) >= 0
1543 /* Don't reload paradoxical subregs because we could be looping
1544 having repeatedly final regno out of hard regs range. */
1545 && (hard_regno_nregs
[hard_regno
][innermode
]
1546 >= hard_regno_nregs
[hard_regno
][mode
])
1547 && simplify_subreg_regno (hard_regno
, innermode
,
1548 SUBREG_BYTE (operand
), mode
) < 0
1549 /* Don't reload subreg for matching reload. It is actually
1550 valid subreg in LRA. */
1551 && ! LRA_SUBREG_P (operand
))
1552 || CONSTANT_P (reg
) || GET_CODE (reg
) == PLUS
|| MEM_P (reg
))
1554 enum reg_class rclass
;
1557 /* There is a big probability that we will get the same class
1558 for the new pseudo and we will get the same insn which
1559 means infinite looping. So spill the new pseudo. */
1562 /* The class will be defined later in curr_insn_transform. */
1564 = (enum reg_class
) targetm
.preferred_reload_class (reg
, ALL_REGS
);
1566 if (get_reload_reg (curr_static_id
->operand
[nop
].type
, reg_mode
, reg
,
1567 rclass
, TRUE
, "subreg reg", &new_reg
))
1569 bool insert_before
, insert_after
;
1570 bitmap_set_bit (&lra_subreg_reload_pseudos
, REGNO (new_reg
));
1572 insert_before
= (type
!= OP_OUT
1573 || GET_MODE_SIZE (innermode
) > GET_MODE_SIZE (mode
));
1574 insert_after
= (type
!= OP_IN
);
1575 insert_move_for_subreg (insert_before
? &before
: NULL
,
1576 insert_after
? &after
: NULL
,
1579 SUBREG_REG (operand
) = new_reg
;
1580 lra_process_new_insns (curr_insn
, before
, after
,
1581 "Inserting subreg reload");
1584 /* Force a reload for a paradoxical subreg. For paradoxical subreg,
1585 IRA allocates hardreg to the inner pseudo reg according to its mode
1586 instead of the outermode, so the size of the hardreg may not be enough
1587 to contain the outermode operand, in that case we may need to insert
1588 reload for the reg. For the following two types of paradoxical subreg,
1589 we need to insert reload:
1590 1. If the op_type is OP_IN, and the hardreg could not be paired with
1591 other hardreg to contain the outermode operand
1592 (checked by in_hard_reg_set_p), we need to insert the reload.
1593 2. If the op_type is OP_OUT or OP_INOUT.
1595 Here is a paradoxical subreg example showing how the reload is generated:
1597 (insn 5 4 7 2 (set (reg:TI 106 [ __comp ])
1598 (subreg:TI (reg:DI 107 [ __comp ]) 0)) {*movti_internal_rex64}
1600 In IRA, reg107 is allocated to a DImode hardreg. We use x86-64 as example
1601 here, if reg107 is assigned to hardreg R15, because R15 is the last
1602 hardreg, compiler cannot find another hardreg to pair with R15 to
1603 contain TImode data. So we insert a TImode reload reg180 for it.
1604 After reload is inserted:
1606 (insn 283 0 0 (set (subreg:DI (reg:TI 180 [orig:107 __comp ] [107]) 0)
1607 (reg:DI 107 [ __comp ])) -1
1608 (insn 5 4 7 2 (set (reg:TI 106 [ __comp ])
1609 (subreg:TI (reg:TI 180 [orig:107 __comp ] [107]) 0)) {*movti_internal_rex64}
1611 Two reload hard registers will be allocated to reg180 to save TImode data
1613 else if (REG_P (reg
)
1614 && REGNO (reg
) >= FIRST_PSEUDO_REGISTER
1615 && (hard_regno
= lra_get_regno_hard_regno (REGNO (reg
))) >= 0
1616 && (hard_regno_nregs
[hard_regno
][innermode
]
1617 < hard_regno_nregs
[hard_regno
][mode
])
1618 && (regclass
= lra_get_allocno_class (REGNO (reg
)))
1620 || !in_hard_reg_set_p (reg_class_contents
[regclass
],
1623 /* The class will be defined later in curr_insn_transform. */
1624 enum reg_class rclass
1625 = (enum reg_class
) targetm
.preferred_reload_class (reg
, ALL_REGS
);
1627 if (get_reload_reg (curr_static_id
->operand
[nop
].type
, mode
, reg
,
1628 rclass
, TRUE
, "paradoxical subreg", &new_reg
))
1631 bool insert_before
, insert_after
;
1633 PUT_MODE (new_reg
, mode
);
1634 subreg
= gen_lowpart_SUBREG (innermode
, new_reg
);
1635 bitmap_set_bit (&lra_subreg_reload_pseudos
, REGNO (new_reg
));
1637 insert_before
= (type
!= OP_OUT
);
1638 insert_after
= (type
!= OP_IN
);
1639 insert_move_for_subreg (insert_before
? &before
: NULL
,
1640 insert_after
? &after
: NULL
,
1643 SUBREG_REG (operand
) = new_reg
;
1644 lra_process_new_insns (curr_insn
, before
, after
,
1645 "Inserting paradoxical subreg reload");
1651 /* Return TRUE if X refers for a hard register from SET. */
1653 uses_hard_regs_p (rtx x
, HARD_REG_SET set
)
1655 int i
, j
, x_hard_regno
;
1662 code
= GET_CODE (x
);
1663 mode
= GET_MODE (x
);
1667 code
= GET_CODE (x
);
1668 if (GET_MODE_SIZE (GET_MODE (x
)) > GET_MODE_SIZE (mode
))
1669 mode
= GET_MODE (x
);
1674 x_hard_regno
= get_hard_regno (x
);
1675 return (x_hard_regno
>= 0
1676 && overlaps_hard_reg_set_p (set
, mode
, x_hard_regno
));
1680 struct address_info ad
;
1682 decompose_mem_address (&ad
, x
);
1683 if (ad
.base_term
!= NULL
&& uses_hard_regs_p (*ad
.base_term
, set
))
1685 if (ad
.index_term
!= NULL
&& uses_hard_regs_p (*ad
.index_term
, set
))
1688 fmt
= GET_RTX_FORMAT (code
);
1689 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
1693 if (uses_hard_regs_p (XEXP (x
, i
), set
))
1696 else if (fmt
[i
] == 'E')
1698 for (j
= XVECLEN (x
, i
) - 1; j
>= 0; j
--)
1699 if (uses_hard_regs_p (XVECEXP (x
, i
, j
), set
))
1706 /* Return true if OP is a spilled pseudo. */
1708 spilled_pseudo_p (rtx op
)
1711 && REGNO (op
) >= FIRST_PSEUDO_REGISTER
&& in_mem_p (REGNO (op
)));
1714 /* Return true if X is a general constant. */
1716 general_constant_p (rtx x
)
1718 return CONSTANT_P (x
) && (! flag_pic
|| LEGITIMATE_PIC_OPERAND_P (x
));
1722 reg_in_class_p (rtx reg
, enum reg_class cl
)
1725 return get_reg_class (REGNO (reg
)) == NO_REGS
;
1726 return in_class_p (reg
, cl
, NULL
);
1729 /* Return true if SET of RCLASS contains no hard regs which can be
1732 prohibited_class_reg_set_mode_p (enum reg_class rclass
,
1734 enum machine_mode mode
)
1738 lra_assert (hard_reg_set_subset_p (reg_class_contents
[rclass
], set
));
1739 COPY_HARD_REG_SET (temp
, set
);
1740 AND_COMPL_HARD_REG_SET (temp
, lra_no_alloc_regs
);
1741 return (hard_reg_set_subset_p
1742 (temp
, ira_prohibited_class_mode_regs
[rclass
][mode
]));
1745 /* Major function to choose the current insn alternative and what
1746 operands should be reloaded and how. If ONLY_ALTERNATIVE is not
1747 negative we should consider only this alternative. Return false if
1748 we can not choose the alternative or find how to reload the
1751 process_alt_operands (int only_alternative
)
1754 int nop
, overall
, nalt
;
1755 int n_alternatives
= curr_static_id
->n_alternatives
;
1756 int n_operands
= curr_static_id
->n_operands
;
1757 /* LOSERS counts the operands that don't fit this alternative and
1758 would require loading. */
1760 /* REJECT is a count of how undesirable this alternative says it is
1761 if any reloading is required. If the alternative matches exactly
1762 then REJECT is ignored, but otherwise it gets this much counted
1763 against it in addition to the reloading needed. */
1766 /* The number of elements in the following array. */
1767 int early_clobbered_regs_num
;
1768 /* Numbers of operands which are early clobber registers. */
1769 int early_clobbered_nops
[MAX_RECOG_OPERANDS
];
1770 enum reg_class curr_alt
[MAX_RECOG_OPERANDS
];
1771 HARD_REG_SET curr_alt_set
[MAX_RECOG_OPERANDS
];
1772 bool curr_alt_match_win
[MAX_RECOG_OPERANDS
];
1773 bool curr_alt_win
[MAX_RECOG_OPERANDS
];
1774 bool curr_alt_offmemok
[MAX_RECOG_OPERANDS
];
1775 int curr_alt_matches
[MAX_RECOG_OPERANDS
];
1776 /* The number of elements in the following array. */
1777 int curr_alt_dont_inherit_ops_num
;
1778 /* Numbers of operands whose reload pseudos should not be inherited. */
1779 int curr_alt_dont_inherit_ops
[MAX_RECOG_OPERANDS
];
1781 /* The register when the operand is a subreg of register, otherwise the
1783 rtx no_subreg_reg_operand
[MAX_RECOG_OPERANDS
];
1784 /* The register if the operand is a register or subreg of register,
1786 rtx operand_reg
[MAX_RECOG_OPERANDS
];
1787 int hard_regno
[MAX_RECOG_OPERANDS
];
1788 machine_mode biggest_mode
[MAX_RECOG_OPERANDS
];
1789 int reload_nregs
, reload_sum
;
1793 /* Calculate some data common for all alternatives to speed up the
1795 for (nop
= 0; nop
< n_operands
; nop
++)
1799 op
= no_subreg_reg_operand
[nop
] = *curr_id
->operand_loc
[nop
];
1800 /* The real hard regno of the operand after the allocation. */
1801 hard_regno
[nop
] = get_hard_regno (op
);
1803 operand_reg
[nop
] = reg
= op
;
1804 biggest_mode
[nop
] = GET_MODE (op
);
1805 if (GET_CODE (op
) == SUBREG
)
1807 operand_reg
[nop
] = reg
= SUBREG_REG (op
);
1808 if (GET_MODE_SIZE (biggest_mode
[nop
])
1809 < GET_MODE_SIZE (GET_MODE (reg
)))
1810 biggest_mode
[nop
] = GET_MODE (reg
);
1813 operand_reg
[nop
] = NULL_RTX
;
1814 else if (REGNO (reg
) >= FIRST_PSEUDO_REGISTER
1815 || ((int) REGNO (reg
)
1816 == lra_get_elimination_hard_regno (REGNO (reg
))))
1817 no_subreg_reg_operand
[nop
] = reg
;
1819 operand_reg
[nop
] = no_subreg_reg_operand
[nop
]
1820 /* Just use natural mode for elimination result. It should
1821 be enough for extra constraints hooks. */
1822 = regno_reg_rtx
[hard_regno
[nop
]];
1825 /* The constraints are made of several alternatives. Each operand's
1826 constraint looks like foo,bar,... with commas separating the
1827 alternatives. The first alternatives for all operands go
1828 together, the second alternatives go together, etc.
1830 First loop over alternatives. */
1831 alternative_mask preferred
= curr_id
->preferred_alternatives
;
1832 if (only_alternative
>= 0)
1833 preferred
&= ALTERNATIVE_BIT (only_alternative
);
1835 for (nalt
= 0; nalt
< n_alternatives
; nalt
++)
1837 /* Loop over operands for one constraint alternative. */
1838 if (!TEST_BIT (preferred
, nalt
))
1841 overall
= losers
= reject
= reload_nregs
= reload_sum
= 0;
1842 for (nop
= 0; nop
< n_operands
; nop
++)
1844 int inc
= (curr_static_id
1845 ->operand_alternative
[nalt
* n_operands
+ nop
].reject
);
1846 if (lra_dump_file
!= NULL
&& inc
!= 0)
1847 fprintf (lra_dump_file
,
1848 " Staticly defined alt reject+=%d\n", inc
);
1851 early_clobbered_regs_num
= 0;
1853 for (nop
= 0; nop
< n_operands
; nop
++)
1857 int len
, c
, m
, i
, opalt_num
, this_alternative_matches
;
1858 bool win
, did_match
, offmemok
, early_clobber_p
;
1859 /* false => this operand can be reloaded somehow for this
1862 /* true => this operand can be reloaded if the alternative
1865 /* True if a constant forced into memory would be OK for
1868 enum reg_class this_alternative
, this_costly_alternative
;
1869 HARD_REG_SET this_alternative_set
, this_costly_alternative_set
;
1870 bool this_alternative_match_win
, this_alternative_win
;
1871 bool this_alternative_offmemok
;
1874 enum constraint_num cn
;
1876 opalt_num
= nalt
* n_operands
+ nop
;
1877 if (curr_static_id
->operand_alternative
[opalt_num
].anything_ok
)
1879 /* Fast track for no constraints at all. */
1880 curr_alt
[nop
] = NO_REGS
;
1881 CLEAR_HARD_REG_SET (curr_alt_set
[nop
]);
1882 curr_alt_win
[nop
] = true;
1883 curr_alt_match_win
[nop
] = false;
1884 curr_alt_offmemok
[nop
] = false;
1885 curr_alt_matches
[nop
] = -1;
1889 op
= no_subreg_reg_operand
[nop
];
1890 mode
= curr_operand_mode
[nop
];
1892 win
= did_match
= winreg
= offmemok
= constmemok
= false;
1895 early_clobber_p
= false;
1896 p
= curr_static_id
->operand_alternative
[opalt_num
].constraint
;
1898 this_costly_alternative
= this_alternative
= NO_REGS
;
1899 /* We update set of possible hard regs besides its class
1900 because reg class might be inaccurate. For example,
1901 union of LO_REGS (l), HI_REGS(h), and STACK_REG(k) in ARM
1902 is translated in HI_REGS because classes are merged by
1903 pairs and there is no accurate intermediate class. */
1904 CLEAR_HARD_REG_SET (this_alternative_set
);
1905 CLEAR_HARD_REG_SET (this_costly_alternative_set
);
1906 this_alternative_win
= false;
1907 this_alternative_match_win
= false;
1908 this_alternative_offmemok
= false;
1909 this_alternative_matches
= -1;
1911 /* An empty constraint should be excluded by the fast
1913 lra_assert (*p
!= 0 && *p
!= ',');
1916 /* Scan this alternative's specs for this operand; set WIN
1917 if the operand fits any letter in this alternative.
1918 Otherwise, clear BADOP if this operand could fit some
1919 letter after reloads, or set WINREG if this operand could
1920 fit after reloads provided the constraint allows some
1925 switch ((c
= *p
, len
= CONSTRAINT_LEN (c
, p
)), c
)
1935 early_clobber_p
= true;
1939 op_reject
+= LRA_MAX_REJECT
;
1942 op_reject
+= LRA_LOSER_COST_FACTOR
;
1946 /* Ignore rest of this alternative. */
1950 case '0': case '1': case '2': case '3': case '4':
1951 case '5': case '6': case '7': case '8': case '9':
1956 m
= strtoul (p
, &end
, 10);
1959 lra_assert (nop
> m
);
1961 this_alternative_matches
= m
;
1962 m_hregno
= get_hard_regno (*curr_id
->operand_loc
[m
]);
1963 /* We are supposed to match a previous operand.
1964 If we do, we win if that one did. If we do
1965 not, count both of the operands as losers.
1966 (This is too conservative, since most of the
1967 time only a single reload insn will be needed
1968 to make the two operands win. As a result,
1969 this alternative may be rejected when it is
1970 actually desirable.) */
1972 if (operands_match_p (*curr_id
->operand_loc
[nop
],
1973 *curr_id
->operand_loc
[m
], m_hregno
))
1975 /* We should reject matching of an early
1976 clobber operand if the matching operand is
1977 not dying in the insn. */
1978 if (! curr_static_id
->operand
[m
].early_clobber
1979 || operand_reg
[nop
] == NULL_RTX
1980 || (find_regno_note (curr_insn
, REG_DEAD
,
1982 || REGNO (op
) == REGNO (operand_reg
[m
])))
1987 /* If we are matching a non-offsettable
1988 address where an offsettable address was
1989 expected, then we must reject this
1990 combination, because we can't reload
1992 if (curr_alt_offmemok
[m
]
1993 && MEM_P (*curr_id
->operand_loc
[m
])
1994 && curr_alt
[m
] == NO_REGS
&& ! curr_alt_win
[m
])
1999 /* Operands don't match. Both operands must
2000 allow a reload register, otherwise we
2001 cannot make them match. */
2002 if (curr_alt
[m
] == NO_REGS
)
2004 /* Retroactively mark the operand we had to
2005 match as a loser, if it wasn't already and
2006 it wasn't matched to a register constraint
2007 (e.g it might be matched by memory). */
2009 && (operand_reg
[m
] == NULL_RTX
2010 || hard_regno
[m
] < 0))
2014 += (ira_reg_class_max_nregs
[curr_alt
[m
]]
2015 [GET_MODE (*curr_id
->operand_loc
[m
])]);
2018 /* Prefer matching earlyclobber alternative as
2019 it results in less hard regs required for
2020 the insn than a non-matching earlyclobber
2022 if (curr_static_id
->operand
[m
].early_clobber
)
2024 if (lra_dump_file
!= NULL
)
2027 " %d Matching earlyclobber alt:"
2032 /* Otherwise we prefer no matching
2033 alternatives because it gives more freedom
2035 else if (operand_reg
[nop
] == NULL_RTX
2036 || (find_regno_note (curr_insn
, REG_DEAD
,
2037 REGNO (operand_reg
[nop
]))
2040 if (lra_dump_file
!= NULL
)
2043 " %d Matching alt: reject+=2\n",
2048 /* If we have to reload this operand and some
2049 previous operand also had to match the same
2050 thing as this operand, we don't know how to do
2052 if (!match_p
|| !curr_alt_win
[m
])
2054 for (i
= 0; i
< nop
; i
++)
2055 if (curr_alt_matches
[i
] == m
)
2063 /* This can be fixed with reloads if the operand
2064 we are supposed to match can be fixed with
2067 this_alternative
= curr_alt
[m
];
2068 COPY_HARD_REG_SET (this_alternative_set
, curr_alt_set
[m
]);
2069 winreg
= this_alternative
!= NO_REGS
;
2075 || general_constant_p (op
)
2076 || spilled_pseudo_p (op
))
2082 cn
= lookup_constraint (p
);
2083 switch (get_constraint_type (cn
))
2086 cl
= reg_class_for_constraint (cn
);
2092 if (CONST_INT_P (op
)
2093 && insn_const_int_ok_for_constraint (INTVAL (op
), cn
))
2099 && satisfies_memory_constraint_p (op
, cn
))
2101 else if (spilled_pseudo_p (op
))
2104 /* If we didn't already win, we can reload constants
2105 via force_const_mem or put the pseudo value into
2106 memory, or make other memory by reloading the
2107 address like for 'o'. */
2108 if (CONST_POOL_OK_P (mode
, op
)
2109 || MEM_P (op
) || REG_P (op
)
2110 /* We can restore the equiv insn by a
2112 || equiv_substition_p
[nop
])
2119 /* If we didn't already win, we can reload the address
2120 into a base register. */
2121 if (satisfies_address_constraint_p (op
, cn
))
2123 cl
= base_reg_class (VOIDmode
, ADDR_SPACE_GENERIC
,
2129 if (constraint_satisfied_p (op
, cn
))
2133 case CT_SPECIAL_MEMORY
:
2135 && satisfies_memory_constraint_p (op
, cn
))
2137 else if (spilled_pseudo_p (op
))
2144 this_alternative
= reg_class_subunion
[this_alternative
][cl
];
2145 IOR_HARD_REG_SET (this_alternative_set
,
2146 reg_class_contents
[cl
]);
2149 this_costly_alternative
2150 = reg_class_subunion
[this_costly_alternative
][cl
];
2151 IOR_HARD_REG_SET (this_costly_alternative_set
,
2152 reg_class_contents
[cl
]);
2154 if (mode
== BLKmode
)
2159 if (hard_regno
[nop
] >= 0
2160 && in_hard_reg_set_p (this_alternative_set
,
2161 mode
, hard_regno
[nop
]))
2163 else if (hard_regno
[nop
] < 0
2164 && in_class_p (op
, this_alternative
, NULL
))
2169 if (c
!= ' ' && c
!= '\t')
2170 costly_p
= c
== '*';
2172 while ((p
+= len
), c
);
2174 scratch_p
= (operand_reg
[nop
] != NULL_RTX
2175 && lra_former_scratch_p (REGNO (operand_reg
[nop
])));
2176 /* Record which operands fit this alternative. */
2179 this_alternative_win
= true;
2180 if (operand_reg
[nop
] != NULL_RTX
)
2182 if (hard_regno
[nop
] >= 0)
2184 if (in_hard_reg_set_p (this_costly_alternative_set
,
2185 mode
, hard_regno
[nop
]))
2187 if (lra_dump_file
!= NULL
)
2188 fprintf (lra_dump_file
,
2189 " %d Costly set: reject++\n",
2196 /* Prefer won reg to spilled pseudo under other
2197 equal conditions for possibe inheritance. */
2200 if (lra_dump_file
!= NULL
)
2203 " %d Non pseudo reload: reject++\n",
2207 if (in_class_p (operand_reg
[nop
],
2208 this_costly_alternative
, NULL
))
2210 if (lra_dump_file
!= NULL
)
2213 " %d Non pseudo costly reload:"
2219 /* We simulate the behavior of old reload here.
2220 Although scratches need hard registers and it
2221 might result in spilling other pseudos, no reload
2222 insns are generated for the scratches. So it
2223 might cost something but probably less than old
2224 reload pass believes. */
2227 if (lra_dump_file
!= NULL
)
2228 fprintf (lra_dump_file
,
2229 " %d Scratch win: reject+=2\n",
2236 this_alternative_match_win
= true;
2239 int const_to_mem
= 0;
2242 reject
+= op_reject
;
2243 /* Never do output reload of stack pointer. It makes
2244 impossible to do elimination when SP is changed in
2246 if (op
== stack_pointer_rtx
&& ! frame_pointer_needed
2247 && curr_static_id
->operand
[nop
].type
!= OP_IN
)
2250 /* If this alternative asks for a specific reg class, see if there
2251 is at least one allocatable register in that class. */
2253 = (this_alternative
== NO_REGS
2254 || (hard_reg_set_subset_p
2255 (reg_class_contents
[this_alternative
],
2256 lra_no_alloc_regs
)));
2258 /* For asms, verify that the class for this alternative is possible
2259 for the mode that is specified. */
2260 if (!no_regs_p
&& INSN_CODE (curr_insn
) < 0)
2263 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
2264 if (HARD_REGNO_MODE_OK (i
, mode
)
2265 && in_hard_reg_set_p (reg_class_contents
[this_alternative
],
2268 if (i
== FIRST_PSEUDO_REGISTER
)
2272 /* If this operand accepts a register, and if the
2273 register class has at least one allocatable register,
2274 then this operand can be reloaded. */
2275 if (winreg
&& !no_regs_p
)
2280 if (lra_dump_file
!= NULL
)
2281 fprintf (lra_dump_file
,
2282 " alt=%d: Bad operand -- refuse\n",
2287 if (this_alternative
!= NO_REGS
)
2289 HARD_REG_SET available_regs
;
2291 COPY_HARD_REG_SET (available_regs
,
2292 reg_class_contents
[this_alternative
]);
2293 AND_COMPL_HARD_REG_SET
2295 ira_prohibited_class_mode_regs
[this_alternative
][mode
]);
2296 AND_COMPL_HARD_REG_SET (available_regs
, lra_no_alloc_regs
);
2297 if (hard_reg_set_empty_p (available_regs
))
2299 /* There are no hard regs holding a value of given
2303 this_alternative
= NO_REGS
;
2304 if (lra_dump_file
!= NULL
)
2305 fprintf (lra_dump_file
,
2306 " %d Using memory because of"
2307 " a bad mode: reject+=2\n",
2313 if (lra_dump_file
!= NULL
)
2314 fprintf (lra_dump_file
,
2315 " alt=%d: Wrong mode -- refuse\n",
2322 /* If not assigned pseudo has a class which a subset of
2323 required reg class, it is a less costly alternative
2324 as the pseudo still can get a hard reg of necessary
2326 if (! no_regs_p
&& REG_P (op
) && hard_regno
[nop
] < 0
2327 && (cl
= get_reg_class (REGNO (op
))) != NO_REGS
2328 && ira_class_subset_p
[this_alternative
][cl
])
2330 if (lra_dump_file
!= NULL
)
2333 " %d Super set class reg: reject-=3\n", nop
);
2337 this_alternative_offmemok
= offmemok
;
2338 if (this_costly_alternative
!= NO_REGS
)
2340 if (lra_dump_file
!= NULL
)
2341 fprintf (lra_dump_file
,
2342 " %d Costly loser: reject++\n", nop
);
2345 /* If the operand is dying, has a matching constraint,
2346 and satisfies constraints of the matched operand
2347 which failed to satisfy the own constraints, most probably
2348 the reload for this operand will be gone. */
2349 if (this_alternative_matches
>= 0
2350 && !curr_alt_win
[this_alternative_matches
]
2352 && find_regno_note (curr_insn
, REG_DEAD
, REGNO (op
))
2353 && (hard_regno
[nop
] >= 0
2354 ? in_hard_reg_set_p (this_alternative_set
,
2355 mode
, hard_regno
[nop
])
2356 : in_class_p (op
, this_alternative
, NULL
)))
2358 if (lra_dump_file
!= NULL
)
2361 " %d Dying matched operand reload: reject++\n",
2367 /* Strict_low_part requires to reload the register
2368 not the sub-register. In this case we should
2369 check that a final reload hard reg can hold the
2371 if (curr_static_id
->operand
[nop
].strict_low
2373 && hard_regno
[nop
] < 0
2374 && GET_CODE (*curr_id
->operand_loc
[nop
]) == SUBREG
2375 && ira_class_hard_regs_num
[this_alternative
] > 0
2376 && ! HARD_REGNO_MODE_OK (ira_class_hard_regs
2377 [this_alternative
][0],
2379 (*curr_id
->operand_loc
[nop
])))
2381 if (lra_dump_file
!= NULL
)
2384 " alt=%d: Strict low subreg reload -- refuse\n",
2390 if (operand_reg
[nop
] != NULL_RTX
2391 /* Output operands and matched input operands are
2392 not inherited. The following conditions do not
2393 exactly describe the previous statement but they
2394 are pretty close. */
2395 && curr_static_id
->operand
[nop
].type
!= OP_OUT
2396 && (this_alternative_matches
< 0
2397 || curr_static_id
->operand
[nop
].type
!= OP_IN
))
2399 int last_reload
= (lra_reg_info
[ORIGINAL_REGNO
2403 /* The value of reload_sum has sense only if we
2404 process insns in their order. It happens only on
2405 the first constraints sub-pass when we do most of
2407 if (lra_constraint_iter
== 1 && last_reload
> bb_reload_num
)
2408 reload_sum
+= last_reload
- bb_reload_num
;
2410 /* If this is a constant that is reloaded into the
2411 desired class by copying it to memory first, count
2412 that as another reload. This is consistent with
2413 other code and is required to avoid choosing another
2414 alternative when the constant is moved into memory.
2415 Note that the test here is precisely the same as in
2416 the code below that calls force_const_mem. */
2417 if (CONST_POOL_OK_P (mode
, op
)
2418 && ((targetm
.preferred_reload_class
2419 (op
, this_alternative
) == NO_REGS
)
2420 || no_input_reloads_p
))
2427 /* Alternative loses if it requires a type of reload not
2428 permitted for this insn. We can always reload
2429 objects with a REG_UNUSED note. */
2430 if ((curr_static_id
->operand
[nop
].type
!= OP_IN
2431 && no_output_reloads_p
2432 && ! find_reg_note (curr_insn
, REG_UNUSED
, op
))
2433 || (curr_static_id
->operand
[nop
].type
!= OP_OUT
2434 && no_input_reloads_p
&& ! const_to_mem
)
2435 || (this_alternative_matches
>= 0
2436 && (no_input_reloads_p
2437 || (no_output_reloads_p
2438 && (curr_static_id
->operand
2439 [this_alternative_matches
].type
!= OP_IN
)
2440 && ! find_reg_note (curr_insn
, REG_UNUSED
,
2441 no_subreg_reg_operand
2442 [this_alternative_matches
])))))
2444 if (lra_dump_file
!= NULL
)
2447 " alt=%d: No input/otput reload -- refuse\n",
2452 /* Alternative loses if it required class pseudo can not
2453 hold value of required mode. Such insns can be
2454 described by insn definitions with mode iterators. */
2455 if (GET_MODE (*curr_id
->operand_loc
[nop
]) != VOIDmode
2456 && ! hard_reg_set_empty_p (this_alternative_set
)
2457 /* It is common practice for constraints to use a
2458 class which does not have actually enough regs to
2459 hold the value (e.g. x86 AREG for mode requiring
2460 more one general reg). Therefore we have 2
2461 conditions to check that the reload pseudo can
2462 not hold the mode value. */
2463 && ! HARD_REGNO_MODE_OK (ira_class_hard_regs
2464 [this_alternative
][0],
2465 GET_MODE (*curr_id
->operand_loc
[nop
]))
2466 /* The above condition is not enough as the first
2467 reg in ira_class_hard_regs can be not aligned for
2468 multi-words mode values. */
2469 && (prohibited_class_reg_set_mode_p
2470 (this_alternative
, this_alternative_set
,
2471 GET_MODE (*curr_id
->operand_loc
[nop
]))))
2473 if (lra_dump_file
!= NULL
)
2474 fprintf (lra_dump_file
,
2475 " alt=%d: reload pseudo for op %d "
2476 " can not hold the mode value -- refuse\n",
2481 /* Check strong discouragement of reload of non-constant
2482 into class THIS_ALTERNATIVE. */
2483 if (! CONSTANT_P (op
) && ! no_regs_p
2484 && (targetm
.preferred_reload_class
2485 (op
, this_alternative
) == NO_REGS
2486 || (curr_static_id
->operand
[nop
].type
== OP_OUT
2487 && (targetm
.preferred_output_reload_class
2488 (op
, this_alternative
) == NO_REGS
))))
2490 if (lra_dump_file
!= NULL
)
2491 fprintf (lra_dump_file
,
2492 " %d Non-prefered reload: reject+=%d\n",
2493 nop
, LRA_MAX_REJECT
);
2494 reject
+= LRA_MAX_REJECT
;
2497 if (! (MEM_P (op
) && offmemok
)
2498 && ! (const_to_mem
&& constmemok
))
2500 /* We prefer to reload pseudos over reloading other
2501 things, since such reloads may be able to be
2502 eliminated later. So bump REJECT in other cases.
2503 Don't do this in the case where we are forcing a
2504 constant into memory and it will then win since
2505 we don't want to have a different alternative
2507 if (! (REG_P (op
) && REGNO (op
) >= FIRST_PSEUDO_REGISTER
))
2509 if (lra_dump_file
!= NULL
)
2512 " %d Non-pseudo reload: reject+=2\n",
2519 += ira_reg_class_max_nregs
[this_alternative
][mode
];
2521 if (SMALL_REGISTER_CLASS_P (this_alternative
))
2523 if (lra_dump_file
!= NULL
)
2526 " %d Small class reload: reject+=%d\n",
2527 nop
, LRA_LOSER_COST_FACTOR
/ 2);
2528 reject
+= LRA_LOSER_COST_FACTOR
/ 2;
2532 /* We are trying to spill pseudo into memory. It is
2533 usually more costly than moving to a hard register
2534 although it might takes the same number of
2537 Non-pseudo spill may happen also. Suppose a target allows both
2538 register and memory in the operand constraint alternatives,
2539 then it's typical that an eliminable register has a substition
2540 of "base + offset" which can either be reloaded by a simple
2541 "new_reg <= base + offset" which will match the register
2542 constraint, or a similar reg addition followed by further spill
2543 to and reload from memory which will match the memory
2544 constraint, but this memory spill will be much more costly
2547 Code below increases the reject for both pseudo and non-pseudo
2550 && !(MEM_P (op
) && offmemok
)
2551 && !(REG_P (op
) && hard_regno
[nop
] < 0))
2553 if (lra_dump_file
!= NULL
)
2556 " %d Spill %spseudo into memory: reject+=3\n",
2557 nop
, REG_P (op
) ? "" : "Non-");
2559 if (VECTOR_MODE_P (mode
))
2561 /* Spilling vectors into memory is usually more
2562 costly as they contain big values. */
2563 if (lra_dump_file
!= NULL
)
2566 " %d Spill vector pseudo: reject+=2\n",
2572 #ifdef SECONDARY_MEMORY_NEEDED
2573 /* If reload requires moving value through secondary
2574 memory, it will need one more insn at least. */
2575 if (this_alternative
!= NO_REGS
2576 && REG_P (op
) && (cl
= get_reg_class (REGNO (op
))) != NO_REGS
2577 && ((curr_static_id
->operand
[nop
].type
!= OP_OUT
2578 && SECONDARY_MEMORY_NEEDED (cl
, this_alternative
,
2580 || (curr_static_id
->operand
[nop
].type
!= OP_IN
2581 && SECONDARY_MEMORY_NEEDED (this_alternative
, cl
,
2585 /* Input reloads can be inherited more often than output
2586 reloads can be removed, so penalize output
2588 if (!REG_P (op
) || curr_static_id
->operand
[nop
].type
!= OP_IN
)
2590 if (lra_dump_file
!= NULL
)
2593 " %d Non input pseudo reload: reject++\n",
2599 if (early_clobber_p
&& ! scratch_p
)
2601 if (lra_dump_file
!= NULL
)
2602 fprintf (lra_dump_file
,
2603 " %d Early clobber: reject++\n", nop
);
2606 /* ??? We check early clobbers after processing all operands
2607 (see loop below) and there we update the costs more.
2608 Should we update the cost (may be approximately) here
2609 because of early clobber register reloads or it is a rare
2610 or non-important thing to be worth to do it. */
2611 overall
= losers
* LRA_LOSER_COST_FACTOR
+ reject
;
2612 if ((best_losers
== 0 || losers
!= 0) && best_overall
< overall
)
2614 if (lra_dump_file
!= NULL
)
2615 fprintf (lra_dump_file
,
2616 " alt=%d,overall=%d,losers=%d -- refuse\n",
2617 nalt
, overall
, losers
);
2621 curr_alt
[nop
] = this_alternative
;
2622 COPY_HARD_REG_SET (curr_alt_set
[nop
], this_alternative_set
);
2623 curr_alt_win
[nop
] = this_alternative_win
;
2624 curr_alt_match_win
[nop
] = this_alternative_match_win
;
2625 curr_alt_offmemok
[nop
] = this_alternative_offmemok
;
2626 curr_alt_matches
[nop
] = this_alternative_matches
;
2628 if (this_alternative_matches
>= 0
2629 && !did_match
&& !this_alternative_win
)
2630 curr_alt_win
[this_alternative_matches
] = false;
2632 if (early_clobber_p
&& operand_reg
[nop
] != NULL_RTX
)
2633 early_clobbered_nops
[early_clobbered_regs_num
++] = nop
;
2635 if (curr_insn_set
!= NULL_RTX
&& n_operands
== 2
2636 /* Prevent processing non-move insns. */
2637 && (GET_CODE (SET_SRC (curr_insn_set
)) == SUBREG
2638 || SET_SRC (curr_insn_set
) == no_subreg_reg_operand
[1])
2639 && ((! curr_alt_win
[0] && ! curr_alt_win
[1]
2640 && REG_P (no_subreg_reg_operand
[0])
2641 && REG_P (no_subreg_reg_operand
[1])
2642 && (reg_in_class_p (no_subreg_reg_operand
[0], curr_alt
[1])
2643 || reg_in_class_p (no_subreg_reg_operand
[1], curr_alt
[0])))
2644 || (! curr_alt_win
[0] && curr_alt_win
[1]
2645 && REG_P (no_subreg_reg_operand
[1])
2646 && reg_in_class_p (no_subreg_reg_operand
[1], curr_alt
[0]))
2647 || (curr_alt_win
[0] && ! curr_alt_win
[1]
2648 && REG_P (no_subreg_reg_operand
[0])
2649 && reg_in_class_p (no_subreg_reg_operand
[0], curr_alt
[1])
2650 && (! CONST_POOL_OK_P (curr_operand_mode
[1],
2651 no_subreg_reg_operand
[1])
2652 || (targetm
.preferred_reload_class
2653 (no_subreg_reg_operand
[1],
2654 (enum reg_class
) curr_alt
[1]) != NO_REGS
))
2655 /* If it is a result of recent elimination in move
2656 insn we can transform it into an add still by
2657 using this alternative. */
2658 && GET_CODE (no_subreg_reg_operand
[1]) != PLUS
)))
2660 /* We have a move insn and a new reload insn will be similar
2661 to the current insn. We should avoid such situation as it
2662 results in LRA cycling. */
2663 overall
+= LRA_MAX_REJECT
;
2666 curr_alt_dont_inherit_ops_num
= 0;
2667 for (nop
= 0; nop
< early_clobbered_regs_num
; nop
++)
2669 int i
, j
, clobbered_hard_regno
, first_conflict_j
, last_conflict_j
;
2670 HARD_REG_SET temp_set
;
2672 i
= early_clobbered_nops
[nop
];
2673 if ((! curr_alt_win
[i
] && ! curr_alt_match_win
[i
])
2674 || hard_regno
[i
] < 0)
2676 lra_assert (operand_reg
[i
] != NULL_RTX
);
2677 clobbered_hard_regno
= hard_regno
[i
];
2678 CLEAR_HARD_REG_SET (temp_set
);
2679 add_to_hard_reg_set (&temp_set
, biggest_mode
[i
], clobbered_hard_regno
);
2680 first_conflict_j
= last_conflict_j
= -1;
2681 for (j
= 0; j
< n_operands
; j
++)
2683 /* We don't want process insides of match_operator and
2684 match_parallel because otherwise we would process
2685 their operands once again generating a wrong
2687 || curr_static_id
->operand
[j
].is_operator
)
2689 else if ((curr_alt_matches
[j
] == i
&& curr_alt_match_win
[j
])
2690 || (curr_alt_matches
[i
] == j
&& curr_alt_match_win
[i
]))
2692 /* If we don't reload j-th operand, check conflicts. */
2693 else if ((curr_alt_win
[j
] || curr_alt_match_win
[j
])
2694 && uses_hard_regs_p (*curr_id
->operand_loc
[j
], temp_set
))
2696 if (first_conflict_j
< 0)
2697 first_conflict_j
= j
;
2698 last_conflict_j
= j
;
2700 if (last_conflict_j
< 0)
2702 /* If earlyclobber operand conflicts with another
2703 non-matching operand which is actually the same register
2704 as the earlyclobber operand, it is better to reload the
2705 another operand as an operand matching the earlyclobber
2706 operand can be also the same. */
2707 if (first_conflict_j
== last_conflict_j
2708 && operand_reg
[last_conflict_j
] != NULL_RTX
2709 && ! curr_alt_match_win
[last_conflict_j
]
2710 && REGNO (operand_reg
[i
]) == REGNO (operand_reg
[last_conflict_j
]))
2712 curr_alt_win
[last_conflict_j
] = false;
2713 curr_alt_dont_inherit_ops
[curr_alt_dont_inherit_ops_num
++]
2716 /* Early clobber was already reflected in REJECT. */
2717 lra_assert (reject
> 0);
2718 if (lra_dump_file
!= NULL
)
2721 " %d Conflict early clobber reload: reject--\n",
2724 overall
+= LRA_LOSER_COST_FACTOR
- 1;
2728 /* We need to reload early clobbered register and the
2729 matched registers. */
2730 for (j
= 0; j
< n_operands
; j
++)
2731 if (curr_alt_matches
[j
] == i
)
2733 curr_alt_match_win
[j
] = false;
2735 overall
+= LRA_LOSER_COST_FACTOR
;
2737 if (! curr_alt_match_win
[i
])
2738 curr_alt_dont_inherit_ops
[curr_alt_dont_inherit_ops_num
++] = i
;
2741 /* Remember pseudos used for match reloads are never
2743 lra_assert (curr_alt_matches
[i
] >= 0);
2744 curr_alt_win
[curr_alt_matches
[i
]] = false;
2746 curr_alt_win
[i
] = curr_alt_match_win
[i
] = false;
2748 /* Early clobber was already reflected in REJECT. */
2749 lra_assert (reject
> 0);
2750 if (lra_dump_file
!= NULL
)
2753 " %d Matched conflict early clobber reloads:"
2757 overall
+= LRA_LOSER_COST_FACTOR
- 1;
2760 if (lra_dump_file
!= NULL
)
2761 fprintf (lra_dump_file
, " alt=%d,overall=%d,losers=%d,rld_nregs=%d\n",
2762 nalt
, overall
, losers
, reload_nregs
);
2764 /* If this alternative can be made to work by reloading, and it
2765 needs less reloading than the others checked so far, record
2766 it as the chosen goal for reloading. */
2767 if ((best_losers
!= 0 && losers
== 0)
2768 || (((best_losers
== 0 && losers
== 0)
2769 || (best_losers
!= 0 && losers
!= 0))
2770 && (best_overall
> overall
2771 || (best_overall
== overall
2772 /* If the cost of the reloads is the same,
2773 prefer alternative which requires minimal
2774 number of reload regs. */
2775 && (reload_nregs
< best_reload_nregs
2776 || (reload_nregs
== best_reload_nregs
2777 && (best_reload_sum
< reload_sum
2778 || (best_reload_sum
== reload_sum
2779 && nalt
< goal_alt_number
))))))))
2781 for (nop
= 0; nop
< n_operands
; nop
++)
2783 goal_alt_win
[nop
] = curr_alt_win
[nop
];
2784 goal_alt_match_win
[nop
] = curr_alt_match_win
[nop
];
2785 goal_alt_matches
[nop
] = curr_alt_matches
[nop
];
2786 goal_alt
[nop
] = curr_alt
[nop
];
2787 goal_alt_offmemok
[nop
] = curr_alt_offmemok
[nop
];
2789 goal_alt_dont_inherit_ops_num
= curr_alt_dont_inherit_ops_num
;
2790 for (nop
= 0; nop
< curr_alt_dont_inherit_ops_num
; nop
++)
2791 goal_alt_dont_inherit_ops
[nop
] = curr_alt_dont_inherit_ops
[nop
];
2792 goal_alt_swapped
= curr_swapped
;
2793 best_overall
= overall
;
2794 best_losers
= losers
;
2795 best_reload_nregs
= reload_nregs
;
2796 best_reload_sum
= reload_sum
;
2797 goal_alt_number
= nalt
;
2800 /* Everything is satisfied. Do not process alternatives
2809 /* Make reload base reg from address AD. */
2811 base_to_reg (struct address_info
*ad
)
2815 rtx new_inner
= NULL_RTX
;
2816 rtx new_reg
= NULL_RTX
;
2818 rtx_insn
*last_insn
= get_last_insn();
2820 lra_assert (ad
->base
== ad
->base_term
&& ad
->disp
== ad
->disp_term
);
2821 cl
= base_reg_class (ad
->mode
, ad
->as
, ad
->base_outer_code
,
2822 get_index_code (ad
));
2823 new_reg
= lra_create_new_reg (GET_MODE (*ad
->base_term
), NULL_RTX
,
2825 new_inner
= simplify_gen_binary (PLUS
, GET_MODE (new_reg
), new_reg
,
2826 ad
->disp_term
== NULL
2827 ? gen_int_mode (0, ad
->mode
)
2829 if (!valid_address_p (ad
->mode
, new_inner
, ad
->as
))
2831 insn
= emit_insn (gen_rtx_SET (new_reg
, *ad
->base_term
));
2832 code
= recog_memoized (insn
);
2835 delete_insns_since (last_insn
);
2842 /* Make reload base reg + disp from address AD. Return the new pseudo. */
2844 base_plus_disp_to_reg (struct address_info
*ad
)
2849 lra_assert (ad
->base
== ad
->base_term
&& ad
->disp
== ad
->disp_term
);
2850 cl
= base_reg_class (ad
->mode
, ad
->as
, ad
->base_outer_code
,
2851 get_index_code (ad
));
2852 new_reg
= lra_create_new_reg (GET_MODE (*ad
->base_term
), NULL_RTX
,
2854 lra_emit_add (new_reg
, *ad
->base_term
, *ad
->disp_term
);
2858 /* Make reload of index part of address AD. Return the new
2861 index_part_to_reg (struct address_info
*ad
)
2865 new_reg
= lra_create_new_reg (GET_MODE (*ad
->index
), NULL_RTX
,
2866 INDEX_REG_CLASS
, "index term");
2867 expand_mult (GET_MODE (*ad
->index
), *ad
->index_term
,
2868 GEN_INT (get_index_scale (ad
)), new_reg
, 1);
2872 /* Return true if we can add a displacement to address AD, even if that
2873 makes the address invalid. The fix-up code requires any new address
2874 to be the sum of the BASE_TERM, INDEX and DISP_TERM fields. */
2876 can_add_disp_p (struct address_info
*ad
)
2878 return (!ad
->autoinc_p
2879 && ad
->segment
== NULL
2880 && ad
->base
== ad
->base_term
2881 && ad
->disp
== ad
->disp_term
);
2884 /* Make equiv substitution in address AD. Return true if a substitution
2887 equiv_address_substitution (struct address_info
*ad
)
2889 rtx base_reg
, new_base_reg
, index_reg
, new_index_reg
, *base_term
, *index_term
;
2890 HOST_WIDE_INT disp
, scale
;
2893 base_term
= strip_subreg (ad
->base_term
);
2894 if (base_term
== NULL
)
2895 base_reg
= new_base_reg
= NULL_RTX
;
2898 base_reg
= *base_term
;
2899 new_base_reg
= get_equiv_with_elimination (base_reg
, curr_insn
);
2901 index_term
= strip_subreg (ad
->index_term
);
2902 if (index_term
== NULL
)
2903 index_reg
= new_index_reg
= NULL_RTX
;
2906 index_reg
= *index_term
;
2907 new_index_reg
= get_equiv_with_elimination (index_reg
, curr_insn
);
2909 if (base_reg
== new_base_reg
&& index_reg
== new_index_reg
)
2913 if (lra_dump_file
!= NULL
)
2915 fprintf (lra_dump_file
, "Changing address in insn %d ",
2916 INSN_UID (curr_insn
));
2917 dump_value_slim (lra_dump_file
, *ad
->outer
, 1);
2919 if (base_reg
!= new_base_reg
)
2921 if (REG_P (new_base_reg
))
2923 *base_term
= new_base_reg
;
2926 else if (GET_CODE (new_base_reg
) == PLUS
2927 && REG_P (XEXP (new_base_reg
, 0))
2928 && CONST_INT_P (XEXP (new_base_reg
, 1))
2929 && can_add_disp_p (ad
))
2931 disp
+= INTVAL (XEXP (new_base_reg
, 1));
2932 *base_term
= XEXP (new_base_reg
, 0);
2935 if (ad
->base_term2
!= NULL
)
2936 *ad
->base_term2
= *ad
->base_term
;
2938 if (index_reg
!= new_index_reg
)
2940 if (REG_P (new_index_reg
))
2942 *index_term
= new_index_reg
;
2945 else if (GET_CODE (new_index_reg
) == PLUS
2946 && REG_P (XEXP (new_index_reg
, 0))
2947 && CONST_INT_P (XEXP (new_index_reg
, 1))
2948 && can_add_disp_p (ad
)
2949 && (scale
= get_index_scale (ad
)))
2951 disp
+= INTVAL (XEXP (new_index_reg
, 1)) * scale
;
2952 *index_term
= XEXP (new_index_reg
, 0);
2958 if (ad
->disp
!= NULL
)
2959 *ad
->disp
= plus_constant (GET_MODE (*ad
->inner
), *ad
->disp
, disp
);
2962 *ad
->inner
= plus_constant (GET_MODE (*ad
->inner
), *ad
->inner
, disp
);
2963 update_address (ad
);
2967 if (lra_dump_file
!= NULL
)
2970 fprintf (lra_dump_file
, " -- no change\n");
2973 fprintf (lra_dump_file
, " on equiv ");
2974 dump_value_slim (lra_dump_file
, *ad
->outer
, 1);
2975 fprintf (lra_dump_file
, "\n");
2981 /* Major function to make reloads for an address in operand NOP or
2982 check its correctness (If CHECK_ONLY_P is true). The supported
2985 1) an address that existed before LRA started, at which point it
2986 must have been valid. These addresses are subject to elimination
2987 and may have become invalid due to the elimination offset being out
2990 2) an address created by forcing a constant to memory
2991 (force_const_to_mem). The initial form of these addresses might
2992 not be valid, and it is this function's job to make them valid.
2994 3) a frame address formed from a register and a (possibly zero)
2995 constant offset. As above, these addresses might not be valid and
2996 this function must make them so.
2998 Add reloads to the lists *BEFORE and *AFTER. We might need to add
2999 reloads to *AFTER because of inc/dec, {pre, post} modify in the
3000 address. Return true for any RTL change.
3002 The function is a helper function which does not produce all
3003 transformations (when CHECK_ONLY_P is false) which can be
3004 necessary. It does just basic steps. To do all necessary
3005 transformations use function process_address. */
3007 process_address_1 (int nop
, bool check_only_p
,
3008 rtx_insn
**before
, rtx_insn
**after
)
3010 struct address_info ad
;
3012 HOST_WIDE_INT scale
;
3013 rtx op
= *curr_id
->operand_loc
[nop
];
3014 const char *constraint
= curr_static_id
->operand
[nop
].constraint
;
3015 enum constraint_num cn
= lookup_constraint (constraint
);
3016 bool change_p
= false;
3019 && GET_MODE (op
) == BLKmode
3020 && GET_CODE (XEXP (op
, 0)) == SCRATCH
)
3023 if (insn_extra_address_constraint (cn
))
3024 decompose_lea_address (&ad
, curr_id
->operand_loc
[nop
]);
3025 else if (MEM_P (op
))
3026 decompose_mem_address (&ad
, op
);
3027 else if (GET_CODE (op
) == SUBREG
3028 && MEM_P (SUBREG_REG (op
)))
3029 decompose_mem_address (&ad
, SUBREG_REG (op
));
3032 /* If INDEX_REG_CLASS is assigned to base_term already and isn't to
3033 index_term, swap them so to avoid assigning INDEX_REG_CLASS to both
3034 when INDEX_REG_CLASS is a single register class. */
3035 if (ad
.base_term
!= NULL
3036 && ad
.index_term
!= NULL
3037 && ira_class_hard_regs_num
[INDEX_REG_CLASS
] == 1
3038 && REG_P (*ad
.base_term
)
3039 && REG_P (*ad
.index_term
)
3040 && in_class_p (*ad
.base_term
, INDEX_REG_CLASS
, NULL
)
3041 && ! in_class_p (*ad
.index_term
, INDEX_REG_CLASS
, NULL
))
3043 std::swap (ad
.base
, ad
.index
);
3044 std::swap (ad
.base_term
, ad
.index_term
);
3047 change_p
= equiv_address_substitution (&ad
);
3048 if (ad
.base_term
!= NULL
3049 && (process_addr_reg
3050 (ad
.base_term
, check_only_p
, before
,
3052 && !(REG_P (*ad
.base_term
)
3053 && find_regno_note (curr_insn
, REG_DEAD
,
3054 REGNO (*ad
.base_term
)) != NULL_RTX
)
3056 base_reg_class (ad
.mode
, ad
.as
, ad
.base_outer_code
,
3057 get_index_code (&ad
)))))
3060 if (ad
.base_term2
!= NULL
)
3061 *ad
.base_term2
= *ad
.base_term
;
3063 if (ad
.index_term
!= NULL
3064 && process_addr_reg (ad
.index_term
, check_only_p
,
3065 before
, NULL
, INDEX_REG_CLASS
))
3068 /* Target hooks sometimes don't treat extra-constraint addresses as
3069 legitimate address_operands, so handle them specially. */
3070 if (insn_extra_address_constraint (cn
)
3071 && satisfies_address_constraint_p (&ad
, cn
))
3077 /* There are three cases where the shape of *AD.INNER may now be invalid:
3079 1) the original address was valid, but either elimination or
3080 equiv_address_substitution was applied and that made
3081 the address invalid.
3083 2) the address is an invalid symbolic address created by
3086 3) the address is a frame address with an invalid offset.
3088 4) the address is a frame address with an invalid base.
3090 All these cases involve a non-autoinc address, so there is no
3091 point revalidating other types. */
3092 if (ad
.autoinc_p
|| valid_address_p (&ad
))
3095 /* Any index existed before LRA started, so we can assume that the
3096 presence and shape of the index is valid. */
3097 push_to_sequence (*before
);
3098 lra_assert (ad
.disp
== ad
.disp_term
);
3099 if (ad
.base
== NULL
)
3101 if (ad
.index
== NULL
)
3104 rtx_insn
*last
= get_last_insn ();
3106 enum reg_class cl
= base_reg_class (ad
.mode
, ad
.as
,
3108 rtx addr
= *ad
.inner
;
3110 new_reg
= lra_create_new_reg (Pmode
, NULL_RTX
, cl
, "addr");
3113 /* addr => lo_sum (new_base, addr), case (2) above. */
3114 insn
= emit_insn (gen_rtx_SET
3116 gen_rtx_HIGH (Pmode
, copy_rtx (addr
))));
3117 code
= recog_memoized (insn
);
3120 *ad
.inner
= gen_rtx_LO_SUM (Pmode
, new_reg
, addr
);
3121 if (! valid_address_p (ad
.mode
, *ad
.outer
, ad
.as
))
3123 /* Try to put lo_sum into register. */
3124 insn
= emit_insn (gen_rtx_SET
3126 gen_rtx_LO_SUM (Pmode
, new_reg
, addr
)));
3127 code
= recog_memoized (insn
);
3130 *ad
.inner
= new_reg
;
3131 if (! valid_address_p (ad
.mode
, *ad
.outer
, ad
.as
))
3141 delete_insns_since (last
);
3146 /* addr => new_base, case (2) above. */
3147 lra_emit_move (new_reg
, addr
);
3149 for (insn
= last
== NULL_RTX
? get_insns () : NEXT_INSN (last
);
3151 insn
= NEXT_INSN (insn
))
3152 if (recog_memoized (insn
) < 0)
3154 if (insn
!= NULL_RTX
)
3156 /* Do nothing if we cannot generate right insns.
3157 This is analogous to reload pass behavior. */
3158 delete_insns_since (last
);
3162 *ad
.inner
= new_reg
;
3167 /* index * scale + disp => new base + index * scale,
3169 enum reg_class cl
= base_reg_class (ad
.mode
, ad
.as
, PLUS
,
3170 GET_CODE (*ad
.index
));
3172 lra_assert (INDEX_REG_CLASS
!= NO_REGS
);
3173 new_reg
= lra_create_new_reg (Pmode
, NULL_RTX
, cl
, "disp");
3174 lra_emit_move (new_reg
, *ad
.disp
);
3175 *ad
.inner
= simplify_gen_binary (PLUS
, GET_MODE (new_reg
),
3176 new_reg
, *ad
.index
);
3179 else if (ad
.index
== NULL
)
3184 rtx_insn
*insns
, *last_insn
;
3185 /* Try to reload base into register only if the base is invalid
3186 for the address but with valid offset, case (4) above. */
3188 new_reg
= base_to_reg (&ad
);
3190 /* base + disp => new base, cases (1) and (3) above. */
3191 /* Another option would be to reload the displacement into an
3192 index register. However, postreload has code to optimize
3193 address reloads that have the same base and different
3194 displacements, so reloading into an index register would
3195 not necessarily be a win. */
3196 if (new_reg
== NULL_RTX
)
3197 new_reg
= base_plus_disp_to_reg (&ad
);
3198 insns
= get_insns ();
3199 last_insn
= get_last_insn ();
3200 /* If we generated at least two insns, try last insn source as
3201 an address. If we succeed, we generate one less insn. */
3202 if (last_insn
!= insns
&& (set
= single_set (last_insn
)) != NULL_RTX
3203 && GET_CODE (SET_SRC (set
)) == PLUS
3204 && REG_P (XEXP (SET_SRC (set
), 0))
3205 && CONSTANT_P (XEXP (SET_SRC (set
), 1)))
3207 *ad
.inner
= SET_SRC (set
);
3208 if (valid_address_p (ad
.mode
, *ad
.outer
, ad
.as
))
3210 *ad
.base_term
= XEXP (SET_SRC (set
), 0);
3211 *ad
.disp_term
= XEXP (SET_SRC (set
), 1);
3212 cl
= base_reg_class (ad
.mode
, ad
.as
, ad
.base_outer_code
,
3213 get_index_code (&ad
));
3214 regno
= REGNO (*ad
.base_term
);
3215 if (regno
>= FIRST_PSEUDO_REGISTER
3216 && cl
!= lra_get_allocno_class (regno
))
3217 lra_change_class (regno
, cl
, " Change to", true);
3218 new_reg
= SET_SRC (set
);
3219 delete_insns_since (PREV_INSN (last_insn
));
3222 /* Try if target can split displacement into legitimite new disp
3223 and offset. If it's the case, we replace the last insn with
3224 insns for base + offset => new_reg and set new_reg + new disp
3226 last_insn
= get_last_insn ();
3227 if ((set
= single_set (last_insn
)) != NULL_RTX
3228 && GET_CODE (SET_SRC (set
)) == PLUS
3229 && REG_P (XEXP (SET_SRC (set
), 0))
3230 && REGNO (XEXP (SET_SRC (set
), 0)) < FIRST_PSEUDO_REGISTER
3231 && CONST_INT_P (XEXP (SET_SRC (set
), 1)))
3233 rtx addend
, disp
= XEXP (SET_SRC (set
), 1);
3234 if (targetm
.legitimize_address_displacement (&disp
, &addend
,
3237 rtx_insn
*new_insns
;
3239 lra_emit_add (new_reg
, XEXP (SET_SRC (set
), 0), addend
);
3240 new_insns
= get_insns ();
3242 new_reg
= gen_rtx_PLUS (Pmode
, new_reg
, disp
);
3243 delete_insns_since (PREV_INSN (last_insn
));
3244 add_insn (new_insns
);
3245 insns
= get_insns ();
3250 *ad
.inner
= new_reg
;
3252 else if (ad
.disp_term
!= NULL
)
3254 /* base + scale * index + disp => new base + scale * index,
3256 new_reg
= base_plus_disp_to_reg (&ad
);
3257 *ad
.inner
= simplify_gen_binary (PLUS
, GET_MODE (new_reg
),
3258 new_reg
, *ad
.index
);
3260 else if ((scale
= get_index_scale (&ad
)) == 1)
3262 /* The last transformation to one reg will be made in
3263 curr_insn_transform function. */
3267 else if (scale
!= 0)
3269 /* base + scale * index => base + new_reg,
3271 Index part of address may become invalid. For example, we
3272 changed pseudo on the equivalent memory and a subreg of the
3273 pseudo onto the memory of different mode for which the scale is
3275 new_reg
= index_part_to_reg (&ad
);
3276 *ad
.inner
= simplify_gen_binary (PLUS
, GET_MODE (new_reg
),
3277 *ad
.base_term
, new_reg
);
3281 enum reg_class cl
= base_reg_class (ad
.mode
, ad
.as
,
3283 rtx addr
= *ad
.inner
;
3285 new_reg
= lra_create_new_reg (Pmode
, NULL_RTX
, cl
, "addr");
3286 /* addr => new_base. */
3287 lra_emit_move (new_reg
, addr
);
3288 *ad
.inner
= new_reg
;
3290 *before
= get_insns ();
3295 /* If CHECK_ONLY_P is false, do address reloads until it is necessary.
3296 Use process_address_1 as a helper function. Return true for any
3299 If CHECK_ONLY_P is true, just check address correctness. Return
3300 false if the address correct. */
3302 process_address (int nop
, bool check_only_p
,
3303 rtx_insn
**before
, rtx_insn
**after
)
3307 while (process_address_1 (nop
, check_only_p
, before
, after
))
3316 /* Emit insns to reload VALUE into a new register. VALUE is an
3317 auto-increment or auto-decrement RTX whose operand is a register or
3318 memory location; so reloading involves incrementing that location.
3319 IN is either identical to VALUE, or some cheaper place to reload
3320 value being incremented/decremented from.
3322 INC_AMOUNT is the number to increment or decrement by (always
3323 positive and ignored for POST_MODIFY/PRE_MODIFY).
3325 Return pseudo containing the result. */
3327 emit_inc (enum reg_class new_rclass
, rtx in
, rtx value
, int inc_amount
)
3329 /* REG or MEM to be copied and incremented. */
3330 rtx incloc
= XEXP (value
, 0);
3331 /* Nonzero if increment after copying. */
3332 int post
= (GET_CODE (value
) == POST_DEC
|| GET_CODE (value
) == POST_INC
3333 || GET_CODE (value
) == POST_MODIFY
);
3338 rtx real_in
= in
== value
? incloc
: in
;
3342 if (GET_CODE (value
) == PRE_MODIFY
|| GET_CODE (value
) == POST_MODIFY
)
3344 lra_assert (GET_CODE (XEXP (value
, 1)) == PLUS
3345 || GET_CODE (XEXP (value
, 1)) == MINUS
);
3346 lra_assert (rtx_equal_p (XEXP (XEXP (value
, 1), 0), XEXP (value
, 0)));
3347 plus_p
= GET_CODE (XEXP (value
, 1)) == PLUS
;
3348 inc
= XEXP (XEXP (value
, 1), 1);
3352 if (GET_CODE (value
) == PRE_DEC
|| GET_CODE (value
) == POST_DEC
)
3353 inc_amount
= -inc_amount
;
3355 inc
= GEN_INT (inc_amount
);
3358 if (! post
&& REG_P (incloc
))
3361 result
= lra_create_new_reg (GET_MODE (value
), value
, new_rclass
,
3364 if (real_in
!= result
)
3366 /* First copy the location to the result register. */
3367 lra_assert (REG_P (result
));
3368 emit_insn (gen_move_insn (result
, real_in
));
3371 /* We suppose that there are insns to add/sub with the constant
3372 increment permitted in {PRE/POST)_{DEC/INC/MODIFY}. At least the
3373 old reload worked with this assumption. If the assumption
3374 becomes wrong, we should use approach in function
3375 base_plus_disp_to_reg. */
3378 /* See if we can directly increment INCLOC. */
3379 last
= get_last_insn ();
3380 add_insn
= emit_insn (plus_p
3381 ? gen_add2_insn (incloc
, inc
)
3382 : gen_sub2_insn (incloc
, inc
));
3384 code
= recog_memoized (add_insn
);
3387 if (! post
&& result
!= incloc
)
3388 emit_insn (gen_move_insn (result
, incloc
));
3391 delete_insns_since (last
);
3394 /* If couldn't do the increment directly, must increment in RESULT.
3395 The way we do this depends on whether this is pre- or
3396 post-increment. For pre-increment, copy INCLOC to the reload
3397 register, increment it there, then save back. */
3400 if (real_in
!= result
)
3401 emit_insn (gen_move_insn (result
, real_in
));
3403 emit_insn (gen_add2_insn (result
, inc
));
3405 emit_insn (gen_sub2_insn (result
, inc
));
3406 if (result
!= incloc
)
3407 emit_insn (gen_move_insn (incloc
, result
));
3413 Because this might be a jump insn or a compare, and because
3414 RESULT may not be available after the insn in an input
3415 reload, we must do the incrementing before the insn being
3418 We have already copied IN to RESULT. Increment the copy in
3419 RESULT, save that back, then decrement RESULT so it has
3420 the original value. */
3422 emit_insn (gen_add2_insn (result
, inc
));
3424 emit_insn (gen_sub2_insn (result
, inc
));
3425 emit_insn (gen_move_insn (incloc
, result
));
3426 /* Restore non-modified value for the result. We prefer this
3427 way because it does not require an additional hard
3431 if (CONST_INT_P (inc
))
3432 emit_insn (gen_add2_insn (result
,
3433 gen_int_mode (-INTVAL (inc
),
3434 GET_MODE (result
))));
3436 emit_insn (gen_sub2_insn (result
, inc
));
3439 emit_insn (gen_add2_insn (result
, inc
));
3444 /* Return true if the current move insn does not need processing as we
3445 already know that it satisfies its constraints. */
3447 simple_move_p (void)
3450 enum reg_class dclass
, sclass
;
3452 lra_assert (curr_insn_set
!= NULL_RTX
);
3453 dest
= SET_DEST (curr_insn_set
);
3454 src
= SET_SRC (curr_insn_set
);
3455 return ((dclass
= get_op_class (dest
)) != NO_REGS
3456 && (sclass
= get_op_class (src
)) != NO_REGS
3457 /* The backend guarantees that register moves of cost 2
3458 never need reloads. */
3459 && targetm
.register_move_cost (GET_MODE (src
), sclass
, dclass
) == 2);
3462 /* Swap operands NOP and NOP + 1. */
3464 swap_operands (int nop
)
3466 std::swap (curr_operand_mode
[nop
], curr_operand_mode
[nop
+ 1]);
3467 std::swap (original_subreg_reg_mode
[nop
], original_subreg_reg_mode
[nop
+ 1]);
3468 std::swap (*curr_id
->operand_loc
[nop
], *curr_id
->operand_loc
[nop
+ 1]);
3469 std::swap (equiv_substition_p
[nop
], equiv_substition_p
[nop
+ 1]);
3470 /* Swap the duplicates too. */
3471 lra_update_dup (curr_id
, nop
);
3472 lra_update_dup (curr_id
, nop
+ 1);
3475 /* Main entry point of the constraint code: search the body of the
3476 current insn to choose the best alternative. It is mimicking insn
3477 alternative cost calculation model of former reload pass. That is
3478 because machine descriptions were written to use this model. This
3479 model can be changed in future. Make commutative operand exchange
3482 if CHECK_ONLY_P is false, do RTL changes to satisfy the
3483 constraints. Return true if any change happened during function
3486 If CHECK_ONLY_P is true then don't do any transformation. Just
3487 check that the insn satisfies all constraints. If the insn does
3488 not satisfy any constraint, return true. */
3490 curr_insn_transform (bool check_only_p
)
3497 signed char goal_alt_matched
[MAX_RECOG_OPERANDS
][MAX_RECOG_OPERANDS
];
3498 signed char match_inputs
[MAX_RECOG_OPERANDS
+ 1];
3499 signed char outputs
[MAX_RECOG_OPERANDS
+ 1];
3500 rtx_insn
*before
, *after
;
3502 /* Flag that the insn has been changed through a transformation. */
3505 #ifdef SECONDARY_MEMORY_NEEDED
3508 int max_regno_before
;
3509 int reused_alternative_num
;
3511 curr_insn_set
= single_set (curr_insn
);
3512 if (curr_insn_set
!= NULL_RTX
&& simple_move_p ())
3515 no_input_reloads_p
= no_output_reloads_p
= false;
3516 goal_alt_number
= -1;
3517 change_p
= sec_mem_p
= false;
3518 /* JUMP_INSNs and CALL_INSNs are not allowed to have any output
3519 reloads; neither are insns that SET cc0. Insns that use CC0 are
3520 not allowed to have any input reloads. */
3521 if (JUMP_P (curr_insn
) || CALL_P (curr_insn
))
3522 no_output_reloads_p
= true;
3524 if (HAVE_cc0
&& reg_referenced_p (cc0_rtx
, PATTERN (curr_insn
)))
3525 no_input_reloads_p
= true;
3526 if (HAVE_cc0
&& reg_set_p (cc0_rtx
, PATTERN (curr_insn
)))
3527 no_output_reloads_p
= true;
3529 n_operands
= curr_static_id
->n_operands
;
3530 n_alternatives
= curr_static_id
->n_alternatives
;
3532 /* Just return "no reloads" if insn has no operands with
3534 if (n_operands
== 0 || n_alternatives
== 0)
3537 max_regno_before
= max_reg_num ();
3539 for (i
= 0; i
< n_operands
; i
++)
3541 goal_alt_matched
[i
][0] = -1;
3542 goal_alt_matches
[i
] = -1;
3545 commutative
= curr_static_id
->commutative
;
3547 /* Now see what we need for pseudos that didn't get hard regs or got
3548 the wrong kind of hard reg. For this, we must consider all the
3549 operands together against the register constraints. */
3551 best_losers
= best_overall
= INT_MAX
;
3552 best_reload_sum
= 0;
3554 curr_swapped
= false;
3555 goal_alt_swapped
= false;
3558 /* Make equivalence substitution and memory subreg elimination
3559 before address processing because an address legitimacy can
3560 depend on memory mode. */
3561 for (i
= 0; i
< n_operands
; i
++)
3564 bool op_change_p
= false;
3566 if (curr_static_id
->operand
[i
].is_operator
)
3569 old
= op
= *curr_id
->operand_loc
[i
];
3570 if (GET_CODE (old
) == SUBREG
)
3571 old
= SUBREG_REG (old
);
3572 subst
= get_equiv_with_elimination (old
, curr_insn
);
3573 original_subreg_reg_mode
[i
] = VOIDmode
;
3574 equiv_substition_p
[i
] = false;
3577 equiv_substition_p
[i
] = true;
3578 subst
= copy_rtx (subst
);
3579 lra_assert (REG_P (old
));
3580 if (GET_CODE (op
) != SUBREG
)
3581 *curr_id
->operand_loc
[i
] = subst
;
3584 SUBREG_REG (op
) = subst
;
3585 if (GET_MODE (subst
) == VOIDmode
)
3586 original_subreg_reg_mode
[i
] = GET_MODE (old
);
3588 if (lra_dump_file
!= NULL
)
3590 fprintf (lra_dump_file
,
3591 "Changing pseudo %d in operand %i of insn %u on equiv ",
3592 REGNO (old
), i
, INSN_UID (curr_insn
));
3593 dump_value_slim (lra_dump_file
, subst
, 1);
3594 fprintf (lra_dump_file
, "\n");
3596 op_change_p
= change_p
= true;
3598 if (simplify_operand_subreg (i
, GET_MODE (old
)) || op_change_p
)
3601 lra_update_dup (curr_id
, i
);
3605 /* Reload address registers and displacements. We do it before
3606 finding an alternative because of memory constraints. */
3607 before
= after
= NULL
;
3608 for (i
= 0; i
< n_operands
; i
++)
3609 if (! curr_static_id
->operand
[i
].is_operator
3610 && process_address (i
, check_only_p
, &before
, &after
))
3615 lra_update_dup (curr_id
, i
);
3619 /* If we've changed the instruction then any alternative that
3620 we chose previously may no longer be valid. */
3621 lra_set_used_insn_alternative (curr_insn
, -1);
3623 if (! check_only_p
&& curr_insn_set
!= NULL_RTX
3624 && check_and_process_move (&change_p
, &sec_mem_p
))
3629 reused_alternative_num
= check_only_p
? -1 : curr_id
->used_insn_alternative
;
3630 if (lra_dump_file
!= NULL
&& reused_alternative_num
>= 0)
3631 fprintf (lra_dump_file
, "Reusing alternative %d for insn #%u\n",
3632 reused_alternative_num
, INSN_UID (curr_insn
));
3634 if (process_alt_operands (reused_alternative_num
))
3638 return ! alt_p
|| best_losers
!= 0;
3640 /* If insn is commutative (it's safe to exchange a certain pair of
3641 operands) then we need to try each alternative twice, the second
3642 time matching those two operands as if we had exchanged them. To
3643 do this, really exchange them in operands.
3645 If we have just tried the alternatives the second time, return
3646 operands to normal and drop through. */
3648 if (reused_alternative_num
< 0 && commutative
>= 0)
3650 curr_swapped
= !curr_swapped
;
3653 swap_operands (commutative
);
3657 swap_operands (commutative
);
3660 if (! alt_p
&& ! sec_mem_p
)
3662 /* No alternative works with reloads?? */
3663 if (INSN_CODE (curr_insn
) >= 0)
3664 fatal_insn ("unable to generate reloads for:", curr_insn
);
3665 error_for_asm (curr_insn
,
3666 "inconsistent operand constraints in an %<asm%>");
3667 /* Avoid further trouble with this insn. */
3668 PATTERN (curr_insn
) = gen_rtx_USE (VOIDmode
, const0_rtx
);
3669 lra_invalidate_insn_data (curr_insn
);
3673 /* If the best alternative is with operands 1 and 2 swapped, swap
3674 them. Update the operand numbers of any reloads already
3677 if (goal_alt_swapped
)
3679 if (lra_dump_file
!= NULL
)
3680 fprintf (lra_dump_file
, " Commutative operand exchange in insn %u\n",
3681 INSN_UID (curr_insn
));
3683 /* Swap the duplicates too. */
3684 swap_operands (commutative
);
3688 #ifdef SECONDARY_MEMORY_NEEDED
3689 /* Some target macros SECONDARY_MEMORY_NEEDED (e.g. x86) are defined
3690 too conservatively. So we use the secondary memory only if there
3691 is no any alternative without reloads. */
3692 use_sec_mem_p
= false;
3694 use_sec_mem_p
= true;
3697 for (i
= 0; i
< n_operands
; i
++)
3698 if (! goal_alt_win
[i
] && ! goal_alt_match_win
[i
])
3700 use_sec_mem_p
= i
< n_operands
;
3705 int in
= -1, out
= -1;
3706 rtx new_reg
, src
, dest
, rld
;
3707 machine_mode sec_mode
, rld_mode
;
3709 lra_assert (curr_insn_set
!= NULL_RTX
&& sec_mem_p
);
3710 dest
= SET_DEST (curr_insn_set
);
3711 src
= SET_SRC (curr_insn_set
);
3712 for (i
= 0; i
< n_operands
; i
++)
3713 if (*curr_id
->operand_loc
[i
] == dest
)
3715 else if (*curr_id
->operand_loc
[i
] == src
)
3717 for (i
= 0; i
< curr_static_id
->n_dups
; i
++)
3718 if (out
< 0 && *curr_id
->dup_loc
[i
] == dest
)
3719 out
= curr_static_id
->dup_num
[i
];
3720 else if (in
< 0 && *curr_id
->dup_loc
[i
] == src
)
3721 in
= curr_static_id
->dup_num
[i
];
3722 lra_assert (out
>= 0 && in
>= 0
3723 && curr_static_id
->operand
[out
].type
== OP_OUT
3724 && curr_static_id
->operand
[in
].type
== OP_IN
);
3725 rld
= (GET_MODE_SIZE (GET_MODE (dest
)) <= GET_MODE_SIZE (GET_MODE (src
))
3727 rld_mode
= GET_MODE (rld
);
3728 #ifdef SECONDARY_MEMORY_NEEDED_MODE
3729 sec_mode
= SECONDARY_MEMORY_NEEDED_MODE (rld_mode
);
3731 sec_mode
= rld_mode
;
3733 new_reg
= lra_create_new_reg (sec_mode
, NULL_RTX
,
3734 NO_REGS
, "secondary");
3735 /* If the mode is changed, it should be wider. */
3736 lra_assert (GET_MODE_SIZE (sec_mode
) >= GET_MODE_SIZE (rld_mode
));
3737 if (sec_mode
!= rld_mode
)
3739 /* If the target says specifically to use another mode for
3740 secondary memory moves we can not reuse the original
3742 after
= emit_spill_move (false, new_reg
, dest
);
3743 lra_process_new_insns (curr_insn
, NULL
, after
,
3744 "Inserting the sec. move");
3745 /* We may have non null BEFORE here (e.g. after address
3747 push_to_sequence (before
);
3748 before
= emit_spill_move (true, new_reg
, src
);
3750 before
= get_insns ();
3752 lra_process_new_insns (curr_insn
, before
, NULL
, "Changing on");
3753 lra_set_insn_deleted (curr_insn
);
3755 else if (dest
== rld
)
3757 *curr_id
->operand_loc
[out
] = new_reg
;
3758 lra_update_dup (curr_id
, out
);
3759 after
= emit_spill_move (false, new_reg
, dest
);
3760 lra_process_new_insns (curr_insn
, NULL
, after
,
3761 "Inserting the sec. move");
3765 *curr_id
->operand_loc
[in
] = new_reg
;
3766 lra_update_dup (curr_id
, in
);
3767 /* See comments above. */
3768 push_to_sequence (before
);
3769 before
= emit_spill_move (true, new_reg
, src
);
3771 before
= get_insns ();
3773 lra_process_new_insns (curr_insn
, before
, NULL
,
3774 "Inserting the sec. move");
3776 lra_update_insn_regno_info (curr_insn
);
3781 lra_assert (goal_alt_number
>= 0);
3782 lra_set_used_insn_alternative (curr_insn
, goal_alt_number
);
3784 if (lra_dump_file
!= NULL
)
3788 fprintf (lra_dump_file
, " Choosing alt %d in insn %u:",
3789 goal_alt_number
, INSN_UID (curr_insn
));
3790 for (i
= 0; i
< n_operands
; i
++)
3792 p
= (curr_static_id
->operand_alternative
3793 [goal_alt_number
* n_operands
+ i
].constraint
);
3796 fprintf (lra_dump_file
, " (%d) ", i
);
3797 for (; *p
!= '\0' && *p
!= ',' && *p
!= '#'; p
++)
3798 fputc (*p
, lra_dump_file
);
3800 if (INSN_CODE (curr_insn
) >= 0
3801 && (p
= get_insn_name (INSN_CODE (curr_insn
))) != NULL
)
3802 fprintf (lra_dump_file
, " {%s}", p
);
3803 if (curr_id
->sp_offset
!= 0)
3804 fprintf (lra_dump_file
, " (sp_off=%" HOST_WIDE_INT_PRINT
"d)",
3805 curr_id
->sp_offset
);
3806 fprintf (lra_dump_file
, "\n");
3809 /* Right now, for any pair of operands I and J that are required to
3810 match, with J < I, goal_alt_matches[I] is J. Add I to
3811 goal_alt_matched[J]. */
3813 for (i
= 0; i
< n_operands
; i
++)
3814 if ((j
= goal_alt_matches
[i
]) >= 0)
3816 for (k
= 0; goal_alt_matched
[j
][k
] >= 0; k
++)
3818 /* We allow matching one output operand and several input
3821 || (curr_static_id
->operand
[j
].type
== OP_OUT
3822 && curr_static_id
->operand
[i
].type
== OP_IN
3823 && (curr_static_id
->operand
3824 [goal_alt_matched
[j
][0]].type
== OP_IN
)));
3825 goal_alt_matched
[j
][k
] = i
;
3826 goal_alt_matched
[j
][k
+ 1] = -1;
3829 for (i
= 0; i
< n_operands
; i
++)
3830 goal_alt_win
[i
] |= goal_alt_match_win
[i
];
3832 /* Any constants that aren't allowed and can't be reloaded into
3833 registers are here changed into memory references. */
3834 for (i
= 0; i
< n_operands
; i
++)
3835 if (goal_alt_win
[i
])
3838 enum reg_class new_class
;
3839 rtx reg
= *curr_id
->operand_loc
[i
];
3841 if (GET_CODE (reg
) == SUBREG
)
3842 reg
= SUBREG_REG (reg
);
3844 if (REG_P (reg
) && (regno
= REGNO (reg
)) >= FIRST_PSEUDO_REGISTER
)
3846 bool ok_p
= in_class_p (reg
, goal_alt
[i
], &new_class
);
3848 if (new_class
!= NO_REGS
&& get_reg_class (regno
) != new_class
)
3851 lra_change_class (regno
, new_class
, " Change to", true);
3857 const char *constraint
;
3859 rtx op
= *curr_id
->operand_loc
[i
];
3860 rtx subreg
= NULL_RTX
;
3861 machine_mode mode
= curr_operand_mode
[i
];
3863 if (GET_CODE (op
) == SUBREG
)
3866 op
= SUBREG_REG (op
);
3867 mode
= GET_MODE (op
);
3870 if (CONST_POOL_OK_P (mode
, op
)
3871 && ((targetm
.preferred_reload_class
3872 (op
, (enum reg_class
) goal_alt
[i
]) == NO_REGS
)
3873 || no_input_reloads_p
))
3875 rtx tem
= force_const_mem (mode
, op
);
3878 if (subreg
!= NULL_RTX
)
3879 tem
= gen_rtx_SUBREG (mode
, tem
, SUBREG_BYTE (subreg
));
3881 *curr_id
->operand_loc
[i
] = tem
;
3882 lra_update_dup (curr_id
, i
);
3883 process_address (i
, false, &before
, &after
);
3885 /* If the alternative accepts constant pool refs directly
3886 there will be no reload needed at all. */
3887 if (subreg
!= NULL_RTX
)
3889 /* Skip alternatives before the one requested. */
3890 constraint
= (curr_static_id
->operand_alternative
3891 [goal_alt_number
* n_operands
+ i
].constraint
);
3893 (c
= *constraint
) && c
!= ',' && c
!= '#';
3894 constraint
+= CONSTRAINT_LEN (c
, constraint
))
3896 enum constraint_num cn
= lookup_constraint (constraint
);
3897 if ((insn_extra_memory_constraint (cn
)
3898 || insn_extra_special_memory_constraint (cn
))
3899 && satisfies_memory_constraint_p (tem
, cn
))
3902 if (c
== '\0' || c
== ',' || c
== '#')
3905 goal_alt_win
[i
] = true;
3911 for (i
= 0; i
< n_operands
; i
++)
3914 bool optional_p
= false;
3916 rtx op
= *curr_id
->operand_loc
[i
];
3918 if (goal_alt_win
[i
])
3920 if (goal_alt
[i
] == NO_REGS
3922 /* When we assign NO_REGS it means that we will not
3923 assign a hard register to the scratch pseudo by
3924 assigment pass and the scratch pseudo will be
3925 spilled. Spilled scratch pseudos are transformed
3926 back to scratches at the LRA end. */
3927 && lra_former_scratch_operand_p (curr_insn
, i
)
3928 && lra_former_scratch_p (REGNO (op
)))
3930 int regno
= REGNO (op
);
3931 lra_change_class (regno
, NO_REGS
, " Change to", true);
3932 if (lra_get_regno_hard_regno (regno
) >= 0)
3933 /* We don't have to mark all insn affected by the
3934 spilled pseudo as there is only one such insn, the
3936 reg_renumber
[regno
] = -1;
3937 lra_assert (bitmap_single_bit_set_p
3938 (&lra_reg_info
[REGNO (op
)].insn_bitmap
));
3940 /* We can do an optional reload. If the pseudo got a hard
3941 reg, we might improve the code through inheritance. If
3942 it does not get a hard register we coalesce memory/memory
3943 moves later. Ignore move insns to avoid cycling. */
3945 && lra_undo_inheritance_iter
< LRA_MAX_INHERITANCE_PASSES
3946 && goal_alt
[i
] != NO_REGS
&& REG_P (op
)
3947 && (regno
= REGNO (op
)) >= FIRST_PSEUDO_REGISTER
3948 && regno
< new_regno_start
3949 && ! lra_former_scratch_p (regno
)
3950 && reg_renumber
[regno
] < 0
3951 /* Check that the optional reload pseudo will be able to
3952 hold given mode value. */
3953 && ! (prohibited_class_reg_set_mode_p
3954 (goal_alt
[i
], reg_class_contents
[goal_alt
[i
]],
3955 PSEUDO_REGNO_MODE (regno
)))
3956 && (curr_insn_set
== NULL_RTX
3957 || !((REG_P (SET_SRC (curr_insn_set
))
3958 || MEM_P (SET_SRC (curr_insn_set
))
3959 || GET_CODE (SET_SRC (curr_insn_set
)) == SUBREG
)
3960 && (REG_P (SET_DEST (curr_insn_set
))
3961 || MEM_P (SET_DEST (curr_insn_set
))
3962 || GET_CODE (SET_DEST (curr_insn_set
)) == SUBREG
))))
3968 /* Operands that match previous ones have already been handled. */
3969 if (goal_alt_matches
[i
] >= 0)
3972 /* We should not have an operand with a non-offsettable address
3973 appearing where an offsettable address will do. It also may
3974 be a case when the address should be special in other words
3975 not a general one (e.g. it needs no index reg). */
3976 if (goal_alt_matched
[i
][0] == -1 && goal_alt_offmemok
[i
] && MEM_P (op
))
3978 enum reg_class rclass
;
3979 rtx
*loc
= &XEXP (op
, 0);
3980 enum rtx_code code
= GET_CODE (*loc
);
3982 push_to_sequence (before
);
3983 rclass
= base_reg_class (GET_MODE (op
), MEM_ADDR_SPACE (op
),
3985 if (GET_RTX_CLASS (code
) == RTX_AUTOINC
)
3986 new_reg
= emit_inc (rclass
, *loc
, *loc
,
3987 /* This value does not matter for MODIFY. */
3988 GET_MODE_SIZE (GET_MODE (op
)));
3989 else if (get_reload_reg (OP_IN
, Pmode
, *loc
, rclass
, FALSE
,
3990 "offsetable address", &new_reg
))
3991 lra_emit_move (new_reg
, *loc
);
3992 before
= get_insns ();
3995 lra_update_dup (curr_id
, i
);
3997 else if (goal_alt_matched
[i
][0] == -1)
4001 int hard_regno
, byte
;
4002 enum op_type type
= curr_static_id
->operand
[i
].type
;
4004 loc
= curr_id
->operand_loc
[i
];
4005 mode
= curr_operand_mode
[i
];
4006 if (GET_CODE (*loc
) == SUBREG
)
4008 reg
= SUBREG_REG (*loc
);
4009 byte
= SUBREG_BYTE (*loc
);
4011 /* Strict_low_part requires reload the register not
4012 the sub-register. */
4013 && (curr_static_id
->operand
[i
].strict_low
4014 || (GET_MODE_SIZE (mode
)
4015 <= GET_MODE_SIZE (GET_MODE (reg
))
4017 = get_try_hard_regno (REGNO (reg
))) >= 0
4018 && (simplify_subreg_regno
4020 GET_MODE (reg
), byte
, mode
) < 0)
4021 && (goal_alt
[i
] == NO_REGS
4022 || (simplify_subreg_regno
4023 (ira_class_hard_regs
[goal_alt
[i
]][0],
4024 GET_MODE (reg
), byte
, mode
) >= 0)))))
4028 loc
= &SUBREG_REG (*loc
);
4029 mode
= GET_MODE (*loc
);
4033 if (get_reload_reg (type
, mode
, old
, goal_alt
[i
],
4034 loc
!= curr_id
->operand_loc
[i
], "", &new_reg
)
4037 push_to_sequence (before
);
4038 lra_emit_move (new_reg
, old
);
4039 before
= get_insns ();
4044 && find_reg_note (curr_insn
, REG_UNUSED
, old
) == NULL_RTX
)
4047 lra_emit_move (type
== OP_INOUT
? copy_rtx (old
) : old
, new_reg
);
4049 after
= get_insns ();
4053 for (j
= 0; j
< goal_alt_dont_inherit_ops_num
; j
++)
4054 if (goal_alt_dont_inherit_ops
[j
] == i
)
4056 lra_set_regno_unique_value (REGNO (new_reg
));
4059 lra_update_dup (curr_id
, i
);
4061 else if (curr_static_id
->operand
[i
].type
== OP_IN
4062 && (curr_static_id
->operand
[goal_alt_matched
[i
][0]].type
4065 /* generate reloads for input and matched outputs. */
4066 match_inputs
[0] = i
;
4067 match_inputs
[1] = -1;
4068 match_reload (goal_alt_matched
[i
][0], match_inputs
, outputs
,
4069 goal_alt
[i
], &before
, &after
,
4070 curr_static_id
->operand_alternative
4071 [goal_alt_number
* n_operands
+ goal_alt_matched
[i
][0]]
4074 else if (curr_static_id
->operand
[i
].type
== OP_OUT
4075 && (curr_static_id
->operand
[goal_alt_matched
[i
][0]].type
4077 /* Generate reloads for output and matched inputs. */
4078 match_reload (i
, goal_alt_matched
[i
], outputs
, goal_alt
[i
], &before
,
4079 &after
, curr_static_id
->operand_alternative
4080 [goal_alt_number
* n_operands
+ i
].earlyclobber
);
4081 else if (curr_static_id
->operand
[i
].type
== OP_IN
4082 && (curr_static_id
->operand
[goal_alt_matched
[i
][0]].type
4085 /* Generate reloads for matched inputs. */
4086 match_inputs
[0] = i
;
4087 for (j
= 0; (k
= goal_alt_matched
[i
][j
]) >= 0; j
++)
4088 match_inputs
[j
+ 1] = k
;
4089 match_inputs
[j
+ 1] = -1;
4090 match_reload (-1, match_inputs
, outputs
, goal_alt
[i
], &before
,
4094 /* We must generate code in any case when function
4095 process_alt_operands decides that it is possible. */
4098 /* Memorise processed outputs so that output remaining to be processed
4099 can avoid using the same register value (see match_reload). */
4100 if (curr_static_id
->operand
[i
].type
== OP_OUT
)
4102 outputs
[n_outputs
++] = i
;
4103 outputs
[n_outputs
] = -1;
4108 lra_assert (REG_P (op
));
4110 op
= *curr_id
->operand_loc
[i
]; /* Substitution. */
4111 if (GET_CODE (op
) == SUBREG
)
4112 op
= SUBREG_REG (op
);
4113 gcc_assert (REG_P (op
) && (int) REGNO (op
) >= new_regno_start
);
4114 bitmap_set_bit (&lra_optional_reload_pseudos
, REGNO (op
));
4115 lra_reg_info
[REGNO (op
)].restore_regno
= regno
;
4116 if (lra_dump_file
!= NULL
)
4117 fprintf (lra_dump_file
,
4118 " Making reload reg %d for reg %d optional\n",
4122 if (before
!= NULL_RTX
|| after
!= NULL_RTX
4123 || max_regno_before
!= max_reg_num ())
4127 lra_update_operator_dups (curr_id
);
4128 /* Something changes -- process the insn. */
4129 lra_update_insn_regno_info (curr_insn
);
4131 lra_process_new_insns (curr_insn
, before
, after
, "Inserting insn reload");
4135 /* Return true if INSN satisfies all constraints. In other words, no
4136 reload insns are needed. */
4138 lra_constrain_insn (rtx_insn
*insn
)
4140 int saved_new_regno_start
= new_regno_start
;
4141 int saved_new_insn_uid_start
= new_insn_uid_start
;
4145 curr_id
= lra_get_insn_recog_data (curr_insn
);
4146 curr_static_id
= curr_id
->insn_static_data
;
4147 new_insn_uid_start
= get_max_uid ();
4148 new_regno_start
= max_reg_num ();
4149 change_p
= curr_insn_transform (true);
4150 new_regno_start
= saved_new_regno_start
;
4151 new_insn_uid_start
= saved_new_insn_uid_start
;
4155 /* Return true if X is in LIST. */
4157 in_list_p (rtx x
, rtx list
)
4159 for (; list
!= NULL_RTX
; list
= XEXP (list
, 1))
4160 if (XEXP (list
, 0) == x
)
4165 /* Return true if X contains an allocatable hard register (if
4166 HARD_REG_P) or a (spilled if SPILLED_P) pseudo. */
4168 contains_reg_p (rtx x
, bool hard_reg_p
, bool spilled_p
)
4174 code
= GET_CODE (x
);
4177 int regno
= REGNO (x
);
4178 HARD_REG_SET alloc_regs
;
4182 if (regno
>= FIRST_PSEUDO_REGISTER
)
4183 regno
= lra_get_regno_hard_regno (regno
);
4186 COMPL_HARD_REG_SET (alloc_regs
, lra_no_alloc_regs
);
4187 return overlaps_hard_reg_set_p (alloc_regs
, GET_MODE (x
), regno
);
4191 if (regno
< FIRST_PSEUDO_REGISTER
)
4195 return lra_get_regno_hard_regno (regno
) < 0;
4198 fmt
= GET_RTX_FORMAT (code
);
4199 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
4203 if (contains_reg_p (XEXP (x
, i
), hard_reg_p
, spilled_p
))
4206 else if (fmt
[i
] == 'E')
4208 for (j
= XVECLEN (x
, i
) - 1; j
>= 0; j
--)
4209 if (contains_reg_p (XVECEXP (x
, i
, j
), hard_reg_p
, spilled_p
))
4216 /* Process all regs in location *LOC and change them on equivalent
4217 substitution. Return true if any change was done. */
4219 loc_equivalence_change_p (rtx
*loc
)
4221 rtx subst
, reg
, x
= *loc
;
4222 bool result
= false;
4223 enum rtx_code code
= GET_CODE (x
);
4229 reg
= SUBREG_REG (x
);
4230 if ((subst
= get_equiv_with_elimination (reg
, curr_insn
)) != reg
4231 && GET_MODE (subst
) == VOIDmode
)
4233 /* We cannot reload debug location. Simplify subreg here
4234 while we know the inner mode. */
4235 *loc
= simplify_gen_subreg (GET_MODE (x
), subst
,
4236 GET_MODE (reg
), SUBREG_BYTE (x
));
4240 if (code
== REG
&& (subst
= get_equiv_with_elimination (x
, curr_insn
)) != x
)
4246 /* Scan all the operand sub-expressions. */
4247 fmt
= GET_RTX_FORMAT (code
);
4248 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
4251 result
= loc_equivalence_change_p (&XEXP (x
, i
)) || result
;
4252 else if (fmt
[i
] == 'E')
4253 for (j
= XVECLEN (x
, i
) - 1; j
>= 0; j
--)
4255 = loc_equivalence_change_p (&XVECEXP (x
, i
, j
)) || result
;
4260 /* Similar to loc_equivalence_change_p, but for use as
4261 simplify_replace_fn_rtx callback. DATA is insn for which the
4262 elimination is done. If it null we don't do the elimination. */
4264 loc_equivalence_callback (rtx loc
, const_rtx
, void *data
)
4269 rtx subst
= (data
== NULL
4270 ? get_equiv (loc
) : get_equiv_with_elimination (loc
, (rtx_insn
*) data
));
4277 /* Maximum number of generated reload insns per an insn. It is for
4278 preventing this pass cycling in a bug case. */
4279 #define MAX_RELOAD_INSNS_NUMBER LRA_MAX_INSN_RELOADS
4281 /* The current iteration number of this LRA pass. */
4282 int lra_constraint_iter
;
4284 /* True if we substituted equiv which needs checking register
4285 allocation correctness because the equivalent value contains
4286 allocatable hard registers or when we restore multi-register
4288 bool lra_risky_transformations_p
;
4290 /* Return true if REGNO is referenced in more than one block. */
4292 multi_block_pseudo_p (int regno
)
4294 basic_block bb
= NULL
;
4298 if (regno
< FIRST_PSEUDO_REGISTER
)
4301 EXECUTE_IF_SET_IN_BITMAP (&lra_reg_info
[regno
].insn_bitmap
, 0, uid
, bi
)
4303 bb
= BLOCK_FOR_INSN (lra_insn_recog_data
[uid
]->insn
);
4304 else if (BLOCK_FOR_INSN (lra_insn_recog_data
[uid
]->insn
) != bb
)
4309 /* Return true if LIST contains a deleted insn. */
4311 contains_deleted_insn_p (rtx_insn_list
*list
)
4313 for (; list
!= NULL_RTX
; list
= list
->next ())
4314 if (NOTE_P (list
->insn ())
4315 && NOTE_KIND (list
->insn ()) == NOTE_INSN_DELETED
)
4320 /* Return true if X contains a pseudo dying in INSN. */
4322 dead_pseudo_p (rtx x
, rtx_insn
*insn
)
4329 return (insn
!= NULL_RTX
4330 && find_regno_note (insn
, REG_DEAD
, REGNO (x
)) != NULL_RTX
);
4331 code
= GET_CODE (x
);
4332 fmt
= GET_RTX_FORMAT (code
);
4333 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
4337 if (dead_pseudo_p (XEXP (x
, i
), insn
))
4340 else if (fmt
[i
] == 'E')
4342 for (j
= XVECLEN (x
, i
) - 1; j
>= 0; j
--)
4343 if (dead_pseudo_p (XVECEXP (x
, i
, j
), insn
))
4350 /* Return true if INSN contains a dying pseudo in INSN right hand
4353 insn_rhs_dead_pseudo_p (rtx_insn
*insn
)
4355 rtx set
= single_set (insn
);
4357 gcc_assert (set
!= NULL
);
4358 return dead_pseudo_p (SET_SRC (set
), insn
);
4361 /* Return true if any init insn of REGNO contains a dying pseudo in
4362 insn right hand side. */
4364 init_insn_rhs_dead_pseudo_p (int regno
)
4366 rtx_insn_list
*insns
= ira_reg_equiv
[regno
].init_insns
;
4370 for (; insns
!= NULL_RTX
; insns
= insns
->next ())
4371 if (insn_rhs_dead_pseudo_p (insns
->insn ()))
4376 /* Return TRUE if REGNO has a reverse equivalence. The equivalence is
4377 reverse only if we have one init insn with given REGNO as a
4380 reverse_equiv_p (int regno
)
4382 rtx_insn_list
*insns
= ira_reg_equiv
[regno
].init_insns
;
4387 if (! INSN_P (insns
->insn ())
4388 || insns
->next () != NULL
)
4390 if ((set
= single_set (insns
->insn ())) == NULL_RTX
)
4392 return REG_P (SET_SRC (set
)) && (int) REGNO (SET_SRC (set
)) == regno
;
4395 /* Return TRUE if REGNO was reloaded in an equivalence init insn. We
4396 call this function only for non-reverse equivalence. */
4398 contains_reloaded_insn_p (int regno
)
4401 rtx_insn_list
*list
= ira_reg_equiv
[regno
].init_insns
;
4403 for (; list
!= NULL
; list
= list
->next ())
4404 if ((set
= single_set (list
->insn ())) == NULL_RTX
4405 || ! REG_P (SET_DEST (set
))
4406 || (int) REGNO (SET_DEST (set
)) != regno
)
4411 /* Entry function of LRA constraint pass. Return true if the
4412 constraint pass did change the code. */
4414 lra_constraints (bool first_p
)
4417 int i
, hard_regno
, new_insns_num
;
4418 unsigned int min_len
, new_min_len
, uid
;
4419 rtx set
, x
, reg
, dest_reg
;
4420 basic_block last_bb
;
4421 bitmap_head equiv_insn_bitmap
;
4424 lra_constraint_iter
++;
4425 if (lra_dump_file
!= NULL
)
4426 fprintf (lra_dump_file
, "\n********** Local #%d: **********\n\n",
4427 lra_constraint_iter
);
4429 if (pic_offset_table_rtx
4430 && REGNO (pic_offset_table_rtx
) >= FIRST_PSEUDO_REGISTER
)
4431 lra_risky_transformations_p
= true;
4433 lra_risky_transformations_p
= false;
4434 new_insn_uid_start
= get_max_uid ();
4435 new_regno_start
= first_p
? lra_constraint_new_regno_start
: max_reg_num ();
4436 /* Mark used hard regs for target stack size calulations. */
4437 for (i
= FIRST_PSEUDO_REGISTER
; i
< new_regno_start
; i
++)
4438 if (lra_reg_info
[i
].nrefs
!= 0
4439 && (hard_regno
= lra_get_regno_hard_regno (i
)) >= 0)
4443 nregs
= hard_regno_nregs
[hard_regno
][lra_reg_info
[i
].biggest_mode
];
4444 for (j
= 0; j
< nregs
; j
++)
4445 df_set_regs_ever_live (hard_regno
+ j
, true);
4447 /* Do elimination before the equivalence processing as we can spill
4448 some pseudos during elimination. */
4449 lra_eliminate (false, first_p
);
4450 bitmap_initialize (&equiv_insn_bitmap
, ®_obstack
);
4451 for (i
= FIRST_PSEUDO_REGISTER
; i
< new_regno_start
; i
++)
4452 if (lra_reg_info
[i
].nrefs
!= 0)
4454 ira_reg_equiv
[i
].profitable_p
= true;
4455 reg
= regno_reg_rtx
[i
];
4456 if (lra_get_regno_hard_regno (i
) < 0 && (x
= get_equiv (reg
)) != reg
)
4458 bool pseudo_p
= contains_reg_p (x
, false, false);
4460 /* After RTL transformation, we can not guarantee that
4461 pseudo in the substitution was not reloaded which might
4462 make equivalence invalid. For example, in reverse
4469 the memory address register was reloaded before the 2nd
4471 if ((! first_p
&& pseudo_p
)
4472 /* We don't use DF for compilation speed sake. So it
4473 is problematic to update live info when we use an
4474 equivalence containing pseudos in more than one
4476 || (pseudo_p
&& multi_block_pseudo_p (i
))
4477 /* If an init insn was deleted for some reason, cancel
4478 the equiv. We could update the equiv insns after
4479 transformations including an equiv insn deletion
4480 but it is not worthy as such cases are extremely
4482 || contains_deleted_insn_p (ira_reg_equiv
[i
].init_insns
)
4483 /* If it is not a reverse equivalence, we check that a
4484 pseudo in rhs of the init insn is not dying in the
4485 insn. Otherwise, the live info at the beginning of
4486 the corresponding BB might be wrong after we
4487 removed the insn. When the equiv can be a
4488 constant, the right hand side of the init insn can
4490 || (! reverse_equiv_p (i
)
4491 && (init_insn_rhs_dead_pseudo_p (i
)
4492 /* If we reloaded the pseudo in an equivalence
4493 init insn, we can not remove the equiv init
4494 insns and the init insns might write into
4495 const memory in this case. */
4496 || contains_reloaded_insn_p (i
)))
4497 /* Prevent access beyond equivalent memory for
4498 paradoxical subregs. */
4500 && (GET_MODE_SIZE (lra_reg_info
[i
].biggest_mode
)
4501 > GET_MODE_SIZE (GET_MODE (x
))))
4502 || (pic_offset_table_rtx
4503 && ((CONST_POOL_OK_P (PSEUDO_REGNO_MODE (i
), x
)
4504 && (targetm
.preferred_reload_class
4505 (x
, lra_get_allocno_class (i
)) == NO_REGS
))
4506 || contains_symbol_ref_p (x
))))
4507 ira_reg_equiv
[i
].defined_p
= false;
4508 if (contains_reg_p (x
, false, true))
4509 ira_reg_equiv
[i
].profitable_p
= false;
4510 if (get_equiv (reg
) != reg
)
4511 bitmap_ior_into (&equiv_insn_bitmap
, &lra_reg_info
[i
].insn_bitmap
);
4514 for (i
= FIRST_PSEUDO_REGISTER
; i
< new_regno_start
; i
++)
4516 /* We should add all insns containing pseudos which should be
4517 substituted by their equivalences. */
4518 EXECUTE_IF_SET_IN_BITMAP (&equiv_insn_bitmap
, 0, uid
, bi
)
4519 lra_push_insn_by_uid (uid
);
4520 min_len
= lra_insn_stack_length ();
4524 while ((new_min_len
= lra_insn_stack_length ()) != 0)
4526 curr_insn
= lra_pop_insn ();
4528 curr_bb
= BLOCK_FOR_INSN (curr_insn
);
4529 if (curr_bb
!= last_bb
)
4532 bb_reload_num
= lra_curr_reload_num
;
4534 if (min_len
> new_min_len
)
4536 min_len
= new_min_len
;
4539 if (new_insns_num
> MAX_RELOAD_INSNS_NUMBER
)
4541 ("Max. number of generated reload insns per insn is achieved (%d)\n",
4542 MAX_RELOAD_INSNS_NUMBER
);
4544 if (DEBUG_INSN_P (curr_insn
))
4546 /* We need to check equivalence in debug insn and change
4547 pseudo to the equivalent value if necessary. */
4548 curr_id
= lra_get_insn_recog_data (curr_insn
);
4549 if (bitmap_bit_p (&equiv_insn_bitmap
, INSN_UID (curr_insn
)))
4551 rtx old
= *curr_id
->operand_loc
[0];
4552 *curr_id
->operand_loc
[0]
4553 = simplify_replace_fn_rtx (old
, NULL_RTX
,
4554 loc_equivalence_callback
, curr_insn
);
4555 if (old
!= *curr_id
->operand_loc
[0])
4557 lra_update_insn_regno_info (curr_insn
);
4562 else if (INSN_P (curr_insn
))
4564 if ((set
= single_set (curr_insn
)) != NULL_RTX
)
4566 dest_reg
= SET_DEST (set
);
4567 /* The equivalence pseudo could be set up as SUBREG in a
4568 case when it is a call restore insn in a mode
4569 different from the pseudo mode. */
4570 if (GET_CODE (dest_reg
) == SUBREG
)
4571 dest_reg
= SUBREG_REG (dest_reg
);
4572 if ((REG_P (dest_reg
)
4573 && (x
= get_equiv (dest_reg
)) != dest_reg
4574 /* Remove insns which set up a pseudo whose value
4575 can not be changed. Such insns might be not in
4576 init_insns because we don't update equiv data
4577 during insn transformations.
4579 As an example, let suppose that a pseudo got
4580 hard register and on the 1st pass was not
4581 changed to equivalent constant. We generate an
4582 additional insn setting up the pseudo because of
4583 secondary memory movement. Then the pseudo is
4584 spilled and we use the equiv constant. In this
4585 case we should remove the additional insn and
4586 this insn is not init_insns list. */
4587 && (! MEM_P (x
) || MEM_READONLY_P (x
)
4588 /* Check that this is actually an insn setting
4589 up the equivalence. */
4590 || in_list_p (curr_insn
,
4592 [REGNO (dest_reg
)].init_insns
)))
4593 || (((x
= get_equiv (SET_SRC (set
))) != SET_SRC (set
))
4594 && in_list_p (curr_insn
,
4596 [REGNO (SET_SRC (set
))].init_insns
)))
4598 /* This is equiv init insn of pseudo which did not get a
4599 hard register -- remove the insn. */
4600 if (lra_dump_file
!= NULL
)
4602 fprintf (lra_dump_file
,
4603 " Removing equiv init insn %i (freq=%d)\n",
4604 INSN_UID (curr_insn
),
4605 REG_FREQ_FROM_BB (BLOCK_FOR_INSN (curr_insn
)));
4606 dump_insn_slim (lra_dump_file
, curr_insn
);
4608 if (contains_reg_p (x
, true, false))
4609 lra_risky_transformations_p
= true;
4610 lra_set_insn_deleted (curr_insn
);
4614 curr_id
= lra_get_insn_recog_data (curr_insn
);
4615 curr_static_id
= curr_id
->insn_static_data
;
4616 init_curr_insn_input_reloads ();
4617 init_curr_operand_mode ();
4618 if (curr_insn_transform (false))
4620 /* Check non-transformed insns too for equiv change as USE
4621 or CLOBBER don't need reloads but can contain pseudos
4622 being changed on their equivalences. */
4623 else if (bitmap_bit_p (&equiv_insn_bitmap
, INSN_UID (curr_insn
))
4624 && loc_equivalence_change_p (&PATTERN (curr_insn
)))
4626 lra_update_insn_regno_info (curr_insn
);
4631 bitmap_clear (&equiv_insn_bitmap
);
4632 /* If we used a new hard regno, changed_p should be true because the
4633 hard reg is assigned to a new pseudo. */
4634 if (flag_checking
&& !changed_p
)
4636 for (i
= FIRST_PSEUDO_REGISTER
; i
< new_regno_start
; i
++)
4637 if (lra_reg_info
[i
].nrefs
!= 0
4638 && (hard_regno
= lra_get_regno_hard_regno (i
)) >= 0)
4640 int j
, nregs
= hard_regno_nregs
[hard_regno
][PSEUDO_REGNO_MODE (i
)];
4642 for (j
= 0; j
< nregs
; j
++)
4643 lra_assert (df_regs_ever_live_p (hard_regno
+ j
));
4649 /* Initiate the LRA constraint pass. It is done once per
4652 lra_constraints_init (void)
4656 /* Finalize the LRA constraint pass. It is done once per
4659 lra_constraints_finish (void)
4665 /* This page contains code to do inheritance/split
4668 /* Number of reloads passed so far in current EBB. */
4669 static int reloads_num
;
4671 /* Number of calls passed so far in current EBB. */
4672 static int calls_num
;
4674 /* Current reload pseudo check for validity of elements in
4676 static int curr_usage_insns_check
;
4678 /* Info about last usage of registers in EBB to do inheritance/split
4679 transformation. Inheritance transformation is done from a spilled
4680 pseudo and split transformations from a hard register or a pseudo
4681 assigned to a hard register. */
4684 /* If the value is equal to CURR_USAGE_INSNS_CHECK, then the member
4685 value INSNS is valid. The insns is chain of optional debug insns
4686 and a finishing non-debug insn using the corresponding reg. The
4687 value is also used to mark the registers which are set up in the
4688 current insn. The negated insn uid is used for this. */
4690 /* Value of global reloads_num at the last insn in INSNS. */
4692 /* Value of global reloads_nums at the last insn in INSNS. */
4694 /* It can be true only for splitting. And it means that the restore
4695 insn should be put after insn given by the following member. */
4697 /* Next insns in the current EBB which use the original reg and the
4698 original reg value is not changed between the current insn and
4699 the next insns. In order words, e.g. for inheritance, if we need
4700 to use the original reg value again in the next insns we can try
4701 to use the value in a hard register from a reload insn of the
4706 /* Map: regno -> corresponding pseudo usage insns. */
4707 static struct usage_insns
*usage_insns
;
4710 setup_next_usage_insn (int regno
, rtx insn
, int reloads_num
, bool after_p
)
4712 usage_insns
[regno
].check
= curr_usage_insns_check
;
4713 usage_insns
[regno
].insns
= insn
;
4714 usage_insns
[regno
].reloads_num
= reloads_num
;
4715 usage_insns
[regno
].calls_num
= calls_num
;
4716 usage_insns
[regno
].after_p
= after_p
;
4719 /* The function is used to form list REGNO usages which consists of
4720 optional debug insns finished by a non-debug insn using REGNO.
4721 RELOADS_NUM is current number of reload insns processed so far. */
4723 add_next_usage_insn (int regno
, rtx_insn
*insn
, int reloads_num
)
4725 rtx next_usage_insns
;
4727 if (usage_insns
[regno
].check
== curr_usage_insns_check
4728 && (next_usage_insns
= usage_insns
[regno
].insns
) != NULL_RTX
4729 && DEBUG_INSN_P (insn
))
4731 /* Check that we did not add the debug insn yet. */
4732 if (next_usage_insns
!= insn
4733 && (GET_CODE (next_usage_insns
) != INSN_LIST
4734 || XEXP (next_usage_insns
, 0) != insn
))
4735 usage_insns
[regno
].insns
= gen_rtx_INSN_LIST (VOIDmode
, insn
,
4738 else if (NONDEBUG_INSN_P (insn
))
4739 setup_next_usage_insn (regno
, insn
, reloads_num
, false);
4741 usage_insns
[regno
].check
= 0;
4744 /* Return first non-debug insn in list USAGE_INSNS. */
4746 skip_usage_debug_insns (rtx usage_insns
)
4750 /* Skip debug insns. */
4751 for (insn
= usage_insns
;
4752 insn
!= NULL_RTX
&& GET_CODE (insn
) == INSN_LIST
;
4753 insn
= XEXP (insn
, 1))
4755 return safe_as_a
<rtx_insn
*> (insn
);
4758 /* Return true if we need secondary memory moves for insn in
4759 USAGE_INSNS after inserting inherited pseudo of class INHER_CL
4762 check_secondary_memory_needed_p (enum reg_class inher_cl ATTRIBUTE_UNUSED
,
4763 rtx usage_insns ATTRIBUTE_UNUSED
)
4765 #ifndef SECONDARY_MEMORY_NEEDED
4772 if (inher_cl
== ALL_REGS
4773 || (insn
= skip_usage_debug_insns (usage_insns
)) == NULL_RTX
)
4775 lra_assert (INSN_P (insn
));
4776 if ((set
= single_set (insn
)) == NULL_RTX
|| ! REG_P (SET_DEST (set
)))
4778 dest
= SET_DEST (set
);
4781 lra_assert (inher_cl
!= NO_REGS
);
4782 cl
= get_reg_class (REGNO (dest
));
4783 return (cl
!= NO_REGS
&& cl
!= ALL_REGS
4784 && SECONDARY_MEMORY_NEEDED (inher_cl
, cl
, GET_MODE (dest
)));
4788 /* Registers involved in inheritance/split in the current EBB
4789 (inheritance/split pseudos and original registers). */
4790 static bitmap_head check_only_regs
;
4792 /* Do inheritance transformations for insn INSN, which defines (if
4793 DEF_P) or uses ORIGINAL_REGNO. NEXT_USAGE_INSNS specifies which
4794 instruction in the EBB next uses ORIGINAL_REGNO; it has the same
4795 form as the "insns" field of usage_insns. Return true if we
4796 succeed in such transformation.
4798 The transformations look like:
4801 ... p <- i (new insn)
4803 <- ... p ... <- ... i ...
4805 ... i <- p (new insn)
4806 <- ... p ... <- ... i ...
4808 <- ... p ... <- ... i ...
4809 where p is a spilled original pseudo and i is a new inheritance pseudo.
4812 The inheritance pseudo has the smallest class of two classes CL and
4813 class of ORIGINAL REGNO. */
4815 inherit_reload_reg (bool def_p
, int original_regno
,
4816 enum reg_class cl
, rtx_insn
*insn
, rtx next_usage_insns
)
4818 if (optimize_function_for_size_p (cfun
))
4821 enum reg_class rclass
= lra_get_allocno_class (original_regno
);
4822 rtx original_reg
= regno_reg_rtx
[original_regno
];
4823 rtx new_reg
, usage_insn
;
4824 rtx_insn
*new_insns
;
4826 lra_assert (! usage_insns
[original_regno
].after_p
);
4827 if (lra_dump_file
!= NULL
)
4828 fprintf (lra_dump_file
,
4829 " <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n");
4830 if (! ira_reg_classes_intersect_p
[cl
][rclass
])
4832 if (lra_dump_file
!= NULL
)
4834 fprintf (lra_dump_file
,
4835 " Rejecting inheritance for %d "
4836 "because of disjoint classes %s and %s\n",
4837 original_regno
, reg_class_names
[cl
],
4838 reg_class_names
[rclass
]);
4839 fprintf (lra_dump_file
,
4840 " >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n");
4844 if ((ira_class_subset_p
[cl
][rclass
] && cl
!= rclass
)
4845 /* We don't use a subset of two classes because it can be
4846 NO_REGS. This transformation is still profitable in most
4847 cases even if the classes are not intersected as register
4848 move is probably cheaper than a memory load. */
4849 || ira_class_hard_regs_num
[cl
] < ira_class_hard_regs_num
[rclass
])
4851 if (lra_dump_file
!= NULL
)
4852 fprintf (lra_dump_file
, " Use smallest class of %s and %s\n",
4853 reg_class_names
[cl
], reg_class_names
[rclass
]);
4857 if (check_secondary_memory_needed_p (rclass
, next_usage_insns
))
4859 /* Reject inheritance resulting in secondary memory moves.
4860 Otherwise, there is a danger in LRA cycling. Also such
4861 transformation will be unprofitable. */
4862 if (lra_dump_file
!= NULL
)
4864 rtx_insn
*insn
= skip_usage_debug_insns (next_usage_insns
);
4865 rtx set
= single_set (insn
);
4867 lra_assert (set
!= NULL_RTX
);
4869 rtx dest
= SET_DEST (set
);
4871 lra_assert (REG_P (dest
));
4872 fprintf (lra_dump_file
,
4873 " Rejecting inheritance for insn %d(%s)<-%d(%s) "
4874 "as secondary mem is needed\n",
4875 REGNO (dest
), reg_class_names
[get_reg_class (REGNO (dest
))],
4876 original_regno
, reg_class_names
[rclass
]);
4877 fprintf (lra_dump_file
,
4878 " >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n");
4882 new_reg
= lra_create_new_reg (GET_MODE (original_reg
), original_reg
,
4883 rclass
, "inheritance");
4886 lra_emit_move (original_reg
, new_reg
);
4888 lra_emit_move (new_reg
, original_reg
);
4889 new_insns
= get_insns ();
4891 if (NEXT_INSN (new_insns
) != NULL_RTX
)
4893 if (lra_dump_file
!= NULL
)
4895 fprintf (lra_dump_file
,
4896 " Rejecting inheritance %d->%d "
4897 "as it results in 2 or more insns:\n",
4898 original_regno
, REGNO (new_reg
));
4899 dump_rtl_slim (lra_dump_file
, new_insns
, NULL
, -1, 0);
4900 fprintf (lra_dump_file
,
4901 " >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n");
4905 lra_substitute_pseudo_within_insn (insn
, original_regno
, new_reg
, false);
4906 lra_update_insn_regno_info (insn
);
4908 /* We now have a new usage insn for original regno. */
4909 setup_next_usage_insn (original_regno
, new_insns
, reloads_num
, false);
4910 if (lra_dump_file
!= NULL
)
4911 fprintf (lra_dump_file
, " Original reg change %d->%d (bb%d):\n",
4912 original_regno
, REGNO (new_reg
), BLOCK_FOR_INSN (insn
)->index
);
4913 lra_reg_info
[REGNO (new_reg
)].restore_regno
= original_regno
;
4914 bitmap_set_bit (&check_only_regs
, REGNO (new_reg
));
4915 bitmap_set_bit (&check_only_regs
, original_regno
);
4916 bitmap_set_bit (&lra_inheritance_pseudos
, REGNO (new_reg
));
4918 lra_process_new_insns (insn
, NULL
, new_insns
,
4919 "Add original<-inheritance");
4921 lra_process_new_insns (insn
, new_insns
, NULL
,
4922 "Add inheritance<-original");
4923 while (next_usage_insns
!= NULL_RTX
)
4925 if (GET_CODE (next_usage_insns
) != INSN_LIST
)
4927 usage_insn
= next_usage_insns
;
4928 lra_assert (NONDEBUG_INSN_P (usage_insn
));
4929 next_usage_insns
= NULL
;
4933 usage_insn
= XEXP (next_usage_insns
, 0);
4934 lra_assert (DEBUG_INSN_P (usage_insn
));
4935 next_usage_insns
= XEXP (next_usage_insns
, 1);
4937 lra_substitute_pseudo (&usage_insn
, original_regno
, new_reg
, false);
4938 lra_update_insn_regno_info (as_a
<rtx_insn
*> (usage_insn
));
4939 if (lra_dump_file
!= NULL
)
4941 fprintf (lra_dump_file
,
4942 " Inheritance reuse change %d->%d (bb%d):\n",
4943 original_regno
, REGNO (new_reg
),
4944 BLOCK_FOR_INSN (usage_insn
)->index
);
4945 dump_insn_slim (lra_dump_file
, as_a
<rtx_insn
*> (usage_insn
));
4948 if (lra_dump_file
!= NULL
)
4949 fprintf (lra_dump_file
,
4950 " >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n");
4954 /* Return true if we need a caller save/restore for pseudo REGNO which
4955 was assigned to a hard register. */
4957 need_for_call_save_p (int regno
)
4959 lra_assert (regno
>= FIRST_PSEUDO_REGISTER
&& reg_renumber
[regno
] >= 0);
4960 return (usage_insns
[regno
].calls_num
< calls_num
4961 && (overlaps_hard_reg_set_p
4963 ! hard_reg_set_empty_p (lra_reg_info
[regno
].actual_call_used_reg_set
))
4964 ? lra_reg_info
[regno
].actual_call_used_reg_set
4965 : call_used_reg_set
,
4966 PSEUDO_REGNO_MODE (regno
), reg_renumber
[regno
])
4967 || HARD_REGNO_CALL_PART_CLOBBERED (reg_renumber
[regno
],
4968 PSEUDO_REGNO_MODE (regno
))));
4971 /* Global registers occurring in the current EBB. */
4972 static bitmap_head ebb_global_regs
;
4974 /* Return true if we need a split for hard register REGNO or pseudo
4975 REGNO which was assigned to a hard register.
4976 POTENTIAL_RELOAD_HARD_REGS contains hard registers which might be
4977 used for reloads since the EBB end. It is an approximation of the
4978 used hard registers in the split range. The exact value would
4979 require expensive calculations. If we were aggressive with
4980 splitting because of the approximation, the split pseudo will save
4981 the same hard register assignment and will be removed in the undo
4982 pass. We still need the approximation because too aggressive
4983 splitting would result in too inaccurate cost calculation in the
4984 assignment pass because of too many generated moves which will be
4985 probably removed in the undo pass. */
4987 need_for_split_p (HARD_REG_SET potential_reload_hard_regs
, int regno
)
4989 int hard_regno
= regno
< FIRST_PSEUDO_REGISTER
? regno
: reg_renumber
[regno
];
4991 lra_assert (hard_regno
>= 0);
4992 return ((TEST_HARD_REG_BIT (potential_reload_hard_regs
, hard_regno
)
4993 /* Don't split eliminable hard registers, otherwise we can
4994 split hard registers like hard frame pointer, which
4995 lives on BB start/end according to DF-infrastructure,
4996 when there is a pseudo assigned to the register and
4997 living in the same BB. */
4998 && (regno
>= FIRST_PSEUDO_REGISTER
4999 || ! TEST_HARD_REG_BIT (eliminable_regset
, hard_regno
))
5000 && ! TEST_HARD_REG_BIT (lra_no_alloc_regs
, hard_regno
)
5001 /* Don't split call clobbered hard regs living through
5002 calls, otherwise we might have a check problem in the
5003 assign sub-pass as in the most cases (exception is a
5004 situation when lra_risky_transformations_p value is
5005 true) the assign pass assumes that all pseudos living
5006 through calls are assigned to call saved hard regs. */
5007 && (regno
>= FIRST_PSEUDO_REGISTER
5008 || ! TEST_HARD_REG_BIT (call_used_reg_set
, regno
)
5009 || usage_insns
[regno
].calls_num
== calls_num
)
5010 /* We need at least 2 reloads to make pseudo splitting
5011 profitable. We should provide hard regno splitting in
5012 any case to solve 1st insn scheduling problem when
5013 moving hard register definition up might result in
5014 impossibility to find hard register for reload pseudo of
5015 small register class. */
5016 && (usage_insns
[regno
].reloads_num
5017 + (regno
< FIRST_PSEUDO_REGISTER
? 0 : 3) < reloads_num
)
5018 && (regno
< FIRST_PSEUDO_REGISTER
5019 /* For short living pseudos, spilling + inheritance can
5020 be considered a substitution for splitting.
5021 Therefore we do not splitting for local pseudos. It
5022 decreases also aggressiveness of splitting. The
5023 minimal number of references is chosen taking into
5024 account that for 2 references splitting has no sense
5025 as we can just spill the pseudo. */
5026 || (regno
>= FIRST_PSEUDO_REGISTER
5027 && lra_reg_info
[regno
].nrefs
> 3
5028 && bitmap_bit_p (&ebb_global_regs
, regno
))))
5029 || (regno
>= FIRST_PSEUDO_REGISTER
&& need_for_call_save_p (regno
)));
5032 /* Return class for the split pseudo created from original pseudo with
5033 ALLOCNO_CLASS and MODE which got a hard register HARD_REGNO. We
5034 choose subclass of ALLOCNO_CLASS which contains HARD_REGNO and
5035 results in no secondary memory movements. */
5036 static enum reg_class
5037 choose_split_class (enum reg_class allocno_class
,
5038 int hard_regno ATTRIBUTE_UNUSED
,
5039 machine_mode mode ATTRIBUTE_UNUSED
)
5041 #ifndef SECONDARY_MEMORY_NEEDED
5042 return allocno_class
;
5045 enum reg_class cl
, best_cl
= NO_REGS
;
5046 enum reg_class hard_reg_class ATTRIBUTE_UNUSED
5047 = REGNO_REG_CLASS (hard_regno
);
5049 if (! SECONDARY_MEMORY_NEEDED (allocno_class
, allocno_class
, mode
)
5050 && TEST_HARD_REG_BIT (reg_class_contents
[allocno_class
], hard_regno
))
5051 return allocno_class
;
5053 (cl
= reg_class_subclasses
[allocno_class
][i
]) != LIM_REG_CLASSES
;
5055 if (! SECONDARY_MEMORY_NEEDED (cl
, hard_reg_class
, mode
)
5056 && ! SECONDARY_MEMORY_NEEDED (hard_reg_class
, cl
, mode
)
5057 && TEST_HARD_REG_BIT (reg_class_contents
[cl
], hard_regno
)
5058 && (best_cl
== NO_REGS
5059 || ira_class_hard_regs_num
[best_cl
] < ira_class_hard_regs_num
[cl
]))
5065 /* Do split transformations for insn INSN, which defines or uses
5066 ORIGINAL_REGNO. NEXT_USAGE_INSNS specifies which instruction in
5067 the EBB next uses ORIGINAL_REGNO; it has the same form as the
5068 "insns" field of usage_insns.
5070 The transformations look like:
5073 ... s <- p (new insn -- save)
5075 ... p <- s (new insn -- restore)
5076 <- ... p ... <- ... p ...
5078 <- ... p ... <- ... p ...
5079 ... s <- p (new insn -- save)
5081 ... p <- s (new insn -- restore)
5082 <- ... p ... <- ... p ...
5084 where p is an original pseudo got a hard register or a hard
5085 register and s is a new split pseudo. The save is put before INSN
5086 if BEFORE_P is true. Return true if we succeed in such
5089 split_reg (bool before_p
, int original_regno
, rtx_insn
*insn
,
5090 rtx next_usage_insns
)
5092 enum reg_class rclass
;
5094 int hard_regno
, nregs
;
5095 rtx new_reg
, usage_insn
;
5096 rtx_insn
*restore
, *save
;
5101 if (original_regno
< FIRST_PSEUDO_REGISTER
)
5103 rclass
= ira_allocno_class_translate
[REGNO_REG_CLASS (original_regno
)];
5104 hard_regno
= original_regno
;
5105 call_save_p
= false;
5107 mode
= lra_reg_info
[hard_regno
].biggest_mode
;
5108 machine_mode reg_rtx_mode
= GET_MODE (regno_reg_rtx
[hard_regno
]);
5109 /* A reg can have a biggest_mode of VOIDmode if it was only ever seen
5110 as part of a multi-word register. In that case, or if the biggest
5111 mode was larger than a register, just use the reg_rtx. Otherwise,
5112 limit the size to that of the biggest access in the function. */
5113 if (mode
== VOIDmode
5114 || GET_MODE_SIZE (mode
) > GET_MODE_SIZE (reg_rtx_mode
))
5116 original_reg
= regno_reg_rtx
[hard_regno
];
5117 mode
= reg_rtx_mode
;
5120 original_reg
= gen_rtx_REG (mode
, hard_regno
);
5124 mode
= PSEUDO_REGNO_MODE (original_regno
);
5125 hard_regno
= reg_renumber
[original_regno
];
5126 nregs
= hard_regno_nregs
[hard_regno
][mode
];
5127 rclass
= lra_get_allocno_class (original_regno
);
5128 original_reg
= regno_reg_rtx
[original_regno
];
5129 call_save_p
= need_for_call_save_p (original_regno
);
5131 lra_assert (hard_regno
>= 0);
5132 if (lra_dump_file
!= NULL
)
5133 fprintf (lra_dump_file
,
5134 " ((((((((((((((((((((((((((((((((((((((((((((((((\n");
5138 mode
= HARD_REGNO_CALLER_SAVE_MODE (hard_regno
,
5139 hard_regno_nregs
[hard_regno
][mode
],
5141 new_reg
= lra_create_new_reg (mode
, NULL_RTX
, NO_REGS
, "save");
5145 rclass
= choose_split_class (rclass
, hard_regno
, mode
);
5146 if (rclass
== NO_REGS
)
5148 if (lra_dump_file
!= NULL
)
5150 fprintf (lra_dump_file
,
5151 " Rejecting split of %d(%s): "
5152 "no good reg class for %d(%s)\n",
5154 reg_class_names
[lra_get_allocno_class (original_regno
)],
5156 reg_class_names
[REGNO_REG_CLASS (hard_regno
)]);
5159 " ))))))))))))))))))))))))))))))))))))))))))))))))\n");
5163 new_reg
= lra_create_new_reg (mode
, original_reg
, rclass
, "split");
5164 reg_renumber
[REGNO (new_reg
)] = hard_regno
;
5166 save
= emit_spill_move (true, new_reg
, original_reg
);
5167 if (NEXT_INSN (save
) != NULL_RTX
&& !call_save_p
)
5169 if (lra_dump_file
!= NULL
)
5173 " Rejecting split %d->%d resulting in > 2 save insns:\n",
5174 original_regno
, REGNO (new_reg
));
5175 dump_rtl_slim (lra_dump_file
, save
, NULL
, -1, 0);
5176 fprintf (lra_dump_file
,
5177 " ))))))))))))))))))))))))))))))))))))))))))))))))\n");
5181 restore
= emit_spill_move (false, new_reg
, original_reg
);
5182 if (NEXT_INSN (restore
) != NULL_RTX
&& !call_save_p
)
5184 if (lra_dump_file
!= NULL
)
5186 fprintf (lra_dump_file
,
5187 " Rejecting split %d->%d "
5188 "resulting in > 2 restore insns:\n",
5189 original_regno
, REGNO (new_reg
));
5190 dump_rtl_slim (lra_dump_file
, restore
, NULL
, -1, 0);
5191 fprintf (lra_dump_file
,
5192 " ))))))))))))))))))))))))))))))))))))))))))))))))\n");
5196 after_p
= usage_insns
[original_regno
].after_p
;
5197 lra_reg_info
[REGNO (new_reg
)].restore_regno
= original_regno
;
5198 bitmap_set_bit (&check_only_regs
, REGNO (new_reg
));
5199 bitmap_set_bit (&check_only_regs
, original_regno
);
5200 bitmap_set_bit (&lra_split_regs
, REGNO (new_reg
));
5203 if (GET_CODE (next_usage_insns
) != INSN_LIST
)
5205 usage_insn
= next_usage_insns
;
5208 usage_insn
= XEXP (next_usage_insns
, 0);
5209 lra_assert (DEBUG_INSN_P (usage_insn
));
5210 next_usage_insns
= XEXP (next_usage_insns
, 1);
5211 lra_substitute_pseudo (&usage_insn
, original_regno
, new_reg
, false);
5212 lra_update_insn_regno_info (as_a
<rtx_insn
*> (usage_insn
));
5213 if (lra_dump_file
!= NULL
)
5215 fprintf (lra_dump_file
, " Split reuse change %d->%d:\n",
5216 original_regno
, REGNO (new_reg
));
5217 dump_insn_slim (lra_dump_file
, as_a
<rtx_insn
*> (usage_insn
));
5220 lra_assert (NOTE_P (usage_insn
) || NONDEBUG_INSN_P (usage_insn
));
5221 lra_assert (usage_insn
!= insn
|| (after_p
&& before_p
));
5222 lra_process_new_insns (as_a
<rtx_insn
*> (usage_insn
),
5223 after_p
? NULL
: restore
,
5224 after_p
? restore
: NULL
,
5226 ? "Add reg<-save" : "Add reg<-split");
5227 lra_process_new_insns (insn
, before_p
? save
: NULL
,
5228 before_p
? NULL
: save
,
5230 ? "Add save<-reg" : "Add split<-reg");
5232 /* If we are trying to split multi-register. We should check
5233 conflicts on the next assignment sub-pass. IRA can allocate on
5234 sub-register levels, LRA do this on pseudos level right now and
5235 this discrepancy may create allocation conflicts after
5237 lra_risky_transformations_p
= true;
5238 if (lra_dump_file
!= NULL
)
5239 fprintf (lra_dump_file
,
5240 " ))))))))))))))))))))))))))))))))))))))))))))))))\n");
5244 /* Recognize that we need a split transformation for insn INSN, which
5245 defines or uses REGNO in its insn biggest MODE (we use it only if
5246 REGNO is a hard register). POTENTIAL_RELOAD_HARD_REGS contains
5247 hard registers which might be used for reloads since the EBB end.
5248 Put the save before INSN if BEFORE_P is true. MAX_UID is maximla
5249 uid before starting INSN processing. Return true if we succeed in
5250 such transformation. */
5252 split_if_necessary (int regno
, machine_mode mode
,
5253 HARD_REG_SET potential_reload_hard_regs
,
5254 bool before_p
, rtx_insn
*insn
, int max_uid
)
5258 rtx next_usage_insns
;
5260 if (regno
< FIRST_PSEUDO_REGISTER
)
5261 nregs
= hard_regno_nregs
[regno
][mode
];
5262 for (i
= 0; i
< nregs
; i
++)
5263 if (usage_insns
[regno
+ i
].check
== curr_usage_insns_check
5264 && (next_usage_insns
= usage_insns
[regno
+ i
].insns
) != NULL_RTX
5265 /* To avoid processing the register twice or more. */
5266 && ((GET_CODE (next_usage_insns
) != INSN_LIST
5267 && INSN_UID (next_usage_insns
) < max_uid
)
5268 || (GET_CODE (next_usage_insns
) == INSN_LIST
5269 && (INSN_UID (XEXP (next_usage_insns
, 0)) < max_uid
)))
5270 && need_for_split_p (potential_reload_hard_regs
, regno
+ i
)
5271 && split_reg (before_p
, regno
+ i
, insn
, next_usage_insns
))
5276 /* Check only registers living at the current program point in the
5278 static bitmap_head live_regs
;
5280 /* Update live info in EBB given by its HEAD and TAIL insns after
5281 inheritance/split transformation. The function removes dead moves
5284 update_ebb_live_info (rtx_insn
*head
, rtx_insn
*tail
)
5289 rtx_insn
*prev_insn
;
5292 basic_block last_bb
, prev_bb
, curr_bb
;
5294 struct lra_insn_reg
*reg
;
5298 last_bb
= BLOCK_FOR_INSN (tail
);
5300 for (curr_insn
= tail
;
5301 curr_insn
!= PREV_INSN (head
);
5302 curr_insn
= prev_insn
)
5304 prev_insn
= PREV_INSN (curr_insn
);
5305 /* We need to process empty blocks too. They contain
5306 NOTE_INSN_BASIC_BLOCK referring for the basic block. */
5307 if (NOTE_P (curr_insn
) && NOTE_KIND (curr_insn
) != NOTE_INSN_BASIC_BLOCK
)
5309 curr_bb
= BLOCK_FOR_INSN (curr_insn
);
5310 if (curr_bb
!= prev_bb
)
5312 if (prev_bb
!= NULL
)
5314 /* Update df_get_live_in (prev_bb): */
5315 EXECUTE_IF_SET_IN_BITMAP (&check_only_regs
, 0, j
, bi
)
5316 if (bitmap_bit_p (&live_regs
, j
))
5317 bitmap_set_bit (df_get_live_in (prev_bb
), j
);
5319 bitmap_clear_bit (df_get_live_in (prev_bb
), j
);
5321 if (curr_bb
!= last_bb
)
5323 /* Update df_get_live_out (curr_bb): */
5324 EXECUTE_IF_SET_IN_BITMAP (&check_only_regs
, 0, j
, bi
)
5326 live_p
= bitmap_bit_p (&live_regs
, j
);
5328 FOR_EACH_EDGE (e
, ei
, curr_bb
->succs
)
5329 if (bitmap_bit_p (df_get_live_in (e
->dest
), j
))
5335 bitmap_set_bit (df_get_live_out (curr_bb
), j
);
5337 bitmap_clear_bit (df_get_live_out (curr_bb
), j
);
5341 bitmap_and (&live_regs
, &check_only_regs
, df_get_live_out (curr_bb
));
5343 if (! NONDEBUG_INSN_P (curr_insn
))
5345 curr_id
= lra_get_insn_recog_data (curr_insn
);
5346 curr_static_id
= curr_id
->insn_static_data
;
5348 if ((set
= single_set (curr_insn
)) != NULL_RTX
5349 && REG_P (SET_DEST (set
))
5350 && (regno
= REGNO (SET_DEST (set
))) >= FIRST_PSEUDO_REGISTER
5351 && SET_DEST (set
) != pic_offset_table_rtx
5352 && bitmap_bit_p (&check_only_regs
, regno
)
5353 && ! bitmap_bit_p (&live_regs
, regno
))
5355 /* See which defined values die here. */
5356 for (reg
= curr_id
->regs
; reg
!= NULL
; reg
= reg
->next
)
5357 if (reg
->type
== OP_OUT
&& ! reg
->subreg_p
)
5358 bitmap_clear_bit (&live_regs
, reg
->regno
);
5359 for (reg
= curr_static_id
->hard_regs
; reg
!= NULL
; reg
= reg
->next
)
5360 if (reg
->type
== OP_OUT
&& ! reg
->subreg_p
)
5361 bitmap_clear_bit (&live_regs
, reg
->regno
);
5362 if (curr_id
->arg_hard_regs
!= NULL
)
5363 /* Make clobbered argument hard registers die. */
5364 for (i
= 0; (regno
= curr_id
->arg_hard_regs
[i
]) >= 0; i
++)
5365 if (regno
>= FIRST_PSEUDO_REGISTER
)
5366 bitmap_clear_bit (&live_regs
, regno
- FIRST_PSEUDO_REGISTER
);
5367 /* Mark each used value as live. */
5368 for (reg
= curr_id
->regs
; reg
!= NULL
; reg
= reg
->next
)
5369 if (reg
->type
!= OP_OUT
5370 && bitmap_bit_p (&check_only_regs
, reg
->regno
))
5371 bitmap_set_bit (&live_regs
, reg
->regno
);
5372 for (reg
= curr_static_id
->hard_regs
; reg
!= NULL
; reg
= reg
->next
)
5373 if (reg
->type
!= OP_OUT
5374 && bitmap_bit_p (&check_only_regs
, reg
->regno
))
5375 bitmap_set_bit (&live_regs
, reg
->regno
);
5376 if (curr_id
->arg_hard_regs
!= NULL
)
5377 /* Make used argument hard registers live. */
5378 for (i
= 0; (regno
= curr_id
->arg_hard_regs
[i
]) >= 0; i
++)
5379 if (regno
< FIRST_PSEUDO_REGISTER
5380 && bitmap_bit_p (&check_only_regs
, regno
))
5381 bitmap_set_bit (&live_regs
, regno
);
5382 /* It is quite important to remove dead move insns because it
5383 means removing dead store. We don't need to process them for
5387 if (lra_dump_file
!= NULL
)
5389 fprintf (lra_dump_file
, " Removing dead insn:\n ");
5390 dump_insn_slim (lra_dump_file
, curr_insn
);
5392 lra_set_insn_deleted (curr_insn
);
5397 /* The structure describes info to do an inheritance for the current
5398 insn. We need to collect such info first before doing the
5399 transformations because the transformations change the insn
5400 internal representation. */
5403 /* Original regno. */
5405 /* Subsequent insns which can inherit original reg value. */
5409 /* Array containing all info for doing inheritance from the current
5411 static struct to_inherit to_inherit
[LRA_MAX_INSN_RELOADS
];
5413 /* Number elements in the previous array. */
5414 static int to_inherit_num
;
5416 /* Add inheritance info REGNO and INSNS. Their meaning is described in
5417 structure to_inherit. */
5419 add_to_inherit (int regno
, rtx insns
)
5423 for (i
= 0; i
< to_inherit_num
; i
++)
5424 if (to_inherit
[i
].regno
== regno
)
5426 lra_assert (to_inherit_num
< LRA_MAX_INSN_RELOADS
);
5427 to_inherit
[to_inherit_num
].regno
= regno
;
5428 to_inherit
[to_inherit_num
++].insns
= insns
;
5431 /* Return the last non-debug insn in basic block BB, or the block begin
5434 get_last_insertion_point (basic_block bb
)
5438 FOR_BB_INSNS_REVERSE (bb
, insn
)
5439 if (NONDEBUG_INSN_P (insn
) || NOTE_INSN_BASIC_BLOCK_P (insn
))
5444 /* Set up RES by registers living on edges FROM except the edge (FROM,
5445 TO) or by registers set up in a jump insn in BB FROM. */
5447 get_live_on_other_edges (basic_block from
, basic_block to
, bitmap res
)
5450 struct lra_insn_reg
*reg
;
5454 lra_assert (to
!= NULL
);
5456 FOR_EACH_EDGE (e
, ei
, from
->succs
)
5458 bitmap_ior_into (res
, df_get_live_in (e
->dest
));
5459 last
= get_last_insertion_point (from
);
5460 if (! JUMP_P (last
))
5462 curr_id
= lra_get_insn_recog_data (last
);
5463 for (reg
= curr_id
->regs
; reg
!= NULL
; reg
= reg
->next
)
5464 if (reg
->type
!= OP_IN
)
5465 bitmap_set_bit (res
, reg
->regno
);
5468 /* Used as a temporary results of some bitmap calculations. */
5469 static bitmap_head temp_bitmap
;
5471 /* We split for reloads of small class of hard regs. The following
5472 defines how many hard regs the class should have to be qualified as
5473 small. The code is mostly oriented to x86/x86-64 architecture
5474 where some insns need to use only specific register or pair of
5475 registers and these register can live in RTL explicitly, e.g. for
5476 parameter passing. */
5477 static const int max_small_class_regs_num
= 2;
5479 /* Do inheritance/split transformations in EBB starting with HEAD and
5480 finishing on TAIL. We process EBB insns in the reverse order.
5481 Return true if we did any inheritance/split transformation in the
5484 We should avoid excessive splitting which results in worse code
5485 because of inaccurate cost calculations for spilling new split
5486 pseudos in such case. To achieve this we do splitting only if
5487 register pressure is high in given basic block and there are reload
5488 pseudos requiring hard registers. We could do more register
5489 pressure calculations at any given program point to avoid necessary
5490 splitting even more but it is to expensive and the current approach
5491 works well enough. */
5493 inherit_in_ebb (rtx_insn
*head
, rtx_insn
*tail
)
5495 int i
, src_regno
, dst_regno
, nregs
;
5496 bool change_p
, succ_p
, update_reloads_num_p
;
5497 rtx_insn
*prev_insn
, *last_insn
;
5498 rtx next_usage_insns
, set
;
5500 struct lra_insn_reg
*reg
;
5501 basic_block last_processed_bb
, curr_bb
= NULL
;
5502 HARD_REG_SET potential_reload_hard_regs
, live_hard_regs
;
5506 bool head_p
, after_p
;
5509 curr_usage_insns_check
++;
5510 reloads_num
= calls_num
= 0;
5511 bitmap_clear (&check_only_regs
);
5512 last_processed_bb
= NULL
;
5513 CLEAR_HARD_REG_SET (potential_reload_hard_regs
);
5514 COPY_HARD_REG_SET (live_hard_regs
, eliminable_regset
);
5515 IOR_HARD_REG_SET (live_hard_regs
, lra_no_alloc_regs
);
5516 /* We don't process new insns generated in the loop. */
5517 for (curr_insn
= tail
; curr_insn
!= PREV_INSN (head
); curr_insn
= prev_insn
)
5519 prev_insn
= PREV_INSN (curr_insn
);
5520 if (BLOCK_FOR_INSN (curr_insn
) != NULL
)
5521 curr_bb
= BLOCK_FOR_INSN (curr_insn
);
5522 if (last_processed_bb
!= curr_bb
)
5524 /* We are at the end of BB. Add qualified living
5525 pseudos for potential splitting. */
5526 to_process
= df_get_live_out (curr_bb
);
5527 if (last_processed_bb
!= NULL
)
5529 /* We are somewhere in the middle of EBB. */
5530 get_live_on_other_edges (curr_bb
, last_processed_bb
,
5532 to_process
= &temp_bitmap
;
5534 last_processed_bb
= curr_bb
;
5535 last_insn
= get_last_insertion_point (curr_bb
);
5536 after_p
= (! JUMP_P (last_insn
)
5537 && (! CALL_P (last_insn
)
5538 || (find_reg_note (last_insn
,
5539 REG_NORETURN
, NULL_RTX
) == NULL_RTX
5540 && ! SIBLING_CALL_P (last_insn
))));
5541 CLEAR_HARD_REG_SET (potential_reload_hard_regs
);
5542 EXECUTE_IF_SET_IN_BITMAP (to_process
, 0, j
, bi
)
5544 if ((int) j
>= lra_constraint_new_regno_start
)
5546 if (j
< FIRST_PSEUDO_REGISTER
|| reg_renumber
[j
] >= 0)
5548 if (j
< FIRST_PSEUDO_REGISTER
)
5549 SET_HARD_REG_BIT (live_hard_regs
, j
);
5551 add_to_hard_reg_set (&live_hard_regs
,
5552 PSEUDO_REGNO_MODE (j
),
5554 setup_next_usage_insn (j
, last_insn
, reloads_num
, after_p
);
5558 src_regno
= dst_regno
= -1;
5559 if (NONDEBUG_INSN_P (curr_insn
)
5560 && (set
= single_set (curr_insn
)) != NULL_RTX
5561 && REG_P (SET_DEST (set
)) && REG_P (SET_SRC (set
)))
5563 src_regno
= REGNO (SET_SRC (set
));
5564 dst_regno
= REGNO (SET_DEST (set
));
5566 update_reloads_num_p
= true;
5567 if (src_regno
< lra_constraint_new_regno_start
5568 && src_regno
>= FIRST_PSEUDO_REGISTER
5569 && reg_renumber
[src_regno
] < 0
5570 && dst_regno
>= lra_constraint_new_regno_start
5571 && (cl
= lra_get_allocno_class (dst_regno
)) != NO_REGS
)
5573 /* 'reload_pseudo <- original_pseudo'. */
5574 if (ira_class_hard_regs_num
[cl
] <= max_small_class_regs_num
)
5576 update_reloads_num_p
= false;
5578 if (usage_insns
[src_regno
].check
== curr_usage_insns_check
5579 && (next_usage_insns
= usage_insns
[src_regno
].insns
) != NULL_RTX
)
5580 succ_p
= inherit_reload_reg (false, src_regno
, cl
,
5581 curr_insn
, next_usage_insns
);
5585 setup_next_usage_insn (src_regno
, curr_insn
, reloads_num
, false);
5586 if (hard_reg_set_subset_p (reg_class_contents
[cl
], live_hard_regs
))
5587 IOR_HARD_REG_SET (potential_reload_hard_regs
,
5588 reg_class_contents
[cl
]);
5590 else if (src_regno
>= lra_constraint_new_regno_start
5591 && dst_regno
< lra_constraint_new_regno_start
5592 && dst_regno
>= FIRST_PSEUDO_REGISTER
5593 && reg_renumber
[dst_regno
] < 0
5594 && (cl
= lra_get_allocno_class (src_regno
)) != NO_REGS
5595 && usage_insns
[dst_regno
].check
== curr_usage_insns_check
5596 && (next_usage_insns
5597 = usage_insns
[dst_regno
].insns
) != NULL_RTX
)
5599 if (ira_class_hard_regs_num
[cl
] <= max_small_class_regs_num
)
5601 update_reloads_num_p
= false;
5602 /* 'original_pseudo <- reload_pseudo'. */
5603 if (! JUMP_P (curr_insn
)
5604 && inherit_reload_reg (true, dst_regno
, cl
,
5605 curr_insn
, next_usage_insns
))
5608 usage_insns
[dst_regno
].check
= 0;
5609 if (hard_reg_set_subset_p (reg_class_contents
[cl
], live_hard_regs
))
5610 IOR_HARD_REG_SET (potential_reload_hard_regs
,
5611 reg_class_contents
[cl
]);
5613 else if (INSN_P (curr_insn
))
5616 int max_uid
= get_max_uid ();
5618 curr_id
= lra_get_insn_recog_data (curr_insn
);
5619 curr_static_id
= curr_id
->insn_static_data
;
5621 /* Process insn definitions. */
5622 for (iter
= 0; iter
< 2; iter
++)
5623 for (reg
= iter
== 0 ? curr_id
->regs
: curr_static_id
->hard_regs
;
5626 if (reg
->type
!= OP_IN
5627 && (dst_regno
= reg
->regno
) < lra_constraint_new_regno_start
)
5629 if (dst_regno
>= FIRST_PSEUDO_REGISTER
&& reg
->type
== OP_OUT
5630 && reg_renumber
[dst_regno
] < 0 && ! reg
->subreg_p
5631 && usage_insns
[dst_regno
].check
== curr_usage_insns_check
5632 && (next_usage_insns
5633 = usage_insns
[dst_regno
].insns
) != NULL_RTX
)
5635 struct lra_insn_reg
*r
;
5637 for (r
= curr_id
->regs
; r
!= NULL
; r
= r
->next
)
5638 if (r
->type
!= OP_OUT
&& r
->regno
== dst_regno
)
5640 /* Don't do inheritance if the pseudo is also
5641 used in the insn. */
5643 /* We can not do inheritance right now
5644 because the current insn reg info (chain
5645 regs) can change after that. */
5646 add_to_inherit (dst_regno
, next_usage_insns
);
5648 /* We can not process one reg twice here because of
5649 usage_insns invalidation. */
5650 if ((dst_regno
< FIRST_PSEUDO_REGISTER
5651 || reg_renumber
[dst_regno
] >= 0)
5652 && ! reg
->subreg_p
&& reg
->type
!= OP_IN
)
5656 if (split_if_necessary (dst_regno
, reg
->biggest_mode
,
5657 potential_reload_hard_regs
,
5658 false, curr_insn
, max_uid
))
5660 CLEAR_HARD_REG_SET (s
);
5661 if (dst_regno
< FIRST_PSEUDO_REGISTER
)
5662 add_to_hard_reg_set (&s
, reg
->biggest_mode
, dst_regno
);
5664 add_to_hard_reg_set (&s
, PSEUDO_REGNO_MODE (dst_regno
),
5665 reg_renumber
[dst_regno
]);
5666 AND_COMPL_HARD_REG_SET (live_hard_regs
, s
);
5668 /* We should invalidate potential inheritance or
5669 splitting for the current insn usages to the next
5670 usage insns (see code below) as the output pseudo
5672 if ((dst_regno
>= FIRST_PSEUDO_REGISTER
5673 && reg_renumber
[dst_regno
] < 0)
5674 || (reg
->type
== OP_OUT
&& ! reg
->subreg_p
5675 && (dst_regno
< FIRST_PSEUDO_REGISTER
5676 || reg_renumber
[dst_regno
] >= 0)))
5678 /* Invalidate and mark definitions. */
5679 if (dst_regno
>= FIRST_PSEUDO_REGISTER
)
5680 usage_insns
[dst_regno
].check
= -(int) INSN_UID (curr_insn
);
5683 nregs
= hard_regno_nregs
[dst_regno
][reg
->biggest_mode
];
5684 for (i
= 0; i
< nregs
; i
++)
5685 usage_insns
[dst_regno
+ i
].check
5686 = -(int) INSN_UID (curr_insn
);
5690 /* Process clobbered call regs. */
5691 if (curr_id
->arg_hard_regs
!= NULL
)
5692 for (i
= 0; (dst_regno
= curr_id
->arg_hard_regs
[i
]) >= 0; i
++)
5693 if (dst_regno
>= FIRST_PSEUDO_REGISTER
)
5694 usage_insns
[dst_regno
- FIRST_PSEUDO_REGISTER
].check
5695 = -(int) INSN_UID (curr_insn
);
5696 if (! JUMP_P (curr_insn
))
5697 for (i
= 0; i
< to_inherit_num
; i
++)
5698 if (inherit_reload_reg (true, to_inherit
[i
].regno
,
5699 ALL_REGS
, curr_insn
,
5700 to_inherit
[i
].insns
))
5702 if (CALL_P (curr_insn
))
5704 rtx cheap
, pat
, dest
;
5706 int regno
, hard_regno
;
5709 if ((cheap
= find_reg_note (curr_insn
,
5710 REG_RETURNED
, NULL_RTX
)) != NULL_RTX
5711 && ((cheap
= XEXP (cheap
, 0)), true)
5712 && (regno
= REGNO (cheap
)) >= FIRST_PSEUDO_REGISTER
5713 && (hard_regno
= reg_renumber
[regno
]) >= 0
5714 /* If there are pending saves/restores, the
5715 optimization is not worth. */
5716 && usage_insns
[regno
].calls_num
== calls_num
- 1
5717 && TEST_HARD_REG_BIT (call_used_reg_set
, hard_regno
))
5719 /* Restore the pseudo from the call result as
5720 REG_RETURNED note says that the pseudo value is
5721 in the call result and the pseudo is an argument
5723 pat
= PATTERN (curr_insn
);
5724 if (GET_CODE (pat
) == PARALLEL
)
5725 pat
= XVECEXP (pat
, 0, 0);
5726 dest
= SET_DEST (pat
);
5727 /* For multiple return values dest is PARALLEL.
5728 Currently we handle only single return value case. */
5732 emit_move_insn (cheap
, copy_rtx (dest
));
5733 restore
= get_insns ();
5735 lra_process_new_insns (curr_insn
, NULL
, restore
,
5736 "Inserting call parameter restore");
5737 /* We don't need to save/restore of the pseudo from
5739 usage_insns
[regno
].calls_num
= calls_num
;
5740 bitmap_set_bit (&check_only_regs
, regno
);
5745 /* Process insn usages. */
5746 for (iter
= 0; iter
< 2; iter
++)
5747 for (reg
= iter
== 0 ? curr_id
->regs
: curr_static_id
->hard_regs
;
5750 if ((reg
->type
!= OP_OUT
5751 || (reg
->type
== OP_OUT
&& reg
->subreg_p
))
5752 && (src_regno
= reg
->regno
) < lra_constraint_new_regno_start
)
5754 if (src_regno
>= FIRST_PSEUDO_REGISTER
5755 && reg_renumber
[src_regno
] < 0 && reg
->type
== OP_IN
)
5757 if (usage_insns
[src_regno
].check
== curr_usage_insns_check
5758 && (next_usage_insns
5759 = usage_insns
[src_regno
].insns
) != NULL_RTX
5760 && NONDEBUG_INSN_P (curr_insn
))
5761 add_to_inherit (src_regno
, next_usage_insns
);
5762 else if (usage_insns
[src_regno
].check
5763 != -(int) INSN_UID (curr_insn
))
5764 /* Add usages but only if the reg is not set up
5765 in the same insn. */
5766 add_next_usage_insn (src_regno
, curr_insn
, reloads_num
);
5768 else if (src_regno
< FIRST_PSEUDO_REGISTER
5769 || reg_renumber
[src_regno
] >= 0)
5772 rtx_insn
*use_insn
= curr_insn
;
5774 before_p
= (JUMP_P (curr_insn
)
5775 || (CALL_P (curr_insn
) && reg
->type
== OP_IN
));
5776 if (NONDEBUG_INSN_P (curr_insn
)
5777 && (! JUMP_P (curr_insn
) || reg
->type
== OP_IN
)
5778 && split_if_necessary (src_regno
, reg
->biggest_mode
,
5779 potential_reload_hard_regs
,
5780 before_p
, curr_insn
, max_uid
))
5783 lra_risky_transformations_p
= true;
5786 usage_insns
[src_regno
].check
= 0;
5788 use_insn
= PREV_INSN (curr_insn
);
5790 if (NONDEBUG_INSN_P (curr_insn
))
5792 if (src_regno
< FIRST_PSEUDO_REGISTER
)
5793 add_to_hard_reg_set (&live_hard_regs
,
5794 reg
->biggest_mode
, src_regno
);
5796 add_to_hard_reg_set (&live_hard_regs
,
5797 PSEUDO_REGNO_MODE (src_regno
),
5798 reg_renumber
[src_regno
]);
5800 add_next_usage_insn (src_regno
, use_insn
, reloads_num
);
5803 /* Process used call regs. */
5804 if (curr_id
->arg_hard_regs
!= NULL
)
5805 for (i
= 0; (src_regno
= curr_id
->arg_hard_regs
[i
]) >= 0; i
++)
5806 if (src_regno
< FIRST_PSEUDO_REGISTER
)
5808 SET_HARD_REG_BIT (live_hard_regs
, src_regno
);
5809 add_next_usage_insn (src_regno
, curr_insn
, reloads_num
);
5811 for (i
= 0; i
< to_inherit_num
; i
++)
5813 src_regno
= to_inherit
[i
].regno
;
5814 if (inherit_reload_reg (false, src_regno
, ALL_REGS
,
5815 curr_insn
, to_inherit
[i
].insns
))
5818 setup_next_usage_insn (src_regno
, curr_insn
, reloads_num
, false);
5821 if (update_reloads_num_p
5822 && NONDEBUG_INSN_P (curr_insn
)
5823 && (set
= single_set (curr_insn
)) != NULL_RTX
)
5826 if ((REG_P (SET_DEST (set
))
5827 && (regno
= REGNO (SET_DEST (set
))) >= lra_constraint_new_regno_start
5828 && reg_renumber
[regno
] < 0
5829 && (cl
= lra_get_allocno_class (regno
)) != NO_REGS
)
5830 || (REG_P (SET_SRC (set
))
5831 && (regno
= REGNO (SET_SRC (set
))) >= lra_constraint_new_regno_start
5832 && reg_renumber
[regno
] < 0
5833 && (cl
= lra_get_allocno_class (regno
)) != NO_REGS
))
5835 if (ira_class_hard_regs_num
[cl
] <= max_small_class_regs_num
)
5837 if (hard_reg_set_subset_p (reg_class_contents
[cl
], live_hard_regs
))
5838 IOR_HARD_REG_SET (potential_reload_hard_regs
,
5839 reg_class_contents
[cl
]);
5842 /* We reached the start of the current basic block. */
5843 if (prev_insn
== NULL_RTX
|| prev_insn
== PREV_INSN (head
)
5844 || BLOCK_FOR_INSN (prev_insn
) != curr_bb
)
5846 /* We reached the beginning of the current block -- do
5847 rest of spliting in the current BB. */
5848 to_process
= df_get_live_in (curr_bb
);
5849 if (BLOCK_FOR_INSN (head
) != curr_bb
)
5851 /* We are somewhere in the middle of EBB. */
5852 get_live_on_other_edges (EDGE_PRED (curr_bb
, 0)->src
,
5853 curr_bb
, &temp_bitmap
);
5854 to_process
= &temp_bitmap
;
5857 EXECUTE_IF_SET_IN_BITMAP (to_process
, 0, j
, bi
)
5859 if ((int) j
>= lra_constraint_new_regno_start
)
5861 if (((int) j
< FIRST_PSEUDO_REGISTER
|| reg_renumber
[j
] >= 0)
5862 && usage_insns
[j
].check
== curr_usage_insns_check
5863 && (next_usage_insns
= usage_insns
[j
].insns
) != NULL_RTX
)
5865 if (need_for_split_p (potential_reload_hard_regs
, j
))
5867 if (lra_dump_file
!= NULL
&& head_p
)
5869 fprintf (lra_dump_file
,
5870 " ----------------------------------\n");
5873 if (split_reg (false, j
, bb_note (curr_bb
),
5877 usage_insns
[j
].check
= 0;
5885 /* This value affects EBB forming. If probability of edge from EBB to
5886 a BB is not greater than the following value, we don't add the BB
5888 #define EBB_PROBABILITY_CUTOFF \
5889 ((REG_BR_PROB_BASE * LRA_INHERITANCE_EBB_PROBABILITY_CUTOFF) / 100)
5891 /* Current number of inheritance/split iteration. */
5892 int lra_inheritance_iter
;
5894 /* Entry function for inheritance/split pass. */
5896 lra_inheritance (void)
5899 basic_block bb
, start_bb
;
5902 lra_inheritance_iter
++;
5903 if (lra_inheritance_iter
> LRA_MAX_INHERITANCE_PASSES
)
5905 timevar_push (TV_LRA_INHERITANCE
);
5906 if (lra_dump_file
!= NULL
)
5907 fprintf (lra_dump_file
, "\n********** Inheritance #%d: **********\n\n",
5908 lra_inheritance_iter
);
5909 curr_usage_insns_check
= 0;
5910 usage_insns
= XNEWVEC (struct usage_insns
, lra_constraint_new_regno_start
);
5911 for (i
= 0; i
< lra_constraint_new_regno_start
; i
++)
5912 usage_insns
[i
].check
= 0;
5913 bitmap_initialize (&check_only_regs
, ®_obstack
);
5914 bitmap_initialize (&live_regs
, ®_obstack
);
5915 bitmap_initialize (&temp_bitmap
, ®_obstack
);
5916 bitmap_initialize (&ebb_global_regs
, ®_obstack
);
5917 FOR_EACH_BB_FN (bb
, cfun
)
5920 if (lra_dump_file
!= NULL
)
5921 fprintf (lra_dump_file
, "EBB");
5922 /* Form a EBB starting with BB. */
5923 bitmap_clear (&ebb_global_regs
);
5924 bitmap_ior_into (&ebb_global_regs
, df_get_live_in (bb
));
5927 if (lra_dump_file
!= NULL
)
5928 fprintf (lra_dump_file
, " %d", bb
->index
);
5929 if (bb
->next_bb
== EXIT_BLOCK_PTR_FOR_FN (cfun
)
5930 || LABEL_P (BB_HEAD (bb
->next_bb
)))
5932 e
= find_fallthru_edge (bb
->succs
);
5935 if (e
->probability
< EBB_PROBABILITY_CUTOFF
)
5939 bitmap_ior_into (&ebb_global_regs
, df_get_live_out (bb
));
5940 if (lra_dump_file
!= NULL
)
5941 fprintf (lra_dump_file
, "\n");
5942 if (inherit_in_ebb (BB_HEAD (start_bb
), BB_END (bb
)))
5943 /* Remember that the EBB head and tail can change in
5945 update_ebb_live_info (BB_HEAD (start_bb
), BB_END (bb
));
5947 bitmap_clear (&ebb_global_regs
);
5948 bitmap_clear (&temp_bitmap
);
5949 bitmap_clear (&live_regs
);
5950 bitmap_clear (&check_only_regs
);
5953 timevar_pop (TV_LRA_INHERITANCE
);
5958 /* This page contains code to undo failed inheritance/split
5961 /* Current number of iteration undoing inheritance/split. */
5962 int lra_undo_inheritance_iter
;
5964 /* Fix BB live info LIVE after removing pseudos created on pass doing
5965 inheritance/split which are REMOVED_PSEUDOS. */
5967 fix_bb_live_info (bitmap live
, bitmap removed_pseudos
)
5972 EXECUTE_IF_SET_IN_BITMAP (removed_pseudos
, 0, regno
, bi
)
5973 if (bitmap_clear_bit (live
, regno
))
5974 bitmap_set_bit (live
, lra_reg_info
[regno
].restore_regno
);
5977 /* Return regno of the (subreg of) REG. Otherwise, return a negative
5982 if (GET_CODE (reg
) == SUBREG
)
5983 reg
= SUBREG_REG (reg
);
5989 /* Delete a move INSN with destination reg DREGNO and a previous
5990 clobber insn with the same regno. The inheritance/split code can
5991 generate moves with preceding clobber and when we delete such moves
5992 we should delete the clobber insn too to keep the correct life
5995 delete_move_and_clobber (rtx_insn
*insn
, int dregno
)
5997 rtx_insn
*prev_insn
= PREV_INSN (insn
);
5999 lra_set_insn_deleted (insn
);
6000 lra_assert (dregno
>= 0);
6001 if (prev_insn
!= NULL
&& NONDEBUG_INSN_P (prev_insn
)
6002 && GET_CODE (PATTERN (prev_insn
)) == CLOBBER
6003 && dregno
== get_regno (XEXP (PATTERN (prev_insn
), 0)))
6004 lra_set_insn_deleted (prev_insn
);
6007 /* Remove inheritance/split pseudos which are in REMOVE_PSEUDOS and
6008 return true if we did any change. The undo transformations for
6009 inheritance looks like
6013 p <- i, i <- p, and i <- i3
6014 where p is original pseudo from which inheritance pseudo i was
6015 created, i and i3 are removed inheritance pseudos, i2 is another
6016 not removed inheritance pseudo. All split pseudos or other
6017 occurrences of removed inheritance pseudos are changed on the
6018 corresponding original pseudos.
6020 The function also schedules insns changed and created during
6021 inheritance/split pass for processing by the subsequent constraint
6024 remove_inheritance_pseudos (bitmap remove_pseudos
)
6027 int regno
, sregno
, prev_sregno
, dregno
, restore_regno
;
6029 rtx_insn
*prev_insn
;
6030 bool change_p
, done_p
;
6032 change_p
= ! bitmap_empty_p (remove_pseudos
);
6033 /* We can not finish the function right away if CHANGE_P is true
6034 because we need to marks insns affected by previous
6035 inheritance/split pass for processing by the subsequent
6037 FOR_EACH_BB_FN (bb
, cfun
)
6039 fix_bb_live_info (df_get_live_in (bb
), remove_pseudos
);
6040 fix_bb_live_info (df_get_live_out (bb
), remove_pseudos
);
6041 FOR_BB_INSNS_REVERSE (bb
, curr_insn
)
6043 if (! INSN_P (curr_insn
))
6046 sregno
= dregno
= -1;
6047 if (change_p
&& NONDEBUG_INSN_P (curr_insn
)
6048 && (set
= single_set (curr_insn
)) != NULL_RTX
)
6050 dregno
= get_regno (SET_DEST (set
));
6051 sregno
= get_regno (SET_SRC (set
));
6054 if (sregno
>= 0 && dregno
>= 0)
6056 if ((bitmap_bit_p (remove_pseudos
, sregno
)
6057 && (lra_reg_info
[sregno
].restore_regno
== dregno
6058 || (bitmap_bit_p (remove_pseudos
, dregno
)
6059 && (lra_reg_info
[sregno
].restore_regno
6060 == lra_reg_info
[dregno
].restore_regno
))))
6061 || (bitmap_bit_p (remove_pseudos
, dregno
)
6062 && lra_reg_info
[dregno
].restore_regno
== sregno
))
6063 /* One of the following cases:
6064 original <- removed inheritance pseudo
6065 removed inherit pseudo <- another removed inherit pseudo
6066 removed inherit pseudo <- original pseudo
6068 removed_split_pseudo <- original_reg
6069 original_reg <- removed_split_pseudo */
6071 if (lra_dump_file
!= NULL
)
6073 fprintf (lra_dump_file
, " Removing %s:\n",
6074 bitmap_bit_p (&lra_split_regs
, sregno
)
6075 || bitmap_bit_p (&lra_split_regs
, dregno
)
6076 ? "split" : "inheritance");
6077 dump_insn_slim (lra_dump_file
, curr_insn
);
6079 delete_move_and_clobber (curr_insn
, dregno
);
6082 else if (bitmap_bit_p (remove_pseudos
, sregno
)
6083 && bitmap_bit_p (&lra_inheritance_pseudos
, sregno
))
6085 /* Search the following pattern:
6086 inherit_or_split_pseudo1 <- inherit_or_split_pseudo2
6087 original_pseudo <- inherit_or_split_pseudo1
6088 where the 2nd insn is the current insn and
6089 inherit_or_split_pseudo2 is not removed. If it is found,
6090 change the current insn onto:
6091 original_pseudo <- inherit_or_split_pseudo2. */
6092 for (prev_insn
= PREV_INSN (curr_insn
);
6093 prev_insn
!= NULL_RTX
&& ! NONDEBUG_INSN_P (prev_insn
);
6094 prev_insn
= PREV_INSN (prev_insn
))
6096 if (prev_insn
!= NULL_RTX
&& BLOCK_FOR_INSN (prev_insn
) == bb
6097 && (prev_set
= single_set (prev_insn
)) != NULL_RTX
6098 /* There should be no subregs in insn we are
6099 searching because only the original reg might
6100 be in subreg when we changed the mode of
6101 load/store for splitting. */
6102 && REG_P (SET_DEST (prev_set
))
6103 && REG_P (SET_SRC (prev_set
))
6104 && (int) REGNO (SET_DEST (prev_set
)) == sregno
6105 && ((prev_sregno
= REGNO (SET_SRC (prev_set
)))
6106 >= FIRST_PSEUDO_REGISTER
)
6107 /* As we consider chain of inheritance or
6108 splitting described in above comment we should
6109 check that sregno and prev_sregno were
6110 inheritance/split pseudos created from the
6111 same original regno. */
6112 && (lra_reg_info
[sregno
].restore_regno
6113 == lra_reg_info
[prev_sregno
].restore_regno
)
6114 && ! bitmap_bit_p (remove_pseudos
, prev_sregno
))
6116 lra_assert (GET_MODE (SET_SRC (prev_set
))
6117 == GET_MODE (regno_reg_rtx
[sregno
]));
6118 if (GET_CODE (SET_SRC (set
)) == SUBREG
)
6119 SUBREG_REG (SET_SRC (set
)) = SET_SRC (prev_set
);
6121 SET_SRC (set
) = SET_SRC (prev_set
);
6122 /* As we are finishing with processing the insn
6123 here, check the destination too as it might
6124 inheritance pseudo for another pseudo. */
6125 if (bitmap_bit_p (remove_pseudos
, dregno
)
6126 && bitmap_bit_p (&lra_inheritance_pseudos
, dregno
)
6128 = lra_reg_info
[dregno
].restore_regno
) >= 0)
6130 if (GET_CODE (SET_DEST (set
)) == SUBREG
)
6131 SUBREG_REG (SET_DEST (set
))
6132 = regno_reg_rtx
[restore_regno
];
6134 SET_DEST (set
) = regno_reg_rtx
[restore_regno
];
6136 lra_push_insn_and_update_insn_regno_info (curr_insn
);
6137 lra_set_used_insn_alternative_by_uid
6138 (INSN_UID (curr_insn
), -1);
6140 if (lra_dump_file
!= NULL
)
6142 fprintf (lra_dump_file
, " Change reload insn:\n");
6143 dump_insn_slim (lra_dump_file
, curr_insn
);
6150 struct lra_insn_reg
*reg
;
6151 bool restored_regs_p
= false;
6152 bool kept_regs_p
= false;
6154 curr_id
= lra_get_insn_recog_data (curr_insn
);
6155 for (reg
= curr_id
->regs
; reg
!= NULL
; reg
= reg
->next
)
6158 restore_regno
= lra_reg_info
[regno
].restore_regno
;
6159 if (restore_regno
>= 0)
6161 if (change_p
&& bitmap_bit_p (remove_pseudos
, regno
))
6163 lra_substitute_pseudo_within_insn
6164 (curr_insn
, regno
, regno_reg_rtx
[restore_regno
],
6166 restored_regs_p
= true;
6172 if (NONDEBUG_INSN_P (curr_insn
) && kept_regs_p
)
6174 /* The instruction has changed since the previous
6175 constraints pass. */
6176 lra_push_insn_and_update_insn_regno_info (curr_insn
);
6177 lra_set_used_insn_alternative_by_uid
6178 (INSN_UID (curr_insn
), -1);
6180 else if (restored_regs_p
)
6181 /* The instruction has been restored to the form that
6182 it had during the previous constraints pass. */
6183 lra_update_insn_regno_info (curr_insn
);
6184 if (restored_regs_p
&& lra_dump_file
!= NULL
)
6186 fprintf (lra_dump_file
, " Insn after restoring regs:\n");
6187 dump_insn_slim (lra_dump_file
, curr_insn
);
6195 /* If optional reload pseudos failed to get a hard register or was not
6196 inherited, it is better to remove optional reloads. We do this
6197 transformation after undoing inheritance to figure out necessity to
6198 remove optional reloads easier. Return true if we do any
6201 undo_optional_reloads (void)
6203 bool change_p
, keep_p
;
6204 unsigned int regno
, uid
;
6205 bitmap_iterator bi
, bi2
;
6208 bitmap_head removed_optional_reload_pseudos
, insn_bitmap
;
6210 bitmap_initialize (&removed_optional_reload_pseudos
, ®_obstack
);
6211 bitmap_copy (&removed_optional_reload_pseudos
, &lra_optional_reload_pseudos
);
6212 EXECUTE_IF_SET_IN_BITMAP (&lra_optional_reload_pseudos
, 0, regno
, bi
)
6215 /* Keep optional reloads from previous subpasses. */
6216 if (lra_reg_info
[regno
].restore_regno
< 0
6217 /* If the original pseudo changed its allocation, just
6218 removing the optional pseudo is dangerous as the original
6219 pseudo will have longer live range. */
6220 || reg_renumber
[lra_reg_info
[regno
].restore_regno
] >= 0)
6222 else if (reg_renumber
[regno
] >= 0)
6223 EXECUTE_IF_SET_IN_BITMAP (&lra_reg_info
[regno
].insn_bitmap
, 0, uid
, bi2
)
6225 insn
= lra_insn_recog_data
[uid
]->insn
;
6226 if ((set
= single_set (insn
)) == NULL_RTX
)
6228 src
= SET_SRC (set
);
6229 dest
= SET_DEST (set
);
6230 if (! REG_P (src
) || ! REG_P (dest
))
6232 if (REGNO (dest
) == regno
6233 /* Ignore insn for optional reloads itself. */
6234 && lra_reg_info
[regno
].restore_regno
!= (int) REGNO (src
)
6235 /* Check only inheritance on last inheritance pass. */
6236 && (int) REGNO (src
) >= new_regno_start
6237 /* Check that the optional reload was inherited. */
6238 && bitmap_bit_p (&lra_inheritance_pseudos
, REGNO (src
)))
6246 bitmap_clear_bit (&removed_optional_reload_pseudos
, regno
);
6247 if (lra_dump_file
!= NULL
)
6248 fprintf (lra_dump_file
, "Keep optional reload reg %d\n", regno
);
6251 change_p
= ! bitmap_empty_p (&removed_optional_reload_pseudos
);
6252 bitmap_initialize (&insn_bitmap
, ®_obstack
);
6253 EXECUTE_IF_SET_IN_BITMAP (&removed_optional_reload_pseudos
, 0, regno
, bi
)
6255 if (lra_dump_file
!= NULL
)
6256 fprintf (lra_dump_file
, "Remove optional reload reg %d\n", regno
);
6257 bitmap_copy (&insn_bitmap
, &lra_reg_info
[regno
].insn_bitmap
);
6258 EXECUTE_IF_SET_IN_BITMAP (&insn_bitmap
, 0, uid
, bi2
)
6260 insn
= lra_insn_recog_data
[uid
]->insn
;
6261 if ((set
= single_set (insn
)) != NULL_RTX
)
6263 src
= SET_SRC (set
);
6264 dest
= SET_DEST (set
);
6265 if (REG_P (src
) && REG_P (dest
)
6266 && ((REGNO (src
) == regno
6267 && (lra_reg_info
[regno
].restore_regno
6268 == (int) REGNO (dest
)))
6269 || (REGNO (dest
) == regno
6270 && (lra_reg_info
[regno
].restore_regno
6271 == (int) REGNO (src
)))))
6273 if (lra_dump_file
!= NULL
)
6275 fprintf (lra_dump_file
, " Deleting move %u\n",
6277 dump_insn_slim (lra_dump_file
, insn
);
6279 delete_move_and_clobber (insn
, REGNO (dest
));
6282 /* We should not worry about generation memory-memory
6283 moves here as if the corresponding inheritance did
6284 not work (inheritance pseudo did not get a hard reg),
6285 we remove the inheritance pseudo and the optional
6288 lra_substitute_pseudo_within_insn
6289 (insn
, regno
, regno_reg_rtx
[lra_reg_info
[regno
].restore_regno
],
6291 lra_update_insn_regno_info (insn
);
6292 if (lra_dump_file
!= NULL
)
6294 fprintf (lra_dump_file
,
6295 " Restoring original insn:\n");
6296 dump_insn_slim (lra_dump_file
, insn
);
6300 /* Clear restore_regnos. */
6301 EXECUTE_IF_SET_IN_BITMAP (&lra_optional_reload_pseudos
, 0, regno
, bi
)
6302 lra_reg_info
[regno
].restore_regno
= -1;
6303 bitmap_clear (&insn_bitmap
);
6304 bitmap_clear (&removed_optional_reload_pseudos
);
6308 /* Entry function for undoing inheritance/split transformation. Return true
6309 if we did any RTL change in this pass. */
6311 lra_undo_inheritance (void)
6314 int restore_regno
, hard_regno
;
6315 int n_all_inherit
, n_inherit
, n_all_split
, n_split
;
6316 bitmap_head remove_pseudos
;
6320 lra_undo_inheritance_iter
++;
6321 if (lra_undo_inheritance_iter
> LRA_MAX_INHERITANCE_PASSES
)
6323 if (lra_dump_file
!= NULL
)
6324 fprintf (lra_dump_file
,
6325 "\n********** Undoing inheritance #%d: **********\n\n",
6326 lra_undo_inheritance_iter
);
6327 bitmap_initialize (&remove_pseudos
, ®_obstack
);
6328 n_inherit
= n_all_inherit
= 0;
6329 EXECUTE_IF_SET_IN_BITMAP (&lra_inheritance_pseudos
, 0, regno
, bi
)
6330 if (lra_reg_info
[regno
].restore_regno
>= 0)
6333 if (reg_renumber
[regno
] < 0
6334 /* If the original pseudo changed its allocation, just
6335 removing inheritance is dangerous as for changing
6336 allocation we used shorter live-ranges. */
6337 && reg_renumber
[lra_reg_info
[regno
].restore_regno
] < 0)
6338 bitmap_set_bit (&remove_pseudos
, regno
);
6342 if (lra_dump_file
!= NULL
&& n_all_inherit
!= 0)
6343 fprintf (lra_dump_file
, "Inherit %d out of %d (%.2f%%)\n",
6344 n_inherit
, n_all_inherit
,
6345 (double) n_inherit
/ n_all_inherit
* 100);
6346 n_split
= n_all_split
= 0;
6347 EXECUTE_IF_SET_IN_BITMAP (&lra_split_regs
, 0, regno
, bi
)
6348 if ((restore_regno
= lra_reg_info
[regno
].restore_regno
) >= 0)
6351 hard_regno
= (restore_regno
>= FIRST_PSEUDO_REGISTER
6352 ? reg_renumber
[restore_regno
] : restore_regno
);
6353 if (hard_regno
< 0 || reg_renumber
[regno
] == hard_regno
)
6354 bitmap_set_bit (&remove_pseudos
, regno
);
6358 if (lra_dump_file
!= NULL
)
6359 fprintf (lra_dump_file
, " Keep split r%d (orig=r%d)\n",
6360 regno
, restore_regno
);
6363 if (lra_dump_file
!= NULL
&& n_all_split
!= 0)
6364 fprintf (lra_dump_file
, "Split %d out of %d (%.2f%%)\n",
6365 n_split
, n_all_split
,
6366 (double) n_split
/ n_all_split
* 100);
6367 change_p
= remove_inheritance_pseudos (&remove_pseudos
);
6368 bitmap_clear (&remove_pseudos
);
6369 /* Clear restore_regnos. */
6370 EXECUTE_IF_SET_IN_BITMAP (&lra_inheritance_pseudos
, 0, regno
, bi
)
6371 lra_reg_info
[regno
].restore_regno
= -1;
6372 EXECUTE_IF_SET_IN_BITMAP (&lra_split_regs
, 0, regno
, bi
)
6373 lra_reg_info
[regno
].restore_regno
= -1;
6374 change_p
= undo_optional_reloads () || change_p
;