Line data Source code
1 : /* Code for RTL transformations to satisfy insn constraints.
2 : Copyright (C) 2010-2026 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 "hooks.h"
114 : #include "target.h"
115 : #include "rtl.h"
116 : #include "tree.h"
117 : #include "stmt.h"
118 : #include "predict.h"
119 : #include "df.h"
120 : #include "memmodel.h"
121 : #include "tm_p.h"
122 : #include "expmed.h"
123 : #include "optabs.h"
124 : #include "regs.h"
125 : #include "ira.h"
126 : #include "ira-int.h"
127 : #include "recog.h"
128 : #include "output.h"
129 : #include "addresses.h"
130 : #include "expr.h"
131 : #include "cfgrtl.h"
132 : #include "rtl-error.h"
133 : #include "lra.h"
134 : #include "lra-int.h"
135 : #include "print-rtl.h"
136 : #include "function-abi.h"
137 : #include "rtl-iter.h"
138 : #include "hash-set.h"
139 :
140 : /* Value of LRA_CURR_RELOAD_NUM at the beginning of BB of the current
141 : insn. Remember that LRA_CURR_RELOAD_NUM is the number of emitted
142 : reload insns. */
143 : static int bb_reload_num;
144 :
145 : /* The current insn being processed and corresponding its single set
146 : (NULL otherwise), its data (basic block, the insn data, the insn
147 : static data, and the mode of each operand). */
148 : static rtx_insn *curr_insn;
149 : static rtx curr_insn_set;
150 : static basic_block curr_bb;
151 : static lra_insn_recog_data_t curr_id;
152 : static struct lra_static_insn_data *curr_static_id;
153 : static machine_mode curr_operand_mode[MAX_RECOG_OPERANDS];
154 : /* Mode of the register substituted by its equivalence with VOIDmode
155 : (e.g. constant) and whose subreg is given operand of the current
156 : insn. VOIDmode in all other cases. */
157 : static machine_mode original_subreg_reg_mode[MAX_RECOG_OPERANDS];
158 : /* The first call insn after curr_insn within the EBB during inherit_in_ebb
159 : or NULL outside of that function. */
160 : static rtx_insn *first_call_insn;
161 :
162 :
163 :
164 : /* Start numbers for new registers and insns at the current constraints
165 : pass start. */
166 : static int new_regno_start;
167 : static int new_insn_uid_start;
168 :
169 : /* If LOC is nonnull, strip any outer subreg from it. */
170 : static inline rtx *
171 231487954 : strip_subreg (rtx *loc)
172 : {
173 102400822 : return loc && GET_CODE (*loc) == SUBREG ? &SUBREG_REG (*loc) : loc;
174 : }
175 :
176 : /* Return hard regno of REGNO or if it is was not assigned to a hard
177 : register, use a hard register from its allocno class. */
178 : static int
179 77190 : get_try_hard_regno (int regno)
180 : {
181 77190 : int hard_regno;
182 77190 : enum reg_class rclass;
183 :
184 77190 : if ((hard_regno = regno) >= FIRST_PSEUDO_REGISTER)
185 77190 : hard_regno = lra_get_regno_hard_regno (regno);
186 77190 : if (hard_regno >= 0)
187 : return hard_regno;
188 42864 : rclass = lra_get_allocno_class (regno);
189 42864 : if (rclass == NO_REGS)
190 : return -1;
191 41497 : return ira_class_hard_regs[rclass][0];
192 : }
193 :
194 : /* Return the hard regno of X after removing its subreg. If X is not a
195 : register or a subreg of a register, return -1. If X is a pseudo, use its
196 : assignment. If X is a hard regno, return the final hard regno which will be
197 : after elimination. */
198 : static int
199 293366140 : get_hard_regno (rtx x)
200 : {
201 293366140 : rtx reg;
202 293366140 : int hard_regno;
203 :
204 293366140 : reg = x;
205 293366140 : if (SUBREG_P (x))
206 5313536 : reg = SUBREG_REG (x);
207 293366140 : if (! REG_P (reg))
208 : return -1;
209 202611932 : int regno = REGNO (reg);
210 202611932 : if (HARD_REGISTER_NUM_P (regno))
211 35541598 : hard_regno = lra_get_elimination_hard_regno (regno);
212 : else
213 167070334 : hard_regno = lra_get_regno_hard_regno (regno);
214 202611932 : if (hard_regno < 0)
215 : return -1;
216 184454004 : if (SUBREG_P (x))
217 4605559 : hard_regno += subreg_regno_offset (hard_regno, GET_MODE (reg),
218 4605559 : SUBREG_BYTE (x), GET_MODE (x));
219 : return hard_regno;
220 : }
221 :
222 : /* If REGNO is a hard register or has been allocated a hard register,
223 : return the class of that register. If REGNO is a reload pseudo
224 : created by the current constraints pass, return its allocno class.
225 : Return NO_REGS otherwise. */
226 : static enum reg_class
227 521931194 : get_reg_class (int regno)
228 : {
229 521931194 : int hard_regno;
230 :
231 521931194 : if (HARD_REGISTER_NUM_P (regno))
232 66706886 : hard_regno = lra_get_elimination_hard_regno (regno);
233 : else
234 455224308 : hard_regno = lra_get_regno_hard_regno (regno);
235 521931194 : if (hard_regno >= 0)
236 326463159 : return REGNO_REG_CLASS (hard_regno);
237 195468035 : if (regno >= new_regno_start)
238 63664201 : return lra_get_allocno_class (regno);
239 : return NO_REGS;
240 : }
241 :
242 : /* Return true if REG_CLASS has enough allocatable hard regs to keep value of
243 : REG_MODE. */
244 : static bool
245 19166822 : enough_allocatable_hard_regs_p (enum reg_class reg_class,
246 : enum machine_mode reg_mode)
247 : {
248 19166822 : int i, j, hard_regno, class_size, nregs;
249 :
250 38333644 : if (hard_reg_set_subset_p (reg_class_contents[reg_class], lra_no_alloc_regs))
251 : return false;
252 6530361 : class_size = ira_class_hard_regs_num[reg_class];
253 6530361 : for (i = 0; i < class_size; i++)
254 : {
255 6530361 : hard_regno = ira_class_hard_regs[reg_class][i];
256 6530361 : nregs = hard_regno_nregs (hard_regno, reg_mode);
257 6530361 : if (nregs == 1)
258 : return true;
259 255705 : for (j = 0; j < nregs; j++)
260 170470 : if (TEST_HARD_REG_BIT (lra_no_alloc_regs, hard_regno + j)
261 170470 : || ! TEST_HARD_REG_BIT (reg_class_contents[reg_class],
262 : hard_regno + j))
263 : break;
264 85235 : if (j >= nregs)
265 : return true;
266 : }
267 : return false;
268 : }
269 :
270 : /* True if C is a non-empty register class that has too few registers
271 : to be safely used as a reload target class. */
272 : #define SMALL_REGISTER_CLASS_P(C) \
273 : (ira_class_hard_regs_num [(C)] == 1 \
274 : || (ira_class_hard_regs_num [(C)] >= 1 \
275 : && targetm.class_likely_spilled_p (C)))
276 :
277 : /* Return true if REG satisfies (or will satisfy) reg class constraint
278 : CL. Use elimination first if REG is a hard register. If REG is a
279 : reload pseudo created by this constraints pass, assume that it will
280 : be allocated a hard register from its allocno class, but allow that
281 : class to be narrowed to CL if it is currently a superset of CL and
282 : if either:
283 :
284 : - ALLOW_ALL_RELOAD_CLASS_CHANGES_P is true or
285 : - the instruction we're processing is not a reload move.
286 :
287 : If NEW_CLASS is nonnull, set *NEW_CLASS to the new allocno class of
288 : REGNO (reg), or NO_REGS if no change in its class was needed. */
289 : static bool
290 221859245 : in_class_p (rtx reg, enum reg_class cl, enum reg_class *new_class,
291 : bool allow_all_reload_class_changes_p = false)
292 : {
293 221859245 : enum reg_class rclass, common_class;
294 221859245 : machine_mode reg_mode;
295 221859245 : rtx src;
296 221859245 : int regno = REGNO (reg);
297 :
298 221859245 : if (new_class != NULL)
299 114034598 : *new_class = NO_REGS;
300 221859245 : if (regno < FIRST_PSEUDO_REGISTER)
301 : {
302 28113346 : rtx final_reg = reg;
303 28113346 : rtx *final_loc = &final_reg;
304 :
305 28113346 : lra_eliminate_reg_if_possible (final_loc);
306 28113346 : return TEST_HARD_REG_BIT (reg_class_contents[cl], REGNO (*final_loc));
307 : }
308 193745899 : reg_mode = GET_MODE (reg);
309 193745899 : rclass = get_reg_class (regno);
310 193745899 : src = curr_insn_set != NULL ? SET_SRC (curr_insn_set) : NULL;
311 193745899 : if (regno < new_regno_start
312 : /* Do not allow the constraints for reload instructions to
313 : influence the classes of new pseudos. These reloads are
314 : typically moves that have many alternatives, and restricting
315 : reload pseudos for one alternative may lead to situations
316 : where other reload pseudos are no longer allocatable. */
317 193745899 : || (!allow_all_reload_class_changes_p
318 15380950 : && INSN_UID (curr_insn) >= new_insn_uid_start
319 14850545 : && src != NULL
320 14850545 : && ((REG_P (src) || MEM_P (src))
321 1480187 : || (GET_CODE (src) == SUBREG
322 649200 : && (REG_P (SUBREG_REG (src)) || MEM_P (SUBREG_REG (src)))))))
323 : /* When we don't know what class will be used finally for reload
324 : pseudos, we use ALL_REGS. */
325 14019558 : return ((regno >= new_regno_start && rclass == ALL_REGS)
326 188596188 : || (rclass != NO_REGS && ira_class_subset_p[rclass][cl]
327 203446440 : && ! hard_reg_set_subset_p (reg_class_contents[cl],
328 : lra_no_alloc_regs)));
329 : else
330 : {
331 19166822 : common_class = ira_reg_class_subset[rclass][cl];
332 19166822 : if (new_class != NULL)
333 5389536 : *new_class = common_class;
334 19166822 : return (enough_allocatable_hard_regs_p (common_class, reg_mode)
335 : /* Do not permit reload insn operand matching (new_class == NULL
336 : case) if the new class is too small. */
337 19166822 : && (new_class != NULL || common_class == rclass
338 1052863 : || !SMALL_REGISTER_CLASS_P (common_class)));
339 : }
340 : }
341 :
342 : /* Return true if REGNO satisfies a memory constraint. */
343 : static bool
344 64720706 : in_mem_p (int regno)
345 : {
346 0 : return get_reg_class (regno) == NO_REGS;
347 : }
348 :
349 : /* Return true if ADDR is a valid memory address for mode MODE in address
350 : space AS, and check that each pseudo has the proper kind of hard
351 : reg. */
352 : static bool
353 36011632 : valid_address_p (machine_mode mode ATTRIBUTE_UNUSED,
354 : rtx addr, addr_space_t as)
355 : {
356 : #ifdef GO_IF_LEGITIMATE_ADDRESS
357 : lra_assert (ADDR_SPACE_GENERIC_P (as));
358 : GO_IF_LEGITIMATE_ADDRESS (mode, addr, win);
359 : return false;
360 :
361 : win:
362 : return true;
363 : #else
364 0 : return targetm.addr_space.legitimate_address_p (mode, addr, 0, as,
365 36011632 : ERROR_MARK);
366 : #endif
367 : }
368 :
369 : namespace {
370 : /* Temporarily eliminates registers in an address (for the lifetime of
371 : the object). */
372 : class address_eliminator {
373 : public:
374 : address_eliminator (struct address_info *ad);
375 : ~address_eliminator ();
376 :
377 : private:
378 : struct address_info *m_ad;
379 : rtx *m_base_loc;
380 : rtx m_base_reg;
381 : rtx *m_index_loc;
382 : rtx m_index_reg;
383 : };
384 : }
385 :
386 75838881 : address_eliminator::address_eliminator (struct address_info *ad)
387 75838881 : : m_ad (ad),
388 75838881 : m_base_loc (strip_subreg (ad->base_term)),
389 75838881 : m_base_reg (NULL_RTX),
390 75838881 : m_index_loc (strip_subreg (ad->index_term)),
391 75838881 : m_index_reg (NULL_RTX)
392 : {
393 75838881 : if (m_base_loc != NULL)
394 : {
395 63324346 : m_base_reg = *m_base_loc;
396 : /* If we have non-legitimate address which is decomposed not in
397 : the way we expected, don't do elimination here. In such case
398 : the address will be reloaded and elimination will be done in
399 : reload insn finally. */
400 63324346 : if (REG_P (m_base_reg))
401 63324346 : lra_eliminate_reg_if_possible (m_base_loc);
402 63324346 : if (m_ad->base_term2 != NULL)
403 0 : *m_ad->base_term2 = *m_ad->base_term;
404 : }
405 75838881 : if (m_index_loc != NULL)
406 : {
407 3563465 : m_index_reg = *m_index_loc;
408 3563465 : if (REG_P (m_index_reg))
409 3563465 : lra_eliminate_reg_if_possible (m_index_loc);
410 : }
411 75838881 : }
412 :
413 75838881 : address_eliminator::~address_eliminator ()
414 : {
415 75838881 : if (m_base_loc && *m_base_loc != m_base_reg)
416 : {
417 44884000 : *m_base_loc = m_base_reg;
418 44884000 : if (m_ad->base_term2 != NULL)
419 0 : *m_ad->base_term2 = *m_ad->base_term;
420 : }
421 75838881 : if (m_index_loc && *m_index_loc != m_index_reg)
422 0 : *m_index_loc = m_index_reg;
423 75838881 : }
424 :
425 : /* Return true if the eliminated form of AD is a legitimate target address.
426 : If OP is a MEM, AD is the address within OP, otherwise OP should be
427 : ignored. CONSTRAINT is one constraint that the operand may need
428 : to meet. */
429 : static bool
430 35988580 : valid_address_p (rtx op, struct address_info *ad,
431 : enum constraint_num constraint)
432 : {
433 35988580 : address_eliminator eliminator (ad);
434 :
435 : /* Allow a memory OP if it matches CONSTRAINT, even if CONSTRAINT is more
436 : forgiving than "m".
437 : Need to extract memory from op for special memory constraint,
438 : i.e. bcst_mem_operand in i386 backend. */
439 35988580 : if (MEM_P (extract_mem_from_operand (op))
440 : && insn_extra_relaxed_memory_constraint (constraint)
441 : && constraint_satisfied_p (op, constraint))
442 : return true;
443 :
444 35988580 : return valid_address_p (ad->mode, *ad->outer, ad->as);
445 35988580 : }
446 :
447 : /* For special_memory_operand, it could be false for MEM_P (op),
448 : i.e. bcst_mem_operand in i386 backend.
449 : Extract and return real memory operand or op. */
450 : rtx
451 633636696 : extract_mem_from_operand (rtx op)
452 : {
453 635325911 : for (rtx x = op;; x = XEXP (x, 0))
454 : {
455 635325911 : if (MEM_P (x))
456 : return x;
457 452397975 : if (GET_RTX_LENGTH (GET_CODE (x)) != 1
458 370330806 : || GET_RTX_FORMAT (GET_CODE (x))[0] != 'e')
459 : break;
460 : }
461 : return op;
462 : }
463 :
464 : /* Return true if the eliminated form of memory reference OP satisfies
465 : extra (special) memory constraint CONSTRAINT. */
466 : static bool
467 37302349 : satisfies_memory_constraint_p (rtx op, enum constraint_num constraint)
468 : {
469 37302349 : struct address_info ad;
470 37302349 : rtx mem = extract_mem_from_operand (op);
471 37302349 : if (!MEM_P (mem))
472 : return false;
473 :
474 36260374 : decompose_mem_address (&ad, mem);
475 36260374 : address_eliminator eliminator (&ad);
476 36260374 : return constraint_satisfied_p (op, constraint);
477 36260374 : }
478 :
479 : /* Return true if the eliminated form of address AD satisfies extra
480 : address constraint CONSTRAINT. */
481 : static bool
482 3589927 : satisfies_address_constraint_p (struct address_info *ad,
483 : enum constraint_num constraint)
484 : {
485 3589927 : address_eliminator eliminator (ad);
486 3589927 : return constraint_satisfied_p (*ad->outer, constraint);
487 3589927 : }
488 :
489 : /* Return true if the eliminated form of address OP satisfies extra
490 : address constraint CONSTRAINT. */
491 : static bool
492 1763726 : satisfies_address_constraint_p (rtx op, enum constraint_num constraint)
493 : {
494 1763726 : struct address_info ad;
495 :
496 1763726 : decompose_lea_address (&ad, &op);
497 1763726 : return satisfies_address_constraint_p (&ad, constraint);
498 : }
499 :
500 : /* Set of equivalences whose original targets have set up pointer flag. */
501 : static hash_set <rtx> *pointer_equiv_set;
502 :
503 : /* Add x to pointer_equiv_set. */
504 : void
505 2002999 : lra_pointer_equiv_set_add (rtx x)
506 : {
507 2002999 : pointer_equiv_set->add (x);
508 2002999 : }
509 :
510 : /* Return true if x is in pointer_equiv_set. */
511 : bool
512 10046959 : lra_pointer_equiv_set_in (rtx x)
513 : {
514 10046959 : return pointer_equiv_set->contains (x);
515 : }
516 :
517 : /* Initiate equivalences for LRA. As we keep original equivalences
518 : before any elimination, we need to make copies otherwise any change
519 : in insns might change the equivalences. */
520 : void
521 1504950 : lra_init_equiv (void)
522 : {
523 1504950 : ira_expand_reg_equiv ();
524 71088195 : for (int i = FIRST_PSEUDO_REGISTER; i < max_reg_num (); i++)
525 : {
526 69583245 : rtx res;
527 :
528 69583245 : if ((res = ira_reg_equiv[i].memory) != NULL_RTX)
529 3026915 : ira_reg_equiv[i].memory = copy_rtx (res);
530 69583245 : if ((res = ira_reg_equiv[i].invariant) != NULL_RTX)
531 903696 : ira_reg_equiv[i].invariant = copy_rtx (res);
532 : }
533 1504950 : pointer_equiv_set = new hash_set <rtx>;
534 1504950 : }
535 :
536 : /* Finish equivalence data for LRA. */
537 : void
538 1504950 : lra_finish_equiv (void)
539 : {
540 3009900 : delete pointer_equiv_set;
541 1504950 : }
542 :
543 : static rtx loc_equivalence_callback (rtx, const_rtx, void *);
544 :
545 : /* Update equivalence for REGNO. We need to this as the equivalence
546 : might contain other pseudos which are changed by their
547 : equivalences. */
548 : static void
549 206815139 : update_equiv (int regno)
550 : {
551 206815139 : rtx x;
552 :
553 206815139 : if ((x = ira_reg_equiv[regno].memory) != NULL_RTX)
554 9196432 : ira_reg_equiv[regno].memory
555 9196432 : = simplify_replace_fn_rtx (x, NULL_RTX, loc_equivalence_callback,
556 : NULL_RTX);
557 206815139 : if ((x = ira_reg_equiv[regno].invariant) != NULL_RTX)
558 2806219 : ira_reg_equiv[regno].invariant
559 2806219 : = simplify_replace_fn_rtx (x, NULL_RTX, loc_equivalence_callback,
560 : NULL_RTX);
561 206815139 : }
562 :
563 : /* If we have decided to substitute X with another value, return that
564 : value, otherwise return X. */
565 : static rtx
566 443227509 : get_equiv (rtx x)
567 : {
568 443227509 : int regno;
569 443227509 : rtx res;
570 :
571 299856864 : if (! REG_P (x) || (regno = REGNO (x)) < FIRST_PSEUDO_REGISTER
572 198629399 : || regno >= ira_reg_equiv_len
573 198629399 : || ! ira_reg_equiv[regno].defined_p
574 25855851 : || ! ira_reg_equiv[regno].profitable_p
575 469041785 : || lra_get_regno_hard_regno (regno) >= 0)
576 438126269 : return x;
577 5101240 : if ((res = ira_reg_equiv[regno].memory) != NULL_RTX)
578 : {
579 2265919 : if (targetm.cannot_substitute_mem_equiv_p (res))
580 : return x;
581 : return res;
582 : }
583 2835321 : if ((res = ira_reg_equiv[regno].constant) != NULL_RTX)
584 : {
585 871738 : if (targetm.cannot_substitute_const_equiv_p (res))
586 : return x;
587 : return res;
588 : }
589 1963583 : if ((res = ira_reg_equiv[regno].invariant) != NULL_RTX)
590 : return res;
591 0 : gcc_unreachable ();
592 : }
593 :
594 : /* If we have decided to substitute X with the equivalent value, return that
595 : value after elimination for INSN, otherwise return X. Add the result to
596 : pointer_equiv_set if X has set up pointer flag. */
597 : static rtx
598 249336247 : get_equiv_with_elimination (rtx x, rtx_insn *insn)
599 : {
600 249336247 : rtx res = get_equiv (x);
601 :
602 249336247 : if (x == res || CONSTANT_P (res))
603 : return res;
604 1557961 : res = lra_eliminate_regs_1 (insn, res, GET_MODE (res),
605 : false, false, 0, true);
606 1557961 : if (REG_POINTER (x))
607 1078548 : lra_pointer_equiv_set_add (res);
608 : return res;
609 : }
610 :
611 : /* Set up curr_operand_mode. */
612 : static void
613 107706638 : init_curr_operand_mode (void)
614 : {
615 107706638 : int nop = curr_static_id->n_operands;
616 335764298 : for (int i = 0; i < nop; i++)
617 : {
618 228057660 : machine_mode mode = GET_MODE (*curr_id->operand_loc[i]);
619 228057660 : if (mode == VOIDmode)
620 : {
621 : /* The .md mode for address operands is the mode of the
622 : addressed value rather than the mode of the address itself. */
623 44142908 : if (curr_id->icode >= 0 && curr_static_id->operand[i].is_address)
624 95 : mode = Pmode;
625 : else
626 44142813 : mode = curr_static_id->operand[i].mode;
627 : }
628 228057660 : curr_operand_mode[i] = mode;
629 : }
630 107706638 : }
631 :
632 :
633 :
634 : /* The page contains code to reuse input reloads. */
635 :
636 : /* Structure describes input reload of the current insns. */
637 : struct input_reload
638 : {
639 : /* True for input reload of matched operands. */
640 : bool match_p;
641 : /* True for input reload of inout earlyclobber operand. */
642 : bool early_clobber_p;
643 : /* Reloaded value. */
644 : rtx input;
645 : /* Reload pseudo used. */
646 : rtx reg;
647 : };
648 :
649 : /* The number of elements in the following array. */
650 : static int curr_insn_input_reloads_num;
651 : /* Array containing info about input reloads. It is used to find the
652 : same input reload and reuse the reload pseudo in this case. */
653 : static struct input_reload curr_insn_input_reloads[LRA_MAX_INSN_RELOADS];
654 :
655 : /* Initiate data concerning reuse of input reloads for the current
656 : insn. */
657 : static void
658 107706638 : init_curr_insn_input_reloads (void)
659 : {
660 107706638 : curr_insn_input_reloads_num = 0;
661 0 : }
662 :
663 : /* The canonical form of an rtx inside a MEM is not necessarily the same as the
664 : canonical form of the rtx outside the MEM. Fix this up in the case that
665 : we're reloading an address (and therefore pulling it outside a MEM). */
666 : static rtx
667 72 : canonicalize_reload_addr (rtx addr)
668 : {
669 72 : subrtx_var_iterator::array_type array;
670 246 : FOR_EACH_SUBRTX_VAR (iter, array, addr, NONCONST)
671 : {
672 174 : rtx x = *iter;
673 174 : if (GET_CODE (x) == MULT && CONST_INT_P (XEXP (x, 1)))
674 : {
675 14 : const HOST_WIDE_INT ci = INTVAL (XEXP (x, 1));
676 188 : const int pwr2 = exact_log2 (ci);
677 14 : if (pwr2 > 0)
678 : {
679 : /* Rewrite this to use a shift instead, which is canonical when
680 : outside of a MEM. */
681 14 : PUT_CODE (x, ASHIFT);
682 14 : XEXP (x, 1) = GEN_INT (pwr2);
683 : }
684 : }
685 : }
686 :
687 72 : return addr;
688 72 : }
689 :
690 : /* Return rtx accessing reload REG of RCLASS matching another reload reg in
691 : MODE. */
692 : static rtx
693 125830 : get_matching_reload_reg_subreg (machine_mode mode, rtx reg,
694 : enum reg_class rclass)
695 : {
696 125830 : int hard_regno = ira_class_hard_regs[rclass][0];
697 125830 : if (subreg_regno_offset (hard_regno,
698 125830 : GET_MODE (reg),
699 125830 : subreg_lowpart_offset (mode, GET_MODE (reg)),
700 : mode) == 0)
701 : /* For matching scalar int modes generate the right subreg byte offset for
702 : BE targets -- see call of reload.cc:operands_match_p in
703 : recog.cc:constrain_operands. */
704 125830 : return lowpart_subreg (mode, reg, GET_MODE (reg));
705 0 : int offset = (lra_constraint_offset (hard_regno, GET_MODE (reg))
706 0 : - lra_constraint_offset (hard_regno, mode)) * UNITS_PER_WORD;
707 0 : lra_assert (offset >= 0);
708 0 : return gen_rtx_SUBREG (mode, reg, offset);
709 : }
710 :
711 : /* Create a new pseudo using MODE, RCLASS, EXCLUDE_START_HARD_REGS, ORIGINAL or
712 : reuse an existing reload pseudo. Don't reuse an existing reload pseudo if
713 : IN_SUBREG_P is true and the reused pseudo should be wrapped up in a SUBREG.
714 : EARLY_CLOBBER_P is true for input reload of inout early clobber operand.
715 : The result pseudo is returned through RESULT_REG. Return TRUE if we created
716 : a new pseudo, FALSE if we reused an existing reload pseudo. Use TITLE to
717 : describe new registers for debug purposes. */
718 : static bool
719 3910043 : get_reload_reg (enum op_type type, machine_mode mode, rtx original,
720 : enum reg_class rclass, HARD_REG_SET *exclude_start_hard_regs,
721 : bool in_subreg_p, bool early_clobber_p,
722 : const char *title, rtx *result_reg)
723 : {
724 3910043 : int i, regno;
725 3910043 : enum reg_class new_class;
726 :
727 3910043 : if (type == OP_OUT)
728 : {
729 : /* Output reload registers tend to start out with a conservative
730 : choice of register class. Usually this is ALL_REGS, although
731 : a target might narrow it (for performance reasons) through
732 : targetm.preferred_reload_class. It's therefore quite common
733 : for a reload instruction to require a more restrictive class
734 : than the class that was originally assigned to the reload register.
735 :
736 : In these situations, it's more efficient to refine the choice
737 : of register class rather than create a second reload register.
738 : This also helps to avoid cycling for registers that are only
739 : used by reload instructions. */
740 977593 : if (REG_P (original)
741 716256 : && (int) REGNO (original) >= new_regno_start
742 7310 : && (INSN_UID (curr_insn) >= new_insn_uid_start
743 250 : || ira_former_scratch_p (REGNO (original)))
744 7310 : && in_class_p (original, rclass, &new_class, true)
745 977843 : && (exclude_start_hard_regs == nullptr
746 250 : || hard_reg_set_intersect_p (
747 977843 : ~lra_reg_info[REGNO (original)].exclude_start_hard_regs,
748 250 : ~*exclude_start_hard_regs)))
749 : {
750 250 : unsigned int regno = REGNO (original);
751 250 : if (lra_dump_file != NULL)
752 : {
753 0 : fprintf (lra_dump_file, " Reuse r%d for output ", regno);
754 0 : dump_value_slim (lra_dump_file, original, 1);
755 : }
756 500 : if (new_class != lra_get_allocno_class (regno))
757 250 : lra_change_class (regno, new_class, ", change to", false);
758 250 : if (lra_dump_file != NULL)
759 0 : fprintf (lra_dump_file, "\n");
760 250 : if (exclude_start_hard_regs)
761 250 : lra_reg_info[regno].exclude_start_hard_regs
762 250 : |= *exclude_start_hard_regs;
763 250 : *result_reg = original;
764 250 : return false;
765 : }
766 977343 : *result_reg
767 977343 : = lra_create_new_reg_with_unique_value (mode, original, rclass,
768 : exclude_start_hard_regs, title);
769 977343 : return true;
770 : }
771 :
772 2932450 : bool unique_p = early_clobber_p;
773 : /* Prevent reuse value of expression with side effects,
774 : e.g. volatile memory. */
775 2932450 : if (! side_effects_p (original))
776 3161263 : for (i = 0; i < curr_insn_input_reloads_num; i++)
777 : {
778 247949 : if (! curr_insn_input_reloads[i].match_p
779 102155 : && ! curr_insn_input_reloads[i].early_clobber_p
780 102154 : && rtx_equal_p (curr_insn_input_reloads[i].input, original)
781 257057 : && in_class_p (curr_insn_input_reloads[i].reg, rclass, &new_class))
782 : {
783 9095 : rtx reg = curr_insn_input_reloads[i].reg;
784 9095 : regno = REGNO (reg);
785 : /* If input is equal to original and both are VOIDmode,
786 : GET_MODE (reg) might be still different from mode.
787 : Ensure we don't return *result_reg with wrong mode. */
788 9095 : if (GET_MODE (reg) != mode)
789 : {
790 0 : if (in_subreg_p)
791 0 : continue;
792 0 : if (maybe_lt (GET_MODE_SIZE (GET_MODE (reg)),
793 0 : GET_MODE_SIZE (mode)))
794 0 : continue;
795 0 : reg = get_matching_reload_reg_subreg (mode, reg, new_class);
796 0 : if (reg == NULL_RTX || GET_CODE (reg) != SUBREG)
797 0 : continue;
798 : }
799 : /* If the existing reload and this have no start hard register in
800 : common, then skip. Otherwise update exclude_start_hard_regs. */
801 9095 : if (exclude_start_hard_regs
802 10397 : && ! hard_reg_set_empty_p (*exclude_start_hard_regs))
803 : {
804 1 : HARD_REG_SET r = lra_reg_info[regno].exclude_start_hard_regs
805 1 : | *exclude_start_hard_regs;
806 2 : if (hard_reg_set_empty_p (~r))
807 0 : continue;
808 : else
809 1 : lra_reg_info[regno].exclude_start_hard_regs = r;
810 : }
811 9095 : *result_reg = reg;
812 9095 : if (lra_dump_file != NULL)
813 : {
814 0 : fprintf (lra_dump_file, " Reuse r%d for reload ", regno);
815 0 : dump_value_slim (lra_dump_file, original, 1);
816 : }
817 18190 : if (new_class != lra_get_allocno_class (regno))
818 4430 : lra_change_class (regno, new_class, ", change to", false);
819 9095 : if (lra_dump_file != NULL)
820 0 : fprintf (lra_dump_file, "\n");
821 9095 : return false;
822 : }
823 : /* If we have an input reload with a different mode, make sure it
824 : will get a different hard reg. */
825 238854 : else if (REG_P (original)
826 186914 : && REG_P (curr_insn_input_reloads[i].input)
827 153394 : && REGNO (original) == REGNO (curr_insn_input_reloads[i].input)
828 238854 : && (GET_MODE (original)
829 2379 : != GET_MODE (curr_insn_input_reloads[i].input)))
830 : unique_p = true;
831 : }
832 5846710 : *result_reg = (unique_p
833 2923355 : ? lra_create_new_reg_with_unique_value
834 2923355 : : lra_create_new_reg) (mode, original, rclass,
835 : exclude_start_hard_regs, title);
836 2923355 : lra_assert (curr_insn_input_reloads_num < LRA_MAX_INSN_RELOADS);
837 2923355 : curr_insn_input_reloads[curr_insn_input_reloads_num].input = original;
838 2923355 : curr_insn_input_reloads[curr_insn_input_reloads_num].match_p = false;
839 2923355 : curr_insn_input_reloads[curr_insn_input_reloads_num].early_clobber_p
840 2923355 : = early_clobber_p;
841 2923355 : curr_insn_input_reloads[curr_insn_input_reloads_num++].reg = *result_reg;
842 2923355 : return true;
843 : }
844 :
845 :
846 : /* The page contains major code to choose the current insn alternative
847 : and generate reloads for it. */
848 :
849 : /* Return the offset from REGNO of the least significant register
850 : in (reg:MODE REGNO).
851 :
852 : This function is used to tell whether two registers satisfy
853 : a matching constraint. (reg:MODE1 REGNO1) matches (reg:MODE2 REGNO2) if:
854 :
855 : REGNO1 + lra_constraint_offset (REGNO1, MODE1)
856 : == REGNO2 + lra_constraint_offset (REGNO2, MODE2) */
857 : int
858 44304850 : lra_constraint_offset (int regno, machine_mode mode)
859 : {
860 44304850 : lra_assert (regno < FIRST_PSEUDO_REGISTER);
861 :
862 44304850 : scalar_int_mode int_mode;
863 44304850 : if (WORDS_BIG_ENDIAN
864 : && is_a <scalar_int_mode> (mode, &int_mode)
865 : && GET_MODE_SIZE (int_mode) > UNITS_PER_WORD)
866 : return hard_regno_nregs (regno, mode) - 1;
867 44304850 : return 0;
868 : }
869 :
870 : /* Like rtx_equal_p except that it allows a REG and a SUBREG to match
871 : if they are the same hard reg, and has special hacks for
872 : auto-increment and auto-decrement. This is specifically intended for
873 : process_alt_operands to use in determining whether two operands
874 : match. X is the operand whose number is the lower of the two.
875 :
876 : It is supposed that X is the output operand and Y is the input
877 : operand. Y_HARD_REGNO is the final hard regno of register Y or
878 : register in subreg Y as we know it now. Otherwise, it is a
879 : negative value. */
880 : static bool
881 58649677 : operands_match_p (rtx x, rtx y, int y_hard_regno)
882 : {
883 58649677 : int i;
884 58649677 : RTX_CODE code = GET_CODE (x);
885 58649677 : const char *fmt;
886 :
887 58649677 : if (x == y)
888 : return true;
889 50955418 : if ((code == REG || (code == SUBREG && REG_P (SUBREG_REG (x))))
890 24182087 : && (REG_P (y) || (GET_CODE (y) == SUBREG && REG_P (SUBREG_REG (y)))))
891 : {
892 24088871 : int j;
893 :
894 24088871 : i = get_hard_regno (x);
895 24088871 : if (i < 0)
896 1243750 : goto slow;
897 :
898 22845121 : if ((j = y_hard_regno) < 0)
899 692696 : goto slow;
900 :
901 22152425 : i += lra_constraint_offset (i, GET_MODE (x));
902 22152425 : j += lra_constraint_offset (j, GET_MODE (y));
903 :
904 22152425 : return i == j;
905 : }
906 :
907 : /* If two operands must match, because they are really a single
908 : operand of an assembler insn, then two post-increments are invalid
909 : because the assembler insn would increment only once. On the
910 : other hand, a post-increment matches ordinary indexing if the
911 : post-increment is the output operand. */
912 26866547 : if (code == POST_DEC || code == POST_INC || code == POST_MODIFY)
913 0 : return operands_match_p (XEXP (x, 0), y, y_hard_regno);
914 :
915 : /* Two pre-increments are invalid because the assembler insn would
916 : increment only once. On the other hand, a pre-increment matches
917 : ordinary indexing if the pre-increment is the input operand. */
918 26866547 : if (GET_CODE (y) == PRE_DEC || GET_CODE (y) == PRE_INC
919 26866547 : || GET_CODE (y) == PRE_MODIFY)
920 0 : return operands_match_p (x, XEXP (y, 0), -1);
921 :
922 26866547 : slow:
923 :
924 28802993 : if (code == REG && REG_P (y))
925 1841102 : return REGNO (x) == REGNO (y);
926 :
927 94348 : if (code == REG && GET_CODE (y) == SUBREG && REG_P (SUBREG_REG (y))
928 7942 : && x == SUBREG_REG (y))
929 : return true;
930 26961891 : if (GET_CODE (y) == REG && code == SUBREG && REG_P (SUBREG_REG (x))
931 62130 : && SUBREG_REG (x) == y)
932 : return true;
933 :
934 : /* Now we have disposed of all the cases in which different rtx
935 : codes can match. */
936 26961717 : if (code != GET_CODE (y))
937 : return false;
938 :
939 : /* (MULT:SI x y) and (MULT:HI x y) are NOT equivalent. */
940 1079683 : if (GET_MODE (x) != GET_MODE (y))
941 : return false;
942 :
943 1078932 : switch (code)
944 : {
945 : CASE_CONST_UNIQUE:
946 : return false;
947 :
948 : case CONST_VECTOR:
949 : if (!same_vector_encodings_p (x, y))
950 : return false;
951 : break;
952 :
953 0 : case LABEL_REF:
954 0 : return label_ref_label (x) == label_ref_label (y);
955 25 : case SYMBOL_REF:
956 25 : return XSTR (x, 0) == XSTR (y, 0);
957 :
958 : default:
959 : break;
960 : }
961 :
962 : /* Compare the elements. If any pair of corresponding elements fail
963 : to match, return false for the whole things. */
964 :
965 1054050 : fmt = GET_RTX_FORMAT (code);
966 3050126 : for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
967 : {
968 2073187 : int val, j;
969 2073187 : switch (fmt[i])
970 : {
971 0 : case 'w':
972 0 : if (XWINT (x, i) != XWINT (y, i))
973 : return false;
974 : break;
975 :
976 494 : case 'i':
977 494 : if (XINT (x, i) != XINT (y, i))
978 : return false;
979 : break;
980 :
981 0 : case 'L':
982 0 : if (XLOC (x, i) != XLOC (y, i))
983 : return false;
984 : break;
985 :
986 25184 : case 'p':
987 25184 : if (maybe_ne (SUBREG_BYTE (x), SUBREG_BYTE (y)))
988 : return false;
989 : break;
990 :
991 1506446 : case 'e':
992 1506446 : val = operands_match_p (XEXP (x, i), XEXP (y, i), -1);
993 1506446 : if (val == 0)
994 : return false;
995 : break;
996 :
997 : case '0':
998 : break;
999 :
1000 494 : case 'E':
1001 494 : if (XVECLEN (x, i) != XVECLEN (y, i))
1002 : return false;
1003 988 : for (j = XVECLEN (x, i) - 1; j >= 0; --j)
1004 : {
1005 494 : val = operands_match_p (XVECEXP (x, i, j), XVECEXP (y, i, j), -1);
1006 494 : if (val == 0)
1007 : return false;
1008 : }
1009 : break;
1010 :
1011 : /* It is believed that rtx's at this level will never
1012 : contain anything but integers and other rtx's, except for
1013 : within LABEL_REFs and SYMBOL_REFs. */
1014 0 : default:
1015 0 : gcc_unreachable ();
1016 : }
1017 : }
1018 : return true;
1019 : }
1020 :
1021 : /* If REG is a reload pseudo, try to make its class satisfying CL. */
1022 : static void
1023 3527794 : narrow_reload_pseudo_class (rtx reg, enum reg_class cl)
1024 : {
1025 3527794 : enum reg_class rclass;
1026 :
1027 : /* Do not make more accurate class from reloads generated. They are
1028 : mostly moves with a lot of constraints. Making more accurate
1029 : class may results in very narrow class and impossibility of find
1030 : registers for several reloads of one insn. */
1031 3527794 : if (INSN_UID (curr_insn) >= new_insn_uid_start)
1032 3527762 : return;
1033 3527676 : if (GET_CODE (reg) == SUBREG)
1034 166805 : reg = SUBREG_REG (reg);
1035 3527676 : if (! REG_P (reg) || (int) REGNO (reg) < new_regno_start)
1036 : return;
1037 32 : if (in_class_p (reg, cl, &rclass) && rclass != cl)
1038 13 : lra_change_class (REGNO (reg), rclass, " Change to", true);
1039 : }
1040 :
1041 : /* Searches X for any reference to a reg with the same value as REGNO,
1042 : returning the rtx of the reference found if any. Otherwise,
1043 : returns NULL_RTX. */
1044 : static rtx
1045 555194 : regno_val_use_in (unsigned int regno, rtx x)
1046 : {
1047 555194 : const char *fmt;
1048 555194 : int i, j;
1049 555194 : rtx tem;
1050 :
1051 555194 : if (REG_P (x) && lra_reg_info[REGNO (x)].val == lra_reg_info[regno].val)
1052 : return x;
1053 :
1054 554849 : fmt = GET_RTX_FORMAT (GET_CODE (x));
1055 1116104 : for (i = GET_RTX_LENGTH (GET_CODE (x)) - 1; i >= 0; i--)
1056 : {
1057 561255 : if (fmt[i] == 'e')
1058 : {
1059 7691 : if ((tem = regno_val_use_in (regno, XEXP (x, i))))
1060 : return tem;
1061 : }
1062 553564 : else if (fmt[i] == 'E')
1063 0 : for (j = XVECLEN (x, i) - 1; j >= 0; j--)
1064 0 : if ((tem = regno_val_use_in (regno , XVECEXP (x, i, j))))
1065 : return tem;
1066 : }
1067 :
1068 : return NULL_RTX;
1069 : }
1070 :
1071 : /* Return true if all current insn non-output operands except INS (it
1072 : has a negaitve end marker) do not use pseudos with the same value
1073 : as REGNO. */
1074 : static bool
1075 2 : check_conflict_input_operands (int regno, signed char *ins)
1076 : {
1077 2 : int in;
1078 2 : int n_operands = curr_static_id->n_operands;
1079 :
1080 8 : for (int nop = 0; nop < n_operands; nop++)
1081 7 : if (! curr_static_id->operand[nop].is_operator
1082 7 : && curr_static_id->operand[nop].type != OP_OUT)
1083 : {
1084 5 : for (int i = 0; (in = ins[i]) >= 0; i++)
1085 4 : if (in == nop)
1086 : break;
1087 3 : if (in < 0
1088 3 : && regno_val_use_in (regno, *curr_id->operand_loc[nop]) != NULL_RTX)
1089 : return false;
1090 : }
1091 : return true;
1092 : }
1093 :
1094 : /* Generate reloads for matching OUT and INS (array of input operand numbers
1095 : with end marker -1) with reg class GOAL_CLASS and EXCLUDE_START_HARD_REGS,
1096 : considering output operands OUTS (similar array to INS) needing to be in
1097 : different registers. Add input and output reloads correspondingly to the
1098 : lists *BEFORE and *AFTER. OUT might be negative. In this case we generate
1099 : input reloads for matched input operands INS. EARLY_CLOBBER_P is a flag
1100 : that the output operand is early clobbered for chosen alternative. */
1101 : static void
1102 1763897 : match_reload (signed char out, signed char *ins, signed char *outs,
1103 : enum reg_class goal_class, HARD_REG_SET *exclude_start_hard_regs,
1104 : rtx_insn **before, rtx_insn **after, bool early_clobber_p)
1105 : {
1106 1763897 : bool out_conflict;
1107 1763897 : int i, in;
1108 1763897 : rtx new_in_reg, new_out_reg, reg;
1109 1763897 : machine_mode inmode, outmode;
1110 1763897 : rtx in_rtx = *curr_id->operand_loc[ins[0]];
1111 1763897 : rtx out_rtx = out < 0 ? in_rtx : *curr_id->operand_loc[out];
1112 :
1113 1763897 : inmode = curr_operand_mode[ins[0]];
1114 1763897 : outmode = out < 0 ? inmode : curr_operand_mode[out];
1115 1763897 : push_to_sequence (*before);
1116 1763897 : if (inmode != outmode)
1117 : {
1118 : /* process_alt_operands has already checked that the mode sizes
1119 : are ordered. */
1120 125830 : if (partial_subreg_p (outmode, inmode))
1121 : {
1122 1689 : bool asm_p = asm_noperands (PATTERN (curr_insn)) >= 0;
1123 1689 : int hr;
1124 1689 : HARD_REG_SET temp_hard_reg_set;
1125 :
1126 19 : if (asm_p && (hr = get_hard_regno (out_rtx)) >= 0
1127 1692 : && hard_regno_nregs (hr, inmode) > 1)
1128 : {
1129 : /* See gcc.c-torture/execute/20030222-1.c.
1130 : Consider the code for 32-bit (e.g. BE) target:
1131 : int i, v; long x; x = v; asm ("" : "=r" (i) : "0" (x));
1132 : We generate the following RTL with reload insns:
1133 : 1. subreg:si(x:di, 0) = 0;
1134 : 2. subreg:si(x:di, 4) = v:si;
1135 : 3. t:di = x:di, dead x;
1136 : 4. asm ("" : "=r" (subreg:si(t:di,4)) : "0" (t:di))
1137 : 5. i:si = subreg:si(t:di,4);
1138 : If we assign hard reg of x to t, dead code elimination
1139 : will remove insn #2 and we will use uninitialized hard reg.
1140 : So exclude the hard reg of x for t. We could ignore this
1141 : problem for non-empty asm using all x value but it is hard to
1142 : check that the asm are expanded into insn really using x
1143 : and setting r. */
1144 0 : CLEAR_HARD_REG_SET (temp_hard_reg_set);
1145 0 : if (exclude_start_hard_regs != NULL)
1146 0 : temp_hard_reg_set = *exclude_start_hard_regs;
1147 0 : SET_HARD_REG_BIT (temp_hard_reg_set, hr);
1148 0 : exclude_start_hard_regs = &temp_hard_reg_set;
1149 : }
1150 3378 : reg = new_in_reg
1151 1689 : = lra_create_new_reg_with_unique_value (inmode, in_rtx, goal_class,
1152 : exclude_start_hard_regs,
1153 : "");
1154 1689 : new_out_reg = get_matching_reload_reg_subreg (outmode, reg, goal_class);
1155 1689 : LRA_SUBREG_P (new_out_reg) = 1;
1156 : /* If the input reg is dying here, we can use the same hard
1157 : register for REG and IN_RTX. We do it only for original
1158 : pseudos as reload pseudos can die although original
1159 : pseudos still live where reload pseudos dies. */
1160 1368 : if (REG_P (in_rtx) && (int) REGNO (in_rtx) < lra_new_regno_start
1161 1310 : && find_regno_note (curr_insn, REG_DEAD, REGNO (in_rtx))
1162 2490 : && (!early_clobber_p
1163 2 : || check_conflict_input_operands(REGNO (in_rtx), ins)))
1164 800 : lra_assign_reg_val (REGNO (in_rtx), REGNO (reg));
1165 : }
1166 : else
1167 : {
1168 248282 : reg = new_out_reg
1169 124141 : = lra_create_new_reg_with_unique_value (outmode, out_rtx,
1170 : goal_class,
1171 : exclude_start_hard_regs,
1172 : "");
1173 124141 : new_in_reg = get_matching_reload_reg_subreg (inmode, reg, goal_class);
1174 : /* NEW_IN_REG is non-paradoxical subreg. We don't want
1175 : NEW_OUT_REG living above. We add clobber clause for
1176 : this. This is just a temporary clobber. We can remove
1177 : it at the end of LRA work. */
1178 124141 : rtx_insn *clobber = emit_clobber (new_out_reg);
1179 124141 : LRA_TEMP_CLOBBER_P (PATTERN (clobber)) = 1;
1180 124141 : LRA_SUBREG_P (new_in_reg) = 1;
1181 124141 : if (GET_CODE (in_rtx) == SUBREG)
1182 : {
1183 1794 : rtx subreg_reg = SUBREG_REG (in_rtx);
1184 :
1185 : /* If SUBREG_REG is dying here and sub-registers IN_RTX
1186 : and NEW_IN_REG are similar, we can use the same hard
1187 : register for REG and SUBREG_REG. */
1188 1794 : if (REG_P (subreg_reg)
1189 1794 : && (int) REGNO (subreg_reg) < lra_new_regno_start
1190 1794 : && GET_MODE (subreg_reg) == outmode
1191 1118 : && known_eq (SUBREG_BYTE (in_rtx), SUBREG_BYTE (new_in_reg))
1192 1118 : && find_regno_note (curr_insn, REG_DEAD, REGNO (subreg_reg))
1193 1900 : && (! early_clobber_p
1194 0 : || check_conflict_input_operands (REGNO (subreg_reg),
1195 : ins)))
1196 106 : lra_assign_reg_val (REGNO (subreg_reg), REGNO (reg));
1197 : }
1198 : }
1199 : }
1200 : else
1201 : {
1202 : /* Pseudos have values -- see comments for lra_reg_info.
1203 : Different pseudos with the same value do not conflict even if
1204 : they live in the same place. When we create a pseudo we
1205 : assign value of original pseudo (if any) from which we
1206 : created the new pseudo. If we create the pseudo from the
1207 : input pseudo, the new pseudo will have no conflict with the
1208 : input pseudo which is wrong when the input pseudo lives after
1209 : the insn and as the new pseudo value is changed by the insn
1210 : output. Therefore we create the new pseudo from the output
1211 : except the case when we have single matched dying input
1212 : pseudo.
1213 :
1214 : We cannot reuse the current output register because we might
1215 : have a situation like "a <- a op b", where the constraints
1216 : force the second input operand ("b") to match the output
1217 : operand ("a"). "b" must then be copied into a new register
1218 : so that it doesn't clobber the current value of "a".
1219 :
1220 : We cannot use the same value if the output pseudo is
1221 : early clobbered or the input pseudo is mentioned in the
1222 : output, e.g. as an address part in memory, because
1223 : output reload will actually extend the pseudo liveness.
1224 : We don't care about eliminable hard regs here as we are
1225 : interesting only in pseudos. */
1226 :
1227 : /* Matching input's register value is the same as one of the other
1228 : output operand. Output operands in a parallel insn must be in
1229 : different registers. */
1230 1638067 : out_conflict = false;
1231 1638067 : if (REG_P (in_rtx))
1232 : {
1233 2839187 : for (i = 0; outs[i] >= 0; i++)
1234 : {
1235 1476782 : rtx other_out_rtx = *curr_id->operand_loc[outs[i]];
1236 114148 : if (outs[i] != out && REG_P (other_out_rtx)
1237 1590736 : && (regno_val_use_in (REGNO (in_rtx), other_out_rtx)
1238 : != NULL_RTX))
1239 : {
1240 : out_conflict = true;
1241 : break;
1242 : }
1243 : }
1244 : }
1245 :
1246 1638067 : new_in_reg = new_out_reg
1247 1605992 : = (! early_clobber_p && ins[1] < 0 && REG_P (in_rtx)
1248 1331392 : && (int) REGNO (in_rtx) < lra_new_regno_start
1249 1331107 : && find_regno_note (curr_insn, REG_DEAD, REGNO (in_rtx))
1250 433548 : && (out < 0
1251 433548 : || regno_val_use_in (REGNO (in_rtx), out_rtx) == NULL_RTX)
1252 433497 : && !out_conflict
1253 2071562 : ? lra_create_new_reg (inmode, in_rtx, goal_class,
1254 : exclude_start_hard_regs, "")
1255 1204572 : : lra_create_new_reg_with_unique_value (outmode, out_rtx, goal_class,
1256 : exclude_start_hard_regs,
1257 : ""));
1258 : }
1259 : /* In operand can be got from transformations before processing insn
1260 : constraints. One example of such transformations is subreg
1261 : reloading (see function simplify_operand_subreg). The new
1262 : pseudos created by the transformations might have inaccurate
1263 : class (ALL_REGS) and we should make their classes more
1264 : accurate. */
1265 1763897 : narrow_reload_pseudo_class (in_rtx, goal_class);
1266 1763897 : lra_emit_move (copy_rtx (new_in_reg), in_rtx);
1267 1763897 : *before = end_sequence ();
1268 : /* Add the new pseudo to consider values of subsequent input reload
1269 : pseudos. */
1270 1763897 : lra_assert (curr_insn_input_reloads_num < LRA_MAX_INSN_RELOADS);
1271 1763897 : curr_insn_input_reloads[curr_insn_input_reloads_num].input = in_rtx;
1272 1763897 : curr_insn_input_reloads[curr_insn_input_reloads_num].match_p = true;
1273 1763897 : curr_insn_input_reloads[curr_insn_input_reloads_num].early_clobber_p = false;
1274 1763897 : curr_insn_input_reloads[curr_insn_input_reloads_num++].reg = new_in_reg;
1275 3527795 : for (i = 0; (in = ins[i]) >= 0; i++)
1276 1763898 : if (GET_MODE (*curr_id->operand_loc[in]) == VOIDmode
1277 1735096 : || GET_MODE (new_in_reg) == GET_MODE (*curr_id->operand_loc[in]))
1278 1763897 : *curr_id->operand_loc[in] = new_in_reg;
1279 : else
1280 : {
1281 1 : lra_assert
1282 : (GET_MODE (new_out_reg) == GET_MODE (*curr_id->operand_loc[in]));
1283 1 : *curr_id->operand_loc[in] = new_out_reg;
1284 : }
1285 1763897 : lra_update_dups (curr_id, ins);
1286 1763897 : if (out < 0)
1287 : return;
1288 : /* See a comment for the input operand above. */
1289 1763897 : narrow_reload_pseudo_class (out_rtx, goal_class);
1290 1763897 : reg = SUBREG_P (out_rtx) ? SUBREG_REG (out_rtx) : out_rtx;
1291 1763897 : if (find_reg_note (curr_insn, REG_UNUSED, reg) == NULL_RTX
1292 1763897 : && (!REG_P (reg) || !ira_former_scratch_p (REGNO (reg))))
1293 : {
1294 1672088 : start_sequence ();
1295 : /* If we had strict_low_part, use it also in reload to keep other
1296 : parts unchanged but do it only for regs as strict_low_part
1297 : has no sense for memory and probably there is no insn pattern
1298 : to match the reload insn in memory case. */
1299 1672088 : if (out >= 0 && curr_static_id->operand[out].strict_low && REG_P (reg))
1300 0 : out_rtx = gen_rtx_STRICT_LOW_PART (VOIDmode, out_rtx);
1301 1672088 : lra_emit_move (out_rtx, copy_rtx (new_out_reg));
1302 1672088 : emit_insn (*after);
1303 1672088 : *after = end_sequence ();
1304 : }
1305 1763897 : *curr_id->operand_loc[out] = new_out_reg;
1306 1763897 : lra_update_dup (curr_id, out);
1307 : }
1308 :
1309 : /* Return register class which is union of all reg classes in insn
1310 : constraint alternative string starting with P. */
1311 : static enum reg_class
1312 0 : reg_class_from_constraints (const char *p)
1313 : {
1314 0 : int c, len;
1315 0 : enum reg_class op_class = NO_REGS;
1316 :
1317 0 : do
1318 0 : switch ((c = *p, len = CONSTRAINT_LEN (c, p)), c)
1319 : {
1320 : case '#':
1321 : case ',':
1322 : return op_class;
1323 :
1324 0 : case 'g':
1325 0 : op_class = reg_class_subunion[op_class][GENERAL_REGS];
1326 0 : break;
1327 :
1328 0 : default:
1329 0 : enum constraint_num cn = lookup_constraint (p);
1330 0 : enum reg_class cl = reg_class_for_constraint (cn);
1331 0 : if (cl == NO_REGS)
1332 : {
1333 0 : if (insn_extra_address_constraint (cn))
1334 0 : op_class
1335 0 : = (reg_class_subunion
1336 0 : [op_class][base_reg_class (VOIDmode, ADDR_SPACE_GENERIC,
1337 0 : ADDRESS, SCRATCH)]);
1338 : break;
1339 : }
1340 :
1341 0 : op_class = reg_class_subunion[op_class][cl];
1342 0 : break;
1343 : }
1344 0 : while ((p += len), c);
1345 : return op_class;
1346 : }
1347 :
1348 : /* If OP is a register, return the class of the register as per
1349 : get_reg_class, otherwise return NO_REGS. */
1350 : static inline enum reg_class
1351 165469875 : get_op_class (rtx op)
1352 : {
1353 137462435 : return REG_P (op) ? get_reg_class (REGNO (op)) : NO_REGS;
1354 : }
1355 :
1356 : /* Return generated insn mem_pseudo:=val if TO_P or val:=mem_pseudo
1357 : otherwise. If modes of MEM_PSEUDO and VAL are different, use
1358 : SUBREG for VAL to make them equal. */
1359 : static rtx_insn *
1360 1337595 : emit_spill_move (bool to_p, rtx mem_pseudo, rtx val)
1361 : {
1362 1337595 : if (GET_MODE (mem_pseudo) != GET_MODE (val))
1363 : {
1364 : /* Usually size of mem_pseudo is greater than val size but in
1365 : rare cases it can be less as it can be defined by target
1366 : dependent macro HARD_REGNO_CALLER_SAVE_MODE. */
1367 3002 : if (! MEM_P (val))
1368 : {
1369 3002 : val = gen_lowpart_SUBREG (GET_MODE (mem_pseudo),
1370 : GET_CODE (val) == SUBREG
1371 : ? SUBREG_REG (val) : val);
1372 3002 : LRA_SUBREG_P (val) = 1;
1373 : }
1374 : else
1375 : {
1376 0 : mem_pseudo = gen_lowpart_SUBREG (GET_MODE (val), mem_pseudo);
1377 0 : LRA_SUBREG_P (mem_pseudo) = 1;
1378 : }
1379 : }
1380 1337595 : return to_p ? gen_move_insn (mem_pseudo, val)
1381 675319 : : gen_move_insn (val, mem_pseudo);
1382 : }
1383 :
1384 : /* Process a special case insn (register move), return true if we
1385 : don't need to process it anymore. INSN should be a single set
1386 : insn. Set up that RTL was changed through CHANGE_P and that hook
1387 : TARGET_SECONDARY_MEMORY_NEEDED says to use secondary memory through
1388 : SEC_MEM_P. */
1389 : static bool
1390 76697187 : check_and_process_move (bool *change_p, bool *sec_mem_p ATTRIBUTE_UNUSED)
1391 : {
1392 76697187 : int sregno, dregno;
1393 76697187 : rtx dest, src, dreg, sreg, new_reg, scratch_reg;
1394 76697187 : rtx_insn *before;
1395 76697187 : enum reg_class dclass, sclass, secondary_class;
1396 76697187 : secondary_reload_info sri;
1397 :
1398 76697187 : lra_assert (curr_insn_set != NULL_RTX);
1399 76697187 : dreg = dest = SET_DEST (curr_insn_set);
1400 76697187 : sreg = src = SET_SRC (curr_insn_set);
1401 76697187 : if (GET_CODE (dest) == SUBREG)
1402 1216867 : dreg = SUBREG_REG (dest);
1403 76697187 : if (GET_CODE (src) == SUBREG)
1404 1250639 : sreg = SUBREG_REG (src);
1405 76697187 : if (! (REG_P (dreg) || MEM_P (dreg)) || ! (REG_P (sreg) || MEM_P (sreg)))
1406 : return false;
1407 35808405 : sclass = dclass = NO_REGS;
1408 35808405 : if (REG_P (dreg))
1409 23075834 : dclass = get_reg_class (REGNO (dreg));
1410 23075834 : gcc_assert (dclass < LIM_REG_CLASSES && dclass >= NO_REGS);
1411 35808405 : if (dclass == ALL_REGS)
1412 : /* ALL_REGS is used for new pseudos created by transformations
1413 : like reload of SUBREG_REG (see function
1414 : simplify_operand_subreg). We don't know their class yet. We
1415 : should figure out the class from processing the insn
1416 : constraints not in this fast path function. Even if ALL_REGS
1417 : were a right class for the pseudo, secondary_... hooks usually
1418 : are not define for ALL_REGS. */
1419 : return false;
1420 35806169 : if (REG_P (sreg))
1421 20005521 : sclass = get_reg_class (REGNO (sreg));
1422 20005521 : gcc_assert (sclass < LIM_REG_CLASSES && sclass >= NO_REGS);
1423 35806169 : if (sclass == ALL_REGS)
1424 : /* See comments above. */
1425 : return false;
1426 35806169 : if (sclass == NO_REGS && dclass == NO_REGS)
1427 : return false;
1428 34327257 : if (targetm.secondary_memory_needed (GET_MODE (src), sclass, dclass)
1429 34327257 : && ((sclass != NO_REGS && dclass != NO_REGS)
1430 0 : || (GET_MODE (src)
1431 0 : != targetm.secondary_memory_needed_mode (GET_MODE (src)))))
1432 : {
1433 13235 : *sec_mem_p = true;
1434 13235 : return false;
1435 : }
1436 34314022 : if (! REG_P (dreg) || ! REG_P (sreg))
1437 : return false;
1438 7787228 : sri.prev_sri = NULL;
1439 7787228 : sri.icode = CODE_FOR_nothing;
1440 7787228 : sri.extra_cost = 0;
1441 7787228 : secondary_class = NO_REGS;
1442 : /* Set up hard register for a reload pseudo for hook
1443 : secondary_reload because some targets just ignore unassigned
1444 : pseudos in the hook. */
1445 7787228 : if (dclass != NO_REGS && lra_get_regno_hard_regno (REGNO (dreg)) < 0)
1446 : {
1447 2898053 : dregno = REGNO (dreg);
1448 2898053 : reg_renumber[dregno] = ira_class_hard_regs[dclass][0];
1449 : }
1450 : else
1451 : dregno = -1;
1452 7787228 : if (sclass != NO_REGS && lra_get_regno_hard_regno (REGNO (sreg)) < 0)
1453 : {
1454 1293107 : sregno = REGNO (sreg);
1455 1293107 : reg_renumber[sregno] = ira_class_hard_regs[sclass][0];
1456 : }
1457 : else
1458 : sregno = -1;
1459 7787228 : if (sclass != NO_REGS)
1460 3940039 : secondary_class
1461 7880078 : = (enum reg_class) targetm.secondary_reload (false, dest,
1462 : (reg_class_t) sclass,
1463 3940039 : GET_MODE (src), &sri);
1464 3940039 : if (sclass == NO_REGS
1465 3940039 : || ((secondary_class != NO_REGS || sri.icode != CODE_FOR_nothing)
1466 1342 : && dclass != NO_REGS))
1467 : {
1468 3847189 : enum reg_class old_sclass = secondary_class;
1469 3847189 : secondary_reload_info old_sri = sri;
1470 :
1471 3847189 : sri.prev_sri = NULL;
1472 3847189 : sri.icode = CODE_FOR_nothing;
1473 3847189 : sri.extra_cost = 0;
1474 3847189 : secondary_class
1475 7694378 : = (enum reg_class) targetm.secondary_reload (true, src,
1476 : (reg_class_t) dclass,
1477 3847189 : GET_MODE (src), &sri);
1478 : /* Check the target hook consistency. */
1479 3847189 : lra_assert
1480 : ((secondary_class == NO_REGS && sri.icode == CODE_FOR_nothing)
1481 : || (old_sclass == NO_REGS && old_sri.icode == CODE_FOR_nothing)
1482 : || (secondary_class == old_sclass && sri.icode == old_sri.icode));
1483 : }
1484 7787228 : if (sregno >= 0)
1485 1293107 : reg_renumber [sregno] = -1;
1486 7787228 : if (dregno >= 0)
1487 2898053 : reg_renumber [dregno] = -1;
1488 7787228 : if (secondary_class == NO_REGS && sri.icode == CODE_FOR_nothing)
1489 : return false;
1490 1343 : *change_p = true;
1491 1343 : new_reg = NULL_RTX;
1492 0 : if (secondary_class != NO_REGS)
1493 1343 : new_reg = lra_create_new_reg_with_unique_value (GET_MODE (src), NULL_RTX,
1494 : secondary_class, NULL,
1495 : "secondary");
1496 1343 : start_sequence ();
1497 1343 : if (sri.icode == CODE_FOR_nothing)
1498 1343 : lra_emit_move (new_reg, src);
1499 : else
1500 : {
1501 0 : enum reg_class scratch_class;
1502 :
1503 0 : scratch_class = (reg_class_from_constraints
1504 0 : (insn_data[sri.icode].operand[2].constraint));
1505 0 : scratch_reg = (lra_create_new_reg_with_unique_value
1506 0 : (insn_data[sri.icode].operand[2].mode, NULL_RTX,
1507 : scratch_class, NULL, "scratch"));
1508 0 : emit_insn (GEN_FCN (sri.icode) (new_reg != NULL_RTX ? new_reg : dest,
1509 : src, scratch_reg));
1510 : }
1511 1343 : before = end_sequence ();
1512 1343 : lra_process_new_insns (curr_insn, before, NULL, "Inserting the move");
1513 1343 : if (new_reg != NULL_RTX)
1514 1343 : SET_SRC (curr_insn_set) = new_reg;
1515 : else
1516 : {
1517 0 : if (lra_dump_file != NULL)
1518 : {
1519 0 : fprintf (lra_dump_file, "Deleting move %u\n", INSN_UID (curr_insn));
1520 0 : dump_insn_slim (lra_dump_file, curr_insn);
1521 : }
1522 0 : lra_set_insn_deleted (curr_insn);
1523 0 : return true;
1524 : }
1525 1343 : return false;
1526 : }
1527 :
1528 : /* The following data describe the result of process_alt_operands.
1529 : The data are used in curr_insn_transform to generate reloads. */
1530 :
1531 : /* The chosen reg classes which should be used for the corresponding
1532 : operands. */
1533 : static enum reg_class goal_alt[MAX_RECOG_OPERANDS];
1534 : /* Hard registers which cannot be a start hard register for the corresponding
1535 : operands. */
1536 : static HARD_REG_SET goal_alt_exclude_start_hard_regs[MAX_RECOG_OPERANDS];
1537 : /* True if the operand should be the same as another operand and that
1538 : other operand does not need a reload. */
1539 : static bool goal_alt_match_win[MAX_RECOG_OPERANDS];
1540 : /* True if the operand does not need a reload. */
1541 : static bool goal_alt_win[MAX_RECOG_OPERANDS];
1542 : /* True if the operand can be offsetable memory. */
1543 : static bool goal_alt_offmemok[MAX_RECOG_OPERANDS];
1544 : /* The number of an operand to which given operand can be matched to. */
1545 : static int goal_alt_matches[MAX_RECOG_OPERANDS];
1546 : /* The number of elements in the following array. */
1547 : static int goal_alt_dont_inherit_ops_num;
1548 : /* Numbers of operands whose reload pseudos should not be inherited. */
1549 : static int goal_alt_dont_inherit_ops[MAX_RECOG_OPERANDS];
1550 : /* True if we should try only this alternative for the next constraint sub-pass
1551 : to speed up the sub-pass. */
1552 : static bool goal_reuse_alt_p;
1553 : /* True if the insn commutative operands should be swapped. */
1554 : static bool goal_alt_swapped;
1555 : /* The chosen insn alternative. */
1556 : static int goal_alt_number;
1557 : /* True if output reload of the stack pointer should be generated. */
1558 : static bool goal_alt_out_sp_reload_p;
1559 :
1560 : /* True if the corresponding operand is the result of an equivalence
1561 : substitution. */
1562 : static bool equiv_substition_p[MAX_RECOG_OPERANDS];
1563 :
1564 : /* The following five variables are used to choose the best insn
1565 : alternative. They reflect final characteristics of the best
1566 : alternative. */
1567 :
1568 : /* Number of necessary reloads and overall cost reflecting the
1569 : previous value and other unpleasantness of the best alternative. */
1570 : static int best_losers, best_overall;
1571 : /* Overall number hard registers used for reloads. For example, on
1572 : some targets we need 2 general registers to reload DFmode and only
1573 : one floating point register. */
1574 : static int best_reload_nregs;
1575 : /* Overall number reflecting distances of previous reloading the same
1576 : value. The distances are counted from the current BB start. It is
1577 : used to improve inheritance chances. */
1578 : static int best_reload_sum;
1579 :
1580 : /* True if the current insn should have no correspondingly input or
1581 : output reloads. */
1582 : static bool no_input_reloads_p, no_output_reloads_p;
1583 :
1584 : /* True if we swapped the commutative operands in the current
1585 : insn. */
1586 : static int curr_swapped;
1587 :
1588 : /* if CHECK_ONLY_P is false, arrange for address element *LOC to be a
1589 : register of class CL. Add any input reloads to list BEFORE. AFTER
1590 : is nonnull if *LOC is an automodified value; handle that case by
1591 : adding the required output reloads to list AFTER. Return true if
1592 : the RTL was changed.
1593 :
1594 : if CHECK_ONLY_P is true, check that the *LOC is a correct address
1595 : register. Return false if the address register is correct. */
1596 : static bool
1597 35520396 : process_addr_reg (rtx *loc, bool check_only_p, rtx_insn **before, rtx_insn **after,
1598 : enum reg_class cl)
1599 : {
1600 35520396 : int regno;
1601 35520396 : enum reg_class rclass, new_class;
1602 35520396 : rtx reg;
1603 35520396 : rtx new_reg;
1604 35520396 : machine_mode mode;
1605 35520396 : bool subreg_p, before_p = false;
1606 :
1607 35520396 : subreg_p = GET_CODE (*loc) == SUBREG;
1608 35520396 : if (subreg_p)
1609 : {
1610 15004 : reg = SUBREG_REG (*loc);
1611 15004 : mode = GET_MODE (reg);
1612 :
1613 : /* For mode with size bigger than ptr_mode, there unlikely to be "mov"
1614 : between two registers with different classes, but there normally will
1615 : be "mov" which transfers element of vector register into the general
1616 : register, and this normally will be a subreg which should be reloaded
1617 : as a whole. This is particularly likely to be triggered when
1618 : -fno-split-wide-types specified. */
1619 15004 : if (!REG_P (reg)
1620 15004 : || in_class_p (reg, cl, &new_class)
1621 17402 : || known_le (GET_MODE_SIZE (mode), GET_MODE_SIZE (ptr_mode)))
1622 15004 : loc = &SUBREG_REG (*loc);
1623 : }
1624 :
1625 35520396 : reg = *loc;
1626 35520396 : mode = GET_MODE (reg);
1627 35520396 : if (! REG_P (reg))
1628 : {
1629 0 : if (check_only_p)
1630 : return true;
1631 : /* Always reload memory in an address even if the target supports
1632 : such addresses. */
1633 0 : new_reg = lra_create_new_reg_with_unique_value (mode, reg, cl, NULL,
1634 : "address");
1635 0 : before_p = true;
1636 : }
1637 : else
1638 : {
1639 35520396 : regno = REGNO (reg);
1640 35520396 : rclass = get_reg_class (regno);
1641 35520396 : if (! check_only_p
1642 35520396 : && (*loc = get_equiv_with_elimination (reg, curr_insn)) != reg)
1643 : {
1644 113653 : if (lra_dump_file != NULL)
1645 : {
1646 0 : fprintf (lra_dump_file,
1647 : "Changing pseudo %d in address of insn %u on equiv ",
1648 0 : REGNO (reg), INSN_UID (curr_insn));
1649 0 : dump_value_slim (lra_dump_file, *loc, 1);
1650 0 : fprintf (lra_dump_file, "\n");
1651 : }
1652 113653 : rtx new_equiv = copy_rtx (*loc);
1653 113653 : if (lra_pointer_equiv_set_in (*loc))
1654 108560 : lra_pointer_equiv_set_add (new_equiv);
1655 113653 : *loc = new_equiv;
1656 : }
1657 35520396 : if (*loc != reg || ! in_class_p (reg, cl, &new_class))
1658 : {
1659 478009 : if (check_only_p)
1660 : return true;
1661 478009 : reg = *loc;
1662 478009 : if (get_reload_reg (after == NULL ? OP_IN : OP_INOUT,
1663 : mode, reg, cl, NULL,
1664 : subreg_p, false, "address", &new_reg))
1665 : before_p = true;
1666 : }
1667 35042387 : else if (new_class != NO_REGS && rclass != new_class)
1668 : {
1669 466506 : if (check_only_p)
1670 : return true;
1671 466506 : lra_change_class (regno, new_class, " Change to", true);
1672 466506 : return false;
1673 : }
1674 : else
1675 : return false;
1676 : }
1677 0 : if (before_p)
1678 : {
1679 470216 : push_to_sequence (*before);
1680 470216 : lra_emit_move (new_reg, reg);
1681 470216 : *before = end_sequence ();
1682 : }
1683 478009 : *loc = new_reg;
1684 478009 : if (after != NULL)
1685 : {
1686 0 : start_sequence ();
1687 0 : lra_emit_move (before_p ? copy_rtx (reg) : reg, new_reg);
1688 0 : emit_insn (*after);
1689 0 : *after = end_sequence ();
1690 : }
1691 : return true;
1692 : }
1693 :
1694 : /* Insert move insn in simplify_operand_subreg. BEFORE returns
1695 : the insn to be inserted before curr insn. AFTER returns the
1696 : the insn to be inserted after curr insn. ORIGREG and NEWREG
1697 : are the original reg and new reg for reload. */
1698 : static void
1699 466 : insert_move_for_subreg (rtx_insn **before, rtx_insn **after, rtx origreg,
1700 : rtx newreg)
1701 : {
1702 466 : if (before)
1703 : {
1704 466 : push_to_sequence (*before);
1705 466 : lra_emit_move (newreg, origreg);
1706 466 : *before = end_sequence ();
1707 : }
1708 466 : if (after)
1709 : {
1710 0 : start_sequence ();
1711 0 : lra_emit_move (origreg, newreg);
1712 0 : emit_insn (*after);
1713 0 : *after = end_sequence ();
1714 : }
1715 466 : }
1716 :
1717 : static bool valid_address_p (machine_mode mode, rtx addr, addr_space_t as);
1718 : static bool process_address (int, bool, rtx_insn **, rtx_insn **);
1719 :
1720 : /* Make reloads for subreg in operand NOP with internal subreg mode
1721 : REG_MODE, add new reloads for further processing. Return true if
1722 : any change was done. */
1723 : static bool
1724 178275767 : simplify_operand_subreg (int nop, machine_mode reg_mode)
1725 : {
1726 178275767 : int hard_regno, inner_hard_regno;
1727 178275767 : rtx_insn *before, *after;
1728 178275767 : machine_mode mode, innermode;
1729 178275767 : rtx reg, new_reg;
1730 178275767 : rtx operand = *curr_id->operand_loc[nop];
1731 178275767 : enum reg_class regclass;
1732 178275767 : enum op_type type;
1733 :
1734 178275767 : before = after = NULL;
1735 :
1736 178275767 : if (GET_CODE (operand) != SUBREG)
1737 : return false;
1738 :
1739 3787808 : mode = GET_MODE (operand);
1740 3787808 : reg = SUBREG_REG (operand);
1741 3787808 : innermode = GET_MODE (reg);
1742 3787808 : type = curr_static_id->operand[nop].type;
1743 3787808 : if (MEM_P (reg))
1744 : {
1745 11526 : const bool addr_was_valid
1746 11526 : = valid_address_p (innermode, XEXP (reg, 0), MEM_ADDR_SPACE (reg));
1747 11526 : alter_subreg (curr_id->operand_loc[nop], false);
1748 11526 : rtx subst = *curr_id->operand_loc[nop];
1749 11526 : lra_assert (MEM_P (subst));
1750 11526 : const bool addr_is_valid = valid_address_p (GET_MODE (subst),
1751 : XEXP (subst, 0),
1752 11526 : MEM_ADDR_SPACE (subst));
1753 11526 : if (!addr_was_valid
1754 11526 : || addr_is_valid
1755 11526 : || ((get_constraint_type (lookup_constraint
1756 0 : (curr_static_id->operand[nop].constraint))
1757 : != CT_SPECIAL_MEMORY)
1758 : /* We still can reload address and if the address is
1759 : valid, we can remove subreg without reloading its
1760 : inner memory. */
1761 0 : && valid_address_p (GET_MODE (subst),
1762 0 : regno_reg_rtx
1763 : [ira_class_hard_regs
1764 0 : [base_reg_class (GET_MODE (subst),
1765 0 : MEM_ADDR_SPACE (subst),
1766 0 : ADDRESS, SCRATCH)][0]],
1767 0 : MEM_ADDR_SPACE (subst))))
1768 : {
1769 : /* If we change the address for a paradoxical subreg of memory, the
1770 : new address might violate the necessary alignment or the access
1771 : might be slow; take this into consideration. We need not worry
1772 : about accesses beyond allocated memory for paradoxical memory
1773 : subregs as we don't substitute such equiv memory (see processing
1774 : equivalences in function lra_constraints) and because for spilled
1775 : pseudos we allocate stack memory enough for the biggest
1776 : corresponding paradoxical subreg.
1777 :
1778 : However, do not blindly simplify a (subreg (mem ...)) for
1779 : WORD_REGISTER_OPERATIONS targets as this may lead to loading junk
1780 : data into a register when the inner is narrower than outer or
1781 : missing important data from memory when the inner is wider than
1782 : outer. This rule only applies to modes that are no wider than
1783 : a word.
1784 :
1785 : If valid memory becomes invalid after subreg elimination
1786 : and address might be different we still have to reload
1787 : memory.
1788 : */
1789 11526 : if ((! addr_was_valid
1790 : || addr_is_valid
1791 0 : || known_eq (GET_MODE_SIZE (mode), GET_MODE_SIZE (innermode)))
1792 11526 : && !(maybe_ne (GET_MODE_PRECISION (mode),
1793 11526 : GET_MODE_PRECISION (innermode))
1794 13434 : && known_le (GET_MODE_SIZE (mode), UNITS_PER_WORD)
1795 20031 : && known_le (GET_MODE_SIZE (innermode), UNITS_PER_WORD)
1796 : && WORD_REGISTER_OPERATIONS)
1797 24196 : && (!(MEM_ALIGN (subst) < GET_MODE_ALIGNMENT (mode)
1798 1144 : && targetm.slow_unaligned_access (mode, MEM_ALIGN (subst)))
1799 0 : || (MEM_ALIGN (reg) < GET_MODE_ALIGNMENT (innermode)
1800 0 : && targetm.slow_unaligned_access (innermode,
1801 0 : MEM_ALIGN (reg)))))
1802 11526 : return true;
1803 :
1804 0 : *curr_id->operand_loc[nop] = operand;
1805 :
1806 : /* But if the address was not valid, we cannot reload the MEM without
1807 : reloading the address first. */
1808 0 : if (!addr_was_valid)
1809 0 : process_address (nop, false, &before, &after);
1810 :
1811 : /* INNERMODE is fast, MODE slow. Reload the mem in INNERMODE. */
1812 0 : enum reg_class rclass
1813 0 : = (enum reg_class) targetm.preferred_reload_class (reg, ALL_REGS);
1814 0 : if (get_reload_reg (curr_static_id->operand[nop].type, innermode,
1815 : reg, rclass, NULL,
1816 : true, false, "slow/invalid mem", &new_reg))
1817 : {
1818 0 : bool insert_before, insert_after;
1819 0 : bitmap_set_bit (&lra_subreg_reload_pseudos, REGNO (new_reg));
1820 :
1821 0 : insert_before = (type != OP_OUT
1822 0 : || partial_subreg_p (mode, innermode));
1823 0 : insert_after = type != OP_IN;
1824 0 : insert_move_for_subreg (insert_before ? &before : NULL,
1825 : insert_after ? &after : NULL,
1826 : reg, new_reg);
1827 : }
1828 0 : SUBREG_REG (operand) = new_reg;
1829 :
1830 : /* Convert to MODE. */
1831 0 : reg = operand;
1832 0 : rclass
1833 0 : = (enum reg_class) targetm.preferred_reload_class (reg, ALL_REGS);
1834 0 : if (get_reload_reg (curr_static_id->operand[nop].type, mode, reg,
1835 : rclass, NULL,
1836 : true, false, "slow/invalid mem", &new_reg))
1837 : {
1838 0 : bool insert_before, insert_after;
1839 0 : bitmap_set_bit (&lra_subreg_reload_pseudos, REGNO (new_reg));
1840 :
1841 0 : insert_before = type != OP_OUT;
1842 0 : insert_after = type != OP_IN;
1843 0 : insert_move_for_subreg (insert_before ? &before : NULL,
1844 : insert_after ? &after : NULL,
1845 : reg, new_reg);
1846 : }
1847 0 : *curr_id->operand_loc[nop] = new_reg;
1848 0 : lra_process_new_insns (curr_insn, before, after,
1849 : "Inserting slow/invalid mem reload");
1850 0 : return true;
1851 : }
1852 :
1853 : /* If the address was valid and became invalid, prefer to reload
1854 : the memory. Typical case is when the index scale should
1855 : correspond the memory. */
1856 0 : *curr_id->operand_loc[nop] = operand;
1857 : /* Do not return false here as the MEM_P (reg) will be processed
1858 : later in this function. */
1859 : }
1860 3776282 : else if (REG_P (reg) && REGNO (reg) < FIRST_PSEUDO_REGISTER)
1861 : {
1862 : /* A narrowing subreg of a hard register that is not representable as a
1863 : hard register (its offset does not fall on a register boundary) cannot
1864 : be turned into one, and would otherwise be resolved to the wrong part
1865 : of the register. Reload it through memory so that the correct bytes
1866 : are accessed, as is done for pseudos below. Leave the frame, arg and
1867 : stack pointers alone: simplify_subreg_regno can reject them simply
1868 : because reload is not finished yet. */
1869 56 : if (partial_subreg_p (mode, innermode)
1870 56 : && REGNO (reg) != FRAME_POINTER_REGNUM
1871 : && REGNO (reg) != ARG_POINTER_REGNUM
1872 : && REGNO (reg) != STACK_POINTER_REGNUM
1873 61 : && simplify_subreg_regno (REGNO (reg), innermode,
1874 5 : SUBREG_BYTE (operand), mode) < 0)
1875 : {
1876 0 : if (get_reload_reg (type, innermode, reg, NO_REGS, NULL,
1877 : true, false, "non-representable subreg", &new_reg))
1878 : {
1879 0 : bitmap_set_bit (&lra_subreg_reload_pseudos, REGNO (new_reg));
1880 0 : bool insert_before = (type != OP_OUT
1881 0 : || read_modify_subreg_p (operand));
1882 0 : bool insert_after = (type != OP_IN);
1883 0 : insert_move_for_subreg (insert_before ? &before : NULL,
1884 : insert_after ? &after : NULL,
1885 : reg, new_reg);
1886 : }
1887 0 : SUBREG_REG (operand) = new_reg;
1888 0 : lra_process_new_insns (curr_insn, before, after,
1889 : "Inserting non-representable subreg reload");
1890 0 : return true;
1891 : }
1892 56 : alter_subreg (curr_id->operand_loc[nop], false);
1893 56 : return true;
1894 : }
1895 3776226 : else if (CONSTANT_P (reg))
1896 : {
1897 : /* Try to simplify subreg of constant. It is usually result of
1898 : equivalence substitution. */
1899 45508 : if (innermode == VOIDmode
1900 45508 : && (innermode = original_subreg_reg_mode[nop]) == VOIDmode)
1901 0 : innermode = curr_static_id->operand[nop].mode;
1902 45508 : if ((new_reg = simplify_subreg (mode, reg, innermode,
1903 45508 : SUBREG_BYTE (operand))) != NULL_RTX)
1904 : {
1905 45084 : *curr_id->operand_loc[nop] = new_reg;
1906 45084 : return true;
1907 : }
1908 : }
1909 : /* Put constant into memory when we have mixed modes. It generates
1910 : a better code in most cases as it does not need a secondary
1911 : reload memory. It also prevents LRA looping when LRA is using
1912 : secondary reload memory again and again. */
1913 848 : if (CONSTANT_P (reg) && CONST_POOL_OK_P (reg_mode, reg)
1914 3731566 : && SCALAR_INT_MODE_P (reg_mode) != SCALAR_INT_MODE_P (mode))
1915 : {
1916 8 : SUBREG_REG (operand) = force_const_mem (reg_mode, reg);
1917 8 : alter_subreg (curr_id->operand_loc[nop], false);
1918 8 : return true;
1919 : }
1920 3731134 : auto fp_subreg_can_be_simplified_after_reload_p = [] (machine_mode innermode,
1921 : poly_uint64 offset,
1922 : machine_mode mode) {
1923 0 : reload_completed = 1;
1924 0 : bool res = simplify_subreg_regno (FRAME_POINTER_REGNUM,
1925 : innermode,
1926 0 : offset, mode) >= 0;
1927 0 : reload_completed = 0;
1928 0 : return res;
1929 : };
1930 : /* Force a reload of the SUBREG_REG if this is a constant or PLUS or
1931 : if there may be a problem accessing OPERAND in the outer
1932 : mode. */
1933 3731134 : if ((REG_P (reg)
1934 3730668 : && REGNO (reg) >= FIRST_PSEUDO_REGISTER
1935 3730668 : && (hard_regno = lra_get_regno_hard_regno (REGNO (reg))) >= 0
1936 : /* Don't reload paradoxical subregs because we could be looping
1937 : having repeatedly final regno out of hard regs range. */
1938 3160894 : && (hard_regno_nregs (hard_regno, innermode)
1939 3160894 : >= hard_regno_nregs (hard_regno, mode))
1940 3155546 : && simplify_subreg_regno (hard_regno, innermode,
1941 3155546 : SUBREG_BYTE (operand), mode) < 0
1942 : /* Exclude reloading of frame pointer in subreg if frame pointer can not
1943 : be simplified here only because the reload is not finished yet. */
1944 845 : && (hard_regno != FRAME_POINTER_REGNUM
1945 0 : || !fp_subreg_can_be_simplified_after_reload_p (innermode,
1946 0 : SUBREG_BYTE (operand),
1947 : mode))
1948 : /* Don't reload subreg for matching reload. It is actually
1949 : valid subreg in LRA. */
1950 845 : && ! LRA_SUBREG_P (operand))
1951 7461802 : || CONSTANT_P (reg) || GET_CODE (reg) == PLUS || MEM_P (reg))
1952 : {
1953 466 : enum reg_class rclass;
1954 :
1955 466 : if (REG_P (reg))
1956 : /* There is a big probability that we will get the same class
1957 : for the new pseudo and we will get the same insn which
1958 : means infinite looping. So spill the new pseudo. */
1959 : rclass = NO_REGS;
1960 : else
1961 : /* The class will be defined later in curr_insn_transform. */
1962 466 : rclass
1963 466 : = (enum reg_class) targetm.preferred_reload_class (reg, ALL_REGS);
1964 :
1965 466 : if (get_reload_reg (curr_static_id->operand[nop].type, reg_mode, reg,
1966 : rclass, NULL,
1967 : true, false, "subreg reg", &new_reg))
1968 : {
1969 466 : bool insert_before, insert_after;
1970 466 : bitmap_set_bit (&lra_subreg_reload_pseudos, REGNO (new_reg));
1971 :
1972 932 : insert_before = (type != OP_OUT
1973 466 : || read_modify_subreg_p (operand));
1974 466 : insert_after = (type != OP_IN);
1975 932 : insert_move_for_subreg (insert_before ? &before : NULL,
1976 : insert_after ? &after : NULL,
1977 : reg, new_reg);
1978 : }
1979 466 : SUBREG_REG (operand) = new_reg;
1980 466 : lra_process_new_insns (curr_insn, before, after,
1981 : "Inserting subreg reload");
1982 466 : return true;
1983 : }
1984 : /* Force a reload for a paradoxical subreg. For paradoxical subreg,
1985 : IRA allocates hardreg to the inner pseudo reg according to its mode
1986 : instead of the outermode, so the size of the hardreg may not be enough
1987 : to contain the outermode operand, in that case we may need to insert
1988 : reload for the reg. For the following two types of paradoxical subreg,
1989 : we need to insert reload:
1990 : 1. If the op_type is OP_IN, and the hardreg could not be paired with
1991 : other hardreg to contain the outermode operand
1992 : (checked by in_hard_reg_set_p), we need to insert the reload.
1993 : 2. If the op_type is OP_OUT or OP_INOUT.
1994 :
1995 : Here is a paradoxical subreg example showing how the reload is generated:
1996 :
1997 : (insn 5 4 7 2 (set (reg:TI 106 [ __comp ])
1998 : (subreg:TI (reg:DI 107 [ __comp ]) 0)) {*movti_internal_rex64}
1999 :
2000 : In IRA, reg107 is allocated to a DImode hardreg. We use x86-64 as example
2001 : here, if reg107 is assigned to hardreg R15, because R15 is the last
2002 : hardreg, compiler cannot find another hardreg to pair with R15 to
2003 : contain TImode data. So we insert a TImode reload reg180 for it.
2004 : After reload is inserted:
2005 :
2006 : (insn 283 0 0 (set (subreg:DI (reg:TI 180 [orig:107 __comp ] [107]) 0)
2007 : (reg:DI 107 [ __comp ])) -1
2008 : (insn 5 4 7 2 (set (reg:TI 106 [ __comp ])
2009 : (subreg:TI (reg:TI 180 [orig:107 __comp ] [107]) 0)) {*movti_internal_rex64}
2010 :
2011 : Two reload hard registers will be allocated to reg180 to save TImode data
2012 : in LRA_assign.
2013 :
2014 : For LRA pseudos this should normally be handled by the biggest_mode
2015 : mechanism. However, it's possible for new uses of an LRA pseudo
2016 : to be introduced after we've allocated it, such as when undoing
2017 : inheritance, and the allocated register might not then be appropriate
2018 : for the new uses. */
2019 3730668 : else if (REG_P (reg)
2020 3730668 : && REGNO (reg) >= FIRST_PSEUDO_REGISTER
2021 3730668 : && paradoxical_subreg_p (operand)
2022 1045345 : && (inner_hard_regno = lra_get_regno_hard_regno (REGNO (reg))) >= 0
2023 954360 : && hard_regno_nregs (inner_hard_regno, mode) > 1
2024 3730668 : && ((hard_regno
2025 3736016 : = simplify_subreg_regno (inner_hard_regno, innermode,
2026 5348 : SUBREG_BYTE (operand), mode)) < 0
2027 5348 : || ((hard_regno_nregs (inner_hard_regno, innermode)
2028 5348 : < hard_regno_nregs (hard_regno, mode))
2029 10696 : && (regclass = lra_get_allocno_class (REGNO (reg)))
2030 5348 : && (type != OP_IN
2031 5348 : || !in_hard_reg_set_p (reg_class_contents[regclass],
2032 : mode, hard_regno)
2033 5348 : || overlaps_hard_reg_set_p (lra_no_alloc_regs,
2034 : mode, hard_regno)))))
2035 : {
2036 : /* The class will be defined later in curr_insn_transform. */
2037 0 : enum reg_class rclass
2038 0 : = (enum reg_class) targetm.preferred_reload_class (reg, ALL_REGS);
2039 :
2040 0 : if (get_reload_reg (curr_static_id->operand[nop].type, mode, reg,
2041 : rclass, NULL,
2042 : true, false, "paradoxical subreg", &new_reg))
2043 : {
2044 0 : rtx subreg;
2045 0 : bool insert_before, insert_after;
2046 :
2047 0 : PUT_MODE (new_reg, mode);
2048 0 : subreg = gen_lowpart_SUBREG (innermode, new_reg);
2049 0 : bitmap_set_bit (&lra_subreg_reload_pseudos, REGNO (new_reg));
2050 :
2051 0 : insert_before = (type != OP_OUT);
2052 0 : insert_after = (type != OP_IN);
2053 0 : insert_move_for_subreg (insert_before ? &before : NULL,
2054 : insert_after ? &after : NULL,
2055 : reg, subreg);
2056 : }
2057 0 : SUBREG_REG (operand) = new_reg;
2058 0 : lra_process_new_insns (curr_insn, before, after,
2059 : "Inserting paradoxical subreg reload");
2060 0 : return true;
2061 : }
2062 : return false;
2063 : }
2064 :
2065 : /* Return TRUE if X refers for a hard register from SET. */
2066 : static bool
2067 404878 : uses_hard_regs_p (rtx x, HARD_REG_SET set)
2068 : {
2069 404878 : int i, j, x_hard_regno;
2070 404878 : machine_mode mode;
2071 404878 : const char *fmt;
2072 404878 : enum rtx_code code;
2073 :
2074 404878 : if (x == NULL_RTX)
2075 : return false;
2076 404878 : code = GET_CODE (x);
2077 404878 : mode = GET_MODE (x);
2078 :
2079 404878 : if (code == SUBREG)
2080 : {
2081 : /* For all SUBREGs we want to check whether the full multi-register
2082 : overlaps the set. For normal SUBREGs this means 'get_hard_regno' of
2083 : the inner register, for paradoxical SUBREGs this means the
2084 : 'get_hard_regno' of the full SUBREG and for complete SUBREGs either is
2085 : fine. Use the wider mode for all cases. */
2086 9814 : rtx subreg = SUBREG_REG (x);
2087 9814 : mode = wider_subreg_mode (x);
2088 9814 : if (mode == GET_MODE (subreg))
2089 : {
2090 8778 : x = subreg;
2091 8778 : code = GET_CODE (x);
2092 : }
2093 : }
2094 :
2095 404878 : if (REG_P (x) || SUBREG_P (x))
2096 : {
2097 261607 : x_hard_regno = get_hard_regno (x);
2098 261607 : return (x_hard_regno >= 0
2099 261607 : && overlaps_hard_reg_set_p (set, mode, x_hard_regno));
2100 : }
2101 143271 : fmt = GET_RTX_FORMAT (code);
2102 372547 : for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
2103 : {
2104 231289 : if (fmt[i] == 'e')
2105 : {
2106 113170 : if (uses_hard_regs_p (XEXP (x, i), set))
2107 : return true;
2108 : }
2109 118119 : else if (fmt[i] == 'E')
2110 : {
2111 4398 : for (j = XVECLEN (x, i) - 1; j >= 0; j--)
2112 3980 : if (uses_hard_regs_p (XVECEXP (x, i, j), set))
2113 : return true;
2114 : }
2115 : }
2116 : return false;
2117 : }
2118 :
2119 : /* Return true if OP is a spilled pseudo. */
2120 : static inline bool
2121 81985201 : spilled_pseudo_p (rtx op)
2122 : {
2123 81985201 : return (REG_P (op)
2124 81985201 : && REGNO (op) >= FIRST_PSEUDO_REGISTER && in_mem_p (REGNO (op)));
2125 : }
2126 :
2127 : /* Return true if X is a general constant. */
2128 : static inline bool
2129 7902745 : general_constant_p (rtx x)
2130 : {
2131 7902745 : return CONSTANT_P (x) && (! flag_pic || LEGITIMATE_PIC_OPERAND_P (x));
2132 : }
2133 :
2134 : static bool
2135 25126457 : reg_in_class_p (rtx reg, enum reg_class cl)
2136 : {
2137 25126457 : if (cl == NO_REGS)
2138 1135681 : return get_reg_class (REGNO (reg)) == NO_REGS;
2139 23990776 : return in_class_p (reg, cl, NULL);
2140 : }
2141 :
2142 : /* Return true if SET of RCLASS contains no hard regs which can be
2143 : used in MODE. */
2144 : static bool
2145 3886915 : prohibited_class_reg_set_mode_p (enum reg_class rclass,
2146 : HARD_REG_SET &set,
2147 : machine_mode mode)
2148 : {
2149 3886915 : HARD_REG_SET temp;
2150 :
2151 7773830 : lra_assert (hard_reg_set_subset_p (reg_class_contents[rclass], set));
2152 3886915 : temp = set & ~lra_no_alloc_regs;
2153 3886915 : return (hard_reg_set_subset_p
2154 3886915 : (temp, ira_prohibited_class_mode_regs[rclass][mode]));
2155 : }
2156 :
2157 :
2158 : /* Used to check validity info about small class input operands. It
2159 : should be incremented at start of processing an insn
2160 : alternative. */
2161 : static unsigned int curr_small_class_check = 0;
2162 :
2163 : /* Update number of used inputs of class OP_CLASS for operand NOP
2164 : of alternative NALT. Return true if we have more such class operands
2165 : than the number of available regs. */
2166 : static bool
2167 399539002 : update_and_check_small_class_inputs (int nop, int nalt,
2168 : enum reg_class op_class)
2169 : {
2170 399539002 : static unsigned int small_class_check[LIM_REG_CLASSES];
2171 399539002 : static int small_class_input_nums[LIM_REG_CLASSES];
2172 :
2173 396579364 : if (SMALL_REGISTER_CLASS_P (op_class)
2174 : /* We are interesting in classes became small because of fixing
2175 : some hard regs, e.g. by an user through GCC options. */
2176 3068219 : && hard_reg_set_intersect_p (reg_class_contents[op_class],
2177 3068219 : ira_no_alloc_regs)
2178 399539040 : && (curr_static_id->operand[nop].type != OP_OUT
2179 32 : || TEST_BIT (curr_static_id->operand[nop].early_clobber_alts, nalt)))
2180 : {
2181 6 : if (small_class_check[op_class] == curr_small_class_check)
2182 0 : small_class_input_nums[op_class]++;
2183 : else
2184 : {
2185 6 : small_class_check[op_class] = curr_small_class_check;
2186 6 : small_class_input_nums[op_class] = 1;
2187 : }
2188 6 : if (small_class_input_nums[op_class] > ira_class_hard_regs_num[op_class])
2189 : return true;
2190 : }
2191 : return false;
2192 : }
2193 :
2194 : /* Print operand constraints for alternative ALT_NUMBER of the current
2195 : insn. */
2196 : static void
2197 4590 : print_curr_insn_alt (int alt_number)
2198 : {
2199 15917 : for (int i = 0; i < curr_static_id->n_operands; i++)
2200 : {
2201 11327 : const char *p = (curr_static_id->operand_alternative
2202 11327 : [alt_number * curr_static_id->n_operands + i].constraint);
2203 11327 : if (*p == '\0')
2204 220 : continue;
2205 11107 : fprintf (lra_dump_file, " (%d) ", i);
2206 39435 : for (; *p != '\0' && *p != ',' && *p != '#'; p++)
2207 17221 : fputc (*p, lra_dump_file);
2208 : }
2209 4590 : }
2210 :
2211 : struct dependent_filter_cache_hasher
2212 : : free_ptr_hash <dependent_filter_entry>
2213 : {
2214 0 : static inline hashval_t hash (const dependent_filter_entry *e)
2215 : {
2216 0 : hashval_t h = (hashval_t) e->id;
2217 0 : h = iterative_hash_hashval_t ((hashval_t) e->mode, h);
2218 0 : h = iterative_hash_hashval_t ((hashval_t) e->partner_mode, h);
2219 0 : h = iterative_hash_hashval_t (e->partner_regno, h);
2220 0 : h = iterative_hash_hashval_t ((hashval_t) e->is_ref, h);
2221 0 : return h;
2222 : }
2223 0 : static inline bool equal (const dependent_filter_entry *a,
2224 : const dependent_filter_entry *b)
2225 : {
2226 0 : return (a->id == b->id && a->mode == b->mode
2227 0 : && a->partner_mode == b->partner_mode
2228 0 : && a->partner_regno == b->partner_regno
2229 0 : && a->is_ref == b->is_ref);
2230 : }
2231 : };
2232 :
2233 : static hash_table<dependent_filter_cache_hasher> *dependent_filter_htab;
2234 :
2235 : /* Allocate the dependent-filter cache. */
2236 :
2237 : void
2238 214556 : lra_init_dependent_filter_cache (void)
2239 : {
2240 214556 : gcc_assert (!dependent_filter_htab);
2241 214556 : dependent_filter_htab = new hash_table<dependent_filter_cache_hasher> (16);
2242 214556 : }
2243 :
2244 : /* Release the dependent-filter cache. */
2245 :
2246 : void
2247 282895 : lra_finish_dependent_filter_cache (void)
2248 : {
2249 282895 : delete dependent_filter_htab;
2250 282895 : dependent_filter_htab = nullptr;
2251 282895 : }
2252 :
2253 : /* Reset the dependent-filter cache. */
2254 :
2255 : void
2256 3009900 : lra_reset_dependent_filters (void)
2257 : {
2258 3009900 : if (dependent_filter_htab)
2259 3009900 : dependent_filter_htab->empty ();
2260 3009900 : }
2261 :
2262 : /* Return the set of hardregs allowed by dependent filter ID for an operand
2263 : of mode MODE when the referenced operand has PARTNER_REGNO in
2264 : PARTNER_MODE. That is when IS_REF is false. If it is true, the roles are
2265 : reversed and PARTNER_REGNO as well as PARTNER_MODE refer to the dependent
2266 : operand.
2267 :
2268 : We fill the set for all hardregs and add the resulting regset to
2269 : a hash table if it doesn't already exist in it. */
2270 :
2271 : const HARD_REG_SET *
2272 0 : lra_get_dependent_filter (int id, machine_mode mode,
2273 : unsigned int partner_regno,
2274 : machine_mode partner_mode, bool is_ref)
2275 : {
2276 0 : dependent_filter_entry key;
2277 0 : key.id = id;
2278 0 : key.mode = mode;
2279 0 : key.partner_mode = partner_mode;
2280 0 : key.partner_regno = partner_regno;
2281 0 : key.is_ref = is_ref;
2282 :
2283 0 : dependent_filter_entry **slot
2284 0 : = dependent_filter_htab->find_slot (&key, INSERT);
2285 0 : if (*slot)
2286 0 : return &(*slot)->allowed;
2287 :
2288 0 : auto *e = XCNEW (dependent_filter_entry);
2289 0 : e->id = id;
2290 0 : e->mode = mode;
2291 0 : e->partner_mode = partner_mode;
2292 0 : e->partner_regno = partner_regno;
2293 0 : e->is_ref = is_ref;
2294 :
2295 : /* ??? Should we restrict ourselves to a register class here? */
2296 0 : for (unsigned regno = 0; regno < FIRST_PSEUDO_REGISTER; ++regno)
2297 : {
2298 0 : bool ok;
2299 0 : if (is_ref)
2300 0 : ok = eval_dependent_filter (id, partner_regno, partner_mode,
2301 : regno, mode);
2302 : else
2303 0 : ok = eval_dependent_filter (id, regno, mode,
2304 : partner_regno, partner_mode);
2305 0 : if (ok)
2306 0 : SET_HARD_REG_BIT (e->allowed, regno);
2307 : }
2308 0 : *slot = e;
2309 0 : return &e->allowed;
2310 : }
2311 :
2312 : /* Add the dependent filter ID to REGNO's dependent filters with
2313 : referenced PARTNER_REGNO and PARTNER_MODE if IS_REF is false.
2314 : If IS_REF is true, the roles are reversed. We need both
2315 : directions in case the referenced op is assigned a hardreg first. */
2316 :
2317 : void
2318 0 : lra_add_dependent_filter (int regno, int id, machine_mode mode,
2319 : int partner_regno, machine_mode partner_mode,
2320 : bool is_ref)
2321 : {
2322 : /* Only meaningful for pseudo partners. */
2323 0 : if (partner_regno < FIRST_PSEUDO_REGISTER)
2324 0 : return;
2325 :
2326 0 : vec<dependent_filter> &filters = lra_reg_info[regno].dependent_filters;
2327 0 : unsigned int i;
2328 0 : dependent_filter *filter;
2329 :
2330 : /* If this filter already exists, do nothing. */
2331 0 : FOR_EACH_VEC_ELT (filters, i, filter)
2332 0 : if (filter->id == id
2333 0 : && filter->partner_regno == (unsigned int) partner_regno
2334 0 : && filter->mode == mode && filter->partner_mode == partner_mode
2335 0 : && filter->is_ref == is_ref)
2336 : return;
2337 :
2338 : /* Otherwise, create a new filter. */
2339 0 : dependent_filter new_filter;
2340 0 : new_filter.id = id;
2341 0 : new_filter.mode = mode;
2342 0 : new_filter.partner_mode = partner_mode;
2343 0 : new_filter.partner_regno = (unsigned int) partner_regno;
2344 0 : new_filter.is_ref = is_ref;
2345 0 : filters.safe_push (new_filter);
2346 : }
2347 :
2348 : /* Return the set of hardregs for the constraint CN in MODE,
2349 : allowed by its dependent filter.
2350 : If there is no dependent filter or the involved registers are no
2351 : hardregs, return NULL. */
2352 :
2353 : static const HARD_REG_SET *
2354 0 : get_dependent_filter (constraint_num cn, machine_mode mode)
2355 : {
2356 349517478 : int id = get_dependent_filter_id (cn);
2357 0 : if (id < 0)
2358 0 : return nullptr;
2359 :
2360 : gcc_assert (reg_class_for_constraint (cn) != NO_REGS);
2361 :
2362 : int ref_opno = get_dependent_filter_ref (id);
2363 : gcc_assert (ref_opno >= 0 && ref_opno < curr_static_id->n_operands);
2364 :
2365 : rtx ref_op = *curr_id->operand_loc[ref_opno];
2366 : if (SUBREG_P (ref_op))
2367 : ref_op = SUBREG_REG (ref_op);
2368 : if (!REG_P (ref_op))
2369 : return nullptr;
2370 : unsigned int ref_regno = REGNO (ref_op);
2371 : if (ref_regno >= FIRST_PSEUDO_REGISTER)
2372 : {
2373 : int ref_hard_regno = reg_renumber[ref_regno];
2374 : /* Even with a pseudo reference op, the filter can still reject
2375 : based on the partner. We call it with INVALID_REGNUM
2376 : to give it a chance to do so. Otherwise we'd introduce
2377 : an "all choices legal" filter that might later
2378 : "change its mind" once there is a fixed reference. */
2379 : if (ref_hard_regno < 0)
2380 : return lra_get_dependent_filter (id, mode, INVALID_REGNUM,
2381 : GET_MODE (ref_op), false);
2382 : ref_regno = (unsigned int) ref_hard_regno;
2383 : }
2384 :
2385 : return lra_get_dependent_filter (id, mode, ref_regno, GET_MODE (ref_op),
2386 : false);
2387 : }
2388 :
2389 : /* Go through all operands and their constraints, looking for a dependent
2390 : filter. If we find one, add it to the respective reg_info's
2391 : dependent-filter list. After assigning a hardreg to either the dependent
2392 : or the referenced op, this allows us to filter the other's regset. */
2393 :
2394 : static void
2395 80582234 : process_dependent_filters (void)
2396 : {
2397 80582234 : int n_operands = curr_static_id->n_operands;
2398 260281397 : for (int i = 0; i < n_operands; i++)
2399 : {
2400 179699163 : rtx op = *curr_id->operand_loc[i];
2401 179699163 : if (!REG_P (op) || HARD_REGISTER_P (op))
2402 98525642 : continue;
2403 81173521 : const char *constraint
2404 81173521 : = curr_static_id->operand_alternative
2405 81173521 : [goal_alt_number * n_operands + i].constraint;
2406 81173521 : for (const char *p = constraint;
2407 213322155 : *p && *p != ',' && *p != '#';
2408 132148634 : p += CONSTRAINT_LEN (*p, p))
2409 : {
2410 132148634 : enum constraint_num cn = lookup_constraint (p);
2411 132148634 : int id = get_dependent_filter_id (cn);
2412 132148634 : if (id < 0)
2413 132148634 : continue;
2414 : if (reg_class_for_constraint (cn) == NO_REGS)
2415 : continue;
2416 : int ref_opno = get_dependent_filter_ref (id);
2417 : if (ref_opno < 0 || ref_opno >= n_operands)
2418 : continue;
2419 : rtx ref_op = *curr_id->operand_loc[ref_opno];
2420 : if (!REG_P (ref_op) || HARD_REGISTER_P (ref_op))
2421 : continue;
2422 : machine_mode mode = curr_operand_mode[i];
2423 : lra_add_dependent_filter (REGNO (op), id, mode,
2424 : REGNO (ref_op), GET_MODE (ref_op),
2425 : false);
2426 : lra_add_dependent_filter (REGNO (ref_op), id, GET_MODE (ref_op),
2427 : REGNO (op), mode, true);
2428 : }
2429 : }
2430 80582234 : }
2431 :
2432 : /* Major function to choose the current insn alternative and what
2433 : operands should be reloaded and how. If ONLY_ALTERNATIVE is not
2434 : negative we should consider only this alternative. Return false if
2435 : we cannot choose the alternative or find how to reload the
2436 : operands. */
2437 : static bool
2438 91133200 : process_alt_operands (int only_alternative)
2439 : {
2440 91133200 : bool ok_p = false;
2441 91133200 : int nop, overall, nalt;
2442 91133200 : int n_alternatives = curr_static_id->n_alternatives;
2443 91133200 : int n_operands = curr_static_id->n_operands;
2444 : /* LOSERS counts the operands that don't fit this alternative and
2445 : would require loading. */
2446 91133200 : int losers;
2447 91133200 : int addr_losers;
2448 : /* REJECT is a count of how undesirable this alternative says it is
2449 : if any reloading is required. If the alternative matches exactly
2450 : then REJECT is ignored, but otherwise it gets this much counted
2451 : against it in addition to the reloading needed. */
2452 91133200 : int reject;
2453 : /* This is defined by '!' or '?' alternative constraint and added to
2454 : reject. But in some cases it can be ignored. */
2455 91133200 : int static_reject;
2456 91133200 : int op_reject;
2457 : /* The number of elements in the following array. */
2458 91133200 : int early_clobbered_regs_num;
2459 : /* Numbers of operands which are early clobber registers. */
2460 91133200 : int early_clobbered_nops[MAX_RECOG_OPERANDS];
2461 91133200 : enum reg_class curr_alt[MAX_RECOG_OPERANDS];
2462 91133200 : enum reg_class all_this_alternative;
2463 91133200 : int all_used_nregs, all_reload_nregs;
2464 91133200 : HARD_REG_SET curr_alt_set[MAX_RECOG_OPERANDS];
2465 91133200 : HARD_REG_SET curr_alt_exclude_start_hard_regs[MAX_RECOG_OPERANDS];
2466 91133200 : bool curr_alt_match_win[MAX_RECOG_OPERANDS];
2467 91133200 : bool curr_alt_win[MAX_RECOG_OPERANDS];
2468 91133200 : bool curr_alt_offmemok[MAX_RECOG_OPERANDS];
2469 91133200 : int curr_alt_matches[MAX_RECOG_OPERANDS];
2470 : /* The number of elements in the following array. */
2471 91133200 : int curr_alt_dont_inherit_ops_num;
2472 : /* Numbers of operands whose reload pseudos should not be inherited. */
2473 91133200 : int curr_alt_dont_inherit_ops[MAX_RECOG_OPERANDS];
2474 91133200 : bool curr_reuse_alt_p;
2475 : /* True if output stack pointer reload should be generated for the current
2476 : alternative. */
2477 91133200 : bool curr_alt_out_sp_reload_p;
2478 91133200 : bool curr_alt_class_change_p;
2479 91133200 : rtx op;
2480 : /* The register when the operand is a subreg of register, otherwise the
2481 : operand itself. */
2482 91133200 : rtx no_subreg_reg_operand[MAX_RECOG_OPERANDS];
2483 : /* The register if the operand is a register or subreg of register,
2484 : otherwise NULL. */
2485 91133200 : rtx operand_reg[MAX_RECOG_OPERANDS];
2486 91133200 : int hard_regno[MAX_RECOG_OPERANDS];
2487 91133200 : machine_mode biggest_mode[MAX_RECOG_OPERANDS];
2488 91133200 : int reload_nregs, reload_sum;
2489 91133200 : bool costly_p;
2490 91133200 : enum reg_class cl;
2491 91133200 : const HARD_REG_SET *cl_filter;
2492 91133200 : HARD_REG_SET hard_reg_constraint;
2493 :
2494 : /* Calculate some data common for all alternatives to speed up the
2495 : function. */
2496 303006106 : for (nop = 0; nop < n_operands; nop++)
2497 : {
2498 211872906 : rtx reg;
2499 :
2500 211872906 : op = no_subreg_reg_operand[nop] = *curr_id->operand_loc[nop];
2501 : /* The real hard regno of the operand after the allocation. */
2502 211872906 : hard_regno[nop] = get_hard_regno (op);
2503 :
2504 211872906 : operand_reg[nop] = reg = op;
2505 211872906 : biggest_mode[nop] = GET_MODE (op);
2506 211872906 : if (GET_CODE (op) == SUBREG)
2507 : {
2508 4256697 : biggest_mode[nop] = wider_subreg_mode (op);
2509 4256697 : operand_reg[nop] = reg = SUBREG_REG (op);
2510 : }
2511 211872906 : if (! REG_P (reg))
2512 89672377 : operand_reg[nop] = NULL_RTX;
2513 122200529 : else if (REGNO (reg) >= FIRST_PSEUDO_REGISTER
2514 143570313 : || ((int) REGNO (reg)
2515 21369784 : == lra_get_elimination_hard_regno (REGNO (reg))))
2516 119157477 : no_subreg_reg_operand[nop] = reg;
2517 : else
2518 3043052 : operand_reg[nop] = no_subreg_reg_operand[nop]
2519 : /* Just use natural mode for elimination result. It should
2520 : be enough for extra constraints hooks. */
2521 3043052 : = regno_reg_rtx[hard_regno[nop]];
2522 : }
2523 :
2524 : /* The constraints are made of several alternatives. Each operand's
2525 : constraint looks like foo,bar,... with commas separating the
2526 : alternatives. The first alternatives for all operands go
2527 : together, the second alternatives go together, etc.
2528 :
2529 : First loop over alternatives. */
2530 91133200 : alternative_mask preferred = curr_id->preferred_alternatives;
2531 91133200 : if (only_alternative >= 0)
2532 979535 : preferred &= ALTERNATIVE_BIT (only_alternative);
2533 :
2534 91133200 : bool prefer_memory_p = false;
2535 91133302 : repeat:
2536 385726426 : for (nalt = 0; nalt < n_alternatives; nalt++)
2537 : {
2538 : /* Loop over operands for one constraint alternative. */
2539 371759349 : if (!TEST_BIT (preferred, nalt))
2540 110611647 : continue;
2541 :
2542 261147702 : if (lra_dump_file != NULL)
2543 : {
2544 3403 : fprintf (lra_dump_file, " Considering alt=%d of insn %d: ",
2545 3403 : nalt, INSN_UID (curr_insn));
2546 3403 : print_curr_insn_alt (nalt);
2547 3403 : fprintf (lra_dump_file, "\n");
2548 : }
2549 :
2550 261147702 : bool matching_early_clobber[MAX_RECOG_OPERANDS];
2551 261147702 : curr_small_class_check++;
2552 261147702 : overall = losers = addr_losers = 0;
2553 261147702 : static_reject = reject = reload_nregs = reload_sum = 0;
2554 866092363 : for (nop = 0; nop < n_operands; nop++)
2555 : {
2556 604944661 : int inc = (curr_static_id
2557 604944661 : ->operand_alternative[nalt * n_operands + nop].reject);
2558 604944661 : if (lra_dump_file != NULL && inc != 0)
2559 53 : fprintf (lra_dump_file,
2560 : " Statically defined alt reject+=%d\n", inc);
2561 604944661 : static_reject += inc;
2562 604944661 : matching_early_clobber[nop] = 0;
2563 : }
2564 : reject += static_reject;
2565 : early_clobbered_regs_num = 0;
2566 : curr_alt_out_sp_reload_p = false;
2567 : curr_reuse_alt_p = true;
2568 : curr_alt_class_change_p = false;
2569 : all_this_alternative = NO_REGS;
2570 : all_used_nregs = all_reload_nregs = 0;
2571 675676338 : for (nop = 0; nop < n_operands; nop++)
2572 : {
2573 538968239 : const char *p;
2574 538968239 : char *end;
2575 538968239 : int len, c, m, i, opalt_num, this_alternative_matches;
2576 538968239 : bool win, did_match, offmemok, early_clobber_p;
2577 : /* false => this operand can be reloaded somehow for this
2578 : alternative. */
2579 538968239 : bool badop;
2580 : /* true => this operand can be reloaded if the alternative
2581 : allows regs. */
2582 538968239 : bool winreg;
2583 : /* True if a constant forced into memory would be OK for
2584 : this operand. */
2585 538968239 : bool constmemok;
2586 538968239 : enum reg_class this_alternative, this_costly_alternative;
2587 538968239 : HARD_REG_SET this_alternative_set, this_costly_alternative_set;
2588 538968239 : HARD_REG_SET this_alternative_exclude_start_hard_regs;
2589 538968239 : bool this_alternative_match_win, this_alternative_win;
2590 538968239 : bool this_alternative_offmemok;
2591 538968239 : bool scratch_p;
2592 538968239 : machine_mode mode;
2593 538968239 : enum constraint_num cn;
2594 538968239 : bool class_change_p = false;
2595 :
2596 538968239 : opalt_num = nalt * n_operands + nop;
2597 538968239 : if (curr_static_id->operand_alternative[opalt_num].anything_ok)
2598 : {
2599 : /* Fast track for no constraints at all. */
2600 14989634 : curr_alt[nop] = NO_REGS;
2601 14989634 : CLEAR_HARD_REG_SET (curr_alt_set[nop]);
2602 14989634 : curr_alt_win[nop] = true;
2603 14989634 : curr_alt_match_win[nop] = false;
2604 14989634 : curr_alt_offmemok[nop] = false;
2605 14989634 : curr_alt_matches[nop] = -1;
2606 14989634 : continue;
2607 : }
2608 :
2609 523978605 : op = no_subreg_reg_operand[nop];
2610 523978605 : mode = curr_operand_mode[nop];
2611 :
2612 523978605 : win = did_match = winreg = offmemok = constmemok = false;
2613 523978605 : badop = true;
2614 523978605 : const HARD_REG_SET *cl_dep_filter = nullptr;
2615 :
2616 523978605 : early_clobber_p = false;
2617 523978605 : p = curr_static_id->operand_alternative[opalt_num].constraint;
2618 :
2619 523978605 : this_costly_alternative = this_alternative = NO_REGS;
2620 : /* We update set of possible hard regs besides its class
2621 : because reg class might be inaccurate. For example,
2622 : union of LO_REGS (l), HI_REGS(h), and STACK_REG(k) in ARM
2623 : is translated in HI_REGS because classes are merged by
2624 : pairs and there is no accurate intermediate class. */
2625 2095914420 : CLEAR_HARD_REG_SET (this_alternative_set);
2626 1571935815 : CLEAR_HARD_REG_SET (this_costly_alternative_set);
2627 523978605 : CLEAR_HARD_REG_SET (this_alternative_exclude_start_hard_regs);
2628 523978605 : this_alternative_win = false;
2629 523978605 : this_alternative_match_win = false;
2630 523978605 : this_alternative_offmemok = false;
2631 523978605 : this_alternative_matches = -1;
2632 :
2633 : /* An empty constraint should be excluded by the fast
2634 : track. */
2635 523978605 : lra_assert (*p != 0 && *p != ',');
2636 :
2637 : op_reject = 0;
2638 : /* Scan this alternative's specs for this operand; set WIN
2639 : if the operand fits any letter in this alternative.
2640 : Otherwise, clear BADOP if this operand could fit some
2641 : letter after reloads, or set WINREG if this operand could
2642 : fit after reloads provided the constraint allows some
2643 : registers. */
2644 : costly_p = false;
2645 1330869478 : do
2646 : {
2647 1330869478 : switch ((c = *p, len = CONSTRAINT_LEN (c, p)), c)
2648 : {
2649 : case '\0':
2650 : len = 0;
2651 : break;
2652 500867623 : case ',':
2653 500867623 : c = '\0';
2654 500867623 : break;
2655 :
2656 185739 : case '&':
2657 185739 : early_clobber_p = true;
2658 185739 : break;
2659 :
2660 20567 : case '$':
2661 20567 : op_reject += LRA_MAX_REJECT;
2662 20567 : break;
2663 0 : case '^':
2664 0 : op_reject += LRA_LOSER_COST_FACTOR;
2665 0 : break;
2666 :
2667 0 : case '#':
2668 : /* Ignore rest of this alternative. */
2669 0 : c = '\0';
2670 0 : break;
2671 :
2672 57142738 : case '0': case '1': case '2': case '3': case '4':
2673 57142738 : case '5': case '6': case '7': case '8': case '9':
2674 57142738 : {
2675 57142738 : int m_hregno;
2676 57142738 : bool match_p;
2677 :
2678 57142738 : m = strtoul (p, &end, 10);
2679 57142738 : p = end;
2680 57142738 : len = 0;
2681 57142738 : lra_assert (nop > m);
2682 :
2683 : /* Reject matches if we don't know which operand is
2684 : bigger. This situation would arguably be a bug in
2685 : an .md pattern, but could also occur in a user asm. */
2686 171428214 : if (!ordered_p (GET_MODE_SIZE (biggest_mode[m]),
2687 57142738 : GET_MODE_SIZE (biggest_mode[nop])))
2688 : break;
2689 :
2690 : /* Don't match wrong asm insn operands for proper
2691 : diagnostic later. */
2692 57142738 : if (INSN_CODE (curr_insn) < 0
2693 34760 : && (curr_operand_mode[m] == BLKmode
2694 34759 : || curr_operand_mode[nop] == BLKmode)
2695 1 : && curr_operand_mode[m] != curr_operand_mode[nop])
2696 : break;
2697 :
2698 57142737 : m_hregno = get_hard_regno (*curr_id->operand_loc[m]);
2699 : /* We are supposed to match a previous operand.
2700 : If we do, we win if that one did. If we do
2701 : not, count both of the operands as losers.
2702 : (This is too conservative, since most of the
2703 : time only a single reload insn will be needed
2704 : to make the two operands win. As a result,
2705 : this alternative may be rejected when it is
2706 : actually desirable.) */
2707 57142737 : match_p = false;
2708 57142737 : if (operands_match_p (*curr_id->operand_loc[nop],
2709 57142737 : *curr_id->operand_loc[m], m_hregno))
2710 : {
2711 : /* We should reject matching of an early
2712 : clobber operand if the matching operand is
2713 : not dying in the insn. */
2714 15033890 : if (!TEST_BIT (curr_static_id->operand[m]
2715 : .early_clobber_alts, nalt)
2716 18495 : || operand_reg[nop] == NULL_RTX
2717 15052385 : || (find_regno_note (curr_insn, REG_DEAD,
2718 : REGNO (op))
2719 4372 : || REGNO (op) == REGNO (operand_reg[m])))
2720 15033890 : match_p = true;
2721 : }
2722 15033890 : if (match_p)
2723 : {
2724 : /* If we are matching a non-offsettable
2725 : address where an offsettable address was
2726 : expected, then we must reject this
2727 : combination, because we can't reload
2728 : it. */
2729 15033890 : if (curr_alt_offmemok[m]
2730 1490 : && MEM_P (*curr_id->operand_loc[m])
2731 0 : && curr_alt[m] == NO_REGS && ! curr_alt_win[m])
2732 0 : continue;
2733 : }
2734 : else
2735 : {
2736 : /* If the operands do not match and one
2737 : operand is INOUT, we can not match them.
2738 : Try other possibilities, e.g. other
2739 : alternatives or commutative operand
2740 : exchange. */
2741 42108847 : if (curr_static_id->operand[nop].type == OP_INOUT
2742 42108847 : || curr_static_id->operand[m].type == OP_INOUT)
2743 : break;
2744 : /* Operands don't match. For asm if the operands
2745 : are different user defined explicit hard
2746 : registers, then we cannot make them match
2747 : when one is early clobber operand. */
2748 42108434 : if ((REG_P (*curr_id->operand_loc[nop])
2749 26331960 : || SUBREG_P (*curr_id->operand_loc[nop]))
2750 16363770 : && (REG_P (*curr_id->operand_loc[m])
2751 203373 : || SUBREG_P (*curr_id->operand_loc[m]))
2752 16270590 : && INSN_CODE (curr_insn) < 0)
2753 : {
2754 590 : rtx nop_reg = *curr_id->operand_loc[nop];
2755 590 : if (SUBREG_P (nop_reg))
2756 0 : nop_reg = SUBREG_REG (nop_reg);
2757 590 : rtx m_reg = *curr_id->operand_loc[m];
2758 590 : if (SUBREG_P (m_reg))
2759 0 : m_reg = SUBREG_REG (m_reg);
2760 :
2761 590 : if (REG_P (nop_reg)
2762 590 : && HARD_REGISTER_P (nop_reg)
2763 0 : && REG_USERVAR_P (nop_reg)
2764 0 : && REG_P (m_reg)
2765 0 : && HARD_REGISTER_P (m_reg)
2766 590 : && REG_USERVAR_P (m_reg))
2767 : {
2768 : int i;
2769 :
2770 0 : for (i = 0; i < early_clobbered_regs_num; i++)
2771 0 : if (m == early_clobbered_nops[i])
2772 : break;
2773 0 : if (i < early_clobbered_regs_num
2774 0 : || early_clobber_p)
2775 : break;
2776 : }
2777 : }
2778 : /* Both operands must allow a reload register,
2779 : otherwise we cannot make them match. */
2780 42108434 : if (curr_alt[m] == NO_REGS)
2781 : break;
2782 : /* Retroactively mark the operand we had to
2783 : match as a loser, if it wasn't already and
2784 : it wasn't matched to a register constraint
2785 : (e.g it might be matched by memory). */
2786 42084210 : if (curr_alt_win[m]
2787 41223301 : && (operand_reg[m] == NULL_RTX
2788 40702017 : || hard_regno[m] < 0))
2789 : {
2790 1289576 : if (lra_dump_file != NULL)
2791 9 : fprintf
2792 9 : (lra_dump_file,
2793 : " %d Matched operand reload: "
2794 : "losers++\n", m);
2795 1289576 : losers++;
2796 1289576 : reload_nregs
2797 1289576 : += (ira_reg_class_max_nregs[curr_alt[m]]
2798 1289576 : [GET_MODE (*curr_id->operand_loc[m])]);
2799 : }
2800 :
2801 : /* Prefer matching earlyclobber alternative as
2802 : it results in less hard regs required for
2803 : the insn than a non-matching earlyclobber
2804 : alternative. */
2805 42084210 : if (TEST_BIT (curr_static_id->operand[m]
2806 : .early_clobber_alts, nalt))
2807 : {
2808 18876 : if (lra_dump_file != NULL)
2809 0 : fprintf
2810 0 : (lra_dump_file,
2811 : " %d Matching earlyclobber alt:"
2812 : " reject--\n",
2813 : nop);
2814 18876 : if (!matching_early_clobber[m])
2815 : {
2816 18876 : reject--;
2817 18876 : matching_early_clobber[m] = 1;
2818 : }
2819 : }
2820 : /* Otherwise we prefer no matching
2821 : alternatives because it gives more freedom
2822 : in RA. */
2823 42065334 : else if (operand_reg[nop] == NULL_RTX
2824 42065334 : || (find_regno_note (curr_insn, REG_DEAD,
2825 16338031 : REGNO (operand_reg[nop]))
2826 : == NULL_RTX))
2827 : {
2828 37024908 : if (lra_dump_file != NULL)
2829 912 : fprintf
2830 912 : (lra_dump_file,
2831 : " %d Matching alt: reject+=2\n",
2832 : nop);
2833 37024908 : reject += 2;
2834 : }
2835 : }
2836 : /* If we have to reload this operand and some
2837 : previous operand also had to match the same
2838 : thing as this operand, we don't know how to do
2839 : that. */
2840 57118100 : if (!match_p || !curr_alt_win[m])
2841 : {
2842 88487042 : for (i = 0; i < nop; i++)
2843 46294225 : if (curr_alt_matches[i] == m)
2844 : break;
2845 42192818 : if (i < nop)
2846 : break;
2847 : }
2848 : else
2849 : did_match = true;
2850 :
2851 57118099 : this_alternative_matches = m;
2852 : /* This can be fixed with reloads if the operand
2853 : we are supposed to match can be fixed with
2854 : reloads. */
2855 57118099 : badop = false;
2856 57118099 : this_alternative = curr_alt[m];
2857 57118099 : this_alternative_set = curr_alt_set[m];
2858 57118099 : this_alternative_exclude_start_hard_regs
2859 57118099 : = curr_alt_exclude_start_hard_regs[m];
2860 57118099 : winreg = this_alternative != NO_REGS;
2861 57118099 : break;
2862 : }
2863 :
2864 11792003 : case 'g':
2865 11792003 : if (MEM_P (op)
2866 7902745 : || general_constant_p (op)
2867 16380646 : || spilled_pseudo_p (op))
2868 : win = true;
2869 11792003 : if (REG_P (op) && prefer_memory_p)
2870 : {
2871 11792003 : badop = false;
2872 11792003 : offmemok = true;
2873 : }
2874 11792003 : cl = GENERAL_REGS;
2875 11792003 : cl_filter = nullptr;
2876 11792003 : cl_dep_filter = nullptr;
2877 11792003 : goto reg;
2878 :
2879 1140 : case '{':
2880 1140 : {
2881 1140 : int regno = decode_hard_reg_constraint (p);
2882 1140 : gcc_assert (regno >= 0);
2883 1140 : cl = NO_REGS;
2884 1140 : int nregs = hard_regno_nregs (regno, mode);
2885 2280 : for (int i = 0; i < nregs; ++i)
2886 1140 : cl = reg_class_superunion[cl][REGNO_REG_CLASS (regno + i)];
2887 1140 : CLEAR_HARD_REG_SET (hard_reg_constraint);
2888 1140 : SET_HARD_REG_BIT (hard_reg_constraint, regno);
2889 1140 : cl_filter = &hard_reg_constraint;
2890 1140 : cl_dep_filter = nullptr;
2891 1140 : goto reg;
2892 : }
2893 :
2894 737748686 : default:
2895 737748686 : cn = lookup_constraint (p);
2896 737748686 : switch (get_constraint_type (cn))
2897 : {
2898 488115631 : case CT_REGISTER:
2899 488115631 : cl = reg_class_for_constraint (cn);
2900 358969214 : if (cl != NO_REGS)
2901 : {
2902 349517478 : cl_filter = get_register_filter (cn);
2903 349517478 : cl_dep_filter = get_dependent_filter (cn, mode);
2904 349517478 : goto reg;
2905 : }
2906 : break;
2907 :
2908 2155498 : case CT_CONST_INT:
2909 2155498 : if (CONST_INT_P (op)
2910 2155498 : && insn_const_int_ok_for_constraint (INTVAL (op), cn))
2911 : win = true;
2912 : break;
2913 :
2914 112280332 : case CT_MEMORY:
2915 112280332 : case CT_RELAXED_MEMORY:
2916 112280332 : if (MEM_P (op)
2917 112280332 : && satisfies_memory_constraint_p (op, cn))
2918 : win = true;
2919 76318654 : else if (spilled_pseudo_p (op))
2920 45526959 : win = true;
2921 :
2922 : /* If we didn't already win, we can reload constants
2923 : via force_const_mem or put the pseudo value into
2924 : memory, or make other memory by reloading the
2925 : address like for 'o'. */
2926 117414870 : if (CONST_POOL_OK_P (mode, op)
2927 107145630 : || MEM_P (op) || REG_P (op)
2928 : /* We can restore the equiv insn by a
2929 : reload. */
2930 112906001 : || equiv_substition_p[nop])
2931 112244981 : badop = false;
2932 : constmemok = true;
2933 : offmemok = true;
2934 : break;
2935 :
2936 1763745 : case CT_ADDRESS:
2937 : /* An asm operand with an address constraint
2938 : that doesn't satisfy address_operand has
2939 : is_address cleared, so that we don't try to
2940 : make a non-address fit. */
2941 1763745 : if (!curr_static_id->operand[nop].is_address)
2942 : break;
2943 : /* If we didn't already win, we can reload the address
2944 : into a base register. */
2945 1763726 : if (satisfies_address_constraint_p (op, cn))
2946 1763726 : win = true;
2947 1763726 : cl = base_reg_class (VOIDmode, ADDR_SPACE_GENERIC,
2948 : ADDRESS, SCRATCH);
2949 1763726 : cl_filter = nullptr;
2950 1763726 : cl_dep_filter = nullptr;
2951 1763726 : badop = false;
2952 1763726 : goto reg;
2953 :
2954 132193034 : case CT_FIXED_FORM:
2955 132193034 : if (constraint_satisfied_p (op, cn))
2956 1330869478 : win = true;
2957 : break;
2958 :
2959 1240446 : case CT_SPECIAL_MEMORY:
2960 1240446 : if (satisfies_memory_constraint_p (op, cn))
2961 : win = true;
2962 1077904 : else if (spilled_pseudo_p (op))
2963 : {
2964 1330869478 : curr_reuse_alt_p = false;
2965 1330869478 : win = true;
2966 : }
2967 : break;
2968 : }
2969 : break;
2970 :
2971 363074347 : reg:
2972 363074347 : if (mode == BLKmode)
2973 : break;
2974 363074329 : this_alternative = reg_class_subunion[this_alternative][cl];
2975 363074329 : if (hard_reg_set_subset_p (this_alternative_set,
2976 363074329 : reg_class_contents[cl]))
2977 363070704 : this_alternative_exclude_start_hard_regs
2978 363070704 : = ira_exclude_class_mode_regs[cl][mode];
2979 3625 : else if (!hard_reg_set_subset_p (reg_class_contents[cl],
2980 : this_alternative_set))
2981 3624 : this_alternative_exclude_start_hard_regs
2982 1089226611 : |= ira_exclude_class_mode_regs[cl][mode];
2983 363074329 : this_alternative_set |= reg_class_contents[cl];
2984 363074329 : if (cl_filter)
2985 2280 : this_alternative_exclude_start_hard_regs |= ~*cl_filter;
2986 363074329 : if (cl_dep_filter)
2987 : this_alternative_exclude_start_hard_regs |= ~*cl_dep_filter;
2988 363074329 : if (costly_p)
2989 : {
2990 21672889 : this_costly_alternative
2991 21672889 : = reg_class_subunion[this_costly_alternative][cl];
2992 21672889 : this_costly_alternative_set |= reg_class_contents[cl];
2993 : }
2994 363074329 : winreg = true;
2995 363074329 : if (REG_P (op))
2996 : {
2997 231445289 : rtx orig_op = *curr_id->operand_loc[nop];
2998 6858116 : if (GET_CODE (orig_op) == SUBREG && HARD_REGISTER_P (op)
2999 231445380 : && !targetm.hard_regno_mode_ok (REGNO (op),
3000 91 : GET_MODE(orig_op)))
3001 : break;
3002 :
3003 231445289 : tree decl;
3004 :
3005 231445289 : if (hard_regno[nop] >= 0
3006 195198502 : && in_hard_reg_set_p (this_alternative_set,
3007 : mode, hard_regno[nop])
3008 176520786 : && (!cl_filter
3009 590 : || TEST_HARD_REG_BIT (*cl_filter,
3010 : hard_regno[nop]))
3011 : && (!cl_dep_filter
3012 : || TEST_HARD_REG_BIT (*cl_dep_filter,
3013 : hard_regno[nop]))
3014 407966069 : && ((REG_ATTRS (op) && (decl = REG_EXPR (op)) != NULL
3015 98551883 : && VAR_P (decl) && DECL_HARD_REGISTER (decl))
3016 176517523 : || !(TEST_HARD_REG_BIT
3017 176517523 : (this_alternative_exclude_start_hard_regs,
3018 : hard_regno[nop]))))
3019 : win = true;
3020 54924516 : else if (hard_regno[nop] < 0 && !prefer_memory_p)
3021 : {
3022 36246651 : if (in_class_p (op, this_alternative, NULL))
3023 : win = true;
3024 27151538 : else if (in_class_p (op, this_alternative, NULL, true))
3025 : {
3026 1330869478 : class_change_p = true;
3027 1330869478 : win = true;
3028 : }
3029 : }
3030 : }
3031 : break;
3032 : }
3033 1330869478 : if (c != ' ' && c != '\t')
3034 1330869478 : costly_p = c == '*';
3035 : }
3036 1330869478 : while ((p += len), c);
3037 :
3038 1047957210 : scratch_p = (operand_reg[nop] != NULL_RTX
3039 523978605 : && ira_former_scratch_p (REGNO (operand_reg[nop])));
3040 : /* Record which operands fit this alternative. */
3041 523978605 : if (win)
3042 : {
3043 282238861 : if (early_clobber_p
3044 282089731 : || curr_static_id->operand[nop].type != OP_OUT)
3045 : {
3046 123472412 : if (winreg)
3047 102046336 : all_used_nregs
3048 102046336 : += ira_reg_class_min_nregs[this_alternative][mode];
3049 123472412 : all_this_alternative
3050 123472412 : = (reg_class_subunion
3051 123472412 : [all_this_alternative][this_alternative]);
3052 : }
3053 282238861 : this_alternative_win = true;
3054 282238861 : if (class_change_p)
3055 : {
3056 259421 : curr_alt_class_change_p = true;
3057 259421 : if (lra_dump_file != NULL)
3058 10 : fprintf (lra_dump_file,
3059 : " %d Narrowing class: reject+=3\n",
3060 : nop);
3061 259421 : reject += 3;
3062 : }
3063 282238861 : if (operand_reg[nop] != NULL_RTX)
3064 : {
3065 196864514 : if (hard_regno[nop] >= 0)
3066 : {
3067 176464284 : if (in_hard_reg_set_p (this_costly_alternative_set,
3068 : mode, hard_regno[nop]))
3069 : {
3070 779266 : if (lra_dump_file != NULL)
3071 21 : fprintf (lra_dump_file,
3072 : " %d Costly set: reject++\n",
3073 : nop);
3074 779266 : reject++;
3075 : }
3076 : }
3077 : else
3078 : {
3079 : /* Prefer won reg to spilled pseudo under other
3080 : equal conditions for possible inheritance. */
3081 20400230 : if (! scratch_p)
3082 : {
3083 20395608 : if (lra_dump_file != NULL)
3084 59 : fprintf
3085 59 : (lra_dump_file,
3086 : " %d Non pseudo reload: reject++\n",
3087 : nop);
3088 20395608 : reject++;
3089 : }
3090 20400230 : if (in_class_p (operand_reg[nop],
3091 : this_costly_alternative, NULL, true))
3092 : {
3093 134692 : if (lra_dump_file != NULL)
3094 0 : fprintf
3095 0 : (lra_dump_file,
3096 : " %d Non pseudo costly reload:"
3097 : " reject++\n",
3098 : nop);
3099 134692 : reject++;
3100 : }
3101 : }
3102 : /* We simulate the behavior of old reload here.
3103 : Although scratches need hard registers and it
3104 : might result in spilling other pseudos, no reload
3105 : insns are generated for the scratches. So it
3106 : might cost something but probably less than old
3107 : reload pass believes. */
3108 196864514 : if (scratch_p)
3109 : {
3110 120496 : if (lra_dump_file != NULL)
3111 6 : fprintf (lra_dump_file,
3112 : " %d Scratch win: reject+=2\n",
3113 : nop);
3114 120496 : reject += 2;
3115 : }
3116 : }
3117 : }
3118 241739744 : else if (did_match)
3119 : this_alternative_match_win = true;
3120 : else
3121 : {
3122 226814462 : if (prefer_memory_p && offmemok)
3123 : {
3124 0 : winreg = false;
3125 0 : this_alternative = NO_REGS;
3126 : }
3127 :
3128 226814462 : int const_to_mem = 0;
3129 226814462 : bool no_regs_p;
3130 :
3131 226814462 : reject += op_reject;
3132 : /* Mark output reload of the stack pointer. */
3133 226814462 : if (op == stack_pointer_rtx
3134 56041 : && curr_static_id->operand[nop].type != OP_IN)
3135 226814462 : curr_alt_out_sp_reload_p = true;
3136 :
3137 : /* If this alternative asks for a specific reg class, see if there
3138 : is at least one allocatable register in that class. */
3139 226814462 : no_regs_p
3140 395473643 : = (this_alternative == NO_REGS
3141 226814462 : || (hard_reg_set_subset_p
3142 337318390 : (reg_class_contents[this_alternative],
3143 : lra_no_alloc_regs)));
3144 :
3145 : /* For asms, verify that the class for this alternative is possible
3146 : for the mode that is specified. */
3147 168659181 : if (!no_regs_p && INSN_CODE (curr_insn) < 0)
3148 : {
3149 : int i;
3150 69498 : for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
3151 69496 : if (targetm.hard_regno_mode_ok (i, mode)
3152 69496 : && in_hard_reg_set_p (reg_class_contents[this_alternative],
3153 : mode, i))
3154 : break;
3155 20302 : if (i == FIRST_PSEUDO_REGISTER)
3156 226814462 : winreg = false;
3157 : }
3158 :
3159 : /* If this operand accepts a register, and if the
3160 : register class has at least one allocatable register,
3161 : then this operand can be reloaded. */
3162 226814462 : if (winreg && !no_regs_p)
3163 : badop = false;
3164 :
3165 58155283 : if (badop)
3166 : {
3167 48585905 : if (lra_dump_file != NULL)
3168 606 : fprintf (lra_dump_file,
3169 : " Bad operand -- refuse\n");
3170 124439603 : goto fail;
3171 : }
3172 :
3173 178228557 : if (this_alternative != NO_REGS)
3174 : {
3175 168659180 : HARD_REG_SET available_regs
3176 168659180 : = (reg_class_contents[this_alternative]
3177 168659180 : & ~((ira_prohibited_class_mode_regs
3178 168659180 : [this_alternative][mode])
3179 168659180 : | lra_no_alloc_regs));
3180 337318360 : if (!hard_reg_set_empty_p (available_regs))
3181 : {
3182 168657623 : if (early_clobber_p
3183 168621014 : || curr_static_id->operand[nop].type != OP_OUT)
3184 : {
3185 88294614 : all_reload_nregs
3186 88294614 : += ira_reg_class_min_nregs[this_alternative][mode];
3187 88294614 : all_this_alternative
3188 88294614 : = (reg_class_subunion
3189 88294614 : [all_this_alternative][this_alternative]);
3190 : }
3191 : }
3192 : else
3193 : {
3194 : /* There are no hard regs holding a value of given
3195 : mode. */
3196 1557 : if (offmemok)
3197 : {
3198 166 : this_alternative = NO_REGS;
3199 166 : if (lra_dump_file != NULL)
3200 0 : fprintf (lra_dump_file,
3201 : " %d Using memory because of"
3202 : " a bad mode: reject+=2\n",
3203 : nop);
3204 166 : reject += 2;
3205 : }
3206 : else
3207 : {
3208 1391 : if (lra_dump_file != NULL)
3209 0 : fprintf (lra_dump_file,
3210 : " Wrong mode -- refuse\n");
3211 1391 : goto fail;
3212 : }
3213 : }
3214 : }
3215 :
3216 : /* If not assigned pseudo has a class which a subset of
3217 : required reg class, it is a less costly alternative
3218 : as the pseudo still can get a hard reg of necessary
3219 : class. */
3220 168657789 : if (! no_regs_p && REG_P (op) && hard_regno[nop] < 0
3221 21734702 : && (cl = get_reg_class (REGNO (op))) != NO_REGS
3222 181386976 : && ira_class_subset_p[this_alternative][cl])
3223 : {
3224 1066 : if (lra_dump_file != NULL)
3225 0 : fprintf
3226 0 : (lra_dump_file,
3227 : " %d Super set class reg: reject-=3\n", nop);
3228 1066 : reject -= 3;
3229 : }
3230 :
3231 178227166 : this_alternative_offmemok = offmemok;
3232 178227166 : if (this_costly_alternative != NO_REGS)
3233 : {
3234 19501261 : if (lra_dump_file != NULL)
3235 25 : fprintf (lra_dump_file,
3236 : " %d Costly loser: reject++\n", nop);
3237 19501261 : reject++;
3238 : }
3239 : /* If the operand is dying, has a matching constraint,
3240 : and satisfies constraints of the matched operand
3241 : which failed to satisfy the own constraints, most probably
3242 : the reload for this operand will be gone. */
3243 178227166 : if (this_alternative_matches >= 0
3244 42175446 : && !curr_alt_win[this_alternative_matches]
3245 969037 : && REG_P (op)
3246 715035 : && find_regno_note (curr_insn, REG_DEAD, REGNO (op))
3247 178964160 : && (hard_regno[nop] >= 0
3248 386223 : ? in_hard_reg_set_p (this_alternative_set,
3249 : mode, hard_regno[nop])
3250 35452 : : in_class_p (op, this_alternative, NULL)))
3251 : {
3252 237037 : if (lra_dump_file != NULL)
3253 1 : fprintf
3254 1 : (lra_dump_file,
3255 : " %d Dying matched operand reload: reject++\n",
3256 : nop);
3257 237037 : reject++;
3258 : }
3259 : else
3260 : {
3261 : /* Strict_low_part requires to reload the register
3262 : not the sub-register. In this case we should
3263 : check that a final reload hard reg can hold the
3264 : value mode. */
3265 177990129 : if (curr_static_id->operand[nop].strict_low
3266 114 : && REG_P (op)
3267 107 : && hard_regno[nop] < 0
3268 81 : && GET_CODE (*curr_id->operand_loc[nop]) == SUBREG
3269 81 : && ira_class_hard_regs_num[this_alternative] > 0
3270 177990210 : && (!targetm.hard_regno_mode_ok
3271 81 : (ira_class_hard_regs[this_alternative][0],
3272 81 : GET_MODE (*curr_id->operand_loc[nop]))))
3273 : {
3274 0 : if (lra_dump_file != NULL)
3275 0 : fprintf
3276 0 : (lra_dump_file,
3277 : " Strict low subreg reload -- refuse\n");
3278 0 : goto fail;
3279 : }
3280 177990129 : if (lra_dump_file != NULL)
3281 2177 : fprintf
3282 2177 : (lra_dump_file,
3283 : " %d Operand reload: losers++\n", nop);
3284 177990129 : losers++;
3285 : }
3286 178227166 : if (operand_reg[nop] != NULL_RTX
3287 : /* Output operands and matched input operands are
3288 : not inherited. The following conditions do not
3289 : exactly describe the previous statement but they
3290 : are pretty close. */
3291 64345412 : && curr_static_id->operand[nop].type != OP_OUT
3292 28192943 : && (this_alternative_matches < 0
3293 16431883 : || curr_static_id->operand[nop].type != OP_IN))
3294 : {
3295 11761060 : int last_reload = (lra_reg_info[ORIGINAL_REGNO
3296 11761060 : (operand_reg[nop])]
3297 11761060 : .last_reload);
3298 :
3299 : /* The value of reload_sum has sense only if we
3300 : process insns in their order. It happens only on
3301 : the first constraints sub-pass when we do most of
3302 : reload work. */
3303 11761060 : if (lra_constraint_iter == 1 && last_reload > bb_reload_num)
3304 2565697 : reload_sum += last_reload - bb_reload_num;
3305 : }
3306 : /* If this is a constant that is reloaded into the
3307 : desired class by copying it to memory first, count
3308 : that as another reload. This is consistent with
3309 : other code and is required to avoid choosing another
3310 : alternative when the constant is moved into memory.
3311 : Note that the test here is precisely the same as in
3312 : the code below that calls force_const_mem. */
3313 228871213 : if (CONST_POOL_OK_P (mode, op)
3314 228871284 : && ((targetm.preferred_reload_class
3315 50644118 : (op, this_alternative) == NO_REGS)
3316 49087938 : || no_input_reloads_p))
3317 : {
3318 1556180 : const_to_mem = 1;
3319 1556180 : if (! no_regs_p)
3320 : {
3321 724763 : if (lra_dump_file != NULL)
3322 0 : fprintf
3323 0 : (lra_dump_file,
3324 : " %d Constant reload through memory: "
3325 : "losers++\n", nop);
3326 724763 : losers++;
3327 : }
3328 : }
3329 :
3330 : /* Alternative loses if it requires a type of reload not
3331 : permitted for this insn. We can always reload
3332 : objects with a REG_UNUSED note. */
3333 178227166 : if ((curr_static_id->operand[nop].type != OP_IN
3334 86711133 : && no_output_reloads_p
3335 0 : && ! find_reg_note (curr_insn, REG_UNUSED, op)
3336 0 : && ! scratch_p)
3337 178227166 : || (curr_static_id->operand[nop].type != OP_OUT
3338 91516301 : && no_input_reloads_p && ! const_to_mem)
3339 356454332 : || (this_alternative_matches >= 0
3340 42175446 : && (no_input_reloads_p
3341 42175446 : || (no_output_reloads_p
3342 0 : && (curr_static_id->operand
3343 0 : [this_alternative_matches].type != OP_IN)
3344 0 : && ! find_reg_note (curr_insn, REG_UNUSED,
3345 : no_subreg_reg_operand
3346 0 : [this_alternative_matches])
3347 0 : && ! scratch_p))))
3348 : {
3349 0 : if (lra_dump_file != NULL)
3350 0 : fprintf
3351 0 : (lra_dump_file,
3352 : " No input/output reload -- refuse\n");
3353 0 : goto fail;
3354 : }
3355 :
3356 : /* Alternative loses if it required class pseudo cannot
3357 : hold value of required mode. Such insns can be
3358 : described by insn definitions with mode iterators. */
3359 178227166 : if (GET_MODE (*curr_id->operand_loc[nop]) != VOIDmode
3360 129003236 : && ! hard_reg_set_empty_p (this_alternative_set)
3361 : /* It is common practice for constraints to use a
3362 : class which does not have actually enough regs to
3363 : hold the value (e.g. x86 AREG for mode requiring
3364 : more one general reg). Therefore we have 2
3365 : conditions to check that the reload pseudo cannot
3366 : hold the mode value. */
3367 120163982 : && (!targetm.hard_regno_mode_ok
3368 120163982 : (ira_class_hard_regs[this_alternative][0],
3369 : GET_MODE (*curr_id->operand_loc[nop])))
3370 : /* The above condition is not enough as the first
3371 : reg in ira_class_hard_regs can be not aligned for
3372 : multi-words mode values. */
3373 178227166 : && (prohibited_class_reg_set_mode_p
3374 0 : (this_alternative, this_alternative_set,
3375 0 : GET_MODE (*curr_id->operand_loc[nop]))))
3376 : {
3377 0 : if (lra_dump_file != NULL)
3378 0 : fprintf (lra_dump_file,
3379 : " reload pseudo for op %d "
3380 : "cannot hold the mode value -- refuse\n",
3381 : nop);
3382 0 : goto fail;
3383 : }
3384 :
3385 : /* Check strong discouragement of reload of non-constant
3386 : into class THIS_ALTERNATIVE. */
3387 127583048 : if (! CONSTANT_P (op) && ! no_regs_p
3388 297072254 : && (targetm.preferred_reload_class
3389 118845088 : (op, this_alternative) == NO_REGS
3390 110268097 : || (curr_static_id->operand[nop].type == OP_OUT
3391 75951607 : && (targetm.preferred_output_reload_class
3392 75951607 : (op, this_alternative) == NO_REGS))))
3393 : {
3394 13131406 : if (offmemok && REG_P (op))
3395 : {
3396 793367 : if (lra_dump_file != NULL)
3397 0 : fprintf
3398 0 : (lra_dump_file,
3399 : " %d Spill pseudo into memory: reject+=3\n",
3400 : nop);
3401 793367 : reject += 3;
3402 : }
3403 : else
3404 : {
3405 12338039 : if (lra_dump_file != NULL)
3406 0 : fprintf
3407 0 : (lra_dump_file,
3408 : " %d Non-preferred reload: reject+=%d\n",
3409 : nop, LRA_MAX_REJECT);
3410 12338039 : reject += LRA_MAX_REJECT;
3411 : }
3412 : }
3413 :
3414 178227166 : if (! (MEM_P (op) && offmemok)
3415 178227094 : && ! (const_to_mem && constmemok))
3416 : {
3417 : /* We prefer to reload pseudos over reloading other
3418 : things, since such reloads may be able to be
3419 : eliminated later. So bump REJECT in other cases.
3420 : Don't do this in the case where we are forcing a
3421 : constant into memory and it will then win since
3422 : we don't want to have a different alternative
3423 : match then. */
3424 177276372 : if (! (REG_P (op) && REGNO (op) >= FIRST_PSEUDO_REGISTER))
3425 : {
3426 126850194 : if (lra_dump_file != NULL)
3427 1648 : fprintf
3428 1648 : (lra_dump_file,
3429 : " %d Non-pseudo reload: reject+=2\n",
3430 : nop);
3431 126850194 : reject += 2;
3432 : }
3433 :
3434 177276372 : if (! no_regs_p)
3435 168538482 : reload_nregs
3436 168538482 : += ira_reg_class_max_nregs[this_alternative][mode];
3437 :
3438 177276372 : if (SMALL_REGISTER_CLASS_P (this_alternative))
3439 : {
3440 889901 : if (lra_dump_file != NULL)
3441 45 : fprintf
3442 45 : (lra_dump_file,
3443 : " %d Small class reload: reject+=%d\n",
3444 : nop, LRA_LOSER_COST_FACTOR / 2);
3445 889901 : reject += LRA_LOSER_COST_FACTOR / 2;
3446 : }
3447 : }
3448 :
3449 : /* We are trying to spill pseudo into memory. It is
3450 : usually more costly than moving to a hard register
3451 : although it might takes the same number of
3452 : reloads.
3453 :
3454 : Non-pseudo spill may happen also. Suppose a target allows both
3455 : register and memory in the operand constraint alternatives,
3456 : then it's typical that an eliminable register has a substition
3457 : of "base + offset" which can either be reloaded by a simple
3458 : "new_reg <= base + offset" which will match the register
3459 : constraint, or a similar reg addition followed by further spill
3460 : to and reload from memory which will match the memory
3461 : constraint, but this memory spill will be much more costly
3462 : usually.
3463 :
3464 : Code below increases the reject for both pseudo and non-pseudo
3465 : spill. */
3466 178227166 : if (no_regs_p
3467 9569377 : && !(MEM_P (op) && offmemok)
3468 9569307 : && !(REG_P (op) && hard_regno[nop] < 0))
3469 : {
3470 8432180 : if (lra_dump_file != NULL)
3471 13 : fprintf
3472 20 : (lra_dump_file,
3473 : " %d Spill %spseudo into memory: reject+=3\n",
3474 : nop, REG_P (op) ? "" : "Non-");
3475 8432180 : reject += 3;
3476 8432180 : if (VECTOR_MODE_P (mode))
3477 : {
3478 : /* Spilling vectors into memory is usually more
3479 : costly as they contain big values. */
3480 397598 : if (lra_dump_file != NULL)
3481 0 : fprintf
3482 0 : (lra_dump_file,
3483 : " %d Spill vector pseudo: reject+=2\n",
3484 : nop);
3485 397598 : reject += 2;
3486 : }
3487 : }
3488 :
3489 : /* When we use an operand requiring memory in given
3490 : alternative, the insn should write *and* read the
3491 : value to/from memory it is costly in comparison with
3492 : an insn alternative which does not use memory
3493 : (e.g. register or immediate operand). We exclude
3494 : memory operand for such case as we can satisfy the
3495 : memory constraints by reloading address. */
3496 9569377 : if (no_regs_p && offmemok && !MEM_P (op))
3497 : {
3498 9569140 : if (lra_dump_file != NULL)
3499 27 : fprintf
3500 27 : (lra_dump_file,
3501 : " Using memory insn operand %d: reject+=3\n",
3502 : nop);
3503 9569140 : reject += 3;
3504 : }
3505 :
3506 : /* If reload requires moving value through secondary
3507 : memory, it will need one more insn at least. */
3508 178227166 : if (this_alternative != NO_REGS
3509 168657623 : && REG_P (op) && (cl = get_reg_class (REGNO (op))) != NO_REGS
3510 215265527 : && ((curr_static_id->operand[nop].type != OP_OUT
3511 20779757 : && targetm.secondary_memory_needed (mode, cl,
3512 : this_alternative))
3513 33770495 : || (curr_static_id->operand[nop].type != OP_IN
3514 16258774 : && (targetm.secondary_memory_needed
3515 16258774 : (mode, this_alternative, cl)))))
3516 : {
3517 11134061 : if (lra_dump_file != NULL)
3518 16 : fprintf
3519 16 : (lra_dump_file,
3520 : " %d Secondary memory reload needed: "
3521 : "losers++\n", nop);
3522 11134061 : losers++;
3523 : }
3524 :
3525 178227166 : if (MEM_P (op) && offmemok)
3526 72 : addr_losers++;
3527 : else
3528 : {
3529 : /* Input reloads can be inherited more often than
3530 : output reloads can be removed, so penalize output
3531 : reloads. */
3532 178227094 : if (!REG_P (op) || curr_static_id->operand[nop].type != OP_IN)
3533 : {
3534 150034412 : if (lra_dump_file != NULL)
3535 1722 : fprintf
3536 1722 : (lra_dump_file,
3537 : " %d Non input pseudo reload: reject++\n",
3538 : nop);
3539 150034412 : reject++;
3540 : }
3541 :
3542 178227094 : if (curr_static_id->operand[nop].type == OP_INOUT)
3543 : {
3544 268 : if (lra_dump_file != NULL)
3545 0 : fprintf
3546 0 : (lra_dump_file,
3547 : " %d Input/Output reload: reject+=%d\n",
3548 : nop, LRA_LOSER_COST_FACTOR);
3549 268 : reject += LRA_LOSER_COST_FACTOR;
3550 : }
3551 : }
3552 : }
3553 :
3554 475391309 : if (early_clobber_p && ! scratch_p)
3555 : {
3556 174346 : if (lra_dump_file != NULL)
3557 4 : fprintf (lra_dump_file,
3558 : " %d Early clobber: reject++\n", nop);
3559 174346 : reject++;
3560 : }
3561 : /* ??? We check early clobbers after processing all operands
3562 : (see loop below) and there we update the costs more.
3563 : Should we update the cost (may be approximately) here
3564 : because of early clobber register reloads or it is a rare
3565 : or non-important thing to be worth to do it. */
3566 950782618 : overall = (losers * LRA_LOSER_COST_FACTOR + reject
3567 475391309 : - (addr_losers == losers ? static_reject : 0));
3568 475391309 : if ((best_losers == 0 || losers != 0) && best_overall < overall)
3569 : {
3570 75852307 : if (lra_dump_file != NULL)
3571 1036 : fprintf (lra_dump_file,
3572 : " overall=%d,losers=%d -- refuse\n",
3573 : overall, losers);
3574 75852307 : goto fail;
3575 : }
3576 :
3577 399539002 : if (update_and_check_small_class_inputs (nop, nalt,
3578 : this_alternative))
3579 : {
3580 0 : if (lra_dump_file != NULL)
3581 0 : fprintf (lra_dump_file,
3582 : " not enough small class regs -- refuse\n");
3583 0 : goto fail;
3584 : }
3585 399539002 : curr_alt[nop] = this_alternative;
3586 399539002 : curr_alt_set[nop] = this_alternative_set;
3587 399539002 : curr_alt_exclude_start_hard_regs[nop]
3588 399539002 : = this_alternative_exclude_start_hard_regs;
3589 399539002 : curr_alt_win[nop] = this_alternative_win;
3590 399539002 : curr_alt_match_win[nop] = this_alternative_match_win;
3591 399539002 : curr_alt_offmemok[nop] = this_alternative_offmemok;
3592 399539002 : curr_alt_matches[nop] = this_alternative_matches;
3593 :
3594 399539002 : if (this_alternative_matches >= 0
3595 399539002 : && !did_match && !this_alternative_win)
3596 13524506 : curr_alt_win[this_alternative_matches] = false;
3597 :
3598 399539002 : if (early_clobber_p && operand_reg[nop] != NULL_RTX)
3599 178747 : early_clobbered_nops[early_clobbered_regs_num++] = nop;
3600 : }
3601 :
3602 136708099 : if (curr_insn_set != NULL_RTX
3603 : /* Allow just two operands or three operands where the third
3604 : is a clobber. */
3605 132748516 : && (n_operands == 2
3606 29234462 : || (n_operands == 3
3607 27028507 : && GET_CODE (PATTERN (curr_insn)) == PARALLEL
3608 22929298 : && XVECLEN (PATTERN (curr_insn), 0) == 2
3609 22870499 : && GET_CODE (XVECEXP (PATTERN (curr_insn), 0, 1))
3610 : == CLOBBER))
3611 : /* Prevent processing non-move insns. */
3612 126299839 : && (GET_CODE (SET_SRC (curr_insn_set)) == SUBREG
3613 124458813 : || SET_SRC (curr_insn_set) == no_subreg_reg_operand[1])
3614 229088012 : && ((! curr_alt_win[0] && ! curr_alt_win[1]
3615 5970421 : && REG_P (no_subreg_reg_operand[0])
3616 2900625 : && REG_P (no_subreg_reg_operand[1])
3617 1232237 : && (reg_in_class_p (no_subreg_reg_operand[0], curr_alt[1])
3618 1015992 : || reg_in_class_p (no_subreg_reg_operand[1], curr_alt[0])))
3619 91842912 : || (! curr_alt_win[0] && curr_alt_win[1]
3620 27465320 : && REG_P (no_subreg_reg_operand[1])
3621 : /* Check that we reload memory not the memory
3622 : address. */
3623 15709588 : && ! (curr_alt_offmemok[0]
3624 403516 : && MEM_P (no_subreg_reg_operand[0]))
3625 15709588 : && reg_in_class_p (no_subreg_reg_operand[1], curr_alt[0]))
3626 77550805 : || (curr_alt_win[0] && ! curr_alt_win[1]
3627 9656716 : && REG_P (no_subreg_reg_operand[0])
3628 : /* Check that we reload memory not the memory
3629 : address. */
3630 7168642 : && ! (curr_alt_offmemok[1]
3631 1098278 : && MEM_P (no_subreg_reg_operand[1]))
3632 7168640 : && reg_in_class_p (no_subreg_reg_operand[0], curr_alt[1])
3633 6286240 : && (! CONST_POOL_OK_P (curr_operand_mode[1],
3634 : no_subreg_reg_operand[1])
3635 2310789 : || (targetm.preferred_reload_class
3636 2310789 : (no_subreg_reg_operand[1],
3637 : (enum reg_class) curr_alt[1]) != NO_REGS))
3638 : /* If it is a result of recent elimination in move
3639 : insn we can transform it into an add still by
3640 : using this alternative. */
3641 6242973 : && GET_CODE (no_subreg_reg_operand[1]) != PLUS
3642 : /* Likewise if the source has been replaced with an
3643 : equivalent value. This only happens once -- the reload
3644 : will use the equivalent value instead of the register it
3645 : replaces -- so there should be no danger of cycling. */
3646 5713023 : && !equiv_substition_p[1])))
3647 : {
3648 : /* We have a move insn and a new reload insn will be similar
3649 : to the current insn. We should avoid such situation as
3650 : it results in LRA cycling. */
3651 20513635 : if (lra_dump_file != NULL)
3652 239 : fprintf (lra_dump_file,
3653 : " Cycle danger: overall += LRA_MAX_REJECT\n");
3654 20513635 : overall += LRA_MAX_REJECT;
3655 : }
3656 136708099 : if (all_this_alternative != NO_REGS
3657 116951734 : && !SMALL_REGISTER_CLASS_P (all_this_alternative)
3658 116074608 : && all_used_nregs != 0 && all_reload_nregs != 0
3659 136708099 : && (all_used_nregs + all_reload_nregs + 1
3660 4114438 : >= ira_class_hard_regs_num[all_this_alternative]))
3661 : {
3662 366 : if (lra_dump_file != NULL)
3663 0 : fprintf
3664 0 : (lra_dump_file,
3665 : " Register starvation: overall += LRA_MAX_REJECT"
3666 : "(class=%s,avail=%d,used=%d,reload=%d)\n",
3667 : reg_class_names[all_this_alternative],
3668 : ira_class_hard_regs_num[all_this_alternative],
3669 : all_used_nregs, all_reload_nregs);
3670 366 : overall += LRA_MAX_REJECT;
3671 366 : if (!prefer_memory_p && INSN_CODE (curr_insn) < 0)
3672 : {
3673 : /* asm can permit memory and reg and can be not enough regs for
3674 : asm -- try now memory: */
3675 102 : prefer_memory_p = true;
3676 102 : if (lra_dump_file != NULL)
3677 0 : fprintf
3678 0 : (lra_dump_file,
3679 : " Trying now memory for operands\n");
3680 102 : goto repeat;
3681 : }
3682 : }
3683 136883073 : ok_p = true;
3684 : curr_alt_dont_inherit_ops_num = 0;
3685 136883073 : for (nop = 0; nop < early_clobbered_regs_num; nop++)
3686 : {
3687 175077 : int i, j, clobbered_hard_regno, first_conflict_j, last_conflict_j;
3688 175077 : HARD_REG_SET temp_set;
3689 :
3690 175077 : i = early_clobbered_nops[nop];
3691 175077 : if ((! curr_alt_win[i] && ! curr_alt_match_win[i])
3692 130181 : || hard_regno[i] < 0)
3693 174404 : continue;
3694 128330 : lra_assert (operand_reg[i] != NULL_RTX);
3695 : clobbered_hard_regno = hard_regno[i];
3696 128330 : CLEAR_HARD_REG_SET (temp_set);
3697 128330 : add_to_hard_reg_set (&temp_set, GET_MODE (*curr_id->operand_loc[i]),
3698 : clobbered_hard_regno);
3699 128330 : first_conflict_j = last_conflict_j = -1;
3700 648088 : for (j = 0; j < n_operands; j++)
3701 519759 : if (j == i
3702 : /* We don't want process insides of match_operator and
3703 : match_parallel because otherwise we would process
3704 : their operands once again generating a wrong
3705 : code. */
3706 391429 : || curr_static_id->operand[j].is_operator)
3707 130474 : continue;
3708 389285 : else if ((curr_alt_matches[j] == i && curr_alt_match_win[j])
3709 371194 : || (curr_alt_matches[i] == j && curr_alt_match_win[i]))
3710 18091 : continue;
3711 : /* If we don't reload j-th operand, check conflicts. */
3712 140088 : else if ((curr_alt_win[j] || curr_alt_match_win[j])
3713 427816 : && uses_hard_regs_p (*curr_id->operand_loc[j], temp_set))
3714 : {
3715 1147 : if (first_conflict_j < 0)
3716 673 : first_conflict_j = j;
3717 1147 : last_conflict_j = j;
3718 : /* Both the earlyclobber operand and conflicting operand
3719 : cannot both be user defined hard registers for asm.
3720 : Let curr_insn_transform diagnose it. */
3721 1147 : if (HARD_REGISTER_P (operand_reg[i])
3722 1 : && REG_USERVAR_P (operand_reg[i])
3723 1 : && operand_reg[j] != NULL_RTX
3724 1 : && HARD_REGISTER_P (operand_reg[j])
3725 1 : && REG_USERVAR_P (operand_reg[j])
3726 1148 : && INSN_CODE (curr_insn) < 0)
3727 1 : return false;
3728 : }
3729 128329 : if (last_conflict_j < 0)
3730 127657 : continue;
3731 :
3732 : /* If an earlyclobber operand conflicts with another non-matching
3733 : operand (ie, they have been assigned the same hard register),
3734 : then it is better to reload the other operand, as there may
3735 : exist yet another operand with a matching constraint associated
3736 : with the earlyclobber operand. However, if one of the operands
3737 : is an explicit use of a hard register, then we must reload the
3738 : other non-hard register operand. */
3739 672 : if (HARD_REGISTER_P (operand_reg[i])
3740 672 : || (first_conflict_j == last_conflict_j
3741 198 : && operand_reg[last_conflict_j] != NULL_RTX
3742 57 : && !curr_alt_match_win[last_conflict_j]
3743 57 : && !HARD_REGISTER_P (operand_reg[last_conflict_j])))
3744 : {
3745 57 : curr_alt_win[last_conflict_j] = false;
3746 57 : curr_alt_dont_inherit_ops[curr_alt_dont_inherit_ops_num++]
3747 57 : = last_conflict_j;
3748 57 : losers++;
3749 57 : if (lra_dump_file != NULL)
3750 0 : fprintf
3751 0 : (lra_dump_file,
3752 : " %d Conflict early clobber reload: losers++\n",
3753 : i);
3754 : }
3755 : else
3756 : {
3757 : /* We need to reload early clobbered register and the
3758 : matched registers. */
3759 3069 : for (j = 0; j < n_operands; j++)
3760 2454 : if (curr_alt_matches[j] == i)
3761 : {
3762 2 : curr_alt_match_win[j] = false;
3763 2 : losers++;
3764 2 : if (lra_dump_file != NULL)
3765 0 : fprintf
3766 0 : (lra_dump_file,
3767 : " %d Matching conflict early clobber "
3768 : "reloads: losers++\n",
3769 : j);
3770 2 : overall += LRA_LOSER_COST_FACTOR;
3771 : }
3772 615 : if (! curr_alt_match_win[i])
3773 615 : curr_alt_dont_inherit_ops[curr_alt_dont_inherit_ops_num++] = i;
3774 : else
3775 : {
3776 : /* Remember pseudos used for match reloads are never
3777 : inherited. */
3778 0 : lra_assert (curr_alt_matches[i] >= 0);
3779 0 : curr_alt_win[curr_alt_matches[i]] = false;
3780 : }
3781 615 : curr_alt_win[i] = curr_alt_match_win[i] = false;
3782 615 : losers++;
3783 615 : if (lra_dump_file != NULL)
3784 0 : fprintf
3785 0 : (lra_dump_file,
3786 : " %d Matched conflict early clobber reloads: "
3787 : "losers++\n",
3788 : i);
3789 : }
3790 : /* Early clobber was already reflected in REJECT. */
3791 672 : if (!matching_early_clobber[i])
3792 : {
3793 672 : lra_assert (reject > 0);
3794 672 : reject--;
3795 672 : matching_early_clobber[i] = 1;
3796 : }
3797 672 : overall += LRA_LOSER_COST_FACTOR - 1;
3798 : }
3799 136707996 : if (lra_dump_file != NULL)
3800 1761 : fprintf (lra_dump_file, " overall=%d,losers=%d,rld_nregs=%d\n",
3801 : overall, losers, reload_nregs);
3802 :
3803 : /* If this alternative can be made to work by reloading, and it
3804 : needs less reloading than the others checked so far, record
3805 : it as the chosen goal for reloading. */
3806 136707996 : if ((best_losers != 0 && losers == 0)
3807 60523970 : || (((best_losers == 0 && losers == 0)
3808 59529602 : || (best_losers != 0 && losers != 0))
3809 60523970 : && (best_overall > overall
3810 15576313 : || (best_overall == overall
3811 : /* If the cost of the reloads is the same,
3812 : prefer alternative which requires minimal
3813 : number of reload regs. */
3814 11646853 : && (reload_nregs < best_reload_nregs
3815 11544301 : || (reload_nregs == best_reload_nregs
3816 11502377 : && (best_reload_sum < reload_sum
3817 11481115 : || (best_reload_sum == reload_sum
3818 11457381 : && nalt < goal_alt_number))))))))
3819 : {
3820 394638390 : for (nop = 0; nop < n_operands; nop++)
3821 : {
3822 273140550 : goal_alt_win[nop] = curr_alt_win[nop];
3823 273140550 : goal_alt_match_win[nop] = curr_alt_match_win[nop];
3824 273140550 : goal_alt_matches[nop] = curr_alt_matches[nop];
3825 273140550 : goal_alt[nop] = curr_alt[nop];
3826 273140550 : goal_alt_exclude_start_hard_regs[nop]
3827 273140550 : = curr_alt_exclude_start_hard_regs[nop];
3828 273140550 : goal_alt_offmemok[nop] = curr_alt_offmemok[nop];
3829 : }
3830 121497840 : goal_alt_dont_inherit_ops_num = curr_alt_dont_inherit_ops_num;
3831 121497840 : goal_reuse_alt_p = curr_reuse_alt_p;
3832 121498502 : for (nop = 0; nop < curr_alt_dont_inherit_ops_num; nop++)
3833 662 : goal_alt_dont_inherit_ops[nop] = curr_alt_dont_inherit_ops[nop];
3834 121497840 : goal_alt_swapped = curr_swapped;
3835 121497840 : goal_alt_out_sp_reload_p = curr_alt_out_sp_reload_p;
3836 121497840 : best_overall = overall;
3837 121497840 : best_losers = losers;
3838 121497840 : best_reload_nregs = reload_nregs;
3839 121497840 : best_reload_sum = reload_sum;
3840 121497840 : goal_alt_number = nalt;
3841 : }
3842 136707996 : if (losers == 0 && !curr_alt_class_change_p)
3843 : /* Everything is satisfied. Do not process alternatives
3844 : anymore. */
3845 : break;
3846 59541874 : fail:
3847 183981477 : ;
3848 : }
3849 : return ok_p;
3850 : }
3851 :
3852 : /* Make reload base reg from address AD. */
3853 : static rtx
3854 0 : base_to_reg (struct address_info *ad)
3855 : {
3856 0 : enum reg_class cl;
3857 0 : int code = -1;
3858 0 : rtx new_inner = NULL_RTX;
3859 0 : rtx new_reg = NULL_RTX;
3860 0 : rtx_insn *insn;
3861 0 : rtx_insn *last_insn = get_last_insn();
3862 :
3863 0 : lra_assert (ad->disp == ad->disp_term);
3864 0 : cl = base_reg_class (ad->mode, ad->as, ad->base_outer_code,
3865 : get_index_code (ad));
3866 0 : new_reg = lra_create_new_reg (GET_MODE (*ad->base), NULL_RTX, cl, NULL,
3867 : "base");
3868 0 : new_inner = simplify_gen_binary (PLUS, GET_MODE (new_reg), new_reg,
3869 0 : ad->disp_term == NULL
3870 : ? const0_rtx
3871 : : *ad->disp_term);
3872 0 : if (!valid_address_p (ad->mode, new_inner, ad->as))
3873 : return NULL_RTX;
3874 0 : insn = emit_insn (gen_rtx_SET (new_reg, *ad->base));
3875 0 : code = recog_memoized (insn);
3876 0 : if (code < 0)
3877 : {
3878 0 : delete_insns_since (last_insn);
3879 0 : return NULL_RTX;
3880 : }
3881 :
3882 : return new_inner;
3883 : }
3884 :
3885 : /* Make reload base reg + DISP from address AD. Return the new pseudo. */
3886 : static rtx
3887 47 : base_plus_disp_to_reg (struct address_info *ad, rtx disp)
3888 : {
3889 47 : enum reg_class cl;
3890 47 : rtx new_reg;
3891 :
3892 47 : lra_assert (ad->base == ad->base_term);
3893 47 : cl = base_reg_class (ad->mode, ad->as, ad->base_outer_code,
3894 : get_index_code (ad));
3895 47 : new_reg = lra_create_new_reg (GET_MODE (*ad->base_term), NULL_RTX, cl, NULL,
3896 : "base + disp");
3897 47 : lra_emit_add (new_reg, *ad->base_term, disp);
3898 47 : return new_reg;
3899 : }
3900 :
3901 : /* Make reload of index part of address AD. Return the new
3902 : pseudo. */
3903 : static rtx
3904 0 : index_part_to_reg (struct address_info *ad, enum reg_class index_class)
3905 : {
3906 0 : rtx new_reg;
3907 :
3908 0 : new_reg = lra_create_new_reg (GET_MODE (*ad->index), NULL_RTX,
3909 : index_class, NULL, "index term");
3910 0 : expand_mult (GET_MODE (*ad->index), *ad->index_term,
3911 : GEN_INT (get_index_scale (ad)), new_reg, 1);
3912 0 : return new_reg;
3913 : }
3914 :
3915 : /* Return true if we can add a displacement to address AD, even if that
3916 : makes the address invalid. The fix-up code requires any new address
3917 : to be the sum of the BASE_TERM, INDEX and DISP_TERM fields. */
3918 : static bool
3919 19945 : can_add_disp_p (struct address_info *ad)
3920 : {
3921 19945 : return (!ad->autoinc_p
3922 19945 : && ad->segment == NULL
3923 19945 : && ad->base == ad->base_term
3924 39890 : && ad->disp == ad->disp_term);
3925 : }
3926 :
3927 : /* Make equiv substitution in address AD. Return true if a substitution
3928 : was made. */
3929 : static bool
3930 39905096 : equiv_address_substitution (struct address_info *ad)
3931 : {
3932 39905096 : rtx base_reg, new_base_reg, index_reg, new_index_reg, *base_term, *index_term;
3933 39905096 : poly_int64 disp;
3934 39905096 : HOST_WIDE_INT scale;
3935 39905096 : bool change_p;
3936 :
3937 39905096 : base_term = strip_subreg (ad->base_term);
3938 9101 : if (base_term == NULL)
3939 : base_reg = new_base_reg = NULL_RTX;
3940 : else
3941 : {
3942 33699410 : base_reg = *base_term;
3943 33699410 : new_base_reg = get_equiv_with_elimination (base_reg, curr_insn);
3944 : }
3945 39905096 : index_term = strip_subreg (ad->index_term);
3946 5483 : if (index_term == NULL)
3947 : index_reg = new_index_reg = NULL_RTX;
3948 : else
3949 : {
3950 1813601 : index_reg = *index_term;
3951 1813601 : new_index_reg = get_equiv_with_elimination (index_reg, curr_insn);
3952 : }
3953 39905096 : if (base_reg == new_base_reg && index_reg == new_index_reg)
3954 : return false;
3955 141762 : disp = 0;
3956 141762 : change_p = false;
3957 141762 : if (lra_dump_file != NULL)
3958 : {
3959 0 : fprintf (lra_dump_file, "Changing address in insn %d ",
3960 0 : INSN_UID (curr_insn));
3961 0 : dump_value_slim (lra_dump_file, *ad->outer, 1);
3962 : }
3963 141762 : if (base_reg != new_base_reg)
3964 : {
3965 141312 : poly_int64 offset;
3966 141312 : if (REG_P (new_base_reg))
3967 : {
3968 8369 : *base_term = new_base_reg;
3969 8369 : change_p = true;
3970 : }
3971 132943 : else if (GET_CODE (new_base_reg) == PLUS
3972 19944 : && REG_P (XEXP (new_base_reg, 0))
3973 19944 : && poly_int_rtx_p (XEXP (new_base_reg, 1), &offset)
3974 152887 : && can_add_disp_p (ad))
3975 : {
3976 : disp += offset;
3977 19944 : *base_term = XEXP (new_base_reg, 0);
3978 19944 : change_p = true;
3979 : }
3980 141312 : if (ad->base_term2 != NULL)
3981 0 : *ad->base_term2 = *ad->base_term;
3982 : }
3983 141762 : if (index_reg != new_index_reg)
3984 : {
3985 655 : poly_int64 offset;
3986 655 : if (REG_P (new_index_reg))
3987 : {
3988 0 : *index_term = new_index_reg;
3989 0 : change_p = true;
3990 : }
3991 655 : else if (GET_CODE (new_index_reg) == PLUS
3992 1 : && REG_P (XEXP (new_index_reg, 0))
3993 1 : && poly_int_rtx_p (XEXP (new_index_reg, 1), &offset)
3994 1 : && can_add_disp_p (ad)
3995 656 : && (scale = get_index_scale (ad)))
3996 : {
3997 1 : disp += offset * scale;
3998 1 : *index_term = XEXP (new_index_reg, 0);
3999 1 : change_p = true;
4000 : }
4001 : }
4002 141762 : if (maybe_ne (disp, 0))
4003 : {
4004 19945 : if (ad->disp != NULL)
4005 6742 : *ad->disp = plus_constant (GET_MODE (*ad->inner), *ad->disp, disp);
4006 : else
4007 : {
4008 13203 : *ad->inner = plus_constant (GET_MODE (*ad->inner), *ad->inner, disp);
4009 13203 : update_address (ad);
4010 : }
4011 : change_p = true;
4012 : }
4013 141762 : if (lra_dump_file != NULL)
4014 : {
4015 0 : if (! change_p)
4016 0 : fprintf (lra_dump_file, " -- no change\n");
4017 : else
4018 : {
4019 0 : fprintf (lra_dump_file, " on equiv ");
4020 0 : dump_value_slim (lra_dump_file, *ad->outer, 1);
4021 0 : fprintf (lra_dump_file, "\n");
4022 : }
4023 : }
4024 : return change_p;
4025 : }
4026 :
4027 : /* Skip all modifiers and whitespaces in constraint STR and return the
4028 : result. */
4029 : static const char *
4030 520308230 : skip_constraint_modifiers (const char *str)
4031 : {
4032 732315772 : for (;;str++)
4033 626312001 : switch (*str)
4034 : {
4035 106003771 : case '+': case '&' : case '=': case '*': case ' ': case '\t':
4036 106003771 : case '$': case '^' : case '%': case '?': case '!':
4037 106003771 : break;
4038 520308230 : default: return str;
4039 : }
4040 : }
4041 :
4042 : /* Takes a string of 0 or more comma-separated constraints. When more
4043 : than one constraint is present, evaluate whether they all correspond
4044 : to a single, repeated constraint (e.g. "r,r") or whether we have
4045 : more than one distinct constraints (e.g. "r,m"). */
4046 : static bool
4047 165021678 : constraint_unique (const char *cstr)
4048 : {
4049 165021678 : enum constraint_num ca, cb;
4050 165021678 : ca = CONSTRAINT__UNKNOWN;
4051 327437360 : for (;;)
4052 : {
4053 327437360 : cstr = skip_constraint_modifiers (cstr);
4054 327437360 : if (*cstr == '\0' || *cstr == ',')
4055 : cb = CONSTRAINT_X;
4056 : else
4057 : {
4058 327437360 : cb = lookup_constraint (cstr);
4059 327437360 : if (cb == CONSTRAINT__UNKNOWN)
4060 : return false;
4061 315253443 : cstr += CONSTRAINT_LEN (cstr[0], cstr);
4062 : }
4063 : /* Handle the first iteration of the loop. */
4064 315253443 : if (ca == CONSTRAINT__UNKNOWN)
4065 : ca = cb;
4066 : /* Handle the general case of comparing ca with subsequent
4067 : constraints. */
4068 162276422 : else if (ca != cb)
4069 : return false;
4070 170062446 : if (*cstr == '\0')
4071 : return true;
4072 162415682 : if (*cstr == ',')
4073 89824217 : cstr += 1;
4074 : }
4075 : }
4076 :
4077 : /* Major function to make reloads for an address in operand NOP or
4078 : check its correctness (If CHECK_ONLY_P is true). The supported
4079 : cases are:
4080 :
4081 : 1) an address that existed before LRA started, at which point it
4082 : must have been valid. These addresses are subject to elimination
4083 : and may have become invalid due to the elimination offset being out
4084 : of range.
4085 :
4086 : 2) an address created by forcing a constant to memory
4087 : (force_const_to_mem). The initial form of these addresses might
4088 : not be valid, and it is this function's job to make them valid.
4089 :
4090 : 3) a frame address formed from a register and a (possibly zero)
4091 : constant offset. As above, these addresses might not be valid and
4092 : this function must make them so.
4093 :
4094 : Add reloads to the lists *BEFORE and *AFTER. We might need to add
4095 : reloads to *AFTER because of inc/dec, {pre, post} modify in the
4096 : address. Return true for any RTL change.
4097 :
4098 : The function is a helper function which does not produce all
4099 : transformations (when CHECK_ONLY_P is false) which can be
4100 : necessary. It does just basic steps. To do all necessary
4101 : transformations use function process_address. */
4102 : static bool
4103 178950150 : process_address_1 (int nop, bool check_only_p,
4104 : rtx_insn **before, rtx_insn **after)
4105 : {
4106 178950150 : struct address_info ad;
4107 178950150 : rtx new_reg;
4108 178950150 : HOST_WIDE_INT scale;
4109 178950150 : rtx op = *curr_id->operand_loc[nop];
4110 178950150 : rtx mem = extract_mem_from_operand (op);
4111 178950150 : const char *constraint;
4112 178950150 : enum constraint_num cn;
4113 178950150 : bool change_p = false;
4114 :
4115 178950150 : if (MEM_P (mem)
4116 38086022 : && GET_MODE (mem) == BLKmode
4117 26356 : && GET_CODE (XEXP (mem, 0)) == SCRATCH)
4118 : return false;
4119 :
4120 178950150 : constraint
4121 178950150 : = skip_constraint_modifiers (curr_static_id->operand[nop].constraint);
4122 178950150 : if (IN_RANGE (constraint[0], '0', '9'))
4123 : {
4124 13920720 : char *end;
4125 13920720 : unsigned long dup = strtoul (constraint, &end, 10);
4126 13920720 : constraint
4127 13920720 : = skip_constraint_modifiers (curr_static_id->operand[dup].constraint);
4128 : }
4129 191052403 : cn = lookup_constraint (*constraint == '\0' ? "X" : constraint);
4130 : /* If we have several alternatives or/and several constraints in an
4131 : alternative and we can not say at this stage what constraint will be used,
4132 : use unknown constraint. The exception is an address constraint. If
4133 : operand has one address constraint, probably all others constraints are
4134 : address ones. */
4135 166847897 : if (constraint[0] != '\0' && get_constraint_type (cn) != CT_ADDRESS
4136 343971828 : && !constraint_unique (constraint))
4137 : cn = CONSTRAINT__UNKNOWN;
4138 21575236 : if (insn_extra_address_constraint (cn)
4139 : /* When we find an asm operand with an address constraint that
4140 : doesn't satisfy address_operand to begin with, we clear
4141 : is_address, so that we don't try to make a non-address fit.
4142 : If the asm statement got this far, it's because other
4143 : constraints are available, and we'll use them, disregarding
4144 : the unsatisfiable address ones. */
4145 21575236 : && curr_static_id->operand[nop].is_address)
4146 1826200 : decompose_lea_address (&ad, curr_id->operand_loc[nop]);
4147 : /* Do not attempt to decompose arbitrary addresses generated by combine
4148 : for asm operands with loose constraints, e.g 'X'.
4149 : Need to extract memory from op for special memory constraint,
4150 : i.e. bcst_mem_operand in i386 backend. */
4151 177123950 : else if (MEM_P (mem)
4152 177124109 : && !(INSN_CODE (curr_insn) < 0
4153 22457 : && get_constraint_type (cn) == CT_FIXED_FORM
4154 159 : && constraint_satisfied_p (op, cn)))
4155 38085863 : decompose_mem_address (&ad, mem);
4156 139038087 : else if (GET_CODE (op) == SUBREG
4157 3730853 : && MEM_P (SUBREG_REG (op)))
4158 0 : decompose_mem_address (&ad, SUBREG_REG (op));
4159 : else
4160 : return false;
4161 : /* If INDEX_REG_CLASS is assigned to base_term already and isn't to
4162 : index_term, swap them so to avoid assigning INDEX_REG_CLASS to both
4163 : when INDEX_REG_CLASS is a single register class. */
4164 39912063 : enum reg_class index_cl = index_reg_class (curr_insn);
4165 39912063 : if (ad.base_term != NULL
4166 33706320 : && ad.index_term != NULL
4167 1446220 : && ira_class_hard_regs_num[index_cl] == 1
4168 0 : && REG_P (*ad.base_term)
4169 0 : && REG_P (*ad.index_term)
4170 0 : && in_class_p (*ad.base_term, index_cl, NULL)
4171 39912063 : && ! in_class_p (*ad.index_term, index_cl, NULL))
4172 : {
4173 0 : std::swap (ad.base, ad.index);
4174 0 : std::swap (ad.base_term, ad.index_term);
4175 : }
4176 39912063 : if (! check_only_p)
4177 39905096 : change_p = equiv_address_substitution (&ad);
4178 39912063 : if (ad.base_term != NULL
4179 73618383 : && (process_addr_reg
4180 67412640 : (ad.base_term, check_only_p, before,
4181 33706320 : (ad.autoinc_p
4182 4186258 : && !(REG_P (*ad.base_term)
4183 2093129 : && find_regno_note (curr_insn, REG_DEAD,
4184 : REGNO (*ad.base_term)) != NULL_RTX)
4185 : ? after : NULL),
4186 33706320 : base_reg_class (ad.mode, ad.as, ad.base_outer_code,
4187 : get_index_code (&ad), curr_insn))))
4188 : {
4189 436953 : change_p = true;
4190 436953 : if (ad.base_term2 != NULL)
4191 0 : *ad.base_term2 = *ad.base_term;
4192 : }
4193 39912063 : if (ad.index_term != NULL
4194 39912063 : && process_addr_reg (ad.index_term, check_only_p,
4195 : before, NULL, index_cl))
4196 : change_p = true;
4197 :
4198 : /* Target hooks sometimes don't treat extra-constraint addresses as
4199 : legitimate address_operands, so handle them specially. */
4200 39912063 : if (insn_extra_address_constraint (cn)
4201 39912063 : && satisfies_address_constraint_p (&ad, cn))
4202 : return change_p;
4203 :
4204 38085870 : if (check_only_p)
4205 : return change_p;
4206 :
4207 : /* There are three cases where the shape of *AD.INNER may now be invalid:
4208 :
4209 : 1) the original address was valid, but either elimination or
4210 : equiv_address_substitution was applied and that made
4211 : the address invalid.
4212 :
4213 : 2) the address is an invalid symbolic address created by
4214 : force_const_to_mem.
4215 :
4216 : 3) the address is a frame address with an invalid offset.
4217 :
4218 : 4) the address is a frame address with an invalid base.
4219 :
4220 : All these cases involve a non-autoinc address, so there is no
4221 : point revalidating other types. */
4222 38079571 : if (ad.autoinc_p || valid_address_p (op, &ad, cn))
4223 38079141 : return change_p;
4224 :
4225 : /* Any index existed before LRA started, so we can assume that the
4226 : presence and shape of the index is valid. */
4227 430 : push_to_sequence (*before);
4228 430 : lra_assert (ad.disp == ad.disp_term);
4229 430 : if (ad.base == NULL)
4230 : {
4231 330 : if (ad.index == NULL)
4232 : {
4233 330 : rtx_insn *insn;
4234 330 : rtx_insn *last = get_last_insn ();
4235 330 : int code = -1;
4236 330 : enum reg_class cl = base_reg_class (ad.mode, ad.as,
4237 : SCRATCH, SCRATCH,
4238 : curr_insn);
4239 330 : rtx addr = *ad.inner;
4240 :
4241 651 : new_reg = lra_create_new_reg (Pmode, NULL_RTX, cl, NULL, "addr");
4242 330 : if (HAVE_lo_sum)
4243 : {
4244 : /* addr => lo_sum (new_base, addr), case (2) above. */
4245 : insn = emit_insn (gen_rtx_SET
4246 : (new_reg,
4247 : gen_rtx_HIGH (Pmode, copy_rtx (addr))));
4248 : code = recog_memoized (insn);
4249 : if (code >= 0)
4250 : {
4251 : *ad.inner = gen_rtx_LO_SUM (Pmode, new_reg, addr);
4252 : if (!valid_address_p (op, &ad, cn))
4253 : {
4254 : /* Try to put lo_sum into register. */
4255 : insn = emit_insn (gen_rtx_SET
4256 : (new_reg,
4257 : gen_rtx_LO_SUM (Pmode, new_reg, addr)));
4258 : code = recog_memoized (insn);
4259 : if (code >= 0)
4260 : {
4261 : *ad.inner = new_reg;
4262 : if (!valid_address_p (op, &ad, cn))
4263 : {
4264 : *ad.inner = addr;
4265 : code = -1;
4266 : }
4267 : }
4268 :
4269 : }
4270 : }
4271 : if (code < 0)
4272 : delete_insns_since (last);
4273 : }
4274 :
4275 330 : if (code < 0)
4276 : {
4277 : /* addr => new_base, case (2) above. */
4278 330 : lra_emit_move (new_reg, addr);
4279 :
4280 660 : for (insn = last == NULL_RTX ? get_insns () : NEXT_INSN (last);
4281 660 : insn != NULL_RTX;
4282 330 : insn = NEXT_INSN (insn))
4283 330 : if (recog_memoized (insn) < 0)
4284 : break;
4285 330 : if (insn != NULL_RTX)
4286 : {
4287 : /* Do nothing if we cannot generate right insns.
4288 : This is analogous to reload pass behavior. */
4289 0 : delete_insns_since (last);
4290 0 : end_sequence ();
4291 0 : return false;
4292 : }
4293 330 : *ad.inner = new_reg;
4294 : }
4295 : }
4296 : else
4297 : {
4298 : /* index * scale + disp => new base + index * scale,
4299 : case (1) above. */
4300 0 : enum reg_class cl = base_reg_class (ad.mode, ad.as, PLUS,
4301 0 : GET_CODE (*ad.index),
4302 : curr_insn);
4303 :
4304 0 : lra_assert (index_cl != NO_REGS);
4305 0 : new_reg = lra_create_new_reg (Pmode, NULL_RTX, cl, NULL, "disp");
4306 0 : lra_emit_move (new_reg, *ad.disp);
4307 0 : *ad.inner = simplify_gen_binary (PLUS, GET_MODE (new_reg),
4308 0 : new_reg, *ad.index);
4309 : }
4310 : }
4311 100 : else if (ad.index == NULL)
4312 : {
4313 53 : int regno;
4314 53 : enum reg_class cl;
4315 53 : rtx set;
4316 53 : rtx_insn *insns, *last_insn;
4317 :
4318 53 : cl = base_reg_class (ad.mode, ad.as, ad.base_outer_code,
4319 : get_index_code (&ad), curr_insn);
4320 :
4321 53 : if (REG_P (*ad.base_term)
4322 53 : && ira_class_subset_p[get_reg_class (REGNO (*ad.base_term))][cl])
4323 : /* It seems base reg is already in the base reg class and changing it
4324 : does not make a progress. So reload the whole inner address. */
4325 53 : goto reload_inner_addr;
4326 :
4327 : /* Try to reload base into register only if the base is invalid
4328 : for the address but with valid offset, case (4) above. */
4329 0 : start_sequence ();
4330 0 : new_reg = base_to_reg (&ad);
4331 :
4332 : /* base + disp => new base, cases (1) and (3) above. */
4333 : /* Another option would be to reload the displacement into an
4334 : index register. However, postreload has code to optimize
4335 : address reloads that have the same base and different
4336 : displacements, so reloading into an index register would
4337 : not necessarily be a win. */
4338 0 : if (new_reg == NULL_RTX)
4339 : {
4340 : /* See if the target can split the displacement into a
4341 : legitimate new displacement from a local anchor. */
4342 0 : gcc_assert (ad.disp == ad.disp_term);
4343 0 : poly_int64 orig_offset;
4344 0 : rtx offset1, offset2;
4345 0 : if (poly_int_rtx_p (*ad.disp, &orig_offset)
4346 0 : && targetm.legitimize_address_displacement (&offset1, &offset2,
4347 : orig_offset,
4348 : ad.mode))
4349 : {
4350 0 : new_reg = base_plus_disp_to_reg (&ad, offset1);
4351 0 : new_reg = gen_rtx_PLUS (GET_MODE (new_reg), new_reg, offset2);
4352 : }
4353 : else
4354 0 : new_reg = base_plus_disp_to_reg (&ad, *ad.disp);
4355 : }
4356 0 : insns = get_insns ();
4357 0 : last_insn = get_last_insn ();
4358 : /* If we generated at least two insns, try last insn source as
4359 : an address. If we succeed, we generate one less insn. */
4360 0 : if (REG_P (new_reg)
4361 0 : && last_insn != insns
4362 0 : && (set = single_set (last_insn)) != NULL_RTX
4363 0 : && GET_CODE (SET_SRC (set)) == PLUS
4364 0 : && REG_P (XEXP (SET_SRC (set), 0))
4365 0 : && CONSTANT_P (XEXP (SET_SRC (set), 1)))
4366 : {
4367 0 : *ad.inner = SET_SRC (set);
4368 0 : if (valid_address_p (op, &ad, cn))
4369 : {
4370 0 : *ad.base_term = XEXP (SET_SRC (set), 0);
4371 0 : *ad.disp_term = XEXP (SET_SRC (set), 1);
4372 0 : regno = REGNO (*ad.base_term);
4373 0 : if (regno >= FIRST_PSEUDO_REGISTER
4374 0 : && cl != lra_get_allocno_class (regno))
4375 0 : lra_change_class (regno, cl, " Change to", true);
4376 0 : new_reg = SET_SRC (set);
4377 0 : delete_insns_since (PREV_INSN (last_insn));
4378 : }
4379 : }
4380 0 : end_sequence ();
4381 0 : emit_insn (insns);
4382 0 : *ad.inner = new_reg;
4383 : }
4384 47 : else if (ad.disp_term != NULL)
4385 : {
4386 : /* base + scale * index + disp => new base + scale * index,
4387 : case (1) above. */
4388 47 : gcc_assert (ad.disp == ad.disp_term);
4389 47 : new_reg = base_plus_disp_to_reg (&ad, *ad.disp);
4390 47 : *ad.inner = simplify_gen_binary (PLUS, GET_MODE (new_reg),
4391 47 : new_reg, *ad.index);
4392 : }
4393 0 : else if ((scale = get_index_scale (&ad)) == 1)
4394 : {
4395 : /* The last transformation to one reg will be made in
4396 : curr_insn_transform function. */
4397 0 : end_sequence ();
4398 0 : return false;
4399 : }
4400 0 : else if (scale != 0)
4401 : {
4402 : /* base + scale * index => base + new_reg,
4403 : case (1) above.
4404 : Index part of address may become invalid. For example, we
4405 : changed pseudo on the equivalent memory and a subreg of the
4406 : pseudo onto the memory of different mode for which the scale is
4407 : prohibited. */
4408 0 : new_reg = index_part_to_reg (&ad, index_cl);
4409 0 : *ad.inner = simplify_gen_binary (PLUS, GET_MODE (new_reg),
4410 0 : *ad.base_term, new_reg);
4411 : }
4412 : else
4413 : {
4414 53 : enum reg_class cl;
4415 53 : rtx addr;
4416 0 : reload_inner_addr:
4417 53 : cl = base_reg_class (ad.mode, ad.as, SCRATCH, SCRATCH, curr_insn);
4418 53 : addr = *ad.inner;
4419 53 : new_reg = lra_create_new_reg (Pmode, NULL_RTX, cl, NULL, "addr");
4420 : /* addr => new_base. */
4421 53 : lra_emit_move (new_reg, addr);
4422 53 : *ad.inner = new_reg;
4423 : }
4424 430 : *before = end_sequence ();
4425 430 : return true;
4426 : }
4427 :
4428 : /* If CHECK_ONLY_P is false, do address reloads until it is necessary.
4429 : Use process_address_1 as a helper function. Return true for any
4430 : RTL changes.
4431 :
4432 : If CHECK_ONLY_P is true, just check address correctness. Return
4433 : false if the address correct. */
4434 : static bool
4435 178459918 : process_address (int nop, bool check_only_p,
4436 : rtx_insn **before, rtx_insn **after)
4437 : {
4438 178459918 : bool res = false;
4439 : /* Use enough iterations to process all address parts: */
4440 178950150 : for (int i = 0; i < 10; i++)
4441 : {
4442 178950150 : if (!process_address_1 (nop, check_only_p, before, after))
4443 : {
4444 : return res;
4445 : }
4446 : else
4447 : {
4448 490232 : if (check_only_p)
4449 : return true;
4450 490232 : res = true;
4451 : }
4452 : }
4453 0 : fatal_insn ("unable to reload address in ", curr_insn);
4454 : }
4455 :
4456 : /* Override the generic address_reload_context in order to
4457 : control the creation of reload pseudos. */
4458 : class lra_autoinc_reload_context : public address_reload_context
4459 : {
4460 : machine_mode mode;
4461 : enum reg_class rclass;
4462 :
4463 : public:
4464 0 : lra_autoinc_reload_context (machine_mode mode, enum reg_class new_rclass)
4465 0 : : mode (mode), rclass (new_rclass) {}
4466 :
4467 0 : rtx get_reload_reg () const override final
4468 : {
4469 0 : return lra_create_new_reg (mode, NULL_RTX, rclass, NULL, "INC/DEC result");
4470 : }
4471 : };
4472 :
4473 : /* Emit insns to reload VALUE into a new register. VALUE is an
4474 : auto-increment or auto-decrement RTX whose operand is a register or
4475 : memory location; so reloading involves incrementing that location.
4476 :
4477 : INC_AMOUNT is the number to increment or decrement by (always
4478 : positive and ignored for POST_MODIFY/PRE_MODIFY).
4479 :
4480 : Return a pseudo containing the result. */
4481 : static rtx
4482 0 : emit_inc (enum reg_class new_rclass, rtx value, poly_int64 inc_amount)
4483 : {
4484 0 : lra_autoinc_reload_context context (GET_MODE (value), new_rclass);
4485 0 : return context.emit_autoinc (value, inc_amount);
4486 : }
4487 :
4488 : /* Return true if the current move insn does not need processing as we
4489 : already know that it satisfies its constraints. */
4490 : static bool
4491 102245783 : simple_move_p (void)
4492 : {
4493 102245783 : rtx dest, src;
4494 102245783 : enum reg_class dclass, sclass;
4495 :
4496 102245783 : lra_assert (curr_insn_set != NULL_RTX);
4497 102245783 : dest = SET_DEST (curr_insn_set);
4498 102245783 : src = SET_SRC (curr_insn_set);
4499 :
4500 : /* If the instruction has multiple sets we need to process it even if it
4501 : is single_set. This can happen if one or more of the SETs are dead.
4502 : See PR73650. */
4503 102245783 : if (multiple_sets (curr_insn))
4504 : return false;
4505 :
4506 102045282 : return ((dclass = get_op_class (dest)) != NO_REGS
4507 21498350 : && (sclass = get_op_class (src)) != NO_REGS
4508 : /* The backend guarantees that register moves of cost 2
4509 : never need reloads. */
4510 91097127 : && targetm.register_move_cost (GET_MODE (src), sclass, dclass) == 2);
4511 : }
4512 :
4513 : /* Swap operands NOP and NOP + 1. */
4514 : static inline void
4515 21658536 : swap_operands (int nop)
4516 : {
4517 21658536 : std::swap (curr_operand_mode[nop], curr_operand_mode[nop + 1]);
4518 21658536 : std::swap (original_subreg_reg_mode[nop], original_subreg_reg_mode[nop + 1]);
4519 21658536 : std::swap (*curr_id->operand_loc[nop], *curr_id->operand_loc[nop + 1]);
4520 21658536 : std::swap (equiv_substition_p[nop], equiv_substition_p[nop + 1]);
4521 : /* Swap the duplicates too. */
4522 21658536 : lra_update_dup (curr_id, nop);
4523 21658536 : lra_update_dup (curr_id, nop + 1);
4524 21658536 : }
4525 :
4526 : /* Return TRUE if X is a (subreg of) reg and there are no hard regs of X class
4527 : which can contain value of MODE. */
4528 38 : static bool invalid_mode_reg_p (enum machine_mode mode, rtx x)
4529 : {
4530 38 : if (SUBREG_P (x))
4531 3 : x = SUBREG_REG (x);
4532 38 : if (! REG_P (x))
4533 : return false;
4534 38 : enum reg_class rclass = get_reg_class (REGNO (x));
4535 38 : return (!hard_reg_set_empty_p (reg_class_contents[rclass])
4536 38 : && hard_reg_set_subset_p
4537 38 : (reg_class_contents[rclass],
4538 38 : ira_prohibited_class_mode_regs[rclass][mode]));
4539 : }
4540 :
4541 : /* Return TRUE if regno is referenced in more than one non-debug insn. */
4542 : static bool
4543 2911480 : multiple_insn_refs_p (int regno)
4544 : {
4545 2911480 : unsigned int uid;
4546 2911480 : bitmap_iterator bi;
4547 2911480 : int nrefs = 0;
4548 7049928 : EXECUTE_IF_SET_IN_BITMAP (&lra_reg_info[regno].insn_bitmap, 0, uid, bi)
4549 : {
4550 7044301 : if (!NONDEBUG_INSN_P (lra_insn_recog_data[uid]->insn))
4551 1226968 : continue;
4552 5817333 : if (nrefs == 1)
4553 : return true;
4554 2911480 : nrefs++;
4555 : }
4556 : return false;
4557 : }
4558 :
4559 : /* Mark insns starting with FIRST as postponed for processing their
4560 : constraints. See comments for lra_postponed_insns. */
4561 : static void
4562 95580 : postpone_insns (rtx_insn *first)
4563 : {
4564 108181 : for (auto insn = first; insn != NULL_RTX; insn = NEXT_INSN (insn))
4565 : {
4566 12601 : bitmap_set_bit (&lra_postponed_insns, INSN_UID (insn));
4567 12601 : if (lra_dump_file != NULL)
4568 : {
4569 7 : fprintf (lra_dump_file, " Postponing constraint processing: ");
4570 7 : dump_insn_slim (lra_dump_file, insn);
4571 : }
4572 : }
4573 95580 : }
4574 :
4575 : /* Test whether the n-th operand is a MEM where the address is the sum of a
4576 : section anchor and a constant and return true in case of reloading the
4577 : section anchor only results in a satisfiable operand w.r.t. its
4578 : corresponding constraint. Otherwise return false. */
4579 :
4580 : static bool
4581 72 : reload_section_anchor_p (int nop)
4582 : {
4583 72 : rtx op = *curr_id->operand_loc[nop];
4584 72 : if (!MEM_P (op))
4585 : return false;
4586 72 : rtx addr = XEXP (op, 0);
4587 :
4588 72 : if (GET_CODE (addr) != CONST
4589 13 : || GET_CODE (XEXP (addr, 0)) != PLUS
4590 0 : || GET_CODE (XEXP (XEXP (addr, 0), 0)) != SYMBOL_REF
4591 0 : || !SYMBOL_REF_ANCHOR_P (XEXP (XEXP (addr, 0), 0))
4592 0 : || !CONST_INT_P (XEXP (XEXP (addr, 0), 1))
4593 : /* Some offsets are valid in conjunction with a symbol and
4594 : invalid in conjunction with a register. Thus, pull out
4595 : the anchor only in case the offset is a valid anchor
4596 : offset. */
4597 0 : || INTVAL (XEXP (XEXP (addr, 0), 1)) < targetm.min_anchor_offset
4598 72 : || INTVAL (XEXP (XEXP (addr, 0), 1)) > targetm.max_anchor_offset)
4599 : return false;
4600 :
4601 : /* Now test whether a new address of the form REG+DISPLACEMENT is valid for
4602 : the selected alternative. In order to do so, utilize lra_pmode_pseudo
4603 : instead of an actual reload register. */
4604 :
4605 0 : rtx offset = XEXP (XEXP (addr, 0), 1);
4606 0 : rtx new_addr = gen_rtx_PLUS (Pmode, lra_pmode_pseudo, offset);
4607 0 : rtx new_op = shallow_copy_rtx (op);
4608 0 : XEXP (new_op, 0) = new_addr;
4609 :
4610 : /* Get operand constraints for given alternative. */
4611 0 : const char *p = (curr_static_id->operand_alternative
4612 0 : [goal_alt_number * curr_static_id->n_operands + nop]
4613 : .constraint);
4614 0 : char c;
4615 0 : for (;
4616 0 : (c = *p) && c != ',' && c != '#';
4617 0 : p += CONSTRAINT_LEN (c, p))
4618 : {
4619 0 : enum constraint_num cn = lookup_constraint (p);
4620 0 : if (constraint_satisfied_p (new_op, cn))
4621 : return true;
4622 : }
4623 :
4624 : return false;
4625 : }
4626 :
4627 : /* Main entry point of the constraint code: search the body of the
4628 : current insn to choose the best alternative. It is mimicking insn
4629 : alternative cost calculation model of former reload pass. That is
4630 : because machine descriptions were written to use this model. This
4631 : model can be changed in future. Make commutative operand exchange
4632 : if it is chosen.
4633 :
4634 : if CHECK_ONLY_P is false, do RTL changes to satisfy the
4635 : constraints. Return true if any change happened during function
4636 : call.
4637 :
4638 : If CHECK_ONLY_P is true then don't do any transformation. Just
4639 : check that the insn satisfies all constraints. If the insn does
4640 : not satisfy any constraint, return true. */
4641 : static bool
4642 107726271 : curr_insn_transform (bool check_only_p)
4643 : {
4644 107726271 : int i, j, k;
4645 107726271 : int n_operands;
4646 107726271 : int n_alternatives;
4647 107726271 : int n_outputs;
4648 107726271 : int commutative;
4649 107726271 : signed char goal_alt_matched[MAX_RECOG_OPERANDS][MAX_RECOG_OPERANDS];
4650 107726271 : signed char match_inputs[MAX_RECOG_OPERANDS + 1];
4651 107726271 : signed char outputs[MAX_RECOG_OPERANDS + 1];
4652 107726271 : rtx_insn *before, *after;
4653 107726271 : bool alt_p = false;
4654 : /* Flag that the insn has been changed through a transformation. */
4655 107726271 : bool change_p;
4656 107726271 : bool sec_mem_p;
4657 107726271 : bool use_sec_mem_p;
4658 107726271 : int max_regno_before;
4659 107726271 : int reused_alternative_num;
4660 :
4661 107726271 : curr_insn_set = single_set (curr_insn);
4662 107726271 : if (curr_insn_set != NULL_RTX && simple_move_p ())
4663 : {
4664 : /* We assume that the corresponding insn alternative has no
4665 : earlier clobbers. If it is not the case, don't define move
4666 : cost equal to 2 for the corresponding register classes. */
4667 16508244 : lra_set_used_insn_alternative (curr_insn, LRA_NON_CLOBBERED_ALT);
4668 16508244 : return false;
4669 : }
4670 :
4671 91218027 : no_input_reloads_p = no_output_reloads_p = false;
4672 91218027 : goal_alt_number = -1;
4673 91218027 : change_p = sec_mem_p = false;
4674 :
4675 : /* CALL_INSNs are not allowed to have any output reloads. */
4676 91218027 : if (CALL_P (curr_insn))
4677 6115582 : no_output_reloads_p = true;
4678 :
4679 91218027 : n_operands = curr_static_id->n_operands;
4680 91218027 : n_alternatives = curr_static_id->n_alternatives;
4681 :
4682 : /* Just return "no reloads" if insn has no operands with
4683 : constraints. */
4684 91218027 : if (n_operands == 0 || n_alternatives == 0)
4685 : return false;
4686 :
4687 80621489 : max_regno_before = max_reg_num ();
4688 :
4689 341031791 : for (i = 0; i < n_operands; i++)
4690 : {
4691 179788813 : goal_alt_matched[i][0] = -1;
4692 179788813 : goal_alt_matches[i] = -1;
4693 : }
4694 :
4695 80621489 : commutative = curr_static_id->commutative;
4696 :
4697 : /* Now see what we need for pseudos that didn't get hard regs or got
4698 : the wrong kind of hard reg. For this, we must consider all the
4699 : operands together against the register constraints. */
4700 :
4701 80621489 : best_losers = best_overall = INT_MAX;
4702 80621489 : best_reload_sum = 0;
4703 :
4704 80621489 : curr_swapped = false;
4705 80621489 : goal_alt_swapped = false;
4706 :
4707 80621489 : if (! check_only_p)
4708 : /* Make equivalence substitution and memory subreg elimination
4709 : before address processing because an address legitimacy can
4710 : depend on memory mode. */
4711 260340844 : for (i = 0; i < n_operands; i++)
4712 : {
4713 179738795 : rtx op, subst, old;
4714 179738795 : bool op_change_p = false;
4715 :
4716 179738795 : if (curr_static_id->operand[i].is_operator)
4717 1463028 : continue;
4718 :
4719 178275767 : old = op = *curr_id->operand_loc[i];
4720 178275767 : if (GET_CODE (old) == SUBREG)
4721 3787808 : old = SUBREG_REG (old);
4722 178275767 : subst = get_equiv_with_elimination (old, curr_insn);
4723 178275767 : original_subreg_reg_mode[i] = VOIDmode;
4724 178275767 : equiv_substition_p[i] = false;
4725 :
4726 178275767 : if (subst != old
4727 : /* We don't want to change an out operand by constant or invariant
4728 : which will require additional reloads, e.g. by putting a constant
4729 : into memory. */
4730 1578557 : && (curr_static_id->operand[i].type == OP_IN || MEM_P (subst)
4731 0 : || (GET_CODE (subst) == SUBREG && MEM_P (SUBREG_REG (subst)))))
4732 : {
4733 1578557 : equiv_substition_p[i] = true;
4734 1578557 : rtx new_subst = copy_rtx (subst);
4735 1578557 : if (lra_pointer_equiv_set_in (subst))
4736 815891 : lra_pointer_equiv_set_add (new_subst);
4737 1578557 : subst = new_subst;
4738 1578557 : lra_assert (REG_P (old));
4739 1578557 : if (GET_CODE (op) != SUBREG)
4740 1521940 : *curr_id->operand_loc[i] = subst;
4741 : else
4742 : {
4743 56617 : SUBREG_REG (op) = subst;
4744 56617 : if (GET_MODE (subst) == VOIDmode)
4745 88 : original_subreg_reg_mode[i] = GET_MODE (old);
4746 : }
4747 1578557 : if (lra_dump_file != NULL)
4748 : {
4749 3 : fprintf (lra_dump_file,
4750 : "Changing pseudo %d in operand %i of insn %u on equiv ",
4751 3 : REGNO (old), i, INSN_UID (curr_insn));
4752 3 : dump_value_slim (lra_dump_file, subst, 1);
4753 3 : fprintf (lra_dump_file, "\n");
4754 : }
4755 1578557 : op_change_p = change_p = true;
4756 : }
4757 178275767 : if (simplify_operand_subreg (i, GET_MODE (old)) || op_change_p)
4758 : {
4759 1579080 : change_p = true;
4760 1579080 : lra_update_dup (curr_id, i);
4761 : }
4762 : }
4763 :
4764 : /* We process equivalences before ignoring postponed insns on the current
4765 : constraint sub-pass but before any reload insn generation for the
4766 : postponed insn. */
4767 80602049 : if (! check_only_p
4768 80602049 : && bitmap_bit_p (&lra_postponed_insns, INSN_UID (curr_insn)))
4769 : return true;
4770 :
4771 : /* Reload address registers and displacements. We do it before
4772 : finding an alternative because of memory constraints. */
4773 80614742 : before = after = NULL;
4774 260390061 : for (i = 0; i < n_operands; i++)
4775 179775319 : if (! curr_static_id->operand[i].is_operator
4776 179775319 : && process_address (i, check_only_p, &before, &after))
4777 : {
4778 490229 : if (check_only_p)
4779 : return true;
4780 490229 : change_p = true;
4781 490229 : lra_update_dup (curr_id, i);
4782 : }
4783 :
4784 80614742 : if (change_p)
4785 : /* If we've changed the instruction then any alternative that
4786 : we chose previously may no longer be valid. */
4787 2019152 : lra_set_used_insn_alternative (curr_insn, LRA_UNKNOWN_ALT);
4788 :
4789 80595302 : if (! check_only_p && curr_insn_set != NULL_RTX
4790 157311929 : && check_and_process_move (&change_p, &sec_mem_p))
4791 0 : return change_p;
4792 :
4793 80614742 : try_swapped:
4794 :
4795 91133200 : reused_alternative_num = check_only_p ? LRA_UNKNOWN_ALT : curr_id->used_insn_alternative;
4796 91133200 : if (lra_dump_file != NULL && reused_alternative_num >= 0)
4797 0 : fprintf (lra_dump_file, "Reusing alternative %d for insn #%u\n",
4798 0 : reused_alternative_num, INSN_UID (curr_insn));
4799 :
4800 91133200 : if (process_alt_operands (reused_alternative_num))
4801 82409962 : alt_p = true;
4802 :
4803 91133200 : if (check_only_p)
4804 32684 : return ! alt_p || best_losers != 0;
4805 :
4806 : /* If insn is commutative (it's safe to exchange a certain pair of
4807 : operands) then we need to try each alternative twice, the second
4808 : time matching those two operands as if we had exchanged them. To
4809 : do this, really exchange them in operands.
4810 :
4811 : If we have just tried the alternatives the second time, return
4812 : operands to normal and drop through. */
4813 :
4814 91113760 : if (reused_alternative_num < 0 && commutative >= 0)
4815 : {
4816 21036916 : curr_swapped = !curr_swapped;
4817 21036916 : if (curr_swapped)
4818 : {
4819 10518458 : swap_operands (commutative);
4820 10518458 : goto try_swapped;
4821 : }
4822 : else
4823 10518458 : swap_operands (commutative);
4824 : }
4825 :
4826 80595302 : if (! alt_p && ! sec_mem_p)
4827 : {
4828 : /* No alternative works with reloads?? */
4829 6 : if (INSN_CODE (curr_insn) >= 0)
4830 0 : fatal_insn ("unable to generate reloads for:", curr_insn);
4831 6 : error_for_asm (curr_insn,
4832 : "inconsistent operand constraints in an %<asm%>");
4833 6 : lra_asm_error_p = true;
4834 6 : if (! JUMP_P (curr_insn))
4835 : {
4836 : /* Avoid further trouble with this insn. Don't generate use
4837 : pattern here as we could use the insn SP offset. */
4838 6 : lra_set_insn_deleted (curr_insn);
4839 : }
4840 : else
4841 : {
4842 0 : lra_invalidate_insn_data (curr_insn);
4843 0 : ira_nullify_asm_goto (curr_insn);
4844 0 : lra_update_insn_regno_info (curr_insn);
4845 : }
4846 6 : return true;
4847 : }
4848 :
4849 : /* If the best alternative is with operands 1 and 2 swapped, swap
4850 : them. Update the operand numbers of any reloads already
4851 : pushed. */
4852 :
4853 80595296 : if (goal_alt_swapped)
4854 : {
4855 616900 : if (lra_dump_file != NULL)
4856 18 : fprintf (lra_dump_file, " Commutative operand exchange in insn %u\n",
4857 18 : INSN_UID (curr_insn));
4858 :
4859 : /* Swap the duplicates too. */
4860 616900 : swap_operands (commutative);
4861 616900 : change_p = true;
4862 : }
4863 :
4864 : /* Some targets' TARGET_SECONDARY_MEMORY_NEEDED (e.g. x86) are defined
4865 : too conservatively. So we use the secondary memory only if there
4866 : is no any alternative without reloads. */
4867 80595296 : use_sec_mem_p = false;
4868 80595296 : if (! alt_p)
4869 : use_sec_mem_p = true;
4870 80595296 : else if (sec_mem_p)
4871 : {
4872 14909 : for (i = 0; i < n_operands; i++)
4873 14736 : if (! goal_alt_win[i] && ! goal_alt_match_win[i])
4874 : break;
4875 13235 : use_sec_mem_p = i < n_operands;
4876 : }
4877 :
4878 13235 : if (use_sec_mem_p)
4879 : {
4880 13062 : int in = -1, out = -1;
4881 13062 : rtx new_reg, src, dest, rld;
4882 13062 : machine_mode sec_mode, rld_mode;
4883 :
4884 13062 : lra_assert (curr_insn_set != NULL_RTX && sec_mem_p);
4885 13062 : dest = SET_DEST (curr_insn_set);
4886 13062 : src = SET_SRC (curr_insn_set);
4887 39186 : for (i = 0; i < n_operands; i++)
4888 26124 : if (*curr_id->operand_loc[i] == dest)
4889 : out = i;
4890 13062 : else if (*curr_id->operand_loc[i] == src)
4891 13062 : in = i;
4892 13062 : for (i = 0; i < curr_static_id->n_dups; i++)
4893 0 : if (out < 0 && *curr_id->dup_loc[i] == dest)
4894 0 : out = curr_static_id->dup_num[i];
4895 0 : else if (in < 0 && *curr_id->dup_loc[i] == src)
4896 0 : in = curr_static_id->dup_num[i];
4897 13062 : lra_assert (out >= 0 && in >= 0
4898 : && curr_static_id->operand[out].type == OP_OUT
4899 : && curr_static_id->operand[in].type == OP_IN);
4900 13062 : rld = partial_subreg_p (GET_MODE (src), GET_MODE (dest)) ? src : dest;
4901 13062 : rld_mode = GET_MODE (rld);
4902 13062 : sec_mode = targetm.secondary_memory_needed_mode (rld_mode);
4903 13062 : if (rld_mode != sec_mode
4904 13062 : && (invalid_mode_reg_p (sec_mode, dest)
4905 19 : || invalid_mode_reg_p (sec_mode, src)))
4906 : sec_mode = rld_mode;
4907 13062 : new_reg = lra_create_new_reg (sec_mode, NULL_RTX, NO_REGS, NULL,
4908 : "secondary");
4909 : /* If the mode is changed, it should be wider. */
4910 13062 : lra_assert (!partial_subreg_p (sec_mode, rld_mode));
4911 13062 : if (sec_mode != rld_mode)
4912 : {
4913 : /* If the target says specifically to use another mode for
4914 : secondary memory moves we cannot reuse the original
4915 : insn. */
4916 19 : after = emit_spill_move (false, new_reg, dest);
4917 19 : lra_process_new_insns (curr_insn, NULL, after,
4918 : "Inserting the sec. move");
4919 : /* We may have non null BEFORE here (e.g. after address
4920 : processing. */
4921 19 : push_to_sequence (before);
4922 19 : before = emit_spill_move (true, new_reg, src);
4923 19 : emit_insn (before);
4924 19 : before = end_sequence ();
4925 19 : lra_process_new_insns (curr_insn, before, NULL, "Changing on");
4926 19 : lra_set_insn_deleted (curr_insn);
4927 : }
4928 13043 : else if (dest == rld)
4929 : {
4930 13043 : *curr_id->operand_loc[out] = new_reg;
4931 13043 : lra_update_dup (curr_id, out);
4932 13043 : after = emit_spill_move (false, new_reg, dest);
4933 13043 : lra_process_new_insns (curr_insn, NULL, after,
4934 : "Inserting the sec. move");
4935 : }
4936 : else
4937 : {
4938 0 : *curr_id->operand_loc[in] = new_reg;
4939 0 : lra_update_dup (curr_id, in);
4940 : /* See comments above. */
4941 0 : push_to_sequence (before);
4942 0 : before = emit_spill_move (true, new_reg, src);
4943 0 : emit_insn (before);
4944 0 : before = end_sequence ();
4945 0 : lra_process_new_insns (curr_insn, before, NULL,
4946 : "Inserting the sec. move");
4947 : }
4948 13062 : lra_update_insn_regno_info (curr_insn);
4949 13062 : return true;
4950 : }
4951 :
4952 80582234 : lra_assert (goal_alt_number >= 0);
4953 161065791 : lra_set_used_insn_alternative (curr_insn, goal_reuse_alt_p
4954 : ? goal_alt_number : LRA_UNKNOWN_ALT);
4955 :
4956 80582234 : if (lra_dump_file != NULL)
4957 : {
4958 1187 : const char *p;
4959 :
4960 1187 : fprintf (lra_dump_file, " Choosing alt %d in insn %u:",
4961 1187 : goal_alt_number, INSN_UID (curr_insn));
4962 1187 : print_curr_insn_alt (goal_alt_number);
4963 1187 : if (INSN_CODE (curr_insn) >= 0
4964 1187 : && (p = get_insn_name (INSN_CODE (curr_insn))) != NULL)
4965 1180 : fprintf (lra_dump_file, " {%s}", p);
4966 1187 : if (maybe_ne (curr_id->sp_offset, 0))
4967 : {
4968 0 : fprintf (lra_dump_file, " (sp_off=");
4969 0 : print_dec (curr_id->sp_offset, lra_dump_file);
4970 0 : fprintf (lra_dump_file, ")");
4971 : }
4972 1187 : fprintf (lra_dump_file, "\n");
4973 : }
4974 :
4975 : /* Right now, for any pair of operands I and J that are required to
4976 : match, with J < I, goal_alt_matches[I] is J. Add I to
4977 : goal_alt_matched[J]. */
4978 :
4979 260281397 : for (i = 0; i < n_operands; i++)
4980 179699163 : if ((j = goal_alt_matches[i]) >= 0)
4981 : {
4982 10677916 : for (k = 0; goal_alt_matched[j][k] >= 0; k++)
4983 : ;
4984 : /* We allow matching one output operand and several input
4985 : operands. */
4986 10677915 : lra_assert (k == 0
4987 : || (curr_static_id->operand[j].type == OP_OUT
4988 : && curr_static_id->operand[i].type == OP_IN
4989 : && (curr_static_id->operand
4990 : [goal_alt_matched[j][0]].type == OP_IN)));
4991 10677915 : goal_alt_matched[j][k] = i;
4992 10677915 : goal_alt_matched[j][k + 1] = -1;
4993 : }
4994 :
4995 260281397 : for (i = 0; i < n_operands; i++)
4996 179699163 : goal_alt_win[i] |= goal_alt_match_win[i];
4997 :
4998 : /* Any constants that aren't allowed and can't be reloaded into
4999 : registers are here changed into memory references. */
5000 260281397 : for (i = 0; i < n_operands; i++)
5001 179699163 : if (goal_alt_win[i])
5002 : {
5003 173421958 : int regno;
5004 173421958 : enum reg_class new_class;
5005 173421958 : rtx reg = *curr_id->operand_loc[i];
5006 :
5007 173421958 : if (GET_CODE (reg) == SUBREG)
5008 3474461 : reg = SUBREG_REG (reg);
5009 :
5010 173421958 : if (REG_P (reg) && (regno = REGNO (reg)) >= FIRST_PSEUDO_REGISTER)
5011 : {
5012 78596401 : bool ok_p = in_class_p (reg, goal_alt[i], &new_class, true);
5013 :
5014 78596401 : if (new_class != NO_REGS && get_reg_class (regno) != new_class)
5015 : {
5016 3582034 : lra_assert (ok_p);
5017 3582034 : lra_change_class (regno, new_class, " Change to", true);
5018 : }
5019 : }
5020 : }
5021 : else
5022 : {
5023 6277205 : const char *constraint;
5024 6277205 : char c;
5025 6277205 : rtx op = *curr_id->operand_loc[i];
5026 6277205 : rtx subreg = NULL_RTX;
5027 6277205 : machine_mode op_mode = curr_operand_mode[i], mode = op_mode;
5028 :
5029 6277205 : if (GET_CODE (op) == SUBREG)
5030 : {
5031 246664 : subreg = op;
5032 246664 : op = SUBREG_REG (op);
5033 246664 : mode = GET_MODE (op);
5034 : }
5035 :
5036 6500138 : if (CONST_POOL_OK_P (mode, op)
5037 6500138 : && ((targetm.preferred_reload_class
5038 222933 : (op, (enum reg_class) goal_alt[i]) == NO_REGS)
5039 74798 : || no_input_reloads_p))
5040 : {
5041 148135 : rtx tem = force_const_mem (mode, op);
5042 :
5043 148135 : change_p = true;
5044 148135 : if (subreg != NULL_RTX)
5045 0 : tem = gen_rtx_SUBREG (op_mode, tem, SUBREG_BYTE (subreg));
5046 :
5047 148135 : *curr_id->operand_loc[i] = tem;
5048 148135 : lra_update_dup (curr_id, i);
5049 148135 : process_address (i, false, &before, &after);
5050 :
5051 : /* If the alternative accepts constant pool refs directly
5052 : there will be no reload needed at all. */
5053 148135 : if (subreg != NULL_RTX)
5054 0 : continue;
5055 : /* Skip alternatives before the one requested. */
5056 148135 : constraint = (curr_static_id->operand_alternative
5057 148135 : [goal_alt_number * n_operands + i].constraint);
5058 148135 : for (;
5059 251560 : (c = *constraint) && c != ',' && c != '#';
5060 103425 : constraint += CONSTRAINT_LEN (c, constraint))
5061 : {
5062 203578 : enum constraint_num cn = lookup_constraint (constraint);
5063 203578 : if ((insn_extra_memory_constraint (cn)
5064 103807 : || insn_extra_special_memory_constraint (cn)
5065 : || insn_extra_relaxed_memory_constraint (cn))
5066 203960 : && satisfies_memory_constraint_p (tem, cn))
5067 : break;
5068 : }
5069 148135 : if (c == '\0' || c == ',' || c == '#')
5070 47982 : continue;
5071 :
5072 100153 : goal_alt_win[i] = true;
5073 : }
5074 : }
5075 :
5076 : n_outputs = 0;
5077 260281397 : for (i = 0; i < n_operands; i++)
5078 179699163 : if (curr_static_id->operand[i].type == OP_OUT)
5079 69929254 : outputs[n_outputs++] = i;
5080 80582234 : outputs[n_outputs] = -1;
5081 260281397 : for (i = 0; i < n_operands; i++)
5082 : {
5083 179699163 : int regno;
5084 179699163 : bool optional_p = false;
5085 179699163 : rtx old, new_reg;
5086 179699163 : rtx op = *curr_id->operand_loc[i];
5087 :
5088 179699163 : if (goal_alt_win[i])
5089 : {
5090 173522111 : if (goal_alt[i] == NO_REGS
5091 47294345 : && REG_P (op)
5092 5434291 : && (regno = REGNO (op)) >= FIRST_PSEUDO_REGISTER
5093 : /* We assigned a hard register to the pseudo in the past but now
5094 : decided to spill it for the insn. If the pseudo is used only
5095 : in this insn, it is better to spill it here as we free hard
5096 : registers for other pseudos referenced in the insn. The most
5097 : common case of this is a scratch register which will be
5098 : transformed to scratch back at the end of LRA. */
5099 176433591 : && !multiple_insn_refs_p (regno))
5100 : {
5101 11254 : if (lra_get_allocno_class (regno) != NO_REGS)
5102 5347 : lra_change_class (regno, NO_REGS, " Change to", true);
5103 5627 : reg_renumber[regno] = -1;
5104 : }
5105 : /* We can do an optional reload. If the pseudo got a hard
5106 : reg, we might improve the code through inheritance. If
5107 : it does not get a hard register we coalesce memory/memory
5108 : moves later. Ignore move insns to avoid cycling. */
5109 173522111 : if (! lra_simple_p
5110 172977433 : && lra_undo_inheritance_iter < LRA_MAX_INHERITANCE_PASSES
5111 160406965 : && goal_alt[i] != NO_REGS && REG_P (op)
5112 79574959 : && (regno = REGNO (op)) >= FIRST_PSEUDO_REGISTER
5113 66493411 : && regno < new_regno_start
5114 61645885 : && ! ira_former_scratch_p (regno)
5115 61588800 : && reg_renumber[regno] < 0
5116 : /* Check that the optional reload pseudo will be able to
5117 : hold given mode value. */
5118 3886835 : && ! (prohibited_class_reg_set_mode_p
5119 3886835 : (goal_alt[i], reg_class_contents[goal_alt[i]],
5120 3886835 : PSEUDO_REGNO_MODE (regno)))
5121 177408936 : && (curr_insn_set == NULL_RTX
5122 3880719 : || !((REG_P (SET_SRC (curr_insn_set))
5123 : || MEM_P (SET_SRC (curr_insn_set))
5124 : || GET_CODE (SET_SRC (curr_insn_set)) == SUBREG)
5125 3230973 : && (REG_P (SET_DEST (curr_insn_set))
5126 : || MEM_P (SET_DEST (curr_insn_set))
5127 : || GET_CODE (SET_DEST (curr_insn_set)) == SUBREG))))
5128 : optional_p = true;
5129 172866223 : else if (goal_alt_matched[i][0] != -1
5130 8927881 : && curr_static_id->operand[i].type == OP_OUT
5131 8926762 : && (curr_static_id->operand_alternative
5132 8926762 : [goal_alt_number * n_operands + i].earlyclobber)
5133 18675 : && REG_P (op))
5134 : {
5135 23380 : for (j = 0; goal_alt_matched[i][j] != -1; j++)
5136 : {
5137 18622 : rtx op2 = *curr_id->operand_loc[goal_alt_matched[i][j]];
5138 :
5139 18622 : if (REG_P (op2) && REGNO (op) != REGNO (op2))
5140 : break;
5141 : }
5142 18622 : if (goal_alt_matched[i][j] != -1)
5143 : {
5144 : /* Generate reloads for different output and matched
5145 : input registers. This is the easiest way to avoid
5146 : creation of non-existing register conflicts in
5147 : lra-lives.cc. */
5148 13864 : match_reload (i, goal_alt_matched[i], outputs, goal_alt[i],
5149 : &goal_alt_exclude_start_hard_regs[i], &before,
5150 : &after, true);
5151 : }
5152 174517562 : continue;
5153 18622 : }
5154 : else
5155 : {
5156 172847601 : enum reg_class rclass, common_class;
5157 :
5158 90460324 : if (REG_P (op) && goal_alt[i] != NO_REGS
5159 85026033 : && (regno = REGNO (op)) >= new_regno_start
5160 4856208 : && (rclass = get_reg_class (regno)) == ALL_REGS
5161 0 : && ((common_class = ira_reg_class_subset[rclass][goal_alt[i]])
5162 : != NO_REGS)
5163 0 : && common_class != ALL_REGS
5164 172847601 : && enough_allocatable_hard_regs_p (common_class,
5165 0 : GET_MODE (op)))
5166 : /* Refine reload pseudo class from chosen alternative
5167 : constraint. */
5168 0 : lra_change_class (regno, common_class, " Change to", true);
5169 172847601 : continue;
5170 172847601 : }
5171 : }
5172 :
5173 : /* Operands that match previous ones have already been handled. */
5174 6832940 : if (goal_alt_matches[i] >= 0)
5175 1651339 : continue;
5176 :
5177 : /* We should not have an operand with a non-offsettable address
5178 : appearing where an offsettable address will do. It also may
5179 : be a case when the address should be special in other words
5180 : not a general one (e.g. it needs no index reg). */
5181 5181601 : if (goal_alt_matched[i][0] == -1 && goal_alt_offmemok[i] && MEM_P (op))
5182 : {
5183 72 : enum reg_class rclass;
5184 72 : rtx *loc = &XEXP (op, 0);
5185 72 : enum rtx_code code = GET_CODE (*loc);
5186 :
5187 72 : push_to_sequence (before);
5188 72 : rclass = base_reg_class (GET_MODE (op), MEM_ADDR_SPACE (op),
5189 : MEM, SCRATCH, curr_insn);
5190 72 : if (GET_RTX_CLASS (code) == RTX_AUTOINC)
5191 0 : new_reg = emit_inc (rclass, *loc,
5192 : /* This value does not matter for MODIFY. */
5193 0 : GET_MODE_SIZE (GET_MODE (op)));
5194 : /* Try to pull out section anchors. For example, instead of
5195 : reloading an "entire" address like .LANCHOR42+offset only reload
5196 : .LANCHOR42 and use the new reload register as the base register.
5197 : This allows following optimizations to share section anchors and
5198 : remove redundant loads. */
5199 72 : else if (reload_section_anchor_p (i))
5200 : {
5201 0 : rtx anchor = XEXP (XEXP (*loc, 0), 0);
5202 0 : rtx offset = XEXP (XEXP (*loc, 0), 1);
5203 :
5204 0 : if (get_reload_reg (OP_IN, Pmode, anchor, rclass, NULL, false,
5205 : false, "offsetable address", &new_reg))
5206 0 : lra_emit_move (new_reg, anchor);
5207 :
5208 0 : rtx new_addr = gen_rtx_PLUS (Pmode, new_reg, offset);
5209 0 : rtx new_op = shallow_copy_rtx (op);
5210 0 : XEXP (new_op, 0) = new_addr;
5211 :
5212 0 : new_reg = new_op;
5213 0 : loc = curr_id->operand_loc[i];
5214 : }
5215 86 : else if (get_reload_reg (OP_IN, Pmode, *loc, rclass,
5216 : NULL, false, false,
5217 : "offsetable address", &new_reg))
5218 : {
5219 72 : rtx addr = *loc;
5220 72 : enum rtx_code code = GET_CODE (addr);
5221 72 : bool align_p = false;
5222 :
5223 72 : if (code == AND && CONST_INT_P (XEXP (addr, 1)))
5224 : {
5225 : /* (and ... (const_int -X)) is used to align to X bytes. */
5226 0 : align_p = true;
5227 0 : addr = XEXP (*loc, 0);
5228 : }
5229 : else
5230 72 : addr = canonicalize_reload_addr (addr);
5231 :
5232 72 : lra_emit_move (new_reg, addr);
5233 72 : if (align_p)
5234 0 : emit_move_insn (new_reg, gen_rtx_AND (GET_MODE (new_reg), new_reg, XEXP (*loc, 1)));
5235 : }
5236 72 : before = end_sequence ();
5237 72 : *loc = new_reg;
5238 72 : lra_update_dup (curr_id, i);
5239 72 : }
5240 5181529 : else if (goal_alt_matched[i][0] == -1)
5241 : {
5242 3431496 : machine_mode mode;
5243 3431496 : rtx reg, *loc;
5244 3431496 : int hard_regno;
5245 3431496 : enum op_type type = curr_static_id->operand[i].type;
5246 :
5247 3431496 : loc = curr_id->operand_loc[i];
5248 3431496 : mode = curr_operand_mode[i];
5249 3431496 : if (GET_CODE (*loc) == SUBREG)
5250 : {
5251 79859 : reg = SUBREG_REG (*loc);
5252 79859 : poly_int64 byte = SUBREG_BYTE (*loc);
5253 79859 : if (REG_P (reg)
5254 : /* Strict_low_part requires reloading the register and not
5255 : just the subreg. Likewise for a strict subreg no wider
5256 : than a word for WORD_REGISTER_OPERATIONS targets. */
5257 79859 : && (curr_static_id->operand[i].strict_low
5258 79779 : || (!paradoxical_subreg_p (mode, GET_MODE (reg))
5259 77190 : && (hard_regno
5260 77190 : = get_try_hard_regno (REGNO (reg))) >= 0
5261 75823 : && (simplify_subreg_regno
5262 155682 : (hard_regno,
5263 75823 : GET_MODE (reg), byte, mode) < 0)
5264 0 : && (goal_alt[i] == NO_REGS
5265 0 : || (simplify_subreg_regno
5266 79859 : (ira_class_hard_regs[goal_alt[i]][0],
5267 0 : GET_MODE (reg), byte, mode) >= 0)))
5268 79779 : || (partial_subreg_p (mode, GET_MODE (reg))
5269 79779 : && known_le (GET_MODE_SIZE (GET_MODE (reg)),
5270 : UNITS_PER_WORD)
5271 : && WORD_REGISTER_OPERATIONS))
5272 : /* Avoid the situation when there are no available hard regs
5273 : for the pseudo mode but there are ones for the subreg
5274 : mode: */
5275 79939 : && !(goal_alt[i] != NO_REGS
5276 80 : && REGNO (reg) >= FIRST_PSEUDO_REGISTER
5277 80 : && (prohibited_class_reg_set_mode_p
5278 80 : (goal_alt[i], reg_class_contents[goal_alt[i]],
5279 80 : GET_MODE (reg)))
5280 : && !(prohibited_class_reg_set_mode_p
5281 0 : (goal_alt[i], reg_class_contents[goal_alt[i]],
5282 : mode))))
5283 : {
5284 : /* An OP_INOUT is required when reloading a subreg of a
5285 : mode wider than a word to ensure that data beyond the
5286 : word being reloaded is preserved. Also automatically
5287 : ensure that strict_low_part reloads are made into
5288 : OP_INOUT which should already be true from the backend
5289 : constraints. */
5290 80 : if (type == OP_OUT
5291 80 : && (curr_static_id->operand[i].strict_low
5292 0 : || read_modify_subreg_p (*loc)))
5293 : type = OP_INOUT;
5294 80 : loc = &SUBREG_REG (*loc);
5295 80 : mode = GET_MODE (*loc);
5296 : }
5297 : }
5298 3431496 : old = *loc;
5299 3431496 : if (get_reload_reg (type, mode, old, goal_alt[i],
5300 : &goal_alt_exclude_start_hard_regs[i],
5301 3431496 : loc != curr_id->operand_loc[i],
5302 3431496 : curr_static_id->operand_alternative
5303 3431496 : [goal_alt_number * n_operands + i].earlyclobber,
5304 : "", &new_reg)
5305 3431496 : && type != OP_OUT)
5306 : {
5307 2452601 : push_to_sequence (before);
5308 2452601 : lra_emit_move (new_reg, old);
5309 2452601 : before = end_sequence ();
5310 : }
5311 3431496 : *loc = new_reg;
5312 3431496 : if (type != OP_IN
5313 977834 : && find_reg_note (curr_insn, REG_UNUSED, old) == NULL_RTX
5314 : /* OLD can be an equivalent constant here. */
5315 952650 : && !CONSTANT_P (old)
5316 : /* No need to write back anything for a scratch. */
5317 952650 : && GET_CODE (old) != SCRATCH
5318 4384146 : && (!REG_P(old) || !ira_former_scratch_p (REGNO (old))))
5319 : {
5320 952650 : start_sequence ();
5321 952650 : lra_emit_move (type == OP_INOUT ? copy_rtx (old) : old, new_reg);
5322 952650 : emit_insn (after);
5323 952650 : after = end_sequence ();
5324 952650 : *loc = new_reg;
5325 : }
5326 3431496 : for (j = 0; j < goal_alt_dont_inherit_ops_num; j++)
5327 624 : if (goal_alt_dont_inherit_ops[j] == i)
5328 : {
5329 624 : lra_set_regno_unique_value (REGNO (new_reg));
5330 624 : break;
5331 : }
5332 3431496 : lra_update_dup (curr_id, i);
5333 : }
5334 1750033 : else if (curr_static_id->operand[i].type == OP_IN
5335 1750033 : && (curr_static_id->operand[goal_alt_matched[i][0]].type
5336 : == OP_OUT
5337 0 : || (curr_static_id->operand[goal_alt_matched[i][0]].type
5338 : == OP_INOUT
5339 0 : && (operands_match_p
5340 0 : (*curr_id->operand_loc[i],
5341 0 : *curr_id->operand_loc[goal_alt_matched[i][0]],
5342 : -1)))))
5343 : {
5344 : /* generate reloads for input and matched outputs. */
5345 14973 : match_inputs[0] = i;
5346 14973 : match_inputs[1] = -1;
5347 14973 : match_reload (goal_alt_matched[i][0], match_inputs, outputs,
5348 : goal_alt[i], &goal_alt_exclude_start_hard_regs[i],
5349 : &before, &after,
5350 14973 : curr_static_id->operand_alternative
5351 14973 : [goal_alt_number * n_operands + goal_alt_matched[i][0]]
5352 14973 : .earlyclobber);
5353 : }
5354 1735060 : else if ((curr_static_id->operand[i].type == OP_OUT
5355 0 : || (curr_static_id->operand[i].type == OP_INOUT
5356 0 : && (operands_match_p
5357 0 : (*curr_id->operand_loc[i],
5358 0 : *curr_id->operand_loc[goal_alt_matched[i][0]],
5359 : -1))))
5360 1735060 : && (curr_static_id->operand[goal_alt_matched[i][0]].type
5361 : == OP_IN))
5362 : /* Generate reloads for output and matched inputs. */
5363 1735060 : match_reload (i, goal_alt_matched[i], outputs, goal_alt[i],
5364 : &goal_alt_exclude_start_hard_regs[i], &before, &after,
5365 1735060 : curr_static_id->operand_alternative
5366 1735060 : [goal_alt_number * n_operands + i].earlyclobber);
5367 0 : else if (curr_static_id->operand[i].type == OP_IN
5368 0 : && (curr_static_id->operand[goal_alt_matched[i][0]].type
5369 : == OP_IN))
5370 : {
5371 : /* Generate reloads for matched inputs. */
5372 0 : match_inputs[0] = i;
5373 0 : for (j = 0; (k = goal_alt_matched[i][j]) >= 0; j++)
5374 0 : match_inputs[j + 1] = k;
5375 0 : match_inputs[j + 1] = -1;
5376 0 : match_reload (-1, match_inputs, outputs, goal_alt[i],
5377 : &goal_alt_exclude_start_hard_regs[i],
5378 : &before, &after, false);
5379 : }
5380 : else
5381 : /* We must generate code in any case when function
5382 : process_alt_operands decides that it is possible. */
5383 0 : gcc_unreachable ();
5384 :
5385 5181601 : if (optional_p)
5386 : {
5387 655888 : rtx reg = op;
5388 :
5389 655888 : lra_assert (REG_P (reg));
5390 655888 : regno = REGNO (reg);
5391 655888 : op = *curr_id->operand_loc[i]; /* Substitution. */
5392 655888 : if (GET_CODE (op) == SUBREG)
5393 0 : op = SUBREG_REG (op);
5394 655888 : gcc_assert (REG_P (op) && (int) REGNO (op) >= new_regno_start);
5395 655888 : bitmap_set_bit (&lra_optional_reload_pseudos, REGNO (op));
5396 655888 : lra_reg_info[REGNO (op)].restore_rtx = reg;
5397 655888 : if (lra_dump_file != NULL)
5398 3 : fprintf (lra_dump_file,
5399 : " Making reload reg %d for reg %d optional\n",
5400 : REGNO (op), regno);
5401 : }
5402 : }
5403 :
5404 : /* After the dust has settled, collect and attach dependent filters. */
5405 80582234 : process_dependent_filters ();
5406 :
5407 76149256 : if (before != NULL_RTX || after != NULL_RTX
5408 155916240 : || max_regno_before != max_reg_num ())
5409 5273791 : change_p = true;
5410 80582234 : if (change_p)
5411 : {
5412 6226359 : lra_update_operator_dups (curr_id);
5413 : /* Something changes -- process the insn. */
5414 6226359 : lra_update_insn_regno_info (curr_insn);
5415 6226359 : if (asm_noperands (PATTERN (curr_insn)) >= 0
5416 6226359 : && ++curr_id->asm_reloads_num >= FIRST_PSEUDO_REGISTER)
5417 : /* Most probably there are no enough registers to satisfy asm insn: */
5418 : {
5419 11 : lra_asm_insn_error (curr_insn);
5420 11 : return change_p;
5421 : }
5422 : }
5423 80582223 : if (goal_alt_out_sp_reload_p)
5424 : {
5425 : /* We have an output stack pointer reload -- update sp offset: */
5426 0 : rtx set;
5427 0 : bool done_p = false;
5428 0 : poly_int64 sp_offset = curr_id->sp_offset;
5429 0 : for (rtx_insn *insn = after; insn != NULL_RTX; insn = NEXT_INSN (insn))
5430 0 : if ((set = single_set (insn)) != NULL_RTX
5431 0 : && SET_DEST (set) == stack_pointer_rtx)
5432 : {
5433 0 : lra_assert (!done_p);
5434 0 : done_p = true;
5435 0 : curr_id->sp_offset = 0;
5436 0 : lra_insn_recog_data_t id = lra_get_insn_recog_data (insn);
5437 0 : id->sp_offset = sp_offset;
5438 0 : if (lra_dump_file != NULL)
5439 0 : fprintf (lra_dump_file,
5440 : " Moving sp offset from insn %u to %u\n",
5441 0 : INSN_UID (curr_insn), INSN_UID (insn));
5442 : }
5443 0 : lra_assert (done_p);
5444 : }
5445 80582223 : int const_regno = -1;
5446 80582223 : rtx set;
5447 80582223 : rtx_insn *prev, *const_insn = NULL;
5448 4432973 : if (before != NULL_RTX && (prev = PREV_INSN (curr_insn)) != NULL_RTX
5449 85015196 : && (set = single_set (prev)) != NULL_RTX && CONSTANT_P (SET_SRC (set)))
5450 : {
5451 341754 : rtx reg = SET_DEST (set);
5452 341754 : if (GET_CODE (reg) == SUBREG)
5453 9697 : reg = SUBREG_REG (reg);
5454 : /* Consider only reload insns as we don't want to change the order
5455 : created by previous optimizations. */
5456 250116 : if (REG_P (reg) && (int) REGNO (reg) >= lra_new_regno_start
5457 342580 : && bitmap_bit_p (&lra_reg_info[REGNO (reg)].insn_bitmap,
5458 826 : INSN_UID (curr_insn)))
5459 : {
5460 334 : const_regno = REGNO (reg);
5461 334 : const_insn = prev;
5462 : }
5463 : }
5464 80582223 : if (asm_noperands (PATTERN (curr_insn)) >= 0)
5465 : {
5466 : /* Asm can have a lot of operands. To guarantee their assignment,
5467 : postpone processing the reload insns until the reload pseudos are
5468 : assigned. */
5469 47790 : postpone_insns (before);
5470 47790 : postpone_insns (after);
5471 : }
5472 80582223 : lra_process_new_insns (curr_insn, before, after,
5473 : "Inserting insn reload", true);
5474 80582223 : if (const_regno >= 0) {
5475 668 : bool move_p = true;
5476 668 : for (rtx_insn *insn = before; insn != curr_insn; insn = NEXT_INSN (insn))
5477 334 : if (bitmap_bit_p (&lra_reg_info[const_regno].insn_bitmap,
5478 334 : INSN_UID (insn)))
5479 : {
5480 : move_p = false;
5481 : break;
5482 : }
5483 334 : if (move_p)
5484 : {
5485 334 : reorder_insns_nobb (const_insn, const_insn, PREV_INSN (curr_insn));
5486 334 : if (lra_dump_file != NULL)
5487 : {
5488 0 : dump_insn_slim (lra_dump_file, const_insn);
5489 0 : fprintf (lra_dump_file,
5490 : " to decrease reg pressure, it is moved before:\n");
5491 0 : dump_insn_slim (lra_dump_file, curr_insn);
5492 : }
5493 : }
5494 : }
5495 : return change_p;
5496 : }
5497 :
5498 : /* Return true if INSN satisfies all constraints. In other words, no
5499 : reload insns are needed. */
5500 : bool
5501 3524 : lra_constrain_insn (rtx_insn *insn)
5502 : {
5503 3524 : int saved_new_regno_start = new_regno_start;
5504 3524 : int saved_new_insn_uid_start = new_insn_uid_start;
5505 3524 : bool change_p;
5506 :
5507 3524 : curr_insn = insn;
5508 3524 : curr_id = lra_get_insn_recog_data (curr_insn);
5509 3524 : curr_static_id = curr_id->insn_static_data;
5510 3524 : new_insn_uid_start = get_max_uid ();
5511 3524 : new_regno_start = max_reg_num ();
5512 3524 : change_p = curr_insn_transform (true);
5513 3524 : new_regno_start = saved_new_regno_start;
5514 3524 : new_insn_uid_start = saved_new_insn_uid_start;
5515 3524 : return ! change_p;
5516 : }
5517 :
5518 : /* Return true if X is in LIST. */
5519 : static bool
5520 1366953 : in_list_p (rtx x, rtx list)
5521 : {
5522 2341088 : for (; list != NULL_RTX; list = XEXP (list, 1))
5523 1285876 : if (XEXP (list, 0) == x)
5524 : return true;
5525 : return false;
5526 : }
5527 :
5528 : /* Return true if X contains an allocatable hard register (if
5529 : HARD_REG_P) or a (spilled if SPILLED_P) pseudo. */
5530 : static bool
5531 7569768 : contains_reg_p (rtx x, bool hard_reg_p, bool spilled_p)
5532 : {
5533 7569768 : int i, j;
5534 7569768 : const char *fmt;
5535 7569768 : enum rtx_code code;
5536 :
5537 7569768 : code = GET_CODE (x);
5538 7569768 : if (REG_P (x))
5539 : {
5540 1530170 : int regno = REGNO (x);
5541 1530170 : HARD_REG_SET alloc_regs;
5542 :
5543 1530170 : if (hard_reg_p)
5544 : {
5545 482662 : if (regno >= FIRST_PSEUDO_REGISTER)
5546 142513 : regno = lra_get_regno_hard_regno (regno);
5547 482662 : if (regno < 0)
5548 : return false;
5549 482662 : alloc_regs = ~lra_no_alloc_regs;
5550 482662 : return overlaps_hard_reg_set_p (alloc_regs, GET_MODE (x), regno);
5551 : }
5552 : else
5553 : {
5554 1047508 : if (regno < FIRST_PSEUDO_REGISTER)
5555 : return false;
5556 336109 : if (! spilled_p)
5557 : return true;
5558 177529 : return lra_get_regno_hard_regno (regno) < 0;
5559 : }
5560 : }
5561 6039598 : fmt = GET_RTX_FORMAT (code);
5562 14926313 : for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
5563 : {
5564 9472175 : if (fmt[i] == 'e')
5565 : {
5566 4174459 : if (contains_reg_p (XEXP (x, i), hard_reg_p, spilled_p))
5567 : return true;
5568 : }
5569 5297716 : else if (fmt[i] == 'E')
5570 : {
5571 1305216 : for (j = XVECLEN (x, i) - 1; j >= 0; j--)
5572 1195106 : if (contains_reg_p (XVECEXP (x, i, j), hard_reg_p, spilled_p))
5573 : return true;
5574 : }
5575 : }
5576 : return false;
5577 : }
5578 :
5579 : /* Process all regs in location *LOC and change them on equivalent
5580 : substitution. Return true if any change was done. */
5581 : static bool
5582 3348 : loc_equivalence_change_p (rtx *loc)
5583 : {
5584 3348 : rtx subst, reg, x = *loc;
5585 3348 : bool result = false;
5586 3348 : enum rtx_code code = GET_CODE (x);
5587 3348 : const char *fmt;
5588 3348 : int i, j;
5589 :
5590 3348 : if (code == SUBREG)
5591 : {
5592 20 : reg = SUBREG_REG (x);
5593 20 : if ((subst = get_equiv_with_elimination (reg, curr_insn)) != reg
5594 20 : && GET_MODE (subst) == VOIDmode)
5595 : {
5596 : /* We cannot reload debug location. Simplify subreg here
5597 : while we know the inner mode. */
5598 0 : *loc = simplify_gen_subreg (GET_MODE (x), subst,
5599 0 : GET_MODE (reg), SUBREG_BYTE (x));
5600 0 : return true;
5601 : }
5602 : }
5603 3348 : if (code == REG && (subst = get_equiv_with_elimination (x, curr_insn)) != x)
5604 : {
5605 8 : *loc = subst;
5606 8 : return true;
5607 : }
5608 :
5609 : /* Scan all the operand sub-expressions. */
5610 3340 : fmt = GET_RTX_FORMAT (code);
5611 8168 : for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
5612 : {
5613 4828 : if (fmt[i] == 'e')
5614 2577 : result = loc_equivalence_change_p (&XEXP (x, i)) || result;
5615 2251 : else if (fmt[i] == 'E')
5616 270 : for (j = XVECLEN (x, i) - 1; j >= 0; j--)
5617 200 : result
5618 210 : = loc_equivalence_change_p (&XVECEXP (x, i, j)) || result;
5619 : }
5620 : return result;
5621 : }
5622 :
5623 : /* Similar to loc_equivalence_change_p, but for use as
5624 : simplify_replace_fn_rtx callback. DATA is insn for which the
5625 : elimination is done. If it null we don't do the elimination. */
5626 : static rtx
5627 42153695 : loc_equivalence_callback (rtx loc, const_rtx, void *data)
5628 : {
5629 42153695 : if (!REG_P (loc))
5630 : return NULL_RTX;
5631 :
5632 10839192 : rtx subst = (data == NULL
5633 10839192 : ? get_equiv (loc) : get_equiv_with_elimination (loc, (rtx_insn *) data));
5634 10839192 : if (subst != loc)
5635 : return subst;
5636 :
5637 : return NULL_RTX;
5638 : }
5639 :
5640 : /* Maximum number of generated reload insns per an insn. It is for
5641 : preventing this pass cycling in a bug case. */
5642 : #define MAX_RELOAD_INSNS_NUMBER LRA_MAX_INSN_RELOADS
5643 :
5644 : /* The current iteration number of this LRA pass. */
5645 : int lra_constraint_iter;
5646 :
5647 : /* True if we should during assignment sub-pass check assignment
5648 : correctness for all pseudos and spill some of them to correct
5649 : conflicts. It can be necessary when we substitute equiv which
5650 : needs checking register allocation correctness because the
5651 : equivalent value contains allocatable hard registers, or when we
5652 : restore multi-register pseudo, or when we change the insn code and
5653 : its operand became INOUT operand when it was IN one before. */
5654 : bool check_and_force_assignment_correctness_p;
5655 :
5656 : /* Return true if REGNO is referenced in more than one block. */
5657 : static bool
5658 152251 : multi_block_pseudo_p (int regno)
5659 : {
5660 152251 : basic_block bb = NULL;
5661 152251 : unsigned int uid;
5662 152251 : bitmap_iterator bi;
5663 :
5664 152251 : if (regno < FIRST_PSEUDO_REGISTER)
5665 : return false;
5666 :
5667 466108 : EXECUTE_IF_SET_IN_BITMAP (&lra_reg_info[regno].insn_bitmap, 0, uid, bi)
5668 318676 : if (bb == NULL)
5669 152251 : bb = BLOCK_FOR_INSN (lra_insn_recog_data[uid]->insn);
5670 166425 : else if (BLOCK_FOR_INSN (lra_insn_recog_data[uid]->insn) != bb)
5671 : return true;
5672 : return false;
5673 : }
5674 :
5675 : /* Return true if LIST contains a deleted insn. */
5676 : static bool
5677 735446 : contains_deleted_insn_p (rtx_insn_list *list)
5678 : {
5679 1404935 : for (; list != NULL_RTX; list = list->next ())
5680 669489 : if (NOTE_P (list->insn ())
5681 669489 : && NOTE_KIND (list->insn ()) == NOTE_INSN_DELETED)
5682 : return true;
5683 : return false;
5684 : }
5685 :
5686 : /* Return true if X contains a pseudo dying in INSN. */
5687 : static bool
5688 2292454 : dead_pseudo_p (rtx x, rtx_insn *insn)
5689 : {
5690 2292454 : int i, j;
5691 2292454 : const char *fmt;
5692 2292454 : enum rtx_code code;
5693 :
5694 2292454 : if (REG_P (x))
5695 510068 : return (insn != NULL_RTX
5696 510068 : && find_regno_note (insn, REG_DEAD, REGNO (x)) != NULL_RTX);
5697 1782386 : code = GET_CODE (x);
5698 1782386 : fmt = GET_RTX_FORMAT (code);
5699 4550779 : for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
5700 : {
5701 2773694 : if (fmt[i] == 'e')
5702 : {
5703 1355353 : if (dead_pseudo_p (XEXP (x, i), insn))
5704 : return true;
5705 : }
5706 1418341 : else if (fmt[i] == 'E')
5707 : {
5708 294228 : for (j = XVECLEN (x, i) - 1; j >= 0; j--)
5709 269185 : if (dead_pseudo_p (XVECEXP (x, i, j), insn))
5710 : return true;
5711 : }
5712 : }
5713 : return false;
5714 : }
5715 :
5716 : /* Return true if INSN contains a dying pseudo in INSN right hand
5717 : side. */
5718 : static bool
5719 667916 : insn_rhs_dead_pseudo_p (rtx_insn *insn)
5720 : {
5721 667916 : rtx set = single_set (insn);
5722 :
5723 667916 : gcc_assert (set != NULL);
5724 667916 : return dead_pseudo_p (SET_SRC (set), insn);
5725 : }
5726 :
5727 : /* Return true if any init insn of REGNO contains a dying pseudo in
5728 : insn right hand side. */
5729 : static bool
5730 733873 : init_insn_rhs_dead_pseudo_p (int regno)
5731 : {
5732 733873 : rtx_insn_list *insns = ira_reg_equiv[regno].init_insns;
5733 :
5734 733873 : if (insns == NULL)
5735 : return false;
5736 1329208 : for (; insns != NULL_RTX; insns = insns->next ())
5737 667916 : if (insn_rhs_dead_pseudo_p (insns->insn ()))
5738 : return true;
5739 : return false;
5740 : }
5741 :
5742 : /* Return TRUE if REGNO has a reverse equivalence. The equivalence is
5743 : reverse only if we have one init insn with given REGNO as a
5744 : source. */
5745 : static bool
5746 735446 : reverse_equiv_p (int regno)
5747 : {
5748 735446 : rtx_insn_list *insns = ira_reg_equiv[regno].init_insns;
5749 735446 : rtx set;
5750 :
5751 735446 : if (insns == NULL)
5752 : return false;
5753 669489 : if (! INSN_P (insns->insn ())
5754 1338978 : || insns->next () != NULL)
5755 : return false;
5756 669489 : if ((set = single_set (insns->insn ())) == NULL_RTX)
5757 : return false;
5758 669489 : return REG_P (SET_SRC (set)) && (int) REGNO (SET_SRC (set)) == regno;
5759 : }
5760 :
5761 : /* Return TRUE if REGNO was reloaded in an equivalence init insn. We
5762 : call this function only for non-reverse equivalence. */
5763 : static bool
5764 727249 : contains_reloaded_insn_p (int regno)
5765 : {
5766 727249 : rtx set;
5767 727249 : rtx_insn_list *list = ira_reg_equiv[regno].init_insns;
5768 :
5769 1388541 : for (; list != NULL; list = list->next ())
5770 661292 : if ((set = single_set (list->insn ())) == NULL_RTX
5771 661292 : || ! REG_P (SET_DEST (set))
5772 1322584 : || (int) REGNO (SET_DEST (set)) != regno)
5773 : return true;
5774 : return false;
5775 : }
5776 :
5777 : /* Try combine secondary memory reload insn FROM for insn TO into TO insn.
5778 : FROM should be a load insn (usually a secondary memory reload insn). Return
5779 : TRUE in case of success. */
5780 : static bool
5781 7457348 : combine_reload_insn (rtx_insn *from, rtx_insn *to)
5782 : {
5783 7457348 : bool ok_p;
5784 7457348 : rtx_insn *saved_insn;
5785 7457348 : rtx set, from_reg, to_reg, op;
5786 7457348 : enum reg_class to_class, from_class;
5787 7457348 : int n, nop;
5788 7457348 : signed char changed_nops[MAX_RECOG_OPERANDS + 1];
5789 :
5790 : /* Check conditions for second memory reload and original insn: */
5791 7457348 : if ((targetm.secondary_memory_needed
5792 : == hook_bool_mode_reg_class_t_reg_class_t_false)
5793 7457348 : || NEXT_INSN (from) != to
5794 4440955 : || !NONDEBUG_INSN_P (to)
5795 11898301 : || CALL_P (to))
5796 : return false;
5797 :
5798 4435710 : lra_insn_recog_data_t id = lra_get_insn_recog_data (to);
5799 4435710 : struct lra_static_insn_data *static_id = id->insn_static_data;
5800 :
5801 4435710 : if (id->used_insn_alternative == LRA_UNKNOWN_ALT
5802 4435710 : || (set = single_set (from)) == NULL_RTX)
5803 33912 : return false;
5804 4401798 : from_reg = SET_DEST (set);
5805 4401798 : to_reg = SET_SRC (set);
5806 : /* Ignore optional reloads: */
5807 4321712 : if (! REG_P (from_reg) || ! REG_P (to_reg)
5808 7326050 : || bitmap_bit_p (&lra_optional_reload_pseudos, REGNO (from_reg)))
5809 2031786 : return false;
5810 2370012 : to_class = lra_get_allocno_class (REGNO (to_reg));
5811 2370012 : from_class = lra_get_allocno_class (REGNO (from_reg));
5812 : /* Check that reload insn is a load: */
5813 2370012 : if (to_class != NO_REGS || from_class == NO_REGS)
5814 : return false;
5815 49006 : for (n = nop = 0; nop < static_id->n_operands; nop++)
5816 : {
5817 35238 : if (static_id->operand[nop].type != OP_IN)
5818 12699 : continue;
5819 22539 : op = *id->operand_loc[nop];
5820 22539 : if (!REG_P (op) || REGNO (op) != REGNO (from_reg))
5821 8968 : continue;
5822 13571 : *id->operand_loc[nop] = to_reg;
5823 13571 : changed_nops[n++] = nop;
5824 : }
5825 13768 : changed_nops[n] = -1;
5826 13768 : lra_update_dups (id, changed_nops);
5827 13768 : lra_update_insn_regno_info (to);
5828 13768 : ok_p = recog_memoized (to) >= 0;
5829 13768 : if (ok_p)
5830 : {
5831 : /* Check that combined insn does not need any reloads: */
5832 13749 : saved_insn = curr_insn;
5833 13749 : curr_insn = to;
5834 13749 : curr_id = lra_get_insn_recog_data (curr_insn);
5835 13749 : curr_static_id = curr_id->insn_static_data;
5836 13749 : for (bool swapped_p = false;;)
5837 : {
5838 16109 : ok_p = !curr_insn_transform (true);
5839 16109 : if (ok_p || curr_static_id->commutative < 0)
5840 : break;
5841 4720 : swap_operands (curr_static_id->commutative);
5842 4720 : if (lra_dump_file != NULL)
5843 : {
5844 0 : fprintf (lra_dump_file,
5845 : " Swapping %scombined insn operands:\n",
5846 : swapped_p ? "back " : "");
5847 0 : dump_insn_slim (lra_dump_file, to);
5848 : }
5849 4720 : if (swapped_p)
5850 : break;
5851 : swapped_p = true;
5852 : }
5853 13749 : curr_insn = saved_insn;
5854 13749 : curr_id = lra_get_insn_recog_data (curr_insn);
5855 13749 : curr_static_id = curr_id->insn_static_data;
5856 : }
5857 13768 : if (ok_p)
5858 : {
5859 3586 : id->used_insn_alternative = -1;
5860 3586 : lra_push_insn_and_update_insn_regno_info (to);
5861 3586 : if (lra_dump_file != NULL)
5862 : {
5863 0 : fprintf (lra_dump_file, " Use combined insn:\n");
5864 0 : dump_insn_slim (lra_dump_file, to);
5865 : }
5866 3586 : return true;
5867 : }
5868 10182 : if (lra_dump_file != NULL)
5869 : {
5870 0 : fprintf (lra_dump_file, " Failed combined insn:\n");
5871 0 : dump_insn_slim (lra_dump_file, to);
5872 : }
5873 20635 : for (int i = 0; i < n; i++)
5874 : {
5875 10453 : nop = changed_nops[i];
5876 10453 : *id->operand_loc[nop] = from_reg;
5877 : }
5878 10182 : lra_update_dups (id, changed_nops);
5879 10182 : lra_update_insn_regno_info (to);
5880 10182 : if (lra_dump_file != NULL)
5881 : {
5882 0 : fprintf (lra_dump_file, " Restoring insn after failed combining:\n");
5883 0 : dump_insn_slim (lra_dump_file, to);
5884 : }
5885 : return false;
5886 : }
5887 :
5888 : /* Entry function of LRA constraint pass. Return true if the
5889 : constraint pass did change the code. */
5890 : bool
5891 3276878 : lra_constraints (bool first_p)
5892 : {
5893 3276878 : bool changed_p;
5894 3276878 : int i, hard_regno, new_insns_num;
5895 3276878 : unsigned int min_len, new_min_len, uid;
5896 3276878 : rtx set, x, reg, nosubreg_dest;
5897 3276878 : rtx_insn *original_insn;
5898 3276878 : basic_block last_bb;
5899 3276878 : bitmap_iterator bi;
5900 :
5901 3276878 : lra_constraint_iter++;
5902 3276878 : if (lra_dump_file != NULL)
5903 194 : fprintf (lra_dump_file, "\n********** Local #%d: **********\n\n",
5904 : lra_constraint_iter);
5905 3276878 : changed_p = false;
5906 3276878 : if (pic_offset_table_rtx
5907 3276878 : && REGNO (pic_offset_table_rtx) >= FIRST_PSEUDO_REGISTER)
5908 104771 : check_and_force_assignment_correctness_p = true;
5909 3172107 : else if (first_p)
5910 : /* On the first iteration we should check IRA assignment
5911 : correctness. In rare cases, the assignments can be wrong as
5912 : early clobbers operands are ignored in IRA or usages of
5913 : paradoxical sub-registers are not taken into account by
5914 : IRA. */
5915 1464430 : check_and_force_assignment_correctness_p = true;
5916 3276878 : new_insn_uid_start = get_max_uid ();
5917 3276878 : new_regno_start = first_p ? lra_constraint_new_regno_start : max_reg_num ();
5918 : /* Mark used hard regs for target stack size calculations. */
5919 210092017 : for (i = FIRST_PSEUDO_REGISTER; i < new_regno_start; i++)
5920 206815139 : if (lra_reg_info[i].nrefs != 0
5921 305095240 : && (hard_regno = lra_get_regno_hard_regno (i)) >= 0)
5922 : {
5923 94326153 : int j, nregs;
5924 :
5925 94326153 : nregs = hard_regno_nregs (hard_regno, lra_reg_info[i].biggest_mode);
5926 191719606 : for (j = 0; j < nregs; j++)
5927 97393453 : df_set_regs_ever_live (hard_regno + j, true);
5928 : }
5929 : /* Do elimination before the equivalence processing as we can spill
5930 : some pseudos during elimination. */
5931 3276878 : lra_eliminate (false, first_p);
5932 3276878 : auto_bitmap equiv_insn_bitmap (®_obstack);
5933 :
5934 : /* Register elimination can create new pseudos via the addptr pattern,
5935 : so make sure the equivalency tables are resized appropriately. */
5936 3276878 : ira_expand_reg_equiv ();
5937 210092017 : for (i = FIRST_PSEUDO_REGISTER; i < new_regno_start; i++)
5938 206815139 : if (lra_reg_info[i].nrefs != 0)
5939 : {
5940 98280101 : ira_reg_equiv[i].profitable_p = true;
5941 98280101 : reg = regno_reg_rtx[i];
5942 98280101 : if (lra_get_regno_hard_regno (i) < 0 && (x = get_equiv (reg)) != reg)
5943 : {
5944 746594 : bool pseudo_p = contains_reg_p (x, false, false);
5945 :
5946 : /* After RTL transformation, we cannot guarantee that
5947 : pseudo in the substitution was not reloaded which might
5948 : make equivalence invalid. For example, in reverse
5949 : equiv of p0
5950 :
5951 : p0 <- ...
5952 : ...
5953 : equiv_mem <- p0
5954 :
5955 : the memory address register was reloaded before the 2nd
5956 : insn. */
5957 746594 : if ((! first_p && pseudo_p)
5958 : /* We don't use DF for compilation speed sake. So it
5959 : is problematic to update live info when we use an
5960 : equivalence containing pseudos in more than one
5961 : BB. */
5962 740265 : || (pseudo_p && multi_block_pseudo_p (i))
5963 : /* If an init insn was deleted for some reason, cancel
5964 : the equiv. We could update the equiv insns after
5965 : transformations including an equiv insn deletion
5966 : but it is not worthy as such cases are extremely
5967 : rare. */
5968 735446 : || contains_deleted_insn_p (ira_reg_equiv[i].init_insns)
5969 : /* If it is not a reverse equivalence, we check that a
5970 : pseudo in rhs of the init insn is not dying in the
5971 : insn. Otherwise, the live info at the beginning of
5972 : the corresponding BB might be wrong after we
5973 : removed the insn. When the equiv can be a
5974 : constant, the right hand side of the init insn can
5975 : be a pseudo. */
5976 735446 : || (! reverse_equiv_p (i)
5977 733873 : && (init_insn_rhs_dead_pseudo_p (i)
5978 : /* If we reloaded the pseudo in an equivalence
5979 : init insn, we cannot remove the equiv init
5980 : insns and the init insns might write into
5981 : const memory in this case. */
5982 727249 : || contains_reloaded_insn_p (i)))
5983 : /* Prevent access beyond equivalent memory for
5984 : paradoxical subregs. */
5985 728822 : || (MEM_P (x)
5986 1164963 : && maybe_gt (GET_MODE_SIZE (lra_reg_info[i].biggest_mode),
5987 : GET_MODE_SIZE (GET_MODE (x))))
5988 1474700 : || (pic_offset_table_rtx
5989 53754 : && ((CONST_POOL_OK_P (PSEUDO_REGNO_MODE (i), x)
5990 8816 : && (targetm.preferred_reload_class
5991 4408 : (x, lra_get_allocno_class (i)) == NO_REGS))
5992 51823 : || contains_symbol_ref_p (x))))
5993 21192 : ira_reg_equiv[i].defined_p
5994 21192 : = ira_reg_equiv[i].caller_save_p = false;
5995 746594 : if (contains_reg_p (x, false, true))
5996 9222 : ira_reg_equiv[i].profitable_p = false;
5997 746594 : if (get_equiv (reg) != reg)
5998 720648 : bitmap_ior_into (equiv_insn_bitmap, &lra_reg_info[i].insn_bitmap);
5999 : }
6000 : }
6001 210092017 : for (i = FIRST_PSEUDO_REGISTER; i < new_regno_start; i++)
6002 206815139 : update_equiv (i);
6003 : /* We should add all insns containing pseudos which should be
6004 : substituted by their equivalences. */
6005 5689206 : EXECUTE_IF_SET_IN_BITMAP (equiv_insn_bitmap, 0, uid, bi)
6006 2412328 : lra_push_insn_by_uid (uid);
6007 3276878 : min_len = lra_insn_stack_length ();
6008 3276878 : new_insns_num = 0;
6009 3276878 : last_bb = NULL;
6010 3276878 : changed_p = false;
6011 3276878 : original_insn = NULL;
6012 171301267 : while ((new_min_len = lra_insn_stack_length ()) != 0)
6013 : {
6014 164747511 : curr_insn = lra_pop_insn ();
6015 164747511 : --new_min_len;
6016 164747511 : curr_bb = BLOCK_FOR_INSN (curr_insn);
6017 164747511 : if (curr_bb != last_bb)
6018 : {
6019 20912264 : last_bb = curr_bb;
6020 20912264 : bb_reload_num = lra_curr_reload_num;
6021 : }
6022 164747511 : if (min_len > new_min_len)
6023 : {
6024 : min_len = new_min_len;
6025 : new_insns_num = 0;
6026 : original_insn = curr_insn;
6027 : }
6028 7457348 : else if (combine_reload_insn (curr_insn, original_insn))
6029 : {
6030 3586 : continue;
6031 : }
6032 7453762 : if (new_insns_num > MAX_RELOAD_INSNS_NUMBER)
6033 0 : internal_error
6034 0 : ("maximum number of generated reload insns per insn achieved (%d)",
6035 : MAX_RELOAD_INSNS_NUMBER);
6036 164743925 : new_insns_num++;
6037 164743925 : if (DEBUG_INSN_P (curr_insn))
6038 : {
6039 : /* We need to check equivalence in debug insn and change
6040 : pseudo to the equivalent value if necessary. */
6041 55257863 : curr_id = lra_get_insn_recog_data (curr_insn);
6042 55257863 : if (bitmap_bit_p (equiv_insn_bitmap, INSN_UID (curr_insn)))
6043 : {
6044 29855 : rtx old = *curr_id->operand_loc[0];
6045 29855 : *curr_id->operand_loc[0]
6046 29855 : = simplify_replace_fn_rtx (old, NULL_RTX,
6047 : loc_equivalence_callback, curr_insn);
6048 29855 : if (old != *curr_id->operand_loc[0])
6049 : {
6050 : /* If we substitute pseudo by shared equivalence, we can fail
6051 : to update LRA reg info and this can result in many
6052 : unexpected consequences. So keep rtl unshared: */
6053 29855 : *curr_id->operand_loc[0]
6054 29855 : = copy_rtx (*curr_id->operand_loc[0]);
6055 29855 : lra_update_insn_regno_info (curr_insn);
6056 29855 : changed_p = true;
6057 : }
6058 : }
6059 : }
6060 109486062 : else if (INSN_P (curr_insn))
6061 : {
6062 108413653 : if ((set = single_set (curr_insn)) != NULL_RTX)
6063 : {
6064 102933559 : nosubreg_dest = SET_DEST (set);
6065 : /* The equivalence pseudo could be set up as SUBREG in a
6066 : case when it is a call restore insn in a mode
6067 : different from the pseudo mode. */
6068 102933559 : if (GET_CODE (nosubreg_dest) == SUBREG)
6069 1218608 : nosubreg_dest = SUBREG_REG (nosubreg_dest);
6070 103640574 : if ((REG_P (nosubreg_dest)
6071 76130167 : && (x = get_equiv (nosubreg_dest)) != nosubreg_dest
6072 : /* Remove insns which set up a pseudo whose value
6073 : cannot be changed. Such insns might be not in
6074 : init_insns because we don't update equiv data
6075 : during insn transformations.
6076 :
6077 : As an example, let suppose that a pseudo got
6078 : hard register and on the 1st pass was not
6079 : changed to equivalent constant. We generate an
6080 : additional insn setting up the pseudo because of
6081 : secondary memory movement. Then the pseudo is
6082 : spilled and we use the equiv constant. In this
6083 : case we should remove the additional insn and
6084 : this insn is not init_insns list. */
6085 724998 : && (! MEM_P (x) || MEM_READONLY_P (x)
6086 : /* Check that this is actually an insn setting
6087 : up the equivalence. */
6088 329724 : || in_list_p (curr_insn,
6089 329724 : ira_reg_equiv
6090 329724 : [REGNO (nosubreg_dest)].init_insns)))
6091 178358206 : || (((x = get_equiv (SET_SRC (set))) != SET_SRC (set))
6092 2074458 : && in_list_p (curr_insn,
6093 1037229 : ira_reg_equiv
6094 1037229 : [REGNO (SET_SRC (set))].init_insns)
6095 : /* This is a reverse equivalence to memory (see ira.cc)
6096 : in store insn. We can reload all the destination and
6097 : have an output reload which is a store to memory. If
6098 : we just remove the insn, we will have the output
6099 : reload storing an undefined value to the memory.
6100 : Check that we did not reload the memory to prevent a
6101 : wrong code generation. We could implement using the
6102 : equivalence still in such case but doing this is not
6103 : worth the efforts as such case is very rare. */
6104 1495 : && MEM_P (nosubreg_dest)))
6105 : {
6106 : /* This is equiv init insn of pseudo which did not get a
6107 : hard register -- remove the insn. */
6108 707015 : if (lra_dump_file != NULL)
6109 : {
6110 9 : fprintf (lra_dump_file,
6111 : " Removing equiv init insn %i (freq=%d)\n",
6112 3 : INSN_UID (curr_insn),
6113 6 : REG_FREQ_FROM_BB (BLOCK_FOR_INSN (curr_insn)));
6114 3 : dump_insn_slim (lra_dump_file, curr_insn);
6115 : }
6116 707015 : if (contains_reg_p (x, true, false))
6117 142513 : check_and_force_assignment_correctness_p = true;
6118 707015 : lra_set_insn_deleted (curr_insn);
6119 707015 : continue;
6120 : }
6121 : }
6122 107706638 : curr_id = lra_get_insn_recog_data (curr_insn);
6123 107706638 : curr_static_id = curr_id->insn_static_data;
6124 107706638 : init_curr_insn_input_reloads ();
6125 107706638 : init_curr_operand_mode ();
6126 107706638 : if (curr_insn_transform (false))
6127 : changed_p = true;
6128 : /* Check non-transformed insns too for equiv change as USE
6129 : or CLOBBER don't need reloads but can contain pseudos
6130 : being changed on their equivalences. */
6131 101460464 : else if (bitmap_bit_p (equiv_insn_bitmap, INSN_UID (curr_insn))
6132 101460464 : && loc_equivalence_change_p (&PATTERN (curr_insn)))
6133 : {
6134 8 : lra_update_insn_regno_info (curr_insn);
6135 8 : lra_push_insn_by_uid (INSN_UID (curr_insn));
6136 8 : changed_p = true;
6137 : }
6138 : }
6139 : }
6140 :
6141 : /* If we used a new hard regno, changed_p should be true because the
6142 : hard reg is assigned to a new pseudo. */
6143 3276878 : if (flag_checking && !changed_p)
6144 : {
6145 135391766 : for (i = FIRST_PSEUDO_REGISTER; i < new_regno_start; i++)
6146 132734855 : if (lra_reg_info[i].nrefs != 0
6147 193843973 : && (hard_regno = lra_get_regno_hard_regno (i)) >= 0)
6148 : {
6149 59645680 : int j, nregs = hard_regno_nregs (hard_regno,
6150 59645680 : PSEUDO_REGNO_MODE (i));
6151 :
6152 121328702 : for (j = 0; j < nregs; j++)
6153 61683022 : lra_assert (df_regs_ever_live_p (hard_regno + j));
6154 : }
6155 : }
6156 2656951 : if (changed_p)
6157 619930 : lra_dump_insns_if_possible ("changed func after local");
6158 3276878 : return changed_p;
6159 3276878 : }
6160 :
6161 : static void initiate_invariants (void);
6162 : static void finish_invariants (void);
6163 :
6164 : /* Initiate the LRA constraint pass. It is done once per
6165 : function. */
6166 : void
6167 1504950 : lra_constraints_init (void)
6168 : {
6169 1504950 : initiate_invariants ();
6170 1504950 : }
6171 :
6172 : /* Finalize the LRA constraint pass. It is done once per
6173 : function. */
6174 : void
6175 1504950 : lra_constraints_finish (void)
6176 : {
6177 1504950 : finish_invariants ();
6178 1504950 : }
6179 :
6180 :
6181 :
6182 : /* Structure describes invariants for ineheritance. */
6183 : struct lra_invariant
6184 : {
6185 : /* The order number of the invariant. */
6186 : int num;
6187 : /* The invariant RTX. */
6188 : rtx invariant_rtx;
6189 : /* The origin insn of the invariant. */
6190 : rtx_insn *insn;
6191 : };
6192 :
6193 : typedef lra_invariant invariant_t;
6194 : typedef invariant_t *invariant_ptr_t;
6195 : typedef const invariant_t *const_invariant_ptr_t;
6196 :
6197 : /* Pointer to the inheritance invariants. */
6198 : static vec<invariant_ptr_t> invariants;
6199 :
6200 : /* Allocation pool for the invariants. */
6201 : static object_allocator<lra_invariant> *invariants_pool;
6202 :
6203 : /* Hash table for the invariants. */
6204 : static htab_t invariant_table;
6205 :
6206 : /* Hash function for INVARIANT. */
6207 : static hashval_t
6208 181119 : invariant_hash (const void *invariant)
6209 : {
6210 181119 : rtx inv = ((const_invariant_ptr_t) invariant)->invariant_rtx;
6211 181119 : return lra_rtx_hash (inv);
6212 : }
6213 :
6214 : /* Equal function for invariants INVARIANT1 and INVARIANT2. */
6215 : static int
6216 59441 : invariant_eq_p (const void *invariant1, const void *invariant2)
6217 : {
6218 59441 : rtx inv1 = ((const_invariant_ptr_t) invariant1)->invariant_rtx;
6219 59441 : rtx inv2 = ((const_invariant_ptr_t) invariant2)->invariant_rtx;
6220 :
6221 59441 : return rtx_equal_p (inv1, inv2);
6222 : }
6223 :
6224 : /* Insert INVARIANT_RTX into the table if it is not there yet. Return
6225 : invariant which is in the table. */
6226 : static invariant_ptr_t
6227 180927 : insert_invariant (rtx invariant_rtx)
6228 : {
6229 180927 : void **entry_ptr;
6230 180927 : invariant_t invariant;
6231 180927 : invariant_ptr_t invariant_ptr;
6232 :
6233 180927 : invariant.invariant_rtx = invariant_rtx;
6234 180927 : entry_ptr = htab_find_slot (invariant_table, &invariant, INSERT);
6235 180927 : if (*entry_ptr == NULL)
6236 : {
6237 157064 : invariant_ptr = invariants_pool->allocate ();
6238 157064 : invariant_ptr->invariant_rtx = invariant_rtx;
6239 157064 : invariant_ptr->insn = NULL;
6240 157064 : invariants.safe_push (invariant_ptr);
6241 157064 : *entry_ptr = (void *) invariant_ptr;
6242 : }
6243 180927 : return (invariant_ptr_t) *entry_ptr;
6244 : }
6245 :
6246 : /* Initiate the invariant table. */
6247 : static void
6248 1504950 : initiate_invariants (void)
6249 : {
6250 1504950 : invariants.create (100);
6251 1504950 : invariants_pool
6252 1504950 : = new object_allocator<lra_invariant> ("Inheritance invariants");
6253 1504950 : invariant_table = htab_create (100, invariant_hash, invariant_eq_p, NULL);
6254 1504950 : }
6255 :
6256 : /* Finish the invariant table. */
6257 : static void
6258 1504950 : finish_invariants (void)
6259 : {
6260 1504950 : htab_delete (invariant_table);
6261 3009900 : delete invariants_pool;
6262 1504950 : invariants.release ();
6263 1504950 : }
6264 :
6265 : /* Make the invariant table empty. */
6266 : static void
6267 12765602 : clear_invariants (void)
6268 : {
6269 12765602 : htab_empty (invariant_table);
6270 12765602 : invariants_pool->release ();
6271 12765602 : invariants.truncate (0);
6272 12765602 : }
6273 :
6274 :
6275 :
6276 : /* This page contains code to do inheritance/split
6277 : transformations. */
6278 :
6279 : /* Number of reloads passed so far in current EBB. */
6280 : static int reloads_num;
6281 :
6282 : /* Number of calls passed so far in current EBB. */
6283 : static int calls_num;
6284 :
6285 : /* Index ID is the CALLS_NUM associated the last call we saw with
6286 : ABI identifier ID. */
6287 : static int last_call_for_abi[NUM_ABI_IDS];
6288 :
6289 : /* Which registers have been fully or partially clobbered by a call
6290 : since they were last used. */
6291 : static HARD_REG_SET full_and_partial_call_clobbers;
6292 :
6293 : /* Current reload pseudo check for validity of elements in
6294 : USAGE_INSNS. */
6295 : static int curr_usage_insns_check;
6296 :
6297 : /* Info about last usage of registers in EBB to do inheritance/split
6298 : transformation. Inheritance transformation is done from a spilled
6299 : pseudo and split transformations from a hard register or a pseudo
6300 : assigned to a hard register. */
6301 : struct usage_insns
6302 : {
6303 : /* If the value is equal to CURR_USAGE_INSNS_CHECK, then the member
6304 : value INSNS is valid. The insns is chain of optional debug insns
6305 : and a finishing non-debug insn using the corresponding reg. The
6306 : value is also used to mark the registers which are set up in the
6307 : current insn. The negated insn uid is used for this. */
6308 : int check;
6309 : /* Value of global reloads_num at the last insn in INSNS. */
6310 : int reloads_num;
6311 : /* Value of global reloads_nums at the last insn in INSNS. */
6312 : int calls_num;
6313 : /* It can be true only for splitting. And it means that the restore
6314 : insn should be put after insn given by the following member. */
6315 : bool after_p;
6316 : /* Next insns in the current EBB which use the original reg and the
6317 : original reg value is not changed between the current insn and
6318 : the next insns. In order words, e.g. for inheritance, if we need
6319 : to use the original reg value again in the next insns we can try
6320 : to use the value in a hard register from a reload insn of the
6321 : current insn. */
6322 : rtx insns;
6323 : };
6324 :
6325 : /* Map: regno -> corresponding pseudo usage insns. */
6326 : static struct usage_insns *usage_insns;
6327 :
6328 : static void
6329 248895917 : setup_next_usage_insn (int regno, rtx insn, int reloads_num, bool after_p)
6330 : {
6331 248895917 : usage_insns[regno].check = curr_usage_insns_check;
6332 248895917 : usage_insns[regno].insns = insn;
6333 248895917 : usage_insns[regno].reloads_num = reloads_num;
6334 248895917 : usage_insns[regno].calls_num = calls_num;
6335 248895917 : usage_insns[regno].after_p = after_p;
6336 248895917 : if (regno >= FIRST_PSEUDO_REGISTER && reg_renumber[regno] >= 0)
6337 111866663 : remove_from_hard_reg_set (&full_and_partial_call_clobbers,
6338 111866663 : PSEUDO_REGNO_MODE (regno),
6339 : reg_renumber[regno]);
6340 248895917 : }
6341 :
6342 : /* The function is used to form list REGNO usages which consists of
6343 : optional debug insns finished by a non-debug insn using REGNO.
6344 : RELOADS_NUM is current number of reload insns processed so far. */
6345 : static void
6346 141628531 : add_next_usage_insn (int regno, rtx_insn *insn, int reloads_num)
6347 : {
6348 141628531 : rtx next_usage_insns;
6349 :
6350 141628531 : if (usage_insns[regno].check == curr_usage_insns_check
6351 74030635 : && (next_usage_insns = usage_insns[regno].insns) != NULL_RTX
6352 215659166 : && DEBUG_INSN_P (insn))
6353 : {
6354 : /* Check that we did not add the debug insn yet. */
6355 14371306 : if (next_usage_insns != insn
6356 14371306 : && (GET_CODE (next_usage_insns) != INSN_LIST
6357 6556699 : || XEXP (next_usage_insns, 0) != insn))
6358 14371292 : usage_insns[regno].insns = gen_rtx_INSN_LIST (VOIDmode, insn,
6359 : next_usage_insns);
6360 : }
6361 127257225 : else if (NONDEBUG_INSN_P (insn))
6362 126742051 : setup_next_usage_insn (regno, insn, reloads_num, false);
6363 : else
6364 515174 : usage_insns[regno].check = 0;
6365 141628531 : }
6366 :
6367 : /* Return first non-debug insn in list USAGE_INSNS. */
6368 : static rtx_insn *
6369 1175049 : skip_usage_debug_insns (rtx usage_insns)
6370 : {
6371 1175049 : rtx insn;
6372 :
6373 : /* Skip debug insns. */
6374 1175049 : for (insn = usage_insns;
6375 1469954 : insn != NULL_RTX && GET_CODE (insn) == INSN_LIST;
6376 294905 : insn = XEXP (insn, 1))
6377 : ;
6378 1175049 : return safe_as_a <rtx_insn *> (insn);
6379 : }
6380 :
6381 : /* Return true if we need secondary memory moves for insn in
6382 : USAGE_INSNS after inserting inherited pseudo of class INHER_CL
6383 : into the insn. */
6384 : static bool
6385 1175056 : check_secondary_memory_needed_p (enum reg_class inher_cl ATTRIBUTE_UNUSED,
6386 : rtx usage_insns ATTRIBUTE_UNUSED)
6387 : {
6388 1175056 : rtx_insn *insn;
6389 1175056 : rtx set, dest;
6390 1175056 : enum reg_class cl;
6391 :
6392 1175056 : if (inher_cl == ALL_REGS
6393 1175056 : || (insn = skip_usage_debug_insns (usage_insns)) == NULL_RTX)
6394 : return false;
6395 1175049 : lra_assert (INSN_P (insn));
6396 1175049 : if ((set = single_set (insn)) == NULL_RTX || ! REG_P (SET_DEST (set)))
6397 : return false;
6398 1136910 : dest = SET_DEST (set);
6399 1136910 : if (! REG_P (dest))
6400 : return false;
6401 1136910 : lra_assert (inher_cl != NO_REGS);
6402 1136910 : cl = get_reg_class (REGNO (dest));
6403 1136910 : return (cl != NO_REGS && cl != ALL_REGS
6404 1136910 : && targetm.secondary_memory_needed (GET_MODE (dest), inher_cl, cl));
6405 : }
6406 :
6407 : /* Registers involved in inheritance/split in the current EBB
6408 : (inheritance/split pseudos and original registers). */
6409 : static bitmap_head check_only_regs;
6410 :
6411 : /* Reload pseudos cannot be involded in invariant inheritance in the
6412 : current EBB. */
6413 : static bitmap_head invalid_invariant_regs;
6414 :
6415 : /* Do inheritance transformations for insn INSN, which defines (if
6416 : DEF_P) or uses ORIGINAL_REGNO. NEXT_USAGE_INSNS specifies which
6417 : instruction in the EBB next uses ORIGINAL_REGNO; it has the same
6418 : form as the "insns" field of usage_insns. Return true if we
6419 : succeed in such transformation.
6420 :
6421 : The transformations look like:
6422 :
6423 : p <- ... i <- ...
6424 : ... p <- i (new insn)
6425 : ... =>
6426 : <- ... p ... <- ... i ...
6427 : or
6428 : ... i <- p (new insn)
6429 : <- ... p ... <- ... i ...
6430 : ... =>
6431 : <- ... p ... <- ... i ...
6432 : where p is a spilled original pseudo and i is a new inheritance pseudo.
6433 :
6434 :
6435 : The inheritance pseudo has the smallest class of two classes CL and
6436 : class of ORIGINAL REGNO. */
6437 : static bool
6438 1270120 : inherit_reload_reg (bool def_p, int original_regno,
6439 : enum reg_class cl, rtx_insn *insn, rtx next_usage_insns)
6440 : {
6441 1270120 : if (optimize_function_for_size_p (cfun))
6442 : return false;
6443 :
6444 1239188 : enum reg_class rclass = lra_get_allocno_class (original_regno);
6445 1239188 : rtx original_reg = regno_reg_rtx[original_regno];
6446 1239188 : rtx new_reg, usage_insn;
6447 1239188 : rtx_insn *new_insns;
6448 :
6449 1239188 : lra_assert (! usage_insns[original_regno].after_p);
6450 1239188 : if (lra_dump_file != NULL)
6451 2 : fprintf (lra_dump_file,
6452 : " <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n");
6453 1239188 : if (! ira_reg_classes_intersect_p[cl][rclass])
6454 : {
6455 64132 : if (lra_dump_file != NULL)
6456 : {
6457 0 : fprintf (lra_dump_file,
6458 : " Rejecting inheritance for %d "
6459 : "because of disjoint classes %s and %s\n",
6460 : original_regno, reg_class_names[cl],
6461 : reg_class_names[rclass]);
6462 0 : fprintf (lra_dump_file,
6463 : " >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n");
6464 : }
6465 64132 : return false;
6466 : }
6467 1175056 : if ((ira_class_subset_p[cl][rclass] && cl != rclass)
6468 : /* We don't use a subset of two classes because it can be
6469 : NO_REGS. This transformation is still profitable in most
6470 : cases even if the classes are not intersected as register
6471 : move is probably cheaper than a memory load. */
6472 442162 : || ira_class_hard_regs_num[cl] < ira_class_hard_regs_num[rclass])
6473 : {
6474 732894 : if (lra_dump_file != NULL)
6475 2 : fprintf (lra_dump_file, " Use smallest class of %s and %s\n",
6476 : reg_class_names[cl], reg_class_names[rclass]);
6477 :
6478 : rclass = cl;
6479 : }
6480 1175056 : if (check_secondary_memory_needed_p (rclass, next_usage_insns))
6481 : {
6482 : /* Reject inheritance resulting in secondary memory moves.
6483 : Otherwise, there is a danger in LRA cycling. Also such
6484 : transformation will be unprofitable. */
6485 13895 : if (lra_dump_file != NULL)
6486 : {
6487 0 : rtx_insn *insn = skip_usage_debug_insns (next_usage_insns);
6488 0 : rtx set = single_set (insn);
6489 :
6490 0 : lra_assert (set != NULL_RTX);
6491 :
6492 0 : rtx dest = SET_DEST (set);
6493 :
6494 0 : lra_assert (REG_P (dest));
6495 0 : fprintf (lra_dump_file,
6496 : " Rejecting inheritance for insn %d(%s)<-%d(%s) "
6497 : "as secondary mem is needed\n",
6498 0 : REGNO (dest), reg_class_names[get_reg_class (REGNO (dest))],
6499 0 : original_regno, reg_class_names[rclass]);
6500 0 : fprintf (lra_dump_file,
6501 : " >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n");
6502 : }
6503 13895 : return false;
6504 : }
6505 1161161 : if (ira_reg_class_min_nregs[rclass][GET_MODE (original_reg)]
6506 1161161 : != ira_reg_class_max_nregs[rclass][GET_MODE (original_reg)])
6507 : {
6508 24 : if (lra_dump_file != NULL)
6509 : {
6510 0 : fprintf (lra_dump_file,
6511 : " Rejecting inheritance for %d "
6512 : "because of requiring non-uniform class %s\n",
6513 : original_regno, reg_class_names[rclass]);
6514 0 : fprintf (lra_dump_file,
6515 : " >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n");
6516 : }
6517 24 : return false;
6518 : }
6519 1161137 : new_reg = lra_create_new_reg (GET_MODE (original_reg), original_reg,
6520 : rclass, NULL, "inheritance");
6521 1161137 : start_sequence ();
6522 1161137 : if (def_p)
6523 548113 : lra_emit_move (original_reg, new_reg);
6524 : else
6525 613024 : lra_emit_move (new_reg, original_reg);
6526 1161137 : new_insns = end_sequence ();
6527 1161137 : if (NEXT_INSN (new_insns) != NULL_RTX)
6528 : {
6529 0 : if (lra_dump_file != NULL)
6530 : {
6531 0 : fprintf (lra_dump_file,
6532 : " Rejecting inheritance %d->%d "
6533 : "as it results in 2 or more insns:\n",
6534 : original_regno, REGNO (new_reg));
6535 0 : dump_rtl_slim (lra_dump_file, new_insns, NULL, -1, 0);
6536 0 : fprintf (lra_dump_file,
6537 : " >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n");
6538 : }
6539 0 : return false;
6540 : }
6541 1161137 : lra_substitute_pseudo_within_insn (insn, original_regno, new_reg, false);
6542 1161137 : lra_update_insn_regno_info (insn);
6543 1161137 : if (! def_p)
6544 : /* We now have a new usage insn for original regno. */
6545 613024 : setup_next_usage_insn (original_regno, new_insns, reloads_num, false);
6546 1161137 : if (lra_dump_file != NULL)
6547 2 : fprintf (lra_dump_file, " Original reg change %d->%d (bb%d):\n",
6548 2 : original_regno, REGNO (new_reg), BLOCK_FOR_INSN (insn)->index);
6549 1161137 : lra_reg_info[REGNO (new_reg)].restore_rtx = regno_reg_rtx[original_regno];
6550 1161137 : bitmap_set_bit (&check_only_regs, REGNO (new_reg));
6551 1161137 : bitmap_set_bit (&check_only_regs, original_regno);
6552 1161137 : bitmap_set_bit (&lra_inheritance_pseudos, REGNO (new_reg));
6553 1161137 : if (def_p)
6554 548113 : lra_process_new_insns (insn, NULL, new_insns,
6555 : "Add original<-inheritance");
6556 : else
6557 613024 : lra_process_new_insns (insn, new_insns, NULL,
6558 : "Add inheritance<-original");
6559 2614811 : while (next_usage_insns != NULL_RTX)
6560 : {
6561 1453674 : if (GET_CODE (next_usage_insns) != INSN_LIST)
6562 : {
6563 1161137 : usage_insn = next_usage_insns;
6564 1161137 : lra_assert (NONDEBUG_INSN_P (usage_insn));
6565 : next_usage_insns = NULL;
6566 : }
6567 : else
6568 : {
6569 292537 : usage_insn = XEXP (next_usage_insns, 0);
6570 292537 : lra_assert (DEBUG_INSN_P (usage_insn));
6571 292537 : next_usage_insns = XEXP (next_usage_insns, 1);
6572 : }
6573 1453674 : lra_substitute_pseudo (&usage_insn, original_regno, new_reg, false,
6574 1453674 : DEBUG_INSN_P (usage_insn));
6575 1453674 : lra_update_insn_regno_info (as_a <rtx_insn *> (usage_insn));
6576 1453674 : if (lra_dump_file != NULL)
6577 : {
6578 2 : basic_block bb = BLOCK_FOR_INSN (usage_insn);
6579 2 : fprintf (lra_dump_file,
6580 : " Inheritance reuse change %d->%d (bb%d):\n",
6581 : original_regno, REGNO (new_reg),
6582 : bb ? bb->index : -1);
6583 2 : dump_insn_slim (lra_dump_file, as_a <rtx_insn *> (usage_insn));
6584 : }
6585 : }
6586 1161137 : if (lra_dump_file != NULL)
6587 2 : fprintf (lra_dump_file,
6588 : " >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n");
6589 : return true;
6590 : }
6591 :
6592 : /* Return true if we need a caller save/restore for pseudo REGNO which
6593 : was assigned to a hard register. */
6594 : static inline bool
6595 114529233 : need_for_call_save_p (int regno)
6596 : {
6597 114529233 : lra_assert (regno >= FIRST_PSEUDO_REGISTER && reg_renumber[regno] >= 0);
6598 114529233 : if (usage_insns[regno].calls_num < calls_num)
6599 : {
6600 : unsigned int abis = 0;
6601 119750605 : for (unsigned int i = 0; i < NUM_ABI_IDS; ++i)
6602 110539020 : if (last_call_for_abi[i] > usage_insns[regno].calls_num)
6603 9260904 : abis |= 1 << i;
6604 9211585 : gcc_assert (abis);
6605 9211585 : if (call_clobbered_in_region_p (abis, full_and_partial_call_clobbers,
6606 9211585 : PSEUDO_REGNO_MODE (regno),
6607 : reg_renumber[regno]))
6608 : return true;
6609 : }
6610 : return false;
6611 : }
6612 :
6613 : /* Global registers occurring in the current EBB. */
6614 : static bitmap_head ebb_global_regs;
6615 :
6616 : /* Return true if we need a split for hard register REGNO or pseudo
6617 : REGNO which was assigned to a hard register.
6618 : POTENTIAL_RELOAD_HARD_REGS contains hard registers which might be
6619 : used for reloads since the EBB end. It is an approximation of the
6620 : used hard registers in the split range. The exact value would
6621 : require expensive calculations. If we were aggressive with
6622 : splitting because of the approximation, the split pseudo will save
6623 : the same hard register assignment and will be removed in the undo
6624 : pass. We still need the approximation because too aggressive
6625 : splitting would result in too inaccurate cost calculation in the
6626 : assignment pass because of too many generated moves which will be
6627 : probably removed in the undo pass. */
6628 : static inline bool
6629 244258513 : need_for_split_p (HARD_REG_SET potential_reload_hard_regs, int regno)
6630 : {
6631 244258513 : int hard_regno = regno < FIRST_PSEUDO_REGISTER ? regno : reg_renumber[regno];
6632 :
6633 244258513 : lra_assert (hard_regno >= 0);
6634 244258513 : return ((TEST_HARD_REG_BIT (potential_reload_hard_regs, hard_regno)
6635 : /* Don't split eliminable hard registers, otherwise we can
6636 : split hard registers like hard frame pointer, which
6637 : lives on BB start/end according to DF-infrastructure,
6638 : when there is a pseudo assigned to the register and
6639 : living in the same BB. */
6640 649752 : && (regno >= FIRST_PSEUDO_REGISTER
6641 44002 : || ! TEST_HARD_REG_BIT (eliminable_regset, hard_regno))
6642 620321 : && ! TEST_HARD_REG_BIT (lra_no_alloc_regs, hard_regno)
6643 : /* Don't split call clobbered hard regs living through
6644 : calls, otherwise we might have a check problem in the
6645 : assign sub-pass as in the most cases (exception is a
6646 : situation when check_and_force_assignment_correctness_p value is
6647 : true) the assign pass assumes that all pseudos living
6648 : through calls are assigned to call saved hard regs. */
6649 606781 : && (regno >= FIRST_PSEUDO_REGISTER
6650 1031 : || !TEST_HARD_REG_BIT (full_and_partial_call_clobbers, regno))
6651 : /* We need at least 2 reloads to make pseudo splitting
6652 : profitable. We should provide hard regno splitting in
6653 : any case to solve 1st insn scheduling problem when
6654 : moving hard register definition up might result in
6655 : impossibility to find hard register for reload pseudo of
6656 : small register class. */
6657 1213506 : && (usage_insns[regno].reloads_num
6658 1212503 : + (regno < FIRST_PSEUDO_REGISTER ? 0 : 3) < reloads_num)
6659 2671 : && (regno < FIRST_PSEUDO_REGISTER
6660 : /* For short living pseudos, spilling + inheritance can
6661 : be considered a substitution for splitting.
6662 : Therefore we do not splitting for local pseudos. It
6663 : decreases also aggressiveness of splitting. The
6664 : minimal number of references is chosen taking into
6665 : account that for 2 references splitting has no sense
6666 : as we can just spill the pseudo. */
6667 : || (regno >= FIRST_PSEUDO_REGISTER
6668 2624 : && lra_reg_info[regno].nrefs > 3
6669 2307 : && bitmap_bit_p (&ebb_global_regs, regno))))
6670 244906924 : || (regno >= FIRST_PSEUDO_REGISTER && need_for_call_save_p (regno)));
6671 : }
6672 :
6673 : /* Return class for the split pseudo created from original pseudo with
6674 : ALLOCNO_CLASS and MODE which got a hard register HARD_REGNO. We
6675 : choose subclass of ALLOCNO_CLASS which contains HARD_REGNO and
6676 : results in no secondary memory movements. */
6677 : static enum reg_class
6678 1500 : choose_split_class (enum reg_class allocno_class,
6679 : int hard_regno ATTRIBUTE_UNUSED,
6680 : machine_mode mode ATTRIBUTE_UNUSED)
6681 : {
6682 1500 : int i;
6683 1500 : enum reg_class cl, best_cl = NO_REGS;
6684 1500 : enum reg_class hard_reg_class ATTRIBUTE_UNUSED
6685 : = REGNO_REG_CLASS (hard_regno);
6686 :
6687 1500 : if (! targetm.secondary_memory_needed (mode, allocno_class, allocno_class)
6688 1500 : && TEST_HARD_REG_BIT (reg_class_contents[allocno_class], hard_regno))
6689 : return allocno_class;
6690 0 : for (i = 0;
6691 0 : (cl = reg_class_subclasses[allocno_class][i]) != LIM_REG_CLASSES;
6692 : i++)
6693 0 : if (! targetm.secondary_memory_needed (mode, cl, hard_reg_class)
6694 0 : && ! targetm.secondary_memory_needed (mode, hard_reg_class, cl)
6695 0 : && TEST_HARD_REG_BIT (reg_class_contents[cl], hard_regno)
6696 0 : && (best_cl == NO_REGS
6697 0 : || ira_class_hard_regs_num[best_cl] < ira_class_hard_regs_num[cl]))
6698 : best_cl = cl;
6699 : return best_cl;
6700 : }
6701 :
6702 : /* Copy any equivalence information from ORIGINAL_REGNO to NEW_REGNO. It only
6703 : makes sense to call this function if NEW_REGNO is always equal to
6704 : ORIGINAL_REGNO. Set up defined_p flag when caller_save_p flag is set up and
6705 : CALL_SAVE_P is true. */
6706 :
6707 : static void
6708 660569 : lra_copy_reg_equiv (unsigned int new_regno, unsigned int original_regno,
6709 : bool call_save_p)
6710 : {
6711 660569 : if (!ira_reg_equiv[original_regno].defined_p
6712 595642 : && !(call_save_p && ira_reg_equiv[original_regno].caller_save_p))
6713 : return;
6714 :
6715 65101 : ira_expand_reg_equiv ();
6716 65101 : ira_reg_equiv[new_regno].defined_p = true;
6717 65101 : if (ira_reg_equiv[original_regno].memory)
6718 32205 : ira_reg_equiv[new_regno].memory
6719 32205 : = copy_rtx (ira_reg_equiv[original_regno].memory);
6720 65101 : if (ira_reg_equiv[original_regno].constant)
6721 26450 : ira_reg_equiv[new_regno].constant
6722 26450 : = copy_rtx (ira_reg_equiv[original_regno].constant);
6723 65101 : if (ira_reg_equiv[original_regno].invariant)
6724 6446 : ira_reg_equiv[new_regno].invariant
6725 6446 : = copy_rtx (ira_reg_equiv[original_regno].invariant);
6726 : }
6727 :
6728 : /* Do split transformations for insn INSN, which defines or uses
6729 : ORIGINAL_REGNO. NEXT_USAGE_INSNS specifies which instruction in
6730 : the EBB next uses ORIGINAL_REGNO; it has the same form as the
6731 : "insns" field of usage_insns. If TO is not NULL, we don't use
6732 : usage_insns, we put restore insns after TO insn. It is a case when
6733 : we call it from lra_split_hard_reg_for, outside the inheritance
6734 : pass.
6735 :
6736 : The transformations look like:
6737 :
6738 : p <- ... p <- ...
6739 : ... s <- p (new insn -- save)
6740 : ... =>
6741 : ... p <- s (new insn -- restore)
6742 : <- ... p ... <- ... p ...
6743 : or
6744 : <- ... p ... <- ... p ...
6745 : ... s <- p (new insn -- save)
6746 : ... =>
6747 : ... p <- s (new insn -- restore)
6748 : <- ... p ... <- ... p ...
6749 :
6750 : where p is an original pseudo got a hard register or a hard
6751 : register and s is a new split pseudo. The save is put before INSN
6752 : if BEFORE_P is true. Return true if we succeed in such
6753 : transformation. */
6754 : static bool
6755 662257 : split_reg (bool before_p, int original_regno, rtx_insn *insn,
6756 : rtx next_usage_insns, rtx_insn *to)
6757 : {
6758 662257 : enum reg_class rclass;
6759 662257 : rtx original_reg;
6760 662257 : int hard_regno, nregs;
6761 662257 : rtx new_reg, usage_insn;
6762 662257 : rtx_insn *restore, *save;
6763 662257 : bool after_p;
6764 662257 : bool call_save_p;
6765 662257 : machine_mode mode;
6766 :
6767 662257 : if (original_regno < FIRST_PSEUDO_REGISTER)
6768 : {
6769 206 : rclass = ira_allocno_class_translate[REGNO_REG_CLASS (original_regno)];
6770 206 : hard_regno = original_regno;
6771 206 : call_save_p = false;
6772 206 : nregs = 1;
6773 206 : mode = lra_reg_info[hard_regno].biggest_mode;
6774 206 : machine_mode reg_rtx_mode = GET_MODE (regno_reg_rtx[hard_regno]);
6775 : /* A reg can have a biggest_mode of VOIDmode if it was only ever seen as
6776 : part of a multi-word register. In that case, just use the reg_rtx
6777 : mode. Do the same also if the biggest mode was larger than a register
6778 : or we can not compare the modes. Otherwise, limit the size to that of
6779 : the biggest access in the function or to the natural mode at least. */
6780 206 : if (mode == VOIDmode
6781 206 : || !ordered_p (GET_MODE_PRECISION (mode),
6782 206 : GET_MODE_PRECISION (reg_rtx_mode))
6783 206 : || paradoxical_subreg_p (mode, reg_rtx_mode)
6784 411 : || maybe_gt (GET_MODE_PRECISION (reg_rtx_mode), GET_MODE_PRECISION (mode)))
6785 : {
6786 662257 : original_reg = regno_reg_rtx[hard_regno];
6787 662257 : mode = reg_rtx_mode;
6788 : }
6789 : else
6790 189 : original_reg = gen_rtx_REG (mode, hard_regno);
6791 : }
6792 : else
6793 : {
6794 662051 : mode = PSEUDO_REGNO_MODE (original_regno);
6795 662051 : hard_regno = reg_renumber[original_regno];
6796 662051 : nregs = hard_regno_nregs (hard_regno, mode);
6797 662051 : rclass = lra_get_allocno_class (original_regno);
6798 662051 : original_reg = regno_reg_rtx[original_regno];
6799 662051 : call_save_p = need_for_call_save_p (original_regno);
6800 : }
6801 662257 : lra_assert (hard_regno >= 0);
6802 662257 : if (lra_dump_file != NULL)
6803 0 : fprintf (lra_dump_file,
6804 : " ((((((((((((((((((((((((((((((((((((((((((((((((\n");
6805 :
6806 662257 : if (call_save_p)
6807 : {
6808 660757 : mode = HARD_REGNO_CALLER_SAVE_MODE (hard_regno,
6809 : hard_regno_nregs (hard_regno, mode),
6810 : mode);
6811 660757 : new_reg = lra_create_new_reg (mode, NULL_RTX, NO_REGS, NULL, "save");
6812 : }
6813 : else
6814 : {
6815 1500 : rclass = choose_split_class (rclass, hard_regno, mode);
6816 1500 : if (rclass == NO_REGS)
6817 : {
6818 0 : if (lra_dump_file != NULL)
6819 : {
6820 0 : fprintf (lra_dump_file,
6821 : " Rejecting split of %d(%s): "
6822 : "no good reg class for %d(%s)\n",
6823 : original_regno,
6824 0 : reg_class_names[lra_get_allocno_class (original_regno)],
6825 : hard_regno,
6826 0 : reg_class_names[REGNO_REG_CLASS (hard_regno)]);
6827 0 : fprintf
6828 0 : (lra_dump_file,
6829 : " ))))))))))))))))))))))))))))))))))))))))))))))))\n");
6830 : }
6831 0 : return false;
6832 : }
6833 : /* Split_if_necessary can split hard registers used as part of a
6834 : multi-register mode but splits each register individually. The
6835 : mode used for each independent register may not be supported
6836 : so reject the split. Splitting the wider mode should theoretically
6837 : be possible but is not implemented. */
6838 1500 : if (!targetm.hard_regno_mode_ok (hard_regno, mode))
6839 : {
6840 0 : if (lra_dump_file != NULL)
6841 : {
6842 0 : fprintf (lra_dump_file,
6843 : " Rejecting split of %d(%s): unsuitable mode %s\n",
6844 : original_regno,
6845 0 : reg_class_names[lra_get_allocno_class (original_regno)],
6846 0 : GET_MODE_NAME (mode));
6847 0 : fprintf
6848 0 : (lra_dump_file,
6849 : " ))))))))))))))))))))))))))))))))))))))))))))))))\n");
6850 : }
6851 0 : return false;
6852 : }
6853 1500 : new_reg = lra_create_new_reg (mode, original_reg, rclass, NULL, "split");
6854 1500 : reg_renumber[REGNO (new_reg)] = hard_regno;
6855 : }
6856 662257 : int new_regno = REGNO (new_reg);
6857 662257 : save = emit_spill_move (true, new_reg, original_reg);
6858 662257 : if (NEXT_INSN (save) != NULL_RTX && !call_save_p)
6859 : {
6860 0 : if (lra_dump_file != NULL)
6861 : {
6862 0 : fprintf
6863 0 : (lra_dump_file,
6864 : " Rejecting split %d->%d resulting in > 2 save insns:\n",
6865 : original_regno, new_regno);
6866 0 : dump_rtl_slim (lra_dump_file, save, NULL, -1, 0);
6867 0 : fprintf (lra_dump_file,
6868 : " ))))))))))))))))))))))))))))))))))))))))))))))))\n");
6869 : }
6870 0 : return false;
6871 : }
6872 662257 : restore = emit_spill_move (false, new_reg, original_reg);
6873 662257 : if (NEXT_INSN (restore) != NULL_RTX && !call_save_p)
6874 : {
6875 0 : if (lra_dump_file != NULL)
6876 : {
6877 0 : fprintf (lra_dump_file,
6878 : " Rejecting split %d->%d "
6879 : "resulting in > 2 restore insns:\n",
6880 : original_regno, new_regno);
6881 0 : dump_rtl_slim (lra_dump_file, restore, NULL, -1, 0);
6882 0 : fprintf (lra_dump_file,
6883 : " ))))))))))))))))))))))))))))))))))))))))))))))))\n");
6884 : }
6885 0 : return false;
6886 : }
6887 : /* Transfer equivalence information to the spill register, so that
6888 : if we fail to allocate the spill register, we have the option of
6889 : rematerializing the original value instead of spilling to the stack. */
6890 662257 : if (!HARD_REGISTER_NUM_P (original_regno)
6891 662051 : && mode == PSEUDO_REGNO_MODE (original_regno))
6892 660569 : lra_copy_reg_equiv (new_regno, original_regno, call_save_p);
6893 662257 : lra_reg_info[new_regno].restore_rtx = regno_reg_rtx[original_regno];
6894 662257 : bitmap_set_bit (&lra_split_regs, new_regno);
6895 662257 : if (to != NULL)
6896 : {
6897 159 : lra_assert (next_usage_insns == NULL);
6898 159 : usage_insn = to;
6899 159 : after_p = true;
6900 : }
6901 : else
6902 : {
6903 : /* We need check_only_regs only inside the inheritance pass. */
6904 662098 : bitmap_set_bit (&check_only_regs, new_regno);
6905 662098 : bitmap_set_bit (&check_only_regs, original_regno);
6906 662098 : after_p = usage_insns[original_regno].after_p;
6907 764738 : for (;;)
6908 : {
6909 764738 : if (GET_CODE (next_usage_insns) != INSN_LIST)
6910 : {
6911 662098 : usage_insn = next_usage_insns;
6912 662098 : break;
6913 : }
6914 102640 : usage_insn = XEXP (next_usage_insns, 0);
6915 102640 : lra_assert (DEBUG_INSN_P (usage_insn));
6916 102640 : next_usage_insns = XEXP (next_usage_insns, 1);
6917 102640 : lra_substitute_pseudo (&usage_insn, original_regno, new_reg, false,
6918 : true);
6919 102640 : lra_update_insn_regno_info (as_a <rtx_insn *> (usage_insn));
6920 102640 : if (lra_dump_file != NULL)
6921 : {
6922 0 : fprintf (lra_dump_file, " Split reuse change %d->%d:\n",
6923 : original_regno, new_regno);
6924 0 : dump_insn_slim (lra_dump_file, as_a <rtx_insn *> (usage_insn));
6925 : }
6926 : }
6927 : }
6928 662257 : lra_assert (NOTE_P (usage_insn) || NONDEBUG_INSN_P (usage_insn));
6929 662257 : lra_assert (usage_insn != insn || (after_p && before_p));
6930 1119282 : lra_process_new_insns (as_a <rtx_insn *> (usage_insn),
6931 : after_p ? NULL : restore,
6932 : after_p ? restore : NULL,
6933 : call_save_p ? "Add reg<-save" : "Add reg<-split");
6934 662257 : if (call_save_p
6935 660757 : && first_call_insn != NULL
6936 1323014 : && BLOCK_FOR_INSN (first_call_insn) != BLOCK_FOR_INSN (insn))
6937 : /* PR116028: If original_regno is a pseudo that has been assigned a
6938 : callee-saved hard register, then emit the spill insn before the call
6939 : insn 'first_call_insn' instead of adjacent to 'insn'. If 'insn'
6940 : and 'first_call_insn' belong to the same EBB but to two separate
6941 : BBs, and if 'insn' is present in the entry BB, then generating the
6942 : spill insn in the entry BB can prevent shrink wrap from happening.
6943 : This is because the spill insn references the stack pointer and
6944 : hence the prolog gets generated in the entry BB itself. It is
6945 : also more efficient to generate the spill before
6946 : 'first_call_insn' as the spill now occurs only in the path
6947 : containing the call. */
6948 25902 : lra_process_new_insns (first_call_insn, save, NULL, "Add save<-reg");
6949 : else
6950 1273563 : lra_process_new_insns (insn, before_p ? save : NULL,
6951 : before_p ? NULL : save,
6952 : call_save_p ? "Add save<-reg" : "Add split<-reg");
6953 662257 : if (nregs > 1 || original_regno < FIRST_PSEUDO_REGISTER)
6954 : /* If we are trying to split multi-register. We should check
6955 : conflicts on the next assignment sub-pass. IRA can allocate on
6956 : sub-register levels, LRA do this on pseudos level right now and
6957 : this discrepancy may create allocation conflicts after
6958 : splitting.
6959 :
6960 : If we are trying to split hard register we should also check conflicts
6961 : as such splitting can create artificial conflict of the hard register
6962 : with another pseudo because of simplified conflict calculation in
6963 : LRA. */
6964 9783 : check_and_force_assignment_correctness_p = true;
6965 662257 : if (lra_dump_file != NULL)
6966 0 : fprintf (lra_dump_file,
6967 : " ))))))))))))))))))))))))))))))))))))))))))))))))\n");
6968 : return true;
6969 : }
6970 :
6971 : /* Split a hard reg for reload pseudo REGNO having RCLASS and living
6972 : in the range [FROM, TO]. Return true if did a split. Otherwise,
6973 : return false. */
6974 : bool
6975 1570 : spill_hard_reg_in_range (int regno, enum reg_class rclass, rtx_insn *from, rtx_insn *to)
6976 : {
6977 1570 : int i, hard_regno;
6978 1570 : int rclass_size;
6979 1570 : rtx_insn *insn;
6980 1570 : unsigned int uid;
6981 1570 : bitmap_iterator bi;
6982 1570 : HARD_REG_SET ignore;
6983 :
6984 1570 : lra_assert (from != NULL && to != NULL);
6985 1570 : ignore = lra_no_alloc_regs;
6986 4523 : EXECUTE_IF_SET_IN_BITMAP (&lra_reg_info[regno].insn_bitmap, 0, uid, bi)
6987 : {
6988 2953 : lra_insn_recog_data_t id = lra_insn_recog_data[uid];
6989 2953 : struct lra_static_insn_data *static_id = id->insn_static_data;
6990 2953 : struct lra_insn_reg *reg;
6991 :
6992 9848 : for (reg = id->regs; reg != NULL; reg = reg->next)
6993 6895 : if (reg->regno < FIRST_PSEUDO_REGISTER)
6994 157 : SET_HARD_REG_BIT (ignore, reg->regno);
6995 4609 : for (reg = static_id->hard_regs; reg != NULL; reg = reg->next)
6996 1656 : SET_HARD_REG_BIT (ignore, reg->regno);
6997 : }
6998 1570 : rclass_size = ira_class_hard_regs_num[rclass];
6999 4212 : for (i = 0; i < rclass_size; i++)
7000 : {
7001 2801 : hard_regno = ira_class_hard_regs[rclass][i];
7002 2801 : if (! TEST_HARD_REG_BIT (lra_reg_info[regno].conflict_hard_regs, hard_regno)
7003 2801 : || TEST_HARD_REG_BIT (ignore, hard_regno))
7004 2636 : continue;
7005 476 : for (insn = from; insn != NEXT_INSN (to); insn = NEXT_INSN (insn))
7006 : {
7007 317 : struct lra_static_insn_data *static_id;
7008 317 : struct lra_insn_reg *reg;
7009 :
7010 317 : if (!INSN_P (insn))
7011 0 : continue;
7012 317 : if (bitmap_bit_p (&lra_reg_info[hard_regno].insn_bitmap,
7013 317 : INSN_UID (insn)))
7014 : break;
7015 311 : static_id = lra_get_insn_recog_data (insn)->insn_static_data;
7016 365 : for (reg = static_id->hard_regs; reg != NULL; reg = reg->next)
7017 54 : if (reg->regno == hard_regno)
7018 : break;
7019 : if (reg != NULL)
7020 : break;
7021 : }
7022 165 : if (insn != NEXT_INSN (to))
7023 6 : continue;
7024 159 : if (split_reg (true, hard_regno, from, NULL, to))
7025 : return true;
7026 : }
7027 : return false;
7028 : }
7029 :
7030 : /* Recognize that we need a split transformation for insn INSN, which
7031 : defines or uses REGNO in its insn biggest MODE (we use it only if
7032 : REGNO is a hard register). POTENTIAL_RELOAD_HARD_REGS contains
7033 : hard registers which might be used for reloads since the EBB end.
7034 : Put the save before INSN if BEFORE_P is true. MAX_UID is maximla
7035 : uid before starting INSN processing. Return true if we succeed in
7036 : such transformation. */
7037 : static bool
7038 201394535 : split_if_necessary (int regno, machine_mode mode,
7039 : HARD_REG_SET potential_reload_hard_regs,
7040 : bool before_p, rtx_insn *insn, int max_uid)
7041 : {
7042 201394535 : bool res = false;
7043 201394535 : int i, nregs = 1;
7044 201394535 : rtx next_usage_insns;
7045 :
7046 201394535 : if (regno < FIRST_PSEUDO_REGISTER)
7047 95042767 : nregs = hard_regno_nregs (regno, mode);
7048 403148214 : for (i = 0; i < nregs; i++)
7049 201753679 : if (usage_insns[regno + i].check == curr_usage_insns_check
7050 134570138 : && (next_usage_insns = usage_insns[regno + i].insns) != NULL_RTX
7051 : /* To avoid processing the register twice or more. */
7052 134570138 : && ((GET_CODE (next_usage_insns) != INSN_LIST
7053 130231843 : && INSN_UID (next_usage_insns) < max_uid)
7054 4338295 : || (GET_CODE (next_usage_insns) == INSN_LIST
7055 4338295 : && (INSN_UID (XEXP (next_usage_insns, 0)) < max_uid)))
7056 134570138 : && need_for_split_p (potential_reload_hard_regs, regno + i)
7057 202035372 : && split_reg (before_p, regno + i, insn, next_usage_insns, NULL))
7058 : res = true;
7059 201394535 : return res;
7060 : }
7061 :
7062 : /* Return TRUE if rtx X is considered as an invariant for
7063 : inheritance. */
7064 : static bool
7065 12025445 : invariant_p (const_rtx x)
7066 : {
7067 12025445 : machine_mode mode;
7068 12025445 : const char *fmt;
7069 12025445 : enum rtx_code code;
7070 12025445 : int i, j;
7071 :
7072 12025445 : if (side_effects_p (x))
7073 : return false;
7074 :
7075 11999472 : code = GET_CODE (x);
7076 11999472 : mode = GET_MODE (x);
7077 11999472 : if (code == SUBREG)
7078 : {
7079 473327 : x = SUBREG_REG (x);
7080 473327 : code = GET_CODE (x);
7081 473327 : mode = wider_subreg_mode (mode, GET_MODE (x));
7082 : }
7083 :
7084 11999472 : if (MEM_P (x))
7085 : return false;
7086 :
7087 10228109 : if (REG_P (x))
7088 : {
7089 3641938 : int i, nregs, regno = REGNO (x);
7090 :
7091 3641938 : if (regno >= FIRST_PSEUDO_REGISTER || regno == STACK_POINTER_REGNUM
7092 996931 : || TEST_HARD_REG_BIT (eliminable_regset, regno)
7093 3660219 : || GET_MODE_CLASS (GET_MODE (x)) == MODE_CC)
7094 : return false;
7095 2 : nregs = hard_regno_nregs (regno, mode);
7096 2 : for (i = 0; i < nregs; i++)
7097 2 : if (! fixed_regs[regno + i]
7098 : /* A hard register may be clobbered in the current insn
7099 : but we can ignore this case because if the hard
7100 : register is used it should be set somewhere after the
7101 : clobber. */
7102 2 : || bitmap_bit_p (&invalid_invariant_regs, regno + i))
7103 2 : return false;
7104 : }
7105 6586171 : fmt = GET_RTX_FORMAT (code);
7106 11605180 : for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
7107 : {
7108 8762855 : if (fmt[i] == 'e')
7109 : {
7110 5758965 : if (! invariant_p (XEXP (x, i)))
7111 : return false;
7112 : }
7113 3003890 : else if (fmt[i] == 'E')
7114 : {
7115 657837 : for (j = XVECLEN (x, i) - 1; j >= 0; j--)
7116 543279 : if (! invariant_p (XVECEXP (x, i, j)))
7117 : return false;
7118 : }
7119 : }
7120 : return true;
7121 : }
7122 :
7123 : /* We have 'dest_reg <- invariant'. Let us try to make an invariant
7124 : inheritance transformation (using dest_reg instead invariant in a
7125 : subsequent insn). */
7126 : static bool
7127 180927 : process_invariant_for_inheritance (rtx dst_reg, rtx invariant_rtx)
7128 : {
7129 180927 : invariant_ptr_t invariant_ptr;
7130 180927 : rtx_insn *insn, *new_insns;
7131 180927 : rtx insn_set, insn_reg, new_reg;
7132 180927 : int insn_regno;
7133 180927 : bool succ_p = false;
7134 180927 : int dst_regno = REGNO (dst_reg);
7135 180927 : machine_mode dst_mode = GET_MODE (dst_reg);
7136 180927 : enum reg_class cl = lra_get_allocno_class (dst_regno), insn_reg_cl;
7137 :
7138 180927 : invariant_ptr = insert_invariant (invariant_rtx);
7139 180927 : if ((insn = invariant_ptr->insn) != NULL_RTX)
7140 : {
7141 : /* We have a subsequent insn using the invariant. */
7142 23863 : insn_set = single_set (insn);
7143 23863 : lra_assert (insn_set != NULL);
7144 23863 : insn_reg = SET_DEST (insn_set);
7145 23863 : lra_assert (REG_P (insn_reg));
7146 23863 : insn_regno = REGNO (insn_reg);
7147 23863 : insn_reg_cl = lra_get_allocno_class (insn_regno);
7148 :
7149 23863 : if (dst_mode == GET_MODE (insn_reg)
7150 : /* We should consider only result move reg insns which are
7151 : cheap. */
7152 23797 : && targetm.register_move_cost (dst_mode, cl, insn_reg_cl) == 2
7153 47074 : && targetm.register_move_cost (dst_mode, cl, cl) == 2)
7154 : {
7155 23211 : if (lra_dump_file != NULL)
7156 0 : fprintf (lra_dump_file,
7157 : " [[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[\n");
7158 23211 : new_reg = lra_create_new_reg (dst_mode, dst_reg, cl, NULL,
7159 : "invariant inheritance");
7160 23211 : bitmap_set_bit (&lra_inheritance_pseudos, REGNO (new_reg));
7161 23211 : bitmap_set_bit (&check_only_regs, REGNO (new_reg));
7162 23211 : lra_reg_info[REGNO (new_reg)].restore_rtx = PATTERN (insn);
7163 23211 : start_sequence ();
7164 23211 : lra_emit_move (new_reg, dst_reg);
7165 23211 : new_insns = end_sequence ();
7166 23211 : lra_process_new_insns (curr_insn, NULL, new_insns,
7167 : "Add invariant inheritance<-original");
7168 23211 : start_sequence ();
7169 23211 : lra_emit_move (SET_DEST (insn_set), new_reg);
7170 23211 : new_insns = end_sequence ();
7171 23211 : lra_process_new_insns (insn, NULL, new_insns,
7172 : "Changing reload<-inheritance");
7173 23211 : lra_set_insn_deleted (insn);
7174 23211 : succ_p = true;
7175 23211 : if (lra_dump_file != NULL)
7176 : {
7177 0 : fprintf (lra_dump_file,
7178 : " Invariant inheritance reuse change %d (bb%d):\n",
7179 0 : REGNO (new_reg), BLOCK_FOR_INSN (insn)->index);
7180 0 : dump_insn_slim (lra_dump_file, insn);
7181 0 : fprintf (lra_dump_file,
7182 : " ]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]\n");
7183 : }
7184 : }
7185 : }
7186 180927 : invariant_ptr->insn = curr_insn;
7187 180927 : return succ_p;
7188 : }
7189 :
7190 : /* Check only registers living at the current program point in the
7191 : current EBB. */
7192 : static bitmap_head live_regs;
7193 :
7194 : /* Update live info in EBB given by its HEAD and TAIL insns after
7195 : inheritance/split transformation. The function removes dead moves
7196 : too. */
7197 : static void
7198 750240 : update_ebb_live_info (rtx_insn *head, rtx_insn *tail)
7199 : {
7200 750240 : unsigned int j;
7201 750240 : int i, regno;
7202 750240 : bool live_p;
7203 750240 : rtx_insn *prev_insn;
7204 750240 : rtx set;
7205 750240 : bool remove_p;
7206 750240 : basic_block last_bb, prev_bb, curr_bb;
7207 750240 : bitmap_iterator bi;
7208 750240 : struct lra_insn_reg *reg;
7209 750240 : edge e;
7210 750240 : edge_iterator ei;
7211 :
7212 750240 : last_bb = BLOCK_FOR_INSN (tail);
7213 750240 : prev_bb = NULL;
7214 750240 : for (curr_insn = tail;
7215 38637916 : curr_insn != PREV_INSN (head);
7216 37887676 : curr_insn = prev_insn)
7217 : {
7218 37887676 : prev_insn = PREV_INSN (curr_insn);
7219 : /* We need to process empty blocks too. They contain
7220 : NOTE_INSN_BASIC_BLOCK referring for the basic block. */
7221 37887676 : if (NOTE_P (curr_insn) && NOTE_KIND (curr_insn) != NOTE_INSN_BASIC_BLOCK)
7222 1435635 : continue;
7223 36452041 : curr_bb = BLOCK_FOR_INSN (curr_insn);
7224 36452041 : if (curr_bb != prev_bb)
7225 : {
7226 1495906 : if (prev_bb != NULL)
7227 : {
7228 : /* Update df_get_live_in (prev_bb): */
7229 54341500 : EXECUTE_IF_SET_IN_BITMAP (&check_only_regs, 0, j, bi)
7230 53595834 : if (bitmap_bit_p (&live_regs, j))
7231 1624333 : bitmap_set_bit (df_get_live_in (prev_bb), j);
7232 : else
7233 51971501 : bitmap_clear_bit (df_get_live_in (prev_bb), j);
7234 : }
7235 1495906 : if (curr_bb != last_bb)
7236 : {
7237 : /* Update df_get_live_out (curr_bb): */
7238 54341500 : EXECUTE_IF_SET_IN_BITMAP (&check_only_regs, 0, j, bi)
7239 : {
7240 53595834 : live_p = bitmap_bit_p (&live_regs, j);
7241 53595834 : if (! live_p)
7242 155818867 : FOR_EACH_EDGE (e, ei, curr_bb->succs)
7243 103902450 : if (bitmap_bit_p (df_get_live_in (e->dest), j))
7244 : {
7245 : live_p = true;
7246 : break;
7247 : }
7248 51971501 : if (live_p)
7249 1679417 : bitmap_set_bit (df_get_live_out (curr_bb), j);
7250 : else
7251 51916417 : bitmap_clear_bit (df_get_live_out (curr_bb), j);
7252 : }
7253 : }
7254 1495906 : prev_bb = curr_bb;
7255 1495906 : bitmap_and (&live_regs, &check_only_regs, df_get_live_out (curr_bb));
7256 : }
7257 36452041 : if (! NONDEBUG_INSN_P (curr_insn))
7258 13994262 : continue;
7259 22457779 : curr_id = lra_get_insn_recog_data (curr_insn);
7260 22457779 : curr_static_id = curr_id->insn_static_data;
7261 22457779 : remove_p = false;
7262 22457779 : if ((set = single_set (curr_insn)) != NULL_RTX
7263 21753404 : && REG_P (SET_DEST (set))
7264 17354794 : && (regno = REGNO (SET_DEST (set))) >= FIRST_PSEUDO_REGISTER
7265 12877177 : && SET_DEST (set) != pic_offset_table_rtx
7266 12870592 : && bitmap_bit_p (&check_only_regs, regno)
7267 25711838 : && ! bitmap_bit_p (&live_regs, regno))
7268 : remove_p = true;
7269 : /* See which defined values die here. */
7270 62010322 : for (reg = curr_id->regs; reg != NULL; reg = reg->next)
7271 39552543 : if (reg->type == OP_OUT && ! reg->subreg_p)
7272 15473538 : bitmap_clear_bit (&live_regs, reg->regno);
7273 26705858 : for (reg = curr_static_id->hard_regs; reg != NULL; reg = reg->next)
7274 4248079 : if (reg->type == OP_OUT && ! reg->subreg_p)
7275 3221600 : bitmap_clear_bit (&live_regs, reg->regno);
7276 22457779 : if (curr_id->arg_hard_regs != NULL)
7277 : /* Make clobbered argument hard registers die. */
7278 3240841 : for (i = 0; (regno = curr_id->arg_hard_regs[i]) >= 0; i++)
7279 2269956 : if (regno >= FIRST_PSEUDO_REGISTER)
7280 0 : bitmap_clear_bit (&live_regs, regno - FIRST_PSEUDO_REGISTER);
7281 : /* Mark each used value as live. */
7282 62010322 : for (reg = curr_id->regs; reg != NULL; reg = reg->next)
7283 39552543 : if (reg->type != OP_OUT
7284 39552543 : && bitmap_bit_p (&check_only_regs, reg->regno))
7285 4574759 : bitmap_set_bit (&live_regs, reg->regno);
7286 26705858 : for (reg = curr_static_id->hard_regs; reg != NULL; reg = reg->next)
7287 4248079 : if (reg->type != OP_OUT
7288 4248079 : && bitmap_bit_p (&check_only_regs, reg->regno))
7289 0 : bitmap_set_bit (&live_regs, reg->regno);
7290 22457779 : if (curr_id->arg_hard_regs != NULL)
7291 : /* Make used argument hard registers live. */
7292 3240841 : for (i = 0; (regno = curr_id->arg_hard_regs[i]) >= 0; i++)
7293 2269956 : if (regno < FIRST_PSEUDO_REGISTER
7294 2269956 : && bitmap_bit_p (&check_only_regs, regno))
7295 0 : bitmap_set_bit (&live_regs, regno);
7296 : /* It is quite important to remove dead move insns because it
7297 : means removing dead store. We don't need to process them for
7298 : constraints. */
7299 22457779 : if (remove_p)
7300 : {
7301 298710 : if (lra_dump_file != NULL)
7302 : {
7303 2 : fprintf (lra_dump_file, " Removing dead insn:\n ");
7304 2 : dump_insn_slim (lra_dump_file, curr_insn);
7305 : }
7306 298710 : lra_set_insn_deleted (curr_insn);
7307 : }
7308 : }
7309 750240 : }
7310 :
7311 : /* The structure describes info to do an inheritance for the current
7312 : insn. We need to collect such info first before doing the
7313 : transformations because the transformations change the insn
7314 : internal representation. */
7315 : struct to_inherit
7316 : {
7317 : /* Original regno. */
7318 : int regno;
7319 : /* Subsequent insns which can inherit original reg value. */
7320 : rtx insns;
7321 : };
7322 :
7323 : /* Array containing all info for doing inheritance from the current
7324 : insn. */
7325 : static struct to_inherit to_inherit[LRA_MAX_INSN_RELOADS];
7326 :
7327 : /* Number elements in the previous array. */
7328 : static int to_inherit_num;
7329 :
7330 : /* Add inheritance info REGNO and INSNS. Their meaning is described in
7331 : structure to_inherit. */
7332 : static void
7333 315596 : add_to_inherit (int regno, rtx insns)
7334 : {
7335 315596 : int i;
7336 :
7337 315678 : for (i = 0; i < to_inherit_num; i++)
7338 82 : if (to_inherit[i].regno == regno)
7339 : return;
7340 315596 : lra_assert (to_inherit_num < LRA_MAX_INSN_RELOADS);
7341 315596 : to_inherit[to_inherit_num].regno = regno;
7342 315596 : to_inherit[to_inherit_num++].insns = insns;
7343 : }
7344 :
7345 : /* Return the last non-debug insn in basic block BB, or the block begin
7346 : note if none. */
7347 : static rtx_insn *
7348 30387542 : get_last_insertion_point (basic_block bb)
7349 : {
7350 30387542 : rtx_insn *insn;
7351 :
7352 32946351 : FOR_BB_INSNS_REVERSE (bb, insn)
7353 32946351 : if (NONDEBUG_INSN_P (insn) || NOTE_INSN_BASIC_BLOCK_P (insn))
7354 30387542 : return insn;
7355 0 : gcc_unreachable ();
7356 : }
7357 :
7358 : /* Set up RES by registers living on edges FROM except the edge (FROM,
7359 : TO) or by registers set up in a jump insn in BB FROM. */
7360 : static void
7361 11748045 : get_live_on_other_edges (basic_block from, basic_block to, bitmap res)
7362 : {
7363 11748045 : rtx_insn *last;
7364 11748045 : struct lra_insn_reg *reg;
7365 11748045 : edge e;
7366 11748045 : edge_iterator ei;
7367 :
7368 11748045 : lra_assert (to != NULL);
7369 11748045 : bitmap_clear (res);
7370 34966746 : FOR_EACH_EDGE (e, ei, from->succs)
7371 23218701 : if (e->dest != to)
7372 11470656 : bitmap_ior_into (res, df_get_live_in (e->dest));
7373 11748045 : last = get_last_insertion_point (from);
7374 11748045 : if (! JUMP_P (last))
7375 1944694 : return;
7376 9803351 : curr_id = lra_get_insn_recog_data (last);
7377 19606458 : for (reg = curr_id->regs; reg != NULL; reg = reg->next)
7378 9803107 : if (reg->type != OP_IN)
7379 76 : bitmap_set_bit (res, reg->regno);
7380 : }
7381 :
7382 : /* Used as a temporary results of some bitmap calculations. */
7383 : static bitmap_head temp_bitmap;
7384 :
7385 : /* We split for reloads of small class of hard regs. The following
7386 : defines how many hard regs the class should have to be qualified as
7387 : small. The code is mostly oriented to x86/x86-64 architecture
7388 : where some insns need to use only specific register or pair of
7389 : registers and these register can live in RTL explicitly, e.g. for
7390 : parameter passing. */
7391 : static const int max_small_class_regs_num = 2;
7392 :
7393 : /* Do inheritance/split transformations in EBB starting with HEAD and
7394 : finishing on TAIL. We process EBB insns in the reverse order.
7395 : Return true if we did any inheritance/split transformation in the
7396 : EBB.
7397 :
7398 : We should avoid excessive splitting which results in worse code
7399 : because of inaccurate cost calculations for spilling new split
7400 : pseudos in such case. To achieve this we do splitting only if
7401 : register pressure is high in given basic block and there are reload
7402 : pseudos requiring hard registers. We could do more register
7403 : pressure calculations at any given program point to avoid necessary
7404 : splitting even more but it is to expensive and the current approach
7405 : works well enough. */
7406 : static bool
7407 12765602 : inherit_in_ebb (rtx_insn *head, rtx_insn *tail)
7408 : {
7409 12765602 : int i, src_regno, dst_regno, nregs;
7410 12765602 : bool change_p, succ_p, update_reloads_num_p;
7411 12765602 : rtx_insn *prev_insn, *last_insn;
7412 12765602 : rtx next_usage_insns, curr_set;
7413 12765602 : enum reg_class cl;
7414 12765602 : struct lra_insn_reg *reg;
7415 12765602 : basic_block last_processed_bb, curr_bb = NULL;
7416 12765602 : HARD_REG_SET potential_reload_hard_regs, live_hard_regs;
7417 12765602 : bitmap to_process;
7418 12765602 : unsigned int j;
7419 12765602 : bitmap_iterator bi;
7420 12765602 : bool head_p, after_p;
7421 :
7422 12765602 : change_p = false;
7423 12765602 : curr_usage_insns_check++;
7424 12765602 : clear_invariants ();
7425 12765602 : reloads_num = calls_num = 0;
7426 165952826 : for (unsigned int i = 0; i < NUM_ABI_IDS; ++i)
7427 153187224 : last_call_for_abi[i] = 0;
7428 12765602 : CLEAR_HARD_REG_SET (full_and_partial_call_clobbers);
7429 12765602 : bitmap_clear (&check_only_regs);
7430 12765602 : bitmap_clear (&invalid_invariant_regs);
7431 12765602 : last_processed_bb = NULL;
7432 12765602 : CLEAR_HARD_REG_SET (potential_reload_hard_regs);
7433 12765602 : live_hard_regs = eliminable_regset | lra_no_alloc_regs;
7434 : /* We don't process new insns generated in the loop. */
7435 241025051 : for (curr_insn = tail; curr_insn != PREV_INSN (head); curr_insn = prev_insn)
7436 : {
7437 228259449 : prev_insn = PREV_INSN (curr_insn);
7438 228259449 : if (BLOCK_FOR_INSN (curr_insn) != NULL)
7439 228259194 : curr_bb = BLOCK_FOR_INSN (curr_insn);
7440 228259449 : if (last_processed_bb != curr_bb)
7441 : {
7442 : /* We are at the end of BB. Add qualified living
7443 : pseudos for potential splitting. */
7444 18639497 : to_process = df_get_live_out (curr_bb);
7445 18639497 : if (last_processed_bb != NULL)
7446 : {
7447 : /* We are somewhere in the middle of EBB. */
7448 5873895 : get_live_on_other_edges (curr_bb, last_processed_bb,
7449 : &temp_bitmap);
7450 5873895 : to_process = &temp_bitmap;
7451 : }
7452 18639497 : last_processed_bb = curr_bb;
7453 18639497 : last_insn = get_last_insertion_point (curr_bb);
7454 37278994 : after_p = (! JUMP_P (last_insn)
7455 18639497 : && (! CALL_P (last_insn)
7456 2368934 : || (find_reg_note (last_insn,
7457 : REG_NORETURN, NULL_RTX) == NULL_RTX
7458 1410391 : && ! SIBLING_CALL_P (last_insn))));
7459 18639497 : CLEAR_HARD_REG_SET (potential_reload_hard_regs);
7460 201986170 : EXECUTE_IF_SET_IN_BITMAP (to_process, 0, j, bi)
7461 : {
7462 183346679 : if ((int) j >= lra_constraint_new_regno_start)
7463 : break;
7464 183346673 : if (j < FIRST_PSEUDO_REGISTER || reg_renumber[j] >= 0)
7465 : {
7466 119319020 : if (j < FIRST_PSEUDO_REGISTER)
7467 69985984 : SET_HARD_REG_BIT (live_hard_regs, j);
7468 : else
7469 49333036 : add_to_hard_reg_set (&live_hard_regs,
7470 49333036 : PSEUDO_REGNO_MODE (j),
7471 49333036 : reg_renumber[j]);
7472 119319020 : setup_next_usage_insn (j, last_insn, reloads_num, after_p);
7473 : }
7474 : }
7475 : }
7476 228259449 : src_regno = dst_regno = -1;
7477 228259449 : curr_set = single_set (curr_insn);
7478 228259449 : if (curr_set != NULL_RTX && REG_P (SET_DEST (curr_set)))
7479 84591495 : dst_regno = REGNO (SET_DEST (curr_set));
7480 114664145 : if (curr_set != NULL_RTX && REG_P (SET_SRC (curr_set)))
7481 39689524 : src_regno = REGNO (SET_SRC (curr_set));
7482 228259449 : update_reloads_num_p = true;
7483 228259449 : if (src_regno < lra_constraint_new_regno_start
7484 221723320 : && src_regno >= FIRST_PSEUDO_REGISTER
7485 27896115 : && reg_renumber[src_regno] < 0
7486 3726334 : && dst_regno >= lra_constraint_new_regno_start
7487 230908130 : && (cl = lra_get_allocno_class (dst_regno)) != NO_REGS)
7488 : {
7489 : /* 'reload_pseudo <- original_pseudo'. */
7490 2648681 : if (ira_class_hard_regs_num[cl] <= max_small_class_regs_num)
7491 22452 : reloads_num++;
7492 2648681 : update_reloads_num_p = false;
7493 2648681 : succ_p = false;
7494 2648681 : if (usage_insns[src_regno].check == curr_usage_insns_check
7495 2648681 : && (next_usage_insns = usage_insns[src_regno].insns) != NULL_RTX)
7496 472915 : succ_p = inherit_reload_reg (false, src_regno, cl,
7497 : curr_insn, next_usage_insns);
7498 472915 : if (succ_p)
7499 : change_p = true;
7500 : else
7501 2198538 : setup_next_usage_insn (src_regno, curr_insn, reloads_num, false);
7502 5297362 : if (hard_reg_set_subset_p (reg_class_contents[cl], live_hard_regs))
7503 642411298 : potential_reload_hard_regs |= reg_class_contents[cl];
7504 : }
7505 225610768 : else if (src_regno < 0
7506 188569925 : && dst_regno >= lra_constraint_new_regno_start
7507 5723201 : && invariant_p (SET_SRC (curr_set))
7508 283927 : && (cl = lra_get_allocno_class (dst_regno)) != NO_REGS
7509 283370 : && ! bitmap_bit_p (&invalid_invariant_regs, dst_regno)
7510 225854027 : && ! bitmap_bit_p (&invalid_invariant_regs,
7511 243259 : ORIGINAL_REGNO(regno_reg_rtx[dst_regno])))
7512 : {
7513 : /* 'reload_pseudo <- invariant'. */
7514 180927 : if (ira_class_hard_regs_num[cl] <= max_small_class_regs_num)
7515 10394 : reloads_num++;
7516 180927 : update_reloads_num_p = false;
7517 180927 : if (process_invariant_for_inheritance (SET_DEST (curr_set), SET_SRC (curr_set)))
7518 23211 : change_p = true;
7519 361854 : if (hard_reg_set_subset_p (reg_class_contents[cl], live_hard_regs))
7520 642411298 : potential_reload_hard_regs |= reg_class_contents[cl];
7521 : }
7522 225429841 : else if (src_regno >= lra_constraint_new_regno_start
7523 6536129 : && dst_regno < lra_constraint_new_regno_start
7524 5726705 : && dst_regno >= FIRST_PSEUDO_REGISTER
7525 3790506 : && reg_renumber[dst_regno] < 0
7526 1458788 : && (cl = lra_get_allocno_class (src_regno)) != NO_REGS
7527 1458788 : && usage_insns[dst_regno].check == curr_usage_insns_check
7528 225429841 : && (next_usage_insns
7529 481609 : = usage_insns[dst_regno].insns) != NULL_RTX)
7530 : {
7531 481609 : if (ira_class_hard_regs_num[cl] <= max_small_class_regs_num)
7532 8113 : reloads_num++;
7533 481609 : update_reloads_num_p = false;
7534 : /* 'original_pseudo <- reload_pseudo'. */
7535 481609 : if (! JUMP_P (curr_insn)
7536 481609 : && inherit_reload_reg (true, dst_regno, cl,
7537 : curr_insn, next_usage_insns))
7538 : change_p = true;
7539 : /* Invalidate. */
7540 481609 : usage_insns[dst_regno].check = 0;
7541 963218 : if (hard_reg_set_subset_p (reg_class_contents[cl], live_hard_regs))
7542 642411298 : potential_reload_hard_regs |= reg_class_contents[cl];
7543 : }
7544 224948232 : else if (INSN_P (curr_insn))
7545 : {
7546 189134153 : int iter;
7547 189134153 : int max_uid = get_max_uid ();
7548 :
7549 189134153 : curr_id = lra_get_insn_recog_data (curr_insn);
7550 189134153 : curr_static_id = curr_id->insn_static_data;
7551 189134153 : to_inherit_num = 0;
7552 : /* Process insn definitions. */
7553 567402459 : for (iter = 0; iter < 2; iter++)
7554 378268306 : for (reg = iter == 0 ? curr_id->regs : curr_static_id->hard_regs;
7555 608258497 : reg != NULL;
7556 229990191 : reg = reg->next)
7557 229990191 : if (reg->type != OP_IN
7558 229990191 : && (dst_regno = reg->regno) < lra_constraint_new_regno_start)
7559 : {
7560 46027313 : if (dst_regno >= FIRST_PSEUDO_REGISTER && reg->type == OP_OUT
7561 43881261 : && reg_renumber[dst_regno] < 0 && ! reg->subreg_p
7562 1785095 : && usage_insns[dst_regno].check == curr_usage_insns_check
7563 91759617 : && (next_usage_insns
7564 129431 : = usage_insns[dst_regno].insns) != NULL_RTX)
7565 : {
7566 129431 : struct lra_insn_reg *r;
7567 :
7568 386043 : for (r = curr_id->regs; r != NULL; r = r->next)
7569 256612 : if (r->type != OP_OUT && r->regno == dst_regno)
7570 : break;
7571 : /* Don't do inheritance if the pseudo is also
7572 : used in the insn. */
7573 129431 : if (r == NULL)
7574 : /* We cannot do inheritance right now
7575 : because the current insn reg info (chain
7576 : regs) can change after that. */
7577 129431 : add_to_inherit (dst_regno, next_usage_insns);
7578 : }
7579 : /* We cannot process one reg twice here because of
7580 : usage_insns invalidation. */
7581 91759617 : if ((dst_regno < FIRST_PSEUDO_REGISTER
7582 46027313 : || reg_renumber[dst_regno] >= 0)
7583 89834881 : && ! reg->subreg_p && reg->type != OP_IN)
7584 : {
7585 89550527 : HARD_REG_SET s;
7586 :
7587 89550527 : if (split_if_necessary (dst_regno, reg->biggest_mode,
7588 : potential_reload_hard_regs,
7589 : false, curr_insn, max_uid))
7590 58232 : change_p = true;
7591 89550527 : CLEAR_HARD_REG_SET (s);
7592 89550527 : if (dst_regno < FIRST_PSEUDO_REGISTER)
7593 45732304 : add_to_hard_reg_set (&s, reg->biggest_mode, dst_regno);
7594 : else
7595 43818223 : add_to_hard_reg_set (&s, PSEUDO_REGNO_MODE (dst_regno),
7596 43818223 : reg_renumber[dst_regno]);
7597 89550527 : live_hard_regs &= ~s;
7598 179101054 : potential_reload_hard_regs &= ~s;
7599 : }
7600 : /* We should invalidate potential inheritance or
7601 : splitting for the current insn usages to the next
7602 : usage insns (see code below) as the output pseudo
7603 : prevents this. */
7604 91759617 : if ((dst_regno >= FIRST_PSEUDO_REGISTER
7605 46027313 : && reg_renumber[dst_regno] < 0)
7606 89834881 : || (reg->type == OP_OUT && ! reg->subreg_p
7607 81803806 : && (dst_regno < FIRST_PSEUDO_REGISTER
7608 41680666 : || reg_renumber[dst_regno] >= 0)))
7609 : {
7610 : /* Invalidate and mark definitions. */
7611 43605402 : if (dst_regno >= FIRST_PSEUDO_REGISTER)
7612 43605402 : usage_insns[dst_regno].check = -(int) INSN_UID (curr_insn);
7613 : else
7614 : {
7615 40123140 : nregs = hard_regno_nregs (dst_regno,
7616 40123140 : reg->biggest_mode);
7617 80507406 : for (i = 0; i < nregs; i++)
7618 80768532 : usage_insns[dst_regno + i].check
7619 40384266 : = -(int) INSN_UID (curr_insn);
7620 : }
7621 : }
7622 : }
7623 : /* Process clobbered call regs. */
7624 189134153 : if (curr_id->arg_hard_regs != NULL)
7625 19467515 : for (i = 0; (dst_regno = curr_id->arg_hard_regs[i]) >= 0; i++)
7626 13632756 : if (dst_regno >= FIRST_PSEUDO_REGISTER)
7627 0 : usage_insns[dst_regno - FIRST_PSEUDO_REGISTER].check
7628 0 : = -(int) INSN_UID (curr_insn);
7629 189134153 : if (! JUMP_P (curr_insn))
7630 177635081 : for (i = 0; i < to_inherit_num; i++)
7631 129431 : if (inherit_reload_reg (true, to_inherit[i].regno,
7632 : ALL_REGS, curr_insn,
7633 : to_inherit[i].insns))
7634 103641 : change_p = true;
7635 189134153 : if (CALL_P (curr_insn))
7636 : {
7637 7414065 : rtx cheap, pat, dest;
7638 7414065 : rtx_insn *restore;
7639 7414065 : int regno, hard_regno;
7640 :
7641 7414065 : calls_num++;
7642 7414065 : function_abi callee_abi = insn_callee_abi (curr_insn);
7643 7414065 : last_call_for_abi[callee_abi.id ()] = calls_num;
7644 7414065 : full_and_partial_call_clobbers
7645 7414065 : |= callee_abi.full_and_partial_reg_clobbers ();
7646 7414065 : first_call_insn = curr_insn;
7647 7414065 : if ((cheap = find_reg_note (curr_insn,
7648 : REG_RETURNED, NULL_RTX)) != NULL_RTX
7649 44413 : && ((cheap = XEXP (cheap, 0)), true)
7650 44413 : && (regno = REGNO (cheap)) >= FIRST_PSEUDO_REGISTER
7651 44413 : && (hard_regno = reg_renumber[regno]) >= 0
7652 33601 : && usage_insns[regno].check == curr_usage_insns_check
7653 : /* If there are pending saves/restores, the
7654 : optimization is not worth. */
7655 28839 : && usage_insns[regno].calls_num == calls_num - 1
7656 7441097 : && callee_abi.clobbers_reg_p (GET_MODE (cheap), hard_regno))
7657 : {
7658 : /* Restore the pseudo from the call result as
7659 : REG_RETURNED note says that the pseudo value is
7660 : in the call result and the pseudo is an argument
7661 : of the call. */
7662 12047 : pat = PATTERN (curr_insn);
7663 12047 : if (GET_CODE (pat) == PARALLEL)
7664 0 : pat = XVECEXP (pat, 0, 0);
7665 12047 : dest = SET_DEST (pat);
7666 : /* For multiple return values dest is PARALLEL.
7667 : Currently we handle only single return value case. */
7668 12047 : if (REG_P (dest))
7669 : {
7670 12047 : start_sequence ();
7671 12047 : emit_move_insn (cheap, copy_rtx (dest));
7672 12047 : restore = end_sequence ();
7673 12047 : lra_process_new_insns (curr_insn, NULL, restore,
7674 : "Inserting call parameter restore");
7675 : /* We don't need to save/restore of the pseudo from
7676 : this call. */
7677 12047 : usage_insns[regno].calls_num = calls_num;
7678 12047 : remove_from_hard_reg_set
7679 12047 : (&full_and_partial_call_clobbers,
7680 12047 : GET_MODE (cheap), hard_regno);
7681 12047 : bitmap_set_bit (&check_only_regs, regno);
7682 : }
7683 : }
7684 : }
7685 189134153 : to_inherit_num = 0;
7686 : /* Process insn usages. */
7687 567402459 : for (iter = 0; iter < 2; iter++)
7688 378268306 : for (reg = iter == 0 ? curr_id->regs : curr_static_id->hard_regs;
7689 608258497 : reg != NULL;
7690 229990191 : reg = reg->next)
7691 229990191 : if ((reg->type != OP_OUT
7692 90630717 : || (reg->type == OP_OUT && reg->subreg_p))
7693 230543541 : && (src_regno = reg->regno) < lra_constraint_new_regno_start)
7694 : {
7695 128222779 : if (src_regno >= FIRST_PSEUDO_REGISTER
7696 73987539 : && reg_renumber[src_regno] < 0 && reg->type == OP_IN)
7697 : {
7698 2487132 : if (usage_insns[src_regno].check == curr_usage_insns_check
7699 807633 : && (next_usage_insns
7700 807633 : = usage_insns[src_regno].insns) != NULL_RTX
7701 3294765 : && NONDEBUG_INSN_P (curr_insn))
7702 186165 : add_to_inherit (src_regno, next_usage_insns);
7703 4601934 : else if (usage_insns[src_regno].check
7704 2300967 : != -(int) INSN_UID (curr_insn))
7705 : /* Add usages but only if the reg is not set up
7706 : in the same insn. */
7707 2300967 : add_next_usage_insn (src_regno, curr_insn, reloads_num);
7708 : }
7709 71500407 : else if (src_regno < FIRST_PSEUDO_REGISTER
7710 71500407 : || reg_renumber[src_regno] >= 0)
7711 : {
7712 125596006 : bool before_p;
7713 125596006 : rtx_insn *use_insn = curr_insn;
7714 125596006 : rtx_insn *prev_insn = PREV_INSN (curr_insn);
7715 :
7716 251192012 : before_p = (JUMP_P (curr_insn)
7717 125596006 : || (CALL_P (curr_insn) && reg->type == OP_IN));
7718 125596006 : if (NONDEBUG_INSN_P (curr_insn)
7719 111844113 : && (! JUMP_P (curr_insn) || reg->type == OP_IN)
7720 237440014 : && split_if_necessary (src_regno, reg->biggest_mode,
7721 : potential_reload_hard_regs,
7722 : before_p, curr_insn, max_uid))
7723 : {
7724 223461 : if (reg->subreg_p)
7725 3165 : check_and_force_assignment_correctness_p = true;
7726 223461 : change_p = true;
7727 : /* Invalidate. */
7728 223461 : usage_insns[src_regno].check = 0;
7729 223461 : if (before_p && PREV_INSN (curr_insn) != prev_insn)
7730 : use_insn = PREV_INSN (curr_insn);
7731 : }
7732 125596006 : if (NONDEBUG_INSN_P (curr_insn))
7733 : {
7734 111844113 : if (src_regno < FIRST_PSEUDO_REGISTER)
7735 49310486 : add_to_hard_reg_set (&live_hard_regs,
7736 49310486 : reg->biggest_mode, src_regno);
7737 : else
7738 62533627 : add_to_hard_reg_set (&live_hard_regs,
7739 62533627 : PSEUDO_REGNO_MODE (src_regno),
7740 62533627 : reg_renumber[src_regno]);
7741 : }
7742 125596006 : if (src_regno >= FIRST_PSEUDO_REGISTER)
7743 71360766 : add_next_usage_insn (src_regno, use_insn, reloads_num);
7744 : else
7745 : {
7746 108569282 : for (i = 0; i < hard_regno_nregs (src_regno, reg->biggest_mode); i++)
7747 54334042 : add_next_usage_insn (src_regno + i, use_insn, reloads_num);
7748 : }
7749 : }
7750 : }
7751 : /* Process used call regs. */
7752 189134153 : if (curr_id->arg_hard_regs != NULL)
7753 19467515 : for (i = 0; (src_regno = curr_id->arg_hard_regs[i]) >= 0; i++)
7754 13632756 : if (src_regno < FIRST_PSEUDO_REGISTER)
7755 : {
7756 13632756 : SET_HARD_REG_BIT (live_hard_regs, src_regno);
7757 13632756 : add_next_usage_insn (src_regno, curr_insn, reloads_num);
7758 : }
7759 189320318 : for (i = 0; i < to_inherit_num; i++)
7760 : {
7761 186165 : src_regno = to_inherit[i].regno;
7762 186165 : if (inherit_reload_reg (false, src_regno, ALL_REGS,
7763 : curr_insn, to_inherit[i].insns))
7764 : change_p = true;
7765 : else
7766 23284 : setup_next_usage_insn (src_regno, curr_insn, reloads_num, false);
7767 : }
7768 : }
7769 189203617 : if (update_reloads_num_p
7770 224948232 : && NONDEBUG_INSN_P (curr_insn) && curr_set != NULL_RTX)
7771 : {
7772 111352928 : int regno = -1;
7773 111352928 : if ((REG_P (SET_DEST (curr_set))
7774 81280278 : && (regno = REGNO (SET_DEST (curr_set))) >= lra_constraint_new_regno_start
7775 8393653 : && reg_renumber[regno] < 0
7776 5377947 : && (cl = lra_get_allocno_class (regno)) != NO_REGS)
7777 187526196 : || (REG_P (SET_SRC (curr_set))
7778 35248596 : && (regno = REGNO (SET_SRC (curr_set))) >= lra_constraint_new_regno_start
7779 6125171 : && reg_renumber[regno] < 0
7780 3606201 : && (cl = lra_get_allocno_class (regno)) != NO_REGS))
7781 : {
7782 8454858 : if (ira_class_hard_regs_num[cl] <= max_small_class_regs_num)
7783 246652 : reloads_num++;
7784 16909716 : if (hard_reg_set_subset_p (reg_class_contents[cl], live_hard_regs))
7785 228259449 : potential_reload_hard_regs |= reg_class_contents[cl];
7786 : }
7787 : }
7788 228259449 : if (NONDEBUG_INSN_P (curr_insn))
7789 : {
7790 121116360 : int regno;
7791 :
7792 : /* Invalidate invariants with changed regs. */
7793 121116360 : curr_id = lra_get_insn_recog_data (curr_insn);
7794 310615986 : for (reg = curr_id->regs; reg != NULL; reg = reg->next)
7795 189499626 : if (reg->type != OP_IN)
7796 : {
7797 81167469 : bitmap_set_bit (&invalid_invariant_regs, reg->regno);
7798 162334938 : bitmap_set_bit (&invalid_invariant_regs,
7799 81167469 : ORIGINAL_REGNO (regno_reg_rtx[reg->regno]));
7800 : }
7801 121116360 : curr_static_id = curr_id->insn_static_data;
7802 153033114 : for (reg = curr_static_id->hard_regs; reg != NULL; reg = reg->next)
7803 31916754 : if (reg->type != OP_IN)
7804 22853171 : bitmap_set_bit (&invalid_invariant_regs, reg->regno);
7805 121116360 : if (curr_id->arg_hard_regs != NULL)
7806 19467515 : for (i = 0; (regno = curr_id->arg_hard_regs[i]) >= 0; i++)
7807 13632756 : if (regno >= FIRST_PSEUDO_REGISTER)
7808 0 : bitmap_set_bit (&invalid_invariant_regs,
7809 : regno - FIRST_PSEUDO_REGISTER);
7810 : }
7811 : /* We reached the start of the current basic block. */
7812 228259441 : if (prev_insn == NULL_RTX || prev_insn == PREV_INSN (head)
7813 443753296 : || BLOCK_FOR_INSN (prev_insn) != curr_bb)
7814 : {
7815 : /* We reached the beginning of the current block -- do
7816 : rest of splitting in the current BB. */
7817 18639752 : to_process = df_get_live_in (curr_bb);
7818 18639752 : if (BLOCK_FOR_INSN (head) != curr_bb)
7819 : {
7820 : /* We are somewhere in the middle of EBB. */
7821 5874150 : get_live_on_other_edges (EDGE_PRED (curr_bb, 0)->src,
7822 : curr_bb, &temp_bitmap);
7823 5874150 : to_process = &temp_bitmap;
7824 : }
7825 18639752 : head_p = true;
7826 195372814 : EXECUTE_IF_SET_IN_BITMAP (to_process, 0, j, bi)
7827 : {
7828 176733069 : if ((int) j >= lra_constraint_new_regno_start)
7829 : break;
7830 112447563 : if (((int) j < FIRST_PSEUDO_REGISTER || reg_renumber[j] >= 0)
7831 111594867 : && usage_insns[j].check == curr_usage_insns_check
7832 286421437 : && (next_usage_insns = usage_insns[j].insns) != NULL_RTX)
7833 : {
7834 109688375 : if (need_for_split_p (potential_reload_hard_regs, j))
7835 : {
7836 380405 : if (lra_dump_file != NULL && head_p)
7837 : {
7838 0 : fprintf (lra_dump_file,
7839 : " ----------------------------------\n");
7840 0 : head_p = false;
7841 : }
7842 380405 : if (split_reg (false, j, bb_note (curr_bb),
7843 : next_usage_insns, NULL))
7844 380405 : change_p = true;
7845 : }
7846 109688375 : usage_insns[j].check = 0;
7847 : }
7848 : }
7849 : }
7850 : }
7851 12765602 : first_call_insn = NULL;
7852 12765602 : return change_p;
7853 : }
7854 :
7855 : /* This value affects EBB forming. If probability of edge from EBB to
7856 : a BB is not greater than the following value, we don't add the BB
7857 : to EBB. */
7858 : #define EBB_PROBABILITY_CUTOFF \
7859 : ((REG_BR_PROB_BASE * param_lra_inheritance_ebb_probability_cutoff) / 100)
7860 :
7861 : /* Current number of inheritance/split iteration. */
7862 : int lra_inheritance_iter;
7863 :
7864 : /* Entry function for inheritance/split pass. */
7865 : void
7866 1571259 : lra_inheritance (void)
7867 : {
7868 1571259 : int i;
7869 1571259 : basic_block bb, start_bb;
7870 1571259 : edge e;
7871 :
7872 1571259 : lra_inheritance_iter++;
7873 1571259 : if (lra_inheritance_iter > LRA_MAX_INHERITANCE_PASSES)
7874 : return;
7875 1568078 : timevar_push (TV_LRA_INHERITANCE);
7876 1568078 : if (lra_dump_file != NULL)
7877 97 : fprintf (lra_dump_file, "\n********** Inheritance #%d: **********\n\n",
7878 : lra_inheritance_iter);
7879 1568078 : curr_usage_insns_check = 0;
7880 1568078 : usage_insns = XNEWVEC (struct usage_insns, lra_constraint_new_regno_start);
7881 232555441 : for (i = 0; i < lra_constraint_new_regno_start; i++)
7882 230987363 : usage_insns[i].check = 0;
7883 1568078 : bitmap_initialize (&check_only_regs, ®_obstack);
7884 1568078 : bitmap_initialize (&invalid_invariant_regs, ®_obstack);
7885 1568078 : bitmap_initialize (&live_regs, ®_obstack);
7886 1568078 : bitmap_initialize (&temp_bitmap, ®_obstack);
7887 1568078 : bitmap_initialize (&ebb_global_regs, ®_obstack);
7888 14333680 : FOR_EACH_BB_FN (bb, cfun)
7889 : {
7890 12765602 : start_bb = bb;
7891 12765602 : if (lra_dump_file != NULL)
7892 347 : fprintf (lra_dump_file, "EBB");
7893 : /* Form a EBB starting with BB. */
7894 12765602 : bitmap_clear (&ebb_global_regs);
7895 12765602 : bitmap_ior_into (&ebb_global_regs, df_get_live_in (bb));
7896 18639497 : for (;;)
7897 : {
7898 18639497 : if (lra_dump_file != NULL)
7899 477 : fprintf (lra_dump_file, " %d", bb->index);
7900 18639497 : if (bb->next_bb == EXIT_BLOCK_PTR_FOR_FN (cfun)
7901 17071419 : || LABEL_P (BB_HEAD (bb->next_bb)))
7902 : break;
7903 8251732 : e = find_fallthru_edge (bb->succs);
7904 8251732 : if (! e)
7905 : break;
7906 8251732 : if (e->probability.initialized_p ()
7907 8251732 : && e->probability.to_reg_br_prob_base () < EBB_PROBABILITY_CUTOFF)
7908 : break;
7909 : bb = bb->next_bb;
7910 : }
7911 12765602 : bitmap_ior_into (&ebb_global_regs, df_get_live_out (bb));
7912 12765602 : if (lra_dump_file != NULL)
7913 347 : fprintf (lra_dump_file, "\n");
7914 12765602 : if (inherit_in_ebb (BB_HEAD (start_bb), BB_END (bb)))
7915 : /* Remember that the EBB head and tail can change in
7916 : inherit_in_ebb. */
7917 750240 : update_ebb_live_info (BB_HEAD (start_bb), BB_END (bb));
7918 : }
7919 1568078 : bitmap_release (&ebb_global_regs);
7920 1568078 : bitmap_release (&temp_bitmap);
7921 1568078 : bitmap_release (&live_regs);
7922 1568078 : bitmap_release (&invalid_invariant_regs);
7923 1568078 : bitmap_release (&check_only_regs);
7924 1568078 : free (usage_insns);
7925 1568078 : lra_dump_insns_if_possible ("func after inheritance");
7926 1568078 : timevar_pop (TV_LRA_INHERITANCE);
7927 : }
7928 :
7929 :
7930 :
7931 : /* This page contains code to undo failed inheritance/split
7932 : transformations. */
7933 :
7934 : /* Current number of iteration undoing inheritance/split. */
7935 : int lra_undo_inheritance_iter;
7936 :
7937 : /* Fix BB live info LIVE after removing pseudos created on pass doing
7938 : inheritance/split which are REMOVED_PSEUDOS. */
7939 : static void
7940 37278994 : fix_bb_live_info (bitmap live, bitmap removed_pseudos)
7941 : {
7942 37278994 : unsigned int regno;
7943 37278994 : bitmap_iterator bi;
7944 :
7945 209513280 : EXECUTE_IF_SET_IN_BITMAP (removed_pseudos, 0, regno, bi)
7946 172234286 : if (bitmap_clear_bit (live, regno)
7947 172234286 : && REG_P (lra_reg_info[regno].restore_rtx))
7948 1209314 : bitmap_set_bit (live, REGNO (lra_reg_info[regno].restore_rtx));
7949 37278994 : }
7950 :
7951 : /* Return regno of the (subreg of) REG. Otherwise, return a negative
7952 : number. */
7953 : static int
7954 68120874 : get_regno (rtx reg)
7955 : {
7956 1110678 : if (GET_CODE (reg) == SUBREG)
7957 1051104 : reg = SUBREG_REG (reg);
7958 68120874 : if (REG_P (reg))
7959 44156392 : return REGNO (reg);
7960 : return -1;
7961 : }
7962 :
7963 : /* Delete a move INSN with destination reg DREGNO and a previous
7964 : clobber insn with the same regno. The inheritance/split code can
7965 : generate moves with preceding clobber and when we delete such moves
7966 : we should delete the clobber insn too to keep the correct life
7967 : info. */
7968 : static void
7969 757912 : delete_move_and_clobber (rtx_insn *insn, int dregno)
7970 : {
7971 757912 : rtx_insn *prev_insn = PREV_INSN (insn);
7972 :
7973 757912 : lra_set_insn_deleted (insn);
7974 757912 : lra_assert (dregno >= 0);
7975 757912 : if (prev_insn != NULL && NONDEBUG_INSN_P (prev_insn)
7976 326620 : && GET_CODE (PATTERN (prev_insn)) == CLOBBER
7977 758340 : && dregno == get_regno (XEXP (PATTERN (prev_insn), 0)))
7978 0 : lra_set_insn_deleted (prev_insn);
7979 757912 : }
7980 :
7981 : /* Remove inheritance/split pseudos which are in REMOVE_PSEUDOS and
7982 : return true if we did any change. The undo transformations for
7983 : inheritance looks like
7984 : i <- i2
7985 : p <- i => p <- i2
7986 : or removing
7987 : p <- i, i <- p, and i <- i3
7988 : where p is original pseudo from which inheritance pseudo i was
7989 : created, i and i3 are removed inheritance pseudos, i2 is another
7990 : not removed inheritance pseudo. All split pseudos or other
7991 : occurrences of removed inheritance pseudos are changed on the
7992 : corresponding original pseudos.
7993 :
7994 : The function also schedules insns changed and created during
7995 : inheritance/split pass for processing by the subsequent constraint
7996 : pass. */
7997 : static bool
7998 1568078 : remove_inheritance_pseudos (bitmap remove_pseudos)
7999 : {
8000 1568078 : basic_block bb;
8001 1568078 : int regno, sregno, prev_sregno, dregno;
8002 1568078 : rtx restore_rtx;
8003 1568078 : rtx set, prev_set;
8004 1568078 : rtx_insn *prev_insn;
8005 1568078 : bool change_p, done_p;
8006 :
8007 1568078 : change_p = ! bitmap_empty_p (remove_pseudos);
8008 : /* We cannot finish the function right away if CHANGE_P is true
8009 : because we need to marks insns affected by previous
8010 : inheritance/split pass for processing by the subsequent
8011 : constraint pass. */
8012 20207575 : FOR_EACH_BB_FN (bb, cfun)
8013 : {
8014 18639497 : fix_bb_live_info (df_get_live_in (bb), remove_pseudos);
8015 18639497 : fix_bb_live_info (df_get_live_out (bb), remove_pseudos);
8016 249442493 : FOR_BB_INSNS_REVERSE (bb, curr_insn)
8017 : {
8018 230802996 : if (! INSN_P (curr_insn))
8019 36162023 : continue;
8020 194640973 : done_p = false;
8021 194640973 : sregno = dregno = -1;
8022 47970029 : if (change_p && NONDEBUG_INSN_P (curr_insn)
8023 226835102 : && (set = single_set (curr_insn)) != NULL_RTX)
8024 : {
8025 31167341 : dregno = get_regno (SET_DEST (set));
8026 62334682 : sregno = get_regno (SET_SRC (set));
8027 : }
8028 :
8029 194640973 : if (sregno >= 0 && dregno >= 0)
8030 : {
8031 11019906 : if (bitmap_bit_p (remove_pseudos, dregno)
8032 11019906 : && ! REG_P (lra_reg_info[dregno].restore_rtx))
8033 : {
8034 : /* invariant inheritance pseudo <- original pseudo */
8035 7197 : if (lra_dump_file != NULL)
8036 : {
8037 0 : fprintf (lra_dump_file, " Removing invariant inheritance:\n");
8038 0 : dump_insn_slim (lra_dump_file, curr_insn);
8039 0 : fprintf (lra_dump_file, "\n");
8040 : }
8041 7197 : delete_move_and_clobber (curr_insn, dregno);
8042 7197 : done_p = true;
8043 : }
8044 11012709 : else if (bitmap_bit_p (remove_pseudos, sregno)
8045 11012709 : && ! REG_P (lra_reg_info[sregno].restore_rtx))
8046 : {
8047 : /* reload pseudo <- invariant inheritance pseudo */
8048 7197 : start_sequence ();
8049 : /* We cannot just change the source. It might be
8050 : an insn different from the move. */
8051 7197 : emit_insn (lra_reg_info[sregno].restore_rtx);
8052 7197 : rtx_insn *new_insns = end_sequence ();
8053 7197 : lra_assert (single_set (new_insns) != NULL
8054 : && SET_DEST (set) == SET_DEST (single_set (new_insns)));
8055 7197 : lra_process_new_insns (curr_insn, NULL, new_insns,
8056 : "Changing reload<-invariant inheritance");
8057 7197 : delete_move_and_clobber (curr_insn, dregno);
8058 7197 : done_p = true;
8059 : }
8060 11005512 : else if ((bitmap_bit_p (remove_pseudos, sregno)
8061 1212652 : && (get_regno (lra_reg_info[sregno].restore_rtx) == dregno
8062 569046 : || (bitmap_bit_p (remove_pseudos, dregno)
8063 185602 : && get_regno (lra_reg_info[sregno].restore_rtx) >= 0
8064 185602 : && (get_regno (lra_reg_info[sregno].restore_rtx)
8065 185602 : == get_regno (lra_reg_info[dregno].restore_rtx)))))
8066 11481757 : || (bitmap_bit_p (remove_pseudos, dregno)
8067 652472 : && get_regno (lra_reg_info[dregno].restore_rtx) == sregno))
8068 : /* One of the following cases:
8069 : original <- removed inheritance pseudo
8070 : removed inherit pseudo <- another removed inherit pseudo
8071 : removed inherit pseudo <- original pseudo
8072 : Or
8073 : removed_split_pseudo <- original_reg
8074 : original_reg <- removed_split_pseudo */
8075 : {
8076 177047 : if (lra_dump_file != NULL)
8077 : {
8078 0 : fprintf (lra_dump_file, " Removing %s:\n",
8079 0 : bitmap_bit_p (&lra_split_regs, sregno)
8080 0 : || bitmap_bit_p (&lra_split_regs, dregno)
8081 : ? "split" : "inheritance");
8082 0 : dump_insn_slim (lra_dump_file, curr_insn);
8083 : }
8084 177047 : delete_move_and_clobber (curr_insn, dregno);
8085 177047 : done_p = true;
8086 : }
8087 10828465 : else if (bitmap_bit_p (remove_pseudos, sregno)
8088 10828465 : && bitmap_bit_p (&lra_inheritance_pseudos, sregno))
8089 : {
8090 : /* Search the following pattern:
8091 : inherit_or_split_pseudo1 <- inherit_or_split_pseudo2
8092 : original_pseudo <- inherit_or_split_pseudo1
8093 : where the 2nd insn is the current insn and
8094 : inherit_or_split_pseudo2 is not removed. If it is found,
8095 : change the current insn onto:
8096 : original_pseudo <- inherit_or_split_pseudo2. */
8097 745268 : for (prev_insn = PREV_INSN (curr_insn);
8098 745268 : prev_insn != NULL_RTX && ! NONDEBUG_INSN_P (prev_insn);
8099 269023 : prev_insn = PREV_INSN (prev_insn))
8100 : ;
8101 476245 : if (prev_insn != NULL_RTX && BLOCK_FOR_INSN (prev_insn) == bb
8102 463271 : && (prev_set = single_set (prev_insn)) != NULL_RTX
8103 : /* There should be no subregs in insn we are
8104 : searching because only the original reg might
8105 : be in subreg when we changed the mode of
8106 : load/store for splitting. */
8107 457261 : && REG_P (SET_DEST (prev_set))
8108 350865 : && REG_P (SET_SRC (prev_set))
8109 269134 : && (int) REGNO (SET_DEST (prev_set)) == sregno
8110 182931 : && ((prev_sregno = REGNO (SET_SRC (prev_set)))
8111 : >= FIRST_PSEUDO_REGISTER)
8112 182931 : && (lra_reg_info[prev_sregno].restore_rtx == NULL_RTX
8113 143028 : ||
8114 : /* As we consider chain of inheritance or
8115 : splitting described in above comment we should
8116 : check that sregno and prev_sregno were
8117 : inheritance/split pseudos created from the
8118 : same original regno. */
8119 286056 : (get_regno (lra_reg_info[sregno].restore_rtx) >= 0
8120 286056 : && (get_regno (lra_reg_info[sregno].restore_rtx)
8121 286056 : == get_regno (lra_reg_info[prev_sregno].restore_rtx))))
8122 659176 : && ! bitmap_bit_p (remove_pseudos, prev_sregno))
8123 : {
8124 101764 : int restore_regno = get_regno (lra_reg_info[sregno].restore_rtx);
8125 101764 : if (restore_regno < 0)
8126 0 : restore_regno = prev_sregno;
8127 101764 : lra_assert (GET_MODE (SET_SRC (prev_set))
8128 : == GET_MODE (regno_reg_rtx[restore_regno]));
8129 : /* Although we have a single set, the insn can
8130 : contain more one sregno register occurrence
8131 : as a source. Change all occurrences. */
8132 101764 : lra_substitute_pseudo_within_insn (curr_insn, sregno,
8133 : regno_reg_rtx[restore_regno],
8134 : false);
8135 : /* As we are finishing with processing the insn
8136 : here, check the destination too as it might
8137 : inheritance pseudo for another pseudo. */
8138 101764 : if (bitmap_bit_p (remove_pseudos, dregno)
8139 0 : && bitmap_bit_p (&lra_inheritance_pseudos, dregno)
8140 101764 : && (restore_rtx
8141 0 : = lra_reg_info[dregno].restore_rtx) != NULL_RTX)
8142 : {
8143 0 : if (GET_CODE (SET_DEST (set)) == SUBREG)
8144 0 : SUBREG_REG (SET_DEST (set)) = restore_rtx;
8145 : else
8146 0 : SET_DEST (set) = restore_rtx;
8147 : }
8148 101764 : lra_push_insn_and_update_insn_regno_info (curr_insn);
8149 101764 : lra_set_used_insn_alternative_by_uid
8150 101764 : (INSN_UID (curr_insn), LRA_UNKNOWN_ALT);
8151 101764 : done_p = true;
8152 101764 : if (lra_dump_file != NULL)
8153 : {
8154 0 : fprintf (lra_dump_file, " Change reload insn:\n");
8155 0 : dump_insn_slim (lra_dump_file, curr_insn);
8156 : }
8157 : }
8158 : }
8159 : }
8160 191441 : if (! done_p)
8161 : {
8162 194347768 : struct lra_insn_reg *reg;
8163 194347768 : bool restored_regs_p = false;
8164 194347768 : bool kept_regs_p = false;
8165 :
8166 194347768 : curr_id = lra_get_insn_recog_data (curr_insn);
8167 402709277 : for (reg = curr_id->regs; reg != NULL; reg = reg->next)
8168 : {
8169 208361509 : regno = reg->regno;
8170 208361509 : restore_rtx = lra_reg_info[regno].restore_rtx;
8171 208361509 : if (restore_rtx != NULL_RTX)
8172 : {
8173 5957263 : if (change_p && bitmap_bit_p (remove_pseudos, regno))
8174 : {
8175 831635 : lra_substitute_pseudo_within_insn
8176 831635 : (curr_insn, regno, restore_rtx, false);
8177 831635 : restored_regs_p = true;
8178 : }
8179 : else
8180 : kept_regs_p = true;
8181 : }
8182 : }
8183 194347768 : if (NONDEBUG_INSN_P (curr_insn) && kept_regs_p)
8184 : {
8185 : /* The instruction has changed since the previous
8186 : constraints pass. */
8187 4497629 : lra_push_insn_and_update_insn_regno_info (curr_insn);
8188 4497629 : lra_set_used_insn_alternative_by_uid
8189 4497629 : (INSN_UID (curr_insn), LRA_UNKNOWN_ALT);
8190 : }
8191 189850139 : else if (restored_regs_p)
8192 : /* The instruction has been restored to the form that
8193 : it had during the previous constraints pass. */
8194 668628 : lra_update_insn_regno_info (curr_insn);
8195 5166257 : if (restored_regs_p && lra_dump_file != NULL)
8196 : {
8197 0 : fprintf (lra_dump_file, " Insn after restoring regs:\n");
8198 0 : dump_insn_slim (lra_dump_file, curr_insn);
8199 : }
8200 : }
8201 : }
8202 : }
8203 1568078 : return change_p;
8204 : }
8205 :
8206 : /* If optional reload pseudos failed to get a hard register or was not
8207 : inherited, it is better to remove optional reloads. We do this
8208 : transformation after undoing inheritance to figure out necessity to
8209 : remove optional reloads easier. Return true if we do any
8210 : change. */
8211 : static bool
8212 1568078 : undo_optional_reloads (void)
8213 : {
8214 1568078 : bool change_p, keep_p;
8215 1568078 : unsigned int regno, uid;
8216 1568078 : bitmap_iterator bi, bi2;
8217 1568078 : rtx_insn *insn;
8218 1568078 : rtx set, src, dest;
8219 1568078 : auto_bitmap removed_optional_reload_pseudos (®_obstack);
8220 :
8221 1568078 : bitmap_copy (removed_optional_reload_pseudos, &lra_optional_reload_pseudos);
8222 2584294 : EXECUTE_IF_SET_IN_BITMAP (&lra_optional_reload_pseudos, 0, regno, bi)
8223 : {
8224 1016216 : keep_p = false;
8225 : /* Keep optional reloads from previous subpasses. */
8226 1016216 : if (lra_reg_info[regno].restore_rtx == NULL_RTX
8227 : /* If the original pseudo changed its allocation, just
8228 : removing the optional pseudo is dangerous as the original
8229 : pseudo will have longer live range. */
8230 1016216 : || reg_renumber[REGNO (lra_reg_info[regno].restore_rtx)] >= 0)
8231 : keep_p = true;
8232 630863 : else if (reg_renumber[regno] >= 0)
8233 1814578 : EXECUTE_IF_SET_IN_BITMAP (&lra_reg_info[regno].insn_bitmap, 0, uid, bi2)
8234 : {
8235 1321647 : insn = lra_insn_recog_data[uid]->insn;
8236 1321647 : if ((set = single_set (insn)) == NULL_RTX)
8237 5664 : continue;
8238 1315983 : src = SET_SRC (set);
8239 1315983 : dest = SET_DEST (set);
8240 1315983 : if ((! REG_P (src) && ! SUBREG_P (src))
8241 705021 : || (! REG_P (dest) && ! SUBREG_P (dest)))
8242 610990 : continue;
8243 704993 : if (get_regno (dest) == (int) regno
8244 : /* Ignore insn for optional reloads itself. */
8245 1184344 : && (get_regno (lra_reg_info[regno].restore_rtx)
8246 592172 : != get_regno (src))
8247 : /* Check only inheritance on last inheritance pass. */
8248 123723 : && get_regno (src) >= new_regno_start
8249 : /* Check that the optional reload was inherited. */
8250 828716 : && bitmap_bit_p (&lra_inheritance_pseudos, get_regno (src)))
8251 : {
8252 : keep_p = true;
8253 : break;
8254 : }
8255 : }
8256 1002007 : if (keep_p)
8257 : {
8258 509076 : bitmap_clear_bit (removed_optional_reload_pseudos, regno);
8259 509076 : if (lra_dump_file != NULL)
8260 3 : fprintf (lra_dump_file, "Keep optional reload reg %d\n", regno);
8261 : }
8262 : }
8263 1568078 : change_p = ! bitmap_empty_p (removed_optional_reload_pseudos);
8264 1568078 : auto_bitmap insn_bitmap (®_obstack);
8265 2075218 : EXECUTE_IF_SET_IN_BITMAP (removed_optional_reload_pseudos, 0, regno, bi)
8266 : {
8267 507140 : if (lra_dump_file != NULL)
8268 2 : fprintf (lra_dump_file, "Remove optional reload reg %d\n", regno);
8269 507140 : bitmap_copy (insn_bitmap, &lra_reg_info[regno].insn_bitmap);
8270 1611959 : EXECUTE_IF_SET_IN_BITMAP (insn_bitmap, 0, uid, bi2)
8271 : {
8272 : /* We may have already removed a clobber. */
8273 1104819 : if (!lra_insn_recog_data[uid])
8274 0 : continue;
8275 1104819 : insn = lra_insn_recog_data[uid]->insn;
8276 1104819 : if ((set = single_set (insn)) != NULL_RTX)
8277 : {
8278 1099337 : src = SET_SRC (set);
8279 1099337 : dest = SET_DEST (set);
8280 501641 : if ((REG_P (src) || SUBREG_P (src))
8281 597708 : && (REG_P (dest) || SUBREG_P (dest))
8282 1697016 : && ((get_regno (src) == (int) regno
8283 231658 : && (get_regno (lra_reg_info[regno].restore_rtx)
8284 115829 : == get_regno (dest)))
8285 512999 : || (get_regno (dest) == (int) regno
8286 481850 : && (get_regno (lra_reg_info[regno].restore_rtx)
8287 481850 : == get_regno (src)))))
8288 : {
8289 566471 : if (lra_dump_file != NULL)
8290 : {
8291 0 : fprintf (lra_dump_file, " Deleting move %u\n",
8292 0 : INSN_UID (insn));
8293 0 : dump_insn_slim (lra_dump_file, insn);
8294 : }
8295 1132942 : delete_move_and_clobber (insn, get_regno (dest));
8296 566471 : continue;
8297 : }
8298 : /* We should not worry about generation memory-memory
8299 : moves here as if the corresponding inheritance did
8300 : not work (inheritance pseudo did not get a hard reg),
8301 : we remove the inheritance pseudo and the optional
8302 : reload. */
8303 : }
8304 538348 : rtx pat = PATTERN (insn);
8305 0 : if (GET_CODE (pat) == CLOBBER && REG_P (SET_DEST (pat))
8306 538348 : && get_regno (SET_DEST (pat)) == (int) regno)
8307 : /* Refuse to remap clobbers to preexisting pseudos. */
8308 0 : gcc_unreachable ();
8309 538348 : lra_substitute_pseudo_within_insn
8310 538348 : (insn, regno, lra_reg_info[regno].restore_rtx, false);
8311 538348 : lra_update_insn_regno_info (insn);
8312 538348 : if (lra_dump_file != NULL)
8313 : {
8314 4 : fprintf (lra_dump_file,
8315 : " Restoring original insn:\n");
8316 4 : dump_insn_slim (lra_dump_file, insn);
8317 : }
8318 : }
8319 : }
8320 : /* Clear restore_regnos. */
8321 2584294 : EXECUTE_IF_SET_IN_BITMAP (&lra_optional_reload_pseudos, 0, regno, bi)
8322 1016216 : lra_reg_info[regno].restore_rtx = NULL_RTX;
8323 1568078 : return change_p;
8324 1568078 : }
8325 :
8326 : /* Entry function for undoing inheritance/split transformation. Return true
8327 : if we did any RTL change in this pass. */
8328 : bool
8329 1571259 : lra_undo_inheritance (void)
8330 : {
8331 1571259 : unsigned int regno;
8332 1571259 : int hard_regno;
8333 1571259 : int n_all_inherit, n_inherit, n_all_split, n_split;
8334 1571259 : rtx restore_rtx;
8335 1571259 : bitmap_iterator bi;
8336 1571259 : bool change_p;
8337 :
8338 1571259 : lra_undo_inheritance_iter++;
8339 1571259 : if (lra_undo_inheritance_iter > LRA_MAX_INHERITANCE_PASSES)
8340 : return false;
8341 1568078 : if (lra_dump_file != NULL)
8342 97 : fprintf (lra_dump_file,
8343 : "\n********** Undoing inheritance #%d: **********\n\n",
8344 : lra_undo_inheritance_iter);
8345 1568078 : auto_bitmap remove_pseudos (®_obstack);
8346 1568078 : n_inherit = n_all_inherit = 0;
8347 3438438 : EXECUTE_IF_SET_IN_BITMAP (&lra_inheritance_pseudos, 0, regno, bi)
8348 1870360 : if (lra_reg_info[regno].restore_rtx != NULL_RTX)
8349 : {
8350 1184348 : n_all_inherit++;
8351 1184348 : if (reg_renumber[regno] < 0
8352 : /* If the original pseudo changed its allocation, just
8353 : removing inheritance is dangerous as for changing
8354 : allocation we used shorter live-ranges. */
8355 1184348 : && (! REG_P (lra_reg_info[regno].restore_rtx)
8356 419931 : || reg_renumber[REGNO (lra_reg_info[regno].restore_rtx)] < 0))
8357 427128 : bitmap_set_bit (remove_pseudos, regno);
8358 : else
8359 757220 : n_inherit++;
8360 : }
8361 1568078 : if (lra_dump_file != NULL && n_all_inherit != 0)
8362 2 : fprintf (lra_dump_file, "Inherit %d out of %d (%.2f%%)\n",
8363 : n_inherit, n_all_inherit,
8364 2 : (double) n_inherit / n_all_inherit * 100);
8365 1568078 : n_split = n_all_split = 0;
8366 2520596 : EXECUTE_IF_SET_IN_BITMAP (&lra_split_regs, 0, regno, bi)
8367 952518 : if ((restore_rtx = lra_reg_info[regno].restore_rtx) != NULL_RTX)
8368 : {
8369 662133 : int restore_regno = REGNO (restore_rtx);
8370 :
8371 662133 : n_all_split++;
8372 1324184 : hard_regno = (restore_regno >= FIRST_PSEUDO_REGISTER
8373 662133 : ? reg_renumber[restore_regno] : restore_regno);
8374 662133 : if (hard_regno < 0 || reg_renumber[regno] == hard_regno)
8375 2358 : bitmap_set_bit (remove_pseudos, regno);
8376 : else
8377 : {
8378 659775 : n_split++;
8379 659775 : if (lra_dump_file != NULL)
8380 0 : fprintf (lra_dump_file, " Keep split r%d (orig=r%d)\n",
8381 : regno, restore_regno);
8382 : }
8383 : }
8384 1568078 : if (lra_dump_file != NULL && n_all_split != 0)
8385 0 : fprintf (lra_dump_file, "Split %d out of %d (%.2f%%)\n",
8386 : n_split, n_all_split,
8387 0 : (double) n_split / n_all_split * 100);
8388 1568078 : change_p = remove_inheritance_pseudos (remove_pseudos);
8389 : /* Clear restore_regnos. */
8390 3438438 : EXECUTE_IF_SET_IN_BITMAP (&lra_inheritance_pseudos, 0, regno, bi)
8391 1870360 : lra_reg_info[regno].restore_rtx = NULL_RTX;
8392 2520596 : EXECUTE_IF_SET_IN_BITMAP (&lra_split_regs, 0, regno, bi)
8393 952518 : lra_reg_info[regno].restore_rtx = NULL_RTX;
8394 1568078 : change_p = undo_optional_reloads () || change_p;
8395 : if (change_p)
8396 110860 : lra_dump_insns_if_possible ("changed func after undoing inheritance");
8397 1568078 : return change_p;
8398 1568078 : }
|