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 235123156 : strip_subreg (rtx *loc)
172 : {
173 103844135 : 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 96354 : get_try_hard_regno (int regno)
180 : {
181 96354 : int hard_regno;
182 96354 : enum reg_class rclass;
183 :
184 96354 : if ((hard_regno = regno) >= FIRST_PSEUDO_REGISTER)
185 96354 : hard_regno = lra_get_regno_hard_regno (regno);
186 96354 : if (hard_regno >= 0)
187 : return hard_regno;
188 61186 : rclass = lra_get_allocno_class (regno);
189 61186 : if (rclass == NO_REGS)
190 : return -1;
191 58780 : 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 298923431 : get_hard_regno (rtx x)
200 : {
201 298923431 : rtx reg;
202 298923431 : int hard_regno;
203 :
204 298923431 : reg = x;
205 298923431 : if (SUBREG_P (x))
206 5447767 : reg = SUBREG_REG (x);
207 298923431 : if (! REG_P (reg))
208 : return -1;
209 206698206 : int regno = REGNO (reg);
210 206698206 : if (HARD_REGISTER_NUM_P (regno))
211 35897044 : hard_regno = lra_get_elimination_hard_regno (regno);
212 : else
213 170801162 : hard_regno = lra_get_regno_hard_regno (regno);
214 206698206 : if (hard_regno < 0)
215 : return -1;
216 188370510 : if (SUBREG_P (x))
217 4712652 : hard_regno += subreg_regno_offset (hard_regno, GET_MODE (reg),
218 4712652 : 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 529973335 : get_reg_class (int regno)
228 : {
229 529973335 : int hard_regno;
230 :
231 529973335 : if (HARD_REGISTER_NUM_P (regno))
232 67637584 : hard_regno = lra_get_elimination_hard_regno (regno);
233 : else
234 462335751 : hard_regno = lra_get_regno_hard_regno (regno);
235 529973335 : if (hard_regno >= 0)
236 332983002 : return REGNO_REG_CLASS (hard_regno);
237 196990333 : if (regno >= new_regno_start)
238 63073738 : 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 18978723 : enough_allocatable_hard_regs_p (enum reg_class reg_class,
246 : enum machine_mode reg_mode)
247 : {
248 18978723 : int i, j, hard_regno, class_size, nregs;
249 :
250 37957446 : if (hard_reg_set_subset_p (reg_class_contents[reg_class], lra_no_alloc_regs))
251 : return false;
252 6600197 : class_size = ira_class_hard_regs_num[reg_class];
253 6600197 : for (i = 0; i < class_size; i++)
254 : {
255 6600197 : hard_regno = ira_class_hard_regs[reg_class][i];
256 6600197 : nregs = hard_regno_nregs (hard_regno, reg_mode);
257 6600197 : if (nregs == 1)
258 : return true;
259 292716 : for (j = 0; j < nregs; j++)
260 195144 : if (TEST_HARD_REG_BIT (lra_no_alloc_regs, hard_regno + j)
261 195144 : || ! TEST_HARD_REG_BIT (reg_class_contents[reg_class],
262 : hard_regno + j))
263 : break;
264 97572 : 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 224969762 : 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 224969762 : enum reg_class rclass, common_class;
294 224969762 : machine_mode reg_mode;
295 224969762 : rtx src;
296 224969762 : int regno = REGNO (reg);
297 :
298 224969762 : if (new_class != NULL)
299 116043991 : *new_class = NO_REGS;
300 224969762 : if (regno < FIRST_PSEUDO_REGISTER)
301 : {
302 28554201 : rtx final_reg = reg;
303 28554201 : rtx *final_loc = &final_reg;
304 :
305 28554201 : lra_eliminate_reg_if_possible (final_loc);
306 28554201 : return TEST_HARD_REG_BIT (reg_class_contents[cl], REGNO (*final_loc));
307 : }
308 196415561 : reg_mode = GET_MODE (reg);
309 196415561 : rclass = get_reg_class (regno);
310 196415561 : src = curr_insn_set != NULL ? SET_SRC (curr_insn_set) : NULL;
311 196415561 : 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 196415561 : || (!allow_all_reload_class_changes_p
318 15195172 : && INSN_UID (curr_insn) >= new_insn_uid_start
319 14650663 : && src != NULL
320 14650663 : && ((REG_P (src) || MEM_P (src))
321 1506902 : || (GET_CODE (src) == SUBREG
322 701181 : && (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 13844942 : return ((regno >= new_regno_start && rclass == ALL_REGS)
326 191279245 : || (rclass != NO_REGS && ira_class_subset_p[rclass][cl]
327 207613074 : && ! hard_reg_set_subset_p (reg_class_contents[cl],
328 : lra_no_alloc_regs)));
329 : else
330 : {
331 18978723 : common_class = ira_reg_class_subset[rclass][cl];
332 18978723 : if (new_class != NULL)
333 5428005 : *new_class = common_class;
334 18978723 : 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 18978723 : && (new_class != NULL || common_class == rclass
338 1080672 : || !SMALL_REGISTER_CLASS_P (common_class)));
339 : }
340 : }
341 :
342 : /* Return true if REGNO satisfies a memory constraint. */
343 : static bool
344 65708076 : 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 36582896 : 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 36582896 : 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 77047406 : address_eliminator::address_eliminator (struct address_info *ad)
387 77047406 : : m_ad (ad),
388 77047406 : m_base_loc (strip_subreg (ad->base_term)),
389 77047406 : m_base_reg (NULL_RTX),
390 77047406 : m_index_loc (strip_subreg (ad->index_term)),
391 77047406 : m_index_reg (NULL_RTX)
392 : {
393 77047406 : if (m_base_loc != NULL)
394 : {
395 64258373 : 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 64258373 : if (REG_P (m_base_reg))
401 64258373 : lra_eliminate_reg_if_possible (m_base_loc);
402 64258373 : if (m_ad->base_term2 != NULL)
403 0 : *m_ad->base_term2 = *m_ad->base_term;
404 : }
405 77047406 : if (m_index_loc != NULL)
406 : {
407 3585387 : m_index_reg = *m_index_loc;
408 3585387 : if (REG_P (m_index_reg))
409 3585387 : lra_eliminate_reg_if_possible (m_index_loc);
410 : }
411 77047406 : }
412 :
413 77047406 : address_eliminator::~address_eliminator ()
414 : {
415 77047406 : if (m_base_loc && *m_base_loc != m_base_reg)
416 : {
417 45451702 : *m_base_loc = m_base_reg;
418 45451702 : if (m_ad->base_term2 != NULL)
419 0 : *m_ad->base_term2 = *m_ad->base_term;
420 : }
421 77047406 : if (m_index_loc && *m_index_loc != m_index_reg)
422 0 : *m_index_loc = m_index_reg;
423 77047406 : }
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 36561186 : valid_address_p (rtx op, struct address_info *ad,
431 : enum constraint_num constraint)
432 : {
433 36561186 : 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 36561186 : 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 36561186 : return valid_address_p (ad->mode, *ad->outer, ad->as);
445 36561186 : }
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 646647682 : extract_mem_from_operand (rtx op)
452 : {
453 648375719 : for (rtx x = op;; x = XEXP (x, 0))
454 : {
455 648375719 : if (MEM_P (x))
456 : return x;
457 462262473 : if (GET_RTX_LENGTH (GET_CODE (x)) != 1
458 379010730 : || 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 37881313 : satisfies_memory_constraint_p (rtx op, enum constraint_num constraint)
468 : {
469 37881313 : struct address_info ad;
470 37881313 : rtx mem = extract_mem_from_operand (op);
471 37881313 : if (!MEM_P (mem))
472 : return false;
473 :
474 36841392 : decompose_mem_address (&ad, mem);
475 36841392 : address_eliminator eliminator (&ad);
476 36841392 : return constraint_satisfied_p (op, constraint);
477 36841392 : }
478 :
479 : /* Return true if the eliminated form of address AD satisfies extra
480 : address constraint CONSTRAINT. */
481 : static bool
482 3644828 : satisfies_address_constraint_p (struct address_info *ad,
483 : enum constraint_num constraint)
484 : {
485 3644828 : address_eliminator eliminator (ad);
486 3644828 : return constraint_satisfied_p (*ad->outer, constraint);
487 3644828 : }
488 :
489 : /* Return true if the eliminated form of address OP satisfies extra
490 : address constraint CONSTRAINT. */
491 : static bool
492 1791741 : satisfies_address_constraint_p (rtx op, enum constraint_num constraint)
493 : {
494 1791741 : struct address_info ad;
495 :
496 1791741 : decompose_lea_address (&ad, &op);
497 1791741 : 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 2024421 : lra_pointer_equiv_set_add (rtx x)
506 : {
507 2024421 : pointer_equiv_set->add (x);
508 2024421 : }
509 :
510 : /* Return true if x is in pointer_equiv_set. */
511 : bool
512 10224964 : lra_pointer_equiv_set_in (rtx x)
513 : {
514 10224964 : 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 1531123 : lra_init_equiv (void)
522 : {
523 1531123 : ira_expand_reg_equiv ();
524 74364691 : for (int i = FIRST_PSEUDO_REGISTER; i < max_reg_num (); i++)
525 : {
526 71302445 : rtx res;
527 :
528 71302445 : if ((res = ira_reg_equiv[i].memory) != NULL_RTX)
529 3025261 : ira_reg_equiv[i].memory = copy_rtx (res);
530 71302445 : if ((res = ira_reg_equiv[i].invariant) != NULL_RTX)
531 912569 : ira_reg_equiv[i].invariant = copy_rtx (res);
532 : }
533 1531123 : pointer_equiv_set = new hash_set <rtx>;
534 1531123 : }
535 :
536 : /* Finish equivalence data for LRA. */
537 : void
538 1531123 : lra_finish_equiv (void)
539 : {
540 3062246 : delete pointer_equiv_set;
541 1531123 : }
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 211343646 : update_equiv (int regno)
550 : {
551 211343646 : rtx x;
552 :
553 211343646 : if ((x = ira_reg_equiv[regno].memory) != NULL_RTX)
554 9161956 : ira_reg_equiv[regno].memory
555 9161956 : = simplify_replace_fn_rtx (x, NULL_RTX, loc_equivalence_callback,
556 : NULL_RTX);
557 211343646 : if ((x = ira_reg_equiv[regno].invariant) != NULL_RTX)
558 2833188 : ira_reg_equiv[regno].invariant
559 2833188 : = simplify_replace_fn_rtx (x, NULL_RTX, loc_equivalence_callback,
560 : NULL_RTX);
561 211343646 : }
562 :
563 : /* If we have decided to substitute X with another value, return that
564 : value, otherwise return X. */
565 : static rtx
566 450844968 : get_equiv (rtx x)
567 : {
568 450844968 : int regno;
569 450844968 : rtx res;
570 :
571 304949322 : if (! REG_P (x) || (regno = REGNO (x)) < FIRST_PSEUDO_REGISTER
572 202548684 : || regno >= ira_reg_equiv_len
573 202548684 : || ! ira_reg_equiv[regno].defined_p
574 26671490 : || ! ira_reg_equiv[regno].profitable_p
575 477476146 : || lra_get_regno_hard_regno (regno) >= 0)
576 : return x;
577 5239853 : if ((res = ira_reg_equiv[regno].memory) != NULL_RTX)
578 : {
579 2300180 : if (targetm.cannot_substitute_mem_equiv_p (res))
580 : return x;
581 2300180 : return res;
582 : }
583 2939673 : if ((res = ira_reg_equiv[regno].constant) != NULL_RTX)
584 : {
585 944224 : if (targetm.cannot_substitute_const_equiv_p (res))
586 : return x;
587 944224 : return res;
588 : }
589 1995449 : 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 253558530 : get_equiv_with_elimination (rtx x, rtx_insn *insn)
599 : {
600 253558530 : rtx res = get_equiv (x);
601 :
602 253558530 : if (x == res || CONSTANT_P (res))
603 : return res;
604 1572761 : res = lra_eliminate_regs_1 (insn, res, GET_MODE (res),
605 : false, false, 0, true);
606 1572761 : if (REG_POINTER (x))
607 1088435 : lra_pointer_equiv_set_add (res);
608 : return res;
609 : }
610 :
611 : /* Record invariant INVARIANT_RTX as an equivalence of REG. The equivalence is
612 : used instead of spilling pseudo REG when it gets no hard register, which
613 : avoids a stack slot and therefore a change of the elimination offsets.
614 :
615 : Do not do this when spill slots are not shared as every lra_spill pass
616 : allocates **fresh** slots, so the frame grows, offsets are changed and can
617 : be reloaded for targets with small address displacement. This can result in
618 : LRA cycling (see PR 128174). */
619 : static void
620 30494 : add_invariant (rtx reg, rtx invariant_rtx)
621 : {
622 30494 : int regno = REGNO (reg);
623 :
624 30494 : if (! flag_ira_share_spill_slots)
625 : return;
626 30494 : ira_expand_reg_equiv ();
627 30494 : ira_reg_equiv[regno].defined_p = true;
628 30494 : ira_reg_equiv[regno].profitable_p = true;
629 30494 : if (CONSTANT_P (invariant_rtx))
630 30494 : ira_reg_equiv[regno].constant = copy_rtx (invariant_rtx);
631 : else
632 0 : ira_reg_equiv[regno].invariant = copy_rtx (invariant_rtx);
633 30494 : if (lra_dump_file != NULL)
634 : {
635 0 : fprintf (lra_dump_file, " Add r%d invariant: ", regno);
636 0 : dump_value_slim (lra_dump_file, invariant_rtx, 0);
637 0 : fprintf (lra_dump_file, "\n");
638 : }
639 : }
640 :
641 : /* Set up curr_operand_mode. */
642 : static void
643 109639456 : init_curr_operand_mode (void)
644 : {
645 109639456 : int nop = curr_static_id->n_operands;
646 341990946 : for (int i = 0; i < nop; i++)
647 : {
648 232351490 : machine_mode mode = GET_MODE (*curr_id->operand_loc[i]);
649 232351490 : if (mode == VOIDmode)
650 : {
651 : /* The .md mode for address operands is the mode of the
652 : addressed value rather than the mode of the address itself. */
653 44987551 : if (curr_id->icode >= 0 && curr_static_id->operand[i].is_address)
654 31 : mode = Pmode;
655 : else
656 44987520 : mode = curr_static_id->operand[i].mode;
657 : }
658 232351490 : curr_operand_mode[i] = mode;
659 : }
660 109639456 : }
661 :
662 :
663 :
664 : /* The page contains code to reuse input reloads. */
665 :
666 : /* Structure describes input reload of the current insns. */
667 : struct input_reload
668 : {
669 : /* True for input reload of matched operands. */
670 : bool match_p;
671 : /* True for input reload of inout earlyclobber operand. */
672 : bool early_clobber_p;
673 : /* Reloaded value. */
674 : rtx input;
675 : /* Reload pseudo used. */
676 : rtx reg;
677 : };
678 :
679 : /* The number of elements in the following array. */
680 : static int curr_insn_input_reloads_num;
681 : /* Array containing info about input reloads. It is used to find the
682 : same input reload and reuse the reload pseudo in this case. */
683 : static struct input_reload curr_insn_input_reloads[LRA_MAX_INSN_RELOADS];
684 :
685 : /* Initiate data concerning reuse of input reloads for the current
686 : insn. */
687 : static void
688 109639456 : init_curr_insn_input_reloads (void)
689 : {
690 109639456 : curr_insn_input_reloads_num = 0;
691 0 : }
692 :
693 : /* The canonical form of an rtx inside a MEM is not necessarily the same as the
694 : canonical form of the rtx outside the MEM. Fix this up in the case that
695 : we're reloading an address (and therefore pulling it outside a MEM). */
696 : static rtx
697 125 : canonicalize_reload_addr (rtx addr)
698 : {
699 125 : subrtx_var_iterator::array_type array;
700 458 : FOR_EACH_SUBRTX_VAR (iter, array, addr, NONCONST)
701 : {
702 333 : rtx x = *iter;
703 333 : if (GET_CODE (x) == MULT && CONST_INT_P (XEXP (x, 1)))
704 : {
705 14 : const HOST_WIDE_INT ci = INTVAL (XEXP (x, 1));
706 347 : const int pwr2 = exact_log2 (ci);
707 14 : if (pwr2 > 0)
708 : {
709 : /* Rewrite this to use a shift instead, which is canonical when
710 : outside of a MEM. */
711 14 : PUT_CODE (x, ASHIFT);
712 14 : XEXP (x, 1) = GEN_INT (pwr2);
713 : }
714 : }
715 : }
716 :
717 125 : return addr;
718 125 : }
719 :
720 : /* Return rtx accessing reload REG of RCLASS matching another reload reg in
721 : MODE. */
722 : static rtx
723 114068 : get_matching_reload_reg_subreg (machine_mode mode, rtx reg,
724 : enum reg_class rclass)
725 : {
726 114068 : int hard_regno = ira_class_hard_regs[rclass][0];
727 114068 : if (subreg_regno_offset (hard_regno,
728 114068 : GET_MODE (reg),
729 114068 : subreg_lowpart_offset (mode, GET_MODE (reg)),
730 : mode) == 0)
731 : /* For matching scalar int modes generate the right subreg byte offset for
732 : BE targets -- see call of reload.cc:operands_match_p in
733 : recog.cc:constrain_operands. */
734 114068 : return lowpart_subreg (mode, reg, GET_MODE (reg));
735 0 : int offset = (lra_constraint_offset (hard_regno, GET_MODE (reg))
736 0 : - lra_constraint_offset (hard_regno, mode)) * UNITS_PER_WORD;
737 0 : lra_assert (offset >= 0);
738 0 : return gen_rtx_SUBREG (mode, reg, offset);
739 : }
740 :
741 : /* Create a new pseudo using MODE, RCLASS, EXCLUDE_START_HARD_REGS, ORIGINAL or
742 : reuse an existing reload pseudo. Don't reuse an existing reload pseudo if
743 : IN_SUBREG_P is true and the reused pseudo should be wrapped up in a SUBREG.
744 : EARLY_CLOBBER_P is true for input reload of inout early clobber operand.
745 : The result pseudo is returned through RESULT_REG. Return TRUE if we created
746 : a new pseudo, FALSE if we reused an existing reload pseudo. Use TITLE to
747 : describe new registers for debug purposes. */
748 : static bool
749 3930452 : get_reload_reg (enum op_type type, machine_mode mode, rtx original,
750 : enum reg_class rclass, HARD_REG_SET *exclude_start_hard_regs,
751 : bool in_subreg_p, bool early_clobber_p,
752 : const char *title, rtx *result_reg)
753 : {
754 3930452 : int i, regno;
755 3930452 : enum reg_class new_class;
756 :
757 3930452 : if (type == OP_OUT)
758 : {
759 : /* Output reload registers tend to start out with a conservative
760 : choice of register class. Usually this is ALL_REGS, although
761 : a target might narrow it (for performance reasons) through
762 : targetm.preferred_reload_class. It's therefore quite common
763 : for a reload instruction to require a more restrictive class
764 : than the class that was originally assigned to the reload register.
765 :
766 : In these situations, it's more efficient to refine the choice
767 : of register class rather than create a second reload register.
768 : This also helps to avoid cycling for registers that are only
769 : used by reload instructions. */
770 995178 : if (REG_P (original)
771 716895 : && (int) REGNO (original) >= new_regno_start
772 2772 : && (INSN_UID (curr_insn) >= new_insn_uid_start
773 250 : || ira_former_scratch_p (REGNO (original)))
774 2772 : && in_class_p (original, rclass, &new_class, true)
775 995428 : && (exclude_start_hard_regs == nullptr
776 250 : || hard_reg_set_intersect_p (
777 995428 : ~lra_reg_info[REGNO (original)].exclude_start_hard_regs,
778 500 : ~*exclude_start_hard_regs)))
779 : {
780 250 : unsigned int regno = REGNO (original);
781 250 : if (lra_dump_file != NULL)
782 : {
783 0 : fprintf (lra_dump_file, " Reuse r%d for output ", regno);
784 0 : dump_value_slim (lra_dump_file, original, 1);
785 : }
786 500 : if (new_class != lra_get_allocno_class (regno))
787 250 : lra_change_class (regno, new_class, ", change to", false);
788 250 : if (lra_dump_file != NULL)
789 0 : fprintf (lra_dump_file, "\n");
790 250 : if (exclude_start_hard_regs)
791 250 : lra_reg_info[regno].exclude_start_hard_regs
792 250 : |= *exclude_start_hard_regs;
793 250 : *result_reg = original;
794 250 : return false;
795 : }
796 994928 : *result_reg
797 994928 : = lra_create_new_reg_with_unique_value (mode, original, rclass,
798 : exclude_start_hard_regs, title);
799 994928 : return true;
800 : }
801 :
802 2935274 : bool unique_p = early_clobber_p;
803 : /* Prevent reuse value of expression with side effects,
804 : e.g. volatile memory. */
805 2935274 : if (! side_effects_p (original))
806 3166145 : for (i = 0; i < curr_insn_input_reloads_num; i++)
807 : {
808 240768 : if (! curr_insn_input_reloads[i].match_p
809 98301 : && ! curr_insn_input_reloads[i].early_clobber_p
810 98298 : && rtx_equal_p (curr_insn_input_reloads[i].input, original)
811 250416 : && in_class_p (curr_insn_input_reloads[i].reg, rclass, &new_class))
812 : {
813 9635 : rtx reg = curr_insn_input_reloads[i].reg;
814 9635 : regno = REGNO (reg);
815 : /* If input is equal to original and both are VOIDmode,
816 : GET_MODE (reg) might be still different from mode.
817 : Ensure we don't return *result_reg with wrong mode. */
818 9635 : if (GET_MODE (reg) != mode)
819 : {
820 0 : if (in_subreg_p)
821 0 : continue;
822 0 : if (maybe_lt (GET_MODE_SIZE (GET_MODE (reg)),
823 0 : GET_MODE_SIZE (mode)))
824 0 : continue;
825 0 : reg = get_matching_reload_reg_subreg (mode, reg, new_class);
826 0 : if (reg == NULL_RTX || GET_CODE (reg) != SUBREG)
827 0 : continue;
828 : }
829 : /* If the existing reload and this have no start hard register in
830 : common, then skip. Otherwise update exclude_start_hard_regs. */
831 9635 : if (exclude_start_hard_regs
832 11124 : && ! hard_reg_set_empty_p (*exclude_start_hard_regs))
833 : {
834 1 : HARD_REG_SET r = lra_reg_info[regno].exclude_start_hard_regs
835 1 : | *exclude_start_hard_regs;
836 2 : if (hard_reg_set_empty_p (~r))
837 0 : continue;
838 : else
839 1 : lra_reg_info[regno].exclude_start_hard_regs = r;
840 : }
841 9635 : *result_reg = reg;
842 9635 : if (lra_dump_file != NULL)
843 : {
844 0 : fprintf (lra_dump_file, " Reuse r%d for reload ", regno);
845 0 : dump_value_slim (lra_dump_file, original, 1);
846 : }
847 19270 : if (new_class != lra_get_allocno_class (regno))
848 4782 : lra_change_class (regno, new_class, ", change to", false);
849 9635 : if (lra_dump_file != NULL)
850 0 : fprintf (lra_dump_file, "\n");
851 : return false;
852 : }
853 : /* If we have an input reload with a different mode, make sure it
854 : will get a different hard reg. */
855 231133 : else if (REG_P (original)
856 180137 : && REG_P (curr_insn_input_reloads[i].input)
857 149479 : && REGNO (original) == REGNO (curr_insn_input_reloads[i].input)
858 231133 : && (GET_MODE (original)
859 2144 : != GET_MODE (curr_insn_input_reloads[i].input)))
860 : unique_p = true;
861 : }
862 5851278 : *result_reg = (unique_p
863 2925639 : ? lra_create_new_reg_with_unique_value
864 2925639 : : lra_create_new_reg) (mode, original, rclass,
865 : exclude_start_hard_regs, title);
866 2925639 : lra_assert (curr_insn_input_reloads_num < LRA_MAX_INSN_RELOADS);
867 2925639 : curr_insn_input_reloads[curr_insn_input_reloads_num].input = original;
868 2925639 : curr_insn_input_reloads[curr_insn_input_reloads_num].match_p = false;
869 2925639 : curr_insn_input_reloads[curr_insn_input_reloads_num].early_clobber_p
870 2925639 : = early_clobber_p;
871 2925639 : curr_insn_input_reloads[curr_insn_input_reloads_num++].reg = *result_reg;
872 2925639 : return true;
873 : }
874 :
875 :
876 : /* The page contains major code to choose the current insn alternative
877 : and generate reloads for it. */
878 :
879 : /* Return the offset from REGNO of the least significant register
880 : in (reg:MODE REGNO).
881 :
882 : This function is used to tell whether two registers satisfy
883 : a matching constraint. (reg:MODE1 REGNO1) matches (reg:MODE2 REGNO2) if:
884 :
885 : REGNO1 + lra_constraint_offset (REGNO1, MODE1)
886 : == REGNO2 + lra_constraint_offset (REGNO2, MODE2) */
887 : int
888 45577080 : lra_constraint_offset (int regno, machine_mode mode)
889 : {
890 45577080 : lra_assert (regno < FIRST_PSEUDO_REGISTER);
891 :
892 45577080 : scalar_int_mode int_mode;
893 45577080 : if (WORDS_BIG_ENDIAN
894 : && is_a <scalar_int_mode> (mode, &int_mode)
895 : && GET_MODE_SIZE (int_mode) > UNITS_PER_WORD)
896 : return hard_regno_nregs (regno, mode) - 1;
897 45577080 : return 0;
898 : }
899 :
900 : /* Like rtx_equal_p except that it allows a REG and a SUBREG to match
901 : if they are the same hard reg, and has special hacks for
902 : auto-increment and auto-decrement. This is specifically intended for
903 : process_alt_operands to use in determining whether two operands
904 : match. X is the operand whose number is the lower of the two.
905 :
906 : It is supposed that X is the output operand and Y is the input
907 : operand. Y_HARD_REGNO is the final hard regno of register Y or
908 : register in subreg Y as we know it now. Otherwise, it is a
909 : negative value. */
910 : static bool
911 59622573 : operands_match_p (rtx x, rtx y, int y_hard_regno)
912 : {
913 59622573 : int i;
914 59622573 : RTX_CODE code = GET_CODE (x);
915 59622573 : const char *fmt;
916 :
917 59622573 : if (x == y)
918 : return true;
919 51784899 : if ((code == REG || (code == SUBREG && REG_P (SUBREG_REG (x))))
920 24908366 : && (REG_P (y) || (GET_CODE (y) == SUBREG && REG_P (SUBREG_REG (y)))))
921 : {
922 24812089 : int j;
923 :
924 24812089 : i = get_hard_regno (x);
925 24812089 : if (i < 0)
926 1322386 : goto slow;
927 :
928 23489703 : if ((j = y_hard_regno) < 0)
929 701163 : goto slow;
930 :
931 22788540 : i += lra_constraint_offset (i, GET_MODE (x));
932 22788540 : j += lra_constraint_offset (j, GET_MODE (y));
933 :
934 22788540 : return i == j;
935 : }
936 :
937 : /* If two operands must match, because they are really a single
938 : operand of an assembler insn, then two post-increments are invalid
939 : because the assembler insn would increment only once. On the
940 : other hand, a post-increment matches ordinary indexing if the
941 : post-increment is the output operand. */
942 26972810 : if (code == POST_DEC || code == POST_INC || code == POST_MODIFY)
943 0 : return operands_match_p (XEXP (x, 0), y, y_hard_regno);
944 :
945 : /* Two pre-increments are invalid because the assembler insn would
946 : increment only once. On the other hand, a pre-increment matches
947 : ordinary indexing if the pre-increment is the input operand. */
948 26972810 : if (GET_CODE (y) == PRE_DEC || GET_CODE (y) == PRE_INC
949 26972810 : || GET_CODE (y) == PRE_MODIFY)
950 0 : return operands_match_p (x, XEXP (y, 0), -1);
951 :
952 26972810 : slow:
953 :
954 28996359 : if (code == REG && REG_P (y))
955 1922489 : return REGNO (x) == REGNO (y);
956 :
957 98786 : if (code == REG && GET_CODE (y) == SUBREG && REG_P (SUBREG_REG (y))
958 9259 : && x == SUBREG_REG (y))
959 : return true;
960 27073870 : if (GET_CODE (y) == REG && code == SUBREG && REG_P (SUBREG_REG (x))
961 69311 : && SUBREG_REG (x) == y)
962 : return true;
963 :
964 : /* Now we have disposed of all the cases in which different rtx
965 : codes can match. */
966 27073749 : if (code != GET_CODE (y))
967 : return false;
968 :
969 : /* (MULT:SI x y) and (MULT:HI x y) are NOT equivalent. */
970 1081970 : if (GET_MODE (x) != GET_MODE (y))
971 : return false;
972 :
973 1081256 : switch (code)
974 : {
975 : CASE_CONST_UNIQUE:
976 : return false;
977 :
978 : case CONST_VECTOR:
979 : if (!same_vector_encodings_p (x, y))
980 : return false;
981 : break;
982 :
983 0 : case LABEL_REF:
984 0 : return label_ref_label (x) == label_ref_label (y);
985 25 : case SYMBOL_REF:
986 25 : return XSTR (x, 0) == XSTR (y, 0);
987 :
988 : default:
989 : break;
990 : }
991 :
992 : /* Compare the elements. If any pair of corresponding elements fail
993 : to match, return false for the whole things. */
994 :
995 1050758 : fmt = GET_RTX_FORMAT (code);
996 3025135 : for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
997 : {
998 2060487 : int val, j;
999 2060487 : switch (fmt[i])
1000 : {
1001 0 : case 'w':
1002 0 : if (XWINT (x, i) != XWINT (y, i))
1003 : return false;
1004 : break;
1005 :
1006 524 : case 'i':
1007 524 : if (XINT (x, i) != XINT (y, i))
1008 : return false;
1009 : break;
1010 :
1011 0 : case 'L':
1012 0 : if (XLOC (x, i) != XLOC (y, i))
1013 : return false;
1014 : break;
1015 :
1016 22413 : case 'p':
1017 22413 : if (maybe_ne (SUBREG_BYTE (x), SUBREG_BYTE (y)))
1018 : return false;
1019 : break;
1020 :
1021 1496264 : case 'e':
1022 1496264 : val = operands_match_p (XEXP (x, i), XEXP (y, i), -1);
1023 1496264 : if (val == 0)
1024 : return false;
1025 : break;
1026 :
1027 : case '0':
1028 : break;
1029 :
1030 524 : case 'E':
1031 524 : if (XVECLEN (x, i) != XVECLEN (y, i))
1032 : return false;
1033 1048 : for (j = XVECLEN (x, i) - 1; j >= 0; --j)
1034 : {
1035 524 : val = operands_match_p (XVECEXP (x, i, j), XVECEXP (y, i, j), -1);
1036 524 : if (val == 0)
1037 : return false;
1038 : }
1039 : break;
1040 :
1041 : /* It is believed that rtx's at this level will never
1042 : contain anything but integers and other rtx's, except for
1043 : within LABEL_REFs and SYMBOL_REFs. */
1044 0 : default:
1045 0 : gcc_unreachable ();
1046 : }
1047 : }
1048 : return true;
1049 : }
1050 :
1051 : /* If REG is a reload pseudo, try to make its class satisfying CL. */
1052 : static void
1053 3618316 : narrow_reload_pseudo_class (rtx reg, enum reg_class cl)
1054 : {
1055 3618316 : enum reg_class rclass;
1056 :
1057 : /* Do not make more accurate class from reloads generated. They are
1058 : mostly moves with a lot of constraints. Making more accurate
1059 : class may results in very narrow class and impossibility of find
1060 : registers for several reloads of one insn. */
1061 3618316 : if (INSN_UID (curr_insn) >= new_insn_uid_start)
1062 3605701 : return;
1063 3618146 : if (GET_CODE (reg) == SUBREG)
1064 174813 : reg = SUBREG_REG (reg);
1065 3618146 : if (! REG_P (reg) || (int) REGNO (reg) < new_regno_start)
1066 : return;
1067 12615 : if (in_class_p (reg, cl, &rclass) && rclass != cl)
1068 13 : lra_change_class (REGNO (reg), rclass, " Change to", true);
1069 : }
1070 :
1071 : /* Searches X for any reference to a reg with the same value as REGNO,
1072 : returning the rtx of the reference found if any. Otherwise,
1073 : returns NULL_RTX. */
1074 : static rtx
1075 585627 : regno_val_use_in (unsigned int regno, rtx x)
1076 : {
1077 585627 : const char *fmt;
1078 585627 : int i, j;
1079 585627 : rtx tem;
1080 :
1081 585627 : if (REG_P (x) && lra_reg_info[REGNO (x)].val == lra_reg_info[regno].val)
1082 : return x;
1083 :
1084 585317 : fmt = GET_RTX_FORMAT (GET_CODE (x));
1085 1176903 : for (i = GET_RTX_LENGTH (GET_CODE (x)) - 1; i >= 0; i--)
1086 : {
1087 591586 : if (fmt[i] == 'e')
1088 : {
1089 7559 : if ((tem = regno_val_use_in (regno, XEXP (x, i))))
1090 : return tem;
1091 : }
1092 584027 : else if (fmt[i] == 'E')
1093 0 : for (j = XVECLEN (x, i) - 1; j >= 0; j--)
1094 0 : if ((tem = regno_val_use_in (regno , XVECEXP (x, i, j))))
1095 : return tem;
1096 : }
1097 :
1098 : return NULL_RTX;
1099 : }
1100 :
1101 : /* Return true if all current insn non-output operands except INS (it
1102 : has a negaitve end marker) do not use pseudos with the same value
1103 : as REGNO. */
1104 : static bool
1105 2 : check_conflict_input_operands (int regno, signed char *ins)
1106 : {
1107 2 : int in;
1108 2 : int n_operands = curr_static_id->n_operands;
1109 :
1110 8 : for (int nop = 0; nop < n_operands; nop++)
1111 7 : if (! curr_static_id->operand[nop].is_operator
1112 7 : && curr_static_id->operand[nop].type != OP_OUT)
1113 : {
1114 5 : for (int i = 0; (in = ins[i]) >= 0; i++)
1115 4 : if (in == nop)
1116 : break;
1117 3 : if (in < 0
1118 3 : && regno_val_use_in (regno, *curr_id->operand_loc[nop]) != NULL_RTX)
1119 : return false;
1120 : }
1121 : return true;
1122 : }
1123 :
1124 : /* Generate reloads for matching OUT and INS (array of input operand numbers
1125 : with end marker -1) with reg class GOAL_CLASS and EXCLUDE_START_HARD_REGS,
1126 : considering output operands OUTS (similar array to INS) needing to be in
1127 : different registers. Add input and output reloads correspondingly to the
1128 : lists *BEFORE and *AFTER. OUT might be negative. In this case we generate
1129 : input reloads for matched input operands INS. EARLY_CLOBBER_P is a flag
1130 : that the output operand is early clobbered for chosen alternative. */
1131 : static void
1132 1809158 : match_reload (signed char out, signed char *ins, signed char *outs,
1133 : enum reg_class goal_class, HARD_REG_SET *exclude_start_hard_regs,
1134 : rtx_insn **before, rtx_insn **after, bool early_clobber_p)
1135 : {
1136 1809158 : bool out_conflict;
1137 1809158 : int i, in;
1138 1809158 : rtx new_in_reg, new_out_reg, reg;
1139 1809158 : machine_mode inmode, outmode;
1140 1809158 : rtx in_rtx = *curr_id->operand_loc[ins[0]];
1141 1809158 : rtx out_rtx = out < 0 ? in_rtx : *curr_id->operand_loc[out];
1142 :
1143 1809158 : inmode = curr_operand_mode[ins[0]];
1144 1809158 : outmode = out < 0 ? inmode : curr_operand_mode[out];
1145 1809158 : push_to_sequence (*before);
1146 1809158 : if (inmode != outmode)
1147 : {
1148 : /* process_alt_operands has already checked that the mode sizes
1149 : are ordered. */
1150 114068 : if (partial_subreg_p (outmode, inmode))
1151 : {
1152 2425 : bool asm_p = asm_noperands (PATTERN (curr_insn)) >= 0;
1153 2425 : int hr;
1154 2425 : HARD_REG_SET temp_hard_reg_set;
1155 :
1156 19 : if (asm_p && (hr = get_hard_regno (out_rtx)) >= 0
1157 2428 : && hard_regno_nregs (hr, inmode) > 1)
1158 : {
1159 : /* See gcc.c-torture/execute/20030222-1.c.
1160 : Consider the code for 32-bit (e.g. BE) target:
1161 : int i, v; long x; x = v; asm ("" : "=r" (i) : "0" (x));
1162 : We generate the following RTL with reload insns:
1163 : 1. subreg:si(x:di, 0) = 0;
1164 : 2. subreg:si(x:di, 4) = v:si;
1165 : 3. t:di = x:di, dead x;
1166 : 4. asm ("" : "=r" (subreg:si(t:di,4)) : "0" (t:di))
1167 : 5. i:si = subreg:si(t:di,4);
1168 : If we assign hard reg of x to t, dead code elimination
1169 : will remove insn #2 and we will use uninitialized hard reg.
1170 : So exclude the hard reg of x for t. We could ignore this
1171 : problem for non-empty asm using all x value but it is hard to
1172 : check that the asm are expanded into insn really using x
1173 : and setting r. */
1174 0 : CLEAR_HARD_REG_SET (temp_hard_reg_set);
1175 0 : if (exclude_start_hard_regs != NULL)
1176 0 : temp_hard_reg_set = *exclude_start_hard_regs;
1177 0 : SET_HARD_REG_BIT (temp_hard_reg_set, hr);
1178 0 : exclude_start_hard_regs = &temp_hard_reg_set;
1179 : }
1180 4850 : reg = new_in_reg
1181 2425 : = lra_create_new_reg_with_unique_value (inmode, in_rtx, goal_class,
1182 : exclude_start_hard_regs,
1183 : "");
1184 2425 : new_out_reg = get_matching_reload_reg_subreg (outmode, reg, goal_class);
1185 2425 : LRA_SUBREG_P (new_out_reg) = 1;
1186 : /* If the input reg is dying here, we can use the same hard
1187 : register for REG and IN_RTX. We do it only for original
1188 : pseudos as reload pseudos can die although original
1189 : pseudos still live where reload pseudos dies. */
1190 1914 : if (REG_P (in_rtx) && (int) REGNO (in_rtx) < lra_new_regno_start
1191 1864 : && find_regno_note (curr_insn, REG_DEAD, REGNO (in_rtx))
1192 3327 : && (!early_clobber_p
1193 2 : || check_conflict_input_operands(REGNO (in_rtx), ins)))
1194 901 : lra_assign_reg_val (REGNO (in_rtx), REGNO (reg));
1195 : }
1196 : else
1197 : {
1198 223286 : reg = new_out_reg
1199 111643 : = lra_create_new_reg_with_unique_value (outmode, out_rtx,
1200 : goal_class,
1201 : exclude_start_hard_regs,
1202 : "");
1203 111643 : new_in_reg = get_matching_reload_reg_subreg (inmode, reg, goal_class);
1204 : /* NEW_IN_REG is non-paradoxical subreg. We don't want
1205 : NEW_OUT_REG living above. We add clobber clause for
1206 : this. This is just a temporary clobber. We can remove
1207 : it at the end of LRA work. */
1208 111643 : rtx_insn *clobber = emit_clobber (new_out_reg);
1209 111643 : LRA_TEMP_CLOBBER_P (PATTERN (clobber)) = 1;
1210 111643 : LRA_SUBREG_P (new_in_reg) = 1;
1211 111643 : if (GET_CODE (in_rtx) == SUBREG)
1212 : {
1213 2130 : rtx subreg_reg = SUBREG_REG (in_rtx);
1214 :
1215 : /* If SUBREG_REG is dying here and sub-registers IN_RTX
1216 : and NEW_IN_REG are similar, we can use the same hard
1217 : register for REG and SUBREG_REG. */
1218 2130 : if (REG_P (subreg_reg)
1219 2130 : && (int) REGNO (subreg_reg) < lra_new_regno_start
1220 2130 : && GET_MODE (subreg_reg) == outmode
1221 1781 : && known_eq (SUBREG_BYTE (in_rtx), SUBREG_BYTE (new_in_reg))
1222 1781 : && find_regno_note (curr_insn, REG_DEAD, REGNO (subreg_reg))
1223 2435 : && (! early_clobber_p
1224 0 : || check_conflict_input_operands (REGNO (subreg_reg),
1225 : ins)))
1226 305 : lra_assign_reg_val (REGNO (subreg_reg), REGNO (reg));
1227 : }
1228 : }
1229 : }
1230 : else
1231 : {
1232 : /* Pseudos have values -- see comments for lra_reg_info.
1233 : Different pseudos with the same value do not conflict even if
1234 : they live in the same place. When we create a pseudo we
1235 : assign value of original pseudo (if any) from which we
1236 : created the new pseudo. If we create the pseudo from the
1237 : input pseudo, the new pseudo will have no conflict with the
1238 : input pseudo which is wrong when the input pseudo lives after
1239 : the insn and as the new pseudo value is changed by the insn
1240 : output. Therefore we create the new pseudo from the output
1241 : except the case when we have single matched dying input
1242 : pseudo.
1243 :
1244 : We cannot reuse the current output register because we might
1245 : have a situation like "a <- a op b", where the constraints
1246 : force the second input operand ("b") to match the output
1247 : operand ("a"). "b" must then be copied into a new register
1248 : so that it doesn't clobber the current value of "a".
1249 :
1250 : We cannot use the same value if the output pseudo is
1251 : early clobbered or the input pseudo is mentioned in the
1252 : output, e.g. as an address part in memory, because
1253 : output reload will actually extend the pseudo liveness.
1254 : We don't care about eliminable hard regs here as we are
1255 : interesting only in pseudos. */
1256 :
1257 : /* Matching input's register value is the same as one of the other
1258 : output operand. Output operands in a parallel insn must be in
1259 : different registers. */
1260 1695090 : out_conflict = false;
1261 1695090 : if (REG_P (in_rtx))
1262 : {
1263 2921850 : for (i = 0; outs[i] >= 0; i++)
1264 : {
1265 1524091 : rtx other_out_rtx = *curr_id->operand_loc[outs[i]];
1266 126154 : if (outs[i] != out && REG_P (other_out_rtx)
1267 1650043 : && (regno_val_use_in (REGNO (in_rtx), other_out_rtx)
1268 : != NULL_RTX))
1269 : {
1270 : out_conflict = true;
1271 : break;
1272 : }
1273 : }
1274 : }
1275 :
1276 1695090 : new_in_reg = new_out_reg
1277 1659953 : = (! early_clobber_p && ins[1] < 0 && REG_P (in_rtx)
1278 1363652 : && (int) REGNO (in_rtx) < lra_new_regno_start
1279 1363323 : && find_regno_note (curr_insn, REG_DEAD, REGNO (in_rtx))
1280 452115 : && (out < 0
1281 452115 : || regno_val_use_in (REGNO (in_rtx), out_rtx) == NULL_RTX)
1282 452050 : && !out_conflict
1283 2147138 : ? lra_create_new_reg (inmode, in_rtx, goal_class,
1284 : exclude_start_hard_regs, "")
1285 1243042 : : lra_create_new_reg_with_unique_value (outmode, out_rtx, goal_class,
1286 : exclude_start_hard_regs,
1287 : ""));
1288 : }
1289 : /* In operand can be got from transformations before processing insn
1290 : constraints. One example of such transformations is subreg
1291 : reloading (see function simplify_operand_subreg). The new
1292 : pseudos created by the transformations might have inaccurate
1293 : class (ALL_REGS) and we should make their classes more
1294 : accurate. */
1295 1809158 : narrow_reload_pseudo_class (in_rtx, goal_class);
1296 1809158 : lra_emit_move (copy_rtx (new_in_reg), in_rtx);
1297 1809158 : *before = end_sequence ();
1298 : /* Add the new pseudo to consider values of subsequent input reload
1299 : pseudos. */
1300 1809158 : lra_assert (curr_insn_input_reloads_num < LRA_MAX_INSN_RELOADS);
1301 1809158 : curr_insn_input_reloads[curr_insn_input_reloads_num].input = in_rtx;
1302 1809158 : curr_insn_input_reloads[curr_insn_input_reloads_num].match_p = true;
1303 1809158 : curr_insn_input_reloads[curr_insn_input_reloads_num].early_clobber_p = false;
1304 1809158 : curr_insn_input_reloads[curr_insn_input_reloads_num++].reg = new_in_reg;
1305 3618317 : for (i = 0; (in = ins[i]) >= 0; i++)
1306 1809159 : if (GET_MODE (*curr_id->operand_loc[in]) == VOIDmode
1307 1785242 : || GET_MODE (new_in_reg) == GET_MODE (*curr_id->operand_loc[in]))
1308 1809158 : *curr_id->operand_loc[in] = new_in_reg;
1309 : else
1310 : {
1311 1 : lra_assert
1312 : (GET_MODE (new_out_reg) == GET_MODE (*curr_id->operand_loc[in]));
1313 1 : *curr_id->operand_loc[in] = new_out_reg;
1314 : }
1315 1809158 : lra_update_dups (curr_id, ins);
1316 1809158 : if (out < 0)
1317 : return;
1318 : /* See a comment for the input operand above. */
1319 1809158 : narrow_reload_pseudo_class (out_rtx, goal_class);
1320 1809158 : reg = SUBREG_P (out_rtx) ? SUBREG_REG (out_rtx) : out_rtx;
1321 1809158 : if (find_reg_note (curr_insn, REG_UNUSED, reg) == NULL_RTX
1322 1809158 : && (!REG_P (reg) || !ira_former_scratch_p (REGNO (reg))))
1323 : {
1324 1708281 : start_sequence ();
1325 : /* If we had strict_low_part, use it also in reload to keep other
1326 : parts unchanged but do it only for regs as strict_low_part
1327 : has no sense for memory and probably there is no insn pattern
1328 : to match the reload insn in memory case. */
1329 1708281 : if (out >= 0 && curr_static_id->operand[out].strict_low && REG_P (reg))
1330 0 : out_rtx = gen_rtx_STRICT_LOW_PART (VOIDmode, out_rtx);
1331 1708281 : lra_emit_move (out_rtx, copy_rtx (new_out_reg));
1332 1708281 : emit_insn (*after);
1333 1708281 : *after = end_sequence ();
1334 : }
1335 1809158 : *curr_id->operand_loc[out] = new_out_reg;
1336 1809158 : lra_update_dup (curr_id, out);
1337 : }
1338 :
1339 : /* Return register class which is union of all reg classes in insn
1340 : constraint alternative string starting with P. */
1341 : static enum reg_class
1342 0 : reg_class_from_constraints (const char *p)
1343 : {
1344 0 : int c, len;
1345 0 : enum reg_class op_class = NO_REGS;
1346 :
1347 0 : do
1348 0 : switch ((c = *p, len = CONSTRAINT_LEN (c, p)), c)
1349 : {
1350 : case '#':
1351 : case ',':
1352 : return op_class;
1353 :
1354 0 : case 'g':
1355 0 : op_class = reg_class_subunion[op_class][GENERAL_REGS];
1356 0 : break;
1357 :
1358 0 : default:
1359 0 : enum constraint_num cn = lookup_constraint (p);
1360 0 : enum reg_class cl = reg_class_for_constraint (cn);
1361 0 : if (cl == NO_REGS)
1362 : {
1363 0 : if (insn_extra_address_constraint (cn))
1364 0 : op_class
1365 0 : = (reg_class_subunion
1366 0 : [op_class][base_reg_class (VOIDmode, ADDR_SPACE_GENERIC,
1367 0 : ADDRESS, SCRATCH)]);
1368 : break;
1369 : }
1370 :
1371 0 : op_class = reg_class_subunion[op_class][cl];
1372 0 : break;
1373 : }
1374 0 : while ((p += len), c);
1375 : return op_class;
1376 : }
1377 :
1378 : /* If OP is a register, return the class of the register as per
1379 : get_reg_class, otherwise return NO_REGS. */
1380 : static inline enum reg_class
1381 168655411 : get_op_class (rtx op)
1382 : {
1383 140210706 : return REG_P (op) ? get_reg_class (REGNO (op)) : NO_REGS;
1384 : }
1385 :
1386 : /* Return generated insn mem_pseudo:=val if TO_P or val:=mem_pseudo
1387 : otherwise. If modes of MEM_PSEUDO and VAL are different, use
1388 : SUBREG for VAL to make them equal. */
1389 : static rtx_insn *
1390 1359009 : emit_spill_move (bool to_p, rtx mem_pseudo, rtx val)
1391 : {
1392 1359009 : if (GET_MODE (mem_pseudo) != GET_MODE (val))
1393 : {
1394 : /* Usually size of mem_pseudo is greater than val size but in
1395 : rare cases it can be less as it can be defined by target
1396 : dependent macro HARD_REGNO_CALLER_SAVE_MODE. */
1397 3402 : if (! MEM_P (val))
1398 : {
1399 3402 : val = gen_lowpart_SUBREG (GET_MODE (mem_pseudo),
1400 : GET_CODE (val) == SUBREG
1401 : ? SUBREG_REG (val) : val);
1402 3402 : LRA_SUBREG_P (val) = 1;
1403 : }
1404 : else
1405 : {
1406 0 : mem_pseudo = gen_lowpart_SUBREG (GET_MODE (val), mem_pseudo);
1407 0 : LRA_SUBREG_P (mem_pseudo) = 1;
1408 : }
1409 : }
1410 1359009 : return to_p ? gen_move_insn (mem_pseudo, val)
1411 683703 : : gen_move_insn (val, mem_pseudo);
1412 : }
1413 :
1414 : /* Process a special case insn (register move), return true if we
1415 : don't need to process it anymore. INSN should be a single set
1416 : insn. Set up that RTL was changed through CHANGE_P and that hook
1417 : TARGET_SECONDARY_MEMORY_NEEDED says to use secondary memory through
1418 : SEC_MEM_P. */
1419 : static bool
1420 78060692 : check_and_process_move (bool *change_p, bool *sec_mem_p ATTRIBUTE_UNUSED)
1421 : {
1422 78060692 : int sregno, dregno;
1423 78060692 : rtx dest, src, dreg, sreg, new_reg, scratch_reg;
1424 78060692 : rtx_insn *before;
1425 78060692 : enum reg_class dclass, sclass, secondary_class;
1426 78060692 : secondary_reload_info sri;
1427 :
1428 78060692 : lra_assert (curr_insn_set != NULL_RTX);
1429 78060692 : dreg = dest = SET_DEST (curr_insn_set);
1430 78060692 : sreg = src = SET_SRC (curr_insn_set);
1431 78060692 : if (GET_CODE (dest) == SUBREG)
1432 1215424 : dreg = SUBREG_REG (dest);
1433 78060692 : if (GET_CODE (src) == SUBREG)
1434 1310653 : sreg = SUBREG_REG (src);
1435 78060692 : if (! (REG_P (dreg) || MEM_P (dreg)) || ! (REG_P (sreg) || MEM_P (sreg)))
1436 : return false;
1437 36327919 : sclass = dclass = NO_REGS;
1438 36327919 : if (REG_P (dreg))
1439 23397817 : dclass = get_reg_class (REGNO (dreg));
1440 23397817 : gcc_assert (dclass < LIM_REG_CLASSES && dclass >= NO_REGS);
1441 36327919 : if (dclass == ALL_REGS)
1442 : /* ALL_REGS is used for new pseudos created by transformations
1443 : like reload of SUBREG_REG (see function
1444 : simplify_operand_subreg). We don't know their class yet. We
1445 : should figure out the class from processing the insn
1446 : constraints not in this fast path function. Even if ALL_REGS
1447 : were a right class for the pseudo, secondary_... hooks usually
1448 : are not define for ALL_REGS. */
1449 : return false;
1450 36325644 : if (REG_P (sreg))
1451 20316471 : sclass = get_reg_class (REGNO (sreg));
1452 20316471 : gcc_assert (sclass < LIM_REG_CLASSES && sclass >= NO_REGS);
1453 36325644 : if (sclass == ALL_REGS)
1454 : /* See comments above. */
1455 : return false;
1456 36325644 : if (sclass == NO_REGS && dclass == NO_REGS)
1457 : return false;
1458 34830168 : if (targetm.secondary_memory_needed (GET_MODE (src), sclass, dclass)
1459 34830168 : && ((sclass != NO_REGS && dclass != NO_REGS)
1460 0 : || (GET_MODE (src)
1461 0 : != targetm.secondary_memory_needed_mode (GET_MODE (src)))))
1462 : {
1463 13009 : *sec_mem_p = true;
1464 13009 : return false;
1465 : }
1466 34817159 : if (! REG_P (dreg) || ! REG_P (sreg))
1467 : return false;
1468 7901210 : sri.prev_sri = NULL;
1469 7901210 : sri.icode = CODE_FOR_nothing;
1470 7901210 : sri.extra_cost = 0;
1471 7901210 : secondary_class = NO_REGS;
1472 : /* Set up hard register for a reload pseudo for hook
1473 : secondary_reload because some targets just ignore unassigned
1474 : pseudos in the hook. */
1475 7901210 : if (dclass != NO_REGS && lra_get_regno_hard_regno (REGNO (dreg)) < 0)
1476 : {
1477 2935226 : dregno = REGNO (dreg);
1478 2935226 : reg_renumber[dregno] = ira_class_hard_regs[dclass][0];
1479 : }
1480 : else
1481 : dregno = -1;
1482 7901210 : if (sclass != NO_REGS && lra_get_regno_hard_regno (REGNO (sreg)) < 0)
1483 : {
1484 1307070 : sregno = REGNO (sreg);
1485 1307070 : reg_renumber[sregno] = ira_class_hard_regs[sclass][0];
1486 : }
1487 : else
1488 : sregno = -1;
1489 7901210 : if (sclass != NO_REGS)
1490 4013857 : secondary_class
1491 8027714 : = (enum reg_class) targetm.secondary_reload (false, dest,
1492 : (reg_class_t) sclass,
1493 4013857 : GET_MODE (src), &sri);
1494 4013857 : if (sclass == NO_REGS
1495 4013857 : || ((secondary_class != NO_REGS || sri.icode != CODE_FOR_nothing)
1496 1291 : && dclass != NO_REGS))
1497 : {
1498 3887353 : enum reg_class old_sclass = secondary_class;
1499 3887353 : secondary_reload_info old_sri = sri;
1500 :
1501 3887353 : sri.prev_sri = NULL;
1502 3887353 : sri.icode = CODE_FOR_nothing;
1503 3887353 : sri.extra_cost = 0;
1504 3887353 : secondary_class
1505 7774706 : = (enum reg_class) targetm.secondary_reload (true, src,
1506 : (reg_class_t) dclass,
1507 3887353 : GET_MODE (src), &sri);
1508 : /* Check the target hook consistency. */
1509 3887353 : lra_assert
1510 : ((secondary_class == NO_REGS && sri.icode == CODE_FOR_nothing)
1511 : || (old_sclass == NO_REGS && old_sri.icode == CODE_FOR_nothing)
1512 : || (secondary_class == old_sclass && sri.icode == old_sri.icode));
1513 : }
1514 7901210 : if (sregno >= 0)
1515 1307070 : reg_renumber [sregno] = -1;
1516 7901210 : if (dregno >= 0)
1517 2935226 : reg_renumber [dregno] = -1;
1518 7901210 : if (secondary_class == NO_REGS && sri.icode == CODE_FOR_nothing)
1519 : return false;
1520 1294 : *change_p = true;
1521 1294 : new_reg = NULL_RTX;
1522 0 : if (secondary_class != NO_REGS)
1523 1294 : new_reg = lra_create_new_reg_with_unique_value (GET_MODE (src), NULL_RTX,
1524 : secondary_class, NULL,
1525 : "secondary");
1526 1294 : start_sequence ();
1527 1294 : if (sri.icode == CODE_FOR_nothing)
1528 1294 : lra_emit_move (new_reg, src);
1529 : else
1530 : {
1531 0 : enum reg_class scratch_class;
1532 :
1533 0 : scratch_class = (reg_class_from_constraints
1534 0 : (insn_data[sri.icode].operand[2].constraint));
1535 0 : scratch_reg = (lra_create_new_reg_with_unique_value
1536 0 : (insn_data[sri.icode].operand[2].mode, NULL_RTX,
1537 : scratch_class, NULL, "scratch"));
1538 0 : emit_insn (GEN_FCN (sri.icode) (new_reg != NULL_RTX ? new_reg : dest,
1539 : src, scratch_reg));
1540 : }
1541 1294 : before = end_sequence ();
1542 1294 : lra_process_new_insns (curr_insn, before, NULL, "Inserting the move");
1543 1294 : if (new_reg != NULL_RTX)
1544 1294 : SET_SRC (curr_insn_set) = new_reg;
1545 : else
1546 : {
1547 0 : if (lra_dump_file != NULL)
1548 : {
1549 0 : fprintf (lra_dump_file, "Deleting move %u\n", INSN_UID (curr_insn));
1550 0 : dump_insn_slim (lra_dump_file, curr_insn);
1551 : }
1552 0 : lra_set_insn_deleted (curr_insn);
1553 0 : return true;
1554 : }
1555 1294 : return false;
1556 : }
1557 :
1558 : /* The following data describe the result of process_alt_operands.
1559 : The data are used in curr_insn_transform to generate reloads. */
1560 :
1561 : /* The chosen reg classes which should be used for the corresponding
1562 : operands. */
1563 : static enum reg_class goal_alt[MAX_RECOG_OPERANDS];
1564 : /* Hard registers which cannot be a start hard register for the corresponding
1565 : operands. */
1566 : static HARD_REG_SET goal_alt_exclude_start_hard_regs[MAX_RECOG_OPERANDS];
1567 : /* True if the operand should be the same as another operand and that
1568 : other operand does not need a reload. */
1569 : static bool goal_alt_match_win[MAX_RECOG_OPERANDS];
1570 : /* True if the operand does not need a reload. */
1571 : static bool goal_alt_win[MAX_RECOG_OPERANDS];
1572 : /* True if the operand can be offsetable memory. */
1573 : static bool goal_alt_offmemok[MAX_RECOG_OPERANDS];
1574 : /* The number of an operand to which given operand can be matched to. */
1575 : static int goal_alt_matches[MAX_RECOG_OPERANDS];
1576 : /* The number of elements in the following array. */
1577 : static int goal_alt_dont_inherit_ops_num;
1578 : /* Numbers of operands whose reload pseudos should not be inherited. */
1579 : static int goal_alt_dont_inherit_ops[MAX_RECOG_OPERANDS];
1580 : /* True if we should try only this alternative for the next constraint sub-pass
1581 : to speed up the sub-pass. */
1582 : static bool goal_reuse_alt_p;
1583 : /* True if the insn commutative operands should be swapped. */
1584 : static bool goal_alt_swapped;
1585 : /* The chosen insn alternative. */
1586 : static int goal_alt_number;
1587 : /* True if output reload of the stack pointer should be generated. */
1588 : static bool goal_alt_out_sp_reload_p;
1589 :
1590 : /* True if the corresponding operand is the result of an equivalence
1591 : substitution. */
1592 : static bool equiv_substition_p[MAX_RECOG_OPERANDS];
1593 :
1594 : /* The following five variables are used to choose the best insn
1595 : alternative. They reflect final characteristics of the best
1596 : alternative. */
1597 :
1598 : /* Number of necessary reloads and overall cost reflecting the
1599 : previous value and other unpleasantness of the best alternative. */
1600 : static int best_losers, best_overall;
1601 : /* Overall number hard registers used for reloads. For example, on
1602 : some targets we need 2 general registers to reload DFmode and only
1603 : one floating point register. */
1604 : static int best_reload_nregs;
1605 : /* Overall number reflecting distances of previous reloading the same
1606 : value. The distances are counted from the current BB start. It is
1607 : used to improve inheritance chances. */
1608 : static int best_reload_sum;
1609 :
1610 : /* True if the current insn should have no correspondingly input or
1611 : output reloads. */
1612 : static bool no_input_reloads_p, no_output_reloads_p;
1613 :
1614 : /* True if we swapped the commutative operands in the current
1615 : insn. */
1616 : static int curr_swapped;
1617 :
1618 : /* if CHECK_ONLY_P is false, arrange for address element *LOC to be a
1619 : register of class CL. Add any input reloads to list BEFORE. AFTER
1620 : is nonnull if *LOC is an automodified value; handle that case by
1621 : adding the required output reloads to list AFTER. Return true if
1622 : the RTL was changed.
1623 :
1624 : if CHECK_ONLY_P is true, check that the *LOC is a correct address
1625 : register. Return false if the address register is correct. */
1626 : static bool
1627 36008092 : process_addr_reg (rtx *loc, bool check_only_p, rtx_insn **before, rtx_insn **after,
1628 : enum reg_class cl)
1629 : {
1630 36008092 : int regno;
1631 36008092 : enum reg_class rclass, new_class;
1632 36008092 : rtx reg;
1633 36008092 : rtx new_reg;
1634 36008092 : machine_mode mode;
1635 36008092 : bool subreg_p, before_p = false;
1636 :
1637 36008092 : subreg_p = GET_CODE (*loc) == SUBREG;
1638 36008092 : if (subreg_p)
1639 : {
1640 16822 : reg = SUBREG_REG (*loc);
1641 16822 : mode = GET_MODE (reg);
1642 :
1643 : /* For mode with size bigger than ptr_mode, there unlikely to be "mov"
1644 : between two registers with different classes, but there normally will
1645 : be "mov" which transfers element of vector register into the general
1646 : register, and this normally will be a subreg which should be reloaded
1647 : as a whole. This is particularly likely to be triggered when
1648 : -fno-split-wide-types specified. */
1649 16822 : if (!REG_P (reg)
1650 16822 : || in_class_p (reg, cl, &new_class)
1651 19254 : || known_le (GET_MODE_SIZE (mode), GET_MODE_SIZE (ptr_mode)))
1652 16822 : loc = &SUBREG_REG (*loc);
1653 : }
1654 :
1655 36008092 : reg = *loc;
1656 36008092 : mode = GET_MODE (reg);
1657 36008092 : if (! REG_P (reg))
1658 : {
1659 0 : if (check_only_p)
1660 : return true;
1661 : /* Always reload memory in an address even if the target supports
1662 : such addresses. */
1663 0 : new_reg = lra_create_new_reg_with_unique_value (mode, reg, cl, NULL,
1664 : "address");
1665 0 : before_p = true;
1666 : }
1667 : else
1668 : {
1669 36008092 : regno = REGNO (reg);
1670 36008092 : rclass = get_reg_class (regno);
1671 36008092 : if (! check_only_p
1672 36008092 : && (*loc = get_equiv_with_elimination (reg, curr_insn)) != reg)
1673 : {
1674 111698 : if (lra_dump_file != NULL)
1675 : {
1676 0 : fprintf (lra_dump_file,
1677 : "Changing pseudo %d in address of insn %u on equiv ",
1678 0 : REGNO (reg), INSN_UID (curr_insn));
1679 0 : dump_value_slim (lra_dump_file, *loc, 1);
1680 0 : fprintf (lra_dump_file, "\n");
1681 : }
1682 111698 : rtx new_equiv = copy_rtx (*loc);
1683 111698 : if (lra_pointer_equiv_set_in (*loc))
1684 106380 : lra_pointer_equiv_set_add (new_equiv);
1685 111698 : *loc = new_equiv;
1686 : }
1687 36008092 : if (*loc != reg || ! in_class_p (reg, cl, &new_class))
1688 : {
1689 479897 : if (check_only_p)
1690 : return true;
1691 479897 : reg = *loc;
1692 479897 : if (get_reload_reg (after == NULL ? OP_IN : OP_INOUT,
1693 : mode, reg, cl, NULL,
1694 : subreg_p, false, "address", &new_reg))
1695 : before_p = true;
1696 : }
1697 35528195 : else if (new_class != NO_REGS && rclass != new_class)
1698 : {
1699 467688 : if (check_only_p)
1700 : return true;
1701 467688 : lra_change_class (regno, new_class, " Change to", true);
1702 467688 : return false;
1703 : }
1704 : else
1705 : return false;
1706 : }
1707 0 : if (before_p)
1708 : {
1709 471751 : push_to_sequence (*before);
1710 471751 : lra_emit_move (new_reg, reg);
1711 471751 : *before = end_sequence ();
1712 : }
1713 479897 : *loc = new_reg;
1714 479897 : if (after != NULL)
1715 : {
1716 0 : start_sequence ();
1717 0 : lra_emit_move (before_p ? copy_rtx (reg) : reg, new_reg);
1718 0 : emit_insn (*after);
1719 0 : *after = end_sequence ();
1720 : }
1721 : return true;
1722 : }
1723 :
1724 : /* Insert move insn in simplify_operand_subreg. BEFORE returns
1725 : the insn to be inserted before curr insn. AFTER returns the
1726 : the insn to be inserted after curr insn. ORIGREG and NEWREG
1727 : are the original reg and new reg for reload. */
1728 : static void
1729 461 : insert_move_for_subreg (rtx_insn **before, rtx_insn **after, rtx origreg,
1730 : rtx newreg)
1731 : {
1732 461 : if (before)
1733 : {
1734 461 : push_to_sequence (*before);
1735 461 : lra_emit_move (newreg, origreg);
1736 461 : *before = end_sequence ();
1737 : }
1738 461 : if (after)
1739 : {
1740 2 : start_sequence ();
1741 2 : lra_emit_move (origreg, newreg);
1742 2 : emit_insn (*after);
1743 2 : *after = end_sequence ();
1744 : }
1745 461 : }
1746 :
1747 : static bool valid_address_p (machine_mode mode, rtx addr, addr_space_t as);
1748 : static bool process_address (int, bool, rtx_insn **, rtx_insn **);
1749 :
1750 : /* Make reloads for subreg in operand NOP with internal subreg mode
1751 : REG_MODE, add new reloads for further processing. Return true if
1752 : any change was done. */
1753 : static bool
1754 181524038 : simplify_operand_subreg (int nop, machine_mode reg_mode)
1755 : {
1756 181524038 : int hard_regno, inner_hard_regno;
1757 181524038 : rtx_insn *before, *after;
1758 181524038 : machine_mode mode, innermode;
1759 181524038 : rtx reg, new_reg;
1760 181524038 : rtx operand = *curr_id->operand_loc[nop];
1761 181524038 : enum reg_class regclass;
1762 181524038 : enum op_type type;
1763 :
1764 181524038 : before = after = NULL;
1765 :
1766 181524038 : if (GET_CODE (operand) != SUBREG)
1767 : return false;
1768 :
1769 3885595 : mode = GET_MODE (operand);
1770 3885595 : reg = SUBREG_REG (operand);
1771 3885595 : innermode = GET_MODE (reg);
1772 3885595 : type = curr_static_id->operand[nop].type;
1773 3885595 : if (MEM_P (reg))
1774 : {
1775 10855 : const bool addr_was_valid
1776 10855 : = valid_address_p (innermode, XEXP (reg, 0), MEM_ADDR_SPACE (reg));
1777 10855 : alter_subreg (curr_id->operand_loc[nop], false);
1778 10855 : rtx subst = *curr_id->operand_loc[nop];
1779 10855 : lra_assert (MEM_P (subst));
1780 10855 : const bool addr_is_valid = valid_address_p (GET_MODE (subst),
1781 : XEXP (subst, 0),
1782 10855 : MEM_ADDR_SPACE (subst));
1783 10855 : if (!addr_was_valid
1784 10855 : || addr_is_valid
1785 10855 : || ((get_constraint_type (lookup_constraint
1786 0 : (curr_static_id->operand[nop].constraint))
1787 : != CT_SPECIAL_MEMORY)
1788 : /* We still can reload address and if the address is
1789 : valid, we can remove subreg without reloading its
1790 : inner memory. */
1791 0 : && valid_address_p (GET_MODE (subst),
1792 0 : regno_reg_rtx
1793 : [ira_class_hard_regs
1794 0 : [base_reg_class (GET_MODE (subst),
1795 0 : MEM_ADDR_SPACE (subst),
1796 : ADDRESS, SCRATCH,
1797 0 : subst, curr_insn)][0]],
1798 0 : MEM_ADDR_SPACE (subst))))
1799 : {
1800 : /* If we change the address for a paradoxical subreg of memory, the
1801 : new address might violate the necessary alignment or the access
1802 : might be slow; take this into consideration. We need not worry
1803 : about accesses beyond allocated memory for paradoxical memory
1804 : subregs as we don't substitute such equiv memory (see processing
1805 : equivalences in function lra_constraints) and because for spilled
1806 : pseudos we allocate stack memory enough for the biggest
1807 : corresponding paradoxical subreg.
1808 :
1809 : However, do not blindly simplify a (subreg (mem ...)) for
1810 : WORD_REGISTER_OPERATIONS targets as this may lead to loading junk
1811 : data into a register when the inner is narrower than outer or
1812 : missing important data from memory when the inner is wider than
1813 : outer. This rule only applies to modes that are no wider than
1814 : a word.
1815 :
1816 : If valid memory becomes invalid after subreg elimination
1817 : and address might be different we still have to reload
1818 : memory.
1819 : */
1820 10855 : if ((! addr_was_valid
1821 : || addr_is_valid
1822 0 : || known_eq (GET_MODE_SIZE (mode), GET_MODE_SIZE (innermode)))
1823 10855 : && !(maybe_ne (GET_MODE_PRECISION (mode),
1824 10855 : GET_MODE_PRECISION (innermode))
1825 11923 : && known_le (GET_MODE_SIZE (mode), UNITS_PER_WORD)
1826 18717 : && known_le (GET_MODE_SIZE (innermode), UNITS_PER_WORD)
1827 : && WORD_REGISTER_OPERATIONS)
1828 22800 : && (!(MEM_ALIGN (subst) < GET_MODE_ALIGNMENT (mode)
1829 1090 : && targetm.slow_unaligned_access (mode, MEM_ALIGN (subst)))
1830 0 : || (MEM_ALIGN (reg) < GET_MODE_ALIGNMENT (innermode)
1831 0 : && targetm.slow_unaligned_access (innermode,
1832 0 : MEM_ALIGN (reg)))))
1833 : return true;
1834 :
1835 0 : *curr_id->operand_loc[nop] = operand;
1836 :
1837 : /* But if the address was not valid, we cannot reload the MEM without
1838 : reloading the address first. */
1839 0 : if (!addr_was_valid)
1840 0 : process_address (nop, false, &before, &after);
1841 :
1842 : /* INNERMODE is fast, MODE slow. Reload the mem in INNERMODE. */
1843 0 : enum reg_class rclass
1844 0 : = (enum reg_class) targetm.preferred_reload_class (reg, ALL_REGS);
1845 0 : if (get_reload_reg (curr_static_id->operand[nop].type, innermode,
1846 : reg, rclass, NULL,
1847 : true, false, "slow/invalid mem", &new_reg))
1848 : {
1849 0 : bool insert_before, insert_after;
1850 0 : bitmap_set_bit (&lra_subreg_reload_pseudos, REGNO (new_reg));
1851 :
1852 0 : insert_before = (type != OP_OUT
1853 0 : || partial_subreg_p (mode, innermode));
1854 0 : insert_after = type != OP_IN;
1855 0 : insert_move_for_subreg (insert_before ? &before : NULL,
1856 : insert_after ? &after : NULL,
1857 : reg, new_reg);
1858 : }
1859 0 : SUBREG_REG (operand) = new_reg;
1860 :
1861 : /* Convert to MODE. */
1862 0 : reg = operand;
1863 0 : rclass
1864 0 : = (enum reg_class) targetm.preferred_reload_class (reg, ALL_REGS);
1865 0 : if (get_reload_reg (curr_static_id->operand[nop].type, mode, reg,
1866 : rclass, NULL,
1867 : true, false, "slow/invalid mem", &new_reg))
1868 : {
1869 0 : bool insert_before, insert_after;
1870 0 : bitmap_set_bit (&lra_subreg_reload_pseudos, REGNO (new_reg));
1871 :
1872 0 : insert_before = type != OP_OUT;
1873 0 : insert_after = type != OP_IN;
1874 0 : insert_move_for_subreg (insert_before ? &before : NULL,
1875 : insert_after ? &after : NULL,
1876 : reg, new_reg);
1877 : }
1878 0 : *curr_id->operand_loc[nop] = new_reg;
1879 0 : lra_process_new_insns (curr_insn, before, after,
1880 : "Inserting slow/invalid mem reload");
1881 0 : return true;
1882 : }
1883 :
1884 : /* If the address was valid and became invalid, prefer to reload
1885 : the memory. Typical case is when the index scale should
1886 : correspond the memory. */
1887 0 : *curr_id->operand_loc[nop] = operand;
1888 : /* Do not return false here as the MEM_P (reg) will be processed
1889 : later in this function. */
1890 : }
1891 3874740 : else if (REG_P (reg) && REGNO (reg) < FIRST_PSEUDO_REGISTER)
1892 : {
1893 : /* A narrowing subreg of a hard register that is not representable as a
1894 : hard register (its offset does not fall on a register boundary) cannot
1895 : be turned into one, and would otherwise be resolved to the wrong part
1896 : of the register. Reload it through memory so that the correct bytes
1897 : are accessed, as is done for pseudos below. Leave the frame, arg and
1898 : stack pointers alone: simplify_subreg_regno can reject them simply
1899 : because reload is not finished yet. */
1900 65 : if (partial_subreg_p (mode, innermode)
1901 65 : && REGNO (reg) != FRAME_POINTER_REGNUM
1902 : && REGNO (reg) != ARG_POINTER_REGNUM
1903 : && REGNO (reg) != STACK_POINTER_REGNUM
1904 70 : && simplify_subreg_regno (REGNO (reg), innermode,
1905 5 : SUBREG_BYTE (operand), mode) < 0)
1906 : {
1907 0 : if (get_reload_reg (type, innermode, reg, NO_REGS, NULL,
1908 : true, false, "non-representable subreg", &new_reg))
1909 : {
1910 0 : bitmap_set_bit (&lra_subreg_reload_pseudos, REGNO (new_reg));
1911 0 : bool insert_before = (type != OP_OUT
1912 0 : || read_modify_subreg_p (operand));
1913 0 : bool insert_after = (type != OP_IN);
1914 0 : insert_move_for_subreg (insert_before ? &before : NULL,
1915 : insert_after ? &after : NULL,
1916 : reg, new_reg);
1917 : }
1918 0 : SUBREG_REG (operand) = new_reg;
1919 0 : lra_process_new_insns (curr_insn, before, after,
1920 : "Inserting non-representable subreg reload");
1921 0 : return true;
1922 : }
1923 65 : alter_subreg (curr_id->operand_loc[nop], false);
1924 65 : return true;
1925 : }
1926 3874675 : else if (CONSTANT_P (reg))
1927 : {
1928 : /* Try to simplify subreg of constant. It is usually result of
1929 : equivalence substitution. */
1930 44002 : if (innermode == VOIDmode
1931 44002 : && (innermode = original_subreg_reg_mode[nop]) == VOIDmode)
1932 0 : innermode = curr_static_id->operand[nop].mode;
1933 44002 : if ((new_reg = simplify_subreg (mode, reg, innermode,
1934 44002 : SUBREG_BYTE (operand))) != NULL_RTX)
1935 : {
1936 43586 : *curr_id->operand_loc[nop] = new_reg;
1937 43586 : return true;
1938 : }
1939 : }
1940 : /* Put constant into memory when we have mixed modes. It generates
1941 : a better code in most cases as it does not need a secondary
1942 : reload memory. It also prevents LRA looping when LRA is using
1943 : secondary reload memory again and again. */
1944 832 : if (CONSTANT_P (reg) && CONST_POOL_OK_P (reg_mode, reg)
1945 3831505 : && SCALAR_INT_MODE_P (reg_mode) != SCALAR_INT_MODE_P (mode))
1946 : {
1947 8 : SUBREG_REG (operand) = force_const_mem (reg_mode, reg);
1948 8 : alter_subreg (curr_id->operand_loc[nop], false);
1949 8 : return true;
1950 : }
1951 3831081 : auto fp_subreg_can_be_simplified_after_reload_p = [] (machine_mode innermode,
1952 : poly_uint64 offset,
1953 : machine_mode mode) {
1954 0 : reload_completed = 1;
1955 0 : bool res = simplify_subreg_regno (FRAME_POINTER_REGNUM,
1956 : innermode,
1957 0 : offset, mode) >= 0;
1958 0 : reload_completed = 0;
1959 0 : return res;
1960 : };
1961 : /* Force a reload of the SUBREG_REG if this is a constant or PLUS or
1962 : if there may be a problem accessing OPERAND in the outer
1963 : mode. */
1964 3831081 : if ((REG_P (reg)
1965 3830623 : && REGNO (reg) >= FIRST_PSEUDO_REGISTER
1966 3830623 : && (hard_regno = lra_get_regno_hard_regno (REGNO (reg))) >= 0
1967 : /* Don't reload paradoxical subregs because we could be looping
1968 : having repeatedly final regno out of hard regs range. */
1969 3239890 : && (hard_regno_nregs (hard_regno, innermode)
1970 3239890 : >= hard_regno_nregs (hard_regno, mode))
1971 3234697 : && simplify_subreg_regno (hard_regno, innermode,
1972 3234697 : SUBREG_BYTE (operand), mode) < 0
1973 : /* Exclude reloading of frame pointer in subreg if frame pointer can not
1974 : be simplified here only because the reload is not finished yet. */
1975 816 : && (hard_regno != FRAME_POINTER_REGNUM
1976 461 : || !fp_subreg_can_be_simplified_after_reload_p (innermode,
1977 0 : SUBREG_BYTE (operand),
1978 : mode))
1979 : /* Don't reload subreg for matching reload. It is actually
1980 : valid subreg in LRA. */
1981 816 : && ! LRA_SUBREG_P (operand))
1982 7661701 : || CONSTANT_P (reg) || GET_CODE (reg) == PLUS || MEM_P (reg))
1983 : {
1984 461 : enum reg_class rclass;
1985 :
1986 461 : if (REG_P (reg))
1987 : /* There is a big probability that we will get the same class
1988 : for the new pseudo and we will get the same insn which
1989 : means infinite looping. So spill the new pseudo. */
1990 : rclass = NO_REGS;
1991 : else
1992 : /* The class will be defined later in curr_insn_transform. */
1993 458 : rclass
1994 458 : = (enum reg_class) targetm.preferred_reload_class (reg, ALL_REGS);
1995 :
1996 461 : if (get_reload_reg (curr_static_id->operand[nop].type, reg_mode, reg,
1997 : rclass, NULL,
1998 : true, false, "subreg reg", &new_reg))
1999 : {
2000 461 : bool insert_before, insert_after;
2001 461 : bitmap_set_bit (&lra_subreg_reload_pseudos, REGNO (new_reg));
2002 :
2003 922 : insert_before = (type != OP_OUT
2004 461 : || read_modify_subreg_p (operand));
2005 461 : insert_after = (type != OP_IN);
2006 920 : insert_move_for_subreg (insert_before ? &before : NULL,
2007 : insert_after ? &after : NULL,
2008 : reg, new_reg);
2009 : }
2010 461 : SUBREG_REG (operand) = new_reg;
2011 461 : lra_process_new_insns (curr_insn, before, after,
2012 : "Inserting subreg reload");
2013 461 : return true;
2014 : }
2015 : /* Force a reload for a paradoxical subreg. For paradoxical subreg,
2016 : IRA allocates hardreg to the inner pseudo reg according to its mode
2017 : instead of the outermode, so the size of the hardreg may not be enough
2018 : to contain the outermode operand, in that case we may need to insert
2019 : reload for the reg. For the following two types of paradoxical subreg,
2020 : we need to insert reload:
2021 : 1. If the op_type is OP_IN, and the hardreg could not be paired with
2022 : other hardreg to contain the outermode operand
2023 : (checked by in_hard_reg_set_p), we need to insert the reload.
2024 : 2. If the op_type is OP_OUT or OP_INOUT.
2025 :
2026 : Here is a paradoxical subreg example showing how the reload is generated:
2027 :
2028 : (insn 5 4 7 2 (set (reg:TI 106 [ __comp ])
2029 : (subreg:TI (reg:DI 107 [ __comp ]) 0)) {*movti_internal_rex64}
2030 :
2031 : In IRA, reg107 is allocated to a DImode hardreg. We use x86-64 as example
2032 : here, if reg107 is assigned to hardreg R15, because R15 is the last
2033 : hardreg, compiler cannot find another hardreg to pair with R15 to
2034 : contain TImode data. So we insert a TImode reload reg180 for it.
2035 : After reload is inserted:
2036 :
2037 : (insn 283 0 0 (set (subreg:DI (reg:TI 180 [orig:107 __comp ] [107]) 0)
2038 : (reg:DI 107 [ __comp ])) -1
2039 : (insn 5 4 7 2 (set (reg:TI 106 [ __comp ])
2040 : (subreg:TI (reg:TI 180 [orig:107 __comp ] [107]) 0)) {*movti_internal_rex64}
2041 :
2042 : Two reload hard registers will be allocated to reg180 to save TImode data
2043 : in LRA_assign.
2044 :
2045 : For LRA pseudos this should normally be handled by the biggest_mode
2046 : mechanism. However, it's possible for new uses of an LRA pseudo
2047 : to be introduced after we've allocated it, such as when undoing
2048 : inheritance, and the allocated register might not then be appropriate
2049 : for the new uses. */
2050 3830620 : else if (REG_P (reg)
2051 3830620 : && REGNO (reg) >= FIRST_PSEUDO_REGISTER
2052 3830620 : && paradoxical_subreg_p (operand)
2053 1026519 : && (inner_hard_regno = lra_get_regno_hard_regno (REGNO (reg))) >= 0
2054 948620 : && hard_regno_nregs (inner_hard_regno, mode) > 1
2055 3830620 : && ((hard_regno
2056 3835813 : = simplify_subreg_regno (inner_hard_regno, innermode,
2057 5193 : SUBREG_BYTE (operand), mode)) < 0
2058 5193 : || ((hard_regno_nregs (inner_hard_regno, innermode)
2059 5193 : < hard_regno_nregs (hard_regno, mode))
2060 10386 : && (regclass = lra_get_allocno_class (REGNO (reg)))
2061 5193 : && (type != OP_IN
2062 5193 : || !in_hard_reg_set_p (reg_class_contents[regclass],
2063 : mode, hard_regno)
2064 5193 : || overlaps_hard_reg_set_p (lra_no_alloc_regs,
2065 : mode, hard_regno)))))
2066 : {
2067 : /* The class will be defined later in curr_insn_transform. */
2068 0 : enum reg_class rclass
2069 0 : = (enum reg_class) targetm.preferred_reload_class (reg, ALL_REGS);
2070 :
2071 0 : if (get_reload_reg (curr_static_id->operand[nop].type, mode, reg,
2072 : rclass, NULL,
2073 : true, false, "paradoxical subreg", &new_reg))
2074 : {
2075 0 : rtx subreg;
2076 0 : bool insert_before, insert_after;
2077 :
2078 0 : PUT_MODE (new_reg, mode);
2079 0 : subreg = gen_lowpart_SUBREG (innermode, new_reg);
2080 0 : bitmap_set_bit (&lra_subreg_reload_pseudos, REGNO (new_reg));
2081 :
2082 0 : insert_before = (type != OP_OUT);
2083 0 : insert_after = (type != OP_IN);
2084 0 : insert_move_for_subreg (insert_before ? &before : NULL,
2085 : insert_after ? &after : NULL,
2086 : reg, subreg);
2087 : }
2088 0 : SUBREG_REG (operand) = new_reg;
2089 0 : lra_process_new_insns (curr_insn, before, after,
2090 : "Inserting paradoxical subreg reload");
2091 0 : return true;
2092 : }
2093 : return false;
2094 : }
2095 :
2096 : /* Return TRUE if X refers for a hard register from SET. */
2097 : static bool
2098 421357 : uses_hard_regs_p (rtx x, HARD_REG_SET set)
2099 : {
2100 421357 : int i, j, x_hard_regno;
2101 421357 : machine_mode mode;
2102 421357 : const char *fmt;
2103 421357 : enum rtx_code code;
2104 :
2105 421357 : if (x == NULL_RTX)
2106 : return false;
2107 421357 : code = GET_CODE (x);
2108 421357 : mode = GET_MODE (x);
2109 :
2110 421357 : if (code == SUBREG)
2111 : {
2112 : /* For all SUBREGs we want to check whether the full multi-register
2113 : overlaps the set. For normal SUBREGs this means 'get_hard_regno' of
2114 : the inner register, for paradoxical SUBREGs this means the
2115 : 'get_hard_regno' of the full SUBREG and for complete SUBREGs either is
2116 : fine. Use the wider mode for all cases. */
2117 11523 : rtx subreg = SUBREG_REG (x);
2118 11523 : mode = wider_subreg_mode (x);
2119 11523 : if (mode == GET_MODE (subreg))
2120 : {
2121 10490 : x = subreg;
2122 10490 : code = GET_CODE (x);
2123 : }
2124 : }
2125 :
2126 421357 : if (REG_P (x) || SUBREG_P (x))
2127 : {
2128 272251 : x_hard_regno = get_hard_regno (x);
2129 272251 : return (x_hard_regno >= 0
2130 272251 : && overlaps_hard_reg_set_p (set, mode, x_hard_regno));
2131 : }
2132 149106 : fmt = GET_RTX_FORMAT (code);
2133 386689 : for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
2134 : {
2135 239536 : if (fmt[i] == 'e')
2136 : {
2137 117270 : if (uses_hard_regs_p (XEXP (x, i), set))
2138 : return true;
2139 : }
2140 122266 : else if (fmt[i] == 'E')
2141 : {
2142 4390 : for (j = XVECLEN (x, i) - 1; j >= 0; j--)
2143 3976 : if (uses_hard_regs_p (XVECEXP (x, i, j), set))
2144 : return true;
2145 : }
2146 : }
2147 : return false;
2148 : }
2149 :
2150 : /* Return true if OP is a spilled pseudo. */
2151 : static inline bool
2152 83468554 : spilled_pseudo_p (rtx op)
2153 : {
2154 83468554 : return (REG_P (op)
2155 83468554 : && REGNO (op) >= FIRST_PSEUDO_REGISTER && in_mem_p (REGNO (op)));
2156 : }
2157 :
2158 : /* Return true if OP is (plus (reg) (const)). */
2159 : static inline bool
2160 57573 : reg_plus_const_p (rtx op)
2161 : {
2162 39272 : return (GET_CODE (op) == PLUS && REG_P (XEXP (op, 0))
2163 96845 : && CONSTANT_P (XEXP (op, 1)));
2164 : }
2165 :
2166 : /* Return true if X is a general constant. */
2167 : static inline bool
2168 8108996 : general_constant_p (rtx x)
2169 : {
2170 8108996 : return CONSTANT_P (x) && (! flag_pic || LEGITIMATE_PIC_OPERAND_P (x));
2171 : }
2172 :
2173 : static bool
2174 25826271 : reg_in_class_p (rtx reg, enum reg_class cl)
2175 : {
2176 25826271 : if (cl == NO_REGS)
2177 1148515 : return get_reg_class (REGNO (reg)) == NO_REGS;
2178 24677756 : return in_class_p (reg, cl, NULL);
2179 : }
2180 :
2181 : /* Return true if SET of RCLASS contains no hard regs which can be
2182 : used in MODE. */
2183 : static bool
2184 3891513 : prohibited_class_reg_set_mode_p (enum reg_class rclass,
2185 : HARD_REG_SET &set,
2186 : machine_mode mode)
2187 : {
2188 3891513 : HARD_REG_SET temp;
2189 :
2190 7783026 : lra_assert (hard_reg_set_subset_p (reg_class_contents[rclass], set));
2191 3891513 : temp = set & ~lra_no_alloc_regs;
2192 3891513 : return (hard_reg_set_subset_p
2193 3891513 : (temp, ira_prohibited_class_mode_regs[rclass][mode]));
2194 : }
2195 :
2196 :
2197 : /* Used to check validity info about small class input operands. It
2198 : should be incremented at start of processing an insn
2199 : alternative. */
2200 : static unsigned int curr_small_class_check = 0;
2201 :
2202 : /* Update number of used inputs of class OP_CLASS for operand NOP
2203 : of alternative NALT. Return true if we have more such class operands
2204 : than the number of available regs. */
2205 : static bool
2206 407347849 : update_and_check_small_class_inputs (int nop, int nalt,
2207 : enum reg_class op_class)
2208 : {
2209 407347849 : static unsigned int small_class_check[LIM_REG_CLASSES];
2210 407347849 : static int small_class_input_nums[LIM_REG_CLASSES];
2211 :
2212 404267844 : if (SMALL_REGISTER_CLASS_P (op_class)
2213 : /* We are interesting in classes became small because of fixing
2214 : some hard regs, e.g. by an user through GCC options. */
2215 3212351 : && hard_reg_set_intersect_p (reg_class_contents[op_class],
2216 3212351 : ira_no_alloc_regs)
2217 407347887 : && (curr_static_id->operand[nop].type != OP_OUT
2218 32 : || TEST_BIT (curr_static_id->operand[nop].early_clobber_alts, nalt)))
2219 : {
2220 6 : if (small_class_check[op_class] == curr_small_class_check)
2221 0 : small_class_input_nums[op_class]++;
2222 : else
2223 : {
2224 6 : small_class_check[op_class] = curr_small_class_check;
2225 6 : small_class_input_nums[op_class] = 1;
2226 : }
2227 6 : if (small_class_input_nums[op_class] > ira_class_hard_regs_num[op_class])
2228 0 : return true;
2229 : }
2230 : return false;
2231 : }
2232 :
2233 : /* Print operand constraints for alternative ALT_NUMBER of the current
2234 : insn. */
2235 : static void
2236 4573 : print_curr_insn_alt (int alt_number)
2237 : {
2238 15881 : for (int i = 0; i < curr_static_id->n_operands; i++)
2239 : {
2240 11308 : const char *p = (curr_static_id->operand_alternative
2241 11308 : [alt_number * curr_static_id->n_operands + i].constraint);
2242 11308 : if (*p == '\0')
2243 216 : continue;
2244 11092 : fprintf (lra_dump_file, " (%d) ", i);
2245 39370 : for (; *p != '\0' && *p != ',' && *p != '#'; p++)
2246 17186 : fputc (*p, lra_dump_file);
2247 : }
2248 4573 : }
2249 :
2250 : struct dependent_filter_cache_hasher
2251 : : free_ptr_hash <dependent_filter_entry>
2252 : {
2253 0 : static inline hashval_t hash (const dependent_filter_entry *e)
2254 : {
2255 0 : hashval_t h = (hashval_t) e->id;
2256 0 : h = iterative_hash_hashval_t ((hashval_t) e->mode, h);
2257 0 : h = iterative_hash_hashval_t ((hashval_t) e->partner_mode, h);
2258 0 : h = iterative_hash_hashval_t (e->partner_regno, h);
2259 0 : h = iterative_hash_hashval_t ((hashval_t) e->is_ref, h);
2260 0 : return h;
2261 : }
2262 0 : static inline bool equal (const dependent_filter_entry *a,
2263 : const dependent_filter_entry *b)
2264 : {
2265 0 : return (a->id == b->id && a->mode == b->mode
2266 0 : && a->partner_mode == b->partner_mode
2267 0 : && a->partner_regno == b->partner_regno
2268 0 : && a->is_ref == b->is_ref);
2269 : }
2270 : };
2271 :
2272 : static hash_table<dependent_filter_cache_hasher> *dependent_filter_htab;
2273 :
2274 : /* Allocate the dependent-filter cache. */
2275 :
2276 : void
2277 221764 : lra_init_dependent_filter_cache (void)
2278 : {
2279 221764 : gcc_assert (!dependent_filter_htab);
2280 221764 : dependent_filter_htab = new hash_table<dependent_filter_cache_hasher> (16);
2281 221764 : }
2282 :
2283 : /* Release the dependent-filter cache. */
2284 :
2285 : void
2286 293495 : lra_finish_dependent_filter_cache (void)
2287 : {
2288 293495 : delete dependent_filter_htab;
2289 293495 : dependent_filter_htab = nullptr;
2290 293495 : }
2291 :
2292 : /* Reset the dependent-filter cache. */
2293 :
2294 : void
2295 3062246 : lra_reset_dependent_filters (void)
2296 : {
2297 3062246 : if (dependent_filter_htab)
2298 3062246 : dependent_filter_htab->empty ();
2299 3062246 : }
2300 :
2301 : /* Return the set of hardregs allowed by dependent filter ID for an operand
2302 : of mode MODE when the referenced operand has PARTNER_REGNO in
2303 : PARTNER_MODE. That is when IS_REF is false. If it is true, the roles are
2304 : reversed and PARTNER_REGNO as well as PARTNER_MODE refer to the dependent
2305 : operand.
2306 :
2307 : We fill the set for all hardregs and add the resulting regset to
2308 : a hash table if it doesn't already exist in it. */
2309 :
2310 : const HARD_REG_SET *
2311 0 : lra_get_dependent_filter (int id, machine_mode mode,
2312 : unsigned int partner_regno,
2313 : machine_mode partner_mode, bool is_ref)
2314 : {
2315 0 : dependent_filter_entry key;
2316 0 : key.id = id;
2317 0 : key.mode = mode;
2318 0 : key.partner_mode = partner_mode;
2319 0 : key.partner_regno = partner_regno;
2320 0 : key.is_ref = is_ref;
2321 :
2322 0 : dependent_filter_entry **slot
2323 0 : = dependent_filter_htab->find_slot (&key, INSERT);
2324 0 : if (*slot)
2325 0 : return &(*slot)->allowed;
2326 :
2327 0 : auto *e = XCNEW (dependent_filter_entry);
2328 0 : e->id = id;
2329 0 : e->mode = mode;
2330 0 : e->partner_mode = partner_mode;
2331 0 : e->partner_regno = partner_regno;
2332 0 : e->is_ref = is_ref;
2333 :
2334 : /* ??? Should we restrict ourselves to a register class here? */
2335 0 : for (unsigned regno = 0; regno < FIRST_PSEUDO_REGISTER; ++regno)
2336 : {
2337 0 : bool ok;
2338 0 : if (is_ref)
2339 0 : ok = eval_dependent_filter (id, partner_regno, partner_mode,
2340 : regno, mode);
2341 : else
2342 0 : ok = eval_dependent_filter (id, regno, mode,
2343 : partner_regno, partner_mode);
2344 0 : if (ok)
2345 0 : SET_HARD_REG_BIT (e->allowed, regno);
2346 : }
2347 0 : *slot = e;
2348 0 : return &e->allowed;
2349 : }
2350 :
2351 : /* Add the dependent filter ID to REGNO's dependent filters with
2352 : referenced PARTNER_REGNO and PARTNER_MODE if IS_REF is false.
2353 : If IS_REF is true, the roles are reversed. We need both
2354 : directions in case the referenced op is assigned a hardreg first. */
2355 :
2356 : void
2357 0 : lra_add_dependent_filter (int regno, int id, machine_mode mode,
2358 : int partner_regno, machine_mode partner_mode,
2359 : bool is_ref)
2360 : {
2361 : /* Only meaningful for pseudo partners. */
2362 0 : if (partner_regno < FIRST_PSEUDO_REGISTER)
2363 0 : return;
2364 :
2365 0 : vec<dependent_filter> &filters = lra_reg_info[regno].dependent_filters;
2366 0 : unsigned int i;
2367 0 : dependent_filter *filter;
2368 :
2369 : /* If this filter already exists, do nothing. */
2370 0 : FOR_EACH_VEC_ELT (filters, i, filter)
2371 0 : if (filter->id == id
2372 0 : && filter->partner_regno == (unsigned int) partner_regno
2373 0 : && filter->mode == mode && filter->partner_mode == partner_mode
2374 0 : && filter->is_ref == is_ref)
2375 : return;
2376 :
2377 : /* Otherwise, create a new filter. */
2378 0 : dependent_filter new_filter;
2379 0 : new_filter.id = id;
2380 0 : new_filter.mode = mode;
2381 0 : new_filter.partner_mode = partner_mode;
2382 0 : new_filter.partner_regno = (unsigned int) partner_regno;
2383 0 : new_filter.is_ref = is_ref;
2384 0 : filters.safe_push (new_filter);
2385 : }
2386 :
2387 : /* Return the set of hardregs for the constraint CN in MODE,
2388 : allowed by its dependent filter.
2389 : If there is no dependent filter or the involved registers are no
2390 : hardregs, return NULL. */
2391 :
2392 : static const HARD_REG_SET *
2393 356105745 : get_dependent_filter (constraint_num cn, machine_mode mode)
2394 : {
2395 356105745 : int id = get_dependent_filter_id (cn);
2396 356105745 : if (id < 0)
2397 356105745 : return nullptr;
2398 :
2399 : gcc_assert (reg_class_for_constraint (cn) != NO_REGS);
2400 :
2401 : int ref_opno = get_dependent_filter_ref (id);
2402 : gcc_assert (ref_opno >= 0 && ref_opno < curr_static_id->n_operands);
2403 :
2404 : rtx ref_op = *curr_id->operand_loc[ref_opno];
2405 :
2406 : rtx inner = SUBREG_P (ref_op) ? SUBREG_REG (ref_op) : ref_op;
2407 :
2408 : if (!REG_P (inner))
2409 : return nullptr;
2410 :
2411 : int ref_regno = REGNO (inner);
2412 :
2413 : if (ref_regno >= FIRST_PSEUDO_REGISTER)
2414 : {
2415 : ref_regno = reg_renumber[ref_regno];
2416 : /* Even with a pseudo reference op, the filter can still reject
2417 : based on the partner. We call it with INVALID_REGNUM
2418 : to give it a chance to do so. Otherwise we'd introduce
2419 : an "all choices legal" filter that might later
2420 : "change its mind" once there is a fixed reference. */
2421 : if (ref_regno < 0)
2422 : return lra_get_dependent_filter (id, mode, INVALID_REGNUM,
2423 : GET_MODE (ref_op), false);
2424 : }
2425 :
2426 : /* For a subreg, get the actual regno. */
2427 : if (SUBREG_P (ref_op))
2428 : {
2429 : int subreg_regno = simplify_subreg_regno
2430 : (ref_regno, GET_MODE (inner), SUBREG_BYTE (ref_op),
2431 : GET_MODE (ref_op), true);
2432 : /* The subreg should always map to a hard regno here. */
2433 : gcc_assert (subreg_regno >= 0);
2434 :
2435 : ref_regno = subreg_regno;
2436 : }
2437 :
2438 : return lra_get_dependent_filter (id, mode, ref_regno, GET_MODE (ref_op),
2439 : false);
2440 : }
2441 :
2442 : /* Go through all operands and their constraints, looking for a dependent
2443 : filter. If we find one, add it to the respective reg_info's
2444 : dependent-filter list. After assigning a hardreg to either the dependent
2445 : or the referenced op, this allows us to filter the other's regset. */
2446 :
2447 : static void
2448 81998868 : process_dependent_filters (void)
2449 : {
2450 81998868 : int n_operands = curr_static_id->n_operands;
2451 264979377 : for (int i = 0; i < n_operands; i++)
2452 : {
2453 182980509 : rtx op = *curr_id->operand_loc[i];
2454 182980509 : if (!REG_P (op) || HARD_REGISTER_P (op))
2455 100226879 : continue;
2456 82753630 : const char *constraint
2457 82753630 : = curr_static_id->operand_alternative
2458 82753630 : [goal_alt_number * n_operands + i].constraint;
2459 82753630 : for (const char *p = constraint;
2460 217371486 : *p && *p != ',' && *p != '#';
2461 134617856 : p += CONSTRAINT_LEN (*p, p))
2462 : {
2463 134617856 : enum constraint_num cn = lookup_constraint (p);
2464 134617856 : int id = get_dependent_filter_id (cn);
2465 134617856 : if (id < 0)
2466 134617856 : continue;
2467 : if (reg_class_for_constraint (cn) == NO_REGS)
2468 : continue;
2469 : int ref_opno = get_dependent_filter_ref (id);
2470 : if (ref_opno < 0 || ref_opno >= n_operands)
2471 : continue;
2472 : rtx ref_op = *curr_id->operand_loc[ref_opno];
2473 : if (!REG_P (ref_op) || HARD_REGISTER_P (ref_op))
2474 : continue;
2475 : machine_mode mode = curr_operand_mode[i];
2476 : lra_add_dependent_filter (REGNO (op), id, mode,
2477 : REGNO (ref_op), GET_MODE (ref_op),
2478 : false);
2479 : lra_add_dependent_filter (REGNO (ref_op), id, GET_MODE (ref_op),
2480 : REGNO (op), mode, true);
2481 : }
2482 : }
2483 81998868 : }
2484 :
2485 : /* Major function to choose the current insn alternative and what
2486 : operands should be reloaded and how. If ONLY_ALTERNATIVE is not
2487 : negative we should consider only this alternative. Return false if
2488 : we cannot choose the alternative or find how to reload the
2489 : operands. */
2490 : static bool
2491 92733858 : process_alt_operands (int only_alternative)
2492 : {
2493 92733858 : bool ok_p = false;
2494 92733858 : int nop, overall, nalt;
2495 92733858 : int n_alternatives = curr_static_id->n_alternatives;
2496 92733858 : int n_operands = curr_static_id->n_operands;
2497 : /* LOSERS counts the operands that don't fit this alternative and
2498 : would require loading. */
2499 92733858 : int losers;
2500 92733858 : int addr_losers;
2501 : /* REJECT is a count of how undesirable this alternative says it is
2502 : if any reloading is required. If the alternative matches exactly
2503 : then REJECT is ignored, but otherwise it gets this much counted
2504 : against it in addition to the reloading needed. */
2505 92733858 : int reject;
2506 : /* This is defined by '!' or '?' alternative constraint and added to
2507 : reject. But in some cases it can be ignored. */
2508 92733858 : int static_reject;
2509 92733858 : int op_reject;
2510 : /* The number of elements in the following array. */
2511 92733858 : int early_clobbered_regs_num;
2512 : /* Numbers of operands which are early clobber registers. */
2513 92733858 : int early_clobbered_nops[MAX_RECOG_OPERANDS];
2514 92733858 : enum reg_class curr_alt[MAX_RECOG_OPERANDS];
2515 92733858 : enum reg_class all_this_alternative;
2516 92733858 : int all_used_nregs, all_reload_nregs;
2517 92733858 : HARD_REG_SET curr_alt_set[MAX_RECOG_OPERANDS];
2518 92733858 : HARD_REG_SET curr_alt_exclude_start_hard_regs[MAX_RECOG_OPERANDS];
2519 92733858 : bool curr_alt_match_win[MAX_RECOG_OPERANDS];
2520 92733858 : bool curr_alt_win[MAX_RECOG_OPERANDS];
2521 92733858 : bool curr_alt_offmemok[MAX_RECOG_OPERANDS];
2522 92733858 : int curr_alt_matches[MAX_RECOG_OPERANDS];
2523 : /* The number of elements in the following array. */
2524 92733858 : int curr_alt_dont_inherit_ops_num;
2525 : /* Numbers of operands whose reload pseudos should not be inherited. */
2526 92733858 : int curr_alt_dont_inherit_ops[MAX_RECOG_OPERANDS];
2527 92733858 : bool curr_reuse_alt_p;
2528 : /* True if output stack pointer reload should be generated for the current
2529 : alternative. */
2530 92733858 : bool curr_alt_out_sp_reload_p;
2531 92733858 : bool curr_alt_class_change_p;
2532 92733858 : rtx op;
2533 : /* The register when the operand is a subreg of register, otherwise the
2534 : operand itself. */
2535 92733858 : rtx no_subreg_reg_operand[MAX_RECOG_OPERANDS];
2536 : /* The register if the operand is a register or subreg of register,
2537 : otherwise NULL. */
2538 92733858 : rtx operand_reg[MAX_RECOG_OPERANDS];
2539 92733858 : int hard_regno[MAX_RECOG_OPERANDS];
2540 92733858 : machine_mode biggest_mode[MAX_RECOG_OPERANDS];
2541 92733858 : int reload_nregs, reload_sum;
2542 92733858 : bool costly_p;
2543 92733858 : enum reg_class cl;
2544 92733858 : const HARD_REG_SET *cl_filter;
2545 92733858 : HARD_REG_SET hard_reg_constraint;
2546 :
2547 : /* Calculate some data common for all alternatives to speed up the
2548 : function. */
2549 308447146 : for (nop = 0; nop < n_operands; nop++)
2550 : {
2551 215713288 : rtx reg;
2552 :
2553 215713288 : op = no_subreg_reg_operand[nop] = *curr_id->operand_loc[nop];
2554 : /* The real hard regno of the operand after the allocation. */
2555 215713288 : hard_regno[nop] = get_hard_regno (op);
2556 :
2557 215713288 : operand_reg[nop] = reg = op;
2558 215713288 : biggest_mode[nop] = GET_MODE (op);
2559 215713288 : if (GET_CODE (op) == SUBREG)
2560 : {
2561 4366752 : biggest_mode[nop] = wider_subreg_mode (op);
2562 4366752 : operand_reg[nop] = reg = SUBREG_REG (op);
2563 : }
2564 215713288 : if (! REG_P (reg))
2565 91145893 : operand_reg[nop] = NULL_RTX;
2566 124567395 : else if (REGNO (reg) >= FIRST_PSEUDO_REGISTER
2567 146188903 : || ((int) REGNO (reg)
2568 21621508 : == lra_get_elimination_hard_regno (REGNO (reg))))
2569 121481036 : no_subreg_reg_operand[nop] = reg;
2570 : else
2571 3086359 : operand_reg[nop] = no_subreg_reg_operand[nop]
2572 : /* Just use natural mode for elimination result. It should
2573 : be enough for extra constraints hooks. */
2574 3086359 : = regno_reg_rtx[hard_regno[nop]];
2575 : }
2576 :
2577 : /* The constraints are made of several alternatives. Each operand's
2578 : constraint looks like foo,bar,... with commas separating the
2579 : alternatives. The first alternatives for all operands go
2580 : together, the second alternatives go together, etc.
2581 :
2582 : First loop over alternatives. */
2583 92733858 : alternative_mask preferred = curr_id->preferred_alternatives;
2584 92733858 : if (only_alternative >= 0)
2585 985961 : preferred &= ALTERNATIVE_BIT (only_alternative);
2586 :
2587 92733858 : bool prefer_memory_p = false;
2588 92734429 : repeat:
2589 392038002 : for (nalt = 0; nalt < n_alternatives; nalt++)
2590 : {
2591 : /* Loop over operands for one constraint alternative. */
2592 377930344 : if (!TEST_BIT (preferred, nalt))
2593 112190398 : continue;
2594 :
2595 265739946 : if (lra_dump_file != NULL)
2596 : {
2597 3388 : fprintf (lra_dump_file, " Considering alt=%d of insn %d: ",
2598 3388 : nalt, INSN_UID (curr_insn));
2599 3388 : print_curr_insn_alt (nalt);
2600 3388 : fprintf (lra_dump_file, "\n");
2601 : }
2602 :
2603 265739946 : bool matching_early_clobber[MAX_RECOG_OPERANDS];
2604 265739946 : curr_small_class_check++;
2605 265739946 : overall = losers = addr_losers = 0;
2606 265739946 : static_reject = reject = reload_nregs = reload_sum = 0;
2607 881363100 : for (nop = 0; nop < n_operands; nop++)
2608 : {
2609 615623154 : int inc = (curr_static_id
2610 615623154 : ->operand_alternative[nalt * n_operands + nop].reject);
2611 615623154 : if (lra_dump_file != NULL && inc != 0)
2612 52 : fprintf (lra_dump_file,
2613 : " Statically defined alt reject+=%d\n", inc);
2614 615623154 : static_reject += inc;
2615 615623154 : matching_early_clobber[nop] = 0;
2616 : }
2617 : reject += static_reject;
2618 : early_clobbered_regs_num = 0;
2619 : curr_alt_out_sp_reload_p = false;
2620 : curr_reuse_alt_p = true;
2621 : curr_alt_class_change_p = false;
2622 : all_this_alternative = NO_REGS;
2623 : all_used_nregs = all_reload_nregs = 0;
2624 688385156 : for (nop = 0; nop < n_operands; nop++)
2625 : {
2626 548905099 : const char *p;
2627 548905099 : char *end;
2628 548905099 : int len, c, m, i, opalt_num, this_alternative_matches;
2629 548905099 : bool win, did_match, offmemok, early_clobber_p;
2630 : /* false => this operand can be reloaded somehow for this
2631 : alternative. */
2632 548905099 : bool badop;
2633 : /* true => this operand can be reloaded if the alternative
2634 : allows regs. */
2635 548905099 : bool winreg;
2636 : /* True if a constant forced into memory would be OK for
2637 : this operand. */
2638 548905099 : bool constmemok;
2639 548905099 : enum reg_class this_alternative, this_costly_alternative;
2640 548905099 : HARD_REG_SET this_alternative_set, this_costly_alternative_set;
2641 548905099 : HARD_REG_SET this_alternative_exclude_start_hard_regs;
2642 548905099 : bool this_alternative_match_win, this_alternative_win;
2643 548905099 : bool this_alternative_offmemok;
2644 548905099 : bool scratch_p;
2645 548905099 : machine_mode mode;
2646 548905099 : enum constraint_num cn;
2647 548905099 : bool class_change_p = false;
2648 :
2649 548905099 : opalt_num = nalt * n_operands + nop;
2650 548905099 : if (curr_static_id->operand_alternative[opalt_num].anything_ok)
2651 : {
2652 : /* Fast track for no constraints at all. */
2653 15297361 : curr_alt[nop] = NO_REGS;
2654 15297361 : CLEAR_HARD_REG_SET (curr_alt_set[nop]);
2655 15297361 : curr_alt_win[nop] = true;
2656 15297361 : curr_alt_match_win[nop] = false;
2657 15297361 : curr_alt_offmemok[nop] = false;
2658 15297361 : curr_alt_matches[nop] = -1;
2659 15297361 : continue;
2660 : }
2661 :
2662 533607738 : op = no_subreg_reg_operand[nop];
2663 533607738 : mode = curr_operand_mode[nop];
2664 :
2665 533607738 : win = did_match = winreg = offmemok = constmemok = false;
2666 533607738 : badop = true;
2667 533607738 : const HARD_REG_SET *cl_dep_filter = nullptr;
2668 :
2669 533607738 : early_clobber_p = false;
2670 533607738 : p = curr_static_id->operand_alternative[opalt_num].constraint;
2671 :
2672 533607738 : this_costly_alternative = this_alternative = NO_REGS;
2673 : /* We update set of possible hard regs besides its class
2674 : because reg class might be inaccurate. For example,
2675 : union of LO_REGS (l), HI_REGS(h), and STACK_REG(k) in ARM
2676 : is translated in HI_REGS because classes are merged by
2677 : pairs and there is no accurate intermediate class. */
2678 2134430952 : CLEAR_HARD_REG_SET (this_alternative_set);
2679 1600823214 : CLEAR_HARD_REG_SET (this_costly_alternative_set);
2680 533607738 : CLEAR_HARD_REG_SET (this_alternative_exclude_start_hard_regs);
2681 533607738 : this_alternative_win = false;
2682 533607738 : this_alternative_match_win = false;
2683 533607738 : this_alternative_offmemok = false;
2684 533607738 : this_alternative_matches = -1;
2685 :
2686 : /* An empty constraint should be excluded by the fast
2687 : track. */
2688 533607738 : lra_assert (*p != 0 && *p != ',');
2689 :
2690 : op_reject = 0;
2691 : /* Scan this alternative's specs for this operand; set WIN
2692 : if the operand fits any letter in this alternative.
2693 : Otherwise, clear BADOP if this operand could fit some
2694 : letter after reloads, or set WINREG if this operand could
2695 : fit after reloads provided the constraint allows some
2696 : registers. */
2697 : costly_p = false;
2698 1354971960 : do
2699 : {
2700 1354971960 : switch ((c = *p, len = CONSTRAINT_LEN (c, p)), c)
2701 : {
2702 : case '\0':
2703 : len = 0;
2704 : break;
2705 510189720 : case ',':
2706 510189720 : c = '\0';
2707 510189720 : break;
2708 :
2709 198475 : case '&':
2710 198475 : early_clobber_p = true;
2711 198475 : break;
2712 :
2713 20276 : case '$':
2714 20276 : op_reject += LRA_MAX_REJECT;
2715 20276 : break;
2716 0 : case '^':
2717 0 : op_reject += LRA_LOSER_COST_FACTOR;
2718 0 : break;
2719 :
2720 0 : case '#':
2721 : /* Ignore rest of this alternative. */
2722 0 : c = '\0';
2723 0 : break;
2724 :
2725 58125785 : case '0': case '1': case '2': case '3': case '4':
2726 58125785 : case '5': case '6': case '7': case '8': case '9':
2727 58125785 : {
2728 58125785 : int m_hregno;
2729 58125785 : bool match_p;
2730 :
2731 58125785 : m = strtoul (p, &end, 10);
2732 58125785 : p = end;
2733 58125785 : len = 0;
2734 58125785 : lra_assert (nop > m);
2735 :
2736 : /* Reject matches if we don't know which operand is
2737 : bigger. This situation would arguably be a bug in
2738 : an .md pattern, but could also occur in a user asm. */
2739 174377355 : if (!ordered_p (GET_MODE_SIZE (biggest_mode[m]),
2740 58125785 : GET_MODE_SIZE (biggest_mode[nop])))
2741 : break;
2742 :
2743 : /* Don't match wrong asm insn operands for proper
2744 : diagnostic later. */
2745 58125785 : if (INSN_CODE (curr_insn) < 0
2746 35090 : && (curr_operand_mode[m] == BLKmode
2747 35083 : || curr_operand_mode[nop] == BLKmode)
2748 7 : && curr_operand_mode[m] != curr_operand_mode[nop])
2749 : break;
2750 :
2751 58125784 : m_hregno = get_hard_regno (*curr_id->operand_loc[m]);
2752 : /* We are supposed to match a previous operand.
2753 : If we do, we win if that one did. If we do
2754 : not, count both of the operands as losers.
2755 : (This is too conservative, since most of the
2756 : time only a single reload insn will be needed
2757 : to make the two operands win. As a result,
2758 : this alternative may be rejected when it is
2759 : actually desirable.) */
2760 58125784 : match_p = false;
2761 58125784 : if (operands_match_p (*curr_id->operand_loc[nop],
2762 58125784 : *curr_id->operand_loc[m], m_hregno))
2763 : {
2764 : /* We should reject matching of an early
2765 : clobber operand if the matching operand is
2766 : not dying in the insn. */
2767 15313982 : if (!TEST_BIT (curr_static_id->operand[m]
2768 : .early_clobber_alts, nalt)
2769 20723 : || operand_reg[nop] == NULL_RTX
2770 15334705 : || (find_regno_note (curr_insn, REG_DEAD,
2771 : REGNO (op))
2772 4432 : || REGNO (op) == REGNO (operand_reg[m])))
2773 15313982 : match_p = true;
2774 : }
2775 15313982 : if (match_p)
2776 : {
2777 : /* If we are matching a non-offsettable
2778 : address where an offsettable address was
2779 : expected, then we must reject this
2780 : combination, because we can't reload
2781 : it. */
2782 15313982 : if (curr_alt_offmemok[m]
2783 1574 : && MEM_P (*curr_id->operand_loc[m])
2784 5 : && curr_alt[m] == NO_REGS && ! curr_alt_win[m])
2785 0 : continue;
2786 : }
2787 : else
2788 : {
2789 : /* If the operands do not match and one
2790 : operand is INOUT, we can not match them.
2791 : Try other possibilities, e.g. other
2792 : alternatives or commutative operand
2793 : exchange. */
2794 42811802 : if (curr_static_id->operand[nop].type == OP_INOUT
2795 42811802 : || curr_static_id->operand[m].type == OP_INOUT)
2796 : break;
2797 : /* Operands don't match. For asm if the operands
2798 : are different user defined explicit hard
2799 : registers, then we cannot make them match
2800 : when one is early clobber operand. */
2801 42811363 : if ((REG_P (*curr_id->operand_loc[nop])
2802 26455847 : || SUBREG_P (*curr_id->operand_loc[nop]))
2803 16962972 : && (REG_P (*curr_id->operand_loc[m])
2804 204585 : || SUBREG_P (*curr_id->operand_loc[m]))
2805 16866728 : && INSN_CODE (curr_insn) < 0)
2806 : {
2807 653 : rtx nop_reg = *curr_id->operand_loc[nop];
2808 653 : if (SUBREG_P (nop_reg))
2809 0 : nop_reg = SUBREG_REG (nop_reg);
2810 653 : rtx m_reg = *curr_id->operand_loc[m];
2811 653 : if (SUBREG_P (m_reg))
2812 0 : m_reg = SUBREG_REG (m_reg);
2813 :
2814 653 : if (REG_P (nop_reg)
2815 653 : && HARD_REGISTER_P (nop_reg)
2816 0 : && REG_USERVAR_P (nop_reg)
2817 0 : && REG_P (m_reg)
2818 0 : && HARD_REGISTER_P (m_reg)
2819 653 : && REG_USERVAR_P (m_reg))
2820 : {
2821 : int i;
2822 :
2823 0 : for (i = 0; i < early_clobbered_regs_num; i++)
2824 0 : if (m == early_clobbered_nops[i])
2825 : break;
2826 0 : if (i < early_clobbered_regs_num
2827 0 : || early_clobber_p)
2828 : break;
2829 : }
2830 : }
2831 : /* Both operands must allow a reload register or the
2832 : matched operand accepts memory (e.g. 'g' with a mode
2833 : that fits no hard reg), in which case the operands
2834 : can be matched in memory. */
2835 42811363 : if (curr_alt[m] == NO_REGS && !curr_alt_offmemok[m])
2836 : break;
2837 : /* Retroactively mark the operand we had to
2838 : match as a loser, if it wasn't already and
2839 : it wasn't matched to a register constraint
2840 : (e.g it might be matched by memory). */
2841 42786231 : if (curr_alt_win[m]
2842 41919048 : && (operand_reg[m] == NULL_RTX
2843 41401001 : || hard_regno[m] < 0))
2844 : {
2845 1264569 : if (lra_dump_file != NULL)
2846 9 : fprintf
2847 9 : (lra_dump_file,
2848 : " %d Matched operand reload: "
2849 : "losers++\n", m);
2850 1264569 : losers++;
2851 1264569 : reload_nregs
2852 1264569 : += (ira_reg_class_max_nregs[curr_alt[m]]
2853 1264569 : [GET_MODE (*curr_id->operand_loc[m])]);
2854 : }
2855 :
2856 : /* Prefer matching earlyclobber alternative as
2857 : it results in less hard regs required for
2858 : the insn than a non-matching earlyclobber
2859 : alternative. */
2860 42786231 : if (TEST_BIT (curr_static_id->operand[m]
2861 : .early_clobber_alts, nalt))
2862 : {
2863 19776 : if (lra_dump_file != NULL)
2864 0 : fprintf
2865 0 : (lra_dump_file,
2866 : " %d Matching earlyclobber alt:"
2867 : " reject--\n",
2868 : nop);
2869 19776 : if (!matching_early_clobber[m])
2870 : {
2871 19776 : reject--;
2872 19776 : matching_early_clobber[m] = 1;
2873 : }
2874 : }
2875 : /* Otherwise we prefer no matching
2876 : alternatives because it gives more freedom
2877 : in RA. */
2878 42766455 : else if (operand_reg[nop] == NULL_RTX
2879 42766455 : || (find_regno_note (curr_insn, REG_DEAD,
2880 16936998 : REGNO (operand_reg[nop]))
2881 : == NULL_RTX))
2882 : {
2883 37494815 : if (lra_dump_file != NULL)
2884 916 : fprintf
2885 916 : (lra_dump_file,
2886 : " %d Matching alt: reject+=2\n",
2887 : nop);
2888 37494815 : reject += 2;
2889 : }
2890 : }
2891 : /* If we have to reload this operand and some
2892 : previous operand also had to match the same
2893 : thing as this operand, we don't know how to do
2894 : that. */
2895 58100213 : if (!match_p || !curr_alt_win[m])
2896 : {
2897 90027740 : for (i = 0; i < nop; i++)
2898 47124649 : if (curr_alt_matches[i] == m)
2899 : break;
2900 42903092 : if (i < nop)
2901 : break;
2902 : }
2903 : else
2904 : did_match = true;
2905 :
2906 58100212 : this_alternative_matches = m;
2907 : /* This can be fixed with reloads if the operand
2908 : we are supposed to match can be fixed with
2909 : reloads. */
2910 58100212 : badop = false;
2911 58100212 : this_alternative = curr_alt[m];
2912 58100212 : this_alternative_set = curr_alt_set[m];
2913 58100212 : this_alternative_exclude_start_hard_regs
2914 58100212 : = curr_alt_exclude_start_hard_regs[m];
2915 : /* If the matched operand permits memory (e.g. 'g'),
2916 : so does this one -- they share the same location.
2917 : This lets a matching reload go to memory when no
2918 : hard reg of the class can hold the operand mode. */
2919 58100212 : offmemok = curr_alt_offmemok[m];
2920 58100212 : winreg = this_alternative != NO_REGS;
2921 58100212 : break;
2922 : }
2923 :
2924 12040563 : case 'g':
2925 12040563 : if (MEM_P (op)
2926 8108996 : || general_constant_p (op)
2927 16692820 : || spilled_pseudo_p (op))
2928 : win = true;
2929 12040563 : if (REG_P (op) && prefer_memory_p)
2930 : {
2931 12040563 : badop = false;
2932 12040563 : offmemok = true;
2933 : }
2934 12040563 : cl = GENERAL_REGS;
2935 12040563 : cl_filter = nullptr;
2936 12040563 : cl_dep_filter = nullptr;
2937 12040563 : goto reg;
2938 :
2939 687 : case '{':
2940 687 : {
2941 687 : int regno = decode_hard_reg_constraint (p);
2942 687 : gcc_assert (regno >= 0);
2943 687 : cl = NO_REGS;
2944 687 : int nregs = hard_regno_nregs (regno, mode);
2945 1374 : for (int i = 0; i < nregs; ++i)
2946 687 : cl = reg_class_superunion[cl][REGNO_REG_CLASS (regno + i)];
2947 687 : CLEAR_HARD_REG_SET (hard_reg_constraint);
2948 687 : SET_HARD_REG_BIT (hard_reg_constraint, regno);
2949 687 : cl_filter = &hard_reg_constraint;
2950 687 : cl_dep_filter = nullptr;
2951 687 : goto reg;
2952 : }
2953 :
2954 750978436 : default:
2955 750978436 : cn = lookup_constraint (p);
2956 750978436 : switch (get_constraint_type (cn))
2957 : {
2958 496501191 : case CT_REGISTER:
2959 496501191 : cl = reg_class_for_constraint (cn);
2960 365731456 : if (cl != NO_REGS)
2961 : {
2962 356105745 : cl_filter = get_register_filter (cn);
2963 356105745 : cl_dep_filter = get_dependent_filter (cn, mode);
2964 356105745 : goto reg;
2965 : }
2966 : break;
2967 :
2968 2272689 : case CT_CONST_INT:
2969 2272689 : if (CONST_INT_P (op)
2970 2272689 : && insn_const_int_ok_for_constraint (INTVAL (op), cn))
2971 : win = true;
2972 : break;
2973 :
2974 114294482 : case CT_MEMORY:
2975 114294482 : case CT_RELAXED_MEMORY:
2976 114294482 : if (MEM_P (op)
2977 114294482 : && satisfies_memory_constraint_p (op, cn))
2978 : win = true;
2979 77738995 : else if (spilled_pseudo_p (op))
2980 46230704 : win = true;
2981 :
2982 : /* If we didn't already win, we can reload constants
2983 : via force_const_mem or put the pseudo value into
2984 : memory, or make other memory by reloading the
2985 : address like for 'o'. */
2986 119831013 : if (CONST_POOL_OK_P (mode, op)
2987 108757751 : || MEM_P (op) || REG_P (op)
2988 : /* We can restore the equiv insn by a
2989 : reload. */
2990 632581 : || equiv_substition_p[nop]
2991 : /* It can be a sum produced by elimination of a
2992 : register. We can materialized into a register and
2993 : then spill into memory. */
2994 114329786 : || reg_plus_const_p (op))
2995 : badop = false;
2996 : constmemok = true;
2997 : offmemok = true;
2998 : break;
2999 :
3000 1791760 : case CT_ADDRESS:
3001 : /* An asm operand with an address constraint
3002 : that doesn't satisfy address_operand has
3003 : is_address cleared, so that we don't try to
3004 : make a non-address fit. */
3005 1791760 : if (!curr_static_id->operand[nop].is_address)
3006 : break;
3007 : /* If we didn't already win, we can reload the address
3008 : into a base register. */
3009 1791741 : if (satisfies_address_constraint_p (op, cn))
3010 1791741 : win = true;
3011 1791741 : cl = base_reg_class (VOIDmode, ADDR_SPACE_GENERIC,
3012 : ADDRESS, SCRATCH, NULL_RTX,
3013 : curr_insn);
3014 1791741 : cl_filter = nullptr;
3015 1791741 : cl_dep_filter = nullptr;
3016 1791741 : badop = false;
3017 1791741 : goto reg;
3018 :
3019 134889996 : case CT_FIXED_FORM:
3020 134889996 : if (constraint_satisfied_p (op, cn))
3021 1354971960 : win = true;
3022 : break;
3023 :
3024 1228318 : case CT_SPECIAL_MEMORY:
3025 1228318 : if (satisfies_memory_constraint_p (op, cn))
3026 : win = true;
3027 1077302 : else if (spilled_pseudo_p (op))
3028 : {
3029 1354971960 : curr_reuse_alt_p = false;
3030 1354971960 : win = true;
3031 : }
3032 : break;
3033 : }
3034 : break;
3035 :
3036 369938736 : reg:
3037 369938736 : if (mode == BLKmode)
3038 : break;
3039 369938706 : this_alternative = reg_class_subunion[this_alternative][cl];
3040 369938706 : if (hard_reg_set_subset_p (this_alternative_set,
3041 369938706 : reg_class_contents[cl]))
3042 369935057 : this_alternative_exclude_start_hard_regs
3043 369935057 : = ira_exclude_class_mode_regs[cl][mode];
3044 3649 : else if (!hard_reg_set_subset_p (reg_class_contents[cl],
3045 : this_alternative_set))
3046 3648 : this_alternative_exclude_start_hard_regs
3047 3648 : |= ira_exclude_class_mode_regs[cl][mode];
3048 369938706 : this_alternative_set |= reg_class_contents[cl];
3049 369938706 : if (cl_filter)
3050 1374 : this_alternative_exclude_start_hard_regs |= ~*cl_filter;
3051 369938706 : if (cl_dep_filter)
3052 : this_alternative_exclude_start_hard_regs |= ~*cl_dep_filter;
3053 369938706 : if (costly_p)
3054 : {
3055 21853470 : this_costly_alternative
3056 21853470 : = reg_class_subunion[this_costly_alternative][cl];
3057 21853470 : this_costly_alternative_set |= reg_class_contents[cl];
3058 : }
3059 369938706 : winreg = true;
3060 369938706 : if (REG_P (op))
3061 : {
3062 235763766 : rtx orig_op = *curr_id->operand_loc[nop];
3063 6947295 : if (GET_CODE (orig_op) == SUBREG && HARD_REGISTER_P (op)
3064 235763854 : && !targetm.hard_regno_mode_ok (REGNO (op),
3065 88 : GET_MODE(orig_op)))
3066 : break;
3067 :
3068 235763766 : tree decl;
3069 :
3070 235763766 : if (hard_regno[nop] >= 0
3071 199357527 : && in_hard_reg_set_p (this_alternative_set,
3072 : mode, hard_regno[nop])
3073 180492281 : && (!cl_filter
3074 410 : || TEST_HARD_REG_BIT (*cl_filter,
3075 : hard_regno[nop]))
3076 : && (!cl_dep_filter
3077 : || TEST_HARD_REG_BIT (*cl_dep_filter,
3078 : hard_regno[nop]))
3079 416256041 : && ((REG_ATTRS (op) && (decl = REG_EXPR (op)) != NULL
3080 100648119 : && VAR_P (decl) && DECL_HARD_REGISTER (decl))
3081 180488974 : || !(TEST_HARD_REG_BIT
3082 180488974 : (this_alternative_exclude_start_hard_regs,
3083 : hard_regno[nop]))))
3084 : win = true;
3085 55271492 : else if (hard_regno[nop] < 0 && !prefer_memory_p)
3086 : {
3087 36405474 : if (in_class_p (op, this_alternative, NULL))
3088 : win = true;
3089 27327588 : else if (in_class_p (op, this_alternative, NULL, true))
3090 : {
3091 1354971960 : class_change_p = true;
3092 1354971960 : win = true;
3093 : }
3094 : }
3095 : }
3096 : break;
3097 : }
3098 1354971960 : if (c != ' ' && c != '\t')
3099 1354971960 : costly_p = c == '*';
3100 : }
3101 1354971960 : while ((p += len), c);
3102 :
3103 1067215476 : scratch_p = (operand_reg[nop] != NULL_RTX
3104 533607738 : && ira_former_scratch_p (REGNO (operand_reg[nop])));
3105 : /* Record which operands fit this alternative. */
3106 533607738 : if (win)
3107 : {
3108 287794262 : if (early_clobber_p
3109 287636708 : || curr_static_id->operand[nop].type != OP_OUT)
3110 : {
3111 125875230 : if (winreg)
3112 104093124 : all_used_nregs
3113 104093124 : += ira_reg_class_min_nregs[this_alternative][mode];
3114 125875230 : all_this_alternative
3115 125875230 : = (reg_class_subunion
3116 125875230 : [all_this_alternative][this_alternative]);
3117 : }
3118 287794262 : this_alternative_win = true;
3119 : /* If reg and memory is acceptable here (e.g. 'g') but no hard
3120 : reg of the operand class can hold the operand mode, resolve
3121 : the operand to memory. Mark it so that an operand matching
3122 : this one can also fall back to memory, otherwise the matched
3123 : operand would try to reload into an impossible hard reg and
3124 : LRA would cycle (e.g. TDmode "+g" asm on 32-bit x86).
3125 : An operand which is already memory and won implies the
3126 : constraint accepts memory too, even if nothing set
3127 : OFFMEMOK for it. */
3128 287794262 : if ((offmemok || MEM_P (op)) && this_alternative != NO_REGS
3129 367079466 : && hard_reg_set_subset_p (reg_class_contents[this_alternative],
3130 : ira_prohibited_class_mode_regs
3131 79285204 : [this_alternative][mode]
3132 367079285 : | lra_no_alloc_regs))
3133 : {
3134 181 : this_alternative = NO_REGS;
3135 181 : this_alternative_offmemok = true;
3136 : }
3137 287794262 : if (class_change_p)
3138 : {
3139 266091 : curr_alt_class_change_p = true;
3140 266091 : if (lra_dump_file != NULL)
3141 8 : fprintf (lra_dump_file,
3142 : " %d Narrowing class: reject+=3\n",
3143 : nop);
3144 266091 : reject += 3;
3145 : }
3146 287794262 : if (operand_reg[nop] != NULL_RTX)
3147 : {
3148 200923523 : if (hard_regno[nop] >= 0)
3149 : {
3150 180435486 : if (in_hard_reg_set_p (this_costly_alternative_set,
3151 : mode, hard_regno[nop]))
3152 : {
3153 792726 : if (lra_dump_file != NULL)
3154 21 : fprintf (lra_dump_file,
3155 : " %d Costly set: reject++\n",
3156 : nop);
3157 792726 : reject++;
3158 : }
3159 : }
3160 : else
3161 : {
3162 : /* Prefer won reg to spilled pseudo under other
3163 : equal conditions for possible inheritance. */
3164 20488037 : if (! scratch_p)
3165 : {
3166 20483696 : if (lra_dump_file != NULL)
3167 52 : fprintf
3168 52 : (lra_dump_file,
3169 : " %d Non pseudo reload: reject++\n",
3170 : nop);
3171 20483696 : reject++;
3172 : }
3173 20488037 : if (in_class_p (operand_reg[nop],
3174 : this_costly_alternative, NULL, true))
3175 : {
3176 134195 : if (lra_dump_file != NULL)
3177 0 : fprintf
3178 0 : (lra_dump_file,
3179 : " %d Non pseudo costly reload:"
3180 : " reject++\n",
3181 : nop);
3182 134195 : reject++;
3183 : }
3184 : }
3185 : /* We simulate the behavior of old reload here.
3186 : Although scratches need hard registers and it
3187 : might result in spilling other pseudos, no reload
3188 : insns are generated for the scratches. So it
3189 : might cost something but probably less than old
3190 : reload pass believes. */
3191 200923523 : if (scratch_p)
3192 : {
3193 127014 : if (lra_dump_file != NULL)
3194 6 : fprintf (lra_dump_file,
3195 : " %d Scratch win: reject+=2\n",
3196 : nop);
3197 127014 : reject += 2;
3198 : }
3199 : }
3200 : }
3201 245813476 : else if (did_match)
3202 : this_alternative_match_win = true;
3203 : else
3204 : {
3205 230616355 : if (prefer_memory_p && offmemok)
3206 : {
3207 497 : winreg = false;
3208 497 : this_alternative = NO_REGS;
3209 : }
3210 :
3211 230616355 : int const_to_mem = 0;
3212 230616355 : bool no_regs_p;
3213 :
3214 230616355 : reject += op_reject;
3215 : /* Mark output reload of the stack pointer. */
3216 230616355 : if (op == stack_pointer_rtx
3217 56609 : && curr_static_id->operand[nop].type != OP_IN)
3218 230616355 : curr_alt_out_sp_reload_p = true;
3219 :
3220 : /* If this alternative asks for a specific reg class, see if there
3221 : is at least one allocatable register in that class. */
3222 230616355 : no_regs_p
3223 402122884 : = (this_alternative == NO_REGS
3224 230616355 : || (hard_reg_set_subset_p
3225 343013080 : (reg_class_contents[this_alternative],
3226 : lra_no_alloc_regs)));
3227 :
3228 : /* For asms, verify that the class for this alternative is possible
3229 : for the mode that is specified. */
3230 171506529 : if (!no_regs_p && INSN_CODE (curr_insn) < 0)
3231 : {
3232 : int i;
3233 72157 : for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
3234 72153 : if (targetm.hard_regno_mode_ok (i, mode)
3235 72153 : && in_hard_reg_set_p (reg_class_contents[this_alternative],
3236 : mode, i))
3237 : break;
3238 20539 : if (i == FIRST_PSEUDO_REGISTER)
3239 230616355 : winreg = false;
3240 : }
3241 :
3242 : /* If this operand accepts a register, and if the
3243 : register class has at least one allocatable register,
3244 : then this operand can be reloaded. */
3245 230616355 : if (winreg && !no_regs_p)
3246 : badop = false;
3247 :
3248 59109830 : if (badop)
3249 : {
3250 49480299 : if (lra_dump_file != NULL)
3251 607 : fprintf (lra_dump_file,
3252 : " Bad operand -- refuse\n");
3253 126259428 : goto fail;
3254 : }
3255 :
3256 181136056 : if (this_alternative != NO_REGS)
3257 : {
3258 171506528 : HARD_REG_SET available_regs
3259 171506528 : = (reg_class_contents[this_alternative]
3260 171506528 : & ~((ira_prohibited_class_mode_regs
3261 171506528 : [this_alternative][mode])
3262 171506528 : | lra_no_alloc_regs));
3263 343013056 : if (!hard_reg_set_empty_p (available_regs))
3264 : {
3265 171504584 : if (early_clobber_p
3266 171463663 : || curr_static_id->operand[nop].type != OP_OUT)
3267 : {
3268 89917747 : all_reload_nregs
3269 89917747 : += ira_reg_class_min_nregs[this_alternative][mode];
3270 89917747 : all_this_alternative
3271 89917747 : = (reg_class_subunion
3272 89917747 : [all_this_alternative][this_alternative]);
3273 : }
3274 : }
3275 : else
3276 : {
3277 : /* There are no hard regs holding a value of given
3278 : mode. */
3279 1944 : if (offmemok)
3280 : {
3281 143 : this_alternative = NO_REGS;
3282 143 : if (lra_dump_file != NULL)
3283 0 : fprintf (lra_dump_file,
3284 : " %d Using memory because of"
3285 : " a bad mode: reject+=2\n",
3286 : nop);
3287 143 : reject += 2;
3288 : }
3289 1801 : else if (!prefer_memory_p)
3290 : {
3291 : /* No hard reg of the operand class can hold the
3292 : operand mode, but the constraint may still permit
3293 : memory (e.g. 'g'). Prefer memory for the operands
3294 : before refusing. */
3295 461 : prefer_memory_p = true;
3296 461 : if (lra_dump_file != NULL)
3297 0 : fprintf (lra_dump_file,
3298 : " Trying now memory for"
3299 : " operands\n");
3300 461 : goto repeat;
3301 : }
3302 : else
3303 : {
3304 1340 : if (lra_dump_file != NULL)
3305 0 : fprintf (lra_dump_file,
3306 : " Wrong mode -- refuse\n");
3307 1340 : goto fail;
3308 : }
3309 : }
3310 : }
3311 :
3312 : /* If not assigned pseudo has a class which a subset of
3313 : required reg class, it is a less costly alternative
3314 : as the pseudo still can get a hard reg of necessary
3315 : class. */
3316 171504727 : if (! no_regs_p && REG_P (op) && hard_regno[nop] < 0
3317 22010618 : && (cl = get_reg_class (REGNO (op))) != NO_REGS
3318 184126116 : && ira_class_subset_p[this_alternative][cl])
3319 : {
3320 26278 : if (lra_dump_file != NULL)
3321 0 : fprintf
3322 0 : (lra_dump_file,
3323 : " %d Super set class reg: reject-=3\n", nop);
3324 26278 : reject -= 3;
3325 : }
3326 :
3327 181134255 : this_alternative_offmemok = offmemok;
3328 181134255 : if (this_costly_alternative != NO_REGS)
3329 : {
3330 19655885 : if (lra_dump_file != NULL)
3331 25 : fprintf (lra_dump_file,
3332 : " %d Costly loser: reject++\n", nop);
3333 19655885 : reject++;
3334 : }
3335 : /* If the operand is dying, has a matching constraint,
3336 : and satisfies constraints of the matched operand
3337 : which failed to satisfy the own constraints, most probably
3338 : the reload for this operand will be gone. */
3339 181134255 : if (this_alternative_matches >= 0
3340 42885220 : && !curr_alt_win[this_alternative_matches]
3341 983515 : && REG_P (op)
3342 726349 : && find_regno_note (curr_insn, REG_DEAD, REGNO (op))
3343 181877591 : && (hard_regno[nop] >= 0
3344 385126 : ? in_hard_reg_set_p (this_alternative_set,
3345 : mode, hard_regno[nop])
3346 26916 : : in_class_p (op, this_alternative, NULL)))
3347 : {
3348 240647 : if (lra_dump_file != NULL)
3349 1 : fprintf
3350 1 : (lra_dump_file,
3351 : " %d Dying matched operand reload: reject++\n",
3352 : nop);
3353 240647 : reject++;
3354 : }
3355 : else
3356 : {
3357 : /* Strict_low_part requires to reload the register
3358 : not the sub-register. In this case we should
3359 : check that a final reload hard reg can hold the
3360 : value mode. */
3361 180893608 : if (curr_static_id->operand[nop].strict_low
3362 103 : && REG_P (op)
3363 96 : && hard_regno[nop] < 0
3364 72 : && GET_CODE (*curr_id->operand_loc[nop]) == SUBREG
3365 72 : && ira_class_hard_regs_num[this_alternative] > 0
3366 180893680 : && (!targetm.hard_regno_mode_ok
3367 72 : (ira_class_hard_regs[this_alternative][0],
3368 72 : GET_MODE (*curr_id->operand_loc[nop]))))
3369 : {
3370 0 : if (lra_dump_file != NULL)
3371 0 : fprintf
3372 0 : (lra_dump_file,
3373 : " Strict low subreg reload -- refuse\n");
3374 0 : goto fail;
3375 : }
3376 180893608 : if (lra_dump_file != NULL)
3377 2162 : fprintf
3378 2162 : (lra_dump_file,
3379 : " %d Operand reload: losers++\n", nop);
3380 180893608 : losers++;
3381 : }
3382 181134255 : if (operand_reg[nop] != NULL_RTX
3383 : /* Output operands and matched input operands are
3384 : not inherited. The following conditions do not
3385 : exactly describe the previous statement but they
3386 : are pretty close. */
3387 65357340 : && curr_static_id->operand[nop].type != OP_OUT
3388 28956553 : && (this_alternative_matches < 0
3389 17033474 : || curr_static_id->operand[nop].type != OP_IN))
3390 : {
3391 11923079 : int last_reload = (lra_reg_info[ORIGINAL_REGNO
3392 11923079 : (operand_reg[nop])]
3393 11923079 : .last_reload);
3394 :
3395 : /* The value of reload_sum has sense only if we
3396 : process insns in their order. It happens only on
3397 : the first constraints sub-pass when we do most of
3398 : reload work. */
3399 11923079 : if (lra_constraint_iter == 1 && last_reload > bb_reload_num)
3400 2580546 : reload_sum += last_reload - bb_reload_num;
3401 : }
3402 : /* If this is a constant that is reloaded into the
3403 : desired class by copying it to memory first, count
3404 : that as another reload. This is consistent with
3405 : other code and is required to avoid choosing another
3406 : alternative when the constant is moved into memory.
3407 : Note that the test here is precisely the same as in
3408 : the code below that calls force_const_mem. */
3409 232625480 : if (CONST_POOL_OK_P (mode, op)
3410 232625537 : && ((targetm.preferred_reload_class
3411 51491282 : (op, this_alternative) == NO_REGS)
3412 49891928 : || no_input_reloads_p))
3413 : {
3414 1599354 : const_to_mem = 1;
3415 1599354 : if (! no_regs_p)
3416 : {
3417 735777 : if (lra_dump_file != NULL)
3418 0 : fprintf
3419 0 : (lra_dump_file,
3420 : " %d Constant reload through memory: "
3421 : "losers++\n", nop);
3422 735777 : losers++;
3423 : }
3424 : }
3425 :
3426 : /* Alternative loses if it requires a type of reload not
3427 : permitted for this insn. We can always reload
3428 : objects with a REG_UNUSED note. */
3429 181134255 : if ((curr_static_id->operand[nop].type != OP_IN
3430 87929576 : && no_output_reloads_p
3431 0 : && ! find_reg_note (curr_insn, REG_UNUSED, op)
3432 0 : && ! scratch_p)
3433 181134255 : || (curr_static_id->operand[nop].type != OP_OUT
3434 93204887 : && no_input_reloads_p && ! const_to_mem)
3435 362268510 : || (this_alternative_matches >= 0
3436 42885220 : && (no_input_reloads_p
3437 42885220 : || (no_output_reloads_p
3438 0 : && (curr_static_id->operand
3439 0 : [this_alternative_matches].type != OP_IN)
3440 0 : && ! find_reg_note (curr_insn, REG_UNUSED,
3441 : no_subreg_reg_operand
3442 0 : [this_alternative_matches])
3443 0 : && ! scratch_p))))
3444 : {
3445 0 : if (lra_dump_file != NULL)
3446 0 : fprintf
3447 0 : (lra_dump_file,
3448 : " No input/output reload -- refuse\n");
3449 0 : goto fail;
3450 : }
3451 :
3452 : /* Alternative loses if it required class pseudo cannot
3453 : hold value of required mode. Such insns can be
3454 : described by insn definitions with mode iterators. */
3455 181134255 : if (GET_MODE (*curr_id->operand_loc[nop]) != VOIDmode
3456 131163442 : && ! hard_reg_set_empty_p (this_alternative_set)
3457 : /* It is common practice for constraints to use a
3458 : class which does not have actually enough regs to
3459 : hold the value (e.g. x86 AREG for mode requiring
3460 : more one general reg). Therefore we have 2
3461 : conditions to check that the reload pseudo cannot
3462 : hold the mode value. */
3463 122294381 : && (!targetm.hard_regno_mode_ok
3464 122294381 : (ira_class_hard_regs[this_alternative][0],
3465 : GET_MODE (*curr_id->operand_loc[nop])))
3466 : /* The above condition is not enough as the first
3467 : reg in ira_class_hard_regs can be not aligned for
3468 : multi-words mode values. */
3469 181134255 : && (prohibited_class_reg_set_mode_p
3470 0 : (this_alternative, this_alternative_set,
3471 0 : GET_MODE (*curr_id->operand_loc[nop]))))
3472 : {
3473 0 : if (lra_dump_file != NULL)
3474 0 : fprintf (lra_dump_file,
3475 : " reload pseudo for op %d "
3476 : "cannot hold the mode value -- refuse\n",
3477 : nop);
3478 0 : goto fail;
3479 : }
3480 :
3481 : /* Check strong discouragement of reload of non-constant
3482 : into class THIS_ALTERNATIVE. */
3483 129642970 : if (! CONSTANT_P (op) && ! no_regs_p
3484 302011274 : && (targetm.preferred_reload_class
3485 120877019 : (op, this_alternative) == NO_REGS
3486 112140337 : || (curr_static_id->operand[nop].type == OP_OUT
3487 77091711 : && (targetm.preferred_output_reload_class
3488 77091711 : (op, this_alternative) == NO_REGS))))
3489 : {
3490 13380208 : if (offmemok && REG_P (op))
3491 : {
3492 812400 : if (lra_dump_file != NULL)
3493 0 : fprintf
3494 0 : (lra_dump_file,
3495 : " %d Spill pseudo into memory: reject+=3\n",
3496 : nop);
3497 812400 : reject += 3;
3498 : }
3499 : else
3500 : {
3501 12567808 : if (lra_dump_file != NULL)
3502 0 : fprintf
3503 0 : (lra_dump_file,
3504 : " %d Non-preferred reload: reject+=%d\n",
3505 : nop, LRA_MAX_REJECT);
3506 12567808 : reject += LRA_MAX_REJECT;
3507 : }
3508 : }
3509 :
3510 181134255 : if (! (MEM_P (op) && offmemok)
3511 181133373 : && ! (const_to_mem && constmemok))
3512 : {
3513 : /* We prefer to reload pseudos over reloading other
3514 : things, since such reloads may be able to be
3515 : eliminated later. So bump REJECT in other cases.
3516 : Don't do this in the case where we are forcing a
3517 : constant into memory and it will then win since
3518 : we don't want to have a different alternative
3519 : match then. */
3520 180148550 : if (! (REG_P (op) && REGNO (op) >= FIRST_PSEUDO_REGISTER))
3521 : {
3522 128880655 : if (lra_dump_file != NULL)
3523 1649 : fprintf
3524 1649 : (lra_dump_file,
3525 : " %d Non-pseudo reload: reject+=2\n",
3526 : nop);
3527 128880655 : reject += 2;
3528 : }
3529 :
3530 180148550 : if (! no_regs_p)
3531 171382825 : reload_nregs
3532 171382825 : += ira_reg_class_max_nregs[this_alternative][mode];
3533 :
3534 180148550 : if (SMALL_REGISTER_CLASS_P (this_alternative))
3535 : {
3536 951741 : if (lra_dump_file != NULL)
3537 45 : fprintf
3538 45 : (lra_dump_file,
3539 : " %d Small class reload: reject+=%d\n",
3540 : nop, LRA_LOSER_COST_FACTOR / 2);
3541 951741 : reject += LRA_LOSER_COST_FACTOR / 2;
3542 : }
3543 : }
3544 :
3545 : /* We are trying to spill pseudo into memory. It is
3546 : usually more costly than moving to a hard register
3547 : although it might takes the same number of
3548 : reloads.
3549 :
3550 : Non-pseudo spill may happen also. Suppose a target allows both
3551 : register and memory in the operand constraint alternatives,
3552 : then it's typical that an eliminable register has a substition
3553 : of "base + offset" which can either be reloaded by a simple
3554 : "new_reg <= base + offset" which will match the register
3555 : constraint, or a similar reg addition followed by further spill
3556 : to and reload from memory which will match the memory
3557 : constraint, but this memory spill will be much more costly
3558 : usually.
3559 :
3560 : Code below increases the reject for both pseudo and non-pseudo
3561 : spill. */
3562 181134255 : if (no_regs_p
3563 9629528 : && !(MEM_P (op) && offmemok)
3564 9629169 : && !(REG_P (op) && hard_regno[nop] < 0))
3565 : {
3566 8554595 : if (lra_dump_file != NULL)
3567 13 : fprintf
3568 20 : (lra_dump_file,
3569 : " %d Spill %spseudo into memory: reject+=3\n",
3570 : nop, REG_P (op) ? "" : "Non-");
3571 8554595 : reject += 3;
3572 8554595 : if (VECTOR_MODE_P (mode))
3573 : {
3574 : /* Spilling vectors into memory is usually more
3575 : costly as they contain big values. */
3576 390093 : if (lra_dump_file != NULL)
3577 0 : fprintf
3578 0 : (lra_dump_file,
3579 : " %d Spill vector pseudo: reject+=2\n",
3580 : nop);
3581 390093 : reject += 2;
3582 : }
3583 : }
3584 :
3585 : /* When we use an operand requiring memory in given
3586 : alternative, the insn should write *and* read the
3587 : value to/from memory it is costly in comparison with
3588 : an insn alternative which does not use memory
3589 : (e.g. register or immediate operand). We exclude
3590 : memory operand for such case as we can satisfy the
3591 : memory constraints by reloading address. */
3592 9629528 : if (no_regs_p && offmemok && !MEM_P (op))
3593 : {
3594 9629169 : if (lra_dump_file != NULL)
3595 26 : fprintf
3596 26 : (lra_dump_file,
3597 : " Using memory insn operand %d: reject+=3\n",
3598 : nop);
3599 9629169 : reject += 3;
3600 : }
3601 :
3602 : /* If reload requires moving value through secondary
3603 : memory, it will need one more insn at least. */
3604 181134255 : if (this_alternative != NO_REGS
3605 171504584 : && REG_P (op) && (cl = get_reg_class (REGNO (op))) != NO_REGS
3606 218713430 : && ((curr_static_id->operand[nop].type != OP_OUT
3607 21348034 : && targetm.secondary_memory_needed (mode, cl,
3608 : this_alternative))
3609 34398373 : || (curr_static_id->operand[nop].type != OP_IN
3610 16231257 : && (targetm.secondary_memory_needed
3611 16231257 : (mode, this_alternative, cl)))))
3612 : {
3613 10992031 : if (lra_dump_file != NULL)
3614 16 : fprintf
3615 16 : (lra_dump_file,
3616 : " %d Secondary memory reload needed: "
3617 : "losers++\n", nop);
3618 10992031 : losers++;
3619 : }
3620 :
3621 181134255 : if (MEM_P (op) && offmemok)
3622 882 : addr_losers++;
3623 : else
3624 : {
3625 : /* Input reloads can be inherited more often than
3626 : output reloads can be removed, so penalize output
3627 : reloads. */
3628 181133373 : if (!REG_P (op) || curr_static_id->operand[nop].type != OP_IN)
3629 : {
3630 152177021 : if (lra_dump_file != NULL)
3631 1709 : fprintf
3632 1709 : (lra_dump_file,
3633 : " %d Non input pseudo reload: reject++\n",
3634 : nop);
3635 152177021 : reject++;
3636 : }
3637 :
3638 181133373 : if (curr_static_id->operand[nop].type == OP_INOUT)
3639 : {
3640 208 : if (lra_dump_file != NULL)
3641 0 : fprintf
3642 0 : (lra_dump_file,
3643 : " %d Input/Output reload: reject+=%d\n",
3644 : nop, LRA_LOSER_COST_FACTOR);
3645 208 : reject += LRA_LOSER_COST_FACTOR;
3646 : }
3647 : }
3648 : }
3649 :
3650 484125638 : if (early_clobber_p && ! scratch_p)
3651 : {
3652 187721 : if (lra_dump_file != NULL)
3653 4 : fprintf (lra_dump_file,
3654 : " %d Early clobber: reject++\n", nop);
3655 187721 : reject++;
3656 : }
3657 : /* ??? We check early clobbers after processing all operands
3658 : (see loop below) and there we update the costs more.
3659 : Should we update the cost (may be approximately) here
3660 : because of early clobber register reloads or it is a rare
3661 : or non-important thing to be worth to do it. */
3662 968251276 : overall = (losers * LRA_LOSER_COST_FACTOR + reject
3663 484125638 : - (addr_losers == losers ? static_reject : 0));
3664 484125638 : if ((best_losers == 0 || losers != 0) && best_overall < overall)
3665 : {
3666 76777789 : if (lra_dump_file != NULL)
3667 1029 : fprintf (lra_dump_file,
3668 : " overall=%d,losers=%d -- refuse\n",
3669 : overall, losers);
3670 76777789 : goto fail;
3671 : }
3672 :
3673 407347849 : if (update_and_check_small_class_inputs (nop, nalt,
3674 : this_alternative))
3675 : {
3676 0 : if (lra_dump_file != NULL)
3677 0 : fprintf (lra_dump_file,
3678 : " not enough small class regs -- refuse\n");
3679 0 : goto fail;
3680 : }
3681 407347849 : curr_alt[nop] = this_alternative;
3682 407347849 : curr_alt_set[nop] = this_alternative_set;
3683 407347849 : curr_alt_exclude_start_hard_regs[nop]
3684 407347849 : = this_alternative_exclude_start_hard_regs;
3685 407347849 : curr_alt_win[nop] = this_alternative_win;
3686 407347849 : curr_alt_match_win[nop] = this_alternative_match_win;
3687 407347849 : curr_alt_offmemok[nop] = this_alternative_offmemok;
3688 407347849 : curr_alt_matches[nop] = this_alternative_matches;
3689 :
3690 407347849 : if (this_alternative_matches >= 0
3691 407347849 : && !did_match && !this_alternative_win)
3692 13914247 : curr_alt_win[this_alternative_matches] = false;
3693 :
3694 407347849 : if (early_clobber_p && operand_reg[nop] != NULL_RTX)
3695 191339 : early_clobbered_nops[early_clobbered_regs_num++] = nop;
3696 : }
3697 :
3698 139480057 : if (curr_insn_set != NULL_RTX
3699 : /* Allow just two operands or three operands where the third
3700 : is a clobber. */
3701 135465326 : && (n_operands == 2
3702 29910685 : || (n_operands == 3
3703 27617896 : && GET_CODE (PATTERN (curr_insn)) == PARALLEL
3704 23442830 : && XVECLEN (PATTERN (curr_insn), 0) == 2
3705 23387644 : && GET_CODE (XVECEXP (PATTERN (curr_insn), 0, 1))
3706 : == CLOBBER))
3707 : /* Prevent processing non-move insns. */
3708 128855129 : && (GET_CODE (SET_SRC (curr_insn_set)) == SUBREG
3709 126927237 : || SET_SRC (curr_insn_set) == no_subreg_reg_operand[1])
3710 233815573 : && ((! curr_alt_win[0] && ! curr_alt_win[1]
3711 6156400 : && REG_P (no_subreg_reg_operand[0])
3712 3000595 : && REG_P (no_subreg_reg_operand[1])
3713 1255200 : && (reg_in_class_p (no_subreg_reg_operand[0], curr_alt[1])
3714 1035424 : || reg_in_class_p (no_subreg_reg_operand[1], curr_alt[0])))
3715 93784674 : || (! curr_alt_win[0] && curr_alt_win[1]
3716 27899313 : && REG_P (no_subreg_reg_operand[1])
3717 : /* Check that we reload memory not the memory
3718 : address. */
3719 15958562 : && ! (curr_alt_offmemok[0]
3720 397333 : && MEM_P (no_subreg_reg_operand[0]))
3721 15958562 : && reg_in_class_p (no_subreg_reg_operand[1], curr_alt[0]))
3722 79252223 : || (curr_alt_win[0] && ! curr_alt_win[1]
3723 10108343 : && REG_P (no_subreg_reg_operand[0])
3724 : /* Check that we reload memory not the memory
3725 : address. */
3726 7577087 : && ! (curr_alt_offmemok[1]
3727 1405778 : && MEM_P (no_subreg_reg_operand[1]))
3728 7577085 : && reg_in_class_p (no_subreg_reg_operand[0], curr_alt[1])
3729 6679039 : && (! CONST_POOL_OK_P (curr_operand_mode[1],
3730 : no_subreg_reg_operand[1])
3731 2662414 : || (targetm.preferred_reload_class
3732 2662414 : (no_subreg_reg_operand[1],
3733 : (enum reg_class) curr_alt[1]) != NO_REGS))
3734 : /* If it is a result of recent elimination in move
3735 : insn we can transform it into an add still by
3736 : using this alternative. */
3737 6634957 : && GET_CODE (no_subreg_reg_operand[1]) != PLUS
3738 : /* Likewise if the source has been replaced with an
3739 : equivalent value. This only happens once -- the reload
3740 : will use the equivalent value instead of the register it
3741 : replaces -- so there should be no danger of cycling. */
3742 6099406 : && !equiv_substition_p[1])))
3743 : {
3744 : /* We have a move insn and a new reload insn will be similar
3745 : to the current insn. We should avoid such situation as
3746 : it results in LRA cycling. */
3747 21132212 : if (lra_dump_file != NULL)
3748 233 : fprintf (lra_dump_file,
3749 : " Cycle danger: overall += LRA_MAX_REJECT\n");
3750 21132212 : overall += LRA_MAX_REJECT;
3751 : }
3752 139480057 : if (all_this_alternative != NO_REGS
3753 119457011 : && !SMALL_REGISTER_CLASS_P (all_this_alternative)
3754 118599460 : && all_used_nregs != 0 && all_reload_nregs != 0
3755 139480057 : && (all_used_nregs + all_reload_nregs + 1
3756 4287916 : >= ira_class_hard_regs_num[all_this_alternative]))
3757 : {
3758 383 : if (lra_dump_file != NULL)
3759 0 : fprintf
3760 0 : (lra_dump_file,
3761 : " Register starvation: overall += LRA_MAX_REJECT"
3762 : "(class=%s,avail=%d,used=%d,reload=%d)\n",
3763 : reg_class_names[all_this_alternative],
3764 : ira_class_hard_regs_num[all_this_alternative],
3765 : all_used_nregs, all_reload_nregs);
3766 383 : overall += LRA_MAX_REJECT;
3767 383 : if (!prefer_memory_p && INSN_CODE (curr_insn) < 0)
3768 : {
3769 : /* asm can permit memory and reg and can be not enough regs for
3770 : asm -- try now memory: */
3771 110 : prefer_memory_p = true;
3772 110 : if (lra_dump_file != NULL)
3773 0 : fprintf
3774 0 : (lra_dump_file,
3775 : " Trying now memory for operands\n");
3776 110 : goto repeat;
3777 : }
3778 : }
3779 139479947 : ok_p = true;
3780 139479947 : curr_alt_dont_inherit_ops_num = 0;
3781 139666747 : for (nop = 0; nop < early_clobbered_regs_num; nop++)
3782 : {
3783 186801 : int i, j, clobbered_hard_regno, first_conflict_j, last_conflict_j;
3784 186801 : HARD_REG_SET temp_set;
3785 :
3786 186801 : i = early_clobbered_nops[nop];
3787 186801 : if ((! curr_alt_win[i] && ! curr_alt_match_win[i])
3788 139196 : || hard_regno[i] < 0)
3789 186132 : continue;
3790 137632 : lra_assert (operand_reg[i] != NULL_RTX);
3791 : clobbered_hard_regno = hard_regno[i];
3792 137632 : CLEAR_HARD_REG_SET (temp_set);
3793 137632 : add_to_hard_reg_set (&temp_set, GET_MODE (*curr_id->operand_loc[i]),
3794 : clobbered_hard_regno);
3795 137632 : first_conflict_j = last_conflict_j = -1;
3796 830339 : for (j = 0; j < n_operands; j++)
3797 555076 : if (j == i
3798 : /* We don't want process insides of match_operator and
3799 : match_parallel because otherwise we would process
3800 : their operands once again generating a wrong
3801 : code. */
3802 417444 : || curr_static_id->operand[j].is_operator)
3803 139714 : continue;
3804 415362 : else if ((curr_alt_matches[j] == i && curr_alt_match_win[j])
3805 395037 : || (curr_alt_matches[i] == j && curr_alt_match_win[i]))
3806 20325 : continue;
3807 : /* If we don't reload j-th operand, check conflicts. */
3808 152840 : else if ((curr_alt_win[j] || curr_alt_match_win[j])
3809 452951 : && uses_hard_regs_p (*curr_id->operand_loc[j], temp_set))
3810 : {
3811 1071 : if (first_conflict_j < 0)
3812 669 : first_conflict_j = j;
3813 1071 : last_conflict_j = j;
3814 : /* Both the earlyclobber operand and conflicting operand
3815 : cannot both be user defined hard registers for asm.
3816 : Let curr_insn_transform diagnose it. */
3817 1071 : if (HARD_REGISTER_P (operand_reg[i])
3818 1 : && REG_USERVAR_P (operand_reg[i])
3819 1 : && operand_reg[j] != NULL_RTX
3820 1 : && HARD_REGISTER_P (operand_reg[j])
3821 1 : && REG_USERVAR_P (operand_reg[j])
3822 1072 : && INSN_CODE (curr_insn) < 0)
3823 1 : return false;
3824 : }
3825 137631 : if (last_conflict_j < 0)
3826 136963 : continue;
3827 :
3828 : /* If an earlyclobber operand conflicts with another non-matching
3829 : operand (ie, they have been assigned the same hard register),
3830 : then it is better to reload the other operand, as there may
3831 : exist yet another operand with a matching constraint associated
3832 : with the earlyclobber operand. However, if one of the operands
3833 : is an explicit use of a hard register, then we must reload the
3834 : other non-hard register operand. */
3835 668 : if (HARD_REGISTER_P (operand_reg[i])
3836 668 : || (first_conflict_j == last_conflict_j
3837 266 : && operand_reg[last_conflict_j] != NULL_RTX
3838 62 : && !curr_alt_match_win[last_conflict_j]
3839 62 : && !HARD_REGISTER_P (operand_reg[last_conflict_j])))
3840 : {
3841 62 : curr_alt_win[last_conflict_j] = false;
3842 62 : curr_alt_dont_inherit_ops[curr_alt_dont_inherit_ops_num++]
3843 62 : = last_conflict_j;
3844 62 : losers++;
3845 62 : if (lra_dump_file != NULL)
3846 0 : fprintf
3847 0 : (lra_dump_file,
3848 : " %d Conflict early clobber reload: losers++\n",
3849 : i);
3850 : }
3851 : else
3852 : {
3853 : /* We need to reload early clobbered register and the
3854 : matched registers. */
3855 3024 : for (j = 0; j < n_operands; j++)
3856 2418 : if (curr_alt_matches[j] == i)
3857 : {
3858 2 : curr_alt_match_win[j] = false;
3859 2 : losers++;
3860 2 : if (lra_dump_file != NULL)
3861 0 : fprintf
3862 0 : (lra_dump_file,
3863 : " %d Matching conflict early clobber "
3864 : "reloads: losers++\n",
3865 : j);
3866 2 : overall += LRA_LOSER_COST_FACTOR;
3867 : }
3868 606 : if (! curr_alt_match_win[i])
3869 606 : curr_alt_dont_inherit_ops[curr_alt_dont_inherit_ops_num++] = i;
3870 : else
3871 : {
3872 : /* Remember pseudos used for match reloads are never
3873 : inherited. */
3874 0 : lra_assert (curr_alt_matches[i] >= 0);
3875 0 : curr_alt_win[curr_alt_matches[i]] = false;
3876 : }
3877 606 : curr_alt_win[i] = curr_alt_match_win[i] = false;
3878 606 : losers++;
3879 606 : if (lra_dump_file != NULL)
3880 0 : fprintf
3881 0 : (lra_dump_file,
3882 : " %d Matched conflict early clobber reloads: "
3883 : "losers++\n",
3884 : i);
3885 : }
3886 : /* Early clobber was already reflected in REJECT. */
3887 668 : if (!matching_early_clobber[i])
3888 : {
3889 668 : lra_assert (reject > 0);
3890 668 : reject--;
3891 668 : matching_early_clobber[i] = 1;
3892 : }
3893 668 : overall += LRA_LOSER_COST_FACTOR - 1;
3894 : }
3895 139479946 : if (lra_dump_file != NULL)
3896 1752 : fprintf (lra_dump_file, " overall=%d,losers=%d,rld_nregs=%d\n",
3897 : overall, losers, reload_nregs);
3898 :
3899 : /* If this alternative can be made to work by reloading, and it
3900 : needs less reloading than the others checked so far, record
3901 : it as the chosen goal for reloading. */
3902 139479946 : if ((best_losers != 0 && losers == 0)
3903 61960769 : || (((best_losers == 0 && losers == 0)
3904 60840884 : || (best_losers != 0 && losers != 0))
3905 61960769 : && (best_overall > overall
3906 15929285 : || (best_overall == overall
3907 : /* If the cost of the reloads is the same,
3908 : prefer alternative which requires minimal
3909 : number of reload regs. */
3910 11937139 : && (reload_nregs < best_reload_nregs
3911 11835551 : || (reload_nregs == best_reload_nregs
3912 11792106 : && (best_reload_sum < reload_sum
3913 11768286 : || (best_reload_sum == reload_sum
3914 11744629 : && nalt < goal_alt_number))))))))
3915 : {
3916 402759300 : for (nop = 0; nop < n_operands; nop++)
3917 : {
3918 278794042 : goal_alt_win[nop] = curr_alt_win[nop];
3919 278794042 : goal_alt_match_win[nop] = curr_alt_match_win[nop];
3920 278794042 : goal_alt_matches[nop] = curr_alt_matches[nop];
3921 278794042 : goal_alt[nop] = curr_alt[nop];
3922 278794042 : goal_alt_exclude_start_hard_regs[nop]
3923 278794042 : = curr_alt_exclude_start_hard_regs[nop];
3924 278794042 : goal_alt_offmemok[nop] = curr_alt_offmemok[nop];
3925 : }
3926 123965258 : goal_alt_dont_inherit_ops_num = curr_alt_dont_inherit_ops_num;
3927 123965258 : goal_reuse_alt_p = curr_reuse_alt_p;
3928 123965916 : for (nop = 0; nop < curr_alt_dont_inherit_ops_num; nop++)
3929 658 : goal_alt_dont_inherit_ops[nop] = curr_alt_dont_inherit_ops[nop];
3930 123965258 : goal_alt_swapped = curr_swapped;
3931 123965258 : goal_alt_out_sp_reload_p = curr_alt_out_sp_reload_p;
3932 123965258 : best_overall = overall;
3933 123965258 : best_losers = losers;
3934 123965258 : best_reload_nregs = reload_nregs;
3935 123965258 : best_reload_sum = reload_sum;
3936 123965258 : goal_alt_number = nalt;
3937 : }
3938 139479946 : if (losers == 0 && !curr_alt_class_change_p)
3939 : /* Everything is satisfied. Do not process alternatives
3940 : anymore. */
3941 : break;
3942 60853747 : fail:
3943 187113175 : ;
3944 : }
3945 : return ok_p;
3946 : }
3947 :
3948 : /* Make reload base reg from address AD. */
3949 : static rtx
3950 0 : base_to_reg (struct address_info *ad)
3951 : {
3952 0 : enum reg_class cl;
3953 0 : int code = -1;
3954 0 : rtx new_inner = NULL_RTX;
3955 0 : rtx new_reg = NULL_RTX;
3956 0 : rtx_insn *insn;
3957 0 : rtx_insn *last_insn = get_last_insn();
3958 :
3959 0 : lra_assert (ad->disp == ad->disp_term);
3960 0 : cl = base_reg_class (ad->mode, ad->as, ad->base_outer_code,
3961 : get_index_code (ad), ad->mem, curr_insn);
3962 0 : new_reg = lra_create_new_reg (GET_MODE (*ad->base), NULL_RTX, cl, NULL,
3963 : "base");
3964 0 : new_inner = simplify_gen_binary (PLUS, GET_MODE (new_reg), new_reg,
3965 0 : ad->disp_term == NULL
3966 : ? const0_rtx
3967 : : *ad->disp_term);
3968 0 : if (!valid_address_p (ad->mode, new_inner, ad->as))
3969 : return NULL_RTX;
3970 0 : insn = emit_insn (gen_rtx_SET (new_reg, *ad->base));
3971 0 : code = recog_memoized (insn);
3972 0 : if (code < 0)
3973 : {
3974 0 : delete_insns_since (last_insn);
3975 0 : return NULL_RTX;
3976 : }
3977 :
3978 : return new_inner;
3979 : }
3980 :
3981 : /* Make reload base reg + DISP from address AD. Return the new pseudo. */
3982 : static rtx
3983 47 : base_plus_disp_to_reg (struct address_info *ad, rtx disp)
3984 : {
3985 47 : enum reg_class cl;
3986 47 : rtx new_reg;
3987 :
3988 47 : lra_assert (ad->base == ad->base_term);
3989 47 : cl = base_reg_class (ad->mode, ad->as, ad->base_outer_code,
3990 : get_index_code (ad), ad->mem, curr_insn);
3991 47 : new_reg = lra_create_new_reg (GET_MODE (*ad->base_term), NULL_RTX, cl, NULL,
3992 : "base + disp");
3993 47 : lra_emit_add (new_reg, *ad->base_term, disp);
3994 47 : return new_reg;
3995 : }
3996 :
3997 : /* Make reload of index part of address AD. Return the new
3998 : pseudo. */
3999 : static rtx
4000 0 : index_part_to_reg (struct address_info *ad, enum reg_class index_class)
4001 : {
4002 0 : rtx new_reg;
4003 :
4004 0 : new_reg = lra_create_new_reg (GET_MODE (*ad->index), NULL_RTX,
4005 : index_class, NULL, "index term");
4006 0 : expand_mult (GET_MODE (*ad->index), *ad->index_term,
4007 : GEN_INT (get_index_scale (ad)), new_reg, 1);
4008 0 : return new_reg;
4009 : }
4010 :
4011 : /* Return true if we can add a displacement to address AD, even if that
4012 : makes the address invalid. The fix-up code requires any new address
4013 : to be the sum of the BASE_TERM, INDEX and DISP_TERM fields. */
4014 : static bool
4015 20887 : can_add_disp_p (struct address_info *ad)
4016 : {
4017 20887 : return (!ad->autoinc_p
4018 20887 : && ad->segment == NULL
4019 20887 : && ad->base == ad->base_term
4020 41774 : && ad->disp == ad->disp_term);
4021 : }
4022 :
4023 : /* Make equiv substitution in address AD. Return true if a substitution
4024 : was made. */
4025 : static bool
4026 40514172 : equiv_address_substitution (struct address_info *ad)
4027 : {
4028 40514172 : rtx base_reg, new_base_reg, index_reg, new_index_reg, *base_term, *index_term;
4029 40514172 : poly_int64 disp;
4030 40514172 : HOST_WIDE_INT scale;
4031 40514172 : bool change_p;
4032 :
4033 40514172 : base_term = strip_subreg (ad->base_term);
4034 10101 : if (base_term == NULL)
4035 : base_reg = new_base_reg = NULL_RTX;
4036 : else
4037 : {
4038 34174793 : base_reg = *base_term;
4039 34174793 : new_base_reg = get_equiv_with_elimination (base_reg, curr_insn);
4040 : }
4041 40514172 : index_term = strip_subreg (ad->index_term);
4042 6307 : if (index_term == NULL)
4043 : index_reg = new_index_reg = NULL_RTX;
4044 : else
4045 : {
4046 1825582 : index_reg = *index_term;
4047 1825582 : new_index_reg = get_equiv_with_elimination (index_reg, curr_insn);
4048 : }
4049 40514172 : if (base_reg == new_base_reg && index_reg == new_index_reg)
4050 : return false;
4051 140556 : disp = 0;
4052 140556 : change_p = false;
4053 140556 : if (lra_dump_file != NULL)
4054 : {
4055 0 : fprintf (lra_dump_file, "Changing address in insn %d ",
4056 0 : INSN_UID (curr_insn));
4057 0 : dump_value_slim (lra_dump_file, *ad->outer, 1);
4058 : }
4059 140556 : if (base_reg != new_base_reg)
4060 : {
4061 140104 : poly_int64 offset;
4062 140104 : if (REG_P (new_base_reg))
4063 : {
4064 8177 : *base_term = new_base_reg;
4065 8177 : change_p = true;
4066 : }
4067 131927 : else if (GET_CODE (new_base_reg) == PLUS
4068 20886 : && REG_P (XEXP (new_base_reg, 0))
4069 20886 : && poly_int_rtx_p (XEXP (new_base_reg, 1), &offset)
4070 152813 : && can_add_disp_p (ad))
4071 : {
4072 : disp += offset;
4073 20886 : *base_term = XEXP (new_base_reg, 0);
4074 20886 : change_p = true;
4075 : }
4076 140104 : if (ad->base_term2 != NULL)
4077 0 : *ad->base_term2 = *ad->base_term;
4078 : }
4079 140556 : if (index_reg != new_index_reg)
4080 : {
4081 658 : poly_int64 offset;
4082 658 : if (REG_P (new_index_reg))
4083 : {
4084 0 : *index_term = new_index_reg;
4085 0 : change_p = true;
4086 : }
4087 658 : else if (GET_CODE (new_index_reg) == PLUS
4088 1 : && REG_P (XEXP (new_index_reg, 0))
4089 1 : && poly_int_rtx_p (XEXP (new_index_reg, 1), &offset)
4090 1 : && can_add_disp_p (ad)
4091 659 : && (scale = get_index_scale (ad)))
4092 : {
4093 1 : disp += offset * scale;
4094 1 : *index_term = XEXP (new_index_reg, 0);
4095 1 : change_p = true;
4096 : }
4097 : }
4098 140556 : if (maybe_ne (disp, 0))
4099 : {
4100 20887 : if (ad->disp != NULL)
4101 7169 : *ad->disp = plus_constant (GET_MODE (*ad->inner), *ad->disp, disp);
4102 : else
4103 : {
4104 13718 : *ad->inner = plus_constant (GET_MODE (*ad->inner), *ad->inner, disp);
4105 13718 : update_address (ad);
4106 : }
4107 : change_p = true;
4108 : }
4109 140556 : if (lra_dump_file != NULL)
4110 : {
4111 0 : if (! change_p)
4112 0 : fprintf (lra_dump_file, " -- no change\n");
4113 : else
4114 : {
4115 0 : fprintf (lra_dump_file, " on equiv ");
4116 0 : dump_value_slim (lra_dump_file, *ad->outer, 1);
4117 0 : fprintf (lra_dump_file, "\n");
4118 : }
4119 : }
4120 : return change_p;
4121 : }
4122 :
4123 : /* Skip all modifiers and whitespaces in constraint STR and return the
4124 : result. */
4125 : static const char *
4126 529852814 : skip_constraint_modifiers (const char *str)
4127 : {
4128 745697558 : for (;;str++)
4129 637775186 : switch (*str)
4130 : {
4131 107922372 : case '+': case '&' : case '=': case '*': case ' ': case '\t':
4132 107922372 : case '$': case '^' : case '%': case '?': case '!':
4133 107922372 : break;
4134 529852814 : default: return str;
4135 : }
4136 : }
4137 :
4138 : /* Takes a string of 0 or more comma-separated constraints. When more
4139 : than one constraint is present, evaluate whether they all correspond
4140 : to a single, repeated constraint (e.g. "r,r") or whether we have
4141 : more than one distinct constraints (e.g. "r,m"). */
4142 : static bool
4143 168007697 : constraint_unique (const char *cstr)
4144 : {
4145 168007697 : enum constraint_num ca, cb;
4146 168007697 : ca = CONSTRAINT__UNKNOWN;
4147 333492320 : for (;;)
4148 : {
4149 333492320 : cstr = skip_constraint_modifiers (cstr);
4150 333492320 : if (*cstr == '\0' || *cstr == ',')
4151 : cb = CONSTRAINT_X;
4152 : else
4153 : {
4154 333492320 : cb = lookup_constraint (cstr);
4155 333492320 : if (cb == CONSTRAINT__UNKNOWN)
4156 : return false;
4157 321019425 : cstr += CONSTRAINT_LEN (cstr[0], cstr);
4158 : }
4159 : /* Handle the first iteration of the loop. */
4160 321019425 : if (ca == CONSTRAINT__UNKNOWN)
4161 : ca = cb;
4162 : /* Handle the general case of comparing ca with subsequent
4163 : constraints. */
4164 165306738 : else if (ca != cb)
4165 : return false;
4166 173296141 : if (*cstr == '\0')
4167 : return true;
4168 165484623 : if (*cstr == ',')
4169 91621331 : cstr += 1;
4170 : }
4171 : }
4172 :
4173 : /* Major function to make reloads for an address in operand NOP or
4174 : check its correctness (If CHECK_ONLY_P is true). The supported
4175 : cases are:
4176 :
4177 : 1) an address that existed before LRA started, at which point it
4178 : must have been valid. These addresses are subject to elimination
4179 : and may have become invalid due to the elimination offset being out
4180 : of range.
4181 :
4182 : 2) an address created by forcing a constant to memory
4183 : (force_const_to_mem). The initial form of these addresses might
4184 : not be valid, and it is this function's job to make them valid.
4185 :
4186 : 3) a frame address formed from a register and a (possibly zero)
4187 : constant offset. As above, these addresses might not be valid and
4188 : this function must make them so.
4189 :
4190 : Add reloads to the lists *BEFORE and *AFTER. We might need to add
4191 : reloads to *AFTER because of inc/dec, {pre, post} modify in the
4192 : address. Return true for any RTL change.
4193 :
4194 : The function is a helper function which does not produce all
4195 : transformations (when CHECK_ONLY_P is false) which can be
4196 : necessary. It does just basic steps. To do all necessary
4197 : transformations use function process_address. */
4198 : static bool
4199 182195477 : process_address_1 (int nop, bool check_only_p,
4200 : rtx_insn **before, rtx_insn **after)
4201 : {
4202 182195477 : struct address_info ad;
4203 182195477 : rtx new_reg;
4204 182195477 : HOST_WIDE_INT scale;
4205 182195477 : rtx op = *curr_id->operand_loc[nop];
4206 182195477 : rtx mem = extract_mem_from_operand (op);
4207 182195477 : const char *constraint;
4208 182195477 : enum constraint_num cn;
4209 182195477 : bool change_p = false;
4210 :
4211 182195477 : if (MEM_P (mem)
4212 38668490 : && GET_MODE (mem) == BLKmode
4213 24754 : && GET_CODE (XEXP (mem, 0)) == SCRATCH)
4214 : return false;
4215 :
4216 182195477 : constraint
4217 182195477 : = skip_constraint_modifiers (curr_static_id->operand[nop].constraint);
4218 182195477 : if (IN_RANGE (constraint[0], '0', '9'))
4219 : {
4220 14165017 : char *end;
4221 14165017 : unsigned long dup = strtoul (constraint, &end, 10);
4222 14165017 : constraint
4223 14165017 : = skip_constraint_modifiers (curr_static_id->operand[dup].constraint);
4224 : }
4225 194530152 : cn = lookup_constraint (*constraint == '\0' ? "X" : constraint);
4226 : /* If we have several alternatives or/and several constraints in an
4227 : alternative and we can not say at this stage what constraint will be used,
4228 : use unknown constraint. The exception is an address constraint. If
4229 : operand has one address constraint, probably all others constraints are
4230 : address ones. */
4231 169860802 : if (constraint[0] != '\0' && get_constraint_type (cn) != CT_ADDRESS
4232 350203174 : && !constraint_unique (constraint))
4233 : cn = CONSTRAINT__UNKNOWN;
4234 21999298 : if (insn_extra_address_constraint (cn)
4235 : /* When we find an asm operand with an address constraint that
4236 : doesn't satisfy address_operand to begin with, we clear
4237 : is_address, so that we don't try to make a non-address fit.
4238 : If the asm statement got this far, it's because other
4239 : constraints are available, and we'll use them, disregarding
4240 : the unsatisfiable address ones. */
4241 21999298 : && curr_static_id->operand[nop].is_address)
4242 1853086 : decompose_lea_address (&ad, curr_id->operand_loc[nop]);
4243 : /* Do not attempt to decompose arbitrary addresses generated by combine
4244 : for asm operands with loose constraints, e.g 'X'.
4245 : Need to extract memory from op for special memory constraint,
4246 : i.e. bcst_mem_operand in i386 backend. */
4247 180342391 : else if (MEM_P (mem)
4248 180342679 : && !(INSN_CODE (curr_insn) < 0
4249 20763 : && get_constraint_type (cn) == CT_FIXED_FORM
4250 288 : && constraint_satisfied_p (op, cn)))
4251 38668202 : decompose_mem_address (&ad, mem);
4252 141674189 : else if (GET_CODE (op) == SUBREG
4253 3830662 : && MEM_P (SUBREG_REG (op)))
4254 0 : decompose_mem_address (&ad, SUBREG_REG (op));
4255 : else
4256 : return false;
4257 : /* If INDEX_REG_CLASS is assigned to base_term already and isn't to
4258 : index_term, swap them so to avoid assigning INDEX_REG_CLASS to both
4259 : when INDEX_REG_CLASS is a single register class. */
4260 40521288 : enum reg_class index_cl = index_reg_class (curr_insn);
4261 40521288 : if (ad.base_term != NULL
4262 34181854 : && ad.index_term != NULL
4263 1454738 : && ira_class_hard_regs_num[index_cl] == 1
4264 0 : && REG_P (*ad.base_term)
4265 0 : && REG_P (*ad.index_term)
4266 0 : && in_class_p (*ad.base_term, index_cl, NULL)
4267 40521288 : && ! in_class_p (*ad.index_term, index_cl, NULL))
4268 : {
4269 0 : std::swap (ad.base, ad.index);
4270 0 : std::swap (ad.base_term, ad.index_term);
4271 : }
4272 40521288 : if (! check_only_p)
4273 40514172 : change_p = equiv_address_substitution (&ad);
4274 40521288 : if (ad.base_term != NULL
4275 74703142 : && (process_addr_reg
4276 68363708 : (ad.base_term, check_only_p, before,
4277 34181854 : (ad.autoinc_p
4278 4205428 : && !(REG_P (*ad.base_term)
4279 2102714 : && find_regno_note (curr_insn, REG_DEAD,
4280 : REGNO (*ad.base_term)) != NULL_RTX)
4281 : ? after : NULL),
4282 : base_reg_class (ad.mode, ad.as, ad.base_outer_code,
4283 : get_index_code (&ad), ad.mem, curr_insn))))
4284 : {
4285 437344 : change_p = true;
4286 437344 : if (ad.base_term2 != NULL)
4287 0 : *ad.base_term2 = *ad.base_term;
4288 : }
4289 40521288 : if (ad.index_term != NULL
4290 40521288 : && process_addr_reg (ad.index_term, check_only_p,
4291 : before, NULL, index_cl))
4292 : change_p = true;
4293 :
4294 : /* Target hooks sometimes don't treat extra-constraint addresses as
4295 : legitimate address_operands, so handle them specially. */
4296 40521288 : if (insn_extra_address_constraint (cn)
4297 40521288 : && satisfies_address_constraint_p (&ad, cn))
4298 : return change_p;
4299 :
4300 38668209 : if (check_only_p)
4301 : return change_p;
4302 :
4303 : /* There are three cases where the shape of *AD.INNER may now be invalid:
4304 :
4305 : 1) the original address was valid, but either elimination or
4306 : equiv_address_substitution was applied and that made
4307 : the address invalid.
4308 :
4309 : 2) the address is an invalid symbolic address created by
4310 : force_const_to_mem.
4311 :
4312 : 3) the address is a frame address with an invalid offset.
4313 :
4314 : 4) the address is a frame address with an invalid base.
4315 :
4316 : All these cases involve a non-autoinc address, so there is no
4317 : point revalidating other types. */
4318 38661740 : if (ad.autoinc_p || valid_address_p (op, &ad, cn))
4319 : return change_p;
4320 :
4321 : /* Any index existed before LRA started, so we can assume that the
4322 : presence and shape of the index is valid. */
4323 444 : push_to_sequence (*before);
4324 444 : lra_assert (ad.disp == ad.disp_term);
4325 444 : if (ad.base == NULL)
4326 : {
4327 344 : if (ad.index == NULL)
4328 : {
4329 344 : rtx_insn *insn;
4330 344 : rtx_insn *last = get_last_insn ();
4331 344 : int code = -1;
4332 344 : enum reg_class cl = base_reg_class (ad.mode, ad.as,
4333 : SCRATCH, SCRATCH,
4334 : ad.mem, curr_insn);
4335 344 : rtx addr = *ad.inner;
4336 :
4337 687 : new_reg = lra_create_new_reg (Pmode, NULL_RTX, cl, NULL, "addr");
4338 344 : if (HAVE_lo_sum)
4339 : {
4340 : /* addr => lo_sum (new_base, addr), case (2) above. */
4341 : insn = emit_insn (gen_rtx_SET
4342 : (new_reg,
4343 : gen_rtx_HIGH (Pmode, copy_rtx (addr))));
4344 : code = recog_memoized (insn);
4345 : if (code >= 0)
4346 : {
4347 : *ad.inner = gen_rtx_LO_SUM (Pmode, new_reg, addr);
4348 : if (!valid_address_p (op, &ad, cn))
4349 : {
4350 : /* Try to put lo_sum into register. */
4351 : insn = emit_insn (gen_rtx_SET
4352 : (new_reg,
4353 : gen_rtx_LO_SUM (Pmode, new_reg, addr)));
4354 : code = recog_memoized (insn);
4355 : if (code >= 0)
4356 : {
4357 : *ad.inner = new_reg;
4358 : if (!valid_address_p (op, &ad, cn))
4359 : {
4360 : *ad.inner = addr;
4361 : code = -1;
4362 : }
4363 : }
4364 :
4365 : }
4366 : }
4367 : if (code < 0)
4368 : delete_insns_since (last);
4369 : }
4370 :
4371 344 : if (code < 0)
4372 : {
4373 : /* addr => new_base, case (2) above. */
4374 344 : lra_emit_move (new_reg, addr);
4375 :
4376 688 : for (insn = last == NULL_RTX ? get_insns () : NEXT_INSN (last);
4377 688 : insn != NULL_RTX;
4378 344 : insn = NEXT_INSN (insn))
4379 344 : if (recog_memoized (insn) < 0)
4380 : break;
4381 344 : if (insn != NULL_RTX)
4382 : {
4383 : /* Do nothing if we cannot generate right insns.
4384 : This is analogous to reload pass behavior. */
4385 0 : delete_insns_since (last);
4386 0 : end_sequence ();
4387 0 : return false;
4388 : }
4389 344 : *ad.inner = new_reg;
4390 : }
4391 : }
4392 : else
4393 : {
4394 : /* index * scale + disp => new base + index * scale,
4395 : case (1) above. */
4396 0 : enum reg_class cl = base_reg_class (ad.mode, ad.as, PLUS,
4397 0 : GET_CODE (*ad.index),
4398 : ad.mem, curr_insn);
4399 :
4400 0 : lra_assert (index_cl != NO_REGS);
4401 0 : new_reg = lra_create_new_reg (Pmode, NULL_RTX, cl, NULL, "disp");
4402 0 : lra_emit_move (new_reg, *ad.disp);
4403 0 : *ad.inner = simplify_gen_binary (PLUS, GET_MODE (new_reg),
4404 0 : new_reg, *ad.index);
4405 : }
4406 : }
4407 100 : else if (ad.index == NULL)
4408 : {
4409 53 : int regno;
4410 53 : enum reg_class cl;
4411 53 : rtx set;
4412 53 : rtx_insn *insns, *last_insn;
4413 :
4414 53 : cl = base_reg_class (ad.mode, ad.as, ad.base_outer_code,
4415 : get_index_code (&ad), ad.mem, curr_insn);
4416 :
4417 53 : if (REG_P (*ad.base_term)
4418 53 : && ira_class_subset_p[get_reg_class (REGNO (*ad.base_term))][cl])
4419 : /* It seems base reg is already in the base reg class and changing it
4420 : does not make a progress. So reload the whole inner address. */
4421 53 : goto reload_inner_addr;
4422 :
4423 : /* Try to reload base into register only if the base is invalid
4424 : for the address but with valid offset, case (4) above. */
4425 0 : start_sequence ();
4426 0 : new_reg = base_to_reg (&ad);
4427 :
4428 : /* base + disp => new base, cases (1) and (3) above. */
4429 : /* Another option would be to reload the displacement into an
4430 : index register. However, postreload has code to optimize
4431 : address reloads that have the same base and different
4432 : displacements, so reloading into an index register would
4433 : not necessarily be a win. */
4434 0 : if (new_reg == NULL_RTX)
4435 : {
4436 : /* See if the target can split the displacement into a
4437 : legitimate new displacement from a local anchor. */
4438 0 : gcc_assert (ad.disp == ad.disp_term);
4439 0 : poly_int64 orig_offset;
4440 0 : rtx offset1, offset2;
4441 0 : if (poly_int_rtx_p (*ad.disp, &orig_offset)
4442 0 : && targetm.legitimize_address_displacement (&offset1, &offset2,
4443 : orig_offset,
4444 : ad.mode))
4445 : {
4446 0 : new_reg = base_plus_disp_to_reg (&ad, offset1);
4447 0 : new_reg = gen_rtx_PLUS (GET_MODE (new_reg), new_reg, offset2);
4448 : }
4449 : else
4450 0 : new_reg = base_plus_disp_to_reg (&ad, *ad.disp);
4451 : }
4452 0 : insns = get_insns ();
4453 0 : last_insn = get_last_insn ();
4454 : /* If we generated at least two insns, try last insn source as
4455 : an address. If we succeed, we generate one less insn. */
4456 0 : if (REG_P (new_reg)
4457 0 : && last_insn != insns
4458 0 : && (set = single_set (last_insn)) != NULL_RTX
4459 0 : && reg_plus_const_p (SET_SRC (set)))
4460 : {
4461 0 : *ad.inner = SET_SRC (set);
4462 0 : if (valid_address_p (op, &ad, cn))
4463 : {
4464 0 : *ad.base_term = XEXP (SET_SRC (set), 0);
4465 0 : *ad.disp_term = XEXP (SET_SRC (set), 1);
4466 0 : regno = REGNO (*ad.base_term);
4467 0 : if (regno >= FIRST_PSEUDO_REGISTER
4468 0 : && cl != lra_get_allocno_class (regno))
4469 0 : lra_change_class (regno, cl, " Change to", true);
4470 0 : new_reg = SET_SRC (set);
4471 0 : delete_insns_since (PREV_INSN (last_insn));
4472 : }
4473 : }
4474 0 : end_sequence ();
4475 0 : emit_insn (insns);
4476 0 : *ad.inner = new_reg;
4477 : }
4478 47 : else if (ad.disp_term != NULL)
4479 : {
4480 : /* base + scale * index + disp => new base + scale * index,
4481 : case (1) above. */
4482 47 : gcc_assert (ad.disp == ad.disp_term);
4483 47 : new_reg = base_plus_disp_to_reg (&ad, *ad.disp);
4484 47 : *ad.inner = simplify_gen_binary (PLUS, GET_MODE (new_reg),
4485 47 : new_reg, *ad.index);
4486 : }
4487 0 : else if ((scale = get_index_scale (&ad)) == 1)
4488 : {
4489 : /* The last transformation to one reg will be made in
4490 : curr_insn_transform function. */
4491 0 : end_sequence ();
4492 0 : return false;
4493 : }
4494 0 : else if (scale != 0)
4495 : {
4496 : /* base + scale * index => base + new_reg,
4497 : case (1) above.
4498 : Index part of address may become invalid. For example, we
4499 : changed pseudo on the equivalent memory and a subreg of the
4500 : pseudo onto the memory of different mode for which the scale is
4501 : prohibited. */
4502 0 : new_reg = index_part_to_reg (&ad, index_cl);
4503 0 : *ad.inner = simplify_gen_binary (PLUS, GET_MODE (new_reg),
4504 0 : *ad.base_term, new_reg);
4505 : }
4506 : else
4507 : {
4508 53 : enum reg_class cl;
4509 53 : rtx addr;
4510 0 : reload_inner_addr:
4511 53 : cl = base_reg_class (ad.mode, ad.as, SCRATCH, SCRATCH, ad.mem,
4512 : curr_insn);
4513 53 : addr = *ad.inner;
4514 53 : new_reg = lra_create_new_reg (Pmode, NULL_RTX, cl, NULL, "addr");
4515 : /* addr => new_base. */
4516 53 : lra_emit_move (new_reg, canonicalize_reload_addr (addr));
4517 53 : *ad.inner = new_reg;
4518 : }
4519 444 : *before = end_sequence ();
4520 444 : return true;
4521 : }
4522 :
4523 : /* If CHECK_ONLY_P is false, do address reloads until it is necessary.
4524 : Use process_address_1 as a helper function. Return true for any
4525 : RTL changes.
4526 :
4527 : If CHECK_ONLY_P is true, just check address correctness. Return
4528 : false if the address correct. */
4529 : static bool
4530 181702837 : process_address (int nop, bool check_only_p,
4531 : rtx_insn **before, rtx_insn **after)
4532 : {
4533 181702837 : bool res = false;
4534 : /* Use enough iterations to process all address parts: */
4535 182195477 : for (int i = 0; i < 10; i++)
4536 : {
4537 182195477 : if (!process_address_1 (nop, check_only_p, before, after))
4538 : {
4539 : return res;
4540 : }
4541 : else
4542 : {
4543 492640 : if (check_only_p)
4544 : return true;
4545 492640 : res = true;
4546 : }
4547 : }
4548 0 : fatal_insn ("unable to reload address in ", curr_insn);
4549 : }
4550 :
4551 : /* Override the generic address_reload_context in order to
4552 : control the creation of reload pseudos. */
4553 : class lra_autoinc_reload_context : public address_reload_context
4554 : {
4555 : machine_mode mode;
4556 : enum reg_class rclass;
4557 :
4558 : public:
4559 0 : lra_autoinc_reload_context (machine_mode mode, enum reg_class new_rclass)
4560 0 : : mode (mode), rclass (new_rclass) {}
4561 :
4562 0 : rtx get_reload_reg () const override final
4563 : {
4564 0 : return lra_create_new_reg (mode, NULL_RTX, rclass, NULL, "INC/DEC result");
4565 : }
4566 : };
4567 :
4568 : /* Emit insns to reload VALUE into a new register. VALUE is an
4569 : auto-increment or auto-decrement RTX whose operand is a register or
4570 : memory location; so reloading involves incrementing that location.
4571 :
4572 : INC_AMOUNT is the number to increment or decrement by (always
4573 : positive and ignored for POST_MODIFY/PRE_MODIFY).
4574 :
4575 : Return a pseudo containing the result. */
4576 : static rtx
4577 0 : emit_inc (enum reg_class new_rclass, rtx value, poly_int64 inc_amount)
4578 : {
4579 0 : lra_autoinc_reload_context context (GET_MODE (value), new_rclass);
4580 0 : return context.emit_autoinc (value, inc_amount);
4581 : }
4582 :
4583 : /* Return true if the current move insn does not need processing as we
4584 : already know that it satisfies its constraints. */
4585 : static bool
4586 104126482 : simple_move_p (void)
4587 : {
4588 104126482 : rtx dest, src;
4589 104126482 : enum reg_class dclass, sclass;
4590 :
4591 104126482 : lra_assert (curr_insn_set != NULL_RTX);
4592 104126482 : dest = SET_DEST (curr_insn_set);
4593 104126482 : src = SET_SRC (curr_insn_set);
4594 :
4595 : /* If the instruction has multiple sets we need to process it even if it
4596 : is single_set. This can happen if one or more of the SETs are dead.
4597 : See PR73650. */
4598 104126482 : if (multiple_sets (curr_insn))
4599 : return false;
4600 :
4601 103915435 : return ((dclass = get_op_class (dest)) != NO_REGS
4602 21975569 : && (sclass = get_op_class (src)) != NO_REGS
4603 : /* The backend guarantees that register moves of cost 2
4604 : never need reloads. */
4605 92944950 : && targetm.register_move_cost (GET_MODE (src), sclass, dclass) == 2);
4606 : }
4607 :
4608 : /* Swap operands NOP and NOP + 1. */
4609 : static inline void
4610 22070966 : swap_operands (int nop)
4611 : {
4612 22070966 : std::swap (curr_operand_mode[nop], curr_operand_mode[nop + 1]);
4613 22070966 : std::swap (original_subreg_reg_mode[nop], original_subreg_reg_mode[nop + 1]);
4614 22070966 : std::swap (*curr_id->operand_loc[nop], *curr_id->operand_loc[nop + 1]);
4615 22070966 : std::swap (equiv_substition_p[nop], equiv_substition_p[nop + 1]);
4616 : /* Swap the duplicates too. */
4617 22070966 : lra_update_dup (curr_id, nop);
4618 22070966 : lra_update_dup (curr_id, nop + 1);
4619 22070966 : }
4620 :
4621 : /* Return TRUE if X is a (subreg of) reg and there are no hard regs of X class
4622 : which can contain value of MODE. */
4623 32 : static bool invalid_mode_reg_p (enum machine_mode mode, rtx x)
4624 : {
4625 32 : if (SUBREG_P (x))
4626 1 : x = SUBREG_REG (x);
4627 32 : if (! REG_P (x))
4628 : return false;
4629 32 : enum reg_class rclass = get_reg_class (REGNO (x));
4630 32 : return (!hard_reg_set_empty_p (reg_class_contents[rclass])
4631 32 : && hard_reg_set_subset_p
4632 32 : (reg_class_contents[rclass],
4633 32 : ira_prohibited_class_mode_regs[rclass][mode]));
4634 : }
4635 :
4636 : /* Return TRUE if regno is referenced in more than one non-debug insn. */
4637 : static bool
4638 2973691 : multiple_insn_refs_p (int regno)
4639 : {
4640 2973691 : unsigned int uid;
4641 2973691 : bitmap_iterator bi;
4642 2973691 : int nrefs = 0;
4643 7269075 : EXECUTE_IF_SET_IN_BITMAP (&lra_reg_info[regno].insn_bitmap, 0, uid, bi)
4644 : {
4645 7264161 : if (!NONDEBUG_INSN_P (lra_insn_recog_data[uid]->insn))
4646 1321693 : continue;
4647 5942468 : if (nrefs == 1)
4648 : return true;
4649 2973691 : nrefs++;
4650 : }
4651 : return false;
4652 : }
4653 :
4654 : /* Mark insns starting with FIRST as postponed for processing their
4655 : constraints. See comments for lra_postponed_insns. */
4656 : static void
4657 94770 : postpone_insns (rtx_insn *first)
4658 : {
4659 107213 : for (auto insn = first; insn != NULL_RTX; insn = NEXT_INSN (insn))
4660 : {
4661 12443 : bitmap_set_bit (&lra_postponed_insns, INSN_UID (insn));
4662 12443 : if (lra_dump_file != NULL)
4663 : {
4664 7 : fprintf (lra_dump_file, " Postponing constraint processing: ");
4665 7 : dump_insn_slim (lra_dump_file, insn);
4666 : }
4667 : }
4668 94770 : }
4669 :
4670 : /* Test whether the n-th operand is a MEM where the address is the sum of a
4671 : section anchor and a constant and return true in case of reloading the
4672 : section anchor only results in a satisfiable operand w.r.t. its
4673 : corresponding constraint. Otherwise return false. */
4674 :
4675 : static bool
4676 72 : reload_section_anchor_p (int nop)
4677 : {
4678 72 : rtx op = *curr_id->operand_loc[nop];
4679 72 : if (!MEM_P (op))
4680 : return false;
4681 72 : rtx addr = XEXP (op, 0);
4682 :
4683 72 : if (GET_CODE (addr) != CONST
4684 13 : || GET_CODE (XEXP (addr, 0)) != PLUS
4685 0 : || GET_CODE (XEXP (XEXP (addr, 0), 0)) != SYMBOL_REF
4686 0 : || !SYMBOL_REF_ANCHOR_P (XEXP (XEXP (addr, 0), 0))
4687 0 : || !CONST_INT_P (XEXP (XEXP (addr, 0), 1))
4688 : /* Some offsets are valid in conjunction with a symbol and
4689 : invalid in conjunction with a register. Thus, pull out
4690 : the anchor only in case the offset is a valid anchor
4691 : offset. */
4692 0 : || INTVAL (XEXP (XEXP (addr, 0), 1)) < targetm.min_anchor_offset
4693 72 : || INTVAL (XEXP (XEXP (addr, 0), 1)) > targetm.max_anchor_offset)
4694 : return false;
4695 :
4696 : /* Now test whether a new address of the form REG+DISPLACEMENT is valid for
4697 : the selected alternative. In order to do so, utilize lra_pmode_pseudo
4698 : instead of an actual reload register. */
4699 :
4700 0 : rtx offset = XEXP (XEXP (addr, 0), 1);
4701 0 : rtx new_addr = gen_rtx_PLUS (Pmode, lra_pmode_pseudo, offset);
4702 0 : rtx new_op = shallow_copy_rtx (op);
4703 0 : XEXP (new_op, 0) = new_addr;
4704 :
4705 : /* Get operand constraints for given alternative. */
4706 0 : const char *p = (curr_static_id->operand_alternative
4707 0 : [goal_alt_number * curr_static_id->n_operands + nop]
4708 : .constraint);
4709 0 : char c;
4710 0 : for (;
4711 0 : (c = *p) && c != ',' && c != '#';
4712 0 : p += CONSTRAINT_LEN (c, p))
4713 : {
4714 0 : enum constraint_num cn = lookup_constraint (p);
4715 0 : if (constraint_satisfied_p (new_op, cn))
4716 : return true;
4717 : }
4718 :
4719 : return false;
4720 : }
4721 :
4722 : /* Main entry point of the constraint code: search the body of the
4723 : current insn to choose the best alternative. It is mimicking insn
4724 : alternative cost calculation model of former reload pass. That is
4725 : because machine descriptions were written to use this model. This
4726 : model can be changed in future. Make commutative operand exchange
4727 : if it is chosen.
4728 :
4729 : if CHECK_ONLY_P is false, do RTL changes to satisfy the
4730 : constraints. Return true if any change happened during function
4731 : call.
4732 :
4733 : If CHECK_ONLY_P is true then don't do any transformation. Just
4734 : check that the insn satisfies all constraints. If the insn does
4735 : not satisfy any constraint, return true. */
4736 : static bool
4737 109658285 : curr_insn_transform (bool check_only_p)
4738 : {
4739 109658285 : int i, j, k;
4740 109658285 : int n_operands;
4741 109658285 : int n_alternatives;
4742 109658285 : int n_outputs;
4743 109658285 : int commutative;
4744 109658285 : signed char goal_alt_matched[MAX_RECOG_OPERANDS][MAX_RECOG_OPERANDS];
4745 109658285 : signed char match_inputs[MAX_RECOG_OPERANDS + 1];
4746 109658285 : signed char outputs[MAX_RECOG_OPERANDS + 1];
4747 109658285 : rtx_insn *before, *after;
4748 109658285 : bool alt_p = false;
4749 : /* Flag that the insn has been changed through a transformation. */
4750 109658285 : bool change_p;
4751 109658285 : bool sec_mem_p;
4752 109658285 : bool use_sec_mem_p;
4753 109658285 : int max_regno_before;
4754 109658285 : int reused_alternative_num;
4755 :
4756 109658285 : curr_insn_set = single_set (curr_insn);
4757 109658285 : if (curr_insn_set != NULL_RTX && simple_move_p ())
4758 : {
4759 : /* We assume that the corresponding insn alternative has no
4760 : earlier clobbers. If it is not the case, don't define move
4761 : cost equal to 2 for the corresponding register classes. */
4762 16924651 : lra_set_used_insn_alternative (curr_insn, LRA_NON_CLOBBERED_ALT);
4763 16924651 : return false;
4764 : }
4765 :
4766 92733634 : no_input_reloads_p = no_output_reloads_p = false;
4767 92733634 : goal_alt_number = -1;
4768 92733634 : change_p = sec_mem_p = false;
4769 :
4770 : /* CALL_INSNs are not allowed to have any output reloads. */
4771 92733634 : if (CALL_P (curr_insn))
4772 6209235 : no_output_reloads_p = true;
4773 :
4774 92733634 : n_operands = curr_static_id->n_operands;
4775 92733634 : n_alternatives = curr_static_id->n_alternatives;
4776 :
4777 : /* Just return "no reloads" if insn has no operands with
4778 : constraints. */
4779 92733634 : if (n_operands == 0 || n_alternatives == 0)
4780 : return false;
4781 :
4782 82036637 : max_regno_before = max_reg_num ();
4783 :
4784 347140349 : for (i = 0; i < n_operands; i++)
4785 : {
4786 183067075 : goal_alt_matched[i][0] = -1;
4787 183067075 : goal_alt_matches[i] = -1;
4788 : }
4789 :
4790 82036637 : commutative = curr_static_id->commutative;
4791 :
4792 : /* Now see what we need for pseudos that didn't get hard regs or got
4793 : the wrong kind of hard reg. For this, we must consider all the
4794 : operands together against the register constraints. */
4795 :
4796 82036637 : best_losers = best_overall = INT_MAX;
4797 82036637 : best_reload_sum = 0;
4798 :
4799 82036637 : curr_swapped = false;
4800 82036637 : goal_alt_swapped = false;
4801 :
4802 82036637 : if (! check_only_p)
4803 : /* Make equivalence substitution and memory subreg elimination
4804 : before address processing because an address legitimacy can
4805 : depend on memory mode. */
4806 265036847 : for (i = 0; i < n_operands; i++)
4807 : {
4808 183018824 : rtx op, subst, old;
4809 183018824 : bool op_change_p = false;
4810 :
4811 183018824 : if (curr_static_id->operand[i].is_operator)
4812 1494786 : continue;
4813 :
4814 181524038 : old = op = *curr_id->operand_loc[i];
4815 181524038 : if (GET_CODE (old) == SUBREG)
4816 3885595 : old = SUBREG_REG (old);
4817 181524038 : subst = get_equiv_with_elimination (old, curr_insn);
4818 181524038 : original_subreg_reg_mode[i] = VOIDmode;
4819 181524038 : equiv_substition_p[i] = false;
4820 :
4821 181524038 : if (subst != old
4822 : /* We don't want to change an out operand by constant or invariant
4823 : which will require additional reloads, e.g. by putting a constant
4824 : into memory. */
4825 1620310 : && (curr_static_id->operand[i].type == OP_IN || MEM_P (subst)
4826 0 : || (GET_CODE (subst) == SUBREG && MEM_P (SUBREG_REG (subst)))))
4827 : {
4828 1620310 : equiv_substition_p[i] = true;
4829 1620310 : rtx new_subst = copy_rtx (subst);
4830 1620310 : if (lra_pointer_equiv_set_in (subst))
4831 829606 : lra_pointer_equiv_set_add (new_subst);
4832 1620310 : subst = new_subst;
4833 1620310 : lra_assert (REG_P (old));
4834 1620310 : if (GET_CODE (op) != SUBREG)
4835 1565863 : *curr_id->operand_loc[i] = subst;
4836 : else
4837 : {
4838 54447 : SUBREG_REG (op) = subst;
4839 54447 : if (GET_MODE (subst) == VOIDmode)
4840 62 : original_subreg_reg_mode[i] = GET_MODE (old);
4841 : }
4842 1620310 : if (lra_dump_file != NULL)
4843 : {
4844 3 : fprintf (lra_dump_file,
4845 : "Changing pseudo %d in operand %i of insn %u on equiv ",
4846 3 : REGNO (old), i, INSN_UID (curr_insn));
4847 3 : dump_value_slim (lra_dump_file, subst, 1);
4848 3 : fprintf (lra_dump_file, "\n");
4849 : }
4850 1620310 : op_change_p = change_p = true;
4851 : }
4852 181524038 : if (simplify_operand_subreg (i, GET_MODE (old)) || op_change_p)
4853 : {
4854 1620838 : change_p = true;
4855 1620838 : lra_update_dup (curr_id, i);
4856 : }
4857 : }
4858 :
4859 : /* We process equivalences before ignoring postponed insns on the current
4860 : constraint sub-pass but before any reload insn generation for the
4861 : postponed insn. */
4862 82018023 : if (! check_only_p
4863 82018023 : && bitmap_bit_p (&lra_postponed_insns, INSN_UID (curr_insn)))
4864 : return true;
4865 :
4866 : /* Reload address registers and displacements. We do it before
4867 : finding an alternative because of memory constraints. */
4868 82030325 : before = after = NULL;
4869 265084773 : for (i = 0; i < n_operands; i++)
4870 183054448 : if (! curr_static_id->operand[i].is_operator
4871 183054448 : && process_address (i, check_only_p, &before, &after))
4872 : {
4873 492638 : if (check_only_p)
4874 : return true;
4875 492638 : change_p = true;
4876 492638 : lra_update_dup (curr_id, i);
4877 : }
4878 :
4879 82030325 : if (change_p)
4880 : /* If we've changed the instruction then any alternative that
4881 : we chose previously may no longer be valid. */
4882 2066303 : lra_set_used_insn_alternative (curr_insn, LRA_UNKNOWN_ALT);
4883 :
4884 82011711 : if (! check_only_p && curr_insn_set != NULL_RTX
4885 160091017 : && check_and_process_move (&change_p, &sec_mem_p))
4886 0 : return change_p;
4887 :
4888 82030325 : try_swapped:
4889 :
4890 92733858 : reused_alternative_num = check_only_p ? LRA_UNKNOWN_ALT : curr_id->used_insn_alternative;
4891 92733858 : if (lra_dump_file != NULL && reused_alternative_num >= 0)
4892 0 : fprintf (lra_dump_file, "Reusing alternative %d for insn #%u\n",
4893 0 : reused_alternative_num, INSN_UID (curr_insn));
4894 :
4895 92733858 : if (process_alt_operands (reused_alternative_num))
4896 83960855 : alt_p = true;
4897 :
4898 92733858 : if (check_only_p)
4899 18614 : return ! alt_p || best_losers != 0;
4900 :
4901 : /* If insn is commutative (it's safe to exchange a certain pair of
4902 : operands) then we need to try each alternative twice, the second
4903 : time matching those two operands as if we had exchanged them. To
4904 : do this, really exchange them in operands.
4905 :
4906 : If we have just tried the alternatives the second time, return
4907 : operands to normal and drop through. */
4908 :
4909 92715244 : if (reused_alternative_num < 0 && commutative >= 0)
4910 : {
4911 21407066 : curr_swapped = !curr_swapped;
4912 21407066 : if (curr_swapped)
4913 : {
4914 10703533 : swap_operands (commutative);
4915 10703533 : goto try_swapped;
4916 : }
4917 : else
4918 10703533 : swap_operands (commutative);
4919 : }
4920 :
4921 82011711 : if (! alt_p && ! sec_mem_p)
4922 : {
4923 : /* No alternative works with reloads?? */
4924 6 : if (INSN_CODE (curr_insn) >= 0)
4925 0 : fatal_insn ("unable to generate reloads for:", curr_insn);
4926 6 : error_for_asm (curr_insn,
4927 : "inconsistent operand constraints in an %<asm%>");
4928 6 : lra_asm_error_p = true;
4929 6 : if (! JUMP_P (curr_insn))
4930 : {
4931 : /* Avoid further trouble with this insn. Don't generate use
4932 : pattern here as we could use the insn SP offset. */
4933 6 : lra_set_insn_deleted (curr_insn);
4934 : }
4935 : else
4936 : {
4937 0 : lra_invalidate_insn_data (curr_insn);
4938 0 : ira_nullify_asm_goto (curr_insn);
4939 0 : lra_update_insn_regno_info (curr_insn);
4940 : }
4941 : return true;
4942 : }
4943 :
4944 : /* If the best alternative is with operands 1 and 2 swapped, swap
4945 : them. Update the operand numbers of any reloads already
4946 : pushed. */
4947 :
4948 82011705 : if (goal_alt_swapped)
4949 : {
4950 659600 : if (lra_dump_file != NULL)
4951 21 : fprintf (lra_dump_file, " Commutative operand exchange in insn %u\n",
4952 21 : INSN_UID (curr_insn));
4953 :
4954 : /* Swap the duplicates too. */
4955 659600 : swap_operands (commutative);
4956 659600 : change_p = true;
4957 : }
4958 :
4959 : /* Some targets' TARGET_SECONDARY_MEMORY_NEEDED (e.g. x86) are defined
4960 : too conservatively. So we use the secondary memory only if there
4961 : is no any alternative without reloads. */
4962 82011705 : use_sec_mem_p = false;
4963 82011705 : if (! alt_p)
4964 : use_sec_mem_p = true;
4965 82011705 : else if (sec_mem_p)
4966 : {
4967 14562 : for (i = 0; i < n_operands; i++)
4968 14390 : if (! goal_alt_win[i] && ! goal_alt_match_win[i])
4969 : break;
4970 13009 : use_sec_mem_p = i < n_operands;
4971 : }
4972 :
4973 13009 : if (use_sec_mem_p)
4974 : {
4975 12837 : int in = -1, out = -1;
4976 12837 : rtx new_reg, src, dest, rld;
4977 12837 : machine_mode sec_mode, rld_mode;
4978 :
4979 12837 : lra_assert (curr_insn_set != NULL_RTX && sec_mem_p);
4980 12837 : dest = SET_DEST (curr_insn_set);
4981 12837 : src = SET_SRC (curr_insn_set);
4982 38511 : for (i = 0; i < n_operands; i++)
4983 25674 : if (*curr_id->operand_loc[i] == dest)
4984 : out = i;
4985 12837 : else if (*curr_id->operand_loc[i] == src)
4986 12837 : in = i;
4987 12837 : for (i = 0; i < curr_static_id->n_dups; i++)
4988 0 : if (out < 0 && *curr_id->dup_loc[i] == dest)
4989 0 : out = curr_static_id->dup_num[i];
4990 0 : else if (in < 0 && *curr_id->dup_loc[i] == src)
4991 0 : in = curr_static_id->dup_num[i];
4992 12837 : lra_assert (out >= 0 && in >= 0
4993 : && curr_static_id->operand[out].type == OP_OUT
4994 : && curr_static_id->operand[in].type == OP_IN);
4995 12837 : rld = partial_subreg_p (GET_MODE (src), GET_MODE (dest)) ? src : dest;
4996 12837 : rld_mode = GET_MODE (rld);
4997 12837 : sec_mode = targetm.secondary_memory_needed_mode (rld_mode);
4998 12837 : if (rld_mode != sec_mode
4999 12837 : && (invalid_mode_reg_p (sec_mode, dest)
5000 16 : || invalid_mode_reg_p (sec_mode, src)))
5001 : sec_mode = rld_mode;
5002 12837 : new_reg = lra_create_new_reg (sec_mode, NULL_RTX, NO_REGS, NULL,
5003 : "secondary");
5004 : /* If the mode is changed, it should be wider. */
5005 12837 : lra_assert (!partial_subreg_p (sec_mode, rld_mode));
5006 12837 : if (sec_mode != rld_mode)
5007 : {
5008 : /* If the target says specifically to use another mode for
5009 : secondary memory moves we cannot reuse the original
5010 : insn. */
5011 16 : after = emit_spill_move (false, new_reg, dest);
5012 16 : lra_process_new_insns (curr_insn, NULL, after,
5013 : "Inserting the sec. move");
5014 : /* We may have non null BEFORE here (e.g. after address
5015 : processing. */
5016 16 : push_to_sequence (before);
5017 16 : before = emit_spill_move (true, new_reg, src);
5018 16 : emit_insn (before);
5019 16 : before = end_sequence ();
5020 16 : lra_process_new_insns (curr_insn, before, NULL, "Changing on");
5021 16 : lra_set_insn_deleted (curr_insn);
5022 : }
5023 12821 : else if (dest == rld)
5024 : {
5025 12821 : *curr_id->operand_loc[out] = new_reg;
5026 12821 : lra_update_dup (curr_id, out);
5027 12821 : after = emit_spill_move (false, new_reg, dest);
5028 12821 : lra_process_new_insns (curr_insn, NULL, after,
5029 : "Inserting the sec. move");
5030 : }
5031 : else
5032 : {
5033 0 : *curr_id->operand_loc[in] = new_reg;
5034 0 : lra_update_dup (curr_id, in);
5035 : /* See comments above. */
5036 0 : push_to_sequence (before);
5037 0 : before = emit_spill_move (true, new_reg, src);
5038 0 : emit_insn (before);
5039 0 : before = end_sequence ();
5040 0 : lra_process_new_insns (curr_insn, before, NULL,
5041 : "Inserting the sec. move");
5042 : }
5043 12837 : lra_update_insn_regno_info (curr_insn);
5044 12837 : return true;
5045 : }
5046 :
5047 81998868 : lra_assert (goal_alt_number >= 0);
5048 163907337 : lra_set_used_insn_alternative (curr_insn, goal_reuse_alt_p
5049 : ? goal_alt_number : LRA_UNKNOWN_ALT);
5050 :
5051 81998868 : if (lra_dump_file != NULL)
5052 : {
5053 1185 : const char *p;
5054 :
5055 1185 : fprintf (lra_dump_file, " Choosing alt %d in insn %u:",
5056 1185 : goal_alt_number, INSN_UID (curr_insn));
5057 1185 : print_curr_insn_alt (goal_alt_number);
5058 1185 : if (INSN_CODE (curr_insn) >= 0
5059 1185 : && (p = get_insn_name (INSN_CODE (curr_insn))) != NULL)
5060 1178 : fprintf (lra_dump_file, " {%s}", p);
5061 1185 : if (maybe_ne (curr_id->sp_offset, 0))
5062 : {
5063 0 : fprintf (lra_dump_file, " (sp_off=");
5064 0 : print_dec (curr_id->sp_offset, lra_dump_file);
5065 0 : fprintf (lra_dump_file, ")");
5066 : }
5067 1185 : fprintf (lra_dump_file, "\n");
5068 : }
5069 :
5070 : /* Right now, for any pair of operands I and J that are required to
5071 : match, with J < I, goal_alt_matches[I] is J. Add I to
5072 : goal_alt_matched[J]. */
5073 :
5074 264979377 : for (i = 0; i < n_operands; i++)
5075 182980509 : if ((j = goal_alt_matches[i]) >= 0)
5076 : {
5077 10876360 : for (k = 0; goal_alt_matched[j][k] >= 0; k++)
5078 : ;
5079 : /* We allow matching one output operand and several input
5080 : operands. */
5081 10876359 : lra_assert (k == 0
5082 : || (curr_static_id->operand[j].type == OP_OUT
5083 : && curr_static_id->operand[i].type == OP_IN
5084 : && (curr_static_id->operand
5085 : [goal_alt_matched[j][0]].type == OP_IN)));
5086 10876359 : goal_alt_matched[j][k] = i;
5087 10876359 : goal_alt_matched[j][k + 1] = -1;
5088 : }
5089 :
5090 264979377 : for (i = 0; i < n_operands; i++)
5091 182980509 : goal_alt_win[i] |= goal_alt_match_win[i];
5092 :
5093 : /* Any constants that aren't allowed and can't be reloaded into
5094 : registers are here changed into memory references. */
5095 264979377 : for (i = 0; i < n_operands; i++)
5096 182980509 : if (goal_alt_win[i])
5097 : {
5098 176573874 : int regno;
5099 176573874 : enum reg_class new_class;
5100 176573874 : rtx reg = *curr_id->operand_loc[i];
5101 :
5102 176573874 : if (GET_CODE (reg) == SUBREG)
5103 3547611 : reg = SUBREG_REG (reg);
5104 :
5105 176573874 : if (REG_P (reg) && (regno = REGNO (reg)) >= FIRST_PSEUDO_REGISTER)
5106 : {
5107 80105740 : bool ok_p = in_class_p (reg, goal_alt[i], &new_class, true);
5108 :
5109 80105740 : if (new_class != NO_REGS && get_reg_class (regno) != new_class)
5110 : {
5111 3624751 : lra_assert (ok_p);
5112 3624751 : lra_change_class (regno, new_class, " Change to", true);
5113 : }
5114 : }
5115 : }
5116 : else
5117 : {
5118 6406635 : const char *constraint;
5119 6406635 : char c;
5120 6406635 : rtx op = *curr_id->operand_loc[i];
5121 6406635 : rtx subreg = NULL_RTX;
5122 6406635 : machine_mode op_mode = curr_operand_mode[i], mode = op_mode;
5123 :
5124 6406635 : if (GET_CODE (op) == SUBREG)
5125 : {
5126 273691 : subreg = op;
5127 273691 : op = SUBREG_REG (op);
5128 273691 : mode = GET_MODE (op);
5129 : }
5130 :
5131 6628228 : if (CONST_POOL_OK_P (mode, op)
5132 6628228 : && ((targetm.preferred_reload_class
5133 221593 : (op, (enum reg_class) goal_alt[i]) == NO_REGS)
5134 77868 : || no_input_reloads_p))
5135 : {
5136 143725 : rtx tem = force_const_mem (mode, op);
5137 :
5138 143725 : change_p = true;
5139 143725 : if (subreg != NULL_RTX)
5140 0 : tem = gen_rtx_SUBREG (op_mode, tem, SUBREG_BYTE (subreg));
5141 :
5142 143725 : *curr_id->operand_loc[i] = tem;
5143 143725 : lra_update_dup (curr_id, i);
5144 143725 : process_address (i, false, &before, &after);
5145 :
5146 : /* If the alternative accepts constant pool refs directly
5147 : there will be no reload needed at all. */
5148 143725 : if (subreg != NULL_RTX)
5149 0 : continue;
5150 : /* Skip alternatives before the one requested. */
5151 143725 : constraint = (curr_static_id->operand_alternative
5152 143725 : [goal_alt_number * n_operands + i].constraint);
5153 143725 : for (;
5154 245644 : (c = *constraint) && c != ',' && c != '#';
5155 101919 : constraint += CONSTRAINT_LEN (c, constraint))
5156 : {
5157 199355 : enum constraint_num cn = lookup_constraint (constraint);
5158 199355 : if ((insn_extra_memory_constraint (cn)
5159 102173 : || insn_extra_special_memory_constraint (cn)
5160 : || insn_extra_relaxed_memory_constraint (cn))
5161 199609 : && satisfies_memory_constraint_p (tem, cn))
5162 : break;
5163 : }
5164 143725 : if (c == '\0' || c == ',' || c == '#')
5165 46289 : continue;
5166 :
5167 97436 : goal_alt_win[i] = true;
5168 : }
5169 : }
5170 :
5171 : n_outputs = 0;
5172 264979377 : for (i = 0; i < n_operands; i++)
5173 182980509 : if (curr_static_id->operand[i].type == OP_OUT)
5174 71231203 : outputs[n_outputs++] = i;
5175 81998868 : outputs[n_outputs] = -1;
5176 264979377 : for (i = 0; i < n_operands; i++)
5177 : {
5178 182980509 : int regno;
5179 182980509 : bool optional_p = false;
5180 182980509 : rtx old, new_reg;
5181 182980509 : rtx op = *curr_id->operand_loc[i];
5182 :
5183 182980509 : if (goal_alt_win[i])
5184 : {
5185 176671310 : if (goal_alt[i] == NO_REGS
5186 48208355 : && REG_P (op)
5187 5545561 : && (regno = REGNO (op)) >= FIRST_PSEUDO_REGISTER
5188 : /* We assigned a hard register to the pseudo in the past but now
5189 : decided to spill it for the insn. If the pseudo is used only
5190 : in this insn, it is better to spill it here as we free hard
5191 : registers for other pseudos referenced in the insn. The most
5192 : common case of this is a scratch register which will be
5193 : transformed to scratch back at the end of LRA. */
5194 179645001 : && !multiple_insn_refs_p (regno))
5195 : {
5196 9828 : if (lra_get_allocno_class (regno) != NO_REGS)
5197 4643 : lra_change_class (regno, NO_REGS, " Change to", true);
5198 4914 : reg_renumber[regno] = -1;
5199 : }
5200 : /* We can do an optional reload. If the pseudo got a hard
5201 : reg, we might improve the code through inheritance. If
5202 : it does not get a hard register we coalesce memory/memory
5203 : moves later. Ignore move insns to avoid cycling. */
5204 176671310 : if (! lra_simple_p
5205 176125692 : && lra_undo_inheritance_iter < LRA_MAX_INHERITANCE_PASSES
5206 163372234 : && goal_alt[i] != NO_REGS && REG_P (op)
5207 81020563 : && (regno = REGNO (op)) >= FIRST_PSEUDO_REGISTER
5208 67797288 : && regno < new_regno_start
5209 62917262 : && ! ira_former_scratch_p (regno)
5210 62857675 : && reg_renumber[regno] < 0
5211 : /* Check that the optional reload pseudo will be able to
5212 : hold given mode value. */
5213 3891438 : && ! (prohibited_class_reg_set_mode_p
5214 3891438 : (goal_alt[i], reg_class_contents[goal_alt[i]],
5215 3891438 : PSEUDO_REGNO_MODE (regno)))
5216 180562738 : && (curr_insn_set == NULL_RTX
5217 3884849 : || !((REG_P (SET_SRC (curr_insn_set))
5218 : || MEM_P (SET_SRC (curr_insn_set))
5219 : || GET_CODE (SET_SRC (curr_insn_set)) == SUBREG)
5220 3254063 : && (REG_P (SET_DEST (curr_insn_set))
5221 : || MEM_P (SET_DEST (curr_insn_set))
5222 : || GET_CODE (SET_DEST (curr_insn_set)) == SUBREG))))
5223 : optional_p = true;
5224 176033910 : else if (goal_alt_matched[i][0] != -1
5225 9083232 : && curr_static_id->operand[i].type == OP_OUT
5226 9082256 : && (curr_static_id->operand_alternative
5227 9082256 : [goal_alt_number * n_operands + i].earlyclobber)
5228 20889 : && REG_P (op))
5229 : {
5230 25640 : for (j = 0; goal_alt_matched[i][j] != -1; j++)
5231 : {
5232 20836 : rtx op2 = *curr_id->operand_loc[goal_alt_matched[i][j]];
5233 :
5234 20836 : if (REG_P (op2) && REGNO (op) != REGNO (op2))
5235 : break;
5236 : }
5237 20836 : if (goal_alt_matched[i][j] != -1)
5238 : {
5239 : /* Generate reloads for different output and matched
5240 : input registers. This is the easiest way to avoid
5241 : creation of non-existing register conflicts in
5242 : lra-lives.cc. */
5243 16032 : match_reload (i, goal_alt_matched[i], outputs, goal_alt[i],
5244 : &goal_alt_exclude_start_hard_regs[i], &before,
5245 : &after, true);
5246 : }
5247 177737289 : continue;
5248 20836 : }
5249 : else
5250 : {
5251 176013074 : enum reg_class rclass, common_class;
5252 :
5253 92126951 : if (REG_P (op) && goal_alt[i] != NO_REGS
5254 86581390 : && (regno = REGNO (op)) >= new_regno_start
5255 4890028 : && (rclass = get_reg_class (regno)) == ALL_REGS
5256 0 : && ((common_class = ira_reg_class_subset[rclass][goal_alt[i]])
5257 : != NO_REGS)
5258 0 : && common_class != ALL_REGS
5259 176013074 : && enough_allocatable_hard_regs_p (common_class,
5260 0 : GET_MODE (op)))
5261 : /* Refine reload pseudo class from chosen alternative
5262 : constraint. */
5263 0 : lra_change_class (regno, common_class, " Change to", true);
5264 176013074 : continue;
5265 176013074 : }
5266 : }
5267 :
5268 : /* Operands that match previous ones have already been handled. */
5269 6946599 : if (goal_alt_matches[i] >= 0)
5270 1703379 : continue;
5271 :
5272 : /* We should not have an operand with a non-offsettable address
5273 : appearing where an offsettable address will do. It also may
5274 : be a case when the address should be special in other words
5275 : not a general one (e.g. it needs no index reg). */
5276 5243220 : if (goal_alt_matched[i][0] == -1 && goal_alt_offmemok[i] && MEM_P (op))
5277 : {
5278 72 : enum reg_class rclass;
5279 72 : rtx *loc = &XEXP (op, 0);
5280 72 : enum rtx_code code = GET_CODE (*loc);
5281 :
5282 72 : push_to_sequence (before);
5283 72 : rclass = base_reg_class (GET_MODE (op), MEM_ADDR_SPACE (op),
5284 : MEM, SCRATCH, op, curr_insn);
5285 72 : if (GET_RTX_CLASS (code) == RTX_AUTOINC)
5286 0 : new_reg = emit_inc (rclass, *loc,
5287 : /* This value does not matter for MODIFY. */
5288 0 : GET_MODE_SIZE (GET_MODE (op)));
5289 : /* Try to pull out section anchors. For example, instead of
5290 : reloading an "entire" address like .LANCHOR42+offset only reload
5291 : .LANCHOR42 and use the new reload register as the base register.
5292 : This allows following optimizations to share section anchors and
5293 : remove redundant loads. */
5294 72 : else if (reload_section_anchor_p (i))
5295 : {
5296 0 : rtx anchor = XEXP (XEXP (*loc, 0), 0);
5297 0 : rtx offset = XEXP (XEXP (*loc, 0), 1);
5298 :
5299 0 : if (get_reload_reg (OP_IN, Pmode, anchor, rclass, NULL, false,
5300 : false, "offsetable address", &new_reg))
5301 0 : lra_emit_move (new_reg, anchor);
5302 :
5303 0 : rtx new_addr = gen_rtx_PLUS (Pmode, new_reg, offset);
5304 0 : rtx new_op = shallow_copy_rtx (op);
5305 0 : XEXP (new_op, 0) = new_addr;
5306 :
5307 0 : new_reg = new_op;
5308 0 : loc = curr_id->operand_loc[i];
5309 : }
5310 86 : else if (get_reload_reg (OP_IN, Pmode, *loc, rclass,
5311 : NULL, false, false,
5312 : "offsetable address", &new_reg))
5313 : {
5314 72 : rtx addr = *loc;
5315 72 : enum rtx_code code = GET_CODE (addr);
5316 72 : bool align_p = false;
5317 :
5318 72 : if (code == AND && CONST_INT_P (XEXP (addr, 1)))
5319 : {
5320 : /* (and ... (const_int -X)) is used to align to X bytes. */
5321 0 : align_p = true;
5322 0 : addr = XEXP (*loc, 0);
5323 : }
5324 : else
5325 72 : addr = canonicalize_reload_addr (addr);
5326 :
5327 72 : lra_emit_move (new_reg, addr);
5328 72 : if (align_p)
5329 0 : emit_move_insn (new_reg, gen_rtx_AND (GET_MODE (new_reg),
5330 : new_reg, XEXP (*loc, 1)));
5331 : }
5332 72 : before = end_sequence ();
5333 72 : *loc = new_reg;
5334 72 : lra_update_dup (curr_id, i);
5335 72 : }
5336 3450022 : else if (goal_alt_matched[i][0] == -1 && goal_alt[i] == NO_REGS
5337 5265417 : && goal_alt_offmemok[i] && reg_plus_const_p (op))
5338 : {
5339 : /* Materialize the sum probably produced by elimination of a register
5340 : and then spill it into memory to satisfy the memory constraint. */
5341 4424 : machine_mode mode = curr_operand_mode[i];
5342 4424 : enum reg_class rclass
5343 4424 : = base_reg_class (mode, ADDR_SPACE_GENERIC, PLUS, SCRATCH, op,
5344 : curr_insn);
5345 4424 : rtx mem_pseudo;
5346 :
5347 4424 : push_to_sequence (before);
5348 4424 : if (get_reload_reg (curr_static_id->operand[i].type, mode, op,
5349 : rclass, NULL, false, false, "elimination sum",
5350 : &new_reg))
5351 4424 : lra_emit_move (new_reg, op);
5352 4424 : mem_pseudo = lra_create_new_reg (mode, NULL_RTX, NO_REGS,
5353 : NULL, "elimination sum mem");
5354 4424 : emit_insn (emit_spill_move (true, mem_pseudo, new_reg));
5355 4424 : before = end_sequence ();
5356 4424 : *curr_id->operand_loc[i] = mem_pseudo;
5357 4424 : lra_update_dup (curr_id, i);
5358 : }
5359 5238724 : else if (goal_alt_matched[i][0] == -1)
5360 : {
5361 3445598 : machine_mode mode;
5362 3445598 : rtx reg, *loc;
5363 3445598 : int hard_regno;
5364 3445598 : enum op_type type = curr_static_id->operand[i].type;
5365 :
5366 3445598 : loc = curr_id->operand_loc[i];
5367 3445598 : mode = curr_operand_mode[i];
5368 3445598 : if (GET_CODE (*loc) == SUBREG)
5369 : {
5370 98878 : reg = SUBREG_REG (*loc);
5371 98878 : poly_int64 byte = SUBREG_BYTE (*loc);
5372 98878 : if (REG_P (reg)
5373 : /* Strict_low_part requires reloading the register and not
5374 : just the subreg. Likewise for a strict subreg no wider
5375 : than a word for WORD_REGISTER_OPERATIONS targets. */
5376 98878 : && (curr_static_id->operand[i].strict_low
5377 98803 : || (!paradoxical_subreg_p (mode, GET_MODE (reg))
5378 96354 : && (hard_regno
5379 96354 : = get_try_hard_regno (REGNO (reg))) >= 0
5380 93948 : && (simplify_subreg_regno
5381 192826 : (hard_regno,
5382 93948 : GET_MODE (reg), byte, mode) < 0)
5383 0 : && (goal_alt[i] == NO_REGS
5384 0 : || (simplify_subreg_regno
5385 75 : (ira_class_hard_regs[goal_alt[i]][0],
5386 0 : GET_MODE (reg), byte, mode) >= 0)))
5387 98803 : || (partial_subreg_p (mode, GET_MODE (reg))
5388 98803 : && known_le (GET_MODE_SIZE (GET_MODE (reg)),
5389 : UNITS_PER_WORD)
5390 : && WORD_REGISTER_OPERATIONS))
5391 : /* Avoid the situation when there are no available hard regs
5392 : for the pseudo mode but there are ones for the subreg
5393 : mode: */
5394 98953 : && !(goal_alt[i] != NO_REGS
5395 75 : && REGNO (reg) >= FIRST_PSEUDO_REGISTER
5396 75 : && (prohibited_class_reg_set_mode_p
5397 75 : (goal_alt[i], reg_class_contents[goal_alt[i]],
5398 75 : GET_MODE (reg)))
5399 : && !(prohibited_class_reg_set_mode_p
5400 0 : (goal_alt[i], reg_class_contents[goal_alt[i]],
5401 : mode))))
5402 : {
5403 : /* An OP_INOUT is required when reloading a subreg of a
5404 : mode wider than a word to ensure that data beyond the
5405 : word being reloaded is preserved. Also automatically
5406 : ensure that strict_low_part reloads are made into
5407 : OP_INOUT which should already be true from the backend
5408 : constraints. */
5409 75 : if (type == OP_OUT
5410 75 : && (curr_static_id->operand[i].strict_low
5411 0 : || read_modify_subreg_p (*loc)))
5412 : type = OP_INOUT;
5413 75 : loc = &SUBREG_REG (*loc);
5414 75 : mode = GET_MODE (*loc);
5415 : }
5416 : }
5417 3445598 : old = *loc;
5418 3445598 : if (get_reload_reg (type, mode, old, goal_alt[i],
5419 : &goal_alt_exclude_start_hard_regs[i],
5420 3445598 : loc != curr_id->operand_loc[i],
5421 3445598 : curr_static_id->operand_alternative
5422 3445598 : [goal_alt_number * n_operands + i].earlyclobber,
5423 : "", &new_reg)
5424 3445598 : && type != OP_OUT)
5425 : {
5426 2448933 : push_to_sequence (before);
5427 2448933 : lra_emit_move (new_reg, old);
5428 2448933 : before = end_sequence ();
5429 : }
5430 3445598 : *loc = new_reg;
5431 3445598 : if (type != OP_IN
5432 995361 : && find_reg_note (curr_insn, REG_UNUSED, old) == NULL_RTX
5433 : /* OLD can be an equivalent constant here. */
5434 969363 : && !CONSTANT_P (old)
5435 : /* No need to write back anything for a scratch. */
5436 969363 : && GET_CODE (old) != SCRATCH
5437 4414961 : && (!REG_P(old) || !ira_former_scratch_p (REGNO (old))))
5438 : {
5439 969363 : start_sequence ();
5440 969363 : lra_emit_move (type == OP_INOUT ? copy_rtx (old) : old, new_reg);
5441 969363 : emit_insn (after);
5442 969363 : after = end_sequence ();
5443 969363 : *loc = new_reg;
5444 : }
5445 3445598 : for (j = 0; j < goal_alt_dont_inherit_ops_num; j++)
5446 620 : if (goal_alt_dont_inherit_ops[j] == i)
5447 : {
5448 620 : lra_set_regno_unique_value (REGNO (new_reg));
5449 620 : break;
5450 : }
5451 3445598 : lra_update_dup (curr_id, i);
5452 : }
5453 1793126 : else if (curr_static_id->operand[i].type == OP_IN
5454 1793126 : && (curr_static_id->operand[goal_alt_matched[i][0]].type
5455 : == OP_OUT
5456 0 : || (curr_static_id->operand[goal_alt_matched[i][0]].type
5457 : == OP_INOUT
5458 0 : && (operands_match_p
5459 0 : (*curr_id->operand_loc[i],
5460 0 : *curr_id->operand_loc[goal_alt_matched[i][0]],
5461 : -1)))))
5462 : {
5463 : /* generate reloads for input and matched outputs. */
5464 18067 : match_inputs[0] = i;
5465 18067 : match_inputs[1] = -1;
5466 18067 : match_reload (goal_alt_matched[i][0], match_inputs, outputs,
5467 : goal_alt[i], &goal_alt_exclude_start_hard_regs[i],
5468 : &before, &after,
5469 18067 : curr_static_id->operand_alternative
5470 18067 : [goal_alt_number * n_operands + goal_alt_matched[i][0]]
5471 18067 : .earlyclobber);
5472 : }
5473 1775059 : else if ((curr_static_id->operand[i].type == OP_OUT
5474 1 : || (curr_static_id->operand[i].type == OP_INOUT
5475 1 : && (operands_match_p
5476 1 : (*curr_id->operand_loc[i],
5477 1 : *curr_id->operand_loc[goal_alt_matched[i][0]],
5478 : -1))))
5479 1775060 : && (curr_static_id->operand[goal_alt_matched[i][0]].type
5480 : == OP_IN))
5481 : /* Generate reloads for output and matched inputs. */
5482 1775059 : match_reload (i, goal_alt_matched[i], outputs, goal_alt[i],
5483 : &goal_alt_exclude_start_hard_regs[i], &before, &after,
5484 1775059 : curr_static_id->operand_alternative
5485 1775059 : [goal_alt_number * n_operands + i].earlyclobber);
5486 0 : else if (curr_static_id->operand[i].type == OP_IN
5487 0 : && (curr_static_id->operand[goal_alt_matched[i][0]].type
5488 : == OP_IN))
5489 : {
5490 : /* Generate reloads for matched inputs. */
5491 0 : match_inputs[0] = i;
5492 0 : for (j = 0; (k = goal_alt_matched[i][j]) >= 0; j++)
5493 0 : match_inputs[j + 1] = k;
5494 0 : match_inputs[j + 1] = -1;
5495 0 : match_reload (-1, match_inputs, outputs, goal_alt[i],
5496 : &goal_alt_exclude_start_hard_regs[i],
5497 : &before, &after, false);
5498 : }
5499 : else
5500 : /* We must generate code in any case when function
5501 : process_alt_operands decides that it is possible. */
5502 0 : gcc_unreachable ();
5503 :
5504 5243220 : if (optional_p)
5505 : {
5506 637400 : rtx reg = op;
5507 :
5508 637400 : lra_assert (REG_P (reg));
5509 637400 : regno = REGNO (reg);
5510 637400 : op = *curr_id->operand_loc[i]; /* Substitution. */
5511 637400 : if (GET_CODE (op) == SUBREG)
5512 0 : op = SUBREG_REG (op);
5513 637400 : gcc_assert (REG_P (op) && (int) REGNO (op) >= new_regno_start);
5514 637400 : bitmap_set_bit (&lra_optional_reload_pseudos, REGNO (op));
5515 637400 : lra_reg_info[REGNO (op)].restore_rtx = reg;
5516 637400 : if (lra_dump_file != NULL)
5517 2 : fprintf (lra_dump_file,
5518 : " Making reload reg %d for reg %d optional\n",
5519 : REGNO (op), regno);
5520 : }
5521 : }
5522 :
5523 : /* After the dust has settled, collect and attach dependent filters. */
5524 81998868 : process_dependent_filters ();
5525 :
5526 77510435 : if (before != NULL_RTX || after != NULL_RTX
5527 158683628 : || max_regno_before != max_reg_num ())
5528 5340334 : change_p = true;
5529 81998868 : if (change_p)
5530 : {
5531 6370128 : lra_update_operator_dups (curr_id);
5532 : /* Something changes -- process the insn. */
5533 6370128 : lra_update_insn_regno_info (curr_insn);
5534 6370128 : if (asm_noperands (PATTERN (curr_insn)) >= 0
5535 6370128 : && ++curr_id->asm_reloads_num >= FIRST_PSEUDO_REGISTER)
5536 : /* Most probably there are no enough registers to satisfy asm insn: */
5537 : {
5538 5 : lra_asm_insn_error (curr_insn);
5539 5 : return change_p;
5540 : }
5541 : }
5542 81998863 : if (goal_alt_out_sp_reload_p)
5543 : {
5544 : /* We have an output stack pointer reload -- update sp offset: */
5545 0 : rtx set;
5546 0 : bool done_p = false;
5547 0 : poly_int64 sp_offset = curr_id->sp_offset;
5548 0 : for (rtx_insn *insn = after; insn != NULL_RTX; insn = NEXT_INSN (insn))
5549 0 : if ((set = single_set (insn)) != NULL_RTX
5550 0 : && SET_DEST (set) == stack_pointer_rtx)
5551 : {
5552 0 : lra_assert (!done_p);
5553 0 : done_p = true;
5554 0 : curr_id->sp_offset = 0;
5555 0 : lra_insn_recog_data_t id = lra_get_insn_recog_data (insn);
5556 0 : id->sp_offset = sp_offset;
5557 0 : if (lra_dump_file != NULL)
5558 0 : fprintf (lra_dump_file,
5559 : " Moving sp offset from insn %u to %u\n",
5560 0 : INSN_UID (curr_insn), INSN_UID (insn));
5561 : }
5562 0 : lra_assert (done_p);
5563 : }
5564 81998863 : int const_regno = -1;
5565 81998863 : rtx set;
5566 81998863 : rtx_insn *prev, *const_insn = NULL;
5567 4488432 : if (before != NULL_RTX && (prev = PREV_INSN (curr_insn)) != NULL_RTX
5568 86487295 : && (set = single_set (prev)) != NULL_RTX && CONSTANT_P (SET_SRC (set)))
5569 : {
5570 342398 : rtx reg = SET_DEST (set);
5571 342398 : if (GET_CODE (reg) == SUBREG)
5572 10651 : reg = SUBREG_REG (reg);
5573 : /* Consider only reload insns as we don't want to change the order
5574 : created by previous optimizations. */
5575 249010 : if (REG_P (reg) && (int) REGNO (reg) >= lra_new_regno_start
5576 344037 : && bitmap_bit_p (&lra_reg_info[REGNO (reg)].insn_bitmap,
5577 1639 : INSN_UID (curr_insn)))
5578 : {
5579 1116 : const_regno = REGNO (reg);
5580 1116 : const_insn = prev;
5581 : }
5582 : }
5583 81998863 : if (asm_noperands (PATTERN (curr_insn)) >= 0)
5584 : {
5585 : /* Asm can have a lot of operands. To guarantee their assignment,
5586 : postpone processing the reload insns until the reload pseudos are
5587 : assigned. */
5588 47385 : postpone_insns (before);
5589 47385 : postpone_insns (after);
5590 : }
5591 81998863 : lra_process_new_insns (curr_insn, before, after,
5592 : "Inserting insn reload", true);
5593 81998863 : if (const_regno >= 0) {
5594 2232 : bool move_p = true;
5595 2232 : for (rtx_insn *insn = before; insn != curr_insn; insn = NEXT_INSN (insn))
5596 1116 : if (bitmap_bit_p (&lra_reg_info[const_regno].insn_bitmap,
5597 1116 : INSN_UID (insn)))
5598 : {
5599 : move_p = false;
5600 : break;
5601 : }
5602 1116 : if (move_p)
5603 : {
5604 1116 : reorder_insns_nobb (const_insn, const_insn, PREV_INSN (curr_insn));
5605 1116 : if (lra_dump_file != NULL)
5606 : {
5607 0 : dump_insn_slim (lra_dump_file, const_insn);
5608 0 : fprintf (lra_dump_file,
5609 : " to decrease reg pressure, it is moved before:\n");
5610 0 : dump_insn_slim (lra_dump_file, curr_insn);
5611 : }
5612 : }
5613 : }
5614 : return change_p;
5615 : }
5616 :
5617 : /* Return true if INSN satisfies all constraints. In other words, no
5618 : reload insns are needed. */
5619 : bool
5620 3420 : lra_constrain_insn (rtx_insn *insn)
5621 : {
5622 3420 : int saved_new_regno_start = new_regno_start;
5623 3420 : int saved_new_insn_uid_start = new_insn_uid_start;
5624 3420 : bool change_p;
5625 :
5626 3420 : curr_insn = insn;
5627 3420 : curr_id = lra_get_insn_recog_data (curr_insn);
5628 3420 : curr_static_id = curr_id->insn_static_data;
5629 3420 : new_insn_uid_start = get_max_uid ();
5630 3420 : new_regno_start = max_reg_num ();
5631 3420 : change_p = curr_insn_transform (true);
5632 3420 : new_regno_start = saved_new_regno_start;
5633 3420 : new_insn_uid_start = saved_new_insn_uid_start;
5634 3420 : return ! change_p;
5635 : }
5636 :
5637 : /* Return true if X is in LIST. */
5638 : static bool
5639 1417172 : in_list_p (rtx x, rtx list)
5640 : {
5641 2428843 : for (; list != NULL_RTX; list = XEXP (list, 1))
5642 1326896 : if (XEXP (list, 0) == x)
5643 : return true;
5644 : return false;
5645 : }
5646 :
5647 : /* Return true if X contains an allocatable hard register (if
5648 : HARD_REG_P) or a (spilled if SPILLED_P) pseudo. */
5649 : static bool
5650 7830014 : contains_reg_p (rtx x, bool hard_reg_p, bool spilled_p)
5651 : {
5652 7830014 : int i, j;
5653 7830014 : const char *fmt;
5654 7830014 : enum rtx_code code;
5655 :
5656 7830014 : code = GET_CODE (x);
5657 7830014 : if (REG_P (x))
5658 : {
5659 1558229 : int regno = REGNO (x);
5660 1558229 : HARD_REG_SET alloc_regs;
5661 :
5662 1558229 : if (hard_reg_p)
5663 : {
5664 490785 : if (regno >= FIRST_PSEUDO_REGISTER)
5665 145819 : regno = lra_get_regno_hard_regno (regno);
5666 490785 : if (regno < 0)
5667 : return false;
5668 490785 : alloc_regs = ~lra_no_alloc_regs;
5669 490785 : return overlaps_hard_reg_set_p (alloc_regs, GET_MODE (x), regno);
5670 : }
5671 : else
5672 : {
5673 1067444 : if (regno < FIRST_PSEUDO_REGISTER)
5674 : return false;
5675 342340 : if (! spilled_p)
5676 : return true;
5677 180879 : return lra_get_regno_hard_regno (regno) < 0;
5678 : }
5679 : }
5680 6271785 : fmt = GET_RTX_FORMAT (code);
5681 15452453 : for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
5682 : {
5683 9778825 : if (fmt[i] == 'e')
5684 : {
5685 4239309 : if (contains_reg_p (XEXP (x, i), hard_reg_p, spilled_p))
5686 : return true;
5687 : }
5688 5539516 : else if (fmt[i] == 'E')
5689 : {
5690 1462641 : for (j = XVECLEN (x, i) - 1; j >= 0; j--)
5691 1337456 : if (contains_reg_p (XVECEXP (x, i, j), hard_reg_p, spilled_p))
5692 : return true;
5693 : }
5694 : }
5695 : return false;
5696 : }
5697 :
5698 : /* Process all regs in location *LOC and change them on equivalent
5699 : substitution. Return true if any change was done. */
5700 : static bool
5701 3328 : loc_equivalence_change_p (rtx *loc)
5702 : {
5703 3328 : rtx subst, reg, x = *loc;
5704 3328 : bool result = false;
5705 3328 : enum rtx_code code = GET_CODE (x);
5706 3328 : const char *fmt;
5707 3328 : int i, j;
5708 :
5709 3328 : if (code == SUBREG)
5710 : {
5711 20 : reg = SUBREG_REG (x);
5712 20 : if ((subst = get_equiv_with_elimination (reg, curr_insn)) != reg
5713 20 : && GET_MODE (subst) == VOIDmode)
5714 : {
5715 : /* We cannot reload debug location. Simplify subreg here
5716 : while we know the inner mode. */
5717 0 : *loc = simplify_gen_subreg (GET_MODE (x), subst,
5718 0 : GET_MODE (reg), SUBREG_BYTE (x));
5719 0 : return true;
5720 : }
5721 : }
5722 3328 : if (code == REG && (subst = get_equiv_with_elimination (x, curr_insn)) != x)
5723 : {
5724 8 : *loc = subst;
5725 8 : return true;
5726 : }
5727 :
5728 : /* Scan all the operand sub-expressions. */
5729 3320 : fmt = GET_RTX_FORMAT (code);
5730 8120 : for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
5731 : {
5732 4800 : if (fmt[i] == 'e')
5733 2561 : result = loc_equivalence_change_p (&XEXP (x, i)) || result;
5734 2239 : else if (fmt[i] == 'E')
5735 270 : for (j = XVECLEN (x, i) - 1; j >= 0; j--)
5736 200 : result
5737 210 : = loc_equivalence_change_p (&XVECEXP (x, i, j)) || result;
5738 : }
5739 : return result;
5740 : }
5741 :
5742 : /* Similar to loc_equivalence_change_p, but for use as
5743 : simplify_replace_fn_rtx callback. DATA is insn for which the
5744 : elimination is done. If it null we don't do the elimination. */
5745 : static rtx
5746 42011546 : loc_equivalence_callback (rtx loc, const_rtx, void *data)
5747 : {
5748 42011546 : if (!REG_P (loc))
5749 : return NULL_RTX;
5750 :
5751 10789404 : rtx subst = (data == NULL
5752 10789404 : ? get_equiv (loc) : get_equiv_with_elimination (loc, (rtx_insn *) data));
5753 10789404 : if (subst != loc)
5754 38165 : return subst;
5755 :
5756 : return NULL_RTX;
5757 : }
5758 :
5759 : /* Maximum number of generated reload insns per an insn. It is for
5760 : preventing this pass cycling in a bug case. */
5761 : #define MAX_RELOAD_INSNS_NUMBER LRA_MAX_INSN_RELOADS
5762 :
5763 : /* The current iteration number of this LRA pass. */
5764 : int lra_constraint_iter;
5765 :
5766 : /* True if we should during assignment sub-pass check assignment
5767 : correctness for all pseudos and spill some of them to correct
5768 : conflicts. It can be necessary when we substitute equiv which
5769 : needs checking register allocation correctness because the
5770 : equivalent value contains allocatable hard registers, or when we
5771 : restore multi-register pseudo, or when we change the insn code and
5772 : its operand became INOUT operand when it was IN one before. */
5773 : bool check_and_force_assignment_correctness_p;
5774 :
5775 : /* Return true if REGNO is referenced in more than one block. */
5776 : static bool
5777 155427 : multi_block_pseudo_p (int regno)
5778 : {
5779 155427 : basic_block bb = NULL;
5780 155427 : unsigned int uid;
5781 155427 : bitmap_iterator bi;
5782 :
5783 155427 : if (regno < FIRST_PSEUDO_REGISTER)
5784 : return false;
5785 :
5786 476334 : EXECUTE_IF_SET_IN_BITMAP (&lra_reg_info[regno].insn_bitmap, 0, uid, bi)
5787 325727 : if (bb == NULL)
5788 155427 : bb = BLOCK_FOR_INSN (lra_insn_recog_data[uid]->insn);
5789 170300 : else if (BLOCK_FOR_INSN (lra_insn_recog_data[uid]->insn) != bb)
5790 : return true;
5791 : return false;
5792 : }
5793 :
5794 : /* Return true if LIST contains a deleted insn. */
5795 : static bool
5796 754216 : contains_deleted_insn_p (rtx_insn_list *list)
5797 : {
5798 1435644 : for (; list != NULL_RTX; list = list->next ())
5799 681428 : if (NOTE_P (list->insn ())
5800 681428 : && NOTE_KIND (list->insn ()) == NOTE_INSN_DELETED)
5801 : return true;
5802 : return false;
5803 : }
5804 :
5805 : /* Return true if X contains a pseudo dying in INSN. */
5806 : static bool
5807 2323418 : dead_pseudo_p (rtx x, rtx_insn *insn)
5808 : {
5809 2323418 : int i, j;
5810 2323418 : const char *fmt;
5811 2323418 : enum rtx_code code;
5812 :
5813 2323418 : if (REG_P (x))
5814 520994 : return (insn != NULL_RTX
5815 520994 : && find_regno_note (insn, REG_DEAD, REGNO (x)) != NULL_RTX);
5816 1802424 : code = GET_CODE (x);
5817 1802424 : fmt = GET_RTX_FORMAT (code);
5818 4608280 : for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
5819 : {
5820 2811861 : if (fmt[i] == 'e')
5821 : {
5822 1374630 : if (dead_pseudo_p (XEXP (x, i), insn))
5823 : return true;
5824 : }
5825 1437231 : else if (fmt[i] == 'E')
5826 : {
5827 293677 : for (j = XVECLEN (x, i) - 1; j >= 0; j--)
5828 268718 : if (dead_pseudo_p (XVECEXP (x, i, j), insn))
5829 : return true;
5830 : }
5831 : }
5832 : return false;
5833 : }
5834 :
5835 : /* Return true if INSN contains a dying pseudo in INSN right hand
5836 : side. */
5837 : static bool
5838 680070 : insn_rhs_dead_pseudo_p (rtx_insn *insn)
5839 : {
5840 680070 : rtx set = single_set (insn);
5841 :
5842 680070 : gcc_assert (set != NULL);
5843 680070 : return dead_pseudo_p (SET_SRC (set), insn);
5844 : }
5845 :
5846 : /* Return true if any init insn of REGNO contains a dying pseudo in
5847 : insn right hand side. */
5848 : static bool
5849 752858 : init_insn_rhs_dead_pseudo_p (int regno)
5850 : {
5851 752858 : rtx_insn_list *insns = ira_reg_equiv[regno].init_insns;
5852 :
5853 752858 : if (insns == NULL)
5854 : return false;
5855 1352639 : for (; insns != NULL_RTX; insns = insns->next ())
5856 680070 : if (insn_rhs_dead_pseudo_p (insns->insn ()))
5857 : return true;
5858 : return false;
5859 : }
5860 :
5861 : /* Return TRUE if REGNO has a reverse equivalence. The equivalence is
5862 : reverse only if we have one init insn with given REGNO as a
5863 : source. */
5864 : static bool
5865 754216 : reverse_equiv_p (int regno)
5866 : {
5867 754216 : rtx_insn_list *insns = ira_reg_equiv[regno].init_insns;
5868 754216 : rtx set;
5869 :
5870 754216 : if (insns == NULL)
5871 : return false;
5872 681428 : if (! INSN_P (insns->insn ())
5873 1362856 : || insns->next () != NULL)
5874 : return false;
5875 681428 : if ((set = single_set (insns->insn ())) == NULL_RTX)
5876 : return false;
5877 681428 : return REG_P (SET_SRC (set)) && (int) REGNO (SET_SRC (set)) == regno;
5878 : }
5879 :
5880 : /* Return TRUE if REGNO was reloaded in an equivalence init insn. We
5881 : call this function only for non-reverse equivalence. */
5882 : static bool
5883 745357 : contains_reloaded_insn_p (int regno)
5884 : {
5885 745357 : rtx set;
5886 745357 : rtx_insn_list *list = ira_reg_equiv[regno].init_insns;
5887 :
5888 1417924 : for (; list != NULL; list = list->next ())
5889 672569 : if ((set = single_set (list->insn ())) == NULL_RTX
5890 672569 : || ! REG_P (SET_DEST (set))
5891 1345138 : || (int) REGNO (SET_DEST (set)) != regno)
5892 : return true;
5893 : return false;
5894 : }
5895 :
5896 : /* Try combine secondary memory reload insn FROM for insn TO into TO insn.
5897 : FROM should be a load insn (usually a secondary memory reload insn). Return
5898 : TRUE in case of success. */
5899 : static bool
5900 7549553 : combine_reload_insn (rtx_insn *from, rtx_insn *to)
5901 : {
5902 7549553 : bool ok_p;
5903 7549553 : rtx_insn *saved_insn;
5904 7549553 : rtx set, from_reg, to_reg, op;
5905 7549553 : enum reg_class to_class, from_class;
5906 7549553 : int n, nop;
5907 7549553 : signed char changed_nops[MAX_RECOG_OPERANDS + 1];
5908 :
5909 : /* Check conditions for second memory reload and original insn: */
5910 7549553 : if ((targetm.secondary_memory_needed
5911 : == hook_bool_mode_reg_class_t_reg_class_t_false)
5912 7549553 : || NEXT_INSN (from) != to
5913 4491652 : || !NONDEBUG_INSN_P (to)
5914 12041205 : || CALL_P (to))
5915 : return false;
5916 :
5917 4486265 : lra_insn_recog_data_t id = lra_get_insn_recog_data (to);
5918 4486265 : struct lra_static_insn_data *static_id = id->insn_static_data;
5919 :
5920 4486265 : if (id->used_insn_alternative == LRA_UNKNOWN_ALT
5921 4486265 : || (set = single_set (from)) == NULL_RTX)
5922 : return false;
5923 4454080 : from_reg = SET_DEST (set);
5924 4454080 : to_reg = SET_SRC (set);
5925 : /* Ignore optional reloads: */
5926 4377089 : if (! REG_P (from_reg) || ! REG_P (to_reg)
5927 7411754 : || bitmap_bit_p (&lra_optional_reload_pseudos, REGNO (from_reg)))
5928 : return false;
5929 2408279 : to_class = lra_get_allocno_class (REGNO (to_reg));
5930 2408279 : from_class = lra_get_allocno_class (REGNO (from_reg));
5931 : /* Check that reload insn is a load: */
5932 2408279 : if (to_class != NO_REGS || from_class == NO_REGS)
5933 : return false;
5934 47713 : for (n = nop = 0; nop < static_id->n_operands; nop++)
5935 : {
5936 34435 : if (static_id->operand[nop].type != OP_IN)
5937 12270 : continue;
5938 22165 : op = *id->operand_loc[nop];
5939 22165 : if (!REG_P (op) || REGNO (op) != REGNO (from_reg))
5940 9079 : continue;
5941 13086 : *id->operand_loc[nop] = to_reg;
5942 13086 : changed_nops[n++] = nop;
5943 : }
5944 13278 : changed_nops[n] = -1;
5945 13278 : lra_update_dups (id, changed_nops);
5946 13278 : lra_update_insn_regno_info (to);
5947 13278 : ok_p = recog_memoized (to) >= 0;
5948 13278 : if (ok_p)
5949 : {
5950 : /* Check that combined insn does not need any reloads: */
5951 13259 : saved_insn = curr_insn;
5952 13259 : curr_insn = to;
5953 13259 : curr_id = lra_get_insn_recog_data (curr_insn);
5954 13259 : curr_static_id = curr_id->insn_static_data;
5955 13259 : for (bool swapped_p = false;;)
5956 : {
5957 15409 : ok_p = !curr_insn_transform (true);
5958 15409 : if (ok_p || curr_static_id->commutative < 0)
5959 : break;
5960 4300 : swap_operands (curr_static_id->commutative);
5961 4300 : if (lra_dump_file != NULL)
5962 : {
5963 0 : fprintf (lra_dump_file,
5964 : " Swapping %scombined insn operands:\n",
5965 : swapped_p ? "back " : "");
5966 0 : dump_insn_slim (lra_dump_file, to);
5967 : }
5968 4300 : if (swapped_p)
5969 : break;
5970 : swapped_p = true;
5971 : }
5972 13259 : curr_insn = saved_insn;
5973 13259 : curr_id = lra_get_insn_recog_data (curr_insn);
5974 13259 : curr_static_id = curr_id->insn_static_data;
5975 : }
5976 13278 : if (ok_p)
5977 : {
5978 3685 : id->used_insn_alternative = -1;
5979 3685 : lra_push_insn_and_update_insn_regno_info (to);
5980 3685 : if (lra_dump_file != NULL)
5981 : {
5982 0 : fprintf (lra_dump_file, " Use combined insn:\n");
5983 0 : dump_insn_slim (lra_dump_file, to);
5984 : }
5985 : return true;
5986 : }
5987 9593 : if (lra_dump_file != NULL)
5988 : {
5989 0 : fprintf (lra_dump_file, " Failed combined insn:\n");
5990 0 : dump_insn_slim (lra_dump_file, to);
5991 : }
5992 19456 : for (int i = 0; i < n; i++)
5993 : {
5994 9863 : nop = changed_nops[i];
5995 9863 : *id->operand_loc[nop] = from_reg;
5996 : }
5997 9593 : lra_update_dups (id, changed_nops);
5998 9593 : lra_update_insn_regno_info (to);
5999 9593 : if (lra_dump_file != NULL)
6000 : {
6001 0 : fprintf (lra_dump_file, " Restoring insn after failed combining:\n");
6002 0 : dump_insn_slim (lra_dump_file, to);
6003 : }
6004 : return false;
6005 : }
6006 :
6007 : static bool
6008 530459 : virtual_reg_p (const_rtx reg)
6009 : {
6010 0 : return (VIRTUAL_REGISTER_P (reg)
6011 530459 : || (REGNO(reg) == ARG_POINTER_REGNUM
6012 : && !HARD_FRAME_POINTER_IS_ARG_POINTER)
6013 985352 : || (REGNO(reg) == FRAME_POINTER_REGNUM
6014 0 : && !HARD_FRAME_POINTER_IS_FRAME_POINTER));
6015 : }
6016 :
6017 : /* Return true if X contains a virtual register. */
6018 : static bool
6019 743366 : contains_virtual_reg_p (rtx x)
6020 : {
6021 743366 : subrtx_iterator::array_type array;
6022 2117022 : FOR_EACH_SUBRTX (iter, array, x, NONCONST)
6023 1904115 : if (REG_P (*iter) && virtual_reg_p (*iter))
6024 361003 : return true;
6025 382363 : return false;
6026 743366 : }
6027 :
6028 : /* Return true if pseudo REGNO is an operand of an incdec rtx in any of its
6029 : insns. */
6030 : static bool
6031 361003 : reg_has_incdec_p (int regno)
6032 : {
6033 361003 : unsigned int uid;
6034 361003 : bitmap_iterator bi;
6035 1827867 : EXECUTE_IF_SET_IN_BITMAP (&lra_reg_info[regno].insn_bitmap, 0, uid, bi)
6036 : {
6037 1466864 : rtx_insn *insn = lra_insn_recog_data[uid]->insn;
6038 1466864 : if (!NONDEBUG_INSN_P (insn))
6039 25900 : continue;
6040 1440964 : subrtx_iterator::array_type array;
6041 8462578 : FOR_EACH_SUBRTX (iter, array, PATTERN (insn), NONCONST)
6042 : {
6043 7021614 : const_rtx x = *iter;
6044 7021614 : if ((GET_CODE (x) == PRE_INC || GET_CODE (x) == PRE_DEC
6045 6917295 : || GET_CODE (x) == POST_INC || GET_CODE (x) == POST_DEC
6046 6917295 : || GET_CODE (x) == PRE_MODIFY || GET_CODE (x) == POST_MODIFY)
6047 105682 : && REG_P (XEXP (x, 0))
6048 7127296 : && REGNO (XEXP (x, 0)) == (unsigned int) regno)
6049 0 : return true;
6050 : }
6051 1440964 : }
6052 : return false;
6053 : }
6054 :
6055 : /* Entry function of LRA constraint pass. Return true if the
6056 : constraint pass did change the code. */
6057 : bool
6058 3331922 : lra_constraints (bool first_p)
6059 : {
6060 3331922 : bool changed_p;
6061 3331922 : int i, hard_regno, new_insns_num;
6062 3331922 : unsigned int min_len, new_min_len, uid;
6063 3331922 : rtx set, x, reg, nosubreg_dest;
6064 3331922 : rtx_insn *original_insn;
6065 3331922 : basic_block last_bb;
6066 3331922 : bitmap_iterator bi;
6067 :
6068 3331922 : lra_constraint_iter++;
6069 3331922 : if (lra_dump_file != NULL)
6070 193 : fprintf (lra_dump_file, "\n********** Local #%d: **********\n\n",
6071 : lra_constraint_iter);
6072 3331922 : changed_p = false;
6073 3331922 : if (pic_offset_table_rtx
6074 3331922 : && REGNO (pic_offset_table_rtx) >= FIRST_PSEUDO_REGISTER)
6075 105338 : check_and_force_assignment_correctness_p = true;
6076 3226584 : else if (first_p)
6077 : /* On the first iteration we should check IRA assignment
6078 : correctness. In rare cases, the assignments can be wrong as
6079 : early clobbers operands are ignored in IRA or usages of
6080 : paradoxical sub-registers are not taken into account by
6081 : IRA. */
6082 1490589 : check_and_force_assignment_correctness_p = true;
6083 3331922 : new_insn_uid_start = get_max_uid ();
6084 3331922 : new_regno_start = first_p ? lra_constraint_new_regno_start : max_reg_num ();
6085 : /* Mark used hard regs for target stack size calculations. */
6086 214675568 : for (i = FIRST_PSEUDO_REGISTER; i < new_regno_start; i++)
6087 211343646 : if (lra_reg_info[i].nrefs != 0
6088 311588461 : && (hard_regno = lra_get_regno_hard_regno (i)) >= 0)
6089 : {
6090 96205779 : int j, nregs;
6091 :
6092 96205779 : nregs = hard_regno_nregs (hard_regno, lra_reg_info[i].biggest_mode);
6093 195669453 : for (j = 0; j < nregs; j++)
6094 99463674 : df_set_regs_ever_live (hard_regno + j, true);
6095 : }
6096 : /* Do elimination before the equivalence processing as we can spill
6097 : some pseudos during elimination. */
6098 3331922 : lra_eliminate (false, first_p);
6099 3331922 : auto_bitmap equiv_insn_bitmap (®_obstack);
6100 :
6101 : /* Register elimination can create new pseudos via the addptr pattern,
6102 : so make sure the equivalency tables are resized appropriately. */
6103 3331922 : ira_expand_reg_equiv ();
6104 218007490 : for (i = FIRST_PSEUDO_REGISTER; i < new_regno_start; i++)
6105 211343646 : if (lra_reg_info[i].nrefs != 0)
6106 : {
6107 100244815 : ira_reg_equiv[i].profitable_p = true;
6108 100244815 : reg = regno_reg_rtx[i];
6109 100244815 : if (lra_get_regno_hard_regno (i) < 0 && (x = get_equiv (reg)) != reg)
6110 : {
6111 765070 : bool pseudo_p = contains_reg_p (x, false, false);
6112 :
6113 : /* After RTL transformation, we cannot guarantee that
6114 : pseudo in the substitution was not reloaded which might
6115 : make equivalence invalid. For example, in reverse
6116 : equiv of p0
6117 :
6118 : p0 <- ...
6119 : ...
6120 : equiv_mem <- p0
6121 :
6122 : the memory address register was reloaded before the 2nd
6123 : insn. */
6124 765070 : if ((! first_p && pseudo_p)
6125 : /* We don't use DF for compilation speed sake. So it
6126 : is problematic to update live info when we use an
6127 : equivalence containing pseudos in more than one
6128 : BB. */
6129 759036 : || (pseudo_p && multi_block_pseudo_p (i))
6130 : /* If an init insn was deleted for some reason, cancel
6131 : the equiv. We could update the equiv insns after
6132 : transformations including an equiv insn deletion
6133 : but it is not worthy as such cases are extremely
6134 : rare. */
6135 754216 : || contains_deleted_insn_p (ira_reg_equiv[i].init_insns)
6136 : /* If it is not a reverse equivalence, we check that a
6137 : pseudo in rhs of the init insn is not dying in the
6138 : insn. Otherwise, the live info at the beginning of
6139 : the corresponding BB might be wrong after we
6140 : removed the insn. When the equiv can be a
6141 : constant, the right hand side of the init insn can
6142 : be a pseudo. */
6143 754216 : || (! reverse_equiv_p (i)
6144 752858 : && (init_insn_rhs_dead_pseudo_p (i)
6145 : /* If we reloaded the pseudo in an equivalence
6146 : init insn, we cannot remove the equiv init
6147 : insns and the init insns might write into
6148 : const memory in this case. */
6149 745357 : || contains_reloaded_insn_p (i)))
6150 : /* Prevent access beyond equivalent memory for
6151 : paradoxical subregs. */
6152 746713 : || (MEM_P (x)
6153 1188336 : && maybe_gt (GET_MODE_SIZE (lra_reg_info[i].biggest_mode),
6154 : GET_MODE_SIZE (GET_MODE (x))))
6155 745979 : || (pic_offset_table_rtx
6156 54271 : && ((CONST_POOL_OK_P (PSEUDO_REGNO_MODE (i), x)
6157 9462 : && (targetm.preferred_reload_class
6158 4731 : (x, lra_get_allocno_class (i)) == NO_REGS))
6159 52478 : || contains_symbol_ref_p (x)))
6160 : /* PR120165: An inc/dec changes the reg value, so we cannot
6161 : substitute the equiv which might contain virtual regs
6162 : requiring elimination. An insn with inc/dec can also change
6163 : the value of another reg (e.g. sp) against which we
6164 : eliminate. As we update elimination once per insn and an
6165 : inc/dec operand might require input and output reloads, we
6166 : can generate a wrong offset for a reload insn. */
6167 1508436 : || (contains_virtual_reg_p (x) && reg_has_incdec_p (i)))
6168 21704 : ira_reg_equiv[i].defined_p
6169 21704 : = ira_reg_equiv[i].caller_save_p = false;
6170 765070 : if (contains_reg_p (x, false, true))
6171 9235 : ira_reg_equiv[i].profitable_p = false;
6172 765070 : if (get_equiv (reg) != reg)
6173 738784 : bitmap_ior_into (equiv_insn_bitmap, &lra_reg_info[i].insn_bitmap);
6174 : }
6175 : }
6176 214675568 : for (i = FIRST_PSEUDO_REGISTER; i < new_regno_start; i++)
6177 211343646 : update_equiv (i);
6178 : /* We should add all insns containing pseudos which should be
6179 : substituted by their equivalences. */
6180 5803832 : EXECUTE_IF_SET_IN_BITMAP (equiv_insn_bitmap, 0, uid, bi)
6181 2471910 : lra_push_insn_by_uid (uid);
6182 3331922 : min_len = lra_insn_stack_length ();
6183 3331922 : new_insns_num = 0;
6184 3331922 : last_bb = NULL;
6185 3331922 : changed_p = false;
6186 3331922 : original_insn = NULL;
6187 173679319 : while ((new_min_len = lra_insn_stack_length ()) != 0)
6188 : {
6189 167015475 : curr_insn = lra_pop_insn ();
6190 167015475 : --new_min_len;
6191 167015475 : curr_bb = BLOCK_FOR_INSN (curr_insn);
6192 167015475 : if (curr_bb != last_bb)
6193 : {
6194 21090930 : last_bb = curr_bb;
6195 21090930 : bb_reload_num = lra_curr_reload_num;
6196 : }
6197 167015475 : if (min_len > new_min_len)
6198 : {
6199 : min_len = new_min_len;
6200 : new_insns_num = 0;
6201 : original_insn = curr_insn;
6202 : }
6203 7549553 : else if (combine_reload_insn (curr_insn, original_insn))
6204 : {
6205 3685 : continue;
6206 : }
6207 7545868 : if (new_insns_num > MAX_RELOAD_INSNS_NUMBER)
6208 0 : internal_error
6209 0 : ("maximum number of generated reload insns per insn achieved (%d)",
6210 : MAX_RELOAD_INSNS_NUMBER);
6211 167011790 : new_insns_num++;
6212 167011790 : if (DEBUG_INSN_P (curr_insn))
6213 : {
6214 : /* We need to check equivalence in debug insn and change
6215 : pseudo to the equivalent value if necessary. */
6216 55575490 : curr_id = lra_get_insn_recog_data (curr_insn);
6217 55575490 : if (bitmap_bit_p (equiv_insn_bitmap, INSN_UID (curr_insn)))
6218 : {
6219 29523 : rtx old = *curr_id->operand_loc[0];
6220 29523 : *curr_id->operand_loc[0]
6221 29523 : = simplify_replace_fn_rtx (old, NULL_RTX,
6222 : loc_equivalence_callback, curr_insn);
6223 29523 : if (old != *curr_id->operand_loc[0])
6224 : {
6225 : /* If we substitute pseudo by shared equivalence, we can fail
6226 : to update LRA reg info and this can result in many
6227 : unexpected consequences. So keep rtl unshared: */
6228 29523 : *curr_id->operand_loc[0]
6229 29523 : = copy_rtx (*curr_id->operand_loc[0]);
6230 29523 : lra_update_insn_regno_info (curr_insn);
6231 29523 : changed_p = true;
6232 : }
6233 : }
6234 : }
6235 111436300 : else if (INSN_P (curr_insn))
6236 : {
6237 110362565 : if ((set = single_set (curr_insn)) != NULL_RTX)
6238 : {
6239 104831194 : nosubreg_dest = SET_DEST (set);
6240 : /* The equivalence pseudo could be set up as SUBREG in a
6241 : case when it is a call restore insn in a mode
6242 : different from the pseudo mode. */
6243 104831194 : if (GET_CODE (nosubreg_dest) == SUBREG)
6244 1216878 : nosubreg_dest = SUBREG_REG (nosubreg_dest);
6245 105554303 : if ((REG_P (nosubreg_dest)
6246 77588306 : && (x = get_equiv (nosubreg_dest)) != nosubreg_dest
6247 : /* Remove insns which set up a pseudo whose value
6248 : cannot be changed. Such insns might be not in
6249 : init_insns because we don't update equiv data
6250 : during insn transformations.
6251 :
6252 : As an example, let suppose that a pseudo got
6253 : hard register and on the 1st pass was not
6254 : changed to equivalent constant. We generate an
6255 : additional insn setting up the pseudo because of
6256 : secondary memory movement. Then the pseudo is
6257 : spilled and we use the equiv constant. In this
6258 : case we should remove the additional insn and
6259 : this insn is not init_insns list. */
6260 742718 : && (! MEM_P (x) || MEM_READONLY_P (x)
6261 : /* Check that this is actually an insn setting
6262 : up the equivalence. */
6263 334834 : || in_list_p (curr_insn,
6264 334834 : ira_reg_equiv
6265 334834 : [REGNO (nosubreg_dest)].init_insns)))
6266 181697683 : || (((x = get_equiv (SET_SRC (set))) != SET_SRC (set))
6267 2164676 : && in_list_p (curr_insn,
6268 1082338 : ira_reg_equiv
6269 1082338 : [REGNO (SET_SRC (set))].init_insns)
6270 : /* This is a reverse equivalence to memory (see ira.cc)
6271 : in store insn. We can reload all the destination and
6272 : have an output reload which is a store to memory. If
6273 : we just remove the insn, we will have the output
6274 : reload storing an undefined value to the memory.
6275 : Check that we did not reload the memory to prevent a
6276 : wrong code generation. We could implement using the
6277 : equivalence still in such case but doing this is not
6278 : worth the efforts as such case is very rare. */
6279 1292 : && MEM_P (nosubreg_dest)))
6280 : {
6281 : /* This is equiv init insn of pseudo which did not get a
6282 : hard register -- remove the insn. */
6283 723109 : if (lra_dump_file != NULL)
6284 : {
6285 9 : fprintf (lra_dump_file,
6286 : " Removing equiv init insn %i (freq=%d)\n",
6287 3 : INSN_UID (curr_insn),
6288 6 : REG_FREQ_FROM_BB (BLOCK_FOR_INSN (curr_insn)));
6289 3 : dump_insn_slim (lra_dump_file, curr_insn);
6290 : }
6291 723109 : if (contains_reg_p (x, true, false))
6292 145819 : check_and_force_assignment_correctness_p = true;
6293 723109 : lra_set_insn_deleted (curr_insn);
6294 723109 : continue;
6295 : }
6296 : }
6297 109639456 : curr_id = lra_get_insn_recog_data (curr_insn);
6298 109639456 : curr_static_id = curr_id->insn_static_data;
6299 109639456 : init_curr_insn_input_reloads ();
6300 109639456 : init_curr_operand_mode ();
6301 109639456 : if (curr_insn_transform (false))
6302 : changed_p = true;
6303 : /* Check non-transformed insns too for equiv change as USE
6304 : or CLOBBER don't need reloads but can contain pseudos
6305 : being changed on their equivalences. */
6306 103250173 : else if (bitmap_bit_p (equiv_insn_bitmap, INSN_UID (curr_insn))
6307 103250173 : && loc_equivalence_change_p (&PATTERN (curr_insn)))
6308 : {
6309 8 : lra_update_insn_regno_info (curr_insn);
6310 8 : lra_push_insn_by_uid (INSN_UID (curr_insn));
6311 8 : changed_p = true;
6312 : }
6313 : }
6314 : }
6315 :
6316 : /* If we used a new hard regno, changed_p should be true because the
6317 : hard reg is assigned to a new pseudo. */
6318 3331922 : if (flag_checking && !changed_p)
6319 : {
6320 137903431 : for (i = FIRST_PSEUDO_REGISTER; i < new_regno_start; i++)
6321 135208395 : if (lra_reg_info[i].nrefs != 0
6322 197275262 : && (hard_regno = lra_get_regno_hard_regno (i)) >= 0)
6323 : {
6324 60576405 : int j, nregs = hard_regno_nregs (hard_regno,
6325 60576405 : PSEUDO_REGNO_MODE (i));
6326 :
6327 123294303 : for (j = 0; j < nregs; j++)
6328 62717898 : lra_assert (df_regs_ever_live_p (hard_regno + j));
6329 : }
6330 : }
6331 2695076 : if (changed_p)
6332 636849 : lra_dump_insns_if_possible ("changed func after local");
6333 3331922 : return changed_p;
6334 3331922 : }
6335 :
6336 : static void initiate_invariants (void);
6337 : static void finish_invariants (void);
6338 :
6339 : /* Initiate the LRA constraint pass. It is done once per
6340 : function. */
6341 : void
6342 1531123 : lra_constraints_init (void)
6343 : {
6344 1531123 : initiate_invariants ();
6345 1531123 : }
6346 :
6347 : /* Finalize the LRA constraint pass. It is done once per
6348 : function. */
6349 : void
6350 1531123 : lra_constraints_finish (void)
6351 : {
6352 1531123 : finish_invariants ();
6353 1531123 : }
6354 :
6355 :
6356 :
6357 : /* Structure describes invariants for ineheritance. */
6358 : struct lra_invariant
6359 : {
6360 : /* The order number of the invariant. */
6361 : int num;
6362 : /* The invariant RTX. */
6363 : rtx invariant_rtx;
6364 : /* The origin insn of the invariant. */
6365 : rtx_insn *insn;
6366 : };
6367 :
6368 : typedef lra_invariant invariant_t;
6369 : typedef invariant_t *invariant_ptr_t;
6370 : typedef const invariant_t *const_invariant_ptr_t;
6371 :
6372 : /* Pointer to the inheritance invariants. */
6373 : static vec<invariant_ptr_t> invariants;
6374 :
6375 : /* Allocation pool for the invariants. */
6376 : static object_allocator<lra_invariant> *invariants_pool;
6377 :
6378 : /* Hash table for the invariants. */
6379 : static htab_t invariant_table;
6380 :
6381 : /* Hash function for INVARIANT. */
6382 : static hashval_t
6383 205797 : invariant_hash (const void *invariant)
6384 : {
6385 205797 : rtx inv = ((const_invariant_ptr_t) invariant)->invariant_rtx;
6386 205797 : return lra_rtx_hash (inv);
6387 : }
6388 :
6389 : /* Equal function for invariants INVARIANT1 and INVARIANT2. */
6390 : static int
6391 74259 : invariant_eq_p (const void *invariant1, const void *invariant2)
6392 : {
6393 74259 : rtx inv1 = ((const_invariant_ptr_t) invariant1)->invariant_rtx;
6394 74259 : rtx inv2 = ((const_invariant_ptr_t) invariant2)->invariant_rtx;
6395 :
6396 74259 : return rtx_equal_p (inv1, inv2);
6397 : }
6398 :
6399 : /* Insert INVARIANT_RTX into the table if it is not there yet. Return
6400 : invariant which is in the table. */
6401 : static invariant_ptr_t
6402 204557 : insert_invariant (rtx invariant_rtx)
6403 : {
6404 204557 : void **entry_ptr;
6405 204557 : invariant_t invariant;
6406 204557 : invariant_ptr_t invariant_ptr;
6407 :
6408 204557 : invariant.invariant_rtx = invariant_rtx;
6409 204557 : entry_ptr = htab_find_slot (invariant_table, &invariant, INSERT);
6410 204557 : if (*entry_ptr == NULL)
6411 : {
6412 172801 : invariant_ptr = invariants_pool->allocate ();
6413 172801 : invariant_ptr->invariant_rtx = invariant_rtx;
6414 172801 : invariant_ptr->insn = NULL;
6415 172801 : invariants.safe_push (invariant_ptr);
6416 172801 : *entry_ptr = (void *) invariant_ptr;
6417 : }
6418 204557 : return (invariant_ptr_t) *entry_ptr;
6419 : }
6420 :
6421 : /* Initiate the invariant table. */
6422 : static void
6423 1531123 : initiate_invariants (void)
6424 : {
6425 1531123 : invariants.create (100);
6426 1531123 : invariants_pool
6427 1531123 : = new object_allocator<lra_invariant> ("Inheritance invariants");
6428 1531123 : invariant_table = htab_create (100, invariant_hash, invariant_eq_p, NULL);
6429 1531123 : }
6430 :
6431 : /* Finish the invariant table. */
6432 : static void
6433 1531123 : finish_invariants (void)
6434 : {
6435 1531123 : htab_delete (invariant_table);
6436 3062246 : delete invariants_pool;
6437 1531123 : invariants.release ();
6438 1531123 : }
6439 :
6440 : /* Make the invariant table empty. */
6441 : static void
6442 12943316 : clear_invariants (void)
6443 : {
6444 12943316 : htab_empty (invariant_table);
6445 12943316 : invariants_pool->release ();
6446 12943316 : invariants.truncate (0);
6447 12943316 : }
6448 :
6449 :
6450 :
6451 : /* This page contains code to do inheritance/split
6452 : transformations. */
6453 :
6454 : /* Number of reloads passed so far in current EBB. */
6455 : static int reloads_num;
6456 :
6457 : /* Number of calls passed so far in current EBB. */
6458 : static int calls_num;
6459 :
6460 : /* Index ID is the CALLS_NUM associated the last call we saw with
6461 : ABI identifier ID. */
6462 : static int last_call_for_abi[NUM_ABI_IDS];
6463 :
6464 : /* Which registers have been fully or partially clobbered by a call
6465 : since they were last used. */
6466 : static HARD_REG_SET full_and_partial_call_clobbers;
6467 :
6468 : /* Current reload pseudo check for validity of elements in
6469 : USAGE_INSNS. */
6470 : static int curr_usage_insns_check;
6471 :
6472 : /* Info about last usage of registers in EBB to do inheritance/split
6473 : transformation. Inheritance transformation is done from a spilled
6474 : pseudo and split transformations from a hard register or a pseudo
6475 : assigned to a hard register. */
6476 : struct usage_insns
6477 : {
6478 : /* If the value is equal to CURR_USAGE_INSNS_CHECK, then the member
6479 : value INSNS is valid. The insns is chain of optional debug insns
6480 : and a finishing non-debug insn using the corresponding reg. The
6481 : value is also used to mark the registers which are set up in the
6482 : current insn. The negated insn uid is used for this. */
6483 : int check;
6484 : /* Value of global reloads_num at the last insn in INSNS. */
6485 : int reloads_num;
6486 : /* Value of global reloads_nums at the last insn in INSNS. */
6487 : int calls_num;
6488 : /* It can be true only for splitting. And it means that the restore
6489 : insn should be put after insn given by the following member. */
6490 : bool after_p;
6491 : /* Next insns in the current EBB which use the original reg and the
6492 : original reg value is not changed between the current insn and
6493 : the next insns. In order words, e.g. for inheritance, if we need
6494 : to use the original reg value again in the next insns we can try
6495 : to use the value in a hard register from a reload insn of the
6496 : current insn. */
6497 : rtx_insn_list *insns;
6498 : };
6499 :
6500 : /* Map: regno -> corresponding pseudo usage insns. */
6501 : static struct usage_insns *usage_insns;
6502 :
6503 : static void
6504 253298840 : setup_next_usage_insn (int regno, rtx_insn *insn, int reloads_num, bool after_p)
6505 : {
6506 253298840 : usage_insns[regno].check = curr_usage_insns_check;
6507 253298840 : usage_insns[regno].insns = gen_rtx_INSN_LIST (VOIDmode, insn, nullptr);
6508 253298840 : usage_insns[regno].reloads_num = reloads_num;
6509 253298840 : usage_insns[regno].calls_num = calls_num;
6510 253298840 : usage_insns[regno].after_p = after_p;
6511 253298840 : if (regno >= FIRST_PSEUDO_REGISTER && reg_renumber[regno] >= 0)
6512 114362657 : remove_from_hard_reg_set (&full_and_partial_call_clobbers,
6513 114362657 : PSEUDO_REGNO_MODE (regno),
6514 : reg_renumber[regno]);
6515 253298840 : }
6516 :
6517 : /* The function is used to form list REGNO usages which consists of
6518 : optional debug insns finished by a non-debug insn using REGNO.
6519 : RELOADS_NUM is current number of reload insns processed so far. */
6520 : static void
6521 144158550 : add_next_usage_insn (int regno, rtx_insn *insn, int reloads_num)
6522 : {
6523 144158550 : rtx_insn_list *next_usage_insns;
6524 :
6525 144158550 : if (usage_insns[regno].check == curr_usage_insns_check
6526 75138651 : && (next_usage_insns = usage_insns[regno].insns) != NULL_RTX
6527 219297201 : && DEBUG_INSN_P (insn))
6528 : {
6529 : /* Check that we did not add the debug insn yet. */
6530 14417697 : if (next_usage_insns->insn () != insn)
6531 14417683 : usage_insns[regno].insns = gen_rtx_INSN_LIST (VOIDmode, insn,
6532 : next_usage_insns);
6533 : }
6534 129740853 : else if (NONDEBUG_INSN_P (insn))
6535 129221728 : setup_next_usage_insn (regno, insn, reloads_num, false);
6536 : else
6537 519125 : usage_insns[regno].check = 0;
6538 144158550 : }
6539 :
6540 : /* Return first non-debug insn in list USAGE_INSNS. */
6541 : static rtx_insn *
6542 1192633 : skip_usage_debug_insns (rtx_insn_list *usage_insns)
6543 : {
6544 1192633 : rtx_insn_list *next;
6545 :
6546 : /* All but the last insn are debug insns. Skip them. */
6547 1510004 : while (usage_insns)
6548 : {
6549 1510004 : next = usage_insns->next ();
6550 1510004 : if (next)
6551 : usage_insns = next;
6552 : else
6553 1192633 : return usage_insns->insn ();
6554 : }
6555 :
6556 : return nullptr;
6557 : }
6558 :
6559 : /* Return true if we need secondary memory moves for insn in
6560 : USAGE_INSNS after inserting inherited pseudo of class INHER_CL
6561 : into the insn. */
6562 : static bool
6563 1192640 : check_secondary_memory_needed_p (enum reg_class inher_cl ATTRIBUTE_UNUSED,
6564 : rtx_insn_list *usage_insns)
6565 : {
6566 1192640 : rtx_insn *insn;
6567 1192640 : rtx set, dest;
6568 1192640 : enum reg_class cl;
6569 :
6570 1192640 : if (inher_cl == ALL_REGS
6571 1192640 : || (insn = skip_usage_debug_insns (usage_insns)) == NULL_RTX)
6572 : return false;
6573 1192633 : lra_assert (INSN_P (insn));
6574 1192633 : if ((set = single_set (insn)) == NULL_RTX || ! REG_P (SET_DEST (set)))
6575 : return false;
6576 1155342 : dest = SET_DEST (set);
6577 1155342 : if (! REG_P (dest))
6578 : return false;
6579 1155342 : lra_assert (inher_cl != NO_REGS);
6580 1155342 : cl = get_reg_class (REGNO (dest));
6581 1155342 : return (cl != NO_REGS && cl != ALL_REGS
6582 1155342 : && targetm.secondary_memory_needed (GET_MODE (dest), inher_cl, cl));
6583 : }
6584 :
6585 : /* Registers involved in inheritance/split in the current EBB
6586 : (inheritance/split pseudos and original registers). */
6587 : static bitmap_head check_only_regs;
6588 :
6589 : /* Reload pseudos cannot be involded in invariant inheritance in the
6590 : current EBB. */
6591 : static bitmap_head invalid_invariant_regs;
6592 :
6593 : /* Do inheritance transformations for insn INSN, which defines (if
6594 : DEF_P) or uses ORIGINAL_REGNO. NEXT_USAGE_INSNS specifies which
6595 : instruction in the EBB next uses ORIGINAL_REGNO; it has the same
6596 : form as the "insns" field of usage_insns. Return true if we
6597 : succeed in such transformation.
6598 :
6599 : The transformations look like:
6600 :
6601 : p <- ... i <- ...
6602 : ... p <- i (new insn)
6603 : ... =>
6604 : <- ... p ... <- ... i ...
6605 : or
6606 : ... i <- p (new insn)
6607 : <- ... p ... <- ... i ...
6608 : ... =>
6609 : <- ... p ... <- ... i ...
6610 : where p is a spilled original pseudo and i is a new inheritance pseudo.
6611 :
6612 :
6613 : The inheritance pseudo has the smallest class of two classes CL and
6614 : class of ORIGINAL REGNO. */
6615 : static bool
6616 1281580 : inherit_reload_reg (bool def_p, int original_regno,
6617 : enum reg_class cl, rtx_insn *insn,
6618 : rtx_insn_list *next_usage_insns)
6619 : {
6620 1281580 : if (optimize_function_for_size_p (cfun))
6621 : return false;
6622 :
6623 1255283 : enum reg_class rclass = lra_get_allocno_class (original_regno);
6624 1255283 : rtx original_reg = regno_reg_rtx[original_regno];
6625 1255283 : rtx new_reg;
6626 1255283 : rtx_insn *new_insns;
6627 :
6628 1255283 : lra_assert (! usage_insns[original_regno].after_p);
6629 1255283 : if (lra_dump_file != NULL)
6630 1 : fprintf (lra_dump_file,
6631 : " <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n");
6632 1255283 : if (! ira_reg_classes_intersect_p[cl][rclass])
6633 : {
6634 62643 : if (lra_dump_file != NULL)
6635 : {
6636 0 : fprintf (lra_dump_file,
6637 : " Rejecting inheritance for %d "
6638 : "because of disjoint classes %s and %s\n",
6639 : original_regno, reg_class_names[cl],
6640 : reg_class_names[rclass]);
6641 0 : fprintf (lra_dump_file,
6642 : " >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n");
6643 : }
6644 : return false;
6645 : }
6646 1192640 : if ((ira_class_subset_p[cl][rclass] && cl != rclass)
6647 : /* We don't use a subset of two classes because it can be
6648 : NO_REGS. This transformation is still profitable in most
6649 : cases even if the classes are not intersected as register
6650 : move is probably cheaper than a memory load. */
6651 452518 : || ira_class_hard_regs_num[cl] < ira_class_hard_regs_num[rclass])
6652 : {
6653 740122 : if (lra_dump_file != NULL)
6654 1 : fprintf (lra_dump_file, " Use smallest class of %s and %s\n",
6655 : reg_class_names[cl], reg_class_names[rclass]);
6656 :
6657 : rclass = cl;
6658 : }
6659 1192640 : if (check_secondary_memory_needed_p (rclass, next_usage_insns))
6660 : {
6661 : /* Reject inheritance resulting in secondary memory moves.
6662 : Otherwise, there is a danger in LRA cycling. Also such
6663 : transformation will be unprofitable. */
6664 15048 : if (lra_dump_file != NULL)
6665 : {
6666 0 : rtx_insn *insn = skip_usage_debug_insns (next_usage_insns);
6667 0 : rtx set = single_set (insn);
6668 :
6669 0 : lra_assert (set != NULL_RTX);
6670 :
6671 0 : rtx dest = SET_DEST (set);
6672 :
6673 0 : lra_assert (REG_P (dest));
6674 0 : fprintf (lra_dump_file,
6675 : " Rejecting inheritance for insn %d(%s)<-%d(%s) "
6676 : "as secondary mem is needed\n",
6677 0 : REGNO (dest), reg_class_names[get_reg_class (REGNO (dest))],
6678 0 : original_regno, reg_class_names[rclass]);
6679 0 : fprintf (lra_dump_file,
6680 : " >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n");
6681 : }
6682 : return false;
6683 : }
6684 1177592 : if (ira_reg_class_min_nregs[rclass][GET_MODE (original_reg)]
6685 1177592 : != ira_reg_class_max_nregs[rclass][GET_MODE (original_reg)])
6686 : {
6687 24 : if (lra_dump_file != NULL)
6688 : {
6689 0 : fprintf (lra_dump_file,
6690 : " Rejecting inheritance for %d "
6691 : "because of requiring non-uniform class %s\n",
6692 : original_regno, reg_class_names[rclass]);
6693 0 : fprintf (lra_dump_file,
6694 : " >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n");
6695 : }
6696 : return false;
6697 : }
6698 1177568 : new_reg = lra_create_new_reg (GET_MODE (original_reg), original_reg,
6699 : rclass, NULL, "inheritance");
6700 1177568 : start_sequence ();
6701 1177568 : if (def_p)
6702 548896 : lra_emit_move (original_reg, new_reg);
6703 : else
6704 628672 : lra_emit_move (new_reg, original_reg);
6705 1177568 : new_insns = end_sequence ();
6706 1177568 : if (NEXT_INSN (new_insns) != NULL_RTX)
6707 : {
6708 0 : if (lra_dump_file != NULL)
6709 : {
6710 0 : fprintf (lra_dump_file,
6711 : " Rejecting inheritance %d->%d "
6712 : "as it results in 2 or more insns:\n",
6713 : original_regno, REGNO (new_reg));
6714 0 : dump_rtl_slim (lra_dump_file, new_insns, NULL, -1, 0);
6715 0 : fprintf (lra_dump_file,
6716 : " >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n");
6717 : }
6718 : return false;
6719 : }
6720 1177568 : lra_substitute_pseudo_within_insn (insn, original_regno, new_reg, false);
6721 1177568 : lra_update_insn_regno_info (insn);
6722 1177568 : if (! def_p)
6723 : /* We now have a new usage insn for original regno. */
6724 628672 : setup_next_usage_insn (original_regno, new_insns, reloads_num, false);
6725 1177568 : if (lra_dump_file != NULL)
6726 1 : fprintf (lra_dump_file, " Original reg change %d->%d (bb%d):\n",
6727 1 : original_regno, REGNO (new_reg), BLOCK_FOR_INSN (insn)->index);
6728 1177568 : lra_reg_info[REGNO (new_reg)].restore_rtx = regno_reg_rtx[original_regno];
6729 1177568 : bitmap_set_bit (&check_only_regs, REGNO (new_reg));
6730 1177568 : bitmap_set_bit (&check_only_regs, original_regno);
6731 1177568 : bitmap_set_bit (&lra_inheritance_pseudos, REGNO (new_reg));
6732 1177568 : if (def_p)
6733 548896 : lra_process_new_insns (insn, NULL, new_insns,
6734 : "Add original<-inheritance");
6735 : else
6736 628672 : lra_process_new_insns (insn, new_insns, NULL,
6737 : "Add inheritance<-original");
6738 : rtx_insn *usage_insn;
6739 2669735 : while (next_usage_insns != NULL_RTX)
6740 : {
6741 1492167 : usage_insn = next_usage_insns->insn ();
6742 1492167 : if (!next_usage_insns->next ())
6743 : {
6744 1177568 : lra_assert (NONDEBUG_INSN_P (usage_insn));
6745 : next_usage_insns = NULL;
6746 : }
6747 : else
6748 : {
6749 314599 : lra_assert (DEBUG_INSN_P (usage_insn));
6750 : next_usage_insns = next_usage_insns->next ();
6751 : }
6752 1492167 : rtx temp = usage_insn;
6753 1492167 : lra_substitute_pseudo (&temp, original_regno, new_reg, false,
6754 1492167 : DEBUG_INSN_P (usage_insn));
6755 1492167 : lra_update_insn_regno_info (usage_insn);
6756 1492167 : if (lra_dump_file != NULL)
6757 : {
6758 1 : basic_block bb = BLOCK_FOR_INSN (usage_insn);
6759 1 : fprintf (lra_dump_file,
6760 : " Inheritance reuse change %d->%d (bb%d):\n",
6761 : original_regno, REGNO (new_reg),
6762 : bb ? bb->index : -1);
6763 1 : dump_insn_slim (lra_dump_file, usage_insn);
6764 : }
6765 : }
6766 1177568 : if (lra_dump_file != NULL)
6767 1 : fprintf (lra_dump_file,
6768 : " >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n");
6769 : return true;
6770 : }
6771 :
6772 : /* Return true if we need a caller save/restore for pseudo REGNO which
6773 : was assigned to a hard register. */
6774 : static inline bool
6775 117146536 : need_for_call_save_p (int regno)
6776 : {
6777 117146536 : lra_assert (regno >= FIRST_PSEUDO_REGISTER && reg_renumber[regno] >= 0);
6778 117146536 : if (usage_insns[regno].calls_num < calls_num)
6779 : {
6780 : unsigned int abis = 0;
6781 121527510 : for (unsigned int i = 0; i < NUM_ABI_IDS; ++i)
6782 112179240 : if (last_call_for_abi[i] > usage_insns[regno].calls_num)
6783 9397589 : abis |= 1 << i;
6784 9348270 : gcc_assert (abis);
6785 9348270 : if (call_clobbered_in_region_p (abis, full_and_partial_call_clobbers,
6786 9348270 : PSEUDO_REGNO_MODE (regno),
6787 : reg_renumber[regno]))
6788 : return true;
6789 : }
6790 : return false;
6791 : }
6792 :
6793 : /* Global registers occurring in the current EBB. */
6794 : static bitmap_head ebb_global_regs;
6795 :
6796 : /* Return true if we need a split for hard register REGNO or pseudo
6797 : REGNO which was assigned to a hard register.
6798 : POTENTIAL_RELOAD_HARD_REGS contains hard registers which might be
6799 : used for reloads since the EBB end. It is an approximation of the
6800 : used hard registers in the split range. The exact value would
6801 : require expensive calculations. If we were aggressive with
6802 : splitting because of the approximation, the split pseudo will save
6803 : the same hard register assignment and will be removed in the undo
6804 : pass. We still need the approximation because too aggressive
6805 : splitting would result in too inaccurate cost calculation in the
6806 : assignment pass because of too many generated moves which will be
6807 : probably removed in the undo pass. */
6808 : static inline bool
6809 248508046 : need_for_split_p (HARD_REG_SET potential_reload_hard_regs, int regno)
6810 : {
6811 248508046 : int hard_regno = regno < FIRST_PSEUDO_REGISTER ? regno : reg_renumber[regno];
6812 :
6813 248508046 : lra_assert (hard_regno >= 0);
6814 248508046 : return ((TEST_HARD_REG_BIT (potential_reload_hard_regs, hard_regno)
6815 : /* Don't split eliminable hard registers, otherwise we can
6816 : split hard registers like hard frame pointer, which
6817 : lives on BB start/end according to DF-infrastructure,
6818 : when there is a pseudo assigned to the register and
6819 : living in the same BB. */
6820 696034 : && (regno >= FIRST_PSEUDO_REGISTER
6821 45869 : || ! TEST_HARD_REG_BIT (eliminable_regset, hard_regno))
6822 665137 : && ! TEST_HARD_REG_BIT (lra_no_alloc_regs, hard_regno)
6823 : /* Don't split call clobbered hard regs living through
6824 : calls, otherwise we might have a check problem in the
6825 : assign sub-pass as in the most cases (exception is a
6826 : situation when check_and_force_assignment_correctness_p value is
6827 : true) the assign pass assumes that all pseudos living
6828 : through calls are assigned to call saved hard regs. */
6829 651181 : && (regno >= FIRST_PSEUDO_REGISTER
6830 1016 : || !TEST_HARD_REG_BIT (full_and_partial_call_clobbers, regno))
6831 : /* We need at least 2 reloads to make pseudo splitting
6832 : profitable. We should provide hard regno splitting in
6833 : any case to solve 1st insn scheduling problem when
6834 : moving hard register definition up might result in
6835 : impossibility to find hard register for reload pseudo of
6836 : small register class. */
6837 1302306 : && (usage_insns[regno].reloads_num
6838 1301318 : + (regno < FIRST_PSEUDO_REGISTER ? 0 : 3) < reloads_num)
6839 3097 : && (regno < FIRST_PSEUDO_REGISTER
6840 : /* For short living pseudos, spilling + inheritance can
6841 : be considered a substitution for splitting.
6842 : Therefore we do not splitting for local pseudos. It
6843 : decreases also aggressiveness of splitting. The
6844 : minimal number of references is chosen taking into
6845 : account that for 2 references splitting has no sense
6846 : as we can just spill the pseudo. */
6847 : || (regno >= FIRST_PSEUDO_REGISTER
6848 3050 : && lra_reg_info[regno].nrefs > 3
6849 2783 : && bitmap_bit_p (&ebb_global_regs, regno))))
6850 249202606 : || (regno >= FIRST_PSEUDO_REGISTER && need_for_call_save_p (regno)));
6851 : }
6852 :
6853 : /* Return class for the split pseudo created from original pseudo with
6854 : ALLOCNO_CLASS and MODE which got a hard register HARD_REGNO. We
6855 : choose subclass of ALLOCNO_CLASS which contains HARD_REGNO and
6856 : results in no secondary memory movements. */
6857 : static enum reg_class
6858 1634 : choose_split_class (enum reg_class allocno_class,
6859 : int hard_regno ATTRIBUTE_UNUSED,
6860 : machine_mode mode ATTRIBUTE_UNUSED)
6861 : {
6862 1634 : int i;
6863 1634 : enum reg_class cl, best_cl = NO_REGS;
6864 1634 : enum reg_class hard_reg_class ATTRIBUTE_UNUSED
6865 : = REGNO_REG_CLASS (hard_regno);
6866 :
6867 1634 : if (! targetm.secondary_memory_needed (mode, allocno_class, allocno_class)
6868 1634 : && TEST_HARD_REG_BIT (reg_class_contents[allocno_class], hard_regno))
6869 : return allocno_class;
6870 0 : for (i = 0;
6871 0 : (cl = reg_class_subclasses[allocno_class][i]) != LIM_REG_CLASSES;
6872 : i++)
6873 0 : if (! targetm.secondary_memory_needed (mode, cl, hard_reg_class)
6874 0 : && ! targetm.secondary_memory_needed (mode, hard_reg_class, cl)
6875 0 : && TEST_HARD_REG_BIT (reg_class_contents[cl], hard_regno)
6876 0 : && (best_cl == NO_REGS
6877 0 : || ira_class_hard_regs_num[best_cl] < ira_class_hard_regs_num[cl]))
6878 : best_cl = cl;
6879 : return best_cl;
6880 : }
6881 :
6882 : /* Copy any equivalence information from ORIGINAL_REGNO to NEW_REGNO. It only
6883 : makes sense to call this function if NEW_REGNO is always equal to
6884 : ORIGINAL_REGNO. Set up defined_p flag when caller_save_p flag is set up and
6885 : CALL_SAVE_P is true. */
6886 :
6887 : static void
6888 668973 : lra_copy_reg_equiv (unsigned int new_regno, unsigned int original_regno,
6889 : bool call_save_p)
6890 : {
6891 668973 : if (!ira_reg_equiv[original_regno].defined_p
6892 598241 : && !(call_save_p && ira_reg_equiv[original_regno].caller_save_p))
6893 : return;
6894 :
6895 70924 : ira_expand_reg_equiv ();
6896 70924 : ira_reg_equiv[new_regno].defined_p = true;
6897 70924 : if (ira_reg_equiv[original_regno].memory)
6898 34167 : ira_reg_equiv[new_regno].memory
6899 34167 : = copy_rtx (ira_reg_equiv[original_regno].memory);
6900 70924 : if (ira_reg_equiv[original_regno].constant)
6901 30143 : ira_reg_equiv[new_regno].constant
6902 30143 : = copy_rtx (ira_reg_equiv[original_regno].constant);
6903 70924 : if (ira_reg_equiv[original_regno].invariant)
6904 6614 : ira_reg_equiv[new_regno].invariant
6905 6614 : = copy_rtx (ira_reg_equiv[original_regno].invariant);
6906 : }
6907 :
6908 : /* Do split transformations for insn INSN, which defines or uses
6909 : ORIGINAL_REGNO. NEXT_USAGE_INSNS specifies which instruction in
6910 : the EBB next uses ORIGINAL_REGNO; it has the same form as the
6911 : "insns" field of usage_insns. If TO is not NULL, we don't use
6912 : usage_insns, we put restore insns after TO insn. It is a case when
6913 : we call it from lra_split_hard_reg_for, outside the inheritance
6914 : pass.
6915 :
6916 : The transformations look like:
6917 :
6918 : p <- ... p <- ...
6919 : ... s <- p (new insn -- save)
6920 : ... =>
6921 : ... p <- s (new insn -- restore)
6922 : <- ... p ... <- ... p ...
6923 : or
6924 : <- ... p ... <- ... p ...
6925 : ... s <- p (new insn -- save)
6926 : ... =>
6927 : ... p <- s (new insn -- restore)
6928 : <- ... p ... <- ... p ...
6929 :
6930 : where p is an original pseudo got a hard register or a hard
6931 : register and s is a new split pseudo. The save is put before INSN
6932 : if BEFORE_P is true. Return true if we succeed in such
6933 : transformation. */
6934 : static bool
6935 670866 : split_reg (bool before_p, int original_regno, rtx_insn *insn,
6936 : rtx_insn_list *next_usage_insns, rtx_insn *to)
6937 : {
6938 670866 : enum reg_class rclass;
6939 670866 : rtx original_reg;
6940 670866 : int hard_regno, nregs;
6941 670866 : rtx new_reg;
6942 670866 : rtx_insn *restore, *save;
6943 670866 : bool after_p;
6944 670866 : bool call_save_p;
6945 670866 : machine_mode mode;
6946 :
6947 670866 : if (original_regno < FIRST_PSEUDO_REGISTER)
6948 : {
6949 208 : rclass = ira_allocno_class_translate[REGNO_REG_CLASS (original_regno)];
6950 208 : hard_regno = original_regno;
6951 208 : call_save_p = false;
6952 208 : nregs = 1;
6953 208 : mode = lra_reg_info[hard_regno].biggest_mode;
6954 208 : machine_mode reg_rtx_mode = GET_MODE (regno_reg_rtx[hard_regno]);
6955 : /* A reg can have a biggest_mode of VOIDmode if it was only ever seen as
6956 : part of a multi-word register. In that case, just use the reg_rtx
6957 : mode. Do the same also if the biggest mode was larger than a register
6958 : or we can not compare the modes. Otherwise, limit the size to that of
6959 : the biggest access in the function or to the natural mode at least. */
6960 208 : if (mode == VOIDmode
6961 208 : || !ordered_p (GET_MODE_PRECISION (mode),
6962 208 : GET_MODE_PRECISION (reg_rtx_mode))
6963 208 : || paradoxical_subreg_p (mode, reg_rtx_mode)
6964 415 : || maybe_gt (GET_MODE_PRECISION (reg_rtx_mode), GET_MODE_PRECISION (mode)))
6965 : {
6966 : original_reg = regno_reg_rtx[hard_regno];
6967 : mode = reg_rtx_mode;
6968 : }
6969 : else
6970 191 : original_reg = gen_rtx_REG (mode, hard_regno);
6971 : }
6972 : else
6973 : {
6974 670658 : mode = PSEUDO_REGNO_MODE (original_regno);
6975 670658 : hard_regno = reg_renumber[original_regno];
6976 670658 : nregs = hard_regno_nregs (hard_regno, mode);
6977 670658 : rclass = lra_get_allocno_class (original_regno);
6978 670658 : original_reg = regno_reg_rtx[original_regno];
6979 670658 : call_save_p = need_for_call_save_p (original_regno);
6980 : }
6981 670866 : lra_assert (hard_regno >= 0);
6982 670866 : if (lra_dump_file != NULL)
6983 0 : fprintf (lra_dump_file,
6984 : " ((((((((((((((((((((((((((((((((((((((((((((((((\n");
6985 :
6986 670866 : if (call_save_p)
6987 : {
6988 669232 : mode = HARD_REGNO_CALLER_SAVE_MODE (hard_regno,
6989 : hard_regno_nregs (hard_regno, mode),
6990 : mode);
6991 669232 : new_reg = lra_create_new_reg (mode, NULL_RTX, NO_REGS, NULL, "save");
6992 : }
6993 : else
6994 : {
6995 1634 : rclass = choose_split_class (rclass, hard_regno, mode);
6996 1634 : if (rclass == NO_REGS)
6997 : {
6998 0 : if (lra_dump_file != NULL)
6999 : {
7000 0 : fprintf (lra_dump_file,
7001 : " Rejecting split of %d(%s): "
7002 : "no good reg class for %d(%s)\n",
7003 : original_regno,
7004 0 : reg_class_names[lra_get_allocno_class (original_regno)],
7005 : hard_regno,
7006 0 : reg_class_names[REGNO_REG_CLASS (hard_regno)]);
7007 0 : fprintf
7008 0 : (lra_dump_file,
7009 : " ))))))))))))))))))))))))))))))))))))))))))))))))\n");
7010 : }
7011 : return false;
7012 : }
7013 : /* Split_if_necessary can split hard registers used as part of a
7014 : multi-register mode but splits each register individually. The
7015 : mode used for each independent register may not be supported
7016 : so reject the split. Splitting the wider mode should theoretically
7017 : be possible but is not implemented. */
7018 1634 : if (!targetm.hard_regno_mode_ok (hard_regno, mode))
7019 : {
7020 0 : if (lra_dump_file != NULL)
7021 : {
7022 0 : fprintf (lra_dump_file,
7023 : " Rejecting split of %d(%s): unsuitable mode %s\n",
7024 : original_regno,
7025 0 : reg_class_names[lra_get_allocno_class (original_regno)],
7026 0 : GET_MODE_NAME (mode));
7027 0 : fprintf
7028 0 : (lra_dump_file,
7029 : " ))))))))))))))))))))))))))))))))))))))))))))))))\n");
7030 : }
7031 : return false;
7032 : }
7033 1634 : new_reg = lra_create_new_reg (mode, original_reg, rclass, NULL, "split");
7034 1634 : reg_renumber[REGNO (new_reg)] = hard_regno;
7035 : }
7036 670866 : int new_regno = REGNO (new_reg);
7037 670866 : save = emit_spill_move (true, new_reg, original_reg);
7038 670866 : if (NEXT_INSN (save) != NULL_RTX && !call_save_p)
7039 : {
7040 0 : if (lra_dump_file != NULL)
7041 : {
7042 0 : fprintf
7043 0 : (lra_dump_file,
7044 : " Rejecting split %d->%d resulting in > 2 save insns:\n",
7045 : original_regno, new_regno);
7046 0 : dump_rtl_slim (lra_dump_file, save, NULL, -1, 0);
7047 0 : fprintf (lra_dump_file,
7048 : " ))))))))))))))))))))))))))))))))))))))))))))))))\n");
7049 : }
7050 : return false;
7051 : }
7052 670866 : restore = emit_spill_move (false, new_reg, original_reg);
7053 670866 : if (NEXT_INSN (restore) != NULL_RTX && !call_save_p)
7054 : {
7055 0 : if (lra_dump_file != NULL)
7056 : {
7057 0 : fprintf (lra_dump_file,
7058 : " Rejecting split %d->%d "
7059 : "resulting in > 2 restore insns:\n",
7060 : original_regno, new_regno);
7061 0 : dump_rtl_slim (lra_dump_file, restore, NULL, -1, 0);
7062 0 : fprintf (lra_dump_file,
7063 : " ))))))))))))))))))))))))))))))))))))))))))))))))\n");
7064 : }
7065 : return false;
7066 : }
7067 : /* Transfer equivalence information to the spill register, so that
7068 : if we fail to allocate the spill register, we have the option of
7069 : rematerializing the original value instead of spilling to the stack. */
7070 670866 : if (!HARD_REGISTER_NUM_P (original_regno)
7071 670658 : && mode == PSEUDO_REGNO_MODE (original_regno))
7072 668973 : lra_copy_reg_equiv (new_regno, original_regno, call_save_p);
7073 670866 : lra_reg_info[new_regno].restore_rtx = regno_reg_rtx[original_regno];
7074 670866 : bitmap_set_bit (&lra_split_regs, new_regno);
7075 670866 : rtx_insn *usage_insn;
7076 670866 : if (to != NULL)
7077 : {
7078 161 : lra_assert (next_usage_insns == NULL);
7079 : usage_insn = to;
7080 : after_p = true;
7081 : }
7082 : else
7083 : {
7084 : /* We need check_only_regs only inside the inheritance pass. */
7085 670705 : bitmap_set_bit (&check_only_regs, new_regno);
7086 670705 : bitmap_set_bit (&check_only_regs, original_regno);
7087 670705 : after_p = usage_insns[original_regno].after_p;
7088 889411 : for (;;)
7089 : {
7090 780058 : usage_insn = next_usage_insns->insn ();
7091 780058 : if (!next_usage_insns->next ())
7092 : break;
7093 :
7094 109353 : lra_assert (DEBUG_INSN_P (usage_insn));
7095 109353 : next_usage_insns = next_usage_insns->next ();
7096 109353 : rtx temp = usage_insn;
7097 109353 : lra_substitute_pseudo (&temp, original_regno, new_reg, false,
7098 : true);
7099 109353 : lra_update_insn_regno_info (usage_insn);
7100 109353 : if (lra_dump_file != NULL)
7101 : {
7102 0 : fprintf (lra_dump_file, " Split reuse change %d->%d:\n",
7103 : original_regno, new_regno);
7104 0 : dump_insn_slim (lra_dump_file, usage_insn);
7105 : }
7106 109353 : }
7107 : }
7108 670866 : lra_assert (NOTE_P (usage_insn) || NONDEBUG_INSN_P (usage_insn));
7109 670866 : lra_assert (usage_insn != insn || (after_p && before_p));
7110 1131060 : lra_process_new_insns (usage_insn,
7111 : after_p ? NULL : restore,
7112 : after_p ? restore : NULL,
7113 : call_save_p ? "Add reg<-save" : "Add reg<-split");
7114 670866 : if (call_save_p
7115 669232 : && first_call_insn != NULL
7116 1340098 : && BLOCK_FOR_INSN (first_call_insn) != BLOCK_FOR_INSN (insn))
7117 : /* PR116028: If original_regno is a pseudo that has been assigned a
7118 : callee-saved hard register, then emit the spill insn before the call
7119 : insn 'first_call_insn' instead of adjacent to 'insn'. If 'insn'
7120 : and 'first_call_insn' belong to the same EBB but to two separate
7121 : BBs, and if 'insn' is present in the entry BB, then generating the
7122 : spill insn in the entry BB can prevent shrink wrap from happening.
7123 : This is because the spill insn references the stack pointer and
7124 : hence the prolog gets generated in the entry BB itself. It is
7125 : also more efficient to generate the spill before
7126 : 'first_call_insn' as the spill now occurs only in the path
7127 : containing the call. */
7128 25747 : lra_process_new_insns (first_call_insn, save, NULL, "Add save<-reg");
7129 : else
7130 1291344 : lra_process_new_insns (insn, before_p ? save : NULL,
7131 : before_p ? NULL : save,
7132 : call_save_p ? "Add save<-reg" : "Add split<-reg");
7133 670866 : if (nregs > 1 || original_regno < FIRST_PSEUDO_REGISTER)
7134 : /* If we are trying to split multi-register. We should check
7135 : conflicts on the next assignment sub-pass. IRA can allocate on
7136 : sub-register levels, LRA do this on pseudos level right now and
7137 : this discrepancy may create allocation conflicts after
7138 : splitting.
7139 :
7140 : If we are trying to split hard register we should also check conflicts
7141 : as such splitting can create artificial conflict of the hard register
7142 : with another pseudo because of simplified conflict calculation in
7143 : LRA. */
7144 9185 : check_and_force_assignment_correctness_p = true;
7145 670866 : if (lra_dump_file != NULL)
7146 0 : fprintf (lra_dump_file,
7147 : " ))))))))))))))))))))))))))))))))))))))))))))))))\n");
7148 : return true;
7149 : }
7150 :
7151 : /* Split a hard reg for reload pseudo REGNO having RCLASS and living
7152 : in the range [FROM, TO]. Return true if did a split. Otherwise,
7153 : return false. */
7154 : bool
7155 991 : spill_hard_reg_in_range (int regno, enum reg_class rclass, rtx_insn *from, rtx_insn *to)
7156 : {
7157 991 : int i, hard_regno;
7158 991 : int rclass_size;
7159 991 : rtx_insn *insn;
7160 991 : unsigned int uid;
7161 991 : bitmap_iterator bi;
7162 991 : HARD_REG_SET ignore;
7163 :
7164 991 : lra_assert (from != NULL && to != NULL);
7165 991 : ignore = lra_no_alloc_regs;
7166 2768 : EXECUTE_IF_SET_IN_BITMAP (&lra_reg_info[regno].insn_bitmap, 0, uid, bi)
7167 : {
7168 1777 : lra_insn_recog_data_t id = lra_insn_recog_data[uid];
7169 1777 : struct lra_static_insn_data *static_id = id->insn_static_data;
7170 1777 : struct lra_insn_reg *reg;
7171 :
7172 6357 : for (reg = id->regs; reg != NULL; reg = reg->next)
7173 4580 : if (reg->regno < FIRST_PSEUDO_REGISTER)
7174 295 : SET_HARD_REG_BIT (ignore, reg->regno);
7175 2850 : for (reg = static_id->hard_regs; reg != NULL; reg = reg->next)
7176 1073 : SET_HARD_REG_BIT (ignore, reg->regno);
7177 : }
7178 991 : rclass_size = ira_class_hard_regs_num[rclass];
7179 3165 : for (i = 0; i < rclass_size; i++)
7180 : {
7181 2335 : hard_regno = ira_class_hard_regs[rclass][i];
7182 2335 : if (! TEST_HARD_REG_BIT (lra_reg_info[regno].conflict_hard_regs, hard_regno)
7183 2335 : || TEST_HARD_REG_BIT (ignore, hard_regno))
7184 2168 : continue;
7185 482 : for (insn = from; insn != NEXT_INSN (to); insn = NEXT_INSN (insn))
7186 : {
7187 321 : struct lra_static_insn_data *static_id;
7188 321 : struct lra_insn_reg *reg;
7189 :
7190 321 : if (!INSN_P (insn))
7191 0 : continue;
7192 321 : if (bitmap_bit_p (&lra_reg_info[hard_regno].insn_bitmap,
7193 321 : INSN_UID (insn)))
7194 : break;
7195 315 : static_id = lra_get_insn_recog_data (insn)->insn_static_data;
7196 369 : for (reg = static_id->hard_regs; reg != NULL; reg = reg->next)
7197 54 : if (reg->regno == hard_regno)
7198 : break;
7199 : if (reg != NULL)
7200 : break;
7201 : }
7202 167 : if (insn != NEXT_INSN (to))
7203 6 : continue;
7204 161 : if (split_reg (true, hard_regno, from, NULL, to))
7205 : return true;
7206 : }
7207 : return false;
7208 : }
7209 :
7210 : /* Recognize that we need a split transformation for insn INSN, which
7211 : defines or uses REGNO in its insn biggest MODE (we use it only if
7212 : REGNO is a hard register). POTENTIAL_RELOAD_HARD_REGS contains
7213 : hard registers which might be used for reloads since the EBB end.
7214 : Put the save before INSN if BEFORE_P is true. MAX_UID is maximla
7215 : uid before starting INSN processing. Return true if we succeed in
7216 : such transformation. */
7217 : static bool
7218 205477507 : split_if_necessary (int regno, machine_mode mode,
7219 : HARD_REG_SET potential_reload_hard_regs,
7220 : bool before_p, rtx_insn *insn, int max_uid)
7221 : {
7222 205477507 : bool res = false;
7223 205477507 : int i, nregs = 1;
7224 205477507 : rtx_insn_list *next_usage_insns;
7225 :
7226 205477507 : if (regno < FIRST_PSEUDO_REGISTER)
7227 96450526 : nregs = hard_regno_nregs (regno, mode);
7228 411317652 : for (i = 0; i < nregs; i++)
7229 205840145 : if (usage_insns[regno + i].check == curr_usage_insns_check
7230 137251509 : && (next_usage_insns = usage_insns[regno + i].insns) != NULL_RTX
7231 : /* To avoid processing the register twice or more. */
7232 137251509 : && INSN_UID (next_usage_insns->insn ()) < max_uid
7233 137251509 : && need_for_split_p (potential_reload_hard_regs, regno + i)
7234 206121573 : && split_reg (before_p, regno + i, insn, next_usage_insns, NULL))
7235 : res = true;
7236 205477507 : return res;
7237 : }
7238 :
7239 : /* Return TRUE if rtx X is considered as an invariant for
7240 : inheritance. */
7241 : static bool
7242 12411698 : invariant_p (const_rtx x)
7243 : {
7244 12411698 : machine_mode mode;
7245 12411698 : const char *fmt;
7246 12411698 : enum rtx_code code;
7247 12411698 : int i, j;
7248 :
7249 12411698 : if (side_effects_p (x))
7250 : return false;
7251 :
7252 12397025 : code = GET_CODE (x);
7253 12397025 : mode = GET_MODE (x);
7254 12397025 : if (code == SUBREG)
7255 : {
7256 507930 : x = SUBREG_REG (x);
7257 507930 : code = GET_CODE (x);
7258 507930 : mode = wider_subreg_mode (mode, GET_MODE (x));
7259 : }
7260 :
7261 12397025 : if (MEM_P (x))
7262 : return false;
7263 :
7264 10616442 : if (REG_P (x))
7265 : {
7266 3754109 : int i, nregs, regno = REGNO (x);
7267 :
7268 3754109 : if (regno >= FIRST_PSEUDO_REGISTER || regno == STACK_POINTER_REGNUM
7269 1011062 : || TEST_HARD_REG_BIT (eliminable_regset, regno)
7270 3770578 : || GET_MODE_CLASS (GET_MODE (x)) == MODE_CC)
7271 : return false;
7272 2 : nregs = hard_regno_nregs (regno, mode);
7273 2 : for (i = 0; i < nregs; i++)
7274 2 : if (! fixed_regs[regno + i]
7275 : /* A hard register may be clobbered in the current insn
7276 : but we can ignore this case because if the hard
7277 : register is used it should be set somewhere after the
7278 : clobber. */
7279 2 : || bitmap_bit_p (&invalid_invariant_regs, regno + i))
7280 : return false;
7281 : }
7282 6862333 : fmt = GET_RTX_FORMAT (code);
7283 12124364 : for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
7284 : {
7285 9110510 : if (fmt[i] == 'e')
7286 : {
7287 5917529 : if (! invariant_p (XEXP (x, i)))
7288 : return false;
7289 : }
7290 3192981 : else if (fmt[i] == 'E')
7291 : {
7292 756295 : for (j = XVECLEN (x, i) - 1; j >= 0; j--)
7293 636395 : if (! invariant_p (XVECEXP (x, i, j)))
7294 : return false;
7295 : }
7296 : }
7297 : return true;
7298 : }
7299 :
7300 : /* We have 'dest_reg <- invariant'. Let us try to make an invariant
7301 : inheritance transformation (using dest_reg instead invariant in a
7302 : subsequent insn). */
7303 : static bool
7304 204557 : process_invariant_for_inheritance (rtx dst_reg, rtx invariant_rtx)
7305 : {
7306 204557 : invariant_ptr_t invariant_ptr;
7307 204557 : rtx_insn *insn, *new_insns;
7308 204557 : rtx insn_set, insn_reg, new_reg;
7309 204557 : int insn_regno;
7310 204557 : bool succ_p = false;
7311 204557 : int dst_regno = REGNO (dst_reg);
7312 204557 : machine_mode dst_mode = GET_MODE (dst_reg);
7313 204557 : enum reg_class cl = lra_get_allocno_class (dst_regno), insn_reg_cl;
7314 :
7315 204557 : invariant_ptr = insert_invariant (invariant_rtx);
7316 204557 : if ((insn = invariant_ptr->insn) != NULL_RTX)
7317 : {
7318 : /* We have a subsequent insn using the invariant. */
7319 31756 : insn_set = single_set (insn);
7320 31756 : lra_assert (insn_set != NULL);
7321 31756 : insn_reg = SET_DEST (insn_set);
7322 31756 : lra_assert (REG_P (insn_reg));
7323 31756 : insn_regno = REGNO (insn_reg);
7324 31756 : insn_reg_cl = lra_get_allocno_class (insn_regno);
7325 :
7326 31756 : if (dst_mode == GET_MODE (insn_reg)
7327 : /* We should consider only result move reg insns which are
7328 : cheap. */
7329 31686 : && targetm.register_move_cost (dst_mode, cl, insn_reg_cl) == 2
7330 62250 : && targetm.register_move_cost (dst_mode, cl, cl) == 2)
7331 : {
7332 30494 : if (lra_dump_file != NULL)
7333 0 : fprintf (lra_dump_file,
7334 : " [[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[\n");
7335 30494 : new_reg = lra_create_new_reg (dst_mode, dst_reg, cl, NULL,
7336 : "invariant inheritance");
7337 30494 : bitmap_set_bit (&lra_inheritance_pseudos, REGNO (new_reg));
7338 30494 : bitmap_set_bit (&check_only_regs, REGNO (new_reg));
7339 30494 : add_invariant (new_reg, invariant_rtx);
7340 30494 : lra_reg_info[REGNO (new_reg)].restore_rtx = PATTERN (insn);
7341 30494 : start_sequence ();
7342 30494 : lra_emit_move (new_reg, dst_reg);
7343 30494 : new_insns = end_sequence ();
7344 30494 : lra_process_new_insns (curr_insn, NULL, new_insns,
7345 : "Add invariant inheritance<-original");
7346 30494 : start_sequence ();
7347 30494 : lra_emit_move (SET_DEST (insn_set), new_reg);
7348 30494 : new_insns = end_sequence ();
7349 30494 : lra_process_new_insns (insn, NULL, new_insns,
7350 : "Changing reload<-inheritance");
7351 30494 : lra_set_insn_deleted (insn);
7352 30494 : succ_p = true;
7353 30494 : if (lra_dump_file != NULL)
7354 : {
7355 0 : fprintf (lra_dump_file,
7356 : " Invariant inheritance reuse change %d (bb%d):\n",
7357 0 : REGNO (new_reg), BLOCK_FOR_INSN (insn)->index);
7358 0 : dump_insn_slim (lra_dump_file, insn);
7359 0 : fprintf (lra_dump_file,
7360 : " ]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]\n");
7361 : }
7362 : }
7363 : }
7364 204557 : invariant_ptr->insn = curr_insn;
7365 204557 : return succ_p;
7366 : }
7367 :
7368 : /* Check only registers living at the current program point in the
7369 : current EBB. */
7370 : static bitmap_head live_regs;
7371 :
7372 : /* Update live info in EBB given by its HEAD and TAIL insns after
7373 : inheritance/split transformation. The function removes dead moves
7374 : too. */
7375 : static void
7376 749097 : update_ebb_live_info (rtx_insn *head, rtx_insn *tail)
7377 : {
7378 749097 : unsigned int j;
7379 749097 : int i, regno;
7380 749097 : bool live_p;
7381 749097 : rtx_insn *prev_insn;
7382 749097 : rtx set;
7383 749097 : bool remove_p;
7384 749097 : basic_block last_bb, prev_bb, curr_bb;
7385 749097 : bitmap_iterator bi;
7386 749097 : struct lra_insn_reg *reg;
7387 749097 : edge e;
7388 749097 : edge_iterator ei;
7389 :
7390 749097 : last_bb = BLOCK_FOR_INSN (tail);
7391 749097 : prev_bb = NULL;
7392 749097 : for (curr_insn = tail;
7393 39079417 : curr_insn != PREV_INSN (head);
7394 38330320 : curr_insn = prev_insn)
7395 : {
7396 38330320 : prev_insn = PREV_INSN (curr_insn);
7397 : /* We need to process empty blocks too. They contain
7398 : NOTE_INSN_BASIC_BLOCK referring for the basic block. */
7399 38330320 : if (NOTE_P (curr_insn) && NOTE_KIND (curr_insn) != NOTE_INSN_BASIC_BLOCK)
7400 1440151 : continue;
7401 36890169 : curr_bb = BLOCK_FOR_INSN (curr_insn);
7402 36890169 : if (curr_bb != prev_bb)
7403 : {
7404 1498930 : if (prev_bb != NULL)
7405 : {
7406 : /* Update df_get_live_in (prev_bb): */
7407 9724418 : EXECUTE_IF_SET_IN_BITMAP (&check_only_regs, 0, j, bi)
7408 8974585 : if (bitmap_bit_p (&live_regs, j))
7409 1265984 : bitmap_set_bit (df_get_live_in (prev_bb), j);
7410 : else
7411 7708601 : bitmap_clear_bit (df_get_live_in (prev_bb), j);
7412 : }
7413 1498930 : if (curr_bb != last_bb)
7414 : {
7415 : /* Update df_get_live_out (curr_bb): */
7416 9724418 : EXECUTE_IF_SET_IN_BITMAP (&check_only_regs, 0, j, bi)
7417 : {
7418 8974585 : live_p = bitmap_bit_p (&live_regs, j);
7419 8974585 : if (! live_p)
7420 23027953 : FOR_EACH_EDGE (e, ei, curr_bb->succs)
7421 15374998 : if (bitmap_bit_p (df_get_live_in (e->dest), j))
7422 : {
7423 : live_p = true;
7424 : break;
7425 : }
7426 7708601 : if (live_p)
7427 1321630 : bitmap_set_bit (df_get_live_out (curr_bb), j);
7428 : else
7429 7652955 : bitmap_clear_bit (df_get_live_out (curr_bb), j);
7430 : }
7431 : }
7432 1498930 : prev_bb = curr_bb;
7433 1498930 : bitmap_and (&live_regs, &check_only_regs, df_get_live_out (curr_bb));
7434 : }
7435 36890169 : if (! NONDEBUG_INSN_P (curr_insn))
7436 14246227 : continue;
7437 22643942 : curr_id = lra_get_insn_recog_data (curr_insn);
7438 22643942 : curr_static_id = curr_id->insn_static_data;
7439 22643942 : remove_p = false;
7440 22643942 : if ((set = single_set (curr_insn)) != NULL_RTX
7441 21937240 : && REG_P (SET_DEST (set))
7442 17520498 : && (regno = REGNO (SET_DEST (set))) >= FIRST_PSEUDO_REGISTER
7443 12996004 : && SET_DEST (set) != pic_offset_table_rtx
7444 12989158 : && bitmap_bit_p (&check_only_regs, regno)
7445 25932183 : && ! bitmap_bit_p (&live_regs, regno))
7446 : remove_p = true;
7447 : /* See which defined values die here. */
7448 62484745 : for (reg = curr_id->regs; reg != NULL; reg = reg->next)
7449 39840803 : if (reg->type == OP_OUT && ! reg->subreg_p)
7450 15603026 : bitmap_clear_bit (&live_regs, reg->regno);
7451 26922374 : for (reg = curr_static_id->hard_regs; reg != NULL; reg = reg->next)
7452 4278432 : if (reg->type == OP_OUT && ! reg->subreg_p)
7453 3251076 : bitmap_clear_bit (&live_regs, reg->regno);
7454 22643942 : if (curr_id->arg_hard_regs != NULL)
7455 : /* Make clobbered argument hard registers die. */
7456 3299702 : for (i = 0; (regno = curr_id->arg_hard_regs[i]) >= 0; i++)
7457 2307943 : if (regno >= FIRST_PSEUDO_REGISTER)
7458 0 : bitmap_clear_bit (&live_regs, regno - FIRST_PSEUDO_REGISTER);
7459 : /* Mark each used value as live. */
7460 62484745 : for (reg = curr_id->regs; reg != NULL; reg = reg->next)
7461 39840803 : if (reg->type != OP_OUT
7462 39840803 : && bitmap_bit_p (&check_only_regs, reg->regno))
7463 4618667 : bitmap_set_bit (&live_regs, reg->regno);
7464 26922374 : for (reg = curr_static_id->hard_regs; reg != NULL; reg = reg->next)
7465 4278432 : if (reg->type != OP_OUT
7466 4278432 : && bitmap_bit_p (&check_only_regs, reg->regno))
7467 0 : bitmap_set_bit (&live_regs, reg->regno);
7468 22643942 : if (curr_id->arg_hard_regs != NULL)
7469 : /* Make used argument hard registers live. */
7470 3299702 : for (i = 0; (regno = curr_id->arg_hard_regs[i]) >= 0; i++)
7471 2307943 : if (regno < FIRST_PSEUDO_REGISTER
7472 2307943 : && bitmap_bit_p (&check_only_regs, regno))
7473 0 : bitmap_set_bit (&live_regs, regno);
7474 : /* It is quite important to remove dead move insns because it
7475 : means removing dead store. We don't need to process them for
7476 : constraints. */
7477 22643942 : if (remove_p)
7478 : {
7479 292586 : if (lra_dump_file != NULL)
7480 : {
7481 1 : fprintf (lra_dump_file, " Removing dead insn:\n ");
7482 1 : dump_insn_slim (lra_dump_file, curr_insn);
7483 : }
7484 292586 : lra_set_insn_deleted (curr_insn);
7485 : }
7486 : }
7487 749097 : }
7488 :
7489 : /* The structure describes info to do an inheritance for the current
7490 : insn. We need to collect such info first before doing the
7491 : transformations because the transformations change the insn
7492 : internal representation. */
7493 : struct to_inherit
7494 : {
7495 : /* Original regno. */
7496 : int regno;
7497 : /* Subsequent insns which can inherit original reg value. */
7498 : rtx_insn_list *insns;
7499 : };
7500 :
7501 : /* Array containing all info for doing inheritance from the current
7502 : insn. */
7503 : static struct to_inherit to_inherit[LRA_MAX_INSN_RELOADS];
7504 :
7505 : /* Number elements in the previous array. */
7506 : static int to_inherit_num;
7507 :
7508 : /* Add inheritance info REGNO and INSNS. Their meaning is described in
7509 : structure to_inherit. */
7510 : static void
7511 329989 : add_to_inherit (int regno, rtx_insn_list *insns)
7512 : {
7513 329989 : int i;
7514 :
7515 330076 : for (i = 0; i < to_inherit_num; i++)
7516 87 : if (to_inherit[i].regno == regno)
7517 : return;
7518 329989 : lra_assert (to_inherit_num < LRA_MAX_INSN_RELOADS);
7519 329989 : to_inherit[to_inherit_num].regno = regno;
7520 329989 : to_inherit[to_inherit_num++].insns = insns;
7521 : }
7522 :
7523 : /* Return the last non-debug insn in basic block BB, or the block begin
7524 : note if none. */
7525 : static rtx_insn *
7526 30781879 : get_last_insertion_point (basic_block bb)
7527 : {
7528 30781879 : rtx_insn *insn;
7529 :
7530 33218329 : FOR_BB_INSNS_REVERSE (bb, insn)
7531 2436450 : if (NONDEBUG_INSN_P (insn) || NOTE_INSN_BASIC_BLOCK_P (insn))
7532 30781879 : return insn;
7533 0 : gcc_unreachable ();
7534 : }
7535 :
7536 : /* Set up RES by registers living on edges FROM except the edge (FROM,
7537 : TO) or by registers set up in a jump insn in BB FROM. */
7538 : static void
7539 11892469 : get_live_on_other_edges (basic_block from, basic_block to, bitmap res)
7540 : {
7541 11892469 : rtx_insn *last;
7542 11892469 : struct lra_insn_reg *reg;
7543 11892469 : edge e;
7544 11892469 : edge_iterator ei;
7545 :
7546 11892469 : lra_assert (to != NULL);
7547 11892469 : bitmap_clear (res);
7548 35393526 : FOR_EACH_EDGE (e, ei, from->succs)
7549 23501057 : if (e->dest != to)
7550 11608588 : bitmap_ior_into (res, df_get_live_in (e->dest));
7551 11892469 : last = get_last_insertion_point (from);
7552 11892469 : if (! JUMP_P (last))
7553 1979850 : return;
7554 9912619 : curr_id = lra_get_insn_recog_data (last);
7555 19824938 : for (reg = curr_id->regs; reg != NULL; reg = reg->next)
7556 9912319 : if (reg->type != OP_IN)
7557 86 : bitmap_set_bit (res, reg->regno);
7558 : }
7559 :
7560 : /* Used as a temporary results of some bitmap calculations. */
7561 : static bitmap_head temp_bitmap;
7562 :
7563 : /* We split for reloads of small class of hard regs. The following
7564 : defines how many hard regs the class should have to be qualified as
7565 : small. The code is mostly oriented to x86/x86-64 architecture
7566 : where some insns need to use only specific register or pair of
7567 : registers and these register can live in RTL explicitly, e.g. for
7568 : parameter passing. */
7569 : static const int max_small_class_regs_num = 2;
7570 :
7571 : /* Do inheritance/split transformations in EBB starting with HEAD and
7572 : finishing on TAIL. We process EBB insns in the reverse order.
7573 : Return true if we did any inheritance/split transformation in the
7574 : EBB.
7575 :
7576 : We should avoid excessive splitting which results in worse code
7577 : because of inaccurate cost calculations for spilling new split
7578 : pseudos in such case. To achieve this we do splitting only if
7579 : register pressure is high in given basic block and there are reload
7580 : pseudos requiring hard registers. We could do more register
7581 : pressure calculations at any given program point to avoid necessary
7582 : splitting even more but it is to expensive and the current approach
7583 : works well enough. */
7584 : static bool
7585 12943316 : inherit_in_ebb (rtx_insn *head, rtx_insn *tail)
7586 : {
7587 12943316 : int i, src_regno, dst_regno, nregs;
7588 12943316 : bool change_p, succ_p, update_reloads_num_p;
7589 12943316 : rtx_insn *prev_insn, *last_insn;
7590 12943316 : rtx_insn_list *next_usage_insns;
7591 12943316 : rtx curr_set;
7592 12943316 : enum reg_class cl;
7593 12943316 : struct lra_insn_reg *reg;
7594 12943316 : basic_block last_processed_bb, curr_bb = NULL;
7595 12943316 : HARD_REG_SET potential_reload_hard_regs, live_hard_regs;
7596 12943316 : bitmap to_process;
7597 12943316 : unsigned int j;
7598 12943316 : bitmap_iterator bi;
7599 12943316 : bool head_p, after_p;
7600 :
7601 12943316 : change_p = false;
7602 12943316 : curr_usage_insns_check++;
7603 12943316 : clear_invariants ();
7604 12943316 : reloads_num = calls_num = 0;
7605 168263108 : for (unsigned int i = 0; i < NUM_ABI_IDS; ++i)
7606 155319792 : last_call_for_abi[i] = 0;
7607 12943316 : CLEAR_HARD_REG_SET (full_and_partial_call_clobbers);
7608 12943316 : bitmap_clear (&check_only_regs);
7609 12943316 : bitmap_clear (&invalid_invariant_regs);
7610 12943316 : last_processed_bb = NULL;
7611 12943316 : CLEAR_HARD_REG_SET (potential_reload_hard_regs);
7612 12943316 : live_hard_regs = eliminable_regset | lra_no_alloc_regs;
7613 : /* We don't process new insns generated in the loop. */
7614 245218112 : for (curr_insn = tail; curr_insn != PREV_INSN (head); curr_insn = prev_insn)
7615 : {
7616 232274796 : prev_insn = PREV_INSN (curr_insn);
7617 232274796 : if (BLOCK_FOR_INSN (curr_insn) != NULL)
7618 232274515 : curr_bb = BLOCK_FOR_INSN (curr_insn);
7619 232274796 : if (last_processed_bb != curr_bb)
7620 : {
7621 : /* We are at the end of BB. Add qualified living
7622 : pseudos for potential splitting. */
7623 18889410 : to_process = df_get_live_out (curr_bb);
7624 18889410 : if (last_processed_bb != NULL)
7625 : {
7626 : /* We are somewhere in the middle of EBB. */
7627 5946094 : get_live_on_other_edges (curr_bb, last_processed_bb,
7628 : &temp_bitmap);
7629 5946094 : to_process = &temp_bitmap;
7630 : }
7631 18889410 : last_processed_bb = curr_bb;
7632 18889410 : last_insn = get_last_insertion_point (curr_bb);
7633 18889410 : auto call = dyn_cast<rtx_call_insn *> (last_insn);
7634 37778820 : after_p = (! JUMP_P (last_insn)
7635 18889410 : && (! call
7636 2400091 : || (find_reg_note (call,
7637 : REG_NORETURN, NULL_RTX) == NULL_RTX
7638 1425314 : && ! SIBLING_CALL_P (call))));
7639 18889410 : CLEAR_HARD_REG_SET (potential_reload_hard_regs);
7640 204362436 : EXECUTE_IF_SET_IN_BITMAP (to_process, 0, j, bi)
7641 : {
7642 185473033 : if ((int) j >= lra_constraint_new_regno_start)
7643 : break;
7644 185473026 : if (j < FIRST_PSEUDO_REGISTER || reg_renumber[j] >= 0)
7645 : {
7646 121228649 : if (j < FIRST_PSEUDO_REGISTER)
7647 70906358 : SET_HARD_REG_BIT (live_hard_regs, j);
7648 : else
7649 50322291 : add_to_hard_reg_set (&live_hard_regs,
7650 50322291 : PSEUDO_REGNO_MODE (j),
7651 50322291 : reg_renumber[j]);
7652 121228649 : setup_next_usage_insn (j, last_insn, reloads_num, after_p);
7653 : }
7654 : }
7655 : }
7656 232274796 : src_regno = dst_regno = -1;
7657 232274796 : curr_set = single_set (curr_insn);
7658 232274796 : if (curr_set != NULL_RTX && REG_P (SET_DEST (curr_set)))
7659 86445943 : dst_regno = REGNO (SET_DEST (curr_set));
7660 116986003 : if (curr_set != NULL_RTX && REG_P (SET_SRC (curr_set)))
7661 40539201 : src_regno = REGNO (SET_SRC (curr_set));
7662 232274796 : update_reloads_num_p = true;
7663 232274796 : if (src_regno < lra_constraint_new_regno_start
7664 225619049 : && src_regno >= FIRST_PSEUDO_REGISTER
7665 28528031 : && reg_renumber[src_regno] < 0
7666 3766013 : && dst_regno >= lra_constraint_new_regno_start
7667 234924751 : && (cl = lra_get_allocno_class (dst_regno)) != NO_REGS)
7668 : {
7669 : /* 'reload_pseudo <- original_pseudo'. */
7670 2649955 : if (ira_class_hard_regs_num[cl] <= max_small_class_regs_num)
7671 28983 : reloads_num++;
7672 2649955 : update_reloads_num_p = false;
7673 2649955 : succ_p = false;
7674 2649955 : if (usage_insns[src_regno].check == curr_usage_insns_check
7675 2649955 : && (next_usage_insns = usage_insns[src_regno].insns) != NULL_RTX)
7676 468916 : succ_p = inherit_reload_reg (false, src_regno, cl,
7677 : curr_insn, next_usage_insns);
7678 468916 : if (succ_p)
7679 : change_p = true;
7680 : else
7681 2197856 : setup_next_usage_insn (src_regno, curr_insn, reloads_num, false);
7682 5299910 : if (hard_reg_set_subset_p (reg_class_contents[cl], live_hard_regs))
7683 653906117 : potential_reload_hard_regs |= reg_class_contents[cl];
7684 : }
7685 229624841 : else if (src_regno < 0
7686 191735595 : && dst_regno >= lra_constraint_new_regno_start
7687 5857774 : && invariant_p (SET_SRC (curr_set))
7688 308409 : && (cl = lra_get_allocno_class (dst_regno)) != NO_REGS
7689 307872 : && ! bitmap_bit_p (&invalid_invariant_regs, dst_regno)
7690 229890808 : && ! bitmap_bit_p (&invalid_invariant_regs,
7691 265967 : ORIGINAL_REGNO(regno_reg_rtx[dst_regno])))
7692 : {
7693 : /* 'reload_pseudo <- invariant'. */
7694 204557 : if (ira_class_hard_regs_num[cl] <= max_small_class_regs_num)
7695 11137 : reloads_num++;
7696 204557 : update_reloads_num_p = false;
7697 204557 : if (process_invariant_for_inheritance (SET_DEST (curr_set), SET_SRC (curr_set)))
7698 30494 : change_p = true;
7699 409114 : if (hard_reg_set_subset_p (reg_class_contents[cl], live_hard_regs))
7700 653906117 : potential_reload_hard_regs |= reg_class_contents[cl];
7701 : }
7702 229420284 : else if (src_regno >= lra_constraint_new_regno_start
7703 6655747 : && dst_regno < lra_constraint_new_regno_start
7704 5845985 : && dst_regno >= FIRST_PSEUDO_REGISTER
7705 3876237 : && reg_renumber[dst_regno] < 0
7706 1481804 : && (cl = lra_get_allocno_class (src_regno)) != NO_REGS
7707 1481804 : && usage_insns[dst_regno].check == curr_usage_insns_check
7708 229420284 : && (next_usage_insns
7709 482675 : = usage_insns[dst_regno].insns) != NULL_RTX)
7710 : {
7711 482675 : if (ira_class_hard_regs_num[cl] <= max_small_class_regs_num)
7712 10179 : reloads_num++;
7713 482675 : update_reloads_num_p = false;
7714 : /* 'original_pseudo <- reload_pseudo'. */
7715 482675 : if (! JUMP_P (curr_insn)
7716 482675 : && inherit_reload_reg (true, dst_regno, cl,
7717 : curr_insn, next_usage_insns))
7718 : change_p = true;
7719 : /* Invalidate. */
7720 482675 : usage_insns[dst_regno].check = 0;
7721 965350 : if (hard_reg_set_subset_p (reg_class_contents[cl], live_hard_regs))
7722 653906117 : potential_reload_hard_regs |= reg_class_contents[cl];
7723 : }
7724 228937609 : else if (INSN_P (curr_insn))
7725 : {
7726 192617975 : int iter;
7727 192617975 : int max_uid = get_max_uid ();
7728 :
7729 192617975 : curr_id = lra_get_insn_recog_data (curr_insn);
7730 192617975 : curr_static_id = curr_id->insn_static_data;
7731 192617975 : to_inherit_num = 0;
7732 : /* Process insn definitions. */
7733 577853925 : for (iter = 0; iter < 2; iter++)
7734 385235950 : for (reg = iter == 0 ? curr_id->regs : curr_static_id->hard_regs;
7735 619569965 : reg != NULL;
7736 234334015 : reg = reg->next)
7737 234334015 : if (reg->type != OP_IN
7738 234334015 : && (dst_regno = reg->regno) < lra_constraint_new_regno_start)
7739 : {
7740 47244357 : if (dst_regno >= FIRST_PSEUDO_REGISTER && reg->type == OP_OUT
7741 44980633 : && reg_renumber[dst_regno] < 0 && ! reg->subreg_p
7742 1828462 : && usage_insns[dst_regno].check == curr_usage_insns_check
7743 93720727 : && (next_usage_insns
7744 131481 : = usage_insns[dst_regno].insns) != NULL_RTX)
7745 : {
7746 131481 : struct lra_insn_reg *r;
7747 :
7748 392283 : for (r = curr_id->regs; r != NULL; r = r->next)
7749 260802 : if (r->type != OP_OUT && r->regno == dst_regno)
7750 : break;
7751 : /* Don't do inheritance if the pseudo is also
7752 : used in the insn. */
7753 131481 : if (r == NULL)
7754 : /* We cannot do inheritance right now
7755 : because the current insn reg info (chain
7756 : regs) can change after that. */
7757 131481 : add_to_inherit (dst_regno, next_usage_insns);
7758 : }
7759 : /* We cannot process one reg twice here because of
7760 : usage_insns invalidation. */
7761 93720727 : if ((dst_regno < FIRST_PSEUDO_REGISTER
7762 47244357 : || reg_renumber[dst_regno] >= 0)
7763 91752959 : && ! reg->subreg_p && reg->type != OP_IN)
7764 : {
7765 91463067 : HARD_REG_SET s;
7766 :
7767 91463067 : if (split_if_necessary (dst_regno, reg->biggest_mode,
7768 : potential_reload_hard_regs,
7769 : false, curr_insn, max_uid))
7770 58368 : change_p = true;
7771 91463067 : CLEAR_HARD_REG_SET (s);
7772 91463067 : if (dst_regno < FIRST_PSEUDO_REGISTER)
7773 46476370 : add_to_hard_reg_set (&s, reg->biggest_mode, dst_regno);
7774 : else
7775 44986697 : add_to_hard_reg_set (&s, PSEUDO_REGNO_MODE (dst_regno),
7776 44986697 : reg_renumber[dst_regno]);
7777 91463067 : live_hard_regs &= ~s;
7778 182926134 : potential_reload_hard_regs &= ~s;
7779 : }
7780 : /* We should invalidate potential inheritance or
7781 : splitting for the current insn usages to the next
7782 : usage insns (see code below) as the output pseudo
7783 : prevents this. */
7784 93720727 : if ((dst_regno >= FIRST_PSEUDO_REGISTER
7785 47244357 : && reg_renumber[dst_regno] < 0)
7786 91752959 : || (reg->type == OP_OUT && ! reg->subreg_p
7787 83580326 : && (dst_regno < FIRST_PSEUDO_REGISTER
7788 42731546 : || reg_renumber[dst_regno] >= 0)))
7789 : {
7790 : /* Invalidate and mark definitions. */
7791 44699314 : if (dst_regno >= FIRST_PSEUDO_REGISTER)
7792 44699314 : usage_insns[dst_regno].check = -(int) INSN_UID (curr_insn);
7793 : else
7794 : {
7795 40848780 : nregs = hard_regno_nregs (dst_regno,
7796 40848780 : reg->biggest_mode);
7797 81961033 : for (i = 0; i < nregs; i++)
7798 82224506 : usage_insns[dst_regno + i].check
7799 41112253 : = -(int) INSN_UID (curr_insn);
7800 : }
7801 : }
7802 : }
7803 : /* Process clobbered call regs. */
7804 192617975 : if (curr_id->arg_hard_regs != NULL)
7805 19845448 : for (i = 0; (dst_regno = curr_id->arg_hard_regs[i]) >= 0; i++)
7806 13892202 : if (dst_regno >= FIRST_PSEUDO_REGISTER)
7807 0 : usage_insns[dst_regno - FIRST_PSEUDO_REGISTER].check
7808 0 : = -(int) INSN_UID (curr_insn);
7809 192617975 : if (! JUMP_P (curr_insn))
7810 180988193 : for (i = 0; i < to_inherit_num; i++)
7811 131481 : if (inherit_reload_reg (true, to_inherit[i].regno,
7812 : ALL_REGS, curr_insn,
7813 : to_inherit[i].insns))
7814 104168 : change_p = true;
7815 192617975 : if (auto call = dyn_cast<rtx_call_insn *> (curr_insn))
7816 : {
7817 7544283 : rtx cheap, pat, dest;
7818 7544283 : rtx_insn *restore;
7819 7544283 : int regno, hard_regno;
7820 :
7821 7544283 : calls_num++;
7822 7544283 : function_abi callee_abi = insn_callee_abi (call);
7823 7544283 : last_call_for_abi[callee_abi.id ()] = calls_num;
7824 7544283 : full_and_partial_call_clobbers
7825 7544283 : |= callee_abi.full_and_partial_reg_clobbers ();
7826 7544283 : first_call_insn = call;
7827 7544283 : if ((cheap = find_reg_note (call,
7828 : REG_RETURNED, NULL_RTX)) != NULL_RTX
7829 47053 : && ((cheap = XEXP (cheap, 0)), true)
7830 47053 : && (regno = REGNO (cheap)) >= FIRST_PSEUDO_REGISTER
7831 47053 : && (hard_regno = reg_renumber[regno]) >= 0
7832 34492 : && usage_insns[regno].check == curr_usage_insns_check
7833 : /* If there are pending saves/restores, the
7834 : optimization is not worth. */
7835 29584 : && usage_insns[regno].calls_num == calls_num - 1
7836 7571978 : && callee_abi.clobbers_reg_p (GET_MODE (cheap), hard_regno))
7837 : {
7838 : /* Restore the pseudo from the call result as
7839 : REG_RETURNED note says that the pseudo value is
7840 : in the call result and the pseudo is an argument
7841 : of the call. */
7842 12026 : pat = PATTERN (call);
7843 12026 : if (GET_CODE (pat) == PARALLEL)
7844 0 : pat = XVECEXP (pat, 0, 0);
7845 12026 : dest = SET_DEST (pat);
7846 : /* For multiple return values dest is PARALLEL.
7847 : Currently we handle only single return value case. */
7848 12026 : if (REG_P (dest))
7849 : {
7850 12026 : start_sequence ();
7851 12026 : emit_move_insn (cheap, copy_rtx (dest));
7852 12026 : restore = end_sequence ();
7853 12026 : lra_process_new_insns (call, NULL, restore,
7854 : "Inserting call parameter restore");
7855 : /* We don't need to save/restore of the pseudo from
7856 : this call. */
7857 12026 : usage_insns[regno].calls_num = calls_num;
7858 12026 : remove_from_hard_reg_set
7859 12026 : (&full_and_partial_call_clobbers,
7860 12026 : GET_MODE (cheap), hard_regno);
7861 12026 : bitmap_set_bit (&check_only_regs, regno);
7862 : }
7863 : }
7864 : }
7865 192617975 : to_inherit_num = 0;
7866 : /* Process insn usages. */
7867 577853925 : for (iter = 0; iter < 2; iter++)
7868 385235950 : for (reg = iter == 0 ? curr_id->regs : curr_static_id->hard_regs;
7869 619569965 : reg != NULL;
7870 234334015 : reg = reg->next)
7871 234334015 : if ((reg->type != OP_OUT
7872 92512946 : || (reg->type == OP_OUT && reg->subreg_p))
7873 234872379 : && (src_regno = reg->regno) < lra_constraint_new_regno_start)
7874 : {
7875 130504247 : if (src_regno >= FIRST_PSEUDO_REGISTER
7876 75673343 : && reg_renumber[src_regno] < 0 && reg->type == OP_IN)
7877 : {
7878 2575127 : if (usage_insns[src_regno].check == curr_usage_insns_check
7879 843087 : && (next_usage_insns
7880 843087 : = usage_insns[src_regno].insns) != NULL_RTX
7881 3418214 : && NONDEBUG_INSN_P (curr_insn))
7882 198508 : add_to_inherit (src_regno, next_usage_insns);
7883 4753238 : else if (usage_insns[src_regno].check
7884 2376619 : != -(int) INSN_UID (curr_insn))
7885 : /* Add usages but only if the reg is not set up
7886 : in the same insn. */
7887 2376619 : add_next_usage_insn (src_regno, curr_insn, reloads_num);
7888 : }
7889 73098216 : else if (src_regno < FIRST_PSEUDO_REGISTER
7890 73098216 : || reg_renumber[src_regno] >= 0)
7891 : {
7892 127789814 : bool before_p;
7893 127789814 : rtx_insn *use_insn = curr_insn;
7894 127789814 : rtx_insn *prev_insn = PREV_INSN (curr_insn);
7895 :
7896 255579628 : before_p = (JUMP_P (curr_insn)
7897 127789814 : || (CALL_P (curr_insn) && reg->type == OP_IN));
7898 127789814 : if (NONDEBUG_INSN_P (curr_insn)
7899 114014545 : && (! JUMP_P (curr_insn) || reg->type == OP_IN)
7900 241804254 : && split_if_necessary (src_regno, reg->biggest_mode,
7901 : potential_reload_hard_regs,
7902 : before_p, curr_insn, max_uid))
7903 : {
7904 223060 : if (reg->subreg_p)
7905 3124 : check_and_force_assignment_correctness_p = true;
7906 223060 : change_p = true;
7907 : /* Invalidate. */
7908 223060 : usage_insns[src_regno].check = 0;
7909 223060 : if (before_p && PREV_INSN (curr_insn) != prev_insn)
7910 : use_insn = PREV_INSN (curr_insn);
7911 : }
7912 127789814 : if (NONDEBUG_INSN_P (curr_insn))
7913 : {
7914 114014545 : if (src_regno < FIRST_PSEUDO_REGISTER)
7915 49974179 : add_to_hard_reg_set (&live_hard_regs,
7916 49974179 : reg->biggest_mode, src_regno);
7917 : else
7918 64040366 : add_to_hard_reg_set (&live_hard_regs,
7919 64040366 : PSEUDO_REGNO_MODE (src_regno),
7920 64040366 : reg_renumber[src_regno]);
7921 : }
7922 127789814 : if (src_regno >= FIRST_PSEUDO_REGISTER)
7923 72958910 : add_next_usage_insn (src_regno, use_insn, reloads_num);
7924 : else
7925 : {
7926 109761723 : for (i = 0; i < hard_regno_nregs (src_regno, reg->biggest_mode); i++)
7927 54930819 : add_next_usage_insn (src_regno + i, use_insn, reloads_num);
7928 : }
7929 : }
7930 : }
7931 : /* Process used call regs. */
7932 192617975 : if (curr_id->arg_hard_regs != NULL)
7933 19845448 : for (i = 0; (src_regno = curr_id->arg_hard_regs[i]) >= 0; i++)
7934 13892202 : if (src_regno < FIRST_PSEUDO_REGISTER)
7935 : {
7936 13892202 : SET_HARD_REG_BIT (live_hard_regs, src_regno);
7937 13892202 : add_next_usage_insn (src_regno, curr_insn, reloads_num);
7938 : }
7939 192816483 : for (i = 0; i < to_inherit_num; i++)
7940 : {
7941 198508 : src_regno = to_inherit[i].regno;
7942 198508 : if (inherit_reload_reg (false, src_regno, ALL_REGS,
7943 : curr_insn, to_inherit[i].insns))
7944 : change_p = true;
7945 : else
7946 21935 : setup_next_usage_insn (src_regno, curr_insn, reloads_num, false);
7947 : }
7948 : }
7949 192693712 : if (update_reloads_num_p
7950 228937609 : && NONDEBUG_INSN_P (curr_insn) && curr_set != NULL_RTX)
7951 : {
7952 113648816 : int regno = -1;
7953 113648816 : if ((REG_P (SET_DEST (curr_set))
7954 83108756 : && (regno = REGNO (SET_DEST (curr_set))) >= lra_constraint_new_regno_start
7955 8566839 : && reg_renumber[regno] < 0
7956 5480552 : && (cl = lra_get_allocno_class (regno)) != NO_REGS)
7957 191555960 : || (REG_P (SET_SRC (curr_set))
7958 36057720 : && (regno = REGNO (SET_SRC (curr_set))) >= lra_constraint_new_regno_start
7959 6246815 : && reg_renumber[regno] < 0
7960 3693003 : && (cl = lra_get_allocno_class (regno)) != NO_REGS))
7961 : {
7962 8628286 : if (ira_class_hard_regs_num[cl] <= max_small_class_regs_num)
7963 274222 : reloads_num++;
7964 17256572 : if (hard_reg_set_subset_p (reg_class_contents[cl], live_hard_regs))
7965 232274796 : potential_reload_hard_regs |= reg_class_contents[cl];
7966 : }
7967 : }
7968 232274796 : if (NONDEBUG_INSN_P (curr_insn))
7969 : {
7970 123498072 : int regno;
7971 :
7972 : /* Invalidate invariants with changed regs. */
7973 123498072 : curr_id = lra_get_insn_recog_data (curr_insn);
7974 316803869 : for (reg = curr_id->regs; reg != NULL; reg = reg->next)
7975 193305797 : if (reg->type != OP_IN)
7976 : {
7977 82932321 : bitmap_set_bit (&invalid_invariant_regs, reg->regno);
7978 165864642 : bitmap_set_bit (&invalid_invariant_regs,
7979 82932321 : ORIGINAL_REGNO (regno_reg_rtx[reg->regno]));
7980 : }
7981 123498072 : curr_static_id = curr_id->insn_static_data;
7982 155924365 : for (reg = curr_static_id->hard_regs; reg != NULL; reg = reg->next)
7983 32426293 : if (reg->type != OP_IN)
7984 23230754 : bitmap_set_bit (&invalid_invariant_regs, reg->regno);
7985 123498072 : if (curr_id->arg_hard_regs != NULL)
7986 19845448 : for (i = 0; (regno = curr_id->arg_hard_regs[i]) >= 0; i++)
7987 13892202 : if (regno >= FIRST_PSEUDO_REGISTER)
7988 0 : bitmap_set_bit (&invalid_invariant_regs,
7989 : regno - FIRST_PSEUDO_REGISTER);
7990 : }
7991 : /* We reached the start of the current basic block. */
7992 232274774 : if (prev_insn == NULL_RTX || prev_insn == PREV_INSN (head)
7993 451606276 : || BLOCK_FOR_INSN (prev_insn) != curr_bb)
7994 : {
7995 : /* We reached the beginning of the current block -- do
7996 : rest of splitting in the current BB. */
7997 18889691 : to_process = df_get_live_in (curr_bb);
7998 18889691 : if (BLOCK_FOR_INSN (head) != curr_bb)
7999 : {
8000 : /* We are somewhere in the middle of EBB. */
8001 5946375 : get_live_on_other_edges (EDGE_PRED (curr_bb, 0)->src,
8002 : curr_bb, &temp_bitmap);
8003 5946375 : to_process = &temp_bitmap;
8004 : }
8005 18889691 : head_p = true;
8006 197425413 : EXECUTE_IF_SET_IN_BITMAP (to_process, 0, j, bi)
8007 : {
8008 178535730 : if ((int) j >= lra_constraint_new_regno_start)
8009 : break;
8010 113509012 : if (((int) j < FIRST_PSEUDO_REGISTER || reg_renumber[j] >= 0)
8011 113192700 : && usage_insns[j].check == curr_usage_insns_check
8012 289792259 : && (next_usage_insns = usage_insns[j].insns) != NULL_RTX)
8013 : {
8014 111256537 : if (need_for_split_p (potential_reload_hard_regs, j))
8015 : {
8016 389277 : if (lra_dump_file != NULL && head_p)
8017 : {
8018 0 : fprintf (lra_dump_file,
8019 : " ----------------------------------\n");
8020 0 : head_p = false;
8021 : }
8022 389277 : if (split_reg (false, j, bb_note (curr_bb),
8023 : next_usage_insns, NULL))
8024 389277 : change_p = true;
8025 : }
8026 111256537 : usage_insns[j].check = 0;
8027 : }
8028 : }
8029 : }
8030 : }
8031 12943316 : first_call_insn = NULL;
8032 12943316 : return change_p;
8033 : }
8034 :
8035 : /* This value affects EBB forming. If probability of edge from EBB to
8036 : a BB is not greater than the following value, we don't add the BB
8037 : to EBB. */
8038 : #define EBB_PROBABILITY_CUTOFF \
8039 : ((REG_BR_PROB_BASE * param_lra_inheritance_ebb_probability_cutoff) / 100)
8040 :
8041 : /* Current number of inheritance/split iteration. */
8042 : int lra_inheritance_iter;
8043 :
8044 : /* Entry function for inheritance/split pass. */
8045 : void
8046 1599592 : lra_inheritance (void)
8047 : {
8048 1599592 : int i;
8049 1599592 : basic_block bb, start_bb;
8050 1599592 : edge e;
8051 :
8052 1599592 : lra_inheritance_iter++;
8053 1599592 : if (lra_inheritance_iter > LRA_MAX_INHERITANCE_PASSES)
8054 : return;
8055 1595813 : timevar_push (TV_LRA_INHERITANCE);
8056 1595813 : if (lra_dump_file != NULL)
8057 96 : fprintf (lra_dump_file, "\n********** Inheritance #%d: **********\n\n",
8058 : lra_inheritance_iter);
8059 1595813 : curr_usage_insns_check = 0;
8060 1595813 : usage_insns = XNEWVEC (struct usage_insns, lra_constraint_new_regno_start);
8061 240540294 : for (i = 0; i < lra_constraint_new_regno_start; i++)
8062 238944481 : usage_insns[i].check = 0;
8063 1595813 : bitmap_initialize (&check_only_regs, ®_obstack);
8064 1595813 : bitmap_initialize (&invalid_invariant_regs, ®_obstack);
8065 1595813 : bitmap_initialize (&live_regs, ®_obstack);
8066 1595813 : bitmap_initialize (&temp_bitmap, ®_obstack);
8067 1595813 : bitmap_initialize (&ebb_global_regs, ®_obstack);
8068 14539129 : FOR_EACH_BB_FN (bb, cfun)
8069 : {
8070 12943316 : start_bb = bb;
8071 12943316 : if (lra_dump_file != NULL)
8072 321 : fprintf (lra_dump_file, "EBB");
8073 : /* Form a EBB starting with BB. */
8074 12943316 : bitmap_clear (&ebb_global_regs);
8075 12943316 : bitmap_ior_into (&ebb_global_regs, df_get_live_in (bb));
8076 24835504 : for (;;)
8077 : {
8078 18889410 : if (lra_dump_file != NULL)
8079 435 : fprintf (lra_dump_file, " %d", bb->index);
8080 18889410 : if (bb->next_bb == EXIT_BLOCK_PTR_FOR_FN (cfun)
8081 17293597 : || LABEL_P (BB_HEAD (bb->next_bb)))
8082 : break;
8083 8364540 : e = find_fallthru_edge (bb->succs);
8084 8364540 : if (! e)
8085 : break;
8086 8364540 : if (e->probability.initialized_p ()
8087 8364540 : && e->probability.to_reg_br_prob_base () < EBB_PROBABILITY_CUTOFF)
8088 : break;
8089 5946094 : bb = bb->next_bb;
8090 : }
8091 12943316 : bitmap_ior_into (&ebb_global_regs, df_get_live_out (bb));
8092 12943316 : if (lra_dump_file != NULL)
8093 321 : fprintf (lra_dump_file, "\n");
8094 12943316 : if (inherit_in_ebb (BB_HEAD (start_bb), BB_END (bb)))
8095 : /* Remember that the EBB head and tail can change in
8096 : inherit_in_ebb. */
8097 749097 : update_ebb_live_info (BB_HEAD (start_bb), BB_END (bb));
8098 : }
8099 1595813 : bitmap_release (&ebb_global_regs);
8100 1595813 : bitmap_release (&temp_bitmap);
8101 1595813 : bitmap_release (&live_regs);
8102 1595813 : bitmap_release (&invalid_invariant_regs);
8103 1595813 : bitmap_release (&check_only_regs);
8104 1595813 : free (usage_insns);
8105 1595813 : lra_dump_insns_if_possible ("func after inheritance");
8106 1595813 : timevar_pop (TV_LRA_INHERITANCE);
8107 : }
8108 :
8109 :
8110 :
8111 : /* This page contains code to undo failed inheritance/split
8112 : transformations. */
8113 :
8114 : /* Current number of iteration undoing inheritance/split. */
8115 : int lra_undo_inheritance_iter;
8116 :
8117 : /* Fix BB live info LIVE after removing pseudos created on pass doing
8118 : inheritance/split which are REMOVED_PSEUDOS. */
8119 : static void
8120 37778820 : fix_bb_live_info (bitmap live, bitmap removed_pseudos)
8121 : {
8122 37778820 : unsigned int regno;
8123 37778820 : bitmap_iterator bi;
8124 :
8125 180473602 : EXECUTE_IF_SET_IN_BITMAP (removed_pseudos, 0, regno, bi)
8126 142694782 : if (bitmap_clear_bit (live, regno)
8127 142694782 : && REG_P (lra_reg_info[regno].restore_rtx))
8128 511970 : bitmap_set_bit (live, REGNO (lra_reg_info[regno].restore_rtx));
8129 37778820 : }
8130 :
8131 : /* Return regno of the (subreg of) REG. Otherwise, return a negative
8132 : number. */
8133 : static int
8134 70738478 : get_regno (rtx reg)
8135 : {
8136 1018324 : if (GET_CODE (reg) == SUBREG)
8137 1067696 : reg = SUBREG_REG (reg);
8138 70738478 : if (REG_P (reg))
8139 45755673 : return REGNO (reg);
8140 : return -1;
8141 : }
8142 :
8143 : /* Delete a move INSN with destination reg DREGNO and a previous
8144 : clobber insn with the same regno. The inheritance/split code can
8145 : generate moves with preceding clobber and when we delete such moves
8146 : we should delete the clobber insn too to keep the correct life
8147 : info. */
8148 : static void
8149 764276 : delete_move_and_clobber (rtx_insn *insn, int dregno)
8150 : {
8151 764276 : rtx_insn *prev_insn = PREV_INSN (insn);
8152 :
8153 764276 : lra_set_insn_deleted (insn);
8154 764276 : lra_assert (dregno >= 0);
8155 764276 : if (prev_insn != NULL && NONDEBUG_INSN_P (prev_insn)
8156 334285 : && GET_CODE (PATTERN (prev_insn)) == CLOBBER
8157 764788 : && dregno == get_regno (XEXP (PATTERN (prev_insn), 0)))
8158 0 : lra_set_insn_deleted (prev_insn);
8159 764276 : }
8160 :
8161 : /* Remove inheritance/split pseudos which are in REMOVE_PSEUDOS and
8162 : return true if we did any change. The undo transformations for
8163 : inheritance looks like
8164 : i <- i2
8165 : p <- i => p <- i2
8166 : or removing
8167 : p <- i, i <- p, and i <- i3
8168 : where p is original pseudo from which inheritance pseudo i was
8169 : created, i and i3 are removed inheritance pseudos, i2 is another
8170 : not removed inheritance pseudo. All split pseudos or other
8171 : occurrences of removed inheritance pseudos are changed on the
8172 : corresponding original pseudos.
8173 :
8174 : The function also schedules insns changed and created during
8175 : inheritance/split pass for processing by the subsequent constraint
8176 : pass. */
8177 : static bool
8178 1595813 : remove_inheritance_pseudos (bitmap remove_pseudos)
8179 : {
8180 1595813 : basic_block bb;
8181 1595813 : int regno, sregno, prev_sregno, dregno;
8182 1595813 : rtx restore_rtx;
8183 1595813 : rtx set, prev_set;
8184 1595813 : rtx_insn *prev_insn;
8185 1595813 : bool change_p, done_p;
8186 :
8187 1595813 : change_p = ! bitmap_empty_p (remove_pseudos);
8188 : /* We cannot finish the function right away if CHANGE_P is true
8189 : because we need to marks insns affected by previous
8190 : inheritance/split pass for processing by the subsequent
8191 : constraint pass. */
8192 20485223 : FOR_EACH_BB_FN (bb, cfun)
8193 : {
8194 18889410 : fix_bb_live_info (df_get_live_in (bb), remove_pseudos);
8195 18889410 : fix_bb_live_info (df_get_live_out (bb), remove_pseudos);
8196 253755917 : FOR_BB_INSNS_REVERSE (bb, curr_insn)
8197 : {
8198 234866507 : if (! INSN_P (curr_insn))
8199 36671270 : continue;
8200 198195237 : done_p = false;
8201 198195237 : sregno = dregno = -1;
8202 49626674 : if (change_p && NONDEBUG_INSN_P (curr_insn)
8203 231103826 : && (set = single_set (curr_insn)) != NULL_RTX)
8204 : {
8205 31850550 : dregno = get_regno (SET_DEST (set));
8206 63701100 : sregno = get_regno (SET_SRC (set));
8207 : }
8208 :
8209 198195237 : if (sregno >= 0 && dregno >= 0)
8210 : {
8211 11339974 : if (bitmap_bit_p (remove_pseudos, dregno)
8212 11339974 : && ! REG_P (lra_reg_info[dregno].restore_rtx))
8213 : {
8214 : /* invariant inheritance pseudo <- original pseudo */
8215 9526 : if (lra_dump_file != NULL)
8216 : {
8217 0 : fprintf (lra_dump_file, " Removing invariant inheritance:\n");
8218 0 : dump_insn_slim (lra_dump_file, curr_insn);
8219 0 : fprintf (lra_dump_file, "\n");
8220 : }
8221 9526 : delete_move_and_clobber (curr_insn, dregno);
8222 9526 : done_p = true;
8223 : }
8224 11330448 : else if (bitmap_bit_p (remove_pseudos, sregno)
8225 11330448 : && ! REG_P (lra_reg_info[sregno].restore_rtx))
8226 : {
8227 : /* reload pseudo <- invariant inheritance pseudo */
8228 9526 : start_sequence ();
8229 : /* We cannot just change the source. It might be
8230 : an insn different from the move. */
8231 9526 : emit_insn (lra_reg_info[sregno].restore_rtx);
8232 9526 : rtx_insn *new_insns = end_sequence ();
8233 9526 : lra_assert (single_set (new_insns) != NULL
8234 : && SET_DEST (set) == SET_DEST (single_set (new_insns)));
8235 9526 : lra_process_new_insns (curr_insn, NULL, new_insns,
8236 : "Changing reload<-invariant inheritance");
8237 9526 : delete_move_and_clobber (curr_insn, dregno);
8238 9526 : done_p = true;
8239 : }
8240 11320922 : else if ((bitmap_bit_p (remove_pseudos, sregno)
8241 1299058 : && (get_regno (lra_reg_info[sregno].restore_rtx) == dregno
8242 610426 : || (bitmap_bit_p (remove_pseudos, dregno)
8243 211630 : && get_regno (lra_reg_info[sregno].restore_rtx) >= 0
8244 211630 : && (get_regno (lra_reg_info[sregno].restore_rtx)
8245 211630 : == get_regno (lra_reg_info[dregno].restore_rtx)))))
8246 11825533 : || (bitmap_bit_p (remove_pseudos, dregno)
8247 685488 : && get_regno (lra_reg_info[dregno].restore_rtx) == sregno))
8248 : /* One of the following cases:
8249 : original <- removed inheritance pseudo
8250 : removed inherit pseudo <- another removed inherit pseudo
8251 : removed inherit pseudo <- original pseudo
8252 : Or
8253 : removed_split_pseudo <- original_reg
8254 : original_reg <- removed_split_pseudo */
8255 : {
8256 194076 : if (lra_dump_file != NULL)
8257 : {
8258 0 : fprintf (lra_dump_file, " Removing %s:\n",
8259 0 : bitmap_bit_p (&lra_split_regs, sregno)
8260 0 : || bitmap_bit_p (&lra_split_regs, dregno)
8261 : ? "split" : "inheritance");
8262 0 : dump_insn_slim (lra_dump_file, curr_insn);
8263 : }
8264 194076 : delete_move_and_clobber (curr_insn, dregno);
8265 194076 : done_p = true;
8266 : }
8267 11126846 : else if (bitmap_bit_p (remove_pseudos, sregno)
8268 11126846 : && bitmap_bit_p (&lra_inheritance_pseudos, sregno))
8269 : {
8270 : /* Search the following pattern:
8271 : inherit_or_split_pseudo1 <- inherit_or_split_pseudo2
8272 : original_pseudo <- inherit_or_split_pseudo1
8273 : where the 2nd insn is the current insn and
8274 : inherit_or_split_pseudo2 is not removed. If it is found,
8275 : change the current insn onto:
8276 : original_pseudo <- inherit_or_split_pseudo2. */
8277 787143 : for (prev_insn = PREV_INSN (curr_insn);
8278 787143 : prev_insn != NULL_RTX && ! NONDEBUG_INSN_P (prev_insn);
8279 282532 : prev_insn = PREV_INSN (prev_insn))
8280 : ;
8281 504611 : if (prev_insn != NULL_RTX && BLOCK_FOR_INSN (prev_insn) == bb
8282 492135 : && (prev_set = single_set (prev_insn)) != NULL_RTX
8283 : /* There should be no subregs in insn we are
8284 : searching because only the original reg might
8285 : be in subreg when we changed the mode of
8286 : load/store for splitting. */
8287 485570 : && REG_P (SET_DEST (prev_set))
8288 377735 : && REG_P (SET_SRC (prev_set))
8289 290577 : && (int) REGNO (SET_DEST (prev_set)) == sregno
8290 196694 : && ((prev_sregno = REGNO (SET_SRC (prev_set)))
8291 : >= FIRST_PSEUDO_REGISTER)
8292 196694 : && (lra_reg_info[prev_sregno].restore_rtx == NULL_RTX
8293 154860 : ||
8294 : /* As we consider chain of inheritance or
8295 : splitting described in above comment we should
8296 : check that sregno and prev_sregno were
8297 : inheritance/split pseudos created from the
8298 : same original regno. */
8299 309720 : (get_regno (lra_reg_info[sregno].restore_rtx) >= 0
8300 309720 : && (get_regno (lra_reg_info[sregno].restore_rtx)
8301 309720 : == get_regno (lra_reg_info[prev_sregno].restore_rtx))))
8302 701305 : && ! bitmap_bit_p (remove_pseudos, prev_sregno))
8303 : {
8304 106100 : int restore_regno = get_regno (lra_reg_info[sregno].restore_rtx);
8305 106100 : if (restore_regno < 0)
8306 0 : restore_regno = prev_sregno;
8307 106100 : lra_assert (GET_MODE (SET_SRC (prev_set))
8308 : == GET_MODE (regno_reg_rtx[restore_regno]));
8309 : /* Although we have a single set, the insn can
8310 : contain more one sregno register occurrence
8311 : as a source. Change all occurrences. */
8312 106100 : lra_substitute_pseudo_within_insn (curr_insn, sregno,
8313 : regno_reg_rtx[restore_regno],
8314 : false);
8315 : /* As we are finishing with processing the insn
8316 : here, check the destination too as it might
8317 : inheritance pseudo for another pseudo. */
8318 106100 : if (bitmap_bit_p (remove_pseudos, dregno)
8319 0 : && bitmap_bit_p (&lra_inheritance_pseudos, dregno)
8320 106100 : && (restore_rtx
8321 0 : = lra_reg_info[dregno].restore_rtx) != NULL_RTX)
8322 : {
8323 0 : if (GET_CODE (SET_DEST (set)) == SUBREG)
8324 0 : SUBREG_REG (SET_DEST (set)) = restore_rtx;
8325 : else
8326 0 : SET_DEST (set) = restore_rtx;
8327 : }
8328 106100 : lra_push_insn_and_update_insn_regno_info (curr_insn);
8329 106100 : lra_set_used_insn_alternative_by_uid
8330 106100 : (INSN_UID (curr_insn), LRA_UNKNOWN_ALT);
8331 106100 : done_p = true;
8332 106100 : if (lra_dump_file != NULL)
8333 : {
8334 0 : fprintf (lra_dump_file, " Change reload insn:\n");
8335 0 : dump_insn_slim (lra_dump_file, curr_insn);
8336 : }
8337 : }
8338 : }
8339 : }
8340 213128 : if (! done_p)
8341 : {
8342 197876009 : struct lra_insn_reg *reg;
8343 197876009 : bool restored_regs_p = false;
8344 197876009 : bool kept_regs_p = false;
8345 :
8346 197876009 : curr_id = lra_get_insn_recog_data (curr_insn);
8347 410145134 : for (reg = curr_id->regs; reg != NULL; reg = reg->next)
8348 : {
8349 212269125 : regno = reg->regno;
8350 212269125 : restore_rtx = lra_reg_info[regno].restore_rtx;
8351 212269125 : if (restore_rtx != NULL_RTX)
8352 : {
8353 5989681 : if (change_p && bitmap_bit_p (remove_pseudos, regno))
8354 : {
8355 893192 : lra_substitute_pseudo_within_insn
8356 893192 : (curr_insn, regno, restore_rtx, false);
8357 893192 : restored_regs_p = true;
8358 : }
8359 : else
8360 : kept_regs_p = true;
8361 : }
8362 : }
8363 197876009 : if (NONDEBUG_INSN_P (curr_insn) && kept_regs_p)
8364 : {
8365 : /* The instruction has changed since the previous
8366 : constraints pass. */
8367 4484913 : lra_push_insn_and_update_insn_regno_info (curr_insn);
8368 4484913 : lra_set_used_insn_alternative_by_uid
8369 4484913 : (INSN_UID (curr_insn), LRA_UNKNOWN_ALT);
8370 : }
8371 193391096 : else if (restored_regs_p)
8372 : /* The instruction has been restored to the form that
8373 : it had during the previous constraints pass. */
8374 715806 : lra_update_insn_regno_info (curr_insn);
8375 5200719 : if (restored_regs_p && lra_dump_file != NULL)
8376 : {
8377 0 : fprintf (lra_dump_file, " Insn after restoring regs:\n");
8378 0 : dump_insn_slim (lra_dump_file, curr_insn);
8379 : }
8380 : }
8381 : }
8382 : }
8383 1595813 : return change_p;
8384 : }
8385 :
8386 : /* Return true if REGNO is an inheritance pseudo. */
8387 : static bool
8388 131191 : inheritance_pseudo_p (int regno)
8389 : {
8390 131191 : return (regno >= new_regno_start
8391 131191 : && bitmap_bit_p (&lra_inheritance_pseudos, regno));
8392 : }
8393 :
8394 : /* If optional reload pseudos failed to get a hard register or was not
8395 : inherited, it is better to remove optional reloads. We do this
8396 : transformation after undoing inheritance to figure out necessity to
8397 : remove optional reloads easier. Return true if we do any
8398 : change. */
8399 : static bool
8400 1595813 : undo_optional_reloads (void)
8401 : {
8402 1595813 : bool change_p, keep_p;
8403 1595813 : unsigned int regno, uid;
8404 1595813 : bitmap_iterator bi, bi2;
8405 1595813 : rtx_insn *insn;
8406 1595813 : rtx set, src, dest;
8407 1595813 : auto_bitmap removed_optional_reload_pseudos (®_obstack);
8408 :
8409 1595813 : bitmap_copy (removed_optional_reload_pseudos, &lra_optional_reload_pseudos);
8410 2584585 : EXECUTE_IF_SET_IN_BITMAP (&lra_optional_reload_pseudos, 0, regno, bi)
8411 : {
8412 988772 : keep_p = false;
8413 : /* Keep optional reloads from previous subpasses. */
8414 988772 : if (lra_reg_info[regno].restore_rtx == NULL_RTX
8415 : /* If the original pseudo changed its allocation, just
8416 : removing the optional pseudo is dangerous as the original
8417 : pseudo will have longer live range. */
8418 988772 : || reg_renumber[REGNO (lra_reg_info[regno].restore_rtx)] >= 0)
8419 : keep_p = true;
8420 611187 : else if (reg_renumber[regno] >= 0)
8421 1740715 : EXECUTE_IF_SET_IN_BITMAP (&lra_reg_info[regno].insn_bitmap, 0, uid, bi2)
8422 : {
8423 1274126 : insn = lra_insn_recog_data[uid]->insn;
8424 1274126 : if ((set = single_set (insn)) == NULL_RTX)
8425 6078 : continue;
8426 1268048 : int src_regno = get_regno (SET_SRC (set));
8427 1268048 : int dest_regno = get_regno (SET_DEST (set));
8428 1268048 : if (src_regno < 0 || dest_regno < 0)
8429 591702 : continue;
8430 676346 : int restore_regno = get_regno (lra_reg_info[regno].restore_rtx);
8431 676346 : if (restore_regno < 0)
8432 0 : continue;
8433 676346 : if (((dest_regno == (int) regno
8434 : /* Ignore insn for optional reloads itself. */
8435 579447 : && restore_regno != src_regno
8436 : /* Check that the optional reload was inherited. */
8437 115660 : && inheritance_pseudo_p (src_regno))
8438 1140133 : || (src_regno == (int) regno
8439 96899 : && restore_regno != dest_regno
8440 : /* The optional reload is an inheritance source. */
8441 15531 : && inheritance_pseudo_p (dest_regno))))
8442 : {
8443 : keep_p = true;
8444 : break;
8445 : }
8446 : }
8447 623993 : if (keep_p)
8448 : {
8449 508776 : bitmap_clear_bit (removed_optional_reload_pseudos, regno);
8450 508776 : if (lra_dump_file != NULL)
8451 2 : fprintf (lra_dump_file, "Keep optional reload reg %d\n", regno);
8452 : }
8453 : }
8454 1595813 : change_p = ! bitmap_empty_p (removed_optional_reload_pseudos);
8455 1595813 : auto_bitmap insn_bitmap (®_obstack);
8456 2075809 : EXECUTE_IF_SET_IN_BITMAP (removed_optional_reload_pseudos, 0, regno, bi)
8457 : {
8458 479996 : if (lra_dump_file != NULL)
8459 0 : fprintf (lra_dump_file, "Remove optional reload reg %d\n", regno);
8460 479996 : bitmap_copy (insn_bitmap, &lra_reg_info[regno].insn_bitmap);
8461 1511241 : EXECUTE_IF_SET_IN_BITMAP (insn_bitmap, 0, uid, bi2)
8462 : {
8463 : /* We may have already removed a clobber. */
8464 1031245 : if (!lra_insn_recog_data[uid])
8465 0 : continue;
8466 1031245 : insn = lra_insn_recog_data[uid]->insn;
8467 1031245 : if ((set = single_set (insn)) != NULL_RTX)
8468 : {
8469 1025404 : src = SET_SRC (set);
8470 1025404 : dest = SET_DEST (set);
8471 474141 : if ((REG_P (src) || SUBREG_P (src))
8472 551275 : && (REG_P (dest) || SUBREG_P (dest))
8473 1576653 : && ((get_regno (src) == (int) regno
8474 168472 : && (get_regno (lra_reg_info[regno].restore_rtx)
8475 84236 : == get_regno (dest)))
8476 467075 : || (get_regno (dest) == (int) regno
8477 467013 : && (get_regno (lra_reg_info[regno].restore_rtx)
8478 467013 : == get_regno (src)))))
8479 : {
8480 551148 : if (lra_dump_file != NULL)
8481 : {
8482 0 : fprintf (lra_dump_file, " Deleting move %u\n",
8483 0 : INSN_UID (insn));
8484 0 : dump_insn_slim (lra_dump_file, insn);
8485 : }
8486 1102296 : delete_move_and_clobber (insn, get_regno (dest));
8487 551148 : continue;
8488 : }
8489 : /* We should not worry about generation memory-memory
8490 : moves here as if the corresponding inheritance did
8491 : not work (inheritance pseudo did not get a hard reg),
8492 : we remove the inheritance pseudo and the optional
8493 : reload. */
8494 : }
8495 480097 : rtx pat = PATTERN (insn);
8496 0 : if (GET_CODE (pat) == CLOBBER && REG_P (SET_DEST (pat))
8497 480097 : && get_regno (SET_DEST (pat)) == (int) regno)
8498 : /* Refuse to remap clobbers to preexisting pseudos. */
8499 0 : gcc_unreachable ();
8500 480097 : lra_substitute_pseudo_within_insn
8501 480097 : (insn, regno, lra_reg_info[regno].restore_rtx, false);
8502 480097 : lra_update_insn_regno_info (insn);
8503 480097 : if (lra_dump_file != NULL)
8504 : {
8505 0 : fprintf (lra_dump_file,
8506 : " Restoring original insn:\n");
8507 0 : dump_insn_slim (lra_dump_file, insn);
8508 : }
8509 : }
8510 : }
8511 : /* Clear restore_regnos. */
8512 2584585 : EXECUTE_IF_SET_IN_BITMAP (&lra_optional_reload_pseudos, 0, regno, bi)
8513 988772 : lra_reg_info[regno].restore_rtx = NULL_RTX;
8514 1595813 : return change_p;
8515 1595813 : }
8516 :
8517 : /* Entry function for undoing inheritance/split transformation. Return true
8518 : if we did any RTL change in this pass. */
8519 : bool
8520 1599592 : lra_undo_inheritance (void)
8521 : {
8522 1599592 : unsigned int regno;
8523 1599592 : int hard_regno;
8524 1599592 : int n_all_inherit, n_inherit, n_all_split, n_split;
8525 1599592 : rtx restore_rtx;
8526 1599592 : bitmap_iterator bi;
8527 1599592 : bool change_p;
8528 :
8529 1599592 : lra_undo_inheritance_iter++;
8530 1599592 : if (lra_undo_inheritance_iter > LRA_MAX_INHERITANCE_PASSES)
8531 : return false;
8532 1595813 : if (lra_dump_file != NULL)
8533 96 : fprintf (lra_dump_file,
8534 : "\n********** Undoing inheritance #%d: **********\n\n",
8535 : lra_undo_inheritance_iter);
8536 1595813 : auto_bitmap remove_pseudos (®_obstack);
8537 1595813 : n_inherit = n_all_inherit = 0;
8538 3499603 : EXECUTE_IF_SET_IN_BITMAP (&lra_inheritance_pseudos, 0, regno, bi)
8539 1903790 : if (lra_reg_info[regno].restore_rtx != NULL_RTX)
8540 : {
8541 1208062 : n_all_inherit++;
8542 1208062 : if (reg_renumber[regno] < 0
8543 : /* If the original pseudo changed its allocation, just
8544 : removing inheritance is dangerous as for changing
8545 : allocation we used shorter live-ranges. */
8546 1208062 : && (! REG_P (lra_reg_info[regno].restore_rtx)
8547 449517 : || reg_renumber[REGNO (lra_reg_info[regno].restore_rtx)] < 0))
8548 459043 : bitmap_set_bit (remove_pseudos, regno);
8549 : else
8550 749019 : n_inherit++;
8551 : }
8552 1595813 : if (lra_dump_file != NULL && n_all_inherit != 0)
8553 1 : fprintf (lra_dump_file, "Inherit %d out of %d (%.2f%%)\n",
8554 : n_inherit, n_all_inherit,
8555 1 : (double) n_inherit / n_all_inherit * 100);
8556 1595813 : n_split = n_all_split = 0;
8557 2571162 : EXECUTE_IF_SET_IN_BITMAP (&lra_split_regs, 0, regno, bi)
8558 975349 : if ((restore_rtx = lra_reg_info[regno].restore_rtx) != NULL_RTX)
8559 : {
8560 670740 : int restore_regno = REGNO (restore_rtx);
8561 :
8562 670740 : n_all_split++;
8563 1341398 : hard_regno = (restore_regno >= FIRST_PSEUDO_REGISTER
8564 670740 : ? reg_renumber[restore_regno] : restore_regno);
8565 670740 : if (hard_regno < 0 || reg_renumber[regno] == hard_regno)
8566 2295 : bitmap_set_bit (remove_pseudos, regno);
8567 : else
8568 : {
8569 668445 : n_split++;
8570 668445 : if (lra_dump_file != NULL)
8571 0 : fprintf (lra_dump_file, " Keep split r%d (orig=r%d)\n",
8572 : regno, restore_regno);
8573 : }
8574 : }
8575 1595813 : if (lra_dump_file != NULL && n_all_split != 0)
8576 0 : fprintf (lra_dump_file, "Split %d out of %d (%.2f%%)\n",
8577 : n_split, n_all_split,
8578 0 : (double) n_split / n_all_split * 100);
8579 1595813 : change_p = remove_inheritance_pseudos (remove_pseudos);
8580 : /* Clear restore_regnos. */
8581 3499603 : EXECUTE_IF_SET_IN_BITMAP (&lra_inheritance_pseudos, 0, regno, bi)
8582 1903790 : lra_reg_info[regno].restore_rtx = NULL_RTX;
8583 2571162 : EXECUTE_IF_SET_IN_BITMAP (&lra_split_regs, 0, regno, bi)
8584 975349 : lra_reg_info[regno].restore_rtx = NULL_RTX;
8585 1595813 : change_p = undo_optional_reloads () || change_p;
8586 : if (change_p)
8587 112496 : lra_dump_insns_if_possible ("changed func after undoing inheritance");
8588 1595813 : return change_p;
8589 1595813 : }
|