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