1 /* Code for RTL transformations to satisfy insn constraints.
2 Copyright (C) 2010-2015 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"
124 #include "hash-set.h"
126 #include "machmode.h"
128 #include "function.h"
131 #include "statistics.h"
132 #include "double-int.h"
134 #include "fixed-value.h"
136 #include "wide-int.h"
143 #include "emit-rtl.h"
148 #include "dominance.h"
151 #include "basic-block.h"
156 #include "rtl-error.h"
160 /* Value of LRA_CURR_RELOAD_NUM at the beginning of BB of the current
161 insn. Remember that LRA_CURR_RELOAD_NUM is the number of emitted
163 static int bb_reload_num
;
165 /* The current insn being processed and corresponding its single set
166 (NULL otherwise), its data (basic block, the insn data, the insn
167 static data, and the mode of each operand). */
168 static rtx_insn
*curr_insn
;
169 static rtx curr_insn_set
;
170 static basic_block curr_bb
;
171 static lra_insn_recog_data_t curr_id
;
172 static struct lra_static_insn_data
*curr_static_id
;
173 static machine_mode curr_operand_mode
[MAX_RECOG_OPERANDS
];
174 /* Mode of the register substituted by its equivalence with VOIDmode
175 (e.g. constant) and whose subreg is given operand of the current
176 insn. VOIDmode in all other cases. */
177 static machine_mode original_subreg_reg_mode
[MAX_RECOG_OPERANDS
];
181 /* Start numbers for new registers and insns at the current constraints
183 static int new_regno_start
;
184 static int new_insn_uid_start
;
186 /* If LOC is nonnull, strip any outer subreg from it. */
188 strip_subreg (rtx
*loc
)
190 return loc
&& GET_CODE (*loc
) == SUBREG
? &SUBREG_REG (*loc
) : loc
;
193 /* Return hard regno of REGNO or if it is was not assigned to a hard
194 register, use a hard register from its allocno class. */
196 get_try_hard_regno (int regno
)
199 enum reg_class rclass
;
201 if ((hard_regno
= regno
) >= FIRST_PSEUDO_REGISTER
)
202 hard_regno
= lra_get_regno_hard_regno (regno
);
205 rclass
= lra_get_allocno_class (regno
);
206 if (rclass
== NO_REGS
)
208 return ira_class_hard_regs
[rclass
][0];
211 /* Return final hard regno (plus offset) which will be after
212 elimination. We do this for matching constraints because the final
213 hard regno could have a different class. */
215 get_final_hard_regno (int hard_regno
, int offset
)
219 hard_regno
= lra_get_elimination_hard_regno (hard_regno
);
220 return hard_regno
+ offset
;
223 /* Return hard regno of X after removing subreg and making
224 elimination. If X is not a register or subreg of register, return
225 -1. For pseudo use its assignment. */
227 get_hard_regno (rtx x
)
230 int offset
, hard_regno
;
233 if (GET_CODE (x
) == SUBREG
)
234 reg
= SUBREG_REG (x
);
237 if ((hard_regno
= REGNO (reg
)) >= FIRST_PSEUDO_REGISTER
)
238 hard_regno
= lra_get_regno_hard_regno (hard_regno
);
242 if (GET_CODE (x
) == SUBREG
)
243 offset
+= subreg_regno_offset (hard_regno
, GET_MODE (reg
),
244 SUBREG_BYTE (x
), GET_MODE (x
));
245 return get_final_hard_regno (hard_regno
, offset
);
248 /* If REGNO is a hard register or has been allocated a hard register,
249 return the class of that register. If REGNO is a reload pseudo
250 created by the current constraints pass, return its allocno class.
251 Return NO_REGS otherwise. */
252 static enum reg_class
253 get_reg_class (int regno
)
257 if ((hard_regno
= regno
) >= FIRST_PSEUDO_REGISTER
)
258 hard_regno
= lra_get_regno_hard_regno (regno
);
261 hard_regno
= get_final_hard_regno (hard_regno
, 0);
262 return REGNO_REG_CLASS (hard_regno
);
264 if (regno
>= new_regno_start
)
265 return lra_get_allocno_class (regno
);
269 /* Return true if REG satisfies (or will satisfy) reg class constraint
270 CL. Use elimination first if REG is a hard register. If REG is a
271 reload pseudo created by this constraints pass, assume that it will
272 be allocated a hard register from its allocno class, but allow that
273 class to be narrowed to CL if it is currently a superset of CL.
275 If NEW_CLASS is nonnull, set *NEW_CLASS to the new allocno class of
276 REGNO (reg), or NO_REGS if no change in its class was needed. */
278 in_class_p (rtx reg
, enum reg_class cl
, enum reg_class
*new_class
)
280 enum reg_class rclass
, common_class
;
281 machine_mode reg_mode
;
282 int class_size
, hard_regno
, nregs
, i
, j
;
283 int regno
= REGNO (reg
);
285 if (new_class
!= NULL
)
286 *new_class
= NO_REGS
;
287 if (regno
< FIRST_PSEUDO_REGISTER
)
290 rtx
*final_loc
= &final_reg
;
292 lra_eliminate_reg_if_possible (final_loc
);
293 return TEST_HARD_REG_BIT (reg_class_contents
[cl
], REGNO (*final_loc
));
295 reg_mode
= GET_MODE (reg
);
296 rclass
= get_reg_class (regno
);
297 if (regno
< new_regno_start
298 /* Do not allow the constraints for reload instructions to
299 influence the classes of new pseudos. These reloads are
300 typically moves that have many alternatives, and restricting
301 reload pseudos for one alternative may lead to situations
302 where other reload pseudos are no longer allocatable. */
303 || (INSN_UID (curr_insn
) >= new_insn_uid_start
304 && curr_insn_set
!= NULL
305 && ((OBJECT_P (SET_SRC (curr_insn_set
))
306 && ! CONSTANT_P (SET_SRC (curr_insn_set
)))
307 || (GET_CODE (SET_SRC (curr_insn_set
)) == SUBREG
308 && OBJECT_P (SUBREG_REG (SET_SRC (curr_insn_set
)))
309 && ! CONSTANT_P (SUBREG_REG (SET_SRC (curr_insn_set
)))))))
310 /* When we don't know what class will be used finally for reload
311 pseudos, we use ALL_REGS. */
312 return ((regno
>= new_regno_start
&& rclass
== ALL_REGS
)
313 || (rclass
!= NO_REGS
&& ira_class_subset_p
[rclass
][cl
]
314 && ! hard_reg_set_subset_p (reg_class_contents
[cl
],
315 lra_no_alloc_regs
)));
318 common_class
= ira_reg_class_subset
[rclass
][cl
];
319 if (new_class
!= NULL
)
320 *new_class
= common_class
;
321 if (hard_reg_set_subset_p (reg_class_contents
[common_class
],
324 /* Check that there are enough allocatable regs. */
325 class_size
= ira_class_hard_regs_num
[common_class
];
326 for (i
= 0; i
< class_size
; i
++)
328 hard_regno
= ira_class_hard_regs
[common_class
][i
];
329 nregs
= hard_regno_nregs
[hard_regno
][reg_mode
];
332 for (j
= 0; j
< nregs
; j
++)
333 if (TEST_HARD_REG_BIT (lra_no_alloc_regs
, hard_regno
+ j
)
334 || ! TEST_HARD_REG_BIT (reg_class_contents
[common_class
],
344 /* Return true if REGNO satisfies a memory constraint. */
348 return get_reg_class (regno
) == NO_REGS
;
351 /* Return 1 if ADDR is a valid memory address for mode MODE in address
352 space AS, and check that each pseudo has the proper kind of hard
355 valid_address_p (machine_mode mode ATTRIBUTE_UNUSED
,
356 rtx addr
, addr_space_t as
)
358 #ifdef GO_IF_LEGITIMATE_ADDRESS
359 lra_assert (ADDR_SPACE_GENERIC_P (as
));
360 GO_IF_LEGITIMATE_ADDRESS (mode
, addr
, win
);
366 return targetm
.addr_space
.legitimate_address_p (mode
, addr
, 0, as
);
371 /* Temporarily eliminates registers in an address (for the lifetime of
373 class address_eliminator
{
375 address_eliminator (struct address_info
*ad
);
376 ~address_eliminator ();
379 struct address_info
*m_ad
;
387 address_eliminator::address_eliminator (struct address_info
*ad
)
389 m_base_loc (strip_subreg (ad
->base_term
)),
390 m_base_reg (NULL_RTX
),
391 m_index_loc (strip_subreg (ad
->index_term
)),
392 m_index_reg (NULL_RTX
)
394 if (m_base_loc
!= NULL
)
396 m_base_reg
= *m_base_loc
;
397 lra_eliminate_reg_if_possible (m_base_loc
);
398 if (m_ad
->base_term2
!= NULL
)
399 *m_ad
->base_term2
= *m_ad
->base_term
;
401 if (m_index_loc
!= NULL
)
403 m_index_reg
= *m_index_loc
;
404 lra_eliminate_reg_if_possible (m_index_loc
);
408 address_eliminator::~address_eliminator ()
410 if (m_base_loc
&& *m_base_loc
!= m_base_reg
)
412 *m_base_loc
= m_base_reg
;
413 if (m_ad
->base_term2
!= NULL
)
414 *m_ad
->base_term2
= *m_ad
->base_term
;
416 if (m_index_loc
&& *m_index_loc
!= m_index_reg
)
417 *m_index_loc
= m_index_reg
;
420 /* Return true if the eliminated form of AD is a legitimate target address. */
422 valid_address_p (struct address_info
*ad
)
424 address_eliminator
eliminator (ad
);
425 return valid_address_p (ad
->mode
, *ad
->outer
, ad
->as
);
428 /* Return true if the eliminated form of memory reference OP satisfies
429 extra memory constraint CONSTRAINT. */
431 satisfies_memory_constraint_p (rtx op
, enum constraint_num constraint
)
433 struct address_info ad
;
435 decompose_mem_address (&ad
, op
);
436 address_eliminator
eliminator (&ad
);
437 return constraint_satisfied_p (op
, constraint
);
440 /* Return true if the eliminated form of address AD satisfies extra
441 address constraint CONSTRAINT. */
443 satisfies_address_constraint_p (struct address_info
*ad
,
444 enum constraint_num constraint
)
446 address_eliminator
eliminator (ad
);
447 return constraint_satisfied_p (*ad
->outer
, constraint
);
450 /* Return true if the eliminated form of address OP satisfies extra
451 address constraint CONSTRAINT. */
453 satisfies_address_constraint_p (rtx op
, enum constraint_num constraint
)
455 struct address_info ad
;
457 decompose_lea_address (&ad
, &op
);
458 return satisfies_address_constraint_p (&ad
, constraint
);
461 /* Initiate equivalences for LRA. As we keep original equivalences
462 before any elimination, we need to make copies otherwise any change
463 in insns might change the equivalences. */
465 lra_init_equiv (void)
467 ira_expand_reg_equiv ();
468 for (int i
= FIRST_PSEUDO_REGISTER
; i
< max_reg_num (); i
++)
472 if ((res
= ira_reg_equiv
[i
].memory
) != NULL_RTX
)
473 ira_reg_equiv
[i
].memory
= copy_rtx (res
);
474 if ((res
= ira_reg_equiv
[i
].invariant
) != NULL_RTX
)
475 ira_reg_equiv
[i
].invariant
= copy_rtx (res
);
479 static rtx
loc_equivalence_callback (rtx
, const_rtx
, void *);
481 /* Update equivalence for REGNO. We need to this as the equivalence
482 might contain other pseudos which are changed by their
485 update_equiv (int regno
)
489 if ((x
= ira_reg_equiv
[regno
].memory
) != NULL_RTX
)
490 ira_reg_equiv
[regno
].memory
491 = simplify_replace_fn_rtx (x
, NULL_RTX
, loc_equivalence_callback
,
493 if ((x
= ira_reg_equiv
[regno
].invariant
) != NULL_RTX
)
494 ira_reg_equiv
[regno
].invariant
495 = simplify_replace_fn_rtx (x
, NULL_RTX
, loc_equivalence_callback
,
499 /* If we have decided to substitute X with another value, return that
500 value, otherwise return X. */
507 if (! REG_P (x
) || (regno
= REGNO (x
)) < FIRST_PSEUDO_REGISTER
508 || ! ira_reg_equiv
[regno
].defined_p
509 || ! ira_reg_equiv
[regno
].profitable_p
510 || lra_get_regno_hard_regno (regno
) >= 0)
512 if ((res
= ira_reg_equiv
[regno
].memory
) != NULL_RTX
)
514 if (targetm
.cannot_substitute_mem_equiv_p (res
))
518 if ((res
= ira_reg_equiv
[regno
].constant
) != NULL_RTX
)
520 if ((res
= ira_reg_equiv
[regno
].invariant
) != NULL_RTX
)
525 /* If we have decided to substitute X with the equivalent value,
526 return that value after elimination for INSN, otherwise return
529 get_equiv_with_elimination (rtx x
, rtx_insn
*insn
)
531 rtx res
= get_equiv (x
);
533 if (x
== res
|| CONSTANT_P (res
))
535 return lra_eliminate_regs_1 (insn
, res
, GET_MODE (res
),
536 0, false, false, true);
539 /* Set up curr_operand_mode. */
541 init_curr_operand_mode (void)
543 int nop
= curr_static_id
->n_operands
;
544 for (int i
= 0; i
< nop
; i
++)
546 machine_mode mode
= GET_MODE (*curr_id
->operand_loc
[i
]);
547 if (mode
== VOIDmode
)
549 /* The .md mode for address operands is the mode of the
550 addressed value rather than the mode of the address itself. */
551 if (curr_id
->icode
>= 0 && curr_static_id
->operand
[i
].is_address
)
554 mode
= curr_static_id
->operand
[i
].mode
;
556 curr_operand_mode
[i
] = mode
;
562 /* The page contains code to reuse input reloads. */
564 /* Structure describes input reload of the current insns. */
567 /* Reloaded value. */
569 /* Reload pseudo used. */
573 /* The number of elements in the following array. */
574 static int curr_insn_input_reloads_num
;
575 /* Array containing info about input reloads. It is used to find the
576 same input reload and reuse the reload pseudo in this case. */
577 static struct input_reload curr_insn_input_reloads
[LRA_MAX_INSN_RELOADS
];
579 /* Initiate data concerning reuse of input reloads for the current
582 init_curr_insn_input_reloads (void)
584 curr_insn_input_reloads_num
= 0;
587 /* Create a new pseudo using MODE, RCLASS, ORIGINAL or reuse already
588 created input reload pseudo (only if TYPE is not OP_OUT). Don't
589 reuse pseudo if IN_SUBREG_P is true and the reused pseudo should be
590 wrapped up in SUBREG. The result pseudo is returned through
591 RESULT_REG. Return TRUE if we created a new pseudo, FALSE if we
592 reused the already created input reload pseudo. Use TITLE to
593 describe new registers for debug purposes. */
595 get_reload_reg (enum op_type type
, machine_mode mode
, rtx original
,
596 enum reg_class rclass
, bool in_subreg_p
,
597 const char *title
, rtx
*result_reg
)
600 enum reg_class new_class
;
605 = lra_create_new_reg_with_unique_value (mode
, original
, rclass
, title
);
608 /* Prevent reuse value of expression with side effects,
609 e.g. volatile memory. */
610 if (! side_effects_p (original
))
611 for (i
= 0; i
< curr_insn_input_reloads_num
; i
++)
612 if (rtx_equal_p (curr_insn_input_reloads
[i
].input
, original
)
613 && in_class_p (curr_insn_input_reloads
[i
].reg
, rclass
, &new_class
))
615 rtx reg
= curr_insn_input_reloads
[i
].reg
;
617 /* If input is equal to original and both are VOIDmode,
618 GET_MODE (reg) might be still different from mode.
619 Ensure we don't return *result_reg with wrong mode. */
620 if (GET_MODE (reg
) != mode
)
624 if (GET_MODE_SIZE (GET_MODE (reg
)) < GET_MODE_SIZE (mode
))
626 reg
= lowpart_subreg (mode
, reg
, GET_MODE (reg
));
627 if (reg
== NULL_RTX
|| GET_CODE (reg
) != SUBREG
)
631 if (lra_dump_file
!= NULL
)
633 fprintf (lra_dump_file
, " Reuse r%d for reload ", regno
);
634 dump_value_slim (lra_dump_file
, original
, 1);
636 if (new_class
!= lra_get_allocno_class (regno
))
637 lra_change_class (regno
, new_class
, ", change to", false);
638 if (lra_dump_file
!= NULL
)
639 fprintf (lra_dump_file
, "\n");
642 *result_reg
= lra_create_new_reg (mode
, original
, rclass
, title
);
643 lra_assert (curr_insn_input_reloads_num
< LRA_MAX_INSN_RELOADS
);
644 curr_insn_input_reloads
[curr_insn_input_reloads_num
].input
= original
;
645 curr_insn_input_reloads
[curr_insn_input_reloads_num
++].reg
= *result_reg
;
651 /* The page contains code to extract memory address parts. */
653 /* Wrapper around REGNO_OK_FOR_INDEX_P, to allow pseudos. */
655 ok_for_index_p_nonstrict (rtx reg
)
657 unsigned regno
= REGNO (reg
);
659 return regno
>= FIRST_PSEUDO_REGISTER
|| REGNO_OK_FOR_INDEX_P (regno
);
662 /* A version of regno_ok_for_base_p for use here, when all pseudos
663 should count as OK. Arguments as for regno_ok_for_base_p. */
665 ok_for_base_p_nonstrict (rtx reg
, machine_mode mode
, addr_space_t as
,
666 enum rtx_code outer_code
, enum rtx_code index_code
)
668 unsigned regno
= REGNO (reg
);
670 if (regno
>= FIRST_PSEUDO_REGISTER
)
672 return ok_for_base_p_1 (regno
, mode
, as
, outer_code
, index_code
);
677 /* The page contains major code to choose the current insn alternative
678 and generate reloads for it. */
680 /* Return the offset from REGNO of the least significant register
683 This function is used to tell whether two registers satisfy
684 a matching constraint. (reg:MODE1 REGNO1) matches (reg:MODE2 REGNO2) if:
686 REGNO1 + lra_constraint_offset (REGNO1, MODE1)
687 == REGNO2 + lra_constraint_offset (REGNO2, MODE2) */
689 lra_constraint_offset (int regno
, machine_mode mode
)
691 lra_assert (regno
< FIRST_PSEUDO_REGISTER
);
692 if (WORDS_BIG_ENDIAN
&& GET_MODE_SIZE (mode
) > UNITS_PER_WORD
693 && SCALAR_INT_MODE_P (mode
))
694 return hard_regno_nregs
[regno
][mode
] - 1;
698 /* Like rtx_equal_p except that it allows a REG and a SUBREG to match
699 if they are the same hard reg, and has special hacks for
700 auto-increment and auto-decrement. This is specifically intended for
701 process_alt_operands to use in determining whether two operands
702 match. X is the operand whose number is the lower of the two.
704 It is supposed that X is the output operand and Y is the input
705 operand. Y_HARD_REGNO is the final hard regno of register Y or
706 register in subreg Y as we know it now. Otherwise, it is a
709 operands_match_p (rtx x
, rtx y
, int y_hard_regno
)
712 RTX_CODE code
= GET_CODE (x
);
717 if ((code
== REG
|| (code
== SUBREG
&& REG_P (SUBREG_REG (x
))))
718 && (REG_P (y
) || (GET_CODE (y
) == SUBREG
&& REG_P (SUBREG_REG (y
)))))
722 i
= get_hard_regno (x
);
726 if ((j
= y_hard_regno
) < 0)
729 i
+= lra_constraint_offset (i
, GET_MODE (x
));
730 j
+= lra_constraint_offset (j
, GET_MODE (y
));
735 /* If two operands must match, because they are really a single
736 operand of an assembler insn, then two post-increments are invalid
737 because the assembler insn would increment only once. On the
738 other hand, a post-increment matches ordinary indexing if the
739 post-increment is the output operand. */
740 if (code
== POST_DEC
|| code
== POST_INC
|| code
== POST_MODIFY
)
741 return operands_match_p (XEXP (x
, 0), y
, y_hard_regno
);
743 /* Two pre-increments are invalid because the assembler insn would
744 increment only once. On the other hand, a pre-increment matches
745 ordinary indexing if the pre-increment is the input operand. */
746 if (GET_CODE (y
) == PRE_DEC
|| GET_CODE (y
) == PRE_INC
747 || GET_CODE (y
) == PRE_MODIFY
)
748 return operands_match_p (x
, XEXP (y
, 0), -1);
752 if (code
== REG
&& GET_CODE (y
) == SUBREG
&& REG_P (SUBREG_REG (y
))
753 && x
== SUBREG_REG (y
))
755 if (GET_CODE (y
) == REG
&& code
== SUBREG
&& REG_P (SUBREG_REG (x
))
756 && SUBREG_REG (x
) == y
)
759 /* Now we have disposed of all the cases in which different rtx
761 if (code
!= GET_CODE (y
))
764 /* (MULT:SI x y) and (MULT:HI x y) are NOT equivalent. */
765 if (GET_MODE (x
) != GET_MODE (y
))
774 return LABEL_REF_LABEL (x
) == LABEL_REF_LABEL (y
);
776 return XSTR (x
, 0) == XSTR (y
, 0);
782 /* Compare the elements. If any pair of corresponding elements fail
783 to match, return false for the whole things. */
785 fmt
= GET_RTX_FORMAT (code
);
786 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
792 if (XWINT (x
, i
) != XWINT (y
, i
))
797 if (XINT (x
, i
) != XINT (y
, i
))
802 val
= operands_match_p (XEXP (x
, i
), XEXP (y
, i
), -1);
811 if (XVECLEN (x
, i
) != XVECLEN (y
, i
))
813 for (j
= XVECLEN (x
, i
) - 1; j
>= 0; --j
)
815 val
= operands_match_p (XVECEXP (x
, i
, j
), XVECEXP (y
, i
, j
), -1);
821 /* It is believed that rtx's at this level will never
822 contain anything but integers and other rtx's, except for
823 within LABEL_REFs and SYMBOL_REFs. */
831 /* True if X is a constant that can be forced into the constant pool.
832 MODE is the mode of the operand, or VOIDmode if not known. */
833 #define CONST_POOL_OK_P(MODE, X) \
834 ((MODE) != VOIDmode \
836 && GET_CODE (X) != HIGH \
837 && !targetm.cannot_force_const_mem (MODE, X))
839 /* True if C is a non-empty register class that has too few registers
840 to be safely used as a reload target class. */
841 #define SMALL_REGISTER_CLASS_P(C) \
842 (ira_class_hard_regs_num [(C)] == 1 \
843 || (ira_class_hard_regs_num [(C)] >= 1 \
844 && targetm.class_likely_spilled_p (C)))
846 /* If REG is a reload pseudo, try to make its class satisfying CL. */
848 narrow_reload_pseudo_class (rtx reg
, enum reg_class cl
)
850 enum reg_class rclass
;
852 /* Do not make more accurate class from reloads generated. They are
853 mostly moves with a lot of constraints. Making more accurate
854 class may results in very narrow class and impossibility of find
855 registers for several reloads of one insn. */
856 if (INSN_UID (curr_insn
) >= new_insn_uid_start
)
858 if (GET_CODE (reg
) == SUBREG
)
859 reg
= SUBREG_REG (reg
);
860 if (! REG_P (reg
) || (int) REGNO (reg
) < new_regno_start
)
862 if (in_class_p (reg
, cl
, &rclass
) && rclass
!= cl
)
863 lra_change_class (REGNO (reg
), rclass
, " Change to", true);
866 /* Generate reloads for matching OUT and INS (array of input operand
867 numbers with end marker -1) with reg class GOAL_CLASS. Add input
868 and output reloads correspondingly to the lists *BEFORE and *AFTER.
869 OUT might be negative. In this case we generate input reloads for
870 matched input operands INS. */
872 match_reload (signed char out
, signed char *ins
, enum reg_class goal_class
,
873 rtx_insn
**before
, rtx_insn
**after
)
876 rtx new_in_reg
, new_out_reg
, reg
, clobber
;
877 machine_mode inmode
, outmode
;
878 rtx in_rtx
= *curr_id
->operand_loc
[ins
[0]];
879 rtx out_rtx
= out
< 0 ? in_rtx
: *curr_id
->operand_loc
[out
];
881 inmode
= curr_operand_mode
[ins
[0]];
882 outmode
= out
< 0 ? inmode
: curr_operand_mode
[out
];
883 push_to_sequence (*before
);
884 if (inmode
!= outmode
)
886 if (GET_MODE_SIZE (inmode
) > GET_MODE_SIZE (outmode
))
889 = lra_create_new_reg_with_unique_value (inmode
, in_rtx
,
891 if (SCALAR_INT_MODE_P (inmode
))
892 new_out_reg
= gen_lowpart_SUBREG (outmode
, reg
);
894 new_out_reg
= gen_rtx_SUBREG (outmode
, reg
, 0);
895 LRA_SUBREG_P (new_out_reg
) = 1;
896 /* If the input reg is dying here, we can use the same hard
897 register for REG and IN_RTX. We do it only for original
898 pseudos as reload pseudos can die although original
899 pseudos still live where reload pseudos dies. */
900 if (REG_P (in_rtx
) && (int) REGNO (in_rtx
) < lra_new_regno_start
901 && find_regno_note (curr_insn
, REG_DEAD
, REGNO (in_rtx
)))
902 lra_assign_reg_val (REGNO (in_rtx
), REGNO (reg
));
907 = lra_create_new_reg_with_unique_value (outmode
, out_rtx
,
909 if (SCALAR_INT_MODE_P (outmode
))
910 new_in_reg
= gen_lowpart_SUBREG (inmode
, reg
);
912 new_in_reg
= gen_rtx_SUBREG (inmode
, reg
, 0);
913 /* NEW_IN_REG is non-paradoxical subreg. We don't want
914 NEW_OUT_REG living above. We add clobber clause for
915 this. This is just a temporary clobber. We can remove
916 it at the end of LRA work. */
917 clobber
= emit_clobber (new_out_reg
);
918 LRA_TEMP_CLOBBER_P (PATTERN (clobber
)) = 1;
919 LRA_SUBREG_P (new_in_reg
) = 1;
920 if (GET_CODE (in_rtx
) == SUBREG
)
922 rtx subreg_reg
= SUBREG_REG (in_rtx
);
924 /* If SUBREG_REG is dying here and sub-registers IN_RTX
925 and NEW_IN_REG are similar, we can use the same hard
926 register for REG and SUBREG_REG. */
927 if (REG_P (subreg_reg
)
928 && (int) REGNO (subreg_reg
) < lra_new_regno_start
929 && GET_MODE (subreg_reg
) == outmode
930 && SUBREG_BYTE (in_rtx
) == SUBREG_BYTE (new_in_reg
)
931 && find_regno_note (curr_insn
, REG_DEAD
, REGNO (subreg_reg
)))
932 lra_assign_reg_val (REGNO (subreg_reg
), REGNO (reg
));
938 /* Pseudos have values -- see comments for lra_reg_info.
939 Different pseudos with the same value do not conflict even if
940 they live in the same place. When we create a pseudo we
941 assign value of original pseudo (if any) from which we
942 created the new pseudo. If we create the pseudo from the
943 input pseudo, the new pseudo will no conflict with the input
944 pseudo which is wrong when the input pseudo lives after the
945 insn and as the new pseudo value is changed by the insn
946 output. Therefore we create the new pseudo from the output.
948 We cannot reuse the current output register because we might
949 have a situation like "a <- a op b", where the constraints
950 force the second input operand ("b") to match the output
951 operand ("a"). "b" must then be copied into a new register
952 so that it doesn't clobber the current value of "a". */
954 new_in_reg
= new_out_reg
955 = lra_create_new_reg_with_unique_value (outmode
, out_rtx
,
958 /* In operand can be got from transformations before processing insn
959 constraints. One example of such transformations is subreg
960 reloading (see function simplify_operand_subreg). The new
961 pseudos created by the transformations might have inaccurate
962 class (ALL_REGS) and we should make their classes more
964 narrow_reload_pseudo_class (in_rtx
, goal_class
);
965 lra_emit_move (copy_rtx (new_in_reg
), in_rtx
);
966 *before
= get_insns ();
968 for (i
= 0; (in
= ins
[i
]) >= 0; i
++)
971 (GET_MODE (*curr_id
->operand_loc
[in
]) == VOIDmode
972 || GET_MODE (new_in_reg
) == GET_MODE (*curr_id
->operand_loc
[in
]));
973 *curr_id
->operand_loc
[in
] = new_in_reg
;
975 lra_update_dups (curr_id
, ins
);
978 /* See a comment for the input operand above. */
979 narrow_reload_pseudo_class (out_rtx
, goal_class
);
980 if (find_reg_note (curr_insn
, REG_UNUSED
, out_rtx
) == NULL_RTX
)
983 lra_emit_move (out_rtx
, copy_rtx (new_out_reg
));
985 *after
= get_insns ();
988 *curr_id
->operand_loc
[out
] = new_out_reg
;
989 lra_update_dup (curr_id
, out
);
992 /* Return register class which is union of all reg classes in insn
993 constraint alternative string starting with P. */
994 static enum reg_class
995 reg_class_from_constraints (const char *p
)
998 enum reg_class op_class
= NO_REGS
;
1001 switch ((c
= *p
, len
= CONSTRAINT_LEN (c
, p
)), c
)
1008 op_class
= reg_class_subunion
[op_class
][GENERAL_REGS
];
1012 enum constraint_num cn
= lookup_constraint (p
);
1013 enum reg_class cl
= reg_class_for_constraint (cn
);
1016 if (insn_extra_address_constraint (cn
))
1018 = (reg_class_subunion
1019 [op_class
][base_reg_class (VOIDmode
, ADDR_SPACE_GENERIC
,
1020 ADDRESS
, SCRATCH
)]);
1024 op_class
= reg_class_subunion
[op_class
][cl
];
1027 while ((p
+= len
), c
);
1031 /* If OP is a register, return the class of the register as per
1032 get_reg_class, otherwise return NO_REGS. */
1033 static inline enum reg_class
1034 get_op_class (rtx op
)
1036 return REG_P (op
) ? get_reg_class (REGNO (op
)) : NO_REGS
;
1039 /* Return generated insn mem_pseudo:=val if TO_P or val:=mem_pseudo
1040 otherwise. If modes of MEM_PSEUDO and VAL are different, use
1041 SUBREG for VAL to make them equal. */
1043 emit_spill_move (bool to_p
, rtx mem_pseudo
, rtx val
)
1045 if (GET_MODE (mem_pseudo
) != GET_MODE (val
))
1047 /* Usually size of mem_pseudo is greater than val size but in
1048 rare cases it can be less as it can be defined by target
1049 dependent macro HARD_REGNO_CALLER_SAVE_MODE. */
1052 val
= gen_rtx_SUBREG (GET_MODE (mem_pseudo
),
1053 GET_CODE (val
) == SUBREG
? SUBREG_REG (val
) : val
,
1055 LRA_SUBREG_P (val
) = 1;
1059 mem_pseudo
= gen_lowpart_SUBREG (GET_MODE (val
), mem_pseudo
);
1060 LRA_SUBREG_P (mem_pseudo
) = 1;
1063 return as_a
<rtx_insn
*> (to_p
1064 ? gen_move_insn (mem_pseudo
, val
)
1065 : gen_move_insn (val
, mem_pseudo
));
1068 /* Process a special case insn (register move), return true if we
1069 don't need to process it anymore. INSN should be a single set
1070 insn. Set up that RTL was changed through CHANGE_P and macro
1071 SECONDARY_MEMORY_NEEDED says to use secondary memory through
1074 check_and_process_move (bool *change_p
, bool *sec_mem_p ATTRIBUTE_UNUSED
)
1077 rtx dest
, src
, dreg
, sreg
, old_sreg
, new_reg
, scratch_reg
;
1079 enum reg_class dclass
, sclass
, secondary_class
;
1080 machine_mode sreg_mode
;
1081 secondary_reload_info sri
;
1083 lra_assert (curr_insn_set
!= NULL_RTX
);
1084 dreg
= dest
= SET_DEST (curr_insn_set
);
1085 sreg
= src
= SET_SRC (curr_insn_set
);
1086 if (GET_CODE (dest
) == SUBREG
)
1087 dreg
= SUBREG_REG (dest
);
1088 if (GET_CODE (src
) == SUBREG
)
1089 sreg
= SUBREG_REG (src
);
1090 if (! (REG_P (dreg
) || MEM_P (dreg
)) || ! (REG_P (sreg
) || MEM_P (sreg
)))
1092 sclass
= dclass
= NO_REGS
;
1094 dclass
= get_reg_class (REGNO (dreg
));
1095 if (dclass
== ALL_REGS
)
1096 /* ALL_REGS is used for new pseudos created by transformations
1097 like reload of SUBREG_REG (see function
1098 simplify_operand_subreg). We don't know their class yet. We
1099 should figure out the class from processing the insn
1100 constraints not in this fast path function. Even if ALL_REGS
1101 were a right class for the pseudo, secondary_... hooks usually
1102 are not define for ALL_REGS. */
1104 sreg_mode
= GET_MODE (sreg
);
1107 sclass
= get_reg_class (REGNO (sreg
));
1108 if (sclass
== ALL_REGS
)
1109 /* See comments above. */
1111 if (sclass
== NO_REGS
&& dclass
== NO_REGS
)
1113 #ifdef SECONDARY_MEMORY_NEEDED
1114 if (SECONDARY_MEMORY_NEEDED (sclass
, dclass
, GET_MODE (src
))
1115 #ifdef SECONDARY_MEMORY_NEEDED_MODE
1116 && ((sclass
!= NO_REGS
&& dclass
!= NO_REGS
)
1117 || GET_MODE (src
) != SECONDARY_MEMORY_NEEDED_MODE (GET_MODE (src
)))
1125 if (! REG_P (dreg
) || ! REG_P (sreg
))
1127 sri
.prev_sri
= NULL
;
1128 sri
.icode
= CODE_FOR_nothing
;
1130 secondary_class
= NO_REGS
;
1131 /* Set up hard register for a reload pseudo for hook
1132 secondary_reload because some targets just ignore unassigned
1133 pseudos in the hook. */
1134 if (dclass
!= NO_REGS
&& lra_get_regno_hard_regno (REGNO (dreg
)) < 0)
1136 dregno
= REGNO (dreg
);
1137 reg_renumber
[dregno
] = ira_class_hard_regs
[dclass
][0];
1141 if (sclass
!= NO_REGS
&& lra_get_regno_hard_regno (REGNO (sreg
)) < 0)
1143 sregno
= REGNO (sreg
);
1144 reg_renumber
[sregno
] = ira_class_hard_regs
[sclass
][0];
1148 if (sclass
!= NO_REGS
)
1150 = (enum reg_class
) targetm
.secondary_reload (false, dest
,
1151 (reg_class_t
) sclass
,
1152 GET_MODE (src
), &sri
);
1153 if (sclass
== NO_REGS
1154 || ((secondary_class
!= NO_REGS
|| sri
.icode
!= CODE_FOR_nothing
)
1155 && dclass
!= NO_REGS
))
1157 enum reg_class old_sclass
= secondary_class
;
1158 secondary_reload_info old_sri
= sri
;
1160 sri
.prev_sri
= NULL
;
1161 sri
.icode
= CODE_FOR_nothing
;
1164 = (enum reg_class
) targetm
.secondary_reload (true, sreg
,
1165 (reg_class_t
) dclass
,
1167 /* Check the target hook consistency. */
1169 ((secondary_class
== NO_REGS
&& sri
.icode
== CODE_FOR_nothing
)
1170 || (old_sclass
== NO_REGS
&& old_sri
.icode
== CODE_FOR_nothing
)
1171 || (secondary_class
== old_sclass
&& sri
.icode
== old_sri
.icode
));
1174 reg_renumber
[sregno
] = -1;
1176 reg_renumber
[dregno
] = -1;
1177 if (secondary_class
== NO_REGS
&& sri
.icode
== CODE_FOR_nothing
)
1181 if (secondary_class
!= NO_REGS
)
1182 new_reg
= lra_create_new_reg_with_unique_value (sreg_mode
, NULL_RTX
,
1186 if (old_sreg
!= sreg
)
1187 sreg
= copy_rtx (sreg
);
1188 if (sri
.icode
== CODE_FOR_nothing
)
1189 lra_emit_move (new_reg
, sreg
);
1192 enum reg_class scratch_class
;
1194 scratch_class
= (reg_class_from_constraints
1195 (insn_data
[sri
.icode
].operand
[2].constraint
));
1196 scratch_reg
= (lra_create_new_reg_with_unique_value
1197 (insn_data
[sri
.icode
].operand
[2].mode
, NULL_RTX
,
1198 scratch_class
, "scratch"));
1199 emit_insn (GEN_FCN (sri
.icode
) (new_reg
!= NULL_RTX
? new_reg
: dest
,
1200 sreg
, scratch_reg
));
1202 before
= get_insns ();
1204 lra_process_new_insns (curr_insn
, before
, NULL
, "Inserting the move");
1205 if (new_reg
!= NULL_RTX
)
1207 if (GET_CODE (src
) == SUBREG
)
1208 SUBREG_REG (src
) = new_reg
;
1210 SET_SRC (curr_insn_set
) = new_reg
;
1214 if (lra_dump_file
!= NULL
)
1216 fprintf (lra_dump_file
, "Deleting move %u\n", INSN_UID (curr_insn
));
1217 dump_insn_slim (lra_dump_file
, curr_insn
);
1219 lra_set_insn_deleted (curr_insn
);
1225 /* The following data describe the result of process_alt_operands.
1226 The data are used in curr_insn_transform to generate reloads. */
1228 /* The chosen reg classes which should be used for the corresponding
1230 static enum reg_class goal_alt
[MAX_RECOG_OPERANDS
];
1231 /* True if the operand should be the same as another operand and that
1232 other operand does not need a reload. */
1233 static bool goal_alt_match_win
[MAX_RECOG_OPERANDS
];
1234 /* True if the operand does not need a reload. */
1235 static bool goal_alt_win
[MAX_RECOG_OPERANDS
];
1236 /* True if the operand can be offsetable memory. */
1237 static bool goal_alt_offmemok
[MAX_RECOG_OPERANDS
];
1238 /* The number of an operand to which given operand can be matched to. */
1239 static int goal_alt_matches
[MAX_RECOG_OPERANDS
];
1240 /* The number of elements in the following array. */
1241 static int goal_alt_dont_inherit_ops_num
;
1242 /* Numbers of operands whose reload pseudos should not be inherited. */
1243 static int goal_alt_dont_inherit_ops
[MAX_RECOG_OPERANDS
];
1244 /* True if the insn commutative operands should be swapped. */
1245 static bool goal_alt_swapped
;
1246 /* The chosen insn alternative. */
1247 static int goal_alt_number
;
1249 /* The following five variables are used to choose the best insn
1250 alternative. They reflect final characteristics of the best
1253 /* Number of necessary reloads and overall cost reflecting the
1254 previous value and other unpleasantness of the best alternative. */
1255 static int best_losers
, best_overall
;
1256 /* Overall number hard registers used for reloads. For example, on
1257 some targets we need 2 general registers to reload DFmode and only
1258 one floating point register. */
1259 static int best_reload_nregs
;
1260 /* Overall number reflecting distances of previous reloading the same
1261 value. The distances are counted from the current BB start. It is
1262 used to improve inheritance chances. */
1263 static int best_reload_sum
;
1265 /* True if the current insn should have no correspondingly input or
1267 static bool no_input_reloads_p
, no_output_reloads_p
;
1269 /* True if we swapped the commutative operands in the current
1271 static int curr_swapped
;
1273 /* if CHECK_ONLY_P is false, arrange for address element *LOC to be a
1274 register of class CL. Add any input reloads to list BEFORE. AFTER
1275 is nonnull if *LOC is an automodified value; handle that case by
1276 adding the required output reloads to list AFTER. Return true if
1277 the RTL was changed.
1279 if CHECK_ONLY_P is true, check that the *LOC is a correct address
1280 register. Return false if the address register is correct. */
1282 process_addr_reg (rtx
*loc
, bool check_only_p
, rtx_insn
**before
, rtx_insn
**after
,
1286 enum reg_class rclass
, new_class
;
1290 bool subreg_p
, before_p
= false;
1292 subreg_p
= GET_CODE (*loc
) == SUBREG
;
1294 loc
= &SUBREG_REG (*loc
);
1296 mode
= GET_MODE (reg
);
1301 /* Always reload memory in an address even if the target supports
1303 new_reg
= lra_create_new_reg_with_unique_value (mode
, reg
, cl
, "address");
1308 regno
= REGNO (reg
);
1309 rclass
= get_reg_class (regno
);
1311 && (*loc
= get_equiv_with_elimination (reg
, curr_insn
)) != reg
)
1313 if (lra_dump_file
!= NULL
)
1315 fprintf (lra_dump_file
,
1316 "Changing pseudo %d in address of insn %u on equiv ",
1317 REGNO (reg
), INSN_UID (curr_insn
));
1318 dump_value_slim (lra_dump_file
, *loc
, 1);
1319 fprintf (lra_dump_file
, "\n");
1321 *loc
= copy_rtx (*loc
);
1323 if (*loc
!= reg
|| ! in_class_p (reg
, cl
, &new_class
))
1328 if (get_reload_reg (after
== NULL
? OP_IN
: OP_INOUT
,
1329 mode
, reg
, cl
, subreg_p
, "address", &new_reg
))
1332 else if (new_class
!= NO_REGS
&& rclass
!= new_class
)
1336 lra_change_class (regno
, new_class
, " Change to", true);
1344 push_to_sequence (*before
);
1345 lra_emit_move (new_reg
, reg
);
1346 *before
= get_insns ();
1353 lra_emit_move (reg
, new_reg
);
1355 *after
= get_insns ();
1361 /* Insert move insn in simplify_operand_subreg. BEFORE returns
1362 the insn to be inserted before curr insn. AFTER returns the
1363 the insn to be inserted after curr insn. ORIGREG and NEWREG
1364 are the original reg and new reg for reload. */
1366 insert_move_for_subreg (rtx_insn
**before
, rtx_insn
**after
, rtx origreg
,
1371 push_to_sequence (*before
);
1372 lra_emit_move (newreg
, origreg
);
1373 *before
= get_insns ();
1379 lra_emit_move (origreg
, newreg
);
1381 *after
= get_insns ();
1386 static int valid_address_p (machine_mode mode
, rtx addr
, addr_space_t as
);
1388 /* Make reloads for subreg in operand NOP with internal subreg mode
1389 REG_MODE, add new reloads for further processing. Return true if
1390 any change was done. */
1392 simplify_operand_subreg (int nop
, machine_mode reg_mode
)
1395 rtx_insn
*before
, *after
;
1396 machine_mode mode
, innermode
;
1398 rtx operand
= *curr_id
->operand_loc
[nop
];
1399 enum reg_class regclass
;
1402 before
= after
= NULL
;
1404 if (GET_CODE (operand
) != SUBREG
)
1407 mode
= GET_MODE (operand
);
1408 reg
= SUBREG_REG (operand
);
1409 innermode
= GET_MODE (reg
);
1410 type
= curr_static_id
->operand
[nop
].type
;
1411 /* If we change address for paradoxical subreg of memory, the
1412 address might violate the necessary alignment or the access might
1413 be slow. So take this into consideration. We should not worry
1414 about access beyond allocated memory for paradoxical memory
1415 subregs as we don't substitute such equiv memory (see processing
1416 equivalences in function lra_constraints) and because for spilled
1417 pseudos we allocate stack memory enough for the biggest
1418 corresponding paradoxical subreg. */
1420 && (! SLOW_UNALIGNED_ACCESS (mode
, MEM_ALIGN (reg
))
1421 || MEM_ALIGN (reg
) >= GET_MODE_ALIGNMENT (mode
)))
1423 rtx subst
, old
= *curr_id
->operand_loc
[nop
];
1425 alter_subreg (curr_id
->operand_loc
[nop
], false);
1426 subst
= *curr_id
->operand_loc
[nop
];
1427 lra_assert (MEM_P (subst
));
1428 if (! valid_address_p (innermode
, XEXP (reg
, 0),
1429 MEM_ADDR_SPACE (reg
))
1430 || valid_address_p (GET_MODE (subst
), XEXP (subst
, 0),
1431 MEM_ADDR_SPACE (subst
)))
1433 /* If the address was valid and became invalid, prefer to reload
1434 the memory. Typical case is when the index scale should
1435 correspond the memory. */
1436 *curr_id
->operand_loc
[nop
] = old
;
1438 else if (REG_P (reg
) && REGNO (reg
) < FIRST_PSEUDO_REGISTER
)
1440 alter_subreg (curr_id
->operand_loc
[nop
], false);
1443 else if (CONSTANT_P (reg
))
1445 /* Try to simplify subreg of constant. It is usually result of
1446 equivalence substitution. */
1447 if (innermode
== VOIDmode
1448 && (innermode
= original_subreg_reg_mode
[nop
]) == VOIDmode
)
1449 innermode
= curr_static_id
->operand
[nop
].mode
;
1450 if ((new_reg
= simplify_subreg (mode
, reg
, innermode
,
1451 SUBREG_BYTE (operand
))) != NULL_RTX
)
1453 *curr_id
->operand_loc
[nop
] = new_reg
;
1457 /* Put constant into memory when we have mixed modes. It generates
1458 a better code in most cases as it does not need a secondary
1459 reload memory. It also prevents LRA looping when LRA is using
1460 secondary reload memory again and again. */
1461 if (CONSTANT_P (reg
) && CONST_POOL_OK_P (reg_mode
, reg
)
1462 && SCALAR_INT_MODE_P (reg_mode
) != SCALAR_INT_MODE_P (mode
))
1464 SUBREG_REG (operand
) = force_const_mem (reg_mode
, reg
);
1465 alter_subreg (curr_id
->operand_loc
[nop
], false);
1468 /* Force a reload of the SUBREG_REG if this is a constant or PLUS or
1469 if there may be a problem accessing OPERAND in the outer
1472 && REGNO (reg
) >= FIRST_PSEUDO_REGISTER
1473 && (hard_regno
= lra_get_regno_hard_regno (REGNO (reg
))) >= 0
1474 /* Don't reload paradoxical subregs because we could be looping
1475 having repeatedly final regno out of hard regs range. */
1476 && (hard_regno_nregs
[hard_regno
][innermode
]
1477 >= hard_regno_nregs
[hard_regno
][mode
])
1478 && simplify_subreg_regno (hard_regno
, innermode
,
1479 SUBREG_BYTE (operand
), mode
) < 0
1480 /* Don't reload subreg for matching reload. It is actually
1481 valid subreg in LRA. */
1482 && ! LRA_SUBREG_P (operand
))
1483 || CONSTANT_P (reg
) || GET_CODE (reg
) == PLUS
|| MEM_P (reg
))
1485 enum reg_class rclass
;
1488 /* There is a big probability that we will get the same class
1489 for the new pseudo and we will get the same insn which
1490 means infinite looping. So spill the new pseudo. */
1493 /* The class will be defined later in curr_insn_transform. */
1495 = (enum reg_class
) targetm
.preferred_reload_class (reg
, ALL_REGS
);
1497 if (get_reload_reg (curr_static_id
->operand
[nop
].type
, reg_mode
, reg
,
1498 rclass
, TRUE
, "subreg reg", &new_reg
))
1500 bool insert_before
, insert_after
;
1501 bitmap_set_bit (&lra_subreg_reload_pseudos
, REGNO (new_reg
));
1503 insert_before
= (type
!= OP_OUT
1504 || GET_MODE_SIZE (innermode
) > GET_MODE_SIZE (mode
));
1505 insert_after
= (type
!= OP_IN
);
1506 insert_move_for_subreg (insert_before
? &before
: NULL
,
1507 insert_after
? &after
: NULL
,
1510 SUBREG_REG (operand
) = new_reg
;
1511 lra_process_new_insns (curr_insn
, before
, after
,
1512 "Inserting subreg reload");
1515 /* Force a reload for a paradoxical subreg. For paradoxical subreg,
1516 IRA allocates hardreg to the inner pseudo reg according to its mode
1517 instead of the outermode, so the size of the hardreg may not be enough
1518 to contain the outermode operand, in that case we may need to insert
1519 reload for the reg. For the following two types of paradoxical subreg,
1520 we need to insert reload:
1521 1. If the op_type is OP_IN, and the hardreg could not be paired with
1522 other hardreg to contain the outermode operand
1523 (checked by in_hard_reg_set_p), we need to insert the reload.
1524 2. If the op_type is OP_OUT or OP_INOUT.
1526 Here is a paradoxical subreg example showing how the reload is generated:
1528 (insn 5 4 7 2 (set (reg:TI 106 [ __comp ])
1529 (subreg:TI (reg:DI 107 [ __comp ]) 0)) {*movti_internal_rex64}
1531 In IRA, reg107 is allocated to a DImode hardreg. We use x86-64 as example
1532 here, if reg107 is assigned to hardreg R15, because R15 is the last
1533 hardreg, compiler cannot find another hardreg to pair with R15 to
1534 contain TImode data. So we insert a TImode reload reg180 for it.
1535 After reload is inserted:
1537 (insn 283 0 0 (set (subreg:DI (reg:TI 180 [orig:107 __comp ] [107]) 0)
1538 (reg:DI 107 [ __comp ])) -1
1539 (insn 5 4 7 2 (set (reg:TI 106 [ __comp ])
1540 (subreg:TI (reg:TI 180 [orig:107 __comp ] [107]) 0)) {*movti_internal_rex64}
1542 Two reload hard registers will be allocated to reg180 to save TImode data
1544 else if (REG_P (reg
)
1545 && REGNO (reg
) >= FIRST_PSEUDO_REGISTER
1546 && (hard_regno
= lra_get_regno_hard_regno (REGNO (reg
))) >= 0
1547 && (hard_regno_nregs
[hard_regno
][innermode
]
1548 < hard_regno_nregs
[hard_regno
][mode
])
1549 && (regclass
= lra_get_allocno_class (REGNO (reg
)))
1551 || !in_hard_reg_set_p (reg_class_contents
[regclass
],
1554 /* The class will be defined later in curr_insn_transform. */
1555 enum reg_class rclass
1556 = (enum reg_class
) targetm
.preferred_reload_class (reg
, ALL_REGS
);
1558 if (get_reload_reg (curr_static_id
->operand
[nop
].type
, mode
, reg
,
1559 rclass
, TRUE
, "paradoxical subreg", &new_reg
))
1562 bool insert_before
, insert_after
;
1564 PUT_MODE (new_reg
, mode
);
1565 subreg
= simplify_gen_subreg (innermode
, new_reg
, mode
, 0);
1566 bitmap_set_bit (&lra_subreg_reload_pseudos
, REGNO (new_reg
));
1568 insert_before
= (type
!= OP_OUT
);
1569 insert_after
= (type
!= OP_IN
);
1570 insert_move_for_subreg (insert_before
? &before
: NULL
,
1571 insert_after
? &after
: NULL
,
1574 SUBREG_REG (operand
) = new_reg
;
1575 lra_process_new_insns (curr_insn
, before
, after
,
1576 "Inserting paradoxical subreg reload");
1582 /* Return TRUE if X refers for a hard register from SET. */
1584 uses_hard_regs_p (rtx x
, HARD_REG_SET set
)
1586 int i
, j
, x_hard_regno
;
1593 code
= GET_CODE (x
);
1594 mode
= GET_MODE (x
);
1598 code
= GET_CODE (x
);
1599 if (GET_MODE_SIZE (GET_MODE (x
)) > GET_MODE_SIZE (mode
))
1600 mode
= GET_MODE (x
);
1605 x_hard_regno
= get_hard_regno (x
);
1606 return (x_hard_regno
>= 0
1607 && overlaps_hard_reg_set_p (set
, mode
, x_hard_regno
));
1611 struct address_info ad
;
1613 decompose_mem_address (&ad
, x
);
1614 if (ad
.base_term
!= NULL
&& uses_hard_regs_p (*ad
.base_term
, set
))
1616 if (ad
.index_term
!= NULL
&& uses_hard_regs_p (*ad
.index_term
, set
))
1619 fmt
= GET_RTX_FORMAT (code
);
1620 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
1624 if (uses_hard_regs_p (XEXP (x
, i
), set
))
1627 else if (fmt
[i
] == 'E')
1629 for (j
= XVECLEN (x
, i
) - 1; j
>= 0; j
--)
1630 if (uses_hard_regs_p (XVECEXP (x
, i
, j
), set
))
1637 /* Return true if OP is a spilled pseudo. */
1639 spilled_pseudo_p (rtx op
)
1642 && REGNO (op
) >= FIRST_PSEUDO_REGISTER
&& in_mem_p (REGNO (op
)));
1645 /* Return true if X is a general constant. */
1647 general_constant_p (rtx x
)
1649 return CONSTANT_P (x
) && (! flag_pic
|| LEGITIMATE_PIC_OPERAND_P (x
));
1653 reg_in_class_p (rtx reg
, enum reg_class cl
)
1656 return get_reg_class (REGNO (reg
)) == NO_REGS
;
1657 return in_class_p (reg
, cl
, NULL
);
1660 /* Return true if SET of RCLASS contains no hard regs which can be
1663 prohibited_class_reg_set_mode_p (enum reg_class rclass
,
1665 enum machine_mode mode
)
1669 lra_assert (hard_reg_set_subset_p (set
, reg_class_contents
[rclass
]));
1670 COPY_HARD_REG_SET (temp
, set
);
1671 AND_COMPL_HARD_REG_SET (temp
, lra_no_alloc_regs
);
1672 return (hard_reg_set_subset_p
1673 (temp
, ira_prohibited_class_mode_regs
[rclass
][mode
]));
1676 /* Major function to choose the current insn alternative and what
1677 operands should be reloaded and how. If ONLY_ALTERNATIVE is not
1678 negative we should consider only this alternative. Return false if
1679 we can not choose the alternative or find how to reload the
1682 process_alt_operands (int only_alternative
)
1685 int nop
, overall
, nalt
;
1686 int n_alternatives
= curr_static_id
->n_alternatives
;
1687 int n_operands
= curr_static_id
->n_operands
;
1688 /* LOSERS counts the operands that don't fit this alternative and
1689 would require loading. */
1691 /* REJECT is a count of how undesirable this alternative says it is
1692 if any reloading is required. If the alternative matches exactly
1693 then REJECT is ignored, but otherwise it gets this much counted
1694 against it in addition to the reloading needed. */
1697 /* The number of elements in the following array. */
1698 int early_clobbered_regs_num
;
1699 /* Numbers of operands which are early clobber registers. */
1700 int early_clobbered_nops
[MAX_RECOG_OPERANDS
];
1701 enum reg_class curr_alt
[MAX_RECOG_OPERANDS
];
1702 HARD_REG_SET curr_alt_set
[MAX_RECOG_OPERANDS
];
1703 bool curr_alt_match_win
[MAX_RECOG_OPERANDS
];
1704 bool curr_alt_win
[MAX_RECOG_OPERANDS
];
1705 bool curr_alt_offmemok
[MAX_RECOG_OPERANDS
];
1706 int curr_alt_matches
[MAX_RECOG_OPERANDS
];
1707 /* The number of elements in the following array. */
1708 int curr_alt_dont_inherit_ops_num
;
1709 /* Numbers of operands whose reload pseudos should not be inherited. */
1710 int curr_alt_dont_inherit_ops
[MAX_RECOG_OPERANDS
];
1712 /* The register when the operand is a subreg of register, otherwise the
1714 rtx no_subreg_reg_operand
[MAX_RECOG_OPERANDS
];
1715 /* The register if the operand is a register or subreg of register,
1717 rtx operand_reg
[MAX_RECOG_OPERANDS
];
1718 int hard_regno
[MAX_RECOG_OPERANDS
];
1719 machine_mode biggest_mode
[MAX_RECOG_OPERANDS
];
1720 int reload_nregs
, reload_sum
;
1724 /* Calculate some data common for all alternatives to speed up the
1726 for (nop
= 0; nop
< n_operands
; nop
++)
1730 op
= no_subreg_reg_operand
[nop
] = *curr_id
->operand_loc
[nop
];
1731 /* The real hard regno of the operand after the allocation. */
1732 hard_regno
[nop
] = get_hard_regno (op
);
1734 operand_reg
[nop
] = reg
= op
;
1735 biggest_mode
[nop
] = GET_MODE (op
);
1736 if (GET_CODE (op
) == SUBREG
)
1738 operand_reg
[nop
] = reg
= SUBREG_REG (op
);
1739 if (GET_MODE_SIZE (biggest_mode
[nop
])
1740 < GET_MODE_SIZE (GET_MODE (reg
)))
1741 biggest_mode
[nop
] = GET_MODE (reg
);
1744 operand_reg
[nop
] = NULL_RTX
;
1745 else if (REGNO (reg
) >= FIRST_PSEUDO_REGISTER
1746 || ((int) REGNO (reg
)
1747 == lra_get_elimination_hard_regno (REGNO (reg
))))
1748 no_subreg_reg_operand
[nop
] = reg
;
1750 operand_reg
[nop
] = no_subreg_reg_operand
[nop
]
1751 /* Just use natural mode for elimination result. It should
1752 be enough for extra constraints hooks. */
1753 = regno_reg_rtx
[hard_regno
[nop
]];
1756 /* The constraints are made of several alternatives. Each operand's
1757 constraint looks like foo,bar,... with commas separating the
1758 alternatives. The first alternatives for all operands go
1759 together, the second alternatives go together, etc.
1761 First loop over alternatives. */
1762 alternative_mask preferred
= curr_id
->preferred_alternatives
;
1763 if (only_alternative
>= 0)
1764 preferred
&= ALTERNATIVE_BIT (only_alternative
);
1766 for (nalt
= 0; nalt
< n_alternatives
; nalt
++)
1768 /* Loop over operands for one constraint alternative. */
1769 if (!TEST_BIT (preferred
, nalt
))
1772 overall
= losers
= reject
= reload_nregs
= reload_sum
= 0;
1773 for (nop
= 0; nop
< n_operands
; nop
++)
1775 int inc
= (curr_static_id
1776 ->operand_alternative
[nalt
* n_operands
+ nop
].reject
);
1777 if (lra_dump_file
!= NULL
&& inc
!= 0)
1778 fprintf (lra_dump_file
,
1779 " Staticly defined alt reject+=%d\n", inc
);
1782 early_clobbered_regs_num
= 0;
1784 for (nop
= 0; nop
< n_operands
; nop
++)
1788 int len
, c
, m
, i
, opalt_num
, this_alternative_matches
;
1789 bool win
, did_match
, offmemok
, early_clobber_p
;
1790 /* false => this operand can be reloaded somehow for this
1793 /* true => this operand can be reloaded if the alternative
1796 /* True if a constant forced into memory would be OK for
1799 enum reg_class this_alternative
, this_costly_alternative
;
1800 HARD_REG_SET this_alternative_set
, this_costly_alternative_set
;
1801 bool this_alternative_match_win
, this_alternative_win
;
1802 bool this_alternative_offmemok
;
1805 enum constraint_num cn
;
1807 opalt_num
= nalt
* n_operands
+ nop
;
1808 if (curr_static_id
->operand_alternative
[opalt_num
].anything_ok
)
1810 /* Fast track for no constraints at all. */
1811 curr_alt
[nop
] = NO_REGS
;
1812 CLEAR_HARD_REG_SET (curr_alt_set
[nop
]);
1813 curr_alt_win
[nop
] = true;
1814 curr_alt_match_win
[nop
] = false;
1815 curr_alt_offmemok
[nop
] = false;
1816 curr_alt_matches
[nop
] = -1;
1820 op
= no_subreg_reg_operand
[nop
];
1821 mode
= curr_operand_mode
[nop
];
1823 win
= did_match
= winreg
= offmemok
= constmemok
= false;
1826 early_clobber_p
= false;
1827 p
= curr_static_id
->operand_alternative
[opalt_num
].constraint
;
1829 this_costly_alternative
= this_alternative
= NO_REGS
;
1830 /* We update set of possible hard regs besides its class
1831 because reg class might be inaccurate. For example,
1832 union of LO_REGS (l), HI_REGS(h), and STACK_REG(k) in ARM
1833 is translated in HI_REGS because classes are merged by
1834 pairs and there is no accurate intermediate class. */
1835 CLEAR_HARD_REG_SET (this_alternative_set
);
1836 CLEAR_HARD_REG_SET (this_costly_alternative_set
);
1837 this_alternative_win
= false;
1838 this_alternative_match_win
= false;
1839 this_alternative_offmemok
= false;
1840 this_alternative_matches
= -1;
1842 /* An empty constraint should be excluded by the fast
1844 lra_assert (*p
!= 0 && *p
!= ',');
1847 /* Scan this alternative's specs for this operand; set WIN
1848 if the operand fits any letter in this alternative.
1849 Otherwise, clear BADOP if this operand could fit some
1850 letter after reloads, or set WINREG if this operand could
1851 fit after reloads provided the constraint allows some
1856 switch ((c
= *p
, len
= CONSTRAINT_LEN (c
, p
)), c
)
1866 early_clobber_p
= true;
1870 op_reject
+= LRA_MAX_REJECT
;
1873 op_reject
+= LRA_LOSER_COST_FACTOR
;
1877 /* Ignore rest of this alternative. */
1881 case '0': case '1': case '2': case '3': case '4':
1882 case '5': case '6': case '7': case '8': case '9':
1887 m
= strtoul (p
, &end
, 10);
1890 lra_assert (nop
> m
);
1892 this_alternative_matches
= m
;
1893 m_hregno
= get_hard_regno (*curr_id
->operand_loc
[m
]);
1894 /* We are supposed to match a previous operand.
1895 If we do, we win if that one did. If we do
1896 not, count both of the operands as losers.
1897 (This is too conservative, since most of the
1898 time only a single reload insn will be needed
1899 to make the two operands win. As a result,
1900 this alternative may be rejected when it is
1901 actually desirable.) */
1903 if (operands_match_p (*curr_id
->operand_loc
[nop
],
1904 *curr_id
->operand_loc
[m
], m_hregno
))
1906 /* We should reject matching of an early
1907 clobber operand if the matching operand is
1908 not dying in the insn. */
1909 if (! curr_static_id
->operand
[m
].early_clobber
1910 || operand_reg
[nop
] == NULL_RTX
1911 || (find_regno_note (curr_insn
, REG_DEAD
,
1913 || REGNO (op
) == REGNO (operand_reg
[m
])))
1918 /* If we are matching a non-offsettable
1919 address where an offsettable address was
1920 expected, then we must reject this
1921 combination, because we can't reload
1923 if (curr_alt_offmemok
[m
]
1924 && MEM_P (*curr_id
->operand_loc
[m
])
1925 && curr_alt
[m
] == NO_REGS
&& ! curr_alt_win
[m
])
1930 /* Operands don't match. Both operands must
1931 allow a reload register, otherwise we
1932 cannot make them match. */
1933 if (curr_alt
[m
] == NO_REGS
)
1935 /* Retroactively mark the operand we had to
1936 match as a loser, if it wasn't already and
1937 it wasn't matched to a register constraint
1938 (e.g it might be matched by memory). */
1940 && (operand_reg
[m
] == NULL_RTX
1941 || hard_regno
[m
] < 0))
1945 += (ira_reg_class_max_nregs
[curr_alt
[m
]]
1946 [GET_MODE (*curr_id
->operand_loc
[m
])]);
1949 /* Prefer matching earlyclobber alternative as
1950 it results in less hard regs required for
1951 the insn than a non-matching earlyclobber
1953 if (curr_static_id
->operand
[m
].early_clobber
)
1955 if (lra_dump_file
!= NULL
)
1958 " %d Matching earlyclobber alt:"
1963 /* Otherwise we prefer no matching
1964 alternatives because it gives more freedom
1966 else if (operand_reg
[nop
] == NULL_RTX
1967 || (find_regno_note (curr_insn
, REG_DEAD
,
1968 REGNO (operand_reg
[nop
]))
1971 if (lra_dump_file
!= NULL
)
1974 " %d Matching alt: reject+=2\n",
1979 /* If we have to reload this operand and some
1980 previous operand also had to match the same
1981 thing as this operand, we don't know how to do
1983 if (!match_p
|| !curr_alt_win
[m
])
1985 for (i
= 0; i
< nop
; i
++)
1986 if (curr_alt_matches
[i
] == m
)
1994 /* This can be fixed with reloads if the operand
1995 we are supposed to match can be fixed with
1998 this_alternative
= curr_alt
[m
];
1999 COPY_HARD_REG_SET (this_alternative_set
, curr_alt_set
[m
]);
2000 winreg
= this_alternative
!= NO_REGS
;
2006 || general_constant_p (op
)
2007 || spilled_pseudo_p (op
))
2013 cn
= lookup_constraint (p
);
2014 switch (get_constraint_type (cn
))
2017 cl
= reg_class_for_constraint (cn
);
2023 if (CONST_INT_P (op
)
2024 && insn_const_int_ok_for_constraint (INTVAL (op
), cn
))
2030 && satisfies_memory_constraint_p (op
, cn
))
2032 else if (spilled_pseudo_p (op
))
2035 /* If we didn't already win, we can reload constants
2036 via force_const_mem or put the pseudo value into
2037 memory, or make other memory by reloading the
2038 address like for 'o'. */
2039 if (CONST_POOL_OK_P (mode
, op
)
2040 || MEM_P (op
) || REG_P (op
))
2047 /* If we didn't already win, we can reload the address
2048 into a base register. */
2049 if (satisfies_address_constraint_p (op
, cn
))
2051 cl
= base_reg_class (VOIDmode
, ADDR_SPACE_GENERIC
,
2057 if (constraint_satisfied_p (op
, cn
))
2064 this_alternative
= reg_class_subunion
[this_alternative
][cl
];
2065 IOR_HARD_REG_SET (this_alternative_set
,
2066 reg_class_contents
[cl
]);
2069 this_costly_alternative
2070 = reg_class_subunion
[this_costly_alternative
][cl
];
2071 IOR_HARD_REG_SET (this_costly_alternative_set
,
2072 reg_class_contents
[cl
]);
2074 if (mode
== BLKmode
)
2079 if (hard_regno
[nop
] >= 0
2080 && in_hard_reg_set_p (this_alternative_set
,
2081 mode
, hard_regno
[nop
]))
2083 else if (hard_regno
[nop
] < 0
2084 && in_class_p (op
, this_alternative
, NULL
))
2089 if (c
!= ' ' && c
!= '\t')
2090 costly_p
= c
== '*';
2092 while ((p
+= len
), c
);
2094 scratch_p
= (operand_reg
[nop
] != NULL_RTX
2095 && lra_former_scratch_p (REGNO (operand_reg
[nop
])));
2096 /* Record which operands fit this alternative. */
2099 this_alternative_win
= true;
2100 if (operand_reg
[nop
] != NULL_RTX
)
2102 if (hard_regno
[nop
] >= 0)
2104 if (in_hard_reg_set_p (this_costly_alternative_set
,
2105 mode
, hard_regno
[nop
]))
2107 if (lra_dump_file
!= NULL
)
2108 fprintf (lra_dump_file
,
2109 " %d Costly set: reject++\n",
2116 /* Prefer won reg to spilled pseudo under other
2117 equal conditions for possibe inheritance. */
2120 if (lra_dump_file
!= NULL
)
2123 " %d Non pseudo reload: reject++\n",
2127 if (in_class_p (operand_reg
[nop
],
2128 this_costly_alternative
, NULL
))
2130 if (lra_dump_file
!= NULL
)
2133 " %d Non pseudo costly reload:"
2139 /* We simulate the behaviour of old reload here.
2140 Although scratches need hard registers and it
2141 might result in spilling other pseudos, no reload
2142 insns are generated for the scratches. So it
2143 might cost something but probably less than old
2144 reload pass believes. */
2147 if (lra_dump_file
!= NULL
)
2148 fprintf (lra_dump_file
,
2149 " %d Scratch win: reject+=2\n",
2156 this_alternative_match_win
= true;
2159 int const_to_mem
= 0;
2162 reject
+= op_reject
;
2163 /* Never do output reload of stack pointer. It makes
2164 impossible to do elimination when SP is changed in
2166 if (op
== stack_pointer_rtx
&& ! frame_pointer_needed
2167 && curr_static_id
->operand
[nop
].type
!= OP_IN
)
2170 /* If this alternative asks for a specific reg class, see if there
2171 is at least one allocatable register in that class. */
2173 = (this_alternative
== NO_REGS
2174 || (hard_reg_set_subset_p
2175 (reg_class_contents
[this_alternative
],
2176 lra_no_alloc_regs
)));
2178 /* For asms, verify that the class for this alternative is possible
2179 for the mode that is specified. */
2180 if (!no_regs_p
&& INSN_CODE (curr_insn
) < 0)
2183 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
2184 if (HARD_REGNO_MODE_OK (i
, mode
)
2185 && in_hard_reg_set_p (reg_class_contents
[this_alternative
],
2188 if (i
== FIRST_PSEUDO_REGISTER
)
2192 /* If this operand accepts a register, and if the
2193 register class has at least one allocatable register,
2194 then this operand can be reloaded. */
2195 if (winreg
&& !no_regs_p
)
2200 if (lra_dump_file
!= NULL
)
2201 fprintf (lra_dump_file
,
2202 " alt=%d: Bad operand -- refuse\n",
2207 /* If not assigned pseudo has a class which a subset of
2208 required reg class, it is a less costly alternative
2209 as the pseudo still can get a hard reg of necessary
2211 if (! no_regs_p
&& REG_P (op
) && hard_regno
[nop
] < 0
2212 && (cl
= get_reg_class (REGNO (op
))) != NO_REGS
2213 && ira_class_subset_p
[this_alternative
][cl
])
2215 if (lra_dump_file
!= NULL
)
2218 " %d Super set class reg: reject-=3\n", nop
);
2222 this_alternative_offmemok
= offmemok
;
2223 if (this_costly_alternative
!= NO_REGS
)
2225 if (lra_dump_file
!= NULL
)
2226 fprintf (lra_dump_file
,
2227 " %d Costly loser: reject++\n", nop
);
2230 /* If the operand is dying, has a matching constraint,
2231 and satisfies constraints of the matched operand
2232 which failed to satisfy the own constraints, most probably
2233 the reload for this operand will be gone. */
2234 if (this_alternative_matches
>= 0
2235 && !curr_alt_win
[this_alternative_matches
]
2237 && find_regno_note (curr_insn
, REG_DEAD
, REGNO (op
))
2238 && (hard_regno
[nop
] >= 0
2239 ? in_hard_reg_set_p (this_alternative_set
,
2240 mode
, hard_regno
[nop
])
2241 : in_class_p (op
, this_alternative
, NULL
)))
2243 if (lra_dump_file
!= NULL
)
2246 " %d Dying matched operand reload: reject++\n",
2252 /* Strict_low_part requires to reload the register
2253 not the sub-register. In this case we should
2254 check that a final reload hard reg can hold the
2256 if (curr_static_id
->operand
[nop
].strict_low
2258 && hard_regno
[nop
] < 0
2259 && GET_CODE (*curr_id
->operand_loc
[nop
]) == SUBREG
2260 && ira_class_hard_regs_num
[this_alternative
] > 0
2261 && ! HARD_REGNO_MODE_OK (ira_class_hard_regs
2262 [this_alternative
][0],
2264 (*curr_id
->operand_loc
[nop
])))
2266 if (lra_dump_file
!= NULL
)
2269 " alt=%d: Strict low subreg reload -- refuse\n",
2275 if (operand_reg
[nop
] != NULL_RTX
2276 /* Output operands and matched input operands are
2277 not inherited. The following conditions do not
2278 exactly describe the previous statement but they
2279 are pretty close. */
2280 && curr_static_id
->operand
[nop
].type
!= OP_OUT
2281 && (this_alternative_matches
< 0
2282 || curr_static_id
->operand
[nop
].type
!= OP_IN
))
2284 int last_reload
= (lra_reg_info
[ORIGINAL_REGNO
2288 /* The value of reload_sum has sense only if we
2289 process insns in their order. It happens only on
2290 the first constraints sub-pass when we do most of
2292 if (lra_constraint_iter
== 1 && last_reload
> bb_reload_num
)
2293 reload_sum
+= last_reload
- bb_reload_num
;
2295 /* If this is a constant that is reloaded into the
2296 desired class by copying it to memory first, count
2297 that as another reload. This is consistent with
2298 other code and is required to avoid choosing another
2299 alternative when the constant is moved into memory.
2300 Note that the test here is precisely the same as in
2301 the code below that calls force_const_mem. */
2302 if (CONST_POOL_OK_P (mode
, op
)
2303 && ((targetm
.preferred_reload_class
2304 (op
, this_alternative
) == NO_REGS
)
2305 || no_input_reloads_p
))
2312 /* Alternative loses if it requires a type of reload not
2313 permitted for this insn. We can always reload
2314 objects with a REG_UNUSED note. */
2315 if ((curr_static_id
->operand
[nop
].type
!= OP_IN
2316 && no_output_reloads_p
2317 && ! find_reg_note (curr_insn
, REG_UNUSED
, op
))
2318 || (curr_static_id
->operand
[nop
].type
!= OP_OUT
2319 && no_input_reloads_p
&& ! const_to_mem
)
2320 || (this_alternative_matches
>= 0
2321 && (no_input_reloads_p
2322 || (no_output_reloads_p
2323 && (curr_static_id
->operand
2324 [this_alternative_matches
].type
!= OP_IN
)
2325 && ! find_reg_note (curr_insn
, REG_UNUSED
,
2326 no_subreg_reg_operand
2327 [this_alternative_matches
])))))
2329 if (lra_dump_file
!= NULL
)
2332 " alt=%d: No input/otput reload -- refuse\n",
2337 /* Alternative loses if it required class pseudo can not
2338 hold value of required mode. Such insns can be
2339 described by insn definitions with mode iterators. */
2340 if (GET_MODE (*curr_id
->operand_loc
[nop
]) != VOIDmode
2341 && ! hard_reg_set_empty_p (this_alternative_set
)
2342 /* It is common practice for constraints to use a
2343 class which does not have actually enough regs to
2344 hold the value (e.g. x86 AREG for mode requiring
2345 more one general reg). Therefore we have 2
2346 conditions to check that the reload pseudo can
2347 not hold the mode value. */
2348 && ! HARD_REGNO_MODE_OK (ira_class_hard_regs
2349 [this_alternative
][0],
2350 GET_MODE (*curr_id
->operand_loc
[nop
]))
2351 /* The above condition is not enough as the first
2352 reg in ira_class_hard_regs can be not aligned for
2353 multi-words mode values. */
2354 && (prohibited_class_reg_set_mode_p
2355 (this_alternative
, this_alternative_set
,
2356 GET_MODE (*curr_id
->operand_loc
[nop
]))))
2358 if (lra_dump_file
!= NULL
)
2359 fprintf (lra_dump_file
,
2360 " alt=%d: reload pseudo for op %d "
2361 " can not hold the mode value -- refuse\n",
2366 /* Check strong discouragement of reload of non-constant
2367 into class THIS_ALTERNATIVE. */
2368 if (! CONSTANT_P (op
) && ! no_regs_p
2369 && (targetm
.preferred_reload_class
2370 (op
, this_alternative
) == NO_REGS
2371 || (curr_static_id
->operand
[nop
].type
== OP_OUT
2372 && (targetm
.preferred_output_reload_class
2373 (op
, this_alternative
) == NO_REGS
))))
2375 if (lra_dump_file
!= NULL
)
2376 fprintf (lra_dump_file
,
2377 " %d Non-prefered reload: reject+=%d\n",
2378 nop
, LRA_MAX_REJECT
);
2379 reject
+= LRA_MAX_REJECT
;
2382 if (! (MEM_P (op
) && offmemok
)
2383 && ! (const_to_mem
&& constmemok
))
2385 /* We prefer to reload pseudos over reloading other
2386 things, since such reloads may be able to be
2387 eliminated later. So bump REJECT in other cases.
2388 Don't do this in the case where we are forcing a
2389 constant into memory and it will then win since
2390 we don't want to have a different alternative
2392 if (! (REG_P (op
) && REGNO (op
) >= FIRST_PSEUDO_REGISTER
))
2394 if (lra_dump_file
!= NULL
)
2397 " %d Non-pseudo reload: reject+=2\n",
2404 += ira_reg_class_max_nregs
[this_alternative
][mode
];
2406 if (SMALL_REGISTER_CLASS_P (this_alternative
))
2408 if (lra_dump_file
!= NULL
)
2411 " %d Small class reload: reject+=%d\n",
2412 nop
, LRA_LOSER_COST_FACTOR
/ 2);
2413 reject
+= LRA_LOSER_COST_FACTOR
/ 2;
2417 /* We are trying to spill pseudo into memory. It is
2418 usually more costly than moving to a hard register
2419 although it might takes the same number of
2421 if (no_regs_p
&& REG_P (op
) && hard_regno
[nop
] >= 0)
2423 if (lra_dump_file
!= NULL
)
2426 " %d Spill pseudo into memory: reject+=3\n",
2429 if (VECTOR_MODE_P (mode
))
2431 /* Spilling vectors into memory is usually more
2432 costly as they contain big values. */
2433 if (lra_dump_file
!= NULL
)
2436 " %d Spill vector pseudo: reject+=2\n",
2442 #ifdef SECONDARY_MEMORY_NEEDED
2443 /* If reload requires moving value through secondary
2444 memory, it will need one more insn at least. */
2445 if (this_alternative
!= NO_REGS
2446 && REG_P (op
) && (cl
= get_reg_class (REGNO (op
))) != NO_REGS
2447 && ((curr_static_id
->operand
[nop
].type
!= OP_OUT
2448 && SECONDARY_MEMORY_NEEDED (cl
, this_alternative
,
2450 || (curr_static_id
->operand
[nop
].type
!= OP_IN
2451 && SECONDARY_MEMORY_NEEDED (this_alternative
, cl
,
2455 /* Input reloads can be inherited more often than output
2456 reloads can be removed, so penalize output
2458 if (!REG_P (op
) || curr_static_id
->operand
[nop
].type
!= OP_IN
)
2460 if (lra_dump_file
!= NULL
)
2463 " %d Non input pseudo reload: reject++\n",
2469 if (early_clobber_p
&& ! scratch_p
)
2471 if (lra_dump_file
!= NULL
)
2472 fprintf (lra_dump_file
,
2473 " %d Early clobber: reject++\n", nop
);
2476 /* ??? We check early clobbers after processing all operands
2477 (see loop below) and there we update the costs more.
2478 Should we update the cost (may be approximately) here
2479 because of early clobber register reloads or it is a rare
2480 or non-important thing to be worth to do it. */
2481 overall
= losers
* LRA_LOSER_COST_FACTOR
+ reject
;
2482 if ((best_losers
== 0 || losers
!= 0) && best_overall
< overall
)
2484 if (lra_dump_file
!= NULL
)
2485 fprintf (lra_dump_file
,
2486 " alt=%d,overall=%d,losers=%d -- refuse\n",
2487 nalt
, overall
, losers
);
2491 curr_alt
[nop
] = this_alternative
;
2492 COPY_HARD_REG_SET (curr_alt_set
[nop
], this_alternative_set
);
2493 curr_alt_win
[nop
] = this_alternative_win
;
2494 curr_alt_match_win
[nop
] = this_alternative_match_win
;
2495 curr_alt_offmemok
[nop
] = this_alternative_offmemok
;
2496 curr_alt_matches
[nop
] = this_alternative_matches
;
2498 if (this_alternative_matches
>= 0
2499 && !did_match
&& !this_alternative_win
)
2500 curr_alt_win
[this_alternative_matches
] = false;
2502 if (early_clobber_p
&& operand_reg
[nop
] != NULL_RTX
)
2503 early_clobbered_nops
[early_clobbered_regs_num
++] = nop
;
2505 if (curr_insn_set
!= NULL_RTX
&& n_operands
== 2
2506 /* Prevent processing non-move insns. */
2507 && (GET_CODE (SET_SRC (curr_insn_set
)) == SUBREG
2508 || SET_SRC (curr_insn_set
) == no_subreg_reg_operand
[1])
2509 && ((! curr_alt_win
[0] && ! curr_alt_win
[1]
2510 && REG_P (no_subreg_reg_operand
[0])
2511 && REG_P (no_subreg_reg_operand
[1])
2512 && (reg_in_class_p (no_subreg_reg_operand
[0], curr_alt
[1])
2513 || reg_in_class_p (no_subreg_reg_operand
[1], curr_alt
[0])))
2514 || (! curr_alt_win
[0] && curr_alt_win
[1]
2515 && REG_P (no_subreg_reg_operand
[1])
2516 && reg_in_class_p (no_subreg_reg_operand
[1], curr_alt
[0]))
2517 || (curr_alt_win
[0] && ! curr_alt_win
[1]
2518 && REG_P (no_subreg_reg_operand
[0])
2519 && reg_in_class_p (no_subreg_reg_operand
[0], curr_alt
[1])
2520 && (! CONST_POOL_OK_P (curr_operand_mode
[1],
2521 no_subreg_reg_operand
[1])
2522 || (targetm
.preferred_reload_class
2523 (no_subreg_reg_operand
[1],
2524 (enum reg_class
) curr_alt
[1]) != NO_REGS
))
2525 /* If it is a result of recent elimination in move
2526 insn we can transform it into an add still by
2527 using this alternative. */
2528 && GET_CODE (no_subreg_reg_operand
[1]) != PLUS
)))
2530 /* We have a move insn and a new reload insn will be similar
2531 to the current insn. We should avoid such situation as it
2532 results in LRA cycling. */
2533 overall
+= LRA_MAX_REJECT
;
2536 curr_alt_dont_inherit_ops_num
= 0;
2537 for (nop
= 0; nop
< early_clobbered_regs_num
; nop
++)
2539 int i
, j
, clobbered_hard_regno
, first_conflict_j
, last_conflict_j
;
2540 HARD_REG_SET temp_set
;
2542 i
= early_clobbered_nops
[nop
];
2543 if ((! curr_alt_win
[i
] && ! curr_alt_match_win
[i
])
2544 || hard_regno
[i
] < 0)
2546 lra_assert (operand_reg
[i
] != NULL_RTX
);
2547 clobbered_hard_regno
= hard_regno
[i
];
2548 CLEAR_HARD_REG_SET (temp_set
);
2549 add_to_hard_reg_set (&temp_set
, biggest_mode
[i
], clobbered_hard_regno
);
2550 first_conflict_j
= last_conflict_j
= -1;
2551 for (j
= 0; j
< n_operands
; j
++)
2553 /* We don't want process insides of match_operator and
2554 match_parallel because otherwise we would process
2555 their operands once again generating a wrong
2557 || curr_static_id
->operand
[j
].is_operator
)
2559 else if ((curr_alt_matches
[j
] == i
&& curr_alt_match_win
[j
])
2560 || (curr_alt_matches
[i
] == j
&& curr_alt_match_win
[i
]))
2562 /* If we don't reload j-th operand, check conflicts. */
2563 else if ((curr_alt_win
[j
] || curr_alt_match_win
[j
])
2564 && uses_hard_regs_p (*curr_id
->operand_loc
[j
], temp_set
))
2566 if (first_conflict_j
< 0)
2567 first_conflict_j
= j
;
2568 last_conflict_j
= j
;
2570 if (last_conflict_j
< 0)
2572 /* If earlyclobber operand conflicts with another
2573 non-matching operand which is actually the same register
2574 as the earlyclobber operand, it is better to reload the
2575 another operand as an operand matching the earlyclobber
2576 operand can be also the same. */
2577 if (first_conflict_j
== last_conflict_j
2578 && operand_reg
[last_conflict_j
]
2579 != NULL_RTX
&& ! curr_alt_match_win
[last_conflict_j
]
2580 && REGNO (operand_reg
[i
]) == REGNO (operand_reg
[last_conflict_j
]))
2582 curr_alt_win
[last_conflict_j
] = false;
2583 curr_alt_dont_inherit_ops
[curr_alt_dont_inherit_ops_num
++]
2586 /* Early clobber was already reflected in REJECT. */
2587 lra_assert (reject
> 0);
2588 if (lra_dump_file
!= NULL
)
2591 " %d Conflict early clobber reload: reject--\n",
2594 overall
+= LRA_LOSER_COST_FACTOR
- 1;
2598 /* We need to reload early clobbered register and the
2599 matched registers. */
2600 for (j
= 0; j
< n_operands
; j
++)
2601 if (curr_alt_matches
[j
] == i
)
2603 curr_alt_match_win
[j
] = false;
2605 overall
+= LRA_LOSER_COST_FACTOR
;
2607 if (! curr_alt_match_win
[i
])
2608 curr_alt_dont_inherit_ops
[curr_alt_dont_inherit_ops_num
++] = i
;
2611 /* Remember pseudos used for match reloads are never
2613 lra_assert (curr_alt_matches
[i
] >= 0);
2614 curr_alt_win
[curr_alt_matches
[i
]] = false;
2616 curr_alt_win
[i
] = curr_alt_match_win
[i
] = false;
2618 /* Early clobber was already reflected in REJECT. */
2619 lra_assert (reject
> 0);
2620 if (lra_dump_file
!= NULL
)
2623 " %d Matched conflict early clobber reloads:"
2627 overall
+= LRA_LOSER_COST_FACTOR
- 1;
2630 if (lra_dump_file
!= NULL
)
2631 fprintf (lra_dump_file
, " alt=%d,overall=%d,losers=%d,rld_nregs=%d\n",
2632 nalt
, overall
, losers
, reload_nregs
);
2634 /* If this alternative can be made to work by reloading, and it
2635 needs less reloading than the others checked so far, record
2636 it as the chosen goal for reloading. */
2637 if ((best_losers
!= 0 && losers
== 0)
2638 || (((best_losers
== 0 && losers
== 0)
2639 || (best_losers
!= 0 && losers
!= 0))
2640 && (best_overall
> overall
2641 || (best_overall
== overall
2642 /* If the cost of the reloads is the same,
2643 prefer alternative which requires minimal
2644 number of reload regs. */
2645 && (reload_nregs
< best_reload_nregs
2646 || (reload_nregs
== best_reload_nregs
2647 && (best_reload_sum
< reload_sum
2648 || (best_reload_sum
== reload_sum
2649 && nalt
< goal_alt_number
))))))))
2651 for (nop
= 0; nop
< n_operands
; nop
++)
2653 goal_alt_win
[nop
] = curr_alt_win
[nop
];
2654 goal_alt_match_win
[nop
] = curr_alt_match_win
[nop
];
2655 goal_alt_matches
[nop
] = curr_alt_matches
[nop
];
2656 goal_alt
[nop
] = curr_alt
[nop
];
2657 goal_alt_offmemok
[nop
] = curr_alt_offmemok
[nop
];
2659 goal_alt_dont_inherit_ops_num
= curr_alt_dont_inherit_ops_num
;
2660 for (nop
= 0; nop
< curr_alt_dont_inherit_ops_num
; nop
++)
2661 goal_alt_dont_inherit_ops
[nop
] = curr_alt_dont_inherit_ops
[nop
];
2662 goal_alt_swapped
= curr_swapped
;
2663 best_overall
= overall
;
2664 best_losers
= losers
;
2665 best_reload_nregs
= reload_nregs
;
2666 best_reload_sum
= reload_sum
;
2667 goal_alt_number
= nalt
;
2670 /* Everything is satisfied. Do not process alternatives
2679 /* Make reload base reg from address AD. */
2681 base_to_reg (struct address_info
*ad
)
2685 rtx new_inner
= NULL_RTX
;
2686 rtx new_reg
= NULL_RTX
;
2688 rtx_insn
*last_insn
= get_last_insn();
2690 lra_assert (ad
->base
== ad
->base_term
&& ad
->disp
== ad
->disp_term
);
2691 cl
= base_reg_class (ad
->mode
, ad
->as
, ad
->base_outer_code
,
2692 get_index_code (ad
));
2693 new_reg
= lra_create_new_reg (GET_MODE (*ad
->base_term
), NULL_RTX
,
2695 new_inner
= simplify_gen_binary (PLUS
, GET_MODE (new_reg
), new_reg
,
2696 ad
->disp_term
== NULL
2697 ? gen_int_mode (0, ad
->mode
)
2699 if (!valid_address_p (ad
->mode
, new_inner
, ad
->as
))
2701 insn
= emit_insn (gen_rtx_SET (ad
->mode
, new_reg
, *ad
->base_term
));
2702 code
= recog_memoized (insn
);
2705 delete_insns_since (last_insn
);
2712 /* Make reload base reg + disp from address AD. Return the new pseudo. */
2714 base_plus_disp_to_reg (struct address_info
*ad
)
2719 lra_assert (ad
->base
== ad
->base_term
&& ad
->disp
== ad
->disp_term
);
2720 cl
= base_reg_class (ad
->mode
, ad
->as
, ad
->base_outer_code
,
2721 get_index_code (ad
));
2722 new_reg
= lra_create_new_reg (GET_MODE (*ad
->base_term
), NULL_RTX
,
2724 lra_emit_add (new_reg
, *ad
->base_term
, *ad
->disp_term
);
2728 /* Make reload of index part of address AD. Return the new
2731 index_part_to_reg (struct address_info
*ad
)
2735 new_reg
= lra_create_new_reg (GET_MODE (*ad
->index
), NULL_RTX
,
2736 INDEX_REG_CLASS
, "index term");
2737 expand_mult (GET_MODE (*ad
->index
), *ad
->index_term
,
2738 GEN_INT (get_index_scale (ad
)), new_reg
, 1);
2742 /* Return true if we can add a displacement to address AD, even if that
2743 makes the address invalid. The fix-up code requires any new address
2744 to be the sum of the BASE_TERM, INDEX and DISP_TERM fields. */
2746 can_add_disp_p (struct address_info
*ad
)
2748 return (!ad
->autoinc_p
2749 && ad
->segment
== NULL
2750 && ad
->base
== ad
->base_term
2751 && ad
->disp
== ad
->disp_term
);
2754 /* Make equiv substitution in address AD. Return true if a substitution
2757 equiv_address_substitution (struct address_info
*ad
)
2759 rtx base_reg
, new_base_reg
, index_reg
, new_index_reg
, *base_term
, *index_term
;
2760 HOST_WIDE_INT disp
, scale
;
2763 base_term
= strip_subreg (ad
->base_term
);
2764 if (base_term
== NULL
)
2765 base_reg
= new_base_reg
= NULL_RTX
;
2768 base_reg
= *base_term
;
2769 new_base_reg
= get_equiv_with_elimination (base_reg
, curr_insn
);
2771 index_term
= strip_subreg (ad
->index_term
);
2772 if (index_term
== NULL
)
2773 index_reg
= new_index_reg
= NULL_RTX
;
2776 index_reg
= *index_term
;
2777 new_index_reg
= get_equiv_with_elimination (index_reg
, curr_insn
);
2779 if (base_reg
== new_base_reg
&& index_reg
== new_index_reg
)
2783 if (lra_dump_file
!= NULL
)
2785 fprintf (lra_dump_file
, "Changing address in insn %d ",
2786 INSN_UID (curr_insn
));
2787 dump_value_slim (lra_dump_file
, *ad
->outer
, 1);
2789 if (base_reg
!= new_base_reg
)
2791 if (REG_P (new_base_reg
))
2793 *base_term
= new_base_reg
;
2796 else if (GET_CODE (new_base_reg
) == PLUS
2797 && REG_P (XEXP (new_base_reg
, 0))
2798 && CONST_INT_P (XEXP (new_base_reg
, 1))
2799 && can_add_disp_p (ad
))
2801 disp
+= INTVAL (XEXP (new_base_reg
, 1));
2802 *base_term
= XEXP (new_base_reg
, 0);
2805 if (ad
->base_term2
!= NULL
)
2806 *ad
->base_term2
= *ad
->base_term
;
2808 if (index_reg
!= new_index_reg
)
2810 if (REG_P (new_index_reg
))
2812 *index_term
= new_index_reg
;
2815 else if (GET_CODE (new_index_reg
) == PLUS
2816 && REG_P (XEXP (new_index_reg
, 0))
2817 && CONST_INT_P (XEXP (new_index_reg
, 1))
2818 && can_add_disp_p (ad
)
2819 && (scale
= get_index_scale (ad
)))
2821 disp
+= INTVAL (XEXP (new_index_reg
, 1)) * scale
;
2822 *index_term
= XEXP (new_index_reg
, 0);
2828 if (ad
->disp
!= NULL
)
2829 *ad
->disp
= plus_constant (GET_MODE (*ad
->inner
), *ad
->disp
, disp
);
2832 *ad
->inner
= plus_constant (GET_MODE (*ad
->inner
), *ad
->inner
, disp
);
2833 update_address (ad
);
2837 if (lra_dump_file
!= NULL
)
2840 fprintf (lra_dump_file
, " -- no change\n");
2843 fprintf (lra_dump_file
, " on equiv ");
2844 dump_value_slim (lra_dump_file
, *ad
->outer
, 1);
2845 fprintf (lra_dump_file
, "\n");
2851 /* Major function to make reloads for an address in operand NOP or
2852 check its correctness (If CHECK_ONLY_P is true). The supported
2855 1) an address that existed before LRA started, at which point it
2856 must have been valid. These addresses are subject to elimination
2857 and may have become invalid due to the elimination offset being out
2860 2) an address created by forcing a constant to memory
2861 (force_const_to_mem). The initial form of these addresses might
2862 not be valid, and it is this function's job to make them valid.
2864 3) a frame address formed from a register and a (possibly zero)
2865 constant offset. As above, these addresses might not be valid and
2866 this function must make them so.
2868 Add reloads to the lists *BEFORE and *AFTER. We might need to add
2869 reloads to *AFTER because of inc/dec, {pre, post} modify in the
2870 address. Return true for any RTL change.
2872 The function is a helper function which does not produce all
2873 transformations (when CHECK_ONLY_P is false) which can be
2874 necessary. It does just basic steps. To do all necessary
2875 transformations use function process_address. */
2877 process_address_1 (int nop
, bool check_only_p
,
2878 rtx_insn
**before
, rtx_insn
**after
)
2880 struct address_info ad
;
2882 rtx op
= *curr_id
->operand_loc
[nop
];
2883 const char *constraint
= curr_static_id
->operand
[nop
].constraint
;
2884 enum constraint_num cn
= lookup_constraint (constraint
);
2885 bool change_p
= false;
2887 if (insn_extra_address_constraint (cn
))
2888 decompose_lea_address (&ad
, curr_id
->operand_loc
[nop
]);
2889 else if (MEM_P (op
))
2890 decompose_mem_address (&ad
, op
);
2891 else if (GET_CODE (op
) == SUBREG
2892 && MEM_P (SUBREG_REG (op
)))
2893 decompose_mem_address (&ad
, SUBREG_REG (op
));
2896 /* If INDEX_REG_CLASS is assigned to base_term already and isn't to
2897 index_term, swap them so to avoid assigning INDEX_REG_CLASS to both
2898 when INDEX_REG_CLASS is a single register class. */
2899 if (ad
.base_term
!= NULL
2900 && ad
.index_term
!= NULL
2901 && ira_class_hard_regs_num
[INDEX_REG_CLASS
] == 1
2902 && REG_P (*ad
.base_term
)
2903 && REG_P (*ad
.index_term
)
2904 && in_class_p (*ad
.base_term
, INDEX_REG_CLASS
, NULL
)
2905 && ! in_class_p (*ad
.index_term
, INDEX_REG_CLASS
, NULL
))
2907 std::swap (ad
.base
, ad
.index
);
2908 std::swap (ad
.base_term
, ad
.index_term
);
2911 change_p
= equiv_address_substitution (&ad
);
2912 if (ad
.base_term
!= NULL
2913 && (process_addr_reg
2914 (ad
.base_term
, check_only_p
, before
,
2916 && !(REG_P (*ad
.base_term
)
2917 && find_regno_note (curr_insn
, REG_DEAD
,
2918 REGNO (*ad
.base_term
)) != NULL_RTX
)
2920 base_reg_class (ad
.mode
, ad
.as
, ad
.base_outer_code
,
2921 get_index_code (&ad
)))))
2924 if (ad
.base_term2
!= NULL
)
2925 *ad
.base_term2
= *ad
.base_term
;
2927 if (ad
.index_term
!= NULL
2928 && process_addr_reg (ad
.index_term
, check_only_p
,
2929 before
, NULL
, INDEX_REG_CLASS
))
2932 /* Target hooks sometimes don't treat extra-constraint addresses as
2933 legitimate address_operands, so handle them specially. */
2934 if (insn_extra_address_constraint (cn
)
2935 && satisfies_address_constraint_p (&ad
, cn
))
2941 /* There are three cases where the shape of *AD.INNER may now be invalid:
2943 1) the original address was valid, but either elimination or
2944 equiv_address_substitution was applied and that made
2945 the address invalid.
2947 2) the address is an invalid symbolic address created by
2950 3) the address is a frame address with an invalid offset.
2952 4) the address is a frame address with an invalid base.
2954 All these cases involve a non-autoinc address, so there is no
2955 point revalidating other types. */
2956 if (ad
.autoinc_p
|| valid_address_p (&ad
))
2959 /* Any index existed before LRA started, so we can assume that the
2960 presence and shape of the index is valid. */
2961 push_to_sequence (*before
);
2962 lra_assert (ad
.disp
== ad
.disp_term
);
2963 if (ad
.base
== NULL
)
2965 if (ad
.index
== NULL
)
2968 enum reg_class cl
= base_reg_class (ad
.mode
, ad
.as
,
2970 rtx addr
= *ad
.inner
;
2972 new_reg
= lra_create_new_reg (Pmode
, NULL_RTX
, cl
, "addr");
2976 rtx_insn
*last
= get_last_insn ();
2978 /* addr => lo_sum (new_base, addr), case (2) above. */
2979 insn
= emit_insn (gen_rtx_SET
2981 gen_rtx_HIGH (Pmode
, copy_rtx (addr
))));
2982 code
= recog_memoized (insn
);
2985 *ad
.inner
= gen_rtx_LO_SUM (Pmode
, new_reg
, addr
);
2986 if (! valid_address_p (ad
.mode
, *ad
.outer
, ad
.as
))
2988 /* Try to put lo_sum into register. */
2989 insn
= emit_insn (gen_rtx_SET
2991 gen_rtx_LO_SUM (Pmode
, new_reg
, addr
)));
2992 code
= recog_memoized (insn
);
2995 *ad
.inner
= new_reg
;
2996 if (! valid_address_p (ad
.mode
, *ad
.outer
, ad
.as
))
3006 delete_insns_since (last
);
3011 /* addr => new_base, case (2) above. */
3012 lra_emit_move (new_reg
, addr
);
3013 *ad
.inner
= new_reg
;
3018 /* index * scale + disp => new base + index * scale,
3020 enum reg_class cl
= base_reg_class (ad
.mode
, ad
.as
, PLUS
,
3021 GET_CODE (*ad
.index
));
3023 lra_assert (INDEX_REG_CLASS
!= NO_REGS
);
3024 new_reg
= lra_create_new_reg (Pmode
, NULL_RTX
, cl
, "disp");
3025 lra_emit_move (new_reg
, *ad
.disp
);
3026 *ad
.inner
= simplify_gen_binary (PLUS
, GET_MODE (new_reg
),
3027 new_reg
, *ad
.index
);
3030 else if (ad
.index
== NULL
)
3035 rtx_insn
*insns
, *last_insn
;
3036 /* Try to reload base into register only if the base is invalid
3037 for the address but with valid offset, case (4) above. */
3039 new_reg
= base_to_reg (&ad
);
3041 /* base + disp => new base, cases (1) and (3) above. */
3042 /* Another option would be to reload the displacement into an
3043 index register. However, postreload has code to optimize
3044 address reloads that have the same base and different
3045 displacements, so reloading into an index register would
3046 not necessarily be a win. */
3047 if (new_reg
== NULL_RTX
)
3048 new_reg
= base_plus_disp_to_reg (&ad
);
3049 insns
= get_insns ();
3050 last_insn
= get_last_insn ();
3051 /* If we generated at least two insns, try last insn source as
3052 an address. If we succeed, we generate one less insn. */
3053 if (last_insn
!= insns
&& (set
= single_set (last_insn
)) != NULL_RTX
3054 && GET_CODE (SET_SRC (set
)) == PLUS
3055 && REG_P (XEXP (SET_SRC (set
), 0))
3056 && CONSTANT_P (XEXP (SET_SRC (set
), 1)))
3058 *ad
.inner
= SET_SRC (set
);
3059 if (valid_address_p (ad
.mode
, *ad
.outer
, ad
.as
))
3061 *ad
.base_term
= XEXP (SET_SRC (set
), 0);
3062 *ad
.disp_term
= XEXP (SET_SRC (set
), 1);
3063 cl
= base_reg_class (ad
.mode
, ad
.as
, ad
.base_outer_code
,
3064 get_index_code (&ad
));
3065 regno
= REGNO (*ad
.base_term
);
3066 if (regno
>= FIRST_PSEUDO_REGISTER
3067 && cl
!= lra_get_allocno_class (regno
))
3068 lra_change_class (regno
, cl
, " Change to", true);
3069 new_reg
= SET_SRC (set
);
3070 delete_insns_since (PREV_INSN (last_insn
));
3073 /* Try if target can split displacement into legitimite new disp
3074 and offset. If it's the case, we replace the last insn with
3075 insns for base + offset => new_reg and set new_reg + new disp
3077 last_insn
= get_last_insn ();
3078 if ((set
= single_set (last_insn
)) != NULL_RTX
3079 && GET_CODE (SET_SRC (set
)) == PLUS
3080 && REG_P (XEXP (SET_SRC (set
), 0))
3081 && REGNO (XEXP (SET_SRC (set
), 0)) < FIRST_PSEUDO_REGISTER
3082 && CONST_INT_P (XEXP (SET_SRC (set
), 1)))
3084 rtx addend
, disp
= XEXP (SET_SRC (set
), 1);
3085 if (targetm
.legitimize_address_displacement (&disp
, &addend
,
3088 rtx_insn
*new_insns
;
3090 lra_emit_add (new_reg
, XEXP (SET_SRC (set
), 0), addend
);
3091 new_insns
= get_insns ();
3093 new_reg
= gen_rtx_PLUS (Pmode
, new_reg
, disp
);
3094 delete_insns_since (PREV_INSN (last_insn
));
3095 add_insn (new_insns
);
3096 insns
= get_insns ();
3101 *ad
.inner
= new_reg
;
3103 else if (ad
.disp_term
!= NULL
)
3105 /* base + scale * index + disp => new base + scale * index,
3107 new_reg
= base_plus_disp_to_reg (&ad
);
3108 *ad
.inner
= simplify_gen_binary (PLUS
, GET_MODE (new_reg
),
3109 new_reg
, *ad
.index
);
3111 else if (get_index_scale (&ad
) == 1)
3113 /* The last transformation to one reg will be made in
3114 curr_insn_transform function. */
3120 /* base + scale * index => base + new_reg,
3122 Index part of address may become invalid. For example, we
3123 changed pseudo on the equivalent memory and a subreg of the
3124 pseudo onto the memory of different mode for which the scale is
3126 new_reg
= index_part_to_reg (&ad
);
3127 *ad
.inner
= simplify_gen_binary (PLUS
, GET_MODE (new_reg
),
3128 *ad
.base_term
, new_reg
);
3130 *before
= get_insns ();
3135 /* If CHECK_ONLY_P is false, do address reloads until it is necessary.
3136 Use process_address_1 as a helper function. Return true for any
3139 If CHECK_ONLY_P is true, just check address correctness. Return
3140 false if the address correct. */
3142 process_address (int nop
, bool check_only_p
,
3143 rtx_insn
**before
, rtx_insn
**after
)
3147 while (process_address_1 (nop
, check_only_p
, before
, after
))
3156 /* Emit insns to reload VALUE into a new register. VALUE is an
3157 auto-increment or auto-decrement RTX whose operand is a register or
3158 memory location; so reloading involves incrementing that location.
3159 IN is either identical to VALUE, or some cheaper place to reload
3160 value being incremented/decremented from.
3162 INC_AMOUNT is the number to increment or decrement by (always
3163 positive and ignored for POST_MODIFY/PRE_MODIFY).
3165 Return pseudo containing the result. */
3167 emit_inc (enum reg_class new_rclass
, rtx in
, rtx value
, int inc_amount
)
3169 /* REG or MEM to be copied and incremented. */
3170 rtx incloc
= XEXP (value
, 0);
3171 /* Nonzero if increment after copying. */
3172 int post
= (GET_CODE (value
) == POST_DEC
|| GET_CODE (value
) == POST_INC
3173 || GET_CODE (value
) == POST_MODIFY
);
3178 rtx real_in
= in
== value
? incloc
: in
;
3182 if (GET_CODE (value
) == PRE_MODIFY
|| GET_CODE (value
) == POST_MODIFY
)
3184 lra_assert (GET_CODE (XEXP (value
, 1)) == PLUS
3185 || GET_CODE (XEXP (value
, 1)) == MINUS
);
3186 lra_assert (rtx_equal_p (XEXP (XEXP (value
, 1), 0), XEXP (value
, 0)));
3187 plus_p
= GET_CODE (XEXP (value
, 1)) == PLUS
;
3188 inc
= XEXP (XEXP (value
, 1), 1);
3192 if (GET_CODE (value
) == PRE_DEC
|| GET_CODE (value
) == POST_DEC
)
3193 inc_amount
= -inc_amount
;
3195 inc
= GEN_INT (inc_amount
);
3198 if (! post
&& REG_P (incloc
))
3201 result
= lra_create_new_reg (GET_MODE (value
), value
, new_rclass
,
3204 if (real_in
!= result
)
3206 /* First copy the location to the result register. */
3207 lra_assert (REG_P (result
));
3208 emit_insn (gen_move_insn (result
, real_in
));
3211 /* We suppose that there are insns to add/sub with the constant
3212 increment permitted in {PRE/POST)_{DEC/INC/MODIFY}. At least the
3213 old reload worked with this assumption. If the assumption
3214 becomes wrong, we should use approach in function
3215 base_plus_disp_to_reg. */
3218 /* See if we can directly increment INCLOC. */
3219 last
= get_last_insn ();
3220 add_insn
= emit_insn (plus_p
3221 ? gen_add2_insn (incloc
, inc
)
3222 : gen_sub2_insn (incloc
, inc
));
3224 code
= recog_memoized (add_insn
);
3227 if (! post
&& result
!= incloc
)
3228 emit_insn (gen_move_insn (result
, incloc
));
3231 delete_insns_since (last
);
3234 /* If couldn't do the increment directly, must increment in RESULT.
3235 The way we do this depends on whether this is pre- or
3236 post-increment. For pre-increment, copy INCLOC to the reload
3237 register, increment it there, then save back. */
3240 if (real_in
!= result
)
3241 emit_insn (gen_move_insn (result
, real_in
));
3243 emit_insn (gen_add2_insn (result
, inc
));
3245 emit_insn (gen_sub2_insn (result
, inc
));
3246 if (result
!= incloc
)
3247 emit_insn (gen_move_insn (incloc
, result
));
3253 Because this might be a jump insn or a compare, and because
3254 RESULT may not be available after the insn in an input
3255 reload, we must do the incrementing before the insn being
3258 We have already copied IN to RESULT. Increment the copy in
3259 RESULT, save that back, then decrement RESULT so it has
3260 the original value. */
3262 emit_insn (gen_add2_insn (result
, inc
));
3264 emit_insn (gen_sub2_insn (result
, inc
));
3265 emit_insn (gen_move_insn (incloc
, result
));
3266 /* Restore non-modified value for the result. We prefer this
3267 way because it does not require an additional hard
3271 if (CONST_INT_P (inc
))
3272 emit_insn (gen_add2_insn (result
,
3273 gen_int_mode (-INTVAL (inc
),
3274 GET_MODE (result
))));
3276 emit_insn (gen_sub2_insn (result
, inc
));
3279 emit_insn (gen_add2_insn (result
, inc
));
3284 /* Return true if the current move insn does not need processing as we
3285 already know that it satisfies its constraints. */
3287 simple_move_p (void)
3290 enum reg_class dclass
, sclass
;
3292 lra_assert (curr_insn_set
!= NULL_RTX
);
3293 dest
= SET_DEST (curr_insn_set
);
3294 src
= SET_SRC (curr_insn_set
);
3295 return ((dclass
= get_op_class (dest
)) != NO_REGS
3296 && (sclass
= get_op_class (src
)) != NO_REGS
3297 /* The backend guarantees that register moves of cost 2
3298 never need reloads. */
3299 && targetm
.register_move_cost (GET_MODE (src
), sclass
, dclass
) == 2);
3302 /* Swap operands NOP and NOP + 1. */
3304 swap_operands (int nop
)
3306 machine_mode mode
= curr_operand_mode
[nop
];
3307 curr_operand_mode
[nop
] = curr_operand_mode
[nop
+ 1];
3308 curr_operand_mode
[nop
+ 1] = mode
;
3309 mode
= original_subreg_reg_mode
[nop
];
3310 original_subreg_reg_mode
[nop
] = original_subreg_reg_mode
[nop
+ 1];
3311 original_subreg_reg_mode
[nop
+ 1] = mode
;
3312 rtx x
= *curr_id
->operand_loc
[nop
];
3313 *curr_id
->operand_loc
[nop
] = *curr_id
->operand_loc
[nop
+ 1];
3314 *curr_id
->operand_loc
[nop
+ 1] = x
;
3315 /* Swap the duplicates too. */
3316 lra_update_dup (curr_id
, nop
);
3317 lra_update_dup (curr_id
, nop
+ 1);
3320 /* Main entry point of the constraint code: search the body of the
3321 current insn to choose the best alternative. It is mimicking insn
3322 alternative cost calculation model of former reload pass. That is
3323 because machine descriptions were written to use this model. This
3324 model can be changed in future. Make commutative operand exchange
3327 if CHECK_ONLY_P is false, do RTL changes to satisfy the
3328 constraints. Return true if any change happened during function
3331 If CHECK_ONLY_P is true then don't do any transformation. Just
3332 check that the insn satisfies all constraints. If the insn does
3333 not satisfy any constraint, return true. */
3335 curr_insn_transform (bool check_only_p
)
3341 signed char goal_alt_matched
[MAX_RECOG_OPERANDS
][MAX_RECOG_OPERANDS
];
3342 signed char match_inputs
[MAX_RECOG_OPERANDS
+ 1];
3343 rtx_insn
*before
, *after
;
3345 /* Flag that the insn has been changed through a transformation. */
3348 #ifdef SECONDARY_MEMORY_NEEDED
3351 int max_regno_before
;
3352 int reused_alternative_num
;
3354 curr_insn_set
= single_set (curr_insn
);
3355 if (curr_insn_set
!= NULL_RTX
&& simple_move_p ())
3358 no_input_reloads_p
= no_output_reloads_p
= false;
3359 goal_alt_number
= -1;
3360 change_p
= sec_mem_p
= false;
3361 /* JUMP_INSNs and CALL_INSNs are not allowed to have any output
3362 reloads; neither are insns that SET cc0. Insns that use CC0 are
3363 not allowed to have any input reloads. */
3364 if (JUMP_P (curr_insn
) || CALL_P (curr_insn
))
3365 no_output_reloads_p
= true;
3368 if (reg_referenced_p (cc0_rtx
, PATTERN (curr_insn
)))
3369 no_input_reloads_p
= true;
3370 if (reg_set_p (cc0_rtx
, PATTERN (curr_insn
)))
3371 no_output_reloads_p
= true;
3374 n_operands
= curr_static_id
->n_operands
;
3375 n_alternatives
= curr_static_id
->n_alternatives
;
3377 /* Just return "no reloads" if insn has no operands with
3379 if (n_operands
== 0 || n_alternatives
== 0)
3382 max_regno_before
= max_reg_num ();
3384 for (i
= 0; i
< n_operands
; i
++)
3386 goal_alt_matched
[i
][0] = -1;
3387 goal_alt_matches
[i
] = -1;
3390 commutative
= curr_static_id
->commutative
;
3392 /* Now see what we need for pseudos that didn't get hard regs or got
3393 the wrong kind of hard reg. For this, we must consider all the
3394 operands together against the register constraints. */
3396 best_losers
= best_overall
= INT_MAX
;
3397 best_reload_sum
= 0;
3399 curr_swapped
= false;
3400 goal_alt_swapped
= false;
3403 /* Make equivalence substitution and memory subreg elimination
3404 before address processing because an address legitimacy can
3405 depend on memory mode. */
3406 for (i
= 0; i
< n_operands
; i
++)
3408 rtx op
= *curr_id
->operand_loc
[i
];
3409 rtx subst
, old
= op
;
3410 bool op_change_p
= false;
3412 if (GET_CODE (old
) == SUBREG
)
3413 old
= SUBREG_REG (old
);
3414 subst
= get_equiv_with_elimination (old
, curr_insn
);
3415 original_subreg_reg_mode
[i
] = VOIDmode
;
3418 subst
= copy_rtx (subst
);
3419 lra_assert (REG_P (old
));
3420 if (GET_CODE (op
) != SUBREG
)
3421 *curr_id
->operand_loc
[i
] = subst
;
3424 SUBREG_REG (op
) = subst
;
3425 if (GET_MODE (subst
) == VOIDmode
)
3426 original_subreg_reg_mode
[i
] = GET_MODE (old
);
3428 if (lra_dump_file
!= NULL
)
3430 fprintf (lra_dump_file
,
3431 "Changing pseudo %d in operand %i of insn %u on equiv ",
3432 REGNO (old
), i
, INSN_UID (curr_insn
));
3433 dump_value_slim (lra_dump_file
, subst
, 1);
3434 fprintf (lra_dump_file
, "\n");
3436 op_change_p
= change_p
= true;
3438 if (simplify_operand_subreg (i
, GET_MODE (old
)) || op_change_p
)
3441 lra_update_dup (curr_id
, i
);
3445 /* Reload address registers and displacements. We do it before
3446 finding an alternative because of memory constraints. */
3447 before
= after
= NULL
;
3448 for (i
= 0; i
< n_operands
; i
++)
3449 if (! curr_static_id
->operand
[i
].is_operator
3450 && process_address (i
, check_only_p
, &before
, &after
))
3455 lra_update_dup (curr_id
, i
);
3459 /* If we've changed the instruction then any alternative that
3460 we chose previously may no longer be valid. */
3461 lra_set_used_insn_alternative (curr_insn
, -1);
3463 if (! check_only_p
&& curr_insn_set
!= NULL_RTX
3464 && check_and_process_move (&change_p
, &sec_mem_p
))
3469 reused_alternative_num
= check_only_p
? -1 : curr_id
->used_insn_alternative
;
3470 if (lra_dump_file
!= NULL
&& reused_alternative_num
>= 0)
3471 fprintf (lra_dump_file
, "Reusing alternative %d for insn #%u\n",
3472 reused_alternative_num
, INSN_UID (curr_insn
));
3474 if (process_alt_operands (reused_alternative_num
))
3478 return ! alt_p
|| best_losers
!= 0;
3480 /* If insn is commutative (it's safe to exchange a certain pair of
3481 operands) then we need to try each alternative twice, the second
3482 time matching those two operands as if we had exchanged them. To
3483 do this, really exchange them in operands.
3485 If we have just tried the alternatives the second time, return
3486 operands to normal and drop through. */
3488 if (reused_alternative_num
< 0 && commutative
>= 0)
3490 curr_swapped
= !curr_swapped
;
3493 swap_operands (commutative
);
3497 swap_operands (commutative
);
3500 if (! alt_p
&& ! sec_mem_p
)
3502 /* No alternative works with reloads?? */
3503 if (INSN_CODE (curr_insn
) >= 0)
3504 fatal_insn ("unable to generate reloads for:", curr_insn
);
3505 error_for_asm (curr_insn
,
3506 "inconsistent operand constraints in an %<asm%>");
3507 /* Avoid further trouble with this insn. */
3508 PATTERN (curr_insn
) = gen_rtx_USE (VOIDmode
, const0_rtx
);
3509 lra_invalidate_insn_data (curr_insn
);
3513 /* If the best alternative is with operands 1 and 2 swapped, swap
3514 them. Update the operand numbers of any reloads already
3517 if (goal_alt_swapped
)
3519 if (lra_dump_file
!= NULL
)
3520 fprintf (lra_dump_file
, " Commutative operand exchange in insn %u\n",
3521 INSN_UID (curr_insn
));
3523 /* Swap the duplicates too. */
3524 swap_operands (commutative
);
3528 #ifdef SECONDARY_MEMORY_NEEDED
3529 /* Some target macros SECONDARY_MEMORY_NEEDED (e.g. x86) are defined
3530 too conservatively. So we use the secondary memory only if there
3531 is no any alternative without reloads. */
3532 use_sec_mem_p
= false;
3534 use_sec_mem_p
= true;
3537 for (i
= 0; i
< n_operands
; i
++)
3538 if (! goal_alt_win
[i
] && ! goal_alt_match_win
[i
])
3540 use_sec_mem_p
= i
< n_operands
;
3545 rtx new_reg
, src
, dest
, rld
;
3546 machine_mode sec_mode
, rld_mode
;
3548 lra_assert (sec_mem_p
);
3549 lra_assert (curr_static_id
->operand
[0].type
== OP_OUT
3550 && curr_static_id
->operand
[1].type
== OP_IN
);
3551 dest
= *curr_id
->operand_loc
[0];
3552 src
= *curr_id
->operand_loc
[1];
3553 rld
= (GET_MODE_SIZE (GET_MODE (dest
)) <= GET_MODE_SIZE (GET_MODE (src
))
3555 rld_mode
= GET_MODE (rld
);
3556 #ifdef SECONDARY_MEMORY_NEEDED_MODE
3557 sec_mode
= SECONDARY_MEMORY_NEEDED_MODE (rld_mode
);
3559 sec_mode
= rld_mode
;
3561 new_reg
= lra_create_new_reg (sec_mode
, NULL_RTX
,
3562 NO_REGS
, "secondary");
3563 /* If the mode is changed, it should be wider. */
3564 lra_assert (GET_MODE_SIZE (sec_mode
) >= GET_MODE_SIZE (rld_mode
));
3565 if (sec_mode
!= rld_mode
)
3567 /* If the target says specifically to use another mode for
3568 secondary memory moves we can not reuse the original
3570 after
= emit_spill_move (false, new_reg
, dest
);
3571 lra_process_new_insns (curr_insn
, NULL
, after
,
3572 "Inserting the sec. move");
3573 /* We may have non null BEFORE here (e.g. after address
3575 push_to_sequence (before
);
3576 before
= emit_spill_move (true, new_reg
, src
);
3578 before
= get_insns ();
3580 lra_process_new_insns (curr_insn
, before
, NULL
, "Changing on");
3581 lra_set_insn_deleted (curr_insn
);
3583 else if (dest
== rld
)
3585 *curr_id
->operand_loc
[0] = new_reg
;
3586 after
= emit_spill_move (false, new_reg
, dest
);
3587 lra_process_new_insns (curr_insn
, NULL
, after
,
3588 "Inserting the sec. move");
3592 *curr_id
->operand_loc
[1] = new_reg
;
3593 /* See comments above. */
3594 push_to_sequence (before
);
3595 before
= emit_spill_move (true, new_reg
, src
);
3597 before
= get_insns ();
3599 lra_process_new_insns (curr_insn
, before
, NULL
,
3600 "Inserting the sec. move");
3602 lra_update_insn_regno_info (curr_insn
);
3607 lra_assert (goal_alt_number
>= 0);
3608 lra_set_used_insn_alternative (curr_insn
, goal_alt_number
);
3610 if (lra_dump_file
!= NULL
)
3614 fprintf (lra_dump_file
, " Choosing alt %d in insn %u:",
3615 goal_alt_number
, INSN_UID (curr_insn
));
3616 for (i
= 0; i
< n_operands
; i
++)
3618 p
= (curr_static_id
->operand_alternative
3619 [goal_alt_number
* n_operands
+ i
].constraint
);
3622 fprintf (lra_dump_file
, " (%d) ", i
);
3623 for (; *p
!= '\0' && *p
!= ',' && *p
!= '#'; p
++)
3624 fputc (*p
, lra_dump_file
);
3626 if (INSN_CODE (curr_insn
) >= 0
3627 && (p
= get_insn_name (INSN_CODE (curr_insn
))) != NULL
)
3628 fprintf (lra_dump_file
, " {%s}", p
);
3629 if (curr_id
->sp_offset
!= 0)
3630 fprintf (lra_dump_file
, " (sp_off=%" HOST_WIDE_INT_PRINT
"d)",
3631 curr_id
->sp_offset
);
3632 fprintf (lra_dump_file
, "\n");
3635 /* Right now, for any pair of operands I and J that are required to
3636 match, with J < I, goal_alt_matches[I] is J. Add I to
3637 goal_alt_matched[J]. */
3639 for (i
= 0; i
< n_operands
; i
++)
3640 if ((j
= goal_alt_matches
[i
]) >= 0)
3642 for (k
= 0; goal_alt_matched
[j
][k
] >= 0; k
++)
3644 /* We allow matching one output operand and several input
3647 || (curr_static_id
->operand
[j
].type
== OP_OUT
3648 && curr_static_id
->operand
[i
].type
== OP_IN
3649 && (curr_static_id
->operand
3650 [goal_alt_matched
[j
][0]].type
== OP_IN
)));
3651 goal_alt_matched
[j
][k
] = i
;
3652 goal_alt_matched
[j
][k
+ 1] = -1;
3655 for (i
= 0; i
< n_operands
; i
++)
3656 goal_alt_win
[i
] |= goal_alt_match_win
[i
];
3658 /* Any constants that aren't allowed and can't be reloaded into
3659 registers are here changed into memory references. */
3660 for (i
= 0; i
< n_operands
; i
++)
3661 if (goal_alt_win
[i
])
3664 enum reg_class new_class
;
3665 rtx reg
= *curr_id
->operand_loc
[i
];
3667 if (GET_CODE (reg
) == SUBREG
)
3668 reg
= SUBREG_REG (reg
);
3670 if (REG_P (reg
) && (regno
= REGNO (reg
)) >= FIRST_PSEUDO_REGISTER
)
3672 bool ok_p
= in_class_p (reg
, goal_alt
[i
], &new_class
);
3674 if (new_class
!= NO_REGS
&& get_reg_class (regno
) != new_class
)
3677 lra_change_class (regno
, new_class
, " Change to", true);
3683 const char *constraint
;
3685 rtx op
= *curr_id
->operand_loc
[i
];
3686 rtx subreg
= NULL_RTX
;
3687 machine_mode mode
= curr_operand_mode
[i
];
3689 if (GET_CODE (op
) == SUBREG
)
3692 op
= SUBREG_REG (op
);
3693 mode
= GET_MODE (op
);
3696 if (CONST_POOL_OK_P (mode
, op
)
3697 && ((targetm
.preferred_reload_class
3698 (op
, (enum reg_class
) goal_alt
[i
]) == NO_REGS
)
3699 || no_input_reloads_p
))
3701 rtx tem
= force_const_mem (mode
, op
);
3704 if (subreg
!= NULL_RTX
)
3705 tem
= gen_rtx_SUBREG (mode
, tem
, SUBREG_BYTE (subreg
));
3707 *curr_id
->operand_loc
[i
] = tem
;
3708 lra_update_dup (curr_id
, i
);
3709 process_address (i
, false, &before
, &after
);
3711 /* If the alternative accepts constant pool refs directly
3712 there will be no reload needed at all. */
3713 if (subreg
!= NULL_RTX
)
3715 /* Skip alternatives before the one requested. */
3716 constraint
= (curr_static_id
->operand_alternative
3717 [goal_alt_number
* n_operands
+ i
].constraint
);
3719 (c
= *constraint
) && c
!= ',' && c
!= '#';
3720 constraint
+= CONSTRAINT_LEN (c
, constraint
))
3722 enum constraint_num cn
= lookup_constraint (constraint
);
3723 if (insn_extra_memory_constraint (cn
)
3724 && satisfies_memory_constraint_p (tem
, cn
))
3727 if (c
== '\0' || c
== ',' || c
== '#')
3730 goal_alt_win
[i
] = true;
3734 for (i
= 0; i
< n_operands
; i
++)
3737 bool optional_p
= false;
3739 rtx op
= *curr_id
->operand_loc
[i
];
3741 if (goal_alt_win
[i
])
3743 if (goal_alt
[i
] == NO_REGS
3745 /* When we assign NO_REGS it means that we will not
3746 assign a hard register to the scratch pseudo by
3747 assigment pass and the scratch pseudo will be
3748 spilled. Spilled scratch pseudos are transformed
3749 back to scratches at the LRA end. */
3750 && lra_former_scratch_operand_p (curr_insn
, i
))
3752 int regno
= REGNO (op
);
3753 lra_change_class (regno
, NO_REGS
, " Change to", true);
3754 if (lra_get_regno_hard_regno (regno
) >= 0)
3755 /* We don't have to mark all insn affected by the
3756 spilled pseudo as there is only one such insn, the
3758 reg_renumber
[regno
] = -1;
3760 /* We can do an optional reload. If the pseudo got a hard
3761 reg, we might improve the code through inheritance. If
3762 it does not get a hard register we coalesce memory/memory
3763 moves later. Ignore move insns to avoid cycling. */
3765 && lra_undo_inheritance_iter
< LRA_MAX_INHERITANCE_PASSES
3766 && goal_alt
[i
] != NO_REGS
&& REG_P (op
)
3767 && (regno
= REGNO (op
)) >= FIRST_PSEUDO_REGISTER
3768 && regno
< new_regno_start
3769 && ! lra_former_scratch_p (regno
)
3770 && reg_renumber
[regno
] < 0
3771 /* Check that the optional reload pseudo will be able to
3772 hold given mode value. */
3773 && ! (prohibited_class_reg_set_mode_p
3774 (goal_alt
[i
], reg_class_contents
[goal_alt
[i
]],
3775 PSEUDO_REGNO_MODE (regno
)))
3776 && (curr_insn_set
== NULL_RTX
3777 || !((REG_P (SET_SRC (curr_insn_set
))
3778 || MEM_P (SET_SRC (curr_insn_set
))
3779 || GET_CODE (SET_SRC (curr_insn_set
)) == SUBREG
)
3780 && (REG_P (SET_DEST (curr_insn_set
))
3781 || MEM_P (SET_DEST (curr_insn_set
))
3782 || GET_CODE (SET_DEST (curr_insn_set
)) == SUBREG
))))
3788 /* Operands that match previous ones have already been handled. */
3789 if (goal_alt_matches
[i
] >= 0)
3792 /* We should not have an operand with a non-offsettable address
3793 appearing where an offsettable address will do. It also may
3794 be a case when the address should be special in other words
3795 not a general one (e.g. it needs no index reg). */
3796 if (goal_alt_matched
[i
][0] == -1 && goal_alt_offmemok
[i
] && MEM_P (op
))
3798 enum reg_class rclass
;
3799 rtx
*loc
= &XEXP (op
, 0);
3800 enum rtx_code code
= GET_CODE (*loc
);
3802 push_to_sequence (before
);
3803 rclass
= base_reg_class (GET_MODE (op
), MEM_ADDR_SPACE (op
),
3805 if (GET_RTX_CLASS (code
) == RTX_AUTOINC
)
3806 new_reg
= emit_inc (rclass
, *loc
, *loc
,
3807 /* This value does not matter for MODIFY. */
3808 GET_MODE_SIZE (GET_MODE (op
)));
3809 else if (get_reload_reg (OP_IN
, Pmode
, *loc
, rclass
, FALSE
,
3810 "offsetable address", &new_reg
))
3811 lra_emit_move (new_reg
, *loc
);
3812 before
= get_insns ();
3815 lra_update_dup (curr_id
, i
);
3817 else if (goal_alt_matched
[i
][0] == -1)
3821 int hard_regno
, byte
;
3822 enum op_type type
= curr_static_id
->operand
[i
].type
;
3824 loc
= curr_id
->operand_loc
[i
];
3825 mode
= curr_operand_mode
[i
];
3826 if (GET_CODE (*loc
) == SUBREG
)
3828 reg
= SUBREG_REG (*loc
);
3829 byte
= SUBREG_BYTE (*loc
);
3831 /* Strict_low_part requires reload the register not
3832 the sub-register. */
3833 && (curr_static_id
->operand
[i
].strict_low
3834 || (GET_MODE_SIZE (mode
)
3835 <= GET_MODE_SIZE (GET_MODE (reg
))
3837 = get_try_hard_regno (REGNO (reg
))) >= 0
3838 && (simplify_subreg_regno
3840 GET_MODE (reg
), byte
, mode
) < 0)
3841 && (goal_alt
[i
] == NO_REGS
3842 || (simplify_subreg_regno
3843 (ira_class_hard_regs
[goal_alt
[i
]][0],
3844 GET_MODE (reg
), byte
, mode
) >= 0)))))
3848 loc
= &SUBREG_REG (*loc
);
3849 mode
= GET_MODE (*loc
);
3853 if (get_reload_reg (type
, mode
, old
, goal_alt
[i
],
3854 loc
!= curr_id
->operand_loc
[i
], "", &new_reg
)
3857 push_to_sequence (before
);
3858 lra_emit_move (new_reg
, old
);
3859 before
= get_insns ();
3864 && find_reg_note (curr_insn
, REG_UNUSED
, old
) == NULL_RTX
)
3867 lra_emit_move (type
== OP_INOUT
? copy_rtx (old
) : old
, new_reg
);
3869 after
= get_insns ();
3873 for (j
= 0; j
< goal_alt_dont_inherit_ops_num
; j
++)
3874 if (goal_alt_dont_inherit_ops
[j
] == i
)
3876 lra_set_regno_unique_value (REGNO (new_reg
));
3879 lra_update_dup (curr_id
, i
);
3881 else if (curr_static_id
->operand
[i
].type
== OP_IN
3882 && (curr_static_id
->operand
[goal_alt_matched
[i
][0]].type
3885 /* generate reloads for input and matched outputs. */
3886 match_inputs
[0] = i
;
3887 match_inputs
[1] = -1;
3888 match_reload (goal_alt_matched
[i
][0], match_inputs
,
3889 goal_alt
[i
], &before
, &after
);
3891 else if (curr_static_id
->operand
[i
].type
== OP_OUT
3892 && (curr_static_id
->operand
[goal_alt_matched
[i
][0]].type
3894 /* Generate reloads for output and matched inputs. */
3895 match_reload (i
, goal_alt_matched
[i
], goal_alt
[i
], &before
, &after
);
3896 else if (curr_static_id
->operand
[i
].type
== OP_IN
3897 && (curr_static_id
->operand
[goal_alt_matched
[i
][0]].type
3900 /* Generate reloads for matched inputs. */
3901 match_inputs
[0] = i
;
3902 for (j
= 0; (k
= goal_alt_matched
[i
][j
]) >= 0; j
++)
3903 match_inputs
[j
+ 1] = k
;
3904 match_inputs
[j
+ 1] = -1;
3905 match_reload (-1, match_inputs
, goal_alt
[i
], &before
, &after
);
3908 /* We must generate code in any case when function
3909 process_alt_operands decides that it is possible. */
3913 lra_assert (REG_P (op
));
3915 op
= *curr_id
->operand_loc
[i
]; /* Substitution. */
3916 if (GET_CODE (op
) == SUBREG
)
3917 op
= SUBREG_REG (op
);
3918 gcc_assert (REG_P (op
) && (int) REGNO (op
) >= new_regno_start
);
3919 bitmap_set_bit (&lra_optional_reload_pseudos
, REGNO (op
));
3920 lra_reg_info
[REGNO (op
)].restore_regno
= regno
;
3921 if (lra_dump_file
!= NULL
)
3922 fprintf (lra_dump_file
,
3923 " Making reload reg %d for reg %d optional\n",
3927 if (before
!= NULL_RTX
|| after
!= NULL_RTX
3928 || max_regno_before
!= max_reg_num ())
3932 lra_update_operator_dups (curr_id
);
3933 /* Something changes -- process the insn. */
3934 lra_update_insn_regno_info (curr_insn
);
3936 lra_process_new_insns (curr_insn
, before
, after
, "Inserting insn reload");
3940 /* Return true if INSN satisfies all constraints. In other words, no
3941 reload insns are needed. */
3943 lra_constrain_insn (rtx_insn
*insn
)
3945 int saved_new_regno_start
= new_regno_start
;
3946 int saved_new_insn_uid_start
= new_insn_uid_start
;
3950 curr_id
= lra_get_insn_recog_data (curr_insn
);
3951 curr_static_id
= curr_id
->insn_static_data
;
3952 new_insn_uid_start
= get_max_uid ();
3953 new_regno_start
= max_reg_num ();
3954 change_p
= curr_insn_transform (true);
3955 new_regno_start
= saved_new_regno_start
;
3956 new_insn_uid_start
= saved_new_insn_uid_start
;
3960 /* Return true if X is in LIST. */
3962 in_list_p (rtx x
, rtx list
)
3964 for (; list
!= NULL_RTX
; list
= XEXP (list
, 1))
3965 if (XEXP (list
, 0) == x
)
3970 /* Return true if X contains an allocatable hard register (if
3971 HARD_REG_P) or a (spilled if SPILLED_P) pseudo. */
3973 contains_reg_p (rtx x
, bool hard_reg_p
, bool spilled_p
)
3979 code
= GET_CODE (x
);
3982 int regno
= REGNO (x
);
3983 HARD_REG_SET alloc_regs
;
3987 if (regno
>= FIRST_PSEUDO_REGISTER
)
3988 regno
= lra_get_regno_hard_regno (regno
);
3991 COMPL_HARD_REG_SET (alloc_regs
, lra_no_alloc_regs
);
3992 return overlaps_hard_reg_set_p (alloc_regs
, GET_MODE (x
), regno
);
3996 if (regno
< FIRST_PSEUDO_REGISTER
)
4000 return lra_get_regno_hard_regno (regno
) < 0;
4003 fmt
= GET_RTX_FORMAT (code
);
4004 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
4008 if (contains_reg_p (XEXP (x
, i
), hard_reg_p
, spilled_p
))
4011 else if (fmt
[i
] == 'E')
4013 for (j
= XVECLEN (x
, i
) - 1; j
>= 0; j
--)
4014 if (contains_reg_p (XVECEXP (x
, i
, j
), hard_reg_p
, spilled_p
))
4021 /* Return true if X contains a symbol reg. */
4023 contains_symbol_ref_p (rtx x
)
4029 code
= GET_CODE (x
);
4030 if (code
== SYMBOL_REF
)
4032 fmt
= GET_RTX_FORMAT (code
);
4033 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
4037 if (contains_symbol_ref_p (XEXP (x
, i
)))
4040 else if (fmt
[i
] == 'E')
4042 for (j
= XVECLEN (x
, i
) - 1; j
>= 0; j
--)
4043 if (contains_symbol_ref_p (XVECEXP (x
, i
, j
)))
4050 /* Process all regs in location *LOC and change them on equivalent
4051 substitution. Return true if any change was done. */
4053 loc_equivalence_change_p (rtx
*loc
)
4055 rtx subst
, reg
, x
= *loc
;
4056 bool result
= false;
4057 enum rtx_code code
= GET_CODE (x
);
4063 reg
= SUBREG_REG (x
);
4064 if ((subst
= get_equiv_with_elimination (reg
, curr_insn
)) != reg
4065 && GET_MODE (subst
) == VOIDmode
)
4067 /* We cannot reload debug location. Simplify subreg here
4068 while we know the inner mode. */
4069 *loc
= simplify_gen_subreg (GET_MODE (x
), subst
,
4070 GET_MODE (reg
), SUBREG_BYTE (x
));
4074 if (code
== REG
&& (subst
= get_equiv_with_elimination (x
, curr_insn
)) != x
)
4080 /* Scan all the operand sub-expressions. */
4081 fmt
= GET_RTX_FORMAT (code
);
4082 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
4085 result
= loc_equivalence_change_p (&XEXP (x
, i
)) || result
;
4086 else if (fmt
[i
] == 'E')
4087 for (j
= XVECLEN (x
, i
) - 1; j
>= 0; j
--)
4089 = loc_equivalence_change_p (&XVECEXP (x
, i
, j
)) || result
;
4094 /* Similar to loc_equivalence_change_p, but for use as
4095 simplify_replace_fn_rtx callback. DATA is insn for which the
4096 elimination is done. If it null we don't do the elimination. */
4098 loc_equivalence_callback (rtx loc
, const_rtx
, void *data
)
4103 rtx subst
= (data
== NULL
4104 ? get_equiv (loc
) : get_equiv_with_elimination (loc
, (rtx_insn
*) data
));
4111 /* Maximum number of generated reload insns per an insn. It is for
4112 preventing this pass cycling in a bug case. */
4113 #define MAX_RELOAD_INSNS_NUMBER LRA_MAX_INSN_RELOADS
4115 /* The current iteration number of this LRA pass. */
4116 int lra_constraint_iter
;
4118 /* True if we substituted equiv which needs checking register
4119 allocation correctness because the equivalent value contains
4120 allocatable hard registers or when we restore multi-register
4122 bool lra_risky_transformations_p
;
4124 /* Return true if REGNO is referenced in more than one block. */
4126 multi_block_pseudo_p (int regno
)
4128 basic_block bb
= NULL
;
4132 if (regno
< FIRST_PSEUDO_REGISTER
)
4135 EXECUTE_IF_SET_IN_BITMAP (&lra_reg_info
[regno
].insn_bitmap
, 0, uid
, bi
)
4137 bb
= BLOCK_FOR_INSN (lra_insn_recog_data
[uid
]->insn
);
4138 else if (BLOCK_FOR_INSN (lra_insn_recog_data
[uid
]->insn
) != bb
)
4143 /* Return true if LIST contains a deleted insn. */
4145 contains_deleted_insn_p (rtx_insn_list
*list
)
4147 for (; list
!= NULL_RTX
; list
= list
->next ())
4148 if (NOTE_P (list
->insn ())
4149 && NOTE_KIND (list
->insn ()) == NOTE_INSN_DELETED
)
4154 /* Return true if X contains a pseudo dying in INSN. */
4156 dead_pseudo_p (rtx x
, rtx insn
)
4163 return (insn
!= NULL_RTX
4164 && find_regno_note (insn
, REG_DEAD
, REGNO (x
)) != NULL_RTX
);
4165 code
= GET_CODE (x
);
4166 fmt
= GET_RTX_FORMAT (code
);
4167 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
4171 if (dead_pseudo_p (XEXP (x
, i
), insn
))
4174 else if (fmt
[i
] == 'E')
4176 for (j
= XVECLEN (x
, i
) - 1; j
>= 0; j
--)
4177 if (dead_pseudo_p (XVECEXP (x
, i
, j
), insn
))
4184 /* Return true if INSN contains a dying pseudo in INSN right hand
4187 insn_rhs_dead_pseudo_p (rtx_insn
*insn
)
4189 rtx set
= single_set (insn
);
4191 gcc_assert (set
!= NULL
);
4192 return dead_pseudo_p (SET_SRC (set
), insn
);
4195 /* Return true if any init insn of REGNO contains a dying pseudo in
4196 insn right hand side. */
4198 init_insn_rhs_dead_pseudo_p (int regno
)
4200 rtx_insn_list
*insns
= ira_reg_equiv
[regno
].init_insns
;
4204 for (; insns
!= NULL_RTX
; insns
= insns
->next ())
4205 if (insn_rhs_dead_pseudo_p (insns
->insn ()))
4210 /* Return TRUE if REGNO has a reverse equivalence. The equivalence is
4211 reverse only if we have one init insn with given REGNO as a
4214 reverse_equiv_p (int regno
)
4216 rtx_insn_list
*insns
= ira_reg_equiv
[regno
].init_insns
;
4221 if (! INSN_P (insns
->insn ())
4222 || insns
->next () != NULL
)
4224 if ((set
= single_set (insns
->insn ())) == NULL_RTX
)
4226 return REG_P (SET_SRC (set
)) && (int) REGNO (SET_SRC (set
)) == regno
;
4229 /* Return TRUE if REGNO was reloaded in an equivalence init insn. We
4230 call this function only for non-reverse equivalence. */
4232 contains_reloaded_insn_p (int regno
)
4235 rtx_insn_list
*list
= ira_reg_equiv
[regno
].init_insns
;
4237 for (; list
!= NULL
; list
= list
->next ())
4238 if ((set
= single_set (list
->insn ())) == NULL_RTX
4239 || ! REG_P (SET_DEST (set
))
4240 || (int) REGNO (SET_DEST (set
)) != regno
)
4245 /* Entry function of LRA constraint pass. Return true if the
4246 constraint pass did change the code. */
4248 lra_constraints (bool first_p
)
4251 int i
, hard_regno
, new_insns_num
;
4252 unsigned int min_len
, new_min_len
, uid
;
4253 rtx set
, x
, reg
, dest_reg
;
4254 basic_block last_bb
;
4255 bitmap_head equiv_insn_bitmap
;
4258 lra_constraint_iter
++;
4259 if (lra_dump_file
!= NULL
)
4260 fprintf (lra_dump_file
, "\n********** Local #%d: **********\n\n",
4261 lra_constraint_iter
);
4263 if (pic_offset_table_rtx
4264 && REGNO (pic_offset_table_rtx
) >= FIRST_PSEUDO_REGISTER
)
4265 lra_risky_transformations_p
= true;
4267 lra_risky_transformations_p
= false;
4268 new_insn_uid_start
= get_max_uid ();
4269 new_regno_start
= first_p
? lra_constraint_new_regno_start
: max_reg_num ();
4270 /* Mark used hard regs for target stack size calulations. */
4271 for (i
= FIRST_PSEUDO_REGISTER
; i
< new_regno_start
; i
++)
4272 if (lra_reg_info
[i
].nrefs
!= 0
4273 && (hard_regno
= lra_get_regno_hard_regno (i
)) >= 0)
4277 nregs
= hard_regno_nregs
[hard_regno
][lra_reg_info
[i
].biggest_mode
];
4278 for (j
= 0; j
< nregs
; j
++)
4279 df_set_regs_ever_live (hard_regno
+ j
, true);
4281 /* Do elimination before the equivalence processing as we can spill
4282 some pseudos during elimination. */
4283 lra_eliminate (false, first_p
);
4284 bitmap_initialize (&equiv_insn_bitmap
, ®_obstack
);
4285 for (i
= FIRST_PSEUDO_REGISTER
; i
< new_regno_start
; i
++)
4286 if (lra_reg_info
[i
].nrefs
!= 0)
4288 ira_reg_equiv
[i
].profitable_p
= true;
4289 reg
= regno_reg_rtx
[i
];
4290 if (lra_get_regno_hard_regno (i
) < 0 && (x
= get_equiv (reg
)) != reg
)
4292 bool pseudo_p
= contains_reg_p (x
, false, false);
4294 /* After RTL transformation, we can not guarantee that
4295 pseudo in the substitution was not reloaded which might
4296 make equivalence invalid. For example, in reverse
4303 the memory address register was reloaded before the 2nd
4305 if ((! first_p
&& pseudo_p
)
4306 /* We don't use DF for compilation speed sake. So it
4307 is problematic to update live info when we use an
4308 equivalence containing pseudos in more than one
4310 || (pseudo_p
&& multi_block_pseudo_p (i
))
4311 /* If an init insn was deleted for some reason, cancel
4312 the equiv. We could update the equiv insns after
4313 transformations including an equiv insn deletion
4314 but it is not worthy as such cases are extremely
4316 || contains_deleted_insn_p (ira_reg_equiv
[i
].init_insns
)
4317 /* If it is not a reverse equivalence, we check that a
4318 pseudo in rhs of the init insn is not dying in the
4319 insn. Otherwise, the live info at the beginning of
4320 the corresponding BB might be wrong after we
4321 removed the insn. When the equiv can be a
4322 constant, the right hand side of the init insn can
4324 || (! reverse_equiv_p (i
)
4325 && (init_insn_rhs_dead_pseudo_p (i
)
4326 /* If we reloaded the pseudo in an equivalence
4327 init insn, we can not remove the equiv init
4328 insns and the init insns might write into
4329 const memory in this case. */
4330 || contains_reloaded_insn_p (i
)))
4331 /* Prevent access beyond equivalent memory for
4332 paradoxical subregs. */
4334 && (GET_MODE_SIZE (lra_reg_info
[i
].biggest_mode
)
4335 > GET_MODE_SIZE (GET_MODE (x
))))
4336 || (pic_offset_table_rtx
4337 && ((CONST_POOL_OK_P (PSEUDO_REGNO_MODE (i
), x
)
4338 && (targetm
.preferred_reload_class
4339 (x
, lra_get_allocno_class (i
)) == NO_REGS
))
4340 || contains_symbol_ref_p (x
))))
4341 ira_reg_equiv
[i
].defined_p
= false;
4342 if (contains_reg_p (x
, false, true))
4343 ira_reg_equiv
[i
].profitable_p
= false;
4344 if (get_equiv (reg
) != reg
)
4345 bitmap_ior_into (&equiv_insn_bitmap
, &lra_reg_info
[i
].insn_bitmap
);
4348 for (i
= FIRST_PSEUDO_REGISTER
; i
< new_regno_start
; i
++)
4350 /* We should add all insns containing pseudos which should be
4351 substituted by their equivalences. */
4352 EXECUTE_IF_SET_IN_BITMAP (&equiv_insn_bitmap
, 0, uid
, bi
)
4353 lra_push_insn_by_uid (uid
);
4354 min_len
= lra_insn_stack_length ();
4358 while ((new_min_len
= lra_insn_stack_length ()) != 0)
4360 curr_insn
= lra_pop_insn ();
4362 curr_bb
= BLOCK_FOR_INSN (curr_insn
);
4363 if (curr_bb
!= last_bb
)
4366 bb_reload_num
= lra_curr_reload_num
;
4368 if (min_len
> new_min_len
)
4370 min_len
= new_min_len
;
4373 if (new_insns_num
> MAX_RELOAD_INSNS_NUMBER
)
4375 ("Max. number of generated reload insns per insn is achieved (%d)\n",
4376 MAX_RELOAD_INSNS_NUMBER
);
4378 if (DEBUG_INSN_P (curr_insn
))
4380 /* We need to check equivalence in debug insn and change
4381 pseudo to the equivalent value if necessary. */
4382 curr_id
= lra_get_insn_recog_data (curr_insn
);
4383 if (bitmap_bit_p (&equiv_insn_bitmap
, INSN_UID (curr_insn
)))
4385 rtx old
= *curr_id
->operand_loc
[0];
4386 *curr_id
->operand_loc
[0]
4387 = simplify_replace_fn_rtx (old
, NULL_RTX
,
4388 loc_equivalence_callback
, curr_insn
);
4389 if (old
!= *curr_id
->operand_loc
[0])
4391 lra_update_insn_regno_info (curr_insn
);
4396 else if (INSN_P (curr_insn
))
4398 if ((set
= single_set (curr_insn
)) != NULL_RTX
)
4400 dest_reg
= SET_DEST (set
);
4401 /* The equivalence pseudo could be set up as SUBREG in a
4402 case when it is a call restore insn in a mode
4403 different from the pseudo mode. */
4404 if (GET_CODE (dest_reg
) == SUBREG
)
4405 dest_reg
= SUBREG_REG (dest_reg
);
4406 if ((REG_P (dest_reg
)
4407 && (x
= get_equiv (dest_reg
)) != dest_reg
4408 /* Remove insns which set up a pseudo whose value
4409 can not be changed. Such insns might be not in
4410 init_insns because we don't update equiv data
4411 during insn transformations.
4413 As an example, let suppose that a pseudo got
4414 hard register and on the 1st pass was not
4415 changed to equivalent constant. We generate an
4416 additional insn setting up the pseudo because of
4417 secondary memory movement. Then the pseudo is
4418 spilled and we use the equiv constant. In this
4419 case we should remove the additional insn and
4420 this insn is not init_insns list. */
4421 && (! MEM_P (x
) || MEM_READONLY_P (x
)
4422 /* Check that this is actually an insn setting
4423 up the equivalence. */
4424 || in_list_p (curr_insn
,
4426 [REGNO (dest_reg
)].init_insns
)))
4427 || (((x
= get_equiv (SET_SRC (set
))) != SET_SRC (set
))
4428 && in_list_p (curr_insn
,
4430 [REGNO (SET_SRC (set
))].init_insns
)))
4432 /* This is equiv init insn of pseudo which did not get a
4433 hard register -- remove the insn. */
4434 if (lra_dump_file
!= NULL
)
4436 fprintf (lra_dump_file
,
4437 " Removing equiv init insn %i (freq=%d)\n",
4438 INSN_UID (curr_insn
),
4439 REG_FREQ_FROM_BB (BLOCK_FOR_INSN (curr_insn
)));
4440 dump_insn_slim (lra_dump_file
, curr_insn
);
4442 if (contains_reg_p (x
, true, false))
4443 lra_risky_transformations_p
= true;
4444 lra_set_insn_deleted (curr_insn
);
4448 curr_id
= lra_get_insn_recog_data (curr_insn
);
4449 curr_static_id
= curr_id
->insn_static_data
;
4450 init_curr_insn_input_reloads ();
4451 init_curr_operand_mode ();
4452 if (curr_insn_transform (false))
4454 /* Check non-transformed insns too for equiv change as USE
4455 or CLOBBER don't need reloads but can contain pseudos
4456 being changed on their equivalences. */
4457 else if (bitmap_bit_p (&equiv_insn_bitmap
, INSN_UID (curr_insn
))
4458 && loc_equivalence_change_p (&PATTERN (curr_insn
)))
4460 lra_update_insn_regno_info (curr_insn
);
4465 bitmap_clear (&equiv_insn_bitmap
);
4466 /* If we used a new hard regno, changed_p should be true because the
4467 hard reg is assigned to a new pseudo. */
4468 #ifdef ENABLE_CHECKING
4471 for (i
= FIRST_PSEUDO_REGISTER
; i
< new_regno_start
; i
++)
4472 if (lra_reg_info
[i
].nrefs
!= 0
4473 && (hard_regno
= lra_get_regno_hard_regno (i
)) >= 0)
4475 int j
, nregs
= hard_regno_nregs
[hard_regno
][PSEUDO_REGNO_MODE (i
)];
4477 for (j
= 0; j
< nregs
; j
++)
4478 lra_assert (df_regs_ever_live_p (hard_regno
+ j
));
4485 /* Initiate the LRA constraint pass. It is done once per
4488 lra_constraints_init (void)
4492 /* Finalize the LRA constraint pass. It is done once per
4495 lra_constraints_finish (void)
4501 /* This page contains code to do inheritance/split
4504 /* Number of reloads passed so far in current EBB. */
4505 static int reloads_num
;
4507 /* Number of calls passed so far in current EBB. */
4508 static int calls_num
;
4510 /* Current reload pseudo check for validity of elements in
4512 static int curr_usage_insns_check
;
4514 /* Info about last usage of registers in EBB to do inheritance/split
4515 transformation. Inheritance transformation is done from a spilled
4516 pseudo and split transformations from a hard register or a pseudo
4517 assigned to a hard register. */
4520 /* If the value is equal to CURR_USAGE_INSNS_CHECK, then the member
4521 value INSNS is valid. The insns is chain of optional debug insns
4522 and a finishing non-debug insn using the corresponding reg. The
4523 value is also used to mark the registers which are set up in the
4524 current insn. The negated insn uid is used for this. */
4526 /* Value of global reloads_num at the last insn in INSNS. */
4528 /* Value of global reloads_nums at the last insn in INSNS. */
4530 /* It can be true only for splitting. And it means that the restore
4531 insn should be put after insn given by the following member. */
4533 /* Next insns in the current EBB which use the original reg and the
4534 original reg value is not changed between the current insn and
4535 the next insns. In order words, e.g. for inheritance, if we need
4536 to use the original reg value again in the next insns we can try
4537 to use the value in a hard register from a reload insn of the
4542 /* Map: regno -> corresponding pseudo usage insns. */
4543 static struct usage_insns
*usage_insns
;
4546 setup_next_usage_insn (int regno
, rtx insn
, int reloads_num
, bool after_p
)
4548 usage_insns
[regno
].check
= curr_usage_insns_check
;
4549 usage_insns
[regno
].insns
= insn
;
4550 usage_insns
[regno
].reloads_num
= reloads_num
;
4551 usage_insns
[regno
].calls_num
= calls_num
;
4552 usage_insns
[regno
].after_p
= after_p
;
4555 /* The function is used to form list REGNO usages which consists of
4556 optional debug insns finished by a non-debug insn using REGNO.
4557 RELOADS_NUM is current number of reload insns processed so far. */
4559 add_next_usage_insn (int regno
, rtx insn
, int reloads_num
)
4561 rtx next_usage_insns
;
4563 if (usage_insns
[regno
].check
== curr_usage_insns_check
4564 && (next_usage_insns
= usage_insns
[regno
].insns
) != NULL_RTX
4565 && DEBUG_INSN_P (insn
))
4567 /* Check that we did not add the debug insn yet. */
4568 if (next_usage_insns
!= insn
4569 && (GET_CODE (next_usage_insns
) != INSN_LIST
4570 || XEXP (next_usage_insns
, 0) != insn
))
4571 usage_insns
[regno
].insns
= gen_rtx_INSN_LIST (VOIDmode
, insn
,
4574 else if (NONDEBUG_INSN_P (insn
))
4575 setup_next_usage_insn (regno
, insn
, reloads_num
, false);
4577 usage_insns
[regno
].check
= 0;
4580 /* Return first non-debug insn in list USAGE_INSNS. */
4582 skip_usage_debug_insns (rtx usage_insns
)
4586 /* Skip debug insns. */
4587 for (insn
= usage_insns
;
4588 insn
!= NULL_RTX
&& GET_CODE (insn
) == INSN_LIST
;
4589 insn
= XEXP (insn
, 1))
4591 return safe_as_a
<rtx_insn
*> (insn
);
4594 /* Return true if we need secondary memory moves for insn in
4595 USAGE_INSNS after inserting inherited pseudo of class INHER_CL
4598 check_secondary_memory_needed_p (enum reg_class inher_cl ATTRIBUTE_UNUSED
,
4599 rtx usage_insns ATTRIBUTE_UNUSED
)
4601 #ifndef SECONDARY_MEMORY_NEEDED
4608 if (inher_cl
== ALL_REGS
4609 || (insn
= skip_usage_debug_insns (usage_insns
)) == NULL_RTX
)
4611 lra_assert (INSN_P (insn
));
4612 if ((set
= single_set (insn
)) == NULL_RTX
|| ! REG_P (SET_DEST (set
)))
4614 dest
= SET_DEST (set
);
4617 lra_assert (inher_cl
!= NO_REGS
);
4618 cl
= get_reg_class (REGNO (dest
));
4619 return (cl
!= NO_REGS
&& cl
!= ALL_REGS
4620 && SECONDARY_MEMORY_NEEDED (inher_cl
, cl
, GET_MODE (dest
)));
4624 /* Registers involved in inheritance/split in the current EBB
4625 (inheritance/split pseudos and original registers). */
4626 static bitmap_head check_only_regs
;
4628 /* Do inheritance transformations for insn INSN, which defines (if
4629 DEF_P) or uses ORIGINAL_REGNO. NEXT_USAGE_INSNS specifies which
4630 instruction in the EBB next uses ORIGINAL_REGNO; it has the same
4631 form as the "insns" field of usage_insns. Return true if we
4632 succeed in such transformation.
4634 The transformations look like:
4637 ... p <- i (new insn)
4639 <- ... p ... <- ... i ...
4641 ... i <- p (new insn)
4642 <- ... p ... <- ... i ...
4644 <- ... p ... <- ... i ...
4645 where p is a spilled original pseudo and i is a new inheritance pseudo.
4648 The inheritance pseudo has the smallest class of two classes CL and
4649 class of ORIGINAL REGNO. */
4651 inherit_reload_reg (bool def_p
, int original_regno
,
4652 enum reg_class cl
, rtx_insn
*insn
, rtx next_usage_insns
)
4654 if (optimize_function_for_size_p (cfun
))
4657 enum reg_class rclass
= lra_get_allocno_class (original_regno
);
4658 rtx original_reg
= regno_reg_rtx
[original_regno
];
4659 rtx new_reg
, usage_insn
;
4660 rtx_insn
*new_insns
;
4662 lra_assert (! usage_insns
[original_regno
].after_p
);
4663 if (lra_dump_file
!= NULL
)
4664 fprintf (lra_dump_file
,
4665 " <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n");
4666 if (! ira_reg_classes_intersect_p
[cl
][rclass
])
4668 if (lra_dump_file
!= NULL
)
4670 fprintf (lra_dump_file
,
4671 " Rejecting inheritance for %d "
4672 "because of disjoint classes %s and %s\n",
4673 original_regno
, reg_class_names
[cl
],
4674 reg_class_names
[rclass
]);
4675 fprintf (lra_dump_file
,
4676 " >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n");
4680 if ((ira_class_subset_p
[cl
][rclass
] && cl
!= rclass
)
4681 /* We don't use a subset of two classes because it can be
4682 NO_REGS. This transformation is still profitable in most
4683 cases even if the classes are not intersected as register
4684 move is probably cheaper than a memory load. */
4685 || ira_class_hard_regs_num
[cl
] < ira_class_hard_regs_num
[rclass
])
4687 if (lra_dump_file
!= NULL
)
4688 fprintf (lra_dump_file
, " Use smallest class of %s and %s\n",
4689 reg_class_names
[cl
], reg_class_names
[rclass
]);
4693 if (check_secondary_memory_needed_p (rclass
, next_usage_insns
))
4695 /* Reject inheritance resulting in secondary memory moves.
4696 Otherwise, there is a danger in LRA cycling. Also such
4697 transformation will be unprofitable. */
4698 if (lra_dump_file
!= NULL
)
4700 rtx_insn
*insn
= skip_usage_debug_insns (next_usage_insns
);
4701 rtx set
= single_set (insn
);
4703 lra_assert (set
!= NULL_RTX
);
4705 rtx dest
= SET_DEST (set
);
4707 lra_assert (REG_P (dest
));
4708 fprintf (lra_dump_file
,
4709 " Rejecting inheritance for insn %d(%s)<-%d(%s) "
4710 "as secondary mem is needed\n",
4711 REGNO (dest
), reg_class_names
[get_reg_class (REGNO (dest
))],
4712 original_regno
, reg_class_names
[rclass
]);
4713 fprintf (lra_dump_file
,
4714 " >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n");
4718 new_reg
= lra_create_new_reg (GET_MODE (original_reg
), original_reg
,
4719 rclass
, "inheritance");
4722 lra_emit_move (original_reg
, new_reg
);
4724 lra_emit_move (new_reg
, original_reg
);
4725 new_insns
= get_insns ();
4727 if (NEXT_INSN (new_insns
) != NULL_RTX
)
4729 if (lra_dump_file
!= NULL
)
4731 fprintf (lra_dump_file
,
4732 " Rejecting inheritance %d->%d "
4733 "as it results in 2 or more insns:\n",
4734 original_regno
, REGNO (new_reg
));
4735 dump_rtl_slim (lra_dump_file
, new_insns
, NULL
, -1, 0);
4736 fprintf (lra_dump_file
,
4737 " >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n");
4741 lra_substitute_pseudo_within_insn (insn
, original_regno
, new_reg
);
4742 lra_update_insn_regno_info (insn
);
4744 /* We now have a new usage insn for original regno. */
4745 setup_next_usage_insn (original_regno
, new_insns
, reloads_num
, false);
4746 if (lra_dump_file
!= NULL
)
4747 fprintf (lra_dump_file
, " Original reg change %d->%d (bb%d):\n",
4748 original_regno
, REGNO (new_reg
), BLOCK_FOR_INSN (insn
)->index
);
4749 lra_reg_info
[REGNO (new_reg
)].restore_regno
= original_regno
;
4750 bitmap_set_bit (&check_only_regs
, REGNO (new_reg
));
4751 bitmap_set_bit (&check_only_regs
, original_regno
);
4752 bitmap_set_bit (&lra_inheritance_pseudos
, REGNO (new_reg
));
4754 lra_process_new_insns (insn
, NULL
, new_insns
,
4755 "Add original<-inheritance");
4757 lra_process_new_insns (insn
, new_insns
, NULL
,
4758 "Add inheritance<-original");
4759 while (next_usage_insns
!= NULL_RTX
)
4761 if (GET_CODE (next_usage_insns
) != INSN_LIST
)
4763 usage_insn
= next_usage_insns
;
4764 lra_assert (NONDEBUG_INSN_P (usage_insn
));
4765 next_usage_insns
= NULL
;
4769 usage_insn
= XEXP (next_usage_insns
, 0);
4770 lra_assert (DEBUG_INSN_P (usage_insn
));
4771 next_usage_insns
= XEXP (next_usage_insns
, 1);
4773 lra_substitute_pseudo (&usage_insn
, original_regno
, new_reg
);
4774 lra_update_insn_regno_info (as_a
<rtx_insn
*> (usage_insn
));
4775 if (lra_dump_file
!= NULL
)
4777 fprintf (lra_dump_file
,
4778 " Inheritance reuse change %d->%d (bb%d):\n",
4779 original_regno
, REGNO (new_reg
),
4780 BLOCK_FOR_INSN (usage_insn
)->index
);
4781 dump_insn_slim (lra_dump_file
, usage_insn
);
4784 if (lra_dump_file
!= NULL
)
4785 fprintf (lra_dump_file
,
4786 " >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n");
4790 /* Return true if we need a caller save/restore for pseudo REGNO which
4791 was assigned to a hard register. */
4793 need_for_call_save_p (int regno
)
4795 lra_assert (regno
>= FIRST_PSEUDO_REGISTER
&& reg_renumber
[regno
] >= 0);
4796 return (usage_insns
[regno
].calls_num
< calls_num
4797 && (overlaps_hard_reg_set_p
4799 ! hard_reg_set_empty_p (lra_reg_info
[regno
].actual_call_used_reg_set
))
4800 ? lra_reg_info
[regno
].actual_call_used_reg_set
4801 : call_used_reg_set
,
4802 PSEUDO_REGNO_MODE (regno
), reg_renumber
[regno
])
4803 || HARD_REGNO_CALL_PART_CLOBBERED (reg_renumber
[regno
],
4804 PSEUDO_REGNO_MODE (regno
))));
4807 /* Global registers occurring in the current EBB. */
4808 static bitmap_head ebb_global_regs
;
4810 /* Return true if we need a split for hard register REGNO or pseudo
4811 REGNO which was assigned to a hard register.
4812 POTENTIAL_RELOAD_HARD_REGS contains hard registers which might be
4813 used for reloads since the EBB end. It is an approximation of the
4814 used hard registers in the split range. The exact value would
4815 require expensive calculations. If we were aggressive with
4816 splitting because of the approximation, the split pseudo will save
4817 the same hard register assignment and will be removed in the undo
4818 pass. We still need the approximation because too aggressive
4819 splitting would result in too inaccurate cost calculation in the
4820 assignment pass because of too many generated moves which will be
4821 probably removed in the undo pass. */
4823 need_for_split_p (HARD_REG_SET potential_reload_hard_regs
, int regno
)
4825 int hard_regno
= regno
< FIRST_PSEUDO_REGISTER
? regno
: reg_renumber
[regno
];
4827 lra_assert (hard_regno
>= 0);
4828 return ((TEST_HARD_REG_BIT (potential_reload_hard_regs
, hard_regno
)
4829 /* Don't split eliminable hard registers, otherwise we can
4830 split hard registers like hard frame pointer, which
4831 lives on BB start/end according to DF-infrastructure,
4832 when there is a pseudo assigned to the register and
4833 living in the same BB. */
4834 && (regno
>= FIRST_PSEUDO_REGISTER
4835 || ! TEST_HARD_REG_BIT (eliminable_regset
, hard_regno
))
4836 && ! TEST_HARD_REG_BIT (lra_no_alloc_regs
, hard_regno
)
4837 /* Don't split call clobbered hard regs living through
4838 calls, otherwise we might have a check problem in the
4839 assign sub-pass as in the most cases (exception is a
4840 situation when lra_risky_transformations_p value is
4841 true) the assign pass assumes that all pseudos living
4842 through calls are assigned to call saved hard regs. */
4843 && (regno
>= FIRST_PSEUDO_REGISTER
4844 || ! TEST_HARD_REG_BIT (call_used_reg_set
, regno
)
4845 || usage_insns
[regno
].calls_num
== calls_num
)
4846 /* We need at least 2 reloads to make pseudo splitting
4847 profitable. We should provide hard regno splitting in
4848 any case to solve 1st insn scheduling problem when
4849 moving hard register definition up might result in
4850 impossibility to find hard register for reload pseudo of
4851 small register class. */
4852 && (usage_insns
[regno
].reloads_num
4853 + (regno
< FIRST_PSEUDO_REGISTER
? 0 : 3) < reloads_num
)
4854 && (regno
< FIRST_PSEUDO_REGISTER
4855 /* For short living pseudos, spilling + inheritance can
4856 be considered a substitution for splitting.
4857 Therefore we do not splitting for local pseudos. It
4858 decreases also aggressiveness of splitting. The
4859 minimal number of references is chosen taking into
4860 account that for 2 references splitting has no sense
4861 as we can just spill the pseudo. */
4862 || (regno
>= FIRST_PSEUDO_REGISTER
4863 && lra_reg_info
[regno
].nrefs
> 3
4864 && bitmap_bit_p (&ebb_global_regs
, regno
))))
4865 || (regno
>= FIRST_PSEUDO_REGISTER
&& need_for_call_save_p (regno
)));
4868 /* Return class for the split pseudo created from original pseudo with
4869 ALLOCNO_CLASS and MODE which got a hard register HARD_REGNO. We
4870 choose subclass of ALLOCNO_CLASS which contains HARD_REGNO and
4871 results in no secondary memory movements. */
4872 static enum reg_class
4873 choose_split_class (enum reg_class allocno_class
,
4874 int hard_regno ATTRIBUTE_UNUSED
,
4875 machine_mode mode ATTRIBUTE_UNUSED
)
4877 #ifndef SECONDARY_MEMORY_NEEDED
4878 return allocno_class
;
4881 enum reg_class cl
, best_cl
= NO_REGS
;
4882 enum reg_class hard_reg_class ATTRIBUTE_UNUSED
4883 = REGNO_REG_CLASS (hard_regno
);
4885 if (! SECONDARY_MEMORY_NEEDED (allocno_class
, allocno_class
, mode
)
4886 && TEST_HARD_REG_BIT (reg_class_contents
[allocno_class
], hard_regno
))
4887 return allocno_class
;
4889 (cl
= reg_class_subclasses
[allocno_class
][i
]) != LIM_REG_CLASSES
;
4891 if (! SECONDARY_MEMORY_NEEDED (cl
, hard_reg_class
, mode
)
4892 && ! SECONDARY_MEMORY_NEEDED (hard_reg_class
, cl
, mode
)
4893 && TEST_HARD_REG_BIT (reg_class_contents
[cl
], hard_regno
)
4894 && (best_cl
== NO_REGS
4895 || ira_class_hard_regs_num
[best_cl
] < ira_class_hard_regs_num
[cl
]))
4901 /* Do split transformations for insn INSN, which defines or uses
4902 ORIGINAL_REGNO. NEXT_USAGE_INSNS specifies which instruction in
4903 the EBB next uses ORIGINAL_REGNO; it has the same form as the
4904 "insns" field of usage_insns.
4906 The transformations look like:
4909 ... s <- p (new insn -- save)
4911 ... p <- s (new insn -- restore)
4912 <- ... p ... <- ... p ...
4914 <- ... p ... <- ... p ...
4915 ... s <- p (new insn -- save)
4917 ... p <- s (new insn -- restore)
4918 <- ... p ... <- ... p ...
4920 where p is an original pseudo got a hard register or a hard
4921 register and s is a new split pseudo. The save is put before INSN
4922 if BEFORE_P is true. Return true if we succeed in such
4925 split_reg (bool before_p
, int original_regno
, rtx_insn
*insn
,
4926 rtx next_usage_insns
)
4928 enum reg_class rclass
;
4930 int hard_regno
, nregs
;
4931 rtx new_reg
, usage_insn
;
4932 rtx_insn
*restore
, *save
;
4936 if (original_regno
< FIRST_PSEUDO_REGISTER
)
4938 rclass
= ira_allocno_class_translate
[REGNO_REG_CLASS (original_regno
)];
4939 hard_regno
= original_regno
;
4940 call_save_p
= false;
4945 hard_regno
= reg_renumber
[original_regno
];
4946 nregs
= hard_regno_nregs
[hard_regno
][PSEUDO_REGNO_MODE (original_regno
)];
4947 rclass
= lra_get_allocno_class (original_regno
);
4948 original_reg
= regno_reg_rtx
[original_regno
];
4949 call_save_p
= need_for_call_save_p (original_regno
);
4951 original_reg
= regno_reg_rtx
[original_regno
];
4952 lra_assert (hard_regno
>= 0);
4953 if (lra_dump_file
!= NULL
)
4954 fprintf (lra_dump_file
,
4955 " ((((((((((((((((((((((((((((((((((((((((((((((((\n");
4958 machine_mode mode
= GET_MODE (original_reg
);
4960 mode
= HARD_REGNO_CALLER_SAVE_MODE (hard_regno
,
4961 hard_regno_nregs
[hard_regno
][mode
],
4963 new_reg
= lra_create_new_reg (mode
, NULL_RTX
, NO_REGS
, "save");
4967 rclass
= choose_split_class (rclass
, hard_regno
,
4968 GET_MODE (original_reg
));
4969 if (rclass
== NO_REGS
)
4971 if (lra_dump_file
!= NULL
)
4973 fprintf (lra_dump_file
,
4974 " Rejecting split of %d(%s): "
4975 "no good reg class for %d(%s)\n",
4977 reg_class_names
[lra_get_allocno_class (original_regno
)],
4979 reg_class_names
[REGNO_REG_CLASS (hard_regno
)]);
4982 " ))))))))))))))))))))))))))))))))))))))))))))))))\n");
4986 new_reg
= lra_create_new_reg (GET_MODE (original_reg
), original_reg
,
4988 reg_renumber
[REGNO (new_reg
)] = hard_regno
;
4990 save
= emit_spill_move (true, new_reg
, original_reg
);
4991 if (NEXT_INSN (save
) != NULL_RTX
&& !call_save_p
)
4993 if (lra_dump_file
!= NULL
)
4997 " Rejecting split %d->%d resulting in > 2 save insns:\n",
4998 original_regno
, REGNO (new_reg
));
4999 dump_rtl_slim (lra_dump_file
, save
, NULL
, -1, 0);
5000 fprintf (lra_dump_file
,
5001 " ))))))))))))))))))))))))))))))))))))))))))))))))\n");
5005 restore
= emit_spill_move (false, new_reg
, original_reg
);
5006 if (NEXT_INSN (restore
) != NULL_RTX
&& !call_save_p
)
5008 if (lra_dump_file
!= NULL
)
5010 fprintf (lra_dump_file
,
5011 " Rejecting split %d->%d "
5012 "resulting in > 2 restore insns:\n",
5013 original_regno
, REGNO (new_reg
));
5014 dump_rtl_slim (lra_dump_file
, restore
, NULL
, -1, 0);
5015 fprintf (lra_dump_file
,
5016 " ))))))))))))))))))))))))))))))))))))))))))))))))\n");
5020 after_p
= usage_insns
[original_regno
].after_p
;
5021 lra_reg_info
[REGNO (new_reg
)].restore_regno
= original_regno
;
5022 bitmap_set_bit (&check_only_regs
, REGNO (new_reg
));
5023 bitmap_set_bit (&check_only_regs
, original_regno
);
5024 bitmap_set_bit (&lra_split_regs
, REGNO (new_reg
));
5027 if (GET_CODE (next_usage_insns
) != INSN_LIST
)
5029 usage_insn
= next_usage_insns
;
5032 usage_insn
= XEXP (next_usage_insns
, 0);
5033 lra_assert (DEBUG_INSN_P (usage_insn
));
5034 next_usage_insns
= XEXP (next_usage_insns
, 1);
5035 lra_substitute_pseudo (&usage_insn
, original_regno
, new_reg
);
5036 lra_update_insn_regno_info (as_a
<rtx_insn
*> (usage_insn
));
5037 if (lra_dump_file
!= NULL
)
5039 fprintf (lra_dump_file
, " Split reuse change %d->%d:\n",
5040 original_regno
, REGNO (new_reg
));
5041 dump_insn_slim (lra_dump_file
, usage_insn
);
5044 lra_assert (NOTE_P (usage_insn
) || NONDEBUG_INSN_P (usage_insn
));
5045 lra_assert (usage_insn
!= insn
|| (after_p
&& before_p
));
5046 lra_process_new_insns (as_a
<rtx_insn
*> (usage_insn
),
5047 after_p
? NULL
: restore
,
5048 after_p
? restore
: NULL
,
5050 ? "Add reg<-save" : "Add reg<-split");
5051 lra_process_new_insns (insn
, before_p
? save
: NULL
,
5052 before_p
? NULL
: save
,
5054 ? "Add save<-reg" : "Add split<-reg");
5056 /* If we are trying to split multi-register. We should check
5057 conflicts on the next assignment sub-pass. IRA can allocate on
5058 sub-register levels, LRA do this on pseudos level right now and
5059 this discrepancy may create allocation conflicts after
5061 lra_risky_transformations_p
= true;
5062 if (lra_dump_file
!= NULL
)
5063 fprintf (lra_dump_file
,
5064 " ))))))))))))))))))))))))))))))))))))))))))))))))\n");
5068 /* Recognize that we need a split transformation for insn INSN, which
5069 defines or uses REGNO in its insn biggest MODE (we use it only if
5070 REGNO is a hard register). POTENTIAL_RELOAD_HARD_REGS contains
5071 hard registers which might be used for reloads since the EBB end.
5072 Put the save before INSN if BEFORE_P is true. MAX_UID is maximla
5073 uid before starting INSN processing. Return true if we succeed in
5074 such transformation. */
5076 split_if_necessary (int regno
, machine_mode mode
,
5077 HARD_REG_SET potential_reload_hard_regs
,
5078 bool before_p
, rtx_insn
*insn
, int max_uid
)
5082 rtx next_usage_insns
;
5084 if (regno
< FIRST_PSEUDO_REGISTER
)
5085 nregs
= hard_regno_nregs
[regno
][mode
];
5086 for (i
= 0; i
< nregs
; i
++)
5087 if (usage_insns
[regno
+ i
].check
== curr_usage_insns_check
5088 && (next_usage_insns
= usage_insns
[regno
+ i
].insns
) != NULL_RTX
5089 /* To avoid processing the register twice or more. */
5090 && ((GET_CODE (next_usage_insns
) != INSN_LIST
5091 && INSN_UID (next_usage_insns
) < max_uid
)
5092 || (GET_CODE (next_usage_insns
) == INSN_LIST
5093 && (INSN_UID (XEXP (next_usage_insns
, 0)) < max_uid
)))
5094 && need_for_split_p (potential_reload_hard_regs
, regno
+ i
)
5095 && split_reg (before_p
, regno
+ i
, insn
, next_usage_insns
))
5100 /* Check only registers living at the current program point in the
5102 static bitmap_head live_regs
;
5104 /* Update live info in EBB given by its HEAD and TAIL insns after
5105 inheritance/split transformation. The function removes dead moves
5108 update_ebb_live_info (rtx_insn
*head
, rtx_insn
*tail
)
5113 rtx_insn
*prev_insn
;
5116 basic_block last_bb
, prev_bb
, curr_bb
;
5118 struct lra_insn_reg
*reg
;
5122 last_bb
= BLOCK_FOR_INSN (tail
);
5124 for (curr_insn
= tail
;
5125 curr_insn
!= PREV_INSN (head
);
5126 curr_insn
= prev_insn
)
5128 prev_insn
= PREV_INSN (curr_insn
);
5129 /* We need to process empty blocks too. They contain
5130 NOTE_INSN_BASIC_BLOCK referring for the basic block. */
5131 if (NOTE_P (curr_insn
) && NOTE_KIND (curr_insn
) != NOTE_INSN_BASIC_BLOCK
)
5133 curr_bb
= BLOCK_FOR_INSN (curr_insn
);
5134 if (curr_bb
!= prev_bb
)
5136 if (prev_bb
!= NULL
)
5138 /* Update df_get_live_in (prev_bb): */
5139 EXECUTE_IF_SET_IN_BITMAP (&check_only_regs
, 0, j
, bi
)
5140 if (bitmap_bit_p (&live_regs
, j
))
5141 bitmap_set_bit (df_get_live_in (prev_bb
), j
);
5143 bitmap_clear_bit (df_get_live_in (prev_bb
), j
);
5145 if (curr_bb
!= last_bb
)
5147 /* Update df_get_live_out (curr_bb): */
5148 EXECUTE_IF_SET_IN_BITMAP (&check_only_regs
, 0, j
, bi
)
5150 live_p
= bitmap_bit_p (&live_regs
, j
);
5152 FOR_EACH_EDGE (e
, ei
, curr_bb
->succs
)
5153 if (bitmap_bit_p (df_get_live_in (e
->dest
), j
))
5159 bitmap_set_bit (df_get_live_out (curr_bb
), j
);
5161 bitmap_clear_bit (df_get_live_out (curr_bb
), j
);
5165 bitmap_and (&live_regs
, &check_only_regs
, df_get_live_out (curr_bb
));
5167 if (! NONDEBUG_INSN_P (curr_insn
))
5169 curr_id
= lra_get_insn_recog_data (curr_insn
);
5170 curr_static_id
= curr_id
->insn_static_data
;
5172 if ((set
= single_set (curr_insn
)) != NULL_RTX
&& REG_P (SET_DEST (set
))
5173 && (regno
= REGNO (SET_DEST (set
))) >= FIRST_PSEUDO_REGISTER
5174 && bitmap_bit_p (&check_only_regs
, regno
)
5175 && ! bitmap_bit_p (&live_regs
, regno
))
5177 /* See which defined values die here. */
5178 for (reg
= curr_id
->regs
; reg
!= NULL
; reg
= reg
->next
)
5179 if (reg
->type
== OP_OUT
&& ! reg
->subreg_p
)
5180 bitmap_clear_bit (&live_regs
, reg
->regno
);
5181 for (reg
= curr_static_id
->hard_regs
; reg
!= NULL
; reg
= reg
->next
)
5182 if (reg
->type
== OP_OUT
&& ! reg
->subreg_p
)
5183 bitmap_clear_bit (&live_regs
, reg
->regno
);
5184 /* Mark each used value as live. */
5185 for (reg
= curr_id
->regs
; reg
!= NULL
; reg
= reg
->next
)
5186 if (reg
->type
!= OP_OUT
5187 && bitmap_bit_p (&check_only_regs
, reg
->regno
))
5188 bitmap_set_bit (&live_regs
, reg
->regno
);
5189 for (reg
= curr_static_id
->hard_regs
; reg
!= NULL
; reg
= reg
->next
)
5190 if (reg
->type
!= OP_OUT
5191 && bitmap_bit_p (&check_only_regs
, reg
->regno
))
5192 bitmap_set_bit (&live_regs
, reg
->regno
);
5193 if (curr_id
->arg_hard_regs
!= NULL
)
5194 /* Make argument hard registers live. */
5195 for (i
= 0; (regno
= curr_id
->arg_hard_regs
[i
]) >= 0; i
++)
5196 if (bitmap_bit_p (&check_only_regs
, regno
))
5197 bitmap_set_bit (&live_regs
, regno
);
5198 /* It is quite important to remove dead move insns because it
5199 means removing dead store. We don't need to process them for
5203 if (lra_dump_file
!= NULL
)
5205 fprintf (lra_dump_file
, " Removing dead insn:\n ");
5206 dump_insn_slim (lra_dump_file
, curr_insn
);
5208 lra_set_insn_deleted (curr_insn
);
5213 /* The structure describes info to do an inheritance for the current
5214 insn. We need to collect such info first before doing the
5215 transformations because the transformations change the insn
5216 internal representation. */
5219 /* Original regno. */
5221 /* Subsequent insns which can inherit original reg value. */
5225 /* Array containing all info for doing inheritance from the current
5227 static struct to_inherit to_inherit
[LRA_MAX_INSN_RELOADS
];
5229 /* Number elements in the previous array. */
5230 static int to_inherit_num
;
5232 /* Add inheritance info REGNO and INSNS. Their meaning is described in
5233 structure to_inherit. */
5235 add_to_inherit (int regno
, rtx insns
)
5239 for (i
= 0; i
< to_inherit_num
; i
++)
5240 if (to_inherit
[i
].regno
== regno
)
5242 lra_assert (to_inherit_num
< LRA_MAX_INSN_RELOADS
);
5243 to_inherit
[to_inherit_num
].regno
= regno
;
5244 to_inherit
[to_inherit_num
++].insns
= insns
;
5247 /* Return the last non-debug insn in basic block BB, or the block begin
5250 get_last_insertion_point (basic_block bb
)
5254 FOR_BB_INSNS_REVERSE (bb
, insn
)
5255 if (NONDEBUG_INSN_P (insn
) || NOTE_INSN_BASIC_BLOCK_P (insn
))
5260 /* Set up RES by registers living on edges FROM except the edge (FROM,
5261 TO) or by registers set up in a jump insn in BB FROM. */
5263 get_live_on_other_edges (basic_block from
, basic_block to
, bitmap res
)
5266 struct lra_insn_reg
*reg
;
5270 lra_assert (to
!= NULL
);
5272 FOR_EACH_EDGE (e
, ei
, from
->succs
)
5274 bitmap_ior_into (res
, df_get_live_in (e
->dest
));
5275 last
= get_last_insertion_point (from
);
5276 if (! JUMP_P (last
))
5278 curr_id
= lra_get_insn_recog_data (last
);
5279 for (reg
= curr_id
->regs
; reg
!= NULL
; reg
= reg
->next
)
5280 if (reg
->type
!= OP_IN
)
5281 bitmap_set_bit (res
, reg
->regno
);
5284 /* Used as a temporary results of some bitmap calculations. */
5285 static bitmap_head temp_bitmap
;
5287 /* We split for reloads of small class of hard regs. The following
5288 defines how many hard regs the class should have to be qualified as
5289 small. The code is mostly oriented to x86/x86-64 architecture
5290 where some insns need to use only specific register or pair of
5291 registers and these register can live in RTL explicitly, e.g. for
5292 parameter passing. */
5293 static const int max_small_class_regs_num
= 2;
5295 /* Do inheritance/split transformations in EBB starting with HEAD and
5296 finishing on TAIL. We process EBB insns in the reverse order.
5297 Return true if we did any inheritance/split transformation in the
5300 We should avoid excessive splitting which results in worse code
5301 because of inaccurate cost calculations for spilling new split
5302 pseudos in such case. To achieve this we do splitting only if
5303 register pressure is high in given basic block and there are reload
5304 pseudos requiring hard registers. We could do more register
5305 pressure calculations at any given program point to avoid necessary
5306 splitting even more but it is to expensive and the current approach
5307 works well enough. */
5309 inherit_in_ebb (rtx_insn
*head
, rtx_insn
*tail
)
5311 int i
, src_regno
, dst_regno
, nregs
;
5312 bool change_p
, succ_p
, update_reloads_num_p
;
5313 rtx_insn
*prev_insn
, *last_insn
;
5314 rtx next_usage_insns
, set
;
5316 struct lra_insn_reg
*reg
;
5317 basic_block last_processed_bb
, curr_bb
= NULL
;
5318 HARD_REG_SET potential_reload_hard_regs
, live_hard_regs
;
5322 bool head_p
, after_p
;
5325 curr_usage_insns_check
++;
5326 reloads_num
= calls_num
= 0;
5327 bitmap_clear (&check_only_regs
);
5328 last_processed_bb
= NULL
;
5329 CLEAR_HARD_REG_SET (potential_reload_hard_regs
);
5330 COPY_HARD_REG_SET (live_hard_regs
, eliminable_regset
);
5331 IOR_HARD_REG_SET (live_hard_regs
, lra_no_alloc_regs
);
5332 /* We don't process new insns generated in the loop. */
5333 for (curr_insn
= tail
; curr_insn
!= PREV_INSN (head
); curr_insn
= prev_insn
)
5335 prev_insn
= PREV_INSN (curr_insn
);
5336 if (BLOCK_FOR_INSN (curr_insn
) != NULL
)
5337 curr_bb
= BLOCK_FOR_INSN (curr_insn
);
5338 if (last_processed_bb
!= curr_bb
)
5340 /* We are at the end of BB. Add qualified living
5341 pseudos for potential splitting. */
5342 to_process
= df_get_live_out (curr_bb
);
5343 if (last_processed_bb
!= NULL
)
5345 /* We are somewhere in the middle of EBB. */
5346 get_live_on_other_edges (curr_bb
, last_processed_bb
,
5348 to_process
= &temp_bitmap
;
5350 last_processed_bb
= curr_bb
;
5351 last_insn
= get_last_insertion_point (curr_bb
);
5352 after_p
= (! JUMP_P (last_insn
)
5353 && (! CALL_P (last_insn
)
5354 || (find_reg_note (last_insn
,
5355 REG_NORETURN
, NULL_RTX
) == NULL_RTX
5356 && ! SIBLING_CALL_P (last_insn
))));
5357 CLEAR_HARD_REG_SET (potential_reload_hard_regs
);
5358 EXECUTE_IF_SET_IN_BITMAP (to_process
, 0, j
, bi
)
5360 if ((int) j
>= lra_constraint_new_regno_start
)
5362 if (j
< FIRST_PSEUDO_REGISTER
|| reg_renumber
[j
] >= 0)
5364 if (j
< FIRST_PSEUDO_REGISTER
)
5365 SET_HARD_REG_BIT (live_hard_regs
, j
);
5367 add_to_hard_reg_set (&live_hard_regs
,
5368 PSEUDO_REGNO_MODE (j
),
5370 setup_next_usage_insn (j
, last_insn
, reloads_num
, after_p
);
5374 src_regno
= dst_regno
= -1;
5375 if (NONDEBUG_INSN_P (curr_insn
)
5376 && (set
= single_set (curr_insn
)) != NULL_RTX
5377 && REG_P (SET_DEST (set
)) && REG_P (SET_SRC (set
)))
5379 src_regno
= REGNO (SET_SRC (set
));
5380 dst_regno
= REGNO (SET_DEST (set
));
5382 update_reloads_num_p
= true;
5383 if (src_regno
< lra_constraint_new_regno_start
5384 && src_regno
>= FIRST_PSEUDO_REGISTER
5385 && reg_renumber
[src_regno
] < 0
5386 && dst_regno
>= lra_constraint_new_regno_start
5387 && (cl
= lra_get_allocno_class (dst_regno
)) != NO_REGS
)
5389 /* 'reload_pseudo <- original_pseudo'. */
5390 if (ira_class_hard_regs_num
[cl
] <= max_small_class_regs_num
)
5392 update_reloads_num_p
= false;
5394 if (usage_insns
[src_regno
].check
== curr_usage_insns_check
5395 && (next_usage_insns
= usage_insns
[src_regno
].insns
) != NULL_RTX
)
5396 succ_p
= inherit_reload_reg (false, src_regno
, cl
,
5397 curr_insn
, next_usage_insns
);
5401 setup_next_usage_insn (src_regno
, curr_insn
, reloads_num
, false);
5402 if (hard_reg_set_subset_p (reg_class_contents
[cl
], live_hard_regs
))
5403 IOR_HARD_REG_SET (potential_reload_hard_regs
,
5404 reg_class_contents
[cl
]);
5406 else if (src_regno
>= lra_constraint_new_regno_start
5407 && dst_regno
< lra_constraint_new_regno_start
5408 && dst_regno
>= FIRST_PSEUDO_REGISTER
5409 && reg_renumber
[dst_regno
] < 0
5410 && (cl
= lra_get_allocno_class (src_regno
)) != NO_REGS
5411 && usage_insns
[dst_regno
].check
== curr_usage_insns_check
5412 && (next_usage_insns
5413 = usage_insns
[dst_regno
].insns
) != NULL_RTX
)
5415 if (ira_class_hard_regs_num
[cl
] <= max_small_class_regs_num
)
5417 update_reloads_num_p
= false;
5418 /* 'original_pseudo <- reload_pseudo'. */
5419 if (! JUMP_P (curr_insn
)
5420 && inherit_reload_reg (true, dst_regno
, cl
,
5421 curr_insn
, next_usage_insns
))
5424 usage_insns
[dst_regno
].check
= 0;
5425 if (hard_reg_set_subset_p (reg_class_contents
[cl
], live_hard_regs
))
5426 IOR_HARD_REG_SET (potential_reload_hard_regs
,
5427 reg_class_contents
[cl
]);
5429 else if (INSN_P (curr_insn
))
5432 int max_uid
= get_max_uid ();
5434 curr_id
= lra_get_insn_recog_data (curr_insn
);
5435 curr_static_id
= curr_id
->insn_static_data
;
5437 /* Process insn definitions. */
5438 for (iter
= 0; iter
< 2; iter
++)
5439 for (reg
= iter
== 0 ? curr_id
->regs
: curr_static_id
->hard_regs
;
5442 if (reg
->type
!= OP_IN
5443 && (dst_regno
= reg
->regno
) < lra_constraint_new_regno_start
)
5445 if (dst_regno
>= FIRST_PSEUDO_REGISTER
&& reg
->type
== OP_OUT
5446 && reg_renumber
[dst_regno
] < 0 && ! reg
->subreg_p
5447 && usage_insns
[dst_regno
].check
== curr_usage_insns_check
5448 && (next_usage_insns
5449 = usage_insns
[dst_regno
].insns
) != NULL_RTX
)
5451 struct lra_insn_reg
*r
;
5453 for (r
= curr_id
->regs
; r
!= NULL
; r
= r
->next
)
5454 if (r
->type
!= OP_OUT
&& r
->regno
== dst_regno
)
5456 /* Don't do inheritance if the pseudo is also
5457 used in the insn. */
5459 /* We can not do inheritance right now
5460 because the current insn reg info (chain
5461 regs) can change after that. */
5462 add_to_inherit (dst_regno
, next_usage_insns
);
5464 /* We can not process one reg twice here because of
5465 usage_insns invalidation. */
5466 if ((dst_regno
< FIRST_PSEUDO_REGISTER
5467 || reg_renumber
[dst_regno
] >= 0)
5468 && ! reg
->subreg_p
&& reg
->type
!= OP_IN
)
5472 if (split_if_necessary (dst_regno
, reg
->biggest_mode
,
5473 potential_reload_hard_regs
,
5474 false, curr_insn
, max_uid
))
5476 CLEAR_HARD_REG_SET (s
);
5477 if (dst_regno
< FIRST_PSEUDO_REGISTER
)
5478 add_to_hard_reg_set (&s
, reg
->biggest_mode
, dst_regno
);
5480 add_to_hard_reg_set (&s
, PSEUDO_REGNO_MODE (dst_regno
),
5481 reg_renumber
[dst_regno
]);
5482 AND_COMPL_HARD_REG_SET (live_hard_regs
, s
);
5484 /* We should invalidate potential inheritance or
5485 splitting for the current insn usages to the next
5486 usage insns (see code below) as the output pseudo
5488 if ((dst_regno
>= FIRST_PSEUDO_REGISTER
5489 && reg_renumber
[dst_regno
] < 0)
5490 || (reg
->type
== OP_OUT
&& ! reg
->subreg_p
5491 && (dst_regno
< FIRST_PSEUDO_REGISTER
5492 || reg_renumber
[dst_regno
] >= 0)))
5494 /* Invalidate and mark definitions. */
5495 if (dst_regno
>= FIRST_PSEUDO_REGISTER
)
5496 usage_insns
[dst_regno
].check
= -(int) INSN_UID (curr_insn
);
5499 nregs
= hard_regno_nregs
[dst_regno
][reg
->biggest_mode
];
5500 for (i
= 0; i
< nregs
; i
++)
5501 usage_insns
[dst_regno
+ i
].check
5502 = -(int) INSN_UID (curr_insn
);
5506 if (! JUMP_P (curr_insn
))
5507 for (i
= 0; i
< to_inherit_num
; i
++)
5508 if (inherit_reload_reg (true, to_inherit
[i
].regno
,
5509 ALL_REGS
, curr_insn
,
5510 to_inherit
[i
].insns
))
5512 if (CALL_P (curr_insn
))
5514 rtx cheap
, pat
, dest
;
5516 int regno
, hard_regno
;
5519 if ((cheap
= find_reg_note (curr_insn
,
5520 REG_RETURNED
, NULL_RTX
)) != NULL_RTX
5521 && ((cheap
= XEXP (cheap
, 0)), true)
5522 && (regno
= REGNO (cheap
)) >= FIRST_PSEUDO_REGISTER
5523 && (hard_regno
= reg_renumber
[regno
]) >= 0
5524 /* If there are pending saves/restores, the
5525 optimization is not worth. */
5526 && usage_insns
[regno
].calls_num
== calls_num
- 1
5527 && TEST_HARD_REG_BIT (call_used_reg_set
, hard_regno
))
5529 /* Restore the pseudo from the call result as
5530 REG_RETURNED note says that the pseudo value is
5531 in the call result and the pseudo is an argument
5533 pat
= PATTERN (curr_insn
);
5534 if (GET_CODE (pat
) == PARALLEL
)
5535 pat
= XVECEXP (pat
, 0, 0);
5536 dest
= SET_DEST (pat
);
5537 /* For multiple return values dest is PARALLEL.
5538 Currently we handle only single return value case. */
5542 emit_move_insn (cheap
, copy_rtx (dest
));
5543 restore
= get_insns ();
5545 lra_process_new_insns (curr_insn
, NULL
, restore
,
5546 "Inserting call parameter restore");
5547 /* We don't need to save/restore of the pseudo from
5549 usage_insns
[regno
].calls_num
= calls_num
;
5550 bitmap_set_bit (&check_only_regs
, regno
);
5555 /* Process insn usages. */
5556 for (iter
= 0; iter
< 2; iter
++)
5557 for (reg
= iter
== 0 ? curr_id
->regs
: curr_static_id
->hard_regs
;
5560 if ((reg
->type
!= OP_OUT
5561 || (reg
->type
== OP_OUT
&& reg
->subreg_p
))
5562 && (src_regno
= reg
->regno
) < lra_constraint_new_regno_start
)
5564 if (src_regno
>= FIRST_PSEUDO_REGISTER
5565 && reg_renumber
[src_regno
] < 0 && reg
->type
== OP_IN
)
5567 if (usage_insns
[src_regno
].check
== curr_usage_insns_check
5568 && (next_usage_insns
5569 = usage_insns
[src_regno
].insns
) != NULL_RTX
5570 && NONDEBUG_INSN_P (curr_insn
))
5571 add_to_inherit (src_regno
, next_usage_insns
);
5572 else if (usage_insns
[src_regno
].check
5573 != -(int) INSN_UID (curr_insn
))
5574 /* Add usages but only if the reg is not set up
5575 in the same insn. */
5576 add_next_usage_insn (src_regno
, curr_insn
, reloads_num
);
5578 else if (src_regno
< FIRST_PSEUDO_REGISTER
5579 || reg_renumber
[src_regno
] >= 0)
5582 rtx use_insn
= curr_insn
;
5584 before_p
= (JUMP_P (curr_insn
)
5585 || (CALL_P (curr_insn
) && reg
->type
== OP_IN
));
5586 if (NONDEBUG_INSN_P (curr_insn
)
5587 && (! JUMP_P (curr_insn
) || reg
->type
== OP_IN
)
5588 && split_if_necessary (src_regno
, reg
->biggest_mode
,
5589 potential_reload_hard_regs
,
5590 before_p
, curr_insn
, max_uid
))
5593 lra_risky_transformations_p
= true;
5596 usage_insns
[src_regno
].check
= 0;
5598 use_insn
= PREV_INSN (curr_insn
);
5600 if (NONDEBUG_INSN_P (curr_insn
))
5602 if (src_regno
< FIRST_PSEUDO_REGISTER
)
5603 add_to_hard_reg_set (&live_hard_regs
,
5604 reg
->biggest_mode
, src_regno
);
5606 add_to_hard_reg_set (&live_hard_regs
,
5607 PSEUDO_REGNO_MODE (src_regno
),
5608 reg_renumber
[src_regno
]);
5610 add_next_usage_insn (src_regno
, use_insn
, reloads_num
);
5613 /* Process call args. */
5614 if (curr_id
->arg_hard_regs
!= NULL
)
5615 for (i
= 0; (src_regno
= curr_id
->arg_hard_regs
[i
]) >= 0; i
++)
5616 if (src_regno
< FIRST_PSEUDO_REGISTER
)
5618 SET_HARD_REG_BIT (live_hard_regs
, src_regno
);
5619 add_next_usage_insn (src_regno
, curr_insn
, reloads_num
);
5621 for (i
= 0; i
< to_inherit_num
; i
++)
5623 src_regno
= to_inherit
[i
].regno
;
5624 if (inherit_reload_reg (false, src_regno
, ALL_REGS
,
5625 curr_insn
, to_inherit
[i
].insns
))
5628 setup_next_usage_insn (src_regno
, curr_insn
, reloads_num
, false);
5631 if (update_reloads_num_p
5632 && NONDEBUG_INSN_P (curr_insn
)
5633 && (set
= single_set (curr_insn
)) != NULL_RTX
)
5636 if ((REG_P (SET_DEST (set
))
5637 && (regno
= REGNO (SET_DEST (set
))) >= lra_constraint_new_regno_start
5638 && reg_renumber
[regno
] < 0
5639 && (cl
= lra_get_allocno_class (regno
)) != NO_REGS
)
5640 || (REG_P (SET_SRC (set
))
5641 && (regno
= REGNO (SET_SRC (set
))) >= lra_constraint_new_regno_start
5642 && reg_renumber
[regno
] < 0
5643 && (cl
= lra_get_allocno_class (regno
)) != NO_REGS
))
5645 if (ira_class_hard_regs_num
[cl
] <= max_small_class_regs_num
)
5647 if (hard_reg_set_subset_p (reg_class_contents
[cl
], live_hard_regs
))
5648 IOR_HARD_REG_SET (potential_reload_hard_regs
,
5649 reg_class_contents
[cl
]);
5652 /* We reached the start of the current basic block. */
5653 if (prev_insn
== NULL_RTX
|| prev_insn
== PREV_INSN (head
)
5654 || BLOCK_FOR_INSN (prev_insn
) != curr_bb
)
5656 /* We reached the beginning of the current block -- do
5657 rest of spliting in the current BB. */
5658 to_process
= df_get_live_in (curr_bb
);
5659 if (BLOCK_FOR_INSN (head
) != curr_bb
)
5661 /* We are somewhere in the middle of EBB. */
5662 get_live_on_other_edges (EDGE_PRED (curr_bb
, 0)->src
,
5663 curr_bb
, &temp_bitmap
);
5664 to_process
= &temp_bitmap
;
5667 EXECUTE_IF_SET_IN_BITMAP (to_process
, 0, j
, bi
)
5669 if ((int) j
>= lra_constraint_new_regno_start
)
5671 if (((int) j
< FIRST_PSEUDO_REGISTER
|| reg_renumber
[j
] >= 0)
5672 && usage_insns
[j
].check
== curr_usage_insns_check
5673 && (next_usage_insns
= usage_insns
[j
].insns
) != NULL_RTX
)
5675 if (need_for_split_p (potential_reload_hard_regs
, j
))
5677 if (lra_dump_file
!= NULL
&& head_p
)
5679 fprintf (lra_dump_file
,
5680 " ----------------------------------\n");
5683 if (split_reg (false, j
, bb_note (curr_bb
),
5687 usage_insns
[j
].check
= 0;
5695 /* This value affects EBB forming. If probability of edge from EBB to
5696 a BB is not greater than the following value, we don't add the BB
5698 #define EBB_PROBABILITY_CUTOFF \
5699 ((REG_BR_PROB_BASE * LRA_INHERITANCE_EBB_PROBABILITY_CUTOFF) / 100)
5701 /* Current number of inheritance/split iteration. */
5702 int lra_inheritance_iter
;
5704 /* Entry function for inheritance/split pass. */
5706 lra_inheritance (void)
5709 basic_block bb
, start_bb
;
5712 lra_inheritance_iter
++;
5713 if (lra_inheritance_iter
> LRA_MAX_INHERITANCE_PASSES
)
5715 timevar_push (TV_LRA_INHERITANCE
);
5716 if (lra_dump_file
!= NULL
)
5717 fprintf (lra_dump_file
, "\n********** Inheritance #%d: **********\n\n",
5718 lra_inheritance_iter
);
5719 curr_usage_insns_check
= 0;
5720 usage_insns
= XNEWVEC (struct usage_insns
, lra_constraint_new_regno_start
);
5721 for (i
= 0; i
< lra_constraint_new_regno_start
; i
++)
5722 usage_insns
[i
].check
= 0;
5723 bitmap_initialize (&check_only_regs
, ®_obstack
);
5724 bitmap_initialize (&live_regs
, ®_obstack
);
5725 bitmap_initialize (&temp_bitmap
, ®_obstack
);
5726 bitmap_initialize (&ebb_global_regs
, ®_obstack
);
5727 FOR_EACH_BB_FN (bb
, cfun
)
5730 if (lra_dump_file
!= NULL
)
5731 fprintf (lra_dump_file
, "EBB");
5732 /* Form a EBB starting with BB. */
5733 bitmap_clear (&ebb_global_regs
);
5734 bitmap_ior_into (&ebb_global_regs
, df_get_live_in (bb
));
5737 if (lra_dump_file
!= NULL
)
5738 fprintf (lra_dump_file
, " %d", bb
->index
);
5739 if (bb
->next_bb
== EXIT_BLOCK_PTR_FOR_FN (cfun
)
5740 || LABEL_P (BB_HEAD (bb
->next_bb
)))
5742 e
= find_fallthru_edge (bb
->succs
);
5745 if (e
->probability
< EBB_PROBABILITY_CUTOFF
)
5749 bitmap_ior_into (&ebb_global_regs
, df_get_live_out (bb
));
5750 if (lra_dump_file
!= NULL
)
5751 fprintf (lra_dump_file
, "\n");
5752 if (inherit_in_ebb (BB_HEAD (start_bb
), BB_END (bb
)))
5753 /* Remember that the EBB head and tail can change in
5755 update_ebb_live_info (BB_HEAD (start_bb
), BB_END (bb
));
5757 bitmap_clear (&ebb_global_regs
);
5758 bitmap_clear (&temp_bitmap
);
5759 bitmap_clear (&live_regs
);
5760 bitmap_clear (&check_only_regs
);
5763 timevar_pop (TV_LRA_INHERITANCE
);
5768 /* This page contains code to undo failed inheritance/split
5771 /* Current number of iteration undoing inheritance/split. */
5772 int lra_undo_inheritance_iter
;
5774 /* Fix BB live info LIVE after removing pseudos created on pass doing
5775 inheritance/split which are REMOVED_PSEUDOS. */
5777 fix_bb_live_info (bitmap live
, bitmap removed_pseudos
)
5782 EXECUTE_IF_SET_IN_BITMAP (removed_pseudos
, 0, regno
, bi
)
5783 if (bitmap_clear_bit (live
, regno
))
5784 bitmap_set_bit (live
, lra_reg_info
[regno
].restore_regno
);
5787 /* Return regno of the (subreg of) REG. Otherwise, return a negative
5792 if (GET_CODE (reg
) == SUBREG
)
5793 reg
= SUBREG_REG (reg
);
5799 /* Remove inheritance/split pseudos which are in REMOVE_PSEUDOS and
5800 return true if we did any change. The undo transformations for
5801 inheritance looks like
5805 p <- i, i <- p, and i <- i3
5806 where p is original pseudo from which inheritance pseudo i was
5807 created, i and i3 are removed inheritance pseudos, i2 is another
5808 not removed inheritance pseudo. All split pseudos or other
5809 occurrences of removed inheritance pseudos are changed on the
5810 corresponding original pseudos.
5812 The function also schedules insns changed and created during
5813 inheritance/split pass for processing by the subsequent constraint
5816 remove_inheritance_pseudos (bitmap remove_pseudos
)
5819 int regno
, sregno
, prev_sregno
, dregno
, restore_regno
;
5821 rtx_insn
*prev_insn
;
5822 bool change_p
, done_p
;
5824 change_p
= ! bitmap_empty_p (remove_pseudos
);
5825 /* We can not finish the function right away if CHANGE_P is true
5826 because we need to marks insns affected by previous
5827 inheritance/split pass for processing by the subsequent
5829 FOR_EACH_BB_FN (bb
, cfun
)
5831 fix_bb_live_info (df_get_live_in (bb
), remove_pseudos
);
5832 fix_bb_live_info (df_get_live_out (bb
), remove_pseudos
);
5833 FOR_BB_INSNS_REVERSE (bb
, curr_insn
)
5835 if (! INSN_P (curr_insn
))
5838 sregno
= dregno
= -1;
5839 if (change_p
&& NONDEBUG_INSN_P (curr_insn
)
5840 && (set
= single_set (curr_insn
)) != NULL_RTX
)
5842 dregno
= get_regno (SET_DEST (set
));
5843 sregno
= get_regno (SET_SRC (set
));
5846 if (sregno
>= 0 && dregno
>= 0)
5848 if ((bitmap_bit_p (remove_pseudos
, sregno
)
5849 && (lra_reg_info
[sregno
].restore_regno
== dregno
5850 || (bitmap_bit_p (remove_pseudos
, dregno
)
5851 && (lra_reg_info
[sregno
].restore_regno
5852 == lra_reg_info
[dregno
].restore_regno
))))
5853 || (bitmap_bit_p (remove_pseudos
, dregno
)
5854 && lra_reg_info
[dregno
].restore_regno
== sregno
))
5855 /* One of the following cases:
5856 original <- removed inheritance pseudo
5857 removed inherit pseudo <- another removed inherit pseudo
5858 removed inherit pseudo <- original pseudo
5860 removed_split_pseudo <- original_reg
5861 original_reg <- removed_split_pseudo */
5863 if (lra_dump_file
!= NULL
)
5865 fprintf (lra_dump_file
, " Removing %s:\n",
5866 bitmap_bit_p (&lra_split_regs
, sregno
)
5867 || bitmap_bit_p (&lra_split_regs
, dregno
)
5868 ? "split" : "inheritance");
5869 dump_insn_slim (lra_dump_file
, curr_insn
);
5871 lra_set_insn_deleted (curr_insn
);
5874 else if (bitmap_bit_p (remove_pseudos
, sregno
)
5875 && bitmap_bit_p (&lra_inheritance_pseudos
, sregno
))
5877 /* Search the following pattern:
5878 inherit_or_split_pseudo1 <- inherit_or_split_pseudo2
5879 original_pseudo <- inherit_or_split_pseudo1
5880 where the 2nd insn is the current insn and
5881 inherit_or_split_pseudo2 is not removed. If it is found,
5882 change the current insn onto:
5883 original_pseudo <- inherit_or_split_pseudo2. */
5884 for (prev_insn
= PREV_INSN (curr_insn
);
5885 prev_insn
!= NULL_RTX
&& ! NONDEBUG_INSN_P (prev_insn
);
5886 prev_insn
= PREV_INSN (prev_insn
))
5888 if (prev_insn
!= NULL_RTX
&& BLOCK_FOR_INSN (prev_insn
) == bb
5889 && (prev_set
= single_set (prev_insn
)) != NULL_RTX
5890 /* There should be no subregs in insn we are
5891 searching because only the original reg might
5892 be in subreg when we changed the mode of
5893 load/store for splitting. */
5894 && REG_P (SET_DEST (prev_set
))
5895 && REG_P (SET_SRC (prev_set
))
5896 && (int) REGNO (SET_DEST (prev_set
)) == sregno
5897 && ((prev_sregno
= REGNO (SET_SRC (prev_set
)))
5898 >= FIRST_PSEUDO_REGISTER
)
5899 /* As we consider chain of inheritance or
5900 splitting described in above comment we should
5901 check that sregno and prev_sregno were
5902 inheritance/split pseudos created from the
5903 same original regno. */
5904 && (lra_reg_info
[sregno
].restore_regno
5905 == lra_reg_info
[prev_sregno
].restore_regno
)
5906 && ! bitmap_bit_p (remove_pseudos
, prev_sregno
))
5908 lra_assert (GET_MODE (SET_SRC (prev_set
))
5909 == GET_MODE (regno_reg_rtx
[sregno
]));
5910 if (GET_CODE (SET_SRC (set
)) == SUBREG
)
5911 SUBREG_REG (SET_SRC (set
)) = SET_SRC (prev_set
);
5913 SET_SRC (set
) = SET_SRC (prev_set
);
5914 /* As we are finishing with processing the insn
5915 here, check the destination too as it might
5916 inheritance pseudo for another pseudo. */
5917 if (bitmap_bit_p (remove_pseudos
, dregno
)
5918 && bitmap_bit_p (&lra_inheritance_pseudos
, dregno
)
5920 = lra_reg_info
[dregno
].restore_regno
) >= 0)
5922 if (GET_CODE (SET_DEST (set
)) == SUBREG
)
5923 SUBREG_REG (SET_DEST (set
))
5924 = regno_reg_rtx
[restore_regno
];
5926 SET_DEST (set
) = regno_reg_rtx
[restore_regno
];
5928 lra_push_insn_and_update_insn_regno_info (curr_insn
);
5929 lra_set_used_insn_alternative_by_uid
5930 (INSN_UID (curr_insn
), -1);
5932 if (lra_dump_file
!= NULL
)
5934 fprintf (lra_dump_file
, " Change reload insn:\n");
5935 dump_insn_slim (lra_dump_file
, curr_insn
);
5942 struct lra_insn_reg
*reg
;
5943 bool restored_regs_p
= false;
5944 bool kept_regs_p
= false;
5946 curr_id
= lra_get_insn_recog_data (curr_insn
);
5947 for (reg
= curr_id
->regs
; reg
!= NULL
; reg
= reg
->next
)
5950 restore_regno
= lra_reg_info
[regno
].restore_regno
;
5951 if (restore_regno
>= 0)
5953 if (change_p
&& bitmap_bit_p (remove_pseudos
, regno
))
5955 lra_substitute_pseudo_within_insn (
5956 curr_insn
, regno
, regno_reg_rtx
[restore_regno
]);
5957 restored_regs_p
= true;
5963 if (NONDEBUG_INSN_P (curr_insn
) && kept_regs_p
)
5965 /* The instruction has changed since the previous
5966 constraints pass. */
5967 lra_push_insn_and_update_insn_regno_info (curr_insn
);
5968 lra_set_used_insn_alternative_by_uid
5969 (INSN_UID (curr_insn
), -1);
5971 else if (restored_regs_p
)
5972 /* The instruction has been restored to the form that
5973 it had during the previous constraints pass. */
5974 lra_update_insn_regno_info (curr_insn
);
5975 if (restored_regs_p
&& lra_dump_file
!= NULL
)
5977 fprintf (lra_dump_file
, " Insn after restoring regs:\n");
5978 dump_insn_slim (lra_dump_file
, curr_insn
);
5986 /* If optional reload pseudos failed to get a hard register or was not
5987 inherited, it is better to remove optional reloads. We do this
5988 transformation after undoing inheritance to figure out necessity to
5989 remove optional reloads easier. Return true if we do any
5992 undo_optional_reloads (void)
5994 bool change_p
, keep_p
;
5995 unsigned int regno
, uid
;
5996 bitmap_iterator bi
, bi2
;
5999 bitmap_head removed_optional_reload_pseudos
, insn_bitmap
;
6001 bitmap_initialize (&removed_optional_reload_pseudos
, ®_obstack
);
6002 bitmap_copy (&removed_optional_reload_pseudos
, &lra_optional_reload_pseudos
);
6003 EXECUTE_IF_SET_IN_BITMAP (&lra_optional_reload_pseudos
, 0, regno
, bi
)
6006 /* Keep optional reloads from previous subpasses. */
6007 if (lra_reg_info
[regno
].restore_regno
< 0
6008 /* If the original pseudo changed its allocation, just
6009 removing the optional pseudo is dangerous as the original
6010 pseudo will have longer live range. */
6011 || reg_renumber
[lra_reg_info
[regno
].restore_regno
] >= 0)
6013 else if (reg_renumber
[regno
] >= 0)
6014 EXECUTE_IF_SET_IN_BITMAP (&lra_reg_info
[regno
].insn_bitmap
, 0, uid
, bi2
)
6016 insn
= lra_insn_recog_data
[uid
]->insn
;
6017 if ((set
= single_set (insn
)) == NULL_RTX
)
6019 src
= SET_SRC (set
);
6020 dest
= SET_DEST (set
);
6021 if (! REG_P (src
) || ! REG_P (dest
))
6023 if (REGNO (dest
) == regno
6024 /* Ignore insn for optional reloads itself. */
6025 && lra_reg_info
[regno
].restore_regno
!= (int) REGNO (src
)
6026 /* Check only inheritance on last inheritance pass. */
6027 && (int) REGNO (src
) >= new_regno_start
6028 /* Check that the optional reload was inherited. */
6029 && bitmap_bit_p (&lra_inheritance_pseudos
, REGNO (src
)))
6037 bitmap_clear_bit (&removed_optional_reload_pseudos
, regno
);
6038 if (lra_dump_file
!= NULL
)
6039 fprintf (lra_dump_file
, "Keep optional reload reg %d\n", regno
);
6042 change_p
= ! bitmap_empty_p (&removed_optional_reload_pseudos
);
6043 bitmap_initialize (&insn_bitmap
, ®_obstack
);
6044 EXECUTE_IF_SET_IN_BITMAP (&removed_optional_reload_pseudos
, 0, regno
, bi
)
6046 if (lra_dump_file
!= NULL
)
6047 fprintf (lra_dump_file
, "Remove optional reload reg %d\n", regno
);
6048 bitmap_copy (&insn_bitmap
, &lra_reg_info
[regno
].insn_bitmap
);
6049 EXECUTE_IF_SET_IN_BITMAP (&insn_bitmap
, 0, uid
, bi2
)
6051 insn
= lra_insn_recog_data
[uid
]->insn
;
6052 if ((set
= single_set (insn
)) != NULL_RTX
)
6054 src
= SET_SRC (set
);
6055 dest
= SET_DEST (set
);
6056 if (REG_P (src
) && REG_P (dest
)
6057 && ((REGNO (src
) == regno
6058 && (lra_reg_info
[regno
].restore_regno
6059 == (int) REGNO (dest
)))
6060 || (REGNO (dest
) == regno
6061 && (lra_reg_info
[regno
].restore_regno
6062 == (int) REGNO (src
)))))
6064 if (lra_dump_file
!= NULL
)
6066 fprintf (lra_dump_file
, " Deleting move %u\n",
6068 dump_insn_slim (lra_dump_file
, insn
);
6070 lra_set_insn_deleted (insn
);
6073 /* We should not worry about generation memory-memory
6074 moves here as if the corresponding inheritance did
6075 not work (inheritance pseudo did not get a hard reg),
6076 we remove the inheritance pseudo and the optional
6079 lra_substitute_pseudo_within_insn (
6081 regno_reg_rtx
[lra_reg_info
[regno
].restore_regno
]);
6082 lra_update_insn_regno_info (insn
);
6083 if (lra_dump_file
!= NULL
)
6085 fprintf (lra_dump_file
,
6086 " Restoring original insn:\n");
6087 dump_insn_slim (lra_dump_file
, insn
);
6091 /* Clear restore_regnos. */
6092 EXECUTE_IF_SET_IN_BITMAP (&lra_optional_reload_pseudos
, 0, regno
, bi
)
6093 lra_reg_info
[regno
].restore_regno
= -1;
6094 bitmap_clear (&insn_bitmap
);
6095 bitmap_clear (&removed_optional_reload_pseudos
);
6099 /* Entry function for undoing inheritance/split transformation. Return true
6100 if we did any RTL change in this pass. */
6102 lra_undo_inheritance (void)
6105 int restore_regno
, hard_regno
;
6106 int n_all_inherit
, n_inherit
, n_all_split
, n_split
;
6107 bitmap_head remove_pseudos
;
6111 lra_undo_inheritance_iter
++;
6112 if (lra_undo_inheritance_iter
> LRA_MAX_INHERITANCE_PASSES
)
6114 if (lra_dump_file
!= NULL
)
6115 fprintf (lra_dump_file
,
6116 "\n********** Undoing inheritance #%d: **********\n\n",
6117 lra_undo_inheritance_iter
);
6118 bitmap_initialize (&remove_pseudos
, ®_obstack
);
6119 n_inherit
= n_all_inherit
= 0;
6120 EXECUTE_IF_SET_IN_BITMAP (&lra_inheritance_pseudos
, 0, regno
, bi
)
6121 if (lra_reg_info
[regno
].restore_regno
>= 0)
6124 if (reg_renumber
[regno
] < 0
6125 /* If the original pseudo changed its allocation, just
6126 removing inheritance is dangerous as for changing
6127 allocation we used shorter live-ranges. */
6128 && reg_renumber
[lra_reg_info
[regno
].restore_regno
] < 0)
6129 bitmap_set_bit (&remove_pseudos
, regno
);
6133 if (lra_dump_file
!= NULL
&& n_all_inherit
!= 0)
6134 fprintf (lra_dump_file
, "Inherit %d out of %d (%.2f%%)\n",
6135 n_inherit
, n_all_inherit
,
6136 (double) n_inherit
/ n_all_inherit
* 100);
6137 n_split
= n_all_split
= 0;
6138 EXECUTE_IF_SET_IN_BITMAP (&lra_split_regs
, 0, regno
, bi
)
6139 if ((restore_regno
= lra_reg_info
[regno
].restore_regno
) >= 0)
6142 hard_regno
= (restore_regno
>= FIRST_PSEUDO_REGISTER
6143 ? reg_renumber
[restore_regno
] : restore_regno
);
6144 if (hard_regno
< 0 || reg_renumber
[regno
] == hard_regno
)
6145 bitmap_set_bit (&remove_pseudos
, regno
);
6149 if (lra_dump_file
!= NULL
)
6150 fprintf (lra_dump_file
, " Keep split r%d (orig=r%d)\n",
6151 regno
, restore_regno
);
6154 if (lra_dump_file
!= NULL
&& n_all_split
!= 0)
6155 fprintf (lra_dump_file
, "Split %d out of %d (%.2f%%)\n",
6156 n_split
, n_all_split
,
6157 (double) n_split
/ n_all_split
* 100);
6158 change_p
= remove_inheritance_pseudos (&remove_pseudos
);
6159 bitmap_clear (&remove_pseudos
);
6160 /* Clear restore_regnos. */
6161 EXECUTE_IF_SET_IN_BITMAP (&lra_inheritance_pseudos
, 0, regno
, bi
)
6162 lra_reg_info
[regno
].restore_regno
= -1;
6163 EXECUTE_IF_SET_IN_BITMAP (&lra_split_regs
, 0, regno
, bi
)
6164 lra_reg_info
[regno
].restore_regno
= -1;
6165 change_p
= undo_optional_reloads () || change_p
;