lra: Tighten check for reloading paradoxical subregs [PR94052]
[gcc.git] / gcc / lra-constraints.c
1 /* Code for RTL transformations to satisfy insn constraints.
2 Copyright (C) 2010-2020 Free Software Foundation, Inc.
3 Contributed by Vladimir Makarov <vmakarov@redhat.com>.
4
5 This file is part of GCC.
6
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
10 version.
11
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
15 for more details.
16
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/>. */
20
21
22 /* This file contains code for 3 passes: constraint pass,
23 inheritance/split pass, and pass for undoing failed inheritance and
24 split.
25
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.
33
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
37 allocations;
38 o some heuristics to choose insn alternative to improve the
39 inheritance;
40 o early clobbers etc.
41
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
45 changed.
46
47 There is special code for preventing all LRA and this pass cycling
48 in case of bugs.
49
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.
54
55 The inheritance/spilt pass is to transform code to achieve
56 ineheritance and live range splitting. It is done on backward
57 traversal of EBBs.
58
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:
62
63 reload_p1 <- p reload_p1 <- p
64 ... new_p <- reload_p1
65 ... => ...
66 reload_p2 <- p reload_p2 <- new_p
67
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
70 pseudo*.
71
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.
75
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
82 insns.
83
84 Splitting (transformation) is also done in EBB scope on the same
85 pass as the inheritance:
86
87 r <- ... or ... <- r r <- ... or ... <- r
88 ... s <- r (new insn -- save)
89 ... =>
90 ... r <- s (new insn -- restore)
91 ... <- r ... <- r
92
93 The *split pseudo* s is assigned to the hard register of the
94 original pseudo or hard register r.
95
96 Splitting is done:
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.
101
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. */
106
107 #undef REG_OK_STRICT
108
109 #include "config.h"
110 #include "system.h"
111 #include "coretypes.h"
112 #include "backend.h"
113 #include "target.h"
114 #include "rtl.h"
115 #include "tree.h"
116 #include "predict.h"
117 #include "df.h"
118 #include "memmodel.h"
119 #include "tm_p.h"
120 #include "expmed.h"
121 #include "optabs.h"
122 #include "regs.h"
123 #include "ira.h"
124 #include "recog.h"
125 #include "output.h"
126 #include "addresses.h"
127 #include "expr.h"
128 #include "cfgrtl.h"
129 #include "rtl-error.h"
130 #include "lra.h"
131 #include "lra-int.h"
132 #include "print-rtl.h"
133 #include "function-abi.h"
134
135 /* Value of LRA_CURR_RELOAD_NUM at the beginning of BB of the current
136 insn. Remember that LRA_CURR_RELOAD_NUM is the number of emitted
137 reload insns. */
138 static int bb_reload_num;
139
140 /* The current insn being processed and corresponding its single set
141 (NULL otherwise), its data (basic block, the insn data, the insn
142 static data, and the mode of each operand). */
143 static rtx_insn *curr_insn;
144 static rtx curr_insn_set;
145 static basic_block curr_bb;
146 static lra_insn_recog_data_t curr_id;
147 static struct lra_static_insn_data *curr_static_id;
148 static machine_mode curr_operand_mode[MAX_RECOG_OPERANDS];
149 /* Mode of the register substituted by its equivalence with VOIDmode
150 (e.g. constant) and whose subreg is given operand of the current
151 insn. VOIDmode in all other cases. */
152 static machine_mode original_subreg_reg_mode[MAX_RECOG_OPERANDS];
153
154 \f
155
156 /* Start numbers for new registers and insns at the current constraints
157 pass start. */
158 static int new_regno_start;
159 static int new_insn_uid_start;
160
161 /* If LOC is nonnull, strip any outer subreg from it. */
162 static inline rtx *
163 strip_subreg (rtx *loc)
164 {
165 return loc && GET_CODE (*loc) == SUBREG ? &SUBREG_REG (*loc) : loc;
166 }
167
168 /* Return hard regno of REGNO or if it is was not assigned to a hard
169 register, use a hard register from its allocno class. */
170 static int
171 get_try_hard_regno (int regno)
172 {
173 int hard_regno;
174 enum reg_class rclass;
175
176 if ((hard_regno = regno) >= FIRST_PSEUDO_REGISTER)
177 hard_regno = lra_get_regno_hard_regno (regno);
178 if (hard_regno >= 0)
179 return hard_regno;
180 rclass = lra_get_allocno_class (regno);
181 if (rclass == NO_REGS)
182 return -1;
183 return ira_class_hard_regs[rclass][0];
184 }
185
186 /* Return the hard regno of X after removing its subreg. If X is not
187 a register or a subreg of a register, return -1. If X is a pseudo,
188 use its assignment. If FINAL_P return the final hard regno which will
189 be after elimination. */
190 static int
191 get_hard_regno (rtx x, bool final_p)
192 {
193 rtx reg;
194 int hard_regno;
195
196 reg = x;
197 if (SUBREG_P (x))
198 reg = SUBREG_REG (x);
199 if (! REG_P (reg))
200 return -1;
201 if (! HARD_REGISTER_NUM_P (hard_regno = REGNO (reg)))
202 hard_regno = lra_get_regno_hard_regno (hard_regno);
203 if (hard_regno < 0)
204 return -1;
205 if (final_p)
206 hard_regno = lra_get_elimination_hard_regno (hard_regno);
207 if (SUBREG_P (x))
208 hard_regno += subreg_regno_offset (hard_regno, GET_MODE (reg),
209 SUBREG_BYTE (x), GET_MODE (x));
210 return hard_regno;
211 }
212
213 /* If REGNO is a hard register or has been allocated a hard register,
214 return the class of that register. If REGNO is a reload pseudo
215 created by the current constraints pass, return its allocno class.
216 Return NO_REGS otherwise. */
217 static enum reg_class
218 get_reg_class (int regno)
219 {
220 int hard_regno;
221
222 if (! HARD_REGISTER_NUM_P (hard_regno = regno))
223 hard_regno = lra_get_regno_hard_regno (regno);
224 if (hard_regno >= 0)
225 {
226 hard_regno = lra_get_elimination_hard_regno (hard_regno);
227 return REGNO_REG_CLASS (hard_regno);
228 }
229 if (regno >= new_regno_start)
230 return lra_get_allocno_class (regno);
231 return NO_REGS;
232 }
233
234 /* Return true if REG satisfies (or will satisfy) reg class constraint
235 CL. Use elimination first if REG is a hard register. If REG is a
236 reload pseudo created by this constraints pass, assume that it will
237 be allocated a hard register from its allocno class, but allow that
238 class to be narrowed to CL if it is currently a superset of CL.
239
240 If NEW_CLASS is nonnull, set *NEW_CLASS to the new allocno class of
241 REGNO (reg), or NO_REGS if no change in its class was needed. */
242 static bool
243 in_class_p (rtx reg, enum reg_class cl, enum reg_class *new_class)
244 {
245 enum reg_class rclass, common_class;
246 machine_mode reg_mode;
247 int class_size, hard_regno, nregs, i, j;
248 int regno = REGNO (reg);
249
250 if (new_class != NULL)
251 *new_class = NO_REGS;
252 if (regno < FIRST_PSEUDO_REGISTER)
253 {
254 rtx final_reg = reg;
255 rtx *final_loc = &final_reg;
256
257 lra_eliminate_reg_if_possible (final_loc);
258 return TEST_HARD_REG_BIT (reg_class_contents[cl], REGNO (*final_loc));
259 }
260 reg_mode = GET_MODE (reg);
261 rclass = get_reg_class (regno);
262 if (regno < new_regno_start
263 /* Do not allow the constraints for reload instructions to
264 influence the classes of new pseudos. These reloads are
265 typically moves that have many alternatives, and restricting
266 reload pseudos for one alternative may lead to situations
267 where other reload pseudos are no longer allocatable. */
268 || (INSN_UID (curr_insn) >= new_insn_uid_start
269 && curr_insn_set != NULL
270 && ((OBJECT_P (SET_SRC (curr_insn_set))
271 && ! CONSTANT_P (SET_SRC (curr_insn_set)))
272 || (GET_CODE (SET_SRC (curr_insn_set)) == SUBREG
273 && OBJECT_P (SUBREG_REG (SET_SRC (curr_insn_set)))
274 && ! CONSTANT_P (SUBREG_REG (SET_SRC (curr_insn_set)))))))
275 /* When we don't know what class will be used finally for reload
276 pseudos, we use ALL_REGS. */
277 return ((regno >= new_regno_start && rclass == ALL_REGS)
278 || (rclass != NO_REGS && ira_class_subset_p[rclass][cl]
279 && ! hard_reg_set_subset_p (reg_class_contents[cl],
280 lra_no_alloc_regs)));
281 else
282 {
283 common_class = ira_reg_class_subset[rclass][cl];
284 if (new_class != NULL)
285 *new_class = common_class;
286 if (hard_reg_set_subset_p (reg_class_contents[common_class],
287 lra_no_alloc_regs))
288 return false;
289 /* Check that there are enough allocatable regs. */
290 class_size = ira_class_hard_regs_num[common_class];
291 for (i = 0; i < class_size; i++)
292 {
293 hard_regno = ira_class_hard_regs[common_class][i];
294 nregs = hard_regno_nregs (hard_regno, reg_mode);
295 if (nregs == 1)
296 return true;
297 for (j = 0; j < nregs; j++)
298 if (TEST_HARD_REG_BIT (lra_no_alloc_regs, hard_regno + j)
299 || ! TEST_HARD_REG_BIT (reg_class_contents[common_class],
300 hard_regno + j))
301 break;
302 if (j >= nregs)
303 return true;
304 }
305 return false;
306 }
307 }
308
309 /* Return true if REGNO satisfies a memory constraint. */
310 static bool
311 in_mem_p (int regno)
312 {
313 return get_reg_class (regno) == NO_REGS;
314 }
315
316 /* Return 1 if ADDR is a valid memory address for mode MODE in address
317 space AS, and check that each pseudo has the proper kind of hard
318 reg. */
319 static int
320 valid_address_p (machine_mode mode ATTRIBUTE_UNUSED,
321 rtx addr, addr_space_t as)
322 {
323 #ifdef GO_IF_LEGITIMATE_ADDRESS
324 lra_assert (ADDR_SPACE_GENERIC_P (as));
325 GO_IF_LEGITIMATE_ADDRESS (mode, addr, win);
326 return 0;
327
328 win:
329 return 1;
330 #else
331 return targetm.addr_space.legitimate_address_p (mode, addr, 0, as);
332 #endif
333 }
334
335 namespace {
336 /* Temporarily eliminates registers in an address (for the lifetime of
337 the object). */
338 class address_eliminator {
339 public:
340 address_eliminator (struct address_info *ad);
341 ~address_eliminator ();
342
343 private:
344 struct address_info *m_ad;
345 rtx *m_base_loc;
346 rtx m_base_reg;
347 rtx *m_index_loc;
348 rtx m_index_reg;
349 };
350 }
351
352 address_eliminator::address_eliminator (struct address_info *ad)
353 : m_ad (ad),
354 m_base_loc (strip_subreg (ad->base_term)),
355 m_base_reg (NULL_RTX),
356 m_index_loc (strip_subreg (ad->index_term)),
357 m_index_reg (NULL_RTX)
358 {
359 if (m_base_loc != NULL)
360 {
361 m_base_reg = *m_base_loc;
362 /* If we have non-legitimate address which is decomposed not in
363 the way we expected, don't do elimination here. In such case
364 the address will be reloaded and elimination will be done in
365 reload insn finally. */
366 if (REG_P (m_base_reg))
367 lra_eliminate_reg_if_possible (m_base_loc);
368 if (m_ad->base_term2 != NULL)
369 *m_ad->base_term2 = *m_ad->base_term;
370 }
371 if (m_index_loc != NULL)
372 {
373 m_index_reg = *m_index_loc;
374 if (REG_P (m_index_reg))
375 lra_eliminate_reg_if_possible (m_index_loc);
376 }
377 }
378
379 address_eliminator::~address_eliminator ()
380 {
381 if (m_base_loc && *m_base_loc != m_base_reg)
382 {
383 *m_base_loc = m_base_reg;
384 if (m_ad->base_term2 != NULL)
385 *m_ad->base_term2 = *m_ad->base_term;
386 }
387 if (m_index_loc && *m_index_loc != m_index_reg)
388 *m_index_loc = m_index_reg;
389 }
390
391 /* Return true if the eliminated form of AD is a legitimate target address.
392 If OP is a MEM, AD is the address within OP, otherwise OP should be
393 ignored. CONSTRAINT is one constraint that the operand may need
394 to meet. */
395 static bool
396 valid_address_p (rtx op, struct address_info *ad,
397 enum constraint_num constraint)
398 {
399 address_eliminator eliminator (ad);
400
401 /* Allow a memory OP if it matches CONSTRAINT, even if CONSTRAINT is more
402 forgiving than "m". */
403 if (MEM_P (op)
404 && (insn_extra_memory_constraint (constraint)
405 || insn_extra_special_memory_constraint (constraint))
406 && constraint_satisfied_p (op, constraint))
407 return true;
408
409 return valid_address_p (ad->mode, *ad->outer, ad->as);
410 }
411
412 /* Return true if the eliminated form of memory reference OP satisfies
413 extra (special) memory constraint CONSTRAINT. */
414 static bool
415 satisfies_memory_constraint_p (rtx op, enum constraint_num constraint)
416 {
417 struct address_info ad;
418
419 decompose_mem_address (&ad, op);
420 address_eliminator eliminator (&ad);
421 return constraint_satisfied_p (op, constraint);
422 }
423
424 /* Return true if the eliminated form of address AD satisfies extra
425 address constraint CONSTRAINT. */
426 static bool
427 satisfies_address_constraint_p (struct address_info *ad,
428 enum constraint_num constraint)
429 {
430 address_eliminator eliminator (ad);
431 return constraint_satisfied_p (*ad->outer, constraint);
432 }
433
434 /* Return true if the eliminated form of address OP satisfies extra
435 address constraint CONSTRAINT. */
436 static bool
437 satisfies_address_constraint_p (rtx op, enum constraint_num constraint)
438 {
439 struct address_info ad;
440
441 decompose_lea_address (&ad, &op);
442 return satisfies_address_constraint_p (&ad, constraint);
443 }
444
445 /* Initiate equivalences for LRA. As we keep original equivalences
446 before any elimination, we need to make copies otherwise any change
447 in insns might change the equivalences. */
448 void
449 lra_init_equiv (void)
450 {
451 ira_expand_reg_equiv ();
452 for (int i = FIRST_PSEUDO_REGISTER; i < max_reg_num (); i++)
453 {
454 rtx res;
455
456 if ((res = ira_reg_equiv[i].memory) != NULL_RTX)
457 ira_reg_equiv[i].memory = copy_rtx (res);
458 if ((res = ira_reg_equiv[i].invariant) != NULL_RTX)
459 ira_reg_equiv[i].invariant = copy_rtx (res);
460 }
461 }
462
463 static rtx loc_equivalence_callback (rtx, const_rtx, void *);
464
465 /* Update equivalence for REGNO. We need to this as the equivalence
466 might contain other pseudos which are changed by their
467 equivalences. */
468 static void
469 update_equiv (int regno)
470 {
471 rtx x;
472
473 if ((x = ira_reg_equiv[regno].memory) != NULL_RTX)
474 ira_reg_equiv[regno].memory
475 = simplify_replace_fn_rtx (x, NULL_RTX, loc_equivalence_callback,
476 NULL_RTX);
477 if ((x = ira_reg_equiv[regno].invariant) != NULL_RTX)
478 ira_reg_equiv[regno].invariant
479 = simplify_replace_fn_rtx (x, NULL_RTX, loc_equivalence_callback,
480 NULL_RTX);
481 }
482
483 /* If we have decided to substitute X with another value, return that
484 value, otherwise return X. */
485 static rtx
486 get_equiv (rtx x)
487 {
488 int regno;
489 rtx res;
490
491 if (! REG_P (x) || (regno = REGNO (x)) < FIRST_PSEUDO_REGISTER
492 || ! ira_reg_equiv[regno].defined_p
493 || ! ira_reg_equiv[regno].profitable_p
494 || lra_get_regno_hard_regno (regno) >= 0)
495 return x;
496 if ((res = ira_reg_equiv[regno].memory) != NULL_RTX)
497 {
498 if (targetm.cannot_substitute_mem_equiv_p (res))
499 return x;
500 return res;
501 }
502 if ((res = ira_reg_equiv[regno].constant) != NULL_RTX)
503 return res;
504 if ((res = ira_reg_equiv[regno].invariant) != NULL_RTX)
505 return res;
506 gcc_unreachable ();
507 }
508
509 /* If we have decided to substitute X with the equivalent value,
510 return that value after elimination for INSN, otherwise return
511 X. */
512 static rtx
513 get_equiv_with_elimination (rtx x, rtx_insn *insn)
514 {
515 rtx res = get_equiv (x);
516
517 if (x == res || CONSTANT_P (res))
518 return res;
519 return lra_eliminate_regs_1 (insn, res, GET_MODE (res),
520 false, false, 0, true);
521 }
522
523 /* Set up curr_operand_mode. */
524 static void
525 init_curr_operand_mode (void)
526 {
527 int nop = curr_static_id->n_operands;
528 for (int i = 0; i < nop; i++)
529 {
530 machine_mode mode = GET_MODE (*curr_id->operand_loc[i]);
531 if (mode == VOIDmode)
532 {
533 /* The .md mode for address operands is the mode of the
534 addressed value rather than the mode of the address itself. */
535 if (curr_id->icode >= 0 && curr_static_id->operand[i].is_address)
536 mode = Pmode;
537 else
538 mode = curr_static_id->operand[i].mode;
539 }
540 curr_operand_mode[i] = mode;
541 }
542 }
543
544 \f
545
546 /* The page contains code to reuse input reloads. */
547
548 /* Structure describes input reload of the current insns. */
549 struct input_reload
550 {
551 /* True for input reload of matched operands. */
552 bool match_p;
553 /* Reloaded value. */
554 rtx input;
555 /* Reload pseudo used. */
556 rtx reg;
557 };
558
559 /* The number of elements in the following array. */
560 static int curr_insn_input_reloads_num;
561 /* Array containing info about input reloads. It is used to find the
562 same input reload and reuse the reload pseudo in this case. */
563 static struct input_reload curr_insn_input_reloads[LRA_MAX_INSN_RELOADS];
564
565 /* Initiate data concerning reuse of input reloads for the current
566 insn. */
567 static void
568 init_curr_insn_input_reloads (void)
569 {
570 curr_insn_input_reloads_num = 0;
571 }
572
573 /* Create a new pseudo using MODE, RCLASS, ORIGINAL or reuse already
574 created input reload pseudo (only if TYPE is not OP_OUT). Don't
575 reuse pseudo if IN_SUBREG_P is true and the reused pseudo should be
576 wrapped up in SUBREG. The result pseudo is returned through
577 RESULT_REG. Return TRUE if we created a new pseudo, FALSE if we
578 reused the already created input reload pseudo. Use TITLE to
579 describe new registers for debug purposes. */
580 static bool
581 get_reload_reg (enum op_type type, machine_mode mode, rtx original,
582 enum reg_class rclass, bool in_subreg_p,
583 const char *title, rtx *result_reg)
584 {
585 int i, regno;
586 enum reg_class new_class;
587 bool unique_p = false;
588
589 if (type == OP_OUT)
590 {
591 *result_reg
592 = lra_create_new_reg_with_unique_value (mode, original, rclass, title);
593 return true;
594 }
595 /* Prevent reuse value of expression with side effects,
596 e.g. volatile memory. */
597 if (! side_effects_p (original))
598 for (i = 0; i < curr_insn_input_reloads_num; i++)
599 {
600 if (! curr_insn_input_reloads[i].match_p
601 && rtx_equal_p (curr_insn_input_reloads[i].input, original)
602 && in_class_p (curr_insn_input_reloads[i].reg, rclass, &new_class))
603 {
604 rtx reg = curr_insn_input_reloads[i].reg;
605 regno = REGNO (reg);
606 /* If input is equal to original and both are VOIDmode,
607 GET_MODE (reg) might be still different from mode.
608 Ensure we don't return *result_reg with wrong mode. */
609 if (GET_MODE (reg) != mode)
610 {
611 if (in_subreg_p)
612 continue;
613 if (maybe_lt (GET_MODE_SIZE (GET_MODE (reg)),
614 GET_MODE_SIZE (mode)))
615 continue;
616 reg = lowpart_subreg (mode, reg, GET_MODE (reg));
617 if (reg == NULL_RTX || GET_CODE (reg) != SUBREG)
618 continue;
619 }
620 *result_reg = reg;
621 if (lra_dump_file != NULL)
622 {
623 fprintf (lra_dump_file, " Reuse r%d for reload ", regno);
624 dump_value_slim (lra_dump_file, original, 1);
625 }
626 if (new_class != lra_get_allocno_class (regno))
627 lra_change_class (regno, new_class, ", change to", false);
628 if (lra_dump_file != NULL)
629 fprintf (lra_dump_file, "\n");
630 return false;
631 }
632 /* If we have an input reload with a different mode, make sure it
633 will get a different hard reg. */
634 else if (REG_P (original)
635 && REG_P (curr_insn_input_reloads[i].input)
636 && REGNO (original) == REGNO (curr_insn_input_reloads[i].input)
637 && (GET_MODE (original)
638 != GET_MODE (curr_insn_input_reloads[i].input)))
639 unique_p = true;
640 }
641 *result_reg = (unique_p
642 ? lra_create_new_reg_with_unique_value
643 : lra_create_new_reg) (mode, original, rclass, title);
644 lra_assert (curr_insn_input_reloads_num < LRA_MAX_INSN_RELOADS);
645 curr_insn_input_reloads[curr_insn_input_reloads_num].input = original;
646 curr_insn_input_reloads[curr_insn_input_reloads_num].match_p = false;
647 curr_insn_input_reloads[curr_insn_input_reloads_num++].reg = *result_reg;
648 return true;
649 }
650
651 \f
652 /* The page contains major code to choose the current insn alternative
653 and generate reloads for it. */
654
655 /* Return the offset from REGNO of the least significant register
656 in (reg:MODE REGNO).
657
658 This function is used to tell whether two registers satisfy
659 a matching constraint. (reg:MODE1 REGNO1) matches (reg:MODE2 REGNO2) if:
660
661 REGNO1 + lra_constraint_offset (REGNO1, MODE1)
662 == REGNO2 + lra_constraint_offset (REGNO2, MODE2) */
663 int
664 lra_constraint_offset (int regno, machine_mode mode)
665 {
666 lra_assert (regno < FIRST_PSEUDO_REGISTER);
667
668 scalar_int_mode int_mode;
669 if (WORDS_BIG_ENDIAN
670 && is_a <scalar_int_mode> (mode, &int_mode)
671 && GET_MODE_SIZE (int_mode) > UNITS_PER_WORD)
672 return hard_regno_nregs (regno, mode) - 1;
673 return 0;
674 }
675
676 /* Like rtx_equal_p except that it allows a REG and a SUBREG to match
677 if they are the same hard reg, and has special hacks for
678 auto-increment and auto-decrement. This is specifically intended for
679 process_alt_operands to use in determining whether two operands
680 match. X is the operand whose number is the lower of the two.
681
682 It is supposed that X is the output operand and Y is the input
683 operand. Y_HARD_REGNO is the final hard regno of register Y or
684 register in subreg Y as we know it now. Otherwise, it is a
685 negative value. */
686 static bool
687 operands_match_p (rtx x, rtx y, int y_hard_regno)
688 {
689 int i;
690 RTX_CODE code = GET_CODE (x);
691 const char *fmt;
692
693 if (x == y)
694 return true;
695 if ((code == REG || (code == SUBREG && REG_P (SUBREG_REG (x))))
696 && (REG_P (y) || (GET_CODE (y) == SUBREG && REG_P (SUBREG_REG (y)))))
697 {
698 int j;
699
700 i = get_hard_regno (x, false);
701 if (i < 0)
702 goto slow;
703
704 if ((j = y_hard_regno) < 0)
705 goto slow;
706
707 i += lra_constraint_offset (i, GET_MODE (x));
708 j += lra_constraint_offset (j, GET_MODE (y));
709
710 return i == j;
711 }
712
713 /* If two operands must match, because they are really a single
714 operand of an assembler insn, then two post-increments are invalid
715 because the assembler insn would increment only once. On the
716 other hand, a post-increment matches ordinary indexing if the
717 post-increment is the output operand. */
718 if (code == POST_DEC || code == POST_INC || code == POST_MODIFY)
719 return operands_match_p (XEXP (x, 0), y, y_hard_regno);
720
721 /* Two pre-increments are invalid because the assembler insn would
722 increment only once. On the other hand, a pre-increment matches
723 ordinary indexing if the pre-increment is the input operand. */
724 if (GET_CODE (y) == PRE_DEC || GET_CODE (y) == PRE_INC
725 || GET_CODE (y) == PRE_MODIFY)
726 return operands_match_p (x, XEXP (y, 0), -1);
727
728 slow:
729
730 if (code == REG && REG_P (y))
731 return REGNO (x) == REGNO (y);
732
733 if (code == REG && GET_CODE (y) == SUBREG && REG_P (SUBREG_REG (y))
734 && x == SUBREG_REG (y))
735 return true;
736 if (GET_CODE (y) == REG && code == SUBREG && REG_P (SUBREG_REG (x))
737 && SUBREG_REG (x) == y)
738 return true;
739
740 /* Now we have disposed of all the cases in which different rtx
741 codes can match. */
742 if (code != GET_CODE (y))
743 return false;
744
745 /* (MULT:SI x y) and (MULT:HI x y) are NOT equivalent. */
746 if (GET_MODE (x) != GET_MODE (y))
747 return false;
748
749 switch (code)
750 {
751 CASE_CONST_UNIQUE:
752 return false;
753
754 case LABEL_REF:
755 return label_ref_label (x) == label_ref_label (y);
756 case SYMBOL_REF:
757 return XSTR (x, 0) == XSTR (y, 0);
758
759 default:
760 break;
761 }
762
763 /* Compare the elements. If any pair of corresponding elements fail
764 to match, return false for the whole things. */
765
766 fmt = GET_RTX_FORMAT (code);
767 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
768 {
769 int val, j;
770 switch (fmt[i])
771 {
772 case 'w':
773 if (XWINT (x, i) != XWINT (y, i))
774 return false;
775 break;
776
777 case 'i':
778 if (XINT (x, i) != XINT (y, i))
779 return false;
780 break;
781
782 case 'p':
783 if (maybe_ne (SUBREG_BYTE (x), SUBREG_BYTE (y)))
784 return false;
785 break;
786
787 case 'e':
788 val = operands_match_p (XEXP (x, i), XEXP (y, i), -1);
789 if (val == 0)
790 return false;
791 break;
792
793 case '0':
794 break;
795
796 case 'E':
797 if (XVECLEN (x, i) != XVECLEN (y, i))
798 return false;
799 for (j = XVECLEN (x, i) - 1; j >= 0; --j)
800 {
801 val = operands_match_p (XVECEXP (x, i, j), XVECEXP (y, i, j), -1);
802 if (val == 0)
803 return false;
804 }
805 break;
806
807 /* It is believed that rtx's at this level will never
808 contain anything but integers and other rtx's, except for
809 within LABEL_REFs and SYMBOL_REFs. */
810 default:
811 gcc_unreachable ();
812 }
813 }
814 return true;
815 }
816
817 /* True if X is a constant that can be forced into the constant pool.
818 MODE is the mode of the operand, or VOIDmode if not known. */
819 #define CONST_POOL_OK_P(MODE, X) \
820 ((MODE) != VOIDmode \
821 && CONSTANT_P (X) \
822 && GET_CODE (X) != HIGH \
823 && GET_MODE_SIZE (MODE).is_constant () \
824 && !targetm.cannot_force_const_mem (MODE, X))
825
826 /* True if C is a non-empty register class that has too few registers
827 to be safely used as a reload target class. */
828 #define SMALL_REGISTER_CLASS_P(C) \
829 (ira_class_hard_regs_num [(C)] == 1 \
830 || (ira_class_hard_regs_num [(C)] >= 1 \
831 && targetm.class_likely_spilled_p (C)))
832
833 /* If REG is a reload pseudo, try to make its class satisfying CL. */
834 static void
835 narrow_reload_pseudo_class (rtx reg, enum reg_class cl)
836 {
837 enum reg_class rclass;
838
839 /* Do not make more accurate class from reloads generated. They are
840 mostly moves with a lot of constraints. Making more accurate
841 class may results in very narrow class and impossibility of find
842 registers for several reloads of one insn. */
843 if (INSN_UID (curr_insn) >= new_insn_uid_start)
844 return;
845 if (GET_CODE (reg) == SUBREG)
846 reg = SUBREG_REG (reg);
847 if (! REG_P (reg) || (int) REGNO (reg) < new_regno_start)
848 return;
849 if (in_class_p (reg, cl, &rclass) && rclass != cl)
850 lra_change_class (REGNO (reg), rclass, " Change to", true);
851 }
852
853 /* Searches X for any reference to a reg with the same value as REGNO,
854 returning the rtx of the reference found if any. Otherwise,
855 returns NULL_RTX. */
856 static rtx
857 regno_val_use_in (unsigned int regno, rtx x)
858 {
859 const char *fmt;
860 int i, j;
861 rtx tem;
862
863 if (REG_P (x) && lra_reg_info[REGNO (x)].val == lra_reg_info[regno].val)
864 return x;
865
866 fmt = GET_RTX_FORMAT (GET_CODE (x));
867 for (i = GET_RTX_LENGTH (GET_CODE (x)) - 1; i >= 0; i--)
868 {
869 if (fmt[i] == 'e')
870 {
871 if ((tem = regno_val_use_in (regno, XEXP (x, i))))
872 return tem;
873 }
874 else if (fmt[i] == 'E')
875 for (j = XVECLEN (x, i) - 1; j >= 0; j--)
876 if ((tem = regno_val_use_in (regno , XVECEXP (x, i, j))))
877 return tem;
878 }
879
880 return NULL_RTX;
881 }
882
883 /* Return true if all current insn non-output operands except INS (it
884 has a negaitve end marker) do not use pseudos with the same value
885 as REGNO. */
886 static bool
887 check_conflict_input_operands (int regno, signed char *ins)
888 {
889 int in;
890 int n_operands = curr_static_id->n_operands;
891
892 for (int nop = 0; nop < n_operands; nop++)
893 if (! curr_static_id->operand[nop].is_operator
894 && curr_static_id->operand[nop].type != OP_OUT)
895 {
896 for (int i = 0; (in = ins[i]) >= 0; i++)
897 if (in == nop)
898 break;
899 if (in < 0
900 && regno_val_use_in (regno, *curr_id->operand_loc[nop]) != NULL_RTX)
901 return false;
902 }
903 return true;
904 }
905
906 /* Generate reloads for matching OUT and INS (array of input operand
907 numbers with end marker -1) with reg class GOAL_CLASS, considering
908 output operands OUTS (similar array to INS) needing to be in different
909 registers. Add input and output reloads correspondingly to the lists
910 *BEFORE and *AFTER. OUT might be negative. In this case we generate
911 input reloads for matched input operands INS. EARLY_CLOBBER_P is a flag
912 that the output operand is early clobbered for chosen alternative. */
913 static void
914 match_reload (signed char out, signed char *ins, signed char *outs,
915 enum reg_class goal_class, rtx_insn **before,
916 rtx_insn **after, bool early_clobber_p)
917 {
918 bool out_conflict;
919 int i, in;
920 rtx new_in_reg, new_out_reg, reg;
921 machine_mode inmode, outmode;
922 rtx in_rtx = *curr_id->operand_loc[ins[0]];
923 rtx out_rtx = out < 0 ? in_rtx : *curr_id->operand_loc[out];
924
925 inmode = curr_operand_mode[ins[0]];
926 outmode = out < 0 ? inmode : curr_operand_mode[out];
927 push_to_sequence (*before);
928 if (inmode != outmode)
929 {
930 /* process_alt_operands has already checked that the mode sizes
931 are ordered. */
932 if (partial_subreg_p (outmode, inmode))
933 {
934 reg = new_in_reg
935 = lra_create_new_reg_with_unique_value (inmode, in_rtx,
936 goal_class, "");
937 new_out_reg = gen_lowpart_SUBREG (outmode, reg);
938 LRA_SUBREG_P (new_out_reg) = 1;
939 /* If the input reg is dying here, we can use the same hard
940 register for REG and IN_RTX. We do it only for original
941 pseudos as reload pseudos can die although original
942 pseudos still live where reload pseudos dies. */
943 if (REG_P (in_rtx) && (int) REGNO (in_rtx) < lra_new_regno_start
944 && find_regno_note (curr_insn, REG_DEAD, REGNO (in_rtx))
945 && (!early_clobber_p
946 || check_conflict_input_operands(REGNO (in_rtx), ins)))
947 lra_assign_reg_val (REGNO (in_rtx), REGNO (reg));
948 }
949 else
950 {
951 reg = new_out_reg
952 = lra_create_new_reg_with_unique_value (outmode, out_rtx,
953 goal_class, "");
954 new_in_reg = gen_lowpart_SUBREG (inmode, reg);
955 /* NEW_IN_REG is non-paradoxical subreg. We don't want
956 NEW_OUT_REG living above. We add clobber clause for
957 this. This is just a temporary clobber. We can remove
958 it at the end of LRA work. */
959 rtx_insn *clobber = emit_clobber (new_out_reg);
960 LRA_TEMP_CLOBBER_P (PATTERN (clobber)) = 1;
961 LRA_SUBREG_P (new_in_reg) = 1;
962 if (GET_CODE (in_rtx) == SUBREG)
963 {
964 rtx subreg_reg = SUBREG_REG (in_rtx);
965
966 /* If SUBREG_REG is dying here and sub-registers IN_RTX
967 and NEW_IN_REG are similar, we can use the same hard
968 register for REG and SUBREG_REG. */
969 if (REG_P (subreg_reg)
970 && (int) REGNO (subreg_reg) < lra_new_regno_start
971 && GET_MODE (subreg_reg) == outmode
972 && known_eq (SUBREG_BYTE (in_rtx), SUBREG_BYTE (new_in_reg))
973 && find_regno_note (curr_insn, REG_DEAD, REGNO (subreg_reg))
974 && (! early_clobber_p
975 || check_conflict_input_operands (REGNO (subreg_reg),
976 ins)))
977 lra_assign_reg_val (REGNO (subreg_reg), REGNO (reg));
978 }
979 }
980 }
981 else
982 {
983 /* Pseudos have values -- see comments for lra_reg_info.
984 Different pseudos with the same value do not conflict even if
985 they live in the same place. When we create a pseudo we
986 assign value of original pseudo (if any) from which we
987 created the new pseudo. If we create the pseudo from the
988 input pseudo, the new pseudo will have no conflict with the
989 input pseudo which is wrong when the input pseudo lives after
990 the insn and as the new pseudo value is changed by the insn
991 output. Therefore we create the new pseudo from the output
992 except the case when we have single matched dying input
993 pseudo.
994
995 We cannot reuse the current output register because we might
996 have a situation like "a <- a op b", where the constraints
997 force the second input operand ("b") to match the output
998 operand ("a"). "b" must then be copied into a new register
999 so that it doesn't clobber the current value of "a".
1000
1001 We cannot use the same value if the output pseudo is
1002 early clobbered or the input pseudo is mentioned in the
1003 output, e.g. as an address part in memory, because
1004 output reload will actually extend the pseudo liveness.
1005 We don't care about eliminable hard regs here as we are
1006 interesting only in pseudos. */
1007
1008 /* Matching input's register value is the same as one of the other
1009 output operand. Output operands in a parallel insn must be in
1010 different registers. */
1011 out_conflict = false;
1012 if (REG_P (in_rtx))
1013 {
1014 for (i = 0; outs[i] >= 0; i++)
1015 {
1016 rtx other_out_rtx = *curr_id->operand_loc[outs[i]];
1017 if (REG_P (other_out_rtx)
1018 && (regno_val_use_in (REGNO (in_rtx), other_out_rtx)
1019 != NULL_RTX))
1020 {
1021 out_conflict = true;
1022 break;
1023 }
1024 }
1025 }
1026
1027 new_in_reg = new_out_reg
1028 = (! early_clobber_p && ins[1] < 0 && REG_P (in_rtx)
1029 && (int) REGNO (in_rtx) < lra_new_regno_start
1030 && find_regno_note (curr_insn, REG_DEAD, REGNO (in_rtx))
1031 && (! early_clobber_p
1032 || check_conflict_input_operands (REGNO (in_rtx), ins))
1033 && (out < 0
1034 || regno_val_use_in (REGNO (in_rtx), out_rtx) == NULL_RTX)
1035 && !out_conflict
1036 ? lra_create_new_reg (inmode, in_rtx, goal_class, "")
1037 : lra_create_new_reg_with_unique_value (outmode, out_rtx,
1038 goal_class, ""));
1039 }
1040 /* In operand can be got from transformations before processing insn
1041 constraints. One example of such transformations is subreg
1042 reloading (see function simplify_operand_subreg). The new
1043 pseudos created by the transformations might have inaccurate
1044 class (ALL_REGS) and we should make their classes more
1045 accurate. */
1046 narrow_reload_pseudo_class (in_rtx, goal_class);
1047 lra_emit_move (copy_rtx (new_in_reg), in_rtx);
1048 *before = get_insns ();
1049 end_sequence ();
1050 /* Add the new pseudo to consider values of subsequent input reload
1051 pseudos. */
1052 lra_assert (curr_insn_input_reloads_num < LRA_MAX_INSN_RELOADS);
1053 curr_insn_input_reloads[curr_insn_input_reloads_num].input = in_rtx;
1054 curr_insn_input_reloads[curr_insn_input_reloads_num].match_p = true;
1055 curr_insn_input_reloads[curr_insn_input_reloads_num++].reg = new_in_reg;
1056 for (i = 0; (in = ins[i]) >= 0; i++)
1057 if (GET_MODE (*curr_id->operand_loc[in]) == VOIDmode
1058 || GET_MODE (new_in_reg) == GET_MODE (*curr_id->operand_loc[in]))
1059 *curr_id->operand_loc[in] = new_in_reg;
1060 else
1061 {
1062 lra_assert
1063 (GET_MODE (new_out_reg) == GET_MODE (*curr_id->operand_loc[in]));
1064 *curr_id->operand_loc[in] = new_out_reg;
1065 }
1066 lra_update_dups (curr_id, ins);
1067 if (out < 0)
1068 return;
1069 /* See a comment for the input operand above. */
1070 narrow_reload_pseudo_class (out_rtx, goal_class);
1071 if (find_reg_note (curr_insn, REG_UNUSED, out_rtx) == NULL_RTX)
1072 {
1073 start_sequence ();
1074 lra_emit_move (out_rtx, copy_rtx (new_out_reg));
1075 emit_insn (*after);
1076 *after = get_insns ();
1077 end_sequence ();
1078 }
1079 *curr_id->operand_loc[out] = new_out_reg;
1080 lra_update_dup (curr_id, out);
1081 }
1082
1083 /* Return register class which is union of all reg classes in insn
1084 constraint alternative string starting with P. */
1085 static enum reg_class
1086 reg_class_from_constraints (const char *p)
1087 {
1088 int c, len;
1089 enum reg_class op_class = NO_REGS;
1090
1091 do
1092 switch ((c = *p, len = CONSTRAINT_LEN (c, p)), c)
1093 {
1094 case '#':
1095 case ',':
1096 return op_class;
1097
1098 case 'g':
1099 op_class = reg_class_subunion[op_class][GENERAL_REGS];
1100 break;
1101
1102 default:
1103 enum constraint_num cn = lookup_constraint (p);
1104 enum reg_class cl = reg_class_for_constraint (cn);
1105 if (cl == NO_REGS)
1106 {
1107 if (insn_extra_address_constraint (cn))
1108 op_class
1109 = (reg_class_subunion
1110 [op_class][base_reg_class (VOIDmode, ADDR_SPACE_GENERIC,
1111 ADDRESS, SCRATCH)]);
1112 break;
1113 }
1114
1115 op_class = reg_class_subunion[op_class][cl];
1116 break;
1117 }
1118 while ((p += len), c);
1119 return op_class;
1120 }
1121
1122 /* If OP is a register, return the class of the register as per
1123 get_reg_class, otherwise return NO_REGS. */
1124 static inline enum reg_class
1125 get_op_class (rtx op)
1126 {
1127 return REG_P (op) ? get_reg_class (REGNO (op)) : NO_REGS;
1128 }
1129
1130 /* Return generated insn mem_pseudo:=val if TO_P or val:=mem_pseudo
1131 otherwise. If modes of MEM_PSEUDO and VAL are different, use
1132 SUBREG for VAL to make them equal. */
1133 static rtx_insn *
1134 emit_spill_move (bool to_p, rtx mem_pseudo, rtx val)
1135 {
1136 if (GET_MODE (mem_pseudo) != GET_MODE (val))
1137 {
1138 /* Usually size of mem_pseudo is greater than val size but in
1139 rare cases it can be less as it can be defined by target
1140 dependent macro HARD_REGNO_CALLER_SAVE_MODE. */
1141 if (! MEM_P (val))
1142 {
1143 val = gen_lowpart_SUBREG (GET_MODE (mem_pseudo),
1144 GET_CODE (val) == SUBREG
1145 ? SUBREG_REG (val) : val);
1146 LRA_SUBREG_P (val) = 1;
1147 }
1148 else
1149 {
1150 mem_pseudo = gen_lowpart_SUBREG (GET_MODE (val), mem_pseudo);
1151 LRA_SUBREG_P (mem_pseudo) = 1;
1152 }
1153 }
1154 return to_p ? gen_move_insn (mem_pseudo, val)
1155 : gen_move_insn (val, mem_pseudo);
1156 }
1157
1158 /* Process a special case insn (register move), return true if we
1159 don't need to process it anymore. INSN should be a single set
1160 insn. Set up that RTL was changed through CHANGE_P and that hook
1161 TARGET_SECONDARY_MEMORY_NEEDED says to use secondary memory through
1162 SEC_MEM_P. */
1163 static bool
1164 check_and_process_move (bool *change_p, bool *sec_mem_p ATTRIBUTE_UNUSED)
1165 {
1166 int sregno, dregno;
1167 rtx dest, src, dreg, sreg, new_reg, scratch_reg;
1168 rtx_insn *before;
1169 enum reg_class dclass, sclass, secondary_class;
1170 secondary_reload_info sri;
1171
1172 lra_assert (curr_insn_set != NULL_RTX);
1173 dreg = dest = SET_DEST (curr_insn_set);
1174 sreg = src = SET_SRC (curr_insn_set);
1175 if (GET_CODE (dest) == SUBREG)
1176 dreg = SUBREG_REG (dest);
1177 if (GET_CODE (src) == SUBREG)
1178 sreg = SUBREG_REG (src);
1179 if (! (REG_P (dreg) || MEM_P (dreg)) || ! (REG_P (sreg) || MEM_P (sreg)))
1180 return false;
1181 sclass = dclass = NO_REGS;
1182 if (REG_P (dreg))
1183 dclass = get_reg_class (REGNO (dreg));
1184 gcc_assert (dclass < LIM_REG_CLASSES);
1185 if (dclass == ALL_REGS)
1186 /* ALL_REGS is used for new pseudos created by transformations
1187 like reload of SUBREG_REG (see function
1188 simplify_operand_subreg). We don't know their class yet. We
1189 should figure out the class from processing the insn
1190 constraints not in this fast path function. Even if ALL_REGS
1191 were a right class for the pseudo, secondary_... hooks usually
1192 are not define for ALL_REGS. */
1193 return false;
1194 if (REG_P (sreg))
1195 sclass = get_reg_class (REGNO (sreg));
1196 gcc_assert (sclass < LIM_REG_CLASSES);
1197 if (sclass == ALL_REGS)
1198 /* See comments above. */
1199 return false;
1200 if (sclass == NO_REGS && dclass == NO_REGS)
1201 return false;
1202 if (targetm.secondary_memory_needed (GET_MODE (src), sclass, dclass)
1203 && ((sclass != NO_REGS && dclass != NO_REGS)
1204 || (GET_MODE (src)
1205 != targetm.secondary_memory_needed_mode (GET_MODE (src)))))
1206 {
1207 *sec_mem_p = true;
1208 return false;
1209 }
1210 if (! REG_P (dreg) || ! REG_P (sreg))
1211 return false;
1212 sri.prev_sri = NULL;
1213 sri.icode = CODE_FOR_nothing;
1214 sri.extra_cost = 0;
1215 secondary_class = NO_REGS;
1216 /* Set up hard register for a reload pseudo for hook
1217 secondary_reload because some targets just ignore unassigned
1218 pseudos in the hook. */
1219 if (dclass != NO_REGS && lra_get_regno_hard_regno (REGNO (dreg)) < 0)
1220 {
1221 dregno = REGNO (dreg);
1222 reg_renumber[dregno] = ira_class_hard_regs[dclass][0];
1223 }
1224 else
1225 dregno = -1;
1226 if (sclass != NO_REGS && lra_get_regno_hard_regno (REGNO (sreg)) < 0)
1227 {
1228 sregno = REGNO (sreg);
1229 reg_renumber[sregno] = ira_class_hard_regs[sclass][0];
1230 }
1231 else
1232 sregno = -1;
1233 if (sclass != NO_REGS)
1234 secondary_class
1235 = (enum reg_class) targetm.secondary_reload (false, dest,
1236 (reg_class_t) sclass,
1237 GET_MODE (src), &sri);
1238 if (sclass == NO_REGS
1239 || ((secondary_class != NO_REGS || sri.icode != CODE_FOR_nothing)
1240 && dclass != NO_REGS))
1241 {
1242 enum reg_class old_sclass = secondary_class;
1243 secondary_reload_info old_sri = sri;
1244
1245 sri.prev_sri = NULL;
1246 sri.icode = CODE_FOR_nothing;
1247 sri.extra_cost = 0;
1248 secondary_class
1249 = (enum reg_class) targetm.secondary_reload (true, src,
1250 (reg_class_t) dclass,
1251 GET_MODE (src), &sri);
1252 /* Check the target hook consistency. */
1253 lra_assert
1254 ((secondary_class == NO_REGS && sri.icode == CODE_FOR_nothing)
1255 || (old_sclass == NO_REGS && old_sri.icode == CODE_FOR_nothing)
1256 || (secondary_class == old_sclass && sri.icode == old_sri.icode));
1257 }
1258 if (sregno >= 0)
1259 reg_renumber [sregno] = -1;
1260 if (dregno >= 0)
1261 reg_renumber [dregno] = -1;
1262 if (secondary_class == NO_REGS && sri.icode == CODE_FOR_nothing)
1263 return false;
1264 *change_p = true;
1265 new_reg = NULL_RTX;
1266 if (secondary_class != NO_REGS)
1267 new_reg = lra_create_new_reg_with_unique_value (GET_MODE (src), NULL_RTX,
1268 secondary_class,
1269 "secondary");
1270 start_sequence ();
1271 if (sri.icode == CODE_FOR_nothing)
1272 lra_emit_move (new_reg, src);
1273 else
1274 {
1275 enum reg_class scratch_class;
1276
1277 scratch_class = (reg_class_from_constraints
1278 (insn_data[sri.icode].operand[2].constraint));
1279 scratch_reg = (lra_create_new_reg_with_unique_value
1280 (insn_data[sri.icode].operand[2].mode, NULL_RTX,
1281 scratch_class, "scratch"));
1282 emit_insn (GEN_FCN (sri.icode) (new_reg != NULL_RTX ? new_reg : dest,
1283 src, scratch_reg));
1284 }
1285 before = get_insns ();
1286 end_sequence ();
1287 lra_process_new_insns (curr_insn, before, NULL, "Inserting the move");
1288 if (new_reg != NULL_RTX)
1289 SET_SRC (curr_insn_set) = new_reg;
1290 else
1291 {
1292 if (lra_dump_file != NULL)
1293 {
1294 fprintf (lra_dump_file, "Deleting move %u\n", INSN_UID (curr_insn));
1295 dump_insn_slim (lra_dump_file, curr_insn);
1296 }
1297 lra_set_insn_deleted (curr_insn);
1298 return true;
1299 }
1300 return false;
1301 }
1302
1303 /* The following data describe the result of process_alt_operands.
1304 The data are used in curr_insn_transform to generate reloads. */
1305
1306 /* The chosen reg classes which should be used for the corresponding
1307 operands. */
1308 static enum reg_class goal_alt[MAX_RECOG_OPERANDS];
1309 /* True if the operand should be the same as another operand and that
1310 other operand does not need a reload. */
1311 static bool goal_alt_match_win[MAX_RECOG_OPERANDS];
1312 /* True if the operand does not need a reload. */
1313 static bool goal_alt_win[MAX_RECOG_OPERANDS];
1314 /* True if the operand can be offsetable memory. */
1315 static bool goal_alt_offmemok[MAX_RECOG_OPERANDS];
1316 /* The number of an operand to which given operand can be matched to. */
1317 static int goal_alt_matches[MAX_RECOG_OPERANDS];
1318 /* The number of elements in the following array. */
1319 static int goal_alt_dont_inherit_ops_num;
1320 /* Numbers of operands whose reload pseudos should not be inherited. */
1321 static int goal_alt_dont_inherit_ops[MAX_RECOG_OPERANDS];
1322 /* True if the insn commutative operands should be swapped. */
1323 static bool goal_alt_swapped;
1324 /* The chosen insn alternative. */
1325 static int goal_alt_number;
1326
1327 /* True if the corresponding operand is the result of an equivalence
1328 substitution. */
1329 static bool equiv_substition_p[MAX_RECOG_OPERANDS];
1330
1331 /* The following five variables are used to choose the best insn
1332 alternative. They reflect final characteristics of the best
1333 alternative. */
1334
1335 /* Number of necessary reloads and overall cost reflecting the
1336 previous value and other unpleasantness of the best alternative. */
1337 static int best_losers, best_overall;
1338 /* Overall number hard registers used for reloads. For example, on
1339 some targets we need 2 general registers to reload DFmode and only
1340 one floating point register. */
1341 static int best_reload_nregs;
1342 /* Overall number reflecting distances of previous reloading the same
1343 value. The distances are counted from the current BB start. It is
1344 used to improve inheritance chances. */
1345 static int best_reload_sum;
1346
1347 /* True if the current insn should have no correspondingly input or
1348 output reloads. */
1349 static bool no_input_reloads_p, no_output_reloads_p;
1350
1351 /* True if we swapped the commutative operands in the current
1352 insn. */
1353 static int curr_swapped;
1354
1355 /* if CHECK_ONLY_P is false, arrange for address element *LOC to be a
1356 register of class CL. Add any input reloads to list BEFORE. AFTER
1357 is nonnull if *LOC is an automodified value; handle that case by
1358 adding the required output reloads to list AFTER. Return true if
1359 the RTL was changed.
1360
1361 if CHECK_ONLY_P is true, check that the *LOC is a correct address
1362 register. Return false if the address register is correct. */
1363 static bool
1364 process_addr_reg (rtx *loc, bool check_only_p, rtx_insn **before, rtx_insn **after,
1365 enum reg_class cl)
1366 {
1367 int regno;
1368 enum reg_class rclass, new_class;
1369 rtx reg;
1370 rtx new_reg;
1371 machine_mode mode;
1372 bool subreg_p, before_p = false;
1373
1374 subreg_p = GET_CODE (*loc) == SUBREG;
1375 if (subreg_p)
1376 {
1377 reg = SUBREG_REG (*loc);
1378 mode = GET_MODE (reg);
1379
1380 /* For mode with size bigger than ptr_mode, there unlikely to be "mov"
1381 between two registers with different classes, but there normally will
1382 be "mov" which transfers element of vector register into the general
1383 register, and this normally will be a subreg which should be reloaded
1384 as a whole. This is particularly likely to be triggered when
1385 -fno-split-wide-types specified. */
1386 if (!REG_P (reg)
1387 || in_class_p (reg, cl, &new_class)
1388 || known_le (GET_MODE_SIZE (mode), GET_MODE_SIZE (ptr_mode)))
1389 loc = &SUBREG_REG (*loc);
1390 }
1391
1392 reg = *loc;
1393 mode = GET_MODE (reg);
1394 if (! REG_P (reg))
1395 {
1396 if (check_only_p)
1397 return true;
1398 /* Always reload memory in an address even if the target supports
1399 such addresses. */
1400 new_reg = lra_create_new_reg_with_unique_value (mode, reg, cl, "address");
1401 before_p = true;
1402 }
1403 else
1404 {
1405 regno = REGNO (reg);
1406 rclass = get_reg_class (regno);
1407 if (! check_only_p
1408 && (*loc = get_equiv_with_elimination (reg, curr_insn)) != reg)
1409 {
1410 if (lra_dump_file != NULL)
1411 {
1412 fprintf (lra_dump_file,
1413 "Changing pseudo %d in address of insn %u on equiv ",
1414 REGNO (reg), INSN_UID (curr_insn));
1415 dump_value_slim (lra_dump_file, *loc, 1);
1416 fprintf (lra_dump_file, "\n");
1417 }
1418 *loc = copy_rtx (*loc);
1419 }
1420 if (*loc != reg || ! in_class_p (reg, cl, &new_class))
1421 {
1422 if (check_only_p)
1423 return true;
1424 reg = *loc;
1425 if (get_reload_reg (after == NULL ? OP_IN : OP_INOUT,
1426 mode, reg, cl, subreg_p, "address", &new_reg))
1427 before_p = true;
1428 }
1429 else if (new_class != NO_REGS && rclass != new_class)
1430 {
1431 if (check_only_p)
1432 return true;
1433 lra_change_class (regno, new_class, " Change to", true);
1434 return false;
1435 }
1436 else
1437 return false;
1438 }
1439 if (before_p)
1440 {
1441 push_to_sequence (*before);
1442 lra_emit_move (new_reg, reg);
1443 *before = get_insns ();
1444 end_sequence ();
1445 }
1446 *loc = new_reg;
1447 if (after != NULL)
1448 {
1449 start_sequence ();
1450 lra_emit_move (before_p ? copy_rtx (reg) : reg, new_reg);
1451 emit_insn (*after);
1452 *after = get_insns ();
1453 end_sequence ();
1454 }
1455 return true;
1456 }
1457
1458 /* Insert move insn in simplify_operand_subreg. BEFORE returns
1459 the insn to be inserted before curr insn. AFTER returns the
1460 the insn to be inserted after curr insn. ORIGREG and NEWREG
1461 are the original reg and new reg for reload. */
1462 static void
1463 insert_move_for_subreg (rtx_insn **before, rtx_insn **after, rtx origreg,
1464 rtx newreg)
1465 {
1466 if (before)
1467 {
1468 push_to_sequence (*before);
1469 lra_emit_move (newreg, origreg);
1470 *before = get_insns ();
1471 end_sequence ();
1472 }
1473 if (after)
1474 {
1475 start_sequence ();
1476 lra_emit_move (origreg, newreg);
1477 emit_insn (*after);
1478 *after = get_insns ();
1479 end_sequence ();
1480 }
1481 }
1482
1483 static int valid_address_p (machine_mode mode, rtx addr, addr_space_t as);
1484 static bool process_address (int, bool, rtx_insn **, rtx_insn **);
1485
1486 /* Make reloads for subreg in operand NOP with internal subreg mode
1487 REG_MODE, add new reloads for further processing. Return true if
1488 any change was done. */
1489 static bool
1490 simplify_operand_subreg (int nop, machine_mode reg_mode)
1491 {
1492 int hard_regno, inner_hard_regno;
1493 rtx_insn *before, *after;
1494 machine_mode mode, innermode;
1495 rtx reg, new_reg;
1496 rtx operand = *curr_id->operand_loc[nop];
1497 enum reg_class regclass;
1498 enum op_type type;
1499
1500 before = after = NULL;
1501
1502 if (GET_CODE (operand) != SUBREG)
1503 return false;
1504
1505 mode = GET_MODE (operand);
1506 reg = SUBREG_REG (operand);
1507 innermode = GET_MODE (reg);
1508 type = curr_static_id->operand[nop].type;
1509 if (MEM_P (reg))
1510 {
1511 const bool addr_was_valid
1512 = valid_address_p (innermode, XEXP (reg, 0), MEM_ADDR_SPACE (reg));
1513 alter_subreg (curr_id->operand_loc[nop], false);
1514 rtx subst = *curr_id->operand_loc[nop];
1515 lra_assert (MEM_P (subst));
1516 const bool addr_is_valid = valid_address_p (GET_MODE (subst),
1517 XEXP (subst, 0),
1518 MEM_ADDR_SPACE (subst));
1519 if (!addr_was_valid
1520 || addr_is_valid
1521 || ((get_constraint_type (lookup_constraint
1522 (curr_static_id->operand[nop].constraint))
1523 != CT_SPECIAL_MEMORY)
1524 /* We still can reload address and if the address is
1525 valid, we can remove subreg without reloading its
1526 inner memory. */
1527 && valid_address_p (GET_MODE (subst),
1528 regno_reg_rtx
1529 [ira_class_hard_regs
1530 [base_reg_class (GET_MODE (subst),
1531 MEM_ADDR_SPACE (subst),
1532 ADDRESS, SCRATCH)][0]],
1533 MEM_ADDR_SPACE (subst))))
1534 {
1535 /* If we change the address for a paradoxical subreg of memory, the
1536 new address might violate the necessary alignment or the access
1537 might be slow; take this into consideration. We need not worry
1538 about accesses beyond allocated memory for paradoxical memory
1539 subregs as we don't substitute such equiv memory (see processing
1540 equivalences in function lra_constraints) and because for spilled
1541 pseudos we allocate stack memory enough for the biggest
1542 corresponding paradoxical subreg.
1543
1544 However, do not blindly simplify a (subreg (mem ...)) for
1545 WORD_REGISTER_OPERATIONS targets as this may lead to loading junk
1546 data into a register when the inner is narrower than outer or
1547 missing important data from memory when the inner is wider than
1548 outer. This rule only applies to modes that are no wider than
1549 a word.
1550
1551 If valid memory becomes invalid after subreg elimination
1552 and address might be different we still have to reload
1553 memory.
1554 */
1555 if ((! addr_was_valid
1556 || addr_is_valid
1557 || known_eq (GET_MODE_SIZE (mode), GET_MODE_SIZE (innermode)))
1558 && !(maybe_ne (GET_MODE_PRECISION (mode),
1559 GET_MODE_PRECISION (innermode))
1560 && known_le (GET_MODE_SIZE (mode), UNITS_PER_WORD)
1561 && known_le (GET_MODE_SIZE (innermode), UNITS_PER_WORD)
1562 && WORD_REGISTER_OPERATIONS)
1563 && (!(MEM_ALIGN (subst) < GET_MODE_ALIGNMENT (mode)
1564 && targetm.slow_unaligned_access (mode, MEM_ALIGN (subst)))
1565 || (MEM_ALIGN (reg) < GET_MODE_ALIGNMENT (innermode)
1566 && targetm.slow_unaligned_access (innermode,
1567 MEM_ALIGN (reg)))))
1568 return true;
1569
1570 *curr_id->operand_loc[nop] = operand;
1571
1572 /* But if the address was not valid, we cannot reload the MEM without
1573 reloading the address first. */
1574 if (!addr_was_valid)
1575 process_address (nop, false, &before, &after);
1576
1577 /* INNERMODE is fast, MODE slow. Reload the mem in INNERMODE. */
1578 enum reg_class rclass
1579 = (enum reg_class) targetm.preferred_reload_class (reg, ALL_REGS);
1580 if (get_reload_reg (curr_static_id->operand[nop].type, innermode,
1581 reg, rclass, TRUE, "slow/invalid mem", &new_reg))
1582 {
1583 bool insert_before, insert_after;
1584 bitmap_set_bit (&lra_subreg_reload_pseudos, REGNO (new_reg));
1585
1586 insert_before = (type != OP_OUT
1587 || partial_subreg_p (mode, innermode));
1588 insert_after = type != OP_IN;
1589 insert_move_for_subreg (insert_before ? &before : NULL,
1590 insert_after ? &after : NULL,
1591 reg, new_reg);
1592 }
1593 SUBREG_REG (operand) = new_reg;
1594
1595 /* Convert to MODE. */
1596 reg = operand;
1597 rclass
1598 = (enum reg_class) targetm.preferred_reload_class (reg, ALL_REGS);
1599 if (get_reload_reg (curr_static_id->operand[nop].type, mode, reg,
1600 rclass, TRUE, "slow/invalid mem", &new_reg))
1601 {
1602 bool insert_before, insert_after;
1603 bitmap_set_bit (&lra_subreg_reload_pseudos, REGNO (new_reg));
1604
1605 insert_before = type != OP_OUT;
1606 insert_after = type != OP_IN;
1607 insert_move_for_subreg (insert_before ? &before : NULL,
1608 insert_after ? &after : NULL,
1609 reg, new_reg);
1610 }
1611 *curr_id->operand_loc[nop] = new_reg;
1612 lra_process_new_insns (curr_insn, before, after,
1613 "Inserting slow/invalid mem reload");
1614 return true;
1615 }
1616
1617 /* If the address was valid and became invalid, prefer to reload
1618 the memory. Typical case is when the index scale should
1619 correspond the memory. */
1620 *curr_id->operand_loc[nop] = operand;
1621 /* Do not return false here as the MEM_P (reg) will be processed
1622 later in this function. */
1623 }
1624 else if (REG_P (reg) && REGNO (reg) < FIRST_PSEUDO_REGISTER)
1625 {
1626 alter_subreg (curr_id->operand_loc[nop], false);
1627 return true;
1628 }
1629 else if (CONSTANT_P (reg))
1630 {
1631 /* Try to simplify subreg of constant. It is usually result of
1632 equivalence substitution. */
1633 if (innermode == VOIDmode
1634 && (innermode = original_subreg_reg_mode[nop]) == VOIDmode)
1635 innermode = curr_static_id->operand[nop].mode;
1636 if ((new_reg = simplify_subreg (mode, reg, innermode,
1637 SUBREG_BYTE (operand))) != NULL_RTX)
1638 {
1639 *curr_id->operand_loc[nop] = new_reg;
1640 return true;
1641 }
1642 }
1643 /* Put constant into memory when we have mixed modes. It generates
1644 a better code in most cases as it does not need a secondary
1645 reload memory. It also prevents LRA looping when LRA is using
1646 secondary reload memory again and again. */
1647 if (CONSTANT_P (reg) && CONST_POOL_OK_P (reg_mode, reg)
1648 && SCALAR_INT_MODE_P (reg_mode) != SCALAR_INT_MODE_P (mode))
1649 {
1650 SUBREG_REG (operand) = force_const_mem (reg_mode, reg);
1651 alter_subreg (curr_id->operand_loc[nop], false);
1652 return true;
1653 }
1654 /* Force a reload of the SUBREG_REG if this is a constant or PLUS or
1655 if there may be a problem accessing OPERAND in the outer
1656 mode. */
1657 if ((REG_P (reg)
1658 && REGNO (reg) >= FIRST_PSEUDO_REGISTER
1659 && (hard_regno = lra_get_regno_hard_regno (REGNO (reg))) >= 0
1660 /* Don't reload paradoxical subregs because we could be looping
1661 having repeatedly final regno out of hard regs range. */
1662 && (hard_regno_nregs (hard_regno, innermode)
1663 >= hard_regno_nregs (hard_regno, mode))
1664 && simplify_subreg_regno (hard_regno, innermode,
1665 SUBREG_BYTE (operand), mode) < 0
1666 /* Don't reload subreg for matching reload. It is actually
1667 valid subreg in LRA. */
1668 && ! LRA_SUBREG_P (operand))
1669 || CONSTANT_P (reg) || GET_CODE (reg) == PLUS || MEM_P (reg))
1670 {
1671 enum reg_class rclass;
1672
1673 if (REG_P (reg))
1674 /* There is a big probability that we will get the same class
1675 for the new pseudo and we will get the same insn which
1676 means infinite looping. So spill the new pseudo. */
1677 rclass = NO_REGS;
1678 else
1679 /* The class will be defined later in curr_insn_transform. */
1680 rclass
1681 = (enum reg_class) targetm.preferred_reload_class (reg, ALL_REGS);
1682
1683 if (get_reload_reg (curr_static_id->operand[nop].type, reg_mode, reg,
1684 rclass, TRUE, "subreg reg", &new_reg))
1685 {
1686 bool insert_before, insert_after;
1687 bitmap_set_bit (&lra_subreg_reload_pseudos, REGNO (new_reg));
1688
1689 insert_before = (type != OP_OUT
1690 || read_modify_subreg_p (operand));
1691 insert_after = (type != OP_IN);
1692 insert_move_for_subreg (insert_before ? &before : NULL,
1693 insert_after ? &after : NULL,
1694 reg, new_reg);
1695 }
1696 SUBREG_REG (operand) = new_reg;
1697 lra_process_new_insns (curr_insn, before, after,
1698 "Inserting subreg reload");
1699 return true;
1700 }
1701 /* Force a reload for a paradoxical subreg. For paradoxical subreg,
1702 IRA allocates hardreg to the inner pseudo reg according to its mode
1703 instead of the outermode, so the size of the hardreg may not be enough
1704 to contain the outermode operand, in that case we may need to insert
1705 reload for the reg. For the following two types of paradoxical subreg,
1706 we need to insert reload:
1707 1. If the op_type is OP_IN, and the hardreg could not be paired with
1708 other hardreg to contain the outermode operand
1709 (checked by in_hard_reg_set_p), we need to insert the reload.
1710 2. If the op_type is OP_OUT or OP_INOUT.
1711
1712 Here is a paradoxical subreg example showing how the reload is generated:
1713
1714 (insn 5 4 7 2 (set (reg:TI 106 [ __comp ])
1715 (subreg:TI (reg:DI 107 [ __comp ]) 0)) {*movti_internal_rex64}
1716
1717 In IRA, reg107 is allocated to a DImode hardreg. We use x86-64 as example
1718 here, if reg107 is assigned to hardreg R15, because R15 is the last
1719 hardreg, compiler cannot find another hardreg to pair with R15 to
1720 contain TImode data. So we insert a TImode reload reg180 for it.
1721 After reload is inserted:
1722
1723 (insn 283 0 0 (set (subreg:DI (reg:TI 180 [orig:107 __comp ] [107]) 0)
1724 (reg:DI 107 [ __comp ])) -1
1725 (insn 5 4 7 2 (set (reg:TI 106 [ __comp ])
1726 (subreg:TI (reg:TI 180 [orig:107 __comp ] [107]) 0)) {*movti_internal_rex64}
1727
1728 Two reload hard registers will be allocated to reg180 to save TImode data
1729 in LRA_assign.
1730
1731 For LRA pseudos this should normally be handled by the biggest_mode
1732 mechanism. However, it's possible for new uses of an LRA pseudo
1733 to be introduced after we've allocated it, such as when undoing
1734 inheritance, and the allocated register might not then be appropriate
1735 for the new uses. */
1736 else if (REG_P (reg)
1737 && REGNO (reg) >= FIRST_PSEUDO_REGISTER
1738 && paradoxical_subreg_p (operand)
1739 && (inner_hard_regno = lra_get_regno_hard_regno (REGNO (reg))) >= 0
1740 && ((hard_regno
1741 = simplify_subreg_regno (inner_hard_regno, innermode,
1742 SUBREG_BYTE (operand), mode)) < 0
1743 || ((hard_regno_nregs (inner_hard_regno, innermode)
1744 < hard_regno_nregs (hard_regno, mode))
1745 && (regclass = lra_get_allocno_class (REGNO (reg)))
1746 && (type != OP_IN
1747 || !in_hard_reg_set_p (reg_class_contents[regclass],
1748 mode, hard_regno)
1749 || overlaps_hard_reg_set_p (lra_no_alloc_regs,
1750 mode, hard_regno)))))
1751 {
1752 /* The class will be defined later in curr_insn_transform. */
1753 enum reg_class rclass
1754 = (enum reg_class) targetm.preferred_reload_class (reg, ALL_REGS);
1755
1756 if (get_reload_reg (curr_static_id->operand[nop].type, mode, reg,
1757 rclass, TRUE, "paradoxical subreg", &new_reg))
1758 {
1759 rtx subreg;
1760 bool insert_before, insert_after;
1761
1762 PUT_MODE (new_reg, mode);
1763 subreg = gen_lowpart_SUBREG (innermode, new_reg);
1764 bitmap_set_bit (&lra_subreg_reload_pseudos, REGNO (new_reg));
1765
1766 insert_before = (type != OP_OUT);
1767 insert_after = (type != OP_IN);
1768 insert_move_for_subreg (insert_before ? &before : NULL,
1769 insert_after ? &after : NULL,
1770 reg, subreg);
1771 }
1772 SUBREG_REG (operand) = new_reg;
1773 lra_process_new_insns (curr_insn, before, after,
1774 "Inserting paradoxical subreg reload");
1775 return true;
1776 }
1777 return false;
1778 }
1779
1780 /* Return TRUE if X refers for a hard register from SET. */
1781 static bool
1782 uses_hard_regs_p (rtx x, HARD_REG_SET set)
1783 {
1784 int i, j, x_hard_regno;
1785 machine_mode mode;
1786 const char *fmt;
1787 enum rtx_code code;
1788
1789 if (x == NULL_RTX)
1790 return false;
1791 code = GET_CODE (x);
1792 mode = GET_MODE (x);
1793
1794 if (code == SUBREG)
1795 {
1796 /* For all SUBREGs we want to check whether the full multi-register
1797 overlaps the set. For normal SUBREGs this means 'get_hard_regno' of
1798 the inner register, for paradoxical SUBREGs this means the
1799 'get_hard_regno' of the full SUBREG and for complete SUBREGs either is
1800 fine. Use the wider mode for all cases. */
1801 rtx subreg = SUBREG_REG (x);
1802 mode = wider_subreg_mode (x);
1803 if (mode == GET_MODE (subreg))
1804 {
1805 x = subreg;
1806 code = GET_CODE (x);
1807 }
1808 }
1809
1810 if (REG_P (x) || SUBREG_P (x))
1811 {
1812 x_hard_regno = get_hard_regno (x, true);
1813 return (x_hard_regno >= 0
1814 && overlaps_hard_reg_set_p (set, mode, x_hard_regno));
1815 }
1816 if (MEM_P (x))
1817 {
1818 struct address_info ad;
1819
1820 decompose_mem_address (&ad, x);
1821 if (ad.base_term != NULL && uses_hard_regs_p (*ad.base_term, set))
1822 return true;
1823 if (ad.index_term != NULL && uses_hard_regs_p (*ad.index_term, set))
1824 return true;
1825 }
1826 fmt = GET_RTX_FORMAT (code);
1827 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
1828 {
1829 if (fmt[i] == 'e')
1830 {
1831 if (uses_hard_regs_p (XEXP (x, i), set))
1832 return true;
1833 }
1834 else if (fmt[i] == 'E')
1835 {
1836 for (j = XVECLEN (x, i) - 1; j >= 0; j--)
1837 if (uses_hard_regs_p (XVECEXP (x, i, j), set))
1838 return true;
1839 }
1840 }
1841 return false;
1842 }
1843
1844 /* Return true if OP is a spilled pseudo. */
1845 static inline bool
1846 spilled_pseudo_p (rtx op)
1847 {
1848 return (REG_P (op)
1849 && REGNO (op) >= FIRST_PSEUDO_REGISTER && in_mem_p (REGNO (op)));
1850 }
1851
1852 /* Return true if X is a general constant. */
1853 static inline bool
1854 general_constant_p (rtx x)
1855 {
1856 return CONSTANT_P (x) && (! flag_pic || LEGITIMATE_PIC_OPERAND_P (x));
1857 }
1858
1859 static bool
1860 reg_in_class_p (rtx reg, enum reg_class cl)
1861 {
1862 if (cl == NO_REGS)
1863 return get_reg_class (REGNO (reg)) == NO_REGS;
1864 return in_class_p (reg, cl, NULL);
1865 }
1866
1867 /* Return true if SET of RCLASS contains no hard regs which can be
1868 used in MODE. */
1869 static bool
1870 prohibited_class_reg_set_mode_p (enum reg_class rclass,
1871 HARD_REG_SET &set,
1872 machine_mode mode)
1873 {
1874 HARD_REG_SET temp;
1875
1876 lra_assert (hard_reg_set_subset_p (reg_class_contents[rclass], set));
1877 temp = set & ~lra_no_alloc_regs;
1878 return (hard_reg_set_subset_p
1879 (temp, ira_prohibited_class_mode_regs[rclass][mode]));
1880 }
1881
1882
1883 /* Used to check validity info about small class input operands. It
1884 should be incremented at start of processing an insn
1885 alternative. */
1886 static unsigned int curr_small_class_check = 0;
1887
1888 /* Update number of used inputs of class OP_CLASS for operand NOP
1889 of alternative NALT. Return true if we have more such class operands
1890 than the number of available regs. */
1891 static bool
1892 update_and_check_small_class_inputs (int nop, int nalt,
1893 enum reg_class op_class)
1894 {
1895 static unsigned int small_class_check[LIM_REG_CLASSES];
1896 static int small_class_input_nums[LIM_REG_CLASSES];
1897
1898 if (SMALL_REGISTER_CLASS_P (op_class)
1899 /* We are interesting in classes became small because of fixing
1900 some hard regs, e.g. by an user through GCC options. */
1901 && hard_reg_set_intersect_p (reg_class_contents[op_class],
1902 ira_no_alloc_regs)
1903 && (curr_static_id->operand[nop].type != OP_OUT
1904 || TEST_BIT (curr_static_id->operand[nop].early_clobber_alts, nalt)))
1905 {
1906 if (small_class_check[op_class] == curr_small_class_check)
1907 small_class_input_nums[op_class]++;
1908 else
1909 {
1910 small_class_check[op_class] = curr_small_class_check;
1911 small_class_input_nums[op_class] = 1;
1912 }
1913 if (small_class_input_nums[op_class] > ira_class_hard_regs_num[op_class])
1914 return true;
1915 }
1916 return false;
1917 }
1918
1919 /* Major function to choose the current insn alternative and what
1920 operands should be reloaded and how. If ONLY_ALTERNATIVE is not
1921 negative we should consider only this alternative. Return false if
1922 we cannot choose the alternative or find how to reload the
1923 operands. */
1924 static bool
1925 process_alt_operands (int only_alternative)
1926 {
1927 bool ok_p = false;
1928 int nop, overall, nalt;
1929 int n_alternatives = curr_static_id->n_alternatives;
1930 int n_operands = curr_static_id->n_operands;
1931 /* LOSERS counts the operands that don't fit this alternative and
1932 would require loading. */
1933 int losers;
1934 int addr_losers;
1935 /* REJECT is a count of how undesirable this alternative says it is
1936 if any reloading is required. If the alternative matches exactly
1937 then REJECT is ignored, but otherwise it gets this much counted
1938 against it in addition to the reloading needed. */
1939 int reject;
1940 /* This is defined by '!' or '?' alternative constraint and added to
1941 reject. But in some cases it can be ignored. */
1942 int static_reject;
1943 int op_reject;
1944 /* The number of elements in the following array. */
1945 int early_clobbered_regs_num;
1946 /* Numbers of operands which are early clobber registers. */
1947 int early_clobbered_nops[MAX_RECOG_OPERANDS];
1948 enum reg_class curr_alt[MAX_RECOG_OPERANDS];
1949 HARD_REG_SET curr_alt_set[MAX_RECOG_OPERANDS];
1950 bool curr_alt_match_win[MAX_RECOG_OPERANDS];
1951 bool curr_alt_win[MAX_RECOG_OPERANDS];
1952 bool curr_alt_offmemok[MAX_RECOG_OPERANDS];
1953 int curr_alt_matches[MAX_RECOG_OPERANDS];
1954 /* The number of elements in the following array. */
1955 int curr_alt_dont_inherit_ops_num;
1956 /* Numbers of operands whose reload pseudos should not be inherited. */
1957 int curr_alt_dont_inherit_ops[MAX_RECOG_OPERANDS];
1958 rtx op;
1959 /* The register when the operand is a subreg of register, otherwise the
1960 operand itself. */
1961 rtx no_subreg_reg_operand[MAX_RECOG_OPERANDS];
1962 /* The register if the operand is a register or subreg of register,
1963 otherwise NULL. */
1964 rtx operand_reg[MAX_RECOG_OPERANDS];
1965 int hard_regno[MAX_RECOG_OPERANDS];
1966 machine_mode biggest_mode[MAX_RECOG_OPERANDS];
1967 int reload_nregs, reload_sum;
1968 bool costly_p;
1969 enum reg_class cl;
1970
1971 /* Calculate some data common for all alternatives to speed up the
1972 function. */
1973 for (nop = 0; nop < n_operands; nop++)
1974 {
1975 rtx reg;
1976
1977 op = no_subreg_reg_operand[nop] = *curr_id->operand_loc[nop];
1978 /* The real hard regno of the operand after the allocation. */
1979 hard_regno[nop] = get_hard_regno (op, true);
1980
1981 operand_reg[nop] = reg = op;
1982 biggest_mode[nop] = GET_MODE (op);
1983 if (GET_CODE (op) == SUBREG)
1984 {
1985 biggest_mode[nop] = wider_subreg_mode (op);
1986 operand_reg[nop] = reg = SUBREG_REG (op);
1987 }
1988 if (! REG_P (reg))
1989 operand_reg[nop] = NULL_RTX;
1990 else if (REGNO (reg) >= FIRST_PSEUDO_REGISTER
1991 || ((int) REGNO (reg)
1992 == lra_get_elimination_hard_regno (REGNO (reg))))
1993 no_subreg_reg_operand[nop] = reg;
1994 else
1995 operand_reg[nop] = no_subreg_reg_operand[nop]
1996 /* Just use natural mode for elimination result. It should
1997 be enough for extra constraints hooks. */
1998 = regno_reg_rtx[hard_regno[nop]];
1999 }
2000
2001 /* The constraints are made of several alternatives. Each operand's
2002 constraint looks like foo,bar,... with commas separating the
2003 alternatives. The first alternatives for all operands go
2004 together, the second alternatives go together, etc.
2005
2006 First loop over alternatives. */
2007 alternative_mask preferred = curr_id->preferred_alternatives;
2008 if (only_alternative >= 0)
2009 preferred &= ALTERNATIVE_BIT (only_alternative);
2010
2011 for (nalt = 0; nalt < n_alternatives; nalt++)
2012 {
2013 /* Loop over operands for one constraint alternative. */
2014 if (!TEST_BIT (preferred, nalt))
2015 continue;
2016
2017 bool matching_early_clobber[MAX_RECOG_OPERANDS];
2018 curr_small_class_check++;
2019 overall = losers = addr_losers = 0;
2020 static_reject = reject = reload_nregs = reload_sum = 0;
2021 for (nop = 0; nop < n_operands; nop++)
2022 {
2023 int inc = (curr_static_id
2024 ->operand_alternative[nalt * n_operands + nop].reject);
2025 if (lra_dump_file != NULL && inc != 0)
2026 fprintf (lra_dump_file,
2027 " Staticly defined alt reject+=%d\n", inc);
2028 static_reject += inc;
2029 matching_early_clobber[nop] = 0;
2030 }
2031 reject += static_reject;
2032 early_clobbered_regs_num = 0;
2033
2034 for (nop = 0; nop < n_operands; nop++)
2035 {
2036 const char *p;
2037 char *end;
2038 int len, c, m, i, opalt_num, this_alternative_matches;
2039 bool win, did_match, offmemok, early_clobber_p;
2040 /* false => this operand can be reloaded somehow for this
2041 alternative. */
2042 bool badop;
2043 /* true => this operand can be reloaded if the alternative
2044 allows regs. */
2045 bool winreg;
2046 /* True if a constant forced into memory would be OK for
2047 this operand. */
2048 bool constmemok;
2049 enum reg_class this_alternative, this_costly_alternative;
2050 HARD_REG_SET this_alternative_set, this_costly_alternative_set;
2051 bool this_alternative_match_win, this_alternative_win;
2052 bool this_alternative_offmemok;
2053 bool scratch_p;
2054 machine_mode mode;
2055 enum constraint_num cn;
2056
2057 opalt_num = nalt * n_operands + nop;
2058 if (curr_static_id->operand_alternative[opalt_num].anything_ok)
2059 {
2060 /* Fast track for no constraints at all. */
2061 curr_alt[nop] = NO_REGS;
2062 CLEAR_HARD_REG_SET (curr_alt_set[nop]);
2063 curr_alt_win[nop] = true;
2064 curr_alt_match_win[nop] = false;
2065 curr_alt_offmemok[nop] = false;
2066 curr_alt_matches[nop] = -1;
2067 continue;
2068 }
2069
2070 op = no_subreg_reg_operand[nop];
2071 mode = curr_operand_mode[nop];
2072
2073 win = did_match = winreg = offmemok = constmemok = false;
2074 badop = true;
2075
2076 early_clobber_p = false;
2077 p = curr_static_id->operand_alternative[opalt_num].constraint;
2078
2079 this_costly_alternative = this_alternative = NO_REGS;
2080 /* We update set of possible hard regs besides its class
2081 because reg class might be inaccurate. For example,
2082 union of LO_REGS (l), HI_REGS(h), and STACK_REG(k) in ARM
2083 is translated in HI_REGS because classes are merged by
2084 pairs and there is no accurate intermediate class. */
2085 CLEAR_HARD_REG_SET (this_alternative_set);
2086 CLEAR_HARD_REG_SET (this_costly_alternative_set);
2087 this_alternative_win = false;
2088 this_alternative_match_win = false;
2089 this_alternative_offmemok = false;
2090 this_alternative_matches = -1;
2091
2092 /* An empty constraint should be excluded by the fast
2093 track. */
2094 lra_assert (*p != 0 && *p != ',');
2095
2096 op_reject = 0;
2097 /* Scan this alternative's specs for this operand; set WIN
2098 if the operand fits any letter in this alternative.
2099 Otherwise, clear BADOP if this operand could fit some
2100 letter after reloads, or set WINREG if this operand could
2101 fit after reloads provided the constraint allows some
2102 registers. */
2103 costly_p = false;
2104 do
2105 {
2106 switch ((c = *p, len = CONSTRAINT_LEN (c, p)), c)
2107 {
2108 case '\0':
2109 len = 0;
2110 break;
2111 case ',':
2112 c = '\0';
2113 break;
2114
2115 case '&':
2116 early_clobber_p = true;
2117 break;
2118
2119 case '$':
2120 op_reject += LRA_MAX_REJECT;
2121 break;
2122 case '^':
2123 op_reject += LRA_LOSER_COST_FACTOR;
2124 break;
2125
2126 case '#':
2127 /* Ignore rest of this alternative. */
2128 c = '\0';
2129 break;
2130
2131 case '0': case '1': case '2': case '3': case '4':
2132 case '5': case '6': case '7': case '8': case '9':
2133 {
2134 int m_hregno;
2135 bool match_p;
2136
2137 m = strtoul (p, &end, 10);
2138 p = end;
2139 len = 0;
2140 lra_assert (nop > m);
2141
2142 /* Reject matches if we don't know which operand is
2143 bigger. This situation would arguably be a bug in
2144 an .md pattern, but could also occur in a user asm. */
2145 if (!ordered_p (GET_MODE_SIZE (biggest_mode[m]),
2146 GET_MODE_SIZE (biggest_mode[nop])))
2147 break;
2148
2149 /* Don't match wrong asm insn operands for proper
2150 diagnostic later. */
2151 if (INSN_CODE (curr_insn) < 0
2152 && (curr_operand_mode[m] == BLKmode
2153 || curr_operand_mode[nop] == BLKmode)
2154 && curr_operand_mode[m] != curr_operand_mode[nop])
2155 break;
2156
2157 m_hregno = get_hard_regno (*curr_id->operand_loc[m], false);
2158 /* We are supposed to match a previous operand.
2159 If we do, we win if that one did. If we do
2160 not, count both of the operands as losers.
2161 (This is too conservative, since most of the
2162 time only a single reload insn will be needed
2163 to make the two operands win. As a result,
2164 this alternative may be rejected when it is
2165 actually desirable.) */
2166 match_p = false;
2167 if (operands_match_p (*curr_id->operand_loc[nop],
2168 *curr_id->operand_loc[m], m_hregno))
2169 {
2170 /* We should reject matching of an early
2171 clobber operand if the matching operand is
2172 not dying in the insn. */
2173 if (!TEST_BIT (curr_static_id->operand[m]
2174 .early_clobber_alts, nalt)
2175 || operand_reg[nop] == NULL_RTX
2176 || (find_regno_note (curr_insn, REG_DEAD,
2177 REGNO (op))
2178 || REGNO (op) == REGNO (operand_reg[m])))
2179 match_p = true;
2180 }
2181 if (match_p)
2182 {
2183 /* If we are matching a non-offsettable
2184 address where an offsettable address was
2185 expected, then we must reject this
2186 combination, because we can't reload
2187 it. */
2188 if (curr_alt_offmemok[m]
2189 && MEM_P (*curr_id->operand_loc[m])
2190 && curr_alt[m] == NO_REGS && ! curr_alt_win[m])
2191 continue;
2192 }
2193 else
2194 {
2195 /* If the operands do not match and one
2196 operand is INOUT, we can not match them.
2197 Try other possibilities, e.g. other
2198 alternatives or commutative operand
2199 exchange. */
2200 if (curr_static_id->operand[nop].type == OP_INOUT
2201 || curr_static_id->operand[m].type == OP_INOUT)
2202 break;
2203 /* Operands don't match. If the operands are
2204 different user defined explicit hard
2205 registers, then we cannot make them match
2206 when one is early clobber operand. */
2207 if ((REG_P (*curr_id->operand_loc[nop])
2208 || SUBREG_P (*curr_id->operand_loc[nop]))
2209 && (REG_P (*curr_id->operand_loc[m])
2210 || SUBREG_P (*curr_id->operand_loc[m])))
2211 {
2212 rtx nop_reg = *curr_id->operand_loc[nop];
2213 if (SUBREG_P (nop_reg))
2214 nop_reg = SUBREG_REG (nop_reg);
2215 rtx m_reg = *curr_id->operand_loc[m];
2216 if (SUBREG_P (m_reg))
2217 m_reg = SUBREG_REG (m_reg);
2218
2219 if (REG_P (nop_reg)
2220 && HARD_REGISTER_P (nop_reg)
2221 && REG_USERVAR_P (nop_reg)
2222 && REG_P (m_reg)
2223 && HARD_REGISTER_P (m_reg)
2224 && REG_USERVAR_P (m_reg))
2225 {
2226 int i;
2227
2228 for (i = 0; i < early_clobbered_regs_num; i++)
2229 if (m == early_clobbered_nops[i])
2230 break;
2231 if (i < early_clobbered_regs_num
2232 || early_clobber_p)
2233 break;
2234 }
2235 }
2236 /* Both operands must allow a reload register,
2237 otherwise we cannot make them match. */
2238 if (curr_alt[m] == NO_REGS)
2239 break;
2240 /* Retroactively mark the operand we had to
2241 match as a loser, if it wasn't already and
2242 it wasn't matched to a register constraint
2243 (e.g it might be matched by memory). */
2244 if (curr_alt_win[m]
2245 && (operand_reg[m] == NULL_RTX
2246 || hard_regno[m] < 0))
2247 {
2248 losers++;
2249 reload_nregs
2250 += (ira_reg_class_max_nregs[curr_alt[m]]
2251 [GET_MODE (*curr_id->operand_loc[m])]);
2252 }
2253
2254 /* Prefer matching earlyclobber alternative as
2255 it results in less hard regs required for
2256 the insn than a non-matching earlyclobber
2257 alternative. */
2258 if (TEST_BIT (curr_static_id->operand[m]
2259 .early_clobber_alts, nalt))
2260 {
2261 if (lra_dump_file != NULL)
2262 fprintf
2263 (lra_dump_file,
2264 " %d Matching earlyclobber alt:"
2265 " reject--\n",
2266 nop);
2267 if (!matching_early_clobber[m])
2268 {
2269 reject--;
2270 matching_early_clobber[m] = 1;
2271 }
2272 }
2273 /* Otherwise we prefer no matching
2274 alternatives because it gives more freedom
2275 in RA. */
2276 else if (operand_reg[nop] == NULL_RTX
2277 || (find_regno_note (curr_insn, REG_DEAD,
2278 REGNO (operand_reg[nop]))
2279 == NULL_RTX))
2280 {
2281 if (lra_dump_file != NULL)
2282 fprintf
2283 (lra_dump_file,
2284 " %d Matching alt: reject+=2\n",
2285 nop);
2286 reject += 2;
2287 }
2288 }
2289 /* If we have to reload this operand and some
2290 previous operand also had to match the same
2291 thing as this operand, we don't know how to do
2292 that. */
2293 if (!match_p || !curr_alt_win[m])
2294 {
2295 for (i = 0; i < nop; i++)
2296 if (curr_alt_matches[i] == m)
2297 break;
2298 if (i < nop)
2299 break;
2300 }
2301 else
2302 did_match = true;
2303
2304 this_alternative_matches = m;
2305 /* This can be fixed with reloads if the operand
2306 we are supposed to match can be fixed with
2307 reloads. */
2308 badop = false;
2309 this_alternative = curr_alt[m];
2310 this_alternative_set = curr_alt_set[m];
2311 winreg = this_alternative != NO_REGS;
2312 break;
2313 }
2314
2315 case 'g':
2316 if (MEM_P (op)
2317 || general_constant_p (op)
2318 || spilled_pseudo_p (op))
2319 win = true;
2320 cl = GENERAL_REGS;
2321 goto reg;
2322
2323 default:
2324 cn = lookup_constraint (p);
2325 switch (get_constraint_type (cn))
2326 {
2327 case CT_REGISTER:
2328 cl = reg_class_for_constraint (cn);
2329 if (cl != NO_REGS)
2330 goto reg;
2331 break;
2332
2333 case CT_CONST_INT:
2334 if (CONST_INT_P (op)
2335 && insn_const_int_ok_for_constraint (INTVAL (op), cn))
2336 win = true;
2337 break;
2338
2339 case CT_MEMORY:
2340 if (MEM_P (op)
2341 && satisfies_memory_constraint_p (op, cn))
2342 win = true;
2343 else if (spilled_pseudo_p (op))
2344 win = true;
2345
2346 /* If we didn't already win, we can reload constants
2347 via force_const_mem or put the pseudo value into
2348 memory, or make other memory by reloading the
2349 address like for 'o'. */
2350 if (CONST_POOL_OK_P (mode, op)
2351 || MEM_P (op) || REG_P (op)
2352 /* We can restore the equiv insn by a
2353 reload. */
2354 || equiv_substition_p[nop])
2355 badop = false;
2356 constmemok = true;
2357 offmemok = true;
2358 break;
2359
2360 case CT_ADDRESS:
2361 /* An asm operand with an address constraint
2362 that doesn't satisfy address_operand has
2363 is_address cleared, so that we don't try to
2364 make a non-address fit. */
2365 if (!curr_static_id->operand[nop].is_address)
2366 break;
2367 /* If we didn't already win, we can reload the address
2368 into a base register. */
2369 if (satisfies_address_constraint_p (op, cn))
2370 win = true;
2371 cl = base_reg_class (VOIDmode, ADDR_SPACE_GENERIC,
2372 ADDRESS, SCRATCH);
2373 badop = false;
2374 goto reg;
2375
2376 case CT_FIXED_FORM:
2377 if (constraint_satisfied_p (op, cn))
2378 win = true;
2379 break;
2380
2381 case CT_SPECIAL_MEMORY:
2382 if (MEM_P (op)
2383 && satisfies_memory_constraint_p (op, cn))
2384 win = true;
2385 else if (spilled_pseudo_p (op))
2386 win = true;
2387 break;
2388 }
2389 break;
2390
2391 reg:
2392 if (mode == BLKmode)
2393 break;
2394 this_alternative = reg_class_subunion[this_alternative][cl];
2395 this_alternative_set |= reg_class_contents[cl];
2396 if (costly_p)
2397 {
2398 this_costly_alternative
2399 = reg_class_subunion[this_costly_alternative][cl];
2400 this_costly_alternative_set |= reg_class_contents[cl];
2401 }
2402 winreg = true;
2403 if (REG_P (op))
2404 {
2405 if (hard_regno[nop] >= 0
2406 && in_hard_reg_set_p (this_alternative_set,
2407 mode, hard_regno[nop]))
2408 win = true;
2409 else if (hard_regno[nop] < 0
2410 && in_class_p (op, this_alternative, NULL))
2411 win = true;
2412 }
2413 break;
2414 }
2415 if (c != ' ' && c != '\t')
2416 costly_p = c == '*';
2417 }
2418 while ((p += len), c);
2419
2420 scratch_p = (operand_reg[nop] != NULL_RTX
2421 && lra_former_scratch_p (REGNO (operand_reg[nop])));
2422 /* Record which operands fit this alternative. */
2423 if (win)
2424 {
2425 this_alternative_win = true;
2426 if (operand_reg[nop] != NULL_RTX)
2427 {
2428 if (hard_regno[nop] >= 0)
2429 {
2430 if (in_hard_reg_set_p (this_costly_alternative_set,
2431 mode, hard_regno[nop]))
2432 {
2433 if (lra_dump_file != NULL)
2434 fprintf (lra_dump_file,
2435 " %d Costly set: reject++\n",
2436 nop);
2437 reject++;
2438 }
2439 }
2440 else
2441 {
2442 /* Prefer won reg to spilled pseudo under other
2443 equal conditions for possibe inheritance. */
2444 if (! scratch_p)
2445 {
2446 if (lra_dump_file != NULL)
2447 fprintf
2448 (lra_dump_file,
2449 " %d Non pseudo reload: reject++\n",
2450 nop);
2451 reject++;
2452 }
2453 if (in_class_p (operand_reg[nop],
2454 this_costly_alternative, NULL))
2455 {
2456 if (lra_dump_file != NULL)
2457 fprintf
2458 (lra_dump_file,
2459 " %d Non pseudo costly reload:"
2460 " reject++\n",
2461 nop);
2462 reject++;
2463 }
2464 }
2465 /* We simulate the behavior of old reload here.
2466 Although scratches need hard registers and it
2467 might result in spilling other pseudos, no reload
2468 insns are generated for the scratches. So it
2469 might cost something but probably less than old
2470 reload pass believes. */
2471 if (scratch_p)
2472 {
2473 if (lra_dump_file != NULL)
2474 fprintf (lra_dump_file,
2475 " %d Scratch win: reject+=2\n",
2476 nop);
2477 reject += 2;
2478 }
2479 }
2480 }
2481 else if (did_match)
2482 this_alternative_match_win = true;
2483 else
2484 {
2485 int const_to_mem = 0;
2486 bool no_regs_p;
2487
2488 reject += op_reject;
2489 /* Never do output reload of stack pointer. It makes
2490 impossible to do elimination when SP is changed in
2491 RTL. */
2492 if (op == stack_pointer_rtx && ! frame_pointer_needed
2493 && curr_static_id->operand[nop].type != OP_IN)
2494 goto fail;
2495
2496 /* If this alternative asks for a specific reg class, see if there
2497 is at least one allocatable register in that class. */
2498 no_regs_p
2499 = (this_alternative == NO_REGS
2500 || (hard_reg_set_subset_p
2501 (reg_class_contents[this_alternative],
2502 lra_no_alloc_regs)));
2503
2504 /* For asms, verify that the class for this alternative is possible
2505 for the mode that is specified. */
2506 if (!no_regs_p && INSN_CODE (curr_insn) < 0)
2507 {
2508 int i;
2509 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
2510 if (targetm.hard_regno_mode_ok (i, mode)
2511 && in_hard_reg_set_p (reg_class_contents[this_alternative],
2512 mode, i))
2513 break;
2514 if (i == FIRST_PSEUDO_REGISTER)
2515 winreg = false;
2516 }
2517
2518 /* If this operand accepts a register, and if the
2519 register class has at least one allocatable register,
2520 then this operand can be reloaded. */
2521 if (winreg && !no_regs_p)
2522 badop = false;
2523
2524 if (badop)
2525 {
2526 if (lra_dump_file != NULL)
2527 fprintf (lra_dump_file,
2528 " alt=%d: Bad operand -- refuse\n",
2529 nalt);
2530 goto fail;
2531 }
2532
2533 if (this_alternative != NO_REGS)
2534 {
2535 HARD_REG_SET available_regs
2536 = (reg_class_contents[this_alternative]
2537 & ~((ira_prohibited_class_mode_regs
2538 [this_alternative][mode])
2539 | lra_no_alloc_regs));
2540 if (hard_reg_set_empty_p (available_regs))
2541 {
2542 /* There are no hard regs holding a value of given
2543 mode. */
2544 if (offmemok)
2545 {
2546 this_alternative = NO_REGS;
2547 if (lra_dump_file != NULL)
2548 fprintf (lra_dump_file,
2549 " %d Using memory because of"
2550 " a bad mode: reject+=2\n",
2551 nop);
2552 reject += 2;
2553 }
2554 else
2555 {
2556 if (lra_dump_file != NULL)
2557 fprintf (lra_dump_file,
2558 " alt=%d: Wrong mode -- refuse\n",
2559 nalt);
2560 goto fail;
2561 }
2562 }
2563 }
2564
2565 /* If not assigned pseudo has a class which a subset of
2566 required reg class, it is a less costly alternative
2567 as the pseudo still can get a hard reg of necessary
2568 class. */
2569 if (! no_regs_p && REG_P (op) && hard_regno[nop] < 0
2570 && (cl = get_reg_class (REGNO (op))) != NO_REGS
2571 && ira_class_subset_p[this_alternative][cl])
2572 {
2573 if (lra_dump_file != NULL)
2574 fprintf
2575 (lra_dump_file,
2576 " %d Super set class reg: reject-=3\n", nop);
2577 reject -= 3;
2578 }
2579
2580 this_alternative_offmemok = offmemok;
2581 if (this_costly_alternative != NO_REGS)
2582 {
2583 if (lra_dump_file != NULL)
2584 fprintf (lra_dump_file,
2585 " %d Costly loser: reject++\n", nop);
2586 reject++;
2587 }
2588 /* If the operand is dying, has a matching constraint,
2589 and satisfies constraints of the matched operand
2590 which failed to satisfy the own constraints, most probably
2591 the reload for this operand will be gone. */
2592 if (this_alternative_matches >= 0
2593 && !curr_alt_win[this_alternative_matches]
2594 && REG_P (op)
2595 && find_regno_note (curr_insn, REG_DEAD, REGNO (op))
2596 && (hard_regno[nop] >= 0
2597 ? in_hard_reg_set_p (this_alternative_set,
2598 mode, hard_regno[nop])
2599 : in_class_p (op, this_alternative, NULL)))
2600 {
2601 if (lra_dump_file != NULL)
2602 fprintf
2603 (lra_dump_file,
2604 " %d Dying matched operand reload: reject++\n",
2605 nop);
2606 reject++;
2607 }
2608 else
2609 {
2610 /* Strict_low_part requires to reload the register
2611 not the sub-register. In this case we should
2612 check that a final reload hard reg can hold the
2613 value mode. */
2614 if (curr_static_id->operand[nop].strict_low
2615 && REG_P (op)
2616 && hard_regno[nop] < 0
2617 && GET_CODE (*curr_id->operand_loc[nop]) == SUBREG
2618 && ira_class_hard_regs_num[this_alternative] > 0
2619 && (!targetm.hard_regno_mode_ok
2620 (ira_class_hard_regs[this_alternative][0],
2621 GET_MODE (*curr_id->operand_loc[nop]))))
2622 {
2623 if (lra_dump_file != NULL)
2624 fprintf
2625 (lra_dump_file,
2626 " alt=%d: Strict low subreg reload -- refuse\n",
2627 nalt);
2628 goto fail;
2629 }
2630 losers++;
2631 }
2632 if (operand_reg[nop] != NULL_RTX
2633 /* Output operands and matched input operands are
2634 not inherited. The following conditions do not
2635 exactly describe the previous statement but they
2636 are pretty close. */
2637 && curr_static_id->operand[nop].type != OP_OUT
2638 && (this_alternative_matches < 0
2639 || curr_static_id->operand[nop].type != OP_IN))
2640 {
2641 int last_reload = (lra_reg_info[ORIGINAL_REGNO
2642 (operand_reg[nop])]
2643 .last_reload);
2644
2645 /* The value of reload_sum has sense only if we
2646 process insns in their order. It happens only on
2647 the first constraints sub-pass when we do most of
2648 reload work. */
2649 if (lra_constraint_iter == 1 && last_reload > bb_reload_num)
2650 reload_sum += last_reload - bb_reload_num;
2651 }
2652 /* If this is a constant that is reloaded into the
2653 desired class by copying it to memory first, count
2654 that as another reload. This is consistent with
2655 other code and is required to avoid choosing another
2656 alternative when the constant is moved into memory.
2657 Note that the test here is precisely the same as in
2658 the code below that calls force_const_mem. */
2659 if (CONST_POOL_OK_P (mode, op)
2660 && ((targetm.preferred_reload_class
2661 (op, this_alternative) == NO_REGS)
2662 || no_input_reloads_p))
2663 {
2664 const_to_mem = 1;
2665 if (! no_regs_p)
2666 losers++;
2667 }
2668
2669 /* Alternative loses if it requires a type of reload not
2670 permitted for this insn. We can always reload
2671 objects with a REG_UNUSED note. */
2672 if ((curr_static_id->operand[nop].type != OP_IN
2673 && no_output_reloads_p
2674 && ! find_reg_note (curr_insn, REG_UNUSED, op))
2675 || (curr_static_id->operand[nop].type != OP_OUT
2676 && no_input_reloads_p && ! const_to_mem)
2677 || (this_alternative_matches >= 0
2678 && (no_input_reloads_p
2679 || (no_output_reloads_p
2680 && (curr_static_id->operand
2681 [this_alternative_matches].type != OP_IN)
2682 && ! find_reg_note (curr_insn, REG_UNUSED,
2683 no_subreg_reg_operand
2684 [this_alternative_matches])))))
2685 {
2686 if (lra_dump_file != NULL)
2687 fprintf
2688 (lra_dump_file,
2689 " alt=%d: No input/otput reload -- refuse\n",
2690 nalt);
2691 goto fail;
2692 }
2693
2694 /* Alternative loses if it required class pseudo cannot
2695 hold value of required mode. Such insns can be
2696 described by insn definitions with mode iterators. */
2697 if (GET_MODE (*curr_id->operand_loc[nop]) != VOIDmode
2698 && ! hard_reg_set_empty_p (this_alternative_set)
2699 /* It is common practice for constraints to use a
2700 class which does not have actually enough regs to
2701 hold the value (e.g. x86 AREG for mode requiring
2702 more one general reg). Therefore we have 2
2703 conditions to check that the reload pseudo cannot
2704 hold the mode value. */
2705 && (!targetm.hard_regno_mode_ok
2706 (ira_class_hard_regs[this_alternative][0],
2707 GET_MODE (*curr_id->operand_loc[nop])))
2708 /* The above condition is not enough as the first
2709 reg in ira_class_hard_regs can be not aligned for
2710 multi-words mode values. */
2711 && (prohibited_class_reg_set_mode_p
2712 (this_alternative, this_alternative_set,
2713 GET_MODE (*curr_id->operand_loc[nop]))))
2714 {
2715 if (lra_dump_file != NULL)
2716 fprintf (lra_dump_file,
2717 " alt=%d: reload pseudo for op %d "
2718 "cannot hold the mode value -- refuse\n",
2719 nalt, nop);
2720 goto fail;
2721 }
2722
2723 /* Check strong discouragement of reload of non-constant
2724 into class THIS_ALTERNATIVE. */
2725 if (! CONSTANT_P (op) && ! no_regs_p
2726 && (targetm.preferred_reload_class
2727 (op, this_alternative) == NO_REGS
2728 || (curr_static_id->operand[nop].type == OP_OUT
2729 && (targetm.preferred_output_reload_class
2730 (op, this_alternative) == NO_REGS))))
2731 {
2732 if (offmemok && REG_P (op))
2733 {
2734 if (lra_dump_file != NULL)
2735 fprintf
2736 (lra_dump_file,
2737 " %d Spill pseudo into memory: reject+=3\n",
2738 nop);
2739 reject += 3;
2740 }
2741 else
2742 {
2743 if (lra_dump_file != NULL)
2744 fprintf
2745 (lra_dump_file,
2746 " %d Non-prefered reload: reject+=%d\n",
2747 nop, LRA_MAX_REJECT);
2748 reject += LRA_MAX_REJECT;
2749 }
2750 }
2751
2752 if (! (MEM_P (op) && offmemok)
2753 && ! (const_to_mem && constmemok))
2754 {
2755 /* We prefer to reload pseudos over reloading other
2756 things, since such reloads may be able to be
2757 eliminated later. So bump REJECT in other cases.
2758 Don't do this in the case where we are forcing a
2759 constant into memory and it will then win since
2760 we don't want to have a different alternative
2761 match then. */
2762 if (! (REG_P (op) && REGNO (op) >= FIRST_PSEUDO_REGISTER))
2763 {
2764 if (lra_dump_file != NULL)
2765 fprintf
2766 (lra_dump_file,
2767 " %d Non-pseudo reload: reject+=2\n",
2768 nop);
2769 reject += 2;
2770 }
2771
2772 if (! no_regs_p)
2773 reload_nregs
2774 += ira_reg_class_max_nregs[this_alternative][mode];
2775
2776 if (SMALL_REGISTER_CLASS_P (this_alternative))
2777 {
2778 if (lra_dump_file != NULL)
2779 fprintf
2780 (lra_dump_file,
2781 " %d Small class reload: reject+=%d\n",
2782 nop, LRA_LOSER_COST_FACTOR / 2);
2783 reject += LRA_LOSER_COST_FACTOR / 2;
2784 }
2785 }
2786
2787 /* We are trying to spill pseudo into memory. It is
2788 usually more costly than moving to a hard register
2789 although it might takes the same number of
2790 reloads.
2791
2792 Non-pseudo spill may happen also. Suppose a target allows both
2793 register and memory in the operand constraint alternatives,
2794 then it's typical that an eliminable register has a substition
2795 of "base + offset" which can either be reloaded by a simple
2796 "new_reg <= base + offset" which will match the register
2797 constraint, or a similar reg addition followed by further spill
2798 to and reload from memory which will match the memory
2799 constraint, but this memory spill will be much more costly
2800 usually.
2801
2802 Code below increases the reject for both pseudo and non-pseudo
2803 spill. */
2804 if (no_regs_p
2805 && !(MEM_P (op) && offmemok)
2806 && !(REG_P (op) && hard_regno[nop] < 0))
2807 {
2808 if (lra_dump_file != NULL)
2809 fprintf
2810 (lra_dump_file,
2811 " %d Spill %spseudo into memory: reject+=3\n",
2812 nop, REG_P (op) ? "" : "Non-");
2813 reject += 3;
2814 if (VECTOR_MODE_P (mode))
2815 {
2816 /* Spilling vectors into memory is usually more
2817 costly as they contain big values. */
2818 if (lra_dump_file != NULL)
2819 fprintf
2820 (lra_dump_file,
2821 " %d Spill vector pseudo: reject+=2\n",
2822 nop);
2823 reject += 2;
2824 }
2825 }
2826
2827 /* When we use an operand requiring memory in given
2828 alternative, the insn should write *and* read the
2829 value to/from memory it is costly in comparison with
2830 an insn alternative which does not use memory
2831 (e.g. register or immediate operand). We exclude
2832 memory operand for such case as we can satisfy the
2833 memory constraints by reloading address. */
2834 if (no_regs_p && offmemok && !MEM_P (op))
2835 {
2836 if (lra_dump_file != NULL)
2837 fprintf
2838 (lra_dump_file,
2839 " Using memory insn operand %d: reject+=3\n",
2840 nop);
2841 reject += 3;
2842 }
2843
2844 /* If reload requires moving value through secondary
2845 memory, it will need one more insn at least. */
2846 if (this_alternative != NO_REGS
2847 && REG_P (op) && (cl = get_reg_class (REGNO (op))) != NO_REGS
2848 && ((curr_static_id->operand[nop].type != OP_OUT
2849 && targetm.secondary_memory_needed (GET_MODE (op), cl,
2850 this_alternative))
2851 || (curr_static_id->operand[nop].type != OP_IN
2852 && (targetm.secondary_memory_needed
2853 (GET_MODE (op), this_alternative, cl)))))
2854 losers++;
2855
2856 if (MEM_P (op) && offmemok)
2857 addr_losers++;
2858 else
2859 {
2860 /* Input reloads can be inherited more often than
2861 output reloads can be removed, so penalize output
2862 reloads. */
2863 if (!REG_P (op) || curr_static_id->operand[nop].type != OP_IN)
2864 {
2865 if (lra_dump_file != NULL)
2866 fprintf
2867 (lra_dump_file,
2868 " %d Non input pseudo reload: reject++\n",
2869 nop);
2870 reject++;
2871 }
2872
2873 if (curr_static_id->operand[nop].type == OP_INOUT)
2874 {
2875 if (lra_dump_file != NULL)
2876 fprintf
2877 (lra_dump_file,
2878 " %d Input/Output reload: reject+=%d\n",
2879 nop, LRA_LOSER_COST_FACTOR);
2880 reject += LRA_LOSER_COST_FACTOR;
2881 }
2882 }
2883 }
2884
2885 if (early_clobber_p && ! scratch_p)
2886 {
2887 if (lra_dump_file != NULL)
2888 fprintf (lra_dump_file,
2889 " %d Early clobber: reject++\n", nop);
2890 reject++;
2891 }
2892 /* ??? We check early clobbers after processing all operands
2893 (see loop below) and there we update the costs more.
2894 Should we update the cost (may be approximately) here
2895 because of early clobber register reloads or it is a rare
2896 or non-important thing to be worth to do it. */
2897 overall = (losers * LRA_LOSER_COST_FACTOR + reject
2898 - (addr_losers == losers ? static_reject : 0));
2899 if ((best_losers == 0 || losers != 0) && best_overall < overall)
2900 {
2901 if (lra_dump_file != NULL)
2902 fprintf (lra_dump_file,
2903 " alt=%d,overall=%d,losers=%d -- refuse\n",
2904 nalt, overall, losers);
2905 goto fail;
2906 }
2907
2908 if (update_and_check_small_class_inputs (nop, nalt,
2909 this_alternative))
2910 {
2911 if (lra_dump_file != NULL)
2912 fprintf (lra_dump_file,
2913 " alt=%d, not enough small class regs -- refuse\n",
2914 nalt);
2915 goto fail;
2916 }
2917 curr_alt[nop] = this_alternative;
2918 curr_alt_set[nop] = this_alternative_set;
2919 curr_alt_win[nop] = this_alternative_win;
2920 curr_alt_match_win[nop] = this_alternative_match_win;
2921 curr_alt_offmemok[nop] = this_alternative_offmemok;
2922 curr_alt_matches[nop] = this_alternative_matches;
2923
2924 if (this_alternative_matches >= 0
2925 && !did_match && !this_alternative_win)
2926 curr_alt_win[this_alternative_matches] = false;
2927
2928 if (early_clobber_p && operand_reg[nop] != NULL_RTX)
2929 early_clobbered_nops[early_clobbered_regs_num++] = nop;
2930 }
2931
2932 if (curr_insn_set != NULL_RTX && n_operands == 2
2933 /* Prevent processing non-move insns. */
2934 && (GET_CODE (SET_SRC (curr_insn_set)) == SUBREG
2935 || SET_SRC (curr_insn_set) == no_subreg_reg_operand[1])
2936 && ((! curr_alt_win[0] && ! curr_alt_win[1]
2937 && REG_P (no_subreg_reg_operand[0])
2938 && REG_P (no_subreg_reg_operand[1])
2939 && (reg_in_class_p (no_subreg_reg_operand[0], curr_alt[1])
2940 || reg_in_class_p (no_subreg_reg_operand[1], curr_alt[0])))
2941 || (! curr_alt_win[0] && curr_alt_win[1]
2942 && REG_P (no_subreg_reg_operand[1])
2943 /* Check that we reload memory not the memory
2944 address. */
2945 && ! (curr_alt_offmemok[0]
2946 && MEM_P (no_subreg_reg_operand[0]))
2947 && reg_in_class_p (no_subreg_reg_operand[1], curr_alt[0]))
2948 || (curr_alt_win[0] && ! curr_alt_win[1]
2949 && REG_P (no_subreg_reg_operand[0])
2950 /* Check that we reload memory not the memory
2951 address. */
2952 && ! (curr_alt_offmemok[1]
2953 && MEM_P (no_subreg_reg_operand[1]))
2954 && reg_in_class_p (no_subreg_reg_operand[0], curr_alt[1])
2955 && (! CONST_POOL_OK_P (curr_operand_mode[1],
2956 no_subreg_reg_operand[1])
2957 || (targetm.preferred_reload_class
2958 (no_subreg_reg_operand[1],
2959 (enum reg_class) curr_alt[1]) != NO_REGS))
2960 /* If it is a result of recent elimination in move
2961 insn we can transform it into an add still by
2962 using this alternative. */
2963 && GET_CODE (no_subreg_reg_operand[1]) != PLUS
2964 /* Likewise if the source has been replaced with an
2965 equivalent value. This only happens once -- the reload
2966 will use the equivalent value instead of the register it
2967 replaces -- so there should be no danger of cycling. */
2968 && !equiv_substition_p[1])))
2969 {
2970 /* We have a move insn and a new reload insn will be similar
2971 to the current insn. We should avoid such situation as
2972 it results in LRA cycling. */
2973 if (lra_dump_file != NULL)
2974 fprintf (lra_dump_file,
2975 " Cycle danger: overall += LRA_MAX_REJECT\n");
2976 overall += LRA_MAX_REJECT;
2977 }
2978 ok_p = true;
2979 curr_alt_dont_inherit_ops_num = 0;
2980 for (nop = 0; nop < early_clobbered_regs_num; nop++)
2981 {
2982 int i, j, clobbered_hard_regno, first_conflict_j, last_conflict_j;
2983 HARD_REG_SET temp_set;
2984
2985 i = early_clobbered_nops[nop];
2986 if ((! curr_alt_win[i] && ! curr_alt_match_win[i])
2987 || hard_regno[i] < 0)
2988 continue;
2989 lra_assert (operand_reg[i] != NULL_RTX);
2990 clobbered_hard_regno = hard_regno[i];
2991 CLEAR_HARD_REG_SET (temp_set);
2992 add_to_hard_reg_set (&temp_set, biggest_mode[i], clobbered_hard_regno);
2993 first_conflict_j = last_conflict_j = -1;
2994 for (j = 0; j < n_operands; j++)
2995 if (j == i
2996 /* We don't want process insides of match_operator and
2997 match_parallel because otherwise we would process
2998 their operands once again generating a wrong
2999 code. */
3000 || curr_static_id->operand[j].is_operator)
3001 continue;
3002 else if ((curr_alt_matches[j] == i && curr_alt_match_win[j])
3003 || (curr_alt_matches[i] == j && curr_alt_match_win[i]))
3004 continue;
3005 /* If we don't reload j-th operand, check conflicts. */
3006 else if ((curr_alt_win[j] || curr_alt_match_win[j])
3007 && uses_hard_regs_p (*curr_id->operand_loc[j], temp_set))
3008 {
3009 if (first_conflict_j < 0)
3010 first_conflict_j = j;
3011 last_conflict_j = j;
3012 /* Both the earlyclobber operand and conflicting operand
3013 cannot both be user defined hard registers. */
3014 if (HARD_REGISTER_P (operand_reg[i])
3015 && REG_USERVAR_P (operand_reg[i])
3016 && operand_reg[j] != NULL_RTX
3017 && HARD_REGISTER_P (operand_reg[j])
3018 && REG_USERVAR_P (operand_reg[j]))
3019 fatal_insn ("unable to generate reloads for "
3020 "impossible constraints:", curr_insn);
3021 }
3022 if (last_conflict_j < 0)
3023 continue;
3024
3025 /* If an earlyclobber operand conflicts with another non-matching
3026 operand (ie, they have been assigned the same hard register),
3027 then it is better to reload the other operand, as there may
3028 exist yet another operand with a matching constraint associated
3029 with the earlyclobber operand. However, if one of the operands
3030 is an explicit use of a hard register, then we must reload the
3031 other non-hard register operand. */
3032 if (HARD_REGISTER_P (operand_reg[i])
3033 || (first_conflict_j == last_conflict_j
3034 && operand_reg[last_conflict_j] != NULL_RTX
3035 && !curr_alt_match_win[last_conflict_j]
3036 && !HARD_REGISTER_P (operand_reg[last_conflict_j])))
3037 {
3038 curr_alt_win[last_conflict_j] = false;
3039 curr_alt_dont_inherit_ops[curr_alt_dont_inherit_ops_num++]
3040 = last_conflict_j;
3041 losers++;
3042 if (lra_dump_file != NULL)
3043 fprintf
3044 (lra_dump_file,
3045 " %d Conflict early clobber reload: reject--\n",
3046 i);
3047 }
3048 else
3049 {
3050 /* We need to reload early clobbered register and the
3051 matched registers. */
3052 for (j = 0; j < n_operands; j++)
3053 if (curr_alt_matches[j] == i)
3054 {
3055 curr_alt_match_win[j] = false;
3056 losers++;
3057 overall += LRA_LOSER_COST_FACTOR;
3058 }
3059 if (! curr_alt_match_win[i])
3060 curr_alt_dont_inherit_ops[curr_alt_dont_inherit_ops_num++] = i;
3061 else
3062 {
3063 /* Remember pseudos used for match reloads are never
3064 inherited. */
3065 lra_assert (curr_alt_matches[i] >= 0);
3066 curr_alt_win[curr_alt_matches[i]] = false;
3067 }
3068 curr_alt_win[i] = curr_alt_match_win[i] = false;
3069 losers++;
3070 if (lra_dump_file != NULL)
3071 fprintf
3072 (lra_dump_file,
3073 " %d Matched conflict early clobber reloads: "
3074 "reject--\n",
3075 i);
3076 }
3077 /* Early clobber was already reflected in REJECT. */
3078 if (!matching_early_clobber[i])
3079 {
3080 lra_assert (reject > 0);
3081 reject--;
3082 matching_early_clobber[i] = 1;
3083 }
3084 overall += LRA_LOSER_COST_FACTOR - 1;
3085 }
3086 if (lra_dump_file != NULL)
3087 fprintf (lra_dump_file, " alt=%d,overall=%d,losers=%d,rld_nregs=%d\n",
3088 nalt, overall, losers, reload_nregs);
3089
3090 /* If this alternative can be made to work by reloading, and it
3091 needs less reloading than the others checked so far, record
3092 it as the chosen goal for reloading. */
3093 if ((best_losers != 0 && losers == 0)
3094 || (((best_losers == 0 && losers == 0)
3095 || (best_losers != 0 && losers != 0))
3096 && (best_overall > overall
3097 || (best_overall == overall
3098 /* If the cost of the reloads is the same,
3099 prefer alternative which requires minimal
3100 number of reload regs. */
3101 && (reload_nregs < best_reload_nregs
3102 || (reload_nregs == best_reload_nregs
3103 && (best_reload_sum < reload_sum
3104 || (best_reload_sum == reload_sum
3105 && nalt < goal_alt_number))))))))
3106 {
3107 for (nop = 0; nop < n_operands; nop++)
3108 {
3109 goal_alt_win[nop] = curr_alt_win[nop];
3110 goal_alt_match_win[nop] = curr_alt_match_win[nop];
3111 goal_alt_matches[nop] = curr_alt_matches[nop];
3112 goal_alt[nop] = curr_alt[nop];
3113 goal_alt_offmemok[nop] = curr_alt_offmemok[nop];
3114 }
3115 goal_alt_dont_inherit_ops_num = curr_alt_dont_inherit_ops_num;
3116 for (nop = 0; nop < curr_alt_dont_inherit_ops_num; nop++)
3117 goal_alt_dont_inherit_ops[nop] = curr_alt_dont_inherit_ops[nop];
3118 goal_alt_swapped = curr_swapped;
3119 best_overall = overall;
3120 best_losers = losers;
3121 best_reload_nregs = reload_nregs;
3122 best_reload_sum = reload_sum;
3123 goal_alt_number = nalt;
3124 }
3125 if (losers == 0)
3126 /* Everything is satisfied. Do not process alternatives
3127 anymore. */
3128 break;
3129 fail:
3130 ;
3131 }
3132 return ok_p;
3133 }
3134
3135 /* Make reload base reg from address AD. */
3136 static rtx
3137 base_to_reg (struct address_info *ad)
3138 {
3139 enum reg_class cl;
3140 int code = -1;
3141 rtx new_inner = NULL_RTX;
3142 rtx new_reg = NULL_RTX;
3143 rtx_insn *insn;
3144 rtx_insn *last_insn = get_last_insn();
3145
3146 lra_assert (ad->disp == ad->disp_term);
3147 cl = base_reg_class (ad->mode, ad->as, ad->base_outer_code,
3148 get_index_code (ad));
3149 new_reg = lra_create_new_reg (GET_MODE (*ad->base), NULL_RTX,
3150 cl, "base");
3151 new_inner = simplify_gen_binary (PLUS, GET_MODE (new_reg), new_reg,
3152 ad->disp_term == NULL
3153 ? const0_rtx
3154 : *ad->disp_term);
3155 if (!valid_address_p (ad->mode, new_inner, ad->as))
3156 return NULL_RTX;
3157 insn = emit_insn (gen_rtx_SET (new_reg, *ad->base));
3158 code = recog_memoized (insn);
3159 if (code < 0)
3160 {
3161 delete_insns_since (last_insn);
3162 return NULL_RTX;
3163 }
3164
3165 return new_inner;
3166 }
3167
3168 /* Make reload base reg + DISP from address AD. Return the new pseudo. */
3169 static rtx
3170 base_plus_disp_to_reg (struct address_info *ad, rtx disp)
3171 {
3172 enum reg_class cl;
3173 rtx new_reg;
3174
3175 lra_assert (ad->base == ad->base_term);
3176 cl = base_reg_class (ad->mode, ad->as, ad->base_outer_code,
3177 get_index_code (ad));
3178 new_reg = lra_create_new_reg (GET_MODE (*ad->base_term), NULL_RTX,
3179 cl, "base + disp");
3180 lra_emit_add (new_reg, *ad->base_term, disp);
3181 return new_reg;
3182 }
3183
3184 /* Make reload of index part of address AD. Return the new
3185 pseudo. */
3186 static rtx
3187 index_part_to_reg (struct address_info *ad)
3188 {
3189 rtx new_reg;
3190
3191 new_reg = lra_create_new_reg (GET_MODE (*ad->index), NULL_RTX,
3192 INDEX_REG_CLASS, "index term");
3193 expand_mult (GET_MODE (*ad->index), *ad->index_term,
3194 GEN_INT (get_index_scale (ad)), new_reg, 1);
3195 return new_reg;
3196 }
3197
3198 /* Return true if we can add a displacement to address AD, even if that
3199 makes the address invalid. The fix-up code requires any new address
3200 to be the sum of the BASE_TERM, INDEX and DISP_TERM fields. */
3201 static bool
3202 can_add_disp_p (struct address_info *ad)
3203 {
3204 return (!ad->autoinc_p
3205 && ad->segment == NULL
3206 && ad->base == ad->base_term
3207 && ad->disp == ad->disp_term);
3208 }
3209
3210 /* Make equiv substitution in address AD. Return true if a substitution
3211 was made. */
3212 static bool
3213 equiv_address_substitution (struct address_info *ad)
3214 {
3215 rtx base_reg, new_base_reg, index_reg, new_index_reg, *base_term, *index_term;
3216 poly_int64 disp;
3217 HOST_WIDE_INT scale;
3218 bool change_p;
3219
3220 base_term = strip_subreg (ad->base_term);
3221 if (base_term == NULL)
3222 base_reg = new_base_reg = NULL_RTX;
3223 else
3224 {
3225 base_reg = *base_term;
3226 new_base_reg = get_equiv_with_elimination (base_reg, curr_insn);
3227 }
3228 index_term = strip_subreg (ad->index_term);
3229 if (index_term == NULL)
3230 index_reg = new_index_reg = NULL_RTX;
3231 else
3232 {
3233 index_reg = *index_term;
3234 new_index_reg = get_equiv_with_elimination (index_reg, curr_insn);
3235 }
3236 if (base_reg == new_base_reg && index_reg == new_index_reg)
3237 return false;
3238 disp = 0;
3239 change_p = false;
3240 if (lra_dump_file != NULL)
3241 {
3242 fprintf (lra_dump_file, "Changing address in insn %d ",
3243 INSN_UID (curr_insn));
3244 dump_value_slim (lra_dump_file, *ad->outer, 1);
3245 }
3246 if (base_reg != new_base_reg)
3247 {
3248 poly_int64 offset;
3249 if (REG_P (new_base_reg))
3250 {
3251 *base_term = new_base_reg;
3252 change_p = true;
3253 }
3254 else if (GET_CODE (new_base_reg) == PLUS
3255 && REG_P (XEXP (new_base_reg, 0))
3256 && poly_int_rtx_p (XEXP (new_base_reg, 1), &offset)
3257 && can_add_disp_p (ad))
3258 {
3259 disp += offset;
3260 *base_term = XEXP (new_base_reg, 0);
3261 change_p = true;
3262 }
3263 if (ad->base_term2 != NULL)
3264 *ad->base_term2 = *ad->base_term;
3265 }
3266 if (index_reg != new_index_reg)
3267 {
3268 poly_int64 offset;
3269 if (REG_P (new_index_reg))
3270 {
3271 *index_term = new_index_reg;
3272 change_p = true;
3273 }
3274 else if (GET_CODE (new_index_reg) == PLUS
3275 && REG_P (XEXP (new_index_reg, 0))
3276 && poly_int_rtx_p (XEXP (new_index_reg, 1), &offset)
3277 && can_add_disp_p (ad)
3278 && (scale = get_index_scale (ad)))
3279 {
3280 disp += offset * scale;
3281 *index_term = XEXP (new_index_reg, 0);
3282 change_p = true;
3283 }
3284 }
3285 if (maybe_ne (disp, 0))
3286 {
3287 if (ad->disp != NULL)
3288 *ad->disp = plus_constant (GET_MODE (*ad->inner), *ad->disp, disp);
3289 else
3290 {
3291 *ad->inner = plus_constant (GET_MODE (*ad->inner), *ad->inner, disp);
3292 update_address (ad);
3293 }
3294 change_p = true;
3295 }
3296 if (lra_dump_file != NULL)
3297 {
3298 if (! change_p)
3299 fprintf (lra_dump_file, " -- no change\n");
3300 else
3301 {
3302 fprintf (lra_dump_file, " on equiv ");
3303 dump_value_slim (lra_dump_file, *ad->outer, 1);
3304 fprintf (lra_dump_file, "\n");
3305 }
3306 }
3307 return change_p;
3308 }
3309
3310 /* Major function to make reloads for an address in operand NOP or
3311 check its correctness (If CHECK_ONLY_P is true). The supported
3312 cases are:
3313
3314 1) an address that existed before LRA started, at which point it
3315 must have been valid. These addresses are subject to elimination
3316 and may have become invalid due to the elimination offset being out
3317 of range.
3318
3319 2) an address created by forcing a constant to memory
3320 (force_const_to_mem). The initial form of these addresses might
3321 not be valid, and it is this function's job to make them valid.
3322
3323 3) a frame address formed from a register and a (possibly zero)
3324 constant offset. As above, these addresses might not be valid and
3325 this function must make them so.
3326
3327 Add reloads to the lists *BEFORE and *AFTER. We might need to add
3328 reloads to *AFTER because of inc/dec, {pre, post} modify in the
3329 address. Return true for any RTL change.
3330
3331 The function is a helper function which does not produce all
3332 transformations (when CHECK_ONLY_P is false) which can be
3333 necessary. It does just basic steps. To do all necessary
3334 transformations use function process_address. */
3335 static bool
3336 process_address_1 (int nop, bool check_only_p,
3337 rtx_insn **before, rtx_insn **after)
3338 {
3339 struct address_info ad;
3340 rtx new_reg;
3341 HOST_WIDE_INT scale;
3342 rtx op = *curr_id->operand_loc[nop];
3343 const char *constraint = curr_static_id->operand[nop].constraint;
3344 enum constraint_num cn = lookup_constraint (constraint);
3345 bool change_p = false;
3346
3347 if (MEM_P (op)
3348 && GET_MODE (op) == BLKmode
3349 && GET_CODE (XEXP (op, 0)) == SCRATCH)
3350 return false;
3351
3352 if (insn_extra_address_constraint (cn)
3353 /* When we find an asm operand with an address constraint that
3354 doesn't satisfy address_operand to begin with, we clear
3355 is_address, so that we don't try to make a non-address fit.
3356 If the asm statement got this far, it's because other
3357 constraints are available, and we'll use them, disregarding
3358 the unsatisfiable address ones. */
3359 && curr_static_id->operand[nop].is_address)
3360 decompose_lea_address (&ad, curr_id->operand_loc[nop]);
3361 /* Do not attempt to decompose arbitrary addresses generated by combine
3362 for asm operands with loose constraints, e.g 'X'. */
3363 else if (MEM_P (op)
3364 && !(INSN_CODE (curr_insn) < 0
3365 && get_constraint_type (cn) == CT_FIXED_FORM
3366 && constraint_satisfied_p (op, cn)))
3367 decompose_mem_address (&ad, op);
3368 else if (GET_CODE (op) == SUBREG
3369 && MEM_P (SUBREG_REG (op)))
3370 decompose_mem_address (&ad, SUBREG_REG (op));
3371 else
3372 return false;
3373 /* If INDEX_REG_CLASS is assigned to base_term already and isn't to
3374 index_term, swap them so to avoid assigning INDEX_REG_CLASS to both
3375 when INDEX_REG_CLASS is a single register class. */
3376 if (ad.base_term != NULL
3377 && ad.index_term != NULL
3378 && ira_class_hard_regs_num[INDEX_REG_CLASS] == 1
3379 && REG_P (*ad.base_term)
3380 && REG_P (*ad.index_term)
3381 && in_class_p (*ad.base_term, INDEX_REG_CLASS, NULL)
3382 && ! in_class_p (*ad.index_term, INDEX_REG_CLASS, NULL))
3383 {
3384 std::swap (ad.base, ad.index);
3385 std::swap (ad.base_term, ad.index_term);
3386 }
3387 if (! check_only_p)
3388 change_p = equiv_address_substitution (&ad);
3389 if (ad.base_term != NULL
3390 && (process_addr_reg
3391 (ad.base_term, check_only_p, before,
3392 (ad.autoinc_p
3393 && !(REG_P (*ad.base_term)
3394 && find_regno_note (curr_insn, REG_DEAD,
3395 REGNO (*ad.base_term)) != NULL_RTX)
3396 ? after : NULL),
3397 base_reg_class (ad.mode, ad.as, ad.base_outer_code,
3398 get_index_code (&ad)))))
3399 {
3400 change_p = true;
3401 if (ad.base_term2 != NULL)
3402 *ad.base_term2 = *ad.base_term;
3403 }
3404 if (ad.index_term != NULL
3405 && process_addr_reg (ad.index_term, check_only_p,
3406 before, NULL, INDEX_REG_CLASS))
3407 change_p = true;
3408
3409 /* Target hooks sometimes don't treat extra-constraint addresses as
3410 legitimate address_operands, so handle them specially. */
3411 if (insn_extra_address_constraint (cn)
3412 && satisfies_address_constraint_p (&ad, cn))
3413 return change_p;
3414
3415 if (check_only_p)
3416 return change_p;
3417
3418 /* There are three cases where the shape of *AD.INNER may now be invalid:
3419
3420 1) the original address was valid, but either elimination or
3421 equiv_address_substitution was applied and that made
3422 the address invalid.
3423
3424 2) the address is an invalid symbolic address created by
3425 force_const_to_mem.
3426
3427 3) the address is a frame address with an invalid offset.
3428
3429 4) the address is a frame address with an invalid base.
3430
3431 All these cases involve a non-autoinc address, so there is no
3432 point revalidating other types. */
3433 if (ad.autoinc_p || valid_address_p (op, &ad, cn))
3434 return change_p;
3435
3436 /* Any index existed before LRA started, so we can assume that the
3437 presence and shape of the index is valid. */
3438 push_to_sequence (*before);
3439 lra_assert (ad.disp == ad.disp_term);
3440 if (ad.base == NULL)
3441 {
3442 if (ad.index == NULL)
3443 {
3444 rtx_insn *insn;
3445 rtx_insn *last = get_last_insn ();
3446 int code = -1;
3447 enum reg_class cl = base_reg_class (ad.mode, ad.as,
3448 SCRATCH, SCRATCH);
3449 rtx addr = *ad.inner;
3450
3451 new_reg = lra_create_new_reg (Pmode, NULL_RTX, cl, "addr");
3452 if (HAVE_lo_sum)
3453 {
3454 /* addr => lo_sum (new_base, addr), case (2) above. */
3455 insn = emit_insn (gen_rtx_SET
3456 (new_reg,
3457 gen_rtx_HIGH (Pmode, copy_rtx (addr))));
3458 code = recog_memoized (insn);
3459 if (code >= 0)
3460 {
3461 *ad.inner = gen_rtx_LO_SUM (Pmode, new_reg, addr);
3462 if (!valid_address_p (op, &ad, cn))
3463 {
3464 /* Try to put lo_sum into register. */
3465 insn = emit_insn (gen_rtx_SET
3466 (new_reg,
3467 gen_rtx_LO_SUM (Pmode, new_reg, addr)));
3468 code = recog_memoized (insn);
3469 if (code >= 0)
3470 {
3471 *ad.inner = new_reg;
3472 if (!valid_address_p (op, &ad, cn))
3473 {
3474 *ad.inner = addr;
3475 code = -1;
3476 }
3477 }
3478
3479 }
3480 }
3481 if (code < 0)
3482 delete_insns_since (last);
3483 }
3484
3485 if (code < 0)
3486 {
3487 /* addr => new_base, case (2) above. */
3488 lra_emit_move (new_reg, addr);
3489
3490 for (insn = last == NULL_RTX ? get_insns () : NEXT_INSN (last);
3491 insn != NULL_RTX;
3492 insn = NEXT_INSN (insn))
3493 if (recog_memoized (insn) < 0)
3494 break;
3495 if (insn != NULL_RTX)
3496 {
3497 /* Do nothing if we cannot generate right insns.
3498 This is analogous to reload pass behavior. */
3499 delete_insns_since (last);
3500 end_sequence ();
3501 return false;
3502 }
3503 *ad.inner = new_reg;
3504 }
3505 }
3506 else
3507 {
3508 /* index * scale + disp => new base + index * scale,
3509 case (1) above. */
3510 enum reg_class cl = base_reg_class (ad.mode, ad.as, PLUS,
3511 GET_CODE (*ad.index));
3512
3513 lra_assert (INDEX_REG_CLASS != NO_REGS);
3514 new_reg = lra_create_new_reg (Pmode, NULL_RTX, cl, "disp");
3515 lra_emit_move (new_reg, *ad.disp);
3516 *ad.inner = simplify_gen_binary (PLUS, GET_MODE (new_reg),
3517 new_reg, *ad.index);
3518 }
3519 }
3520 else if (ad.index == NULL)
3521 {
3522 int regno;
3523 enum reg_class cl;
3524 rtx set;
3525 rtx_insn *insns, *last_insn;
3526 /* Try to reload base into register only if the base is invalid
3527 for the address but with valid offset, case (4) above. */
3528 start_sequence ();
3529 new_reg = base_to_reg (&ad);
3530
3531 /* base + disp => new base, cases (1) and (3) above. */
3532 /* Another option would be to reload the displacement into an
3533 index register. However, postreload has code to optimize
3534 address reloads that have the same base and different
3535 displacements, so reloading into an index register would
3536 not necessarily be a win. */
3537 if (new_reg == NULL_RTX)
3538 {
3539 /* See if the target can split the displacement into a
3540 legitimate new displacement from a local anchor. */
3541 gcc_assert (ad.disp == ad.disp_term);
3542 poly_int64 orig_offset;
3543 rtx offset1, offset2;
3544 if (poly_int_rtx_p (*ad.disp, &orig_offset)
3545 && targetm.legitimize_address_displacement (&offset1, &offset2,
3546 orig_offset,
3547 ad.mode))
3548 {
3549 new_reg = base_plus_disp_to_reg (&ad, offset1);
3550 new_reg = gen_rtx_PLUS (GET_MODE (new_reg), new_reg, offset2);
3551 }
3552 else
3553 new_reg = base_plus_disp_to_reg (&ad, *ad.disp);
3554 }
3555 insns = get_insns ();
3556 last_insn = get_last_insn ();
3557 /* If we generated at least two insns, try last insn source as
3558 an address. If we succeed, we generate one less insn. */
3559 if (REG_P (new_reg)
3560 && last_insn != insns
3561 && (set = single_set (last_insn)) != NULL_RTX
3562 && GET_CODE (SET_SRC (set)) == PLUS
3563 && REG_P (XEXP (SET_SRC (set), 0))
3564 && CONSTANT_P (XEXP (SET_SRC (set), 1)))
3565 {
3566 *ad.inner = SET_SRC (set);
3567 if (valid_address_p (op, &ad, cn))
3568 {
3569 *ad.base_term = XEXP (SET_SRC (set), 0);
3570 *ad.disp_term = XEXP (SET_SRC (set), 1);
3571 cl = base_reg_class (ad.mode, ad.as, ad.base_outer_code,
3572 get_index_code (&ad));
3573 regno = REGNO (*ad.base_term);
3574 if (regno >= FIRST_PSEUDO_REGISTER
3575 && cl != lra_get_allocno_class (regno))
3576 lra_change_class (regno, cl, " Change to", true);
3577 new_reg = SET_SRC (set);
3578 delete_insns_since (PREV_INSN (last_insn));
3579 }
3580 }
3581 end_sequence ();
3582 emit_insn (insns);
3583 *ad.inner = new_reg;
3584 }
3585 else if (ad.disp_term != NULL)
3586 {
3587 /* base + scale * index + disp => new base + scale * index,
3588 case (1) above. */
3589 gcc_assert (ad.disp == ad.disp_term);
3590 new_reg = base_plus_disp_to_reg (&ad, *ad.disp);
3591 *ad.inner = simplify_gen_binary (PLUS, GET_MODE (new_reg),
3592 new_reg, *ad.index);
3593 }
3594 else if ((scale = get_index_scale (&ad)) == 1)
3595 {
3596 /* The last transformation to one reg will be made in
3597 curr_insn_transform function. */
3598 end_sequence ();
3599 return false;
3600 }
3601 else if (scale != 0)
3602 {
3603 /* base + scale * index => base + new_reg,
3604 case (1) above.
3605 Index part of address may become invalid. For example, we
3606 changed pseudo on the equivalent memory and a subreg of the
3607 pseudo onto the memory of different mode for which the scale is
3608 prohibitted. */
3609 new_reg = index_part_to_reg (&ad);
3610 *ad.inner = simplify_gen_binary (PLUS, GET_MODE (new_reg),
3611 *ad.base_term, new_reg);
3612 }
3613 else
3614 {
3615 enum reg_class cl = base_reg_class (ad.mode, ad.as,
3616 SCRATCH, SCRATCH);
3617 rtx addr = *ad.inner;
3618
3619 new_reg = lra_create_new_reg (Pmode, NULL_RTX, cl, "addr");
3620 /* addr => new_base. */
3621 lra_emit_move (new_reg, addr);
3622 *ad.inner = new_reg;
3623 }
3624 *before = get_insns ();
3625 end_sequence ();
3626 return true;
3627 }
3628
3629 /* If CHECK_ONLY_P is false, do address reloads until it is necessary.
3630 Use process_address_1 as a helper function. Return true for any
3631 RTL changes.
3632
3633 If CHECK_ONLY_P is true, just check address correctness. Return
3634 false if the address correct. */
3635 static bool
3636 process_address (int nop, bool check_only_p,
3637 rtx_insn **before, rtx_insn **after)
3638 {
3639 bool res = false;
3640
3641 while (process_address_1 (nop, check_only_p, before, after))
3642 {
3643 if (check_only_p)
3644 return true;
3645 res = true;
3646 }
3647 return res;
3648 }
3649
3650 /* Emit insns to reload VALUE into a new register. VALUE is an
3651 auto-increment or auto-decrement RTX whose operand is a register or
3652 memory location; so reloading involves incrementing that location.
3653 IN is either identical to VALUE, or some cheaper place to reload
3654 value being incremented/decremented from.
3655
3656 INC_AMOUNT is the number to increment or decrement by (always
3657 positive and ignored for POST_MODIFY/PRE_MODIFY).
3658
3659 Return pseudo containing the result. */
3660 static rtx
3661 emit_inc (enum reg_class new_rclass, rtx in, rtx value, poly_int64 inc_amount)
3662 {
3663 /* REG or MEM to be copied and incremented. */
3664 rtx incloc = XEXP (value, 0);
3665 /* Nonzero if increment after copying. */
3666 int post = (GET_CODE (value) == POST_DEC || GET_CODE (value) == POST_INC
3667 || GET_CODE (value) == POST_MODIFY);
3668 rtx_insn *last;
3669 rtx inc;
3670 rtx_insn *add_insn;
3671 int code;
3672 rtx real_in = in == value ? incloc : in;
3673 rtx result;
3674 bool plus_p = true;
3675
3676 if (GET_CODE (value) == PRE_MODIFY || GET_CODE (value) == POST_MODIFY)
3677 {
3678 lra_assert (GET_CODE (XEXP (value, 1)) == PLUS
3679 || GET_CODE (XEXP (value, 1)) == MINUS);
3680 lra_assert (rtx_equal_p (XEXP (XEXP (value, 1), 0), XEXP (value, 0)));
3681 plus_p = GET_CODE (XEXP (value, 1)) == PLUS;
3682 inc = XEXP (XEXP (value, 1), 1);
3683 }
3684 else
3685 {
3686 if (GET_CODE (value) == PRE_DEC || GET_CODE (value) == POST_DEC)
3687 inc_amount = -inc_amount;
3688
3689 inc = gen_int_mode (inc_amount, GET_MODE (value));
3690 }
3691
3692 if (! post && REG_P (incloc))
3693 result = incloc;
3694 else
3695 result = lra_create_new_reg (GET_MODE (value), value, new_rclass,
3696 "INC/DEC result");
3697
3698 if (real_in != result)
3699 {
3700 /* First copy the location to the result register. */
3701 lra_assert (REG_P (result));
3702 emit_insn (gen_move_insn (result, real_in));
3703 }
3704
3705 /* We suppose that there are insns to add/sub with the constant
3706 increment permitted in {PRE/POST)_{DEC/INC/MODIFY}. At least the
3707 old reload worked with this assumption. If the assumption
3708 becomes wrong, we should use approach in function
3709 base_plus_disp_to_reg. */
3710 if (in == value)
3711 {
3712 /* See if we can directly increment INCLOC. */
3713 last = get_last_insn ();
3714 add_insn = emit_insn (plus_p
3715 ? gen_add2_insn (incloc, inc)
3716 : gen_sub2_insn (incloc, inc));
3717
3718 code = recog_memoized (add_insn);
3719 if (code >= 0)
3720 {
3721 if (! post && result != incloc)
3722 emit_insn (gen_move_insn (result, incloc));
3723 return result;
3724 }
3725 delete_insns_since (last);
3726 }
3727
3728 /* If couldn't do the increment directly, must increment in RESULT.
3729 The way we do this depends on whether this is pre- or
3730 post-increment. For pre-increment, copy INCLOC to the reload
3731 register, increment it there, then save back. */
3732 if (! post)
3733 {
3734 if (real_in != result)
3735 emit_insn (gen_move_insn (result, real_in));
3736 if (plus_p)
3737 emit_insn (gen_add2_insn (result, inc));
3738 else
3739 emit_insn (gen_sub2_insn (result, inc));
3740 if (result != incloc)
3741 emit_insn (gen_move_insn (incloc, result));
3742 }
3743 else
3744 {
3745 /* Post-increment.
3746
3747 Because this might be a jump insn or a compare, and because
3748 RESULT may not be available after the insn in an input
3749 reload, we must do the incrementing before the insn being
3750 reloaded for.
3751
3752 We have already copied IN to RESULT. Increment the copy in
3753 RESULT, save that back, then decrement RESULT so it has
3754 the original value. */
3755 if (plus_p)
3756 emit_insn (gen_add2_insn (result, inc));
3757 else
3758 emit_insn (gen_sub2_insn (result, inc));
3759 emit_insn (gen_move_insn (incloc, result));
3760 /* Restore non-modified value for the result. We prefer this
3761 way because it does not require an additional hard
3762 register. */
3763 if (plus_p)
3764 {
3765 poly_int64 offset;
3766 if (poly_int_rtx_p (inc, &offset))
3767 emit_insn (gen_add2_insn (result,
3768 gen_int_mode (-offset,
3769 GET_MODE (result))));
3770 else
3771 emit_insn (gen_sub2_insn (result, inc));
3772 }
3773 else
3774 emit_insn (gen_add2_insn (result, inc));
3775 }
3776 return result;
3777 }
3778
3779 /* Return true if the current move insn does not need processing as we
3780 already know that it satisfies its constraints. */
3781 static bool
3782 simple_move_p (void)
3783 {
3784 rtx dest, src;
3785 enum reg_class dclass, sclass;
3786
3787 lra_assert (curr_insn_set != NULL_RTX);
3788 dest = SET_DEST (curr_insn_set);
3789 src = SET_SRC (curr_insn_set);
3790
3791 /* If the instruction has multiple sets we need to process it even if it
3792 is single_set. This can happen if one or more of the SETs are dead.
3793 See PR73650. */
3794 if (multiple_sets (curr_insn))
3795 return false;
3796
3797 return ((dclass = get_op_class (dest)) != NO_REGS
3798 && (sclass = get_op_class (src)) != NO_REGS
3799 /* The backend guarantees that register moves of cost 2
3800 never need reloads. */
3801 && targetm.register_move_cost (GET_MODE (src), sclass, dclass) == 2);
3802 }
3803
3804 /* Swap operands NOP and NOP + 1. */
3805 static inline void
3806 swap_operands (int nop)
3807 {
3808 std::swap (curr_operand_mode[nop], curr_operand_mode[nop + 1]);
3809 std::swap (original_subreg_reg_mode[nop], original_subreg_reg_mode[nop + 1]);
3810 std::swap (*curr_id->operand_loc[nop], *curr_id->operand_loc[nop + 1]);
3811 std::swap (equiv_substition_p[nop], equiv_substition_p[nop + 1]);
3812 /* Swap the duplicates too. */
3813 lra_update_dup (curr_id, nop);
3814 lra_update_dup (curr_id, nop + 1);
3815 }
3816
3817 /* Main entry point of the constraint code: search the body of the
3818 current insn to choose the best alternative. It is mimicking insn
3819 alternative cost calculation model of former reload pass. That is
3820 because machine descriptions were written to use this model. This
3821 model can be changed in future. Make commutative operand exchange
3822 if it is chosen.
3823
3824 if CHECK_ONLY_P is false, do RTL changes to satisfy the
3825 constraints. Return true if any change happened during function
3826 call.
3827
3828 If CHECK_ONLY_P is true then don't do any transformation. Just
3829 check that the insn satisfies all constraints. If the insn does
3830 not satisfy any constraint, return true. */
3831 static bool
3832 curr_insn_transform (bool check_only_p)
3833 {
3834 int i, j, k;
3835 int n_operands;
3836 int n_alternatives;
3837 int n_outputs;
3838 int commutative;
3839 signed char goal_alt_matched[MAX_RECOG_OPERANDS][MAX_RECOG_OPERANDS];
3840 signed char match_inputs[MAX_RECOG_OPERANDS + 1];
3841 signed char outputs[MAX_RECOG_OPERANDS + 1];
3842 rtx_insn *before, *after;
3843 bool alt_p = false;
3844 /* Flag that the insn has been changed through a transformation. */
3845 bool change_p;
3846 bool sec_mem_p;
3847 bool use_sec_mem_p;
3848 int max_regno_before;
3849 int reused_alternative_num;
3850
3851 curr_insn_set = single_set (curr_insn);
3852 if (curr_insn_set != NULL_RTX && simple_move_p ())
3853 {
3854 /* We assume that the corresponding insn alternative has no
3855 earlier clobbers. If it is not the case, don't define move
3856 cost equal to 2 for the corresponding register classes. */
3857 lra_set_used_insn_alternative (curr_insn, LRA_NON_CLOBBERED_ALT);
3858 return false;
3859 }
3860
3861 no_input_reloads_p = no_output_reloads_p = false;
3862 goal_alt_number = -1;
3863 change_p = sec_mem_p = false;
3864 /* JUMP_INSNs and CALL_INSNs are not allowed to have any output
3865 reloads; neither are insns that SET cc0. Insns that use CC0 are
3866 not allowed to have any input reloads. */
3867 if (JUMP_P (curr_insn) || CALL_P (curr_insn))
3868 no_output_reloads_p = true;
3869
3870 if (HAVE_cc0 && reg_referenced_p (cc0_rtx, PATTERN (curr_insn)))
3871 no_input_reloads_p = true;
3872 if (HAVE_cc0 && reg_set_p (cc0_rtx, PATTERN (curr_insn)))
3873 no_output_reloads_p = true;
3874
3875 n_operands = curr_static_id->n_operands;
3876 n_alternatives = curr_static_id->n_alternatives;
3877
3878 /* Just return "no reloads" if insn has no operands with
3879 constraints. */
3880 if (n_operands == 0 || n_alternatives == 0)
3881 return false;
3882
3883 max_regno_before = max_reg_num ();
3884
3885 for (i = 0; i < n_operands; i++)
3886 {
3887 goal_alt_matched[i][0] = -1;
3888 goal_alt_matches[i] = -1;
3889 }
3890
3891 commutative = curr_static_id->commutative;
3892
3893 /* Now see what we need for pseudos that didn't get hard regs or got
3894 the wrong kind of hard reg. For this, we must consider all the
3895 operands together against the register constraints. */
3896
3897 best_losers = best_overall = INT_MAX;
3898 best_reload_sum = 0;
3899
3900 curr_swapped = false;
3901 goal_alt_swapped = false;
3902
3903 if (! check_only_p)
3904 /* Make equivalence substitution and memory subreg elimination
3905 before address processing because an address legitimacy can
3906 depend on memory mode. */
3907 for (i = 0; i < n_operands; i++)
3908 {
3909 rtx op, subst, old;
3910 bool op_change_p = false;
3911
3912 if (curr_static_id->operand[i].is_operator)
3913 continue;
3914
3915 old = op = *curr_id->operand_loc[i];
3916 if (GET_CODE (old) == SUBREG)
3917 old = SUBREG_REG (old);
3918 subst = get_equiv_with_elimination (old, curr_insn);
3919 original_subreg_reg_mode[i] = VOIDmode;
3920 equiv_substition_p[i] = false;
3921 if (subst != old)
3922 {
3923 equiv_substition_p[i] = true;
3924 subst = copy_rtx (subst);
3925 lra_assert (REG_P (old));
3926 if (GET_CODE (op) != SUBREG)
3927 *curr_id->operand_loc[i] = subst;
3928 else
3929 {
3930 SUBREG_REG (op) = subst;
3931 if (GET_MODE (subst) == VOIDmode)
3932 original_subreg_reg_mode[i] = GET_MODE (old);
3933 }
3934 if (lra_dump_file != NULL)
3935 {
3936 fprintf (lra_dump_file,
3937 "Changing pseudo %d in operand %i of insn %u on equiv ",
3938 REGNO (old), i, INSN_UID (curr_insn));
3939 dump_value_slim (lra_dump_file, subst, 1);
3940 fprintf (lra_dump_file, "\n");
3941 }
3942 op_change_p = change_p = true;
3943 }
3944 if (simplify_operand_subreg (i, GET_MODE (old)) || op_change_p)
3945 {
3946 change_p = true;
3947 lra_update_dup (curr_id, i);
3948 }
3949 }
3950
3951 /* Reload address registers and displacements. We do it before
3952 finding an alternative because of memory constraints. */
3953 before = after = NULL;
3954 for (i = 0; i < n_operands; i++)
3955 if (! curr_static_id->operand[i].is_operator
3956 && process_address (i, check_only_p, &before, &after))
3957 {
3958 if (check_only_p)
3959 return true;
3960 change_p = true;
3961 lra_update_dup (curr_id, i);
3962 }
3963
3964 if (change_p)
3965 /* If we've changed the instruction then any alternative that
3966 we chose previously may no longer be valid. */
3967 lra_set_used_insn_alternative (curr_insn, LRA_UNKNOWN_ALT);
3968
3969 if (! check_only_p && curr_insn_set != NULL_RTX
3970 && check_and_process_move (&change_p, &sec_mem_p))
3971 return change_p;
3972
3973 try_swapped:
3974
3975 reused_alternative_num = check_only_p ? LRA_UNKNOWN_ALT : curr_id->used_insn_alternative;
3976 if (lra_dump_file != NULL && reused_alternative_num >= 0)
3977 fprintf (lra_dump_file, "Reusing alternative %d for insn #%u\n",
3978 reused_alternative_num, INSN_UID (curr_insn));
3979
3980 if (process_alt_operands (reused_alternative_num))
3981 alt_p = true;
3982
3983 if (check_only_p)
3984 return ! alt_p || best_losers != 0;
3985
3986 /* If insn is commutative (it's safe to exchange a certain pair of
3987 operands) then we need to try each alternative twice, the second
3988 time matching those two operands as if we had exchanged them. To
3989 do this, really exchange them in operands.
3990
3991 If we have just tried the alternatives the second time, return
3992 operands to normal and drop through. */
3993
3994 if (reused_alternative_num < 0 && commutative >= 0)
3995 {
3996 curr_swapped = !curr_swapped;
3997 if (curr_swapped)
3998 {
3999 swap_operands (commutative);
4000 goto try_swapped;
4001 }
4002 else
4003 swap_operands (commutative);
4004 }
4005
4006 if (! alt_p && ! sec_mem_p)
4007 {
4008 /* No alternative works with reloads?? */
4009 if (INSN_CODE (curr_insn) >= 0)
4010 fatal_insn ("unable to generate reloads for:", curr_insn);
4011 error_for_asm (curr_insn,
4012 "inconsistent operand constraints in an %<asm%>");
4013 lra_asm_error_p = true;
4014 /* Avoid further trouble with this insn. Don't generate use
4015 pattern here as we could use the insn SP offset. */
4016 lra_set_insn_deleted (curr_insn);
4017 return true;
4018 }
4019
4020 /* If the best alternative is with operands 1 and 2 swapped, swap
4021 them. Update the operand numbers of any reloads already
4022 pushed. */
4023
4024 if (goal_alt_swapped)
4025 {
4026 if (lra_dump_file != NULL)
4027 fprintf (lra_dump_file, " Commutative operand exchange in insn %u\n",
4028 INSN_UID (curr_insn));
4029
4030 /* Swap the duplicates too. */
4031 swap_operands (commutative);
4032 change_p = true;
4033 }
4034
4035 /* Some targets' TARGET_SECONDARY_MEMORY_NEEDED (e.g. x86) are defined
4036 too conservatively. So we use the secondary memory only if there
4037 is no any alternative without reloads. */
4038 use_sec_mem_p = false;
4039 if (! alt_p)
4040 use_sec_mem_p = true;
4041 else if (sec_mem_p)
4042 {
4043 for (i = 0; i < n_operands; i++)
4044 if (! goal_alt_win[i] && ! goal_alt_match_win[i])
4045 break;
4046 use_sec_mem_p = i < n_operands;
4047 }
4048
4049 if (use_sec_mem_p)
4050 {
4051 int in = -1, out = -1;
4052 rtx new_reg, src, dest, rld;
4053 machine_mode sec_mode, rld_mode;
4054
4055 lra_assert (curr_insn_set != NULL_RTX && sec_mem_p);
4056 dest = SET_DEST (curr_insn_set);
4057 src = SET_SRC (curr_insn_set);
4058 for (i = 0; i < n_operands; i++)
4059 if (*curr_id->operand_loc[i] == dest)
4060 out = i;
4061 else if (*curr_id->operand_loc[i] == src)
4062 in = i;
4063 for (i = 0; i < curr_static_id->n_dups; i++)
4064 if (out < 0 && *curr_id->dup_loc[i] == dest)
4065 out = curr_static_id->dup_num[i];
4066 else if (in < 0 && *curr_id->dup_loc[i] == src)
4067 in = curr_static_id->dup_num[i];
4068 lra_assert (out >= 0 && in >= 0
4069 && curr_static_id->operand[out].type == OP_OUT
4070 && curr_static_id->operand[in].type == OP_IN);
4071 rld = partial_subreg_p (GET_MODE (src), GET_MODE (dest)) ? src : dest;
4072 rld_mode = GET_MODE (rld);
4073 sec_mode = targetm.secondary_memory_needed_mode (rld_mode);
4074 new_reg = lra_create_new_reg (sec_mode, NULL_RTX,
4075 NO_REGS, "secondary");
4076 /* If the mode is changed, it should be wider. */
4077 lra_assert (!partial_subreg_p (sec_mode, rld_mode));
4078 if (sec_mode != rld_mode)
4079 {
4080 /* If the target says specifically to use another mode for
4081 secondary memory moves we cannot reuse the original
4082 insn. */
4083 after = emit_spill_move (false, new_reg, dest);
4084 lra_process_new_insns (curr_insn, NULL, after,
4085 "Inserting the sec. move");
4086 /* We may have non null BEFORE here (e.g. after address
4087 processing. */
4088 push_to_sequence (before);
4089 before = emit_spill_move (true, new_reg, src);
4090 emit_insn (before);
4091 before = get_insns ();
4092 end_sequence ();
4093 lra_process_new_insns (curr_insn, before, NULL, "Changing on");
4094 lra_set_insn_deleted (curr_insn);
4095 }
4096 else if (dest == rld)
4097 {
4098 *curr_id->operand_loc[out] = new_reg;
4099 lra_update_dup (curr_id, out);
4100 after = emit_spill_move (false, new_reg, dest);
4101 lra_process_new_insns (curr_insn, NULL, after,
4102 "Inserting the sec. move");
4103 }
4104 else
4105 {
4106 *curr_id->operand_loc[in] = new_reg;
4107 lra_update_dup (curr_id, in);
4108 /* See comments above. */
4109 push_to_sequence (before);
4110 before = emit_spill_move (true, new_reg, src);
4111 emit_insn (before);
4112 before = get_insns ();
4113 end_sequence ();
4114 lra_process_new_insns (curr_insn, before, NULL,
4115 "Inserting the sec. move");
4116 }
4117 lra_update_insn_regno_info (curr_insn);
4118 return true;
4119 }
4120
4121 lra_assert (goal_alt_number >= 0);
4122 lra_set_used_insn_alternative (curr_insn, goal_alt_number);
4123
4124 if (lra_dump_file != NULL)
4125 {
4126 const char *p;
4127
4128 fprintf (lra_dump_file, " Choosing alt %d in insn %u:",
4129 goal_alt_number, INSN_UID (curr_insn));
4130 for (i = 0; i < n_operands; i++)
4131 {
4132 p = (curr_static_id->operand_alternative
4133 [goal_alt_number * n_operands + i].constraint);
4134 if (*p == '\0')
4135 continue;
4136 fprintf (lra_dump_file, " (%d) ", i);
4137 for (; *p != '\0' && *p != ',' && *p != '#'; p++)
4138 fputc (*p, lra_dump_file);
4139 }
4140 if (INSN_CODE (curr_insn) >= 0
4141 && (p = get_insn_name (INSN_CODE (curr_insn))) != NULL)
4142 fprintf (lra_dump_file, " {%s}", p);
4143 if (maybe_ne (curr_id->sp_offset, 0))
4144 {
4145 fprintf (lra_dump_file, " (sp_off=");
4146 print_dec (curr_id->sp_offset, lra_dump_file);
4147 fprintf (lra_dump_file, ")");
4148 }
4149 fprintf (lra_dump_file, "\n");
4150 }
4151
4152 /* Right now, for any pair of operands I and J that are required to
4153 match, with J < I, goal_alt_matches[I] is J. Add I to
4154 goal_alt_matched[J]. */
4155
4156 for (i = 0; i < n_operands; i++)
4157 if ((j = goal_alt_matches[i]) >= 0)
4158 {
4159 for (k = 0; goal_alt_matched[j][k] >= 0; k++)
4160 ;
4161 /* We allow matching one output operand and several input
4162 operands. */
4163 lra_assert (k == 0
4164 || (curr_static_id->operand[j].type == OP_OUT
4165 && curr_static_id->operand[i].type == OP_IN
4166 && (curr_static_id->operand
4167 [goal_alt_matched[j][0]].type == OP_IN)));
4168 goal_alt_matched[j][k] = i;
4169 goal_alt_matched[j][k + 1] = -1;
4170 }
4171
4172 for (i = 0; i < n_operands; i++)
4173 goal_alt_win[i] |= goal_alt_match_win[i];
4174
4175 /* Any constants that aren't allowed and can't be reloaded into
4176 registers are here changed into memory references. */
4177 for (i = 0; i < n_operands; i++)
4178 if (goal_alt_win[i])
4179 {
4180 int regno;
4181 enum reg_class new_class;
4182 rtx reg = *curr_id->operand_loc[i];
4183
4184 if (GET_CODE (reg) == SUBREG)
4185 reg = SUBREG_REG (reg);
4186
4187 if (REG_P (reg) && (regno = REGNO (reg)) >= FIRST_PSEUDO_REGISTER)
4188 {
4189 bool ok_p = in_class_p (reg, goal_alt[i], &new_class);
4190
4191 if (new_class != NO_REGS && get_reg_class (regno) != new_class)
4192 {
4193 lra_assert (ok_p);
4194 lra_change_class (regno, new_class, " Change to", true);
4195 }
4196 }
4197 }
4198 else
4199 {
4200 const char *constraint;
4201 char c;
4202 rtx op = *curr_id->operand_loc[i];
4203 rtx subreg = NULL_RTX;
4204 machine_mode mode = curr_operand_mode[i];
4205
4206 if (GET_CODE (op) == SUBREG)
4207 {
4208 subreg = op;
4209 op = SUBREG_REG (op);
4210 mode = GET_MODE (op);
4211 }
4212
4213 if (CONST_POOL_OK_P (mode, op)
4214 && ((targetm.preferred_reload_class
4215 (op, (enum reg_class) goal_alt[i]) == NO_REGS)
4216 || no_input_reloads_p))
4217 {
4218 rtx tem = force_const_mem (mode, op);
4219
4220 change_p = true;
4221 if (subreg != NULL_RTX)
4222 tem = gen_rtx_SUBREG (mode, tem, SUBREG_BYTE (subreg));
4223
4224 *curr_id->operand_loc[i] = tem;
4225 lra_update_dup (curr_id, i);
4226 process_address (i, false, &before, &after);
4227
4228 /* If the alternative accepts constant pool refs directly
4229 there will be no reload needed at all. */
4230 if (subreg != NULL_RTX)
4231 continue;
4232 /* Skip alternatives before the one requested. */
4233 constraint = (curr_static_id->operand_alternative
4234 [goal_alt_number * n_operands + i].constraint);
4235 for (;
4236 (c = *constraint) && c != ',' && c != '#';
4237 constraint += CONSTRAINT_LEN (c, constraint))
4238 {
4239 enum constraint_num cn = lookup_constraint (constraint);
4240 if ((insn_extra_memory_constraint (cn)
4241 || insn_extra_special_memory_constraint (cn))
4242 && satisfies_memory_constraint_p (tem, cn))
4243 break;
4244 }
4245 if (c == '\0' || c == ',' || c == '#')
4246 continue;
4247
4248 goal_alt_win[i] = true;
4249 }
4250 }
4251
4252 n_outputs = 0;
4253 outputs[0] = -1;
4254 for (i = 0; i < n_operands; i++)
4255 {
4256 int regno;
4257 bool optional_p = false;
4258 rtx old, new_reg;
4259 rtx op = *curr_id->operand_loc[i];
4260
4261 if (goal_alt_win[i])
4262 {
4263 if (goal_alt[i] == NO_REGS
4264 && REG_P (op)
4265 /* When we assign NO_REGS it means that we will not
4266 assign a hard register to the scratch pseudo by
4267 assigment pass and the scratch pseudo will be
4268 spilled. Spilled scratch pseudos are transformed
4269 back to scratches at the LRA end. */
4270 && lra_former_scratch_operand_p (curr_insn, i)
4271 && lra_former_scratch_p (REGNO (op)))
4272 {
4273 int regno = REGNO (op);
4274 lra_change_class (regno, NO_REGS, " Change to", true);
4275 if (lra_get_regno_hard_regno (regno) >= 0)
4276 /* We don't have to mark all insn affected by the
4277 spilled pseudo as there is only one such insn, the
4278 current one. */
4279 reg_renumber[regno] = -1;
4280 lra_assert (bitmap_single_bit_set_p
4281 (&lra_reg_info[REGNO (op)].insn_bitmap));
4282 }
4283 /* We can do an optional reload. If the pseudo got a hard
4284 reg, we might improve the code through inheritance. If
4285 it does not get a hard register we coalesce memory/memory
4286 moves later. Ignore move insns to avoid cycling. */
4287 if (! lra_simple_p
4288 && lra_undo_inheritance_iter < LRA_MAX_INHERITANCE_PASSES
4289 && goal_alt[i] != NO_REGS && REG_P (op)
4290 && (regno = REGNO (op)) >= FIRST_PSEUDO_REGISTER
4291 && regno < new_regno_start
4292 && ! lra_former_scratch_p (regno)
4293 && reg_renumber[regno] < 0
4294 /* Check that the optional reload pseudo will be able to
4295 hold given mode value. */
4296 && ! (prohibited_class_reg_set_mode_p
4297 (goal_alt[i], reg_class_contents[goal_alt[i]],
4298 PSEUDO_REGNO_MODE (regno)))
4299 && (curr_insn_set == NULL_RTX
4300 || !((REG_P (SET_SRC (curr_insn_set))
4301 || MEM_P (SET_SRC (curr_insn_set))
4302 || GET_CODE (SET_SRC (curr_insn_set)) == SUBREG)
4303 && (REG_P (SET_DEST (curr_insn_set))
4304 || MEM_P (SET_DEST (curr_insn_set))
4305 || GET_CODE (SET_DEST (curr_insn_set)) == SUBREG))))
4306 optional_p = true;
4307 else if (goal_alt_matched[i][0] != -1
4308 && curr_static_id->operand[i].type == OP_OUT
4309 && (curr_static_id->operand_alternative
4310 [goal_alt_number * n_operands + i].earlyclobber)
4311 && REG_P (op))
4312 {
4313 for (j = 0; goal_alt_matched[i][j] != -1; j++)
4314 {
4315 rtx op2 = *curr_id->operand_loc[goal_alt_matched[i][j]];
4316
4317 if (REG_P (op2) && REGNO (op) != REGNO (op2))
4318 break;
4319 }
4320 if (goal_alt_matched[i][j] != -1)
4321 {
4322 /* Generate reloads for different output and matched
4323 input registers. This is the easiest way to avoid
4324 creation of non-existing register conflicts in
4325 lra-lives.c. */
4326 match_reload (i, goal_alt_matched[i], outputs, goal_alt[i], &before,
4327 &after, TRUE);
4328 outputs[n_outputs++] = i;
4329 outputs[n_outputs] = -1;
4330 }
4331 continue;
4332 }
4333 else
4334 continue;
4335 }
4336
4337 /* Operands that match previous ones have already been handled. */
4338 if (goal_alt_matches[i] >= 0)
4339 continue;
4340
4341 /* We should not have an operand with a non-offsettable address
4342 appearing where an offsettable address will do. It also may
4343 be a case when the address should be special in other words
4344 not a general one (e.g. it needs no index reg). */
4345 if (goal_alt_matched[i][0] == -1 && goal_alt_offmemok[i] && MEM_P (op))
4346 {
4347 enum reg_class rclass;
4348 rtx *loc = &XEXP (op, 0);
4349 enum rtx_code code = GET_CODE (*loc);
4350
4351 push_to_sequence (before);
4352 rclass = base_reg_class (GET_MODE (op), MEM_ADDR_SPACE (op),
4353 MEM, SCRATCH);
4354 if (GET_RTX_CLASS (code) == RTX_AUTOINC)
4355 new_reg = emit_inc (rclass, *loc, *loc,
4356 /* This value does not matter for MODIFY. */
4357 GET_MODE_SIZE (GET_MODE (op)));
4358 else if (get_reload_reg (OP_IN, Pmode, *loc, rclass, FALSE,
4359 "offsetable address", &new_reg))
4360 {
4361 rtx addr = *loc;
4362 enum rtx_code code = GET_CODE (addr);
4363
4364 if (code == AND && CONST_INT_P (XEXP (addr, 1)))
4365 /* (and ... (const_int -X)) is used to align to X bytes. */
4366 addr = XEXP (*loc, 0);
4367 lra_emit_move (new_reg, addr);
4368 if (addr != *loc)
4369 emit_move_insn (new_reg, gen_rtx_AND (GET_MODE (new_reg), new_reg, XEXP (*loc, 1)));
4370 }
4371 before = get_insns ();
4372 end_sequence ();
4373 *loc = new_reg;
4374 lra_update_dup (curr_id, i);
4375 }
4376 else if (goal_alt_matched[i][0] == -1)
4377 {
4378 machine_mode mode;
4379 rtx reg, *loc;
4380 int hard_regno;
4381 enum op_type type = curr_static_id->operand[i].type;
4382
4383 loc = curr_id->operand_loc[i];
4384 mode = curr_operand_mode[i];
4385 if (GET_CODE (*loc) == SUBREG)
4386 {
4387 reg = SUBREG_REG (*loc);
4388 poly_int64 byte = SUBREG_BYTE (*loc);
4389 if (REG_P (reg)
4390 /* Strict_low_part requires reloading the register and not
4391 just the subreg. Likewise for a strict subreg no wider
4392 than a word for WORD_REGISTER_OPERATIONS targets. */
4393 && (curr_static_id->operand[i].strict_low
4394 || (!paradoxical_subreg_p (mode, GET_MODE (reg))
4395 && (hard_regno
4396 = get_try_hard_regno (REGNO (reg))) >= 0
4397 && (simplify_subreg_regno
4398 (hard_regno,
4399 GET_MODE (reg), byte, mode) < 0)
4400 && (goal_alt[i] == NO_REGS
4401 || (simplify_subreg_regno
4402 (ira_class_hard_regs[goal_alt[i]][0],
4403 GET_MODE (reg), byte, mode) >= 0)))
4404 || (partial_subreg_p (mode, GET_MODE (reg))
4405 && known_le (GET_MODE_SIZE (GET_MODE (reg)),
4406 UNITS_PER_WORD)
4407 && WORD_REGISTER_OPERATIONS)))
4408 {
4409 /* An OP_INOUT is required when reloading a subreg of a
4410 mode wider than a word to ensure that data beyond the
4411 word being reloaded is preserved. Also automatically
4412 ensure that strict_low_part reloads are made into
4413 OP_INOUT which should already be true from the backend
4414 constraints. */
4415 if (type == OP_OUT
4416 && (curr_static_id->operand[i].strict_low
4417 || read_modify_subreg_p (*loc)))
4418 type = OP_INOUT;
4419 loc = &SUBREG_REG (*loc);
4420 mode = GET_MODE (*loc);
4421 }
4422 }
4423 old = *loc;
4424 if (get_reload_reg (type, mode, old, goal_alt[i],
4425 loc != curr_id->operand_loc[i], "", &new_reg)
4426 && type != OP_OUT)
4427 {
4428 push_to_sequence (before);
4429 lra_emit_move (new_reg, old);
4430 before = get_insns ();
4431 end_sequence ();
4432 }
4433 *loc = new_reg;
4434 if (type != OP_IN
4435 && find_reg_note (curr_insn, REG_UNUSED, old) == NULL_RTX)
4436 {
4437 start_sequence ();
4438 lra_emit_move (type == OP_INOUT ? copy_rtx (old) : old, new_reg);
4439 emit_insn (after);
4440 after = get_insns ();
4441 end_sequence ();
4442 *loc = new_reg;
4443 }
4444 for (j = 0; j < goal_alt_dont_inherit_ops_num; j++)
4445 if (goal_alt_dont_inherit_ops[j] == i)
4446 {
4447 lra_set_regno_unique_value (REGNO (new_reg));
4448 break;
4449 }
4450 lra_update_dup (curr_id, i);
4451 }
4452 else if (curr_static_id->operand[i].type == OP_IN
4453 && (curr_static_id->operand[goal_alt_matched[i][0]].type
4454 == OP_OUT
4455 || (curr_static_id->operand[goal_alt_matched[i][0]].type
4456 == OP_INOUT
4457 && (operands_match_p
4458 (*curr_id->operand_loc[i],
4459 *curr_id->operand_loc[goal_alt_matched[i][0]],
4460 -1)))))
4461 {
4462 /* generate reloads for input and matched outputs. */
4463 match_inputs[0] = i;
4464 match_inputs[1] = -1;
4465 match_reload (goal_alt_matched[i][0], match_inputs, outputs,
4466 goal_alt[i], &before, &after,
4467 curr_static_id->operand_alternative
4468 [goal_alt_number * n_operands + goal_alt_matched[i][0]]
4469 .earlyclobber);
4470 }
4471 else if ((curr_static_id->operand[i].type == OP_OUT
4472 || (curr_static_id->operand[i].type == OP_INOUT
4473 && (operands_match_p
4474 (*curr_id->operand_loc[i],
4475 *curr_id->operand_loc[goal_alt_matched[i][0]],
4476 -1))))
4477 && (curr_static_id->operand[goal_alt_matched[i][0]].type
4478 == OP_IN))
4479 /* Generate reloads for output and matched inputs. */
4480 match_reload (i, goal_alt_matched[i], outputs, goal_alt[i], &before,
4481 &after, curr_static_id->operand_alternative
4482 [goal_alt_number * n_operands + i].earlyclobber);
4483 else if (curr_static_id->operand[i].type == OP_IN
4484 && (curr_static_id->operand[goal_alt_matched[i][0]].type
4485 == OP_IN))
4486 {
4487 /* Generate reloads for matched inputs. */
4488 match_inputs[0] = i;
4489 for (j = 0; (k = goal_alt_matched[i][j]) >= 0; j++)
4490 match_inputs[j + 1] = k;
4491 match_inputs[j + 1] = -1;
4492 match_reload (-1, match_inputs, outputs, goal_alt[i], &before,
4493 &after, false);
4494 }
4495 else
4496 /* We must generate code in any case when function
4497 process_alt_operands decides that it is possible. */
4498 gcc_unreachable ();
4499
4500 /* Memorise processed outputs so that output remaining to be processed
4501 can avoid using the same register value (see match_reload). */
4502 if (curr_static_id->operand[i].type == OP_OUT)
4503 {
4504 outputs[n_outputs++] = i;
4505 outputs[n_outputs] = -1;
4506 }
4507
4508 if (optional_p)
4509 {
4510 rtx reg = op;
4511
4512 lra_assert (REG_P (reg));
4513 regno = REGNO (reg);
4514 op = *curr_id->operand_loc[i]; /* Substitution. */
4515 if (GET_CODE (op) == SUBREG)
4516 op = SUBREG_REG (op);
4517 gcc_assert (REG_P (op) && (int) REGNO (op) >= new_regno_start);
4518 bitmap_set_bit (&lra_optional_reload_pseudos, REGNO (op));
4519 lra_reg_info[REGNO (op)].restore_rtx = reg;
4520 if (lra_dump_file != NULL)
4521 fprintf (lra_dump_file,
4522 " Making reload reg %d for reg %d optional\n",
4523 REGNO (op), regno);
4524 }
4525 }
4526 if (before != NULL_RTX || after != NULL_RTX
4527 || max_regno_before != max_reg_num ())
4528 change_p = true;
4529 if (change_p)
4530 {
4531 lra_update_operator_dups (curr_id);
4532 /* Something changes -- process the insn. */
4533 lra_update_insn_regno_info (curr_insn);
4534 }
4535 lra_process_new_insns (curr_insn, before, after, "Inserting insn reload");
4536 return change_p;
4537 }
4538
4539 /* Return true if INSN satisfies all constraints. In other words, no
4540 reload insns are needed. */
4541 bool
4542 lra_constrain_insn (rtx_insn *insn)
4543 {
4544 int saved_new_regno_start = new_regno_start;
4545 int saved_new_insn_uid_start = new_insn_uid_start;
4546 bool change_p;
4547
4548 curr_insn = insn;
4549 curr_id = lra_get_insn_recog_data (curr_insn);
4550 curr_static_id = curr_id->insn_static_data;
4551 new_insn_uid_start = get_max_uid ();
4552 new_regno_start = max_reg_num ();
4553 change_p = curr_insn_transform (true);
4554 new_regno_start = saved_new_regno_start;
4555 new_insn_uid_start = saved_new_insn_uid_start;
4556 return ! change_p;
4557 }
4558
4559 /* Return true if X is in LIST. */
4560 static bool
4561 in_list_p (rtx x, rtx list)
4562 {
4563 for (; list != NULL_RTX; list = XEXP (list, 1))
4564 if (XEXP (list, 0) == x)
4565 return true;
4566 return false;
4567 }
4568
4569 /* Return true if X contains an allocatable hard register (if
4570 HARD_REG_P) or a (spilled if SPILLED_P) pseudo. */
4571 static bool
4572 contains_reg_p (rtx x, bool hard_reg_p, bool spilled_p)
4573 {
4574 int i, j;
4575 const char *fmt;
4576 enum rtx_code code;
4577
4578 code = GET_CODE (x);
4579 if (REG_P (x))
4580 {
4581 int regno = REGNO (x);
4582 HARD_REG_SET alloc_regs;
4583
4584 if (hard_reg_p)
4585 {
4586 if (regno >= FIRST_PSEUDO_REGISTER)
4587 regno = lra_get_regno_hard_regno (regno);
4588 if (regno < 0)
4589 return false;
4590 alloc_regs = ~lra_no_alloc_regs;
4591 return overlaps_hard_reg_set_p (alloc_regs, GET_MODE (x), regno);
4592 }
4593 else
4594 {
4595 if (regno < FIRST_PSEUDO_REGISTER)
4596 return false;
4597 if (! spilled_p)
4598 return true;
4599 return lra_get_regno_hard_regno (regno) < 0;
4600 }
4601 }
4602 fmt = GET_RTX_FORMAT (code);
4603 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
4604 {
4605 if (fmt[i] == 'e')
4606 {
4607 if (contains_reg_p (XEXP (x, i), hard_reg_p, spilled_p))
4608 return true;
4609 }
4610 else if (fmt[i] == 'E')
4611 {
4612 for (j = XVECLEN (x, i) - 1; j >= 0; j--)
4613 if (contains_reg_p (XVECEXP (x, i, j), hard_reg_p, spilled_p))
4614 return true;
4615 }
4616 }
4617 return false;
4618 }
4619
4620 /* Process all regs in location *LOC and change them on equivalent
4621 substitution. Return true if any change was done. */
4622 static bool
4623 loc_equivalence_change_p (rtx *loc)
4624 {
4625 rtx subst, reg, x = *loc;
4626 bool result = false;
4627 enum rtx_code code = GET_CODE (x);
4628 const char *fmt;
4629 int i, j;
4630
4631 if (code == SUBREG)
4632 {
4633 reg = SUBREG_REG (x);
4634 if ((subst = get_equiv_with_elimination (reg, curr_insn)) != reg
4635 && GET_MODE (subst) == VOIDmode)
4636 {
4637 /* We cannot reload debug location. Simplify subreg here
4638 while we know the inner mode. */
4639 *loc = simplify_gen_subreg (GET_MODE (x), subst,
4640 GET_MODE (reg), SUBREG_BYTE (x));
4641 return true;
4642 }
4643 }
4644 if (code == REG && (subst = get_equiv_with_elimination (x, curr_insn)) != x)
4645 {
4646 *loc = subst;
4647 return true;
4648 }
4649
4650 /* Scan all the operand sub-expressions. */
4651 fmt = GET_RTX_FORMAT (code);
4652 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
4653 {
4654 if (fmt[i] == 'e')
4655 result = loc_equivalence_change_p (&XEXP (x, i)) || result;
4656 else if (fmt[i] == 'E')
4657 for (j = XVECLEN (x, i) - 1; j >= 0; j--)
4658 result
4659 = loc_equivalence_change_p (&XVECEXP (x, i, j)) || result;
4660 }
4661 return result;
4662 }
4663
4664 /* Similar to loc_equivalence_change_p, but for use as
4665 simplify_replace_fn_rtx callback. DATA is insn for which the
4666 elimination is done. If it null we don't do the elimination. */
4667 static rtx
4668 loc_equivalence_callback (rtx loc, const_rtx, void *data)
4669 {
4670 if (!REG_P (loc))
4671 return NULL_RTX;
4672
4673 rtx subst = (data == NULL
4674 ? get_equiv (loc) : get_equiv_with_elimination (loc, (rtx_insn *) data));
4675 if (subst != loc)
4676 return subst;
4677
4678 return NULL_RTX;
4679 }
4680
4681 /* Maximum number of generated reload insns per an insn. It is for
4682 preventing this pass cycling in a bug case. */
4683 #define MAX_RELOAD_INSNS_NUMBER LRA_MAX_INSN_RELOADS
4684
4685 /* The current iteration number of this LRA pass. */
4686 int lra_constraint_iter;
4687
4688 /* True if we should during assignment sub-pass check assignment
4689 correctness for all pseudos and spill some of them to correct
4690 conflicts. It can be necessary when we substitute equiv which
4691 needs checking register allocation correctness because the
4692 equivalent value contains allocatable hard registers, or when we
4693 restore multi-register pseudo, or when we change the insn code and
4694 its operand became INOUT operand when it was IN one before. */
4695 bool check_and_force_assignment_correctness_p;
4696
4697 /* Return true if REGNO is referenced in more than one block. */
4698 static bool
4699 multi_block_pseudo_p (int regno)
4700 {
4701 basic_block bb = NULL;
4702 unsigned int uid;
4703 bitmap_iterator bi;
4704
4705 if (regno < FIRST_PSEUDO_REGISTER)
4706 return false;
4707
4708 EXECUTE_IF_SET_IN_BITMAP (&lra_reg_info[regno].insn_bitmap, 0, uid, bi)
4709 if (bb == NULL)
4710 bb = BLOCK_FOR_INSN (lra_insn_recog_data[uid]->insn);
4711 else if (BLOCK_FOR_INSN (lra_insn_recog_data[uid]->insn) != bb)
4712 return true;
4713 return false;
4714 }
4715
4716 /* Return true if LIST contains a deleted insn. */
4717 static bool
4718 contains_deleted_insn_p (rtx_insn_list *list)
4719 {
4720 for (; list != NULL_RTX; list = list->next ())
4721 if (NOTE_P (list->insn ())
4722 && NOTE_KIND (list->insn ()) == NOTE_INSN_DELETED)
4723 return true;
4724 return false;
4725 }
4726
4727 /* Return true if X contains a pseudo dying in INSN. */
4728 static bool
4729 dead_pseudo_p (rtx x, rtx_insn *insn)
4730 {
4731 int i, j;
4732 const char *fmt;
4733 enum rtx_code code;
4734
4735 if (REG_P (x))
4736 return (insn != NULL_RTX
4737 && find_regno_note (insn, REG_DEAD, REGNO (x)) != NULL_RTX);
4738 code = GET_CODE (x);
4739 fmt = GET_RTX_FORMAT (code);
4740 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
4741 {
4742 if (fmt[i] == 'e')
4743 {
4744 if (dead_pseudo_p (XEXP (x, i), insn))
4745 return true;
4746 }
4747 else if (fmt[i] == 'E')
4748 {
4749 for (j = XVECLEN (x, i) - 1; j >= 0; j--)
4750 if (dead_pseudo_p (XVECEXP (x, i, j), insn))
4751 return true;
4752 }
4753 }
4754 return false;
4755 }
4756
4757 /* Return true if INSN contains a dying pseudo in INSN right hand
4758 side. */
4759 static bool
4760 insn_rhs_dead_pseudo_p (rtx_insn *insn)
4761 {
4762 rtx set = single_set (insn);
4763
4764 gcc_assert (set != NULL);
4765 return dead_pseudo_p (SET_SRC (set), insn);
4766 }
4767
4768 /* Return true if any init insn of REGNO contains a dying pseudo in
4769 insn right hand side. */
4770 static bool
4771 init_insn_rhs_dead_pseudo_p (int regno)
4772 {
4773 rtx_insn_list *insns = ira_reg_equiv[regno].init_insns;
4774
4775 if (insns == NULL)
4776 return false;
4777 for (; insns != NULL_RTX; insns = insns->next ())
4778 if (insn_rhs_dead_pseudo_p (insns->insn ()))
4779 return true;
4780 return false;
4781 }
4782
4783 /* Return TRUE if REGNO has a reverse equivalence. The equivalence is
4784 reverse only if we have one init insn with given REGNO as a
4785 source. */
4786 static bool
4787 reverse_equiv_p (int regno)
4788 {
4789 rtx_insn_list *insns = ira_reg_equiv[regno].init_insns;
4790 rtx set;
4791
4792 if (insns == NULL)
4793 return false;
4794 if (! INSN_P (insns->insn ())
4795 || insns->next () != NULL)
4796 return false;
4797 if ((set = single_set (insns->insn ())) == NULL_RTX)
4798 return false;
4799 return REG_P (SET_SRC (set)) && (int) REGNO (SET_SRC (set)) == regno;
4800 }
4801
4802 /* Return TRUE if REGNO was reloaded in an equivalence init insn. We
4803 call this function only for non-reverse equivalence. */
4804 static bool
4805 contains_reloaded_insn_p (int regno)
4806 {
4807 rtx set;
4808 rtx_insn_list *list = ira_reg_equiv[regno].init_insns;
4809
4810 for (; list != NULL; list = list->next ())
4811 if ((set = single_set (list->insn ())) == NULL_RTX
4812 || ! REG_P (SET_DEST (set))
4813 || (int) REGNO (SET_DEST (set)) != regno)
4814 return true;
4815 return false;
4816 }
4817
4818 /* Entry function of LRA constraint pass. Return true if the
4819 constraint pass did change the code. */
4820 bool
4821 lra_constraints (bool first_p)
4822 {
4823 bool changed_p;
4824 int i, hard_regno, new_insns_num;
4825 unsigned int min_len, new_min_len, uid;
4826 rtx set, x, reg, dest_reg;
4827 basic_block last_bb;
4828 bitmap_iterator bi;
4829
4830 lra_constraint_iter++;
4831 if (lra_dump_file != NULL)
4832 fprintf (lra_dump_file, "\n********** Local #%d: **********\n\n",
4833 lra_constraint_iter);
4834 changed_p = false;
4835 if (pic_offset_table_rtx
4836 && REGNO (pic_offset_table_rtx) >= FIRST_PSEUDO_REGISTER)
4837 check_and_force_assignment_correctness_p = true;
4838 else if (first_p)
4839 /* On the first iteration we should check IRA assignment
4840 correctness. In rare cases, the assignments can be wrong as
4841 early clobbers operands are ignored in IRA or usages of
4842 paradoxical sub-registers are not taken into account by
4843 IRA. */
4844 check_and_force_assignment_correctness_p = true;
4845 new_insn_uid_start = get_max_uid ();
4846 new_regno_start = first_p ? lra_constraint_new_regno_start : max_reg_num ();
4847 /* Mark used hard regs for target stack size calulations. */
4848 for (i = FIRST_PSEUDO_REGISTER; i < new_regno_start; i++)
4849 if (lra_reg_info[i].nrefs != 0
4850 && (hard_regno = lra_get_regno_hard_regno (i)) >= 0)
4851 {
4852 int j, nregs;
4853
4854 nregs = hard_regno_nregs (hard_regno, lra_reg_info[i].biggest_mode);
4855 for (j = 0; j < nregs; j++)
4856 df_set_regs_ever_live (hard_regno + j, true);
4857 }
4858 /* Do elimination before the equivalence processing as we can spill
4859 some pseudos during elimination. */
4860 lra_eliminate (false, first_p);
4861 auto_bitmap equiv_insn_bitmap (&reg_obstack);
4862 for (i = FIRST_PSEUDO_REGISTER; i < new_regno_start; i++)
4863 if (lra_reg_info[i].nrefs != 0)
4864 {
4865 ira_reg_equiv[i].profitable_p = true;
4866 reg = regno_reg_rtx[i];
4867 if (lra_get_regno_hard_regno (i) < 0 && (x = get_equiv (reg)) != reg)
4868 {
4869 bool pseudo_p = contains_reg_p (x, false, false);
4870
4871 /* After RTL transformation, we cannot guarantee that
4872 pseudo in the substitution was not reloaded which might
4873 make equivalence invalid. For example, in reverse
4874 equiv of p0
4875
4876 p0 <- ...
4877 ...
4878 equiv_mem <- p0
4879
4880 the memory address register was reloaded before the 2nd
4881 insn. */
4882 if ((! first_p && pseudo_p)
4883 /* We don't use DF for compilation speed sake. So it
4884 is problematic to update live info when we use an
4885 equivalence containing pseudos in more than one
4886 BB. */
4887 || (pseudo_p && multi_block_pseudo_p (i))
4888 /* If an init insn was deleted for some reason, cancel
4889 the equiv. We could update the equiv insns after
4890 transformations including an equiv insn deletion
4891 but it is not worthy as such cases are extremely
4892 rare. */
4893 || contains_deleted_insn_p (ira_reg_equiv[i].init_insns)
4894 /* If it is not a reverse equivalence, we check that a
4895 pseudo in rhs of the init insn is not dying in the
4896 insn. Otherwise, the live info at the beginning of
4897 the corresponding BB might be wrong after we
4898 removed the insn. When the equiv can be a
4899 constant, the right hand side of the init insn can
4900 be a pseudo. */
4901 || (! reverse_equiv_p (i)
4902 && (init_insn_rhs_dead_pseudo_p (i)
4903 /* If we reloaded the pseudo in an equivalence
4904 init insn, we cannot remove the equiv init
4905 insns and the init insns might write into
4906 const memory in this case. */
4907 || contains_reloaded_insn_p (i)))
4908 /* Prevent access beyond equivalent memory for
4909 paradoxical subregs. */
4910 || (MEM_P (x)
4911 && maybe_gt (GET_MODE_SIZE (lra_reg_info[i].biggest_mode),
4912 GET_MODE_SIZE (GET_MODE (x))))
4913 || (pic_offset_table_rtx
4914 && ((CONST_POOL_OK_P (PSEUDO_REGNO_MODE (i), x)
4915 && (targetm.preferred_reload_class
4916 (x, lra_get_allocno_class (i)) == NO_REGS))
4917 || contains_symbol_ref_p (x))))
4918 ira_reg_equiv[i].defined_p = false;
4919 if (contains_reg_p (x, false, true))
4920 ira_reg_equiv[i].profitable_p = false;
4921 if (get_equiv (reg) != reg)
4922 bitmap_ior_into (equiv_insn_bitmap, &lra_reg_info[i].insn_bitmap);
4923 }
4924 }
4925 for (i = FIRST_PSEUDO_REGISTER; i < new_regno_start; i++)
4926 update_equiv (i);
4927 /* We should add all insns containing pseudos which should be
4928 substituted by their equivalences. */
4929 EXECUTE_IF_SET_IN_BITMAP (equiv_insn_bitmap, 0, uid, bi)
4930 lra_push_insn_by_uid (uid);
4931 min_len = lra_insn_stack_length ();
4932 new_insns_num = 0;
4933 last_bb = NULL;
4934 changed_p = false;
4935 while ((new_min_len = lra_insn_stack_length ()) != 0)
4936 {
4937 curr_insn = lra_pop_insn ();
4938 --new_min_len;
4939 curr_bb = BLOCK_FOR_INSN (curr_insn);
4940 if (curr_bb != last_bb)
4941 {
4942 last_bb = curr_bb;
4943 bb_reload_num = lra_curr_reload_num;
4944 }
4945 if (min_len > new_min_len)
4946 {
4947 min_len = new_min_len;
4948 new_insns_num = 0;
4949 }
4950 if (new_insns_num > MAX_RELOAD_INSNS_NUMBER)
4951 internal_error
4952 ("maximum number of generated reload insns per insn achieved (%d)",
4953 MAX_RELOAD_INSNS_NUMBER);
4954 new_insns_num++;
4955 if (DEBUG_INSN_P (curr_insn))
4956 {
4957 /* We need to check equivalence in debug insn and change
4958 pseudo to the equivalent value if necessary. */
4959 curr_id = lra_get_insn_recog_data (curr_insn);
4960 if (bitmap_bit_p (equiv_insn_bitmap, INSN_UID (curr_insn)))
4961 {
4962 rtx old = *curr_id->operand_loc[0];
4963 *curr_id->operand_loc[0]
4964 = simplify_replace_fn_rtx (old, NULL_RTX,
4965 loc_equivalence_callback, curr_insn);
4966 if (old != *curr_id->operand_loc[0])
4967 {
4968 lra_update_insn_regno_info (curr_insn);
4969 changed_p = true;
4970 }
4971 }
4972 }
4973 else if (INSN_P (curr_insn))
4974 {
4975 if ((set = single_set (curr_insn)) != NULL_RTX)
4976 {
4977 dest_reg = SET_DEST (set);
4978 /* The equivalence pseudo could be set up as SUBREG in a
4979 case when it is a call restore insn in a mode
4980 different from the pseudo mode. */
4981 if (GET_CODE (dest_reg) == SUBREG)
4982 dest_reg = SUBREG_REG (dest_reg);
4983 if ((REG_P (dest_reg)
4984 && (x = get_equiv (dest_reg)) != dest_reg
4985 /* Remove insns which set up a pseudo whose value
4986 cannot be changed. Such insns might be not in
4987 init_insns because we don't update equiv data
4988 during insn transformations.
4989
4990 As an example, let suppose that a pseudo got
4991 hard register and on the 1st pass was not
4992 changed to equivalent constant. We generate an
4993 additional insn setting up the pseudo because of
4994 secondary memory movement. Then the pseudo is
4995 spilled and we use the equiv constant. In this
4996 case we should remove the additional insn and
4997 this insn is not init_insns list. */
4998 && (! MEM_P (x) || MEM_READONLY_P (x)
4999 /* Check that this is actually an insn setting
5000 up the equivalence. */
5001 || in_list_p (curr_insn,
5002 ira_reg_equiv
5003 [REGNO (dest_reg)].init_insns)))
5004 || (((x = get_equiv (SET_SRC (set))) != SET_SRC (set))
5005 && in_list_p (curr_insn,
5006 ira_reg_equiv
5007 [REGNO (SET_SRC (set))].init_insns)))
5008 {
5009 /* This is equiv init insn of pseudo which did not get a
5010 hard register -- remove the insn. */
5011 if (lra_dump_file != NULL)
5012 {
5013 fprintf (lra_dump_file,
5014 " Removing equiv init insn %i (freq=%d)\n",
5015 INSN_UID (curr_insn),
5016 REG_FREQ_FROM_BB (BLOCK_FOR_INSN (curr_insn)));
5017 dump_insn_slim (lra_dump_file, curr_insn);
5018 }
5019 if (contains_reg_p (x, true, false))
5020 check_and_force_assignment_correctness_p = true;
5021 lra_set_insn_deleted (curr_insn);
5022 continue;
5023 }
5024 }
5025 curr_id = lra_get_insn_recog_data (curr_insn);
5026 curr_static_id = curr_id->insn_static_data;
5027 init_curr_insn_input_reloads ();
5028 init_curr_operand_mode ();
5029 if (curr_insn_transform (false))
5030 changed_p = true;
5031 /* Check non-transformed insns too for equiv change as USE
5032 or CLOBBER don't need reloads but can contain pseudos
5033 being changed on their equivalences. */
5034 else if (bitmap_bit_p (equiv_insn_bitmap, INSN_UID (curr_insn))
5035 && loc_equivalence_change_p (&PATTERN (curr_insn)))
5036 {
5037 lra_update_insn_regno_info (curr_insn);
5038 changed_p = true;
5039 }
5040 }
5041 }
5042
5043 /* If we used a new hard regno, changed_p should be true because the
5044 hard reg is assigned to a new pseudo. */
5045 if (flag_checking && !changed_p)
5046 {
5047 for (i = FIRST_PSEUDO_REGISTER; i < new_regno_start; i++)
5048 if (lra_reg_info[i].nrefs != 0
5049 && (hard_regno = lra_get_regno_hard_regno (i)) >= 0)
5050 {
5051 int j, nregs = hard_regno_nregs (hard_regno,
5052 PSEUDO_REGNO_MODE (i));
5053
5054 for (j = 0; j < nregs; j++)
5055 lra_assert (df_regs_ever_live_p (hard_regno + j));
5056 }
5057 }
5058 return changed_p;
5059 }
5060
5061 static void initiate_invariants (void);
5062 static void finish_invariants (void);
5063
5064 /* Initiate the LRA constraint pass. It is done once per
5065 function. */
5066 void
5067 lra_constraints_init (void)
5068 {
5069 initiate_invariants ();
5070 }
5071
5072 /* Finalize the LRA constraint pass. It is done once per
5073 function. */
5074 void
5075 lra_constraints_finish (void)
5076 {
5077 finish_invariants ();
5078 }
5079
5080 \f
5081
5082 /* Structure describes invariants for ineheritance. */
5083 struct lra_invariant
5084 {
5085 /* The order number of the invariant. */
5086 int num;
5087 /* The invariant RTX. */
5088 rtx invariant_rtx;
5089 /* The origin insn of the invariant. */
5090 rtx_insn *insn;
5091 };
5092
5093 typedef lra_invariant invariant_t;
5094 typedef invariant_t *invariant_ptr_t;
5095 typedef const invariant_t *const_invariant_ptr_t;
5096
5097 /* Pointer to the inheritance invariants. */
5098 static vec<invariant_ptr_t> invariants;
5099
5100 /* Allocation pool for the invariants. */
5101 static object_allocator<lra_invariant> *invariants_pool;
5102
5103 /* Hash table for the invariants. */
5104 static htab_t invariant_table;
5105
5106 /* Hash function for INVARIANT. */
5107 static hashval_t
5108 invariant_hash (const void *invariant)
5109 {
5110 rtx inv = ((const_invariant_ptr_t) invariant)->invariant_rtx;
5111 return lra_rtx_hash (inv);
5112 }
5113
5114 /* Equal function for invariants INVARIANT1 and INVARIANT2. */
5115 static int
5116 invariant_eq_p (const void *invariant1, const void *invariant2)
5117 {
5118 rtx inv1 = ((const_invariant_ptr_t) invariant1)->invariant_rtx;
5119 rtx inv2 = ((const_invariant_ptr_t) invariant2)->invariant_rtx;
5120
5121 return rtx_equal_p (inv1, inv2);
5122 }
5123
5124 /* Insert INVARIANT_RTX into the table if it is not there yet. Return
5125 invariant which is in the table. */
5126 static invariant_ptr_t
5127 insert_invariant (rtx invariant_rtx)
5128 {
5129 void **entry_ptr;
5130 invariant_t invariant;
5131 invariant_ptr_t invariant_ptr;
5132
5133 invariant.invariant_rtx = invariant_rtx;
5134 entry_ptr = htab_find_slot (invariant_table, &invariant, INSERT);
5135 if (*entry_ptr == NULL)
5136 {
5137 invariant_ptr = invariants_pool->allocate ();
5138 invariant_ptr->invariant_rtx = invariant_rtx;
5139 invariant_ptr->insn = NULL;
5140 invariants.safe_push (invariant_ptr);
5141 *entry_ptr = (void *) invariant_ptr;
5142 }
5143 return (invariant_ptr_t) *entry_ptr;
5144 }
5145
5146 /* Initiate the invariant table. */
5147 static void
5148 initiate_invariants (void)
5149 {
5150 invariants.create (100);
5151 invariants_pool
5152 = new object_allocator<lra_invariant> ("Inheritance invariants");
5153 invariant_table = htab_create (100, invariant_hash, invariant_eq_p, NULL);
5154 }
5155
5156 /* Finish the invariant table. */
5157 static void
5158 finish_invariants (void)
5159 {
5160 htab_delete (invariant_table);
5161 delete invariants_pool;
5162 invariants.release ();
5163 }
5164
5165 /* Make the invariant table empty. */
5166 static void
5167 clear_invariants (void)
5168 {
5169 htab_empty (invariant_table);
5170 invariants_pool->release ();
5171 invariants.truncate (0);
5172 }
5173
5174 \f
5175
5176 /* This page contains code to do inheritance/split
5177 transformations. */
5178
5179 /* Number of reloads passed so far in current EBB. */
5180 static int reloads_num;
5181
5182 /* Number of calls passed so far in current EBB. */
5183 static int calls_num;
5184
5185 /* Index ID is the CALLS_NUM associated the last call we saw with
5186 ABI identifier ID. */
5187 static int last_call_for_abi[NUM_ABI_IDS];
5188
5189 /* Which registers have been fully or partially clobbered by a call
5190 since they were last used. */
5191 static HARD_REG_SET full_and_partial_call_clobbers;
5192
5193 /* Current reload pseudo check for validity of elements in
5194 USAGE_INSNS. */
5195 static int curr_usage_insns_check;
5196
5197 /* Info about last usage of registers in EBB to do inheritance/split
5198 transformation. Inheritance transformation is done from a spilled
5199 pseudo and split transformations from a hard register or a pseudo
5200 assigned to a hard register. */
5201 struct usage_insns
5202 {
5203 /* If the value is equal to CURR_USAGE_INSNS_CHECK, then the member
5204 value INSNS is valid. The insns is chain of optional debug insns
5205 and a finishing non-debug insn using the corresponding reg. The
5206 value is also used to mark the registers which are set up in the
5207 current insn. The negated insn uid is used for this. */
5208 int check;
5209 /* Value of global reloads_num at the last insn in INSNS. */
5210 int reloads_num;
5211 /* Value of global reloads_nums at the last insn in INSNS. */
5212 int calls_num;
5213 /* It can be true only for splitting. And it means that the restore
5214 insn should be put after insn given by the following member. */
5215 bool after_p;
5216 /* Next insns in the current EBB which use the original reg and the
5217 original reg value is not changed between the current insn and
5218 the next insns. In order words, e.g. for inheritance, if we need
5219 to use the original reg value again in the next insns we can try
5220 to use the value in a hard register from a reload insn of the
5221 current insn. */
5222 rtx insns;
5223 };
5224
5225 /* Map: regno -> corresponding pseudo usage insns. */
5226 static struct usage_insns *usage_insns;
5227
5228 static void
5229 setup_next_usage_insn (int regno, rtx insn, int reloads_num, bool after_p)
5230 {
5231 usage_insns[regno].check = curr_usage_insns_check;
5232 usage_insns[regno].insns = insn;
5233 usage_insns[regno].reloads_num = reloads_num;
5234 usage_insns[regno].calls_num = calls_num;
5235 usage_insns[regno].after_p = after_p;
5236 if (regno >= FIRST_PSEUDO_REGISTER && reg_renumber[regno] >= 0)
5237 remove_from_hard_reg_set (&full_and_partial_call_clobbers,
5238 PSEUDO_REGNO_MODE (regno),
5239 reg_renumber[regno]);
5240 }
5241
5242 /* The function is used to form list REGNO usages which consists of
5243 optional debug insns finished by a non-debug insn using REGNO.
5244 RELOADS_NUM is current number of reload insns processed so far. */
5245 static void
5246 add_next_usage_insn (int regno, rtx_insn *insn, int reloads_num)
5247 {
5248 rtx next_usage_insns;
5249
5250 if (usage_insns[regno].check == curr_usage_insns_check
5251 && (next_usage_insns = usage_insns[regno].insns) != NULL_RTX
5252 && DEBUG_INSN_P (insn))
5253 {
5254 /* Check that we did not add the debug insn yet. */
5255 if (next_usage_insns != insn
5256 && (GET_CODE (next_usage_insns) != INSN_LIST
5257 || XEXP (next_usage_insns, 0) != insn))
5258 usage_insns[regno].insns = gen_rtx_INSN_LIST (VOIDmode, insn,
5259 next_usage_insns);
5260 }
5261 else if (NONDEBUG_INSN_P (insn))
5262 setup_next_usage_insn (regno, insn, reloads_num, false);
5263 else
5264 usage_insns[regno].check = 0;
5265 }
5266
5267 /* Return first non-debug insn in list USAGE_INSNS. */
5268 static rtx_insn *
5269 skip_usage_debug_insns (rtx usage_insns)
5270 {
5271 rtx insn;
5272
5273 /* Skip debug insns. */
5274 for (insn = usage_insns;
5275 insn != NULL_RTX && GET_CODE (insn) == INSN_LIST;
5276 insn = XEXP (insn, 1))
5277 ;
5278 return safe_as_a <rtx_insn *> (insn);
5279 }
5280
5281 /* Return true if we need secondary memory moves for insn in
5282 USAGE_INSNS after inserting inherited pseudo of class INHER_CL
5283 into the insn. */
5284 static bool
5285 check_secondary_memory_needed_p (enum reg_class inher_cl ATTRIBUTE_UNUSED,
5286 rtx usage_insns ATTRIBUTE_UNUSED)
5287 {
5288 rtx_insn *insn;
5289 rtx set, dest;
5290 enum reg_class cl;
5291
5292 if (inher_cl == ALL_REGS
5293 || (insn = skip_usage_debug_insns (usage_insns)) == NULL_RTX)
5294 return false;
5295 lra_assert (INSN_P (insn));
5296 if ((set = single_set (insn)) == NULL_RTX || ! REG_P (SET_DEST (set)))
5297 return false;
5298 dest = SET_DEST (set);
5299 if (! REG_P (dest))
5300 return false;
5301 lra_assert (inher_cl != NO_REGS);
5302 cl = get_reg_class (REGNO (dest));
5303 return (cl != NO_REGS && cl != ALL_REGS
5304 && targetm.secondary_memory_needed (GET_MODE (dest), inher_cl, cl));
5305 }
5306
5307 /* Registers involved in inheritance/split in the current EBB
5308 (inheritance/split pseudos and original registers). */
5309 static bitmap_head check_only_regs;
5310
5311 /* Reload pseudos cannot be involded in invariant inheritance in the
5312 current EBB. */
5313 static bitmap_head invalid_invariant_regs;
5314
5315 /* Do inheritance transformations for insn INSN, which defines (if
5316 DEF_P) or uses ORIGINAL_REGNO. NEXT_USAGE_INSNS specifies which
5317 instruction in the EBB next uses ORIGINAL_REGNO; it has the same
5318 form as the "insns" field of usage_insns. Return true if we
5319 succeed in such transformation.
5320
5321 The transformations look like:
5322
5323 p <- ... i <- ...
5324 ... p <- i (new insn)
5325 ... =>
5326 <- ... p ... <- ... i ...
5327 or
5328 ... i <- p (new insn)
5329 <- ... p ... <- ... i ...
5330 ... =>
5331 <- ... p ... <- ... i ...
5332 where p is a spilled original pseudo and i is a new inheritance pseudo.
5333
5334
5335 The inheritance pseudo has the smallest class of two classes CL and
5336 class of ORIGINAL REGNO. */
5337 static bool
5338 inherit_reload_reg (bool def_p, int original_regno,
5339 enum reg_class cl, rtx_insn *insn, rtx next_usage_insns)
5340 {
5341 if (optimize_function_for_size_p (cfun))
5342 return false;
5343
5344 enum reg_class rclass = lra_get_allocno_class (original_regno);
5345 rtx original_reg = regno_reg_rtx[original_regno];
5346 rtx new_reg, usage_insn;
5347 rtx_insn *new_insns;
5348
5349 lra_assert (! usage_insns[original_regno].after_p);
5350 if (lra_dump_file != NULL)
5351 fprintf (lra_dump_file,
5352 " <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n");
5353 if (! ira_reg_classes_intersect_p[cl][rclass])
5354 {
5355 if (lra_dump_file != NULL)
5356 {
5357 fprintf (lra_dump_file,
5358 " Rejecting inheritance for %d "
5359 "because of disjoint classes %s and %s\n",
5360 original_regno, reg_class_names[cl],
5361 reg_class_names[rclass]);
5362 fprintf (lra_dump_file,
5363 " >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n");
5364 }
5365 return false;
5366 }
5367 if ((ira_class_subset_p[cl][rclass] && cl != rclass)
5368 /* We don't use a subset of two classes because it can be
5369 NO_REGS. This transformation is still profitable in most
5370 cases even if the classes are not intersected as register
5371 move is probably cheaper than a memory load. */
5372 || ira_class_hard_regs_num[cl] < ira_class_hard_regs_num[rclass])
5373 {
5374 if (lra_dump_file != NULL)
5375 fprintf (lra_dump_file, " Use smallest class of %s and %s\n",
5376 reg_class_names[cl], reg_class_names[rclass]);
5377
5378 rclass = cl;
5379 }
5380 if (check_secondary_memory_needed_p (rclass, next_usage_insns))
5381 {
5382 /* Reject inheritance resulting in secondary memory moves.
5383 Otherwise, there is a danger in LRA cycling. Also such
5384 transformation will be unprofitable. */
5385 if (lra_dump_file != NULL)
5386 {
5387 rtx_insn *insn = skip_usage_debug_insns (next_usage_insns);
5388 rtx set = single_set (insn);
5389
5390 lra_assert (set != NULL_RTX);
5391
5392 rtx dest = SET_DEST (set);
5393
5394 lra_assert (REG_P (dest));
5395 fprintf (lra_dump_file,
5396 " Rejecting inheritance for insn %d(%s)<-%d(%s) "
5397 "as secondary mem is needed\n",
5398 REGNO (dest), reg_class_names[get_reg_class (REGNO (dest))],
5399 original_regno, reg_class_names[rclass]);
5400 fprintf (lra_dump_file,
5401 " >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n");
5402 }
5403 return false;
5404 }
5405 new_reg = lra_create_new_reg (GET_MODE (original_reg), original_reg,
5406 rclass, "inheritance");
5407 start_sequence ();
5408 if (def_p)
5409 lra_emit_move (original_reg, new_reg);
5410 else
5411 lra_emit_move (new_reg, original_reg);
5412 new_insns = get_insns ();
5413 end_sequence ();
5414 if (NEXT_INSN (new_insns) != NULL_RTX)
5415 {
5416 if (lra_dump_file != NULL)
5417 {
5418 fprintf (lra_dump_file,
5419 " Rejecting inheritance %d->%d "
5420 "as it results in 2 or more insns:\n",
5421 original_regno, REGNO (new_reg));
5422 dump_rtl_slim (lra_dump_file, new_insns, NULL, -1, 0);
5423 fprintf (lra_dump_file,
5424 " >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n");
5425 }
5426 return false;
5427 }
5428 lra_substitute_pseudo_within_insn (insn, original_regno, new_reg, false);
5429 lra_update_insn_regno_info (insn);
5430 if (! def_p)
5431 /* We now have a new usage insn for original regno. */
5432 setup_next_usage_insn (original_regno, new_insns, reloads_num, false);
5433 if (lra_dump_file != NULL)
5434 fprintf (lra_dump_file, " Original reg change %d->%d (bb%d):\n",
5435 original_regno, REGNO (new_reg), BLOCK_FOR_INSN (insn)->index);
5436 lra_reg_info[REGNO (new_reg)].restore_rtx = regno_reg_rtx[original_regno];
5437 bitmap_set_bit (&check_only_regs, REGNO (new_reg));
5438 bitmap_set_bit (&check_only_regs, original_regno);
5439 bitmap_set_bit (&lra_inheritance_pseudos, REGNO (new_reg));
5440 if (def_p)
5441 lra_process_new_insns (insn, NULL, new_insns,
5442 "Add original<-inheritance");
5443 else
5444 lra_process_new_insns (insn, new_insns, NULL,
5445 "Add inheritance<-original");
5446 while (next_usage_insns != NULL_RTX)
5447 {
5448 if (GET_CODE (next_usage_insns) != INSN_LIST)
5449 {
5450 usage_insn = next_usage_insns;
5451 lra_assert (NONDEBUG_INSN_P (usage_insn));
5452 next_usage_insns = NULL;
5453 }
5454 else
5455 {
5456 usage_insn = XEXP (next_usage_insns, 0);
5457 lra_assert (DEBUG_INSN_P (usage_insn));
5458 next_usage_insns = XEXP (next_usage_insns, 1);
5459 }
5460 lra_substitute_pseudo (&usage_insn, original_regno, new_reg, false,
5461 DEBUG_INSN_P (usage_insn));
5462 lra_update_insn_regno_info (as_a <rtx_insn *> (usage_insn));
5463 if (lra_dump_file != NULL)
5464 {
5465 basic_block bb = BLOCK_FOR_INSN (usage_insn);
5466 fprintf (lra_dump_file,
5467 " Inheritance reuse change %d->%d (bb%d):\n",
5468 original_regno, REGNO (new_reg),
5469 bb ? bb->index : -1);
5470 dump_insn_slim (lra_dump_file, as_a <rtx_insn *> (usage_insn));
5471 }
5472 }
5473 if (lra_dump_file != NULL)
5474 fprintf (lra_dump_file,
5475 " >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n");
5476 return true;
5477 }
5478
5479 /* Return true if we need a caller save/restore for pseudo REGNO which
5480 was assigned to a hard register. */
5481 static inline bool
5482 need_for_call_save_p (int regno)
5483 {
5484 lra_assert (regno >= FIRST_PSEUDO_REGISTER && reg_renumber[regno] >= 0);
5485 if (usage_insns[regno].calls_num < calls_num)
5486 {
5487 unsigned int abis = 0;
5488 for (unsigned int i = 0; i < NUM_ABI_IDS; ++i)
5489 if (last_call_for_abi[i] > usage_insns[regno].calls_num)
5490 abis |= 1 << i;
5491 gcc_assert (abis);
5492 if (call_clobbered_in_region_p (abis, full_and_partial_call_clobbers,
5493 PSEUDO_REGNO_MODE (regno),
5494 reg_renumber[regno]))
5495 return true;
5496 }
5497 return false;
5498 }
5499
5500 /* Global registers occurring in the current EBB. */
5501 static bitmap_head ebb_global_regs;
5502
5503 /* Return true if we need a split for hard register REGNO or pseudo
5504 REGNO which was assigned to a hard register.
5505 POTENTIAL_RELOAD_HARD_REGS contains hard registers which might be
5506 used for reloads since the EBB end. It is an approximation of the
5507 used hard registers in the split range. The exact value would
5508 require expensive calculations. If we were aggressive with
5509 splitting because of the approximation, the split pseudo will save
5510 the same hard register assignment and will be removed in the undo
5511 pass. We still need the approximation because too aggressive
5512 splitting would result in too inaccurate cost calculation in the
5513 assignment pass because of too many generated moves which will be
5514 probably removed in the undo pass. */
5515 static inline bool
5516 need_for_split_p (HARD_REG_SET potential_reload_hard_regs, int regno)
5517 {
5518 int hard_regno = regno < FIRST_PSEUDO_REGISTER ? regno : reg_renumber[regno];
5519
5520 lra_assert (hard_regno >= 0);
5521 return ((TEST_HARD_REG_BIT (potential_reload_hard_regs, hard_regno)
5522 /* Don't split eliminable hard registers, otherwise we can
5523 split hard registers like hard frame pointer, which
5524 lives on BB start/end according to DF-infrastructure,
5525 when there is a pseudo assigned to the register and
5526 living in the same BB. */
5527 && (regno >= FIRST_PSEUDO_REGISTER
5528 || ! TEST_HARD_REG_BIT (eliminable_regset, hard_regno))
5529 && ! TEST_HARD_REG_BIT (lra_no_alloc_regs, hard_regno)
5530 /* Don't split call clobbered hard regs living through
5531 calls, otherwise we might have a check problem in the
5532 assign sub-pass as in the most cases (exception is a
5533 situation when check_and_force_assignment_correctness_p value is
5534 true) the assign pass assumes that all pseudos living
5535 through calls are assigned to call saved hard regs. */
5536 && (regno >= FIRST_PSEUDO_REGISTER
5537 || !TEST_HARD_REG_BIT (full_and_partial_call_clobbers, regno))
5538 /* We need at least 2 reloads to make pseudo splitting
5539 profitable. We should provide hard regno splitting in
5540 any case to solve 1st insn scheduling problem when
5541 moving hard register definition up might result in
5542 impossibility to find hard register for reload pseudo of
5543 small register class. */
5544 && (usage_insns[regno].reloads_num
5545 + (regno < FIRST_PSEUDO_REGISTER ? 0 : 3) < reloads_num)
5546 && (regno < FIRST_PSEUDO_REGISTER
5547 /* For short living pseudos, spilling + inheritance can
5548 be considered a substitution for splitting.
5549 Therefore we do not splitting for local pseudos. It
5550 decreases also aggressiveness of splitting. The
5551 minimal number of references is chosen taking into
5552 account that for 2 references splitting has no sense
5553 as we can just spill the pseudo. */
5554 || (regno >= FIRST_PSEUDO_REGISTER
5555 && lra_reg_info[regno].nrefs > 3
5556 && bitmap_bit_p (&ebb_global_regs, regno))))
5557 || (regno >= FIRST_PSEUDO_REGISTER && need_for_call_save_p (regno)));
5558 }
5559
5560 /* Return class for the split pseudo created from original pseudo with
5561 ALLOCNO_CLASS and MODE which got a hard register HARD_REGNO. We
5562 choose subclass of ALLOCNO_CLASS which contains HARD_REGNO and
5563 results in no secondary memory movements. */
5564 static enum reg_class
5565 choose_split_class (enum reg_class allocno_class,
5566 int hard_regno ATTRIBUTE_UNUSED,
5567 machine_mode mode ATTRIBUTE_UNUSED)
5568 {
5569 int i;
5570 enum reg_class cl, best_cl = NO_REGS;
5571 enum reg_class hard_reg_class ATTRIBUTE_UNUSED
5572 = REGNO_REG_CLASS (hard_regno);
5573
5574 if (! targetm.secondary_memory_needed (mode, allocno_class, allocno_class)
5575 && TEST_HARD_REG_BIT (reg_class_contents[allocno_class], hard_regno))
5576 return allocno_class;
5577 for (i = 0;
5578 (cl = reg_class_subclasses[allocno_class][i]) != LIM_REG_CLASSES;
5579 i++)
5580 if (! targetm.secondary_memory_needed (mode, cl, hard_reg_class)
5581 && ! targetm.secondary_memory_needed (mode, hard_reg_class, cl)
5582 && TEST_HARD_REG_BIT (reg_class_contents[cl], hard_regno)
5583 && (best_cl == NO_REGS
5584 || ira_class_hard_regs_num[best_cl] < ira_class_hard_regs_num[cl]))
5585 best_cl = cl;
5586 return best_cl;
5587 }
5588
5589 /* Copy any equivalence information from ORIGINAL_REGNO to NEW_REGNO.
5590 It only makes sense to call this function if NEW_REGNO is always
5591 equal to ORIGINAL_REGNO. */
5592
5593 static void
5594 lra_copy_reg_equiv (unsigned int new_regno, unsigned int original_regno)
5595 {
5596 if (!ira_reg_equiv[original_regno].defined_p)
5597 return;
5598
5599 ira_expand_reg_equiv ();
5600 ira_reg_equiv[new_regno].defined_p = true;
5601 if (ira_reg_equiv[original_regno].memory)
5602 ira_reg_equiv[new_regno].memory
5603 = copy_rtx (ira_reg_equiv[original_regno].memory);
5604 if (ira_reg_equiv[original_regno].constant)
5605 ira_reg_equiv[new_regno].constant
5606 = copy_rtx (ira_reg_equiv[original_regno].constant);
5607 if (ira_reg_equiv[original_regno].invariant)
5608 ira_reg_equiv[new_regno].invariant
5609 = copy_rtx (ira_reg_equiv[original_regno].invariant);
5610 }
5611
5612 /* Do split transformations for insn INSN, which defines or uses
5613 ORIGINAL_REGNO. NEXT_USAGE_INSNS specifies which instruction in
5614 the EBB next uses ORIGINAL_REGNO; it has the same form as the
5615 "insns" field of usage_insns. If TO is not NULL, we don't use
5616 usage_insns, we put restore insns after TO insn. It is a case when
5617 we call it from lra_split_hard_reg_for, outside the inheritance
5618 pass.
5619
5620 The transformations look like:
5621
5622 p <- ... p <- ...
5623 ... s <- p (new insn -- save)
5624 ... =>
5625 ... p <- s (new insn -- restore)
5626 <- ... p ... <- ... p ...
5627 or
5628 <- ... p ... <- ... p ...
5629 ... s <- p (new insn -- save)
5630 ... =>
5631 ... p <- s (new insn -- restore)
5632 <- ... p ... <- ... p ...
5633
5634 where p is an original pseudo got a hard register or a hard
5635 register and s is a new split pseudo. The save is put before INSN
5636 if BEFORE_P is true. Return true if we succeed in such
5637 transformation. */
5638 static bool
5639 split_reg (bool before_p, int original_regno, rtx_insn *insn,
5640 rtx next_usage_insns, rtx_insn *to)
5641 {
5642 enum reg_class rclass;
5643 rtx original_reg;
5644 int hard_regno, nregs;
5645 rtx new_reg, usage_insn;
5646 rtx_insn *restore, *save;
5647 bool after_p;
5648 bool call_save_p;
5649 machine_mode mode;
5650
5651 if (original_regno < FIRST_PSEUDO_REGISTER)
5652 {
5653 rclass = ira_allocno_class_translate[REGNO_REG_CLASS (original_regno)];
5654 hard_regno = original_regno;
5655 call_save_p = false;
5656 nregs = 1;
5657 mode = lra_reg_info[hard_regno].biggest_mode;
5658 machine_mode reg_rtx_mode = GET_MODE (regno_reg_rtx[hard_regno]);
5659 /* A reg can have a biggest_mode of VOIDmode if it was only ever seen
5660 as part of a multi-word register. In that case, or if the biggest
5661 mode was larger than a register, just use the reg_rtx. Otherwise,
5662 limit the size to that of the biggest access in the function. */
5663 if (mode == VOIDmode
5664 || paradoxical_subreg_p (mode, reg_rtx_mode))
5665 {
5666 original_reg = regno_reg_rtx[hard_regno];
5667 mode = reg_rtx_mode;
5668 }
5669 else
5670 original_reg = gen_rtx_REG (mode, hard_regno);
5671 }
5672 else
5673 {
5674 mode = PSEUDO_REGNO_MODE (original_regno);
5675 hard_regno = reg_renumber[original_regno];
5676 nregs = hard_regno_nregs (hard_regno, mode);
5677 rclass = lra_get_allocno_class (original_regno);
5678 original_reg = regno_reg_rtx[original_regno];
5679 call_save_p = need_for_call_save_p (original_regno);
5680 }
5681 lra_assert (hard_regno >= 0);
5682 if (lra_dump_file != NULL)
5683 fprintf (lra_dump_file,
5684 " ((((((((((((((((((((((((((((((((((((((((((((((((\n");
5685
5686 if (call_save_p)
5687 {
5688 mode = HARD_REGNO_CALLER_SAVE_MODE (hard_regno,
5689 hard_regno_nregs (hard_regno, mode),
5690 mode);
5691 new_reg = lra_create_new_reg (mode, NULL_RTX, NO_REGS, "save");
5692 }
5693 else
5694 {
5695 rclass = choose_split_class (rclass, hard_regno, mode);
5696 if (rclass == NO_REGS)
5697 {
5698 if (lra_dump_file != NULL)
5699 {
5700 fprintf (lra_dump_file,
5701 " Rejecting split of %d(%s): "
5702 "no good reg class for %d(%s)\n",
5703 original_regno,
5704 reg_class_names[lra_get_allocno_class (original_regno)],
5705 hard_regno,
5706 reg_class_names[REGNO_REG_CLASS (hard_regno)]);
5707 fprintf
5708 (lra_dump_file,
5709 " ))))))))))))))))))))))))))))))))))))))))))))))))\n");
5710 }
5711 return false;
5712 }
5713 /* Split_if_necessary can split hard registers used as part of a
5714 multi-register mode but splits each register individually. The
5715 mode used for each independent register may not be supported
5716 so reject the split. Splitting the wider mode should theoretically
5717 be possible but is not implemented. */
5718 if (!targetm.hard_regno_mode_ok (hard_regno, mode))
5719 {
5720 if (lra_dump_file != NULL)
5721 {
5722 fprintf (lra_dump_file,
5723 " Rejecting split of %d(%s): unsuitable mode %s\n",
5724 original_regno,
5725 reg_class_names[lra_get_allocno_class (original_regno)],
5726 GET_MODE_NAME (mode));
5727 fprintf
5728 (lra_dump_file,
5729 " ))))))))))))))))))))))))))))))))))))))))))))))))\n");
5730 }
5731 return false;
5732 }
5733 new_reg = lra_create_new_reg (mode, original_reg, rclass, "split");
5734 reg_renumber[REGNO (new_reg)] = hard_regno;
5735 }
5736 int new_regno = REGNO (new_reg);
5737 save = emit_spill_move (true, new_reg, original_reg);
5738 if (NEXT_INSN (save) != NULL_RTX && !call_save_p)
5739 {
5740 if (lra_dump_file != NULL)
5741 {
5742 fprintf
5743 (lra_dump_file,
5744 " Rejecting split %d->%d resulting in > 2 save insns:\n",
5745 original_regno, new_regno);
5746 dump_rtl_slim (lra_dump_file, save, NULL, -1, 0);
5747 fprintf (lra_dump_file,
5748 " ))))))))))))))))))))))))))))))))))))))))))))))))\n");
5749 }
5750 return false;
5751 }
5752 restore = emit_spill_move (false, new_reg, original_reg);
5753 if (NEXT_INSN (restore) != NULL_RTX && !call_save_p)
5754 {
5755 if (lra_dump_file != NULL)
5756 {
5757 fprintf (lra_dump_file,
5758 " Rejecting split %d->%d "
5759 "resulting in > 2 restore insns:\n",
5760 original_regno, new_regno);
5761 dump_rtl_slim (lra_dump_file, restore, NULL, -1, 0);
5762 fprintf (lra_dump_file,
5763 " ))))))))))))))))))))))))))))))))))))))))))))))))\n");
5764 }
5765 return false;
5766 }
5767 /* Transfer equivalence information to the spill register, so that
5768 if we fail to allocate the spill register, we have the option of
5769 rematerializing the original value instead of spilling to the stack. */
5770 if (!HARD_REGISTER_NUM_P (original_regno)
5771 && mode == PSEUDO_REGNO_MODE (original_regno))
5772 lra_copy_reg_equiv (new_regno, original_regno);
5773 lra_reg_info[new_regno].restore_rtx = regno_reg_rtx[original_regno];
5774 bitmap_set_bit (&lra_split_regs, new_regno);
5775 if (to != NULL)
5776 {
5777 lra_assert (next_usage_insns == NULL);
5778 usage_insn = to;
5779 after_p = TRUE;
5780 }
5781 else
5782 {
5783 /* We need check_only_regs only inside the inheritance pass. */
5784 bitmap_set_bit (&check_only_regs, new_regno);
5785 bitmap_set_bit (&check_only_regs, original_regno);
5786 after_p = usage_insns[original_regno].after_p;
5787 for (;;)
5788 {
5789 if (GET_CODE (next_usage_insns) != INSN_LIST)
5790 {
5791 usage_insn = next_usage_insns;
5792 break;
5793 }
5794 usage_insn = XEXP (next_usage_insns, 0);
5795 lra_assert (DEBUG_INSN_P (usage_insn));
5796 next_usage_insns = XEXP (next_usage_insns, 1);
5797 lra_substitute_pseudo (&usage_insn, original_regno, new_reg, false,
5798 true);
5799 lra_update_insn_regno_info (as_a <rtx_insn *> (usage_insn));
5800 if (lra_dump_file != NULL)
5801 {
5802 fprintf (lra_dump_file, " Split reuse change %d->%d:\n",
5803 original_regno, new_regno);
5804 dump_insn_slim (lra_dump_file, as_a <rtx_insn *> (usage_insn));
5805 }
5806 }
5807 }
5808 lra_assert (NOTE_P (usage_insn) || NONDEBUG_INSN_P (usage_insn));
5809 lra_assert (usage_insn != insn || (after_p && before_p));
5810 lra_process_new_insns (as_a <rtx_insn *> (usage_insn),
5811 after_p ? NULL : restore,
5812 after_p ? restore : NULL,
5813 call_save_p
5814 ? "Add reg<-save" : "Add reg<-split");
5815 lra_process_new_insns (insn, before_p ? save : NULL,
5816 before_p ? NULL : save,
5817 call_save_p
5818 ? "Add save<-reg" : "Add split<-reg");
5819 if (nregs > 1)
5820 /* If we are trying to split multi-register. We should check
5821 conflicts on the next assignment sub-pass. IRA can allocate on
5822 sub-register levels, LRA do this on pseudos level right now and
5823 this discrepancy may create allocation conflicts after
5824 splitting. */
5825 check_and_force_assignment_correctness_p = true;
5826 if (lra_dump_file != NULL)
5827 fprintf (lra_dump_file,
5828 " ))))))))))))))))))))))))))))))))))))))))))))))))\n");
5829 return true;
5830 }
5831
5832 /* Split a hard reg for reload pseudo REGNO having RCLASS and living
5833 in the range [FROM, TO]. Return true if did a split. Otherwise,
5834 return false. */
5835 bool
5836 spill_hard_reg_in_range (int regno, enum reg_class rclass, rtx_insn *from, rtx_insn *to)
5837 {
5838 int i, hard_regno;
5839 int rclass_size;
5840 rtx_insn *insn;
5841 unsigned int uid;
5842 bitmap_iterator bi;
5843 HARD_REG_SET ignore;
5844
5845 lra_assert (from != NULL && to != NULL);
5846 CLEAR_HARD_REG_SET (ignore);
5847 EXECUTE_IF_SET_IN_BITMAP (&lra_reg_info[regno].insn_bitmap, 0, uid, bi)
5848 {
5849 lra_insn_recog_data_t id = lra_insn_recog_data[uid];
5850 struct lra_static_insn_data *static_id = id->insn_static_data;
5851 struct lra_insn_reg *reg;
5852
5853 for (reg = id->regs; reg != NULL; reg = reg->next)
5854 if (reg->regno < FIRST_PSEUDO_REGISTER)
5855 SET_HARD_REG_BIT (ignore, reg->regno);
5856 for (reg = static_id->hard_regs; reg != NULL; reg = reg->next)
5857 SET_HARD_REG_BIT (ignore, reg->regno);
5858 }
5859 rclass_size = ira_class_hard_regs_num[rclass];
5860 for (i = 0; i < rclass_size; i++)
5861 {
5862 hard_regno = ira_class_hard_regs[rclass][i];
5863 if (! TEST_HARD_REG_BIT (lra_reg_info[regno].conflict_hard_regs, hard_regno)
5864 || TEST_HARD_REG_BIT (ignore, hard_regno))
5865 continue;
5866 for (insn = from; insn != NEXT_INSN (to); insn = NEXT_INSN (insn))
5867 {
5868 struct lra_static_insn_data *static_id;
5869 struct lra_insn_reg *reg;
5870
5871 if (!INSN_P (insn))
5872 continue;
5873 if (bitmap_bit_p (&lra_reg_info[hard_regno].insn_bitmap,
5874 INSN_UID (insn)))
5875 break;
5876 static_id = lra_get_insn_recog_data (insn)->insn_static_data;
5877 for (reg = static_id->hard_regs; reg != NULL; reg = reg->next)
5878 if (reg->regno == hard_regno)
5879 break;
5880 if (reg != NULL)
5881 break;
5882 }
5883 if (insn != NEXT_INSN (to))
5884 continue;
5885 if (split_reg (TRUE, hard_regno, from, NULL, to))
5886 return true;
5887 }
5888 return false;
5889 }
5890
5891 /* Recognize that we need a split transformation for insn INSN, which
5892 defines or uses REGNO in its insn biggest MODE (we use it only if
5893 REGNO is a hard register). POTENTIAL_RELOAD_HARD_REGS contains
5894 hard registers which might be used for reloads since the EBB end.
5895 Put the save before INSN if BEFORE_P is true. MAX_UID is maximla
5896 uid before starting INSN processing. Return true if we succeed in
5897 such transformation. */
5898 static bool
5899 split_if_necessary (int regno, machine_mode mode,
5900 HARD_REG_SET potential_reload_hard_regs,
5901 bool before_p, rtx_insn *insn, int max_uid)
5902 {
5903 bool res = false;
5904 int i, nregs = 1;
5905 rtx next_usage_insns;
5906
5907 if (regno < FIRST_PSEUDO_REGISTER)
5908 nregs = hard_regno_nregs (regno, mode);
5909 for (i = 0; i < nregs; i++)
5910 if (usage_insns[regno + i].check == curr_usage_insns_check
5911 && (next_usage_insns = usage_insns[regno + i].insns) != NULL_RTX
5912 /* To avoid processing the register twice or more. */
5913 && ((GET_CODE (next_usage_insns) != INSN_LIST
5914 && INSN_UID (next_usage_insns) < max_uid)
5915 || (GET_CODE (next_usage_insns) == INSN_LIST
5916 && (INSN_UID (XEXP (next_usage_insns, 0)) < max_uid)))
5917 && need_for_split_p (potential_reload_hard_regs, regno + i)
5918 && split_reg (before_p, regno + i, insn, next_usage_insns, NULL))
5919 res = true;
5920 return res;
5921 }
5922
5923 /* Return TRUE if rtx X is considered as an invariant for
5924 inheritance. */
5925 static bool
5926 invariant_p (const_rtx x)
5927 {
5928 machine_mode mode;
5929 const char *fmt;
5930 enum rtx_code code;
5931 int i, j;
5932
5933 if (side_effects_p (x))
5934 return false;
5935
5936 code = GET_CODE (x);
5937 mode = GET_MODE (x);
5938 if (code == SUBREG)
5939 {
5940 x = SUBREG_REG (x);
5941 code = GET_CODE (x);
5942 mode = wider_subreg_mode (mode, GET_MODE (x));
5943 }
5944
5945 if (MEM_P (x))
5946 return false;
5947
5948 if (REG_P (x))
5949 {
5950 int i, nregs, regno = REGNO (x);
5951
5952 if (regno >= FIRST_PSEUDO_REGISTER || regno == STACK_POINTER_REGNUM
5953 || TEST_HARD_REG_BIT (eliminable_regset, regno)
5954 || GET_MODE_CLASS (GET_MODE (x)) == MODE_CC)
5955 return false;
5956 nregs = hard_regno_nregs (regno, mode);
5957 for (i = 0; i < nregs; i++)
5958 if (! fixed_regs[regno + i]
5959 /* A hard register may be clobbered in the current insn
5960 but we can ignore this case because if the hard
5961 register is used it should be set somewhere after the
5962 clobber. */
5963 || bitmap_bit_p (&invalid_invariant_regs, regno + i))
5964 return false;
5965 }
5966 fmt = GET_RTX_FORMAT (code);
5967 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
5968 {
5969 if (fmt[i] == 'e')
5970 {
5971 if (! invariant_p (XEXP (x, i)))
5972 return false;
5973 }
5974 else if (fmt[i] == 'E')
5975 {
5976 for (j = XVECLEN (x, i) - 1; j >= 0; j--)
5977 if (! invariant_p (XVECEXP (x, i, j)))
5978 return false;
5979 }
5980 }
5981 return true;
5982 }
5983
5984 /* We have 'dest_reg <- invariant'. Let us try to make an invariant
5985 inheritance transformation (using dest_reg instead invariant in a
5986 subsequent insn). */
5987 static bool
5988 process_invariant_for_inheritance (rtx dst_reg, rtx invariant_rtx)
5989 {
5990 invariant_ptr_t invariant_ptr;
5991 rtx_insn *insn, *new_insns;
5992 rtx insn_set, insn_reg, new_reg;
5993 int insn_regno;
5994 bool succ_p = false;
5995 int dst_regno = REGNO (dst_reg);
5996 machine_mode dst_mode = GET_MODE (dst_reg);
5997 enum reg_class cl = lra_get_allocno_class (dst_regno), insn_reg_cl;
5998
5999 invariant_ptr = insert_invariant (invariant_rtx);
6000 if ((insn = invariant_ptr->insn) != NULL_RTX)
6001 {
6002 /* We have a subsequent insn using the invariant. */
6003 insn_set = single_set (insn);
6004 lra_assert (insn_set != NULL);
6005 insn_reg = SET_DEST (insn_set);
6006 lra_assert (REG_P (insn_reg));
6007 insn_regno = REGNO (insn_reg);
6008 insn_reg_cl = lra_get_allocno_class (insn_regno);
6009
6010 if (dst_mode == GET_MODE (insn_reg)
6011 /* We should consider only result move reg insns which are
6012 cheap. */
6013 && targetm.register_move_cost (dst_mode, cl, insn_reg_cl) == 2
6014 && targetm.register_move_cost (dst_mode, cl, cl) == 2)
6015 {
6016 if (lra_dump_file != NULL)
6017 fprintf (lra_dump_file,
6018 " [[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[\n");
6019 new_reg = lra_create_new_reg (dst_mode, dst_reg,
6020 cl, "invariant inheritance");
6021 bitmap_set_bit (&lra_inheritance_pseudos, REGNO (new_reg));
6022 bitmap_set_bit (&check_only_regs, REGNO (new_reg));
6023 lra_reg_info[REGNO (new_reg)].restore_rtx = PATTERN (insn);
6024 start_sequence ();
6025 lra_emit_move (new_reg, dst_reg);
6026 new_insns = get_insns ();
6027 end_sequence ();
6028 lra_process_new_insns (curr_insn, NULL, new_insns,
6029 "Add invariant inheritance<-original");
6030 start_sequence ();
6031 lra_emit_move (SET_DEST (insn_set), new_reg);
6032 new_insns = get_insns ();
6033 end_sequence ();
6034 lra_process_new_insns (insn, NULL, new_insns,
6035 "Changing reload<-inheritance");
6036 lra_set_insn_deleted (insn);
6037 succ_p = true;
6038 if (lra_dump_file != NULL)
6039 {
6040 fprintf (lra_dump_file,
6041 " Invariant inheritance reuse change %d (bb%d):\n",
6042 REGNO (new_reg), BLOCK_FOR_INSN (insn)->index);
6043 dump_insn_slim (lra_dump_file, insn);
6044 fprintf (lra_dump_file,
6045 " ]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]\n");
6046 }
6047 }
6048 }
6049 invariant_ptr->insn = curr_insn;
6050 return succ_p;
6051 }
6052
6053 /* Check only registers living at the current program point in the
6054 current EBB. */
6055 static bitmap_head live_regs;
6056
6057 /* Update live info in EBB given by its HEAD and TAIL insns after
6058 inheritance/split transformation. The function removes dead moves
6059 too. */
6060 static void
6061 update_ebb_live_info (rtx_insn *head, rtx_insn *tail)
6062 {
6063 unsigned int j;
6064 int i, regno;
6065 bool live_p;
6066 rtx_insn *prev_insn;
6067 rtx set;
6068 bool remove_p;
6069 basic_block last_bb, prev_bb, curr_bb;
6070 bitmap_iterator bi;
6071 struct lra_insn_reg *reg;
6072 edge e;
6073 edge_iterator ei;
6074
6075 last_bb = BLOCK_FOR_INSN (tail);
6076 prev_bb = NULL;
6077 for (curr_insn = tail;
6078 curr_insn != PREV_INSN (head);
6079 curr_insn = prev_insn)
6080 {
6081 prev_insn = PREV_INSN (curr_insn);
6082 /* We need to process empty blocks too. They contain
6083 NOTE_INSN_BASIC_BLOCK referring for the basic block. */
6084 if (NOTE_P (curr_insn) && NOTE_KIND (curr_insn) != NOTE_INSN_BASIC_BLOCK)
6085 continue;
6086 curr_bb = BLOCK_FOR_INSN (curr_insn);
6087 if (curr_bb != prev_bb)
6088 {
6089 if (prev_bb != NULL)
6090 {
6091 /* Update df_get_live_in (prev_bb): */
6092 EXECUTE_IF_SET_IN_BITMAP (&check_only_regs, 0, j, bi)
6093 if (bitmap_bit_p (&live_regs, j))
6094 bitmap_set_bit (df_get_live_in (prev_bb), j);
6095 else
6096 bitmap_clear_bit (df_get_live_in (prev_bb), j);
6097 }
6098 if (curr_bb != last_bb)
6099 {
6100 /* Update df_get_live_out (curr_bb): */
6101 EXECUTE_IF_SET_IN_BITMAP (&check_only_regs, 0, j, bi)
6102 {
6103 live_p = bitmap_bit_p (&live_regs, j);
6104 if (! live_p)
6105 FOR_EACH_EDGE (e, ei, curr_bb->succs)
6106 if (bitmap_bit_p (df_get_live_in (e->dest), j))
6107 {
6108 live_p = true;
6109 break;
6110 }
6111 if (live_p)
6112 bitmap_set_bit (df_get_live_out (curr_bb), j);
6113 else
6114 bitmap_clear_bit (df_get_live_out (curr_bb), j);
6115 }
6116 }
6117 prev_bb = curr_bb;
6118 bitmap_and (&live_regs, &check_only_regs, df_get_live_out (curr_bb));
6119 }
6120 if (! NONDEBUG_INSN_P (curr_insn))
6121 continue;
6122 curr_id = lra_get_insn_recog_data (curr_insn);
6123 curr_static_id = curr_id->insn_static_data;
6124 remove_p = false;
6125 if ((set = single_set (curr_insn)) != NULL_RTX
6126 && REG_P (SET_DEST (set))
6127 && (regno = REGNO (SET_DEST (set))) >= FIRST_PSEUDO_REGISTER
6128 && SET_DEST (set) != pic_offset_table_rtx
6129 && bitmap_bit_p (&check_only_regs, regno)
6130 && ! bitmap_bit_p (&live_regs, regno))
6131 remove_p = true;
6132 /* See which defined values die here. */
6133 for (reg = curr_id->regs; reg != NULL; reg = reg->next)
6134 if (reg->type == OP_OUT && ! reg->subreg_p)
6135 bitmap_clear_bit (&live_regs, reg->regno);
6136 for (reg = curr_static_id->hard_regs; reg != NULL; reg = reg->next)
6137 if (reg->type == OP_OUT && ! reg->subreg_p)
6138 bitmap_clear_bit (&live_regs, reg->regno);
6139 if (curr_id->arg_hard_regs != NULL)
6140 /* Make clobbered argument hard registers die. */
6141 for (i = 0; (regno = curr_id->arg_hard_regs[i]) >= 0; i++)
6142 if (regno >= FIRST_PSEUDO_REGISTER)
6143 bitmap_clear_bit (&live_regs, regno - FIRST_PSEUDO_REGISTER);
6144 /* Mark each used value as live. */
6145 for (reg = curr_id->regs; reg != NULL; reg = reg->next)
6146 if (reg->type != OP_OUT
6147 && bitmap_bit_p (&check_only_regs, reg->regno))
6148 bitmap_set_bit (&live_regs, reg->regno);
6149 for (reg = curr_static_id->hard_regs; reg != NULL; reg = reg->next)
6150 if (reg->type != OP_OUT
6151 && bitmap_bit_p (&check_only_regs, reg->regno))
6152 bitmap_set_bit (&live_regs, reg->regno);
6153 if (curr_id->arg_hard_regs != NULL)
6154 /* Make used argument hard registers live. */
6155 for (i = 0; (regno = curr_id->arg_hard_regs[i]) >= 0; i++)
6156 if (regno < FIRST_PSEUDO_REGISTER
6157 && bitmap_bit_p (&check_only_regs, regno))
6158 bitmap_set_bit (&live_regs, regno);
6159 /* It is quite important to remove dead move insns because it
6160 means removing dead store. We don't need to process them for
6161 constraints. */
6162 if (remove_p)
6163 {
6164 if (lra_dump_file != NULL)
6165 {
6166 fprintf (lra_dump_file, " Removing dead insn:\n ");
6167 dump_insn_slim (lra_dump_file, curr_insn);
6168 }
6169 lra_set_insn_deleted (curr_insn);
6170 }
6171 }
6172 }
6173
6174 /* The structure describes info to do an inheritance for the current
6175 insn. We need to collect such info first before doing the
6176 transformations because the transformations change the insn
6177 internal representation. */
6178 struct to_inherit
6179 {
6180 /* Original regno. */
6181 int regno;
6182 /* Subsequent insns which can inherit original reg value. */
6183 rtx insns;
6184 };
6185
6186 /* Array containing all info for doing inheritance from the current
6187 insn. */
6188 static struct to_inherit to_inherit[LRA_MAX_INSN_RELOADS];
6189
6190 /* Number elements in the previous array. */
6191 static int to_inherit_num;
6192
6193 /* Add inheritance info REGNO and INSNS. Their meaning is described in
6194 structure to_inherit. */
6195 static void
6196 add_to_inherit (int regno, rtx insns)
6197 {
6198 int i;
6199
6200 for (i = 0; i < to_inherit_num; i++)
6201 if (to_inherit[i].regno == regno)
6202 return;
6203 lra_assert (to_inherit_num < LRA_MAX_INSN_RELOADS);
6204 to_inherit[to_inherit_num].regno = regno;
6205 to_inherit[to_inherit_num++].insns = insns;
6206 }
6207
6208 /* Return the last non-debug insn in basic block BB, or the block begin
6209 note if none. */
6210 static rtx_insn *
6211 get_last_insertion_point (basic_block bb)
6212 {
6213 rtx_insn *insn;
6214
6215 FOR_BB_INSNS_REVERSE (bb, insn)
6216 if (NONDEBUG_INSN_P (insn) || NOTE_INSN_BASIC_BLOCK_P (insn))
6217 return insn;
6218 gcc_unreachable ();
6219 }
6220
6221 /* Set up RES by registers living on edges FROM except the edge (FROM,
6222 TO) or by registers set up in a jump insn in BB FROM. */
6223 static void
6224 get_live_on_other_edges (basic_block from, basic_block to, bitmap res)
6225 {
6226 rtx_insn *last;
6227 struct lra_insn_reg *reg;
6228 edge e;
6229 edge_iterator ei;
6230
6231 lra_assert (to != NULL);
6232 bitmap_clear (res);
6233 FOR_EACH_EDGE (e, ei, from->succs)
6234 if (e->dest != to)
6235 bitmap_ior_into (res, df_get_live_in (e->dest));
6236 last = get_last_insertion_point (from);
6237 if (! JUMP_P (last))
6238 return;
6239 curr_id = lra_get_insn_recog_data (last);
6240 for (reg = curr_id->regs; reg != NULL; reg = reg->next)
6241 if (reg->type != OP_IN)
6242 bitmap_set_bit (res, reg->regno);
6243 }
6244
6245 /* Used as a temporary results of some bitmap calculations. */
6246 static bitmap_head temp_bitmap;
6247
6248 /* We split for reloads of small class of hard regs. The following
6249 defines how many hard regs the class should have to be qualified as
6250 small. The code is mostly oriented to x86/x86-64 architecture
6251 where some insns need to use only specific register or pair of
6252 registers and these register can live in RTL explicitly, e.g. for
6253 parameter passing. */
6254 static const int max_small_class_regs_num = 2;
6255
6256 /* Do inheritance/split transformations in EBB starting with HEAD and
6257 finishing on TAIL. We process EBB insns in the reverse order.
6258 Return true if we did any inheritance/split transformation in the
6259 EBB.
6260
6261 We should avoid excessive splitting which results in worse code
6262 because of inaccurate cost calculations for spilling new split
6263 pseudos in such case. To achieve this we do splitting only if
6264 register pressure is high in given basic block and there are reload
6265 pseudos requiring hard registers. We could do more register
6266 pressure calculations at any given program point to avoid necessary
6267 splitting even more but it is to expensive and the current approach
6268 works well enough. */
6269 static bool
6270 inherit_in_ebb (rtx_insn *head, rtx_insn *tail)
6271 {
6272 int i, src_regno, dst_regno, nregs;
6273 bool change_p, succ_p, update_reloads_num_p;
6274 rtx_insn *prev_insn, *last_insn;
6275 rtx next_usage_insns, curr_set;
6276 enum reg_class cl;
6277 struct lra_insn_reg *reg;
6278 basic_block last_processed_bb, curr_bb = NULL;
6279 HARD_REG_SET potential_reload_hard_regs, live_hard_regs;
6280 bitmap to_process;
6281 unsigned int j;
6282 bitmap_iterator bi;
6283 bool head_p, after_p;
6284
6285 change_p = false;
6286 curr_usage_insns_check++;
6287 clear_invariants ();
6288 reloads_num = calls_num = 0;
6289 for (unsigned int i = 0; i < NUM_ABI_IDS; ++i)
6290 last_call_for_abi[i] = 0;
6291 CLEAR_HARD_REG_SET (full_and_partial_call_clobbers);
6292 bitmap_clear (&check_only_regs);
6293 bitmap_clear (&invalid_invariant_regs);
6294 last_processed_bb = NULL;
6295 CLEAR_HARD_REG_SET (potential_reload_hard_regs);
6296 live_hard_regs = eliminable_regset | lra_no_alloc_regs;
6297 /* We don't process new insns generated in the loop. */
6298 for (curr_insn = tail; curr_insn != PREV_INSN (head); curr_insn = prev_insn)
6299 {
6300 prev_insn = PREV_INSN (curr_insn);
6301 if (BLOCK_FOR_INSN (curr_insn) != NULL)
6302 curr_bb = BLOCK_FOR_INSN (curr_insn);
6303 if (last_processed_bb != curr_bb)
6304 {
6305 /* We are at the end of BB. Add qualified living
6306 pseudos for potential splitting. */
6307 to_process = df_get_live_out (curr_bb);
6308 if (last_processed_bb != NULL)
6309 {
6310 /* We are somewhere in the middle of EBB. */
6311 get_live_on_other_edges (curr_bb, last_processed_bb,
6312 &temp_bitmap);
6313 to_process = &temp_bitmap;
6314 }
6315 last_processed_bb = curr_bb;
6316 last_insn = get_last_insertion_point (curr_bb);
6317 after_p = (! JUMP_P (last_insn)
6318 && (! CALL_P (last_insn)
6319 || (find_reg_note (last_insn,
6320 REG_NORETURN, NULL_RTX) == NULL_RTX
6321 && ! SIBLING_CALL_P (last_insn))));
6322 CLEAR_HARD_REG_SET (potential_reload_hard_regs);
6323 EXECUTE_IF_SET_IN_BITMAP (to_process, 0, j, bi)
6324 {
6325 if ((int) j >= lra_constraint_new_regno_start)
6326 break;
6327 if (j < FIRST_PSEUDO_REGISTER || reg_renumber[j] >= 0)
6328 {
6329 if (j < FIRST_PSEUDO_REGISTER)
6330 SET_HARD_REG_BIT (live_hard_regs, j);
6331 else
6332 add_to_hard_reg_set (&live_hard_regs,
6333 PSEUDO_REGNO_MODE (j),
6334 reg_renumber[j]);
6335 setup_next_usage_insn (j, last_insn, reloads_num, after_p);
6336 }
6337 }
6338 }
6339 src_regno = dst_regno = -1;
6340 curr_set = single_set (curr_insn);
6341 if (curr_set != NULL_RTX && REG_P (SET_DEST (curr_set)))
6342 dst_regno = REGNO (SET_DEST (curr_set));
6343 if (curr_set != NULL_RTX && REG_P (SET_SRC (curr_set)))
6344 src_regno = REGNO (SET_SRC (curr_set));
6345 update_reloads_num_p = true;
6346 if (src_regno < lra_constraint_new_regno_start
6347 && src_regno >= FIRST_PSEUDO_REGISTER
6348 && reg_renumber[src_regno] < 0
6349 && dst_regno >= lra_constraint_new_regno_start
6350 && (cl = lra_get_allocno_class (dst_regno)) != NO_REGS)
6351 {
6352 /* 'reload_pseudo <- original_pseudo'. */
6353 if (ira_class_hard_regs_num[cl] <= max_small_class_regs_num)
6354 reloads_num++;
6355 update_reloads_num_p = false;
6356 succ_p = false;
6357 if (usage_insns[src_regno].check == curr_usage_insns_check
6358 && (next_usage_insns = usage_insns[src_regno].insns) != NULL_RTX)
6359 succ_p = inherit_reload_reg (false, src_regno, cl,
6360 curr_insn, next_usage_insns);
6361 if (succ_p)
6362 change_p = true;
6363 else
6364 setup_next_usage_insn (src_regno, curr_insn, reloads_num, false);
6365 if (hard_reg_set_subset_p (reg_class_contents[cl], live_hard_regs))
6366 potential_reload_hard_regs |= reg_class_contents[cl];
6367 }
6368 else if (src_regno < 0
6369 && dst_regno >= lra_constraint_new_regno_start
6370 && invariant_p (SET_SRC (curr_set))
6371 && (cl = lra_get_allocno_class (dst_regno)) != NO_REGS
6372 && ! bitmap_bit_p (&invalid_invariant_regs, dst_regno)
6373 && ! bitmap_bit_p (&invalid_invariant_regs,
6374 ORIGINAL_REGNO(regno_reg_rtx[dst_regno])))
6375 {
6376 /* 'reload_pseudo <- invariant'. */
6377 if (ira_class_hard_regs_num[cl] <= max_small_class_regs_num)
6378 reloads_num++;
6379 update_reloads_num_p = false;
6380 if (process_invariant_for_inheritance (SET_DEST (curr_set), SET_SRC (curr_set)))
6381 change_p = true;
6382 if (hard_reg_set_subset_p (reg_class_contents[cl], live_hard_regs))
6383 potential_reload_hard_regs |= reg_class_contents[cl];
6384 }
6385 else if (src_regno >= lra_constraint_new_regno_start
6386 && dst_regno < lra_constraint_new_regno_start
6387 && dst_regno >= FIRST_PSEUDO_REGISTER
6388 && reg_renumber[dst_regno] < 0
6389 && (cl = lra_get_allocno_class (src_regno)) != NO_REGS
6390 && usage_insns[dst_regno].check == curr_usage_insns_check
6391 && (next_usage_insns
6392 = usage_insns[dst_regno].insns) != NULL_RTX)
6393 {
6394 if (ira_class_hard_regs_num[cl] <= max_small_class_regs_num)
6395 reloads_num++;
6396 update_reloads_num_p = false;
6397 /* 'original_pseudo <- reload_pseudo'. */
6398 if (! JUMP_P (curr_insn)
6399 && inherit_reload_reg (true, dst_regno, cl,
6400 curr_insn, next_usage_insns))
6401 change_p = true;
6402 /* Invalidate. */
6403 usage_insns[dst_regno].check = 0;
6404 if (hard_reg_set_subset_p (reg_class_contents[cl], live_hard_regs))
6405 potential_reload_hard_regs |= reg_class_contents[cl];
6406 }
6407 else if (INSN_P (curr_insn))
6408 {
6409 int iter;
6410 int max_uid = get_max_uid ();
6411
6412 curr_id = lra_get_insn_recog_data (curr_insn);
6413 curr_static_id = curr_id->insn_static_data;
6414 to_inherit_num = 0;
6415 /* Process insn definitions. */
6416 for (iter = 0; iter < 2; iter++)
6417 for (reg = iter == 0 ? curr_id->regs : curr_static_id->hard_regs;
6418 reg != NULL;
6419 reg = reg->next)
6420 if (reg->type != OP_IN
6421 && (dst_regno = reg->regno) < lra_constraint_new_regno_start)
6422 {
6423 if (dst_regno >= FIRST_PSEUDO_REGISTER && reg->type == OP_OUT
6424 && reg_renumber[dst_regno] < 0 && ! reg->subreg_p
6425 && usage_insns[dst_regno].check == curr_usage_insns_check
6426 && (next_usage_insns
6427 = usage_insns[dst_regno].insns) != NULL_RTX)
6428 {
6429 struct lra_insn_reg *r;
6430
6431 for (r = curr_id->regs; r != NULL; r = r->next)
6432 if (r->type != OP_OUT && r->regno == dst_regno)
6433 break;
6434 /* Don't do inheritance if the pseudo is also
6435 used in the insn. */
6436 if (r == NULL)
6437 /* We cannot do inheritance right now
6438 because the current insn reg info (chain
6439 regs) can change after that. */
6440 add_to_inherit (dst_regno, next_usage_insns);
6441 }
6442 /* We cannot process one reg twice here because of
6443 usage_insns invalidation. */
6444 if ((dst_regno < FIRST_PSEUDO_REGISTER
6445 || reg_renumber[dst_regno] >= 0)
6446 && ! reg->subreg_p && reg->type != OP_IN)
6447 {
6448 HARD_REG_SET s;
6449
6450 if (split_if_necessary (dst_regno, reg->biggest_mode,
6451 potential_reload_hard_regs,
6452 false, curr_insn, max_uid))
6453 change_p = true;
6454 CLEAR_HARD_REG_SET (s);
6455 if (dst_regno < FIRST_PSEUDO_REGISTER)
6456 add_to_hard_reg_set (&s, reg->biggest_mode, dst_regno);
6457 else
6458 add_to_hard_reg_set (&s, PSEUDO_REGNO_MODE (dst_regno),
6459 reg_renumber[dst_regno]);
6460 live_hard_regs &= ~s;
6461 potential_reload_hard_regs &= ~s;
6462 }
6463 /* We should invalidate potential inheritance or
6464 splitting for the current insn usages to the next
6465 usage insns (see code below) as the output pseudo
6466 prevents this. */
6467 if ((dst_regno >= FIRST_PSEUDO_REGISTER
6468 && reg_renumber[dst_regno] < 0)
6469 || (reg->type == OP_OUT && ! reg->subreg_p
6470 && (dst_regno < FIRST_PSEUDO_REGISTER
6471 || reg_renumber[dst_regno] >= 0)))
6472 {
6473 /* Invalidate and mark definitions. */
6474 if (dst_regno >= FIRST_PSEUDO_REGISTER)
6475 usage_insns[dst_regno].check = -(int) INSN_UID (curr_insn);
6476 else
6477 {
6478 nregs = hard_regno_nregs (dst_regno,
6479 reg->biggest_mode);
6480 for (i = 0; i < nregs; i++)
6481 usage_insns[dst_regno + i].check
6482 = -(int) INSN_UID (curr_insn);
6483 }
6484 }
6485 }
6486 /* Process clobbered call regs. */
6487 if (curr_id->arg_hard_regs != NULL)
6488 for (i = 0; (dst_regno = curr_id->arg_hard_regs[i]) >= 0; i++)
6489 if (dst_regno >= FIRST_PSEUDO_REGISTER)
6490 usage_insns[dst_regno - FIRST_PSEUDO_REGISTER].check
6491 = -(int) INSN_UID (curr_insn);
6492 if (! JUMP_P (curr_insn))
6493 for (i = 0; i < to_inherit_num; i++)
6494 if (inherit_reload_reg (true, to_inherit[i].regno,
6495 ALL_REGS, curr_insn,
6496 to_inherit[i].insns))
6497 change_p = true;
6498 if (CALL_P (curr_insn))
6499 {
6500 rtx cheap, pat, dest;
6501 rtx_insn *restore;
6502 int regno, hard_regno;
6503
6504 calls_num++;
6505 function_abi callee_abi = insn_callee_abi (curr_insn);
6506 last_call_for_abi[callee_abi.id ()] = calls_num;
6507 full_and_partial_call_clobbers
6508 |= callee_abi.full_and_partial_reg_clobbers ();
6509 if ((cheap = find_reg_note (curr_insn,
6510 REG_RETURNED, NULL_RTX)) != NULL_RTX
6511 && ((cheap = XEXP (cheap, 0)), true)
6512 && (regno = REGNO (cheap)) >= FIRST_PSEUDO_REGISTER
6513 && (hard_regno = reg_renumber[regno]) >= 0
6514 && usage_insns[regno].check == curr_usage_insns_check
6515 /* If there are pending saves/restores, the
6516 optimization is not worth. */
6517 && usage_insns[regno].calls_num == calls_num - 1
6518 && callee_abi.clobbers_reg_p (GET_MODE (cheap), hard_regno))
6519 {
6520 /* Restore the pseudo from the call result as
6521 REG_RETURNED note says that the pseudo value is
6522 in the call result and the pseudo is an argument
6523 of the call. */
6524 pat = PATTERN (curr_insn);
6525 if (GET_CODE (pat) == PARALLEL)
6526 pat = XVECEXP (pat, 0, 0);
6527 dest = SET_DEST (pat);
6528 /* For multiple return values dest is PARALLEL.
6529 Currently we handle only single return value case. */
6530 if (REG_P (dest))
6531 {
6532 start_sequence ();
6533 emit_move_insn (cheap, copy_rtx (dest));
6534 restore = get_insns ();
6535 end_sequence ();
6536 lra_process_new_insns (curr_insn, NULL, restore,
6537 "Inserting call parameter restore");
6538 /* We don't need to save/restore of the pseudo from
6539 this call. */
6540 usage_insns[regno].calls_num = calls_num;
6541 remove_from_hard_reg_set
6542 (&full_and_partial_call_clobbers,
6543 GET_MODE (cheap), hard_regno);
6544 bitmap_set_bit (&check_only_regs, regno);
6545 }
6546 }
6547 }
6548 to_inherit_num = 0;
6549 /* Process insn usages. */
6550 for (iter = 0; iter < 2; iter++)
6551 for (reg = iter == 0 ? curr_id->regs : curr_static_id->hard_regs;
6552 reg != NULL;
6553 reg = reg->next)
6554 if ((reg->type != OP_OUT
6555 || (reg->type == OP_OUT && reg->subreg_p))
6556 && (src_regno = reg->regno) < lra_constraint_new_regno_start)
6557 {
6558 if (src_regno >= FIRST_PSEUDO_REGISTER
6559 && reg_renumber[src_regno] < 0 && reg->type == OP_IN)
6560 {
6561 if (usage_insns[src_regno].check == curr_usage_insns_check
6562 && (next_usage_insns
6563 = usage_insns[src_regno].insns) != NULL_RTX
6564 && NONDEBUG_INSN_P (curr_insn))
6565 add_to_inherit (src_regno, next_usage_insns);
6566 else if (usage_insns[src_regno].check
6567 != -(int) INSN_UID (curr_insn))
6568 /* Add usages but only if the reg is not set up
6569 in the same insn. */
6570 add_next_usage_insn (src_regno, curr_insn, reloads_num);
6571 }
6572 else if (src_regno < FIRST_PSEUDO_REGISTER
6573 || reg_renumber[src_regno] >= 0)
6574 {
6575 bool before_p;
6576 rtx_insn *use_insn = curr_insn;
6577
6578 before_p = (JUMP_P (curr_insn)
6579 || (CALL_P (curr_insn) && reg->type == OP_IN));
6580 if (NONDEBUG_INSN_P (curr_insn)
6581 && (! JUMP_P (curr_insn) || reg->type == OP_IN)
6582 && split_if_necessary (src_regno, reg->biggest_mode,
6583 potential_reload_hard_regs,
6584 before_p, curr_insn, max_uid))
6585 {
6586 if (reg->subreg_p)
6587 check_and_force_assignment_correctness_p = true;
6588 change_p = true;
6589 /* Invalidate. */
6590 usage_insns[src_regno].check = 0;
6591 if (before_p)
6592 use_insn = PREV_INSN (curr_insn);
6593 }
6594 if (NONDEBUG_INSN_P (curr_insn))
6595 {
6596 if (src_regno < FIRST_PSEUDO_REGISTER)
6597 add_to_hard_reg_set (&live_hard_regs,
6598 reg->biggest_mode, src_regno);
6599 else
6600 add_to_hard_reg_set (&live_hard_regs,
6601 PSEUDO_REGNO_MODE (src_regno),
6602 reg_renumber[src_regno]);
6603 }
6604 if (src_regno >= FIRST_PSEUDO_REGISTER)
6605 add_next_usage_insn (src_regno, use_insn, reloads_num);
6606 else
6607 {
6608 for (i = 0; i < hard_regno_nregs (src_regno, reg->biggest_mode); i++)
6609 add_next_usage_insn (src_regno + i, use_insn, reloads_num);
6610 }
6611 }
6612 }
6613 /* Process used call regs. */
6614 if (curr_id->arg_hard_regs != NULL)
6615 for (i = 0; (src_regno = curr_id->arg_hard_regs[i]) >= 0; i++)
6616 if (src_regno < FIRST_PSEUDO_REGISTER)
6617 {
6618 SET_HARD_REG_BIT (live_hard_regs, src_regno);
6619 add_next_usage_insn (src_regno, curr_insn, reloads_num);
6620 }
6621 for (i = 0; i < to_inherit_num; i++)
6622 {
6623 src_regno = to_inherit[i].regno;
6624 if (inherit_reload_reg (false, src_regno, ALL_REGS,
6625 curr_insn, to_inherit[i].insns))
6626 change_p = true;
6627 else
6628 setup_next_usage_insn (src_regno, curr_insn, reloads_num, false);
6629 }
6630 }
6631 if (update_reloads_num_p
6632 && NONDEBUG_INSN_P (curr_insn) && curr_set != NULL_RTX)
6633 {
6634 int regno = -1;
6635 if ((REG_P (SET_DEST (curr_set))
6636 && (regno = REGNO (SET_DEST (curr_set))) >= lra_constraint_new_regno_start
6637 && reg_renumber[regno] < 0
6638 && (cl = lra_get_allocno_class (regno)) != NO_REGS)
6639 || (REG_P (SET_SRC (curr_set))
6640 && (regno = REGNO (SET_SRC (curr_set))) >= lra_constraint_new_regno_start
6641 && reg_renumber[regno] < 0
6642 && (cl = lra_get_allocno_class (regno)) != NO_REGS))
6643 {
6644 if (ira_class_hard_regs_num[cl] <= max_small_class_regs_num)
6645 reloads_num++;
6646 if (hard_reg_set_subset_p (reg_class_contents[cl], live_hard_regs))
6647 potential_reload_hard_regs |= reg_class_contents[cl];
6648 }
6649 }
6650 if (NONDEBUG_INSN_P (curr_insn))
6651 {
6652 int regno;
6653
6654 /* Invalidate invariants with changed regs. */
6655 curr_id = lra_get_insn_recog_data (curr_insn);
6656 for (reg = curr_id->regs; reg != NULL; reg = reg->next)
6657 if (reg->type != OP_IN)
6658 {
6659 bitmap_set_bit (&invalid_invariant_regs, reg->regno);
6660 bitmap_set_bit (&invalid_invariant_regs,
6661 ORIGINAL_REGNO (regno_reg_rtx[reg->regno]));
6662 }
6663 curr_static_id = curr_id->insn_static_data;
6664 for (reg = curr_static_id->hard_regs; reg != NULL; reg = reg->next)
6665 if (reg->type != OP_IN)
6666 bitmap_set_bit (&invalid_invariant_regs, reg->regno);
6667 if (curr_id->arg_hard_regs != NULL)
6668 for (i = 0; (regno = curr_id->arg_hard_regs[i]) >= 0; i++)
6669 if (regno >= FIRST_PSEUDO_REGISTER)
6670 bitmap_set_bit (&invalid_invariant_regs,
6671 regno - FIRST_PSEUDO_REGISTER);
6672 }
6673 /* We reached the start of the current basic block. */
6674 if (prev_insn == NULL_RTX || prev_insn == PREV_INSN (head)
6675 || BLOCK_FOR_INSN (prev_insn) != curr_bb)
6676 {
6677 /* We reached the beginning of the current block -- do
6678 rest of spliting in the current BB. */
6679 to_process = df_get_live_in (curr_bb);
6680 if (BLOCK_FOR_INSN (head) != curr_bb)
6681 {
6682 /* We are somewhere in the middle of EBB. */
6683 get_live_on_other_edges (EDGE_PRED (curr_bb, 0)->src,
6684 curr_bb, &temp_bitmap);
6685 to_process = &temp_bitmap;
6686 }
6687 head_p = true;
6688 EXECUTE_IF_SET_IN_BITMAP (to_process, 0, j, bi)
6689 {
6690 if ((int) j >= lra_constraint_new_regno_start)
6691 break;
6692 if (((int) j < FIRST_PSEUDO_REGISTER || reg_renumber[j] >= 0)
6693 && usage_insns[j].check == curr_usage_insns_check
6694 && (next_usage_insns = usage_insns[j].insns) != NULL_RTX)
6695 {
6696 if (need_for_split_p (potential_reload_hard_regs, j))
6697 {
6698 if (lra_dump_file != NULL && head_p)
6699 {
6700 fprintf (lra_dump_file,
6701 " ----------------------------------\n");
6702 head_p = false;
6703 }
6704 if (split_reg (false, j, bb_note (curr_bb),
6705 next_usage_insns, NULL))
6706 change_p = true;
6707 }
6708 usage_insns[j].check = 0;
6709 }
6710 }
6711 }
6712 }
6713 return change_p;
6714 }
6715
6716 /* This value affects EBB forming. If probability of edge from EBB to
6717 a BB is not greater than the following value, we don't add the BB
6718 to EBB. */
6719 #define EBB_PROBABILITY_CUTOFF \
6720 ((REG_BR_PROB_BASE * param_lra_inheritance_ebb_probability_cutoff) / 100)
6721
6722 /* Current number of inheritance/split iteration. */
6723 int lra_inheritance_iter;
6724
6725 /* Entry function for inheritance/split pass. */
6726 void
6727 lra_inheritance (void)
6728 {
6729 int i;
6730 basic_block bb, start_bb;
6731 edge e;
6732
6733 lra_inheritance_iter++;
6734 if (lra_inheritance_iter > LRA_MAX_INHERITANCE_PASSES)
6735 return;
6736 timevar_push (TV_LRA_INHERITANCE);
6737 if (lra_dump_file != NULL)
6738 fprintf (lra_dump_file, "\n********** Inheritance #%d: **********\n\n",
6739 lra_inheritance_iter);
6740 curr_usage_insns_check = 0;
6741 usage_insns = XNEWVEC (struct usage_insns, lra_constraint_new_regno_start);
6742 for (i = 0; i < lra_constraint_new_regno_start; i++)
6743 usage_insns[i].check = 0;
6744 bitmap_initialize (&check_only_regs, &reg_obstack);
6745 bitmap_initialize (&invalid_invariant_regs, &reg_obstack);
6746 bitmap_initialize (&live_regs, &reg_obstack);
6747 bitmap_initialize (&temp_bitmap, &reg_obstack);
6748 bitmap_initialize (&ebb_global_regs, &reg_obstack);
6749 FOR_EACH_BB_FN (bb, cfun)
6750 {
6751 start_bb = bb;
6752 if (lra_dump_file != NULL)
6753 fprintf (lra_dump_file, "EBB");
6754 /* Form a EBB starting with BB. */
6755 bitmap_clear (&ebb_global_regs);
6756 bitmap_ior_into (&ebb_global_regs, df_get_live_in (bb));
6757 for (;;)
6758 {
6759 if (lra_dump_file != NULL)
6760 fprintf (lra_dump_file, " %d", bb->index);
6761 if (bb->next_bb == EXIT_BLOCK_PTR_FOR_FN (cfun)
6762 || LABEL_P (BB_HEAD (bb->next_bb)))
6763 break;
6764 e = find_fallthru_edge (bb->succs);
6765 if (! e)
6766 break;
6767 if (e->probability.initialized_p ()
6768 && e->probability.to_reg_br_prob_base () < EBB_PROBABILITY_CUTOFF)
6769 break;
6770 bb = bb->next_bb;
6771 }
6772 bitmap_ior_into (&ebb_global_regs, df_get_live_out (bb));
6773 if (lra_dump_file != NULL)
6774 fprintf (lra_dump_file, "\n");
6775 if (inherit_in_ebb (BB_HEAD (start_bb), BB_END (bb)))
6776 /* Remember that the EBB head and tail can change in
6777 inherit_in_ebb. */
6778 update_ebb_live_info (BB_HEAD (start_bb), BB_END (bb));
6779 }
6780 bitmap_release (&ebb_global_regs);
6781 bitmap_release (&temp_bitmap);
6782 bitmap_release (&live_regs);
6783 bitmap_release (&invalid_invariant_regs);
6784 bitmap_release (&check_only_regs);
6785 free (usage_insns);
6786
6787 timevar_pop (TV_LRA_INHERITANCE);
6788 }
6789
6790 \f
6791
6792 /* This page contains code to undo failed inheritance/split
6793 transformations. */
6794
6795 /* Current number of iteration undoing inheritance/split. */
6796 int lra_undo_inheritance_iter;
6797
6798 /* Fix BB live info LIVE after removing pseudos created on pass doing
6799 inheritance/split which are REMOVED_PSEUDOS. */
6800 static void
6801 fix_bb_live_info (bitmap live, bitmap removed_pseudos)
6802 {
6803 unsigned int regno;
6804 bitmap_iterator bi;
6805
6806 EXECUTE_IF_SET_IN_BITMAP (removed_pseudos, 0, regno, bi)
6807 if (bitmap_clear_bit (live, regno)
6808 && REG_P (lra_reg_info[regno].restore_rtx))
6809 bitmap_set_bit (live, REGNO (lra_reg_info[regno].restore_rtx));
6810 }
6811
6812 /* Return regno of the (subreg of) REG. Otherwise, return a negative
6813 number. */
6814 static int
6815 get_regno (rtx reg)
6816 {
6817 if (GET_CODE (reg) == SUBREG)
6818 reg = SUBREG_REG (reg);
6819 if (REG_P (reg))
6820 return REGNO (reg);
6821 return -1;
6822 }
6823
6824 /* Delete a move INSN with destination reg DREGNO and a previous
6825 clobber insn with the same regno. The inheritance/split code can
6826 generate moves with preceding clobber and when we delete such moves
6827 we should delete the clobber insn too to keep the correct life
6828 info. */
6829 static void
6830 delete_move_and_clobber (rtx_insn *insn, int dregno)
6831 {
6832 rtx_insn *prev_insn = PREV_INSN (insn);
6833
6834 lra_set_insn_deleted (insn);
6835 lra_assert (dregno >= 0);
6836 if (prev_insn != NULL && NONDEBUG_INSN_P (prev_insn)
6837 && GET_CODE (PATTERN (prev_insn)) == CLOBBER
6838 && dregno == get_regno (XEXP (PATTERN (prev_insn), 0)))
6839 lra_set_insn_deleted (prev_insn);
6840 }
6841
6842 /* Remove inheritance/split pseudos which are in REMOVE_PSEUDOS and
6843 return true if we did any change. The undo transformations for
6844 inheritance looks like
6845 i <- i2
6846 p <- i => p <- i2
6847 or removing
6848 p <- i, i <- p, and i <- i3
6849 where p is original pseudo from which inheritance pseudo i was
6850 created, i and i3 are removed inheritance pseudos, i2 is another
6851 not removed inheritance pseudo. All split pseudos or other
6852 occurrences of removed inheritance pseudos are changed on the
6853 corresponding original pseudos.
6854
6855 The function also schedules insns changed and created during
6856 inheritance/split pass for processing by the subsequent constraint
6857 pass. */
6858 static bool
6859 remove_inheritance_pseudos (bitmap remove_pseudos)
6860 {
6861 basic_block bb;
6862 int regno, sregno, prev_sregno, dregno;
6863 rtx restore_rtx;
6864 rtx set, prev_set;
6865 rtx_insn *prev_insn;
6866 bool change_p, done_p;
6867
6868 change_p = ! bitmap_empty_p (remove_pseudos);
6869 /* We cannot finish the function right away if CHANGE_P is true
6870 because we need to marks insns affected by previous
6871 inheritance/split pass for processing by the subsequent
6872 constraint pass. */
6873 FOR_EACH_BB_FN (bb, cfun)
6874 {
6875 fix_bb_live_info (df_get_live_in (bb), remove_pseudos);
6876 fix_bb_live_info (df_get_live_out (bb), remove_pseudos);
6877 FOR_BB_INSNS_REVERSE (bb, curr_insn)
6878 {
6879 if (! INSN_P (curr_insn))
6880 continue;
6881 done_p = false;
6882 sregno = dregno = -1;
6883 if (change_p && NONDEBUG_INSN_P (curr_insn)
6884 && (set = single_set (curr_insn)) != NULL_RTX)
6885 {
6886 dregno = get_regno (SET_DEST (set));
6887 sregno = get_regno (SET_SRC (set));
6888 }
6889
6890 if (sregno >= 0 && dregno >= 0)
6891 {
6892 if (bitmap_bit_p (remove_pseudos, dregno)
6893 && ! REG_P (lra_reg_info[dregno].restore_rtx))
6894 {
6895 /* invariant inheritance pseudo <- original pseudo */
6896 if (lra_dump_file != NULL)
6897 {
6898 fprintf (lra_dump_file, " Removing invariant inheritance:\n");
6899 dump_insn_slim (lra_dump_file, curr_insn);
6900 fprintf (lra_dump_file, "\n");
6901 }
6902 delete_move_and_clobber (curr_insn, dregno);
6903 done_p = true;
6904 }
6905 else if (bitmap_bit_p (remove_pseudos, sregno)
6906 && ! REG_P (lra_reg_info[sregno].restore_rtx))
6907 {
6908 /* reload pseudo <- invariant inheritance pseudo */
6909 start_sequence ();
6910 /* We cannot just change the source. It might be
6911 an insn different from the move. */
6912 emit_insn (lra_reg_info[sregno].restore_rtx);
6913 rtx_insn *new_insns = get_insns ();
6914 end_sequence ();
6915 lra_assert (single_set (new_insns) != NULL
6916 && SET_DEST (set) == SET_DEST (single_set (new_insns)));
6917 lra_process_new_insns (curr_insn, NULL, new_insns,
6918 "Changing reload<-invariant inheritance");
6919 delete_move_and_clobber (curr_insn, dregno);
6920 done_p = true;
6921 }
6922 else if ((bitmap_bit_p (remove_pseudos, sregno)
6923 && (get_regno (lra_reg_info[sregno].restore_rtx) == dregno
6924 || (bitmap_bit_p (remove_pseudos, dregno)
6925 && get_regno (lra_reg_info[sregno].restore_rtx) >= 0
6926 && (get_regno (lra_reg_info[sregno].restore_rtx)
6927 == get_regno (lra_reg_info[dregno].restore_rtx)))))
6928 || (bitmap_bit_p (remove_pseudos, dregno)
6929 && get_regno (lra_reg_info[dregno].restore_rtx) == sregno))
6930 /* One of the following cases:
6931 original <- removed inheritance pseudo
6932 removed inherit pseudo <- another removed inherit pseudo
6933 removed inherit pseudo <- original pseudo
6934 Or
6935 removed_split_pseudo <- original_reg
6936 original_reg <- removed_split_pseudo */
6937 {
6938 if (lra_dump_file != NULL)
6939 {
6940 fprintf (lra_dump_file, " Removing %s:\n",
6941 bitmap_bit_p (&lra_split_regs, sregno)
6942 || bitmap_bit_p (&lra_split_regs, dregno)
6943 ? "split" : "inheritance");
6944 dump_insn_slim (lra_dump_file, curr_insn);
6945 }
6946 delete_move_and_clobber (curr_insn, dregno);
6947 done_p = true;
6948 }
6949 else if (bitmap_bit_p (remove_pseudos, sregno)
6950 && bitmap_bit_p (&lra_inheritance_pseudos, sregno))
6951 {
6952 /* Search the following pattern:
6953 inherit_or_split_pseudo1 <- inherit_or_split_pseudo2
6954 original_pseudo <- inherit_or_split_pseudo1
6955 where the 2nd insn is the current insn and
6956 inherit_or_split_pseudo2 is not removed. If it is found,
6957 change the current insn onto:
6958 original_pseudo <- inherit_or_split_pseudo2. */
6959 for (prev_insn = PREV_INSN (curr_insn);
6960 prev_insn != NULL_RTX && ! NONDEBUG_INSN_P (prev_insn);
6961 prev_insn = PREV_INSN (prev_insn))
6962 ;
6963 if (prev_insn != NULL_RTX && BLOCK_FOR_INSN (prev_insn) == bb
6964 && (prev_set = single_set (prev_insn)) != NULL_RTX
6965 /* There should be no subregs in insn we are
6966 searching because only the original reg might
6967 be in subreg when we changed the mode of
6968 load/store for splitting. */
6969 && REG_P (SET_DEST (prev_set))
6970 && REG_P (SET_SRC (prev_set))
6971 && (int) REGNO (SET_DEST (prev_set)) == sregno
6972 && ((prev_sregno = REGNO (SET_SRC (prev_set)))
6973 >= FIRST_PSEUDO_REGISTER)
6974 && (lra_reg_info[prev_sregno].restore_rtx == NULL_RTX
6975 ||
6976 /* As we consider chain of inheritance or
6977 splitting described in above comment we should
6978 check that sregno and prev_sregno were
6979 inheritance/split pseudos created from the
6980 same original regno. */
6981 (get_regno (lra_reg_info[sregno].restore_rtx) >= 0
6982 && (get_regno (lra_reg_info[sregno].restore_rtx)
6983 == get_regno (lra_reg_info[prev_sregno].restore_rtx))))
6984 && ! bitmap_bit_p (remove_pseudos, prev_sregno))
6985 {
6986 lra_assert (GET_MODE (SET_SRC (prev_set))
6987 == GET_MODE (regno_reg_rtx[sregno]));
6988 /* Although we have a single set, the insn can
6989 contain more one sregno register occurrence
6990 as a source. Change all occurrences. */
6991 lra_substitute_pseudo_within_insn (curr_insn, sregno,
6992 SET_SRC (prev_set),
6993 false);
6994 /* As we are finishing with processing the insn
6995 here, check the destination too as it might
6996 inheritance pseudo for another pseudo. */
6997 if (bitmap_bit_p (remove_pseudos, dregno)
6998 && bitmap_bit_p (&lra_inheritance_pseudos, dregno)
6999 && (restore_rtx
7000 = lra_reg_info[dregno].restore_rtx) != NULL_RTX)
7001 {
7002 if (GET_CODE (SET_DEST (set)) == SUBREG)
7003 SUBREG_REG (SET_DEST (set)) = restore_rtx;
7004 else
7005 SET_DEST (set) = restore_rtx;
7006 }
7007 lra_push_insn_and_update_insn_regno_info (curr_insn);
7008 lra_set_used_insn_alternative_by_uid
7009 (INSN_UID (curr_insn), LRA_UNKNOWN_ALT);
7010 done_p = true;
7011 if (lra_dump_file != NULL)
7012 {
7013 fprintf (lra_dump_file, " Change reload insn:\n");
7014 dump_insn_slim (lra_dump_file, curr_insn);
7015 }
7016 }
7017 }
7018 }
7019 if (! done_p)
7020 {
7021 struct lra_insn_reg *reg;
7022 bool restored_regs_p = false;
7023 bool kept_regs_p = false;
7024
7025 curr_id = lra_get_insn_recog_data (curr_insn);
7026 for (reg = curr_id->regs; reg != NULL; reg = reg->next)
7027 {
7028 regno = reg->regno;
7029 restore_rtx = lra_reg_info[regno].restore_rtx;
7030 if (restore_rtx != NULL_RTX)
7031 {
7032 if (change_p && bitmap_bit_p (remove_pseudos, regno))
7033 {
7034 lra_substitute_pseudo_within_insn
7035 (curr_insn, regno, restore_rtx, false);
7036 restored_regs_p = true;
7037 }
7038 else
7039 kept_regs_p = true;
7040 }
7041 }
7042 if (NONDEBUG_INSN_P (curr_insn) && kept_regs_p)
7043 {
7044 /* The instruction has changed since the previous
7045 constraints pass. */
7046 lra_push_insn_and_update_insn_regno_info (curr_insn);
7047 lra_set_used_insn_alternative_by_uid
7048 (INSN_UID (curr_insn), LRA_UNKNOWN_ALT);
7049 }
7050 else if (restored_regs_p)
7051 /* The instruction has been restored to the form that
7052 it had during the previous constraints pass. */
7053 lra_update_insn_regno_info (curr_insn);
7054 if (restored_regs_p && lra_dump_file != NULL)
7055 {
7056 fprintf (lra_dump_file, " Insn after restoring regs:\n");
7057 dump_insn_slim (lra_dump_file, curr_insn);
7058 }
7059 }
7060 }
7061 }
7062 return change_p;
7063 }
7064
7065 /* If optional reload pseudos failed to get a hard register or was not
7066 inherited, it is better to remove optional reloads. We do this
7067 transformation after undoing inheritance to figure out necessity to
7068 remove optional reloads easier. Return true if we do any
7069 change. */
7070 static bool
7071 undo_optional_reloads (void)
7072 {
7073 bool change_p, keep_p;
7074 unsigned int regno, uid;
7075 bitmap_iterator bi, bi2;
7076 rtx_insn *insn;
7077 rtx set, src, dest;
7078 auto_bitmap removed_optional_reload_pseudos (&reg_obstack);
7079
7080 bitmap_copy (removed_optional_reload_pseudos, &lra_optional_reload_pseudos);
7081 EXECUTE_IF_SET_IN_BITMAP (&lra_optional_reload_pseudos, 0, regno, bi)
7082 {
7083 keep_p = false;
7084 /* Keep optional reloads from previous subpasses. */
7085 if (lra_reg_info[regno].restore_rtx == NULL_RTX
7086 /* If the original pseudo changed its allocation, just
7087 removing the optional pseudo is dangerous as the original
7088 pseudo will have longer live range. */
7089 || reg_renumber[REGNO (lra_reg_info[regno].restore_rtx)] >= 0)
7090 keep_p = true;
7091 else if (reg_renumber[regno] >= 0)
7092 EXECUTE_IF_SET_IN_BITMAP (&lra_reg_info[regno].insn_bitmap, 0, uid, bi2)
7093 {
7094 insn = lra_insn_recog_data[uid]->insn;
7095 if ((set = single_set (insn)) == NULL_RTX)
7096 continue;
7097 src = SET_SRC (set);
7098 dest = SET_DEST (set);
7099 if (! REG_P (src) || ! REG_P (dest))
7100 continue;
7101 if (REGNO (dest) == regno
7102 /* Ignore insn for optional reloads itself. */
7103 && REGNO (lra_reg_info[regno].restore_rtx) != REGNO (src)
7104 /* Check only inheritance on last inheritance pass. */
7105 && (int) REGNO (src) >= new_regno_start
7106 /* Check that the optional reload was inherited. */
7107 && bitmap_bit_p (&lra_inheritance_pseudos, REGNO (src)))
7108 {
7109 keep_p = true;
7110 break;
7111 }
7112 }
7113 if (keep_p)
7114 {
7115 bitmap_clear_bit (removed_optional_reload_pseudos, regno);
7116 if (lra_dump_file != NULL)
7117 fprintf (lra_dump_file, "Keep optional reload reg %d\n", regno);
7118 }
7119 }
7120 change_p = ! bitmap_empty_p (removed_optional_reload_pseudos);
7121 auto_bitmap insn_bitmap (&reg_obstack);
7122 EXECUTE_IF_SET_IN_BITMAP (removed_optional_reload_pseudos, 0, regno, bi)
7123 {
7124 if (lra_dump_file != NULL)
7125 fprintf (lra_dump_file, "Remove optional reload reg %d\n", regno);
7126 bitmap_copy (insn_bitmap, &lra_reg_info[regno].insn_bitmap);
7127 EXECUTE_IF_SET_IN_BITMAP (insn_bitmap, 0, uid, bi2)
7128 {
7129 insn = lra_insn_recog_data[uid]->insn;
7130 if ((set = single_set (insn)) != NULL_RTX)
7131 {
7132 src = SET_SRC (set);
7133 dest = SET_DEST (set);
7134 if (REG_P (src) && REG_P (dest)
7135 && ((REGNO (src) == regno
7136 && (REGNO (lra_reg_info[regno].restore_rtx)
7137 == REGNO (dest)))
7138 || (REGNO (dest) == regno
7139 && (REGNO (lra_reg_info[regno].restore_rtx)
7140 == REGNO (src)))))
7141 {
7142 if (lra_dump_file != NULL)
7143 {
7144 fprintf (lra_dump_file, " Deleting move %u\n",
7145 INSN_UID (insn));
7146 dump_insn_slim (lra_dump_file, insn);
7147 }
7148 delete_move_and_clobber (insn, REGNO (dest));
7149 continue;
7150 }
7151 /* We should not worry about generation memory-memory
7152 moves here as if the corresponding inheritance did
7153 not work (inheritance pseudo did not get a hard reg),
7154 we remove the inheritance pseudo and the optional
7155 reload. */
7156 }
7157 lra_substitute_pseudo_within_insn
7158 (insn, regno, lra_reg_info[regno].restore_rtx, false);
7159 lra_update_insn_regno_info (insn);
7160 if (lra_dump_file != NULL)
7161 {
7162 fprintf (lra_dump_file,
7163 " Restoring original insn:\n");
7164 dump_insn_slim (lra_dump_file, insn);
7165 }
7166 }
7167 }
7168 /* Clear restore_regnos. */
7169 EXECUTE_IF_SET_IN_BITMAP (&lra_optional_reload_pseudos, 0, regno, bi)
7170 lra_reg_info[regno].restore_rtx = NULL_RTX;
7171 return change_p;
7172 }
7173
7174 /* Entry function for undoing inheritance/split transformation. Return true
7175 if we did any RTL change in this pass. */
7176 bool
7177 lra_undo_inheritance (void)
7178 {
7179 unsigned int regno;
7180 int hard_regno;
7181 int n_all_inherit, n_inherit, n_all_split, n_split;
7182 rtx restore_rtx;
7183 bitmap_iterator bi;
7184 bool change_p;
7185
7186 lra_undo_inheritance_iter++;
7187 if (lra_undo_inheritance_iter > LRA_MAX_INHERITANCE_PASSES)
7188 return false;
7189 if (lra_dump_file != NULL)
7190 fprintf (lra_dump_file,
7191 "\n********** Undoing inheritance #%d: **********\n\n",
7192 lra_undo_inheritance_iter);
7193 auto_bitmap remove_pseudos (&reg_obstack);
7194 n_inherit = n_all_inherit = 0;
7195 EXECUTE_IF_SET_IN_BITMAP (&lra_inheritance_pseudos, 0, regno, bi)
7196 if (lra_reg_info[regno].restore_rtx != NULL_RTX)
7197 {
7198 n_all_inherit++;
7199 if (reg_renumber[regno] < 0
7200 /* If the original pseudo changed its allocation, just
7201 removing inheritance is dangerous as for changing
7202 allocation we used shorter live-ranges. */
7203 && (! REG_P (lra_reg_info[regno].restore_rtx)
7204 || reg_renumber[REGNO (lra_reg_info[regno].restore_rtx)] < 0))
7205 bitmap_set_bit (remove_pseudos, regno);
7206 else
7207 n_inherit++;
7208 }
7209 if (lra_dump_file != NULL && n_all_inherit != 0)
7210 fprintf (lra_dump_file, "Inherit %d out of %d (%.2f%%)\n",
7211 n_inherit, n_all_inherit,
7212 (double) n_inherit / n_all_inherit * 100);
7213 n_split = n_all_split = 0;
7214 EXECUTE_IF_SET_IN_BITMAP (&lra_split_regs, 0, regno, bi)
7215 if ((restore_rtx = lra_reg_info[regno].restore_rtx) != NULL_RTX)
7216 {
7217 int restore_regno = REGNO (restore_rtx);
7218
7219 n_all_split++;
7220 hard_regno = (restore_regno >= FIRST_PSEUDO_REGISTER
7221 ? reg_renumber[restore_regno] : restore_regno);
7222 if (hard_regno < 0 || reg_renumber[regno] == hard_regno)
7223 bitmap_set_bit (remove_pseudos, regno);
7224 else
7225 {
7226 n_split++;
7227 if (lra_dump_file != NULL)
7228 fprintf (lra_dump_file, " Keep split r%d (orig=r%d)\n",
7229 regno, restore_regno);
7230 }
7231 }
7232 if (lra_dump_file != NULL && n_all_split != 0)
7233 fprintf (lra_dump_file, "Split %d out of %d (%.2f%%)\n",
7234 n_split, n_all_split,
7235 (double) n_split / n_all_split * 100);
7236 change_p = remove_inheritance_pseudos (remove_pseudos);
7237 /* Clear restore_regnos. */
7238 EXECUTE_IF_SET_IN_BITMAP (&lra_inheritance_pseudos, 0, regno, bi)
7239 lra_reg_info[regno].restore_rtx = NULL_RTX;
7240 EXECUTE_IF_SET_IN_BITMAP (&lra_split_regs, 0, regno, bi)
7241 lra_reg_info[regno].restore_rtx = NULL_RTX;
7242 change_p = undo_optional_reloads () || change_p;
7243 return change_p;
7244 }