1 /* Code for RTL transformations to satisfy insn constraints.
2 Copyright (C) 2010-2021 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"
118 #include "memmodel.h"
126 #include "addresses.h"
129 #include "rtl-error.h"
132 #include "print-rtl.h"
133 #include "function-abi.h"
134 #include "rtl-iter.h"
136 /* Value of LRA_CURR_RELOAD_NUM at the beginning of BB of the current
137 insn. Remember that LRA_CURR_RELOAD_NUM is the number of emitted
139 static int bb_reload_num
;
141 /* The current insn being processed and corresponding its single set
142 (NULL otherwise), its data (basic block, the insn data, the insn
143 static data, and the mode of each operand). */
144 static rtx_insn
*curr_insn
;
145 static rtx curr_insn_set
;
146 static basic_block curr_bb
;
147 static lra_insn_recog_data_t curr_id
;
148 static struct lra_static_insn_data
*curr_static_id
;
149 static machine_mode curr_operand_mode
[MAX_RECOG_OPERANDS
];
150 /* Mode of the register substituted by its equivalence with VOIDmode
151 (e.g. constant) and whose subreg is given operand of the current
152 insn. VOIDmode in all other cases. */
153 static machine_mode original_subreg_reg_mode
[MAX_RECOG_OPERANDS
];
157 /* Start numbers for new registers and insns at the current constraints
159 static int new_regno_start
;
160 static int new_insn_uid_start
;
162 /* If LOC is nonnull, strip any outer subreg from it. */
164 strip_subreg (rtx
*loc
)
166 return loc
&& GET_CODE (*loc
) == SUBREG
? &SUBREG_REG (*loc
) : loc
;
169 /* Return hard regno of REGNO or if it is was not assigned to a hard
170 register, use a hard register from its allocno class. */
172 get_try_hard_regno (int regno
)
175 enum reg_class rclass
;
177 if ((hard_regno
= regno
) >= FIRST_PSEUDO_REGISTER
)
178 hard_regno
= lra_get_regno_hard_regno (regno
);
181 rclass
= lra_get_allocno_class (regno
);
182 if (rclass
== NO_REGS
)
184 return ira_class_hard_regs
[rclass
][0];
187 /* Return the hard regno of X after removing its subreg. If X is not
188 a register or a subreg of a register, return -1. If X is a pseudo,
189 use its assignment. If FINAL_P return the final hard regno which will
190 be after elimination. */
192 get_hard_regno (rtx x
, bool final_p
)
199 reg
= SUBREG_REG (x
);
202 if (! HARD_REGISTER_NUM_P (hard_regno
= REGNO (reg
)))
203 hard_regno
= lra_get_regno_hard_regno (hard_regno
);
207 hard_regno
= lra_get_elimination_hard_regno (hard_regno
);
209 hard_regno
+= subreg_regno_offset (hard_regno
, GET_MODE (reg
),
210 SUBREG_BYTE (x
), GET_MODE (x
));
214 /* If REGNO is a hard register or has been allocated a hard register,
215 return the class of that register. If REGNO is a reload pseudo
216 created by the current constraints pass, return its allocno class.
217 Return NO_REGS otherwise. */
218 static enum reg_class
219 get_reg_class (int regno
)
223 if (! HARD_REGISTER_NUM_P (hard_regno
= regno
))
224 hard_regno
= lra_get_regno_hard_regno (regno
);
227 hard_regno
= lra_get_elimination_hard_regno (hard_regno
);
228 return REGNO_REG_CLASS (hard_regno
);
230 if (regno
>= new_regno_start
)
231 return lra_get_allocno_class (regno
);
235 /* Return true if REG satisfies (or will satisfy) reg class constraint
236 CL. Use elimination first if REG is a hard register. If REG is a
237 reload pseudo created by this constraints pass, assume that it will
238 be allocated a hard register from its allocno class, but allow that
239 class to be narrowed to CL if it is currently a superset of CL and
242 - ALLOW_ALL_RELOAD_CLASS_CHANGES_P is true or
243 - the instruction we're processing is not a reload move.
245 If NEW_CLASS is nonnull, set *NEW_CLASS to the new allocno class of
246 REGNO (reg), or NO_REGS if no change in its class was needed. */
248 in_class_p (rtx reg
, enum reg_class cl
, enum reg_class
*new_class
,
249 bool allow_all_reload_class_changes_p
= false)
251 enum reg_class rclass
, common_class
;
252 machine_mode reg_mode
;
254 int class_size
, hard_regno
, nregs
, i
, j
;
255 int regno
= REGNO (reg
);
257 if (new_class
!= NULL
)
258 *new_class
= NO_REGS
;
259 if (regno
< FIRST_PSEUDO_REGISTER
)
262 rtx
*final_loc
= &final_reg
;
264 lra_eliminate_reg_if_possible (final_loc
);
265 return TEST_HARD_REG_BIT (reg_class_contents
[cl
], REGNO (*final_loc
));
267 reg_mode
= GET_MODE (reg
);
268 rclass
= get_reg_class (regno
);
269 src
= curr_insn_set
!= NULL
? SET_SRC (curr_insn_set
) : NULL
;
270 if (regno
< new_regno_start
271 /* Do not allow the constraints for reload instructions to
272 influence the classes of new pseudos. These reloads are
273 typically moves that have many alternatives, and restricting
274 reload pseudos for one alternative may lead to situations
275 where other reload pseudos are no longer allocatable. */
276 || (!allow_all_reload_class_changes_p
277 && INSN_UID (curr_insn
) >= new_insn_uid_start
279 && ((REG_P (src
) || MEM_P (src
))
280 || (GET_CODE (src
) == SUBREG
281 && (REG_P (SUBREG_REG (src
)) || MEM_P (SUBREG_REG (src
)))))))
282 /* When we don't know what class will be used finally for reload
283 pseudos, we use ALL_REGS. */
284 return ((regno
>= new_regno_start
&& rclass
== ALL_REGS
)
285 || (rclass
!= NO_REGS
&& ira_class_subset_p
[rclass
][cl
]
286 && ! hard_reg_set_subset_p (reg_class_contents
[cl
],
287 lra_no_alloc_regs
)));
290 common_class
= ira_reg_class_subset
[rclass
][cl
];
291 if (new_class
!= NULL
)
292 *new_class
= common_class
;
293 if (hard_reg_set_subset_p (reg_class_contents
[common_class
],
296 /* Check that there are enough allocatable regs. */
297 class_size
= ira_class_hard_regs_num
[common_class
];
298 for (i
= 0; i
< class_size
; i
++)
300 hard_regno
= ira_class_hard_regs
[common_class
][i
];
301 nregs
= hard_regno_nregs (hard_regno
, reg_mode
);
304 for (j
= 0; j
< nregs
; j
++)
305 if (TEST_HARD_REG_BIT (lra_no_alloc_regs
, hard_regno
+ j
)
306 || ! TEST_HARD_REG_BIT (reg_class_contents
[common_class
],
316 /* Return true if REGNO satisfies a memory constraint. */
320 return get_reg_class (regno
) == NO_REGS
;
323 /* Return 1 if ADDR is a valid memory address for mode MODE in address
324 space AS, and check that each pseudo has the proper kind of hard
327 valid_address_p (machine_mode mode ATTRIBUTE_UNUSED
,
328 rtx addr
, addr_space_t as
)
330 #ifdef GO_IF_LEGITIMATE_ADDRESS
331 lra_assert (ADDR_SPACE_GENERIC_P (as
));
332 GO_IF_LEGITIMATE_ADDRESS (mode
, addr
, win
);
338 return targetm
.addr_space
.legitimate_address_p (mode
, addr
, 0, as
);
343 /* Temporarily eliminates registers in an address (for the lifetime of
345 class address_eliminator
{
347 address_eliminator (struct address_info
*ad
);
348 ~address_eliminator ();
351 struct address_info
*m_ad
;
359 address_eliminator::address_eliminator (struct address_info
*ad
)
361 m_base_loc (strip_subreg (ad
->base_term
)),
362 m_base_reg (NULL_RTX
),
363 m_index_loc (strip_subreg (ad
->index_term
)),
364 m_index_reg (NULL_RTX
)
366 if (m_base_loc
!= NULL
)
368 m_base_reg
= *m_base_loc
;
369 /* If we have non-legitimate address which is decomposed not in
370 the way we expected, don't do elimination here. In such case
371 the address will be reloaded and elimination will be done in
372 reload insn finally. */
373 if (REG_P (m_base_reg
))
374 lra_eliminate_reg_if_possible (m_base_loc
);
375 if (m_ad
->base_term2
!= NULL
)
376 *m_ad
->base_term2
= *m_ad
->base_term
;
378 if (m_index_loc
!= NULL
)
380 m_index_reg
= *m_index_loc
;
381 if (REG_P (m_index_reg
))
382 lra_eliminate_reg_if_possible (m_index_loc
);
386 address_eliminator::~address_eliminator ()
388 if (m_base_loc
&& *m_base_loc
!= m_base_reg
)
390 *m_base_loc
= m_base_reg
;
391 if (m_ad
->base_term2
!= NULL
)
392 *m_ad
->base_term2
= *m_ad
->base_term
;
394 if (m_index_loc
&& *m_index_loc
!= m_index_reg
)
395 *m_index_loc
= m_index_reg
;
398 /* Return true if the eliminated form of AD is a legitimate target address.
399 If OP is a MEM, AD is the address within OP, otherwise OP should be
400 ignored. CONSTRAINT is one constraint that the operand may need
403 valid_address_p (rtx op
, struct address_info
*ad
,
404 enum constraint_num constraint
)
406 address_eliminator
eliminator (ad
);
408 /* Allow a memory OP if it matches CONSTRAINT, even if CONSTRAINT is more
410 Need to extract memory from op for special memory constraint,
411 i.e. bcst_mem_operand in i386 backend. */
412 if (MEM_P (extract_mem_from_operand (op
))
413 && insn_extra_relaxed_memory_constraint (constraint
)
414 && constraint_satisfied_p (op
, constraint
))
417 return valid_address_p (ad
->mode
, *ad
->outer
, ad
->as
);
420 /* For special_memory_operand, it could be false for MEM_P (op),
421 i.e. bcst_mem_operand in i386 backend.
422 Extract and return real memory operand or op. */
424 extract_mem_from_operand (rtx op
)
426 for (rtx x
= op
;; x
= XEXP (x
, 0))
430 if (GET_RTX_LENGTH (GET_CODE (x
)) != 1
431 || GET_RTX_FORMAT (GET_CODE (x
))[0] != 'e')
437 /* Return true if the eliminated form of memory reference OP satisfies
438 extra (special) memory constraint CONSTRAINT. */
440 satisfies_memory_constraint_p (rtx op
, enum constraint_num constraint
)
442 struct address_info ad
;
443 rtx mem
= extract_mem_from_operand (op
);
447 decompose_mem_address (&ad
, mem
);
448 address_eliminator
eliminator (&ad
);
449 return constraint_satisfied_p (op
, constraint
);
452 /* Return true if the eliminated form of address AD satisfies extra
453 address constraint CONSTRAINT. */
455 satisfies_address_constraint_p (struct address_info
*ad
,
456 enum constraint_num constraint
)
458 address_eliminator
eliminator (ad
);
459 return constraint_satisfied_p (*ad
->outer
, constraint
);
462 /* Return true if the eliminated form of address OP satisfies extra
463 address constraint CONSTRAINT. */
465 satisfies_address_constraint_p (rtx op
, enum constraint_num constraint
)
467 struct address_info ad
;
469 decompose_lea_address (&ad
, &op
);
470 return satisfies_address_constraint_p (&ad
, constraint
);
473 /* Initiate equivalences for LRA. As we keep original equivalences
474 before any elimination, we need to make copies otherwise any change
475 in insns might change the equivalences. */
477 lra_init_equiv (void)
479 ira_expand_reg_equiv ();
480 for (int i
= FIRST_PSEUDO_REGISTER
; i
< max_reg_num (); i
++)
484 if ((res
= ira_reg_equiv
[i
].memory
) != NULL_RTX
)
485 ira_reg_equiv
[i
].memory
= copy_rtx (res
);
486 if ((res
= ira_reg_equiv
[i
].invariant
) != NULL_RTX
)
487 ira_reg_equiv
[i
].invariant
= copy_rtx (res
);
491 static rtx
loc_equivalence_callback (rtx
, const_rtx
, void *);
493 /* Update equivalence for REGNO. We need to this as the equivalence
494 might contain other pseudos which are changed by their
497 update_equiv (int regno
)
501 if ((x
= ira_reg_equiv
[regno
].memory
) != NULL_RTX
)
502 ira_reg_equiv
[regno
].memory
503 = simplify_replace_fn_rtx (x
, NULL_RTX
, loc_equivalence_callback
,
505 if ((x
= ira_reg_equiv
[regno
].invariant
) != NULL_RTX
)
506 ira_reg_equiv
[regno
].invariant
507 = simplify_replace_fn_rtx (x
, NULL_RTX
, loc_equivalence_callback
,
511 /* If we have decided to substitute X with another value, return that
512 value, otherwise return X. */
519 if (! REG_P (x
) || (regno
= REGNO (x
)) < FIRST_PSEUDO_REGISTER
520 || ! ira_reg_equiv
[regno
].defined_p
521 || ! ira_reg_equiv
[regno
].profitable_p
522 || lra_get_regno_hard_regno (regno
) >= 0)
524 if ((res
= ira_reg_equiv
[regno
].memory
) != NULL_RTX
)
526 if (targetm
.cannot_substitute_mem_equiv_p (res
))
530 if ((res
= ira_reg_equiv
[regno
].constant
) != NULL_RTX
)
532 if ((res
= ira_reg_equiv
[regno
].invariant
) != NULL_RTX
)
537 /* If we have decided to substitute X with the equivalent value,
538 return that value after elimination for INSN, otherwise return
541 get_equiv_with_elimination (rtx x
, rtx_insn
*insn
)
543 rtx res
= get_equiv (x
);
545 if (x
== res
|| CONSTANT_P (res
))
547 return lra_eliminate_regs_1 (insn
, res
, GET_MODE (res
),
548 false, false, 0, true);
551 /* Set up curr_operand_mode. */
553 init_curr_operand_mode (void)
555 int nop
= curr_static_id
->n_operands
;
556 for (int i
= 0; i
< nop
; i
++)
558 machine_mode mode
= GET_MODE (*curr_id
->operand_loc
[i
]);
559 if (mode
== VOIDmode
)
561 /* The .md mode for address operands is the mode of the
562 addressed value rather than the mode of the address itself. */
563 if (curr_id
->icode
>= 0 && curr_static_id
->operand
[i
].is_address
)
566 mode
= curr_static_id
->operand
[i
].mode
;
568 curr_operand_mode
[i
] = mode
;
574 /* The page contains code to reuse input reloads. */
576 /* Structure describes input reload of the current insns. */
579 /* True for input reload of matched operands. */
581 /* Reloaded value. */
583 /* Reload pseudo used. */
587 /* The number of elements in the following array. */
588 static int curr_insn_input_reloads_num
;
589 /* Array containing info about input reloads. It is used to find the
590 same input reload and reuse the reload pseudo in this case. */
591 static struct input_reload curr_insn_input_reloads
[LRA_MAX_INSN_RELOADS
];
593 /* Initiate data concerning reuse of input reloads for the current
596 init_curr_insn_input_reloads (void)
598 curr_insn_input_reloads_num
= 0;
601 /* The canonical form of an rtx inside a MEM is not necessarily the same as the
602 canonical form of the rtx outside the MEM. Fix this up in the case that
603 we're reloading an address (and therefore pulling it outside a MEM). */
605 canonicalize_reload_addr (rtx addr
)
607 subrtx_var_iterator::array_type array
;
608 FOR_EACH_SUBRTX_VAR (iter
, array
, addr
, NONCONST
)
611 if (GET_CODE (x
) == MULT
&& CONST_INT_P (XEXP (x
, 1)))
613 const HOST_WIDE_INT ci
= INTVAL (XEXP (x
, 1));
614 const int pwr2
= exact_log2 (ci
);
617 /* Rewrite this to use a shift instead, which is canonical when
619 PUT_CODE (x
, ASHIFT
);
620 XEXP (x
, 1) = GEN_INT (pwr2
);
628 /* Create a new pseudo using MODE, RCLASS, ORIGINAL or reuse an existing
629 reload pseudo. Don't reuse an existing reload pseudo if IN_SUBREG_P
630 is true and the reused pseudo should be wrapped up in a SUBREG.
631 The result pseudo is returned through RESULT_REG. Return TRUE if we
632 created a new pseudo, FALSE if we reused an existing reload pseudo.
633 Use TITLE to describe new registers for debug purposes. */
635 get_reload_reg (enum op_type type
, machine_mode mode
, rtx original
,
636 enum reg_class rclass
, bool in_subreg_p
,
637 const char *title
, rtx
*result_reg
)
640 enum reg_class new_class
;
641 bool unique_p
= false;
645 /* Output reload registers tend to start out with a conservative
646 choice of register class. Usually this is ALL_REGS, although
647 a target might narrow it (for performance reasons) through
648 targetm.preferred_reload_class. It's therefore quite common
649 for a reload instruction to require a more restrictive class
650 than the class that was originally assigned to the reload register.
652 In these situations, it's more efficient to refine the choice
653 of register class rather than create a second reload register.
654 This also helps to avoid cycling for registers that are only
655 used by reload instructions. */
657 && (int) REGNO (original
) >= new_regno_start
658 && INSN_UID (curr_insn
) >= new_insn_uid_start
659 && in_class_p (original
, rclass
, &new_class
, true))
661 unsigned int regno
= REGNO (original
);
662 if (lra_dump_file
!= NULL
)
664 fprintf (lra_dump_file
, " Reuse r%d for output ", regno
);
665 dump_value_slim (lra_dump_file
, original
, 1);
667 if (new_class
!= lra_get_allocno_class (regno
))
668 lra_change_class (regno
, new_class
, ", change to", false);
669 if (lra_dump_file
!= NULL
)
670 fprintf (lra_dump_file
, "\n");
671 *result_reg
= original
;
675 = lra_create_new_reg_with_unique_value (mode
, original
, rclass
, title
);
678 /* Prevent reuse value of expression with side effects,
679 e.g. volatile memory. */
680 if (! side_effects_p (original
))
681 for (i
= 0; i
< curr_insn_input_reloads_num
; i
++)
683 if (! curr_insn_input_reloads
[i
].match_p
684 && rtx_equal_p (curr_insn_input_reloads
[i
].input
, original
)
685 && in_class_p (curr_insn_input_reloads
[i
].reg
, rclass
, &new_class
))
687 rtx reg
= curr_insn_input_reloads
[i
].reg
;
689 /* If input is equal to original and both are VOIDmode,
690 GET_MODE (reg) might be still different from mode.
691 Ensure we don't return *result_reg with wrong mode. */
692 if (GET_MODE (reg
) != mode
)
696 if (maybe_lt (GET_MODE_SIZE (GET_MODE (reg
)),
697 GET_MODE_SIZE (mode
)))
699 reg
= lowpart_subreg (mode
, reg
, GET_MODE (reg
));
700 if (reg
== NULL_RTX
|| GET_CODE (reg
) != SUBREG
)
704 if (lra_dump_file
!= NULL
)
706 fprintf (lra_dump_file
, " Reuse r%d for reload ", regno
);
707 dump_value_slim (lra_dump_file
, original
, 1);
709 if (new_class
!= lra_get_allocno_class (regno
))
710 lra_change_class (regno
, new_class
, ", change to", false);
711 if (lra_dump_file
!= NULL
)
712 fprintf (lra_dump_file
, "\n");
715 /* If we have an input reload with a different mode, make sure it
716 will get a different hard reg. */
717 else if (REG_P (original
)
718 && REG_P (curr_insn_input_reloads
[i
].input
)
719 && REGNO (original
) == REGNO (curr_insn_input_reloads
[i
].input
)
720 && (GET_MODE (original
)
721 != GET_MODE (curr_insn_input_reloads
[i
].input
)))
724 *result_reg
= (unique_p
725 ? lra_create_new_reg_with_unique_value
726 : lra_create_new_reg
) (mode
, original
, rclass
, title
);
727 lra_assert (curr_insn_input_reloads_num
< LRA_MAX_INSN_RELOADS
);
728 curr_insn_input_reloads
[curr_insn_input_reloads_num
].input
= original
;
729 curr_insn_input_reloads
[curr_insn_input_reloads_num
].match_p
= false;
730 curr_insn_input_reloads
[curr_insn_input_reloads_num
++].reg
= *result_reg
;
735 /* The page contains major code to choose the current insn alternative
736 and generate reloads for it. */
738 /* Return the offset from REGNO of the least significant register
741 This function is used to tell whether two registers satisfy
742 a matching constraint. (reg:MODE1 REGNO1) matches (reg:MODE2 REGNO2) if:
744 REGNO1 + lra_constraint_offset (REGNO1, MODE1)
745 == REGNO2 + lra_constraint_offset (REGNO2, MODE2) */
747 lra_constraint_offset (int regno
, machine_mode mode
)
749 lra_assert (regno
< FIRST_PSEUDO_REGISTER
);
751 scalar_int_mode int_mode
;
753 && is_a
<scalar_int_mode
> (mode
, &int_mode
)
754 && GET_MODE_SIZE (int_mode
) > UNITS_PER_WORD
)
755 return hard_regno_nregs (regno
, mode
) - 1;
759 /* Like rtx_equal_p except that it allows a REG and a SUBREG to match
760 if they are the same hard reg, and has special hacks for
761 auto-increment and auto-decrement. This is specifically intended for
762 process_alt_operands to use in determining whether two operands
763 match. X is the operand whose number is the lower of the two.
765 It is supposed that X is the output operand and Y is the input
766 operand. Y_HARD_REGNO is the final hard regno of register Y or
767 register in subreg Y as we know it now. Otherwise, it is a
770 operands_match_p (rtx x
, rtx y
, int y_hard_regno
)
773 RTX_CODE code
= GET_CODE (x
);
778 if ((code
== REG
|| (code
== SUBREG
&& REG_P (SUBREG_REG (x
))))
779 && (REG_P (y
) || (GET_CODE (y
) == SUBREG
&& REG_P (SUBREG_REG (y
)))))
783 i
= get_hard_regno (x
, false);
787 if ((j
= y_hard_regno
) < 0)
790 i
+= lra_constraint_offset (i
, GET_MODE (x
));
791 j
+= lra_constraint_offset (j
, GET_MODE (y
));
796 /* If two operands must match, because they are really a single
797 operand of an assembler insn, then two post-increments are invalid
798 because the assembler insn would increment only once. On the
799 other hand, a post-increment matches ordinary indexing if the
800 post-increment is the output operand. */
801 if (code
== POST_DEC
|| code
== POST_INC
|| code
== POST_MODIFY
)
802 return operands_match_p (XEXP (x
, 0), y
, y_hard_regno
);
804 /* Two pre-increments are invalid because the assembler insn would
805 increment only once. On the other hand, a pre-increment matches
806 ordinary indexing if the pre-increment is the input operand. */
807 if (GET_CODE (y
) == PRE_DEC
|| GET_CODE (y
) == PRE_INC
808 || GET_CODE (y
) == PRE_MODIFY
)
809 return operands_match_p (x
, XEXP (y
, 0), -1);
813 if (code
== REG
&& REG_P (y
))
814 return REGNO (x
) == REGNO (y
);
816 if (code
== REG
&& GET_CODE (y
) == SUBREG
&& REG_P (SUBREG_REG (y
))
817 && x
== SUBREG_REG (y
))
819 if (GET_CODE (y
) == REG
&& code
== SUBREG
&& REG_P (SUBREG_REG (x
))
820 && SUBREG_REG (x
) == y
)
823 /* Now we have disposed of all the cases in which different rtx
825 if (code
!= GET_CODE (y
))
828 /* (MULT:SI x y) and (MULT:HI x y) are NOT equivalent. */
829 if (GET_MODE (x
) != GET_MODE (y
))
838 if (!same_vector_encodings_p (x
, y
))
843 return label_ref_label (x
) == label_ref_label (y
);
845 return XSTR (x
, 0) == XSTR (y
, 0);
851 /* Compare the elements. If any pair of corresponding elements fail
852 to match, return false for the whole things. */
854 fmt
= GET_RTX_FORMAT (code
);
855 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
861 if (XWINT (x
, i
) != XWINT (y
, i
))
866 if (XINT (x
, i
) != XINT (y
, i
))
871 if (maybe_ne (SUBREG_BYTE (x
), SUBREG_BYTE (y
)))
876 val
= operands_match_p (XEXP (x
, i
), XEXP (y
, i
), -1);
885 if (XVECLEN (x
, i
) != XVECLEN (y
, i
))
887 for (j
= XVECLEN (x
, i
) - 1; j
>= 0; --j
)
889 val
= operands_match_p (XVECEXP (x
, i
, j
), XVECEXP (y
, i
, j
), -1);
895 /* It is believed that rtx's at this level will never
896 contain anything but integers and other rtx's, except for
897 within LABEL_REFs and SYMBOL_REFs. */
905 /* True if X is a constant that can be forced into the constant pool.
906 MODE is the mode of the operand, or VOIDmode if not known. */
907 #define CONST_POOL_OK_P(MODE, X) \
908 ((MODE) != VOIDmode \
910 && GET_CODE (X) != HIGH \
911 && GET_MODE_SIZE (MODE).is_constant () \
912 && !targetm.cannot_force_const_mem (MODE, X))
914 /* True if C is a non-empty register class that has too few registers
915 to be safely used as a reload target class. */
916 #define SMALL_REGISTER_CLASS_P(C) \
917 (ira_class_hard_regs_num [(C)] == 1 \
918 || (ira_class_hard_regs_num [(C)] >= 1 \
919 && targetm.class_likely_spilled_p (C)))
921 /* If REG is a reload pseudo, try to make its class satisfying CL. */
923 narrow_reload_pseudo_class (rtx reg
, enum reg_class cl
)
925 enum reg_class rclass
;
927 /* Do not make more accurate class from reloads generated. They are
928 mostly moves with a lot of constraints. Making more accurate
929 class may results in very narrow class and impossibility of find
930 registers for several reloads of one insn. */
931 if (INSN_UID (curr_insn
) >= new_insn_uid_start
)
933 if (GET_CODE (reg
) == SUBREG
)
934 reg
= SUBREG_REG (reg
);
935 if (! REG_P (reg
) || (int) REGNO (reg
) < new_regno_start
)
937 if (in_class_p (reg
, cl
, &rclass
) && rclass
!= cl
)
938 lra_change_class (REGNO (reg
), rclass
, " Change to", true);
941 /* Searches X for any reference to a reg with the same value as REGNO,
942 returning the rtx of the reference found if any. Otherwise,
945 regno_val_use_in (unsigned int regno
, rtx x
)
951 if (REG_P (x
) && lra_reg_info
[REGNO (x
)].val
== lra_reg_info
[regno
].val
)
954 fmt
= GET_RTX_FORMAT (GET_CODE (x
));
955 for (i
= GET_RTX_LENGTH (GET_CODE (x
)) - 1; i
>= 0; i
--)
959 if ((tem
= regno_val_use_in (regno
, XEXP (x
, i
))))
962 else if (fmt
[i
] == 'E')
963 for (j
= XVECLEN (x
, i
) - 1; j
>= 0; j
--)
964 if ((tem
= regno_val_use_in (regno
, XVECEXP (x
, i
, j
))))
971 /* Return true if all current insn non-output operands except INS (it
972 has a negaitve end marker) do not use pseudos with the same value
975 check_conflict_input_operands (int regno
, signed char *ins
)
978 int n_operands
= curr_static_id
->n_operands
;
980 for (int nop
= 0; nop
< n_operands
; nop
++)
981 if (! curr_static_id
->operand
[nop
].is_operator
982 && curr_static_id
->operand
[nop
].type
!= OP_OUT
)
984 for (int i
= 0; (in
= ins
[i
]) >= 0; i
++)
988 && regno_val_use_in (regno
, *curr_id
->operand_loc
[nop
]) != NULL_RTX
)
994 /* Generate reloads for matching OUT and INS (array of input operand
995 numbers with end marker -1) with reg class GOAL_CLASS, considering
996 output operands OUTS (similar array to INS) needing to be in different
997 registers. Add input and output reloads correspondingly to the lists
998 *BEFORE and *AFTER. OUT might be negative. In this case we generate
999 input reloads for matched input operands INS. EARLY_CLOBBER_P is a flag
1000 that the output operand is early clobbered for chosen alternative. */
1002 match_reload (signed char out
, signed char *ins
, signed char *outs
,
1003 enum reg_class goal_class
, rtx_insn
**before
,
1004 rtx_insn
**after
, bool early_clobber_p
)
1008 rtx new_in_reg
, new_out_reg
, reg
;
1009 machine_mode inmode
, outmode
;
1010 rtx in_rtx
= *curr_id
->operand_loc
[ins
[0]];
1011 rtx out_rtx
= out
< 0 ? in_rtx
: *curr_id
->operand_loc
[out
];
1013 inmode
= curr_operand_mode
[ins
[0]];
1014 outmode
= out
< 0 ? inmode
: curr_operand_mode
[out
];
1015 push_to_sequence (*before
);
1016 if (inmode
!= outmode
)
1018 /* process_alt_operands has already checked that the mode sizes
1020 if (partial_subreg_p (outmode
, inmode
))
1023 = lra_create_new_reg_with_unique_value (inmode
, in_rtx
,
1025 new_out_reg
= gen_lowpart_SUBREG (outmode
, reg
);
1026 LRA_SUBREG_P (new_out_reg
) = 1;
1027 /* If the input reg is dying here, we can use the same hard
1028 register for REG and IN_RTX. We do it only for original
1029 pseudos as reload pseudos can die although original
1030 pseudos still live where reload pseudos dies. */
1031 if (REG_P (in_rtx
) && (int) REGNO (in_rtx
) < lra_new_regno_start
1032 && find_regno_note (curr_insn
, REG_DEAD
, REGNO (in_rtx
))
1033 && (!early_clobber_p
1034 || check_conflict_input_operands(REGNO (in_rtx
), ins
)))
1035 lra_assign_reg_val (REGNO (in_rtx
), REGNO (reg
));
1040 = lra_create_new_reg_with_unique_value (outmode
, out_rtx
,
1042 new_in_reg
= gen_lowpart_SUBREG (inmode
, reg
);
1043 /* NEW_IN_REG is non-paradoxical subreg. We don't want
1044 NEW_OUT_REG living above. We add clobber clause for
1045 this. This is just a temporary clobber. We can remove
1046 it at the end of LRA work. */
1047 rtx_insn
*clobber
= emit_clobber (new_out_reg
);
1048 LRA_TEMP_CLOBBER_P (PATTERN (clobber
)) = 1;
1049 LRA_SUBREG_P (new_in_reg
) = 1;
1050 if (GET_CODE (in_rtx
) == SUBREG
)
1052 rtx subreg_reg
= SUBREG_REG (in_rtx
);
1054 /* If SUBREG_REG is dying here and sub-registers IN_RTX
1055 and NEW_IN_REG are similar, we can use the same hard
1056 register for REG and SUBREG_REG. */
1057 if (REG_P (subreg_reg
)
1058 && (int) REGNO (subreg_reg
) < lra_new_regno_start
1059 && GET_MODE (subreg_reg
) == outmode
1060 && known_eq (SUBREG_BYTE (in_rtx
), SUBREG_BYTE (new_in_reg
))
1061 && find_regno_note (curr_insn
, REG_DEAD
, REGNO (subreg_reg
))
1062 && (! early_clobber_p
1063 || check_conflict_input_operands (REGNO (subreg_reg
),
1065 lra_assign_reg_val (REGNO (subreg_reg
), REGNO (reg
));
1071 /* Pseudos have values -- see comments for lra_reg_info.
1072 Different pseudos with the same value do not conflict even if
1073 they live in the same place. When we create a pseudo we
1074 assign value of original pseudo (if any) from which we
1075 created the new pseudo. If we create the pseudo from the
1076 input pseudo, the new pseudo will have no conflict with the
1077 input pseudo which is wrong when the input pseudo lives after
1078 the insn and as the new pseudo value is changed by the insn
1079 output. Therefore we create the new pseudo from the output
1080 except the case when we have single matched dying input
1083 We cannot reuse the current output register because we might
1084 have a situation like "a <- a op b", where the constraints
1085 force the second input operand ("b") to match the output
1086 operand ("a"). "b" must then be copied into a new register
1087 so that it doesn't clobber the current value of "a".
1089 We cannot use the same value if the output pseudo is
1090 early clobbered or the input pseudo is mentioned in the
1091 output, e.g. as an address part in memory, because
1092 output reload will actually extend the pseudo liveness.
1093 We don't care about eliminable hard regs here as we are
1094 interesting only in pseudos. */
1096 /* Matching input's register value is the same as one of the other
1097 output operand. Output operands in a parallel insn must be in
1098 different registers. */
1099 out_conflict
= false;
1102 for (i
= 0; outs
[i
] >= 0; i
++)
1104 rtx other_out_rtx
= *curr_id
->operand_loc
[outs
[i
]];
1105 if (outs
[i
] != out
&& REG_P (other_out_rtx
)
1106 && (regno_val_use_in (REGNO (in_rtx
), other_out_rtx
)
1109 out_conflict
= true;
1115 new_in_reg
= new_out_reg
1116 = (! early_clobber_p
&& ins
[1] < 0 && REG_P (in_rtx
)
1117 && (int) REGNO (in_rtx
) < lra_new_regno_start
1118 && find_regno_note (curr_insn
, REG_DEAD
, REGNO (in_rtx
))
1119 && (! early_clobber_p
1120 || check_conflict_input_operands (REGNO (in_rtx
), ins
))
1122 || regno_val_use_in (REGNO (in_rtx
), out_rtx
) == NULL_RTX
)
1124 ? lra_create_new_reg (inmode
, in_rtx
, goal_class
, "")
1125 : lra_create_new_reg_with_unique_value (outmode
, out_rtx
,
1128 /* In operand can be got from transformations before processing insn
1129 constraints. One example of such transformations is subreg
1130 reloading (see function simplify_operand_subreg). The new
1131 pseudos created by the transformations might have inaccurate
1132 class (ALL_REGS) and we should make their classes more
1134 narrow_reload_pseudo_class (in_rtx
, goal_class
);
1135 lra_emit_move (copy_rtx (new_in_reg
), in_rtx
);
1136 *before
= get_insns ();
1138 /* Add the new pseudo to consider values of subsequent input reload
1140 lra_assert (curr_insn_input_reloads_num
< LRA_MAX_INSN_RELOADS
);
1141 curr_insn_input_reloads
[curr_insn_input_reloads_num
].input
= in_rtx
;
1142 curr_insn_input_reloads
[curr_insn_input_reloads_num
].match_p
= true;
1143 curr_insn_input_reloads
[curr_insn_input_reloads_num
++].reg
= new_in_reg
;
1144 for (i
= 0; (in
= ins
[i
]) >= 0; i
++)
1145 if (GET_MODE (*curr_id
->operand_loc
[in
]) == VOIDmode
1146 || GET_MODE (new_in_reg
) == GET_MODE (*curr_id
->operand_loc
[in
]))
1147 *curr_id
->operand_loc
[in
] = new_in_reg
;
1151 (GET_MODE (new_out_reg
) == GET_MODE (*curr_id
->operand_loc
[in
]));
1152 *curr_id
->operand_loc
[in
] = new_out_reg
;
1154 lra_update_dups (curr_id
, ins
);
1157 /* See a comment for the input operand above. */
1158 narrow_reload_pseudo_class (out_rtx
, goal_class
);
1159 if (find_reg_note (curr_insn
, REG_UNUSED
, out_rtx
) == NULL_RTX
)
1161 reg
= SUBREG_P (out_rtx
) ? SUBREG_REG (out_rtx
) : out_rtx
;
1163 /* If we had strict_low_part, use it also in reload to keep other
1164 parts unchanged but do it only for regs as strict_low_part
1165 has no sense for memory and probably there is no insn pattern
1166 to match the reload insn in memory case. */
1167 if (out
>= 0 && curr_static_id
->operand
[out
].strict_low
&& REG_P (reg
))
1168 out_rtx
= gen_rtx_STRICT_LOW_PART (VOIDmode
, out_rtx
);
1169 lra_emit_move (out_rtx
, copy_rtx (new_out_reg
));
1171 *after
= get_insns ();
1174 *curr_id
->operand_loc
[out
] = new_out_reg
;
1175 lra_update_dup (curr_id
, out
);
1178 /* Return register class which is union of all reg classes in insn
1179 constraint alternative string starting with P. */
1180 static enum reg_class
1181 reg_class_from_constraints (const char *p
)
1184 enum reg_class op_class
= NO_REGS
;
1187 switch ((c
= *p
, len
= CONSTRAINT_LEN (c
, p
)), c
)
1194 op_class
= reg_class_subunion
[op_class
][GENERAL_REGS
];
1198 enum constraint_num cn
= lookup_constraint (p
);
1199 enum reg_class cl
= reg_class_for_constraint (cn
);
1202 if (insn_extra_address_constraint (cn
))
1204 = (reg_class_subunion
1205 [op_class
][base_reg_class (VOIDmode
, ADDR_SPACE_GENERIC
,
1206 ADDRESS
, SCRATCH
)]);
1210 op_class
= reg_class_subunion
[op_class
][cl
];
1213 while ((p
+= len
), c
);
1217 /* If OP is a register, return the class of the register as per
1218 get_reg_class, otherwise return NO_REGS. */
1219 static inline enum reg_class
1220 get_op_class (rtx op
)
1222 return REG_P (op
) ? get_reg_class (REGNO (op
)) : NO_REGS
;
1225 /* Return generated insn mem_pseudo:=val if TO_P or val:=mem_pseudo
1226 otherwise. If modes of MEM_PSEUDO and VAL are different, use
1227 SUBREG for VAL to make them equal. */
1229 emit_spill_move (bool to_p
, rtx mem_pseudo
, rtx val
)
1231 if (GET_MODE (mem_pseudo
) != GET_MODE (val
))
1233 /* Usually size of mem_pseudo is greater than val size but in
1234 rare cases it can be less as it can be defined by target
1235 dependent macro HARD_REGNO_CALLER_SAVE_MODE. */
1238 val
= gen_lowpart_SUBREG (GET_MODE (mem_pseudo
),
1239 GET_CODE (val
) == SUBREG
1240 ? SUBREG_REG (val
) : val
);
1241 LRA_SUBREG_P (val
) = 1;
1245 mem_pseudo
= gen_lowpart_SUBREG (GET_MODE (val
), mem_pseudo
);
1246 LRA_SUBREG_P (mem_pseudo
) = 1;
1249 return to_p
? gen_move_insn (mem_pseudo
, val
)
1250 : gen_move_insn (val
, mem_pseudo
);
1253 /* Process a special case insn (register move), return true if we
1254 don't need to process it anymore. INSN should be a single set
1255 insn. Set up that RTL was changed through CHANGE_P and that hook
1256 TARGET_SECONDARY_MEMORY_NEEDED says to use secondary memory through
1259 check_and_process_move (bool *change_p
, bool *sec_mem_p ATTRIBUTE_UNUSED
)
1262 rtx dest
, src
, dreg
, sreg
, new_reg
, scratch_reg
;
1264 enum reg_class dclass
, sclass
, secondary_class
;
1265 secondary_reload_info sri
;
1267 lra_assert (curr_insn_set
!= NULL_RTX
);
1268 dreg
= dest
= SET_DEST (curr_insn_set
);
1269 sreg
= src
= SET_SRC (curr_insn_set
);
1270 if (GET_CODE (dest
) == SUBREG
)
1271 dreg
= SUBREG_REG (dest
);
1272 if (GET_CODE (src
) == SUBREG
)
1273 sreg
= SUBREG_REG (src
);
1274 if (! (REG_P (dreg
) || MEM_P (dreg
)) || ! (REG_P (sreg
) || MEM_P (sreg
)))
1276 sclass
= dclass
= NO_REGS
;
1278 dclass
= get_reg_class (REGNO (dreg
));
1279 gcc_assert (dclass
< LIM_REG_CLASSES
&& dclass
>= NO_REGS
);
1280 if (dclass
== ALL_REGS
)
1281 /* ALL_REGS is used for new pseudos created by transformations
1282 like reload of SUBREG_REG (see function
1283 simplify_operand_subreg). We don't know their class yet. We
1284 should figure out the class from processing the insn
1285 constraints not in this fast path function. Even if ALL_REGS
1286 were a right class for the pseudo, secondary_... hooks usually
1287 are not define for ALL_REGS. */
1290 sclass
= get_reg_class (REGNO (sreg
));
1291 gcc_assert (sclass
< LIM_REG_CLASSES
&& sclass
>= NO_REGS
);
1292 if (sclass
== ALL_REGS
)
1293 /* See comments above. */
1295 if (sclass
== NO_REGS
&& dclass
== NO_REGS
)
1297 if (targetm
.secondary_memory_needed (GET_MODE (src
), sclass
, dclass
)
1298 && ((sclass
!= NO_REGS
&& dclass
!= NO_REGS
)
1300 != targetm
.secondary_memory_needed_mode (GET_MODE (src
)))))
1305 if (! REG_P (dreg
) || ! REG_P (sreg
))
1307 sri
.prev_sri
= NULL
;
1308 sri
.icode
= CODE_FOR_nothing
;
1310 secondary_class
= NO_REGS
;
1311 /* Set up hard register for a reload pseudo for hook
1312 secondary_reload because some targets just ignore unassigned
1313 pseudos in the hook. */
1314 if (dclass
!= NO_REGS
&& lra_get_regno_hard_regno (REGNO (dreg
)) < 0)
1316 dregno
= REGNO (dreg
);
1317 reg_renumber
[dregno
] = ira_class_hard_regs
[dclass
][0];
1321 if (sclass
!= NO_REGS
&& lra_get_regno_hard_regno (REGNO (sreg
)) < 0)
1323 sregno
= REGNO (sreg
);
1324 reg_renumber
[sregno
] = ira_class_hard_regs
[sclass
][0];
1328 if (sclass
!= NO_REGS
)
1330 = (enum reg_class
) targetm
.secondary_reload (false, dest
,
1331 (reg_class_t
) sclass
,
1332 GET_MODE (src
), &sri
);
1333 if (sclass
== NO_REGS
1334 || ((secondary_class
!= NO_REGS
|| sri
.icode
!= CODE_FOR_nothing
)
1335 && dclass
!= NO_REGS
))
1337 enum reg_class old_sclass
= secondary_class
;
1338 secondary_reload_info old_sri
= sri
;
1340 sri
.prev_sri
= NULL
;
1341 sri
.icode
= CODE_FOR_nothing
;
1344 = (enum reg_class
) targetm
.secondary_reload (true, src
,
1345 (reg_class_t
) dclass
,
1346 GET_MODE (src
), &sri
);
1347 /* Check the target hook consistency. */
1349 ((secondary_class
== NO_REGS
&& sri
.icode
== CODE_FOR_nothing
)
1350 || (old_sclass
== NO_REGS
&& old_sri
.icode
== CODE_FOR_nothing
)
1351 || (secondary_class
== old_sclass
&& sri
.icode
== old_sri
.icode
));
1354 reg_renumber
[sregno
] = -1;
1356 reg_renumber
[dregno
] = -1;
1357 if (secondary_class
== NO_REGS
&& sri
.icode
== CODE_FOR_nothing
)
1361 if (secondary_class
!= NO_REGS
)
1362 new_reg
= lra_create_new_reg_with_unique_value (GET_MODE (src
), NULL_RTX
,
1366 if (sri
.icode
== CODE_FOR_nothing
)
1367 lra_emit_move (new_reg
, src
);
1370 enum reg_class scratch_class
;
1372 scratch_class
= (reg_class_from_constraints
1373 (insn_data
[sri
.icode
].operand
[2].constraint
));
1374 scratch_reg
= (lra_create_new_reg_with_unique_value
1375 (insn_data
[sri
.icode
].operand
[2].mode
, NULL_RTX
,
1376 scratch_class
, "scratch"));
1377 emit_insn (GEN_FCN (sri
.icode
) (new_reg
!= NULL_RTX
? new_reg
: dest
,
1380 before
= get_insns ();
1382 lra_process_new_insns (curr_insn
, before
, NULL
, "Inserting the move");
1383 if (new_reg
!= NULL_RTX
)
1384 SET_SRC (curr_insn_set
) = new_reg
;
1387 if (lra_dump_file
!= NULL
)
1389 fprintf (lra_dump_file
, "Deleting move %u\n", INSN_UID (curr_insn
));
1390 dump_insn_slim (lra_dump_file
, curr_insn
);
1392 lra_set_insn_deleted (curr_insn
);
1398 /* The following data describe the result of process_alt_operands.
1399 The data are used in curr_insn_transform to generate reloads. */
1401 /* The chosen reg classes which should be used for the corresponding
1403 static enum reg_class goal_alt
[MAX_RECOG_OPERANDS
];
1404 /* True if the operand should be the same as another operand and that
1405 other operand does not need a reload. */
1406 static bool goal_alt_match_win
[MAX_RECOG_OPERANDS
];
1407 /* True if the operand does not need a reload. */
1408 static bool goal_alt_win
[MAX_RECOG_OPERANDS
];
1409 /* True if the operand can be offsetable memory. */
1410 static bool goal_alt_offmemok
[MAX_RECOG_OPERANDS
];
1411 /* The number of an operand to which given operand can be matched to. */
1412 static int goal_alt_matches
[MAX_RECOG_OPERANDS
];
1413 /* The number of elements in the following array. */
1414 static int goal_alt_dont_inherit_ops_num
;
1415 /* Numbers of operands whose reload pseudos should not be inherited. */
1416 static int goal_alt_dont_inherit_ops
[MAX_RECOG_OPERANDS
];
1417 /* True if the insn commutative operands should be swapped. */
1418 static bool goal_alt_swapped
;
1419 /* The chosen insn alternative. */
1420 static int goal_alt_number
;
1422 /* True if the corresponding operand is the result of an equivalence
1424 static bool equiv_substition_p
[MAX_RECOG_OPERANDS
];
1426 /* The following five variables are used to choose the best insn
1427 alternative. They reflect final characteristics of the best
1430 /* Number of necessary reloads and overall cost reflecting the
1431 previous value and other unpleasantness of the best alternative. */
1432 static int best_losers
, best_overall
;
1433 /* Overall number hard registers used for reloads. For example, on
1434 some targets we need 2 general registers to reload DFmode and only
1435 one floating point register. */
1436 static int best_reload_nregs
;
1437 /* Overall number reflecting distances of previous reloading the same
1438 value. The distances are counted from the current BB start. It is
1439 used to improve inheritance chances. */
1440 static int best_reload_sum
;
1442 /* True if the current insn should have no correspondingly input or
1444 static bool no_input_reloads_p
, no_output_reloads_p
;
1446 /* True if we swapped the commutative operands in the current
1448 static int curr_swapped
;
1450 /* if CHECK_ONLY_P is false, arrange for address element *LOC to be a
1451 register of class CL. Add any input reloads to list BEFORE. AFTER
1452 is nonnull if *LOC is an automodified value; handle that case by
1453 adding the required output reloads to list AFTER. Return true if
1454 the RTL was changed.
1456 if CHECK_ONLY_P is true, check that the *LOC is a correct address
1457 register. Return false if the address register is correct. */
1459 process_addr_reg (rtx
*loc
, bool check_only_p
, rtx_insn
**before
, rtx_insn
**after
,
1463 enum reg_class rclass
, new_class
;
1467 bool subreg_p
, before_p
= false;
1469 subreg_p
= GET_CODE (*loc
) == SUBREG
;
1472 reg
= SUBREG_REG (*loc
);
1473 mode
= GET_MODE (reg
);
1475 /* For mode with size bigger than ptr_mode, there unlikely to be "mov"
1476 between two registers with different classes, but there normally will
1477 be "mov" which transfers element of vector register into the general
1478 register, and this normally will be a subreg which should be reloaded
1479 as a whole. This is particularly likely to be triggered when
1480 -fno-split-wide-types specified. */
1482 || in_class_p (reg
, cl
, &new_class
)
1483 || known_le (GET_MODE_SIZE (mode
), GET_MODE_SIZE (ptr_mode
)))
1484 loc
= &SUBREG_REG (*loc
);
1488 mode
= GET_MODE (reg
);
1493 /* Always reload memory in an address even if the target supports
1495 new_reg
= lra_create_new_reg_with_unique_value (mode
, reg
, cl
, "address");
1500 regno
= REGNO (reg
);
1501 rclass
= get_reg_class (regno
);
1503 && (*loc
= get_equiv_with_elimination (reg
, curr_insn
)) != reg
)
1505 if (lra_dump_file
!= NULL
)
1507 fprintf (lra_dump_file
,
1508 "Changing pseudo %d in address of insn %u on equiv ",
1509 REGNO (reg
), INSN_UID (curr_insn
));
1510 dump_value_slim (lra_dump_file
, *loc
, 1);
1511 fprintf (lra_dump_file
, "\n");
1513 *loc
= copy_rtx (*loc
);
1515 if (*loc
!= reg
|| ! in_class_p (reg
, cl
, &new_class
))
1520 if (get_reload_reg (after
== NULL
? OP_IN
: OP_INOUT
,
1521 mode
, reg
, cl
, subreg_p
, "address", &new_reg
))
1524 else if (new_class
!= NO_REGS
&& rclass
!= new_class
)
1528 lra_change_class (regno
, new_class
, " Change to", true);
1536 push_to_sequence (*before
);
1537 lra_emit_move (new_reg
, reg
);
1538 *before
= get_insns ();
1545 lra_emit_move (before_p
? copy_rtx (reg
) : reg
, new_reg
);
1547 *after
= get_insns ();
1553 /* Insert move insn in simplify_operand_subreg. BEFORE returns
1554 the insn to be inserted before curr insn. AFTER returns the
1555 the insn to be inserted after curr insn. ORIGREG and NEWREG
1556 are the original reg and new reg for reload. */
1558 insert_move_for_subreg (rtx_insn
**before
, rtx_insn
**after
, rtx origreg
,
1563 push_to_sequence (*before
);
1564 lra_emit_move (newreg
, origreg
);
1565 *before
= get_insns ();
1571 lra_emit_move (origreg
, newreg
);
1573 *after
= get_insns ();
1578 static int valid_address_p (machine_mode mode
, rtx addr
, addr_space_t as
);
1579 static bool process_address (int, bool, rtx_insn
**, rtx_insn
**);
1581 /* Make reloads for subreg in operand NOP with internal subreg mode
1582 REG_MODE, add new reloads for further processing. Return true if
1583 any change was done. */
1585 simplify_operand_subreg (int nop
, machine_mode reg_mode
)
1587 int hard_regno
, inner_hard_regno
;
1588 rtx_insn
*before
, *after
;
1589 machine_mode mode
, innermode
;
1591 rtx operand
= *curr_id
->operand_loc
[nop
];
1592 enum reg_class regclass
;
1595 before
= after
= NULL
;
1597 if (GET_CODE (operand
) != SUBREG
)
1600 mode
= GET_MODE (operand
);
1601 reg
= SUBREG_REG (operand
);
1602 innermode
= GET_MODE (reg
);
1603 type
= curr_static_id
->operand
[nop
].type
;
1606 const bool addr_was_valid
1607 = valid_address_p (innermode
, XEXP (reg
, 0), MEM_ADDR_SPACE (reg
));
1608 alter_subreg (curr_id
->operand_loc
[nop
], false);
1609 rtx subst
= *curr_id
->operand_loc
[nop
];
1610 lra_assert (MEM_P (subst
));
1611 const bool addr_is_valid
= valid_address_p (GET_MODE (subst
),
1613 MEM_ADDR_SPACE (subst
));
1616 || ((get_constraint_type (lookup_constraint
1617 (curr_static_id
->operand
[nop
].constraint
))
1618 != CT_SPECIAL_MEMORY
)
1619 /* We still can reload address and if the address is
1620 valid, we can remove subreg without reloading its
1622 && valid_address_p (GET_MODE (subst
),
1624 [ira_class_hard_regs
1625 [base_reg_class (GET_MODE (subst
),
1626 MEM_ADDR_SPACE (subst
),
1627 ADDRESS
, SCRATCH
)][0]],
1628 MEM_ADDR_SPACE (subst
))))
1630 /* If we change the address for a paradoxical subreg of memory, the
1631 new address might violate the necessary alignment or the access
1632 might be slow; take this into consideration. We need not worry
1633 about accesses beyond allocated memory for paradoxical memory
1634 subregs as we don't substitute such equiv memory (see processing
1635 equivalences in function lra_constraints) and because for spilled
1636 pseudos we allocate stack memory enough for the biggest
1637 corresponding paradoxical subreg.
1639 However, do not blindly simplify a (subreg (mem ...)) for
1640 WORD_REGISTER_OPERATIONS targets as this may lead to loading junk
1641 data into a register when the inner is narrower than outer or
1642 missing important data from memory when the inner is wider than
1643 outer. This rule only applies to modes that are no wider than
1646 If valid memory becomes invalid after subreg elimination
1647 and address might be different we still have to reload
1650 if ((! addr_was_valid
1652 || known_eq (GET_MODE_SIZE (mode
), GET_MODE_SIZE (innermode
)))
1653 && !(maybe_ne (GET_MODE_PRECISION (mode
),
1654 GET_MODE_PRECISION (innermode
))
1655 && known_le (GET_MODE_SIZE (mode
), UNITS_PER_WORD
)
1656 && known_le (GET_MODE_SIZE (innermode
), UNITS_PER_WORD
)
1657 && WORD_REGISTER_OPERATIONS
)
1658 && (!(MEM_ALIGN (subst
) < GET_MODE_ALIGNMENT (mode
)
1659 && targetm
.slow_unaligned_access (mode
, MEM_ALIGN (subst
)))
1660 || (MEM_ALIGN (reg
) < GET_MODE_ALIGNMENT (innermode
)
1661 && targetm
.slow_unaligned_access (innermode
,
1665 *curr_id
->operand_loc
[nop
] = operand
;
1667 /* But if the address was not valid, we cannot reload the MEM without
1668 reloading the address first. */
1669 if (!addr_was_valid
)
1670 process_address (nop
, false, &before
, &after
);
1672 /* INNERMODE is fast, MODE slow. Reload the mem in INNERMODE. */
1673 enum reg_class rclass
1674 = (enum reg_class
) targetm
.preferred_reload_class (reg
, ALL_REGS
);
1675 if (get_reload_reg (curr_static_id
->operand
[nop
].type
, innermode
,
1676 reg
, rclass
, TRUE
, "slow/invalid mem", &new_reg
))
1678 bool insert_before
, insert_after
;
1679 bitmap_set_bit (&lra_subreg_reload_pseudos
, REGNO (new_reg
));
1681 insert_before
= (type
!= OP_OUT
1682 || partial_subreg_p (mode
, innermode
));
1683 insert_after
= type
!= OP_IN
;
1684 insert_move_for_subreg (insert_before
? &before
: NULL
,
1685 insert_after
? &after
: NULL
,
1688 SUBREG_REG (operand
) = new_reg
;
1690 /* Convert to MODE. */
1693 = (enum reg_class
) targetm
.preferred_reload_class (reg
, ALL_REGS
);
1694 if (get_reload_reg (curr_static_id
->operand
[nop
].type
, mode
, reg
,
1695 rclass
, TRUE
, "slow/invalid mem", &new_reg
))
1697 bool insert_before
, insert_after
;
1698 bitmap_set_bit (&lra_subreg_reload_pseudos
, REGNO (new_reg
));
1700 insert_before
= type
!= OP_OUT
;
1701 insert_after
= type
!= OP_IN
;
1702 insert_move_for_subreg (insert_before
? &before
: NULL
,
1703 insert_after
? &after
: NULL
,
1706 *curr_id
->operand_loc
[nop
] = new_reg
;
1707 lra_process_new_insns (curr_insn
, before
, after
,
1708 "Inserting slow/invalid mem reload");
1712 /* If the address was valid and became invalid, prefer to reload
1713 the memory. Typical case is when the index scale should
1714 correspond the memory. */
1715 *curr_id
->operand_loc
[nop
] = operand
;
1716 /* Do not return false here as the MEM_P (reg) will be processed
1717 later in this function. */
1719 else if (REG_P (reg
) && REGNO (reg
) < FIRST_PSEUDO_REGISTER
)
1721 alter_subreg (curr_id
->operand_loc
[nop
], false);
1724 else if (CONSTANT_P (reg
))
1726 /* Try to simplify subreg of constant. It is usually result of
1727 equivalence substitution. */
1728 if (innermode
== VOIDmode
1729 && (innermode
= original_subreg_reg_mode
[nop
]) == VOIDmode
)
1730 innermode
= curr_static_id
->operand
[nop
].mode
;
1731 if ((new_reg
= simplify_subreg (mode
, reg
, innermode
,
1732 SUBREG_BYTE (operand
))) != NULL_RTX
)
1734 *curr_id
->operand_loc
[nop
] = new_reg
;
1738 /* Put constant into memory when we have mixed modes. It generates
1739 a better code in most cases as it does not need a secondary
1740 reload memory. It also prevents LRA looping when LRA is using
1741 secondary reload memory again and again. */
1742 if (CONSTANT_P (reg
) && CONST_POOL_OK_P (reg_mode
, reg
)
1743 && SCALAR_INT_MODE_P (reg_mode
) != SCALAR_INT_MODE_P (mode
))
1745 SUBREG_REG (operand
) = force_const_mem (reg_mode
, reg
);
1746 alter_subreg (curr_id
->operand_loc
[nop
], false);
1749 /* Force a reload of the SUBREG_REG if this is a constant or PLUS or
1750 if there may be a problem accessing OPERAND in the outer
1753 && REGNO (reg
) >= FIRST_PSEUDO_REGISTER
1754 && (hard_regno
= lra_get_regno_hard_regno (REGNO (reg
))) >= 0
1755 /* Don't reload paradoxical subregs because we could be looping
1756 having repeatedly final regno out of hard regs range. */
1757 && (hard_regno_nregs (hard_regno
, innermode
)
1758 >= hard_regno_nregs (hard_regno
, mode
))
1759 && simplify_subreg_regno (hard_regno
, innermode
,
1760 SUBREG_BYTE (operand
), mode
) < 0
1761 /* Don't reload subreg for matching reload. It is actually
1762 valid subreg in LRA. */
1763 && ! LRA_SUBREG_P (operand
))
1764 || CONSTANT_P (reg
) || GET_CODE (reg
) == PLUS
|| MEM_P (reg
))
1766 enum reg_class rclass
;
1769 /* There is a big probability that we will get the same class
1770 for the new pseudo and we will get the same insn which
1771 means infinite looping. So spill the new pseudo. */
1774 /* The class will be defined later in curr_insn_transform. */
1776 = (enum reg_class
) targetm
.preferred_reload_class (reg
, ALL_REGS
);
1778 if (get_reload_reg (curr_static_id
->operand
[nop
].type
, reg_mode
, reg
,
1779 rclass
, TRUE
, "subreg reg", &new_reg
))
1781 bool insert_before
, insert_after
;
1782 bitmap_set_bit (&lra_subreg_reload_pseudos
, REGNO (new_reg
));
1784 insert_before
= (type
!= OP_OUT
1785 || read_modify_subreg_p (operand
));
1786 insert_after
= (type
!= OP_IN
);
1787 insert_move_for_subreg (insert_before
? &before
: NULL
,
1788 insert_after
? &after
: NULL
,
1791 SUBREG_REG (operand
) = new_reg
;
1792 lra_process_new_insns (curr_insn
, before
, after
,
1793 "Inserting subreg reload");
1796 /* Force a reload for a paradoxical subreg. For paradoxical subreg,
1797 IRA allocates hardreg to the inner pseudo reg according to its mode
1798 instead of the outermode, so the size of the hardreg may not be enough
1799 to contain the outermode operand, in that case we may need to insert
1800 reload for the reg. For the following two types of paradoxical subreg,
1801 we need to insert reload:
1802 1. If the op_type is OP_IN, and the hardreg could not be paired with
1803 other hardreg to contain the outermode operand
1804 (checked by in_hard_reg_set_p), we need to insert the reload.
1805 2. If the op_type is OP_OUT or OP_INOUT.
1807 Here is a paradoxical subreg example showing how the reload is generated:
1809 (insn 5 4 7 2 (set (reg:TI 106 [ __comp ])
1810 (subreg:TI (reg:DI 107 [ __comp ]) 0)) {*movti_internal_rex64}
1812 In IRA, reg107 is allocated to a DImode hardreg. We use x86-64 as example
1813 here, if reg107 is assigned to hardreg R15, because R15 is the last
1814 hardreg, compiler cannot find another hardreg to pair with R15 to
1815 contain TImode data. So we insert a TImode reload reg180 for it.
1816 After reload is inserted:
1818 (insn 283 0 0 (set (subreg:DI (reg:TI 180 [orig:107 __comp ] [107]) 0)
1819 (reg:DI 107 [ __comp ])) -1
1820 (insn 5 4 7 2 (set (reg:TI 106 [ __comp ])
1821 (subreg:TI (reg:TI 180 [orig:107 __comp ] [107]) 0)) {*movti_internal_rex64}
1823 Two reload hard registers will be allocated to reg180 to save TImode data
1826 For LRA pseudos this should normally be handled by the biggest_mode
1827 mechanism. However, it's possible for new uses of an LRA pseudo
1828 to be introduced after we've allocated it, such as when undoing
1829 inheritance, and the allocated register might not then be appropriate
1830 for the new uses. */
1831 else if (REG_P (reg
)
1832 && REGNO (reg
) >= FIRST_PSEUDO_REGISTER
1833 && paradoxical_subreg_p (operand
)
1834 && (inner_hard_regno
= lra_get_regno_hard_regno (REGNO (reg
))) >= 0
1836 = simplify_subreg_regno (inner_hard_regno
, innermode
,
1837 SUBREG_BYTE (operand
), mode
)) < 0
1838 || ((hard_regno_nregs (inner_hard_regno
, innermode
)
1839 < hard_regno_nregs (hard_regno
, mode
))
1840 && (regclass
= lra_get_allocno_class (REGNO (reg
)))
1842 || !in_hard_reg_set_p (reg_class_contents
[regclass
],
1844 || overlaps_hard_reg_set_p (lra_no_alloc_regs
,
1845 mode
, hard_regno
)))))
1847 /* The class will be defined later in curr_insn_transform. */
1848 enum reg_class rclass
1849 = (enum reg_class
) targetm
.preferred_reload_class (reg
, ALL_REGS
);
1851 if (get_reload_reg (curr_static_id
->operand
[nop
].type
, mode
, reg
,
1852 rclass
, TRUE
, "paradoxical subreg", &new_reg
))
1855 bool insert_before
, insert_after
;
1857 PUT_MODE (new_reg
, mode
);
1858 subreg
= gen_lowpart_SUBREG (innermode
, new_reg
);
1859 bitmap_set_bit (&lra_subreg_reload_pseudos
, REGNO (new_reg
));
1861 insert_before
= (type
!= OP_OUT
);
1862 insert_after
= (type
!= OP_IN
);
1863 insert_move_for_subreg (insert_before
? &before
: NULL
,
1864 insert_after
? &after
: NULL
,
1867 SUBREG_REG (operand
) = new_reg
;
1868 lra_process_new_insns (curr_insn
, before
, after
,
1869 "Inserting paradoxical subreg reload");
1875 /* Return TRUE if X refers for a hard register from SET. */
1877 uses_hard_regs_p (rtx x
, HARD_REG_SET set
)
1879 int i
, j
, x_hard_regno
;
1886 code
= GET_CODE (x
);
1887 mode
= GET_MODE (x
);
1891 /* For all SUBREGs we want to check whether the full multi-register
1892 overlaps the set. For normal SUBREGs this means 'get_hard_regno' of
1893 the inner register, for paradoxical SUBREGs this means the
1894 'get_hard_regno' of the full SUBREG and for complete SUBREGs either is
1895 fine. Use the wider mode for all cases. */
1896 rtx subreg
= SUBREG_REG (x
);
1897 mode
= wider_subreg_mode (x
);
1898 if (mode
== GET_MODE (subreg
))
1901 code
= GET_CODE (x
);
1905 if (REG_P (x
) || SUBREG_P (x
))
1907 x_hard_regno
= get_hard_regno (x
, true);
1908 return (x_hard_regno
>= 0
1909 && overlaps_hard_reg_set_p (set
, mode
, x_hard_regno
));
1911 fmt
= GET_RTX_FORMAT (code
);
1912 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
1916 if (uses_hard_regs_p (XEXP (x
, i
), set
))
1919 else if (fmt
[i
] == 'E')
1921 for (j
= XVECLEN (x
, i
) - 1; j
>= 0; j
--)
1922 if (uses_hard_regs_p (XVECEXP (x
, i
, j
), set
))
1929 /* Return true if OP is a spilled pseudo. */
1931 spilled_pseudo_p (rtx op
)
1934 && REGNO (op
) >= FIRST_PSEUDO_REGISTER
&& in_mem_p (REGNO (op
)));
1937 /* Return true if X is a general constant. */
1939 general_constant_p (rtx x
)
1941 return CONSTANT_P (x
) && (! flag_pic
|| LEGITIMATE_PIC_OPERAND_P (x
));
1945 reg_in_class_p (rtx reg
, enum reg_class cl
)
1948 return get_reg_class (REGNO (reg
)) == NO_REGS
;
1949 return in_class_p (reg
, cl
, NULL
);
1952 /* Return true if SET of RCLASS contains no hard regs which can be
1955 prohibited_class_reg_set_mode_p (enum reg_class rclass
,
1961 lra_assert (hard_reg_set_subset_p (reg_class_contents
[rclass
], set
));
1962 temp
= set
& ~lra_no_alloc_regs
;
1963 return (hard_reg_set_subset_p
1964 (temp
, ira_prohibited_class_mode_regs
[rclass
][mode
]));
1968 /* Used to check validity info about small class input operands. It
1969 should be incremented at start of processing an insn
1971 static unsigned int curr_small_class_check
= 0;
1973 /* Update number of used inputs of class OP_CLASS for operand NOP
1974 of alternative NALT. Return true if we have more such class operands
1975 than the number of available regs. */
1977 update_and_check_small_class_inputs (int nop
, int nalt
,
1978 enum reg_class op_class
)
1980 static unsigned int small_class_check
[LIM_REG_CLASSES
];
1981 static int small_class_input_nums
[LIM_REG_CLASSES
];
1983 if (SMALL_REGISTER_CLASS_P (op_class
)
1984 /* We are interesting in classes became small because of fixing
1985 some hard regs, e.g. by an user through GCC options. */
1986 && hard_reg_set_intersect_p (reg_class_contents
[op_class
],
1988 && (curr_static_id
->operand
[nop
].type
!= OP_OUT
1989 || TEST_BIT (curr_static_id
->operand
[nop
].early_clobber_alts
, nalt
)))
1991 if (small_class_check
[op_class
] == curr_small_class_check
)
1992 small_class_input_nums
[op_class
]++;
1995 small_class_check
[op_class
] = curr_small_class_check
;
1996 small_class_input_nums
[op_class
] = 1;
1998 if (small_class_input_nums
[op_class
] > ira_class_hard_regs_num
[op_class
])
2004 /* Major function to choose the current insn alternative and what
2005 operands should be reloaded and how. If ONLY_ALTERNATIVE is not
2006 negative we should consider only this alternative. Return false if
2007 we cannot choose the alternative or find how to reload the
2010 process_alt_operands (int only_alternative
)
2013 int nop
, overall
, nalt
;
2014 int n_alternatives
= curr_static_id
->n_alternatives
;
2015 int n_operands
= curr_static_id
->n_operands
;
2016 /* LOSERS counts the operands that don't fit this alternative and
2017 would require loading. */
2020 /* REJECT is a count of how undesirable this alternative says it is
2021 if any reloading is required. If the alternative matches exactly
2022 then REJECT is ignored, but otherwise it gets this much counted
2023 against it in addition to the reloading needed. */
2025 /* This is defined by '!' or '?' alternative constraint and added to
2026 reject. But in some cases it can be ignored. */
2029 /* The number of elements in the following array. */
2030 int early_clobbered_regs_num
;
2031 /* Numbers of operands which are early clobber registers. */
2032 int early_clobbered_nops
[MAX_RECOG_OPERANDS
];
2033 enum reg_class curr_alt
[MAX_RECOG_OPERANDS
];
2034 HARD_REG_SET curr_alt_set
[MAX_RECOG_OPERANDS
];
2035 bool curr_alt_match_win
[MAX_RECOG_OPERANDS
];
2036 bool curr_alt_win
[MAX_RECOG_OPERANDS
];
2037 bool curr_alt_offmemok
[MAX_RECOG_OPERANDS
];
2038 int curr_alt_matches
[MAX_RECOG_OPERANDS
];
2039 /* The number of elements in the following array. */
2040 int curr_alt_dont_inherit_ops_num
;
2041 /* Numbers of operands whose reload pseudos should not be inherited. */
2042 int curr_alt_dont_inherit_ops
[MAX_RECOG_OPERANDS
];
2044 /* The register when the operand is a subreg of register, otherwise the
2046 rtx no_subreg_reg_operand
[MAX_RECOG_OPERANDS
];
2047 /* The register if the operand is a register or subreg of register,
2049 rtx operand_reg
[MAX_RECOG_OPERANDS
];
2050 int hard_regno
[MAX_RECOG_OPERANDS
];
2051 machine_mode biggest_mode
[MAX_RECOG_OPERANDS
];
2052 int reload_nregs
, reload_sum
;
2056 /* Calculate some data common for all alternatives to speed up the
2058 for (nop
= 0; nop
< n_operands
; nop
++)
2062 op
= no_subreg_reg_operand
[nop
] = *curr_id
->operand_loc
[nop
];
2063 /* The real hard regno of the operand after the allocation. */
2064 hard_regno
[nop
] = get_hard_regno (op
, true);
2066 operand_reg
[nop
] = reg
= op
;
2067 biggest_mode
[nop
] = GET_MODE (op
);
2068 if (GET_CODE (op
) == SUBREG
)
2070 biggest_mode
[nop
] = wider_subreg_mode (op
);
2071 operand_reg
[nop
] = reg
= SUBREG_REG (op
);
2074 operand_reg
[nop
] = NULL_RTX
;
2075 else if (REGNO (reg
) >= FIRST_PSEUDO_REGISTER
2076 || ((int) REGNO (reg
)
2077 == lra_get_elimination_hard_regno (REGNO (reg
))))
2078 no_subreg_reg_operand
[nop
] = reg
;
2080 operand_reg
[nop
] = no_subreg_reg_operand
[nop
]
2081 /* Just use natural mode for elimination result. It should
2082 be enough for extra constraints hooks. */
2083 = regno_reg_rtx
[hard_regno
[nop
]];
2086 /* The constraints are made of several alternatives. Each operand's
2087 constraint looks like foo,bar,... with commas separating the
2088 alternatives. The first alternatives for all operands go
2089 together, the second alternatives go together, etc.
2091 First loop over alternatives. */
2092 alternative_mask preferred
= curr_id
->preferred_alternatives
;
2093 if (only_alternative
>= 0)
2094 preferred
&= ALTERNATIVE_BIT (only_alternative
);
2096 for (nalt
= 0; nalt
< n_alternatives
; nalt
++)
2098 /* Loop over operands for one constraint alternative. */
2099 if (!TEST_BIT (preferred
, nalt
))
2102 bool matching_early_clobber
[MAX_RECOG_OPERANDS
];
2103 curr_small_class_check
++;
2104 overall
= losers
= addr_losers
= 0;
2105 static_reject
= reject
= reload_nregs
= reload_sum
= 0;
2106 for (nop
= 0; nop
< n_operands
; nop
++)
2108 int inc
= (curr_static_id
2109 ->operand_alternative
[nalt
* n_operands
+ nop
].reject
);
2110 if (lra_dump_file
!= NULL
&& inc
!= 0)
2111 fprintf (lra_dump_file
,
2112 " Staticly defined alt reject+=%d\n", inc
);
2113 static_reject
+= inc
;
2114 matching_early_clobber
[nop
] = 0;
2116 reject
+= static_reject
;
2117 early_clobbered_regs_num
= 0;
2119 for (nop
= 0; nop
< n_operands
; nop
++)
2123 int len
, c
, m
, i
, opalt_num
, this_alternative_matches
;
2124 bool win
, did_match
, offmemok
, early_clobber_p
;
2125 /* false => this operand can be reloaded somehow for this
2128 /* true => this operand can be reloaded if the alternative
2131 /* True if a constant forced into memory would be OK for
2134 enum reg_class this_alternative
, this_costly_alternative
;
2135 HARD_REG_SET this_alternative_set
, this_costly_alternative_set
;
2136 bool this_alternative_match_win
, this_alternative_win
;
2137 bool this_alternative_offmemok
;
2140 enum constraint_num cn
;
2142 opalt_num
= nalt
* n_operands
+ nop
;
2143 if (curr_static_id
->operand_alternative
[opalt_num
].anything_ok
)
2145 /* Fast track for no constraints at all. */
2146 curr_alt
[nop
] = NO_REGS
;
2147 CLEAR_HARD_REG_SET (curr_alt_set
[nop
]);
2148 curr_alt_win
[nop
] = true;
2149 curr_alt_match_win
[nop
] = false;
2150 curr_alt_offmemok
[nop
] = false;
2151 curr_alt_matches
[nop
] = -1;
2155 op
= no_subreg_reg_operand
[nop
];
2156 mode
= curr_operand_mode
[nop
];
2158 win
= did_match
= winreg
= offmemok
= constmemok
= false;
2161 early_clobber_p
= false;
2162 p
= curr_static_id
->operand_alternative
[opalt_num
].constraint
;
2164 this_costly_alternative
= this_alternative
= NO_REGS
;
2165 /* We update set of possible hard regs besides its class
2166 because reg class might be inaccurate. For example,
2167 union of LO_REGS (l), HI_REGS(h), and STACK_REG(k) in ARM
2168 is translated in HI_REGS because classes are merged by
2169 pairs and there is no accurate intermediate class. */
2170 CLEAR_HARD_REG_SET (this_alternative_set
);
2171 CLEAR_HARD_REG_SET (this_costly_alternative_set
);
2172 this_alternative_win
= false;
2173 this_alternative_match_win
= false;
2174 this_alternative_offmemok
= false;
2175 this_alternative_matches
= -1;
2177 /* An empty constraint should be excluded by the fast
2179 lra_assert (*p
!= 0 && *p
!= ',');
2182 /* Scan this alternative's specs for this operand; set WIN
2183 if the operand fits any letter in this alternative.
2184 Otherwise, clear BADOP if this operand could fit some
2185 letter after reloads, or set WINREG if this operand could
2186 fit after reloads provided the constraint allows some
2191 switch ((c
= *p
, len
= CONSTRAINT_LEN (c
, p
)), c
)
2201 early_clobber_p
= true;
2205 op_reject
+= LRA_MAX_REJECT
;
2208 op_reject
+= LRA_LOSER_COST_FACTOR
;
2212 /* Ignore rest of this alternative. */
2216 case '0': case '1': case '2': case '3': case '4':
2217 case '5': case '6': case '7': case '8': case '9':
2222 m
= strtoul (p
, &end
, 10);
2225 lra_assert (nop
> m
);
2227 /* Reject matches if we don't know which operand is
2228 bigger. This situation would arguably be a bug in
2229 an .md pattern, but could also occur in a user asm. */
2230 if (!ordered_p (GET_MODE_SIZE (biggest_mode
[m
]),
2231 GET_MODE_SIZE (biggest_mode
[nop
])))
2234 /* Don't match wrong asm insn operands for proper
2235 diagnostic later. */
2236 if (INSN_CODE (curr_insn
) < 0
2237 && (curr_operand_mode
[m
] == BLKmode
2238 || curr_operand_mode
[nop
] == BLKmode
)
2239 && curr_operand_mode
[m
] != curr_operand_mode
[nop
])
2242 m_hregno
= get_hard_regno (*curr_id
->operand_loc
[m
], false);
2243 /* We are supposed to match a previous operand.
2244 If we do, we win if that one did. If we do
2245 not, count both of the operands as losers.
2246 (This is too conservative, since most of the
2247 time only a single reload insn will be needed
2248 to make the two operands win. As a result,
2249 this alternative may be rejected when it is
2250 actually desirable.) */
2252 if (operands_match_p (*curr_id
->operand_loc
[nop
],
2253 *curr_id
->operand_loc
[m
], m_hregno
))
2255 /* We should reject matching of an early
2256 clobber operand if the matching operand is
2257 not dying in the insn. */
2258 if (!TEST_BIT (curr_static_id
->operand
[m
]
2259 .early_clobber_alts
, nalt
)
2260 || operand_reg
[nop
] == NULL_RTX
2261 || (find_regno_note (curr_insn
, REG_DEAD
,
2263 || REGNO (op
) == REGNO (operand_reg
[m
])))
2268 /* If we are matching a non-offsettable
2269 address where an offsettable address was
2270 expected, then we must reject this
2271 combination, because we can't reload
2273 if (curr_alt_offmemok
[m
]
2274 && MEM_P (*curr_id
->operand_loc
[m
])
2275 && curr_alt
[m
] == NO_REGS
&& ! curr_alt_win
[m
])
2280 /* If the operands do not match and one
2281 operand is INOUT, we can not match them.
2282 Try other possibilities, e.g. other
2283 alternatives or commutative operand
2285 if (curr_static_id
->operand
[nop
].type
== OP_INOUT
2286 || curr_static_id
->operand
[m
].type
== OP_INOUT
)
2288 /* Operands don't match. If the operands are
2289 different user defined explicit hard
2290 registers, then we cannot make them match
2291 when one is early clobber operand. */
2292 if ((REG_P (*curr_id
->operand_loc
[nop
])
2293 || SUBREG_P (*curr_id
->operand_loc
[nop
]))
2294 && (REG_P (*curr_id
->operand_loc
[m
])
2295 || SUBREG_P (*curr_id
->operand_loc
[m
])))
2297 rtx nop_reg
= *curr_id
->operand_loc
[nop
];
2298 if (SUBREG_P (nop_reg
))
2299 nop_reg
= SUBREG_REG (nop_reg
);
2300 rtx m_reg
= *curr_id
->operand_loc
[m
];
2301 if (SUBREG_P (m_reg
))
2302 m_reg
= SUBREG_REG (m_reg
);
2305 && HARD_REGISTER_P (nop_reg
)
2306 && REG_USERVAR_P (nop_reg
)
2308 && HARD_REGISTER_P (m_reg
)
2309 && REG_USERVAR_P (m_reg
))
2313 for (i
= 0; i
< early_clobbered_regs_num
; i
++)
2314 if (m
== early_clobbered_nops
[i
])
2316 if (i
< early_clobbered_regs_num
2321 /* Both operands must allow a reload register,
2322 otherwise we cannot make them match. */
2323 if (curr_alt
[m
] == NO_REGS
)
2325 /* Retroactively mark the operand we had to
2326 match as a loser, if it wasn't already and
2327 it wasn't matched to a register constraint
2328 (e.g it might be matched by memory). */
2330 && (operand_reg
[m
] == NULL_RTX
2331 || hard_regno
[m
] < 0))
2335 += (ira_reg_class_max_nregs
[curr_alt
[m
]]
2336 [GET_MODE (*curr_id
->operand_loc
[m
])]);
2339 /* Prefer matching earlyclobber alternative as
2340 it results in less hard regs required for
2341 the insn than a non-matching earlyclobber
2343 if (TEST_BIT (curr_static_id
->operand
[m
]
2344 .early_clobber_alts
, nalt
))
2346 if (lra_dump_file
!= NULL
)
2349 " %d Matching earlyclobber alt:"
2352 if (!matching_early_clobber
[m
])
2355 matching_early_clobber
[m
] = 1;
2358 /* Otherwise we prefer no matching
2359 alternatives because it gives more freedom
2361 else if (operand_reg
[nop
] == NULL_RTX
2362 || (find_regno_note (curr_insn
, REG_DEAD
,
2363 REGNO (operand_reg
[nop
]))
2366 if (lra_dump_file
!= NULL
)
2369 " %d Matching alt: reject+=2\n",
2374 /* If we have to reload this operand and some
2375 previous operand also had to match the same
2376 thing as this operand, we don't know how to do
2378 if (!match_p
|| !curr_alt_win
[m
])
2380 for (i
= 0; i
< nop
; i
++)
2381 if (curr_alt_matches
[i
] == m
)
2389 this_alternative_matches
= m
;
2390 /* This can be fixed with reloads if the operand
2391 we are supposed to match can be fixed with
2394 this_alternative
= curr_alt
[m
];
2395 this_alternative_set
= curr_alt_set
[m
];
2396 winreg
= this_alternative
!= NO_REGS
;
2402 || general_constant_p (op
)
2403 || spilled_pseudo_p (op
))
2409 cn
= lookup_constraint (p
);
2410 switch (get_constraint_type (cn
))
2413 cl
= reg_class_for_constraint (cn
);
2419 if (CONST_INT_P (op
)
2420 && insn_const_int_ok_for_constraint (INTVAL (op
), cn
))
2425 case CT_RELAXED_MEMORY
:
2427 && satisfies_memory_constraint_p (op
, cn
))
2429 else if (spilled_pseudo_p (op
))
2432 /* If we didn't already win, we can reload constants
2433 via force_const_mem or put the pseudo value into
2434 memory, or make other memory by reloading the
2435 address like for 'o'. */
2436 if (CONST_POOL_OK_P (mode
, op
)
2437 || MEM_P (op
) || REG_P (op
)
2438 /* We can restore the equiv insn by a
2440 || equiv_substition_p
[nop
])
2447 /* An asm operand with an address constraint
2448 that doesn't satisfy address_operand has
2449 is_address cleared, so that we don't try to
2450 make a non-address fit. */
2451 if (!curr_static_id
->operand
[nop
].is_address
)
2453 /* If we didn't already win, we can reload the address
2454 into a base register. */
2455 if (satisfies_address_constraint_p (op
, cn
))
2457 cl
= base_reg_class (VOIDmode
, ADDR_SPACE_GENERIC
,
2463 if (constraint_satisfied_p (op
, cn
))
2467 case CT_SPECIAL_MEMORY
:
2468 if (satisfies_memory_constraint_p (op
, cn
))
2470 else if (spilled_pseudo_p (op
))
2477 if (mode
== BLKmode
)
2479 this_alternative
= reg_class_subunion
[this_alternative
][cl
];
2480 this_alternative_set
|= reg_class_contents
[cl
];
2483 this_costly_alternative
2484 = reg_class_subunion
[this_costly_alternative
][cl
];
2485 this_costly_alternative_set
|= reg_class_contents
[cl
];
2490 if (hard_regno
[nop
] >= 0
2491 && in_hard_reg_set_p (this_alternative_set
,
2492 mode
, hard_regno
[nop
]))
2494 else if (hard_regno
[nop
] < 0
2495 && in_class_p (op
, this_alternative
, NULL
))
2500 if (c
!= ' ' && c
!= '\t')
2501 costly_p
= c
== '*';
2503 while ((p
+= len
), c
);
2505 scratch_p
= (operand_reg
[nop
] != NULL_RTX
2506 && ira_former_scratch_p (REGNO (operand_reg
[nop
])));
2507 /* Record which operands fit this alternative. */
2510 this_alternative_win
= true;
2511 if (operand_reg
[nop
] != NULL_RTX
)
2513 if (hard_regno
[nop
] >= 0)
2515 if (in_hard_reg_set_p (this_costly_alternative_set
,
2516 mode
, hard_regno
[nop
]))
2518 if (lra_dump_file
!= NULL
)
2519 fprintf (lra_dump_file
,
2520 " %d Costly set: reject++\n",
2527 /* Prefer won reg to spilled pseudo under other
2528 equal conditions for possibe inheritance. */
2531 if (lra_dump_file
!= NULL
)
2534 " %d Non pseudo reload: reject++\n",
2538 if (in_class_p (operand_reg
[nop
],
2539 this_costly_alternative
, NULL
))
2541 if (lra_dump_file
!= NULL
)
2544 " %d Non pseudo costly reload:"
2550 /* We simulate the behavior of old reload here.
2551 Although scratches need hard registers and it
2552 might result in spilling other pseudos, no reload
2553 insns are generated for the scratches. So it
2554 might cost something but probably less than old
2555 reload pass believes. */
2558 if (lra_dump_file
!= NULL
)
2559 fprintf (lra_dump_file
,
2560 " %d Scratch win: reject+=2\n",
2567 this_alternative_match_win
= true;
2570 int const_to_mem
= 0;
2573 reject
+= op_reject
;
2574 /* Never do output reload of stack pointer. It makes
2575 impossible to do elimination when SP is changed in
2577 if (op
== stack_pointer_rtx
&& ! frame_pointer_needed
2578 && curr_static_id
->operand
[nop
].type
!= OP_IN
)
2581 /* If this alternative asks for a specific reg class, see if there
2582 is at least one allocatable register in that class. */
2584 = (this_alternative
== NO_REGS
2585 || (hard_reg_set_subset_p
2586 (reg_class_contents
[this_alternative
],
2587 lra_no_alloc_regs
)));
2589 /* For asms, verify that the class for this alternative is possible
2590 for the mode that is specified. */
2591 if (!no_regs_p
&& INSN_CODE (curr_insn
) < 0)
2594 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
2595 if (targetm
.hard_regno_mode_ok (i
, mode
)
2596 && in_hard_reg_set_p (reg_class_contents
[this_alternative
],
2599 if (i
== FIRST_PSEUDO_REGISTER
)
2603 /* If this operand accepts a register, and if the
2604 register class has at least one allocatable register,
2605 then this operand can be reloaded. */
2606 if (winreg
&& !no_regs_p
)
2611 if (lra_dump_file
!= NULL
)
2612 fprintf (lra_dump_file
,
2613 " alt=%d: Bad operand -- refuse\n",
2618 if (this_alternative
!= NO_REGS
)
2620 HARD_REG_SET available_regs
2621 = (reg_class_contents
[this_alternative
]
2622 & ~((ira_prohibited_class_mode_regs
2623 [this_alternative
][mode
])
2624 | lra_no_alloc_regs
));
2625 if (hard_reg_set_empty_p (available_regs
))
2627 /* There are no hard regs holding a value of given
2631 this_alternative
= NO_REGS
;
2632 if (lra_dump_file
!= NULL
)
2633 fprintf (lra_dump_file
,
2634 " %d Using memory because of"
2635 " a bad mode: reject+=2\n",
2641 if (lra_dump_file
!= NULL
)
2642 fprintf (lra_dump_file
,
2643 " alt=%d: Wrong mode -- refuse\n",
2650 /* If not assigned pseudo has a class which a subset of
2651 required reg class, it is a less costly alternative
2652 as the pseudo still can get a hard reg of necessary
2654 if (! no_regs_p
&& REG_P (op
) && hard_regno
[nop
] < 0
2655 && (cl
= get_reg_class (REGNO (op
))) != NO_REGS
2656 && ira_class_subset_p
[this_alternative
][cl
])
2658 if (lra_dump_file
!= NULL
)
2661 " %d Super set class reg: reject-=3\n", nop
);
2665 this_alternative_offmemok
= offmemok
;
2666 if (this_costly_alternative
!= NO_REGS
)
2668 if (lra_dump_file
!= NULL
)
2669 fprintf (lra_dump_file
,
2670 " %d Costly loser: reject++\n", nop
);
2673 /* If the operand is dying, has a matching constraint,
2674 and satisfies constraints of the matched operand
2675 which failed to satisfy the own constraints, most probably
2676 the reload for this operand will be gone. */
2677 if (this_alternative_matches
>= 0
2678 && !curr_alt_win
[this_alternative_matches
]
2680 && find_regno_note (curr_insn
, REG_DEAD
, REGNO (op
))
2681 && (hard_regno
[nop
] >= 0
2682 ? in_hard_reg_set_p (this_alternative_set
,
2683 mode
, hard_regno
[nop
])
2684 : in_class_p (op
, this_alternative
, NULL
)))
2686 if (lra_dump_file
!= NULL
)
2689 " %d Dying matched operand reload: reject++\n",
2695 /* Strict_low_part requires to reload the register
2696 not the sub-register. In this case we should
2697 check that a final reload hard reg can hold the
2699 if (curr_static_id
->operand
[nop
].strict_low
2701 && hard_regno
[nop
] < 0
2702 && GET_CODE (*curr_id
->operand_loc
[nop
]) == SUBREG
2703 && ira_class_hard_regs_num
[this_alternative
] > 0
2704 && (!targetm
.hard_regno_mode_ok
2705 (ira_class_hard_regs
[this_alternative
][0],
2706 GET_MODE (*curr_id
->operand_loc
[nop
]))))
2708 if (lra_dump_file
!= NULL
)
2711 " alt=%d: Strict low subreg reload -- refuse\n",
2717 if (operand_reg
[nop
] != NULL_RTX
2718 /* Output operands and matched input operands are
2719 not inherited. The following conditions do not
2720 exactly describe the previous statement but they
2721 are pretty close. */
2722 && curr_static_id
->operand
[nop
].type
!= OP_OUT
2723 && (this_alternative_matches
< 0
2724 || curr_static_id
->operand
[nop
].type
!= OP_IN
))
2726 int last_reload
= (lra_reg_info
[ORIGINAL_REGNO
2730 /* The value of reload_sum has sense only if we
2731 process insns in their order. It happens only on
2732 the first constraints sub-pass when we do most of
2734 if (lra_constraint_iter
== 1 && last_reload
> bb_reload_num
)
2735 reload_sum
+= last_reload
- bb_reload_num
;
2737 /* If this is a constant that is reloaded into the
2738 desired class by copying it to memory first, count
2739 that as another reload. This is consistent with
2740 other code and is required to avoid choosing another
2741 alternative when the constant is moved into memory.
2742 Note that the test here is precisely the same as in
2743 the code below that calls force_const_mem. */
2744 if (CONST_POOL_OK_P (mode
, op
)
2745 && ((targetm
.preferred_reload_class
2746 (op
, this_alternative
) == NO_REGS
)
2747 || no_input_reloads_p
))
2754 /* Alternative loses if it requires a type of reload not
2755 permitted for this insn. We can always reload
2756 objects with a REG_UNUSED note. */
2757 if ((curr_static_id
->operand
[nop
].type
!= OP_IN
2758 && no_output_reloads_p
2759 && ! find_reg_note (curr_insn
, REG_UNUSED
, op
))
2760 || (curr_static_id
->operand
[nop
].type
!= OP_OUT
2761 && no_input_reloads_p
&& ! const_to_mem
)
2762 || (this_alternative_matches
>= 0
2763 && (no_input_reloads_p
2764 || (no_output_reloads_p
2765 && (curr_static_id
->operand
2766 [this_alternative_matches
].type
!= OP_IN
)
2767 && ! find_reg_note (curr_insn
, REG_UNUSED
,
2768 no_subreg_reg_operand
2769 [this_alternative_matches
])))))
2771 if (lra_dump_file
!= NULL
)
2774 " alt=%d: No input/output reload -- refuse\n",
2779 /* Alternative loses if it required class pseudo cannot
2780 hold value of required mode. Such insns can be
2781 described by insn definitions with mode iterators. */
2782 if (GET_MODE (*curr_id
->operand_loc
[nop
]) != VOIDmode
2783 && ! hard_reg_set_empty_p (this_alternative_set
)
2784 /* It is common practice for constraints to use a
2785 class which does not have actually enough regs to
2786 hold the value (e.g. x86 AREG for mode requiring
2787 more one general reg). Therefore we have 2
2788 conditions to check that the reload pseudo cannot
2789 hold the mode value. */
2790 && (!targetm
.hard_regno_mode_ok
2791 (ira_class_hard_regs
[this_alternative
][0],
2792 GET_MODE (*curr_id
->operand_loc
[nop
])))
2793 /* The above condition is not enough as the first
2794 reg in ira_class_hard_regs can be not aligned for
2795 multi-words mode values. */
2796 && (prohibited_class_reg_set_mode_p
2797 (this_alternative
, this_alternative_set
,
2798 GET_MODE (*curr_id
->operand_loc
[nop
]))))
2800 if (lra_dump_file
!= NULL
)
2801 fprintf (lra_dump_file
,
2802 " alt=%d: reload pseudo for op %d "
2803 "cannot hold the mode value -- refuse\n",
2808 /* Check strong discouragement of reload of non-constant
2809 into class THIS_ALTERNATIVE. */
2810 if (! CONSTANT_P (op
) && ! no_regs_p
2811 && (targetm
.preferred_reload_class
2812 (op
, this_alternative
) == NO_REGS
2813 || (curr_static_id
->operand
[nop
].type
== OP_OUT
2814 && (targetm
.preferred_output_reload_class
2815 (op
, this_alternative
) == NO_REGS
))))
2817 if (offmemok
&& REG_P (op
))
2819 if (lra_dump_file
!= NULL
)
2822 " %d Spill pseudo into memory: reject+=3\n",
2828 if (lra_dump_file
!= NULL
)
2831 " %d Non-prefered reload: reject+=%d\n",
2832 nop
, LRA_MAX_REJECT
);
2833 reject
+= LRA_MAX_REJECT
;
2837 if (! (MEM_P (op
) && offmemok
)
2838 && ! (const_to_mem
&& constmemok
))
2840 /* We prefer to reload pseudos over reloading other
2841 things, since such reloads may be able to be
2842 eliminated later. So bump REJECT in other cases.
2843 Don't do this in the case where we are forcing a
2844 constant into memory and it will then win since
2845 we don't want to have a different alternative
2847 if (! (REG_P (op
) && REGNO (op
) >= FIRST_PSEUDO_REGISTER
))
2849 if (lra_dump_file
!= NULL
)
2852 " %d Non-pseudo reload: reject+=2\n",
2859 += ira_reg_class_max_nregs
[this_alternative
][mode
];
2861 if (SMALL_REGISTER_CLASS_P (this_alternative
))
2863 if (lra_dump_file
!= NULL
)
2866 " %d Small class reload: reject+=%d\n",
2867 nop
, LRA_LOSER_COST_FACTOR
/ 2);
2868 reject
+= LRA_LOSER_COST_FACTOR
/ 2;
2872 /* We are trying to spill pseudo into memory. It is
2873 usually more costly than moving to a hard register
2874 although it might takes the same number of
2877 Non-pseudo spill may happen also. Suppose a target allows both
2878 register and memory in the operand constraint alternatives,
2879 then it's typical that an eliminable register has a substition
2880 of "base + offset" which can either be reloaded by a simple
2881 "new_reg <= base + offset" which will match the register
2882 constraint, or a similar reg addition followed by further spill
2883 to and reload from memory which will match the memory
2884 constraint, but this memory spill will be much more costly
2887 Code below increases the reject for both pseudo and non-pseudo
2890 && !(MEM_P (op
) && offmemok
)
2891 && !(REG_P (op
) && hard_regno
[nop
] < 0))
2893 if (lra_dump_file
!= NULL
)
2896 " %d Spill %spseudo into memory: reject+=3\n",
2897 nop
, REG_P (op
) ? "" : "Non-");
2899 if (VECTOR_MODE_P (mode
))
2901 /* Spilling vectors into memory is usually more
2902 costly as they contain big values. */
2903 if (lra_dump_file
!= NULL
)
2906 " %d Spill vector pseudo: reject+=2\n",
2912 /* When we use an operand requiring memory in given
2913 alternative, the insn should write *and* read the
2914 value to/from memory it is costly in comparison with
2915 an insn alternative which does not use memory
2916 (e.g. register or immediate operand). We exclude
2917 memory operand for such case as we can satisfy the
2918 memory constraints by reloading address. */
2919 if (no_regs_p
&& offmemok
&& !MEM_P (op
))
2921 if (lra_dump_file
!= NULL
)
2924 " Using memory insn operand %d: reject+=3\n",
2929 /* If reload requires moving value through secondary
2930 memory, it will need one more insn at least. */
2931 if (this_alternative
!= NO_REGS
2932 && REG_P (op
) && (cl
= get_reg_class (REGNO (op
))) != NO_REGS
2933 && ((curr_static_id
->operand
[nop
].type
!= OP_OUT
2934 && targetm
.secondary_memory_needed (GET_MODE (op
), cl
,
2936 || (curr_static_id
->operand
[nop
].type
!= OP_IN
2937 && (targetm
.secondary_memory_needed
2938 (GET_MODE (op
), this_alternative
, cl
)))))
2941 if (MEM_P (op
) && offmemok
)
2945 /* Input reloads can be inherited more often than
2946 output reloads can be removed, so penalize output
2948 if (!REG_P (op
) || curr_static_id
->operand
[nop
].type
!= OP_IN
)
2950 if (lra_dump_file
!= NULL
)
2953 " %d Non input pseudo reload: reject++\n",
2958 if (curr_static_id
->operand
[nop
].type
== OP_INOUT
)
2960 if (lra_dump_file
!= NULL
)
2963 " %d Input/Output reload: reject+=%d\n",
2964 nop
, LRA_LOSER_COST_FACTOR
);
2965 reject
+= LRA_LOSER_COST_FACTOR
;
2970 if (early_clobber_p
&& ! scratch_p
)
2972 if (lra_dump_file
!= NULL
)
2973 fprintf (lra_dump_file
,
2974 " %d Early clobber: reject++\n", nop
);
2977 /* ??? We check early clobbers after processing all operands
2978 (see loop below) and there we update the costs more.
2979 Should we update the cost (may be approximately) here
2980 because of early clobber register reloads or it is a rare
2981 or non-important thing to be worth to do it. */
2982 overall
= (losers
* LRA_LOSER_COST_FACTOR
+ reject
2983 - (addr_losers
== losers
? static_reject
: 0));
2984 if ((best_losers
== 0 || losers
!= 0) && best_overall
< overall
)
2986 if (lra_dump_file
!= NULL
)
2987 fprintf (lra_dump_file
,
2988 " alt=%d,overall=%d,losers=%d -- refuse\n",
2989 nalt
, overall
, losers
);
2993 if (update_and_check_small_class_inputs (nop
, nalt
,
2996 if (lra_dump_file
!= NULL
)
2997 fprintf (lra_dump_file
,
2998 " alt=%d, not enough small class regs -- refuse\n",
3002 curr_alt
[nop
] = this_alternative
;
3003 curr_alt_set
[nop
] = this_alternative_set
;
3004 curr_alt_win
[nop
] = this_alternative_win
;
3005 curr_alt_match_win
[nop
] = this_alternative_match_win
;
3006 curr_alt_offmemok
[nop
] = this_alternative_offmemok
;
3007 curr_alt_matches
[nop
] = this_alternative_matches
;
3009 if (this_alternative_matches
>= 0
3010 && !did_match
&& !this_alternative_win
)
3011 curr_alt_win
[this_alternative_matches
] = false;
3013 if (early_clobber_p
&& operand_reg
[nop
] != NULL_RTX
)
3014 early_clobbered_nops
[early_clobbered_regs_num
++] = nop
;
3017 if (curr_insn_set
!= NULL_RTX
&& n_operands
== 2
3018 /* Prevent processing non-move insns. */
3019 && (GET_CODE (SET_SRC (curr_insn_set
)) == SUBREG
3020 || SET_SRC (curr_insn_set
) == no_subreg_reg_operand
[1])
3021 && ((! curr_alt_win
[0] && ! curr_alt_win
[1]
3022 && REG_P (no_subreg_reg_operand
[0])
3023 && REG_P (no_subreg_reg_operand
[1])
3024 && (reg_in_class_p (no_subreg_reg_operand
[0], curr_alt
[1])
3025 || reg_in_class_p (no_subreg_reg_operand
[1], curr_alt
[0])))
3026 || (! curr_alt_win
[0] && curr_alt_win
[1]
3027 && REG_P (no_subreg_reg_operand
[1])
3028 /* Check that we reload memory not the memory
3030 && ! (curr_alt_offmemok
[0]
3031 && MEM_P (no_subreg_reg_operand
[0]))
3032 && reg_in_class_p (no_subreg_reg_operand
[1], curr_alt
[0]))
3033 || (curr_alt_win
[0] && ! curr_alt_win
[1]
3034 && REG_P (no_subreg_reg_operand
[0])
3035 /* Check that we reload memory not the memory
3037 && ! (curr_alt_offmemok
[1]
3038 && MEM_P (no_subreg_reg_operand
[1]))
3039 && reg_in_class_p (no_subreg_reg_operand
[0], curr_alt
[1])
3040 && (! CONST_POOL_OK_P (curr_operand_mode
[1],
3041 no_subreg_reg_operand
[1])
3042 || (targetm
.preferred_reload_class
3043 (no_subreg_reg_operand
[1],
3044 (enum reg_class
) curr_alt
[1]) != NO_REGS
))
3045 /* If it is a result of recent elimination in move
3046 insn we can transform it into an add still by
3047 using this alternative. */
3048 && GET_CODE (no_subreg_reg_operand
[1]) != PLUS
3049 /* Likewise if the source has been replaced with an
3050 equivalent value. This only happens once -- the reload
3051 will use the equivalent value instead of the register it
3052 replaces -- so there should be no danger of cycling. */
3053 && !equiv_substition_p
[1])))
3055 /* We have a move insn and a new reload insn will be similar
3056 to the current insn. We should avoid such situation as
3057 it results in LRA cycling. */
3058 if (lra_dump_file
!= NULL
)
3059 fprintf (lra_dump_file
,
3060 " Cycle danger: overall += LRA_MAX_REJECT\n");
3061 overall
+= LRA_MAX_REJECT
;
3064 curr_alt_dont_inherit_ops_num
= 0;
3065 for (nop
= 0; nop
< early_clobbered_regs_num
; nop
++)
3067 int i
, j
, clobbered_hard_regno
, first_conflict_j
, last_conflict_j
;
3068 HARD_REG_SET temp_set
;
3070 i
= early_clobbered_nops
[nop
];
3071 if ((! curr_alt_win
[i
] && ! curr_alt_match_win
[i
])
3072 || hard_regno
[i
] < 0)
3074 lra_assert (operand_reg
[i
] != NULL_RTX
);
3075 clobbered_hard_regno
= hard_regno
[i
];
3076 CLEAR_HARD_REG_SET (temp_set
);
3077 add_to_hard_reg_set (&temp_set
, biggest_mode
[i
], clobbered_hard_regno
);
3078 first_conflict_j
= last_conflict_j
= -1;
3079 for (j
= 0; j
< n_operands
; j
++)
3081 /* We don't want process insides of match_operator and
3082 match_parallel because otherwise we would process
3083 their operands once again generating a wrong
3085 || curr_static_id
->operand
[j
].is_operator
)
3087 else if ((curr_alt_matches
[j
] == i
&& curr_alt_match_win
[j
])
3088 || (curr_alt_matches
[i
] == j
&& curr_alt_match_win
[i
]))
3090 /* If we don't reload j-th operand, check conflicts. */
3091 else if ((curr_alt_win
[j
] || curr_alt_match_win
[j
])
3092 && uses_hard_regs_p (*curr_id
->operand_loc
[j
], temp_set
))
3094 if (first_conflict_j
< 0)
3095 first_conflict_j
= j
;
3096 last_conflict_j
= j
;
3097 /* Both the earlyclobber operand and conflicting operand
3098 cannot both be user defined hard registers. */
3099 if (HARD_REGISTER_P (operand_reg
[i
])
3100 && REG_USERVAR_P (operand_reg
[i
])
3101 && operand_reg
[j
] != NULL_RTX
3102 && HARD_REGISTER_P (operand_reg
[j
])
3103 && REG_USERVAR_P (operand_reg
[j
]))
3105 /* For asm, let curr_insn_transform diagnose it. */
3106 if (INSN_CODE (curr_insn
) < 0)
3108 fatal_insn ("unable to generate reloads for "
3109 "impossible constraints:", curr_insn
);
3112 if (last_conflict_j
< 0)
3115 /* If an earlyclobber operand conflicts with another non-matching
3116 operand (ie, they have been assigned the same hard register),
3117 then it is better to reload the other operand, as there may
3118 exist yet another operand with a matching constraint associated
3119 with the earlyclobber operand. However, if one of the operands
3120 is an explicit use of a hard register, then we must reload the
3121 other non-hard register operand. */
3122 if (HARD_REGISTER_P (operand_reg
[i
])
3123 || (first_conflict_j
== last_conflict_j
3124 && operand_reg
[last_conflict_j
] != NULL_RTX
3125 && !curr_alt_match_win
[last_conflict_j
]
3126 && !HARD_REGISTER_P (operand_reg
[last_conflict_j
])))
3128 curr_alt_win
[last_conflict_j
] = false;
3129 curr_alt_dont_inherit_ops
[curr_alt_dont_inherit_ops_num
++]
3132 if (lra_dump_file
!= NULL
)
3135 " %d Conflict early clobber reload: reject--\n",
3140 /* We need to reload early clobbered register and the
3141 matched registers. */
3142 for (j
= 0; j
< n_operands
; j
++)
3143 if (curr_alt_matches
[j
] == i
)
3145 curr_alt_match_win
[j
] = false;
3147 overall
+= LRA_LOSER_COST_FACTOR
;
3149 if (! curr_alt_match_win
[i
])
3150 curr_alt_dont_inherit_ops
[curr_alt_dont_inherit_ops_num
++] = i
;
3153 /* Remember pseudos used for match reloads are never
3155 lra_assert (curr_alt_matches
[i
] >= 0);
3156 curr_alt_win
[curr_alt_matches
[i
]] = false;
3158 curr_alt_win
[i
] = curr_alt_match_win
[i
] = false;
3160 if (lra_dump_file
!= NULL
)
3163 " %d Matched conflict early clobber reloads: "
3167 /* Early clobber was already reflected in REJECT. */
3168 if (!matching_early_clobber
[i
])
3170 lra_assert (reject
> 0);
3172 matching_early_clobber
[i
] = 1;
3174 overall
+= LRA_LOSER_COST_FACTOR
- 1;
3176 if (lra_dump_file
!= NULL
)
3177 fprintf (lra_dump_file
, " alt=%d,overall=%d,losers=%d,rld_nregs=%d\n",
3178 nalt
, overall
, losers
, reload_nregs
);
3180 /* If this alternative can be made to work by reloading, and it
3181 needs less reloading than the others checked so far, record
3182 it as the chosen goal for reloading. */
3183 if ((best_losers
!= 0 && losers
== 0)
3184 || (((best_losers
== 0 && losers
== 0)
3185 || (best_losers
!= 0 && losers
!= 0))
3186 && (best_overall
> overall
3187 || (best_overall
== overall
3188 /* If the cost of the reloads is the same,
3189 prefer alternative which requires minimal
3190 number of reload regs. */
3191 && (reload_nregs
< best_reload_nregs
3192 || (reload_nregs
== best_reload_nregs
3193 && (best_reload_sum
< reload_sum
3194 || (best_reload_sum
== reload_sum
3195 && nalt
< goal_alt_number
))))))))
3197 for (nop
= 0; nop
< n_operands
; nop
++)
3199 goal_alt_win
[nop
] = curr_alt_win
[nop
];
3200 goal_alt_match_win
[nop
] = curr_alt_match_win
[nop
];
3201 goal_alt_matches
[nop
] = curr_alt_matches
[nop
];
3202 goal_alt
[nop
] = curr_alt
[nop
];
3203 goal_alt_offmemok
[nop
] = curr_alt_offmemok
[nop
];
3205 goal_alt_dont_inherit_ops_num
= curr_alt_dont_inherit_ops_num
;
3206 for (nop
= 0; nop
< curr_alt_dont_inherit_ops_num
; nop
++)
3207 goal_alt_dont_inherit_ops
[nop
] = curr_alt_dont_inherit_ops
[nop
];
3208 goal_alt_swapped
= curr_swapped
;
3209 best_overall
= overall
;
3210 best_losers
= losers
;
3211 best_reload_nregs
= reload_nregs
;
3212 best_reload_sum
= reload_sum
;
3213 goal_alt_number
= nalt
;
3216 /* Everything is satisfied. Do not process alternatives
3225 /* Make reload base reg from address AD. */
3227 base_to_reg (struct address_info
*ad
)
3231 rtx new_inner
= NULL_RTX
;
3232 rtx new_reg
= NULL_RTX
;
3234 rtx_insn
*last_insn
= get_last_insn();
3236 lra_assert (ad
->disp
== ad
->disp_term
);
3237 cl
= base_reg_class (ad
->mode
, ad
->as
, ad
->base_outer_code
,
3238 get_index_code (ad
));
3239 new_reg
= lra_create_new_reg (GET_MODE (*ad
->base
), NULL_RTX
,
3241 new_inner
= simplify_gen_binary (PLUS
, GET_MODE (new_reg
), new_reg
,
3242 ad
->disp_term
== NULL
3245 if (!valid_address_p (ad
->mode
, new_inner
, ad
->as
))
3247 insn
= emit_insn (gen_rtx_SET (new_reg
, *ad
->base
));
3248 code
= recog_memoized (insn
);
3251 delete_insns_since (last_insn
);
3258 /* Make reload base reg + DISP from address AD. Return the new pseudo. */
3260 base_plus_disp_to_reg (struct address_info
*ad
, rtx disp
)
3265 lra_assert (ad
->base
== ad
->base_term
);
3266 cl
= base_reg_class (ad
->mode
, ad
->as
, ad
->base_outer_code
,
3267 get_index_code (ad
));
3268 new_reg
= lra_create_new_reg (GET_MODE (*ad
->base_term
), NULL_RTX
,
3270 lra_emit_add (new_reg
, *ad
->base_term
, disp
);
3274 /* Make reload of index part of address AD. Return the new
3277 index_part_to_reg (struct address_info
*ad
)
3281 new_reg
= lra_create_new_reg (GET_MODE (*ad
->index
), NULL_RTX
,
3282 INDEX_REG_CLASS
, "index term");
3283 expand_mult (GET_MODE (*ad
->index
), *ad
->index_term
,
3284 GEN_INT (get_index_scale (ad
)), new_reg
, 1);
3288 /* Return true if we can add a displacement to address AD, even if that
3289 makes the address invalid. The fix-up code requires any new address
3290 to be the sum of the BASE_TERM, INDEX and DISP_TERM fields. */
3292 can_add_disp_p (struct address_info
*ad
)
3294 return (!ad
->autoinc_p
3295 && ad
->segment
== NULL
3296 && ad
->base
== ad
->base_term
3297 && ad
->disp
== ad
->disp_term
);
3300 /* Make equiv substitution in address AD. Return true if a substitution
3303 equiv_address_substitution (struct address_info
*ad
)
3305 rtx base_reg
, new_base_reg
, index_reg
, new_index_reg
, *base_term
, *index_term
;
3307 HOST_WIDE_INT scale
;
3310 base_term
= strip_subreg (ad
->base_term
);
3311 if (base_term
== NULL
)
3312 base_reg
= new_base_reg
= NULL_RTX
;
3315 base_reg
= *base_term
;
3316 new_base_reg
= get_equiv_with_elimination (base_reg
, curr_insn
);
3318 index_term
= strip_subreg (ad
->index_term
);
3319 if (index_term
== NULL
)
3320 index_reg
= new_index_reg
= NULL_RTX
;
3323 index_reg
= *index_term
;
3324 new_index_reg
= get_equiv_with_elimination (index_reg
, curr_insn
);
3326 if (base_reg
== new_base_reg
&& index_reg
== new_index_reg
)
3330 if (lra_dump_file
!= NULL
)
3332 fprintf (lra_dump_file
, "Changing address in insn %d ",
3333 INSN_UID (curr_insn
));
3334 dump_value_slim (lra_dump_file
, *ad
->outer
, 1);
3336 if (base_reg
!= new_base_reg
)
3339 if (REG_P (new_base_reg
))
3341 *base_term
= new_base_reg
;
3344 else if (GET_CODE (new_base_reg
) == PLUS
3345 && REG_P (XEXP (new_base_reg
, 0))
3346 && poly_int_rtx_p (XEXP (new_base_reg
, 1), &offset
)
3347 && can_add_disp_p (ad
))
3350 *base_term
= XEXP (new_base_reg
, 0);
3353 if (ad
->base_term2
!= NULL
)
3354 *ad
->base_term2
= *ad
->base_term
;
3356 if (index_reg
!= new_index_reg
)
3359 if (REG_P (new_index_reg
))
3361 *index_term
= new_index_reg
;
3364 else if (GET_CODE (new_index_reg
) == PLUS
3365 && REG_P (XEXP (new_index_reg
, 0))
3366 && poly_int_rtx_p (XEXP (new_index_reg
, 1), &offset
)
3367 && can_add_disp_p (ad
)
3368 && (scale
= get_index_scale (ad
)))
3370 disp
+= offset
* scale
;
3371 *index_term
= XEXP (new_index_reg
, 0);
3375 if (maybe_ne (disp
, 0))
3377 if (ad
->disp
!= NULL
)
3378 *ad
->disp
= plus_constant (GET_MODE (*ad
->inner
), *ad
->disp
, disp
);
3381 *ad
->inner
= plus_constant (GET_MODE (*ad
->inner
), *ad
->inner
, disp
);
3382 update_address (ad
);
3386 if (lra_dump_file
!= NULL
)
3389 fprintf (lra_dump_file
, " -- no change\n");
3392 fprintf (lra_dump_file
, " on equiv ");
3393 dump_value_slim (lra_dump_file
, *ad
->outer
, 1);
3394 fprintf (lra_dump_file
, "\n");
3400 /* Skip all modifiers and whitespaces in constraint STR and return the
3403 skip_constraint_modifiers (const char *str
)
3408 case '+': case '&' : case '=': case '*': case ' ': case '\t':
3409 case '$': case '^' : case '%': case '?': case '!':
3411 default: return str
;
3415 /* Major function to make reloads for an address in operand NOP or
3416 check its correctness (If CHECK_ONLY_P is true). The supported
3419 1) an address that existed before LRA started, at which point it
3420 must have been valid. These addresses are subject to elimination
3421 and may have become invalid due to the elimination offset being out
3424 2) an address created by forcing a constant to memory
3425 (force_const_to_mem). The initial form of these addresses might
3426 not be valid, and it is this function's job to make them valid.
3428 3) a frame address formed from a register and a (possibly zero)
3429 constant offset. As above, these addresses might not be valid and
3430 this function must make them so.
3432 Add reloads to the lists *BEFORE and *AFTER. We might need to add
3433 reloads to *AFTER because of inc/dec, {pre, post} modify in the
3434 address. Return true for any RTL change.
3436 The function is a helper function which does not produce all
3437 transformations (when CHECK_ONLY_P is false) which can be
3438 necessary. It does just basic steps. To do all necessary
3439 transformations use function process_address. */
3441 process_address_1 (int nop
, bool check_only_p
,
3442 rtx_insn
**before
, rtx_insn
**after
)
3444 struct address_info ad
;
3446 HOST_WIDE_INT scale
;
3447 rtx op
= *curr_id
->operand_loc
[nop
];
3448 rtx mem
= extract_mem_from_operand (op
);
3449 const char *constraint
;
3450 enum constraint_num cn
;
3451 bool change_p
= false;
3454 && GET_MODE (mem
) == BLKmode
3455 && GET_CODE (XEXP (mem
, 0)) == SCRATCH
)
3459 = skip_constraint_modifiers (curr_static_id
->operand
[nop
].constraint
);
3460 if (IN_RANGE (constraint
[0], '0', '9'))
3463 unsigned long dup
= strtoul (constraint
, &end
, 10);
3465 = skip_constraint_modifiers (curr_static_id
->operand
[dup
].constraint
);
3467 cn
= lookup_constraint (*constraint
== '\0' ? "X" : constraint
);
3468 /* If we have several alternatives or/and several constraints in an
3469 alternative and we can not say at this stage what constraint will be used,
3470 use unknown constraint. The exception is an address constraint. If
3471 operand has one address constraint, probably all others constraints are
3473 if (constraint
[0] != '\0' && get_constraint_type (cn
) != CT_ADDRESS
3474 && *skip_constraint_modifiers (constraint
3475 + CONSTRAINT_LEN (constraint
[0],
3476 constraint
)) != '\0')
3477 cn
= CONSTRAINT__UNKNOWN
;
3478 if (insn_extra_address_constraint (cn
)
3479 /* When we find an asm operand with an address constraint that
3480 doesn't satisfy address_operand to begin with, we clear
3481 is_address, so that we don't try to make a non-address fit.
3482 If the asm statement got this far, it's because other
3483 constraints are available, and we'll use them, disregarding
3484 the unsatisfiable address ones. */
3485 && curr_static_id
->operand
[nop
].is_address
)
3486 decompose_lea_address (&ad
, curr_id
->operand_loc
[nop
]);
3487 /* Do not attempt to decompose arbitrary addresses generated by combine
3488 for asm operands with loose constraints, e.g 'X'.
3489 Need to extract memory from op for special memory constraint,
3490 i.e. bcst_mem_operand in i386 backend. */
3491 else if (MEM_P (mem
)
3492 && !(INSN_CODE (curr_insn
) < 0
3493 && get_constraint_type (cn
) == CT_FIXED_FORM
3494 && constraint_satisfied_p (op
, cn
)))
3495 decompose_mem_address (&ad
, mem
);
3496 else if (GET_CODE (op
) == SUBREG
3497 && MEM_P (SUBREG_REG (op
)))
3498 decompose_mem_address (&ad
, SUBREG_REG (op
));
3501 /* If INDEX_REG_CLASS is assigned to base_term already and isn't to
3502 index_term, swap them so to avoid assigning INDEX_REG_CLASS to both
3503 when INDEX_REG_CLASS is a single register class. */
3504 if (ad
.base_term
!= NULL
3505 && ad
.index_term
!= NULL
3506 && ira_class_hard_regs_num
[INDEX_REG_CLASS
] == 1
3507 && REG_P (*ad
.base_term
)
3508 && REG_P (*ad
.index_term
)
3509 && in_class_p (*ad
.base_term
, INDEX_REG_CLASS
, NULL
)
3510 && ! in_class_p (*ad
.index_term
, INDEX_REG_CLASS
, NULL
))
3512 std::swap (ad
.base
, ad
.index
);
3513 std::swap (ad
.base_term
, ad
.index_term
);
3516 change_p
= equiv_address_substitution (&ad
);
3517 if (ad
.base_term
!= NULL
3518 && (process_addr_reg
3519 (ad
.base_term
, check_only_p
, before
,
3521 && !(REG_P (*ad
.base_term
)
3522 && find_regno_note (curr_insn
, REG_DEAD
,
3523 REGNO (*ad
.base_term
)) != NULL_RTX
)
3525 base_reg_class (ad
.mode
, ad
.as
, ad
.base_outer_code
,
3526 get_index_code (&ad
)))))
3529 if (ad
.base_term2
!= NULL
)
3530 *ad
.base_term2
= *ad
.base_term
;
3532 if (ad
.index_term
!= NULL
3533 && process_addr_reg (ad
.index_term
, check_only_p
,
3534 before
, NULL
, INDEX_REG_CLASS
))
3537 /* Target hooks sometimes don't treat extra-constraint addresses as
3538 legitimate address_operands, so handle them specially. */
3539 if (insn_extra_address_constraint (cn
)
3540 && satisfies_address_constraint_p (&ad
, cn
))
3546 /* There are three cases where the shape of *AD.INNER may now be invalid:
3548 1) the original address was valid, but either elimination or
3549 equiv_address_substitution was applied and that made
3550 the address invalid.
3552 2) the address is an invalid symbolic address created by
3555 3) the address is a frame address with an invalid offset.
3557 4) the address is a frame address with an invalid base.
3559 All these cases involve a non-autoinc address, so there is no
3560 point revalidating other types. */
3561 if (ad
.autoinc_p
|| valid_address_p (op
, &ad
, cn
))
3564 /* Any index existed before LRA started, so we can assume that the
3565 presence and shape of the index is valid. */
3566 push_to_sequence (*before
);
3567 lra_assert (ad
.disp
== ad
.disp_term
);
3568 if (ad
.base
== NULL
)
3570 if (ad
.index
== NULL
)
3573 rtx_insn
*last
= get_last_insn ();
3575 enum reg_class cl
= base_reg_class (ad
.mode
, ad
.as
,
3577 rtx addr
= *ad
.inner
;
3579 new_reg
= lra_create_new_reg (Pmode
, NULL_RTX
, cl
, "addr");
3582 /* addr => lo_sum (new_base, addr), case (2) above. */
3583 insn
= emit_insn (gen_rtx_SET
3585 gen_rtx_HIGH (Pmode
, copy_rtx (addr
))));
3586 code
= recog_memoized (insn
);
3589 *ad
.inner
= gen_rtx_LO_SUM (Pmode
, new_reg
, addr
);
3590 if (!valid_address_p (op
, &ad
, cn
))
3592 /* Try to put lo_sum into register. */
3593 insn
= emit_insn (gen_rtx_SET
3595 gen_rtx_LO_SUM (Pmode
, new_reg
, addr
)));
3596 code
= recog_memoized (insn
);
3599 *ad
.inner
= new_reg
;
3600 if (!valid_address_p (op
, &ad
, cn
))
3610 delete_insns_since (last
);
3615 /* addr => new_base, case (2) above. */
3616 lra_emit_move (new_reg
, addr
);
3618 for (insn
= last
== NULL_RTX
? get_insns () : NEXT_INSN (last
);
3620 insn
= NEXT_INSN (insn
))
3621 if (recog_memoized (insn
) < 0)
3623 if (insn
!= NULL_RTX
)
3625 /* Do nothing if we cannot generate right insns.
3626 This is analogous to reload pass behavior. */
3627 delete_insns_since (last
);
3631 *ad
.inner
= new_reg
;
3636 /* index * scale + disp => new base + index * scale,
3638 enum reg_class cl
= base_reg_class (ad
.mode
, ad
.as
, PLUS
,
3639 GET_CODE (*ad
.index
));
3641 lra_assert (INDEX_REG_CLASS
!= NO_REGS
);
3642 new_reg
= lra_create_new_reg (Pmode
, NULL_RTX
, cl
, "disp");
3643 lra_emit_move (new_reg
, *ad
.disp
);
3644 *ad
.inner
= simplify_gen_binary (PLUS
, GET_MODE (new_reg
),
3645 new_reg
, *ad
.index
);
3648 else if (ad
.index
== NULL
)
3653 rtx_insn
*insns
, *last_insn
;
3654 /* Try to reload base into register only if the base is invalid
3655 for the address but with valid offset, case (4) above. */
3657 new_reg
= base_to_reg (&ad
);
3659 /* base + disp => new base, cases (1) and (3) above. */
3660 /* Another option would be to reload the displacement into an
3661 index register. However, postreload has code to optimize
3662 address reloads that have the same base and different
3663 displacements, so reloading into an index register would
3664 not necessarily be a win. */
3665 if (new_reg
== NULL_RTX
)
3667 /* See if the target can split the displacement into a
3668 legitimate new displacement from a local anchor. */
3669 gcc_assert (ad
.disp
== ad
.disp_term
);
3670 poly_int64 orig_offset
;
3671 rtx offset1
, offset2
;
3672 if (poly_int_rtx_p (*ad
.disp
, &orig_offset
)
3673 && targetm
.legitimize_address_displacement (&offset1
, &offset2
,
3677 new_reg
= base_plus_disp_to_reg (&ad
, offset1
);
3678 new_reg
= gen_rtx_PLUS (GET_MODE (new_reg
), new_reg
, offset2
);
3681 new_reg
= base_plus_disp_to_reg (&ad
, *ad
.disp
);
3683 insns
= get_insns ();
3684 last_insn
= get_last_insn ();
3685 /* If we generated at least two insns, try last insn source as
3686 an address. If we succeed, we generate one less insn. */
3688 && last_insn
!= insns
3689 && (set
= single_set (last_insn
)) != NULL_RTX
3690 && GET_CODE (SET_SRC (set
)) == PLUS
3691 && REG_P (XEXP (SET_SRC (set
), 0))
3692 && CONSTANT_P (XEXP (SET_SRC (set
), 1)))
3694 *ad
.inner
= SET_SRC (set
);
3695 if (valid_address_p (op
, &ad
, cn
))
3697 *ad
.base_term
= XEXP (SET_SRC (set
), 0);
3698 *ad
.disp_term
= XEXP (SET_SRC (set
), 1);
3699 cl
= base_reg_class (ad
.mode
, ad
.as
, ad
.base_outer_code
,
3700 get_index_code (&ad
));
3701 regno
= REGNO (*ad
.base_term
);
3702 if (regno
>= FIRST_PSEUDO_REGISTER
3703 && cl
!= lra_get_allocno_class (regno
))
3704 lra_change_class (regno
, cl
, " Change to", true);
3705 new_reg
= SET_SRC (set
);
3706 delete_insns_since (PREV_INSN (last_insn
));
3711 *ad
.inner
= new_reg
;
3713 else if (ad
.disp_term
!= NULL
)
3715 /* base + scale * index + disp => new base + scale * index,
3717 gcc_assert (ad
.disp
== ad
.disp_term
);
3718 new_reg
= base_plus_disp_to_reg (&ad
, *ad
.disp
);
3719 *ad
.inner
= simplify_gen_binary (PLUS
, GET_MODE (new_reg
),
3720 new_reg
, *ad
.index
);
3722 else if ((scale
= get_index_scale (&ad
)) == 1)
3724 /* The last transformation to one reg will be made in
3725 curr_insn_transform function. */
3729 else if (scale
!= 0)
3731 /* base + scale * index => base + new_reg,
3733 Index part of address may become invalid. For example, we
3734 changed pseudo on the equivalent memory and a subreg of the
3735 pseudo onto the memory of different mode for which the scale is
3737 new_reg
= index_part_to_reg (&ad
);
3738 *ad
.inner
= simplify_gen_binary (PLUS
, GET_MODE (new_reg
),
3739 *ad
.base_term
, new_reg
);
3743 enum reg_class cl
= base_reg_class (ad
.mode
, ad
.as
,
3745 rtx addr
= *ad
.inner
;
3747 new_reg
= lra_create_new_reg (Pmode
, NULL_RTX
, cl
, "addr");
3748 /* addr => new_base. */
3749 lra_emit_move (new_reg
, addr
);
3750 *ad
.inner
= new_reg
;
3752 *before
= get_insns ();
3757 /* If CHECK_ONLY_P is false, do address reloads until it is necessary.
3758 Use process_address_1 as a helper function. Return true for any
3761 If CHECK_ONLY_P is true, just check address correctness. Return
3762 false if the address correct. */
3764 process_address (int nop
, bool check_only_p
,
3765 rtx_insn
**before
, rtx_insn
**after
)
3769 while (process_address_1 (nop
, check_only_p
, before
, after
))
3778 /* Emit insns to reload VALUE into a new register. VALUE is an
3779 auto-increment or auto-decrement RTX whose operand is a register or
3780 memory location; so reloading involves incrementing that location.
3781 IN is either identical to VALUE, or some cheaper place to reload
3782 value being incremented/decremented from.
3784 INC_AMOUNT is the number to increment or decrement by (always
3785 positive and ignored for POST_MODIFY/PRE_MODIFY).
3787 Return pseudo containing the result. */
3789 emit_inc (enum reg_class new_rclass
, rtx in
, rtx value
, poly_int64 inc_amount
)
3791 /* REG or MEM to be copied and incremented. */
3792 rtx incloc
= XEXP (value
, 0);
3793 /* Nonzero if increment after copying. */
3794 int post
= (GET_CODE (value
) == POST_DEC
|| GET_CODE (value
) == POST_INC
3795 || GET_CODE (value
) == POST_MODIFY
);
3800 rtx real_in
= in
== value
? incloc
: in
;
3804 if (GET_CODE (value
) == PRE_MODIFY
|| GET_CODE (value
) == POST_MODIFY
)
3806 lra_assert (GET_CODE (XEXP (value
, 1)) == PLUS
3807 || GET_CODE (XEXP (value
, 1)) == MINUS
);
3808 lra_assert (rtx_equal_p (XEXP (XEXP (value
, 1), 0), XEXP (value
, 0)));
3809 plus_p
= GET_CODE (XEXP (value
, 1)) == PLUS
;
3810 inc
= XEXP (XEXP (value
, 1), 1);
3814 if (GET_CODE (value
) == PRE_DEC
|| GET_CODE (value
) == POST_DEC
)
3815 inc_amount
= -inc_amount
;
3817 inc
= gen_int_mode (inc_amount
, GET_MODE (value
));
3820 if (! post
&& REG_P (incloc
))
3823 result
= lra_create_new_reg (GET_MODE (value
), value
, new_rclass
,
3826 if (real_in
!= result
)
3828 /* First copy the location to the result register. */
3829 lra_assert (REG_P (result
));
3830 emit_insn (gen_move_insn (result
, real_in
));
3833 /* We suppose that there are insns to add/sub with the constant
3834 increment permitted in {PRE/POST)_{DEC/INC/MODIFY}. At least the
3835 old reload worked with this assumption. If the assumption
3836 becomes wrong, we should use approach in function
3837 base_plus_disp_to_reg. */
3840 /* See if we can directly increment INCLOC. */
3841 last
= get_last_insn ();
3842 add_insn
= emit_insn (plus_p
3843 ? gen_add2_insn (incloc
, inc
)
3844 : gen_sub2_insn (incloc
, inc
));
3846 code
= recog_memoized (add_insn
);
3849 if (! post
&& result
!= incloc
)
3850 emit_insn (gen_move_insn (result
, incloc
));
3853 delete_insns_since (last
);
3856 /* If couldn't do the increment directly, must increment in RESULT.
3857 The way we do this depends on whether this is pre- or
3858 post-increment. For pre-increment, copy INCLOC to the reload
3859 register, increment it there, then save back. */
3862 if (real_in
!= result
)
3863 emit_insn (gen_move_insn (result
, real_in
));
3865 emit_insn (gen_add2_insn (result
, inc
));
3867 emit_insn (gen_sub2_insn (result
, inc
));
3868 if (result
!= incloc
)
3869 emit_insn (gen_move_insn (incloc
, result
));
3875 Because this might be a jump insn or a compare, and because
3876 RESULT may not be available after the insn in an input
3877 reload, we must do the incrementing before the insn being
3880 We have already copied IN to RESULT. Increment the copy in
3881 RESULT, save that back, then decrement RESULT so it has
3882 the original value. */
3884 emit_insn (gen_add2_insn (result
, inc
));
3886 emit_insn (gen_sub2_insn (result
, inc
));
3887 emit_insn (gen_move_insn (incloc
, result
));
3888 /* Restore non-modified value for the result. We prefer this
3889 way because it does not require an additional hard
3894 if (poly_int_rtx_p (inc
, &offset
))
3895 emit_insn (gen_add2_insn (result
,
3896 gen_int_mode (-offset
,
3897 GET_MODE (result
))));
3899 emit_insn (gen_sub2_insn (result
, inc
));
3902 emit_insn (gen_add2_insn (result
, inc
));
3907 /* Return true if the current move insn does not need processing as we
3908 already know that it satisfies its constraints. */
3910 simple_move_p (void)
3913 enum reg_class dclass
, sclass
;
3915 lra_assert (curr_insn_set
!= NULL_RTX
);
3916 dest
= SET_DEST (curr_insn_set
);
3917 src
= SET_SRC (curr_insn_set
);
3919 /* If the instruction has multiple sets we need to process it even if it
3920 is single_set. This can happen if one or more of the SETs are dead.
3922 if (multiple_sets (curr_insn
))
3925 return ((dclass
= get_op_class (dest
)) != NO_REGS
3926 && (sclass
= get_op_class (src
)) != NO_REGS
3927 /* The backend guarantees that register moves of cost 2
3928 never need reloads. */
3929 && targetm
.register_move_cost (GET_MODE (src
), sclass
, dclass
) == 2);
3932 /* Swap operands NOP and NOP + 1. */
3934 swap_operands (int nop
)
3936 std::swap (curr_operand_mode
[nop
], curr_operand_mode
[nop
+ 1]);
3937 std::swap (original_subreg_reg_mode
[nop
], original_subreg_reg_mode
[nop
+ 1]);
3938 std::swap (*curr_id
->operand_loc
[nop
], *curr_id
->operand_loc
[nop
+ 1]);
3939 std::swap (equiv_substition_p
[nop
], equiv_substition_p
[nop
+ 1]);
3940 /* Swap the duplicates too. */
3941 lra_update_dup (curr_id
, nop
);
3942 lra_update_dup (curr_id
, nop
+ 1);
3945 /* Main entry point of the constraint code: search the body of the
3946 current insn to choose the best alternative. It is mimicking insn
3947 alternative cost calculation model of former reload pass. That is
3948 because machine descriptions were written to use this model. This
3949 model can be changed in future. Make commutative operand exchange
3952 if CHECK_ONLY_P is false, do RTL changes to satisfy the
3953 constraints. Return true if any change happened during function
3956 If CHECK_ONLY_P is true then don't do any transformation. Just
3957 check that the insn satisfies all constraints. If the insn does
3958 not satisfy any constraint, return true. */
3960 curr_insn_transform (bool check_only_p
)
3967 signed char goal_alt_matched
[MAX_RECOG_OPERANDS
][MAX_RECOG_OPERANDS
];
3968 signed char match_inputs
[MAX_RECOG_OPERANDS
+ 1];
3969 signed char outputs
[MAX_RECOG_OPERANDS
+ 1];
3970 rtx_insn
*before
, *after
;
3972 /* Flag that the insn has been changed through a transformation. */
3976 int max_regno_before
;
3977 int reused_alternative_num
;
3979 curr_insn_set
= single_set (curr_insn
);
3980 if (curr_insn_set
!= NULL_RTX
&& simple_move_p ())
3982 /* We assume that the corresponding insn alternative has no
3983 earlier clobbers. If it is not the case, don't define move
3984 cost equal to 2 for the corresponding register classes. */
3985 lra_set_used_insn_alternative (curr_insn
, LRA_NON_CLOBBERED_ALT
);
3989 no_input_reloads_p
= no_output_reloads_p
= false;
3990 goal_alt_number
= -1;
3991 change_p
= sec_mem_p
= false;
3993 /* CALL_INSNs are not allowed to have any output reloads. */
3994 if (CALL_P (curr_insn
))
3995 no_output_reloads_p
= true;
3997 n_operands
= curr_static_id
->n_operands
;
3998 n_alternatives
= curr_static_id
->n_alternatives
;
4000 /* Just return "no reloads" if insn has no operands with
4002 if (n_operands
== 0 || n_alternatives
== 0)
4005 max_regno_before
= max_reg_num ();
4007 for (i
= 0; i
< n_operands
; i
++)
4009 goal_alt_matched
[i
][0] = -1;
4010 goal_alt_matches
[i
] = -1;
4013 commutative
= curr_static_id
->commutative
;
4015 /* Now see what we need for pseudos that didn't get hard regs or got
4016 the wrong kind of hard reg. For this, we must consider all the
4017 operands together against the register constraints. */
4019 best_losers
= best_overall
= INT_MAX
;
4020 best_reload_sum
= 0;
4022 curr_swapped
= false;
4023 goal_alt_swapped
= false;
4026 /* Make equivalence substitution and memory subreg elimination
4027 before address processing because an address legitimacy can
4028 depend on memory mode. */
4029 for (i
= 0; i
< n_operands
; i
++)
4032 bool op_change_p
= false;
4034 if (curr_static_id
->operand
[i
].is_operator
)
4037 old
= op
= *curr_id
->operand_loc
[i
];
4038 if (GET_CODE (old
) == SUBREG
)
4039 old
= SUBREG_REG (old
);
4040 subst
= get_equiv_with_elimination (old
, curr_insn
);
4041 original_subreg_reg_mode
[i
] = VOIDmode
;
4042 equiv_substition_p
[i
] = false;
4045 equiv_substition_p
[i
] = true;
4046 subst
= copy_rtx (subst
);
4047 lra_assert (REG_P (old
));
4048 if (GET_CODE (op
) != SUBREG
)
4049 *curr_id
->operand_loc
[i
] = subst
;
4052 SUBREG_REG (op
) = subst
;
4053 if (GET_MODE (subst
) == VOIDmode
)
4054 original_subreg_reg_mode
[i
] = GET_MODE (old
);
4056 if (lra_dump_file
!= NULL
)
4058 fprintf (lra_dump_file
,
4059 "Changing pseudo %d in operand %i of insn %u on equiv ",
4060 REGNO (old
), i
, INSN_UID (curr_insn
));
4061 dump_value_slim (lra_dump_file
, subst
, 1);
4062 fprintf (lra_dump_file
, "\n");
4064 op_change_p
= change_p
= true;
4066 if (simplify_operand_subreg (i
, GET_MODE (old
)) || op_change_p
)
4069 lra_update_dup (curr_id
, i
);
4073 /* Reload address registers and displacements. We do it before
4074 finding an alternative because of memory constraints. */
4075 before
= after
= NULL
;
4076 for (i
= 0; i
< n_operands
; i
++)
4077 if (! curr_static_id
->operand
[i
].is_operator
4078 && process_address (i
, check_only_p
, &before
, &after
))
4083 lra_update_dup (curr_id
, i
);
4087 /* If we've changed the instruction then any alternative that
4088 we chose previously may no longer be valid. */
4089 lra_set_used_insn_alternative (curr_insn
, LRA_UNKNOWN_ALT
);
4091 if (! check_only_p
&& curr_insn_set
!= NULL_RTX
4092 && check_and_process_move (&change_p
, &sec_mem_p
))
4097 reused_alternative_num
= check_only_p
? LRA_UNKNOWN_ALT
: curr_id
->used_insn_alternative
;
4098 if (lra_dump_file
!= NULL
&& reused_alternative_num
>= 0)
4099 fprintf (lra_dump_file
, "Reusing alternative %d for insn #%u\n",
4100 reused_alternative_num
, INSN_UID (curr_insn
));
4102 if (process_alt_operands (reused_alternative_num
))
4106 return ! alt_p
|| best_losers
!= 0;
4108 /* If insn is commutative (it's safe to exchange a certain pair of
4109 operands) then we need to try each alternative twice, the second
4110 time matching those two operands as if we had exchanged them. To
4111 do this, really exchange them in operands.
4113 If we have just tried the alternatives the second time, return
4114 operands to normal and drop through. */
4116 if (reused_alternative_num
< 0 && commutative
>= 0)
4118 curr_swapped
= !curr_swapped
;
4121 swap_operands (commutative
);
4125 swap_operands (commutative
);
4128 if (! alt_p
&& ! sec_mem_p
)
4130 /* No alternative works with reloads?? */
4131 if (INSN_CODE (curr_insn
) >= 0)
4132 fatal_insn ("unable to generate reloads for:", curr_insn
);
4133 error_for_asm (curr_insn
,
4134 "inconsistent operand constraints in an %<asm%>");
4135 lra_asm_error_p
= true;
4136 if (! JUMP_P (curr_insn
))
4138 /* Avoid further trouble with this insn. Don't generate use
4139 pattern here as we could use the insn SP offset. */
4140 lra_set_insn_deleted (curr_insn
);
4144 lra_invalidate_insn_data (curr_insn
);
4145 ira_nullify_asm_goto (curr_insn
);
4146 lra_update_insn_regno_info (curr_insn
);
4151 /* If the best alternative is with operands 1 and 2 swapped, swap
4152 them. Update the operand numbers of any reloads already
4155 if (goal_alt_swapped
)
4157 if (lra_dump_file
!= NULL
)
4158 fprintf (lra_dump_file
, " Commutative operand exchange in insn %u\n",
4159 INSN_UID (curr_insn
));
4161 /* Swap the duplicates too. */
4162 swap_operands (commutative
);
4166 /* Some targets' TARGET_SECONDARY_MEMORY_NEEDED (e.g. x86) are defined
4167 too conservatively. So we use the secondary memory only if there
4168 is no any alternative without reloads. */
4169 use_sec_mem_p
= false;
4171 use_sec_mem_p
= true;
4174 for (i
= 0; i
< n_operands
; i
++)
4175 if (! goal_alt_win
[i
] && ! goal_alt_match_win
[i
])
4177 use_sec_mem_p
= i
< n_operands
;
4182 int in
= -1, out
= -1;
4183 rtx new_reg
, src
, dest
, rld
;
4184 machine_mode sec_mode
, rld_mode
;
4186 lra_assert (curr_insn_set
!= NULL_RTX
&& sec_mem_p
);
4187 dest
= SET_DEST (curr_insn_set
);
4188 src
= SET_SRC (curr_insn_set
);
4189 for (i
= 0; i
< n_operands
; i
++)
4190 if (*curr_id
->operand_loc
[i
] == dest
)
4192 else if (*curr_id
->operand_loc
[i
] == src
)
4194 for (i
= 0; i
< curr_static_id
->n_dups
; i
++)
4195 if (out
< 0 && *curr_id
->dup_loc
[i
] == dest
)
4196 out
= curr_static_id
->dup_num
[i
];
4197 else if (in
< 0 && *curr_id
->dup_loc
[i
] == src
)
4198 in
= curr_static_id
->dup_num
[i
];
4199 lra_assert (out
>= 0 && in
>= 0
4200 && curr_static_id
->operand
[out
].type
== OP_OUT
4201 && curr_static_id
->operand
[in
].type
== OP_IN
);
4202 rld
= partial_subreg_p (GET_MODE (src
), GET_MODE (dest
)) ? src
: dest
;
4203 rld_mode
= GET_MODE (rld
);
4204 sec_mode
= targetm
.secondary_memory_needed_mode (rld_mode
);
4205 new_reg
= lra_create_new_reg (sec_mode
, NULL_RTX
,
4206 NO_REGS
, "secondary");
4207 /* If the mode is changed, it should be wider. */
4208 lra_assert (!partial_subreg_p (sec_mode
, rld_mode
));
4209 if (sec_mode
!= rld_mode
)
4211 /* If the target says specifically to use another mode for
4212 secondary memory moves we cannot reuse the original
4214 after
= emit_spill_move (false, new_reg
, dest
);
4215 lra_process_new_insns (curr_insn
, NULL
, after
,
4216 "Inserting the sec. move");
4217 /* We may have non null BEFORE here (e.g. after address
4219 push_to_sequence (before
);
4220 before
= emit_spill_move (true, new_reg
, src
);
4222 before
= get_insns ();
4224 lra_process_new_insns (curr_insn
, before
, NULL
, "Changing on");
4225 lra_set_insn_deleted (curr_insn
);
4227 else if (dest
== rld
)
4229 *curr_id
->operand_loc
[out
] = new_reg
;
4230 lra_update_dup (curr_id
, out
);
4231 after
= emit_spill_move (false, new_reg
, dest
);
4232 lra_process_new_insns (curr_insn
, NULL
, after
,
4233 "Inserting the sec. move");
4237 *curr_id
->operand_loc
[in
] = new_reg
;
4238 lra_update_dup (curr_id
, in
);
4239 /* See comments above. */
4240 push_to_sequence (before
);
4241 before
= emit_spill_move (true, new_reg
, src
);
4243 before
= get_insns ();
4245 lra_process_new_insns (curr_insn
, before
, NULL
,
4246 "Inserting the sec. move");
4248 lra_update_insn_regno_info (curr_insn
);
4252 lra_assert (goal_alt_number
>= 0);
4253 lra_set_used_insn_alternative (curr_insn
, goal_alt_number
);
4255 if (lra_dump_file
!= NULL
)
4259 fprintf (lra_dump_file
, " Choosing alt %d in insn %u:",
4260 goal_alt_number
, INSN_UID (curr_insn
));
4261 for (i
= 0; i
< n_operands
; i
++)
4263 p
= (curr_static_id
->operand_alternative
4264 [goal_alt_number
* n_operands
+ i
].constraint
);
4267 fprintf (lra_dump_file
, " (%d) ", i
);
4268 for (; *p
!= '\0' && *p
!= ',' && *p
!= '#'; p
++)
4269 fputc (*p
, lra_dump_file
);
4271 if (INSN_CODE (curr_insn
) >= 0
4272 && (p
= get_insn_name (INSN_CODE (curr_insn
))) != NULL
)
4273 fprintf (lra_dump_file
, " {%s}", p
);
4274 if (maybe_ne (curr_id
->sp_offset
, 0))
4276 fprintf (lra_dump_file
, " (sp_off=");
4277 print_dec (curr_id
->sp_offset
, lra_dump_file
);
4278 fprintf (lra_dump_file
, ")");
4280 fprintf (lra_dump_file
, "\n");
4283 /* Right now, for any pair of operands I and J that are required to
4284 match, with J < I, goal_alt_matches[I] is J. Add I to
4285 goal_alt_matched[J]. */
4287 for (i
= 0; i
< n_operands
; i
++)
4288 if ((j
= goal_alt_matches
[i
]) >= 0)
4290 for (k
= 0; goal_alt_matched
[j
][k
] >= 0; k
++)
4292 /* We allow matching one output operand and several input
4295 || (curr_static_id
->operand
[j
].type
== OP_OUT
4296 && curr_static_id
->operand
[i
].type
== OP_IN
4297 && (curr_static_id
->operand
4298 [goal_alt_matched
[j
][0]].type
== OP_IN
)));
4299 goal_alt_matched
[j
][k
] = i
;
4300 goal_alt_matched
[j
][k
+ 1] = -1;
4303 for (i
= 0; i
< n_operands
; i
++)
4304 goal_alt_win
[i
] |= goal_alt_match_win
[i
];
4306 /* Any constants that aren't allowed and can't be reloaded into
4307 registers are here changed into memory references. */
4308 for (i
= 0; i
< n_operands
; i
++)
4309 if (goal_alt_win
[i
])
4312 enum reg_class new_class
;
4313 rtx reg
= *curr_id
->operand_loc
[i
];
4315 if (GET_CODE (reg
) == SUBREG
)
4316 reg
= SUBREG_REG (reg
);
4318 if (REG_P (reg
) && (regno
= REGNO (reg
)) >= FIRST_PSEUDO_REGISTER
)
4320 bool ok_p
= in_class_p (reg
, goal_alt
[i
], &new_class
);
4322 if (new_class
!= NO_REGS
&& get_reg_class (regno
) != new_class
)
4325 lra_change_class (regno
, new_class
, " Change to", true);
4331 const char *constraint
;
4333 rtx op
= *curr_id
->operand_loc
[i
];
4334 rtx subreg
= NULL_RTX
;
4335 machine_mode mode
= curr_operand_mode
[i
];
4337 if (GET_CODE (op
) == SUBREG
)
4340 op
= SUBREG_REG (op
);
4341 mode
= GET_MODE (op
);
4344 if (CONST_POOL_OK_P (mode
, op
)
4345 && ((targetm
.preferred_reload_class
4346 (op
, (enum reg_class
) goal_alt
[i
]) == NO_REGS
)
4347 || no_input_reloads_p
))
4349 rtx tem
= force_const_mem (mode
, op
);
4352 if (subreg
!= NULL_RTX
)
4353 tem
= gen_rtx_SUBREG (mode
, tem
, SUBREG_BYTE (subreg
));
4355 *curr_id
->operand_loc
[i
] = tem
;
4356 lra_update_dup (curr_id
, i
);
4357 process_address (i
, false, &before
, &after
);
4359 /* If the alternative accepts constant pool refs directly
4360 there will be no reload needed at all. */
4361 if (subreg
!= NULL_RTX
)
4363 /* Skip alternatives before the one requested. */
4364 constraint
= (curr_static_id
->operand_alternative
4365 [goal_alt_number
* n_operands
+ i
].constraint
);
4367 (c
= *constraint
) && c
!= ',' && c
!= '#';
4368 constraint
+= CONSTRAINT_LEN (c
, constraint
))
4370 enum constraint_num cn
= lookup_constraint (constraint
);
4371 if ((insn_extra_memory_constraint (cn
)
4372 || insn_extra_special_memory_constraint (cn
)
4373 || insn_extra_relaxed_memory_constraint (cn
))
4374 && satisfies_memory_constraint_p (tem
, cn
))
4377 if (c
== '\0' || c
== ',' || c
== '#')
4380 goal_alt_win
[i
] = true;
4385 for (i
= 0; i
< n_operands
; i
++)
4386 if (curr_static_id
->operand
[i
].type
== OP_OUT
)
4387 outputs
[n_outputs
++] = i
;
4388 outputs
[n_outputs
] = -1;
4389 for (i
= 0; i
< n_operands
; i
++)
4392 bool optional_p
= false;
4394 rtx op
= *curr_id
->operand_loc
[i
];
4396 if (goal_alt_win
[i
])
4398 if (goal_alt
[i
] == NO_REGS
4400 /* When we assign NO_REGS it means that we will not
4401 assign a hard register to the scratch pseudo by
4402 assigment pass and the scratch pseudo will be
4403 spilled. Spilled scratch pseudos are transformed
4404 back to scratches at the LRA end. */
4405 && ira_former_scratch_operand_p (curr_insn
, i
)
4406 && ira_former_scratch_p (REGNO (op
)))
4408 int regno
= REGNO (op
);
4409 lra_change_class (regno
, NO_REGS
, " Change to", true);
4410 if (lra_get_regno_hard_regno (regno
) >= 0)
4411 /* We don't have to mark all insn affected by the
4412 spilled pseudo as there is only one such insn, the
4414 reg_renumber
[regno
] = -1;
4415 lra_assert (bitmap_single_bit_set_p
4416 (&lra_reg_info
[REGNO (op
)].insn_bitmap
));
4418 /* We can do an optional reload. If the pseudo got a hard
4419 reg, we might improve the code through inheritance. If
4420 it does not get a hard register we coalesce memory/memory
4421 moves later. Ignore move insns to avoid cycling. */
4423 && lra_undo_inheritance_iter
< LRA_MAX_INHERITANCE_PASSES
4424 && goal_alt
[i
] != NO_REGS
&& REG_P (op
)
4425 && (regno
= REGNO (op
)) >= FIRST_PSEUDO_REGISTER
4426 && regno
< new_regno_start
4427 && ! ira_former_scratch_p (regno
)
4428 && reg_renumber
[regno
] < 0
4429 /* Check that the optional reload pseudo will be able to
4430 hold given mode value. */
4431 && ! (prohibited_class_reg_set_mode_p
4432 (goal_alt
[i
], reg_class_contents
[goal_alt
[i
]],
4433 PSEUDO_REGNO_MODE (regno
)))
4434 && (curr_insn_set
== NULL_RTX
4435 || !((REG_P (SET_SRC (curr_insn_set
))
4436 || MEM_P (SET_SRC (curr_insn_set
))
4437 || GET_CODE (SET_SRC (curr_insn_set
)) == SUBREG
)
4438 && (REG_P (SET_DEST (curr_insn_set
))
4439 || MEM_P (SET_DEST (curr_insn_set
))
4440 || GET_CODE (SET_DEST (curr_insn_set
)) == SUBREG
))))
4442 else if (goal_alt_matched
[i
][0] != -1
4443 && curr_static_id
->operand
[i
].type
== OP_OUT
4444 && (curr_static_id
->operand_alternative
4445 [goal_alt_number
* n_operands
+ i
].earlyclobber
)
4448 for (j
= 0; goal_alt_matched
[i
][j
] != -1; j
++)
4450 rtx op2
= *curr_id
->operand_loc
[goal_alt_matched
[i
][j
]];
4452 if (REG_P (op2
) && REGNO (op
) != REGNO (op2
))
4455 if (goal_alt_matched
[i
][j
] != -1)
4457 /* Generate reloads for different output and matched
4458 input registers. This is the easiest way to avoid
4459 creation of non-existing register conflicts in
4461 match_reload (i
, goal_alt_matched
[i
], outputs
, goal_alt
[i
], &before
,
4470 /* Operands that match previous ones have already been handled. */
4471 if (goal_alt_matches
[i
] >= 0)
4474 /* We should not have an operand with a non-offsettable address
4475 appearing where an offsettable address will do. It also may
4476 be a case when the address should be special in other words
4477 not a general one (e.g. it needs no index reg). */
4478 if (goal_alt_matched
[i
][0] == -1 && goal_alt_offmemok
[i
] && MEM_P (op
))
4480 enum reg_class rclass
;
4481 rtx
*loc
= &XEXP (op
, 0);
4482 enum rtx_code code
= GET_CODE (*loc
);
4484 push_to_sequence (before
);
4485 rclass
= base_reg_class (GET_MODE (op
), MEM_ADDR_SPACE (op
),
4487 if (GET_RTX_CLASS (code
) == RTX_AUTOINC
)
4488 new_reg
= emit_inc (rclass
, *loc
, *loc
,
4489 /* This value does not matter for MODIFY. */
4490 GET_MODE_SIZE (GET_MODE (op
)));
4491 else if (get_reload_reg (OP_IN
, Pmode
, *loc
, rclass
, FALSE
,
4492 "offsetable address", &new_reg
))
4495 enum rtx_code code
= GET_CODE (addr
);
4496 bool align_p
= false;
4498 if (code
== AND
&& CONST_INT_P (XEXP (addr
, 1)))
4500 /* (and ... (const_int -X)) is used to align to X bytes. */
4502 addr
= XEXP (*loc
, 0);
4505 addr
= canonicalize_reload_addr (addr
);
4507 lra_emit_move (new_reg
, addr
);
4509 emit_move_insn (new_reg
, gen_rtx_AND (GET_MODE (new_reg
), new_reg
, XEXP (*loc
, 1)));
4511 before
= get_insns ();
4514 lra_update_dup (curr_id
, i
);
4516 else if (goal_alt_matched
[i
][0] == -1)
4521 enum op_type type
= curr_static_id
->operand
[i
].type
;
4523 loc
= curr_id
->operand_loc
[i
];
4524 mode
= curr_operand_mode
[i
];
4525 if (GET_CODE (*loc
) == SUBREG
)
4527 reg
= SUBREG_REG (*loc
);
4528 poly_int64 byte
= SUBREG_BYTE (*loc
);
4530 /* Strict_low_part requires reloading the register and not
4531 just the subreg. Likewise for a strict subreg no wider
4532 than a word for WORD_REGISTER_OPERATIONS targets. */
4533 && (curr_static_id
->operand
[i
].strict_low
4534 || (!paradoxical_subreg_p (mode
, GET_MODE (reg
))
4536 = get_try_hard_regno (REGNO (reg
))) >= 0
4537 && (simplify_subreg_regno
4539 GET_MODE (reg
), byte
, mode
) < 0)
4540 && (goal_alt
[i
] == NO_REGS
4541 || (simplify_subreg_regno
4542 (ira_class_hard_regs
[goal_alt
[i
]][0],
4543 GET_MODE (reg
), byte
, mode
) >= 0)))
4544 || (partial_subreg_p (mode
, GET_MODE (reg
))
4545 && known_le (GET_MODE_SIZE (GET_MODE (reg
)),
4547 && WORD_REGISTER_OPERATIONS
)))
4549 /* An OP_INOUT is required when reloading a subreg of a
4550 mode wider than a word to ensure that data beyond the
4551 word being reloaded is preserved. Also automatically
4552 ensure that strict_low_part reloads are made into
4553 OP_INOUT which should already be true from the backend
4556 && (curr_static_id
->operand
[i
].strict_low
4557 || read_modify_subreg_p (*loc
)))
4559 loc
= &SUBREG_REG (*loc
);
4560 mode
= GET_MODE (*loc
);
4564 if (get_reload_reg (type
, mode
, old
, goal_alt
[i
],
4565 loc
!= curr_id
->operand_loc
[i
], "", &new_reg
)
4568 push_to_sequence (before
);
4569 lra_emit_move (new_reg
, old
);
4570 before
= get_insns ();
4575 && find_reg_note (curr_insn
, REG_UNUSED
, old
) == NULL_RTX
)
4578 lra_emit_move (type
== OP_INOUT
? copy_rtx (old
) : old
, new_reg
);
4580 after
= get_insns ();
4584 for (j
= 0; j
< goal_alt_dont_inherit_ops_num
; j
++)
4585 if (goal_alt_dont_inherit_ops
[j
] == i
)
4587 lra_set_regno_unique_value (REGNO (new_reg
));
4590 lra_update_dup (curr_id
, i
);
4592 else if (curr_static_id
->operand
[i
].type
== OP_IN
4593 && (curr_static_id
->operand
[goal_alt_matched
[i
][0]].type
4595 || (curr_static_id
->operand
[goal_alt_matched
[i
][0]].type
4597 && (operands_match_p
4598 (*curr_id
->operand_loc
[i
],
4599 *curr_id
->operand_loc
[goal_alt_matched
[i
][0]],
4602 /* generate reloads for input and matched outputs. */
4603 match_inputs
[0] = i
;
4604 match_inputs
[1] = -1;
4605 match_reload (goal_alt_matched
[i
][0], match_inputs
, outputs
,
4606 goal_alt
[i
], &before
, &after
,
4607 curr_static_id
->operand_alternative
4608 [goal_alt_number
* n_operands
+ goal_alt_matched
[i
][0]]
4611 else if ((curr_static_id
->operand
[i
].type
== OP_OUT
4612 || (curr_static_id
->operand
[i
].type
== OP_INOUT
4613 && (operands_match_p
4614 (*curr_id
->operand_loc
[i
],
4615 *curr_id
->operand_loc
[goal_alt_matched
[i
][0]],
4617 && (curr_static_id
->operand
[goal_alt_matched
[i
][0]].type
4619 /* Generate reloads for output and matched inputs. */
4620 match_reload (i
, goal_alt_matched
[i
], outputs
, goal_alt
[i
], &before
,
4621 &after
, curr_static_id
->operand_alternative
4622 [goal_alt_number
* n_operands
+ i
].earlyclobber
);
4623 else if (curr_static_id
->operand
[i
].type
== OP_IN
4624 && (curr_static_id
->operand
[goal_alt_matched
[i
][0]].type
4627 /* Generate reloads for matched inputs. */
4628 match_inputs
[0] = i
;
4629 for (j
= 0; (k
= goal_alt_matched
[i
][j
]) >= 0; j
++)
4630 match_inputs
[j
+ 1] = k
;
4631 match_inputs
[j
+ 1] = -1;
4632 match_reload (-1, match_inputs
, outputs
, goal_alt
[i
], &before
,
4636 /* We must generate code in any case when function
4637 process_alt_operands decides that it is possible. */
4644 lra_assert (REG_P (reg
));
4645 regno
= REGNO (reg
);
4646 op
= *curr_id
->operand_loc
[i
]; /* Substitution. */
4647 if (GET_CODE (op
) == SUBREG
)
4648 op
= SUBREG_REG (op
);
4649 gcc_assert (REG_P (op
) && (int) REGNO (op
) >= new_regno_start
);
4650 bitmap_set_bit (&lra_optional_reload_pseudos
, REGNO (op
));
4651 lra_reg_info
[REGNO (op
)].restore_rtx
= reg
;
4652 if (lra_dump_file
!= NULL
)
4653 fprintf (lra_dump_file
,
4654 " Making reload reg %d for reg %d optional\n",
4658 if (before
!= NULL_RTX
|| after
!= NULL_RTX
4659 || max_regno_before
!= max_reg_num ())
4663 lra_update_operator_dups (curr_id
);
4664 /* Something changes -- process the insn. */
4665 lra_update_insn_regno_info (curr_insn
);
4667 lra_process_new_insns (curr_insn
, before
, after
, "Inserting insn reload");
4671 /* Return true if INSN satisfies all constraints. In other words, no
4672 reload insns are needed. */
4674 lra_constrain_insn (rtx_insn
*insn
)
4676 int saved_new_regno_start
= new_regno_start
;
4677 int saved_new_insn_uid_start
= new_insn_uid_start
;
4681 curr_id
= lra_get_insn_recog_data (curr_insn
);
4682 curr_static_id
= curr_id
->insn_static_data
;
4683 new_insn_uid_start
= get_max_uid ();
4684 new_regno_start
= max_reg_num ();
4685 change_p
= curr_insn_transform (true);
4686 new_regno_start
= saved_new_regno_start
;
4687 new_insn_uid_start
= saved_new_insn_uid_start
;
4691 /* Return true if X is in LIST. */
4693 in_list_p (rtx x
, rtx list
)
4695 for (; list
!= NULL_RTX
; list
= XEXP (list
, 1))
4696 if (XEXP (list
, 0) == x
)
4701 /* Return true if X contains an allocatable hard register (if
4702 HARD_REG_P) or a (spilled if SPILLED_P) pseudo. */
4704 contains_reg_p (rtx x
, bool hard_reg_p
, bool spilled_p
)
4710 code
= GET_CODE (x
);
4713 int regno
= REGNO (x
);
4714 HARD_REG_SET alloc_regs
;
4718 if (regno
>= FIRST_PSEUDO_REGISTER
)
4719 regno
= lra_get_regno_hard_regno (regno
);
4722 alloc_regs
= ~lra_no_alloc_regs
;
4723 return overlaps_hard_reg_set_p (alloc_regs
, GET_MODE (x
), regno
);
4727 if (regno
< FIRST_PSEUDO_REGISTER
)
4731 return lra_get_regno_hard_regno (regno
) < 0;
4734 fmt
= GET_RTX_FORMAT (code
);
4735 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
4739 if (contains_reg_p (XEXP (x
, i
), hard_reg_p
, spilled_p
))
4742 else if (fmt
[i
] == 'E')
4744 for (j
= XVECLEN (x
, i
) - 1; j
>= 0; j
--)
4745 if (contains_reg_p (XVECEXP (x
, i
, j
), hard_reg_p
, spilled_p
))
4752 /* Process all regs in location *LOC and change them on equivalent
4753 substitution. Return true if any change was done. */
4755 loc_equivalence_change_p (rtx
*loc
)
4757 rtx subst
, reg
, x
= *loc
;
4758 bool result
= false;
4759 enum rtx_code code
= GET_CODE (x
);
4765 reg
= SUBREG_REG (x
);
4766 if ((subst
= get_equiv_with_elimination (reg
, curr_insn
)) != reg
4767 && GET_MODE (subst
) == VOIDmode
)
4769 /* We cannot reload debug location. Simplify subreg here
4770 while we know the inner mode. */
4771 *loc
= simplify_gen_subreg (GET_MODE (x
), subst
,
4772 GET_MODE (reg
), SUBREG_BYTE (x
));
4776 if (code
== REG
&& (subst
= get_equiv_with_elimination (x
, curr_insn
)) != x
)
4782 /* Scan all the operand sub-expressions. */
4783 fmt
= GET_RTX_FORMAT (code
);
4784 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
4787 result
= loc_equivalence_change_p (&XEXP (x
, i
)) || result
;
4788 else if (fmt
[i
] == 'E')
4789 for (j
= XVECLEN (x
, i
) - 1; j
>= 0; j
--)
4791 = loc_equivalence_change_p (&XVECEXP (x
, i
, j
)) || result
;
4796 /* Similar to loc_equivalence_change_p, but for use as
4797 simplify_replace_fn_rtx callback. DATA is insn for which the
4798 elimination is done. If it null we don't do the elimination. */
4800 loc_equivalence_callback (rtx loc
, const_rtx
, void *data
)
4805 rtx subst
= (data
== NULL
4806 ? get_equiv (loc
) : get_equiv_with_elimination (loc
, (rtx_insn
*) data
));
4813 /* Maximum number of generated reload insns per an insn. It is for
4814 preventing this pass cycling in a bug case. */
4815 #define MAX_RELOAD_INSNS_NUMBER LRA_MAX_INSN_RELOADS
4817 /* The current iteration number of this LRA pass. */
4818 int lra_constraint_iter
;
4820 /* True if we should during assignment sub-pass check assignment
4821 correctness for all pseudos and spill some of them to correct
4822 conflicts. It can be necessary when we substitute equiv which
4823 needs checking register allocation correctness because the
4824 equivalent value contains allocatable hard registers, or when we
4825 restore multi-register pseudo, or when we change the insn code and
4826 its operand became INOUT operand when it was IN one before. */
4827 bool check_and_force_assignment_correctness_p
;
4829 /* Return true if REGNO is referenced in more than one block. */
4831 multi_block_pseudo_p (int regno
)
4833 basic_block bb
= NULL
;
4837 if (regno
< FIRST_PSEUDO_REGISTER
)
4840 EXECUTE_IF_SET_IN_BITMAP (&lra_reg_info
[regno
].insn_bitmap
, 0, uid
, bi
)
4842 bb
= BLOCK_FOR_INSN (lra_insn_recog_data
[uid
]->insn
);
4843 else if (BLOCK_FOR_INSN (lra_insn_recog_data
[uid
]->insn
) != bb
)
4848 /* Return true if LIST contains a deleted insn. */
4850 contains_deleted_insn_p (rtx_insn_list
*list
)
4852 for (; list
!= NULL_RTX
; list
= list
->next ())
4853 if (NOTE_P (list
->insn ())
4854 && NOTE_KIND (list
->insn ()) == NOTE_INSN_DELETED
)
4859 /* Return true if X contains a pseudo dying in INSN. */
4861 dead_pseudo_p (rtx x
, rtx_insn
*insn
)
4868 return (insn
!= NULL_RTX
4869 && find_regno_note (insn
, REG_DEAD
, REGNO (x
)) != NULL_RTX
);
4870 code
= GET_CODE (x
);
4871 fmt
= GET_RTX_FORMAT (code
);
4872 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
4876 if (dead_pseudo_p (XEXP (x
, i
), insn
))
4879 else if (fmt
[i
] == 'E')
4881 for (j
= XVECLEN (x
, i
) - 1; j
>= 0; j
--)
4882 if (dead_pseudo_p (XVECEXP (x
, i
, j
), insn
))
4889 /* Return true if INSN contains a dying pseudo in INSN right hand
4892 insn_rhs_dead_pseudo_p (rtx_insn
*insn
)
4894 rtx set
= single_set (insn
);
4896 gcc_assert (set
!= NULL
);
4897 return dead_pseudo_p (SET_SRC (set
), insn
);
4900 /* Return true if any init insn of REGNO contains a dying pseudo in
4901 insn right hand side. */
4903 init_insn_rhs_dead_pseudo_p (int regno
)
4905 rtx_insn_list
*insns
= ira_reg_equiv
[regno
].init_insns
;
4909 for (; insns
!= NULL_RTX
; insns
= insns
->next ())
4910 if (insn_rhs_dead_pseudo_p (insns
->insn ()))
4915 /* Return TRUE if REGNO has a reverse equivalence. The equivalence is
4916 reverse only if we have one init insn with given REGNO as a
4919 reverse_equiv_p (int regno
)
4921 rtx_insn_list
*insns
= ira_reg_equiv
[regno
].init_insns
;
4926 if (! INSN_P (insns
->insn ())
4927 || insns
->next () != NULL
)
4929 if ((set
= single_set (insns
->insn ())) == NULL_RTX
)
4931 return REG_P (SET_SRC (set
)) && (int) REGNO (SET_SRC (set
)) == regno
;
4934 /* Return TRUE if REGNO was reloaded in an equivalence init insn. We
4935 call this function only for non-reverse equivalence. */
4937 contains_reloaded_insn_p (int regno
)
4940 rtx_insn_list
*list
= ira_reg_equiv
[regno
].init_insns
;
4942 for (; list
!= NULL
; list
= list
->next ())
4943 if ((set
= single_set (list
->insn ())) == NULL_RTX
4944 || ! REG_P (SET_DEST (set
))
4945 || (int) REGNO (SET_DEST (set
)) != regno
)
4950 /* Entry function of LRA constraint pass. Return true if the
4951 constraint pass did change the code. */
4953 lra_constraints (bool first_p
)
4956 int i
, hard_regno
, new_insns_num
;
4957 unsigned int min_len
, new_min_len
, uid
;
4958 rtx set
, x
, reg
, dest_reg
;
4959 basic_block last_bb
;
4962 lra_constraint_iter
++;
4963 if (lra_dump_file
!= NULL
)
4964 fprintf (lra_dump_file
, "\n********** Local #%d: **********\n\n",
4965 lra_constraint_iter
);
4967 if (pic_offset_table_rtx
4968 && REGNO (pic_offset_table_rtx
) >= FIRST_PSEUDO_REGISTER
)
4969 check_and_force_assignment_correctness_p
= true;
4971 /* On the first iteration we should check IRA assignment
4972 correctness. In rare cases, the assignments can be wrong as
4973 early clobbers operands are ignored in IRA or usages of
4974 paradoxical sub-registers are not taken into account by
4976 check_and_force_assignment_correctness_p
= true;
4977 new_insn_uid_start
= get_max_uid ();
4978 new_regno_start
= first_p
? lra_constraint_new_regno_start
: max_reg_num ();
4979 /* Mark used hard regs for target stack size calulations. */
4980 for (i
= FIRST_PSEUDO_REGISTER
; i
< new_regno_start
; i
++)
4981 if (lra_reg_info
[i
].nrefs
!= 0
4982 && (hard_regno
= lra_get_regno_hard_regno (i
)) >= 0)
4986 nregs
= hard_regno_nregs (hard_regno
, lra_reg_info
[i
].biggest_mode
);
4987 for (j
= 0; j
< nregs
; j
++)
4988 df_set_regs_ever_live (hard_regno
+ j
, true);
4990 /* Do elimination before the equivalence processing as we can spill
4991 some pseudos during elimination. */
4992 lra_eliminate (false, first_p
);
4993 auto_bitmap
equiv_insn_bitmap (®_obstack
);
4994 for (i
= FIRST_PSEUDO_REGISTER
; i
< new_regno_start
; i
++)
4995 if (lra_reg_info
[i
].nrefs
!= 0)
4997 ira_reg_equiv
[i
].profitable_p
= true;
4998 reg
= regno_reg_rtx
[i
];
4999 if (lra_get_regno_hard_regno (i
) < 0 && (x
= get_equiv (reg
)) != reg
)
5001 bool pseudo_p
= contains_reg_p (x
, false, false);
5003 /* After RTL transformation, we cannot guarantee that
5004 pseudo in the substitution was not reloaded which might
5005 make equivalence invalid. For example, in reverse
5012 the memory address register was reloaded before the 2nd
5014 if ((! first_p
&& pseudo_p
)
5015 /* We don't use DF for compilation speed sake. So it
5016 is problematic to update live info when we use an
5017 equivalence containing pseudos in more than one
5019 || (pseudo_p
&& multi_block_pseudo_p (i
))
5020 /* If an init insn was deleted for some reason, cancel
5021 the equiv. We could update the equiv insns after
5022 transformations including an equiv insn deletion
5023 but it is not worthy as such cases are extremely
5025 || contains_deleted_insn_p (ira_reg_equiv
[i
].init_insns
)
5026 /* If it is not a reverse equivalence, we check that a
5027 pseudo in rhs of the init insn is not dying in the
5028 insn. Otherwise, the live info at the beginning of
5029 the corresponding BB might be wrong after we
5030 removed the insn. When the equiv can be a
5031 constant, the right hand side of the init insn can
5033 || (! reverse_equiv_p (i
)
5034 && (init_insn_rhs_dead_pseudo_p (i
)
5035 /* If we reloaded the pseudo in an equivalence
5036 init insn, we cannot remove the equiv init
5037 insns and the init insns might write into
5038 const memory in this case. */
5039 || contains_reloaded_insn_p (i
)))
5040 /* Prevent access beyond equivalent memory for
5041 paradoxical subregs. */
5043 && maybe_gt (GET_MODE_SIZE (lra_reg_info
[i
].biggest_mode
),
5044 GET_MODE_SIZE (GET_MODE (x
))))
5045 || (pic_offset_table_rtx
5046 && ((CONST_POOL_OK_P (PSEUDO_REGNO_MODE (i
), x
)
5047 && (targetm
.preferred_reload_class
5048 (x
, lra_get_allocno_class (i
)) == NO_REGS
))
5049 || contains_symbol_ref_p (x
))))
5050 ira_reg_equiv
[i
].defined_p
= false;
5051 if (contains_reg_p (x
, false, true))
5052 ira_reg_equiv
[i
].profitable_p
= false;
5053 if (get_equiv (reg
) != reg
)
5054 bitmap_ior_into (equiv_insn_bitmap
, &lra_reg_info
[i
].insn_bitmap
);
5057 for (i
= FIRST_PSEUDO_REGISTER
; i
< new_regno_start
; i
++)
5059 /* We should add all insns containing pseudos which should be
5060 substituted by their equivalences. */
5061 EXECUTE_IF_SET_IN_BITMAP (equiv_insn_bitmap
, 0, uid
, bi
)
5062 lra_push_insn_by_uid (uid
);
5063 min_len
= lra_insn_stack_length ();
5067 while ((new_min_len
= lra_insn_stack_length ()) != 0)
5069 curr_insn
= lra_pop_insn ();
5071 curr_bb
= BLOCK_FOR_INSN (curr_insn
);
5072 if (curr_bb
!= last_bb
)
5075 bb_reload_num
= lra_curr_reload_num
;
5077 if (min_len
> new_min_len
)
5079 min_len
= new_min_len
;
5082 if (new_insns_num
> MAX_RELOAD_INSNS_NUMBER
)
5084 ("maximum number of generated reload insns per insn achieved (%d)",
5085 MAX_RELOAD_INSNS_NUMBER
);
5087 if (DEBUG_INSN_P (curr_insn
))
5089 /* We need to check equivalence in debug insn and change
5090 pseudo to the equivalent value if necessary. */
5091 curr_id
= lra_get_insn_recog_data (curr_insn
);
5092 if (bitmap_bit_p (equiv_insn_bitmap
, INSN_UID (curr_insn
)))
5094 rtx old
= *curr_id
->operand_loc
[0];
5095 *curr_id
->operand_loc
[0]
5096 = simplify_replace_fn_rtx (old
, NULL_RTX
,
5097 loc_equivalence_callback
, curr_insn
);
5098 if (old
!= *curr_id
->operand_loc
[0])
5100 lra_update_insn_regno_info (curr_insn
);
5105 else if (INSN_P (curr_insn
))
5107 if ((set
= single_set (curr_insn
)) != NULL_RTX
)
5109 dest_reg
= SET_DEST (set
);
5110 /* The equivalence pseudo could be set up as SUBREG in a
5111 case when it is a call restore insn in a mode
5112 different from the pseudo mode. */
5113 if (GET_CODE (dest_reg
) == SUBREG
)
5114 dest_reg
= SUBREG_REG (dest_reg
);
5115 if ((REG_P (dest_reg
)
5116 && (x
= get_equiv (dest_reg
)) != dest_reg
5117 /* Remove insns which set up a pseudo whose value
5118 cannot be changed. Such insns might be not in
5119 init_insns because we don't update equiv data
5120 during insn transformations.
5122 As an example, let suppose that a pseudo got
5123 hard register and on the 1st pass was not
5124 changed to equivalent constant. We generate an
5125 additional insn setting up the pseudo because of
5126 secondary memory movement. Then the pseudo is
5127 spilled and we use the equiv constant. In this
5128 case we should remove the additional insn and
5129 this insn is not init_insns list. */
5130 && (! MEM_P (x
) || MEM_READONLY_P (x
)
5131 /* Check that this is actually an insn setting
5132 up the equivalence. */
5133 || in_list_p (curr_insn
,
5135 [REGNO (dest_reg
)].init_insns
)))
5136 || (((x
= get_equiv (SET_SRC (set
))) != SET_SRC (set
))
5137 && in_list_p (curr_insn
,
5139 [REGNO (SET_SRC (set
))].init_insns
)))
5141 /* This is equiv init insn of pseudo which did not get a
5142 hard register -- remove the insn. */
5143 if (lra_dump_file
!= NULL
)
5145 fprintf (lra_dump_file
,
5146 " Removing equiv init insn %i (freq=%d)\n",
5147 INSN_UID (curr_insn
),
5148 REG_FREQ_FROM_BB (BLOCK_FOR_INSN (curr_insn
)));
5149 dump_insn_slim (lra_dump_file
, curr_insn
);
5151 if (contains_reg_p (x
, true, false))
5152 check_and_force_assignment_correctness_p
= true;
5153 lra_set_insn_deleted (curr_insn
);
5157 curr_id
= lra_get_insn_recog_data (curr_insn
);
5158 curr_static_id
= curr_id
->insn_static_data
;
5159 init_curr_insn_input_reloads ();
5160 init_curr_operand_mode ();
5161 if (curr_insn_transform (false))
5163 /* Check non-transformed insns too for equiv change as USE
5164 or CLOBBER don't need reloads but can contain pseudos
5165 being changed on their equivalences. */
5166 else if (bitmap_bit_p (equiv_insn_bitmap
, INSN_UID (curr_insn
))
5167 && loc_equivalence_change_p (&PATTERN (curr_insn
)))
5169 lra_update_insn_regno_info (curr_insn
);
5175 /* If we used a new hard regno, changed_p should be true because the
5176 hard reg is assigned to a new pseudo. */
5177 if (flag_checking
&& !changed_p
)
5179 for (i
= FIRST_PSEUDO_REGISTER
; i
< new_regno_start
; i
++)
5180 if (lra_reg_info
[i
].nrefs
!= 0
5181 && (hard_regno
= lra_get_regno_hard_regno (i
)) >= 0)
5183 int j
, nregs
= hard_regno_nregs (hard_regno
,
5184 PSEUDO_REGNO_MODE (i
));
5186 for (j
= 0; j
< nregs
; j
++)
5187 lra_assert (df_regs_ever_live_p (hard_regno
+ j
));
5193 static void initiate_invariants (void);
5194 static void finish_invariants (void);
5196 /* Initiate the LRA constraint pass. It is done once per
5199 lra_constraints_init (void)
5201 initiate_invariants ();
5204 /* Finalize the LRA constraint pass. It is done once per
5207 lra_constraints_finish (void)
5209 finish_invariants ();
5214 /* Structure describes invariants for ineheritance. */
5215 struct lra_invariant
5217 /* The order number of the invariant. */
5219 /* The invariant RTX. */
5221 /* The origin insn of the invariant. */
5225 typedef lra_invariant invariant_t
;
5226 typedef invariant_t
*invariant_ptr_t
;
5227 typedef const invariant_t
*const_invariant_ptr_t
;
5229 /* Pointer to the inheritance invariants. */
5230 static vec
<invariant_ptr_t
> invariants
;
5232 /* Allocation pool for the invariants. */
5233 static object_allocator
<lra_invariant
> *invariants_pool
;
5235 /* Hash table for the invariants. */
5236 static htab_t invariant_table
;
5238 /* Hash function for INVARIANT. */
5240 invariant_hash (const void *invariant
)
5242 rtx inv
= ((const_invariant_ptr_t
) invariant
)->invariant_rtx
;
5243 return lra_rtx_hash (inv
);
5246 /* Equal function for invariants INVARIANT1 and INVARIANT2. */
5248 invariant_eq_p (const void *invariant1
, const void *invariant2
)
5250 rtx inv1
= ((const_invariant_ptr_t
) invariant1
)->invariant_rtx
;
5251 rtx inv2
= ((const_invariant_ptr_t
) invariant2
)->invariant_rtx
;
5253 return rtx_equal_p (inv1
, inv2
);
5256 /* Insert INVARIANT_RTX into the table if it is not there yet. Return
5257 invariant which is in the table. */
5258 static invariant_ptr_t
5259 insert_invariant (rtx invariant_rtx
)
5262 invariant_t invariant
;
5263 invariant_ptr_t invariant_ptr
;
5265 invariant
.invariant_rtx
= invariant_rtx
;
5266 entry_ptr
= htab_find_slot (invariant_table
, &invariant
, INSERT
);
5267 if (*entry_ptr
== NULL
)
5269 invariant_ptr
= invariants_pool
->allocate ();
5270 invariant_ptr
->invariant_rtx
= invariant_rtx
;
5271 invariant_ptr
->insn
= NULL
;
5272 invariants
.safe_push (invariant_ptr
);
5273 *entry_ptr
= (void *) invariant_ptr
;
5275 return (invariant_ptr_t
) *entry_ptr
;
5278 /* Initiate the invariant table. */
5280 initiate_invariants (void)
5282 invariants
.create (100);
5284 = new object_allocator
<lra_invariant
> ("Inheritance invariants");
5285 invariant_table
= htab_create (100, invariant_hash
, invariant_eq_p
, NULL
);
5288 /* Finish the invariant table. */
5290 finish_invariants (void)
5292 htab_delete (invariant_table
);
5293 delete invariants_pool
;
5294 invariants
.release ();
5297 /* Make the invariant table empty. */
5299 clear_invariants (void)
5301 htab_empty (invariant_table
);
5302 invariants_pool
->release ();
5303 invariants
.truncate (0);
5308 /* This page contains code to do inheritance/split
5311 /* Number of reloads passed so far in current EBB. */
5312 static int reloads_num
;
5314 /* Number of calls passed so far in current EBB. */
5315 static int calls_num
;
5317 /* Index ID is the CALLS_NUM associated the last call we saw with
5318 ABI identifier ID. */
5319 static int last_call_for_abi
[NUM_ABI_IDS
];
5321 /* Which registers have been fully or partially clobbered by a call
5322 since they were last used. */
5323 static HARD_REG_SET full_and_partial_call_clobbers
;
5325 /* Current reload pseudo check for validity of elements in
5327 static int curr_usage_insns_check
;
5329 /* Info about last usage of registers in EBB to do inheritance/split
5330 transformation. Inheritance transformation is done from a spilled
5331 pseudo and split transformations from a hard register or a pseudo
5332 assigned to a hard register. */
5335 /* If the value is equal to CURR_USAGE_INSNS_CHECK, then the member
5336 value INSNS is valid. The insns is chain of optional debug insns
5337 and a finishing non-debug insn using the corresponding reg. The
5338 value is also used to mark the registers which are set up in the
5339 current insn. The negated insn uid is used for this. */
5341 /* Value of global reloads_num at the last insn in INSNS. */
5343 /* Value of global reloads_nums at the last insn in INSNS. */
5345 /* It can be true only for splitting. And it means that the restore
5346 insn should be put after insn given by the following member. */
5348 /* Next insns in the current EBB which use the original reg and the
5349 original reg value is not changed between the current insn and
5350 the next insns. In order words, e.g. for inheritance, if we need
5351 to use the original reg value again in the next insns we can try
5352 to use the value in a hard register from a reload insn of the
5357 /* Map: regno -> corresponding pseudo usage insns. */
5358 static struct usage_insns
*usage_insns
;
5361 setup_next_usage_insn (int regno
, rtx insn
, int reloads_num
, bool after_p
)
5363 usage_insns
[regno
].check
= curr_usage_insns_check
;
5364 usage_insns
[regno
].insns
= insn
;
5365 usage_insns
[regno
].reloads_num
= reloads_num
;
5366 usage_insns
[regno
].calls_num
= calls_num
;
5367 usage_insns
[regno
].after_p
= after_p
;
5368 if (regno
>= FIRST_PSEUDO_REGISTER
&& reg_renumber
[regno
] >= 0)
5369 remove_from_hard_reg_set (&full_and_partial_call_clobbers
,
5370 PSEUDO_REGNO_MODE (regno
),
5371 reg_renumber
[regno
]);
5374 /* The function is used to form list REGNO usages which consists of
5375 optional debug insns finished by a non-debug insn using REGNO.
5376 RELOADS_NUM is current number of reload insns processed so far. */
5378 add_next_usage_insn (int regno
, rtx_insn
*insn
, int reloads_num
)
5380 rtx next_usage_insns
;
5382 if (usage_insns
[regno
].check
== curr_usage_insns_check
5383 && (next_usage_insns
= usage_insns
[regno
].insns
) != NULL_RTX
5384 && DEBUG_INSN_P (insn
))
5386 /* Check that we did not add the debug insn yet. */
5387 if (next_usage_insns
!= insn
5388 && (GET_CODE (next_usage_insns
) != INSN_LIST
5389 || XEXP (next_usage_insns
, 0) != insn
))
5390 usage_insns
[regno
].insns
= gen_rtx_INSN_LIST (VOIDmode
, insn
,
5393 else if (NONDEBUG_INSN_P (insn
))
5394 setup_next_usage_insn (regno
, insn
, reloads_num
, false);
5396 usage_insns
[regno
].check
= 0;
5399 /* Return first non-debug insn in list USAGE_INSNS. */
5401 skip_usage_debug_insns (rtx usage_insns
)
5405 /* Skip debug insns. */
5406 for (insn
= usage_insns
;
5407 insn
!= NULL_RTX
&& GET_CODE (insn
) == INSN_LIST
;
5408 insn
= XEXP (insn
, 1))
5410 return safe_as_a
<rtx_insn
*> (insn
);
5413 /* Return true if we need secondary memory moves for insn in
5414 USAGE_INSNS after inserting inherited pseudo of class INHER_CL
5417 check_secondary_memory_needed_p (enum reg_class inher_cl ATTRIBUTE_UNUSED
,
5418 rtx usage_insns ATTRIBUTE_UNUSED
)
5424 if (inher_cl
== ALL_REGS
5425 || (insn
= skip_usage_debug_insns (usage_insns
)) == NULL_RTX
)
5427 lra_assert (INSN_P (insn
));
5428 if ((set
= single_set (insn
)) == NULL_RTX
|| ! REG_P (SET_DEST (set
)))
5430 dest
= SET_DEST (set
);
5433 lra_assert (inher_cl
!= NO_REGS
);
5434 cl
= get_reg_class (REGNO (dest
));
5435 return (cl
!= NO_REGS
&& cl
!= ALL_REGS
5436 && targetm
.secondary_memory_needed (GET_MODE (dest
), inher_cl
, cl
));
5439 /* Registers involved in inheritance/split in the current EBB
5440 (inheritance/split pseudos and original registers). */
5441 static bitmap_head check_only_regs
;
5443 /* Reload pseudos cannot be involded in invariant inheritance in the
5445 static bitmap_head invalid_invariant_regs
;
5447 /* Do inheritance transformations for insn INSN, which defines (if
5448 DEF_P) or uses ORIGINAL_REGNO. NEXT_USAGE_INSNS specifies which
5449 instruction in the EBB next uses ORIGINAL_REGNO; it has the same
5450 form as the "insns" field of usage_insns. Return true if we
5451 succeed in such transformation.
5453 The transformations look like:
5456 ... p <- i (new insn)
5458 <- ... p ... <- ... i ...
5460 ... i <- p (new insn)
5461 <- ... p ... <- ... i ...
5463 <- ... p ... <- ... i ...
5464 where p is a spilled original pseudo and i is a new inheritance pseudo.
5467 The inheritance pseudo has the smallest class of two classes CL and
5468 class of ORIGINAL REGNO. */
5470 inherit_reload_reg (bool def_p
, int original_regno
,
5471 enum reg_class cl
, rtx_insn
*insn
, rtx next_usage_insns
)
5473 if (optimize_function_for_size_p (cfun
))
5476 enum reg_class rclass
= lra_get_allocno_class (original_regno
);
5477 rtx original_reg
= regno_reg_rtx
[original_regno
];
5478 rtx new_reg
, usage_insn
;
5479 rtx_insn
*new_insns
;
5481 lra_assert (! usage_insns
[original_regno
].after_p
);
5482 if (lra_dump_file
!= NULL
)
5483 fprintf (lra_dump_file
,
5484 " <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n");
5485 if (! ira_reg_classes_intersect_p
[cl
][rclass
])
5487 if (lra_dump_file
!= NULL
)
5489 fprintf (lra_dump_file
,
5490 " Rejecting inheritance for %d "
5491 "because of disjoint classes %s and %s\n",
5492 original_regno
, reg_class_names
[cl
],
5493 reg_class_names
[rclass
]);
5494 fprintf (lra_dump_file
,
5495 " >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n");
5499 if ((ira_class_subset_p
[cl
][rclass
] && cl
!= rclass
)
5500 /* We don't use a subset of two classes because it can be
5501 NO_REGS. This transformation is still profitable in most
5502 cases even if the classes are not intersected as register
5503 move is probably cheaper than a memory load. */
5504 || ira_class_hard_regs_num
[cl
] < ira_class_hard_regs_num
[rclass
])
5506 if (lra_dump_file
!= NULL
)
5507 fprintf (lra_dump_file
, " Use smallest class of %s and %s\n",
5508 reg_class_names
[cl
], reg_class_names
[rclass
]);
5512 if (check_secondary_memory_needed_p (rclass
, next_usage_insns
))
5514 /* Reject inheritance resulting in secondary memory moves.
5515 Otherwise, there is a danger in LRA cycling. Also such
5516 transformation will be unprofitable. */
5517 if (lra_dump_file
!= NULL
)
5519 rtx_insn
*insn
= skip_usage_debug_insns (next_usage_insns
);
5520 rtx set
= single_set (insn
);
5522 lra_assert (set
!= NULL_RTX
);
5524 rtx dest
= SET_DEST (set
);
5526 lra_assert (REG_P (dest
));
5527 fprintf (lra_dump_file
,
5528 " Rejecting inheritance for insn %d(%s)<-%d(%s) "
5529 "as secondary mem is needed\n",
5530 REGNO (dest
), reg_class_names
[get_reg_class (REGNO (dest
))],
5531 original_regno
, reg_class_names
[rclass
]);
5532 fprintf (lra_dump_file
,
5533 " >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n");
5537 new_reg
= lra_create_new_reg (GET_MODE (original_reg
), original_reg
,
5538 rclass
, "inheritance");
5541 lra_emit_move (original_reg
, new_reg
);
5543 lra_emit_move (new_reg
, original_reg
);
5544 new_insns
= get_insns ();
5546 if (NEXT_INSN (new_insns
) != NULL_RTX
)
5548 if (lra_dump_file
!= NULL
)
5550 fprintf (lra_dump_file
,
5551 " Rejecting inheritance %d->%d "
5552 "as it results in 2 or more insns:\n",
5553 original_regno
, REGNO (new_reg
));
5554 dump_rtl_slim (lra_dump_file
, new_insns
, NULL
, -1, 0);
5555 fprintf (lra_dump_file
,
5556 " >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n");
5560 lra_substitute_pseudo_within_insn (insn
, original_regno
, new_reg
, false);
5561 lra_update_insn_regno_info (insn
);
5563 /* We now have a new usage insn for original regno. */
5564 setup_next_usage_insn (original_regno
, new_insns
, reloads_num
, false);
5565 if (lra_dump_file
!= NULL
)
5566 fprintf (lra_dump_file
, " Original reg change %d->%d (bb%d):\n",
5567 original_regno
, REGNO (new_reg
), BLOCK_FOR_INSN (insn
)->index
);
5568 lra_reg_info
[REGNO (new_reg
)].restore_rtx
= regno_reg_rtx
[original_regno
];
5569 bitmap_set_bit (&check_only_regs
, REGNO (new_reg
));
5570 bitmap_set_bit (&check_only_regs
, original_regno
);
5571 bitmap_set_bit (&lra_inheritance_pseudos
, REGNO (new_reg
));
5573 lra_process_new_insns (insn
, NULL
, new_insns
,
5574 "Add original<-inheritance");
5576 lra_process_new_insns (insn
, new_insns
, NULL
,
5577 "Add inheritance<-original");
5578 while (next_usage_insns
!= NULL_RTX
)
5580 if (GET_CODE (next_usage_insns
) != INSN_LIST
)
5582 usage_insn
= next_usage_insns
;
5583 lra_assert (NONDEBUG_INSN_P (usage_insn
));
5584 next_usage_insns
= NULL
;
5588 usage_insn
= XEXP (next_usage_insns
, 0);
5589 lra_assert (DEBUG_INSN_P (usage_insn
));
5590 next_usage_insns
= XEXP (next_usage_insns
, 1);
5592 lra_substitute_pseudo (&usage_insn
, original_regno
, new_reg
, false,
5593 DEBUG_INSN_P (usage_insn
));
5594 lra_update_insn_regno_info (as_a
<rtx_insn
*> (usage_insn
));
5595 if (lra_dump_file
!= NULL
)
5597 basic_block bb
= BLOCK_FOR_INSN (usage_insn
);
5598 fprintf (lra_dump_file
,
5599 " Inheritance reuse change %d->%d (bb%d):\n",
5600 original_regno
, REGNO (new_reg
),
5601 bb
? bb
->index
: -1);
5602 dump_insn_slim (lra_dump_file
, as_a
<rtx_insn
*> (usage_insn
));
5605 if (lra_dump_file
!= NULL
)
5606 fprintf (lra_dump_file
,
5607 " >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n");
5611 /* Return true if we need a caller save/restore for pseudo REGNO which
5612 was assigned to a hard register. */
5614 need_for_call_save_p (int regno
)
5616 lra_assert (regno
>= FIRST_PSEUDO_REGISTER
&& reg_renumber
[regno
] >= 0);
5617 if (usage_insns
[regno
].calls_num
< calls_num
)
5619 unsigned int abis
= 0;
5620 for (unsigned int i
= 0; i
< NUM_ABI_IDS
; ++i
)
5621 if (last_call_for_abi
[i
] > usage_insns
[regno
].calls_num
)
5624 if (call_clobbered_in_region_p (abis
, full_and_partial_call_clobbers
,
5625 PSEUDO_REGNO_MODE (regno
),
5626 reg_renumber
[regno
]))
5632 /* Global registers occurring in the current EBB. */
5633 static bitmap_head ebb_global_regs
;
5635 /* Return true if we need a split for hard register REGNO or pseudo
5636 REGNO which was assigned to a hard register.
5637 POTENTIAL_RELOAD_HARD_REGS contains hard registers which might be
5638 used for reloads since the EBB end. It is an approximation of the
5639 used hard registers in the split range. The exact value would
5640 require expensive calculations. If we were aggressive with
5641 splitting because of the approximation, the split pseudo will save
5642 the same hard register assignment and will be removed in the undo
5643 pass. We still need the approximation because too aggressive
5644 splitting would result in too inaccurate cost calculation in the
5645 assignment pass because of too many generated moves which will be
5646 probably removed in the undo pass. */
5648 need_for_split_p (HARD_REG_SET potential_reload_hard_regs
, int regno
)
5650 int hard_regno
= regno
< FIRST_PSEUDO_REGISTER
? regno
: reg_renumber
[regno
];
5652 lra_assert (hard_regno
>= 0);
5653 return ((TEST_HARD_REG_BIT (potential_reload_hard_regs
, hard_regno
)
5654 /* Don't split eliminable hard registers, otherwise we can
5655 split hard registers like hard frame pointer, which
5656 lives on BB start/end according to DF-infrastructure,
5657 when there is a pseudo assigned to the register and
5658 living in the same BB. */
5659 && (regno
>= FIRST_PSEUDO_REGISTER
5660 || ! TEST_HARD_REG_BIT (eliminable_regset
, hard_regno
))
5661 && ! TEST_HARD_REG_BIT (lra_no_alloc_regs
, hard_regno
)
5662 /* Don't split call clobbered hard regs living through
5663 calls, otherwise we might have a check problem in the
5664 assign sub-pass as in the most cases (exception is a
5665 situation when check_and_force_assignment_correctness_p value is
5666 true) the assign pass assumes that all pseudos living
5667 through calls are assigned to call saved hard regs. */
5668 && (regno
>= FIRST_PSEUDO_REGISTER
5669 || !TEST_HARD_REG_BIT (full_and_partial_call_clobbers
, regno
))
5670 /* We need at least 2 reloads to make pseudo splitting
5671 profitable. We should provide hard regno splitting in
5672 any case to solve 1st insn scheduling problem when
5673 moving hard register definition up might result in
5674 impossibility to find hard register for reload pseudo of
5675 small register class. */
5676 && (usage_insns
[regno
].reloads_num
5677 + (regno
< FIRST_PSEUDO_REGISTER
? 0 : 3) < reloads_num
)
5678 && (regno
< FIRST_PSEUDO_REGISTER
5679 /* For short living pseudos, spilling + inheritance can
5680 be considered a substitution for splitting.
5681 Therefore we do not splitting for local pseudos. It
5682 decreases also aggressiveness of splitting. The
5683 minimal number of references is chosen taking into
5684 account that for 2 references splitting has no sense
5685 as we can just spill the pseudo. */
5686 || (regno
>= FIRST_PSEUDO_REGISTER
5687 && lra_reg_info
[regno
].nrefs
> 3
5688 && bitmap_bit_p (&ebb_global_regs
, regno
))))
5689 || (regno
>= FIRST_PSEUDO_REGISTER
&& need_for_call_save_p (regno
)));
5692 /* Return class for the split pseudo created from original pseudo with
5693 ALLOCNO_CLASS and MODE which got a hard register HARD_REGNO. We
5694 choose subclass of ALLOCNO_CLASS which contains HARD_REGNO and
5695 results in no secondary memory movements. */
5696 static enum reg_class
5697 choose_split_class (enum reg_class allocno_class
,
5698 int hard_regno ATTRIBUTE_UNUSED
,
5699 machine_mode mode ATTRIBUTE_UNUSED
)
5702 enum reg_class cl
, best_cl
= NO_REGS
;
5703 enum reg_class hard_reg_class ATTRIBUTE_UNUSED
5704 = REGNO_REG_CLASS (hard_regno
);
5706 if (! targetm
.secondary_memory_needed (mode
, allocno_class
, allocno_class
)
5707 && TEST_HARD_REG_BIT (reg_class_contents
[allocno_class
], hard_regno
))
5708 return allocno_class
;
5710 (cl
= reg_class_subclasses
[allocno_class
][i
]) != LIM_REG_CLASSES
;
5712 if (! targetm
.secondary_memory_needed (mode
, cl
, hard_reg_class
)
5713 && ! targetm
.secondary_memory_needed (mode
, hard_reg_class
, cl
)
5714 && TEST_HARD_REG_BIT (reg_class_contents
[cl
], hard_regno
)
5715 && (best_cl
== NO_REGS
5716 || ira_class_hard_regs_num
[best_cl
] < ira_class_hard_regs_num
[cl
]))
5721 /* Copy any equivalence information from ORIGINAL_REGNO to NEW_REGNO.
5722 It only makes sense to call this function if NEW_REGNO is always
5723 equal to ORIGINAL_REGNO. */
5726 lra_copy_reg_equiv (unsigned int new_regno
, unsigned int original_regno
)
5728 if (!ira_reg_equiv
[original_regno
].defined_p
)
5731 ira_expand_reg_equiv ();
5732 ira_reg_equiv
[new_regno
].defined_p
= true;
5733 if (ira_reg_equiv
[original_regno
].memory
)
5734 ira_reg_equiv
[new_regno
].memory
5735 = copy_rtx (ira_reg_equiv
[original_regno
].memory
);
5736 if (ira_reg_equiv
[original_regno
].constant
)
5737 ira_reg_equiv
[new_regno
].constant
5738 = copy_rtx (ira_reg_equiv
[original_regno
].constant
);
5739 if (ira_reg_equiv
[original_regno
].invariant
)
5740 ira_reg_equiv
[new_regno
].invariant
5741 = copy_rtx (ira_reg_equiv
[original_regno
].invariant
);
5744 /* Do split transformations for insn INSN, which defines or uses
5745 ORIGINAL_REGNO. NEXT_USAGE_INSNS specifies which instruction in
5746 the EBB next uses ORIGINAL_REGNO; it has the same form as the
5747 "insns" field of usage_insns. If TO is not NULL, we don't use
5748 usage_insns, we put restore insns after TO insn. It is a case when
5749 we call it from lra_split_hard_reg_for, outside the inheritance
5752 The transformations look like:
5755 ... s <- p (new insn -- save)
5757 ... p <- s (new insn -- restore)
5758 <- ... p ... <- ... p ...
5760 <- ... p ... <- ... p ...
5761 ... s <- p (new insn -- save)
5763 ... p <- s (new insn -- restore)
5764 <- ... p ... <- ... p ...
5766 where p is an original pseudo got a hard register or a hard
5767 register and s is a new split pseudo. The save is put before INSN
5768 if BEFORE_P is true. Return true if we succeed in such
5771 split_reg (bool before_p
, int original_regno
, rtx_insn
*insn
,
5772 rtx next_usage_insns
, rtx_insn
*to
)
5774 enum reg_class rclass
;
5776 int hard_regno
, nregs
;
5777 rtx new_reg
, usage_insn
;
5778 rtx_insn
*restore
, *save
;
5783 if (original_regno
< FIRST_PSEUDO_REGISTER
)
5785 rclass
= ira_allocno_class_translate
[REGNO_REG_CLASS (original_regno
)];
5786 hard_regno
= original_regno
;
5787 call_save_p
= false;
5789 mode
= lra_reg_info
[hard_regno
].biggest_mode
;
5790 machine_mode reg_rtx_mode
= GET_MODE (regno_reg_rtx
[hard_regno
]);
5791 /* A reg can have a biggest_mode of VOIDmode if it was only ever seen as
5792 part of a multi-word register. In that case, just use the reg_rtx
5793 mode. Do the same also if the biggest mode was larger than a register
5794 or we can not compare the modes. Otherwise, limit the size to that of
5795 the biggest access in the function or to the natural mode at least. */
5796 if (mode
== VOIDmode
5797 || !ordered_p (GET_MODE_PRECISION (mode
),
5798 GET_MODE_PRECISION (reg_rtx_mode
))
5799 || paradoxical_subreg_p (mode
, reg_rtx_mode
)
5800 || maybe_gt (GET_MODE_PRECISION (reg_rtx_mode
), GET_MODE_PRECISION (mode
)))
5802 original_reg
= regno_reg_rtx
[hard_regno
];
5803 mode
= reg_rtx_mode
;
5806 original_reg
= gen_rtx_REG (mode
, hard_regno
);
5810 mode
= PSEUDO_REGNO_MODE (original_regno
);
5811 hard_regno
= reg_renumber
[original_regno
];
5812 nregs
= hard_regno_nregs (hard_regno
, mode
);
5813 rclass
= lra_get_allocno_class (original_regno
);
5814 original_reg
= regno_reg_rtx
[original_regno
];
5815 call_save_p
= need_for_call_save_p (original_regno
);
5817 lra_assert (hard_regno
>= 0);
5818 if (lra_dump_file
!= NULL
)
5819 fprintf (lra_dump_file
,
5820 " ((((((((((((((((((((((((((((((((((((((((((((((((\n");
5824 mode
= HARD_REGNO_CALLER_SAVE_MODE (hard_regno
,
5825 hard_regno_nregs (hard_regno
, mode
),
5827 new_reg
= lra_create_new_reg (mode
, NULL_RTX
, NO_REGS
, "save");
5831 rclass
= choose_split_class (rclass
, hard_regno
, mode
);
5832 if (rclass
== NO_REGS
)
5834 if (lra_dump_file
!= NULL
)
5836 fprintf (lra_dump_file
,
5837 " Rejecting split of %d(%s): "
5838 "no good reg class for %d(%s)\n",
5840 reg_class_names
[lra_get_allocno_class (original_regno
)],
5842 reg_class_names
[REGNO_REG_CLASS (hard_regno
)]);
5845 " ))))))))))))))))))))))))))))))))))))))))))))))))\n");
5849 /* Split_if_necessary can split hard registers used as part of a
5850 multi-register mode but splits each register individually. The
5851 mode used for each independent register may not be supported
5852 so reject the split. Splitting the wider mode should theoretically
5853 be possible but is not implemented. */
5854 if (!targetm
.hard_regno_mode_ok (hard_regno
, mode
))
5856 if (lra_dump_file
!= NULL
)
5858 fprintf (lra_dump_file
,
5859 " Rejecting split of %d(%s): unsuitable mode %s\n",
5861 reg_class_names
[lra_get_allocno_class (original_regno
)],
5862 GET_MODE_NAME (mode
));
5865 " ))))))))))))))))))))))))))))))))))))))))))))))))\n");
5869 new_reg
= lra_create_new_reg (mode
, original_reg
, rclass
, "split");
5870 reg_renumber
[REGNO (new_reg
)] = hard_regno
;
5872 int new_regno
= REGNO (new_reg
);
5873 save
= emit_spill_move (true, new_reg
, original_reg
);
5874 if (NEXT_INSN (save
) != NULL_RTX
&& !call_save_p
)
5876 if (lra_dump_file
!= NULL
)
5880 " Rejecting split %d->%d resulting in > 2 save insns:\n",
5881 original_regno
, new_regno
);
5882 dump_rtl_slim (lra_dump_file
, save
, NULL
, -1, 0);
5883 fprintf (lra_dump_file
,
5884 " ))))))))))))))))))))))))))))))))))))))))))))))))\n");
5888 restore
= emit_spill_move (false, new_reg
, original_reg
);
5889 if (NEXT_INSN (restore
) != NULL_RTX
&& !call_save_p
)
5891 if (lra_dump_file
!= NULL
)
5893 fprintf (lra_dump_file
,
5894 " Rejecting split %d->%d "
5895 "resulting in > 2 restore insns:\n",
5896 original_regno
, new_regno
);
5897 dump_rtl_slim (lra_dump_file
, restore
, NULL
, -1, 0);
5898 fprintf (lra_dump_file
,
5899 " ))))))))))))))))))))))))))))))))))))))))))))))))\n");
5903 /* Transfer equivalence information to the spill register, so that
5904 if we fail to allocate the spill register, we have the option of
5905 rematerializing the original value instead of spilling to the stack. */
5906 if (!HARD_REGISTER_NUM_P (original_regno
)
5907 && mode
== PSEUDO_REGNO_MODE (original_regno
))
5908 lra_copy_reg_equiv (new_regno
, original_regno
);
5909 lra_reg_info
[new_regno
].restore_rtx
= regno_reg_rtx
[original_regno
];
5910 bitmap_set_bit (&lra_split_regs
, new_regno
);
5913 lra_assert (next_usage_insns
== NULL
);
5919 /* We need check_only_regs only inside the inheritance pass. */
5920 bitmap_set_bit (&check_only_regs
, new_regno
);
5921 bitmap_set_bit (&check_only_regs
, original_regno
);
5922 after_p
= usage_insns
[original_regno
].after_p
;
5925 if (GET_CODE (next_usage_insns
) != INSN_LIST
)
5927 usage_insn
= next_usage_insns
;
5930 usage_insn
= XEXP (next_usage_insns
, 0);
5931 lra_assert (DEBUG_INSN_P (usage_insn
));
5932 next_usage_insns
= XEXP (next_usage_insns
, 1);
5933 lra_substitute_pseudo (&usage_insn
, original_regno
, new_reg
, false,
5935 lra_update_insn_regno_info (as_a
<rtx_insn
*> (usage_insn
));
5936 if (lra_dump_file
!= NULL
)
5938 fprintf (lra_dump_file
, " Split reuse change %d->%d:\n",
5939 original_regno
, new_regno
);
5940 dump_insn_slim (lra_dump_file
, as_a
<rtx_insn
*> (usage_insn
));
5944 lra_assert (NOTE_P (usage_insn
) || NONDEBUG_INSN_P (usage_insn
));
5945 lra_assert (usage_insn
!= insn
|| (after_p
&& before_p
));
5946 lra_process_new_insns (as_a
<rtx_insn
*> (usage_insn
),
5947 after_p
? NULL
: restore
,
5948 after_p
? restore
: NULL
,
5950 ? "Add reg<-save" : "Add reg<-split");
5951 lra_process_new_insns (insn
, before_p
? save
: NULL
,
5952 before_p
? NULL
: save
,
5954 ? "Add save<-reg" : "Add split<-reg");
5956 /* If we are trying to split multi-register. We should check
5957 conflicts on the next assignment sub-pass. IRA can allocate on
5958 sub-register levels, LRA do this on pseudos level right now and
5959 this discrepancy may create allocation conflicts after
5961 check_and_force_assignment_correctness_p
= true;
5962 if (lra_dump_file
!= NULL
)
5963 fprintf (lra_dump_file
,
5964 " ))))))))))))))))))))))))))))))))))))))))))))))))\n");
5968 /* Split a hard reg for reload pseudo REGNO having RCLASS and living
5969 in the range [FROM, TO]. Return true if did a split. Otherwise,
5972 spill_hard_reg_in_range (int regno
, enum reg_class rclass
, rtx_insn
*from
, rtx_insn
*to
)
5979 HARD_REG_SET ignore
;
5981 lra_assert (from
!= NULL
&& to
!= NULL
);
5982 CLEAR_HARD_REG_SET (ignore
);
5983 EXECUTE_IF_SET_IN_BITMAP (&lra_reg_info
[regno
].insn_bitmap
, 0, uid
, bi
)
5985 lra_insn_recog_data_t id
= lra_insn_recog_data
[uid
];
5986 struct lra_static_insn_data
*static_id
= id
->insn_static_data
;
5987 struct lra_insn_reg
*reg
;
5989 for (reg
= id
->regs
; reg
!= NULL
; reg
= reg
->next
)
5990 if (reg
->regno
< FIRST_PSEUDO_REGISTER
)
5991 SET_HARD_REG_BIT (ignore
, reg
->regno
);
5992 for (reg
= static_id
->hard_regs
; reg
!= NULL
; reg
= reg
->next
)
5993 SET_HARD_REG_BIT (ignore
, reg
->regno
);
5995 rclass_size
= ira_class_hard_regs_num
[rclass
];
5996 for (i
= 0; i
< rclass_size
; i
++)
5998 hard_regno
= ira_class_hard_regs
[rclass
][i
];
5999 if (! TEST_HARD_REG_BIT (lra_reg_info
[regno
].conflict_hard_regs
, hard_regno
)
6000 || TEST_HARD_REG_BIT (ignore
, hard_regno
))
6002 for (insn
= from
; insn
!= NEXT_INSN (to
); insn
= NEXT_INSN (insn
))
6004 struct lra_static_insn_data
*static_id
;
6005 struct lra_insn_reg
*reg
;
6009 if (bitmap_bit_p (&lra_reg_info
[hard_regno
].insn_bitmap
,
6012 static_id
= lra_get_insn_recog_data (insn
)->insn_static_data
;
6013 for (reg
= static_id
->hard_regs
; reg
!= NULL
; reg
= reg
->next
)
6014 if (reg
->regno
== hard_regno
)
6019 if (insn
!= NEXT_INSN (to
))
6021 if (split_reg (TRUE
, hard_regno
, from
, NULL
, to
))
6027 /* Recognize that we need a split transformation for insn INSN, which
6028 defines or uses REGNO in its insn biggest MODE (we use it only if
6029 REGNO is a hard register). POTENTIAL_RELOAD_HARD_REGS contains
6030 hard registers which might be used for reloads since the EBB end.
6031 Put the save before INSN if BEFORE_P is true. MAX_UID is maximla
6032 uid before starting INSN processing. Return true if we succeed in
6033 such transformation. */
6035 split_if_necessary (int regno
, machine_mode mode
,
6036 HARD_REG_SET potential_reload_hard_regs
,
6037 bool before_p
, rtx_insn
*insn
, int max_uid
)
6041 rtx next_usage_insns
;
6043 if (regno
< FIRST_PSEUDO_REGISTER
)
6044 nregs
= hard_regno_nregs (regno
, mode
);
6045 for (i
= 0; i
< nregs
; i
++)
6046 if (usage_insns
[regno
+ i
].check
== curr_usage_insns_check
6047 && (next_usage_insns
= usage_insns
[regno
+ i
].insns
) != NULL_RTX
6048 /* To avoid processing the register twice or more. */
6049 && ((GET_CODE (next_usage_insns
) != INSN_LIST
6050 && INSN_UID (next_usage_insns
) < max_uid
)
6051 || (GET_CODE (next_usage_insns
) == INSN_LIST
6052 && (INSN_UID (XEXP (next_usage_insns
, 0)) < max_uid
)))
6053 && need_for_split_p (potential_reload_hard_regs
, regno
+ i
)
6054 && split_reg (before_p
, regno
+ i
, insn
, next_usage_insns
, NULL
))
6059 /* Return TRUE if rtx X is considered as an invariant for
6062 invariant_p (const_rtx x
)
6069 if (side_effects_p (x
))
6072 code
= GET_CODE (x
);
6073 mode
= GET_MODE (x
);
6077 code
= GET_CODE (x
);
6078 mode
= wider_subreg_mode (mode
, GET_MODE (x
));
6086 int i
, nregs
, regno
= REGNO (x
);
6088 if (regno
>= FIRST_PSEUDO_REGISTER
|| regno
== STACK_POINTER_REGNUM
6089 || TEST_HARD_REG_BIT (eliminable_regset
, regno
)
6090 || GET_MODE_CLASS (GET_MODE (x
)) == MODE_CC
)
6092 nregs
= hard_regno_nregs (regno
, mode
);
6093 for (i
= 0; i
< nregs
; i
++)
6094 if (! fixed_regs
[regno
+ i
]
6095 /* A hard register may be clobbered in the current insn
6096 but we can ignore this case because if the hard
6097 register is used it should be set somewhere after the
6099 || bitmap_bit_p (&invalid_invariant_regs
, regno
+ i
))
6102 fmt
= GET_RTX_FORMAT (code
);
6103 for (i
= GET_RTX_LENGTH (code
) - 1; i
>= 0; i
--)
6107 if (! invariant_p (XEXP (x
, i
)))
6110 else if (fmt
[i
] == 'E')
6112 for (j
= XVECLEN (x
, i
) - 1; j
>= 0; j
--)
6113 if (! invariant_p (XVECEXP (x
, i
, j
)))
6120 /* We have 'dest_reg <- invariant'. Let us try to make an invariant
6121 inheritance transformation (using dest_reg instead invariant in a
6122 subsequent insn). */
6124 process_invariant_for_inheritance (rtx dst_reg
, rtx invariant_rtx
)
6126 invariant_ptr_t invariant_ptr
;
6127 rtx_insn
*insn
, *new_insns
;
6128 rtx insn_set
, insn_reg
, new_reg
;
6130 bool succ_p
= false;
6131 int dst_regno
= REGNO (dst_reg
);
6132 machine_mode dst_mode
= GET_MODE (dst_reg
);
6133 enum reg_class cl
= lra_get_allocno_class (dst_regno
), insn_reg_cl
;
6135 invariant_ptr
= insert_invariant (invariant_rtx
);
6136 if ((insn
= invariant_ptr
->insn
) != NULL_RTX
)
6138 /* We have a subsequent insn using the invariant. */
6139 insn_set
= single_set (insn
);
6140 lra_assert (insn_set
!= NULL
);
6141 insn_reg
= SET_DEST (insn_set
);
6142 lra_assert (REG_P (insn_reg
));
6143 insn_regno
= REGNO (insn_reg
);
6144 insn_reg_cl
= lra_get_allocno_class (insn_regno
);
6146 if (dst_mode
== GET_MODE (insn_reg
)
6147 /* We should consider only result move reg insns which are
6149 && targetm
.register_move_cost (dst_mode
, cl
, insn_reg_cl
) == 2
6150 && targetm
.register_move_cost (dst_mode
, cl
, cl
) == 2)
6152 if (lra_dump_file
!= NULL
)
6153 fprintf (lra_dump_file
,
6154 " [[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[\n");
6155 new_reg
= lra_create_new_reg (dst_mode
, dst_reg
,
6156 cl
, "invariant inheritance");
6157 bitmap_set_bit (&lra_inheritance_pseudos
, REGNO (new_reg
));
6158 bitmap_set_bit (&check_only_regs
, REGNO (new_reg
));
6159 lra_reg_info
[REGNO (new_reg
)].restore_rtx
= PATTERN (insn
);
6161 lra_emit_move (new_reg
, dst_reg
);
6162 new_insns
= get_insns ();
6164 lra_process_new_insns (curr_insn
, NULL
, new_insns
,
6165 "Add invariant inheritance<-original");
6167 lra_emit_move (SET_DEST (insn_set
), new_reg
);
6168 new_insns
= get_insns ();
6170 lra_process_new_insns (insn
, NULL
, new_insns
,
6171 "Changing reload<-inheritance");
6172 lra_set_insn_deleted (insn
);
6174 if (lra_dump_file
!= NULL
)
6176 fprintf (lra_dump_file
,
6177 " Invariant inheritance reuse change %d (bb%d):\n",
6178 REGNO (new_reg
), BLOCK_FOR_INSN (insn
)->index
);
6179 dump_insn_slim (lra_dump_file
, insn
);
6180 fprintf (lra_dump_file
,
6181 " ]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]\n");
6185 invariant_ptr
->insn
= curr_insn
;
6189 /* Check only registers living at the current program point in the
6191 static bitmap_head live_regs
;
6193 /* Update live info in EBB given by its HEAD and TAIL insns after
6194 inheritance/split transformation. The function removes dead moves
6197 update_ebb_live_info (rtx_insn
*head
, rtx_insn
*tail
)
6202 rtx_insn
*prev_insn
;
6205 basic_block last_bb
, prev_bb
, curr_bb
;
6207 struct lra_insn_reg
*reg
;
6211 last_bb
= BLOCK_FOR_INSN (tail
);
6213 for (curr_insn
= tail
;
6214 curr_insn
!= PREV_INSN (head
);
6215 curr_insn
= prev_insn
)
6217 prev_insn
= PREV_INSN (curr_insn
);
6218 /* We need to process empty blocks too. They contain
6219 NOTE_INSN_BASIC_BLOCK referring for the basic block. */
6220 if (NOTE_P (curr_insn
) && NOTE_KIND (curr_insn
) != NOTE_INSN_BASIC_BLOCK
)
6222 curr_bb
= BLOCK_FOR_INSN (curr_insn
);
6223 if (curr_bb
!= prev_bb
)
6225 if (prev_bb
!= NULL
)
6227 /* Update df_get_live_in (prev_bb): */
6228 EXECUTE_IF_SET_IN_BITMAP (&check_only_regs
, 0, j
, bi
)
6229 if (bitmap_bit_p (&live_regs
, j
))
6230 bitmap_set_bit (df_get_live_in (prev_bb
), j
);
6232 bitmap_clear_bit (df_get_live_in (prev_bb
), j
);
6234 if (curr_bb
!= last_bb
)
6236 /* Update df_get_live_out (curr_bb): */
6237 EXECUTE_IF_SET_IN_BITMAP (&check_only_regs
, 0, j
, bi
)
6239 live_p
= bitmap_bit_p (&live_regs
, j
);
6241 FOR_EACH_EDGE (e
, ei
, curr_bb
->succs
)
6242 if (bitmap_bit_p (df_get_live_in (e
->dest
), j
))
6248 bitmap_set_bit (df_get_live_out (curr_bb
), j
);
6250 bitmap_clear_bit (df_get_live_out (curr_bb
), j
);
6254 bitmap_and (&live_regs
, &check_only_regs
, df_get_live_out (curr_bb
));
6256 if (! NONDEBUG_INSN_P (curr_insn
))
6258 curr_id
= lra_get_insn_recog_data (curr_insn
);
6259 curr_static_id
= curr_id
->insn_static_data
;
6261 if ((set
= single_set (curr_insn
)) != NULL_RTX
6262 && REG_P (SET_DEST (set
))
6263 && (regno
= REGNO (SET_DEST (set
))) >= FIRST_PSEUDO_REGISTER
6264 && SET_DEST (set
) != pic_offset_table_rtx
6265 && bitmap_bit_p (&check_only_regs
, regno
)
6266 && ! bitmap_bit_p (&live_regs
, regno
))
6268 /* See which defined values die here. */
6269 for (reg
= curr_id
->regs
; reg
!= NULL
; reg
= reg
->next
)
6270 if (reg
->type
== OP_OUT
&& ! reg
->subreg_p
)
6271 bitmap_clear_bit (&live_regs
, reg
->regno
);
6272 for (reg
= curr_static_id
->hard_regs
; reg
!= NULL
; reg
= reg
->next
)
6273 if (reg
->type
== OP_OUT
&& ! reg
->subreg_p
)
6274 bitmap_clear_bit (&live_regs
, reg
->regno
);
6275 if (curr_id
->arg_hard_regs
!= NULL
)
6276 /* Make clobbered argument hard registers die. */
6277 for (i
= 0; (regno
= curr_id
->arg_hard_regs
[i
]) >= 0; i
++)
6278 if (regno
>= FIRST_PSEUDO_REGISTER
)
6279 bitmap_clear_bit (&live_regs
, regno
- FIRST_PSEUDO_REGISTER
);
6280 /* Mark each used value as live. */
6281 for (reg
= curr_id
->regs
; reg
!= NULL
; reg
= reg
->next
)
6282 if (reg
->type
!= OP_OUT
6283 && bitmap_bit_p (&check_only_regs
, reg
->regno
))
6284 bitmap_set_bit (&live_regs
, reg
->regno
);
6285 for (reg
= curr_static_id
->hard_regs
; reg
!= NULL
; reg
= reg
->next
)
6286 if (reg
->type
!= OP_OUT
6287 && bitmap_bit_p (&check_only_regs
, reg
->regno
))
6288 bitmap_set_bit (&live_regs
, reg
->regno
);
6289 if (curr_id
->arg_hard_regs
!= NULL
)
6290 /* Make used argument hard registers live. */
6291 for (i
= 0; (regno
= curr_id
->arg_hard_regs
[i
]) >= 0; i
++)
6292 if (regno
< FIRST_PSEUDO_REGISTER
6293 && bitmap_bit_p (&check_only_regs
, regno
))
6294 bitmap_set_bit (&live_regs
, regno
);
6295 /* It is quite important to remove dead move insns because it
6296 means removing dead store. We don't need to process them for
6300 if (lra_dump_file
!= NULL
)
6302 fprintf (lra_dump_file
, " Removing dead insn:\n ");
6303 dump_insn_slim (lra_dump_file
, curr_insn
);
6305 lra_set_insn_deleted (curr_insn
);
6310 /* The structure describes info to do an inheritance for the current
6311 insn. We need to collect such info first before doing the
6312 transformations because the transformations change the insn
6313 internal representation. */
6316 /* Original regno. */
6318 /* Subsequent insns which can inherit original reg value. */
6322 /* Array containing all info for doing inheritance from the current
6324 static struct to_inherit to_inherit
[LRA_MAX_INSN_RELOADS
];
6326 /* Number elements in the previous array. */
6327 static int to_inherit_num
;
6329 /* Add inheritance info REGNO and INSNS. Their meaning is described in
6330 structure to_inherit. */
6332 add_to_inherit (int regno
, rtx insns
)
6336 for (i
= 0; i
< to_inherit_num
; i
++)
6337 if (to_inherit
[i
].regno
== regno
)
6339 lra_assert (to_inherit_num
< LRA_MAX_INSN_RELOADS
);
6340 to_inherit
[to_inherit_num
].regno
= regno
;
6341 to_inherit
[to_inherit_num
++].insns
= insns
;
6344 /* Return the last non-debug insn in basic block BB, or the block begin
6347 get_last_insertion_point (basic_block bb
)
6351 FOR_BB_INSNS_REVERSE (bb
, insn
)
6352 if (NONDEBUG_INSN_P (insn
) || NOTE_INSN_BASIC_BLOCK_P (insn
))
6357 /* Set up RES by registers living on edges FROM except the edge (FROM,
6358 TO) or by registers set up in a jump insn in BB FROM. */
6360 get_live_on_other_edges (basic_block from
, basic_block to
, bitmap res
)
6363 struct lra_insn_reg
*reg
;
6367 lra_assert (to
!= NULL
);
6369 FOR_EACH_EDGE (e
, ei
, from
->succs
)
6371 bitmap_ior_into (res
, df_get_live_in (e
->dest
));
6372 last
= get_last_insertion_point (from
);
6373 if (! JUMP_P (last
))
6375 curr_id
= lra_get_insn_recog_data (last
);
6376 for (reg
= curr_id
->regs
; reg
!= NULL
; reg
= reg
->next
)
6377 if (reg
->type
!= OP_IN
)
6378 bitmap_set_bit (res
, reg
->regno
);
6381 /* Used as a temporary results of some bitmap calculations. */
6382 static bitmap_head temp_bitmap
;
6384 /* We split for reloads of small class of hard regs. The following
6385 defines how many hard regs the class should have to be qualified as
6386 small. The code is mostly oriented to x86/x86-64 architecture
6387 where some insns need to use only specific register or pair of
6388 registers and these register can live in RTL explicitly, e.g. for
6389 parameter passing. */
6390 static const int max_small_class_regs_num
= 2;
6392 /* Do inheritance/split transformations in EBB starting with HEAD and
6393 finishing on TAIL. We process EBB insns in the reverse order.
6394 Return true if we did any inheritance/split transformation in the
6397 We should avoid excessive splitting which results in worse code
6398 because of inaccurate cost calculations for spilling new split
6399 pseudos in such case. To achieve this we do splitting only if
6400 register pressure is high in given basic block and there are reload
6401 pseudos requiring hard registers. We could do more register
6402 pressure calculations at any given program point to avoid necessary
6403 splitting even more but it is to expensive and the current approach
6404 works well enough. */
6406 inherit_in_ebb (rtx_insn
*head
, rtx_insn
*tail
)
6408 int i
, src_regno
, dst_regno
, nregs
;
6409 bool change_p
, succ_p
, update_reloads_num_p
;
6410 rtx_insn
*prev_insn
, *last_insn
;
6411 rtx next_usage_insns
, curr_set
;
6413 struct lra_insn_reg
*reg
;
6414 basic_block last_processed_bb
, curr_bb
= NULL
;
6415 HARD_REG_SET potential_reload_hard_regs
, live_hard_regs
;
6419 bool head_p
, after_p
;
6422 curr_usage_insns_check
++;
6423 clear_invariants ();
6424 reloads_num
= calls_num
= 0;
6425 for (unsigned int i
= 0; i
< NUM_ABI_IDS
; ++i
)
6426 last_call_for_abi
[i
] = 0;
6427 CLEAR_HARD_REG_SET (full_and_partial_call_clobbers
);
6428 bitmap_clear (&check_only_regs
);
6429 bitmap_clear (&invalid_invariant_regs
);
6430 last_processed_bb
= NULL
;
6431 CLEAR_HARD_REG_SET (potential_reload_hard_regs
);
6432 live_hard_regs
= eliminable_regset
| lra_no_alloc_regs
;
6433 /* We don't process new insns generated in the loop. */
6434 for (curr_insn
= tail
; curr_insn
!= PREV_INSN (head
); curr_insn
= prev_insn
)
6436 prev_insn
= PREV_INSN (curr_insn
);
6437 if (BLOCK_FOR_INSN (curr_insn
) != NULL
)
6438 curr_bb
= BLOCK_FOR_INSN (curr_insn
);
6439 if (last_processed_bb
!= curr_bb
)
6441 /* We are at the end of BB. Add qualified living
6442 pseudos for potential splitting. */
6443 to_process
= df_get_live_out (curr_bb
);
6444 if (last_processed_bb
!= NULL
)
6446 /* We are somewhere in the middle of EBB. */
6447 get_live_on_other_edges (curr_bb
, last_processed_bb
,
6449 to_process
= &temp_bitmap
;
6451 last_processed_bb
= curr_bb
;
6452 last_insn
= get_last_insertion_point (curr_bb
);
6453 after_p
= (! JUMP_P (last_insn
)
6454 && (! CALL_P (last_insn
)
6455 || (find_reg_note (last_insn
,
6456 REG_NORETURN
, NULL_RTX
) == NULL_RTX
6457 && ! SIBLING_CALL_P (last_insn
))));
6458 CLEAR_HARD_REG_SET (potential_reload_hard_regs
);
6459 EXECUTE_IF_SET_IN_BITMAP (to_process
, 0, j
, bi
)
6461 if ((int) j
>= lra_constraint_new_regno_start
)
6463 if (j
< FIRST_PSEUDO_REGISTER
|| reg_renumber
[j
] >= 0)
6465 if (j
< FIRST_PSEUDO_REGISTER
)
6466 SET_HARD_REG_BIT (live_hard_regs
, j
);
6468 add_to_hard_reg_set (&live_hard_regs
,
6469 PSEUDO_REGNO_MODE (j
),
6471 setup_next_usage_insn (j
, last_insn
, reloads_num
, after_p
);
6475 src_regno
= dst_regno
= -1;
6476 curr_set
= single_set (curr_insn
);
6477 if (curr_set
!= NULL_RTX
&& REG_P (SET_DEST (curr_set
)))
6478 dst_regno
= REGNO (SET_DEST (curr_set
));
6479 if (curr_set
!= NULL_RTX
&& REG_P (SET_SRC (curr_set
)))
6480 src_regno
= REGNO (SET_SRC (curr_set
));
6481 update_reloads_num_p
= true;
6482 if (src_regno
< lra_constraint_new_regno_start
6483 && src_regno
>= FIRST_PSEUDO_REGISTER
6484 && reg_renumber
[src_regno
] < 0
6485 && dst_regno
>= lra_constraint_new_regno_start
6486 && (cl
= lra_get_allocno_class (dst_regno
)) != NO_REGS
)
6488 /* 'reload_pseudo <- original_pseudo'. */
6489 if (ira_class_hard_regs_num
[cl
] <= max_small_class_regs_num
)
6491 update_reloads_num_p
= false;
6493 if (usage_insns
[src_regno
].check
== curr_usage_insns_check
6494 && (next_usage_insns
= usage_insns
[src_regno
].insns
) != NULL_RTX
)
6495 succ_p
= inherit_reload_reg (false, src_regno
, cl
,
6496 curr_insn
, next_usage_insns
);
6500 setup_next_usage_insn (src_regno
, curr_insn
, reloads_num
, false);
6501 if (hard_reg_set_subset_p (reg_class_contents
[cl
], live_hard_regs
))
6502 potential_reload_hard_regs
|= reg_class_contents
[cl
];
6504 else if (src_regno
< 0
6505 && dst_regno
>= lra_constraint_new_regno_start
6506 && invariant_p (SET_SRC (curr_set
))
6507 && (cl
= lra_get_allocno_class (dst_regno
)) != NO_REGS
6508 && ! bitmap_bit_p (&invalid_invariant_regs
, dst_regno
)
6509 && ! bitmap_bit_p (&invalid_invariant_regs
,
6510 ORIGINAL_REGNO(regno_reg_rtx
[dst_regno
])))
6512 /* 'reload_pseudo <- invariant'. */
6513 if (ira_class_hard_regs_num
[cl
] <= max_small_class_regs_num
)
6515 update_reloads_num_p
= false;
6516 if (process_invariant_for_inheritance (SET_DEST (curr_set
), SET_SRC (curr_set
)))
6518 if (hard_reg_set_subset_p (reg_class_contents
[cl
], live_hard_regs
))
6519 potential_reload_hard_regs
|= reg_class_contents
[cl
];
6521 else if (src_regno
>= lra_constraint_new_regno_start
6522 && dst_regno
< lra_constraint_new_regno_start
6523 && dst_regno
>= FIRST_PSEUDO_REGISTER
6524 && reg_renumber
[dst_regno
] < 0
6525 && (cl
= lra_get_allocno_class (src_regno
)) != NO_REGS
6526 && usage_insns
[dst_regno
].check
== curr_usage_insns_check
6527 && (next_usage_insns
6528 = usage_insns
[dst_regno
].insns
) != NULL_RTX
)
6530 if (ira_class_hard_regs_num
[cl
] <= max_small_class_regs_num
)
6532 update_reloads_num_p
= false;
6533 /* 'original_pseudo <- reload_pseudo'. */
6534 if (! JUMP_P (curr_insn
)
6535 && inherit_reload_reg (true, dst_regno
, cl
,
6536 curr_insn
, next_usage_insns
))
6539 usage_insns
[dst_regno
].check
= 0;
6540 if (hard_reg_set_subset_p (reg_class_contents
[cl
], live_hard_regs
))
6541 potential_reload_hard_regs
|= reg_class_contents
[cl
];
6543 else if (INSN_P (curr_insn
))
6546 int max_uid
= get_max_uid ();
6548 curr_id
= lra_get_insn_recog_data (curr_insn
);
6549 curr_static_id
= curr_id
->insn_static_data
;
6551 /* Process insn definitions. */
6552 for (iter
= 0; iter
< 2; iter
++)
6553 for (reg
= iter
== 0 ? curr_id
->regs
: curr_static_id
->hard_regs
;
6556 if (reg
->type
!= OP_IN
6557 && (dst_regno
= reg
->regno
) < lra_constraint_new_regno_start
)
6559 if (dst_regno
>= FIRST_PSEUDO_REGISTER
&& reg
->type
== OP_OUT
6560 && reg_renumber
[dst_regno
] < 0 && ! reg
->subreg_p
6561 && usage_insns
[dst_regno
].check
== curr_usage_insns_check
6562 && (next_usage_insns
6563 = usage_insns
[dst_regno
].insns
) != NULL_RTX
)
6565 struct lra_insn_reg
*r
;
6567 for (r
= curr_id
->regs
; r
!= NULL
; r
= r
->next
)
6568 if (r
->type
!= OP_OUT
&& r
->regno
== dst_regno
)
6570 /* Don't do inheritance if the pseudo is also
6571 used in the insn. */
6573 /* We cannot do inheritance right now
6574 because the current insn reg info (chain
6575 regs) can change after that. */
6576 add_to_inherit (dst_regno
, next_usage_insns
);
6578 /* We cannot process one reg twice here because of
6579 usage_insns invalidation. */
6580 if ((dst_regno
< FIRST_PSEUDO_REGISTER
6581 || reg_renumber
[dst_regno
] >= 0)
6582 && ! reg
->subreg_p
&& reg
->type
!= OP_IN
)
6586 if (split_if_necessary (dst_regno
, reg
->biggest_mode
,
6587 potential_reload_hard_regs
,
6588 false, curr_insn
, max_uid
))
6590 CLEAR_HARD_REG_SET (s
);
6591 if (dst_regno
< FIRST_PSEUDO_REGISTER
)
6592 add_to_hard_reg_set (&s
, reg
->biggest_mode
, dst_regno
);
6594 add_to_hard_reg_set (&s
, PSEUDO_REGNO_MODE (dst_regno
),
6595 reg_renumber
[dst_regno
]);
6596 live_hard_regs
&= ~s
;
6597 potential_reload_hard_regs
&= ~s
;
6599 /* We should invalidate potential inheritance or
6600 splitting for the current insn usages to the next
6601 usage insns (see code below) as the output pseudo
6603 if ((dst_regno
>= FIRST_PSEUDO_REGISTER
6604 && reg_renumber
[dst_regno
] < 0)
6605 || (reg
->type
== OP_OUT
&& ! reg
->subreg_p
6606 && (dst_regno
< FIRST_PSEUDO_REGISTER
6607 || reg_renumber
[dst_regno
] >= 0)))
6609 /* Invalidate and mark definitions. */
6610 if (dst_regno
>= FIRST_PSEUDO_REGISTER
)
6611 usage_insns
[dst_regno
].check
= -(int) INSN_UID (curr_insn
);
6614 nregs
= hard_regno_nregs (dst_regno
,
6616 for (i
= 0; i
< nregs
; i
++)
6617 usage_insns
[dst_regno
+ i
].check
6618 = -(int) INSN_UID (curr_insn
);
6622 /* Process clobbered call regs. */
6623 if (curr_id
->arg_hard_regs
!= NULL
)
6624 for (i
= 0; (dst_regno
= curr_id
->arg_hard_regs
[i
]) >= 0; i
++)
6625 if (dst_regno
>= FIRST_PSEUDO_REGISTER
)
6626 usage_insns
[dst_regno
- FIRST_PSEUDO_REGISTER
].check
6627 = -(int) INSN_UID (curr_insn
);
6628 if (! JUMP_P (curr_insn
))
6629 for (i
= 0; i
< to_inherit_num
; i
++)
6630 if (inherit_reload_reg (true, to_inherit
[i
].regno
,
6631 ALL_REGS
, curr_insn
,
6632 to_inherit
[i
].insns
))
6634 if (CALL_P (curr_insn
))
6636 rtx cheap
, pat
, dest
;
6638 int regno
, hard_regno
;
6641 function_abi callee_abi
= insn_callee_abi (curr_insn
);
6642 last_call_for_abi
[callee_abi
.id ()] = calls_num
;
6643 full_and_partial_call_clobbers
6644 |= callee_abi
.full_and_partial_reg_clobbers ();
6645 if ((cheap
= find_reg_note (curr_insn
,
6646 REG_RETURNED
, NULL_RTX
)) != NULL_RTX
6647 && ((cheap
= XEXP (cheap
, 0)), true)
6648 && (regno
= REGNO (cheap
)) >= FIRST_PSEUDO_REGISTER
6649 && (hard_regno
= reg_renumber
[regno
]) >= 0
6650 && usage_insns
[regno
].check
== curr_usage_insns_check
6651 /* If there are pending saves/restores, the
6652 optimization is not worth. */
6653 && usage_insns
[regno
].calls_num
== calls_num
- 1
6654 && callee_abi
.clobbers_reg_p (GET_MODE (cheap
), hard_regno
))
6656 /* Restore the pseudo from the call result as
6657 REG_RETURNED note says that the pseudo value is
6658 in the call result and the pseudo is an argument
6660 pat
= PATTERN (curr_insn
);
6661 if (GET_CODE (pat
) == PARALLEL
)
6662 pat
= XVECEXP (pat
, 0, 0);
6663 dest
= SET_DEST (pat
);
6664 /* For multiple return values dest is PARALLEL.
6665 Currently we handle only single return value case. */
6669 emit_move_insn (cheap
, copy_rtx (dest
));
6670 restore
= get_insns ();
6672 lra_process_new_insns (curr_insn
, NULL
, restore
,
6673 "Inserting call parameter restore");
6674 /* We don't need to save/restore of the pseudo from
6676 usage_insns
[regno
].calls_num
= calls_num
;
6677 remove_from_hard_reg_set
6678 (&full_and_partial_call_clobbers
,
6679 GET_MODE (cheap
), hard_regno
);
6680 bitmap_set_bit (&check_only_regs
, regno
);
6685 /* Process insn usages. */
6686 for (iter
= 0; iter
< 2; iter
++)
6687 for (reg
= iter
== 0 ? curr_id
->regs
: curr_static_id
->hard_regs
;
6690 if ((reg
->type
!= OP_OUT
6691 || (reg
->type
== OP_OUT
&& reg
->subreg_p
))
6692 && (src_regno
= reg
->regno
) < lra_constraint_new_regno_start
)
6694 if (src_regno
>= FIRST_PSEUDO_REGISTER
6695 && reg_renumber
[src_regno
] < 0 && reg
->type
== OP_IN
)
6697 if (usage_insns
[src_regno
].check
== curr_usage_insns_check
6698 && (next_usage_insns
6699 = usage_insns
[src_regno
].insns
) != NULL_RTX
6700 && NONDEBUG_INSN_P (curr_insn
))
6701 add_to_inherit (src_regno
, next_usage_insns
);
6702 else if (usage_insns
[src_regno
].check
6703 != -(int) INSN_UID (curr_insn
))
6704 /* Add usages but only if the reg is not set up
6705 in the same insn. */
6706 add_next_usage_insn (src_regno
, curr_insn
, reloads_num
);
6708 else if (src_regno
< FIRST_PSEUDO_REGISTER
6709 || reg_renumber
[src_regno
] >= 0)
6712 rtx_insn
*use_insn
= curr_insn
;
6714 before_p
= (JUMP_P (curr_insn
)
6715 || (CALL_P (curr_insn
) && reg
->type
== OP_IN
));
6716 if (NONDEBUG_INSN_P (curr_insn
)
6717 && (! JUMP_P (curr_insn
) || reg
->type
== OP_IN
)
6718 && split_if_necessary (src_regno
, reg
->biggest_mode
,
6719 potential_reload_hard_regs
,
6720 before_p
, curr_insn
, max_uid
))
6723 check_and_force_assignment_correctness_p
= true;
6726 usage_insns
[src_regno
].check
= 0;
6728 use_insn
= PREV_INSN (curr_insn
);
6730 if (NONDEBUG_INSN_P (curr_insn
))
6732 if (src_regno
< FIRST_PSEUDO_REGISTER
)
6733 add_to_hard_reg_set (&live_hard_regs
,
6734 reg
->biggest_mode
, src_regno
);
6736 add_to_hard_reg_set (&live_hard_regs
,
6737 PSEUDO_REGNO_MODE (src_regno
),
6738 reg_renumber
[src_regno
]);
6740 if (src_regno
>= FIRST_PSEUDO_REGISTER
)
6741 add_next_usage_insn (src_regno
, use_insn
, reloads_num
);
6744 for (i
= 0; i
< hard_regno_nregs (src_regno
, reg
->biggest_mode
); i
++)
6745 add_next_usage_insn (src_regno
+ i
, use_insn
, reloads_num
);
6749 /* Process used call regs. */
6750 if (curr_id
->arg_hard_regs
!= NULL
)
6751 for (i
= 0; (src_regno
= curr_id
->arg_hard_regs
[i
]) >= 0; i
++)
6752 if (src_regno
< FIRST_PSEUDO_REGISTER
)
6754 SET_HARD_REG_BIT (live_hard_regs
, src_regno
);
6755 add_next_usage_insn (src_regno
, curr_insn
, reloads_num
);
6757 for (i
= 0; i
< to_inherit_num
; i
++)
6759 src_regno
= to_inherit
[i
].regno
;
6760 if (inherit_reload_reg (false, src_regno
, ALL_REGS
,
6761 curr_insn
, to_inherit
[i
].insns
))
6764 setup_next_usage_insn (src_regno
, curr_insn
, reloads_num
, false);
6767 if (update_reloads_num_p
6768 && NONDEBUG_INSN_P (curr_insn
) && curr_set
!= NULL_RTX
)
6771 if ((REG_P (SET_DEST (curr_set
))
6772 && (regno
= REGNO (SET_DEST (curr_set
))) >= lra_constraint_new_regno_start
6773 && reg_renumber
[regno
] < 0
6774 && (cl
= lra_get_allocno_class (regno
)) != NO_REGS
)
6775 || (REG_P (SET_SRC (curr_set
))
6776 && (regno
= REGNO (SET_SRC (curr_set
))) >= lra_constraint_new_regno_start
6777 && reg_renumber
[regno
] < 0
6778 && (cl
= lra_get_allocno_class (regno
)) != NO_REGS
))
6780 if (ira_class_hard_regs_num
[cl
] <= max_small_class_regs_num
)
6782 if (hard_reg_set_subset_p (reg_class_contents
[cl
], live_hard_regs
))
6783 potential_reload_hard_regs
|= reg_class_contents
[cl
];
6786 if (NONDEBUG_INSN_P (curr_insn
))
6790 /* Invalidate invariants with changed regs. */
6791 curr_id
= lra_get_insn_recog_data (curr_insn
);
6792 for (reg
= curr_id
->regs
; reg
!= NULL
; reg
= reg
->next
)
6793 if (reg
->type
!= OP_IN
)
6795 bitmap_set_bit (&invalid_invariant_regs
, reg
->regno
);
6796 bitmap_set_bit (&invalid_invariant_regs
,
6797 ORIGINAL_REGNO (regno_reg_rtx
[reg
->regno
]));
6799 curr_static_id
= curr_id
->insn_static_data
;
6800 for (reg
= curr_static_id
->hard_regs
; reg
!= NULL
; reg
= reg
->next
)
6801 if (reg
->type
!= OP_IN
)
6802 bitmap_set_bit (&invalid_invariant_regs
, reg
->regno
);
6803 if (curr_id
->arg_hard_regs
!= NULL
)
6804 for (i
= 0; (regno
= curr_id
->arg_hard_regs
[i
]) >= 0; i
++)
6805 if (regno
>= FIRST_PSEUDO_REGISTER
)
6806 bitmap_set_bit (&invalid_invariant_regs
,
6807 regno
- FIRST_PSEUDO_REGISTER
);
6809 /* We reached the start of the current basic block. */
6810 if (prev_insn
== NULL_RTX
|| prev_insn
== PREV_INSN (head
)
6811 || BLOCK_FOR_INSN (prev_insn
) != curr_bb
)
6813 /* We reached the beginning of the current block -- do
6814 rest of spliting in the current BB. */
6815 to_process
= df_get_live_in (curr_bb
);
6816 if (BLOCK_FOR_INSN (head
) != curr_bb
)
6818 /* We are somewhere in the middle of EBB. */
6819 get_live_on_other_edges (EDGE_PRED (curr_bb
, 0)->src
,
6820 curr_bb
, &temp_bitmap
);
6821 to_process
= &temp_bitmap
;
6824 EXECUTE_IF_SET_IN_BITMAP (to_process
, 0, j
, bi
)
6826 if ((int) j
>= lra_constraint_new_regno_start
)
6828 if (((int) j
< FIRST_PSEUDO_REGISTER
|| reg_renumber
[j
] >= 0)
6829 && usage_insns
[j
].check
== curr_usage_insns_check
6830 && (next_usage_insns
= usage_insns
[j
].insns
) != NULL_RTX
)
6832 if (need_for_split_p (potential_reload_hard_regs
, j
))
6834 if (lra_dump_file
!= NULL
&& head_p
)
6836 fprintf (lra_dump_file
,
6837 " ----------------------------------\n");
6840 if (split_reg (false, j
, bb_note (curr_bb
),
6841 next_usage_insns
, NULL
))
6844 usage_insns
[j
].check
= 0;
6852 /* This value affects EBB forming. If probability of edge from EBB to
6853 a BB is not greater than the following value, we don't add the BB
6855 #define EBB_PROBABILITY_CUTOFF \
6856 ((REG_BR_PROB_BASE * param_lra_inheritance_ebb_probability_cutoff) / 100)
6858 /* Current number of inheritance/split iteration. */
6859 int lra_inheritance_iter
;
6861 /* Entry function for inheritance/split pass. */
6863 lra_inheritance (void)
6866 basic_block bb
, start_bb
;
6869 lra_inheritance_iter
++;
6870 if (lra_inheritance_iter
> LRA_MAX_INHERITANCE_PASSES
)
6872 timevar_push (TV_LRA_INHERITANCE
);
6873 if (lra_dump_file
!= NULL
)
6874 fprintf (lra_dump_file
, "\n********** Inheritance #%d: **********\n\n",
6875 lra_inheritance_iter
);
6876 curr_usage_insns_check
= 0;
6877 usage_insns
= XNEWVEC (struct usage_insns
, lra_constraint_new_regno_start
);
6878 for (i
= 0; i
< lra_constraint_new_regno_start
; i
++)
6879 usage_insns
[i
].check
= 0;
6880 bitmap_initialize (&check_only_regs
, ®_obstack
);
6881 bitmap_initialize (&invalid_invariant_regs
, ®_obstack
);
6882 bitmap_initialize (&live_regs
, ®_obstack
);
6883 bitmap_initialize (&temp_bitmap
, ®_obstack
);
6884 bitmap_initialize (&ebb_global_regs
, ®_obstack
);
6885 FOR_EACH_BB_FN (bb
, cfun
)
6888 if (lra_dump_file
!= NULL
)
6889 fprintf (lra_dump_file
, "EBB");
6890 /* Form a EBB starting with BB. */
6891 bitmap_clear (&ebb_global_regs
);
6892 bitmap_ior_into (&ebb_global_regs
, df_get_live_in (bb
));
6895 if (lra_dump_file
!= NULL
)
6896 fprintf (lra_dump_file
, " %d", bb
->index
);
6897 if (bb
->next_bb
== EXIT_BLOCK_PTR_FOR_FN (cfun
)
6898 || LABEL_P (BB_HEAD (bb
->next_bb
)))
6900 e
= find_fallthru_edge (bb
->succs
);
6903 if (e
->probability
.initialized_p ()
6904 && e
->probability
.to_reg_br_prob_base () < EBB_PROBABILITY_CUTOFF
)
6908 bitmap_ior_into (&ebb_global_regs
, df_get_live_out (bb
));
6909 if (lra_dump_file
!= NULL
)
6910 fprintf (lra_dump_file
, "\n");
6911 if (inherit_in_ebb (BB_HEAD (start_bb
), BB_END (bb
)))
6912 /* Remember that the EBB head and tail can change in
6914 update_ebb_live_info (BB_HEAD (start_bb
), BB_END (bb
));
6916 bitmap_release (&ebb_global_regs
);
6917 bitmap_release (&temp_bitmap
);
6918 bitmap_release (&live_regs
);
6919 bitmap_release (&invalid_invariant_regs
);
6920 bitmap_release (&check_only_regs
);
6923 timevar_pop (TV_LRA_INHERITANCE
);
6928 /* This page contains code to undo failed inheritance/split
6931 /* Current number of iteration undoing inheritance/split. */
6932 int lra_undo_inheritance_iter
;
6934 /* Fix BB live info LIVE after removing pseudos created on pass doing
6935 inheritance/split which are REMOVED_PSEUDOS. */
6937 fix_bb_live_info (bitmap live
, bitmap removed_pseudos
)
6942 EXECUTE_IF_SET_IN_BITMAP (removed_pseudos
, 0, regno
, bi
)
6943 if (bitmap_clear_bit (live
, regno
)
6944 && REG_P (lra_reg_info
[regno
].restore_rtx
))
6945 bitmap_set_bit (live
, REGNO (lra_reg_info
[regno
].restore_rtx
));
6948 /* Return regno of the (subreg of) REG. Otherwise, return a negative
6953 if (GET_CODE (reg
) == SUBREG
)
6954 reg
= SUBREG_REG (reg
);
6960 /* Delete a move INSN with destination reg DREGNO and a previous
6961 clobber insn with the same regno. The inheritance/split code can
6962 generate moves with preceding clobber and when we delete such moves
6963 we should delete the clobber insn too to keep the correct life
6966 delete_move_and_clobber (rtx_insn
*insn
, int dregno
)
6968 rtx_insn
*prev_insn
= PREV_INSN (insn
);
6970 lra_set_insn_deleted (insn
);
6971 lra_assert (dregno
>= 0);
6972 if (prev_insn
!= NULL
&& NONDEBUG_INSN_P (prev_insn
)
6973 && GET_CODE (PATTERN (prev_insn
)) == CLOBBER
6974 && dregno
== get_regno (XEXP (PATTERN (prev_insn
), 0)))
6975 lra_set_insn_deleted (prev_insn
);
6978 /* Remove inheritance/split pseudos which are in REMOVE_PSEUDOS and
6979 return true if we did any change. The undo transformations for
6980 inheritance looks like
6984 p <- i, i <- p, and i <- i3
6985 where p is original pseudo from which inheritance pseudo i was
6986 created, i and i3 are removed inheritance pseudos, i2 is another
6987 not removed inheritance pseudo. All split pseudos or other
6988 occurrences of removed inheritance pseudos are changed on the
6989 corresponding original pseudos.
6991 The function also schedules insns changed and created during
6992 inheritance/split pass for processing by the subsequent constraint
6995 remove_inheritance_pseudos (bitmap remove_pseudos
)
6998 int regno
, sregno
, prev_sregno
, dregno
;
7001 rtx_insn
*prev_insn
;
7002 bool change_p
, done_p
;
7004 change_p
= ! bitmap_empty_p (remove_pseudos
);
7005 /* We cannot finish the function right away if CHANGE_P is true
7006 because we need to marks insns affected by previous
7007 inheritance/split pass for processing by the subsequent
7009 FOR_EACH_BB_FN (bb
, cfun
)
7011 fix_bb_live_info (df_get_live_in (bb
), remove_pseudos
);
7012 fix_bb_live_info (df_get_live_out (bb
), remove_pseudos
);
7013 FOR_BB_INSNS_REVERSE (bb
, curr_insn
)
7015 if (! INSN_P (curr_insn
))
7018 sregno
= dregno
= -1;
7019 if (change_p
&& NONDEBUG_INSN_P (curr_insn
)
7020 && (set
= single_set (curr_insn
)) != NULL_RTX
)
7022 dregno
= get_regno (SET_DEST (set
));
7023 sregno
= get_regno (SET_SRC (set
));
7026 if (sregno
>= 0 && dregno
>= 0)
7028 if (bitmap_bit_p (remove_pseudos
, dregno
)
7029 && ! REG_P (lra_reg_info
[dregno
].restore_rtx
))
7031 /* invariant inheritance pseudo <- original pseudo */
7032 if (lra_dump_file
!= NULL
)
7034 fprintf (lra_dump_file
, " Removing invariant inheritance:\n");
7035 dump_insn_slim (lra_dump_file
, curr_insn
);
7036 fprintf (lra_dump_file
, "\n");
7038 delete_move_and_clobber (curr_insn
, dregno
);
7041 else if (bitmap_bit_p (remove_pseudos
, sregno
)
7042 && ! REG_P (lra_reg_info
[sregno
].restore_rtx
))
7044 /* reload pseudo <- invariant inheritance pseudo */
7046 /* We cannot just change the source. It might be
7047 an insn different from the move. */
7048 emit_insn (lra_reg_info
[sregno
].restore_rtx
);
7049 rtx_insn
*new_insns
= get_insns ();
7051 lra_assert (single_set (new_insns
) != NULL
7052 && SET_DEST (set
) == SET_DEST (single_set (new_insns
)));
7053 lra_process_new_insns (curr_insn
, NULL
, new_insns
,
7054 "Changing reload<-invariant inheritance");
7055 delete_move_and_clobber (curr_insn
, dregno
);
7058 else if ((bitmap_bit_p (remove_pseudos
, sregno
)
7059 && (get_regno (lra_reg_info
[sregno
].restore_rtx
) == dregno
7060 || (bitmap_bit_p (remove_pseudos
, dregno
)
7061 && get_regno (lra_reg_info
[sregno
].restore_rtx
) >= 0
7062 && (get_regno (lra_reg_info
[sregno
].restore_rtx
)
7063 == get_regno (lra_reg_info
[dregno
].restore_rtx
)))))
7064 || (bitmap_bit_p (remove_pseudos
, dregno
)
7065 && get_regno (lra_reg_info
[dregno
].restore_rtx
) == sregno
))
7066 /* One of the following cases:
7067 original <- removed inheritance pseudo
7068 removed inherit pseudo <- another removed inherit pseudo
7069 removed inherit pseudo <- original pseudo
7071 removed_split_pseudo <- original_reg
7072 original_reg <- removed_split_pseudo */
7074 if (lra_dump_file
!= NULL
)
7076 fprintf (lra_dump_file
, " Removing %s:\n",
7077 bitmap_bit_p (&lra_split_regs
, sregno
)
7078 || bitmap_bit_p (&lra_split_regs
, dregno
)
7079 ? "split" : "inheritance");
7080 dump_insn_slim (lra_dump_file
, curr_insn
);
7082 delete_move_and_clobber (curr_insn
, dregno
);
7085 else if (bitmap_bit_p (remove_pseudos
, sregno
)
7086 && bitmap_bit_p (&lra_inheritance_pseudos
, sregno
))
7088 /* Search the following pattern:
7089 inherit_or_split_pseudo1 <- inherit_or_split_pseudo2
7090 original_pseudo <- inherit_or_split_pseudo1
7091 where the 2nd insn is the current insn and
7092 inherit_or_split_pseudo2 is not removed. If it is found,
7093 change the current insn onto:
7094 original_pseudo <- inherit_or_split_pseudo2. */
7095 for (prev_insn
= PREV_INSN (curr_insn
);
7096 prev_insn
!= NULL_RTX
&& ! NONDEBUG_INSN_P (prev_insn
);
7097 prev_insn
= PREV_INSN (prev_insn
))
7099 if (prev_insn
!= NULL_RTX
&& BLOCK_FOR_INSN (prev_insn
) == bb
7100 && (prev_set
= single_set (prev_insn
)) != NULL_RTX
7101 /* There should be no subregs in insn we are
7102 searching because only the original reg might
7103 be in subreg when we changed the mode of
7104 load/store for splitting. */
7105 && REG_P (SET_DEST (prev_set
))
7106 && REG_P (SET_SRC (prev_set
))
7107 && (int) REGNO (SET_DEST (prev_set
)) == sregno
7108 && ((prev_sregno
= REGNO (SET_SRC (prev_set
)))
7109 >= FIRST_PSEUDO_REGISTER
)
7110 && (lra_reg_info
[prev_sregno
].restore_rtx
== NULL_RTX
7112 /* As we consider chain of inheritance or
7113 splitting described in above comment we should
7114 check that sregno and prev_sregno were
7115 inheritance/split pseudos created from the
7116 same original regno. */
7117 (get_regno (lra_reg_info
[sregno
].restore_rtx
) >= 0
7118 && (get_regno (lra_reg_info
[sregno
].restore_rtx
)
7119 == get_regno (lra_reg_info
[prev_sregno
].restore_rtx
))))
7120 && ! bitmap_bit_p (remove_pseudos
, prev_sregno
))
7122 lra_assert (GET_MODE (SET_SRC (prev_set
))
7123 == GET_MODE (regno_reg_rtx
[sregno
]));
7124 /* Although we have a single set, the insn can
7125 contain more one sregno register occurrence
7126 as a source. Change all occurrences. */
7127 lra_substitute_pseudo_within_insn (curr_insn
, sregno
,
7130 /* As we are finishing with processing the insn
7131 here, check the destination too as it might
7132 inheritance pseudo for another pseudo. */
7133 if (bitmap_bit_p (remove_pseudos
, dregno
)
7134 && bitmap_bit_p (&lra_inheritance_pseudos
, dregno
)
7136 = lra_reg_info
[dregno
].restore_rtx
) != NULL_RTX
)
7138 if (GET_CODE (SET_DEST (set
)) == SUBREG
)
7139 SUBREG_REG (SET_DEST (set
)) = restore_rtx
;
7141 SET_DEST (set
) = restore_rtx
;
7143 lra_push_insn_and_update_insn_regno_info (curr_insn
);
7144 lra_set_used_insn_alternative_by_uid
7145 (INSN_UID (curr_insn
), LRA_UNKNOWN_ALT
);
7147 if (lra_dump_file
!= NULL
)
7149 fprintf (lra_dump_file
, " Change reload insn:\n");
7150 dump_insn_slim (lra_dump_file
, curr_insn
);
7157 struct lra_insn_reg
*reg
;
7158 bool restored_regs_p
= false;
7159 bool kept_regs_p
= false;
7161 curr_id
= lra_get_insn_recog_data (curr_insn
);
7162 for (reg
= curr_id
->regs
; reg
!= NULL
; reg
= reg
->next
)
7165 restore_rtx
= lra_reg_info
[regno
].restore_rtx
;
7166 if (restore_rtx
!= NULL_RTX
)
7168 if (change_p
&& bitmap_bit_p (remove_pseudos
, regno
))
7170 lra_substitute_pseudo_within_insn
7171 (curr_insn
, regno
, restore_rtx
, false);
7172 restored_regs_p
= true;
7178 if (NONDEBUG_INSN_P (curr_insn
) && kept_regs_p
)
7180 /* The instruction has changed since the previous
7181 constraints pass. */
7182 lra_push_insn_and_update_insn_regno_info (curr_insn
);
7183 lra_set_used_insn_alternative_by_uid
7184 (INSN_UID (curr_insn
), LRA_UNKNOWN_ALT
);
7186 else if (restored_regs_p
)
7187 /* The instruction has been restored to the form that
7188 it had during the previous constraints pass. */
7189 lra_update_insn_regno_info (curr_insn
);
7190 if (restored_regs_p
&& lra_dump_file
!= NULL
)
7192 fprintf (lra_dump_file
, " Insn after restoring regs:\n");
7193 dump_insn_slim (lra_dump_file
, curr_insn
);
7201 /* If optional reload pseudos failed to get a hard register or was not
7202 inherited, it is better to remove optional reloads. We do this
7203 transformation after undoing inheritance to figure out necessity to
7204 remove optional reloads easier. Return true if we do any
7207 undo_optional_reloads (void)
7209 bool change_p
, keep_p
;
7210 unsigned int regno
, uid
;
7211 bitmap_iterator bi
, bi2
;
7214 auto_bitmap
removed_optional_reload_pseudos (®_obstack
);
7216 bitmap_copy (removed_optional_reload_pseudos
, &lra_optional_reload_pseudos
);
7217 EXECUTE_IF_SET_IN_BITMAP (&lra_optional_reload_pseudos
, 0, regno
, bi
)
7220 /* Keep optional reloads from previous subpasses. */
7221 if (lra_reg_info
[regno
].restore_rtx
== NULL_RTX
7222 /* If the original pseudo changed its allocation, just
7223 removing the optional pseudo is dangerous as the original
7224 pseudo will have longer live range. */
7225 || reg_renumber
[REGNO (lra_reg_info
[regno
].restore_rtx
)] >= 0)
7227 else if (reg_renumber
[regno
] >= 0)
7228 EXECUTE_IF_SET_IN_BITMAP (&lra_reg_info
[regno
].insn_bitmap
, 0, uid
, bi2
)
7230 insn
= lra_insn_recog_data
[uid
]->insn
;
7231 if ((set
= single_set (insn
)) == NULL_RTX
)
7233 src
= SET_SRC (set
);
7234 dest
= SET_DEST (set
);
7235 if (! REG_P (src
) || ! REG_P (dest
))
7237 if (REGNO (dest
) == regno
7238 /* Ignore insn for optional reloads itself. */
7239 && REGNO (lra_reg_info
[regno
].restore_rtx
) != REGNO (src
)
7240 /* Check only inheritance on last inheritance pass. */
7241 && (int) REGNO (src
) >= new_regno_start
7242 /* Check that the optional reload was inherited. */
7243 && bitmap_bit_p (&lra_inheritance_pseudos
, REGNO (src
)))
7251 bitmap_clear_bit (removed_optional_reload_pseudos
, regno
);
7252 if (lra_dump_file
!= NULL
)
7253 fprintf (lra_dump_file
, "Keep optional reload reg %d\n", regno
);
7256 change_p
= ! bitmap_empty_p (removed_optional_reload_pseudos
);
7257 auto_bitmap
insn_bitmap (®_obstack
);
7258 EXECUTE_IF_SET_IN_BITMAP (removed_optional_reload_pseudos
, 0, regno
, bi
)
7260 if (lra_dump_file
!= NULL
)
7261 fprintf (lra_dump_file
, "Remove optional reload reg %d\n", regno
);
7262 bitmap_copy (insn_bitmap
, &lra_reg_info
[regno
].insn_bitmap
);
7263 EXECUTE_IF_SET_IN_BITMAP (insn_bitmap
, 0, uid
, bi2
)
7265 insn
= lra_insn_recog_data
[uid
]->insn
;
7266 if ((set
= single_set (insn
)) != NULL_RTX
)
7268 src
= SET_SRC (set
);
7269 dest
= SET_DEST (set
);
7270 if (REG_P (src
) && REG_P (dest
)
7271 && ((REGNO (src
) == regno
7272 && (REGNO (lra_reg_info
[regno
].restore_rtx
)
7274 || (REGNO (dest
) == regno
7275 && (REGNO (lra_reg_info
[regno
].restore_rtx
)
7278 if (lra_dump_file
!= NULL
)
7280 fprintf (lra_dump_file
, " Deleting move %u\n",
7282 dump_insn_slim (lra_dump_file
, insn
);
7284 delete_move_and_clobber (insn
, REGNO (dest
));
7287 /* We should not worry about generation memory-memory
7288 moves here as if the corresponding inheritance did
7289 not work (inheritance pseudo did not get a hard reg),
7290 we remove the inheritance pseudo and the optional
7293 lra_substitute_pseudo_within_insn
7294 (insn
, regno
, lra_reg_info
[regno
].restore_rtx
, false);
7295 lra_update_insn_regno_info (insn
);
7296 if (lra_dump_file
!= NULL
)
7298 fprintf (lra_dump_file
,
7299 " Restoring original insn:\n");
7300 dump_insn_slim (lra_dump_file
, insn
);
7304 /* Clear restore_regnos. */
7305 EXECUTE_IF_SET_IN_BITMAP (&lra_optional_reload_pseudos
, 0, regno
, bi
)
7306 lra_reg_info
[regno
].restore_rtx
= NULL_RTX
;
7310 /* Entry function for undoing inheritance/split transformation. Return true
7311 if we did any RTL change in this pass. */
7313 lra_undo_inheritance (void)
7317 int n_all_inherit
, n_inherit
, n_all_split
, n_split
;
7322 lra_undo_inheritance_iter
++;
7323 if (lra_undo_inheritance_iter
> LRA_MAX_INHERITANCE_PASSES
)
7325 if (lra_dump_file
!= NULL
)
7326 fprintf (lra_dump_file
,
7327 "\n********** Undoing inheritance #%d: **********\n\n",
7328 lra_undo_inheritance_iter
);
7329 auto_bitmap
remove_pseudos (®_obstack
);
7330 n_inherit
= n_all_inherit
= 0;
7331 EXECUTE_IF_SET_IN_BITMAP (&lra_inheritance_pseudos
, 0, regno
, bi
)
7332 if (lra_reg_info
[regno
].restore_rtx
!= NULL_RTX
)
7335 if (reg_renumber
[regno
] < 0
7336 /* If the original pseudo changed its allocation, just
7337 removing inheritance is dangerous as for changing
7338 allocation we used shorter live-ranges. */
7339 && (! REG_P (lra_reg_info
[regno
].restore_rtx
)
7340 || reg_renumber
[REGNO (lra_reg_info
[regno
].restore_rtx
)] < 0))
7341 bitmap_set_bit (remove_pseudos
, regno
);
7345 if (lra_dump_file
!= NULL
&& n_all_inherit
!= 0)
7346 fprintf (lra_dump_file
, "Inherit %d out of %d (%.2f%%)\n",
7347 n_inherit
, n_all_inherit
,
7348 (double) n_inherit
/ n_all_inherit
* 100);
7349 n_split
= n_all_split
= 0;
7350 EXECUTE_IF_SET_IN_BITMAP (&lra_split_regs
, 0, regno
, bi
)
7351 if ((restore_rtx
= lra_reg_info
[regno
].restore_rtx
) != NULL_RTX
)
7353 int restore_regno
= REGNO (restore_rtx
);
7356 hard_regno
= (restore_regno
>= FIRST_PSEUDO_REGISTER
7357 ? reg_renumber
[restore_regno
] : restore_regno
);
7358 if (hard_regno
< 0 || reg_renumber
[regno
] == hard_regno
)
7359 bitmap_set_bit (remove_pseudos
, regno
);
7363 if (lra_dump_file
!= NULL
)
7364 fprintf (lra_dump_file
, " Keep split r%d (orig=r%d)\n",
7365 regno
, restore_regno
);
7368 if (lra_dump_file
!= NULL
&& n_all_split
!= 0)
7369 fprintf (lra_dump_file
, "Split %d out of %d (%.2f%%)\n",
7370 n_split
, n_all_split
,
7371 (double) n_split
/ n_all_split
* 100);
7372 change_p
= remove_inheritance_pseudos (remove_pseudos
);
7373 /* Clear restore_regnos. */
7374 EXECUTE_IF_SET_IN_BITMAP (&lra_inheritance_pseudos
, 0, regno
, bi
)
7375 lra_reg_info
[regno
].restore_rtx
= NULL_RTX
;
7376 EXECUTE_IF_SET_IN_BITMAP (&lra_split_regs
, 0, regno
, bi
)
7377 lra_reg_info
[regno
].restore_rtx
= NULL_RTX
;
7378 change_p
= undo_optional_reloads () || change_p
;