1 /* Code for RTL transformations to satisfy insn constraints.
2 Copyright (C) 2010-2013 Free Software Foundation, Inc.
3 Contributed by Vladimir Makarov <vmakarov@redhat.com>.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 3, or (at your option) any later
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
22 /* This file contains code for 3 passes: constraint pass,
23 inheritance/split pass, and pass for undoing failed inheritance and
26 The major goal of constraint pass is to transform RTL to satisfy
27 insn and address constraints by:
28 o choosing insn alternatives;
29 o generating *reload insns* (or reloads in brief) and *reload
30 pseudos* which will get necessary hard registers later;
31 o substituting pseudos with equivalent values and removing the
32 instructions that initialized those pseudos.
34 The constraint pass has biggest and most complicated code in LRA.
35 There are a lot of important details like:
36 o reuse of input reload pseudos to simplify reload pseudo
38 o some heuristics to choose insn alternative to improve the
42 The pass is mimicking former reload pass in alternative choosing
43 because the reload pass is oriented to current machine description
44 model. It might be changed if the machine description model is
47 There is special code for preventing all LRA and this pass cycling
50 On the first iteration of the pass we process every instruction and
51 choose an alternative for each one. On subsequent iterations we try
52 to avoid reprocessing instructions if we can be sure that the old
53 choice is still valid.
55 The inheritance/spilt pass is to transform code to achieve
56 ineheritance and live range splitting. It is done on backward
59 The inheritance optimization goal is to reuse values in hard
60 registers. There is analogous optimization in old reload pass. The
61 inheritance is achieved by following transformation:
63 reload_p1 <- p reload_p1 <- p
64 ... new_p <- reload_p1
66 reload_p2 <- p reload_p2 <- new_p
68 where p is spilled and not changed between the insns. Reload_p1 is
69 also called *original pseudo* and new_p is called *inheritance
72 The subsequent assignment pass will try to assign the same (or
73 another if it is not possible) hard register to new_p as to
74 reload_p1 or reload_p2.
76 If the assignment pass fails to assign a hard register to new_p,
77 this file will undo the inheritance and restore the original code.
78 This is because implementing the above sequence with a spilled
79 new_p would make the code much worse. The inheritance is done in
80 EBB scope. The above is just a simplified example to get an idea
81 of the inheritance as the inheritance is also done for non-reload
84 Splitting (transformation) is also done in EBB scope on the same
85 pass as the inheritance:
87 r <- ... or ... <- r r <- ... or ... <- r
88 ... s <- r (new insn -- save)
90 ... r <- s (new insn -- restore)
93 The *split pseudo* s is assigned to the hard register of the
94 original pseudo or hard register r.
97 o In EBBs with high register pressure for global pseudos (living
98 in at least 2 BBs) and assigned to hard registers when there
99 are more one reloads needing the hard registers;
100 o for pseudos needing save/restore code around calls.
102 If the split pseudo still has the same hard register as the
103 original pseudo after the subsequent assignment pass or the
104 original pseudo was split, the opposite transformation is done on
105 the same pass for undoing inheritance. */
111 #include "coretypes.h"
113 #include "hard-reg-set.h"
117 #include "insn-config.h"
118 #include "insn-codes.h"
121 #include "addresses.h"
123 #include "function.h"
125 #include "basic-block.h"
130 #include "rtl-error.h"
133 /* Value of LRA_CURR_RELOAD_NUM at the beginning of BB of the current
134 insn. Remember that LRA_CURR_RELOAD_NUM is the number of emitted
136 static int bb_reload_num
;
138 /* The current insn being processed and corresponding its data (basic
139 block, the insn data, the insn static data, and the mode of each
141 static rtx curr_insn
;
142 static basic_block curr_bb
;
143 static lra_insn_recog_data_t curr_id
;
144 static struct lra_static_insn_data
*curr_static_id
;
145 static enum machine_mode curr_operand_mode
[MAX_RECOG_OPERANDS
];
149 /* Start numbers for new registers and insns at the current constraints
151 static int new_regno_start
;
152 static int new_insn_uid_start
;
154 /* If LOC is nonnull, strip any outer subreg from it. */
156 strip_subreg (rtx
*loc
)
158 return loc
&& GET_CODE (*loc
) == SUBREG
? &SUBREG_REG (*loc
) : loc
;
161 /* Return hard regno of REGNO or if it is was not assigned to a hard
162 register, use a hard register from its allocno class. */
164 get_try_hard_regno (int regno
)
167 enum reg_class rclass
;
169 if ((hard_regno
= regno
) >= FIRST_PSEUDO_REGISTER
)
170 hard_regno
= lra_get_regno_hard_regno (regno
);
173 rclass
= lra_get_allocno_class (regno
);
174 if (rclass
== NO_REGS
)
176 return ira_class_hard_regs
[rclass
][0];
179 /* Return final hard regno (plus offset) which will be after
180 elimination. We do this for matching constraints because the final
181 hard regno could have a different class. */
183 get_final_hard_regno (int hard_regno
, int offset
)
187 hard_regno
= lra_get_elimination_hard_regno (hard_regno
);
188 return hard_regno
+ offset
;
191 /* Return hard regno of X after removing subreg and making
192 elimination. If X is not a register or subreg of register, return
193 -1. For pseudo use its assignment. */
195 get_hard_regno (rtx x
)
198 int offset
, hard_regno
;
201 if (GET_CODE (x
) == SUBREG
)
202 reg
= SUBREG_REG (x
);
205 if ((hard_regno
= REGNO (reg
)) >= FIRST_PSEUDO_REGISTER
)
206 hard_regno
= lra_get_regno_hard_regno (hard_regno
);
210 if (GET_CODE (x
) == SUBREG
)
211 offset
+= subreg_regno_offset (hard_regno
, GET_MODE (reg
),
212 SUBREG_BYTE (x
), GET_MODE (x
));
213 return get_final_hard_regno (hard_regno
, offset
);
216 /* If REGNO is a hard register or has been allocated a hard register,
217 return the class of that register. If REGNO is a reload pseudo
218 created by the current constraints pass, return its allocno class.
219 Return NO_REGS otherwise. */
220 static enum reg_class
221 get_reg_class (int regno
)
225 if ((hard_regno
= regno
) >= FIRST_PSEUDO_REGISTER
)
226 hard_regno
= lra_get_regno_hard_regno (regno
);
229 hard_regno
= get_final_hard_regno (hard_regno
, 0);
230 return REGNO_REG_CLASS (hard_regno
);
232 if (regno
>= new_regno_start
)
233 return lra_get_allocno_class (regno
);
237 /* Return true if REG satisfies (or will satisfy) reg class constraint
238 CL. Use elimination first if REG is a hard register. If REG is a
239 reload pseudo created by this constraints pass, assume that it will
240 be allocated a hard register from its allocno class, but allow that
241 class to be narrowed to CL if it is currently a superset of CL.
243 If NEW_CLASS is nonnull, set *NEW_CLASS to the new allocno class of
244 REGNO (reg), or NO_REGS if no change in its class was needed. */
246 in_class_p (rtx reg
, enum reg_class cl
, enum reg_class
*new_class
)
248 enum reg_class rclass
, common_class
;
249 enum machine_mode reg_mode
;
250 int class_size
, hard_regno
, nregs
, i
, j
;
251 int regno
= REGNO (reg
);
253 if (new_class
!= NULL
)
254 *new_class
= NO_REGS
;
255 if (regno
< FIRST_PSEUDO_REGISTER
)
258 rtx
*final_loc
= &final_reg
;
260 lra_eliminate_reg_if_possible (final_loc
);
261 return TEST_HARD_REG_BIT (reg_class_contents
[cl
], REGNO (*final_loc
));
263 reg_mode
= GET_MODE (reg
);
264 rclass
= get_reg_class (regno
);
265 if (regno
< new_regno_start
266 /* Do not allow the constraints for reload instructions to
267 influence the classes of new pseudos. These reloads are
268 typically moves that have many alternatives, and restricting
269 reload pseudos for one alternative may lead to situations
270 where other reload pseudos are no longer allocatable. */
271 || INSN_UID (curr_insn
) >= new_insn_uid_start
)
272 /* When we don't know what class will be used finally for reload
273 pseudos, we use ALL_REGS. */
274 return ((regno
>= new_regno_start
&& rclass
== ALL_REGS
)
275 || (rclass
!= NO_REGS
&& ira_class_subset_p
[rclass
][cl
]
276 && ! hard_reg_set_subset_p (reg_class_contents
[cl
],
277 lra_no_alloc_regs
)));
280 common_class
= ira_reg_class_subset
[rclass
][cl
];
281 if (new_class
!= NULL
)
282 *new_class
= common_class
;
283 if (hard_reg_set_subset_p (reg_class_contents
[common_class
],
286 /* Check that there are enough allocatable regs. */
287 class_size
= ira_class_hard_regs_num
[common_class
];
288 for (i
= 0; i
< class_size
; i
++)
290 hard_regno
= ira_class_hard_regs
[common_class
][i
];
291 nregs
= hard_regno_nregs
[hard_regno
][reg_mode
];
294 for (j
= 0; j
< nregs
; j
++)
295 if (TEST_HARD_REG_BIT (lra_no_alloc_regs
, hard_regno
+ j
)
296 || ! TEST_HARD_REG_BIT (reg_class_contents
[common_class
],
306 /* Return true if REGNO satisfies a memory constraint. */
310 return get_reg_class (regno
) == NO_REGS
;
313 /* If we have decided to substitute X with another value, return that
314 value, otherwise return X. */
316 get_equiv_substitution (rtx x
)
321 if (! REG_P (x
) || (regno
= REGNO (x
)) < FIRST_PSEUDO_REGISTER
322 || ! ira_reg_equiv
[regno
].defined_p
323 || ! ira_reg_equiv
[regno
].profitable_p
324 || lra_get_regno_hard_regno (regno
) >= 0)
326 if ((res
= ira_reg_equiv
[regno
].memory
) != NULL_RTX
)
328 if ((res
= ira_reg_equiv
[regno
].constant
) != NULL_RTX
)
330 if ((res
= ira_reg_equiv
[regno
].invariant
) != NULL_RTX
)
335 /* Set up curr_operand_mode. */
337 init_curr_operand_mode (void)
339 int nop
= curr_static_id
->n_operands
;
340 for (int i
= 0; i
< nop
; i
++)
342 enum machine_mode mode
= GET_MODE (*curr_id
->operand_loc
[i
]);
343 if (mode
== VOIDmode
)
345 /* The .md mode for address operands is the mode of the
346 addressed value rather than the mode of the address itself. */
347 if (curr_id
->icode
>= 0 && curr_static_id
->operand
[i
].is_address
)
350 mode
= curr_static_id
->operand
[i
].mode
;
352 curr_operand_mode
[i
] = mode
;
358 /* The page contains code to reuse input reloads. */
360 /* Structure describes input reload of the current insns. */
363 /* Reloaded value. */
365 /* Reload pseudo used. */
369 /* The number of elements in the following array. */
370 static int curr_insn_input_reloads_num
;
371 /* Array containing info about input reloads. It is used to find the
372 same input reload and reuse the reload pseudo in this case. */
373 static struct input_reload curr_insn_input_reloads
[LRA_MAX_INSN_RELOADS
];
375 /* Initiate data concerning reuse of input reloads for the current
378 init_curr_insn_input_reloads (void)
380 curr_insn_input_reloads_num
= 0;
383 /* Change class of pseudo REGNO to NEW_CLASS. Print info about it
384 using TITLE. Output a new line if NL_P. */
386 change_class (int regno
, enum reg_class new_class
,
387 const char *title
, bool nl_p
)
389 lra_assert (regno
>= FIRST_PSEUDO_REGISTER
);
390 if (lra_dump_file
!= NULL
)
391 fprintf (lra_dump_file
, "%s to class %s for r%d",
392 title
, reg_class_names
[new_class
], regno
);
393 setup_reg_classes (regno
, new_class
, NO_REGS
, new_class
);
394 if (lra_dump_file
!= NULL
&& nl_p
)
395 fprintf (lra_dump_file
, "\n");
398 /* Create a new pseudo using MODE, RCLASS, ORIGINAL or reuse already
399 created input reload pseudo (only if TYPE is not OP_OUT). The
400 result pseudo is returned through RESULT_REG. Return TRUE if we
401 created a new pseudo, FALSE if we reused the already created input
402 reload pseudo. Use TITLE to describe new registers for debug
405 get_reload_reg (enum op_type type
, enum machine_mode mode
, rtx original
,
406 enum reg_class rclass
, const char *title
, rtx
*result_reg
)
409 enum reg_class new_class
;
414 = lra_create_new_reg_with_unique_value (mode
, original
, rclass
, title
);
417 /* Prevent reuse value of expression with side effects,
418 e.g. volatile memory. */
419 if (! side_effects_p (original
))
420 for (i
= 0; i
< curr_insn_input_reloads_num
; i
++)
421 if (rtx_equal_p (curr_insn_input_reloads
[i
].input
, original
)
422 && in_class_p (curr_insn_input_reloads
[i
].reg
, rclass
, &new_class
))
424 rtx reg
= curr_insn_input_reloads
[i
].reg
;
426 /* If input is equal to original and both are VOIDmode,
427 GET_MODE (reg) might be still different from mode.
428 Ensure we don't return *result_reg with wrong mode. */
429 if (GET_MODE (reg
) != mode
)
431 if (GET_MODE_SIZE (GET_MODE (reg
)) < GET_MODE_SIZE (mode
))
433 reg
= lowpart_subreg (mode
, reg
, GET_MODE (reg
));
434 if (reg
== NULL_RTX
|| GET_CODE (reg
) != SUBREG
)
438 if (lra_dump_file
!= NULL
)
440 fprintf (lra_dump_file
, " Reuse r%d for reload ", regno
);
441 dump_value_slim (lra_dump_file
, original
, 1);
443 if (new_class
!= lra_get_allocno_class (regno
))
444 change_class (regno
, new_class
, ", change", false);
445 if (lra_dump_file
!= NULL
)
446 fprintf (lra_dump_file
, "\n");
449 *result_reg
= lra_create_new_reg (mode
, original
, rclass
, title
);
450 lra_assert (curr_insn_input_reloads_num
< LRA_MAX_INSN_RELOADS
);
451 curr_insn_input_reloads
[curr_insn_input_reloads_num
].input
= original
;
452 curr_insn_input_reloads
[curr_insn_input_reloads_num
++].reg
= *result_reg
;
458 /* The page contains code to extract memory address parts. */
460 /* Wrapper around REGNO_OK_FOR_INDEX_P, to allow pseudos. */
462 ok_for_index_p_nonstrict (rtx reg
)
464 unsigned regno
= REGNO (reg
);
466 return regno
>= FIRST_PSEUDO_REGISTER
|| REGNO_OK_FOR_INDEX_P (regno
);
469 /* A version of regno_ok_for_base_p for use here, when all pseudos
470 should count as OK. Arguments as for regno_ok_for_base_p. */
472 ok_for_base_p_nonstrict (rtx reg
, enum machine_mode mode
, addr_space_t as
,
473 enum rtx_code outer_code
, enum rtx_code index_code
)
475 unsigned regno
= REGNO (reg
);
477 if (regno
>= FIRST_PSEUDO_REGISTER
)
479 return ok_for_base_p_1 (regno
, mode
, as
, outer_code
, index_code
);
484 /* The page contains major code to choose the current insn alternative
485 and generate reloads for it. */
487 /* Return the offset from REGNO of the least significant register
490 This function is used to tell whether two registers satisfy
491 a matching constraint. (reg:MODE1 REGNO1) matches (reg:MODE2 REGNO2) if:
493 REGNO1 + lra_constraint_offset (REGNO1, MODE1)
494 == REGNO2 + lra_constraint_offset (REGNO2, MODE2) */
496 lra_constraint_offset (int regno
, enum machine_mode mode
)
498 lra_assert (regno
< FIRST_PSEUDO_REGISTER
);
499 if (WORDS_BIG_ENDIAN
&& GET_MODE_SIZE (mode
) > UNITS_PER_WORD
500 && SCALAR_INT_MODE_P (mode
))
501 return hard_regno_nregs
[regno
][mode
] - 1;
505 /* Like rtx_equal_p except that it allows a REG and a SUBREG to match
506 if they are the same hard reg, and has special hacks for
507 auto-increment and auto-decrement. This is specifically intended for
508 process_alt_operands to use in determining whether two operands
509 match. X is the operand whose number is the lower of the two.
511 It is supposed that X is the output operand and Y is the input
512 operand. Y_HARD_REGNO is the final hard regno of register Y or
513 register in subreg Y as we know it now. Otherwise, it is a
516 operands_match_p (rtx x
, rtx y
, int y_hard_regno
)
519 RTX_CODE code
= GET_CODE (x
);
524 if ((code
== REG
|| (code
== SUBREG
&& REG_P (SUBREG_REG (x
))))
525 && (REG_P (y
) || (GET_CODE (y
) == SUBREG
&& REG_P (SUBREG_REG (y
)))))
529 i
= get_hard_regno (x
);
533 if ((j
= y_hard_regno
) < 0)
536 i
+= lra_constraint_offset (i
, GET_MODE (x
));
537 j
+= lra_constraint_offset (j
, GET_MODE (y
));
542 /* If two operands must match, because they are really a single
543 operand of an assembler insn, then two post-increments are invalid
544 because the assembler insn would increment only once. On the
545 other hand, a post-increment matches ordinary indexing if the
546 post-increment is the output operand. */
547 if (code
== POST_DEC
|| code
== POST_INC
|| code
== POST_MODIFY
)
548 return operands_match_p (XEXP (x
, 0), y
, y_hard_regno
);
550 /* Two pre-increments are invalid because the assembler insn would
551 increment only once. On the other hand, a pre-increment matches
552 ordinary indexing if the pre-increment is the input operand. */
553 if (GET_CODE (y
) == PRE_DEC
|| GET_CODE (y
) == PRE_INC
554 || GET_CODE (y
) == PRE_MODIFY
)
555 return operands_match_p (x
, XEXP (y
, 0), -1);
559 if (code
== REG
&& GET_CODE (y
) == SUBREG
&& REG_P (SUBREG_REG (y
))
560 && x
== SUBREG_REG (y
))
562 if (GET_CODE (y
) == REG
&& code
== SUBREG
&& REG_P (SUBREG_REG (x
))
563 && SUBREG_REG (x
) == y
)
566 /* Now we have disposed of all the cases in which different rtx
568 if (code
!= GET_CODE (y
))
571 /* (MULT:SI x y) and (MULT:HI x y) are NOT equivalent. */
572 if (GET_MODE (x
) != GET_MODE (y
))
581 return XEXP (x
, 0) == XEXP (y
, 0);
583 return XSTR (x
, 0) == XSTR (y
, 0);
589 /* Compare the elements. If any pair of corresponding elements fail
590 to match, return false for the whole things. */
592 fmt
= GET_RTX_FORMAT (code
);
593 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
599 if (XWINT (x
, i
) != XWINT (y
, i
))
604 if (XINT (x
, i
) != XINT (y
, i
))
609 val
= operands_match_p (XEXP (x
, i
), XEXP (y
, i
), -1);
618 if (XVECLEN (x
, i
) != XVECLEN (y
, i
))
620 for (j
= XVECLEN (x
, i
) - 1; j
>= 0; --j
)
622 val
= operands_match_p (XVECEXP (x
, i
, j
), XVECEXP (y
, i
, j
), -1);
628 /* It is believed that rtx's at this level will never
629 contain anything but integers and other rtx's, except for
630 within LABEL_REFs and SYMBOL_REFs. */
638 /* True if X is a constant that can be forced into the constant pool.
639 MODE is the mode of the operand, or VOIDmode if not known. */
640 #define CONST_POOL_OK_P(MODE, X) \
641 ((MODE) != VOIDmode \
643 && GET_CODE (X) != HIGH \
644 && !targetm.cannot_force_const_mem (MODE, X))
646 /* True if C is a non-empty register class that has too few registers
647 to be safely used as a reload target class. */
648 #define SMALL_REGISTER_CLASS_P(C) \
649 (reg_class_size [(C)] == 1 \
650 || (reg_class_size [(C)] >= 1 && targetm.class_likely_spilled_p (C)))
652 /* If REG is a reload pseudo, try to make its class satisfying CL. */
654 narrow_reload_pseudo_class (rtx reg
, enum reg_class cl
)
656 enum reg_class rclass
;
658 /* Do not make more accurate class from reloads generated. They are
659 mostly moves with a lot of constraints. Making more accurate
660 class may results in very narrow class and impossibility of find
661 registers for several reloads of one insn. */
662 if (INSN_UID (curr_insn
) >= new_insn_uid_start
)
664 if (GET_CODE (reg
) == SUBREG
)
665 reg
= SUBREG_REG (reg
);
666 if (! REG_P (reg
) || (int) REGNO (reg
) < new_regno_start
)
668 if (in_class_p (reg
, cl
, &rclass
) && rclass
!= cl
)
669 change_class (REGNO (reg
), rclass
, " Change", true);
672 /* Generate reloads for matching OUT and INS (array of input operand
673 numbers with end marker -1) with reg class GOAL_CLASS. Add input
674 and output reloads correspondingly to the lists *BEFORE and *AFTER.
675 OUT might be negative. In this case we generate input reloads for
676 matched input operands INS. */
678 match_reload (signed char out
, signed char *ins
, enum reg_class goal_class
,
679 rtx
*before
, rtx
*after
)
682 rtx new_in_reg
, new_out_reg
, reg
, clobber
;
683 enum machine_mode inmode
, outmode
;
684 rtx in_rtx
= *curr_id
->operand_loc
[ins
[0]];
685 rtx out_rtx
= out
< 0 ? in_rtx
: *curr_id
->operand_loc
[out
];
687 inmode
= curr_operand_mode
[ins
[0]];
688 outmode
= out
< 0 ? inmode
: curr_operand_mode
[out
];
689 push_to_sequence (*before
);
690 if (inmode
!= outmode
)
692 if (GET_MODE_SIZE (inmode
) > GET_MODE_SIZE (outmode
))
695 = lra_create_new_reg_with_unique_value (inmode
, in_rtx
,
697 if (SCALAR_INT_MODE_P (inmode
))
698 new_out_reg
= gen_lowpart_SUBREG (outmode
, reg
);
700 new_out_reg
= gen_rtx_SUBREG (outmode
, reg
, 0);
701 /* If the input reg is dying here, we can use the same hard
702 register for REG and IN_RTX. We do it only for original
703 pseudos as reload pseudos can die although original
704 pseudos still live where reload pseudos dies. */
705 if (REG_P (in_rtx
) && (int) REGNO (in_rtx
) < lra_new_regno_start
706 && find_regno_note (curr_insn
, REG_DEAD
, REGNO (in_rtx
)))
707 lra_reg_info
[REGNO (reg
)].val
= lra_reg_info
[REGNO (in_rtx
)].val
;
712 = lra_create_new_reg_with_unique_value (outmode
, out_rtx
,
714 if (SCALAR_INT_MODE_P (outmode
))
715 new_in_reg
= gen_lowpart_SUBREG (inmode
, reg
);
717 new_in_reg
= gen_rtx_SUBREG (inmode
, reg
, 0);
718 /* NEW_IN_REG is non-paradoxical subreg. We don't want
719 NEW_OUT_REG living above. We add clobber clause for
720 this. This is just a temporary clobber. We can remove
721 it at the end of LRA work. */
722 clobber
= emit_clobber (new_out_reg
);
723 LRA_TEMP_CLOBBER_P (PATTERN (clobber
)) = 1;
724 if (GET_CODE (in_rtx
) == SUBREG
)
726 rtx subreg_reg
= SUBREG_REG (in_rtx
);
728 /* If SUBREG_REG is dying here and sub-registers IN_RTX
729 and NEW_IN_REG are similar, we can use the same hard
730 register for REG and SUBREG_REG. */
731 if (REG_P (subreg_reg
)
732 && (int) REGNO (subreg_reg
) < lra_new_regno_start
733 && GET_MODE (subreg_reg
) == outmode
734 && SUBREG_BYTE (in_rtx
) == SUBREG_BYTE (new_in_reg
)
735 && find_regno_note (curr_insn
, REG_DEAD
, REGNO (subreg_reg
)))
736 lra_reg_info
[REGNO (reg
)].val
737 = lra_reg_info
[REGNO (subreg_reg
)].val
;
743 /* Pseudos have values -- see comments for lra_reg_info.
744 Different pseudos with the same value do not conflict even if
745 they live in the same place. When we create a pseudo we
746 assign value of original pseudo (if any) from which we
747 created the new pseudo. If we create the pseudo from the
748 input pseudo, the new pseudo will no conflict with the input
749 pseudo which is wrong when the input pseudo lives after the
750 insn and as the new pseudo value is changed by the insn
751 output. Therefore we create the new pseudo from the output.
753 We cannot reuse the current output register because we might
754 have a situation like "a <- a op b", where the constraints
755 force the second input operand ("b") to match the output
756 operand ("a"). "b" must then be copied into a new register
757 so that it doesn't clobber the current value of "a". */
759 new_in_reg
= new_out_reg
760 = lra_create_new_reg_with_unique_value (outmode
, out_rtx
,
763 /* In operand can be got from transformations before processing insn
764 constraints. One example of such transformations is subreg
765 reloading (see function simplify_operand_subreg). The new
766 pseudos created by the transformations might have inaccurate
767 class (ALL_REGS) and we should make their classes more
769 narrow_reload_pseudo_class (in_rtx
, goal_class
);
770 lra_emit_move (copy_rtx (new_in_reg
), in_rtx
);
771 *before
= get_insns ();
773 for (i
= 0; (in
= ins
[i
]) >= 0; i
++)
776 (GET_MODE (*curr_id
->operand_loc
[in
]) == VOIDmode
777 || GET_MODE (new_in_reg
) == GET_MODE (*curr_id
->operand_loc
[in
]));
778 *curr_id
->operand_loc
[in
] = new_in_reg
;
780 lra_update_dups (curr_id
, ins
);
783 /* See a comment for the input operand above. */
784 narrow_reload_pseudo_class (out_rtx
, goal_class
);
785 if (find_reg_note (curr_insn
, REG_UNUSED
, out_rtx
) == NULL_RTX
)
788 lra_emit_move (out_rtx
, copy_rtx (new_out_reg
));
790 *after
= get_insns ();
793 *curr_id
->operand_loc
[out
] = new_out_reg
;
794 lra_update_dup (curr_id
, out
);
797 /* Return register class which is union of all reg classes in insn
798 constraint alternative string starting with P. */
799 static enum reg_class
800 reg_class_from_constraints (const char *p
)
803 enum reg_class op_class
= NO_REGS
;
806 switch ((c
= *p
, len
= CONSTRAINT_LEN (c
, p
)), c
)
813 op_class
= (reg_class_subunion
814 [op_class
][base_reg_class (VOIDmode
, ADDR_SPACE_GENERIC
,
820 op_class
= reg_class_subunion
[op_class
][GENERAL_REGS
];
824 if (REG_CLASS_FROM_CONSTRAINT (c
, p
) == NO_REGS
)
826 #ifdef EXTRA_CONSTRAINT_STR
827 if (EXTRA_ADDRESS_CONSTRAINT (c
, p
))
829 = (reg_class_subunion
830 [op_class
][base_reg_class (VOIDmode
, ADDR_SPACE_GENERIC
,
837 = reg_class_subunion
[op_class
][REG_CLASS_FROM_CONSTRAINT (c
, p
)];
840 while ((p
+= len
), c
);
844 /* If OP is a register, return the class of the register as per
845 get_reg_class, otherwise return NO_REGS. */
846 static inline enum reg_class
847 get_op_class (rtx op
)
849 return REG_P (op
) ? get_reg_class (REGNO (op
)) : NO_REGS
;
852 /* Return generated insn mem_pseudo:=val if TO_P or val:=mem_pseudo
853 otherwise. If modes of MEM_PSEUDO and VAL are different, use
854 SUBREG for VAL to make them equal. */
856 emit_spill_move (bool to_p
, rtx mem_pseudo
, rtx val
)
858 if (GET_MODE (mem_pseudo
) != GET_MODE (val
))
859 val
= gen_rtx_SUBREG (GET_MODE (mem_pseudo
),
860 GET_CODE (val
) == SUBREG
? SUBREG_REG (val
) : val
,
863 ? gen_move_insn (mem_pseudo
, val
)
864 : gen_move_insn (val
, mem_pseudo
));
867 /* Process a special case insn (register move), return true if we
868 don't need to process it anymore. Return that RTL was changed
869 through CHANGE_P and macro SECONDARY_MEMORY_NEEDED says to use
870 secondary memory through SEC_MEM_P. */
872 check_and_process_move (bool *change_p
, bool *sec_mem_p
)
875 rtx set
, dest
, src
, dreg
, sreg
, old_sreg
, new_reg
, before
, scratch_reg
;
876 enum reg_class dclass
, sclass
, secondary_class
;
877 enum machine_mode sreg_mode
;
878 secondary_reload_info sri
;
880 *sec_mem_p
= *change_p
= false;
881 if ((set
= single_set (curr_insn
)) == NULL
)
883 dreg
= dest
= SET_DEST (set
);
884 sreg
= src
= SET_SRC (set
);
885 /* Quick check on the right move insn which does not need
887 if ((dclass
= get_op_class (dest
)) != NO_REGS
888 && (sclass
= get_op_class (src
)) != NO_REGS
889 /* The backend guarantees that register moves of cost 2 never
891 && targetm
.register_move_cost (GET_MODE (src
), dclass
, sclass
) == 2)
893 if (GET_CODE (dest
) == SUBREG
)
894 dreg
= SUBREG_REG (dest
);
895 if (GET_CODE (src
) == SUBREG
)
896 sreg
= SUBREG_REG (src
);
897 if (! REG_P (dreg
) || ! REG_P (sreg
))
899 sclass
= dclass
= NO_REGS
;
900 dreg
= get_equiv_substitution (dreg
);
902 dclass
= get_reg_class (REGNO (dreg
));
903 if (dclass
== ALL_REGS
)
904 /* ALL_REGS is used for new pseudos created by transformations
905 like reload of SUBREG_REG (see function
906 simplify_operand_subreg). We don't know their class yet. We
907 should figure out the class from processing the insn
908 constraints not in this fast path function. Even if ALL_REGS
909 were a right class for the pseudo, secondary_... hooks usually
910 are not define for ALL_REGS. */
912 sreg_mode
= GET_MODE (sreg
);
914 sreg
= get_equiv_substitution (sreg
);
916 sclass
= get_reg_class (REGNO (sreg
));
917 if (sclass
== ALL_REGS
)
918 /* See comments above. */
920 #ifdef SECONDARY_MEMORY_NEEDED
921 if (dclass
!= NO_REGS
&& sclass
!= NO_REGS
922 && SECONDARY_MEMORY_NEEDED (sclass
, dclass
, GET_MODE (src
)))
929 sri
.icode
= CODE_FOR_nothing
;
931 secondary_class
= NO_REGS
;
932 /* Set up hard register for a reload pseudo for hook
933 secondary_reload because some targets just ignore unassigned
934 pseudos in the hook. */
935 if (dclass
!= NO_REGS
&& lra_get_regno_hard_regno (REGNO (dreg
)) < 0)
937 dregno
= REGNO (dreg
);
938 reg_renumber
[dregno
] = ira_class_hard_regs
[dclass
][0];
942 if (sclass
!= NO_REGS
&& lra_get_regno_hard_regno (REGNO (sreg
)) < 0)
944 sregno
= REGNO (sreg
);
945 reg_renumber
[sregno
] = ira_class_hard_regs
[sclass
][0];
949 if (sclass
!= NO_REGS
)
951 = (enum reg_class
) targetm
.secondary_reload (false, dest
,
952 (reg_class_t
) sclass
,
953 GET_MODE (src
), &sri
);
954 if (sclass
== NO_REGS
955 || ((secondary_class
!= NO_REGS
|| sri
.icode
!= CODE_FOR_nothing
)
956 && dclass
!= NO_REGS
))
958 enum reg_class old_sclass
= secondary_class
;
959 secondary_reload_info old_sri
= sri
;
962 sri
.icode
= CODE_FOR_nothing
;
965 = (enum reg_class
) targetm
.secondary_reload (true, sreg
,
966 (reg_class_t
) dclass
,
968 /* Check the target hook consistency. */
970 ((secondary_class
== NO_REGS
&& sri
.icode
== CODE_FOR_nothing
)
971 || (old_sclass
== NO_REGS
&& old_sri
.icode
== CODE_FOR_nothing
)
972 || (secondary_class
== old_sclass
&& sri
.icode
== old_sri
.icode
));
975 reg_renumber
[sregno
] = -1;
977 reg_renumber
[dregno
] = -1;
978 if (secondary_class
== NO_REGS
&& sri
.icode
== CODE_FOR_nothing
)
982 if (secondary_class
!= NO_REGS
)
983 new_reg
= lra_create_new_reg_with_unique_value (sreg_mode
, NULL_RTX
,
987 if (old_sreg
!= sreg
)
988 sreg
= copy_rtx (sreg
);
989 if (sri
.icode
== CODE_FOR_nothing
)
990 lra_emit_move (new_reg
, sreg
);
993 enum reg_class scratch_class
;
995 scratch_class
= (reg_class_from_constraints
996 (insn_data
[sri
.icode
].operand
[2].constraint
));
997 scratch_reg
= (lra_create_new_reg_with_unique_value
998 (insn_data
[sri
.icode
].operand
[2].mode
, NULL_RTX
,
999 scratch_class
, "scratch"));
1000 emit_insn (GEN_FCN (sri
.icode
) (new_reg
!= NULL_RTX
? new_reg
: dest
,
1001 sreg
, scratch_reg
));
1003 before
= get_insns ();
1005 lra_process_new_insns (curr_insn
, before
, NULL_RTX
, "Inserting the move");
1006 if (new_reg
!= NULL_RTX
)
1008 if (GET_CODE (src
) == SUBREG
)
1009 SUBREG_REG (src
) = new_reg
;
1011 SET_SRC (set
) = new_reg
;
1015 if (lra_dump_file
!= NULL
)
1017 fprintf (lra_dump_file
, "Deleting move %u\n", INSN_UID (curr_insn
));
1018 dump_insn_slim (lra_dump_file
, curr_insn
);
1020 lra_set_insn_deleted (curr_insn
);
1026 /* The following data describe the result of process_alt_operands.
1027 The data are used in curr_insn_transform to generate reloads. */
1029 /* The chosen reg classes which should be used for the corresponding
1031 static enum reg_class goal_alt
[MAX_RECOG_OPERANDS
];
1032 /* True if the operand should be the same as another operand and that
1033 other operand does not need a reload. */
1034 static bool goal_alt_match_win
[MAX_RECOG_OPERANDS
];
1035 /* True if the operand does not need a reload. */
1036 static bool goal_alt_win
[MAX_RECOG_OPERANDS
];
1037 /* True if the operand can be offsetable memory. */
1038 static bool goal_alt_offmemok
[MAX_RECOG_OPERANDS
];
1039 /* The number of an operand to which given operand can be matched to. */
1040 static int goal_alt_matches
[MAX_RECOG_OPERANDS
];
1041 /* The number of elements in the following array. */
1042 static int goal_alt_dont_inherit_ops_num
;
1043 /* Numbers of operands whose reload pseudos should not be inherited. */
1044 static int goal_alt_dont_inherit_ops
[MAX_RECOG_OPERANDS
];
1045 /* True if the insn commutative operands should be swapped. */
1046 static bool goal_alt_swapped
;
1047 /* The chosen insn alternative. */
1048 static int goal_alt_number
;
1050 /* The following five variables are used to choose the best insn
1051 alternative. They reflect final characteristics of the best
1054 /* Number of necessary reloads and overall cost reflecting the
1055 previous value and other unpleasantness of the best alternative. */
1056 static int best_losers
, best_overall
;
1057 /* Number of small register classes used for operands of the best
1059 static int best_small_class_operands_num
;
1060 /* Overall number hard registers used for reloads. For example, on
1061 some targets we need 2 general registers to reload DFmode and only
1062 one floating point register. */
1063 static int best_reload_nregs
;
1064 /* Overall number reflecting distances of previous reloading the same
1065 value. The distances are counted from the current BB start. It is
1066 used to improve inheritance chances. */
1067 static int best_reload_sum
;
1069 /* True if the current insn should have no correspondingly input or
1071 static bool no_input_reloads_p
, no_output_reloads_p
;
1073 /* True if we swapped the commutative operands in the current
1075 static int curr_swapped
;
1077 /* Arrange for address element *LOC to be a register of class CL.
1078 Add any input reloads to list BEFORE. AFTER is nonnull if *LOC is an
1079 automodified value; handle that case by adding the required output
1080 reloads to list AFTER. Return true if the RTL was changed. */
1082 process_addr_reg (rtx
*loc
, rtx
*before
, rtx
*after
, enum reg_class cl
)
1085 enum reg_class rclass
, new_class
;
1088 enum machine_mode mode
;
1089 bool before_p
= false;
1091 loc
= strip_subreg (loc
);
1093 mode
= GET_MODE (reg
);
1096 /* Always reload memory in an address even if the target supports
1098 new_reg
= lra_create_new_reg_with_unique_value (mode
, reg
, cl
, "address");
1103 regno
= REGNO (reg
);
1104 rclass
= get_reg_class (regno
);
1105 if ((*loc
= get_equiv_substitution (reg
)) != reg
)
1107 if (lra_dump_file
!= NULL
)
1109 fprintf (lra_dump_file
,
1110 "Changing pseudo %d in address of insn %u on equiv ",
1111 REGNO (reg
), INSN_UID (curr_insn
));
1112 dump_value_slim (lra_dump_file
, *loc
, 1);
1113 fprintf (lra_dump_file
, "\n");
1115 *loc
= copy_rtx (*loc
);
1117 if (*loc
!= reg
|| ! in_class_p (reg
, cl
, &new_class
))
1120 if (get_reload_reg (after
== NULL
? OP_IN
: OP_INOUT
,
1121 mode
, reg
, cl
, "address", &new_reg
))
1124 else if (new_class
!= NO_REGS
&& rclass
!= new_class
)
1126 change_class (regno
, new_class
, " Change", true);
1134 push_to_sequence (*before
);
1135 lra_emit_move (new_reg
, reg
);
1136 *before
= get_insns ();
1143 lra_emit_move (reg
, new_reg
);
1145 *after
= get_insns ();
1151 /* Make reloads for subreg in operand NOP with internal subreg mode
1152 REG_MODE, add new reloads for further processing. Return true if
1153 any reload was generated. */
1155 simplify_operand_subreg (int nop
, enum machine_mode reg_mode
)
1159 enum machine_mode mode
;
1161 rtx operand
= *curr_id
->operand_loc
[nop
];
1163 before
= after
= NULL_RTX
;
1165 if (GET_CODE (operand
) != SUBREG
)
1168 mode
= GET_MODE (operand
);
1169 reg
= SUBREG_REG (operand
);
1170 /* If we change address for paradoxical subreg of memory, the
1171 address might violate the necessary alignment or the access might
1172 be slow. So take this into consideration. We should not worry
1173 about access beyond allocated memory for paradoxical memory
1174 subregs as we don't substitute such equiv memory (see processing
1175 equivalences in function lra_constraints) and because for spilled
1176 pseudos we allocate stack memory enough for the biggest
1177 corresponding paradoxical subreg. */
1179 && (! SLOW_UNALIGNED_ACCESS (mode
, MEM_ALIGN (reg
))
1180 || MEM_ALIGN (reg
) >= GET_MODE_ALIGNMENT (mode
)))
1181 || (REG_P (reg
) && REGNO (reg
) < FIRST_PSEUDO_REGISTER
))
1183 alter_subreg (curr_id
->operand_loc
[nop
], false);
1186 /* Put constant into memory when we have mixed modes. It generates
1187 a better code in most cases as it does not need a secondary
1188 reload memory. It also prevents LRA looping when LRA is using
1189 secondary reload memory again and again. */
1190 if (CONSTANT_P (reg
) && CONST_POOL_OK_P (reg_mode
, reg
)
1191 && SCALAR_INT_MODE_P (reg_mode
) != SCALAR_INT_MODE_P (mode
))
1193 SUBREG_REG (operand
) = force_const_mem (reg_mode
, reg
);
1194 alter_subreg (curr_id
->operand_loc
[nop
], false);
1197 /* Force a reload of the SUBREG_REG if this is a constant or PLUS or
1198 if there may be a problem accessing OPERAND in the outer
1201 && REGNO (reg
) >= FIRST_PSEUDO_REGISTER
1202 && (hard_regno
= lra_get_regno_hard_regno (REGNO (reg
))) >= 0
1203 /* Don't reload paradoxical subregs because we could be looping
1204 having repeatedly final regno out of hard regs range. */
1205 && (hard_regno_nregs
[hard_regno
][GET_MODE (reg
)]
1206 >= hard_regno_nregs
[hard_regno
][mode
])
1207 && simplify_subreg_regno (hard_regno
, GET_MODE (reg
),
1208 SUBREG_BYTE (operand
), mode
) < 0)
1209 || CONSTANT_P (reg
) || GET_CODE (reg
) == PLUS
|| MEM_P (reg
))
1211 enum op_type type
= curr_static_id
->operand
[nop
].type
;
1212 /* The class will be defined later in curr_insn_transform. */
1213 enum reg_class rclass
1214 = (enum reg_class
) targetm
.preferred_reload_class (reg
, ALL_REGS
);
1216 if (get_reload_reg (curr_static_id
->operand
[nop
].type
, reg_mode
, reg
,
1217 rclass
, "subreg reg", &new_reg
))
1219 bitmap_set_bit (&lra_optional_reload_pseudos
, REGNO (new_reg
));
1221 || GET_MODE_SIZE (GET_MODE (reg
)) > GET_MODE_SIZE (mode
))
1223 push_to_sequence (before
);
1224 lra_emit_move (new_reg
, reg
);
1225 before
= get_insns ();
1231 lra_emit_move (reg
, new_reg
);
1233 after
= get_insns ();
1237 SUBREG_REG (operand
) = new_reg
;
1238 lra_process_new_insns (curr_insn
, before
, after
,
1239 "Inserting subreg reload");
1245 /* Return TRUE if X refers for a hard register from SET. */
1247 uses_hard_regs_p (rtx x
, HARD_REG_SET set
)
1249 int i
, j
, x_hard_regno
;
1250 enum machine_mode mode
;
1256 code
= GET_CODE (x
);
1257 mode
= GET_MODE (x
);
1261 code
= GET_CODE (x
);
1262 if (GET_MODE_SIZE (GET_MODE (x
)) > GET_MODE_SIZE (mode
))
1263 mode
= GET_MODE (x
);
1268 x_hard_regno
= get_hard_regno (x
);
1269 return (x_hard_regno
>= 0
1270 && overlaps_hard_reg_set_p (set
, mode
, x_hard_regno
));
1274 struct address_info ad
;
1276 decompose_mem_address (&ad
, x
);
1277 if (ad
.base_term
!= NULL
&& uses_hard_regs_p (*ad
.base_term
, set
))
1279 if (ad
.index_term
!= NULL
&& uses_hard_regs_p (*ad
.index_term
, set
))
1282 fmt
= GET_RTX_FORMAT (code
);
1283 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
1287 if (uses_hard_regs_p (XEXP (x
, i
), set
))
1290 else if (fmt
[i
] == 'E')
1292 for (j
= XVECLEN (x
, i
) - 1; j
>= 0; j
--)
1293 if (uses_hard_regs_p (XVECEXP (x
, i
, j
), set
))
1300 /* Return true if OP is a spilled pseudo. */
1302 spilled_pseudo_p (rtx op
)
1305 && REGNO (op
) >= FIRST_PSEUDO_REGISTER
&& in_mem_p (REGNO (op
)));
1308 /* Return true if X is a general constant. */
1310 general_constant_p (rtx x
)
1312 return CONSTANT_P (x
) && (! flag_pic
|| LEGITIMATE_PIC_OPERAND_P (x
));
1315 /* Major function to choose the current insn alternative and what
1316 operands should be reloaded and how. If ONLY_ALTERNATIVE is not
1317 negative we should consider only this alternative. Return false if
1318 we can not choose the alternative or find how to reload the
1321 process_alt_operands (int only_alternative
)
1324 int nop
, small_class_operands_num
, overall
, nalt
;
1325 int n_alternatives
= curr_static_id
->n_alternatives
;
1326 int n_operands
= curr_static_id
->n_operands
;
1327 /* LOSERS counts the operands that don't fit this alternative and
1328 would require loading. */
1330 /* REJECT is a count of how undesirable this alternative says it is
1331 if any reloading is required. If the alternative matches exactly
1332 then REJECT is ignored, but otherwise it gets this much counted
1333 against it in addition to the reloading needed. */
1335 /* The number of elements in the following array. */
1336 int early_clobbered_regs_num
;
1337 /* Numbers of operands which are early clobber registers. */
1338 int early_clobbered_nops
[MAX_RECOG_OPERANDS
];
1339 enum reg_class curr_alt
[MAX_RECOG_OPERANDS
];
1340 HARD_REG_SET curr_alt_set
[MAX_RECOG_OPERANDS
];
1341 bool curr_alt_match_win
[MAX_RECOG_OPERANDS
];
1342 bool curr_alt_win
[MAX_RECOG_OPERANDS
];
1343 bool curr_alt_offmemok
[MAX_RECOG_OPERANDS
];
1344 int curr_alt_matches
[MAX_RECOG_OPERANDS
];
1345 /* The number of elements in the following array. */
1346 int curr_alt_dont_inherit_ops_num
;
1347 /* Numbers of operands whose reload pseudos should not be inherited. */
1348 int curr_alt_dont_inherit_ops
[MAX_RECOG_OPERANDS
];
1350 /* The register when the operand is a subreg of register, otherwise the
1352 rtx no_subreg_reg_operand
[MAX_RECOG_OPERANDS
];
1353 /* The register if the operand is a register or subreg of register,
1355 rtx operand_reg
[MAX_RECOG_OPERANDS
];
1356 int hard_regno
[MAX_RECOG_OPERANDS
];
1357 enum machine_mode biggest_mode
[MAX_RECOG_OPERANDS
];
1358 int reload_nregs
, reload_sum
;
1362 /* Calculate some data common for all alternatives to speed up the
1364 for (nop
= 0; nop
< n_operands
; nop
++)
1366 op
= no_subreg_reg_operand
[nop
] = *curr_id
->operand_loc
[nop
];
1367 /* The real hard regno of the operand after the allocation. */
1368 hard_regno
[nop
] = get_hard_regno (op
);
1370 operand_reg
[nop
] = op
;
1371 biggest_mode
[nop
] = GET_MODE (operand_reg
[nop
]);
1372 if (GET_CODE (operand_reg
[nop
]) == SUBREG
)
1374 operand_reg
[nop
] = SUBREG_REG (operand_reg
[nop
]);
1375 if (GET_MODE_SIZE (biggest_mode
[nop
])
1376 < GET_MODE_SIZE (GET_MODE (operand_reg
[nop
])))
1377 biggest_mode
[nop
] = GET_MODE (operand_reg
[nop
]);
1379 if (REG_P (operand_reg
[nop
]))
1380 no_subreg_reg_operand
[nop
] = operand_reg
[nop
];
1382 operand_reg
[nop
] = NULL_RTX
;
1385 /* The constraints are made of several alternatives. Each operand's
1386 constraint looks like foo,bar,... with commas separating the
1387 alternatives. The first alternatives for all operands go
1388 together, the second alternatives go together, etc.
1390 First loop over alternatives. */
1391 for (nalt
= 0; nalt
< n_alternatives
; nalt
++)
1393 /* Loop over operands for one constraint alternative. */
1394 #ifdef HAVE_ATTR_enabled
1395 if (curr_id
->alternative_enabled_p
!= NULL
1396 && ! curr_id
->alternative_enabled_p
[nalt
])
1400 if (only_alternative
>= 0 && nalt
!= only_alternative
)
1403 overall
= losers
= reject
= reload_nregs
= reload_sum
= 0;
1404 for (nop
= 0; nop
< n_operands
; nop
++)
1405 reject
+= (curr_static_id
1406 ->operand_alternative
[nalt
* n_operands
+ nop
].reject
);
1407 early_clobbered_regs_num
= 0;
1409 for (nop
= 0; nop
< n_operands
; nop
++)
1413 int len
, c
, m
, i
, opalt_num
, this_alternative_matches
;
1414 bool win
, did_match
, offmemok
, early_clobber_p
;
1415 /* false => this operand can be reloaded somehow for this
1418 /* true => this operand can be reloaded if the alternative
1421 /* True if a constant forced into memory would be OK for
1424 enum reg_class this_alternative
, this_costly_alternative
;
1425 HARD_REG_SET this_alternative_set
, this_costly_alternative_set
;
1426 bool this_alternative_match_win
, this_alternative_win
;
1427 bool this_alternative_offmemok
;
1428 enum machine_mode mode
;
1430 opalt_num
= nalt
* n_operands
+ nop
;
1431 if (curr_static_id
->operand_alternative
[opalt_num
].anything_ok
)
1433 /* Fast track for no constraints at all. */
1434 curr_alt
[nop
] = NO_REGS
;
1435 CLEAR_HARD_REG_SET (curr_alt_set
[nop
]);
1436 curr_alt_win
[nop
] = true;
1437 curr_alt_match_win
[nop
] = false;
1438 curr_alt_offmemok
[nop
] = false;
1439 curr_alt_matches
[nop
] = -1;
1443 op
= no_subreg_reg_operand
[nop
];
1444 mode
= curr_operand_mode
[nop
];
1446 win
= did_match
= winreg
= offmemok
= constmemok
= false;
1449 early_clobber_p
= false;
1450 p
= curr_static_id
->operand_alternative
[opalt_num
].constraint
;
1452 this_costly_alternative
= this_alternative
= NO_REGS
;
1453 /* We update set of possible hard regs besides its class
1454 because reg class might be inaccurate. For example,
1455 union of LO_REGS (l), HI_REGS(h), and STACK_REG(k) in ARM
1456 is translated in HI_REGS because classes are merged by
1457 pairs and there is no accurate intermediate class. */
1458 CLEAR_HARD_REG_SET (this_alternative_set
);
1459 CLEAR_HARD_REG_SET (this_costly_alternative_set
);
1460 this_alternative_win
= false;
1461 this_alternative_match_win
= false;
1462 this_alternative_offmemok
= false;
1463 this_alternative_matches
= -1;
1465 /* An empty constraint should be excluded by the fast
1467 lra_assert (*p
!= 0 && *p
!= ',');
1469 /* Scan this alternative's specs for this operand; set WIN
1470 if the operand fits any letter in this alternative.
1471 Otherwise, clear BADOP if this operand could fit some
1472 letter after reloads, or set WINREG if this operand could
1473 fit after reloads provided the constraint allows some
1478 switch ((c
= *p
, len
= CONSTRAINT_LEN (c
, p
)), c
)
1487 case '=': case '+': case '?': case '*': case '!':
1488 case ' ': case '\t':
1492 /* We only support one commutative marker, the first
1493 one. We already set commutative above. */
1497 early_clobber_p
= true;
1501 /* Ignore rest of this alternative. */
1505 case '0': case '1': case '2': case '3': case '4':
1506 case '5': case '6': case '7': case '8': case '9':
1511 m
= strtoul (p
, &end
, 10);
1514 lra_assert (nop
> m
);
1516 this_alternative_matches
= m
;
1517 m_hregno
= get_hard_regno (*curr_id
->operand_loc
[m
]);
1518 /* We are supposed to match a previous operand.
1519 If we do, we win if that one did. If we do
1520 not, count both of the operands as losers.
1521 (This is too conservative, since most of the
1522 time only a single reload insn will be needed
1523 to make the two operands win. As a result,
1524 this alternative may be rejected when it is
1525 actually desirable.) */
1527 if (operands_match_p (*curr_id
->operand_loc
[nop
],
1528 *curr_id
->operand_loc
[m
], m_hregno
))
1530 /* We should reject matching of an early
1531 clobber operand if the matching operand is
1532 not dying in the insn. */
1533 if (! curr_static_id
->operand
[m
].early_clobber
1534 || operand_reg
[nop
] == NULL_RTX
1535 || (find_regno_note (curr_insn
, REG_DEAD
,
1536 REGNO (operand_reg
[nop
]))
1542 /* If we are matching a non-offsettable
1543 address where an offsettable address was
1544 expected, then we must reject this
1545 combination, because we can't reload
1547 if (curr_alt_offmemok
[m
]
1548 && MEM_P (*curr_id
->operand_loc
[m
])
1549 && curr_alt
[m
] == NO_REGS
&& ! curr_alt_win
[m
])
1555 /* Operands don't match. Both operands must
1556 allow a reload register, otherwise we
1557 cannot make them match. */
1558 if (curr_alt
[m
] == NO_REGS
)
1560 /* Retroactively mark the operand we had to
1561 match as a loser, if it wasn't already and
1562 it wasn't matched to a register constraint
1563 (e.g it might be matched by memory). */
1565 && (operand_reg
[m
] == NULL_RTX
1566 || hard_regno
[m
] < 0))
1570 += (ira_reg_class_max_nregs
[curr_alt
[m
]]
1571 [GET_MODE (*curr_id
->operand_loc
[m
])]);
1574 /* We prefer no matching alternatives because
1575 it gives more freedom in RA. */
1576 if (operand_reg
[nop
] == NULL_RTX
1577 || (find_regno_note (curr_insn
, REG_DEAD
,
1578 REGNO (operand_reg
[nop
]))
1582 /* If we have to reload this operand and some
1583 previous operand also had to match the same
1584 thing as this operand, we don't know how to do
1586 if (!match_p
|| !curr_alt_win
[m
])
1588 for (i
= 0; i
< nop
; i
++)
1589 if (curr_alt_matches
[i
] == m
)
1597 /* This can be fixed with reloads if the operand
1598 we are supposed to match can be fixed with
1601 this_alternative
= curr_alt
[m
];
1602 COPY_HARD_REG_SET (this_alternative_set
, curr_alt_set
[m
]);
1603 winreg
= this_alternative
!= NO_REGS
;
1608 cl
= base_reg_class (VOIDmode
, ADDR_SPACE_GENERIC
,
1610 this_alternative
= reg_class_subunion
[this_alternative
][cl
];
1611 IOR_HARD_REG_SET (this_alternative_set
,
1612 reg_class_contents
[cl
]);
1615 this_costly_alternative
1616 = reg_class_subunion
[this_costly_alternative
][cl
];
1617 IOR_HARD_REG_SET (this_costly_alternative_set
,
1618 reg_class_contents
[cl
]);
1624 case TARGET_MEM_CONSTRAINT
:
1625 if (MEM_P (op
) || spilled_pseudo_p (op
))
1627 /* We can put constant or pseudo value into memory
1628 to satisfy the constraint. */
1629 if (CONST_POOL_OK_P (mode
, op
) || REG_P (op
))
1636 && (GET_CODE (XEXP (op
, 0)) == PRE_DEC
1637 || GET_CODE (XEXP (op
, 0)) == POST_DEC
))
1643 && (GET_CODE (XEXP (op
, 0)) == PRE_INC
1644 || GET_CODE (XEXP (op
, 0)) == POST_INC
))
1648 /* Memory op whose address is not offsettable. */
1651 && ! offsettable_nonstrict_memref_p (op
))
1655 /* Memory operand whose address is offsettable. */
1658 && offsettable_nonstrict_memref_p (op
))
1659 || spilled_pseudo_p (op
))
1661 /* We can put constant or pseudo value into memory
1662 or make memory address offsetable to satisfy the
1664 if (CONST_POOL_OK_P (mode
, op
) || MEM_P (op
) || REG_P (op
))
1672 if (GET_CODE (op
) == CONST_DOUBLE
1673 || (GET_CODE (op
) == CONST_VECTOR
1674 && (GET_MODE_CLASS (mode
) == MODE_VECTOR_FLOAT
)))
1680 if (GET_CODE (op
) == CONST_DOUBLE
1681 && CONST_DOUBLE_OK_FOR_CONSTRAINT_P (op
, c
, p
))
1686 if (CONST_INT_P (op
)
1687 || (GET_CODE (op
) == CONST_DOUBLE
&& mode
== VOIDmode
))
1691 if (general_constant_p (op
))
1696 if (CONST_INT_P (op
)
1697 || (GET_CODE (op
) == CONST_DOUBLE
&& mode
== VOIDmode
))
1709 if (CONST_INT_P (op
)
1710 && CONST_OK_FOR_CONSTRAINT_P (INTVAL (op
), c
, p
))
1715 /* This constraint should be excluded by the fast
1722 || general_constant_p (op
)
1723 || spilled_pseudo_p (op
))
1725 /* Drop through into 'r' case. */
1729 = reg_class_subunion
[this_alternative
][GENERAL_REGS
];
1730 IOR_HARD_REG_SET (this_alternative_set
,
1731 reg_class_contents
[GENERAL_REGS
]);
1734 this_costly_alternative
1735 = (reg_class_subunion
1736 [this_costly_alternative
][GENERAL_REGS
]);
1737 IOR_HARD_REG_SET (this_costly_alternative_set
,
1738 reg_class_contents
[GENERAL_REGS
]);
1743 if (REG_CLASS_FROM_CONSTRAINT (c
, p
) == NO_REGS
)
1745 #ifdef EXTRA_CONSTRAINT_STR
1746 if (EXTRA_MEMORY_CONSTRAINT (c
, p
))
1748 if (EXTRA_CONSTRAINT_STR (op
, c
, p
))
1750 else if (spilled_pseudo_p (op
))
1753 /* If we didn't already win, we can reload
1754 constants via force_const_mem or put the
1755 pseudo value into memory, or make other
1756 memory by reloading the address like for
1758 if (CONST_POOL_OK_P (mode
, op
)
1759 || MEM_P (op
) || REG_P (op
))
1765 if (EXTRA_ADDRESS_CONSTRAINT (c
, p
))
1767 if (EXTRA_CONSTRAINT_STR (op
, c
, p
))
1770 /* If we didn't already win, we can reload
1771 the address into a base register. */
1772 cl
= base_reg_class (VOIDmode
, ADDR_SPACE_GENERIC
,
1775 = reg_class_subunion
[this_alternative
][cl
];
1776 IOR_HARD_REG_SET (this_alternative_set
,
1777 reg_class_contents
[cl
]);
1780 this_costly_alternative
1781 = (reg_class_subunion
1782 [this_costly_alternative
][cl
]);
1783 IOR_HARD_REG_SET (this_costly_alternative_set
,
1784 reg_class_contents
[cl
]);
1790 if (EXTRA_CONSTRAINT_STR (op
, c
, p
))
1796 cl
= REG_CLASS_FROM_CONSTRAINT (c
, p
);
1797 this_alternative
= reg_class_subunion
[this_alternative
][cl
];
1798 IOR_HARD_REG_SET (this_alternative_set
,
1799 reg_class_contents
[cl
]);
1802 this_costly_alternative
1803 = reg_class_subunion
[this_costly_alternative
][cl
];
1804 IOR_HARD_REG_SET (this_costly_alternative_set
,
1805 reg_class_contents
[cl
]);
1808 if (mode
== BLKmode
)
1813 if (hard_regno
[nop
] >= 0
1814 && in_hard_reg_set_p (this_alternative_set
,
1815 mode
, hard_regno
[nop
]))
1817 else if (hard_regno
[nop
] < 0
1818 && in_class_p (op
, this_alternative
, NULL
))
1823 if (c
!= ' ' && c
!= '\t')
1824 costly_p
= c
== '*';
1826 while ((p
+= len
), c
);
1828 /* Record which operands fit this alternative. */
1831 this_alternative_win
= true;
1832 if (operand_reg
[nop
] != NULL_RTX
)
1834 if (hard_regno
[nop
] >= 0)
1836 if (in_hard_reg_set_p (this_costly_alternative_set
,
1837 mode
, hard_regno
[nop
]))
1842 /* Prefer won reg to spilled pseudo under other equal
1845 if (in_class_p (operand_reg
[nop
],
1846 this_costly_alternative
, NULL
))
1849 /* We simulate the behaviour of old reload here.
1850 Although scratches need hard registers and it
1851 might result in spilling other pseudos, no reload
1852 insns are generated for the scratches. So it
1853 might cost something but probably less than old
1854 reload pass believes. */
1855 if (lra_former_scratch_p (REGNO (operand_reg
[nop
])))
1856 reject
+= LRA_LOSER_COST_FACTOR
;
1860 this_alternative_match_win
= true;
1863 int const_to_mem
= 0;
1866 /* If this alternative asks for a specific reg class, see if there
1867 is at least one allocatable register in that class. */
1869 = (this_alternative
== NO_REGS
1870 || (hard_reg_set_subset_p
1871 (reg_class_contents
[this_alternative
],
1872 lra_no_alloc_regs
)));
1874 /* For asms, verify that the class for this alternative is possible
1875 for the mode that is specified. */
1876 if (!no_regs_p
&& REG_P (op
) && INSN_CODE (curr_insn
) < 0)
1879 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
1880 if (HARD_REGNO_MODE_OK (i
, mode
)
1881 && in_hard_reg_set_p (reg_class_contents
[this_alternative
], mode
, i
))
1883 if (i
== FIRST_PSEUDO_REGISTER
)
1887 /* If this operand accepts a register, and if the
1888 register class has at least one allocatable register,
1889 then this operand can be reloaded. */
1890 if (winreg
&& !no_regs_p
)
1896 this_alternative_offmemok
= offmemok
;
1897 if (this_costly_alternative
!= NO_REGS
)
1899 /* If the operand is dying, has a matching constraint,
1900 and satisfies constraints of the matched operand
1901 which failed to satisfy the own constraints, we do
1902 not need to generate a reload insn for this
1904 if (!(this_alternative_matches
>= 0
1905 && !curr_alt_win
[this_alternative_matches
]
1907 && find_regno_note (curr_insn
, REG_DEAD
, REGNO (op
))
1908 && (hard_regno
[nop
] >= 0
1909 ? in_hard_reg_set_p (this_alternative_set
,
1910 mode
, hard_regno
[nop
])
1911 : in_class_p (op
, this_alternative
, NULL
))))
1913 /* Strict_low_part requires to reload the register
1914 not the sub-register. In this case we should
1915 check that a final reload hard reg can hold the
1917 if (curr_static_id
->operand
[nop
].strict_low
1919 && hard_regno
[nop
] < 0
1920 && GET_CODE (*curr_id
->operand_loc
[nop
]) == SUBREG
1921 && ira_class_hard_regs_num
[this_alternative
] > 0
1922 && ! HARD_REGNO_MODE_OK (ira_class_hard_regs
1923 [this_alternative
][0],
1928 if (operand_reg
[nop
] != NULL_RTX
1929 /* Output operands and matched input operands are
1930 not inherited. The following conditions do not
1931 exactly describe the previous statement but they
1932 are pretty close. */
1933 && curr_static_id
->operand
[nop
].type
!= OP_OUT
1934 && (this_alternative_matches
< 0
1935 || curr_static_id
->operand
[nop
].type
!= OP_IN
))
1937 int last_reload
= (lra_reg_info
[ORIGINAL_REGNO
1941 if (last_reload
> bb_reload_num
)
1942 reload_sum
+= last_reload
- bb_reload_num
;
1944 /* If this is a constant that is reloaded into the
1945 desired class by copying it to memory first, count
1946 that as another reload. This is consistent with
1947 other code and is required to avoid choosing another
1948 alternative when the constant is moved into memory.
1949 Note that the test here is precisely the same as in
1950 the code below that calls force_const_mem. */
1951 if (CONST_POOL_OK_P (mode
, op
)
1952 && ((targetm
.preferred_reload_class
1953 (op
, this_alternative
) == NO_REGS
)
1954 || no_input_reloads_p
))
1961 /* Alternative loses if it requires a type of reload not
1962 permitted for this insn. We can always reload
1963 objects with a REG_UNUSED note. */
1964 if ((curr_static_id
->operand
[nop
].type
!= OP_IN
1965 && no_output_reloads_p
1966 && ! find_reg_note (curr_insn
, REG_UNUSED
, op
))
1967 || (curr_static_id
->operand
[nop
].type
!= OP_OUT
1968 && no_input_reloads_p
&& ! const_to_mem
))
1971 /* Check strong discouragement of reload of non-constant
1972 into class THIS_ALTERNATIVE. */
1973 if (! CONSTANT_P (op
) && ! no_regs_p
1974 && (targetm
.preferred_reload_class
1975 (op
, this_alternative
) == NO_REGS
1976 || (curr_static_id
->operand
[nop
].type
== OP_OUT
1977 && (targetm
.preferred_output_reload_class
1978 (op
, this_alternative
) == NO_REGS
))))
1979 reject
+= LRA_MAX_REJECT
;
1981 if (! ((const_to_mem
&& constmemok
)
1982 || (MEM_P (op
) && offmemok
)))
1984 /* We prefer to reload pseudos over reloading other
1985 things, since such reloads may be able to be
1986 eliminated later. So bump REJECT in other cases.
1987 Don't do this in the case where we are forcing a
1988 constant into memory and it will then win since
1989 we don't want to have a different alternative
1991 if (! (REG_P (op
) && REGNO (op
) >= FIRST_PSEUDO_REGISTER
))
1996 += ira_reg_class_max_nregs
[this_alternative
][mode
];
1999 /* We are trying to spill pseudo into memory. It is
2000 usually more costly than moving to a hard register
2001 although it might takes the same number of
2003 if (no_regs_p
&& REG_P (op
))
2006 #ifdef SECONDARY_MEMORY_NEEDED
2007 /* If reload requires moving value through secondary
2008 memory, it will need one more insn at least. */
2009 if (this_alternative
!= NO_REGS
2010 && REG_P (op
) && (cl
= get_reg_class (REGNO (op
))) != NO_REGS
2011 && ((curr_static_id
->operand
[nop
].type
!= OP_OUT
2012 && SECONDARY_MEMORY_NEEDED (cl
, this_alternative
,
2014 || (curr_static_id
->operand
[nop
].type
!= OP_IN
2015 && SECONDARY_MEMORY_NEEDED (this_alternative
, cl
,
2019 /* Input reloads can be inherited more often than output
2020 reloads can be removed, so penalize output
2022 if (!REG_P (op
) || curr_static_id
->operand
[nop
].type
!= OP_IN
)
2026 if (early_clobber_p
)
2028 /* ??? We check early clobbers after processing all operands
2029 (see loop below) and there we update the costs more.
2030 Should we update the cost (may be approximately) here
2031 because of early clobber register reloads or it is a rare
2032 or non-important thing to be worth to do it. */
2033 overall
= losers
* LRA_LOSER_COST_FACTOR
+ reject
;
2034 if ((best_losers
== 0 || losers
!= 0) && best_overall
< overall
)
2037 curr_alt
[nop
] = this_alternative
;
2038 COPY_HARD_REG_SET (curr_alt_set
[nop
], this_alternative_set
);
2039 curr_alt_win
[nop
] = this_alternative_win
;
2040 curr_alt_match_win
[nop
] = this_alternative_match_win
;
2041 curr_alt_offmemok
[nop
] = this_alternative_offmemok
;
2042 curr_alt_matches
[nop
] = this_alternative_matches
;
2044 if (this_alternative_matches
>= 0
2045 && !did_match
&& !this_alternative_win
)
2046 curr_alt_win
[this_alternative_matches
] = false;
2048 if (early_clobber_p
&& operand_reg
[nop
] != NULL_RTX
)
2049 early_clobbered_nops
[early_clobbered_regs_num
++] = nop
;
2052 curr_alt_dont_inherit_ops_num
= 0;
2053 for (nop
= 0; nop
< early_clobbered_regs_num
; nop
++)
2055 int i
, j
, clobbered_hard_regno
;
2056 HARD_REG_SET temp_set
;
2058 i
= early_clobbered_nops
[nop
];
2059 if ((! curr_alt_win
[i
] && ! curr_alt_match_win
[i
])
2060 || hard_regno
[i
] < 0)
2062 clobbered_hard_regno
= hard_regno
[i
];
2063 CLEAR_HARD_REG_SET (temp_set
);
2064 add_to_hard_reg_set (&temp_set
, biggest_mode
[i
], clobbered_hard_regno
);
2065 for (j
= 0; j
< n_operands
; j
++)
2067 /* We don't want process insides of match_operator and
2068 match_parallel because otherwise we would process
2069 their operands once again generating a wrong
2071 || curr_static_id
->operand
[j
].is_operator
)
2073 else if ((curr_alt_matches
[j
] == i
&& curr_alt_match_win
[j
])
2074 || (curr_alt_matches
[i
] == j
&& curr_alt_match_win
[i
]))
2076 else if (uses_hard_regs_p (*curr_id
->operand_loc
[j
], temp_set
))
2078 if (j
>= n_operands
)
2080 /* We need to reload early clobbered register. */
2081 for (j
= 0; j
< n_operands
; j
++)
2082 if (curr_alt_matches
[j
] == i
)
2084 curr_alt_match_win
[j
] = false;
2086 overall
+= LRA_LOSER_COST_FACTOR
;
2088 if (! curr_alt_match_win
[i
])
2089 curr_alt_dont_inherit_ops
[curr_alt_dont_inherit_ops_num
++] = i
;
2092 /* Remember pseudos used for match reloads are never
2094 lra_assert (curr_alt_matches
[i
] >= 0);
2095 curr_alt_win
[curr_alt_matches
[i
]] = false;
2097 curr_alt_win
[i
] = curr_alt_match_win
[i
] = false;
2099 overall
+= LRA_LOSER_COST_FACTOR
;
2101 small_class_operands_num
= 0;
2102 for (nop
= 0; nop
< n_operands
; nop
++)
2103 small_class_operands_num
2104 += SMALL_REGISTER_CLASS_P (curr_alt
[nop
]) ? 1 : 0;
2106 /* If this alternative can be made to work by reloading, and it
2107 needs less reloading than the others checked so far, record
2108 it as the chosen goal for reloading. */
2109 if ((best_losers
!= 0 && losers
== 0)
2110 || (((best_losers
== 0 && losers
== 0)
2111 || (best_losers
!= 0 && losers
!= 0))
2112 && (best_overall
> overall
2113 || (best_overall
== overall
2114 /* If the cost of the reloads is the same,
2115 prefer alternative which requires minimal
2116 number of small register classes for the
2117 operands. This improves chances of reloads
2118 for insn requiring small register
2120 && (small_class_operands_num
2121 < best_small_class_operands_num
2122 || (small_class_operands_num
2123 == best_small_class_operands_num
2124 && (reload_nregs
< best_reload_nregs
2125 || (reload_nregs
== best_reload_nregs
2126 && best_reload_sum
< reload_sum
))))))))
2128 for (nop
= 0; nop
< n_operands
; nop
++)
2130 goal_alt_win
[nop
] = curr_alt_win
[nop
];
2131 goal_alt_match_win
[nop
] = curr_alt_match_win
[nop
];
2132 goal_alt_matches
[nop
] = curr_alt_matches
[nop
];
2133 goal_alt
[nop
] = curr_alt
[nop
];
2134 goal_alt_offmemok
[nop
] = curr_alt_offmemok
[nop
];
2136 goal_alt_dont_inherit_ops_num
= curr_alt_dont_inherit_ops_num
;
2137 for (nop
= 0; nop
< curr_alt_dont_inherit_ops_num
; nop
++)
2138 goal_alt_dont_inherit_ops
[nop
] = curr_alt_dont_inherit_ops
[nop
];
2139 goal_alt_swapped
= curr_swapped
;
2140 best_overall
= overall
;
2141 best_losers
= losers
;
2142 best_small_class_operands_num
= small_class_operands_num
;
2143 best_reload_nregs
= reload_nregs
;
2144 best_reload_sum
= reload_sum
;
2145 goal_alt_number
= nalt
;
2148 /* Everything is satisfied. Do not process alternatives
2157 /* Return 1 if ADDR is a valid memory address for mode MODE in address
2158 space AS, and check that each pseudo has the proper kind of hard
2161 valid_address_p (enum machine_mode mode ATTRIBUTE_UNUSED
,
2162 rtx addr
, addr_space_t as
)
2164 #ifdef GO_IF_LEGITIMATE_ADDRESS
2165 lra_assert (ADDR_SPACE_GENERIC_P (as
));
2166 GO_IF_LEGITIMATE_ADDRESS (mode
, addr
, win
);
2172 return targetm
.addr_space
.legitimate_address_p (mode
, addr
, 0, as
);
2176 /* Return whether address AD is valid. */
2179 valid_address_p (struct address_info
*ad
)
2181 /* Some ports do not check displacements for eliminable registers,
2182 so we replace them temporarily with the elimination target. */
2183 rtx saved_base_reg
= NULL_RTX
;
2184 rtx saved_index_reg
= NULL_RTX
;
2185 rtx
*base_term
= strip_subreg (ad
->base_term
);
2186 rtx
*index_term
= strip_subreg (ad
->index_term
);
2187 if (base_term
!= NULL
)
2189 saved_base_reg
= *base_term
;
2190 lra_eliminate_reg_if_possible (base_term
);
2191 if (ad
->base_term2
!= NULL
)
2192 *ad
->base_term2
= *ad
->base_term
;
2194 if (index_term
!= NULL
)
2196 saved_index_reg
= *index_term
;
2197 lra_eliminate_reg_if_possible (index_term
);
2199 bool ok_p
= valid_address_p (ad
->mode
, *ad
->outer
, ad
->as
);
2200 if (saved_base_reg
!= NULL_RTX
)
2202 *base_term
= saved_base_reg
;
2203 if (ad
->base_term2
!= NULL
)
2204 *ad
->base_term2
= *ad
->base_term
;
2206 if (saved_index_reg
!= NULL_RTX
)
2207 *index_term
= saved_index_reg
;
2211 /* Make reload base reg + disp from address AD. Return the new pseudo. */
2213 base_plus_disp_to_reg (struct address_info
*ad
)
2218 lra_assert (ad
->base
== ad
->base_term
&& ad
->disp
== ad
->disp_term
);
2219 cl
= base_reg_class (ad
->mode
, ad
->as
, ad
->base_outer_code
,
2220 get_index_code (ad
));
2221 new_reg
= lra_create_new_reg (GET_MODE (*ad
->base_term
), NULL_RTX
,
2223 lra_emit_add (new_reg
, *ad
->base_term
, *ad
->disp_term
);
2227 /* Return true if we can add a displacement to address AD, even if that
2228 makes the address invalid. The fix-up code requires any new address
2229 to be the sum of the BASE_TERM, INDEX and DISP_TERM fields. */
2231 can_add_disp_p (struct address_info
*ad
)
2233 return (!ad
->autoinc_p
2234 && ad
->segment
== NULL
2235 && ad
->base
== ad
->base_term
2236 && ad
->disp
== ad
->disp_term
);
2239 /* Make equiv substitution in address AD. Return true if a substitution
2242 equiv_address_substitution (struct address_info
*ad
)
2244 rtx base_reg
, new_base_reg
, index_reg
, new_index_reg
, *base_term
, *index_term
;
2245 HOST_WIDE_INT disp
, scale
;
2248 base_term
= strip_subreg (ad
->base_term
);
2249 if (base_term
== NULL
)
2250 base_reg
= new_base_reg
= NULL_RTX
;
2253 base_reg
= *base_term
;
2254 new_base_reg
= get_equiv_substitution (base_reg
);
2256 index_term
= strip_subreg (ad
->index_term
);
2257 if (index_term
== NULL
)
2258 index_reg
= new_index_reg
= NULL_RTX
;
2261 index_reg
= *index_term
;
2262 new_index_reg
= get_equiv_substitution (index_reg
);
2264 if (base_reg
== new_base_reg
&& index_reg
== new_index_reg
)
2268 if (lra_dump_file
!= NULL
)
2270 fprintf (lra_dump_file
, "Changing address in insn %d ",
2271 INSN_UID (curr_insn
));
2272 dump_value_slim (lra_dump_file
, *ad
->outer
, 1);
2274 if (base_reg
!= new_base_reg
)
2276 if (REG_P (new_base_reg
))
2278 *base_term
= new_base_reg
;
2281 else if (GET_CODE (new_base_reg
) == PLUS
2282 && REG_P (XEXP (new_base_reg
, 0))
2283 && CONST_INT_P (XEXP (new_base_reg
, 1))
2284 && can_add_disp_p (ad
))
2286 disp
+= INTVAL (XEXP (new_base_reg
, 1));
2287 *base_term
= XEXP (new_base_reg
, 0);
2290 if (ad
->base_term2
!= NULL
)
2291 *ad
->base_term2
= *ad
->base_term
;
2293 if (index_reg
!= new_index_reg
)
2295 if (REG_P (new_index_reg
))
2297 *index_term
= new_index_reg
;
2300 else if (GET_CODE (new_index_reg
) == PLUS
2301 && REG_P (XEXP (new_index_reg
, 0))
2302 && CONST_INT_P (XEXP (new_index_reg
, 1))
2303 && can_add_disp_p (ad
)
2304 && (scale
= get_index_scale (ad
)))
2306 disp
+= INTVAL (XEXP (new_index_reg
, 1)) * scale
;
2307 *index_term
= XEXP (new_index_reg
, 0);
2313 if (ad
->disp
!= NULL
)
2314 *ad
->disp
= plus_constant (GET_MODE (*ad
->inner
), *ad
->disp
, disp
);
2317 *ad
->inner
= plus_constant (GET_MODE (*ad
->inner
), *ad
->inner
, disp
);
2318 update_address (ad
);
2322 if (lra_dump_file
!= NULL
)
2325 fprintf (lra_dump_file
, " -- no change\n");
2328 fprintf (lra_dump_file
, " on equiv ");
2329 dump_value_slim (lra_dump_file
, *ad
->outer
, 1);
2330 fprintf (lra_dump_file
, "\n");
2336 /* Major function to make reloads for an address in operand NOP.
2337 The supported cases are:
2339 1) an address that existed before LRA started, at which point it must
2340 have been valid. These addresses are subject to elimination and
2341 may have become invalid due to the elimination offset being out
2344 2) an address created by forcing a constant to memory (force_const_to_mem).
2345 The initial form of these addresses might not be valid, and it is this
2346 function's job to make them valid.
2348 3) a frame address formed from a register and a (possibly zero)
2349 constant offset. As above, these addresses might not be valid
2350 and this function must make them so.
2352 Add reloads to the lists *BEFORE and *AFTER. We might need to add
2353 reloads to *AFTER because of inc/dec, {pre, post} modify in the
2354 address. Return true for any RTL change. */
2356 process_address (int nop
, rtx
*before
, rtx
*after
)
2358 struct address_info ad
;
2360 rtx op
= *curr_id
->operand_loc
[nop
];
2361 const char *constraint
= curr_static_id
->operand
[nop
].constraint
;
2364 if (constraint
[0] == 'p'
2365 || EXTRA_ADDRESS_CONSTRAINT (constraint
[0], constraint
))
2366 decompose_lea_address (&ad
, curr_id
->operand_loc
[nop
]);
2367 else if (MEM_P (op
))
2368 decompose_mem_address (&ad
, op
);
2369 else if (GET_CODE (op
) == SUBREG
2370 && MEM_P (SUBREG_REG (op
)))
2371 decompose_mem_address (&ad
, SUBREG_REG (op
));
2374 change_p
= equiv_address_substitution (&ad
);
2375 if (ad
.base_term
!= NULL
2376 && (process_addr_reg
2377 (ad
.base_term
, before
,
2379 && !(REG_P (*ad
.base_term
)
2380 && find_regno_note (curr_insn
, REG_DEAD
,
2381 REGNO (*ad
.base_term
)) != NULL_RTX
)
2383 base_reg_class (ad
.mode
, ad
.as
, ad
.base_outer_code
,
2384 get_index_code (&ad
)))))
2387 if (ad
.base_term2
!= NULL
)
2388 *ad
.base_term2
= *ad
.base_term
;
2390 if (ad
.index_term
!= NULL
2391 && process_addr_reg (ad
.index_term
, before
, NULL
, INDEX_REG_CLASS
))
2394 /* There are three cases where the shape of *AD.INNER may now be invalid:
2396 1) the original address was valid, but either elimination or
2397 equiv_address_substitution applied a displacement that made
2400 2) the address is an invalid symbolic address created by
2403 3) the address is a frame address with an invalid offset.
2405 All these cases involve a displacement and a non-autoinc address,
2406 so there is no point revalidating other types. */
2407 if (ad
.disp
== NULL
|| ad
.autoinc_p
|| valid_address_p (&ad
))
2410 /* Any index existed before LRA started, so we can assume that the
2411 presence and shape of the index is valid. */
2412 push_to_sequence (*before
);
2413 gcc_assert (ad
.segment
== NULL
);
2414 gcc_assert (ad
.disp
== ad
.disp_term
);
2415 if (ad
.base
== NULL
)
2417 if (ad
.index
== NULL
)
2420 enum reg_class cl
= base_reg_class (ad
.mode
, ad
.as
,
2422 rtx disp
= *ad
.disp
;
2424 new_reg
= lra_create_new_reg (Pmode
, NULL_RTX
, cl
, "disp");
2428 rtx last
= get_last_insn ();
2430 /* disp => lo_sum (new_base, disp), case (2) above. */
2431 insn
= emit_insn (gen_rtx_SET
2433 gen_rtx_HIGH (Pmode
, copy_rtx (disp
))));
2434 code
= recog_memoized (insn
);
2437 *ad
.disp
= gen_rtx_LO_SUM (Pmode
, new_reg
, disp
);
2438 if (! valid_address_p (ad
.mode
, *ad
.outer
, ad
.as
))
2445 delete_insns_since (last
);
2450 /* disp => new_base, case (2) above. */
2451 lra_emit_move (new_reg
, disp
);
2457 /* index * scale + disp => new base + index * scale,
2459 enum reg_class cl
= base_reg_class (ad
.mode
, ad
.as
, PLUS
,
2460 GET_CODE (*ad
.index
));
2462 lra_assert (INDEX_REG_CLASS
!= NO_REGS
);
2463 new_reg
= lra_create_new_reg (Pmode
, NULL_RTX
, cl
, "disp");
2464 lra_emit_move (new_reg
, *ad
.disp
);
2465 *ad
.inner
= simplify_gen_binary (PLUS
, GET_MODE (new_reg
),
2466 new_reg
, *ad
.index
);
2469 else if (ad
.index
== NULL
)
2471 /* base + disp => new base, cases (1) and (3) above. */
2472 /* Another option would be to reload the displacement into an
2473 index register. However, postreload has code to optimize
2474 address reloads that have the same base and different
2475 displacements, so reloading into an index register would
2476 not necessarily be a win. */
2477 new_reg
= base_plus_disp_to_reg (&ad
);
2478 *ad
.inner
= new_reg
;
2482 /* base + scale * index + disp => new base + scale * index,
2484 new_reg
= base_plus_disp_to_reg (&ad
);
2485 *ad
.inner
= simplify_gen_binary (PLUS
, GET_MODE (new_reg
),
2486 new_reg
, *ad
.index
);
2488 *before
= get_insns ();
2493 /* Emit insns to reload VALUE into a new register. VALUE is an
2494 auto-increment or auto-decrement RTX whose operand is a register or
2495 memory location; so reloading involves incrementing that location.
2496 IN is either identical to VALUE, or some cheaper place to reload
2497 value being incremented/decremented from.
2499 INC_AMOUNT is the number to increment or decrement by (always
2500 positive and ignored for POST_MODIFY/PRE_MODIFY).
2502 Return pseudo containing the result. */
2504 emit_inc (enum reg_class new_rclass
, rtx in
, rtx value
, int inc_amount
)
2506 /* REG or MEM to be copied and incremented. */
2507 rtx incloc
= XEXP (value
, 0);
2508 /* Nonzero if increment after copying. */
2509 int post
= (GET_CODE (value
) == POST_DEC
|| GET_CODE (value
) == POST_INC
2510 || GET_CODE (value
) == POST_MODIFY
);
2515 rtx real_in
= in
== value
? incloc
: in
;
2519 if (GET_CODE (value
) == PRE_MODIFY
|| GET_CODE (value
) == POST_MODIFY
)
2521 lra_assert (GET_CODE (XEXP (value
, 1)) == PLUS
2522 || GET_CODE (XEXP (value
, 1)) == MINUS
);
2523 lra_assert (rtx_equal_p (XEXP (XEXP (value
, 1), 0), XEXP (value
, 0)));
2524 plus_p
= GET_CODE (XEXP (value
, 1)) == PLUS
;
2525 inc
= XEXP (XEXP (value
, 1), 1);
2529 if (GET_CODE (value
) == PRE_DEC
|| GET_CODE (value
) == POST_DEC
)
2530 inc_amount
= -inc_amount
;
2532 inc
= GEN_INT (inc_amount
);
2535 if (! post
&& REG_P (incloc
))
2538 result
= lra_create_new_reg (GET_MODE (value
), value
, new_rclass
,
2541 if (real_in
!= result
)
2543 /* First copy the location to the result register. */
2544 lra_assert (REG_P (result
));
2545 emit_insn (gen_move_insn (result
, real_in
));
2548 /* We suppose that there are insns to add/sub with the constant
2549 increment permitted in {PRE/POST)_{DEC/INC/MODIFY}. At least the
2550 old reload worked with this assumption. If the assumption
2551 becomes wrong, we should use approach in function
2552 base_plus_disp_to_reg. */
2555 /* See if we can directly increment INCLOC. */
2556 last
= get_last_insn ();
2557 add_insn
= emit_insn (plus_p
2558 ? gen_add2_insn (incloc
, inc
)
2559 : gen_sub2_insn (incloc
, inc
));
2561 code
= recog_memoized (add_insn
);
2564 if (! post
&& result
!= incloc
)
2565 emit_insn (gen_move_insn (result
, incloc
));
2568 delete_insns_since (last
);
2571 /* If couldn't do the increment directly, must increment in RESULT.
2572 The way we do this depends on whether this is pre- or
2573 post-increment. For pre-increment, copy INCLOC to the reload
2574 register, increment it there, then save back. */
2577 if (real_in
!= result
)
2578 emit_insn (gen_move_insn (result
, real_in
));
2580 emit_insn (gen_add2_insn (result
, inc
));
2582 emit_insn (gen_sub2_insn (result
, inc
));
2583 if (result
!= incloc
)
2584 emit_insn (gen_move_insn (incloc
, result
));
2590 Because this might be a jump insn or a compare, and because
2591 RESULT may not be available after the insn in an input
2592 reload, we must do the incrementing before the insn being
2595 We have already copied IN to RESULT. Increment the copy in
2596 RESULT, save that back, then decrement RESULT so it has
2597 the original value. */
2599 emit_insn (gen_add2_insn (result
, inc
));
2601 emit_insn (gen_sub2_insn (result
, inc
));
2602 emit_insn (gen_move_insn (incloc
, result
));
2603 /* Restore non-modified value for the result. We prefer this
2604 way because it does not require an additional hard
2608 if (CONST_INT_P (inc
))
2609 emit_insn (gen_add2_insn (result
, GEN_INT (-INTVAL (inc
))));
2611 emit_insn (gen_sub2_insn (result
, inc
));
2614 emit_insn (gen_add2_insn (result
, inc
));
2619 /* Swap operands NOP and NOP + 1. */
2621 swap_operands (int nop
)
2623 enum machine_mode mode
= curr_operand_mode
[nop
];
2624 curr_operand_mode
[nop
] = curr_operand_mode
[nop
+ 1];
2625 curr_operand_mode
[nop
+ 1] = mode
;
2626 rtx x
= *curr_id
->operand_loc
[nop
];
2627 *curr_id
->operand_loc
[nop
] = *curr_id
->operand_loc
[nop
+ 1];
2628 *curr_id
->operand_loc
[nop
+ 1] = x
;
2629 /* Swap the duplicates too. */
2630 lra_update_dup (curr_id
, nop
);
2631 lra_update_dup (curr_id
, nop
+ 1);
2634 /* Main entry point of the constraint code: search the body of the
2635 current insn to choose the best alternative. It is mimicking insn
2636 alternative cost calculation model of former reload pass. That is
2637 because machine descriptions were written to use this model. This
2638 model can be changed in future. Make commutative operand exchange
2641 Return true if some RTL changes happened during function call. */
2643 curr_insn_transform (void)
2649 signed char goal_alt_matched
[MAX_RECOG_OPERANDS
][MAX_RECOG_OPERANDS
];
2650 signed char match_inputs
[MAX_RECOG_OPERANDS
+ 1];
2653 /* Flag that the insn has been changed through a transformation. */
2656 #ifdef SECONDARY_MEMORY_NEEDED
2659 int max_regno_before
;
2660 int reused_alternative_num
;
2662 no_input_reloads_p
= no_output_reloads_p
= false;
2663 goal_alt_number
= -1;
2665 if (check_and_process_move (&change_p
, &sec_mem_p
))
2668 /* JUMP_INSNs and CALL_INSNs are not allowed to have any output
2669 reloads; neither are insns that SET cc0. Insns that use CC0 are
2670 not allowed to have any input reloads. */
2671 if (JUMP_P (curr_insn
) || CALL_P (curr_insn
))
2672 no_output_reloads_p
= true;
2675 if (reg_referenced_p (cc0_rtx
, PATTERN (curr_insn
)))
2676 no_input_reloads_p
= true;
2677 if (reg_set_p (cc0_rtx
, PATTERN (curr_insn
)))
2678 no_output_reloads_p
= true;
2681 n_operands
= curr_static_id
->n_operands
;
2682 n_alternatives
= curr_static_id
->n_alternatives
;
2684 /* Just return "no reloads" if insn has no operands with
2686 if (n_operands
== 0 || n_alternatives
== 0)
2689 max_regno_before
= max_reg_num ();
2691 for (i
= 0; i
< n_operands
; i
++)
2693 goal_alt_matched
[i
][0] = -1;
2694 goal_alt_matches
[i
] = -1;
2697 commutative
= curr_static_id
->commutative
;
2699 /* Now see what we need for pseudos that didn't get hard regs or got
2700 the wrong kind of hard reg. For this, we must consider all the
2701 operands together against the register constraints. */
2703 best_losers
= best_overall
= INT_MAX
;
2704 best_small_class_operands_num
= best_reload_sum
= 0;
2706 curr_swapped
= false;
2707 goal_alt_swapped
= false;
2709 /* Make equivalence substitution and memory subreg elimination
2710 before address processing because an address legitimacy can
2711 depend on memory mode. */
2712 for (i
= 0; i
< n_operands
; i
++)
2714 rtx op
= *curr_id
->operand_loc
[i
];
2715 rtx subst
, old
= op
;
2716 bool op_change_p
= false;
2718 if (GET_CODE (old
) == SUBREG
)
2719 old
= SUBREG_REG (old
);
2720 subst
= get_equiv_substitution (old
);
2723 subst
= copy_rtx (subst
);
2724 lra_assert (REG_P (old
));
2725 if (GET_CODE (op
) == SUBREG
)
2726 SUBREG_REG (op
) = subst
;
2728 *curr_id
->operand_loc
[i
] = subst
;
2729 if (lra_dump_file
!= NULL
)
2731 fprintf (lra_dump_file
,
2732 "Changing pseudo %d in operand %i of insn %u on equiv ",
2733 REGNO (old
), i
, INSN_UID (curr_insn
));
2734 dump_value_slim (lra_dump_file
, subst
, 1);
2735 fprintf (lra_dump_file
, "\n");
2737 op_change_p
= change_p
= true;
2739 if (simplify_operand_subreg (i
, GET_MODE (old
)) || op_change_p
)
2742 lra_update_dup (curr_id
, i
);
2746 /* Reload address registers and displacements. We do it before
2747 finding an alternative because of memory constraints. */
2748 before
= after
= NULL_RTX
;
2749 for (i
= 0; i
< n_operands
; i
++)
2750 if (! curr_static_id
->operand
[i
].is_operator
2751 && process_address (i
, &before
, &after
))
2754 lra_update_dup (curr_id
, i
);
2758 /* If we've changed the instruction then any alternative that
2759 we chose previously may no longer be valid. */
2760 lra_set_used_insn_alternative (curr_insn
, -1);
2764 reused_alternative_num
= curr_id
->used_insn_alternative
;
2765 if (lra_dump_file
!= NULL
&& reused_alternative_num
>= 0)
2766 fprintf (lra_dump_file
, "Reusing alternative %d for insn #%u\n",
2767 reused_alternative_num
, INSN_UID (curr_insn
));
2769 if (process_alt_operands (reused_alternative_num
))
2772 /* If insn is commutative (it's safe to exchange a certain pair of
2773 operands) then we need to try each alternative twice, the second
2774 time matching those two operands as if we had exchanged them. To
2775 do this, really exchange them in operands.
2777 If we have just tried the alternatives the second time, return
2778 operands to normal and drop through. */
2780 if (reused_alternative_num
< 0 && commutative
>= 0)
2782 curr_swapped
= !curr_swapped
;
2785 swap_operands (commutative
);
2789 swap_operands (commutative
);
2792 if (! alt_p
&& ! sec_mem_p
)
2794 /* No alternative works with reloads?? */
2795 if (INSN_CODE (curr_insn
) >= 0)
2796 fatal_insn ("unable to generate reloads for:", curr_insn
);
2797 error_for_asm (curr_insn
,
2798 "inconsistent operand constraints in an %<asm%>");
2799 /* Avoid further trouble with this insn. */
2800 PATTERN (curr_insn
) = gen_rtx_USE (VOIDmode
, const0_rtx
);
2801 lra_invalidate_insn_data (curr_insn
);
2805 /* If the best alternative is with operands 1 and 2 swapped, swap
2806 them. Update the operand numbers of any reloads already
2809 if (goal_alt_swapped
)
2811 if (lra_dump_file
!= NULL
)
2812 fprintf (lra_dump_file
, " Commutative operand exchange in insn %u\n",
2813 INSN_UID (curr_insn
));
2815 /* Swap the duplicates too. */
2816 swap_operands (commutative
);
2820 #ifdef SECONDARY_MEMORY_NEEDED
2821 /* Some target macros SECONDARY_MEMORY_NEEDED (e.g. x86) are defined
2822 too conservatively. So we use the secondary memory only if there
2823 is no any alternative without reloads. */
2824 use_sec_mem_p
= false;
2826 use_sec_mem_p
= true;
2829 for (i
= 0; i
< n_operands
; i
++)
2830 if (! goal_alt_win
[i
] && ! goal_alt_match_win
[i
])
2832 use_sec_mem_p
= i
< n_operands
;
2837 rtx new_reg
, src
, dest
, rld
;
2838 enum machine_mode sec_mode
, rld_mode
;
2840 lra_assert (sec_mem_p
);
2841 lra_assert (curr_static_id
->operand
[0].type
== OP_OUT
2842 && curr_static_id
->operand
[1].type
== OP_IN
);
2843 dest
= *curr_id
->operand_loc
[0];
2844 src
= *curr_id
->operand_loc
[1];
2845 rld
= (GET_MODE_SIZE (GET_MODE (dest
)) <= GET_MODE_SIZE (GET_MODE (src
))
2847 rld_mode
= GET_MODE (rld
);
2848 #ifdef SECONDARY_MEMORY_NEEDED_MODE
2849 sec_mode
= SECONDARY_MEMORY_NEEDED_MODE (rld_mode
);
2851 sec_mode
= rld_mode
;
2853 new_reg
= lra_create_new_reg (sec_mode
, NULL_RTX
,
2854 NO_REGS
, "secondary");
2855 /* If the mode is changed, it should be wider. */
2856 lra_assert (GET_MODE_SIZE (sec_mode
) >= GET_MODE_SIZE (rld_mode
));
2857 if (sec_mode
!= rld_mode
)
2859 /* If the target says specifically to use another mode for
2860 secondary memory moves we can not reuse the original
2862 after
= emit_spill_move (false, new_reg
, dest
);
2863 lra_process_new_insns (curr_insn
, NULL_RTX
, after
,
2864 "Inserting the sec. move");
2865 before
= emit_spill_move (true, new_reg
, src
);
2866 lra_process_new_insns (curr_insn
, before
, NULL_RTX
, "Changing on");
2867 lra_set_insn_deleted (curr_insn
);
2869 else if (dest
== rld
)
2871 *curr_id
->operand_loc
[0] = new_reg
;
2872 after
= emit_spill_move (false, new_reg
, dest
);
2873 lra_process_new_insns (curr_insn
, NULL_RTX
, after
,
2874 "Inserting the sec. move");
2878 *curr_id
->operand_loc
[1] = new_reg
;
2879 before
= emit_spill_move (true, new_reg
, src
);
2880 lra_process_new_insns (curr_insn
, before
, NULL_RTX
,
2881 "Inserting the sec. move");
2883 lra_update_insn_regno_info (curr_insn
);
2888 lra_assert (goal_alt_number
>= 0);
2889 lra_set_used_insn_alternative (curr_insn
, goal_alt_number
);
2891 if (lra_dump_file
!= NULL
)
2895 fprintf (lra_dump_file
, " Choosing alt %d in insn %u:",
2896 goal_alt_number
, INSN_UID (curr_insn
));
2897 for (i
= 0; i
< n_operands
; i
++)
2899 p
= (curr_static_id
->operand_alternative
2900 [goal_alt_number
* n_operands
+ i
].constraint
);
2903 fprintf (lra_dump_file
, " (%d) ", i
);
2904 for (; *p
!= '\0' && *p
!= ',' && *p
!= '#'; p
++)
2905 fputc (*p
, lra_dump_file
);
2907 fprintf (lra_dump_file
, "\n");
2910 /* Right now, for any pair of operands I and J that are required to
2911 match, with J < I, goal_alt_matches[I] is J. Add I to
2912 goal_alt_matched[J]. */
2914 for (i
= 0; i
< n_operands
; i
++)
2915 if ((j
= goal_alt_matches
[i
]) >= 0)
2917 for (k
= 0; goal_alt_matched
[j
][k
] >= 0; k
++)
2919 /* We allow matching one output operand and several input
2922 || (curr_static_id
->operand
[j
].type
== OP_OUT
2923 && curr_static_id
->operand
[i
].type
== OP_IN
2924 && (curr_static_id
->operand
2925 [goal_alt_matched
[j
][0]].type
== OP_IN
)));
2926 goal_alt_matched
[j
][k
] = i
;
2927 goal_alt_matched
[j
][k
+ 1] = -1;
2930 for (i
= 0; i
< n_operands
; i
++)
2931 goal_alt_win
[i
] |= goal_alt_match_win
[i
];
2933 /* Any constants that aren't allowed and can't be reloaded into
2934 registers are here changed into memory references. */
2935 for (i
= 0; i
< n_operands
; i
++)
2936 if (goal_alt_win
[i
])
2939 enum reg_class new_class
;
2940 rtx reg
= *curr_id
->operand_loc
[i
];
2942 if (GET_CODE (reg
) == SUBREG
)
2943 reg
= SUBREG_REG (reg
);
2945 if (REG_P (reg
) && (regno
= REGNO (reg
)) >= FIRST_PSEUDO_REGISTER
)
2947 bool ok_p
= in_class_p (reg
, goal_alt
[i
], &new_class
);
2949 if (new_class
!= NO_REGS
&& get_reg_class (regno
) != new_class
)
2952 change_class (regno
, new_class
, " Change", true);
2958 const char *constraint
;
2960 rtx op
= *curr_id
->operand_loc
[i
];
2961 rtx subreg
= NULL_RTX
;
2962 enum machine_mode mode
= curr_operand_mode
[i
];
2964 if (GET_CODE (op
) == SUBREG
)
2967 op
= SUBREG_REG (op
);
2968 mode
= GET_MODE (op
);
2971 if (CONST_POOL_OK_P (mode
, op
)
2972 && ((targetm
.preferred_reload_class
2973 (op
, (enum reg_class
) goal_alt
[i
]) == NO_REGS
)
2974 || no_input_reloads_p
))
2976 rtx tem
= force_const_mem (mode
, op
);
2979 if (subreg
!= NULL_RTX
)
2980 tem
= gen_rtx_SUBREG (mode
, tem
, SUBREG_BYTE (subreg
));
2982 *curr_id
->operand_loc
[i
] = tem
;
2983 lra_update_dup (curr_id
, i
);
2984 process_address (i
, &before
, &after
);
2986 /* If the alternative accepts constant pool refs directly
2987 there will be no reload needed at all. */
2988 if (subreg
!= NULL_RTX
)
2990 /* Skip alternatives before the one requested. */
2991 constraint
= (curr_static_id
->operand_alternative
2992 [goal_alt_number
* n_operands
+ i
].constraint
);
2994 (c
= *constraint
) && c
!= ',' && c
!= '#';
2995 constraint
+= CONSTRAINT_LEN (c
, constraint
))
2997 if (c
== TARGET_MEM_CONSTRAINT
|| c
== 'o')
2999 #ifdef EXTRA_CONSTRAINT_STR
3000 if (EXTRA_MEMORY_CONSTRAINT (c
, constraint
)
3001 && EXTRA_CONSTRAINT_STR (tem
, c
, constraint
))
3005 if (c
== '\0' || c
== ',' || c
== '#')
3008 goal_alt_win
[i
] = true;
3012 for (i
= 0; i
< n_operands
; i
++)
3015 rtx op
= *curr_id
->operand_loc
[i
];
3017 if (goal_alt_win
[i
])
3019 if (goal_alt
[i
] == NO_REGS
3021 /* When we assign NO_REGS it means that we will not
3022 assign a hard register to the scratch pseudo by
3023 assigment pass and the scratch pseudo will be
3024 spilled. Spilled scratch pseudos are transformed
3025 back to scratches at the LRA end. */
3026 && lra_former_scratch_operand_p (curr_insn
, i
))
3027 change_class (REGNO (op
), NO_REGS
, " Change", true);
3031 /* Operands that match previous ones have already been handled. */
3032 if (goal_alt_matches
[i
] >= 0)
3035 /* We should not have an operand with a non-offsettable address
3036 appearing where an offsettable address will do. It also may
3037 be a case when the address should be special in other words
3038 not a general one (e.g. it needs no index reg). */
3039 if (goal_alt_matched
[i
][0] == -1 && goal_alt_offmemok
[i
] && MEM_P (op
))
3041 enum reg_class rclass
;
3042 rtx
*loc
= &XEXP (op
, 0);
3043 enum rtx_code code
= GET_CODE (*loc
);
3045 push_to_sequence (before
);
3046 rclass
= base_reg_class (GET_MODE (op
), MEM_ADDR_SPACE (op
),
3048 if (GET_RTX_CLASS (code
) == RTX_AUTOINC
)
3049 new_reg
= emit_inc (rclass
, *loc
, *loc
,
3050 /* This value does not matter for MODIFY. */
3051 GET_MODE_SIZE (GET_MODE (op
)));
3052 else if (get_reload_reg (OP_IN
, Pmode
, *loc
, rclass
,
3053 "offsetable address", &new_reg
))
3054 lra_emit_move (new_reg
, *loc
);
3055 before
= get_insns ();
3058 lra_update_dup (curr_id
, i
);
3060 else if (goal_alt_matched
[i
][0] == -1)
3062 enum machine_mode mode
;
3064 int hard_regno
, byte
;
3065 enum op_type type
= curr_static_id
->operand
[i
].type
;
3067 loc
= curr_id
->operand_loc
[i
];
3068 mode
= curr_operand_mode
[i
];
3069 if (GET_CODE (*loc
) == SUBREG
)
3071 reg
= SUBREG_REG (*loc
);
3072 byte
= SUBREG_BYTE (*loc
);
3074 /* Strict_low_part requires reload the register not
3075 the sub-register. */
3076 && (curr_static_id
->operand
[i
].strict_low
3077 || (GET_MODE_SIZE (mode
)
3078 <= GET_MODE_SIZE (GET_MODE (reg
))
3080 = get_try_hard_regno (REGNO (reg
))) >= 0
3081 && (simplify_subreg_regno
3083 GET_MODE (reg
), byte
, mode
) < 0)
3084 && (goal_alt
[i
] == NO_REGS
3085 || (simplify_subreg_regno
3086 (ira_class_hard_regs
[goal_alt
[i
]][0],
3087 GET_MODE (reg
), byte
, mode
) >= 0)))))
3089 loc
= &SUBREG_REG (*loc
);
3090 mode
= GET_MODE (*loc
);
3094 if (get_reload_reg (type
, mode
, old
, goal_alt
[i
], "", &new_reg
)
3097 push_to_sequence (before
);
3098 lra_emit_move (new_reg
, old
);
3099 before
= get_insns ();
3104 && find_reg_note (curr_insn
, REG_UNUSED
, old
) == NULL_RTX
)
3107 lra_emit_move (type
== OP_INOUT
? copy_rtx (old
) : old
, new_reg
);
3109 after
= get_insns ();
3113 for (j
= 0; j
< goal_alt_dont_inherit_ops_num
; j
++)
3114 if (goal_alt_dont_inherit_ops
[j
] == i
)
3116 lra_set_regno_unique_value (REGNO (new_reg
));
3119 lra_update_dup (curr_id
, i
);
3121 else if (curr_static_id
->operand
[i
].type
== OP_IN
3122 && (curr_static_id
->operand
[goal_alt_matched
[i
][0]].type
3125 /* generate reloads for input and matched outputs. */
3126 match_inputs
[0] = i
;
3127 match_inputs
[1] = -1;
3128 match_reload (goal_alt_matched
[i
][0], match_inputs
,
3129 goal_alt
[i
], &before
, &after
);
3131 else if (curr_static_id
->operand
[i
].type
== OP_OUT
3132 && (curr_static_id
->operand
[goal_alt_matched
[i
][0]].type
3134 /* Generate reloads for output and matched inputs. */
3135 match_reload (i
, goal_alt_matched
[i
], goal_alt
[i
], &before
, &after
);
3136 else if (curr_static_id
->operand
[i
].type
== OP_IN
3137 && (curr_static_id
->operand
[goal_alt_matched
[i
][0]].type
3140 /* Generate reloads for matched inputs. */
3141 match_inputs
[0] = i
;
3142 for (j
= 0; (k
= goal_alt_matched
[i
][j
]) >= 0; j
++)
3143 match_inputs
[j
+ 1] = k
;
3144 match_inputs
[j
+ 1] = -1;
3145 match_reload (-1, match_inputs
, goal_alt
[i
], &before
, &after
);
3148 /* We must generate code in any case when function
3149 process_alt_operands decides that it is possible. */
3152 if (before
!= NULL_RTX
|| after
!= NULL_RTX
3153 || max_regno_before
!= max_reg_num ())
3157 lra_update_operator_dups (curr_id
);
3158 /* Something changes -- process the insn. */
3159 lra_update_insn_regno_info (curr_insn
);
3161 lra_process_new_insns (curr_insn
, before
, after
, "Inserting insn reload");
3165 /* Return true if X is in LIST. */
3167 in_list_p (rtx x
, rtx list
)
3169 for (; list
!= NULL_RTX
; list
= XEXP (list
, 1))
3170 if (XEXP (list
, 0) == x
)
3175 /* Return true if X contains an allocatable hard register (if
3176 HARD_REG_P) or a (spilled if SPILLED_P) pseudo. */
3178 contains_reg_p (rtx x
, bool hard_reg_p
, bool spilled_p
)
3184 code
= GET_CODE (x
);
3187 int regno
= REGNO (x
);
3188 HARD_REG_SET alloc_regs
;
3192 if (regno
>= FIRST_PSEUDO_REGISTER
)
3193 regno
= lra_get_regno_hard_regno (regno
);
3196 COMPL_HARD_REG_SET (alloc_regs
, lra_no_alloc_regs
);
3197 return overlaps_hard_reg_set_p (alloc_regs
, GET_MODE (x
), regno
);
3201 if (regno
< FIRST_PSEUDO_REGISTER
)
3205 return lra_get_regno_hard_regno (regno
) < 0;
3208 fmt
= GET_RTX_FORMAT (code
);
3209 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
3213 if (contains_reg_p (XEXP (x
, i
), hard_reg_p
, spilled_p
))
3216 else if (fmt
[i
] == 'E')
3218 for (j
= XVECLEN (x
, i
) - 1; j
>= 0; j
--)
3219 if (contains_reg_p (XVECEXP (x
, i
, j
), hard_reg_p
, spilled_p
))
3226 /* Process all regs in location *LOC and change them on equivalent
3227 substitution. Return true if any change was done. */
3229 loc_equivalence_change_p (rtx
*loc
)
3231 rtx subst
, reg
, x
= *loc
;
3232 bool result
= false;
3233 enum rtx_code code
= GET_CODE (x
);
3239 reg
= SUBREG_REG (x
);
3240 if ((subst
= get_equiv_substitution (reg
)) != reg
3241 && GET_MODE (subst
) == VOIDmode
)
3243 /* We cannot reload debug location. Simplify subreg here
3244 while we know the inner mode. */
3245 *loc
= simplify_gen_subreg (GET_MODE (x
), subst
,
3246 GET_MODE (reg
), SUBREG_BYTE (x
));
3250 if (code
== REG
&& (subst
= get_equiv_substitution (x
)) != x
)
3256 /* Scan all the operand sub-expressions. */
3257 fmt
= GET_RTX_FORMAT (code
);
3258 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
3261 result
= loc_equivalence_change_p (&XEXP (x
, i
)) || result
;
3262 else if (fmt
[i
] == 'E')
3263 for (j
= XVECLEN (x
, i
) - 1; j
>= 0; j
--)
3265 = loc_equivalence_change_p (&XVECEXP (x
, i
, j
)) || result
;
3270 /* Similar to loc_equivalence_change_p, but for use as
3271 simplify_replace_fn_rtx callback. */
3273 loc_equivalence_callback (rtx loc
, const_rtx
, void *)
3278 rtx subst
= get_equiv_substitution (loc
);
3285 /* Maximum number of generated reload insns per an insn. It is for
3286 preventing this pass cycling in a bug case. */
3287 #define MAX_RELOAD_INSNS_NUMBER LRA_MAX_INSN_RELOADS
3289 /* The current iteration number of this LRA pass. */
3290 int lra_constraint_iter
;
3292 /* The current iteration number of this LRA pass after the last spill
3294 int lra_constraint_iter_after_spill
;
3296 /* True if we substituted equiv which needs checking register
3297 allocation correctness because the equivalent value contains
3298 allocatable hard registers or when we restore multi-register
3300 bool lra_risky_transformations_p
;
3302 /* Return true if REGNO is referenced in more than one block. */
3304 multi_block_pseudo_p (int regno
)
3306 basic_block bb
= NULL
;
3310 if (regno
< FIRST_PSEUDO_REGISTER
)
3313 EXECUTE_IF_SET_IN_BITMAP (&lra_reg_info
[regno
].insn_bitmap
, 0, uid
, bi
)
3315 bb
= BLOCK_FOR_INSN (lra_insn_recog_data
[uid
]->insn
);
3316 else if (BLOCK_FOR_INSN (lra_insn_recog_data
[uid
]->insn
) != bb
)
3321 /* Return true if LIST contains a deleted insn. */
3323 contains_deleted_insn_p (rtx list
)
3325 for (; list
!= NULL_RTX
; list
= XEXP (list
, 1))
3326 if (NOTE_P (XEXP (list
, 0))
3327 && NOTE_KIND (XEXP (list
, 0)) == NOTE_INSN_DELETED
)
3332 /* Return true if X contains a pseudo dying in INSN. */
3334 dead_pseudo_p (rtx x
, rtx insn
)
3341 return (insn
!= NULL_RTX
3342 && find_regno_note (insn
, REG_DEAD
, REGNO (x
)) != NULL_RTX
);
3343 code
= GET_CODE (x
);
3344 fmt
= GET_RTX_FORMAT (code
);
3345 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
3349 if (dead_pseudo_p (XEXP (x
, i
), insn
))
3352 else if (fmt
[i
] == 'E')
3354 for (j
= XVECLEN (x
, i
) - 1; j
>= 0; j
--)
3355 if (dead_pseudo_p (XVECEXP (x
, i
, j
), insn
))
3362 /* Return true if INSN contains a dying pseudo in INSN right hand
3365 insn_rhs_dead_pseudo_p (rtx insn
)
3367 rtx set
= single_set (insn
);
3369 gcc_assert (set
!= NULL
);
3370 return dead_pseudo_p (SET_SRC (set
), insn
);
3373 /* Return true if any init insn of REGNO contains a dying pseudo in
3374 insn right hand side. */
3376 init_insn_rhs_dead_pseudo_p (int regno
)
3378 rtx insns
= ira_reg_equiv
[regno
].init_insns
;
3383 return insn_rhs_dead_pseudo_p (insns
);
3384 for (; insns
!= NULL_RTX
; insns
= XEXP (insns
, 1))
3385 if (insn_rhs_dead_pseudo_p (XEXP (insns
, 0)))
3390 /* Entry function of LRA constraint pass. Return true if the
3391 constraint pass did change the code. */
3393 lra_constraints (bool first_p
)
3396 int i
, hard_regno
, new_insns_num
;
3397 unsigned int min_len
, new_min_len
, uid
;
3398 rtx set
, x
, reg
, dest_reg
;
3399 basic_block last_bb
;
3400 bitmap_head equiv_insn_bitmap
;
3403 lra_constraint_iter
++;
3404 if (lra_dump_file
!= NULL
)
3405 fprintf (lra_dump_file
, "\n********** Local #%d: **********\n\n",
3406 lra_constraint_iter
);
3407 lra_constraint_iter_after_spill
++;
3408 if (lra_constraint_iter_after_spill
> LRA_MAX_CONSTRAINT_ITERATION_NUMBER
)
3410 ("Maximum number of LRA constraint passes is achieved (%d)\n",
3411 LRA_MAX_CONSTRAINT_ITERATION_NUMBER
);
3413 lra_risky_transformations_p
= false;
3414 new_insn_uid_start
= get_max_uid ();
3415 new_regno_start
= first_p
? lra_constraint_new_regno_start
: max_reg_num ();
3416 bitmap_initialize (&equiv_insn_bitmap
, ®_obstack
);
3417 for (i
= FIRST_PSEUDO_REGISTER
; i
< new_regno_start
; i
++)
3418 if (lra_reg_info
[i
].nrefs
!= 0)
3420 ira_reg_equiv
[i
].profitable_p
= true;
3421 reg
= regno_reg_rtx
[i
];
3422 if ((hard_regno
= lra_get_regno_hard_regno (i
)) >= 0)
3426 nregs
= hard_regno_nregs
[hard_regno
][lra_reg_info
[i
].biggest_mode
];
3427 for (j
= 0; j
< nregs
; j
++)
3428 df_set_regs_ever_live (hard_regno
+ j
, true);
3430 else if ((x
= get_equiv_substitution (reg
)) != reg
)
3432 bool pseudo_p
= contains_reg_p (x
, false, false);
3435 /* After RTL transformation, we can not guarantee that
3436 pseudo in the substitution was not reloaded which might
3437 make equivalence invalid. For example, in reverse
3444 the memory address register was reloaded before the 2nd
3446 if ((! first_p
&& pseudo_p
)
3447 /* We don't use DF for compilation speed sake. So it
3448 is problematic to update live info when we use an
3449 equivalence containing pseudos in more than one
3451 || (pseudo_p
&& multi_block_pseudo_p (i
))
3452 /* If an init insn was deleted for some reason, cancel
3453 the equiv. We could update the equiv insns after
3454 transformations including an equiv insn deletion
3455 but it is not worthy as such cases are extremely
3457 || contains_deleted_insn_p (ira_reg_equiv
[i
].init_insns
)
3458 /* If it is not a reverse equivalence, we check that a
3459 pseudo in rhs of the init insn is not dying in the
3460 insn. Otherwise, the live info at the beginning of
3461 the corresponding BB might be wrong after we
3462 removed the insn. When the equiv can be a
3463 constant, the right hand side of the init insn can
3465 || (! ((insn
= ira_reg_equiv
[i
].init_insns
) != NULL_RTX
3467 && (set
= single_set (insn
)) != NULL_RTX
3468 && REG_P (SET_DEST (set
))
3469 && (int) REGNO (SET_DEST (set
)) == i
)
3470 && init_insn_rhs_dead_pseudo_p (i
))
3471 /* Prevent access beyond equivalent memory for
3472 paradoxical subregs. */
3474 && (GET_MODE_SIZE (lra_reg_info
[i
].biggest_mode
)
3475 > GET_MODE_SIZE (GET_MODE (x
)))))
3476 ira_reg_equiv
[i
].defined_p
= false;
3477 if (contains_reg_p (x
, false, true))
3478 ira_reg_equiv
[i
].profitable_p
= false;
3479 if (get_equiv_substitution (reg
) != reg
)
3480 bitmap_ior_into (&equiv_insn_bitmap
, &lra_reg_info
[i
].insn_bitmap
);
3483 /* We should add all insns containing pseudos which should be
3484 substituted by their equivalences. */
3485 EXECUTE_IF_SET_IN_BITMAP (&equiv_insn_bitmap
, 0, uid
, bi
)
3486 lra_push_insn_by_uid (uid
);
3487 lra_eliminate (false);
3488 min_len
= lra_insn_stack_length ();
3492 while ((new_min_len
= lra_insn_stack_length ()) != 0)
3494 curr_insn
= lra_pop_insn ();
3496 curr_bb
= BLOCK_FOR_INSN (curr_insn
);
3497 if (curr_bb
!= last_bb
)
3500 bb_reload_num
= lra_curr_reload_num
;
3502 if (min_len
> new_min_len
)
3504 min_len
= new_min_len
;
3507 if (new_insns_num
> MAX_RELOAD_INSNS_NUMBER
)
3509 ("Max. number of generated reload insns per insn is achieved (%d)\n",
3510 MAX_RELOAD_INSNS_NUMBER
);
3512 if (DEBUG_INSN_P (curr_insn
))
3514 /* We need to check equivalence in debug insn and change
3515 pseudo to the equivalent value if necessary. */
3516 curr_id
= lra_get_insn_recog_data (curr_insn
);
3517 if (bitmap_bit_p (&equiv_insn_bitmap
, INSN_UID (curr_insn
)))
3519 rtx old
= *curr_id
->operand_loc
[0];
3520 *curr_id
->operand_loc
[0]
3521 = simplify_replace_fn_rtx (old
, NULL_RTX
,
3522 loc_equivalence_callback
, NULL
);
3523 if (old
!= *curr_id
->operand_loc
[0])
3525 lra_update_insn_regno_info (curr_insn
);
3530 else if (INSN_P (curr_insn
))
3532 if ((set
= single_set (curr_insn
)) != NULL_RTX
)
3534 dest_reg
= SET_DEST (set
);
3535 /* The equivalence pseudo could be set up as SUBREG in a
3536 case when it is a call restore insn in a mode
3537 different from the pseudo mode. */
3538 if (GET_CODE (dest_reg
) == SUBREG
)
3539 dest_reg
= SUBREG_REG (dest_reg
);
3540 if ((REG_P (dest_reg
)
3541 && (x
= get_equiv_substitution (dest_reg
)) != dest_reg
3542 /* Remove insns which set up a pseudo whose value
3543 can not be changed. Such insns might be not in
3544 init_insns because we don't update equiv data
3545 during insn transformations.
3547 As an example, let suppose that a pseudo got
3548 hard register and on the 1st pass was not
3549 changed to equivalent constant. We generate an
3550 additional insn setting up the pseudo because of
3551 secondary memory movement. Then the pseudo is
3552 spilled and we use the equiv constant. In this
3553 case we should remove the additional insn and
3554 this insn is not init_insns list. */
3555 && (! MEM_P (x
) || MEM_READONLY_P (x
)
3556 || in_list_p (curr_insn
,
3558 [REGNO (dest_reg
)].init_insns
)))
3559 || (((x
= get_equiv_substitution (SET_SRC (set
)))
3561 && in_list_p (curr_insn
,
3563 [REGNO (SET_SRC (set
))].init_insns
)))
3565 /* This is equiv init insn of pseudo which did not get a
3566 hard register -- remove the insn. */
3567 if (lra_dump_file
!= NULL
)
3569 fprintf (lra_dump_file
,
3570 " Removing equiv init insn %i (freq=%d)\n",
3571 INSN_UID (curr_insn
),
3572 BLOCK_FOR_INSN (curr_insn
)->frequency
);
3573 dump_insn_slim (lra_dump_file
, curr_insn
);
3575 if (contains_reg_p (x
, true, false))
3576 lra_risky_transformations_p
= true;
3577 lra_set_insn_deleted (curr_insn
);
3581 curr_id
= lra_get_insn_recog_data (curr_insn
);
3582 curr_static_id
= curr_id
->insn_static_data
;
3583 init_curr_insn_input_reloads ();
3584 init_curr_operand_mode ();
3585 if (curr_insn_transform ())
3587 /* Check non-transformed insns too for equiv change as USE
3588 or CLOBBER don't need reloads but can contain pseudos
3589 being changed on their equivalences. */
3590 else if (bitmap_bit_p (&equiv_insn_bitmap
, INSN_UID (curr_insn
))
3591 && loc_equivalence_change_p (&PATTERN (curr_insn
)))
3593 lra_update_insn_regno_info (curr_insn
);
3598 bitmap_clear (&equiv_insn_bitmap
);
3599 /* If we used a new hard regno, changed_p should be true because the
3600 hard reg is assigned to a new pseudo. */
3601 #ifdef ENABLE_CHECKING
3604 for (i
= FIRST_PSEUDO_REGISTER
; i
< new_regno_start
; i
++)
3605 if (lra_reg_info
[i
].nrefs
!= 0
3606 && (hard_regno
= lra_get_regno_hard_regno (i
)) >= 0)
3608 int j
, nregs
= hard_regno_nregs
[hard_regno
][PSEUDO_REGNO_MODE (i
)];
3610 for (j
= 0; j
< nregs
; j
++)
3611 lra_assert (df_regs_ever_live_p (hard_regno
+ j
));
3618 /* Initiate the LRA constraint pass. It is done once per
3621 lra_constraints_init (void)
3625 /* Finalize the LRA constraint pass. It is done once per
3628 lra_constraints_finish (void)
3634 /* This page contains code to do inheritance/split
3637 /* Number of reloads passed so far in current EBB. */
3638 static int reloads_num
;
3640 /* Number of calls passed so far in current EBB. */
3641 static int calls_num
;
3643 /* Current reload pseudo check for validity of elements in
3645 static int curr_usage_insns_check
;
3647 /* Info about last usage of registers in EBB to do inheritance/split
3648 transformation. Inheritance transformation is done from a spilled
3649 pseudo and split transformations from a hard register or a pseudo
3650 assigned to a hard register. */
3653 /* If the value is equal to CURR_USAGE_INSNS_CHECK, then the member
3654 value INSNS is valid. The insns is chain of optional debug insns
3655 and a finishing non-debug insn using the corresponding reg. */
3657 /* Value of global reloads_num at the last insn in INSNS. */
3659 /* Value of global reloads_nums at the last insn in INSNS. */
3661 /* It can be true only for splitting. And it means that the restore
3662 insn should be put after insn given by the following member. */
3664 /* Next insns in the current EBB which use the original reg and the
3665 original reg value is not changed between the current insn and
3666 the next insns. In order words, e.g. for inheritance, if we need
3667 to use the original reg value again in the next insns we can try
3668 to use the value in a hard register from a reload insn of the
3673 /* Map: regno -> corresponding pseudo usage insns. */
3674 static struct usage_insns
*usage_insns
;
3677 setup_next_usage_insn (int regno
, rtx insn
, int reloads_num
, bool after_p
)
3679 usage_insns
[regno
].check
= curr_usage_insns_check
;
3680 usage_insns
[regno
].insns
= insn
;
3681 usage_insns
[regno
].reloads_num
= reloads_num
;
3682 usage_insns
[regno
].calls_num
= calls_num
;
3683 usage_insns
[regno
].after_p
= after_p
;
3686 /* The function is used to form list REGNO usages which consists of
3687 optional debug insns finished by a non-debug insn using REGNO.
3688 RELOADS_NUM is current number of reload insns processed so far. */
3690 add_next_usage_insn (int regno
, rtx insn
, int reloads_num
)
3692 rtx next_usage_insns
;
3694 if (usage_insns
[regno
].check
== curr_usage_insns_check
3695 && (next_usage_insns
= usage_insns
[regno
].insns
) != NULL_RTX
3696 && DEBUG_INSN_P (insn
))
3698 /* Check that we did not add the debug insn yet. */
3699 if (next_usage_insns
!= insn
3700 && (GET_CODE (next_usage_insns
) != INSN_LIST
3701 || XEXP (next_usage_insns
, 0) != insn
))
3702 usage_insns
[regno
].insns
= gen_rtx_INSN_LIST (VOIDmode
, insn
,
3705 else if (NONDEBUG_INSN_P (insn
))
3706 setup_next_usage_insn (regno
, insn
, reloads_num
, false);
3708 usage_insns
[regno
].check
= 0;
3711 /* Replace all references to register OLD_REGNO in *LOC with pseudo
3712 register NEW_REG. Return true if any change was made. */
3714 substitute_pseudo (rtx
*loc
, int old_regno
, rtx new_reg
)
3717 bool result
= false;
3725 code
= GET_CODE (x
);
3726 if (code
== REG
&& (int) REGNO (x
) == old_regno
)
3728 enum machine_mode mode
= GET_MODE (*loc
);
3729 enum machine_mode inner_mode
= GET_MODE (new_reg
);
3731 if (mode
!= inner_mode
)
3733 if (GET_MODE_SIZE (mode
) >= GET_MODE_SIZE (inner_mode
)
3734 || ! SCALAR_INT_MODE_P (inner_mode
))
3735 new_reg
= gen_rtx_SUBREG (mode
, new_reg
, 0);
3737 new_reg
= gen_lowpart_SUBREG (mode
, new_reg
);
3743 /* Scan all the operand sub-expressions. */
3744 fmt
= GET_RTX_FORMAT (code
);
3745 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
3749 if (substitute_pseudo (&XEXP (x
, i
), old_regno
, new_reg
))
3752 else if (fmt
[i
] == 'E')
3754 for (j
= XVECLEN (x
, i
) - 1; j
>= 0; j
--)
3755 if (substitute_pseudo (&XVECEXP (x
, i
, j
), old_regno
, new_reg
))
3762 /* Return first non-debug insn in list USAGE_INSNS. */
3764 skip_usage_debug_insns (rtx usage_insns
)
3768 /* Skip debug insns. */
3769 for (insn
= usage_insns
;
3770 insn
!= NULL_RTX
&& GET_CODE (insn
) == INSN_LIST
;
3771 insn
= XEXP (insn
, 1))
3776 /* Return true if we need secondary memory moves for insn in
3777 USAGE_INSNS after inserting inherited pseudo of class INHER_CL
3780 check_secondary_memory_needed_p (enum reg_class inher_cl ATTRIBUTE_UNUSED
,
3781 rtx usage_insns ATTRIBUTE_UNUSED
)
3783 #ifndef SECONDARY_MEMORY_NEEDED
3786 rtx insn
, set
, dest
;
3789 if (inher_cl
== ALL_REGS
3790 || (insn
= skip_usage_debug_insns (usage_insns
)) == NULL_RTX
)
3792 lra_assert (INSN_P (insn
));
3793 if ((set
= single_set (insn
)) == NULL_RTX
|| ! REG_P (SET_DEST (set
)))
3795 dest
= SET_DEST (set
);
3798 lra_assert (inher_cl
!= NO_REGS
);
3799 cl
= get_reg_class (REGNO (dest
));
3800 return (cl
!= NO_REGS
&& cl
!= ALL_REGS
3801 && SECONDARY_MEMORY_NEEDED (inher_cl
, cl
, GET_MODE (dest
)));
3805 /* Registers involved in inheritance/split in the current EBB
3806 (inheritance/split pseudos and original registers). */
3807 static bitmap_head check_only_regs
;
3809 /* Do inheritance transformations for insn INSN, which defines (if
3810 DEF_P) or uses ORIGINAL_REGNO. NEXT_USAGE_INSNS specifies which
3811 instruction in the EBB next uses ORIGINAL_REGNO; it has the same
3812 form as the "insns" field of usage_insns. Return true if we
3813 succeed in such transformation.
3815 The transformations look like:
3818 ... p <- i (new insn)
3820 <- ... p ... <- ... i ...
3822 ... i <- p (new insn)
3823 <- ... p ... <- ... i ...
3825 <- ... p ... <- ... i ...
3826 where p is a spilled original pseudo and i is a new inheritance pseudo.
3829 The inheritance pseudo has the smallest class of two classes CL and
3830 class of ORIGINAL REGNO. */
3832 inherit_reload_reg (bool def_p
, int original_regno
,
3833 enum reg_class cl
, rtx insn
, rtx next_usage_insns
)
3835 enum reg_class rclass
= lra_get_allocno_class (original_regno
);
3836 rtx original_reg
= regno_reg_rtx
[original_regno
];
3837 rtx new_reg
, new_insns
, usage_insn
;
3839 lra_assert (! usage_insns
[original_regno
].after_p
);
3840 if (lra_dump_file
!= NULL
)
3841 fprintf (lra_dump_file
,
3842 " <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n");
3843 if (! ira_reg_classes_intersect_p
[cl
][rclass
])
3845 if (lra_dump_file
!= NULL
)
3847 fprintf (lra_dump_file
,
3848 " Rejecting inheritance for %d "
3849 "because of disjoint classes %s and %s\n",
3850 original_regno
, reg_class_names
[cl
],
3851 reg_class_names
[rclass
]);
3852 fprintf (lra_dump_file
,
3853 " >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n");
3857 if ((ira_class_subset_p
[cl
][rclass
] && cl
!= rclass
)
3858 /* We don't use a subset of two classes because it can be
3859 NO_REGS. This transformation is still profitable in most
3860 cases even if the classes are not intersected as register
3861 move is probably cheaper than a memory load. */
3862 || ira_class_hard_regs_num
[cl
] < ira_class_hard_regs_num
[rclass
])
3864 if (lra_dump_file
!= NULL
)
3865 fprintf (lra_dump_file
, " Use smallest class of %s and %s\n",
3866 reg_class_names
[cl
], reg_class_names
[rclass
]);
3870 if (check_secondary_memory_needed_p (rclass
, next_usage_insns
))
3872 /* Reject inheritance resulting in secondary memory moves.
3873 Otherwise, there is a danger in LRA cycling. Also such
3874 transformation will be unprofitable. */
3875 if (lra_dump_file
!= NULL
)
3877 rtx insn
= skip_usage_debug_insns (next_usage_insns
);
3878 rtx set
= single_set (insn
);
3880 lra_assert (set
!= NULL_RTX
);
3882 rtx dest
= SET_DEST (set
);
3884 lra_assert (REG_P (dest
));
3885 fprintf (lra_dump_file
,
3886 " Rejecting inheritance for insn %d(%s)<-%d(%s) "
3887 "as secondary mem is needed\n",
3888 REGNO (dest
), reg_class_names
[get_reg_class (REGNO (dest
))],
3889 original_regno
, reg_class_names
[rclass
]);
3890 fprintf (lra_dump_file
,
3891 " >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n");
3895 new_reg
= lra_create_new_reg (GET_MODE (original_reg
), original_reg
,
3896 rclass
, "inheritance");
3899 emit_move_insn (original_reg
, new_reg
);
3901 emit_move_insn (new_reg
, original_reg
);
3902 new_insns
= get_insns ();
3904 if (NEXT_INSN (new_insns
) != NULL_RTX
)
3906 if (lra_dump_file
!= NULL
)
3908 fprintf (lra_dump_file
,
3909 " Rejecting inheritance %d->%d "
3910 "as it results in 2 or more insns:\n",
3911 original_regno
, REGNO (new_reg
));
3912 dump_rtl_slim (lra_dump_file
, new_insns
, NULL_RTX
, -1, 0);
3913 fprintf (lra_dump_file
,
3914 " >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n");
3918 substitute_pseudo (&insn
, original_regno
, new_reg
);
3919 lra_update_insn_regno_info (insn
);
3921 /* We now have a new usage insn for original regno. */
3922 setup_next_usage_insn (original_regno
, new_insns
, reloads_num
, false);
3923 if (lra_dump_file
!= NULL
)
3924 fprintf (lra_dump_file
, " Original reg change %d->%d (bb%d):\n",
3925 original_regno
, REGNO (new_reg
), BLOCK_FOR_INSN (insn
)->index
);
3926 lra_reg_info
[REGNO (new_reg
)].restore_regno
= original_regno
;
3927 bitmap_set_bit (&check_only_regs
, REGNO (new_reg
));
3928 bitmap_set_bit (&check_only_regs
, original_regno
);
3929 bitmap_set_bit (&lra_inheritance_pseudos
, REGNO (new_reg
));
3931 lra_process_new_insns (insn
, NULL_RTX
, new_insns
,
3932 "Add original<-inheritance");
3934 lra_process_new_insns (insn
, new_insns
, NULL_RTX
,
3935 "Add inheritance<-original");
3936 while (next_usage_insns
!= NULL_RTX
)
3938 if (GET_CODE (next_usage_insns
) != INSN_LIST
)
3940 usage_insn
= next_usage_insns
;
3941 lra_assert (NONDEBUG_INSN_P (usage_insn
));
3942 next_usage_insns
= NULL
;
3946 usage_insn
= XEXP (next_usage_insns
, 0);
3947 lra_assert (DEBUG_INSN_P (usage_insn
));
3948 next_usage_insns
= XEXP (next_usage_insns
, 1);
3950 substitute_pseudo (&usage_insn
, original_regno
, new_reg
);
3951 lra_update_insn_regno_info (usage_insn
);
3952 if (lra_dump_file
!= NULL
)
3954 fprintf (lra_dump_file
,
3955 " Inheritance reuse change %d->%d (bb%d):\n",
3956 original_regno
, REGNO (new_reg
),
3957 BLOCK_FOR_INSN (usage_insn
)->index
);
3958 dump_insn_slim (lra_dump_file
, usage_insn
);
3961 if (lra_dump_file
!= NULL
)
3962 fprintf (lra_dump_file
,
3963 " >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n");
3967 /* Return true if we need a caller save/restore for pseudo REGNO which
3968 was assigned to a hard register. */
3970 need_for_call_save_p (int regno
)
3972 lra_assert (regno
>= FIRST_PSEUDO_REGISTER
&& reg_renumber
[regno
] >= 0);
3973 return (usage_insns
[regno
].calls_num
< calls_num
3974 && (overlaps_hard_reg_set_p
3976 PSEUDO_REGNO_MODE (regno
), reg_renumber
[regno
])));
3979 /* Global registers occuring in the current EBB. */
3980 static bitmap_head ebb_global_regs
;
3982 /* Return true if we need a split for hard register REGNO or pseudo
3983 REGNO which was assigned to a hard register.
3984 POTENTIAL_RELOAD_HARD_REGS contains hard registers which might be
3985 used for reloads since the EBB end. It is an approximation of the
3986 used hard registers in the split range. The exact value would
3987 require expensive calculations. If we were aggressive with
3988 splitting because of the approximation, the split pseudo will save
3989 the same hard register assignment and will be removed in the undo
3990 pass. We still need the approximation because too aggressive
3991 splitting would result in too inaccurate cost calculation in the
3992 assignment pass because of too many generated moves which will be
3993 probably removed in the undo pass. */
3995 need_for_split_p (HARD_REG_SET potential_reload_hard_regs
, int regno
)
3997 int hard_regno
= regno
< FIRST_PSEUDO_REGISTER
? regno
: reg_renumber
[regno
];
3999 lra_assert (hard_regno
>= 0);
4000 return ((TEST_HARD_REG_BIT (potential_reload_hard_regs
, hard_regno
)
4001 /* Don't split eliminable hard registers, otherwise we can
4002 split hard registers like hard frame pointer, which
4003 lives on BB start/end according to DF-infrastructure,
4004 when there is a pseudo assigned to the register and
4005 living in the same BB. */
4006 && (regno
>= FIRST_PSEUDO_REGISTER
4007 || ! TEST_HARD_REG_BIT (eliminable_regset
, hard_regno
))
4008 && ! TEST_HARD_REG_BIT (lra_no_alloc_regs
, hard_regno
)
4009 /* We need at least 2 reloads to make pseudo splitting
4010 profitable. We should provide hard regno splitting in
4011 any case to solve 1st insn scheduling problem when
4012 moving hard register definition up might result in
4013 impossibility to find hard register for reload pseudo of
4014 small register class. */
4015 && (usage_insns
[regno
].reloads_num
4016 + (regno
< FIRST_PSEUDO_REGISTER
? 0 : 2) < reloads_num
)
4017 && (regno
< FIRST_PSEUDO_REGISTER
4018 /* For short living pseudos, spilling + inheritance can
4019 be considered a substitution for splitting.
4020 Therefore we do not splitting for local pseudos. It
4021 decreases also aggressiveness of splitting. The
4022 minimal number of references is chosen taking into
4023 account that for 2 references splitting has no sense
4024 as we can just spill the pseudo. */
4025 || (regno
>= FIRST_PSEUDO_REGISTER
4026 && lra_reg_info
[regno
].nrefs
> 3
4027 && bitmap_bit_p (&ebb_global_regs
, regno
))))
4028 || (regno
>= FIRST_PSEUDO_REGISTER
&& need_for_call_save_p (regno
)));
4031 /* Return class for the split pseudo created from original pseudo with
4032 ALLOCNO_CLASS and MODE which got a hard register HARD_REGNO. We
4033 choose subclass of ALLOCNO_CLASS which contains HARD_REGNO and
4034 results in no secondary memory movements. */
4035 static enum reg_class
4036 choose_split_class (enum reg_class allocno_class
,
4037 int hard_regno ATTRIBUTE_UNUSED
,
4038 enum machine_mode mode ATTRIBUTE_UNUSED
)
4040 #ifndef SECONDARY_MEMORY_NEEDED
4041 return allocno_class
;
4044 enum reg_class cl
, best_cl
= NO_REGS
;
4045 enum reg_class hard_reg_class ATTRIBUTE_UNUSED
4046 = REGNO_REG_CLASS (hard_regno
);
4048 if (! SECONDARY_MEMORY_NEEDED (allocno_class
, allocno_class
, mode
)
4049 && TEST_HARD_REG_BIT (reg_class_contents
[allocno_class
], hard_regno
))
4050 return allocno_class
;
4052 (cl
= reg_class_subclasses
[allocno_class
][i
]) != LIM_REG_CLASSES
;
4054 if (! SECONDARY_MEMORY_NEEDED (cl
, hard_reg_class
, mode
)
4055 && ! SECONDARY_MEMORY_NEEDED (hard_reg_class
, cl
, mode
)
4056 && TEST_HARD_REG_BIT (reg_class_contents
[cl
], hard_regno
)
4057 && (best_cl
== NO_REGS
4058 || ira_class_hard_regs_num
[best_cl
] < ira_class_hard_regs_num
[cl
]))
4064 /* Do split transformations for insn INSN, which defines or uses
4065 ORIGINAL_REGNO. NEXT_USAGE_INSNS specifies which instruction in
4066 the EBB next uses ORIGINAL_REGNO; it has the same form as the
4067 "insns" field of usage_insns.
4069 The transformations look like:
4072 ... s <- p (new insn -- save)
4074 ... p <- s (new insn -- restore)
4075 <- ... p ... <- ... p ...
4077 <- ... p ... <- ... p ...
4078 ... s <- p (new insn -- save)
4080 ... p <- s (new insn -- restore)
4081 <- ... p ... <- ... p ...
4083 where p is an original pseudo got a hard register or a hard
4084 register and s is a new split pseudo. The save is put before INSN
4085 if BEFORE_P is true. Return true if we succeed in such
4088 split_reg (bool before_p
, int original_regno
, rtx insn
, rtx next_usage_insns
)
4090 enum reg_class rclass
;
4093 rtx new_reg
, save
, restore
, usage_insn
;
4097 if (original_regno
< FIRST_PSEUDO_REGISTER
)
4099 rclass
= ira_allocno_class_translate
[REGNO_REG_CLASS (original_regno
)];
4100 hard_regno
= original_regno
;
4101 call_save_p
= false;
4105 hard_regno
= reg_renumber
[original_regno
];
4106 rclass
= lra_get_allocno_class (original_regno
);
4107 original_reg
= regno_reg_rtx
[original_regno
];
4108 call_save_p
= need_for_call_save_p (original_regno
);
4110 original_reg
= regno_reg_rtx
[original_regno
];
4111 lra_assert (hard_regno
>= 0);
4112 if (lra_dump_file
!= NULL
)
4113 fprintf (lra_dump_file
,
4114 " ((((((((((((((((((((((((((((((((((((((((((((((((\n");
4117 enum machine_mode sec_mode
;
4119 #ifdef SECONDARY_MEMORY_NEEDED_MODE
4120 sec_mode
= SECONDARY_MEMORY_NEEDED_MODE (GET_MODE (original_reg
));
4122 sec_mode
= GET_MODE (original_reg
);
4124 new_reg
= lra_create_new_reg (sec_mode
, NULL_RTX
,
4129 rclass
= choose_split_class (rclass
, hard_regno
,
4130 GET_MODE (original_reg
));
4131 if (rclass
== NO_REGS
)
4133 if (lra_dump_file
!= NULL
)
4135 fprintf (lra_dump_file
,
4136 " Rejecting split of %d(%s): "
4137 "no good reg class for %d(%s)\n",
4139 reg_class_names
[lra_get_allocno_class (original_regno
)],
4141 reg_class_names
[REGNO_REG_CLASS (hard_regno
)]);
4144 " ))))))))))))))))))))))))))))))))))))))))))))))))\n");
4148 new_reg
= lra_create_new_reg (GET_MODE (original_reg
), original_reg
,
4150 reg_renumber
[REGNO (new_reg
)] = hard_regno
;
4152 save
= emit_spill_move (true, new_reg
, original_reg
);
4153 if (NEXT_INSN (save
) != NULL_RTX
)
4155 lra_assert (! call_save_p
);
4156 if (lra_dump_file
!= NULL
)
4160 " Rejecting split %d->%d resulting in > 2 %s save insns:\n",
4161 original_regno
, REGNO (new_reg
), call_save_p
? "call" : "");
4162 dump_rtl_slim (lra_dump_file
, save
, NULL_RTX
, -1, 0);
4163 fprintf (lra_dump_file
,
4164 " ))))))))))))))))))))))))))))))))))))))))))))))))\n");
4168 restore
= emit_spill_move (false, new_reg
, original_reg
);
4169 if (NEXT_INSN (restore
) != NULL_RTX
)
4171 lra_assert (! call_save_p
);
4172 if (lra_dump_file
!= NULL
)
4174 fprintf (lra_dump_file
,
4175 " Rejecting split %d->%d "
4176 "resulting in > 2 %s restore insns:\n",
4177 original_regno
, REGNO (new_reg
), call_save_p
? "call" : "");
4178 dump_rtl_slim (lra_dump_file
, restore
, NULL_RTX
, -1, 0);
4179 fprintf (lra_dump_file
,
4180 " ))))))))))))))))))))))))))))))))))))))))))))))))\n");
4184 after_p
= usage_insns
[original_regno
].after_p
;
4185 lra_reg_info
[REGNO (new_reg
)].restore_regno
= original_regno
;
4186 bitmap_set_bit (&check_only_regs
, REGNO (new_reg
));
4187 bitmap_set_bit (&check_only_regs
, original_regno
);
4188 bitmap_set_bit (&lra_split_regs
, REGNO (new_reg
));
4191 if (GET_CODE (next_usage_insns
) != INSN_LIST
)
4193 usage_insn
= next_usage_insns
;
4196 usage_insn
= XEXP (next_usage_insns
, 0);
4197 lra_assert (DEBUG_INSN_P (usage_insn
));
4198 next_usage_insns
= XEXP (next_usage_insns
, 1);
4199 substitute_pseudo (&usage_insn
, original_regno
, new_reg
);
4200 lra_update_insn_regno_info (usage_insn
);
4201 if (lra_dump_file
!= NULL
)
4203 fprintf (lra_dump_file
, " Split reuse change %d->%d:\n",
4204 original_regno
, REGNO (new_reg
));
4205 dump_insn_slim (lra_dump_file
, usage_insn
);
4208 lra_assert (NOTE_P (usage_insn
) || NONDEBUG_INSN_P (usage_insn
));
4209 lra_assert (usage_insn
!= insn
|| (after_p
&& before_p
));
4210 lra_process_new_insns (usage_insn
, after_p
? NULL_RTX
: restore
,
4211 after_p
? restore
: NULL_RTX
,
4213 ? "Add reg<-save" : "Add reg<-split");
4214 lra_process_new_insns (insn
, before_p
? save
: NULL_RTX
,
4215 before_p
? NULL_RTX
: save
,
4217 ? "Add save<-reg" : "Add split<-reg");
4218 if (lra_dump_file
!= NULL
)
4219 fprintf (lra_dump_file
,
4220 " ))))))))))))))))))))))))))))))))))))))))))))))))\n");
4224 /* Recognize that we need a split transformation for insn INSN, which
4225 defines or uses REGNO in its insn biggest MODE (we use it only if
4226 REGNO is a hard register). POTENTIAL_RELOAD_HARD_REGS contains
4227 hard registers which might be used for reloads since the EBB end.
4228 Put the save before INSN if BEFORE_P is true. MAX_UID is maximla
4229 uid before starting INSN processing. Return true if we succeed in
4230 such transformation. */
4232 split_if_necessary (int regno
, enum machine_mode mode
,
4233 HARD_REG_SET potential_reload_hard_regs
,
4234 bool before_p
, rtx insn
, int max_uid
)
4238 rtx next_usage_insns
;
4240 if (regno
< FIRST_PSEUDO_REGISTER
)
4241 nregs
= hard_regno_nregs
[regno
][mode
];
4242 for (i
= 0; i
< nregs
; i
++)
4243 if (usage_insns
[regno
+ i
].check
== curr_usage_insns_check
4244 && (next_usage_insns
= usage_insns
[regno
+ i
].insns
) != NULL_RTX
4245 /* To avoid processing the register twice or more. */
4246 && ((GET_CODE (next_usage_insns
) != INSN_LIST
4247 && INSN_UID (next_usage_insns
) < max_uid
)
4248 || (GET_CODE (next_usage_insns
) == INSN_LIST
4249 && (INSN_UID (XEXP (next_usage_insns
, 0)) < max_uid
)))
4250 && need_for_split_p (potential_reload_hard_regs
, regno
+ i
)
4251 && split_reg (before_p
, regno
+ i
, insn
, next_usage_insns
))
4256 /* Check only registers living at the current program point in the
4258 static bitmap_head live_regs
;
4260 /* Update live info in EBB given by its HEAD and TAIL insns after
4261 inheritance/split transformation. The function removes dead moves
4264 update_ebb_live_info (rtx head
, rtx tail
)
4271 basic_block last_bb
, prev_bb
, curr_bb
;
4273 struct lra_insn_reg
*reg
;
4277 last_bb
= BLOCK_FOR_INSN (tail
);
4279 for (curr_insn
= tail
;
4280 curr_insn
!= PREV_INSN (head
);
4281 curr_insn
= prev_insn
)
4283 prev_insn
= PREV_INSN (curr_insn
);
4284 /* We need to process empty blocks too. They contain
4285 NOTE_INSN_BASIC_BLOCK referring for the basic block. */
4286 if (NOTE_P (curr_insn
) && NOTE_KIND (curr_insn
) != NOTE_INSN_BASIC_BLOCK
)
4288 curr_bb
= BLOCK_FOR_INSN (curr_insn
);
4289 if (curr_bb
!= prev_bb
)
4291 if (prev_bb
!= NULL
)
4293 /* Update df_get_live_in (prev_bb): */
4294 EXECUTE_IF_SET_IN_BITMAP (&check_only_regs
, 0, j
, bi
)
4295 if (bitmap_bit_p (&live_regs
, j
))
4296 bitmap_set_bit (df_get_live_in (prev_bb
), j
);
4298 bitmap_clear_bit (df_get_live_in (prev_bb
), j
);
4300 if (curr_bb
!= last_bb
)
4302 /* Update df_get_live_out (curr_bb): */
4303 EXECUTE_IF_SET_IN_BITMAP (&check_only_regs
, 0, j
, bi
)
4305 live_p
= bitmap_bit_p (&live_regs
, j
);
4307 FOR_EACH_EDGE (e
, ei
, curr_bb
->succs
)
4308 if (bitmap_bit_p (df_get_live_in (e
->dest
), j
))
4314 bitmap_set_bit (df_get_live_out (curr_bb
), j
);
4316 bitmap_clear_bit (df_get_live_out (curr_bb
), j
);
4320 bitmap_and (&live_regs
, &check_only_regs
, df_get_live_out (curr_bb
));
4322 if (! NONDEBUG_INSN_P (curr_insn
))
4324 curr_id
= lra_get_insn_recog_data (curr_insn
);
4326 if ((set
= single_set (curr_insn
)) != NULL_RTX
&& REG_P (SET_DEST (set
))
4327 && (regno
= REGNO (SET_DEST (set
))) >= FIRST_PSEUDO_REGISTER
4328 && bitmap_bit_p (&check_only_regs
, regno
)
4329 && ! bitmap_bit_p (&live_regs
, regno
))
4331 /* See which defined values die here. */
4332 for (reg
= curr_id
->regs
; reg
!= NULL
; reg
= reg
->next
)
4333 if (reg
->type
== OP_OUT
&& ! reg
->subreg_p
)
4334 bitmap_clear_bit (&live_regs
, reg
->regno
);
4335 /* Mark each used value as live. */
4336 for (reg
= curr_id
->regs
; reg
!= NULL
; reg
= reg
->next
)
4337 if (reg
->type
== OP_IN
4338 && bitmap_bit_p (&check_only_regs
, reg
->regno
))
4339 bitmap_set_bit (&live_regs
, reg
->regno
);
4340 /* It is quite important to remove dead move insns because it
4341 means removing dead store. We don't need to process them for
4345 if (lra_dump_file
!= NULL
)
4347 fprintf (lra_dump_file
, " Removing dead insn:\n ");
4348 dump_insn_slim (lra_dump_file
, curr_insn
);
4350 lra_set_insn_deleted (curr_insn
);
4355 /* The structure describes info to do an inheritance for the current
4356 insn. We need to collect such info first before doing the
4357 transformations because the transformations change the insn
4358 internal representation. */
4361 /* Original regno. */
4363 /* Subsequent insns which can inherit original reg value. */
4367 /* Array containing all info for doing inheritance from the current
4369 static struct to_inherit to_inherit
[LRA_MAX_INSN_RELOADS
];
4371 /* Number elements in the previous array. */
4372 static int to_inherit_num
;
4374 /* Add inheritance info REGNO and INSNS. Their meaning is described in
4375 structure to_inherit. */
4377 add_to_inherit (int regno
, rtx insns
)
4381 for (i
= 0; i
< to_inherit_num
; i
++)
4382 if (to_inherit
[i
].regno
== regno
)
4384 lra_assert (to_inherit_num
< LRA_MAX_INSN_RELOADS
);
4385 to_inherit
[to_inherit_num
].regno
= regno
;
4386 to_inherit
[to_inherit_num
++].insns
= insns
;
4389 /* Return the last non-debug insn in basic block BB, or the block begin
4392 get_last_insertion_point (basic_block bb
)
4396 FOR_BB_INSNS_REVERSE (bb
, insn
)
4397 if (NONDEBUG_INSN_P (insn
) || NOTE_INSN_BASIC_BLOCK_P (insn
))
4402 /* Set up RES by registers living on edges FROM except the edge (FROM,
4403 TO) or by registers set up in a jump insn in BB FROM. */
4405 get_live_on_other_edges (basic_block from
, basic_block to
, bitmap res
)
4408 struct lra_insn_reg
*reg
;
4412 lra_assert (to
!= NULL
);
4414 FOR_EACH_EDGE (e
, ei
, from
->succs
)
4416 bitmap_ior_into (res
, df_get_live_in (e
->dest
));
4417 last
= get_last_insertion_point (from
);
4418 if (! JUMP_P (last
))
4420 curr_id
= lra_get_insn_recog_data (last
);
4421 for (reg
= curr_id
->regs
; reg
!= NULL
; reg
= reg
->next
)
4422 if (reg
->type
!= OP_IN
)
4423 bitmap_set_bit (res
, reg
->regno
);
4426 /* Used as a temporary results of some bitmap calculations. */
4427 static bitmap_head temp_bitmap
;
4429 /* Do inheritance/split transformations in EBB starting with HEAD and
4430 finishing on TAIL. We process EBB insns in the reverse order.
4431 Return true if we did any inheritance/split transformation in the
4434 We should avoid excessive splitting which results in worse code
4435 because of inaccurate cost calculations for spilling new split
4436 pseudos in such case. To achieve this we do splitting only if
4437 register pressure is high in given basic block and there are reload
4438 pseudos requiring hard registers. We could do more register
4439 pressure calculations at any given program point to avoid necessary
4440 splitting even more but it is to expensive and the current approach
4441 works well enough. */
4443 inherit_in_ebb (rtx head
, rtx tail
)
4445 int i
, src_regno
, dst_regno
, nregs
;
4446 bool change_p
, succ_p
;
4447 rtx prev_insn
, next_usage_insns
, set
, last_insn
;
4449 struct lra_insn_reg
*reg
;
4450 basic_block last_processed_bb
, curr_bb
= NULL
;
4451 HARD_REG_SET potential_reload_hard_regs
, live_hard_regs
;
4455 bool head_p
, after_p
;
4458 curr_usage_insns_check
++;
4459 reloads_num
= calls_num
= 0;
4460 bitmap_clear (&check_only_regs
);
4461 last_processed_bb
= NULL
;
4462 CLEAR_HARD_REG_SET (potential_reload_hard_regs
);
4463 CLEAR_HARD_REG_SET (live_hard_regs
);
4464 /* We don't process new insns generated in the loop. */
4465 for (curr_insn
= tail
; curr_insn
!= PREV_INSN (head
); curr_insn
= prev_insn
)
4467 prev_insn
= PREV_INSN (curr_insn
);
4468 if (BLOCK_FOR_INSN (curr_insn
) != NULL
)
4469 curr_bb
= BLOCK_FOR_INSN (curr_insn
);
4470 if (last_processed_bb
!= curr_bb
)
4472 /* We are at the end of BB. Add qualified living
4473 pseudos for potential splitting. */
4474 to_process
= df_get_live_out (curr_bb
);
4475 if (last_processed_bb
!= NULL
)
4477 /* We are somewhere in the middle of EBB. */
4478 get_live_on_other_edges (curr_bb
, last_processed_bb
,
4480 to_process
= &temp_bitmap
;
4482 last_processed_bb
= curr_bb
;
4483 last_insn
= get_last_insertion_point (curr_bb
);
4484 after_p
= (! JUMP_P (last_insn
)
4485 && (! CALL_P (last_insn
)
4486 || (find_reg_note (last_insn
,
4487 REG_NORETURN
, NULL_RTX
) == NULL_RTX
4488 && ! SIBLING_CALL_P (last_insn
))));
4489 REG_SET_TO_HARD_REG_SET (live_hard_regs
, df_get_live_out (curr_bb
));
4490 IOR_HARD_REG_SET (live_hard_regs
, eliminable_regset
);
4491 IOR_HARD_REG_SET (live_hard_regs
, lra_no_alloc_regs
);
4492 CLEAR_HARD_REG_SET (potential_reload_hard_regs
);
4493 EXECUTE_IF_SET_IN_BITMAP (to_process
, 0, j
, bi
)
4495 if ((int) j
>= lra_constraint_new_regno_start
)
4497 if (j
< FIRST_PSEUDO_REGISTER
|| reg_renumber
[j
] >= 0)
4499 if (j
< FIRST_PSEUDO_REGISTER
)
4500 SET_HARD_REG_BIT (live_hard_regs
, j
);
4502 add_to_hard_reg_set (&live_hard_regs
,
4503 PSEUDO_REGNO_MODE (j
),
4505 setup_next_usage_insn (j
, last_insn
, reloads_num
, after_p
);
4509 src_regno
= dst_regno
= -1;
4510 if (NONDEBUG_INSN_P (curr_insn
)
4511 && (set
= single_set (curr_insn
)) != NULL_RTX
4512 && REG_P (SET_DEST (set
)) && REG_P (SET_SRC (set
)))
4514 src_regno
= REGNO (SET_SRC (set
));
4515 dst_regno
= REGNO (SET_DEST (set
));
4517 if (src_regno
< lra_constraint_new_regno_start
4518 && src_regno
>= FIRST_PSEUDO_REGISTER
4519 && reg_renumber
[src_regno
] < 0
4520 && dst_regno
>= lra_constraint_new_regno_start
4521 && (cl
= lra_get_allocno_class (dst_regno
)) != NO_REGS
)
4523 /* 'reload_pseudo <- original_pseudo'. */
4526 if (usage_insns
[src_regno
].check
== curr_usage_insns_check
4527 && (next_usage_insns
= usage_insns
[src_regno
].insns
) != NULL_RTX
)
4528 succ_p
= inherit_reload_reg (false, src_regno
, cl
,
4529 curr_insn
, next_usage_insns
);
4533 setup_next_usage_insn (src_regno
, curr_insn
, reloads_num
, false);
4534 if (hard_reg_set_subset_p (reg_class_contents
[cl
], live_hard_regs
))
4535 IOR_HARD_REG_SET (potential_reload_hard_regs
,
4536 reg_class_contents
[cl
]);
4538 else if (src_regno
>= lra_constraint_new_regno_start
4539 && dst_regno
< lra_constraint_new_regno_start
4540 && dst_regno
>= FIRST_PSEUDO_REGISTER
4541 && reg_renumber
[dst_regno
] < 0
4542 && (cl
= lra_get_allocno_class (src_regno
)) != NO_REGS
4543 && usage_insns
[dst_regno
].check
== curr_usage_insns_check
4544 && (next_usage_insns
4545 = usage_insns
[dst_regno
].insns
) != NULL_RTX
)
4548 /* 'original_pseudo <- reload_pseudo'. */
4549 if (! JUMP_P (curr_insn
)
4550 && inherit_reload_reg (true, dst_regno
, cl
,
4551 curr_insn
, next_usage_insns
))
4554 usage_insns
[dst_regno
].check
= 0;
4555 if (hard_reg_set_subset_p (reg_class_contents
[cl
], live_hard_regs
))
4556 IOR_HARD_REG_SET (potential_reload_hard_regs
,
4557 reg_class_contents
[cl
]);
4559 else if (INSN_P (curr_insn
))
4561 int max_uid
= get_max_uid ();
4563 curr_id
= lra_get_insn_recog_data (curr_insn
);
4565 /* Process insn definitions. */
4566 for (reg
= curr_id
->regs
; reg
!= NULL
; reg
= reg
->next
)
4567 if (reg
->type
!= OP_IN
4568 && (dst_regno
= reg
->regno
) < lra_constraint_new_regno_start
)
4570 if (dst_regno
>= FIRST_PSEUDO_REGISTER
&& reg
->type
== OP_OUT
4571 && reg_renumber
[dst_regno
] < 0 && ! reg
->subreg_p
4572 && usage_insns
[dst_regno
].check
== curr_usage_insns_check
4573 && (next_usage_insns
4574 = usage_insns
[dst_regno
].insns
) != NULL_RTX
)
4576 struct lra_insn_reg
*r
;
4578 for (r
= curr_id
->regs
; r
!= NULL
; r
= r
->next
)
4579 if (r
->type
!= OP_OUT
&& r
->regno
== dst_regno
)
4581 /* Don't do inheritance if the pseudo is also
4582 used in the insn. */
4584 /* We can not do inheritance right now
4585 because the current insn reg info (chain
4586 regs) can change after that. */
4587 add_to_inherit (dst_regno
, next_usage_insns
);
4589 /* We can not process one reg twice here because of
4590 usage_insns invalidation. */
4591 if ((dst_regno
< FIRST_PSEUDO_REGISTER
4592 || reg_renumber
[dst_regno
] >= 0)
4593 && ! reg
->subreg_p
&& reg
->type
== OP_OUT
)
4597 if (split_if_necessary (dst_regno
, reg
->biggest_mode
,
4598 potential_reload_hard_regs
,
4599 false, curr_insn
, max_uid
))
4601 CLEAR_HARD_REG_SET (s
);
4602 if (dst_regno
< FIRST_PSEUDO_REGISTER
)
4603 add_to_hard_reg_set (&s
, reg
->biggest_mode
, dst_regno
);
4605 add_to_hard_reg_set (&s
, PSEUDO_REGNO_MODE (dst_regno
),
4606 reg_renumber
[dst_regno
]);
4607 AND_COMPL_HARD_REG_SET (live_hard_regs
, s
);
4609 /* We should invalidate potential inheritance or
4610 splitting for the current insn usages to the next
4611 usage insns (see code below) as the output pseudo
4613 if ((dst_regno
>= FIRST_PSEUDO_REGISTER
4614 && reg_renumber
[dst_regno
] < 0)
4615 || (reg
->type
== OP_OUT
&& ! reg
->subreg_p
4616 && (dst_regno
< FIRST_PSEUDO_REGISTER
4617 || reg_renumber
[dst_regno
] >= 0)))
4620 if (dst_regno
>= FIRST_PSEUDO_REGISTER
)
4621 usage_insns
[dst_regno
].check
= 0;
4624 nregs
= hard_regno_nregs
[dst_regno
][reg
->biggest_mode
];
4625 for (i
= 0; i
< nregs
; i
++)
4626 usage_insns
[dst_regno
+ i
].check
= 0;
4630 if (! JUMP_P (curr_insn
))
4631 for (i
= 0; i
< to_inherit_num
; i
++)
4632 if (inherit_reload_reg (true, to_inherit
[i
].regno
,
4633 ALL_REGS
, curr_insn
,
4634 to_inherit
[i
].insns
))
4636 if (CALL_P (curr_insn
))
4638 rtx cheap
, pat
, dest
, restore
;
4639 int regno
, hard_regno
;
4642 if ((cheap
= find_reg_note (curr_insn
,
4643 REG_RETURNED
, NULL_RTX
)) != NULL_RTX
4644 && ((cheap
= XEXP (cheap
, 0)), true)
4645 && (regno
= REGNO (cheap
)) >= FIRST_PSEUDO_REGISTER
4646 && (hard_regno
= reg_renumber
[regno
]) >= 0
4647 /* If there are pending saves/restores, the
4648 optimization is not worth. */
4649 && usage_insns
[regno
].calls_num
== calls_num
- 1
4650 && TEST_HARD_REG_BIT (call_used_reg_set
, hard_regno
))
4652 /* Restore the pseudo from the call result as
4653 REG_RETURNED note says that the pseudo value is
4654 in the call result and the pseudo is an argument
4656 pat
= PATTERN (curr_insn
);
4657 if (GET_CODE (pat
) == PARALLEL
)
4658 pat
= XVECEXP (pat
, 0, 0);
4659 dest
= SET_DEST (pat
);
4661 emit_move_insn (cheap
, copy_rtx (dest
));
4662 restore
= get_insns ();
4664 lra_process_new_insns (curr_insn
, NULL
, restore
,
4665 "Inserting call parameter restore");
4666 /* We don't need to save/restore of the pseudo from
4668 usage_insns
[regno
].calls_num
= calls_num
;
4669 bitmap_set_bit (&check_only_regs
, regno
);
4673 /* Process insn usages. */
4674 for (reg
= curr_id
->regs
; reg
!= NULL
; reg
= reg
->next
)
4675 if ((reg
->type
!= OP_OUT
4676 || (reg
->type
== OP_OUT
&& reg
->subreg_p
))
4677 && (src_regno
= reg
->regno
) < lra_constraint_new_regno_start
)
4679 if (src_regno
>= FIRST_PSEUDO_REGISTER
4680 && reg_renumber
[src_regno
] < 0 && reg
->type
== OP_IN
)
4682 if (usage_insns
[src_regno
].check
== curr_usage_insns_check
4683 && (next_usage_insns
4684 = usage_insns
[src_regno
].insns
) != NULL_RTX
4685 && NONDEBUG_INSN_P (curr_insn
))
4686 add_to_inherit (src_regno
, next_usage_insns
);
4689 add_next_usage_insn (src_regno
, curr_insn
, reloads_num
);
4691 else if (src_regno
< FIRST_PSEUDO_REGISTER
4692 || reg_renumber
[src_regno
] >= 0)
4695 rtx use_insn
= curr_insn
;
4697 before_p
= (JUMP_P (curr_insn
)
4698 || (CALL_P (curr_insn
) && reg
->type
== OP_IN
));
4699 if (NONDEBUG_INSN_P (curr_insn
)
4700 && split_if_necessary (src_regno
, reg
->biggest_mode
,
4701 potential_reload_hard_regs
,
4702 before_p
, curr_insn
, max_uid
))
4705 lra_risky_transformations_p
= true;
4708 usage_insns
[src_regno
].check
= 0;
4710 use_insn
= PREV_INSN (curr_insn
);
4712 if (NONDEBUG_INSN_P (curr_insn
))
4714 if (src_regno
< FIRST_PSEUDO_REGISTER
)
4715 add_to_hard_reg_set (&live_hard_regs
,
4716 reg
->biggest_mode
, src_regno
);
4718 add_to_hard_reg_set (&live_hard_regs
,
4719 PSEUDO_REGNO_MODE (src_regno
),
4720 reg_renumber
[src_regno
]);
4722 add_next_usage_insn (src_regno
, use_insn
, reloads_num
);
4725 for (i
= 0; i
< to_inherit_num
; i
++)
4727 src_regno
= to_inherit
[i
].regno
;
4728 if (inherit_reload_reg (false, src_regno
, ALL_REGS
,
4729 curr_insn
, to_inherit
[i
].insns
))
4732 setup_next_usage_insn (src_regno
, curr_insn
, reloads_num
, false);
4735 /* We reached the start of the current basic block. */
4736 if (prev_insn
== NULL_RTX
|| prev_insn
== PREV_INSN (head
)
4737 || BLOCK_FOR_INSN (prev_insn
) != curr_bb
)
4739 /* We reached the beginning of the current block -- do
4740 rest of spliting in the current BB. */
4741 to_process
= df_get_live_in (curr_bb
);
4742 if (BLOCK_FOR_INSN (head
) != curr_bb
)
4744 /* We are somewhere in the middle of EBB. */
4745 get_live_on_other_edges (EDGE_PRED (curr_bb
, 0)->src
,
4746 curr_bb
, &temp_bitmap
);
4747 to_process
= &temp_bitmap
;
4750 EXECUTE_IF_SET_IN_BITMAP (to_process
, 0, j
, bi
)
4752 if ((int) j
>= lra_constraint_new_regno_start
)
4754 if (((int) j
< FIRST_PSEUDO_REGISTER
|| reg_renumber
[j
] >= 0)
4755 && usage_insns
[j
].check
== curr_usage_insns_check
4756 && (next_usage_insns
= usage_insns
[j
].insns
) != NULL_RTX
)
4758 if (need_for_split_p (potential_reload_hard_regs
, j
))
4760 if (lra_dump_file
!= NULL
&& head_p
)
4762 fprintf (lra_dump_file
,
4763 " ----------------------------------\n");
4766 if (split_reg (false, j
, bb_note (curr_bb
),
4770 usage_insns
[j
].check
= 0;
4778 /* This value affects EBB forming. If probability of edge from EBB to
4779 a BB is not greater than the following value, we don't add the BB
4781 #define EBB_PROBABILITY_CUTOFF (REG_BR_PROB_BASE / 2)
4783 /* Current number of inheritance/split iteration. */
4784 int lra_inheritance_iter
;
4786 /* Entry function for inheritance/split pass. */
4788 lra_inheritance (void)
4791 basic_block bb
, start_bb
;
4794 lra_inheritance_iter
++;
4795 if (lra_inheritance_iter
> LRA_MAX_INHERITANCE_PASSES
)
4797 timevar_push (TV_LRA_INHERITANCE
);
4798 if (lra_dump_file
!= NULL
)
4799 fprintf (lra_dump_file
, "\n********** Inheritance #%d: **********\n\n",
4800 lra_inheritance_iter
);
4801 curr_usage_insns_check
= 0;
4802 usage_insns
= XNEWVEC (struct usage_insns
, lra_constraint_new_regno_start
);
4803 for (i
= 0; i
< lra_constraint_new_regno_start
; i
++)
4804 usage_insns
[i
].check
= 0;
4805 bitmap_initialize (&check_only_regs
, ®_obstack
);
4806 bitmap_initialize (&live_regs
, ®_obstack
);
4807 bitmap_initialize (&temp_bitmap
, ®_obstack
);
4808 bitmap_initialize (&ebb_global_regs
, ®_obstack
);
4812 if (lra_dump_file
!= NULL
)
4813 fprintf (lra_dump_file
, "EBB");
4814 /* Form a EBB starting with BB. */
4815 bitmap_clear (&ebb_global_regs
);
4816 bitmap_ior_into (&ebb_global_regs
, df_get_live_in (bb
));
4819 if (lra_dump_file
!= NULL
)
4820 fprintf (lra_dump_file
, " %d", bb
->index
);
4821 if (bb
->next_bb
== EXIT_BLOCK_PTR
|| LABEL_P (BB_HEAD (bb
->next_bb
)))
4823 e
= find_fallthru_edge (bb
->succs
);
4826 if (e
->probability
<= EBB_PROBABILITY_CUTOFF
)
4830 bitmap_ior_into (&ebb_global_regs
, df_get_live_out (bb
));
4831 if (lra_dump_file
!= NULL
)
4832 fprintf (lra_dump_file
, "\n");
4833 if (inherit_in_ebb (BB_HEAD (start_bb
), BB_END (bb
)))
4834 /* Remember that the EBB head and tail can change in
4836 update_ebb_live_info (BB_HEAD (start_bb
), BB_END (bb
));
4838 bitmap_clear (&ebb_global_regs
);
4839 bitmap_clear (&temp_bitmap
);
4840 bitmap_clear (&live_regs
);
4841 bitmap_clear (&check_only_regs
);
4844 timevar_pop (TV_LRA_INHERITANCE
);
4849 /* This page contains code to undo failed inheritance/split
4852 /* Current number of iteration undoing inheritance/split. */
4853 int lra_undo_inheritance_iter
;
4855 /* Fix BB live info LIVE after removing pseudos created on pass doing
4856 inheritance/split which are REMOVED_PSEUDOS. */
4858 fix_bb_live_info (bitmap live
, bitmap removed_pseudos
)
4863 EXECUTE_IF_SET_IN_BITMAP (removed_pseudos
, 0, regno
, bi
)
4864 if (bitmap_clear_bit (live
, regno
))
4865 bitmap_set_bit (live
, lra_reg_info
[regno
].restore_regno
);
4868 /* Return regno of the (subreg of) REG. Otherwise, return a negative
4873 if (GET_CODE (reg
) == SUBREG
)
4874 reg
= SUBREG_REG (reg
);
4880 /* Remove inheritance/split pseudos which are in REMOVE_PSEUDOS and
4881 return true if we did any change. The undo transformations for
4882 inheritance looks like
4886 p <- i, i <- p, and i <- i3
4887 where p is original pseudo from which inheritance pseudo i was
4888 created, i and i3 are removed inheritance pseudos, i2 is another
4889 not removed inheritance pseudo. All split pseudos or other
4890 occurrences of removed inheritance pseudos are changed on the
4891 corresponding original pseudos.
4893 The function also schedules insns changed and created during
4894 inheritance/split pass for processing by the subsequent constraint
4897 remove_inheritance_pseudos (bitmap remove_pseudos
)
4900 int regno
, sregno
, prev_sregno
, dregno
, restore_regno
;
4901 rtx set
, prev_set
, prev_insn
;
4902 bool change_p
, done_p
;
4904 change_p
= ! bitmap_empty_p (remove_pseudos
);
4905 /* We can not finish the function right away if CHANGE_P is true
4906 because we need to marks insns affected by previous
4907 inheritance/split pass for processing by the subsequent
4911 fix_bb_live_info (df_get_live_in (bb
), remove_pseudos
);
4912 fix_bb_live_info (df_get_live_out (bb
), remove_pseudos
);
4913 FOR_BB_INSNS_REVERSE (bb
, curr_insn
)
4915 if (! INSN_P (curr_insn
))
4918 sregno
= dregno
= -1;
4919 if (change_p
&& NONDEBUG_INSN_P (curr_insn
)
4920 && (set
= single_set (curr_insn
)) != NULL_RTX
)
4922 dregno
= get_regno (SET_DEST (set
));
4923 sregno
= get_regno (SET_SRC (set
));
4926 if (sregno
>= 0 && dregno
>= 0)
4928 if ((bitmap_bit_p (remove_pseudos
, sregno
)
4929 && (lra_reg_info
[sregno
].restore_regno
== dregno
4930 || (bitmap_bit_p (remove_pseudos
, dregno
)
4931 && (lra_reg_info
[sregno
].restore_regno
4932 == lra_reg_info
[dregno
].restore_regno
))))
4933 || (bitmap_bit_p (remove_pseudos
, dregno
)
4934 && lra_reg_info
[dregno
].restore_regno
== sregno
))
4935 /* One of the following cases:
4936 original <- removed inheritance pseudo
4937 removed inherit pseudo <- another removed inherit pseudo
4938 removed inherit pseudo <- original pseudo
4940 removed_split_pseudo <- original_reg
4941 original_reg <- removed_split_pseudo */
4943 if (lra_dump_file
!= NULL
)
4945 fprintf (lra_dump_file
, " Removing %s:\n",
4946 bitmap_bit_p (&lra_split_regs
, sregno
)
4947 || bitmap_bit_p (&lra_split_regs
, dregno
)
4948 ? "split" : "inheritance");
4949 dump_insn_slim (lra_dump_file
, curr_insn
);
4951 lra_set_insn_deleted (curr_insn
);
4954 else if (bitmap_bit_p (remove_pseudos
, sregno
)
4955 && bitmap_bit_p (&lra_inheritance_pseudos
, sregno
))
4957 /* Search the following pattern:
4958 inherit_or_split_pseudo1 <- inherit_or_split_pseudo2
4959 original_pseudo <- inherit_or_split_pseudo1
4960 where the 2nd insn is the current insn and
4961 inherit_or_split_pseudo2 is not removed. If it is found,
4962 change the current insn onto:
4963 original_pseudo <- inherit_or_split_pseudo2. */
4964 for (prev_insn
= PREV_INSN (curr_insn
);
4965 prev_insn
!= NULL_RTX
&& ! NONDEBUG_INSN_P (prev_insn
);
4966 prev_insn
= PREV_INSN (prev_insn
))
4968 if (prev_insn
!= NULL_RTX
&& BLOCK_FOR_INSN (prev_insn
) == bb
4969 && (prev_set
= single_set (prev_insn
)) != NULL_RTX
4970 /* There should be no subregs in insn we are
4971 searching because only the original reg might
4972 be in subreg when we changed the mode of
4973 load/store for splitting. */
4974 && REG_P (SET_DEST (prev_set
))
4975 && REG_P (SET_SRC (prev_set
))
4976 && (int) REGNO (SET_DEST (prev_set
)) == sregno
4977 && ((prev_sregno
= REGNO (SET_SRC (prev_set
)))
4978 >= FIRST_PSEUDO_REGISTER
)
4979 /* As we consider chain of inheritance or
4980 splitting described in above comment we should
4981 check that sregno and prev_sregno were
4982 inheritance/split pseudos created from the
4983 same original regno. */
4984 && (lra_reg_info
[sregno
].restore_regno
4985 == lra_reg_info
[prev_sregno
].restore_regno
)
4986 && ! bitmap_bit_p (remove_pseudos
, prev_sregno
))
4988 lra_assert (GET_MODE (SET_SRC (prev_set
))
4989 == GET_MODE (regno_reg_rtx
[sregno
]));
4990 if (GET_CODE (SET_SRC (set
)) == SUBREG
)
4991 SUBREG_REG (SET_SRC (set
)) = SET_SRC (prev_set
);
4993 SET_SRC (set
) = SET_SRC (prev_set
);
4994 lra_push_insn_and_update_insn_regno_info (curr_insn
);
4995 lra_set_used_insn_alternative_by_uid
4996 (INSN_UID (curr_insn
), -1);
4998 if (lra_dump_file
!= NULL
)
5000 fprintf (lra_dump_file
, " Change reload insn:\n");
5001 dump_insn_slim (lra_dump_file
, curr_insn
);
5008 struct lra_insn_reg
*reg
;
5009 bool restored_regs_p
= false;
5010 bool kept_regs_p
= false;
5012 curr_id
= lra_get_insn_recog_data (curr_insn
);
5013 for (reg
= curr_id
->regs
; reg
!= NULL
; reg
= reg
->next
)
5016 restore_regno
= lra_reg_info
[regno
].restore_regno
;
5017 if (restore_regno
>= 0)
5019 if (change_p
&& bitmap_bit_p (remove_pseudos
, regno
))
5021 substitute_pseudo (&curr_insn
, regno
,
5022 regno_reg_rtx
[restore_regno
]);
5023 restored_regs_p
= true;
5029 if (NONDEBUG_INSN_P (curr_insn
) && kept_regs_p
)
5031 /* The instruction has changed since the previous
5032 constraints pass. */
5033 lra_push_insn_and_update_insn_regno_info (curr_insn
);
5034 lra_set_used_insn_alternative_by_uid
5035 (INSN_UID (curr_insn
), -1);
5037 else if (restored_regs_p
)
5038 /* The instruction has been restored to the form that
5039 it had during the previous constraints pass. */
5040 lra_update_insn_regno_info (curr_insn
);
5041 if (restored_regs_p
&& lra_dump_file
!= NULL
)
5043 fprintf (lra_dump_file
, " Insn after restoring regs:\n");
5044 dump_insn_slim (lra_dump_file
, curr_insn
);
5052 /* Entry function for undoing inheritance/split transformation. Return true
5053 if we did any RTL change in this pass. */
5055 lra_undo_inheritance (void)
5058 int restore_regno
, hard_regno
;
5059 int n_all_inherit
, n_inherit
, n_all_split
, n_split
;
5060 bitmap_head remove_pseudos
;
5064 lra_undo_inheritance_iter
++;
5065 if (lra_undo_inheritance_iter
> LRA_MAX_INHERITANCE_PASSES
)
5067 if (lra_dump_file
!= NULL
)
5068 fprintf (lra_dump_file
,
5069 "\n********** Undoing inheritance #%d: **********\n\n",
5070 lra_undo_inheritance_iter
);
5071 bitmap_initialize (&remove_pseudos
, ®_obstack
);
5072 n_inherit
= n_all_inherit
= 0;
5073 EXECUTE_IF_SET_IN_BITMAP (&lra_inheritance_pseudos
, 0, regno
, bi
)
5074 if (lra_reg_info
[regno
].restore_regno
>= 0)
5077 if (reg_renumber
[regno
] < 0)
5078 bitmap_set_bit (&remove_pseudos
, regno
);
5082 if (lra_dump_file
!= NULL
&& n_all_inherit
!= 0)
5083 fprintf (lra_dump_file
, "Inherit %d out of %d (%.2f%%)\n",
5084 n_inherit
, n_all_inherit
,
5085 (double) n_inherit
/ n_all_inherit
* 100);
5086 n_split
= n_all_split
= 0;
5087 EXECUTE_IF_SET_IN_BITMAP (&lra_split_regs
, 0, regno
, bi
)
5088 if ((restore_regno
= lra_reg_info
[regno
].restore_regno
) >= 0)
5091 hard_regno
= (restore_regno
>= FIRST_PSEUDO_REGISTER
5092 ? reg_renumber
[restore_regno
] : restore_regno
);
5093 if (hard_regno
< 0 || reg_renumber
[regno
] == hard_regno
)
5094 bitmap_set_bit (&remove_pseudos
, regno
);
5098 if (lra_dump_file
!= NULL
)
5099 fprintf (lra_dump_file
, " Keep split r%d (orig=r%d)\n",
5100 regno
, restore_regno
);
5103 if (lra_dump_file
!= NULL
&& n_all_split
!= 0)
5104 fprintf (lra_dump_file
, "Split %d out of %d (%.2f%%)\n",
5105 n_split
, n_all_split
,
5106 (double) n_split
/ n_all_split
* 100);
5107 change_p
= remove_inheritance_pseudos (&remove_pseudos
);
5108 bitmap_clear (&remove_pseudos
);
5109 /* Clear restore_regnos. */
5110 EXECUTE_IF_SET_IN_BITMAP (&lra_inheritance_pseudos
, 0, regno
, bi
)
5111 lra_reg_info
[regno
].restore_regno
= -1;
5112 EXECUTE_IF_SET_IN_BITMAP (&lra_split_regs
, 0, regno
, bi
)
5113 lra_reg_info
[regno
].restore_regno
= -1;