1 /* Code for RTL transformations to satisfy insn constraints.
2 Copyright (C) 2010-2014 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"
113 #include "hard-reg-set.h"
117 #include "insn-config.h"
118 #include "insn-codes.h"
121 #include "addresses.h"
123 #include "function.h"
125 #include "basic-block.h"
130 #include "rtl-error.h"
133 /* Value of LRA_CURR_RELOAD_NUM at the beginning of BB of the current
134 insn. Remember that LRA_CURR_RELOAD_NUM is the number of emitted
136 static int bb_reload_num
;
138 /* The current insn being processed and corresponding its single set
139 (NULL otherwise), its data (basic block, the insn data, the insn
140 static data, and the mode of each operand). */
141 static rtx curr_insn
;
142 static rtx curr_insn_set
;
143 static basic_block curr_bb
;
144 static lra_insn_recog_data_t curr_id
;
145 static struct lra_static_insn_data
*curr_static_id
;
146 static enum machine_mode curr_operand_mode
[MAX_RECOG_OPERANDS
];
150 /* Start numbers for new registers and insns at the current constraints
152 static int new_regno_start
;
153 static int new_insn_uid_start
;
155 /* If LOC is nonnull, strip any outer subreg from it. */
157 strip_subreg (rtx
*loc
)
159 return loc
&& GET_CODE (*loc
) == SUBREG
? &SUBREG_REG (*loc
) : loc
;
162 /* Return hard regno of REGNO or if it is was not assigned to a hard
163 register, use a hard register from its allocno class. */
165 get_try_hard_regno (int regno
)
168 enum reg_class rclass
;
170 if ((hard_regno
= regno
) >= FIRST_PSEUDO_REGISTER
)
171 hard_regno
= lra_get_regno_hard_regno (regno
);
174 rclass
= lra_get_allocno_class (regno
);
175 if (rclass
== NO_REGS
)
177 return ira_class_hard_regs
[rclass
][0];
180 /* Return final hard regno (plus offset) which will be after
181 elimination. We do this for matching constraints because the final
182 hard regno could have a different class. */
184 get_final_hard_regno (int hard_regno
, int offset
)
188 hard_regno
= lra_get_elimination_hard_regno (hard_regno
);
189 return hard_regno
+ offset
;
192 /* Return hard regno of X after removing subreg and making
193 elimination. If X is not a register or subreg of register, return
194 -1. For pseudo use its assignment. */
196 get_hard_regno (rtx x
)
199 int offset
, hard_regno
;
202 if (GET_CODE (x
) == SUBREG
)
203 reg
= SUBREG_REG (x
);
206 if ((hard_regno
= REGNO (reg
)) >= FIRST_PSEUDO_REGISTER
)
207 hard_regno
= lra_get_regno_hard_regno (hard_regno
);
211 if (GET_CODE (x
) == SUBREG
)
212 offset
+= subreg_regno_offset (hard_regno
, GET_MODE (reg
),
213 SUBREG_BYTE (x
), GET_MODE (x
));
214 return get_final_hard_regno (hard_regno
, offset
);
217 /* If REGNO is a hard register or has been allocated a hard register,
218 return the class of that register. If REGNO is a reload pseudo
219 created by the current constraints pass, return its allocno class.
220 Return NO_REGS otherwise. */
221 static enum reg_class
222 get_reg_class (int regno
)
226 if ((hard_regno
= regno
) >= FIRST_PSEUDO_REGISTER
)
227 hard_regno
= lra_get_regno_hard_regno (regno
);
230 hard_regno
= get_final_hard_regno (hard_regno
, 0);
231 return REGNO_REG_CLASS (hard_regno
);
233 if (regno
>= new_regno_start
)
234 return lra_get_allocno_class (regno
);
238 /* Return true if REG satisfies (or will satisfy) reg class constraint
239 CL. Use elimination first if REG is a hard register. If REG is a
240 reload pseudo created by this constraints pass, assume that it will
241 be allocated a hard register from its allocno class, but allow that
242 class to be narrowed to CL if it is currently a superset of CL.
244 If NEW_CLASS is nonnull, set *NEW_CLASS to the new allocno class of
245 REGNO (reg), or NO_REGS if no change in its class was needed. */
247 in_class_p (rtx reg
, enum reg_class cl
, enum reg_class
*new_class
)
249 enum reg_class rclass
, common_class
;
250 enum machine_mode reg_mode
;
251 int class_size
, hard_regno
, nregs
, i
, j
;
252 int regno
= REGNO (reg
);
254 if (new_class
!= NULL
)
255 *new_class
= NO_REGS
;
256 if (regno
< FIRST_PSEUDO_REGISTER
)
259 rtx
*final_loc
= &final_reg
;
261 lra_eliminate_reg_if_possible (final_loc
);
262 return TEST_HARD_REG_BIT (reg_class_contents
[cl
], REGNO (*final_loc
));
264 reg_mode
= GET_MODE (reg
);
265 rclass
= get_reg_class (regno
);
266 if (regno
< new_regno_start
267 /* Do not allow the constraints for reload instructions to
268 influence the classes of new pseudos. These reloads are
269 typically moves that have many alternatives, and restricting
270 reload pseudos for one alternative may lead to situations
271 where other reload pseudos are no longer allocatable. */
272 || (INSN_UID (curr_insn
) >= new_insn_uid_start
273 && curr_insn_set
!= NULL
274 && ((OBJECT_P (SET_SRC (curr_insn_set
))
275 && ! CONSTANT_P (SET_SRC (curr_insn_set
)))
276 || (GET_CODE (SET_SRC (curr_insn_set
)) == SUBREG
277 && OBJECT_P (SUBREG_REG (SET_SRC (curr_insn_set
)))
278 && ! CONSTANT_P (SUBREG_REG (SET_SRC (curr_insn_set
)))))))
279 /* When we don't know what class will be used finally for reload
280 pseudos, we use ALL_REGS. */
281 return ((regno
>= new_regno_start
&& rclass
== ALL_REGS
)
282 || (rclass
!= NO_REGS
&& ira_class_subset_p
[rclass
][cl
]
283 && ! hard_reg_set_subset_p (reg_class_contents
[cl
],
284 lra_no_alloc_regs
)));
287 common_class
= ira_reg_class_subset
[rclass
][cl
];
288 if (new_class
!= NULL
)
289 *new_class
= common_class
;
290 if (hard_reg_set_subset_p (reg_class_contents
[common_class
],
293 /* Check that there are enough allocatable regs. */
294 class_size
= ira_class_hard_regs_num
[common_class
];
295 for (i
= 0; i
< class_size
; i
++)
297 hard_regno
= ira_class_hard_regs
[common_class
][i
];
298 nregs
= hard_regno_nregs
[hard_regno
][reg_mode
];
301 for (j
= 0; j
< nregs
; j
++)
302 if (TEST_HARD_REG_BIT (lra_no_alloc_regs
, hard_regno
+ j
)
303 || ! TEST_HARD_REG_BIT (reg_class_contents
[common_class
],
313 /* Return true if REGNO satisfies a memory constraint. */
317 return get_reg_class (regno
) == NO_REGS
;
320 /* Return 1 if ADDR is a valid memory address for mode MODE in address
321 space AS, and check that each pseudo has the proper kind of hard
324 valid_address_p (enum machine_mode mode ATTRIBUTE_UNUSED
,
325 rtx addr
, addr_space_t as
)
327 #ifdef GO_IF_LEGITIMATE_ADDRESS
328 lra_assert (ADDR_SPACE_GENERIC_P (as
));
329 GO_IF_LEGITIMATE_ADDRESS (mode
, addr
, win
);
335 return targetm
.addr_space
.legitimate_address_p (mode
, addr
, 0, as
);
340 /* Temporarily eliminates registers in an address (for the lifetime of
342 class address_eliminator
{
344 address_eliminator (struct address_info
*ad
);
345 ~address_eliminator ();
348 struct address_info
*m_ad
;
356 address_eliminator::address_eliminator (struct address_info
*ad
)
358 m_base_loc (strip_subreg (ad
->base_term
)),
359 m_base_reg (NULL_RTX
),
360 m_index_loc (strip_subreg (ad
->index_term
)),
361 m_index_reg (NULL_RTX
)
363 if (m_base_loc
!= NULL
)
365 m_base_reg
= *m_base_loc
;
366 lra_eliminate_reg_if_possible (m_base_loc
);
367 if (m_ad
->base_term2
!= NULL
)
368 *m_ad
->base_term2
= *m_ad
->base_term
;
370 if (m_index_loc
!= NULL
)
372 m_index_reg
= *m_index_loc
;
373 lra_eliminate_reg_if_possible (m_index_loc
);
377 address_eliminator::~address_eliminator ()
379 if (m_base_loc
&& *m_base_loc
!= m_base_reg
)
381 *m_base_loc
= m_base_reg
;
382 if (m_ad
->base_term2
!= NULL
)
383 *m_ad
->base_term2
= *m_ad
->base_term
;
385 if (m_index_loc
&& *m_index_loc
!= m_index_reg
)
386 *m_index_loc
= m_index_reg
;
389 /* Return true if the eliminated form of AD is a legitimate target address. */
391 valid_address_p (struct address_info
*ad
)
393 address_eliminator
eliminator (ad
);
394 return valid_address_p (ad
->mode
, *ad
->outer
, ad
->as
);
397 #ifdef EXTRA_CONSTRAINT_STR
398 /* Return true if the eliminated form of memory reference OP satisfies
399 extra memory constraint CONSTRAINT. */
401 satisfies_memory_constraint_p (rtx op
, const char *constraint
)
403 struct address_info ad
;
405 decompose_mem_address (&ad
, op
);
406 address_eliminator
eliminator (&ad
);
407 return EXTRA_CONSTRAINT_STR (op
, *constraint
, constraint
);
410 /* Return true if the eliminated form of address AD satisfies extra
411 address constraint CONSTRAINT. */
413 satisfies_address_constraint_p (struct address_info
*ad
,
414 const char *constraint
)
416 address_eliminator
eliminator (ad
);
417 return EXTRA_CONSTRAINT_STR (*ad
->outer
, *constraint
, constraint
);
420 /* Return true if the eliminated form of address OP satisfies extra
421 address constraint CONSTRAINT. */
423 satisfies_address_constraint_p (rtx op
, const char *constraint
)
425 struct address_info ad
;
427 decompose_lea_address (&ad
, &op
);
428 return satisfies_address_constraint_p (&ad
, constraint
);
432 /* Initiate equivalences for LRA. As we keep original equivalences
433 before any elimination, we need to make copies otherwise any change
434 in insns might change the equivalences. */
436 lra_init_equiv (void)
438 ira_expand_reg_equiv ();
439 for (int i
= FIRST_PSEUDO_REGISTER
; i
< max_reg_num (); i
++)
443 if ((res
= ira_reg_equiv
[i
].memory
) != NULL_RTX
)
444 ira_reg_equiv
[i
].memory
= copy_rtx (res
);
445 if ((res
= ira_reg_equiv
[i
].invariant
) != NULL_RTX
)
446 ira_reg_equiv
[i
].invariant
= copy_rtx (res
);
450 static rtx
loc_equivalence_callback (rtx
, const_rtx
, void *);
452 /* Update equivalence for REGNO. We need to this as the equivalence
453 might contain other pseudos which are changed by their
456 update_equiv (int regno
)
460 if ((x
= ira_reg_equiv
[regno
].memory
) != NULL_RTX
)
461 ira_reg_equiv
[regno
].memory
462 = simplify_replace_fn_rtx (x
, NULL_RTX
, loc_equivalence_callback
,
464 if ((x
= ira_reg_equiv
[regno
].invariant
) != NULL_RTX
)
465 ira_reg_equiv
[regno
].invariant
466 = simplify_replace_fn_rtx (x
, NULL_RTX
, loc_equivalence_callback
,
470 /* If we have decided to substitute X with another value, return that
471 value, otherwise return X. */
478 if (! REG_P (x
) || (regno
= REGNO (x
)) < FIRST_PSEUDO_REGISTER
479 || ! ira_reg_equiv
[regno
].defined_p
480 || ! ira_reg_equiv
[regno
].profitable_p
481 || lra_get_regno_hard_regno (regno
) >= 0)
483 if ((res
= ira_reg_equiv
[regno
].memory
) != NULL_RTX
)
485 if ((res
= ira_reg_equiv
[regno
].constant
) != NULL_RTX
)
487 if ((res
= ira_reg_equiv
[regno
].invariant
) != NULL_RTX
)
492 /* If we have decided to substitute X with the equivalent value,
493 return that value after elimination for INSN, otherwise return
496 get_equiv_with_elimination (rtx x
, rtx insn
)
498 rtx res
= get_equiv (x
);
500 if (x
== res
|| CONSTANT_P (res
))
502 return lra_eliminate_regs_1 (insn
, res
, GET_MODE (res
), false, false, true);
505 /* Set up curr_operand_mode. */
507 init_curr_operand_mode (void)
509 int nop
= curr_static_id
->n_operands
;
510 for (int i
= 0; i
< nop
; i
++)
512 enum machine_mode mode
= GET_MODE (*curr_id
->operand_loc
[i
]);
513 if (mode
== VOIDmode
)
515 /* The .md mode for address operands is the mode of the
516 addressed value rather than the mode of the address itself. */
517 if (curr_id
->icode
>= 0 && curr_static_id
->operand
[i
].is_address
)
520 mode
= curr_static_id
->operand
[i
].mode
;
522 curr_operand_mode
[i
] = mode
;
528 /* The page contains code to reuse input reloads. */
530 /* Structure describes input reload of the current insns. */
533 /* Reloaded value. */
535 /* Reload pseudo used. */
539 /* The number of elements in the following array. */
540 static int curr_insn_input_reloads_num
;
541 /* Array containing info about input reloads. It is used to find the
542 same input reload and reuse the reload pseudo in this case. */
543 static struct input_reload curr_insn_input_reloads
[LRA_MAX_INSN_RELOADS
];
545 /* Initiate data concerning reuse of input reloads for the current
548 init_curr_insn_input_reloads (void)
550 curr_insn_input_reloads_num
= 0;
553 /* Create a new pseudo using MODE, RCLASS, ORIGINAL or reuse already
554 created input reload pseudo (only if TYPE is not OP_OUT). Don't
555 reuse pseudo if IN_SUBREG_P is true and the reused pseudo should be
556 wrapped up in SUBREG. The result pseudo is returned through
557 RESULT_REG. Return TRUE if we created a new pseudo, FALSE if we
558 reused the already created input reload pseudo. Use TITLE to
559 describe new registers for debug purposes. */
561 get_reload_reg (enum op_type type
, enum machine_mode mode
, rtx original
,
562 enum reg_class rclass
, bool in_subreg_p
,
563 const char *title
, rtx
*result_reg
)
566 enum reg_class new_class
;
571 = lra_create_new_reg_with_unique_value (mode
, original
, rclass
, title
);
574 /* Prevent reuse value of expression with side effects,
575 e.g. volatile memory. */
576 if (! side_effects_p (original
))
577 for (i
= 0; i
< curr_insn_input_reloads_num
; i
++)
578 if (rtx_equal_p (curr_insn_input_reloads
[i
].input
, original
)
579 && in_class_p (curr_insn_input_reloads
[i
].reg
, rclass
, &new_class
))
581 rtx reg
= curr_insn_input_reloads
[i
].reg
;
583 /* If input is equal to original and both are VOIDmode,
584 GET_MODE (reg) might be still different from mode.
585 Ensure we don't return *result_reg with wrong mode. */
586 if (GET_MODE (reg
) != mode
)
590 if (GET_MODE_SIZE (GET_MODE (reg
)) < GET_MODE_SIZE (mode
))
592 reg
= lowpart_subreg (mode
, reg
, GET_MODE (reg
));
593 if (reg
== NULL_RTX
|| GET_CODE (reg
) != SUBREG
)
597 if (lra_dump_file
!= NULL
)
599 fprintf (lra_dump_file
, " Reuse r%d for reload ", regno
);
600 dump_value_slim (lra_dump_file
, original
, 1);
602 if (new_class
!= lra_get_allocno_class (regno
))
603 lra_change_class (regno
, new_class
, ", change to", false);
604 if (lra_dump_file
!= NULL
)
605 fprintf (lra_dump_file
, "\n");
608 *result_reg
= lra_create_new_reg (mode
, original
, rclass
, title
);
609 lra_assert (curr_insn_input_reloads_num
< LRA_MAX_INSN_RELOADS
);
610 curr_insn_input_reloads
[curr_insn_input_reloads_num
].input
= original
;
611 curr_insn_input_reloads
[curr_insn_input_reloads_num
++].reg
= *result_reg
;
617 /* The page contains code to extract memory address parts. */
619 /* Wrapper around REGNO_OK_FOR_INDEX_P, to allow pseudos. */
621 ok_for_index_p_nonstrict (rtx reg
)
623 unsigned regno
= REGNO (reg
);
625 return regno
>= FIRST_PSEUDO_REGISTER
|| REGNO_OK_FOR_INDEX_P (regno
);
628 /* A version of regno_ok_for_base_p for use here, when all pseudos
629 should count as OK. Arguments as for regno_ok_for_base_p. */
631 ok_for_base_p_nonstrict (rtx reg
, enum machine_mode mode
, addr_space_t as
,
632 enum rtx_code outer_code
, enum rtx_code index_code
)
634 unsigned regno
= REGNO (reg
);
636 if (regno
>= FIRST_PSEUDO_REGISTER
)
638 return ok_for_base_p_1 (regno
, mode
, as
, outer_code
, index_code
);
643 /* The page contains major code to choose the current insn alternative
644 and generate reloads for it. */
646 /* Return the offset from REGNO of the least significant register
649 This function is used to tell whether two registers satisfy
650 a matching constraint. (reg:MODE1 REGNO1) matches (reg:MODE2 REGNO2) if:
652 REGNO1 + lra_constraint_offset (REGNO1, MODE1)
653 == REGNO2 + lra_constraint_offset (REGNO2, MODE2) */
655 lra_constraint_offset (int regno
, enum machine_mode mode
)
657 lra_assert (regno
< FIRST_PSEUDO_REGISTER
);
658 if (WORDS_BIG_ENDIAN
&& GET_MODE_SIZE (mode
) > UNITS_PER_WORD
659 && SCALAR_INT_MODE_P (mode
))
660 return hard_regno_nregs
[regno
][mode
] - 1;
664 /* Like rtx_equal_p except that it allows a REG and a SUBREG to match
665 if they are the same hard reg, and has special hacks for
666 auto-increment and auto-decrement. This is specifically intended for
667 process_alt_operands to use in determining whether two operands
668 match. X is the operand whose number is the lower of the two.
670 It is supposed that X is the output operand and Y is the input
671 operand. Y_HARD_REGNO is the final hard regno of register Y or
672 register in subreg Y as we know it now. Otherwise, it is a
675 operands_match_p (rtx x
, rtx y
, int y_hard_regno
)
678 RTX_CODE code
= GET_CODE (x
);
683 if ((code
== REG
|| (code
== SUBREG
&& REG_P (SUBREG_REG (x
))))
684 && (REG_P (y
) || (GET_CODE (y
) == SUBREG
&& REG_P (SUBREG_REG (y
)))))
688 i
= get_hard_regno (x
);
692 if ((j
= y_hard_regno
) < 0)
695 i
+= lra_constraint_offset (i
, GET_MODE (x
));
696 j
+= lra_constraint_offset (j
, GET_MODE (y
));
701 /* If two operands must match, because they are really a single
702 operand of an assembler insn, then two post-increments are invalid
703 because the assembler insn would increment only once. On the
704 other hand, a post-increment matches ordinary indexing if the
705 post-increment is the output operand. */
706 if (code
== POST_DEC
|| code
== POST_INC
|| code
== POST_MODIFY
)
707 return operands_match_p (XEXP (x
, 0), y
, y_hard_regno
);
709 /* Two pre-increments are invalid because the assembler insn would
710 increment only once. On the other hand, a pre-increment matches
711 ordinary indexing if the pre-increment is the input operand. */
712 if (GET_CODE (y
) == PRE_DEC
|| GET_CODE (y
) == PRE_INC
713 || GET_CODE (y
) == PRE_MODIFY
)
714 return operands_match_p (x
, XEXP (y
, 0), -1);
718 if (code
== REG
&& GET_CODE (y
) == SUBREG
&& REG_P (SUBREG_REG (y
))
719 && x
== SUBREG_REG (y
))
721 if (GET_CODE (y
) == REG
&& code
== SUBREG
&& REG_P (SUBREG_REG (x
))
722 && SUBREG_REG (x
) == y
)
725 /* Now we have disposed of all the cases in which different rtx
727 if (code
!= GET_CODE (y
))
730 /* (MULT:SI x y) and (MULT:HI x y) are NOT equivalent. */
731 if (GET_MODE (x
) != GET_MODE (y
))
740 return XEXP (x
, 0) == XEXP (y
, 0);
742 return XSTR (x
, 0) == XSTR (y
, 0);
748 /* Compare the elements. If any pair of corresponding elements fail
749 to match, return false for the whole things. */
751 fmt
= GET_RTX_FORMAT (code
);
752 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
758 if (XWINT (x
, i
) != XWINT (y
, i
))
763 if (XINT (x
, i
) != XINT (y
, i
))
768 val
= operands_match_p (XEXP (x
, i
), XEXP (y
, i
), -1);
777 if (XVECLEN (x
, i
) != XVECLEN (y
, i
))
779 for (j
= XVECLEN (x
, i
) - 1; j
>= 0; --j
)
781 val
= operands_match_p (XVECEXP (x
, i
, j
), XVECEXP (y
, i
, j
), -1);
787 /* It is believed that rtx's at this level will never
788 contain anything but integers and other rtx's, except for
789 within LABEL_REFs and SYMBOL_REFs. */
797 /* True if X is a constant that can be forced into the constant pool.
798 MODE is the mode of the operand, or VOIDmode if not known. */
799 #define CONST_POOL_OK_P(MODE, X) \
800 ((MODE) != VOIDmode \
802 && GET_CODE (X) != HIGH \
803 && !targetm.cannot_force_const_mem (MODE, X))
805 /* True if C is a non-empty register class that has too few registers
806 to be safely used as a reload target class. */
807 #define SMALL_REGISTER_CLASS_P(C) \
808 (ira_class_hard_regs_num [(C)] == 1 \
809 || (ira_class_hard_regs_num [(C)] >= 1 \
810 && targetm.class_likely_spilled_p (C)))
812 /* If REG is a reload pseudo, try to make its class satisfying CL. */
814 narrow_reload_pseudo_class (rtx reg
, enum reg_class cl
)
816 enum reg_class rclass
;
818 /* Do not make more accurate class from reloads generated. They are
819 mostly moves with a lot of constraints. Making more accurate
820 class may results in very narrow class and impossibility of find
821 registers for several reloads of one insn. */
822 if (INSN_UID (curr_insn
) >= new_insn_uid_start
)
824 if (GET_CODE (reg
) == SUBREG
)
825 reg
= SUBREG_REG (reg
);
826 if (! REG_P (reg
) || (int) REGNO (reg
) < new_regno_start
)
828 if (in_class_p (reg
, cl
, &rclass
) && rclass
!= cl
)
829 lra_change_class (REGNO (reg
), rclass
, " Change to", true);
832 /* Generate reloads for matching OUT and INS (array of input operand
833 numbers with end marker -1) with reg class GOAL_CLASS. Add input
834 and output reloads correspondingly to the lists *BEFORE and *AFTER.
835 OUT might be negative. In this case we generate input reloads for
836 matched input operands INS. */
838 match_reload (signed char out
, signed char *ins
, enum reg_class goal_class
,
839 rtx
*before
, rtx
*after
)
842 rtx new_in_reg
, new_out_reg
, reg
, clobber
;
843 enum machine_mode inmode
, outmode
;
844 rtx in_rtx
= *curr_id
->operand_loc
[ins
[0]];
845 rtx out_rtx
= out
< 0 ? in_rtx
: *curr_id
->operand_loc
[out
];
847 inmode
= curr_operand_mode
[ins
[0]];
848 outmode
= out
< 0 ? inmode
: curr_operand_mode
[out
];
849 push_to_sequence (*before
);
850 if (inmode
!= outmode
)
852 if (GET_MODE_SIZE (inmode
) > GET_MODE_SIZE (outmode
))
855 = lra_create_new_reg_with_unique_value (inmode
, in_rtx
,
857 if (SCALAR_INT_MODE_P (inmode
))
858 new_out_reg
= gen_lowpart_SUBREG (outmode
, reg
);
860 new_out_reg
= gen_rtx_SUBREG (outmode
, reg
, 0);
861 LRA_SUBREG_P (new_out_reg
) = 1;
862 /* If the input reg is dying here, we can use the same hard
863 register for REG and IN_RTX. We do it only for original
864 pseudos as reload pseudos can die although original
865 pseudos still live where reload pseudos dies. */
866 if (REG_P (in_rtx
) && (int) REGNO (in_rtx
) < lra_new_regno_start
867 && find_regno_note (curr_insn
, REG_DEAD
, REGNO (in_rtx
)))
868 lra_assign_reg_val (REGNO (in_rtx
), REGNO (reg
));
873 = lra_create_new_reg_with_unique_value (outmode
, out_rtx
,
875 if (SCALAR_INT_MODE_P (outmode
))
876 new_in_reg
= gen_lowpart_SUBREG (inmode
, reg
);
878 new_in_reg
= gen_rtx_SUBREG (inmode
, reg
, 0);
879 /* NEW_IN_REG is non-paradoxical subreg. We don't want
880 NEW_OUT_REG living above. We add clobber clause for
881 this. This is just a temporary clobber. We can remove
882 it at the end of LRA work. */
883 clobber
= emit_clobber (new_out_reg
);
884 LRA_TEMP_CLOBBER_P (PATTERN (clobber
)) = 1;
885 LRA_SUBREG_P (new_in_reg
) = 1;
886 if (GET_CODE (in_rtx
) == SUBREG
)
888 rtx subreg_reg
= SUBREG_REG (in_rtx
);
890 /* If SUBREG_REG is dying here and sub-registers IN_RTX
891 and NEW_IN_REG are similar, we can use the same hard
892 register for REG and SUBREG_REG. */
893 if (REG_P (subreg_reg
)
894 && (int) REGNO (subreg_reg
) < lra_new_regno_start
895 && GET_MODE (subreg_reg
) == outmode
896 && SUBREG_BYTE (in_rtx
) == SUBREG_BYTE (new_in_reg
)
897 && find_regno_note (curr_insn
, REG_DEAD
, REGNO (subreg_reg
)))
898 lra_assign_reg_val (REGNO (subreg_reg
), REGNO (reg
));
904 /* Pseudos have values -- see comments for lra_reg_info.
905 Different pseudos with the same value do not conflict even if
906 they live in the same place. When we create a pseudo we
907 assign value of original pseudo (if any) from which we
908 created the new pseudo. If we create the pseudo from the
909 input pseudo, the new pseudo will no conflict with the input
910 pseudo which is wrong when the input pseudo lives after the
911 insn and as the new pseudo value is changed by the insn
912 output. Therefore we create the new pseudo from the output.
914 We cannot reuse the current output register because we might
915 have a situation like "a <- a op b", where the constraints
916 force the second input operand ("b") to match the output
917 operand ("a"). "b" must then be copied into a new register
918 so that it doesn't clobber the current value of "a". */
920 new_in_reg
= new_out_reg
921 = lra_create_new_reg_with_unique_value (outmode
, out_rtx
,
924 /* In operand can be got from transformations before processing insn
925 constraints. One example of such transformations is subreg
926 reloading (see function simplify_operand_subreg). The new
927 pseudos created by the transformations might have inaccurate
928 class (ALL_REGS) and we should make their classes more
930 narrow_reload_pseudo_class (in_rtx
, goal_class
);
931 lra_emit_move (copy_rtx (new_in_reg
), in_rtx
);
932 *before
= get_insns ();
934 for (i
= 0; (in
= ins
[i
]) >= 0; i
++)
937 (GET_MODE (*curr_id
->operand_loc
[in
]) == VOIDmode
938 || GET_MODE (new_in_reg
) == GET_MODE (*curr_id
->operand_loc
[in
]));
939 *curr_id
->operand_loc
[in
] = new_in_reg
;
941 lra_update_dups (curr_id
, ins
);
944 /* See a comment for the input operand above. */
945 narrow_reload_pseudo_class (out_rtx
, goal_class
);
946 if (find_reg_note (curr_insn
, REG_UNUSED
, out_rtx
) == NULL_RTX
)
949 lra_emit_move (out_rtx
, copy_rtx (new_out_reg
));
951 *after
= get_insns ();
954 *curr_id
->operand_loc
[out
] = new_out_reg
;
955 lra_update_dup (curr_id
, out
);
958 /* Return register class which is union of all reg classes in insn
959 constraint alternative string starting with P. */
960 static enum reg_class
961 reg_class_from_constraints (const char *p
)
964 enum reg_class op_class
= NO_REGS
;
967 switch ((c
= *p
, len
= CONSTRAINT_LEN (c
, p
)), c
)
974 op_class
= (reg_class_subunion
975 [op_class
][base_reg_class (VOIDmode
, ADDR_SPACE_GENERIC
,
981 op_class
= reg_class_subunion
[op_class
][GENERAL_REGS
];
985 if (REG_CLASS_FROM_CONSTRAINT (c
, p
) == NO_REGS
)
987 #ifdef EXTRA_CONSTRAINT_STR
988 if (EXTRA_ADDRESS_CONSTRAINT (c
, p
))
990 = (reg_class_subunion
991 [op_class
][base_reg_class (VOIDmode
, ADDR_SPACE_GENERIC
,
998 = reg_class_subunion
[op_class
][REG_CLASS_FROM_CONSTRAINT (c
, p
)];
1001 while ((p
+= len
), c
);
1005 /* If OP is a register, return the class of the register as per
1006 get_reg_class, otherwise return NO_REGS. */
1007 static inline enum reg_class
1008 get_op_class (rtx op
)
1010 return REG_P (op
) ? get_reg_class (REGNO (op
)) : NO_REGS
;
1013 /* Return generated insn mem_pseudo:=val if TO_P or val:=mem_pseudo
1014 otherwise. If modes of MEM_PSEUDO and VAL are different, use
1015 SUBREG for VAL to make them equal. */
1017 emit_spill_move (bool to_p
, rtx mem_pseudo
, rtx val
)
1019 if (GET_MODE (mem_pseudo
) != GET_MODE (val
))
1021 /* Usually size of mem_pseudo is greater than val size but in
1022 rare cases it can be less as it can be defined by target
1023 dependent macro HARD_REGNO_CALLER_SAVE_MODE. */
1026 val
= gen_rtx_SUBREG (GET_MODE (mem_pseudo
),
1027 GET_CODE (val
) == SUBREG
? SUBREG_REG (val
) : val
,
1029 LRA_SUBREG_P (val
) = 1;
1033 mem_pseudo
= gen_lowpart_SUBREG (GET_MODE (val
), mem_pseudo
);
1034 LRA_SUBREG_P (mem_pseudo
) = 1;
1038 ? gen_move_insn (mem_pseudo
, val
)
1039 : gen_move_insn (val
, mem_pseudo
));
1042 /* Process a special case insn (register move), return true if we
1043 don't need to process it anymore. INSN should be a single set
1044 insn. Set up that RTL was changed through CHANGE_P and macro
1045 SECONDARY_MEMORY_NEEDED says to use secondary memory through
1048 check_and_process_move (bool *change_p
, bool *sec_mem_p ATTRIBUTE_UNUSED
)
1051 rtx dest
, src
, dreg
, sreg
, old_sreg
, new_reg
, before
, scratch_reg
;
1052 enum reg_class dclass
, sclass
, secondary_class
;
1053 enum machine_mode sreg_mode
;
1054 secondary_reload_info sri
;
1056 lra_assert (curr_insn_set
!= NULL_RTX
);
1057 dreg
= dest
= SET_DEST (curr_insn_set
);
1058 sreg
= src
= SET_SRC (curr_insn_set
);
1059 if (GET_CODE (dest
) == SUBREG
)
1060 dreg
= SUBREG_REG (dest
);
1061 if (GET_CODE (src
) == SUBREG
)
1062 sreg
= SUBREG_REG (src
);
1063 if (! (REG_P (dreg
) || MEM_P (dreg
)) || ! (REG_P (sreg
) || MEM_P (sreg
)))
1065 sclass
= dclass
= NO_REGS
;
1067 dclass
= get_reg_class (REGNO (dreg
));
1068 if (dclass
== ALL_REGS
)
1069 /* ALL_REGS is used for new pseudos created by transformations
1070 like reload of SUBREG_REG (see function
1071 simplify_operand_subreg). We don't know their class yet. We
1072 should figure out the class from processing the insn
1073 constraints not in this fast path function. Even if ALL_REGS
1074 were a right class for the pseudo, secondary_... hooks usually
1075 are not define for ALL_REGS. */
1077 sreg_mode
= GET_MODE (sreg
);
1080 sclass
= get_reg_class (REGNO (sreg
));
1081 if (sclass
== ALL_REGS
)
1082 /* See comments above. */
1084 if (sclass
== NO_REGS
&& dclass
== NO_REGS
)
1086 #ifdef SECONDARY_MEMORY_NEEDED
1087 if (SECONDARY_MEMORY_NEEDED (sclass
, dclass
, GET_MODE (src
))
1088 #ifdef SECONDARY_MEMORY_NEEDED_MODE
1089 && ((sclass
!= NO_REGS
&& dclass
!= NO_REGS
)
1090 || GET_MODE (src
) != SECONDARY_MEMORY_NEEDED_MODE (GET_MODE (src
)))
1098 if (! REG_P (dreg
) || ! REG_P (sreg
))
1100 sri
.prev_sri
= NULL
;
1101 sri
.icode
= CODE_FOR_nothing
;
1103 secondary_class
= NO_REGS
;
1104 /* Set up hard register for a reload pseudo for hook
1105 secondary_reload because some targets just ignore unassigned
1106 pseudos in the hook. */
1107 if (dclass
!= NO_REGS
&& lra_get_regno_hard_regno (REGNO (dreg
)) < 0)
1109 dregno
= REGNO (dreg
);
1110 reg_renumber
[dregno
] = ira_class_hard_regs
[dclass
][0];
1114 if (sclass
!= NO_REGS
&& lra_get_regno_hard_regno (REGNO (sreg
)) < 0)
1116 sregno
= REGNO (sreg
);
1117 reg_renumber
[sregno
] = ira_class_hard_regs
[sclass
][0];
1121 if (sclass
!= NO_REGS
)
1123 = (enum reg_class
) targetm
.secondary_reload (false, dest
,
1124 (reg_class_t
) sclass
,
1125 GET_MODE (src
), &sri
);
1126 if (sclass
== NO_REGS
1127 || ((secondary_class
!= NO_REGS
|| sri
.icode
!= CODE_FOR_nothing
)
1128 && dclass
!= NO_REGS
))
1130 enum reg_class old_sclass
= secondary_class
;
1131 secondary_reload_info old_sri
= sri
;
1133 sri
.prev_sri
= NULL
;
1134 sri
.icode
= CODE_FOR_nothing
;
1137 = (enum reg_class
) targetm
.secondary_reload (true, sreg
,
1138 (reg_class_t
) dclass
,
1140 /* Check the target hook consistency. */
1142 ((secondary_class
== NO_REGS
&& sri
.icode
== CODE_FOR_nothing
)
1143 || (old_sclass
== NO_REGS
&& old_sri
.icode
== CODE_FOR_nothing
)
1144 || (secondary_class
== old_sclass
&& sri
.icode
== old_sri
.icode
));
1147 reg_renumber
[sregno
] = -1;
1149 reg_renumber
[dregno
] = -1;
1150 if (secondary_class
== NO_REGS
&& sri
.icode
== CODE_FOR_nothing
)
1154 if (secondary_class
!= NO_REGS
)
1155 new_reg
= lra_create_new_reg_with_unique_value (sreg_mode
, NULL_RTX
,
1159 if (old_sreg
!= sreg
)
1160 sreg
= copy_rtx (sreg
);
1161 if (sri
.icode
== CODE_FOR_nothing
)
1162 lra_emit_move (new_reg
, sreg
);
1165 enum reg_class scratch_class
;
1167 scratch_class
= (reg_class_from_constraints
1168 (insn_data
[sri
.icode
].operand
[2].constraint
));
1169 scratch_reg
= (lra_create_new_reg_with_unique_value
1170 (insn_data
[sri
.icode
].operand
[2].mode
, NULL_RTX
,
1171 scratch_class
, "scratch"));
1172 emit_insn (GEN_FCN (sri
.icode
) (new_reg
!= NULL_RTX
? new_reg
: dest
,
1173 sreg
, scratch_reg
));
1175 before
= get_insns ();
1177 lra_process_new_insns (curr_insn
, before
, NULL_RTX
, "Inserting the move");
1178 if (new_reg
!= NULL_RTX
)
1180 if (GET_CODE (src
) == SUBREG
)
1181 SUBREG_REG (src
) = new_reg
;
1183 SET_SRC (curr_insn_set
) = new_reg
;
1187 if (lra_dump_file
!= NULL
)
1189 fprintf (lra_dump_file
, "Deleting move %u\n", INSN_UID (curr_insn
));
1190 dump_insn_slim (lra_dump_file
, curr_insn
);
1192 lra_set_insn_deleted (curr_insn
);
1198 /* The following data describe the result of process_alt_operands.
1199 The data are used in curr_insn_transform to generate reloads. */
1201 /* The chosen reg classes which should be used for the corresponding
1203 static enum reg_class goal_alt
[MAX_RECOG_OPERANDS
];
1204 /* True if the operand should be the same as another operand and that
1205 other operand does not need a reload. */
1206 static bool goal_alt_match_win
[MAX_RECOG_OPERANDS
];
1207 /* True if the operand does not need a reload. */
1208 static bool goal_alt_win
[MAX_RECOG_OPERANDS
];
1209 /* True if the operand can be offsetable memory. */
1210 static bool goal_alt_offmemok
[MAX_RECOG_OPERANDS
];
1211 /* The number of an operand to which given operand can be matched to. */
1212 static int goal_alt_matches
[MAX_RECOG_OPERANDS
];
1213 /* The number of elements in the following array. */
1214 static int goal_alt_dont_inherit_ops_num
;
1215 /* Numbers of operands whose reload pseudos should not be inherited. */
1216 static int goal_alt_dont_inherit_ops
[MAX_RECOG_OPERANDS
];
1217 /* True if the insn commutative operands should be swapped. */
1218 static bool goal_alt_swapped
;
1219 /* The chosen insn alternative. */
1220 static int goal_alt_number
;
1222 /* The following five variables are used to choose the best insn
1223 alternative. They reflect final characteristics of the best
1226 /* Number of necessary reloads and overall cost reflecting the
1227 previous value and other unpleasantness of the best alternative. */
1228 static int best_losers
, best_overall
;
1229 /* Overall number hard registers used for reloads. For example, on
1230 some targets we need 2 general registers to reload DFmode and only
1231 one floating point register. */
1232 static int best_reload_nregs
;
1233 /* Overall number reflecting distances of previous reloading the same
1234 value. The distances are counted from the current BB start. It is
1235 used to improve inheritance chances. */
1236 static int best_reload_sum
;
1238 /* True if the current insn should have no correspondingly input or
1240 static bool no_input_reloads_p
, no_output_reloads_p
;
1242 /* True if we swapped the commutative operands in the current
1244 static int curr_swapped
;
1246 /* Arrange for address element *LOC to be a register of class CL.
1247 Add any input reloads to list BEFORE. AFTER is nonnull if *LOC is an
1248 automodified value; handle that case by adding the required output
1249 reloads to list AFTER. Return true if the RTL was changed. */
1251 process_addr_reg (rtx
*loc
, rtx
*before
, rtx
*after
, enum reg_class cl
)
1254 enum reg_class rclass
, new_class
;
1257 enum machine_mode mode
;
1258 bool subreg_p
, before_p
= false;
1260 subreg_p
= GET_CODE (*loc
) == SUBREG
;
1262 loc
= &SUBREG_REG (*loc
);
1264 mode
= GET_MODE (reg
);
1267 /* Always reload memory in an address even if the target supports
1269 new_reg
= lra_create_new_reg_with_unique_value (mode
, reg
, cl
, "address");
1274 regno
= REGNO (reg
);
1275 rclass
= get_reg_class (regno
);
1276 if ((*loc
= get_equiv_with_elimination (reg
, curr_insn
)) != reg
)
1278 if (lra_dump_file
!= NULL
)
1280 fprintf (lra_dump_file
,
1281 "Changing pseudo %d in address of insn %u on equiv ",
1282 REGNO (reg
), INSN_UID (curr_insn
));
1283 dump_value_slim (lra_dump_file
, *loc
, 1);
1284 fprintf (lra_dump_file
, "\n");
1286 *loc
= copy_rtx (*loc
);
1288 if (*loc
!= reg
|| ! in_class_p (reg
, cl
, &new_class
))
1291 if (get_reload_reg (after
== NULL
? OP_IN
: OP_INOUT
,
1292 mode
, reg
, cl
, subreg_p
, "address", &new_reg
))
1295 else if (new_class
!= NO_REGS
&& rclass
!= new_class
)
1297 lra_change_class (regno
, new_class
, " Change to", true);
1305 push_to_sequence (*before
);
1306 lra_emit_move (new_reg
, reg
);
1307 *before
= get_insns ();
1314 lra_emit_move (reg
, new_reg
);
1316 *after
= get_insns ();
1322 /* Insert move insn in simplify_operand_subreg. BEFORE returns
1323 the insn to be inserted before curr insn. AFTER returns the
1324 the insn to be inserted after curr insn. ORIGREG and NEWREG
1325 are the original reg and new reg for reload. */
1327 insert_move_for_subreg (rtx
*before
, rtx
*after
, rtx origreg
, rtx newreg
)
1331 push_to_sequence (*before
);
1332 lra_emit_move (newreg
, origreg
);
1333 *before
= get_insns ();
1339 lra_emit_move (origreg
, newreg
);
1341 *after
= get_insns ();
1346 static int valid_address_p (enum machine_mode mode
, rtx addr
, addr_space_t as
);
1348 /* Make reloads for subreg in operand NOP with internal subreg mode
1349 REG_MODE, add new reloads for further processing. Return true if
1350 any reload was generated. */
1352 simplify_operand_subreg (int nop
, enum machine_mode reg_mode
)
1356 enum machine_mode mode
;
1358 rtx operand
= *curr_id
->operand_loc
[nop
];
1359 enum reg_class regclass
;
1362 before
= after
= NULL_RTX
;
1364 if (GET_CODE (operand
) != SUBREG
)
1367 mode
= GET_MODE (operand
);
1368 reg
= SUBREG_REG (operand
);
1369 type
= curr_static_id
->operand
[nop
].type
;
1370 /* If we change address for paradoxical subreg of memory, the
1371 address might violate the necessary alignment or the access might
1372 be slow. So take this into consideration. We should not worry
1373 about access beyond allocated memory for paradoxical memory
1374 subregs as we don't substitute such equiv memory (see processing
1375 equivalences in function lra_constraints) and because for spilled
1376 pseudos we allocate stack memory enough for the biggest
1377 corresponding paradoxical subreg. */
1379 && (! SLOW_UNALIGNED_ACCESS (mode
, MEM_ALIGN (reg
))
1380 || MEM_ALIGN (reg
) >= GET_MODE_ALIGNMENT (mode
)))
1382 rtx subst
, old
= *curr_id
->operand_loc
[nop
];
1384 alter_subreg (curr_id
->operand_loc
[nop
], false);
1385 subst
= *curr_id
->operand_loc
[nop
];
1386 lra_assert (MEM_P (subst
));
1387 if (! valid_address_p (GET_MODE (reg
), XEXP (reg
, 0),
1388 MEM_ADDR_SPACE (reg
))
1389 || valid_address_p (GET_MODE (subst
), XEXP (subst
, 0),
1390 MEM_ADDR_SPACE (subst
)))
1392 /* If the address was valid and became invalid, prefer to reload
1393 the memory. Typical case is when the index scale should
1394 correspond the memory. */
1395 *curr_id
->operand_loc
[nop
] = old
;
1397 else if (REG_P (reg
) && REGNO (reg
) < FIRST_PSEUDO_REGISTER
)
1399 alter_subreg (curr_id
->operand_loc
[nop
], false);
1402 /* Put constant into memory when we have mixed modes. It generates
1403 a better code in most cases as it does not need a secondary
1404 reload memory. It also prevents LRA looping when LRA is using
1405 secondary reload memory again and again. */
1406 if (CONSTANT_P (reg
) && CONST_POOL_OK_P (reg_mode
, reg
)
1407 && SCALAR_INT_MODE_P (reg_mode
) != SCALAR_INT_MODE_P (mode
))
1409 SUBREG_REG (operand
) = force_const_mem (reg_mode
, reg
);
1410 alter_subreg (curr_id
->operand_loc
[nop
], false);
1413 /* Force a reload of the SUBREG_REG if this is a constant or PLUS or
1414 if there may be a problem accessing OPERAND in the outer
1417 && REGNO (reg
) >= FIRST_PSEUDO_REGISTER
1418 && (hard_regno
= lra_get_regno_hard_regno (REGNO (reg
))) >= 0
1419 /* Don't reload paradoxical subregs because we could be looping
1420 having repeatedly final regno out of hard regs range. */
1421 && (hard_regno_nregs
[hard_regno
][GET_MODE (reg
)]
1422 >= hard_regno_nregs
[hard_regno
][mode
])
1423 && simplify_subreg_regno (hard_regno
, GET_MODE (reg
),
1424 SUBREG_BYTE (operand
), mode
) < 0
1425 /* Don't reload subreg for matching reload. It is actually
1426 valid subreg in LRA. */
1427 && ! LRA_SUBREG_P (operand
))
1428 || CONSTANT_P (reg
) || GET_CODE (reg
) == PLUS
|| MEM_P (reg
))
1430 enum reg_class rclass
;
1433 /* There is a big probability that we will get the same class
1434 for the new pseudo and we will get the same insn which
1435 means infinite looping. So spill the new pseudo. */
1438 /* The class will be defined later in curr_insn_transform. */
1440 = (enum reg_class
) targetm
.preferred_reload_class (reg
, ALL_REGS
);
1442 if (get_reload_reg (curr_static_id
->operand
[nop
].type
, reg_mode
, reg
,
1443 rclass
, TRUE
, "subreg reg", &new_reg
))
1445 bool insert_before
, insert_after
;
1446 bitmap_set_bit (&lra_subreg_reload_pseudos
, REGNO (new_reg
));
1448 insert_before
= (type
!= OP_OUT
1449 || GET_MODE_SIZE (GET_MODE (reg
)) > GET_MODE_SIZE (mode
));
1450 insert_after
= (type
!= OP_IN
);
1451 insert_move_for_subreg (insert_before
? &before
: NULL
,
1452 insert_after
? &after
: NULL
,
1455 SUBREG_REG (operand
) = new_reg
;
1456 lra_process_new_insns (curr_insn
, before
, after
,
1457 "Inserting subreg reload");
1460 /* Force a reload for a paradoxical subreg. For paradoxical subreg,
1461 IRA allocates hardreg to the inner pseudo reg according to its mode
1462 instead of the outermode, so the size of the hardreg may not be enough
1463 to contain the outermode operand, in that case we may need to insert
1464 reload for the reg. For the following two types of paradoxical subreg,
1465 we need to insert reload:
1466 1. If the op_type is OP_IN, and the hardreg could not be paired with
1467 other hardreg to contain the outermode operand
1468 (checked by in_hard_reg_set_p), we need to insert the reload.
1469 2. If the op_type is OP_OUT or OP_INOUT.
1471 Here is a paradoxical subreg example showing how the reload is generated:
1473 (insn 5 4 7 2 (set (reg:TI 106 [ __comp ])
1474 (subreg:TI (reg:DI 107 [ __comp ]) 0)) {*movti_internal_rex64}
1476 In IRA, reg107 is allocated to a DImode hardreg. We use x86-64 as example
1477 here, if reg107 is assigned to hardreg R15, because R15 is the last
1478 hardreg, compiler cannot find another hardreg to pair with R15 to
1479 contain TImode data. So we insert a TImode reload reg180 for it.
1480 After reload is inserted:
1482 (insn 283 0 0 (set (subreg:DI (reg:TI 180 [orig:107 __comp ] [107]) 0)
1483 (reg:DI 107 [ __comp ])) -1
1484 (insn 5 4 7 2 (set (reg:TI 106 [ __comp ])
1485 (subreg:TI (reg:TI 180 [orig:107 __comp ] [107]) 0)) {*movti_internal_rex64}
1487 Two reload hard registers will be allocated to reg180 to save TImode data
1489 else if (REG_P (reg
)
1490 && REGNO (reg
) >= FIRST_PSEUDO_REGISTER
1491 && (hard_regno
= lra_get_regno_hard_regno (REGNO (reg
))) >= 0
1492 && (hard_regno_nregs
[hard_regno
][GET_MODE (reg
)]
1493 < hard_regno_nregs
[hard_regno
][mode
])
1494 && (regclass
= lra_get_allocno_class (REGNO (reg
)))
1496 || !in_hard_reg_set_p (reg_class_contents
[regclass
],
1499 /* The class will be defined later in curr_insn_transform. */
1500 enum reg_class rclass
1501 = (enum reg_class
) targetm
.preferred_reload_class (reg
, ALL_REGS
);
1503 if (get_reload_reg (curr_static_id
->operand
[nop
].type
, mode
, reg
,
1504 rclass
, TRUE
, "paradoxical subreg", &new_reg
))
1507 bool insert_before
, insert_after
;
1509 PUT_MODE (new_reg
, mode
);
1510 subreg
= simplify_gen_subreg (GET_MODE (reg
), new_reg
, mode
, 0);
1511 bitmap_set_bit (&lra_subreg_reload_pseudos
, REGNO (new_reg
));
1513 insert_before
= (type
!= OP_OUT
);
1514 insert_after
= (type
!= OP_IN
);
1515 insert_move_for_subreg (insert_before
? &before
: NULL
,
1516 insert_after
? &after
: NULL
,
1519 SUBREG_REG (operand
) = new_reg
;
1520 lra_process_new_insns (curr_insn
, before
, after
,
1521 "Inserting paradoxical subreg reload");
1527 /* Return TRUE if X refers for a hard register from SET. */
1529 uses_hard_regs_p (rtx x
, HARD_REG_SET set
)
1531 int i
, j
, x_hard_regno
;
1532 enum machine_mode mode
;
1538 code
= GET_CODE (x
);
1539 mode
= GET_MODE (x
);
1543 code
= GET_CODE (x
);
1544 if (GET_MODE_SIZE (GET_MODE (x
)) > GET_MODE_SIZE (mode
))
1545 mode
= GET_MODE (x
);
1550 x_hard_regno
= get_hard_regno (x
);
1551 return (x_hard_regno
>= 0
1552 && overlaps_hard_reg_set_p (set
, mode
, x_hard_regno
));
1556 struct address_info ad
;
1558 decompose_mem_address (&ad
, x
);
1559 if (ad
.base_term
!= NULL
&& uses_hard_regs_p (*ad
.base_term
, set
))
1561 if (ad
.index_term
!= NULL
&& uses_hard_regs_p (*ad
.index_term
, set
))
1564 fmt
= GET_RTX_FORMAT (code
);
1565 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
1569 if (uses_hard_regs_p (XEXP (x
, i
), set
))
1572 else if (fmt
[i
] == 'E')
1574 for (j
= XVECLEN (x
, i
) - 1; j
>= 0; j
--)
1575 if (uses_hard_regs_p (XVECEXP (x
, i
, j
), set
))
1582 /* Return true if OP is a spilled pseudo. */
1584 spilled_pseudo_p (rtx op
)
1587 && REGNO (op
) >= FIRST_PSEUDO_REGISTER
&& in_mem_p (REGNO (op
)));
1590 /* Return true if X is a general constant. */
1592 general_constant_p (rtx x
)
1594 return CONSTANT_P (x
) && (! flag_pic
|| LEGITIMATE_PIC_OPERAND_P (x
));
1598 reg_in_class_p (rtx reg
, enum reg_class cl
)
1601 return get_reg_class (REGNO (reg
)) == NO_REGS
;
1602 return in_class_p (reg
, cl
, NULL
);
1605 /* Major function to choose the current insn alternative and what
1606 operands should be reloaded and how. If ONLY_ALTERNATIVE is not
1607 negative we should consider only this alternative. Return false if
1608 we can not choose the alternative or find how to reload the
1611 process_alt_operands (int only_alternative
)
1614 int nop
, overall
, nalt
;
1615 int n_alternatives
= curr_static_id
->n_alternatives
;
1616 int n_operands
= curr_static_id
->n_operands
;
1617 /* LOSERS counts the operands that don't fit this alternative and
1618 would require loading. */
1620 /* REJECT is a count of how undesirable this alternative says it is
1621 if any reloading is required. If the alternative matches exactly
1622 then REJECT is ignored, but otherwise it gets this much counted
1623 against it in addition to the reloading needed. */
1625 /* The number of elements in the following array. */
1626 int early_clobbered_regs_num
;
1627 /* Numbers of operands which are early clobber registers. */
1628 int early_clobbered_nops
[MAX_RECOG_OPERANDS
];
1629 enum reg_class curr_alt
[MAX_RECOG_OPERANDS
];
1630 HARD_REG_SET curr_alt_set
[MAX_RECOG_OPERANDS
];
1631 bool curr_alt_match_win
[MAX_RECOG_OPERANDS
];
1632 bool curr_alt_win
[MAX_RECOG_OPERANDS
];
1633 bool curr_alt_offmemok
[MAX_RECOG_OPERANDS
];
1634 int curr_alt_matches
[MAX_RECOG_OPERANDS
];
1635 /* The number of elements in the following array. */
1636 int curr_alt_dont_inherit_ops_num
;
1637 /* Numbers of operands whose reload pseudos should not be inherited. */
1638 int curr_alt_dont_inherit_ops
[MAX_RECOG_OPERANDS
];
1640 /* The register when the operand is a subreg of register, otherwise the
1642 rtx no_subreg_reg_operand
[MAX_RECOG_OPERANDS
];
1643 /* The register if the operand is a register or subreg of register,
1645 rtx operand_reg
[MAX_RECOG_OPERANDS
];
1646 int hard_regno
[MAX_RECOG_OPERANDS
];
1647 enum machine_mode biggest_mode
[MAX_RECOG_OPERANDS
];
1648 int reload_nregs
, reload_sum
;
1652 /* Calculate some data common for all alternatives to speed up the
1654 for (nop
= 0; nop
< n_operands
; nop
++)
1658 op
= no_subreg_reg_operand
[nop
] = *curr_id
->operand_loc
[nop
];
1659 /* The real hard regno of the operand after the allocation. */
1660 hard_regno
[nop
] = get_hard_regno (op
);
1662 operand_reg
[nop
] = reg
= op
;
1663 biggest_mode
[nop
] = GET_MODE (op
);
1664 if (GET_CODE (op
) == SUBREG
)
1666 operand_reg
[nop
] = reg
= SUBREG_REG (op
);
1667 if (GET_MODE_SIZE (biggest_mode
[nop
])
1668 < GET_MODE_SIZE (GET_MODE (reg
)))
1669 biggest_mode
[nop
] = GET_MODE (reg
);
1672 operand_reg
[nop
] = NULL_RTX
;
1673 else if (REGNO (reg
) >= FIRST_PSEUDO_REGISTER
1674 || ((int) REGNO (reg
)
1675 == lra_get_elimination_hard_regno (REGNO (reg
))))
1676 no_subreg_reg_operand
[nop
] = reg
;
1678 operand_reg
[nop
] = no_subreg_reg_operand
[nop
]
1679 /* Just use natural mode for elimination result. It should
1680 be enough for extra constraints hooks. */
1681 = regno_reg_rtx
[hard_regno
[nop
]];
1684 /* The constraints are made of several alternatives. Each operand's
1685 constraint looks like foo,bar,... with commas separating the
1686 alternatives. The first alternatives for all operands go
1687 together, the second alternatives go together, etc.
1689 First loop over alternatives. */
1690 for (nalt
= 0; nalt
< n_alternatives
; nalt
++)
1692 /* Loop over operands for one constraint alternative. */
1693 #if HAVE_ATTR_enabled
1694 if (curr_id
->alternative_enabled_p
!= NULL
1695 && ! curr_id
->alternative_enabled_p
[nalt
])
1699 if (only_alternative
>= 0 && nalt
!= only_alternative
)
1703 overall
= losers
= reject
= reload_nregs
= reload_sum
= 0;
1704 for (nop
= 0; nop
< n_operands
; nop
++)
1706 int inc
= (curr_static_id
1707 ->operand_alternative
[nalt
* n_operands
+ nop
].reject
);
1708 if (lra_dump_file
!= NULL
&& inc
!= 0)
1709 fprintf (lra_dump_file
,
1710 " Staticly defined alt reject+=%d\n", inc
);
1713 early_clobbered_regs_num
= 0;
1715 for (nop
= 0; nop
< n_operands
; nop
++)
1719 int len
, c
, m
, i
, opalt_num
, this_alternative_matches
;
1720 bool win
, did_match
, offmemok
, early_clobber_p
;
1721 /* false => this operand can be reloaded somehow for this
1724 /* true => this operand can be reloaded if the alternative
1727 /* True if a constant forced into memory would be OK for
1730 enum reg_class this_alternative
, this_costly_alternative
;
1731 HARD_REG_SET this_alternative_set
, this_costly_alternative_set
;
1732 bool this_alternative_match_win
, this_alternative_win
;
1733 bool this_alternative_offmemok
;
1735 enum machine_mode mode
;
1737 opalt_num
= nalt
* n_operands
+ nop
;
1738 if (curr_static_id
->operand_alternative
[opalt_num
].anything_ok
)
1740 /* Fast track for no constraints at all. */
1741 curr_alt
[nop
] = NO_REGS
;
1742 CLEAR_HARD_REG_SET (curr_alt_set
[nop
]);
1743 curr_alt_win
[nop
] = true;
1744 curr_alt_match_win
[nop
] = false;
1745 curr_alt_offmemok
[nop
] = false;
1746 curr_alt_matches
[nop
] = -1;
1750 op
= no_subreg_reg_operand
[nop
];
1751 mode
= curr_operand_mode
[nop
];
1753 win
= did_match
= winreg
= offmemok
= constmemok
= false;
1756 early_clobber_p
= false;
1757 p
= curr_static_id
->operand_alternative
[opalt_num
].constraint
;
1759 this_costly_alternative
= this_alternative
= NO_REGS
;
1760 /* We update set of possible hard regs besides its class
1761 because reg class might be inaccurate. For example,
1762 union of LO_REGS (l), HI_REGS(h), and STACK_REG(k) in ARM
1763 is translated in HI_REGS because classes are merged by
1764 pairs and there is no accurate intermediate class. */
1765 CLEAR_HARD_REG_SET (this_alternative_set
);
1766 CLEAR_HARD_REG_SET (this_costly_alternative_set
);
1767 this_alternative_win
= false;
1768 this_alternative_match_win
= false;
1769 this_alternative_offmemok
= false;
1770 this_alternative_matches
= -1;
1772 /* An empty constraint should be excluded by the fast
1774 lra_assert (*p
!= 0 && *p
!= ',');
1776 /* Scan this alternative's specs for this operand; set WIN
1777 if the operand fits any letter in this alternative.
1778 Otherwise, clear BADOP if this operand could fit some
1779 letter after reloads, or set WINREG if this operand could
1780 fit after reloads provided the constraint allows some
1785 switch ((c
= *p
, len
= CONSTRAINT_LEN (c
, p
)), c
)
1794 case '=': case '+': case '?': case '*': case '!':
1795 case ' ': case '\t':
1799 /* We only support one commutative marker, the first
1800 one. We already set commutative above. */
1804 early_clobber_p
= true;
1808 /* Ignore rest of this alternative. */
1812 case '0': case '1': case '2': case '3': case '4':
1813 case '5': case '6': case '7': case '8': case '9':
1818 m
= strtoul (p
, &end
, 10);
1821 lra_assert (nop
> m
);
1823 this_alternative_matches
= m
;
1824 m_hregno
= get_hard_regno (*curr_id
->operand_loc
[m
]);
1825 /* We are supposed to match a previous operand.
1826 If we do, we win if that one did. If we do
1827 not, count both of the operands as losers.
1828 (This is too conservative, since most of the
1829 time only a single reload insn will be needed
1830 to make the two operands win. As a result,
1831 this alternative may be rejected when it is
1832 actually desirable.) */
1834 if (operands_match_p (*curr_id
->operand_loc
[nop
],
1835 *curr_id
->operand_loc
[m
], m_hregno
))
1837 /* We should reject matching of an early
1838 clobber operand if the matching operand is
1839 not dying in the insn. */
1840 if (! curr_static_id
->operand
[m
].early_clobber
1841 || operand_reg
[nop
] == NULL_RTX
1842 || (find_regno_note (curr_insn
, REG_DEAD
,
1844 || REGNO (op
) == REGNO (operand_reg
[m
])))
1849 /* If we are matching a non-offsettable
1850 address where an offsettable address was
1851 expected, then we must reject this
1852 combination, because we can't reload
1854 if (curr_alt_offmemok
[m
]
1855 && MEM_P (*curr_id
->operand_loc
[m
])
1856 && curr_alt
[m
] == NO_REGS
&& ! curr_alt_win
[m
])
1861 /* Operands don't match. Both operands must
1862 allow a reload register, otherwise we
1863 cannot make them match. */
1864 if (curr_alt
[m
] == NO_REGS
)
1866 /* Retroactively mark the operand we had to
1867 match as a loser, if it wasn't already and
1868 it wasn't matched to a register constraint
1869 (e.g it might be matched by memory). */
1871 && (operand_reg
[m
] == NULL_RTX
1872 || hard_regno
[m
] < 0))
1876 += (ira_reg_class_max_nregs
[curr_alt
[m
]]
1877 [GET_MODE (*curr_id
->operand_loc
[m
])]);
1880 /* Prefer matching earlyclobber alternative as
1881 it results in less hard regs required for
1882 the insn than a non-matching earlyclobber
1884 if (curr_static_id
->operand
[m
].early_clobber
)
1886 if (lra_dump_file
!= NULL
)
1889 " %d Matching earlyclobber alt:"
1894 /* Otherwise we prefer no matching
1895 alternatives because it gives more freedom
1897 else if (operand_reg
[nop
] == NULL_RTX
1898 || (find_regno_note (curr_insn
, REG_DEAD
,
1899 REGNO (operand_reg
[nop
]))
1902 if (lra_dump_file
!= NULL
)
1905 " %d Matching alt: reject+=2\n",
1910 /* If we have to reload this operand and some
1911 previous operand also had to match the same
1912 thing as this operand, we don't know how to do
1914 if (!match_p
|| !curr_alt_win
[m
])
1916 for (i
= 0; i
< nop
; i
++)
1917 if (curr_alt_matches
[i
] == m
)
1925 /* This can be fixed with reloads if the operand
1926 we are supposed to match can be fixed with
1929 this_alternative
= curr_alt
[m
];
1930 COPY_HARD_REG_SET (this_alternative_set
, curr_alt_set
[m
]);
1931 winreg
= this_alternative
!= NO_REGS
;
1936 cl
= base_reg_class (VOIDmode
, ADDR_SPACE_GENERIC
,
1938 this_alternative
= reg_class_subunion
[this_alternative
][cl
];
1939 IOR_HARD_REG_SET (this_alternative_set
,
1940 reg_class_contents
[cl
]);
1943 this_costly_alternative
1944 = reg_class_subunion
[this_costly_alternative
][cl
];
1945 IOR_HARD_REG_SET (this_costly_alternative_set
,
1946 reg_class_contents
[cl
]);
1952 case TARGET_MEM_CONSTRAINT
:
1953 if (MEM_P (op
) || spilled_pseudo_p (op
))
1955 /* We can put constant or pseudo value into memory
1956 to satisfy the constraint. */
1957 if (CONST_POOL_OK_P (mode
, op
) || REG_P (op
))
1964 && (GET_CODE (XEXP (op
, 0)) == PRE_DEC
1965 || GET_CODE (XEXP (op
, 0)) == POST_DEC
))
1971 && (GET_CODE (XEXP (op
, 0)) == PRE_INC
1972 || GET_CODE (XEXP (op
, 0)) == POST_INC
))
1976 /* Memory op whose address is not offsettable. */
1979 && ! offsettable_nonstrict_memref_p (op
))
1983 /* Memory operand whose address is offsettable. */
1986 && offsettable_nonstrict_memref_p (op
))
1987 || spilled_pseudo_p (op
))
1989 /* We can put constant or pseudo value into memory
1990 or make memory address offsetable to satisfy the
1992 if (CONST_POOL_OK_P (mode
, op
) || MEM_P (op
) || REG_P (op
))
2000 if (GET_CODE (op
) == CONST_DOUBLE
2001 || (GET_CODE (op
) == CONST_VECTOR
2002 && (GET_MODE_CLASS (mode
) == MODE_VECTOR_FLOAT
)))
2008 if (CONST_DOUBLE_AS_FLOAT_P (op
)
2009 && CONST_DOUBLE_OK_FOR_CONSTRAINT_P (op
, c
, p
))
2014 if (CONST_SCALAR_INT_P (op
))
2018 if (general_constant_p (op
))
2023 if (CONST_SCALAR_INT_P (op
))
2035 if (CONST_INT_P (op
)
2036 && CONST_OK_FOR_CONSTRAINT_P (INTVAL (op
), c
, p
))
2041 /* This constraint should be excluded by the fast
2048 || general_constant_p (op
)
2049 || spilled_pseudo_p (op
))
2051 /* Drop through into 'r' case. */
2055 = reg_class_subunion
[this_alternative
][GENERAL_REGS
];
2056 IOR_HARD_REG_SET (this_alternative_set
,
2057 reg_class_contents
[GENERAL_REGS
]);
2060 this_costly_alternative
2061 = (reg_class_subunion
2062 [this_costly_alternative
][GENERAL_REGS
]);
2063 IOR_HARD_REG_SET (this_costly_alternative_set
,
2064 reg_class_contents
[GENERAL_REGS
]);
2069 if (REG_CLASS_FROM_CONSTRAINT (c
, p
) == NO_REGS
)
2071 #ifdef EXTRA_CONSTRAINT_STR
2072 if (EXTRA_MEMORY_CONSTRAINT (c
, p
))
2075 && satisfies_memory_constraint_p (op
, p
))
2077 else if (spilled_pseudo_p (op
))
2080 /* If we didn't already win, we can reload
2081 constants via force_const_mem or put the
2082 pseudo value into memory, or make other
2083 memory by reloading the address like for
2085 if (CONST_POOL_OK_P (mode
, op
)
2086 || MEM_P (op
) || REG_P (op
))
2092 if (EXTRA_ADDRESS_CONSTRAINT (c
, p
))
2094 if (satisfies_address_constraint_p (op
, p
))
2097 /* If we didn't already win, we can reload
2098 the address into a base register. */
2099 cl
= base_reg_class (VOIDmode
, ADDR_SPACE_GENERIC
,
2102 = reg_class_subunion
[this_alternative
][cl
];
2103 IOR_HARD_REG_SET (this_alternative_set
,
2104 reg_class_contents
[cl
]);
2107 this_costly_alternative
2108 = (reg_class_subunion
2109 [this_costly_alternative
][cl
]);
2110 IOR_HARD_REG_SET (this_costly_alternative_set
,
2111 reg_class_contents
[cl
]);
2117 if (EXTRA_CONSTRAINT_STR (op
, c
, p
))
2123 cl
= REG_CLASS_FROM_CONSTRAINT (c
, p
);
2124 this_alternative
= reg_class_subunion
[this_alternative
][cl
];
2125 IOR_HARD_REG_SET (this_alternative_set
,
2126 reg_class_contents
[cl
]);
2129 this_costly_alternative
2130 = reg_class_subunion
[this_costly_alternative
][cl
];
2131 IOR_HARD_REG_SET (this_costly_alternative_set
,
2132 reg_class_contents
[cl
]);
2135 if (mode
== BLKmode
)
2140 if (hard_regno
[nop
] >= 0
2141 && in_hard_reg_set_p (this_alternative_set
,
2142 mode
, hard_regno
[nop
]))
2144 else if (hard_regno
[nop
] < 0
2145 && in_class_p (op
, this_alternative
, NULL
))
2150 if (c
!= ' ' && c
!= '\t')
2151 costly_p
= c
== '*';
2153 while ((p
+= len
), c
);
2155 scratch_p
= (operand_reg
[nop
] != NULL_RTX
2156 && lra_former_scratch_p (REGNO (operand_reg
[nop
])));
2157 /* Record which operands fit this alternative. */
2160 this_alternative_win
= true;
2161 if (operand_reg
[nop
] != NULL_RTX
)
2163 if (hard_regno
[nop
] >= 0)
2165 if (in_hard_reg_set_p (this_costly_alternative_set
,
2166 mode
, hard_regno
[nop
]))
2168 if (lra_dump_file
!= NULL
)
2169 fprintf (lra_dump_file
,
2170 " %d Costly set: reject++\n",
2177 /* Prefer won reg to spilled pseudo under other
2178 equal conditions for possibe inheritance. */
2181 if (lra_dump_file
!= NULL
)
2184 " %d Non pseudo reload: reject++\n",
2188 if (in_class_p (operand_reg
[nop
],
2189 this_costly_alternative
, NULL
))
2191 if (lra_dump_file
!= NULL
)
2194 " %d Non pseudo costly reload:"
2200 /* We simulate the behaviour of old reload here.
2201 Although scratches need hard registers and it
2202 might result in spilling other pseudos, no reload
2203 insns are generated for the scratches. So it
2204 might cost something but probably less than old
2205 reload pass believes. */
2208 if (lra_dump_file
!= NULL
)
2209 fprintf (lra_dump_file
,
2210 " %d Scratch win: reject+=2\n",
2217 this_alternative_match_win
= true;
2220 int const_to_mem
= 0;
2223 /* Never do output reload of stack pointer. It makes
2224 impossible to do elimination when SP is changed in
2226 if (op
== stack_pointer_rtx
&& ! frame_pointer_needed
2227 && curr_static_id
->operand
[nop
].type
!= OP_IN
)
2230 /* If this alternative asks for a specific reg class, see if there
2231 is at least one allocatable register in that class. */
2233 = (this_alternative
== NO_REGS
2234 || (hard_reg_set_subset_p
2235 (reg_class_contents
[this_alternative
],
2236 lra_no_alloc_regs
)));
2238 /* For asms, verify that the class for this alternative is possible
2239 for the mode that is specified. */
2240 if (!no_regs_p
&& INSN_CODE (curr_insn
) < 0)
2243 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
2244 if (HARD_REGNO_MODE_OK (i
, mode
)
2245 && in_hard_reg_set_p (reg_class_contents
[this_alternative
],
2248 if (i
== FIRST_PSEUDO_REGISTER
)
2252 /* If this operand accepts a register, and if the
2253 register class has at least one allocatable register,
2254 then this operand can be reloaded. */
2255 if (winreg
&& !no_regs_p
)
2260 if (lra_dump_file
!= NULL
)
2261 fprintf (lra_dump_file
,
2262 " alt=%d: Bad operand -- refuse\n",
2267 /* If not assigned pseudo has a class which a subset of
2268 required reg class, it is a less costly alternative
2269 as the pseudo still can get a hard reg of necessary
2271 if (! no_regs_p
&& REG_P (op
) && hard_regno
[nop
] < 0
2272 && (cl
= get_reg_class (REGNO (op
))) != NO_REGS
2273 && ira_class_subset_p
[this_alternative
][cl
])
2275 if (lra_dump_file
!= NULL
)
2278 " %d Super set class reg: reject-=3\n", nop
);
2282 this_alternative_offmemok
= offmemok
;
2283 if (this_costly_alternative
!= NO_REGS
)
2285 if (lra_dump_file
!= NULL
)
2286 fprintf (lra_dump_file
,
2287 " %d Costly loser: reject++\n", nop
);
2290 /* If the operand is dying, has a matching constraint,
2291 and satisfies constraints of the matched operand
2292 which failed to satisfy the own constraints, most probably
2293 the reload for this operand will be gone. */
2294 if (this_alternative_matches
>= 0
2295 && !curr_alt_win
[this_alternative_matches
]
2297 && find_regno_note (curr_insn
, REG_DEAD
, REGNO (op
))
2298 && (hard_regno
[nop
] >= 0
2299 ? in_hard_reg_set_p (this_alternative_set
,
2300 mode
, hard_regno
[nop
])
2301 : in_class_p (op
, this_alternative
, NULL
)))
2303 if (lra_dump_file
!= NULL
)
2306 " %d Dying matched operand reload: reject++\n",
2312 /* Strict_low_part requires to reload the register
2313 not the sub-register. In this case we should
2314 check that a final reload hard reg can hold the
2316 if (curr_static_id
->operand
[nop
].strict_low
2318 && hard_regno
[nop
] < 0
2319 && GET_CODE (*curr_id
->operand_loc
[nop
]) == SUBREG
2320 && ira_class_hard_regs_num
[this_alternative
] > 0
2321 && ! HARD_REGNO_MODE_OK (ira_class_hard_regs
2322 [this_alternative
][0],
2324 (*curr_id
->operand_loc
[nop
])))
2326 if (lra_dump_file
!= NULL
)
2329 " alt=%d: Strict low subreg reload -- refuse\n",
2335 if (operand_reg
[nop
] != NULL_RTX
2336 /* Output operands and matched input operands are
2337 not inherited. The following conditions do not
2338 exactly describe the previous statement but they
2339 are pretty close. */
2340 && curr_static_id
->operand
[nop
].type
!= OP_OUT
2341 && (this_alternative_matches
< 0
2342 || curr_static_id
->operand
[nop
].type
!= OP_IN
))
2344 int last_reload
= (lra_reg_info
[ORIGINAL_REGNO
2348 /* The value of reload_sum has sense only if we
2349 process insns in their order. It happens only on
2350 the first constraints sub-pass when we do most of
2352 if (lra_constraint_iter
== 1 && last_reload
> bb_reload_num
)
2353 reload_sum
+= last_reload
- bb_reload_num
;
2355 /* If this is a constant that is reloaded into the
2356 desired class by copying it to memory first, count
2357 that as another reload. This is consistent with
2358 other code and is required to avoid choosing another
2359 alternative when the constant is moved into memory.
2360 Note that the test here is precisely the same as in
2361 the code below that calls force_const_mem. */
2362 if (CONST_POOL_OK_P (mode
, op
)
2363 && ((targetm
.preferred_reload_class
2364 (op
, this_alternative
) == NO_REGS
)
2365 || no_input_reloads_p
))
2372 /* Alternative loses if it requires a type of reload not
2373 permitted for this insn. We can always reload
2374 objects with a REG_UNUSED note. */
2375 if ((curr_static_id
->operand
[nop
].type
!= OP_IN
2376 && no_output_reloads_p
2377 && ! find_reg_note (curr_insn
, REG_UNUSED
, op
))
2378 || (curr_static_id
->operand
[nop
].type
!= OP_OUT
2379 && no_input_reloads_p
&& ! const_to_mem
)
2380 || (this_alternative_matches
>= 0
2381 && (no_input_reloads_p
2382 || (no_output_reloads_p
2383 && (curr_static_id
->operand
2384 [this_alternative_matches
].type
!= OP_IN
)
2385 && ! find_reg_note (curr_insn
, REG_UNUSED
,
2386 no_subreg_reg_operand
2387 [this_alternative_matches
])))))
2389 if (lra_dump_file
!= NULL
)
2392 " alt=%d: No input/otput reload -- refuse\n",
2397 /* Check strong discouragement of reload of non-constant
2398 into class THIS_ALTERNATIVE. */
2399 if (! CONSTANT_P (op
) && ! no_regs_p
2400 && (targetm
.preferred_reload_class
2401 (op
, this_alternative
) == NO_REGS
2402 || (curr_static_id
->operand
[nop
].type
== OP_OUT
2403 && (targetm
.preferred_output_reload_class
2404 (op
, this_alternative
) == NO_REGS
))))
2406 if (lra_dump_file
!= NULL
)
2407 fprintf (lra_dump_file
,
2408 " %d Non-prefered reload: reject+=%d\n",
2409 nop
, LRA_MAX_REJECT
);
2410 reject
+= LRA_MAX_REJECT
;
2413 if (! (MEM_P (op
) && offmemok
)
2414 && ! (const_to_mem
&& constmemok
))
2416 /* We prefer to reload pseudos over reloading other
2417 things, since such reloads may be able to be
2418 eliminated later. So bump REJECT in other cases.
2419 Don't do this in the case where we are forcing a
2420 constant into memory and it will then win since
2421 we don't want to have a different alternative
2423 if (! (REG_P (op
) && REGNO (op
) >= FIRST_PSEUDO_REGISTER
))
2425 if (lra_dump_file
!= NULL
)
2428 " %d Non-pseudo reload: reject+=2\n",
2435 += ira_reg_class_max_nregs
[this_alternative
][mode
];
2437 if (SMALL_REGISTER_CLASS_P (this_alternative
))
2439 if (lra_dump_file
!= NULL
)
2442 " %d Small class reload: reject+=%d\n",
2443 nop
, LRA_LOSER_COST_FACTOR
/ 2);
2444 reject
+= LRA_LOSER_COST_FACTOR
/ 2;
2448 /* We are trying to spill pseudo into memory. It is
2449 usually more costly than moving to a hard register
2450 although it might takes the same number of
2452 if (no_regs_p
&& REG_P (op
) && hard_regno
[nop
] >= 0)
2454 if (lra_dump_file
!= NULL
)
2457 " %d Spill pseudo into memory: reject+=3\n",
2460 if (VECTOR_MODE_P (mode
))
2462 /* Spilling vectors into memory is usually more
2463 costly as they contain big values. */
2464 if (lra_dump_file
!= NULL
)
2467 " %d Spill vector pseudo: reject+=2\n",
2473 #ifdef SECONDARY_MEMORY_NEEDED
2474 /* If reload requires moving value through secondary
2475 memory, it will need one more insn at least. */
2476 if (this_alternative
!= NO_REGS
2477 && REG_P (op
) && (cl
= get_reg_class (REGNO (op
))) != NO_REGS
2478 && ((curr_static_id
->operand
[nop
].type
!= OP_OUT
2479 && SECONDARY_MEMORY_NEEDED (cl
, this_alternative
,
2481 || (curr_static_id
->operand
[nop
].type
!= OP_IN
2482 && SECONDARY_MEMORY_NEEDED (this_alternative
, cl
,
2486 /* Input reloads can be inherited more often than output
2487 reloads can be removed, so penalize output
2489 if (!REG_P (op
) || curr_static_id
->operand
[nop
].type
!= OP_IN
)
2491 if (lra_dump_file
!= NULL
)
2494 " %d Non input pseudo reload: reject++\n",
2500 if (early_clobber_p
&& ! scratch_p
)
2502 if (lra_dump_file
!= NULL
)
2503 fprintf (lra_dump_file
,
2504 " %d Early clobber: reject++\n", nop
);
2507 /* ??? We check early clobbers after processing all operands
2508 (see loop below) and there we update the costs more.
2509 Should we update the cost (may be approximately) here
2510 because of early clobber register reloads or it is a rare
2511 or non-important thing to be worth to do it. */
2512 overall
= losers
* LRA_LOSER_COST_FACTOR
+ reject
;
2513 if ((best_losers
== 0 || losers
!= 0) && best_overall
< overall
)
2515 if (lra_dump_file
!= NULL
)
2516 fprintf (lra_dump_file
,
2517 " alt=%d,overall=%d,losers=%d -- refuse\n",
2518 nalt
, overall
, losers
);
2522 curr_alt
[nop
] = this_alternative
;
2523 COPY_HARD_REG_SET (curr_alt_set
[nop
], this_alternative_set
);
2524 curr_alt_win
[nop
] = this_alternative_win
;
2525 curr_alt_match_win
[nop
] = this_alternative_match_win
;
2526 curr_alt_offmemok
[nop
] = this_alternative_offmemok
;
2527 curr_alt_matches
[nop
] = this_alternative_matches
;
2529 if (this_alternative_matches
>= 0
2530 && !did_match
&& !this_alternative_win
)
2531 curr_alt_win
[this_alternative_matches
] = false;
2533 if (early_clobber_p
&& operand_reg
[nop
] != NULL_RTX
)
2534 early_clobbered_nops
[early_clobbered_regs_num
++] = nop
;
2536 if (curr_insn_set
!= NULL_RTX
&& n_operands
== 2
2537 /* Prevent processing non-move insns. */
2538 && (GET_CODE (SET_SRC (curr_insn_set
)) == SUBREG
2539 || SET_SRC (curr_insn_set
) == no_subreg_reg_operand
[1])
2540 && ((! curr_alt_win
[0] && ! curr_alt_win
[1]
2541 && REG_P (no_subreg_reg_operand
[0])
2542 && REG_P (no_subreg_reg_operand
[1])
2543 && (reg_in_class_p (no_subreg_reg_operand
[0], curr_alt
[1])
2544 || reg_in_class_p (no_subreg_reg_operand
[1], curr_alt
[0])))
2545 || (! curr_alt_win
[0] && curr_alt_win
[1]
2546 && REG_P (no_subreg_reg_operand
[1])
2547 && reg_in_class_p (no_subreg_reg_operand
[1], curr_alt
[0]))
2548 || (curr_alt_win
[0] && ! curr_alt_win
[1]
2549 && REG_P (no_subreg_reg_operand
[0])
2550 && reg_in_class_p (no_subreg_reg_operand
[0], curr_alt
[1])
2551 && (! CONST_POOL_OK_P (curr_operand_mode
[1],
2552 no_subreg_reg_operand
[1])
2553 || (targetm
.preferred_reload_class
2554 (no_subreg_reg_operand
[1],
2555 (enum reg_class
) curr_alt
[1]) != NO_REGS
))
2556 /* If it is a result of recent elimination in move
2557 insn we can transform it into an add still by
2558 using this alternative. */
2559 && GET_CODE (no_subreg_reg_operand
[1]) != PLUS
)))
2561 /* We have a move insn and a new reload insn will be similar
2562 to the current insn. We should avoid such situation as it
2563 results in LRA cycling. */
2564 overall
+= LRA_MAX_REJECT
;
2567 curr_alt_dont_inherit_ops_num
= 0;
2568 for (nop
= 0; nop
< early_clobbered_regs_num
; nop
++)
2570 int i
, j
, clobbered_hard_regno
, first_conflict_j
, last_conflict_j
;
2571 HARD_REG_SET temp_set
;
2573 i
= early_clobbered_nops
[nop
];
2574 if ((! curr_alt_win
[i
] && ! curr_alt_match_win
[i
])
2575 || hard_regno
[i
] < 0)
2577 lra_assert (operand_reg
[i
] != NULL_RTX
);
2578 clobbered_hard_regno
= hard_regno
[i
];
2579 CLEAR_HARD_REG_SET (temp_set
);
2580 add_to_hard_reg_set (&temp_set
, biggest_mode
[i
], clobbered_hard_regno
);
2581 first_conflict_j
= last_conflict_j
= -1;
2582 for (j
= 0; j
< n_operands
; j
++)
2584 /* We don't want process insides of match_operator and
2585 match_parallel because otherwise we would process
2586 their operands once again generating a wrong
2588 || curr_static_id
->operand
[j
].is_operator
)
2590 else if ((curr_alt_matches
[j
] == i
&& curr_alt_match_win
[j
])
2591 || (curr_alt_matches
[i
] == j
&& curr_alt_match_win
[i
]))
2593 /* If we don't reload j-th operand, check conflicts. */
2594 else if ((curr_alt_win
[j
] || curr_alt_match_win
[j
])
2595 && uses_hard_regs_p (*curr_id
->operand_loc
[j
], temp_set
))
2597 if (first_conflict_j
< 0)
2598 first_conflict_j
= j
;
2599 last_conflict_j
= j
;
2601 if (last_conflict_j
< 0)
2603 /* If earlyclobber operand conflicts with another
2604 non-matching operand which is actually the same register
2605 as the earlyclobber operand, it is better to reload the
2606 another operand as an operand matching the earlyclobber
2607 operand can be also the same. */
2608 if (first_conflict_j
== last_conflict_j
2609 && operand_reg
[last_conflict_j
]
2610 != NULL_RTX
&& ! curr_alt_match_win
[last_conflict_j
]
2611 && REGNO (operand_reg
[i
]) == REGNO (operand_reg
[last_conflict_j
]))
2613 curr_alt_win
[last_conflict_j
] = false;
2614 curr_alt_dont_inherit_ops
[curr_alt_dont_inherit_ops_num
++]
2617 /* Early clobber was already reflected in REJECT. */
2618 lra_assert (reject
> 0);
2619 if (lra_dump_file
!= NULL
)
2622 " %d Conflict early clobber reload: reject--\n",
2625 overall
+= LRA_LOSER_COST_FACTOR
- 1;
2629 /* We need to reload early clobbered register and the
2630 matched registers. */
2631 for (j
= 0; j
< n_operands
; j
++)
2632 if (curr_alt_matches
[j
] == i
)
2634 curr_alt_match_win
[j
] = false;
2636 overall
+= LRA_LOSER_COST_FACTOR
;
2638 if (! curr_alt_match_win
[i
])
2639 curr_alt_dont_inherit_ops
[curr_alt_dont_inherit_ops_num
++] = i
;
2642 /* Remember pseudos used for match reloads are never
2644 lra_assert (curr_alt_matches
[i
] >= 0);
2645 curr_alt_win
[curr_alt_matches
[i
]] = false;
2647 curr_alt_win
[i
] = curr_alt_match_win
[i
] = false;
2649 /* Early clobber was already reflected in REJECT. */
2650 lra_assert (reject
> 0);
2651 if (lra_dump_file
!= NULL
)
2654 " %d Matched conflict early clobber reloads:"
2658 overall
+= LRA_LOSER_COST_FACTOR
- 1;
2661 if (lra_dump_file
!= NULL
)
2662 fprintf (lra_dump_file
, " alt=%d,overall=%d,losers=%d,rld_nregs=%d\n",
2663 nalt
, overall
, losers
, reload_nregs
);
2665 /* If this alternative can be made to work by reloading, and it
2666 needs less reloading than the others checked so far, record
2667 it as the chosen goal for reloading. */
2668 if ((best_losers
!= 0 && losers
== 0)
2669 || (((best_losers
== 0 && losers
== 0)
2670 || (best_losers
!= 0 && losers
!= 0))
2671 && (best_overall
> overall
2672 || (best_overall
== overall
2673 /* If the cost of the reloads is the same,
2674 prefer alternative which requires minimal
2675 number of reload regs. */
2676 && (reload_nregs
< best_reload_nregs
2677 || (reload_nregs
== best_reload_nregs
2678 && (best_reload_sum
< reload_sum
2679 || (best_reload_sum
== reload_sum
2680 && nalt
< goal_alt_number
))))))))
2682 for (nop
= 0; nop
< n_operands
; nop
++)
2684 goal_alt_win
[nop
] = curr_alt_win
[nop
];
2685 goal_alt_match_win
[nop
] = curr_alt_match_win
[nop
];
2686 goal_alt_matches
[nop
] = curr_alt_matches
[nop
];
2687 goal_alt
[nop
] = curr_alt
[nop
];
2688 goal_alt_offmemok
[nop
] = curr_alt_offmemok
[nop
];
2690 goal_alt_dont_inherit_ops_num
= curr_alt_dont_inherit_ops_num
;
2691 for (nop
= 0; nop
< curr_alt_dont_inherit_ops_num
; nop
++)
2692 goal_alt_dont_inherit_ops
[nop
] = curr_alt_dont_inherit_ops
[nop
];
2693 goal_alt_swapped
= curr_swapped
;
2694 best_overall
= overall
;
2695 best_losers
= losers
;
2696 best_reload_nregs
= reload_nregs
;
2697 best_reload_sum
= reload_sum
;
2698 goal_alt_number
= nalt
;
2701 /* Everything is satisfied. Do not process alternatives
2710 /* Make reload base reg from address AD. */
2712 base_to_reg (struct address_info
*ad
)
2716 rtx new_inner
= NULL_RTX
;
2717 rtx new_reg
= NULL_RTX
;
2719 rtx last_insn
= get_last_insn();
2721 lra_assert (ad
->base
== ad
->base_term
&& ad
->disp
== ad
->disp_term
);
2722 cl
= base_reg_class (ad
->mode
, ad
->as
, ad
->base_outer_code
,
2723 get_index_code (ad
));
2724 new_reg
= lra_create_new_reg (GET_MODE (*ad
->base_term
), NULL_RTX
,
2726 new_inner
= simplify_gen_binary (PLUS
, GET_MODE (new_reg
), new_reg
,
2727 ad
->disp_term
== NULL
2728 ? gen_int_mode (0, ad
->mode
)
2730 if (!valid_address_p (ad
->mode
, new_inner
, ad
->as
))
2732 insn
= emit_insn (gen_rtx_SET (ad
->mode
, new_reg
, *ad
->base_term
));
2733 code
= recog_memoized (insn
);
2736 delete_insns_since (last_insn
);
2743 /* Make reload base reg + disp from address AD. Return the new pseudo. */
2745 base_plus_disp_to_reg (struct address_info
*ad
)
2750 lra_assert (ad
->base
== ad
->base_term
&& ad
->disp
== ad
->disp_term
);
2751 cl
= base_reg_class (ad
->mode
, ad
->as
, ad
->base_outer_code
,
2752 get_index_code (ad
));
2753 new_reg
= lra_create_new_reg (GET_MODE (*ad
->base_term
), NULL_RTX
,
2755 lra_emit_add (new_reg
, *ad
->base_term
, *ad
->disp_term
);
2759 /* Make reload of index part of address AD. Return the new
2762 index_part_to_reg (struct address_info
*ad
)
2766 new_reg
= lra_create_new_reg (GET_MODE (*ad
->index
), NULL_RTX
,
2767 INDEX_REG_CLASS
, "index term");
2768 expand_mult (GET_MODE (*ad
->index
), *ad
->index_term
,
2769 GEN_INT (get_index_scale (ad
)), new_reg
, 1);
2773 /* Return true if we can add a displacement to address AD, even if that
2774 makes the address invalid. The fix-up code requires any new address
2775 to be the sum of the BASE_TERM, INDEX and DISP_TERM fields. */
2777 can_add_disp_p (struct address_info
*ad
)
2779 return (!ad
->autoinc_p
2780 && ad
->segment
== NULL
2781 && ad
->base
== ad
->base_term
2782 && ad
->disp
== ad
->disp_term
);
2785 /* Make equiv substitution in address AD. Return true if a substitution
2788 equiv_address_substitution (struct address_info
*ad
)
2790 rtx base_reg
, new_base_reg
, index_reg
, new_index_reg
, *base_term
, *index_term
;
2791 HOST_WIDE_INT disp
, scale
;
2794 base_term
= strip_subreg (ad
->base_term
);
2795 if (base_term
== NULL
)
2796 base_reg
= new_base_reg
= NULL_RTX
;
2799 base_reg
= *base_term
;
2800 new_base_reg
= get_equiv_with_elimination (base_reg
, curr_insn
);
2802 index_term
= strip_subreg (ad
->index_term
);
2803 if (index_term
== NULL
)
2804 index_reg
= new_index_reg
= NULL_RTX
;
2807 index_reg
= *index_term
;
2808 new_index_reg
= get_equiv_with_elimination (index_reg
, curr_insn
);
2810 if (base_reg
== new_base_reg
&& index_reg
== new_index_reg
)
2814 if (lra_dump_file
!= NULL
)
2816 fprintf (lra_dump_file
, "Changing address in insn %d ",
2817 INSN_UID (curr_insn
));
2818 dump_value_slim (lra_dump_file
, *ad
->outer
, 1);
2820 if (base_reg
!= new_base_reg
)
2822 if (REG_P (new_base_reg
))
2824 *base_term
= new_base_reg
;
2827 else if (GET_CODE (new_base_reg
) == PLUS
2828 && REG_P (XEXP (new_base_reg
, 0))
2829 && CONST_INT_P (XEXP (new_base_reg
, 1))
2830 && can_add_disp_p (ad
))
2832 disp
+= INTVAL (XEXP (new_base_reg
, 1));
2833 *base_term
= XEXP (new_base_reg
, 0);
2836 if (ad
->base_term2
!= NULL
)
2837 *ad
->base_term2
= *ad
->base_term
;
2839 if (index_reg
!= new_index_reg
)
2841 if (REG_P (new_index_reg
))
2843 *index_term
= new_index_reg
;
2846 else if (GET_CODE (new_index_reg
) == PLUS
2847 && REG_P (XEXP (new_index_reg
, 0))
2848 && CONST_INT_P (XEXP (new_index_reg
, 1))
2849 && can_add_disp_p (ad
)
2850 && (scale
= get_index_scale (ad
)))
2852 disp
+= INTVAL (XEXP (new_index_reg
, 1)) * scale
;
2853 *index_term
= XEXP (new_index_reg
, 0);
2859 if (ad
->disp
!= NULL
)
2860 *ad
->disp
= plus_constant (GET_MODE (*ad
->inner
), *ad
->disp
, disp
);
2863 *ad
->inner
= plus_constant (GET_MODE (*ad
->inner
), *ad
->inner
, disp
);
2864 update_address (ad
);
2868 if (lra_dump_file
!= NULL
)
2871 fprintf (lra_dump_file
, " -- no change\n");
2874 fprintf (lra_dump_file
, " on equiv ");
2875 dump_value_slim (lra_dump_file
, *ad
->outer
, 1);
2876 fprintf (lra_dump_file
, "\n");
2882 /* Major function to make reloads for an address in operand NOP.
2883 The supported cases are:
2885 1) an address that existed before LRA started, at which point it
2886 must have been valid. These addresses are subject to elimination
2887 and may have become invalid due to the elimination offset being out
2890 2) an address created by forcing a constant to memory
2891 (force_const_to_mem). The initial form of these addresses might
2892 not be valid, and it is this function's job to make them valid.
2894 3) a frame address formed from a register and a (possibly zero)
2895 constant offset. As above, these addresses might not be valid and
2896 this function must make them so.
2898 Add reloads to the lists *BEFORE and *AFTER. We might need to add
2899 reloads to *AFTER because of inc/dec, {pre, post} modify in the
2900 address. Return true for any RTL change.
2902 The function is a helper function which does not produce all
2903 transformations which can be necessary. It does just basic steps.
2904 To do all necessary transformations use function
2907 process_address_1 (int nop
, rtx
*before
, rtx
*after
)
2909 struct address_info ad
;
2911 rtx op
= *curr_id
->operand_loc
[nop
];
2912 const char *constraint
= curr_static_id
->operand
[nop
].constraint
;
2915 if (constraint
[0] == 'p'
2916 || EXTRA_ADDRESS_CONSTRAINT (constraint
[0], constraint
))
2917 decompose_lea_address (&ad
, curr_id
->operand_loc
[nop
]);
2918 else if (MEM_P (op
))
2919 decompose_mem_address (&ad
, op
);
2920 else if (GET_CODE (op
) == SUBREG
2921 && MEM_P (SUBREG_REG (op
)))
2922 decompose_mem_address (&ad
, SUBREG_REG (op
));
2925 change_p
= equiv_address_substitution (&ad
);
2926 if (ad
.base_term
!= NULL
2927 && (process_addr_reg
2928 (ad
.base_term
, before
,
2930 && !(REG_P (*ad
.base_term
)
2931 && find_regno_note (curr_insn
, REG_DEAD
,
2932 REGNO (*ad
.base_term
)) != NULL_RTX
)
2934 base_reg_class (ad
.mode
, ad
.as
, ad
.base_outer_code
,
2935 get_index_code (&ad
)))))
2938 if (ad
.base_term2
!= NULL
)
2939 *ad
.base_term2
= *ad
.base_term
;
2941 if (ad
.index_term
!= NULL
2942 && process_addr_reg (ad
.index_term
, before
, NULL
, INDEX_REG_CLASS
))
2945 #ifdef EXTRA_CONSTRAINT_STR
2946 /* Target hooks sometimes reject extra constraint addresses -- use
2947 EXTRA_CONSTRAINT_STR for the validation. */
2948 if (constraint
[0] != 'p'
2949 && EXTRA_ADDRESS_CONSTRAINT (constraint
[0], constraint
)
2950 && satisfies_address_constraint_p (&ad
, constraint
))
2954 /* There are three cases where the shape of *AD.INNER may now be invalid:
2956 1) the original address was valid, but either elimination or
2957 equiv_address_substitution was applied and that made
2958 the address invalid.
2960 2) the address is an invalid symbolic address created by
2963 3) the address is a frame address with an invalid offset.
2965 4) the address is a frame address with an invalid base.
2967 All these cases involve a non-autoinc address, so there is no
2968 point revalidating other types. */
2969 if (ad
.autoinc_p
|| valid_address_p (&ad
))
2972 /* Any index existed before LRA started, so we can assume that the
2973 presence and shape of the index is valid. */
2974 push_to_sequence (*before
);
2975 lra_assert (ad
.disp
== ad
.disp_term
);
2976 if (ad
.base
== NULL
)
2978 if (ad
.index
== NULL
)
2981 enum reg_class cl
= base_reg_class (ad
.mode
, ad
.as
,
2983 rtx addr
= *ad
.inner
;
2985 new_reg
= lra_create_new_reg (Pmode
, NULL_RTX
, cl
, "addr");
2989 rtx last
= get_last_insn ();
2991 /* addr => lo_sum (new_base, addr), case (2) above. */
2992 insn
= emit_insn (gen_rtx_SET
2994 gen_rtx_HIGH (Pmode
, copy_rtx (addr
))));
2995 code
= recog_memoized (insn
);
2998 *ad
.inner
= gen_rtx_LO_SUM (Pmode
, new_reg
, addr
);
2999 if (! valid_address_p (ad
.mode
, *ad
.outer
, ad
.as
))
3001 /* Try to put lo_sum into register. */
3002 insn
= emit_insn (gen_rtx_SET
3004 gen_rtx_LO_SUM (Pmode
, new_reg
, addr
)));
3005 code
= recog_memoized (insn
);
3008 *ad
.inner
= new_reg
;
3009 if (! valid_address_p (ad
.mode
, *ad
.outer
, ad
.as
))
3019 delete_insns_since (last
);
3024 /* addr => new_base, case (2) above. */
3025 lra_emit_move (new_reg
, addr
);
3026 *ad
.inner
= new_reg
;
3031 /* index * scale + disp => new base + index * scale,
3033 enum reg_class cl
= base_reg_class (ad
.mode
, ad
.as
, PLUS
,
3034 GET_CODE (*ad
.index
));
3036 lra_assert (INDEX_REG_CLASS
!= NO_REGS
);
3037 new_reg
= lra_create_new_reg (Pmode
, NULL_RTX
, cl
, "disp");
3038 lra_emit_move (new_reg
, *ad
.disp
);
3039 *ad
.inner
= simplify_gen_binary (PLUS
, GET_MODE (new_reg
),
3040 new_reg
, *ad
.index
);
3043 else if (ad
.index
== NULL
)
3047 rtx set
, insns
, last_insn
;
3048 /* Try to reload base into register only if the base is invalid
3049 for the address but with valid offset, case (4) above. */
3051 new_reg
= base_to_reg (&ad
);
3053 /* base + disp => new base, cases (1) and (3) above. */
3054 /* Another option would be to reload the displacement into an
3055 index register. However, postreload has code to optimize
3056 address reloads that have the same base and different
3057 displacements, so reloading into an index register would
3058 not necessarily be a win. */
3059 if (new_reg
== NULL_RTX
)
3060 new_reg
= base_plus_disp_to_reg (&ad
);
3061 insns
= get_insns ();
3062 last_insn
= get_last_insn ();
3063 /* If we generated at least two insns, try last insn source as
3064 an address. If we succeed, we generate one less insn. */
3065 if (last_insn
!= insns
&& (set
= single_set (last_insn
)) != NULL_RTX
3066 && GET_CODE (SET_SRC (set
)) == PLUS
3067 && REG_P (XEXP (SET_SRC (set
), 0))
3068 && CONSTANT_P (XEXP (SET_SRC (set
), 1)))
3070 *ad
.inner
= SET_SRC (set
);
3071 if (valid_address_p (ad
.mode
, *ad
.outer
, ad
.as
))
3073 *ad
.base_term
= XEXP (SET_SRC (set
), 0);
3074 *ad
.disp_term
= XEXP (SET_SRC (set
), 1);
3075 cl
= base_reg_class (ad
.mode
, ad
.as
, ad
.base_outer_code
,
3076 get_index_code (&ad
));
3077 regno
= REGNO (*ad
.base_term
);
3078 if (regno
>= FIRST_PSEUDO_REGISTER
3079 && cl
!= lra_get_allocno_class (regno
))
3080 lra_change_class (regno
, cl
, " Change to", true);
3081 new_reg
= SET_SRC (set
);
3082 delete_insns_since (PREV_INSN (last_insn
));
3087 *ad
.inner
= new_reg
;
3089 else if (ad
.disp_term
!= NULL
)
3091 /* base + scale * index + disp => new base + scale * index,
3093 new_reg
= base_plus_disp_to_reg (&ad
);
3094 *ad
.inner
= simplify_gen_binary (PLUS
, GET_MODE (new_reg
),
3095 new_reg
, *ad
.index
);
3097 else if (get_index_scale (&ad
) == 1)
3099 /* The last transformation to one reg will be made in
3100 curr_insn_transform function. */
3106 /* base + scale * index => base + new_reg,
3108 Index part of address may become invalid. For example, we
3109 changed pseudo on the equivalent memory and a subreg of the
3110 pseudo onto the memory of different mode for which the scale is
3112 new_reg
= index_part_to_reg (&ad
);
3113 *ad
.inner
= simplify_gen_binary (PLUS
, GET_MODE (new_reg
),
3114 *ad
.base_term
, new_reg
);
3116 *before
= get_insns ();
3121 /* Do address reloads until it is necessary. Use process_address_1 as
3122 a helper function. Return true for any RTL changes. */
3124 process_address (int nop
, rtx
*before
, rtx
*after
)
3128 while (process_address_1 (nop
, before
, after
))
3133 /* Emit insns to reload VALUE into a new register. VALUE is an
3134 auto-increment or auto-decrement RTX whose operand is a register or
3135 memory location; so reloading involves incrementing that location.
3136 IN is either identical to VALUE, or some cheaper place to reload
3137 value being incremented/decremented from.
3139 INC_AMOUNT is the number to increment or decrement by (always
3140 positive and ignored for POST_MODIFY/PRE_MODIFY).
3142 Return pseudo containing the result. */
3144 emit_inc (enum reg_class new_rclass
, rtx in
, rtx value
, int inc_amount
)
3146 /* REG or MEM to be copied and incremented. */
3147 rtx incloc
= XEXP (value
, 0);
3148 /* Nonzero if increment after copying. */
3149 int post
= (GET_CODE (value
) == POST_DEC
|| GET_CODE (value
) == POST_INC
3150 || GET_CODE (value
) == POST_MODIFY
);
3155 rtx real_in
= in
== value
? incloc
: in
;
3159 if (GET_CODE (value
) == PRE_MODIFY
|| GET_CODE (value
) == POST_MODIFY
)
3161 lra_assert (GET_CODE (XEXP (value
, 1)) == PLUS
3162 || GET_CODE (XEXP (value
, 1)) == MINUS
);
3163 lra_assert (rtx_equal_p (XEXP (XEXP (value
, 1), 0), XEXP (value
, 0)));
3164 plus_p
= GET_CODE (XEXP (value
, 1)) == PLUS
;
3165 inc
= XEXP (XEXP (value
, 1), 1);
3169 if (GET_CODE (value
) == PRE_DEC
|| GET_CODE (value
) == POST_DEC
)
3170 inc_amount
= -inc_amount
;
3172 inc
= GEN_INT (inc_amount
);
3175 if (! post
&& REG_P (incloc
))
3178 result
= lra_create_new_reg (GET_MODE (value
), value
, new_rclass
,
3181 if (real_in
!= result
)
3183 /* First copy the location to the result register. */
3184 lra_assert (REG_P (result
));
3185 emit_insn (gen_move_insn (result
, real_in
));
3188 /* We suppose that there are insns to add/sub with the constant
3189 increment permitted in {PRE/POST)_{DEC/INC/MODIFY}. At least the
3190 old reload worked with this assumption. If the assumption
3191 becomes wrong, we should use approach in function
3192 base_plus_disp_to_reg. */
3195 /* See if we can directly increment INCLOC. */
3196 last
= get_last_insn ();
3197 add_insn
= emit_insn (plus_p
3198 ? gen_add2_insn (incloc
, inc
)
3199 : gen_sub2_insn (incloc
, inc
));
3201 code
= recog_memoized (add_insn
);
3204 if (! post
&& result
!= incloc
)
3205 emit_insn (gen_move_insn (result
, incloc
));
3208 delete_insns_since (last
);
3211 /* If couldn't do the increment directly, must increment in RESULT.
3212 The way we do this depends on whether this is pre- or
3213 post-increment. For pre-increment, copy INCLOC to the reload
3214 register, increment it there, then save back. */
3217 if (real_in
!= result
)
3218 emit_insn (gen_move_insn (result
, real_in
));
3220 emit_insn (gen_add2_insn (result
, inc
));
3222 emit_insn (gen_sub2_insn (result
, inc
));
3223 if (result
!= incloc
)
3224 emit_insn (gen_move_insn (incloc
, result
));
3230 Because this might be a jump insn or a compare, and because
3231 RESULT may not be available after the insn in an input
3232 reload, we must do the incrementing before the insn being
3235 We have already copied IN to RESULT. Increment the copy in
3236 RESULT, save that back, then decrement RESULT so it has
3237 the original value. */
3239 emit_insn (gen_add2_insn (result
, inc
));
3241 emit_insn (gen_sub2_insn (result
, inc
));
3242 emit_insn (gen_move_insn (incloc
, result
));
3243 /* Restore non-modified value for the result. We prefer this
3244 way because it does not require an additional hard
3248 if (CONST_INT_P (inc
))
3249 emit_insn (gen_add2_insn (result
,
3250 gen_int_mode (-INTVAL (inc
),
3251 GET_MODE (result
))));
3253 emit_insn (gen_sub2_insn (result
, inc
));
3256 emit_insn (gen_add2_insn (result
, inc
));
3261 /* Return true if the current move insn does not need processing as we
3262 already know that it satisfies its constraints. */
3264 simple_move_p (void)
3267 enum reg_class dclass
, sclass
;
3269 lra_assert (curr_insn_set
!= NULL_RTX
);
3270 dest
= SET_DEST (curr_insn_set
);
3271 src
= SET_SRC (curr_insn_set
);
3272 return ((dclass
= get_op_class (dest
)) != NO_REGS
3273 && (sclass
= get_op_class (src
)) != NO_REGS
3274 /* The backend guarantees that register moves of cost 2
3275 never need reloads. */
3276 && targetm
.register_move_cost (GET_MODE (src
), dclass
, sclass
) == 2);
3279 /* Swap operands NOP and NOP + 1. */
3281 swap_operands (int nop
)
3283 enum machine_mode mode
= curr_operand_mode
[nop
];
3284 curr_operand_mode
[nop
] = curr_operand_mode
[nop
+ 1];
3285 curr_operand_mode
[nop
+ 1] = mode
;
3286 rtx x
= *curr_id
->operand_loc
[nop
];
3287 *curr_id
->operand_loc
[nop
] = *curr_id
->operand_loc
[nop
+ 1];
3288 *curr_id
->operand_loc
[nop
+ 1] = x
;
3289 /* Swap the duplicates too. */
3290 lra_update_dup (curr_id
, nop
);
3291 lra_update_dup (curr_id
, nop
+ 1);
3294 /* Main entry point of the constraint code: search the body of the
3295 current insn to choose the best alternative. It is mimicking insn
3296 alternative cost calculation model of former reload pass. That is
3297 because machine descriptions were written to use this model. This
3298 model can be changed in future. Make commutative operand exchange
3301 Return true if some RTL changes happened during function call. */
3303 curr_insn_transform (void)
3309 signed char goal_alt_matched
[MAX_RECOG_OPERANDS
][MAX_RECOG_OPERANDS
];
3310 signed char match_inputs
[MAX_RECOG_OPERANDS
+ 1];
3313 /* Flag that the insn has been changed through a transformation. */
3316 #ifdef SECONDARY_MEMORY_NEEDED
3319 int max_regno_before
;
3320 int reused_alternative_num
;
3322 curr_insn_set
= single_set (curr_insn
);
3323 if (curr_insn_set
!= NULL_RTX
&& simple_move_p ())
3326 no_input_reloads_p
= no_output_reloads_p
= false;
3327 goal_alt_number
= -1;
3328 change_p
= sec_mem_p
= false;
3329 /* JUMP_INSNs and CALL_INSNs are not allowed to have any output
3330 reloads; neither are insns that SET cc0. Insns that use CC0 are
3331 not allowed to have any input reloads. */
3332 if (JUMP_P (curr_insn
) || CALL_P (curr_insn
))
3333 no_output_reloads_p
= true;
3336 if (reg_referenced_p (cc0_rtx
, PATTERN (curr_insn
)))
3337 no_input_reloads_p
= true;
3338 if (reg_set_p (cc0_rtx
, PATTERN (curr_insn
)))
3339 no_output_reloads_p
= true;
3342 n_operands
= curr_static_id
->n_operands
;
3343 n_alternatives
= curr_static_id
->n_alternatives
;
3345 /* Just return "no reloads" if insn has no operands with
3347 if (n_operands
== 0 || n_alternatives
== 0)
3350 max_regno_before
= max_reg_num ();
3352 for (i
= 0; i
< n_operands
; i
++)
3354 goal_alt_matched
[i
][0] = -1;
3355 goal_alt_matches
[i
] = -1;
3358 commutative
= curr_static_id
->commutative
;
3360 /* Now see what we need for pseudos that didn't get hard regs or got
3361 the wrong kind of hard reg. For this, we must consider all the
3362 operands together against the register constraints. */
3364 best_losers
= best_overall
= INT_MAX
;
3365 best_reload_sum
= 0;
3367 curr_swapped
= false;
3368 goal_alt_swapped
= false;
3370 /* Make equivalence substitution and memory subreg elimination
3371 before address processing because an address legitimacy can
3372 depend on memory mode. */
3373 for (i
= 0; i
< n_operands
; i
++)
3375 rtx op
= *curr_id
->operand_loc
[i
];
3376 rtx subst
, old
= op
;
3377 bool op_change_p
= false;
3379 if (GET_CODE (old
) == SUBREG
)
3380 old
= SUBREG_REG (old
);
3381 subst
= get_equiv_with_elimination (old
, curr_insn
);
3384 subst
= copy_rtx (subst
);
3385 lra_assert (REG_P (old
));
3386 if (GET_CODE (op
) == SUBREG
)
3387 SUBREG_REG (op
) = subst
;
3389 *curr_id
->operand_loc
[i
] = subst
;
3390 if (lra_dump_file
!= NULL
)
3392 fprintf (lra_dump_file
,
3393 "Changing pseudo %d in operand %i of insn %u on equiv ",
3394 REGNO (old
), i
, INSN_UID (curr_insn
));
3395 dump_value_slim (lra_dump_file
, subst
, 1);
3396 fprintf (lra_dump_file
, "\n");
3398 op_change_p
= change_p
= true;
3400 if (simplify_operand_subreg (i
, GET_MODE (old
)) || op_change_p
)
3403 lra_update_dup (curr_id
, i
);
3407 /* Reload address registers and displacements. We do it before
3408 finding an alternative because of memory constraints. */
3409 before
= after
= NULL_RTX
;
3410 for (i
= 0; i
< n_operands
; i
++)
3411 if (! curr_static_id
->operand
[i
].is_operator
3412 && process_address (i
, &before
, &after
))
3415 lra_update_dup (curr_id
, i
);
3419 /* If we've changed the instruction then any alternative that
3420 we chose previously may no longer be valid. */
3421 lra_set_used_insn_alternative (curr_insn
, -1);
3423 if (curr_insn_set
!= NULL_RTX
3424 && check_and_process_move (&change_p
, &sec_mem_p
))
3429 reused_alternative_num
= curr_id
->used_insn_alternative
;
3430 if (lra_dump_file
!= NULL
&& reused_alternative_num
>= 0)
3431 fprintf (lra_dump_file
, "Reusing alternative %d for insn #%u\n",
3432 reused_alternative_num
, INSN_UID (curr_insn
));
3434 if (process_alt_operands (reused_alternative_num
))
3437 /* If insn is commutative (it's safe to exchange a certain pair of
3438 operands) then we need to try each alternative twice, the second
3439 time matching those two operands as if we had exchanged them. To
3440 do this, really exchange them in operands.
3442 If we have just tried the alternatives the second time, return
3443 operands to normal and drop through. */
3445 if (reused_alternative_num
< 0 && commutative
>= 0)
3447 curr_swapped
= !curr_swapped
;
3450 swap_operands (commutative
);
3454 swap_operands (commutative
);
3457 if (! alt_p
&& ! sec_mem_p
)
3459 /* No alternative works with reloads?? */
3460 if (INSN_CODE (curr_insn
) >= 0)
3461 fatal_insn ("unable to generate reloads for:", curr_insn
);
3462 error_for_asm (curr_insn
,
3463 "inconsistent operand constraints in an %<asm%>");
3464 /* Avoid further trouble with this insn. */
3465 PATTERN (curr_insn
) = gen_rtx_USE (VOIDmode
, const0_rtx
);
3466 lra_invalidate_insn_data (curr_insn
);
3470 /* If the best alternative is with operands 1 and 2 swapped, swap
3471 them. Update the operand numbers of any reloads already
3474 if (goal_alt_swapped
)
3476 if (lra_dump_file
!= NULL
)
3477 fprintf (lra_dump_file
, " Commutative operand exchange in insn %u\n",
3478 INSN_UID (curr_insn
));
3480 /* Swap the duplicates too. */
3481 swap_operands (commutative
);
3485 #ifdef SECONDARY_MEMORY_NEEDED
3486 /* Some target macros SECONDARY_MEMORY_NEEDED (e.g. x86) are defined
3487 too conservatively. So we use the secondary memory only if there
3488 is no any alternative without reloads. */
3489 use_sec_mem_p
= false;
3491 use_sec_mem_p
= true;
3494 for (i
= 0; i
< n_operands
; i
++)
3495 if (! goal_alt_win
[i
] && ! goal_alt_match_win
[i
])
3497 use_sec_mem_p
= i
< n_operands
;
3502 rtx new_reg
, src
, dest
, rld
;
3503 enum machine_mode sec_mode
, rld_mode
;
3505 lra_assert (sec_mem_p
);
3506 lra_assert (curr_static_id
->operand
[0].type
== OP_OUT
3507 && curr_static_id
->operand
[1].type
== OP_IN
);
3508 dest
= *curr_id
->operand_loc
[0];
3509 src
= *curr_id
->operand_loc
[1];
3510 rld
= (GET_MODE_SIZE (GET_MODE (dest
)) <= GET_MODE_SIZE (GET_MODE (src
))
3512 rld_mode
= GET_MODE (rld
);
3513 #ifdef SECONDARY_MEMORY_NEEDED_MODE
3514 sec_mode
= SECONDARY_MEMORY_NEEDED_MODE (rld_mode
);
3516 sec_mode
= rld_mode
;
3518 new_reg
= lra_create_new_reg (sec_mode
, NULL_RTX
,
3519 NO_REGS
, "secondary");
3520 /* If the mode is changed, it should be wider. */
3521 lra_assert (GET_MODE_SIZE (sec_mode
) >= GET_MODE_SIZE (rld_mode
));
3522 if (sec_mode
!= rld_mode
)
3524 /* If the target says specifically to use another mode for
3525 secondary memory moves we can not reuse the original
3527 after
= emit_spill_move (false, new_reg
, dest
);
3528 lra_process_new_insns (curr_insn
, NULL_RTX
, after
,
3529 "Inserting the sec. move");
3530 /* We may have non null BEFORE here (e.g. after address
3532 push_to_sequence (before
);
3533 before
= emit_spill_move (true, new_reg
, src
);
3535 before
= get_insns ();
3537 lra_process_new_insns (curr_insn
, before
, NULL_RTX
, "Changing on");
3538 lra_set_insn_deleted (curr_insn
);
3540 else if (dest
== rld
)
3542 *curr_id
->operand_loc
[0] = new_reg
;
3543 after
= emit_spill_move (false, new_reg
, dest
);
3544 lra_process_new_insns (curr_insn
, NULL_RTX
, after
,
3545 "Inserting the sec. move");
3549 *curr_id
->operand_loc
[1] = new_reg
;
3550 /* See comments above. */
3551 push_to_sequence (before
);
3552 before
= emit_spill_move (true, new_reg
, src
);
3554 before
= get_insns ();
3556 lra_process_new_insns (curr_insn
, before
, NULL_RTX
,
3557 "Inserting the sec. move");
3559 lra_update_insn_regno_info (curr_insn
);
3564 lra_assert (goal_alt_number
>= 0);
3565 lra_set_used_insn_alternative (curr_insn
, goal_alt_number
);
3567 if (lra_dump_file
!= NULL
)
3571 fprintf (lra_dump_file
, " Choosing alt %d in insn %u:",
3572 goal_alt_number
, INSN_UID (curr_insn
));
3573 for (i
= 0; i
< n_operands
; i
++)
3575 p
= (curr_static_id
->operand_alternative
3576 [goal_alt_number
* n_operands
+ i
].constraint
);
3579 fprintf (lra_dump_file
, " (%d) ", i
);
3580 for (; *p
!= '\0' && *p
!= ',' && *p
!= '#'; p
++)
3581 fputc (*p
, lra_dump_file
);
3583 if (INSN_CODE (curr_insn
) >= 0
3584 && (p
= get_insn_name (INSN_CODE (curr_insn
))) != NULL
)
3585 fprintf (lra_dump_file
, " {%s}", p
);
3586 if (curr_id
->sp_offset
!= 0)
3587 fprintf (lra_dump_file
, " (sp_off=%" HOST_WIDE_INT_PRINT
"d)",
3588 curr_id
->sp_offset
);
3589 fprintf (lra_dump_file
, "\n");
3592 /* Right now, for any pair of operands I and J that are required to
3593 match, with J < I, goal_alt_matches[I] is J. Add I to
3594 goal_alt_matched[J]. */
3596 for (i
= 0; i
< n_operands
; i
++)
3597 if ((j
= goal_alt_matches
[i
]) >= 0)
3599 for (k
= 0; goal_alt_matched
[j
][k
] >= 0; k
++)
3601 /* We allow matching one output operand and several input
3604 || (curr_static_id
->operand
[j
].type
== OP_OUT
3605 && curr_static_id
->operand
[i
].type
== OP_IN
3606 && (curr_static_id
->operand
3607 [goal_alt_matched
[j
][0]].type
== OP_IN
)));
3608 goal_alt_matched
[j
][k
] = i
;
3609 goal_alt_matched
[j
][k
+ 1] = -1;
3612 for (i
= 0; i
< n_operands
; i
++)
3613 goal_alt_win
[i
] |= goal_alt_match_win
[i
];
3615 /* Any constants that aren't allowed and can't be reloaded into
3616 registers are here changed into memory references. */
3617 for (i
= 0; i
< n_operands
; i
++)
3618 if (goal_alt_win
[i
])
3621 enum reg_class new_class
;
3622 rtx reg
= *curr_id
->operand_loc
[i
];
3624 if (GET_CODE (reg
) == SUBREG
)
3625 reg
= SUBREG_REG (reg
);
3627 if (REG_P (reg
) && (regno
= REGNO (reg
)) >= FIRST_PSEUDO_REGISTER
)
3629 bool ok_p
= in_class_p (reg
, goal_alt
[i
], &new_class
);
3631 if (new_class
!= NO_REGS
&& get_reg_class (regno
) != new_class
)
3634 lra_change_class (regno
, new_class
, " Change to", true);
3640 const char *constraint
;
3642 rtx op
= *curr_id
->operand_loc
[i
];
3643 rtx subreg
= NULL_RTX
;
3644 enum machine_mode mode
= curr_operand_mode
[i
];
3646 if (GET_CODE (op
) == SUBREG
)
3649 op
= SUBREG_REG (op
);
3650 mode
= GET_MODE (op
);
3653 if (CONST_POOL_OK_P (mode
, op
)
3654 && ((targetm
.preferred_reload_class
3655 (op
, (enum reg_class
) goal_alt
[i
]) == NO_REGS
)
3656 || no_input_reloads_p
))
3658 rtx tem
= force_const_mem (mode
, op
);
3661 if (subreg
!= NULL_RTX
)
3662 tem
= gen_rtx_SUBREG (mode
, tem
, SUBREG_BYTE (subreg
));
3664 *curr_id
->operand_loc
[i
] = tem
;
3665 lra_update_dup (curr_id
, i
);
3666 process_address (i
, &before
, &after
);
3668 /* If the alternative accepts constant pool refs directly
3669 there will be no reload needed at all. */
3670 if (subreg
!= NULL_RTX
)
3672 /* Skip alternatives before the one requested. */
3673 constraint
= (curr_static_id
->operand_alternative
3674 [goal_alt_number
* n_operands
+ i
].constraint
);
3676 (c
= *constraint
) && c
!= ',' && c
!= '#';
3677 constraint
+= CONSTRAINT_LEN (c
, constraint
))
3679 if (c
== TARGET_MEM_CONSTRAINT
|| c
== 'o')
3681 #ifdef EXTRA_CONSTRAINT_STR
3682 if (EXTRA_MEMORY_CONSTRAINT (c
, constraint
)
3683 && satisfies_memory_constraint_p (tem
, constraint
))
3687 if (c
== '\0' || c
== ',' || c
== '#')
3690 goal_alt_win
[i
] = true;
3694 for (i
= 0; i
< n_operands
; i
++)
3697 bool optional_p
= false;
3699 rtx op
= *curr_id
->operand_loc
[i
];
3701 if (goal_alt_win
[i
])
3703 if (goal_alt
[i
] == NO_REGS
3705 /* When we assign NO_REGS it means that we will not
3706 assign a hard register to the scratch pseudo by
3707 assigment pass and the scratch pseudo will be
3708 spilled. Spilled scratch pseudos are transformed
3709 back to scratches at the LRA end. */
3710 && lra_former_scratch_operand_p (curr_insn
, i
))
3712 int regno
= REGNO (op
);
3713 lra_change_class (regno
, NO_REGS
, " Change to", true);
3714 if (lra_get_regno_hard_regno (regno
) >= 0)
3715 /* We don't have to mark all insn affected by the
3716 spilled pseudo as there is only one such insn, the
3718 reg_renumber
[regno
] = -1;
3720 /* We can do an optional reload. If the pseudo got a hard
3721 reg, we might improve the code through inheritance. If
3722 it does not get a hard register we coalesce memory/memory
3723 moves later. Ignore move insns to avoid cycling. */
3725 && lra_undo_inheritance_iter
< LRA_MAX_INHERITANCE_PASSES
3726 && goal_alt
[i
] != NO_REGS
&& REG_P (op
)
3727 && (regno
= REGNO (op
)) >= FIRST_PSEUDO_REGISTER
3728 && regno
< new_regno_start
3729 && ! lra_former_scratch_p (regno
)
3730 && reg_renumber
[regno
] < 0
3731 && (curr_insn_set
== NULL_RTX
3732 || !((REG_P (SET_SRC (curr_insn_set
))
3733 || MEM_P (SET_SRC (curr_insn_set
))
3734 || GET_CODE (SET_SRC (curr_insn_set
)) == SUBREG
)
3735 && (REG_P (SET_DEST (curr_insn_set
))
3736 || MEM_P (SET_DEST (curr_insn_set
))
3737 || GET_CODE (SET_DEST (curr_insn_set
)) == SUBREG
))))
3743 /* Operands that match previous ones have already been handled. */
3744 if (goal_alt_matches
[i
] >= 0)
3747 /* We should not have an operand with a non-offsettable address
3748 appearing where an offsettable address will do. It also may
3749 be a case when the address should be special in other words
3750 not a general one (e.g. it needs no index reg). */
3751 if (goal_alt_matched
[i
][0] == -1 && goal_alt_offmemok
[i
] && MEM_P (op
))
3753 enum reg_class rclass
;
3754 rtx
*loc
= &XEXP (op
, 0);
3755 enum rtx_code code
= GET_CODE (*loc
);
3757 push_to_sequence (before
);
3758 rclass
= base_reg_class (GET_MODE (op
), MEM_ADDR_SPACE (op
),
3760 if (GET_RTX_CLASS (code
) == RTX_AUTOINC
)
3761 new_reg
= emit_inc (rclass
, *loc
, *loc
,
3762 /* This value does not matter for MODIFY. */
3763 GET_MODE_SIZE (GET_MODE (op
)));
3764 else if (get_reload_reg (OP_IN
, Pmode
, *loc
, rclass
, FALSE
,
3765 "offsetable address", &new_reg
))
3766 lra_emit_move (new_reg
, *loc
);
3767 before
= get_insns ();
3770 lra_update_dup (curr_id
, i
);
3772 else if (goal_alt_matched
[i
][0] == -1)
3774 enum machine_mode mode
;
3776 int hard_regno
, byte
;
3777 enum op_type type
= curr_static_id
->operand
[i
].type
;
3779 loc
= curr_id
->operand_loc
[i
];
3780 mode
= curr_operand_mode
[i
];
3781 if (GET_CODE (*loc
) == SUBREG
)
3783 reg
= SUBREG_REG (*loc
);
3784 byte
= SUBREG_BYTE (*loc
);
3786 /* Strict_low_part requires reload the register not
3787 the sub-register. */
3788 && (curr_static_id
->operand
[i
].strict_low
3789 || (GET_MODE_SIZE (mode
)
3790 <= GET_MODE_SIZE (GET_MODE (reg
))
3792 = get_try_hard_regno (REGNO (reg
))) >= 0
3793 && (simplify_subreg_regno
3795 GET_MODE (reg
), byte
, mode
) < 0)
3796 && (goal_alt
[i
] == NO_REGS
3797 || (simplify_subreg_regno
3798 (ira_class_hard_regs
[goal_alt
[i
]][0],
3799 GET_MODE (reg
), byte
, mode
) >= 0)))))
3802 loc
= &SUBREG_REG (*loc
);
3803 mode
= GET_MODE (*loc
);
3807 if (get_reload_reg (type
, mode
, old
, goal_alt
[i
],
3808 loc
!= curr_id
->operand_loc
[i
], "", &new_reg
)
3811 push_to_sequence (before
);
3812 lra_emit_move (new_reg
, old
);
3813 before
= get_insns ();
3818 && find_reg_note (curr_insn
, REG_UNUSED
, old
) == NULL_RTX
)
3821 lra_emit_move (type
== OP_INOUT
? copy_rtx (old
) : old
, new_reg
);
3823 after
= get_insns ();
3827 for (j
= 0; j
< goal_alt_dont_inherit_ops_num
; j
++)
3828 if (goal_alt_dont_inherit_ops
[j
] == i
)
3830 lra_set_regno_unique_value (REGNO (new_reg
));
3833 lra_update_dup (curr_id
, i
);
3835 else if (curr_static_id
->operand
[i
].type
== OP_IN
3836 && (curr_static_id
->operand
[goal_alt_matched
[i
][0]].type
3839 /* generate reloads for input and matched outputs. */
3840 match_inputs
[0] = i
;
3841 match_inputs
[1] = -1;
3842 match_reload (goal_alt_matched
[i
][0], match_inputs
,
3843 goal_alt
[i
], &before
, &after
);
3845 else if (curr_static_id
->operand
[i
].type
== OP_OUT
3846 && (curr_static_id
->operand
[goal_alt_matched
[i
][0]].type
3848 /* Generate reloads for output and matched inputs. */
3849 match_reload (i
, goal_alt_matched
[i
], goal_alt
[i
], &before
, &after
);
3850 else if (curr_static_id
->operand
[i
].type
== OP_IN
3851 && (curr_static_id
->operand
[goal_alt_matched
[i
][0]].type
3854 /* Generate reloads for matched inputs. */
3855 match_inputs
[0] = i
;
3856 for (j
= 0; (k
= goal_alt_matched
[i
][j
]) >= 0; j
++)
3857 match_inputs
[j
+ 1] = k
;
3858 match_inputs
[j
+ 1] = -1;
3859 match_reload (-1, match_inputs
, goal_alt
[i
], &before
, &after
);
3862 /* We must generate code in any case when function
3863 process_alt_operands decides that it is possible. */
3867 lra_assert (REG_P (op
));
3869 op
= *curr_id
->operand_loc
[i
]; /* Substitution. */
3870 if (GET_CODE (op
) == SUBREG
)
3871 op
= SUBREG_REG (op
);
3872 gcc_assert (REG_P (op
) && (int) REGNO (op
) >= new_regno_start
);
3873 bitmap_set_bit (&lra_optional_reload_pseudos
, REGNO (op
));
3874 lra_reg_info
[REGNO (op
)].restore_regno
= regno
;
3875 if (lra_dump_file
!= NULL
)
3876 fprintf (lra_dump_file
,
3877 " Making reload reg %d for reg %d optional\n",
3881 if (before
!= NULL_RTX
|| after
!= NULL_RTX
3882 || max_regno_before
!= max_reg_num ())
3886 lra_update_operator_dups (curr_id
);
3887 /* Something changes -- process the insn. */
3888 lra_update_insn_regno_info (curr_insn
);
3890 lra_process_new_insns (curr_insn
, before
, after
, "Inserting insn reload");
3894 /* Return true if X is in LIST. */
3896 in_list_p (rtx x
, rtx list
)
3898 for (; list
!= NULL_RTX
; list
= XEXP (list
, 1))
3899 if (XEXP (list
, 0) == x
)
3904 /* Return true if X contains an allocatable hard register (if
3905 HARD_REG_P) or a (spilled if SPILLED_P) pseudo. */
3907 contains_reg_p (rtx x
, bool hard_reg_p
, bool spilled_p
)
3913 code
= GET_CODE (x
);
3916 int regno
= REGNO (x
);
3917 HARD_REG_SET alloc_regs
;
3921 if (regno
>= FIRST_PSEUDO_REGISTER
)
3922 regno
= lra_get_regno_hard_regno (regno
);
3925 COMPL_HARD_REG_SET (alloc_regs
, lra_no_alloc_regs
);
3926 return overlaps_hard_reg_set_p (alloc_regs
, GET_MODE (x
), regno
);
3930 if (regno
< FIRST_PSEUDO_REGISTER
)
3934 return lra_get_regno_hard_regno (regno
) < 0;
3937 fmt
= GET_RTX_FORMAT (code
);
3938 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
3942 if (contains_reg_p (XEXP (x
, i
), hard_reg_p
, spilled_p
))
3945 else if (fmt
[i
] == 'E')
3947 for (j
= XVECLEN (x
, i
) - 1; j
>= 0; j
--)
3948 if (contains_reg_p (XVECEXP (x
, i
, j
), hard_reg_p
, spilled_p
))
3955 /* Process all regs in location *LOC and change them on equivalent
3956 substitution. Return true if any change was done. */
3958 loc_equivalence_change_p (rtx
*loc
)
3960 rtx subst
, reg
, x
= *loc
;
3961 bool result
= false;
3962 enum rtx_code code
= GET_CODE (x
);
3968 reg
= SUBREG_REG (x
);
3969 if ((subst
= get_equiv_with_elimination (reg
, curr_insn
)) != reg
3970 && GET_MODE (subst
) == VOIDmode
)
3972 /* We cannot reload debug location. Simplify subreg here
3973 while we know the inner mode. */
3974 *loc
= simplify_gen_subreg (GET_MODE (x
), subst
,
3975 GET_MODE (reg
), SUBREG_BYTE (x
));
3979 if (code
== REG
&& (subst
= get_equiv_with_elimination (x
, curr_insn
)) != x
)
3985 /* Scan all the operand sub-expressions. */
3986 fmt
= GET_RTX_FORMAT (code
);
3987 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
3990 result
= loc_equivalence_change_p (&XEXP (x
, i
)) || result
;
3991 else if (fmt
[i
] == 'E')
3992 for (j
= XVECLEN (x
, i
) - 1; j
>= 0; j
--)
3994 = loc_equivalence_change_p (&XVECEXP (x
, i
, j
)) || result
;
3999 /* Similar to loc_equivalence_change_p, but for use as
4000 simplify_replace_fn_rtx callback. DATA is insn for which the
4001 elimination is done. If it null we don't do the elimination. */
4003 loc_equivalence_callback (rtx loc
, const_rtx
, void *data
)
4008 rtx subst
= (data
== NULL
4009 ? get_equiv (loc
) : get_equiv_with_elimination (loc
, (rtx
) data
));
4016 /* Maximum number of generated reload insns per an insn. It is for
4017 preventing this pass cycling in a bug case. */
4018 #define MAX_RELOAD_INSNS_NUMBER LRA_MAX_INSN_RELOADS
4020 /* The current iteration number of this LRA pass. */
4021 int lra_constraint_iter
;
4023 /* True if we substituted equiv which needs checking register
4024 allocation correctness because the equivalent value contains
4025 allocatable hard registers or when we restore multi-register
4027 bool lra_risky_transformations_p
;
4029 /* Return true if REGNO is referenced in more than one block. */
4031 multi_block_pseudo_p (int regno
)
4033 basic_block bb
= NULL
;
4037 if (regno
< FIRST_PSEUDO_REGISTER
)
4040 EXECUTE_IF_SET_IN_BITMAP (&lra_reg_info
[regno
].insn_bitmap
, 0, uid
, bi
)
4042 bb
= BLOCK_FOR_INSN (lra_insn_recog_data
[uid
]->insn
);
4043 else if (BLOCK_FOR_INSN (lra_insn_recog_data
[uid
]->insn
) != bb
)
4048 /* Return true if LIST contains a deleted insn. */
4050 contains_deleted_insn_p (rtx list
)
4052 for (; list
!= NULL_RTX
; list
= XEXP (list
, 1))
4053 if (NOTE_P (XEXP (list
, 0))
4054 && NOTE_KIND (XEXP (list
, 0)) == NOTE_INSN_DELETED
)
4059 /* Return true if X contains a pseudo dying in INSN. */
4061 dead_pseudo_p (rtx x
, rtx insn
)
4068 return (insn
!= NULL_RTX
4069 && find_regno_note (insn
, REG_DEAD
, REGNO (x
)) != NULL_RTX
);
4070 code
= GET_CODE (x
);
4071 fmt
= GET_RTX_FORMAT (code
);
4072 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
4076 if (dead_pseudo_p (XEXP (x
, i
), insn
))
4079 else if (fmt
[i
] == 'E')
4081 for (j
= XVECLEN (x
, i
) - 1; j
>= 0; j
--)
4082 if (dead_pseudo_p (XVECEXP (x
, i
, j
), insn
))
4089 /* Return true if INSN contains a dying pseudo in INSN right hand
4092 insn_rhs_dead_pseudo_p (rtx insn
)
4094 rtx set
= single_set (insn
);
4096 gcc_assert (set
!= NULL
);
4097 return dead_pseudo_p (SET_SRC (set
), insn
);
4100 /* Return true if any init insn of REGNO contains a dying pseudo in
4101 insn right hand side. */
4103 init_insn_rhs_dead_pseudo_p (int regno
)
4105 rtx insns
= ira_reg_equiv
[regno
].init_insns
;
4110 return insn_rhs_dead_pseudo_p (insns
);
4111 for (; insns
!= NULL_RTX
; insns
= XEXP (insns
, 1))
4112 if (insn_rhs_dead_pseudo_p (XEXP (insns
, 0)))
4117 /* Return TRUE if REGNO has a reverse equivalence. The equivalence is
4118 reverse only if we have one init insn with given REGNO as a
4121 reverse_equiv_p (int regno
)
4125 if ((insns
= ira_reg_equiv
[regno
].init_insns
) == NULL_RTX
)
4127 if (! INSN_P (XEXP (insns
, 0))
4128 || XEXP (insns
, 1) != NULL_RTX
)
4130 if ((set
= single_set (XEXP (insns
, 0))) == NULL_RTX
)
4132 return REG_P (SET_SRC (set
)) && (int) REGNO (SET_SRC (set
)) == regno
;
4135 /* Return TRUE if REGNO was reloaded in an equivalence init insn. We
4136 call this function only for non-reverse equivalence. */
4138 contains_reloaded_insn_p (int regno
)
4141 rtx list
= ira_reg_equiv
[regno
].init_insns
;
4143 for (; list
!= NULL_RTX
; list
= XEXP (list
, 1))
4144 if ((set
= single_set (XEXP (list
, 0))) == NULL_RTX
4145 || ! REG_P (SET_DEST (set
))
4146 || (int) REGNO (SET_DEST (set
)) != regno
)
4151 /* Entry function of LRA constraint pass. Return true if the
4152 constraint pass did change the code. */
4154 lra_constraints (bool first_p
)
4157 int i
, hard_regno
, new_insns_num
;
4158 unsigned int min_len
, new_min_len
, uid
;
4159 rtx set
, x
, reg
, dest_reg
;
4160 basic_block last_bb
;
4161 bitmap_head equiv_insn_bitmap
;
4164 lra_constraint_iter
++;
4165 if (lra_dump_file
!= NULL
)
4166 fprintf (lra_dump_file
, "\n********** Local #%d: **********\n\n",
4167 lra_constraint_iter
);
4169 lra_risky_transformations_p
= false;
4170 new_insn_uid_start
= get_max_uid ();
4171 new_regno_start
= first_p
? lra_constraint_new_regno_start
: max_reg_num ();
4172 /* Mark used hard regs for target stack size calulations. */
4173 for (i
= FIRST_PSEUDO_REGISTER
; i
< new_regno_start
; i
++)
4174 if (lra_reg_info
[i
].nrefs
!= 0
4175 && (hard_regno
= lra_get_regno_hard_regno (i
)) >= 0)
4179 nregs
= hard_regno_nregs
[hard_regno
][lra_reg_info
[i
].biggest_mode
];
4180 for (j
= 0; j
< nregs
; j
++)
4181 df_set_regs_ever_live (hard_regno
+ j
, true);
4183 /* Do elimination before the equivalence processing as we can spill
4184 some pseudos during elimination. */
4185 lra_eliminate (false, first_p
);
4186 bitmap_initialize (&equiv_insn_bitmap
, ®_obstack
);
4187 for (i
= FIRST_PSEUDO_REGISTER
; i
< new_regno_start
; i
++)
4188 if (lra_reg_info
[i
].nrefs
!= 0)
4190 ira_reg_equiv
[i
].profitable_p
= true;
4191 reg
= regno_reg_rtx
[i
];
4192 if (lra_get_regno_hard_regno (i
) < 0 && (x
= get_equiv (reg
)) != reg
)
4194 bool pseudo_p
= contains_reg_p (x
, false, false);
4196 /* After RTL transformation, we can not guarantee that
4197 pseudo in the substitution was not reloaded which might
4198 make equivalence invalid. For example, in reverse
4205 the memory address register was reloaded before the 2nd
4207 if ((! first_p
&& pseudo_p
)
4208 /* We don't use DF for compilation speed sake. So it
4209 is problematic to update live info when we use an
4210 equivalence containing pseudos in more than one
4212 || (pseudo_p
&& multi_block_pseudo_p (i
))
4213 /* If an init insn was deleted for some reason, cancel
4214 the equiv. We could update the equiv insns after
4215 transformations including an equiv insn deletion
4216 but it is not worthy as such cases are extremely
4218 || contains_deleted_insn_p (ira_reg_equiv
[i
].init_insns
)
4219 /* If it is not a reverse equivalence, we check that a
4220 pseudo in rhs of the init insn is not dying in the
4221 insn. Otherwise, the live info at the beginning of
4222 the corresponding BB might be wrong after we
4223 removed the insn. When the equiv can be a
4224 constant, the right hand side of the init insn can
4226 || (! reverse_equiv_p (i
)
4227 && (init_insn_rhs_dead_pseudo_p (i
)
4228 /* If we reloaded the pseudo in an equivalence
4229 init insn, we can not remove the equiv init
4230 insns and the init insns might write into
4231 const memory in this case. */
4232 || contains_reloaded_insn_p (i
)))
4233 /* Prevent access beyond equivalent memory for
4234 paradoxical subregs. */
4236 && (GET_MODE_SIZE (lra_reg_info
[i
].biggest_mode
)
4237 > GET_MODE_SIZE (GET_MODE (x
)))))
4238 ira_reg_equiv
[i
].defined_p
= false;
4239 if (contains_reg_p (x
, false, true))
4240 ira_reg_equiv
[i
].profitable_p
= false;
4241 if (get_equiv (reg
) != reg
)
4242 bitmap_ior_into (&equiv_insn_bitmap
, &lra_reg_info
[i
].insn_bitmap
);
4245 for (i
= FIRST_PSEUDO_REGISTER
; i
< new_regno_start
; i
++)
4247 /* We should add all insns containing pseudos which should be
4248 substituted by their equivalences. */
4249 EXECUTE_IF_SET_IN_BITMAP (&equiv_insn_bitmap
, 0, uid
, bi
)
4250 lra_push_insn_by_uid (uid
);
4251 min_len
= lra_insn_stack_length ();
4255 while ((new_min_len
= lra_insn_stack_length ()) != 0)
4257 curr_insn
= lra_pop_insn ();
4259 curr_bb
= BLOCK_FOR_INSN (curr_insn
);
4260 if (curr_bb
!= last_bb
)
4263 bb_reload_num
= lra_curr_reload_num
;
4265 if (min_len
> new_min_len
)
4267 min_len
= new_min_len
;
4270 if (new_insns_num
> MAX_RELOAD_INSNS_NUMBER
)
4272 ("Max. number of generated reload insns per insn is achieved (%d)\n",
4273 MAX_RELOAD_INSNS_NUMBER
);
4275 if (DEBUG_INSN_P (curr_insn
))
4277 /* We need to check equivalence in debug insn and change
4278 pseudo to the equivalent value if necessary. */
4279 curr_id
= lra_get_insn_recog_data (curr_insn
);
4280 if (bitmap_bit_p (&equiv_insn_bitmap
, INSN_UID (curr_insn
)))
4282 rtx old
= *curr_id
->operand_loc
[0];
4283 *curr_id
->operand_loc
[0]
4284 = simplify_replace_fn_rtx (old
, NULL_RTX
,
4285 loc_equivalence_callback
, curr_insn
);
4286 if (old
!= *curr_id
->operand_loc
[0])
4288 lra_update_insn_regno_info (curr_insn
);
4293 else if (INSN_P (curr_insn
))
4295 if ((set
= single_set (curr_insn
)) != NULL_RTX
)
4297 dest_reg
= SET_DEST (set
);
4298 /* The equivalence pseudo could be set up as SUBREG in a
4299 case when it is a call restore insn in a mode
4300 different from the pseudo mode. */
4301 if (GET_CODE (dest_reg
) == SUBREG
)
4302 dest_reg
= SUBREG_REG (dest_reg
);
4303 if ((REG_P (dest_reg
)
4304 && (x
= get_equiv (dest_reg
)) != dest_reg
4305 /* Remove insns which set up a pseudo whose value
4306 can not be changed. Such insns might be not in
4307 init_insns because we don't update equiv data
4308 during insn transformations.
4310 As an example, let suppose that a pseudo got
4311 hard register and on the 1st pass was not
4312 changed to equivalent constant. We generate an
4313 additional insn setting up the pseudo because of
4314 secondary memory movement. Then the pseudo is
4315 spilled and we use the equiv constant. In this
4316 case we should remove the additional insn and
4317 this insn is not init_insns list. */
4318 && (! MEM_P (x
) || MEM_READONLY_P (x
)
4319 /* Check that this is actually an insn setting
4320 up the equivalence. */
4321 || in_list_p (curr_insn
,
4323 [REGNO (dest_reg
)].init_insns
)))
4324 || (((x
= get_equiv (SET_SRC (set
))) != SET_SRC (set
))
4325 && in_list_p (curr_insn
,
4327 [REGNO (SET_SRC (set
))].init_insns
)))
4329 /* This is equiv init insn of pseudo which did not get a
4330 hard register -- remove the insn. */
4331 if (lra_dump_file
!= NULL
)
4333 fprintf (lra_dump_file
,
4334 " Removing equiv init insn %i (freq=%d)\n",
4335 INSN_UID (curr_insn
),
4336 REG_FREQ_FROM_BB (BLOCK_FOR_INSN (curr_insn
)));
4337 dump_insn_slim (lra_dump_file
, curr_insn
);
4339 if (contains_reg_p (x
, true, false))
4340 lra_risky_transformations_p
= true;
4341 lra_set_insn_deleted (curr_insn
);
4345 curr_id
= lra_get_insn_recog_data (curr_insn
);
4346 curr_static_id
= curr_id
->insn_static_data
;
4347 init_curr_insn_input_reloads ();
4348 init_curr_operand_mode ();
4349 if (curr_insn_transform ())
4351 /* Check non-transformed insns too for equiv change as USE
4352 or CLOBBER don't need reloads but can contain pseudos
4353 being changed on their equivalences. */
4354 else if (bitmap_bit_p (&equiv_insn_bitmap
, INSN_UID (curr_insn
))
4355 && loc_equivalence_change_p (&PATTERN (curr_insn
)))
4357 lra_update_insn_regno_info (curr_insn
);
4362 bitmap_clear (&equiv_insn_bitmap
);
4363 /* If we used a new hard regno, changed_p should be true because the
4364 hard reg is assigned to a new pseudo. */
4365 #ifdef ENABLE_CHECKING
4368 for (i
= FIRST_PSEUDO_REGISTER
; i
< new_regno_start
; i
++)
4369 if (lra_reg_info
[i
].nrefs
!= 0
4370 && (hard_regno
= lra_get_regno_hard_regno (i
)) >= 0)
4372 int j
, nregs
= hard_regno_nregs
[hard_regno
][PSEUDO_REGNO_MODE (i
)];
4374 for (j
= 0; j
< nregs
; j
++)
4375 lra_assert (df_regs_ever_live_p (hard_regno
+ j
));
4382 /* Initiate the LRA constraint pass. It is done once per
4385 lra_constraints_init (void)
4389 /* Finalize the LRA constraint pass. It is done once per
4392 lra_constraints_finish (void)
4398 /* This page contains code to do inheritance/split
4401 /* Number of reloads passed so far in current EBB. */
4402 static int reloads_num
;
4404 /* Number of calls passed so far in current EBB. */
4405 static int calls_num
;
4407 /* Current reload pseudo check for validity of elements in
4409 static int curr_usage_insns_check
;
4411 /* Info about last usage of registers in EBB to do inheritance/split
4412 transformation. Inheritance transformation is done from a spilled
4413 pseudo and split transformations from a hard register or a pseudo
4414 assigned to a hard register. */
4417 /* If the value is equal to CURR_USAGE_INSNS_CHECK, then the member
4418 value INSNS is valid. The insns is chain of optional debug insns
4419 and a finishing non-debug insn using the corresponding reg. The
4420 value is also used to mark the registers which are set up in the
4421 current insn. The negated insn uid is used for this. */
4423 /* Value of global reloads_num at the last insn in INSNS. */
4425 /* Value of global reloads_nums at the last insn in INSNS. */
4427 /* It can be true only for splitting. And it means that the restore
4428 insn should be put after insn given by the following member. */
4430 /* Next insns in the current EBB which use the original reg and the
4431 original reg value is not changed between the current insn and
4432 the next insns. In order words, e.g. for inheritance, if we need
4433 to use the original reg value again in the next insns we can try
4434 to use the value in a hard register from a reload insn of the
4439 /* Map: regno -> corresponding pseudo usage insns. */
4440 static struct usage_insns
*usage_insns
;
4443 setup_next_usage_insn (int regno
, rtx insn
, int reloads_num
, bool after_p
)
4445 usage_insns
[regno
].check
= curr_usage_insns_check
;
4446 usage_insns
[regno
].insns
= insn
;
4447 usage_insns
[regno
].reloads_num
= reloads_num
;
4448 usage_insns
[regno
].calls_num
= calls_num
;
4449 usage_insns
[regno
].after_p
= after_p
;
4452 /* The function is used to form list REGNO usages which consists of
4453 optional debug insns finished by a non-debug insn using REGNO.
4454 RELOADS_NUM is current number of reload insns processed so far. */
4456 add_next_usage_insn (int regno
, rtx insn
, int reloads_num
)
4458 rtx next_usage_insns
;
4460 if (usage_insns
[regno
].check
== curr_usage_insns_check
4461 && (next_usage_insns
= usage_insns
[regno
].insns
) != NULL_RTX
4462 && DEBUG_INSN_P (insn
))
4464 /* Check that we did not add the debug insn yet. */
4465 if (next_usage_insns
!= insn
4466 && (GET_CODE (next_usage_insns
) != INSN_LIST
4467 || XEXP (next_usage_insns
, 0) != insn
))
4468 usage_insns
[regno
].insns
= gen_rtx_INSN_LIST (VOIDmode
, insn
,
4471 else if (NONDEBUG_INSN_P (insn
))
4472 setup_next_usage_insn (regno
, insn
, reloads_num
, false);
4474 usage_insns
[regno
].check
= 0;
4477 /* Replace all references to register OLD_REGNO in *LOC with pseudo
4478 register NEW_REG. Return true if any change was made. */
4480 substitute_pseudo (rtx
*loc
, int old_regno
, rtx new_reg
)
4483 bool result
= false;
4491 code
= GET_CODE (x
);
4492 if (code
== REG
&& (int) REGNO (x
) == old_regno
)
4494 enum machine_mode mode
= GET_MODE (*loc
);
4495 enum machine_mode inner_mode
= GET_MODE (new_reg
);
4497 if (mode
!= inner_mode
)
4499 if (GET_MODE_SIZE (mode
) >= GET_MODE_SIZE (inner_mode
)
4500 || ! SCALAR_INT_MODE_P (inner_mode
))
4501 new_reg
= gen_rtx_SUBREG (mode
, new_reg
, 0);
4503 new_reg
= gen_lowpart_SUBREG (mode
, new_reg
);
4509 /* Scan all the operand sub-expressions. */
4510 fmt
= GET_RTX_FORMAT (code
);
4511 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
4515 if (substitute_pseudo (&XEXP (x
, i
), old_regno
, new_reg
))
4518 else if (fmt
[i
] == 'E')
4520 for (j
= XVECLEN (x
, i
) - 1; j
>= 0; j
--)
4521 if (substitute_pseudo (&XVECEXP (x
, i
, j
), old_regno
, new_reg
))
4528 /* Return first non-debug insn in list USAGE_INSNS. */
4530 skip_usage_debug_insns (rtx usage_insns
)
4534 /* Skip debug insns. */
4535 for (insn
= usage_insns
;
4536 insn
!= NULL_RTX
&& GET_CODE (insn
) == INSN_LIST
;
4537 insn
= XEXP (insn
, 1))
4542 /* Return true if we need secondary memory moves for insn in
4543 USAGE_INSNS after inserting inherited pseudo of class INHER_CL
4546 check_secondary_memory_needed_p (enum reg_class inher_cl ATTRIBUTE_UNUSED
,
4547 rtx usage_insns ATTRIBUTE_UNUSED
)
4549 #ifndef SECONDARY_MEMORY_NEEDED
4552 rtx insn
, set
, dest
;
4555 if (inher_cl
== ALL_REGS
4556 || (insn
= skip_usage_debug_insns (usage_insns
)) == NULL_RTX
)
4558 lra_assert (INSN_P (insn
));
4559 if ((set
= single_set (insn
)) == NULL_RTX
|| ! REG_P (SET_DEST (set
)))
4561 dest
= SET_DEST (set
);
4564 lra_assert (inher_cl
!= NO_REGS
);
4565 cl
= get_reg_class (REGNO (dest
));
4566 return (cl
!= NO_REGS
&& cl
!= ALL_REGS
4567 && SECONDARY_MEMORY_NEEDED (inher_cl
, cl
, GET_MODE (dest
)));
4571 /* Registers involved in inheritance/split in the current EBB
4572 (inheritance/split pseudos and original registers). */
4573 static bitmap_head check_only_regs
;
4575 /* Do inheritance transformations for insn INSN, which defines (if
4576 DEF_P) or uses ORIGINAL_REGNO. NEXT_USAGE_INSNS specifies which
4577 instruction in the EBB next uses ORIGINAL_REGNO; it has the same
4578 form as the "insns" field of usage_insns. Return true if we
4579 succeed in such transformation.
4581 The transformations look like:
4584 ... p <- i (new insn)
4586 <- ... p ... <- ... i ...
4588 ... i <- p (new insn)
4589 <- ... p ... <- ... i ...
4591 <- ... p ... <- ... i ...
4592 where p is a spilled original pseudo and i is a new inheritance pseudo.
4595 The inheritance pseudo has the smallest class of two classes CL and
4596 class of ORIGINAL REGNO. */
4598 inherit_reload_reg (bool def_p
, int original_regno
,
4599 enum reg_class cl
, rtx insn
, rtx next_usage_insns
)
4601 if (optimize_function_for_size_p (cfun
))
4604 enum reg_class rclass
= lra_get_allocno_class (original_regno
);
4605 rtx original_reg
= regno_reg_rtx
[original_regno
];
4606 rtx new_reg
, new_insns
, usage_insn
;
4608 lra_assert (! usage_insns
[original_regno
].after_p
);
4609 if (lra_dump_file
!= NULL
)
4610 fprintf (lra_dump_file
,
4611 " <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n");
4612 if (! ira_reg_classes_intersect_p
[cl
][rclass
])
4614 if (lra_dump_file
!= NULL
)
4616 fprintf (lra_dump_file
,
4617 " Rejecting inheritance for %d "
4618 "because of disjoint classes %s and %s\n",
4619 original_regno
, reg_class_names
[cl
],
4620 reg_class_names
[rclass
]);
4621 fprintf (lra_dump_file
,
4622 " >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n");
4626 if ((ira_class_subset_p
[cl
][rclass
] && cl
!= rclass
)
4627 /* We don't use a subset of two classes because it can be
4628 NO_REGS. This transformation is still profitable in most
4629 cases even if the classes are not intersected as register
4630 move is probably cheaper than a memory load. */
4631 || ira_class_hard_regs_num
[cl
] < ira_class_hard_regs_num
[rclass
])
4633 if (lra_dump_file
!= NULL
)
4634 fprintf (lra_dump_file
, " Use smallest class of %s and %s\n",
4635 reg_class_names
[cl
], reg_class_names
[rclass
]);
4639 if (check_secondary_memory_needed_p (rclass
, next_usage_insns
))
4641 /* Reject inheritance resulting in secondary memory moves.
4642 Otherwise, there is a danger in LRA cycling. Also such
4643 transformation will be unprofitable. */
4644 if (lra_dump_file
!= NULL
)
4646 rtx insn
= skip_usage_debug_insns (next_usage_insns
);
4647 rtx set
= single_set (insn
);
4649 lra_assert (set
!= NULL_RTX
);
4651 rtx dest
= SET_DEST (set
);
4653 lra_assert (REG_P (dest
));
4654 fprintf (lra_dump_file
,
4655 " Rejecting inheritance for insn %d(%s)<-%d(%s) "
4656 "as secondary mem is needed\n",
4657 REGNO (dest
), reg_class_names
[get_reg_class (REGNO (dest
))],
4658 original_regno
, reg_class_names
[rclass
]);
4659 fprintf (lra_dump_file
,
4660 " >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n");
4664 new_reg
= lra_create_new_reg (GET_MODE (original_reg
), original_reg
,
4665 rclass
, "inheritance");
4668 lra_emit_move (original_reg
, new_reg
);
4670 lra_emit_move (new_reg
, original_reg
);
4671 new_insns
= get_insns ();
4673 if (NEXT_INSN (new_insns
) != NULL_RTX
)
4675 if (lra_dump_file
!= NULL
)
4677 fprintf (lra_dump_file
,
4678 " Rejecting inheritance %d->%d "
4679 "as it results in 2 or more insns:\n",
4680 original_regno
, REGNO (new_reg
));
4681 dump_rtl_slim (lra_dump_file
, new_insns
, NULL_RTX
, -1, 0);
4682 fprintf (lra_dump_file
,
4683 " >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n");
4687 substitute_pseudo (&insn
, original_regno
, new_reg
);
4688 lra_update_insn_regno_info (insn
);
4690 /* We now have a new usage insn for original regno. */
4691 setup_next_usage_insn (original_regno
, new_insns
, reloads_num
, false);
4692 if (lra_dump_file
!= NULL
)
4693 fprintf (lra_dump_file
, " Original reg change %d->%d (bb%d):\n",
4694 original_regno
, REGNO (new_reg
), BLOCK_FOR_INSN (insn
)->index
);
4695 lra_reg_info
[REGNO (new_reg
)].restore_regno
= original_regno
;
4696 bitmap_set_bit (&check_only_regs
, REGNO (new_reg
));
4697 bitmap_set_bit (&check_only_regs
, original_regno
);
4698 bitmap_set_bit (&lra_inheritance_pseudos
, REGNO (new_reg
));
4700 lra_process_new_insns (insn
, NULL_RTX
, new_insns
,
4701 "Add original<-inheritance");
4703 lra_process_new_insns (insn
, new_insns
, NULL_RTX
,
4704 "Add inheritance<-original");
4705 while (next_usage_insns
!= NULL_RTX
)
4707 if (GET_CODE (next_usage_insns
) != INSN_LIST
)
4709 usage_insn
= next_usage_insns
;
4710 lra_assert (NONDEBUG_INSN_P (usage_insn
));
4711 next_usage_insns
= NULL
;
4715 usage_insn
= XEXP (next_usage_insns
, 0);
4716 lra_assert (DEBUG_INSN_P (usage_insn
));
4717 next_usage_insns
= XEXP (next_usage_insns
, 1);
4719 substitute_pseudo (&usage_insn
, original_regno
, new_reg
);
4720 lra_update_insn_regno_info (usage_insn
);
4721 if (lra_dump_file
!= NULL
)
4723 fprintf (lra_dump_file
,
4724 " Inheritance reuse change %d->%d (bb%d):\n",
4725 original_regno
, REGNO (new_reg
),
4726 BLOCK_FOR_INSN (usage_insn
)->index
);
4727 dump_insn_slim (lra_dump_file
, usage_insn
);
4730 if (lra_dump_file
!= NULL
)
4731 fprintf (lra_dump_file
,
4732 " >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n");
4736 /* Return true if we need a caller save/restore for pseudo REGNO which
4737 was assigned to a hard register. */
4739 need_for_call_save_p (int regno
)
4741 lra_assert (regno
>= FIRST_PSEUDO_REGISTER
&& reg_renumber
[regno
] >= 0);
4742 return (usage_insns
[regno
].calls_num
< calls_num
4743 && (overlaps_hard_reg_set_p
4745 PSEUDO_REGNO_MODE (regno
), reg_renumber
[regno
])
4746 || HARD_REGNO_CALL_PART_CLOBBERED (reg_renumber
[regno
],
4747 PSEUDO_REGNO_MODE (regno
))));
4750 /* Global registers occurring in the current EBB. */
4751 static bitmap_head ebb_global_regs
;
4753 /* Return true if we need a split for hard register REGNO or pseudo
4754 REGNO which was assigned to a hard register.
4755 POTENTIAL_RELOAD_HARD_REGS contains hard registers which might be
4756 used for reloads since the EBB end. It is an approximation of the
4757 used hard registers in the split range. The exact value would
4758 require expensive calculations. If we were aggressive with
4759 splitting because of the approximation, the split pseudo will save
4760 the same hard register assignment and will be removed in the undo
4761 pass. We still need the approximation because too aggressive
4762 splitting would result in too inaccurate cost calculation in the
4763 assignment pass because of too many generated moves which will be
4764 probably removed in the undo pass. */
4766 need_for_split_p (HARD_REG_SET potential_reload_hard_regs
, int regno
)
4768 int hard_regno
= regno
< FIRST_PSEUDO_REGISTER
? regno
: reg_renumber
[regno
];
4770 lra_assert (hard_regno
>= 0);
4771 return ((TEST_HARD_REG_BIT (potential_reload_hard_regs
, hard_regno
)
4772 /* Don't split eliminable hard registers, otherwise we can
4773 split hard registers like hard frame pointer, which
4774 lives on BB start/end according to DF-infrastructure,
4775 when there is a pseudo assigned to the register and
4776 living in the same BB. */
4777 && (regno
>= FIRST_PSEUDO_REGISTER
4778 || ! TEST_HARD_REG_BIT (eliminable_regset
, hard_regno
))
4779 && ! TEST_HARD_REG_BIT (lra_no_alloc_regs
, hard_regno
)
4780 /* Don't split call clobbered hard regs living through
4781 calls, otherwise we might have a check problem in the
4782 assign sub-pass as in the most cases (exception is a
4783 situation when lra_risky_transformations_p value is
4784 true) the assign pass assumes that all pseudos living
4785 through calls are assigned to call saved hard regs. */
4786 && (regno
>= FIRST_PSEUDO_REGISTER
4787 || ! TEST_HARD_REG_BIT (call_used_reg_set
, regno
)
4788 || usage_insns
[regno
].calls_num
== calls_num
)
4789 /* We need at least 2 reloads to make pseudo splitting
4790 profitable. We should provide hard regno splitting in
4791 any case to solve 1st insn scheduling problem when
4792 moving hard register definition up might result in
4793 impossibility to find hard register for reload pseudo of
4794 small register class. */
4795 && (usage_insns
[regno
].reloads_num
4796 + (regno
< FIRST_PSEUDO_REGISTER
? 0 : 3) < reloads_num
)
4797 && (regno
< FIRST_PSEUDO_REGISTER
4798 /* For short living pseudos, spilling + inheritance can
4799 be considered a substitution for splitting.
4800 Therefore we do not splitting for local pseudos. It
4801 decreases also aggressiveness of splitting. The
4802 minimal number of references is chosen taking into
4803 account that for 2 references splitting has no sense
4804 as we can just spill the pseudo. */
4805 || (regno
>= FIRST_PSEUDO_REGISTER
4806 && lra_reg_info
[regno
].nrefs
> 3
4807 && bitmap_bit_p (&ebb_global_regs
, regno
))))
4808 || (regno
>= FIRST_PSEUDO_REGISTER
&& need_for_call_save_p (regno
)));
4811 /* Return class for the split pseudo created from original pseudo with
4812 ALLOCNO_CLASS and MODE which got a hard register HARD_REGNO. We
4813 choose subclass of ALLOCNO_CLASS which contains HARD_REGNO and
4814 results in no secondary memory movements. */
4815 static enum reg_class
4816 choose_split_class (enum reg_class allocno_class
,
4817 int hard_regno ATTRIBUTE_UNUSED
,
4818 enum machine_mode mode ATTRIBUTE_UNUSED
)
4820 #ifndef SECONDARY_MEMORY_NEEDED
4821 return allocno_class
;
4824 enum reg_class cl
, best_cl
= NO_REGS
;
4825 enum reg_class hard_reg_class ATTRIBUTE_UNUSED
4826 = REGNO_REG_CLASS (hard_regno
);
4828 if (! SECONDARY_MEMORY_NEEDED (allocno_class
, allocno_class
, mode
)
4829 && TEST_HARD_REG_BIT (reg_class_contents
[allocno_class
], hard_regno
))
4830 return allocno_class
;
4832 (cl
= reg_class_subclasses
[allocno_class
][i
]) != LIM_REG_CLASSES
;
4834 if (! SECONDARY_MEMORY_NEEDED (cl
, hard_reg_class
, mode
)
4835 && ! SECONDARY_MEMORY_NEEDED (hard_reg_class
, cl
, mode
)
4836 && TEST_HARD_REG_BIT (reg_class_contents
[cl
], hard_regno
)
4837 && (best_cl
== NO_REGS
4838 || ira_class_hard_regs_num
[best_cl
] < ira_class_hard_regs_num
[cl
]))
4844 /* Do split transformations for insn INSN, which defines or uses
4845 ORIGINAL_REGNO. NEXT_USAGE_INSNS specifies which instruction in
4846 the EBB next uses ORIGINAL_REGNO; it has the same form as the
4847 "insns" field of usage_insns.
4849 The transformations look like:
4852 ... s <- p (new insn -- save)
4854 ... p <- s (new insn -- restore)
4855 <- ... p ... <- ... p ...
4857 <- ... p ... <- ... p ...
4858 ... s <- p (new insn -- save)
4860 ... p <- s (new insn -- restore)
4861 <- ... p ... <- ... p ...
4863 where p is an original pseudo got a hard register or a hard
4864 register and s is a new split pseudo. The save is put before INSN
4865 if BEFORE_P is true. Return true if we succeed in such
4868 split_reg (bool before_p
, int original_regno
, rtx insn
, rtx next_usage_insns
)
4870 enum reg_class rclass
;
4872 int hard_regno
, nregs
;
4873 rtx new_reg
, save
, restore
, usage_insn
;
4877 if (original_regno
< FIRST_PSEUDO_REGISTER
)
4879 rclass
= ira_allocno_class_translate
[REGNO_REG_CLASS (original_regno
)];
4880 hard_regno
= original_regno
;
4881 call_save_p
= false;
4886 hard_regno
= reg_renumber
[original_regno
];
4887 nregs
= hard_regno_nregs
[hard_regno
][PSEUDO_REGNO_MODE (original_regno
)];
4888 rclass
= lra_get_allocno_class (original_regno
);
4889 original_reg
= regno_reg_rtx
[original_regno
];
4890 call_save_p
= need_for_call_save_p (original_regno
);
4892 original_reg
= regno_reg_rtx
[original_regno
];
4893 lra_assert (hard_regno
>= 0);
4894 if (lra_dump_file
!= NULL
)
4895 fprintf (lra_dump_file
,
4896 " ((((((((((((((((((((((((((((((((((((((((((((((((\n");
4899 enum machine_mode mode
= GET_MODE (original_reg
);
4901 mode
= HARD_REGNO_CALLER_SAVE_MODE (hard_regno
,
4902 hard_regno_nregs
[hard_regno
][mode
],
4904 new_reg
= lra_create_new_reg (mode
, NULL_RTX
, NO_REGS
, "save");
4908 rclass
= choose_split_class (rclass
, hard_regno
,
4909 GET_MODE (original_reg
));
4910 if (rclass
== NO_REGS
)
4912 if (lra_dump_file
!= NULL
)
4914 fprintf (lra_dump_file
,
4915 " Rejecting split of %d(%s): "
4916 "no good reg class for %d(%s)\n",
4918 reg_class_names
[lra_get_allocno_class (original_regno
)],
4920 reg_class_names
[REGNO_REG_CLASS (hard_regno
)]);
4923 " ))))))))))))))))))))))))))))))))))))))))))))))))\n");
4927 new_reg
= lra_create_new_reg (GET_MODE (original_reg
), original_reg
,
4929 reg_renumber
[REGNO (new_reg
)] = hard_regno
;
4931 save
= emit_spill_move (true, new_reg
, original_reg
);
4932 if (NEXT_INSN (save
) != NULL_RTX
)
4934 lra_assert (! call_save_p
);
4935 if (lra_dump_file
!= NULL
)
4939 " Rejecting split %d->%d resulting in > 2 %s save insns:\n",
4940 original_regno
, REGNO (new_reg
), call_save_p
? "call" : "");
4941 dump_rtl_slim (lra_dump_file
, save
, NULL_RTX
, -1, 0);
4942 fprintf (lra_dump_file
,
4943 " ))))))))))))))))))))))))))))))))))))))))))))))))\n");
4947 restore
= emit_spill_move (false, new_reg
, original_reg
);
4948 if (NEXT_INSN (restore
) != NULL_RTX
)
4950 lra_assert (! call_save_p
);
4951 if (lra_dump_file
!= NULL
)
4953 fprintf (lra_dump_file
,
4954 " Rejecting split %d->%d "
4955 "resulting in > 2 %s restore insns:\n",
4956 original_regno
, REGNO (new_reg
), call_save_p
? "call" : "");
4957 dump_rtl_slim (lra_dump_file
, restore
, NULL_RTX
, -1, 0);
4958 fprintf (lra_dump_file
,
4959 " ))))))))))))))))))))))))))))))))))))))))))))))))\n");
4963 after_p
= usage_insns
[original_regno
].after_p
;
4964 lra_reg_info
[REGNO (new_reg
)].restore_regno
= original_regno
;
4965 bitmap_set_bit (&check_only_regs
, REGNO (new_reg
));
4966 bitmap_set_bit (&check_only_regs
, original_regno
);
4967 bitmap_set_bit (&lra_split_regs
, REGNO (new_reg
));
4970 if (GET_CODE (next_usage_insns
) != INSN_LIST
)
4972 usage_insn
= next_usage_insns
;
4975 usage_insn
= XEXP (next_usage_insns
, 0);
4976 lra_assert (DEBUG_INSN_P (usage_insn
));
4977 next_usage_insns
= XEXP (next_usage_insns
, 1);
4978 substitute_pseudo (&usage_insn
, original_regno
, new_reg
);
4979 lra_update_insn_regno_info (usage_insn
);
4980 if (lra_dump_file
!= NULL
)
4982 fprintf (lra_dump_file
, " Split reuse change %d->%d:\n",
4983 original_regno
, REGNO (new_reg
));
4984 dump_insn_slim (lra_dump_file
, usage_insn
);
4987 lra_assert (NOTE_P (usage_insn
) || NONDEBUG_INSN_P (usage_insn
));
4988 lra_assert (usage_insn
!= insn
|| (after_p
&& before_p
));
4989 lra_process_new_insns (usage_insn
, after_p
? NULL_RTX
: restore
,
4990 after_p
? restore
: NULL_RTX
,
4992 ? "Add reg<-save" : "Add reg<-split");
4993 lra_process_new_insns (insn
, before_p
? save
: NULL_RTX
,
4994 before_p
? NULL_RTX
: save
,
4996 ? "Add save<-reg" : "Add split<-reg");
4998 /* If we are trying to split multi-register. We should check
4999 conflicts on the next assignment sub-pass. IRA can allocate on
5000 sub-register levels, LRA do this on pseudos level right now and
5001 this discrepancy may create allocation conflicts after
5003 lra_risky_transformations_p
= true;
5004 if (lra_dump_file
!= NULL
)
5005 fprintf (lra_dump_file
,
5006 " ))))))))))))))))))))))))))))))))))))))))))))))))\n");
5010 /* Recognize that we need a split transformation for insn INSN, which
5011 defines or uses REGNO in its insn biggest MODE (we use it only if
5012 REGNO is a hard register). POTENTIAL_RELOAD_HARD_REGS contains
5013 hard registers which might be used for reloads since the EBB end.
5014 Put the save before INSN if BEFORE_P is true. MAX_UID is maximla
5015 uid before starting INSN processing. Return true if we succeed in
5016 such transformation. */
5018 split_if_necessary (int regno
, enum machine_mode mode
,
5019 HARD_REG_SET potential_reload_hard_regs
,
5020 bool before_p
, rtx insn
, int max_uid
)
5024 rtx next_usage_insns
;
5026 if (regno
< FIRST_PSEUDO_REGISTER
)
5027 nregs
= hard_regno_nregs
[regno
][mode
];
5028 for (i
= 0; i
< nregs
; i
++)
5029 if (usage_insns
[regno
+ i
].check
== curr_usage_insns_check
5030 && (next_usage_insns
= usage_insns
[regno
+ i
].insns
) != NULL_RTX
5031 /* To avoid processing the register twice or more. */
5032 && ((GET_CODE (next_usage_insns
) != INSN_LIST
5033 && INSN_UID (next_usage_insns
) < max_uid
)
5034 || (GET_CODE (next_usage_insns
) == INSN_LIST
5035 && (INSN_UID (XEXP (next_usage_insns
, 0)) < max_uid
)))
5036 && need_for_split_p (potential_reload_hard_regs
, regno
+ i
)
5037 && split_reg (before_p
, regno
+ i
, insn
, next_usage_insns
))
5042 /* Check only registers living at the current program point in the
5044 static bitmap_head live_regs
;
5046 /* Update live info in EBB given by its HEAD and TAIL insns after
5047 inheritance/split transformation. The function removes dead moves
5050 update_ebb_live_info (rtx head
, rtx tail
)
5057 basic_block last_bb
, prev_bb
, curr_bb
;
5059 struct lra_insn_reg
*reg
;
5063 last_bb
= BLOCK_FOR_INSN (tail
);
5065 for (curr_insn
= tail
;
5066 curr_insn
!= PREV_INSN (head
);
5067 curr_insn
= prev_insn
)
5069 prev_insn
= PREV_INSN (curr_insn
);
5070 /* We need to process empty blocks too. They contain
5071 NOTE_INSN_BASIC_BLOCK referring for the basic block. */
5072 if (NOTE_P (curr_insn
) && NOTE_KIND (curr_insn
) != NOTE_INSN_BASIC_BLOCK
)
5074 curr_bb
= BLOCK_FOR_INSN (curr_insn
);
5075 if (curr_bb
!= prev_bb
)
5077 if (prev_bb
!= NULL
)
5079 /* Update df_get_live_in (prev_bb): */
5080 EXECUTE_IF_SET_IN_BITMAP (&check_only_regs
, 0, j
, bi
)
5081 if (bitmap_bit_p (&live_regs
, j
))
5082 bitmap_set_bit (df_get_live_in (prev_bb
), j
);
5084 bitmap_clear_bit (df_get_live_in (prev_bb
), j
);
5086 if (curr_bb
!= last_bb
)
5088 /* Update df_get_live_out (curr_bb): */
5089 EXECUTE_IF_SET_IN_BITMAP (&check_only_regs
, 0, j
, bi
)
5091 live_p
= bitmap_bit_p (&live_regs
, j
);
5093 FOR_EACH_EDGE (e
, ei
, curr_bb
->succs
)
5094 if (bitmap_bit_p (df_get_live_in (e
->dest
), j
))
5100 bitmap_set_bit (df_get_live_out (curr_bb
), j
);
5102 bitmap_clear_bit (df_get_live_out (curr_bb
), j
);
5106 bitmap_and (&live_regs
, &check_only_regs
, df_get_live_out (curr_bb
));
5108 if (! NONDEBUG_INSN_P (curr_insn
))
5110 curr_id
= lra_get_insn_recog_data (curr_insn
);
5111 curr_static_id
= curr_id
->insn_static_data
;
5113 if ((set
= single_set (curr_insn
)) != NULL_RTX
&& REG_P (SET_DEST (set
))
5114 && (regno
= REGNO (SET_DEST (set
))) >= FIRST_PSEUDO_REGISTER
5115 && bitmap_bit_p (&check_only_regs
, regno
)
5116 && ! bitmap_bit_p (&live_regs
, regno
))
5118 /* See which defined values die here. */
5119 for (reg
= curr_id
->regs
; reg
!= NULL
; reg
= reg
->next
)
5120 if (reg
->type
== OP_OUT
&& ! reg
->subreg_p
)
5121 bitmap_clear_bit (&live_regs
, reg
->regno
);
5122 for (reg
= curr_static_id
->hard_regs
; reg
!= NULL
; reg
= reg
->next
)
5123 if (reg
->type
== OP_OUT
&& ! reg
->subreg_p
)
5124 bitmap_clear_bit (&live_regs
, reg
->regno
);
5125 /* Mark each used value as live. */
5126 for (reg
= curr_id
->regs
; reg
!= NULL
; reg
= reg
->next
)
5127 if (reg
->type
!= OP_OUT
5128 && bitmap_bit_p (&check_only_regs
, reg
->regno
))
5129 bitmap_set_bit (&live_regs
, reg
->regno
);
5130 for (reg
= curr_static_id
->hard_regs
; reg
!= NULL
; reg
= reg
->next
)
5131 if (reg
->type
!= OP_OUT
5132 && bitmap_bit_p (&check_only_regs
, reg
->regno
))
5133 bitmap_set_bit (&live_regs
, reg
->regno
);
5134 if (curr_id
->arg_hard_regs
!= NULL
)
5135 /* Make argument hard registers live. */
5136 for (i
= 0; (regno
= curr_id
->arg_hard_regs
[i
]) >= 0; i
++)
5137 if (bitmap_bit_p (&check_only_regs
, regno
))
5138 bitmap_set_bit (&live_regs
, regno
);
5139 /* It is quite important to remove dead move insns because it
5140 means removing dead store. We don't need to process them for
5144 if (lra_dump_file
!= NULL
)
5146 fprintf (lra_dump_file
, " Removing dead insn:\n ");
5147 dump_insn_slim (lra_dump_file
, curr_insn
);
5149 lra_set_insn_deleted (curr_insn
);
5154 /* The structure describes info to do an inheritance for the current
5155 insn. We need to collect such info first before doing the
5156 transformations because the transformations change the insn
5157 internal representation. */
5160 /* Original regno. */
5162 /* Subsequent insns which can inherit original reg value. */
5166 /* Array containing all info for doing inheritance from the current
5168 static struct to_inherit to_inherit
[LRA_MAX_INSN_RELOADS
];
5170 /* Number elements in the previous array. */
5171 static int to_inherit_num
;
5173 /* Add inheritance info REGNO and INSNS. Their meaning is described in
5174 structure to_inherit. */
5176 add_to_inherit (int regno
, rtx insns
)
5180 for (i
= 0; i
< to_inherit_num
; i
++)
5181 if (to_inherit
[i
].regno
== regno
)
5183 lra_assert (to_inherit_num
< LRA_MAX_INSN_RELOADS
);
5184 to_inherit
[to_inherit_num
].regno
= regno
;
5185 to_inherit
[to_inherit_num
++].insns
= insns
;
5188 /* Return the last non-debug insn in basic block BB, or the block begin
5191 get_last_insertion_point (basic_block bb
)
5195 FOR_BB_INSNS_REVERSE (bb
, insn
)
5196 if (NONDEBUG_INSN_P (insn
) || NOTE_INSN_BASIC_BLOCK_P (insn
))
5201 /* Set up RES by registers living on edges FROM except the edge (FROM,
5202 TO) or by registers set up in a jump insn in BB FROM. */
5204 get_live_on_other_edges (basic_block from
, basic_block to
, bitmap res
)
5207 struct lra_insn_reg
*reg
;
5211 lra_assert (to
!= NULL
);
5213 FOR_EACH_EDGE (e
, ei
, from
->succs
)
5215 bitmap_ior_into (res
, df_get_live_in (e
->dest
));
5216 last
= get_last_insertion_point (from
);
5217 if (! JUMP_P (last
))
5219 curr_id
= lra_get_insn_recog_data (last
);
5220 for (reg
= curr_id
->regs
; reg
!= NULL
; reg
= reg
->next
)
5221 if (reg
->type
!= OP_IN
)
5222 bitmap_set_bit (res
, reg
->regno
);
5225 /* Used as a temporary results of some bitmap calculations. */
5226 static bitmap_head temp_bitmap
;
5228 /* We split for reloads of small class of hard regs. The following
5229 defines how many hard regs the class should have to be qualified as
5230 small. The code is mostly oriented to x86/x86-64 architecture
5231 where some insns need to use only specific register or pair of
5232 registers and these register can live in RTL explicitly, e.g. for
5233 parameter passing. */
5234 static const int max_small_class_regs_num
= 2;
5236 /* Do inheritance/split transformations in EBB starting with HEAD and
5237 finishing on TAIL. We process EBB insns in the reverse order.
5238 Return true if we did any inheritance/split transformation in the
5241 We should avoid excessive splitting which results in worse code
5242 because of inaccurate cost calculations for spilling new split
5243 pseudos in such case. To achieve this we do splitting only if
5244 register pressure is high in given basic block and there are reload
5245 pseudos requiring hard registers. We could do more register
5246 pressure calculations at any given program point to avoid necessary
5247 splitting even more but it is to expensive and the current approach
5248 works well enough. */
5250 inherit_in_ebb (rtx head
, rtx tail
)
5252 int i
, src_regno
, dst_regno
, nregs
;
5253 bool change_p
, succ_p
, update_reloads_num_p
;
5254 rtx prev_insn
, next_usage_insns
, set
, last_insn
;
5256 struct lra_insn_reg
*reg
;
5257 basic_block last_processed_bb
, curr_bb
= NULL
;
5258 HARD_REG_SET potential_reload_hard_regs
, live_hard_regs
;
5262 bool head_p
, after_p
;
5265 curr_usage_insns_check
++;
5266 reloads_num
= calls_num
= 0;
5267 bitmap_clear (&check_only_regs
);
5268 last_processed_bb
= NULL
;
5269 CLEAR_HARD_REG_SET (potential_reload_hard_regs
);
5270 COPY_HARD_REG_SET (live_hard_regs
, eliminable_regset
);
5271 IOR_HARD_REG_SET (live_hard_regs
, lra_no_alloc_regs
);
5272 /* We don't process new insns generated in the loop. */
5273 for (curr_insn
= tail
; curr_insn
!= PREV_INSN (head
); curr_insn
= prev_insn
)
5275 prev_insn
= PREV_INSN (curr_insn
);
5276 if (BLOCK_FOR_INSN (curr_insn
) != NULL
)
5277 curr_bb
= BLOCK_FOR_INSN (curr_insn
);
5278 if (last_processed_bb
!= curr_bb
)
5280 /* We are at the end of BB. Add qualified living
5281 pseudos for potential splitting. */
5282 to_process
= df_get_live_out (curr_bb
);
5283 if (last_processed_bb
!= NULL
)
5285 /* We are somewhere in the middle of EBB. */
5286 get_live_on_other_edges (curr_bb
, last_processed_bb
,
5288 to_process
= &temp_bitmap
;
5290 last_processed_bb
= curr_bb
;
5291 last_insn
= get_last_insertion_point (curr_bb
);
5292 after_p
= (! JUMP_P (last_insn
)
5293 && (! CALL_P (last_insn
)
5294 || (find_reg_note (last_insn
,
5295 REG_NORETURN
, NULL_RTX
) == NULL_RTX
5296 && ! SIBLING_CALL_P (last_insn
))));
5297 CLEAR_HARD_REG_SET (potential_reload_hard_regs
);
5298 EXECUTE_IF_SET_IN_BITMAP (to_process
, 0, j
, bi
)
5300 if ((int) j
>= lra_constraint_new_regno_start
)
5302 if (j
< FIRST_PSEUDO_REGISTER
|| reg_renumber
[j
] >= 0)
5304 if (j
< FIRST_PSEUDO_REGISTER
)
5305 SET_HARD_REG_BIT (live_hard_regs
, j
);
5307 add_to_hard_reg_set (&live_hard_regs
,
5308 PSEUDO_REGNO_MODE (j
),
5310 setup_next_usage_insn (j
, last_insn
, reloads_num
, after_p
);
5314 src_regno
= dst_regno
= -1;
5315 if (NONDEBUG_INSN_P (curr_insn
)
5316 && (set
= single_set (curr_insn
)) != NULL_RTX
5317 && REG_P (SET_DEST (set
)) && REG_P (SET_SRC (set
)))
5319 src_regno
= REGNO (SET_SRC (set
));
5320 dst_regno
= REGNO (SET_DEST (set
));
5322 update_reloads_num_p
= true;
5323 if (src_regno
< lra_constraint_new_regno_start
5324 && src_regno
>= FIRST_PSEUDO_REGISTER
5325 && reg_renumber
[src_regno
] < 0
5326 && dst_regno
>= lra_constraint_new_regno_start
5327 && (cl
= lra_get_allocno_class (dst_regno
)) != NO_REGS
)
5329 /* 'reload_pseudo <- original_pseudo'. */
5330 if (ira_class_hard_regs_num
[cl
] <= max_small_class_regs_num
)
5332 update_reloads_num_p
= false;
5334 if (usage_insns
[src_regno
].check
== curr_usage_insns_check
5335 && (next_usage_insns
= usage_insns
[src_regno
].insns
) != NULL_RTX
)
5336 succ_p
= inherit_reload_reg (false, src_regno
, cl
,
5337 curr_insn
, next_usage_insns
);
5341 setup_next_usage_insn (src_regno
, curr_insn
, reloads_num
, false);
5342 if (hard_reg_set_subset_p (reg_class_contents
[cl
], live_hard_regs
))
5343 IOR_HARD_REG_SET (potential_reload_hard_regs
,
5344 reg_class_contents
[cl
]);
5346 else if (src_regno
>= lra_constraint_new_regno_start
5347 && dst_regno
< lra_constraint_new_regno_start
5348 && dst_regno
>= FIRST_PSEUDO_REGISTER
5349 && reg_renumber
[dst_regno
] < 0
5350 && (cl
= lra_get_allocno_class (src_regno
)) != NO_REGS
5351 && usage_insns
[dst_regno
].check
== curr_usage_insns_check
5352 && (next_usage_insns
5353 = usage_insns
[dst_regno
].insns
) != NULL_RTX
)
5355 if (ira_class_hard_regs_num
[cl
] <= max_small_class_regs_num
)
5357 update_reloads_num_p
= false;
5358 /* 'original_pseudo <- reload_pseudo'. */
5359 if (! JUMP_P (curr_insn
)
5360 && inherit_reload_reg (true, dst_regno
, cl
,
5361 curr_insn
, next_usage_insns
))
5364 usage_insns
[dst_regno
].check
= 0;
5365 if (hard_reg_set_subset_p (reg_class_contents
[cl
], live_hard_regs
))
5366 IOR_HARD_REG_SET (potential_reload_hard_regs
,
5367 reg_class_contents
[cl
]);
5369 else if (INSN_P (curr_insn
))
5372 int max_uid
= get_max_uid ();
5374 curr_id
= lra_get_insn_recog_data (curr_insn
);
5375 curr_static_id
= curr_id
->insn_static_data
;
5377 /* Process insn definitions. */
5378 for (iter
= 0; iter
< 2; iter
++)
5379 for (reg
= iter
== 0 ? curr_id
->regs
: curr_static_id
->hard_regs
;
5382 if (reg
->type
!= OP_IN
5383 && (dst_regno
= reg
->regno
) < lra_constraint_new_regno_start
)
5385 if (dst_regno
>= FIRST_PSEUDO_REGISTER
&& reg
->type
== OP_OUT
5386 && reg_renumber
[dst_regno
] < 0 && ! reg
->subreg_p
5387 && usage_insns
[dst_regno
].check
== curr_usage_insns_check
5388 && (next_usage_insns
5389 = usage_insns
[dst_regno
].insns
) != NULL_RTX
)
5391 struct lra_insn_reg
*r
;
5393 for (r
= curr_id
->regs
; r
!= NULL
; r
= r
->next
)
5394 if (r
->type
!= OP_OUT
&& r
->regno
== dst_regno
)
5396 /* Don't do inheritance if the pseudo is also
5397 used in the insn. */
5399 /* We can not do inheritance right now
5400 because the current insn reg info (chain
5401 regs) can change after that. */
5402 add_to_inherit (dst_regno
, next_usage_insns
);
5404 /* We can not process one reg twice here because of
5405 usage_insns invalidation. */
5406 if ((dst_regno
< FIRST_PSEUDO_REGISTER
5407 || reg_renumber
[dst_regno
] >= 0)
5408 && ! reg
->subreg_p
&& reg
->type
!= OP_IN
)
5412 if (split_if_necessary (dst_regno
, reg
->biggest_mode
,
5413 potential_reload_hard_regs
,
5414 false, curr_insn
, max_uid
))
5416 CLEAR_HARD_REG_SET (s
);
5417 if (dst_regno
< FIRST_PSEUDO_REGISTER
)
5418 add_to_hard_reg_set (&s
, reg
->biggest_mode
, dst_regno
);
5420 add_to_hard_reg_set (&s
, PSEUDO_REGNO_MODE (dst_regno
),
5421 reg_renumber
[dst_regno
]);
5422 AND_COMPL_HARD_REG_SET (live_hard_regs
, s
);
5424 /* We should invalidate potential inheritance or
5425 splitting for the current insn usages to the next
5426 usage insns (see code below) as the output pseudo
5428 if ((dst_regno
>= FIRST_PSEUDO_REGISTER
5429 && reg_renumber
[dst_regno
] < 0)
5430 || (reg
->type
== OP_OUT
&& ! reg
->subreg_p
5431 && (dst_regno
< FIRST_PSEUDO_REGISTER
5432 || reg_renumber
[dst_regno
] >= 0)))
5434 /* Invalidate and mark definitions. */
5435 if (dst_regno
>= FIRST_PSEUDO_REGISTER
)
5436 usage_insns
[dst_regno
].check
= -(int) INSN_UID (curr_insn
);
5439 nregs
= hard_regno_nregs
[dst_regno
][reg
->biggest_mode
];
5440 for (i
= 0; i
< nregs
; i
++)
5441 usage_insns
[dst_regno
+ i
].check
5442 = -(int) INSN_UID (curr_insn
);
5446 if (! JUMP_P (curr_insn
))
5447 for (i
= 0; i
< to_inherit_num
; i
++)
5448 if (inherit_reload_reg (true, to_inherit
[i
].regno
,
5449 ALL_REGS
, curr_insn
,
5450 to_inherit
[i
].insns
))
5452 if (CALL_P (curr_insn
))
5454 rtx cheap
, pat
, dest
, restore
;
5455 int regno
, hard_regno
;
5458 if ((cheap
= find_reg_note (curr_insn
,
5459 REG_RETURNED
, NULL_RTX
)) != NULL_RTX
5460 && ((cheap
= XEXP (cheap
, 0)), true)
5461 && (regno
= REGNO (cheap
)) >= FIRST_PSEUDO_REGISTER
5462 && (hard_regno
= reg_renumber
[regno
]) >= 0
5463 /* If there are pending saves/restores, the
5464 optimization is not worth. */
5465 && usage_insns
[regno
].calls_num
== calls_num
- 1
5466 && TEST_HARD_REG_BIT (call_used_reg_set
, hard_regno
))
5468 /* Restore the pseudo from the call result as
5469 REG_RETURNED note says that the pseudo value is
5470 in the call result and the pseudo is an argument
5472 pat
= PATTERN (curr_insn
);
5473 if (GET_CODE (pat
) == PARALLEL
)
5474 pat
= XVECEXP (pat
, 0, 0);
5475 dest
= SET_DEST (pat
);
5477 emit_move_insn (cheap
, copy_rtx (dest
));
5478 restore
= get_insns ();
5480 lra_process_new_insns (curr_insn
, NULL
, restore
,
5481 "Inserting call parameter restore");
5482 /* We don't need to save/restore of the pseudo from
5484 usage_insns
[regno
].calls_num
= calls_num
;
5485 bitmap_set_bit (&check_only_regs
, regno
);
5489 /* Process insn usages. */
5490 for (iter
= 0; iter
< 2; iter
++)
5491 for (reg
= iter
== 0 ? curr_id
->regs
: curr_static_id
->hard_regs
;
5494 if ((reg
->type
!= OP_OUT
5495 || (reg
->type
== OP_OUT
&& reg
->subreg_p
))
5496 && (src_regno
= reg
->regno
) < lra_constraint_new_regno_start
)
5498 if (src_regno
>= FIRST_PSEUDO_REGISTER
5499 && reg_renumber
[src_regno
] < 0 && reg
->type
== OP_IN
)
5501 if (usage_insns
[src_regno
].check
== curr_usage_insns_check
5502 && (next_usage_insns
5503 = usage_insns
[src_regno
].insns
) != NULL_RTX
5504 && NONDEBUG_INSN_P (curr_insn
))
5505 add_to_inherit (src_regno
, next_usage_insns
);
5506 else if (usage_insns
[src_regno
].check
5507 != -(int) INSN_UID (curr_insn
))
5508 /* Add usages but only if the reg is not set up
5509 in the same insn. */
5510 add_next_usage_insn (src_regno
, curr_insn
, reloads_num
);
5512 else if (src_regno
< FIRST_PSEUDO_REGISTER
5513 || reg_renumber
[src_regno
] >= 0)
5516 rtx use_insn
= curr_insn
;
5518 before_p
= (JUMP_P (curr_insn
)
5519 || (CALL_P (curr_insn
) && reg
->type
== OP_IN
));
5520 if (NONDEBUG_INSN_P (curr_insn
)
5521 && (! JUMP_P (curr_insn
) || reg
->type
== OP_IN
)
5522 && split_if_necessary (src_regno
, reg
->biggest_mode
,
5523 potential_reload_hard_regs
,
5524 before_p
, curr_insn
, max_uid
))
5527 lra_risky_transformations_p
= true;
5530 usage_insns
[src_regno
].check
= 0;
5532 use_insn
= PREV_INSN (curr_insn
);
5534 if (NONDEBUG_INSN_P (curr_insn
))
5536 if (src_regno
< FIRST_PSEUDO_REGISTER
)
5537 add_to_hard_reg_set (&live_hard_regs
,
5538 reg
->biggest_mode
, src_regno
);
5540 add_to_hard_reg_set (&live_hard_regs
,
5541 PSEUDO_REGNO_MODE (src_regno
),
5542 reg_renumber
[src_regno
]);
5544 add_next_usage_insn (src_regno
, use_insn
, reloads_num
);
5547 /* Process call args. */
5548 if (curr_id
->arg_hard_regs
!= NULL
)
5549 for (i
= 0; (src_regno
= curr_id
->arg_hard_regs
[i
]) >= 0; i
++)
5550 if (src_regno
< FIRST_PSEUDO_REGISTER
)
5552 SET_HARD_REG_BIT (live_hard_regs
, src_regno
);
5553 add_next_usage_insn (src_regno
, curr_insn
, reloads_num
);
5555 for (i
= 0; i
< to_inherit_num
; i
++)
5557 src_regno
= to_inherit
[i
].regno
;
5558 if (inherit_reload_reg (false, src_regno
, ALL_REGS
,
5559 curr_insn
, to_inherit
[i
].insns
))
5562 setup_next_usage_insn (src_regno
, curr_insn
, reloads_num
, false);
5565 if (update_reloads_num_p
5566 && NONDEBUG_INSN_P (curr_insn
)
5567 && (set
= single_set (curr_insn
)) != NULL_RTX
)
5570 if ((REG_P (SET_DEST (set
))
5571 && (regno
= REGNO (SET_DEST (set
))) >= lra_constraint_new_regno_start
5572 && reg_renumber
[regno
] < 0
5573 && (cl
= lra_get_allocno_class (regno
)) != NO_REGS
)
5574 || (REG_P (SET_SRC (set
))
5575 && (regno
= REGNO (SET_SRC (set
))) >= lra_constraint_new_regno_start
5576 && reg_renumber
[regno
] < 0
5577 && (cl
= lra_get_allocno_class (regno
)) != NO_REGS
))
5579 if (ira_class_hard_regs_num
[cl
] <= max_small_class_regs_num
)
5581 if (hard_reg_set_subset_p (reg_class_contents
[cl
], live_hard_regs
))
5582 IOR_HARD_REG_SET (potential_reload_hard_regs
,
5583 reg_class_contents
[cl
]);
5586 /* We reached the start of the current basic block. */
5587 if (prev_insn
== NULL_RTX
|| prev_insn
== PREV_INSN (head
)
5588 || BLOCK_FOR_INSN (prev_insn
) != curr_bb
)
5590 /* We reached the beginning of the current block -- do
5591 rest of spliting in the current BB. */
5592 to_process
= df_get_live_in (curr_bb
);
5593 if (BLOCK_FOR_INSN (head
) != curr_bb
)
5595 /* We are somewhere in the middle of EBB. */
5596 get_live_on_other_edges (EDGE_PRED (curr_bb
, 0)->src
,
5597 curr_bb
, &temp_bitmap
);
5598 to_process
= &temp_bitmap
;
5601 EXECUTE_IF_SET_IN_BITMAP (to_process
, 0, j
, bi
)
5603 if ((int) j
>= lra_constraint_new_regno_start
)
5605 if (((int) j
< FIRST_PSEUDO_REGISTER
|| reg_renumber
[j
] >= 0)
5606 && usage_insns
[j
].check
== curr_usage_insns_check
5607 && (next_usage_insns
= usage_insns
[j
].insns
) != NULL_RTX
)
5609 if (need_for_split_p (potential_reload_hard_regs
, j
))
5611 if (lra_dump_file
!= NULL
&& head_p
)
5613 fprintf (lra_dump_file
,
5614 " ----------------------------------\n");
5617 if (split_reg (false, j
, bb_note (curr_bb
),
5621 usage_insns
[j
].check
= 0;
5629 /* This value affects EBB forming. If probability of edge from EBB to
5630 a BB is not greater than the following value, we don't add the BB
5632 #define EBB_PROBABILITY_CUTOFF ((REG_BR_PROB_BASE * 50) / 100)
5634 /* Current number of inheritance/split iteration. */
5635 int lra_inheritance_iter
;
5637 /* Entry function for inheritance/split pass. */
5639 lra_inheritance (void)
5642 basic_block bb
, start_bb
;
5645 lra_inheritance_iter
++;
5646 if (lra_inheritance_iter
> LRA_MAX_INHERITANCE_PASSES
)
5648 timevar_push (TV_LRA_INHERITANCE
);
5649 if (lra_dump_file
!= NULL
)
5650 fprintf (lra_dump_file
, "\n********** Inheritance #%d: **********\n\n",
5651 lra_inheritance_iter
);
5652 curr_usage_insns_check
= 0;
5653 usage_insns
= XNEWVEC (struct usage_insns
, lra_constraint_new_regno_start
);
5654 for (i
= 0; i
< lra_constraint_new_regno_start
; i
++)
5655 usage_insns
[i
].check
= 0;
5656 bitmap_initialize (&check_only_regs
, ®_obstack
);
5657 bitmap_initialize (&live_regs
, ®_obstack
);
5658 bitmap_initialize (&temp_bitmap
, ®_obstack
);
5659 bitmap_initialize (&ebb_global_regs
, ®_obstack
);
5660 FOR_EACH_BB_FN (bb
, cfun
)
5663 if (lra_dump_file
!= NULL
)
5664 fprintf (lra_dump_file
, "EBB");
5665 /* Form a EBB starting with BB. */
5666 bitmap_clear (&ebb_global_regs
);
5667 bitmap_ior_into (&ebb_global_regs
, df_get_live_in (bb
));
5670 if (lra_dump_file
!= NULL
)
5671 fprintf (lra_dump_file
, " %d", bb
->index
);
5672 if (bb
->next_bb
== EXIT_BLOCK_PTR_FOR_FN (cfun
)
5673 || LABEL_P (BB_HEAD (bb
->next_bb
)))
5675 e
= find_fallthru_edge (bb
->succs
);
5678 if (e
->probability
<= EBB_PROBABILITY_CUTOFF
)
5682 bitmap_ior_into (&ebb_global_regs
, df_get_live_out (bb
));
5683 if (lra_dump_file
!= NULL
)
5684 fprintf (lra_dump_file
, "\n");
5685 if (inherit_in_ebb (BB_HEAD (start_bb
), BB_END (bb
)))
5686 /* Remember that the EBB head and tail can change in
5688 update_ebb_live_info (BB_HEAD (start_bb
), BB_END (bb
));
5690 bitmap_clear (&ebb_global_regs
);
5691 bitmap_clear (&temp_bitmap
);
5692 bitmap_clear (&live_regs
);
5693 bitmap_clear (&check_only_regs
);
5696 timevar_pop (TV_LRA_INHERITANCE
);
5701 /* This page contains code to undo failed inheritance/split
5704 /* Current number of iteration undoing inheritance/split. */
5705 int lra_undo_inheritance_iter
;
5707 /* Fix BB live info LIVE after removing pseudos created on pass doing
5708 inheritance/split which are REMOVED_PSEUDOS. */
5710 fix_bb_live_info (bitmap live
, bitmap removed_pseudos
)
5715 EXECUTE_IF_SET_IN_BITMAP (removed_pseudos
, 0, regno
, bi
)
5716 if (bitmap_clear_bit (live
, regno
))
5717 bitmap_set_bit (live
, lra_reg_info
[regno
].restore_regno
);
5720 /* Return regno of the (subreg of) REG. Otherwise, return a negative
5725 if (GET_CODE (reg
) == SUBREG
)
5726 reg
= SUBREG_REG (reg
);
5732 /* Remove inheritance/split pseudos which are in REMOVE_PSEUDOS and
5733 return true if we did any change. The undo transformations for
5734 inheritance looks like
5738 p <- i, i <- p, and i <- i3
5739 where p is original pseudo from which inheritance pseudo i was
5740 created, i and i3 are removed inheritance pseudos, i2 is another
5741 not removed inheritance pseudo. All split pseudos or other
5742 occurrences of removed inheritance pseudos are changed on the
5743 corresponding original pseudos.
5745 The function also schedules insns changed and created during
5746 inheritance/split pass for processing by the subsequent constraint
5749 remove_inheritance_pseudos (bitmap remove_pseudos
)
5752 int regno
, sregno
, prev_sregno
, dregno
, restore_regno
;
5753 rtx set
, prev_set
, prev_insn
;
5754 bool change_p
, done_p
;
5756 change_p
= ! bitmap_empty_p (remove_pseudos
);
5757 /* We can not finish the function right away if CHANGE_P is true
5758 because we need to marks insns affected by previous
5759 inheritance/split pass for processing by the subsequent
5761 FOR_EACH_BB_FN (bb
, cfun
)
5763 fix_bb_live_info (df_get_live_in (bb
), remove_pseudos
);
5764 fix_bb_live_info (df_get_live_out (bb
), remove_pseudos
);
5765 FOR_BB_INSNS_REVERSE (bb
, curr_insn
)
5767 if (! INSN_P (curr_insn
))
5770 sregno
= dregno
= -1;
5771 if (change_p
&& NONDEBUG_INSN_P (curr_insn
)
5772 && (set
= single_set (curr_insn
)) != NULL_RTX
)
5774 dregno
= get_regno (SET_DEST (set
));
5775 sregno
= get_regno (SET_SRC (set
));
5778 if (sregno
>= 0 && dregno
>= 0)
5780 if ((bitmap_bit_p (remove_pseudos
, sregno
)
5781 && (lra_reg_info
[sregno
].restore_regno
== dregno
5782 || (bitmap_bit_p (remove_pseudos
, dregno
)
5783 && (lra_reg_info
[sregno
].restore_regno
5784 == lra_reg_info
[dregno
].restore_regno
))))
5785 || (bitmap_bit_p (remove_pseudos
, dregno
)
5786 && lra_reg_info
[dregno
].restore_regno
== sregno
))
5787 /* One of the following cases:
5788 original <- removed inheritance pseudo
5789 removed inherit pseudo <- another removed inherit pseudo
5790 removed inherit pseudo <- original pseudo
5792 removed_split_pseudo <- original_reg
5793 original_reg <- removed_split_pseudo */
5795 if (lra_dump_file
!= NULL
)
5797 fprintf (lra_dump_file
, " Removing %s:\n",
5798 bitmap_bit_p (&lra_split_regs
, sregno
)
5799 || bitmap_bit_p (&lra_split_regs
, dregno
)
5800 ? "split" : "inheritance");
5801 dump_insn_slim (lra_dump_file
, curr_insn
);
5803 lra_set_insn_deleted (curr_insn
);
5806 else if (bitmap_bit_p (remove_pseudos
, sregno
)
5807 && bitmap_bit_p (&lra_inheritance_pseudos
, sregno
))
5809 /* Search the following pattern:
5810 inherit_or_split_pseudo1 <- inherit_or_split_pseudo2
5811 original_pseudo <- inherit_or_split_pseudo1
5812 where the 2nd insn is the current insn and
5813 inherit_or_split_pseudo2 is not removed. If it is found,
5814 change the current insn onto:
5815 original_pseudo <- inherit_or_split_pseudo2. */
5816 for (prev_insn
= PREV_INSN (curr_insn
);
5817 prev_insn
!= NULL_RTX
&& ! NONDEBUG_INSN_P (prev_insn
);
5818 prev_insn
= PREV_INSN (prev_insn
))
5820 if (prev_insn
!= NULL_RTX
&& BLOCK_FOR_INSN (prev_insn
) == bb
5821 && (prev_set
= single_set (prev_insn
)) != NULL_RTX
5822 /* There should be no subregs in insn we are
5823 searching because only the original reg might
5824 be in subreg when we changed the mode of
5825 load/store for splitting. */
5826 && REG_P (SET_DEST (prev_set
))
5827 && REG_P (SET_SRC (prev_set
))
5828 && (int) REGNO (SET_DEST (prev_set
)) == sregno
5829 && ((prev_sregno
= REGNO (SET_SRC (prev_set
)))
5830 >= FIRST_PSEUDO_REGISTER
)
5831 /* As we consider chain of inheritance or
5832 splitting described in above comment we should
5833 check that sregno and prev_sregno were
5834 inheritance/split pseudos created from the
5835 same original regno. */
5836 && (lra_reg_info
[sregno
].restore_regno
5837 == lra_reg_info
[prev_sregno
].restore_regno
)
5838 && ! bitmap_bit_p (remove_pseudos
, prev_sregno
))
5840 lra_assert (GET_MODE (SET_SRC (prev_set
))
5841 == GET_MODE (regno_reg_rtx
[sregno
]));
5842 if (GET_CODE (SET_SRC (set
)) == SUBREG
)
5843 SUBREG_REG (SET_SRC (set
)) = SET_SRC (prev_set
);
5845 SET_SRC (set
) = SET_SRC (prev_set
);
5846 /* As we are finishing with processing the insn
5847 here, check the destination too as it might
5848 inheritance pseudo for another pseudo. */
5849 if (bitmap_bit_p (remove_pseudos
, dregno
)
5850 && bitmap_bit_p (&lra_inheritance_pseudos
, dregno
)
5852 = lra_reg_info
[dregno
].restore_regno
) >= 0)
5854 if (GET_CODE (SET_DEST (set
)) == SUBREG
)
5855 SUBREG_REG (SET_DEST (set
))
5856 = regno_reg_rtx
[restore_regno
];
5858 SET_DEST (set
) = regno_reg_rtx
[restore_regno
];
5860 lra_push_insn_and_update_insn_regno_info (curr_insn
);
5861 lra_set_used_insn_alternative_by_uid
5862 (INSN_UID (curr_insn
), -1);
5864 if (lra_dump_file
!= NULL
)
5866 fprintf (lra_dump_file
, " Change reload insn:\n");
5867 dump_insn_slim (lra_dump_file
, curr_insn
);
5874 struct lra_insn_reg
*reg
;
5875 bool restored_regs_p
= false;
5876 bool kept_regs_p
= false;
5878 curr_id
= lra_get_insn_recog_data (curr_insn
);
5879 for (reg
= curr_id
->regs
; reg
!= NULL
; reg
= reg
->next
)
5882 restore_regno
= lra_reg_info
[regno
].restore_regno
;
5883 if (restore_regno
>= 0)
5885 if (change_p
&& bitmap_bit_p (remove_pseudos
, regno
))
5887 substitute_pseudo (&curr_insn
, regno
,
5888 regno_reg_rtx
[restore_regno
]);
5889 restored_regs_p
= true;
5895 if (NONDEBUG_INSN_P (curr_insn
) && kept_regs_p
)
5897 /* The instruction has changed since the previous
5898 constraints pass. */
5899 lra_push_insn_and_update_insn_regno_info (curr_insn
);
5900 lra_set_used_insn_alternative_by_uid
5901 (INSN_UID (curr_insn
), -1);
5903 else if (restored_regs_p
)
5904 /* The instruction has been restored to the form that
5905 it had during the previous constraints pass. */
5906 lra_update_insn_regno_info (curr_insn
);
5907 if (restored_regs_p
&& lra_dump_file
!= NULL
)
5909 fprintf (lra_dump_file
, " Insn after restoring regs:\n");
5910 dump_insn_slim (lra_dump_file
, curr_insn
);
5918 /* If optional reload pseudos failed to get a hard register or was not
5919 inherited, it is better to remove optional reloads. We do this
5920 transformation after undoing inheritance to figure out necessity to
5921 remove optional reloads easier. Return true if we do any
5924 undo_optional_reloads (void)
5926 bool change_p
, keep_p
;
5927 unsigned int regno
, uid
;
5928 bitmap_iterator bi
, bi2
;
5929 rtx insn
, set
, src
, dest
;
5930 bitmap_head removed_optional_reload_pseudos
, insn_bitmap
;
5932 bitmap_initialize (&removed_optional_reload_pseudos
, ®_obstack
);
5933 bitmap_copy (&removed_optional_reload_pseudos
, &lra_optional_reload_pseudos
);
5934 EXECUTE_IF_SET_IN_BITMAP (&lra_optional_reload_pseudos
, 0, regno
, bi
)
5937 /* Keep optional reloads from previous subpasses. */
5938 if (lra_reg_info
[regno
].restore_regno
< 0
5939 /* If the original pseudo changed its allocation, just
5940 removing the optional pseudo is dangerous as the original
5941 pseudo will have longer live range. */
5942 || reg_renumber
[lra_reg_info
[regno
].restore_regno
] >= 0)
5944 else if (reg_renumber
[regno
] >= 0)
5945 EXECUTE_IF_SET_IN_BITMAP (&lra_reg_info
[regno
].insn_bitmap
, 0, uid
, bi2
)
5947 insn
= lra_insn_recog_data
[uid
]->insn
;
5948 if ((set
= single_set (insn
)) == NULL_RTX
)
5950 src
= SET_SRC (set
);
5951 dest
= SET_DEST (set
);
5952 if (! REG_P (src
) || ! REG_P (dest
))
5954 if (REGNO (dest
) == regno
5955 /* Ignore insn for optional reloads itself. */
5956 && lra_reg_info
[regno
].restore_regno
!= (int) REGNO (src
)
5957 /* Check only inheritance on last inheritance pass. */
5958 && (int) REGNO (src
) >= new_regno_start
5959 /* Check that the optional reload was inherited. */
5960 && bitmap_bit_p (&lra_inheritance_pseudos
, REGNO (src
)))
5968 bitmap_clear_bit (&removed_optional_reload_pseudos
, regno
);
5969 if (lra_dump_file
!= NULL
)
5970 fprintf (lra_dump_file
, "Keep optional reload reg %d\n", regno
);
5973 change_p
= ! bitmap_empty_p (&removed_optional_reload_pseudos
);
5974 bitmap_initialize (&insn_bitmap
, ®_obstack
);
5975 EXECUTE_IF_SET_IN_BITMAP (&removed_optional_reload_pseudos
, 0, regno
, bi
)
5977 if (lra_dump_file
!= NULL
)
5978 fprintf (lra_dump_file
, "Remove optional reload reg %d\n", regno
);
5979 bitmap_copy (&insn_bitmap
, &lra_reg_info
[regno
].insn_bitmap
);
5980 EXECUTE_IF_SET_IN_BITMAP (&insn_bitmap
, 0, uid
, bi2
)
5982 insn
= lra_insn_recog_data
[uid
]->insn
;
5983 if ((set
= single_set (insn
)) != NULL_RTX
)
5985 src
= SET_SRC (set
);
5986 dest
= SET_DEST (set
);
5987 if (REG_P (src
) && REG_P (dest
)
5988 && ((REGNO (src
) == regno
5989 && (lra_reg_info
[regno
].restore_regno
5990 == (int) REGNO (dest
)))
5991 || (REGNO (dest
) == regno
5992 && (lra_reg_info
[regno
].restore_regno
5993 == (int) REGNO (src
)))))
5995 if (lra_dump_file
!= NULL
)
5997 fprintf (lra_dump_file
, " Deleting move %u\n",
5999 dump_insn_slim (lra_dump_file
, insn
);
6001 lra_set_insn_deleted (insn
);
6004 /* We should not worry about generation memory-memory
6005 moves here as if the corresponding inheritance did
6006 not work (inheritance pseudo did not get a hard reg),
6007 we remove the inheritance pseudo and the optional
6010 substitute_pseudo (&insn
, regno
,
6011 regno_reg_rtx
[lra_reg_info
[regno
].restore_regno
]);
6012 lra_update_insn_regno_info (insn
);
6013 if (lra_dump_file
!= NULL
)
6015 fprintf (lra_dump_file
,
6016 " Restoring original insn:\n");
6017 dump_insn_slim (lra_dump_file
, insn
);
6021 /* Clear restore_regnos. */
6022 EXECUTE_IF_SET_IN_BITMAP (&lra_optional_reload_pseudos
, 0, regno
, bi
)
6023 lra_reg_info
[regno
].restore_regno
= -1;
6024 bitmap_clear (&insn_bitmap
);
6025 bitmap_clear (&removed_optional_reload_pseudos
);
6029 /* Entry function for undoing inheritance/split transformation. Return true
6030 if we did any RTL change in this pass. */
6032 lra_undo_inheritance (void)
6035 int restore_regno
, hard_regno
;
6036 int n_all_inherit
, n_inherit
, n_all_split
, n_split
;
6037 bitmap_head remove_pseudos
;
6041 lra_undo_inheritance_iter
++;
6042 if (lra_undo_inheritance_iter
> LRA_MAX_INHERITANCE_PASSES
)
6044 if (lra_dump_file
!= NULL
)
6045 fprintf (lra_dump_file
,
6046 "\n********** Undoing inheritance #%d: **********\n\n",
6047 lra_undo_inheritance_iter
);
6048 bitmap_initialize (&remove_pseudos
, ®_obstack
);
6049 n_inherit
= n_all_inherit
= 0;
6050 EXECUTE_IF_SET_IN_BITMAP (&lra_inheritance_pseudos
, 0, regno
, bi
)
6051 if (lra_reg_info
[regno
].restore_regno
>= 0)
6054 if (reg_renumber
[regno
] < 0
6055 /* If the original pseudo changed its allocation, just
6056 removing inheritance is dangerous as for changing
6057 allocation we used shorter live-ranges. */
6058 && reg_renumber
[lra_reg_info
[regno
].restore_regno
] < 0)
6059 bitmap_set_bit (&remove_pseudos
, regno
);
6063 if (lra_dump_file
!= NULL
&& n_all_inherit
!= 0)
6064 fprintf (lra_dump_file
, "Inherit %d out of %d (%.2f%%)\n",
6065 n_inherit
, n_all_inherit
,
6066 (double) n_inherit
/ n_all_inherit
* 100);
6067 n_split
= n_all_split
= 0;
6068 EXECUTE_IF_SET_IN_BITMAP (&lra_split_regs
, 0, regno
, bi
)
6069 if ((restore_regno
= lra_reg_info
[regno
].restore_regno
) >= 0)
6072 hard_regno
= (restore_regno
>= FIRST_PSEUDO_REGISTER
6073 ? reg_renumber
[restore_regno
] : restore_regno
);
6074 if (hard_regno
< 0 || reg_renumber
[regno
] == hard_regno
)
6075 bitmap_set_bit (&remove_pseudos
, regno
);
6079 if (lra_dump_file
!= NULL
)
6080 fprintf (lra_dump_file
, " Keep split r%d (orig=r%d)\n",
6081 regno
, restore_regno
);
6084 if (lra_dump_file
!= NULL
&& n_all_split
!= 0)
6085 fprintf (lra_dump_file
, "Split %d out of %d (%.2f%%)\n",
6086 n_split
, n_all_split
,
6087 (double) n_split
/ n_all_split
* 100);
6088 change_p
= remove_inheritance_pseudos (&remove_pseudos
);
6089 bitmap_clear (&remove_pseudos
);
6090 /* Clear restore_regnos. */
6091 EXECUTE_IF_SET_IN_BITMAP (&lra_inheritance_pseudos
, 0, regno
, bi
)
6092 lra_reg_info
[regno
].restore_regno
= -1;
6093 EXECUTE_IF_SET_IN_BITMAP (&lra_split_regs
, 0, regno
, bi
)
6094 lra_reg_info
[regno
].restore_regno
= -1;
6095 change_p
= undo_optional_reloads () || change_p
;