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