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 : 231411430 : strip_subreg (rtx *loc)
170 : : {
171 : 102428633 : 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 : 72227 : get_try_hard_regno (int regno)
178 : : {
179 : 72227 : int hard_regno;
180 : 72227 : enum reg_class rclass;
181 : :
182 : 72227 : if ((hard_regno = regno) >= FIRST_PSEUDO_REGISTER)
183 : 72227 : hard_regno = lra_get_regno_hard_regno (regno);
184 : 72227 : if (hard_regno >= 0)
185 : : return hard_regno;
186 : 39841 : rclass = lra_get_allocno_class (regno);
187 : 39841 : if (rclass == NO_REGS)
188 : : return -1;
189 : 38309 : 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 : 291657889 : get_hard_regno (rtx x)
198 : : {
199 : 291657889 : rtx reg;
200 : 291657889 : int hard_regno;
201 : :
202 : 291657889 : reg = x;
203 : 291657889 : if (SUBREG_P (x))
204 : 5245663 : reg = SUBREG_REG (x);
205 : 291657889 : if (! REG_P (reg))
206 : : return -1;
207 : 201421412 : int regno = REGNO (reg);
208 : 201421412 : if (HARD_REGISTER_NUM_P (regno))
209 : 35166166 : hard_regno = lra_get_elimination_hard_regno (regno);
210 : : else
211 : 166255246 : hard_regno = lra_get_regno_hard_regno (regno);
212 : 201421412 : if (hard_regno < 0)
213 : : return -1;
214 : 183332850 : if (SUBREG_P (x))
215 : 4547766 : hard_regno += subreg_regno_offset (hard_regno, GET_MODE (reg),
216 : 4547766 : 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 : 522073804 : get_reg_class (int regno)
226 : : {
227 : 522073804 : int hard_regno;
228 : :
229 : 522073804 : if (HARD_REGISTER_NUM_P (regno))
230 : 66085765 : hard_regno = lra_get_elimination_hard_regno (regno);
231 : : else
232 : 455988039 : hard_regno = lra_get_regno_hard_regno (regno);
233 : 522073804 : if (hard_regno >= 0)
234 : 326264906 : return REGNO_REG_CLASS (hard_regno);
235 : 195808898 : if (regno >= new_regno_start)
236 : 63367822 : 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 : 19118801 : enough_allocatable_hard_regs_p (enum reg_class reg_class,
244 : : enum machine_mode reg_mode)
245 : : {
246 : 19118801 : int i, j, hard_regno, class_size, nregs;
247 : :
248 : 38237602 : if (hard_reg_set_subset_p (reg_class_contents[reg_class], lra_no_alloc_regs))
249 : : return false;
250 : 6531886 : class_size = ira_class_hard_regs_num[reg_class];
251 : 6531886 : for (i = 0; i < class_size; i++)
252 : : {
253 : 6531886 : hard_regno = ira_class_hard_regs[reg_class][i];
254 : 6531886 : nregs = hard_regno_nregs (hard_regno, reg_mode);
255 : 6531886 : if (nregs == 1)
256 : : return true;
257 : 264594 : for (j = 0; j < nregs; j++)
258 : 176396 : if (TEST_HARD_REG_BIT (lra_no_alloc_regs, hard_regno + j)
259 : 176396 : || ! TEST_HARD_REG_BIT (reg_class_contents[reg_class],
260 : : hard_regno + j))
261 : : break;
262 : 88198 : 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 : 222275003 : 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 : 222275003 : enum reg_class rclass, common_class;
292 : 222275003 : machine_mode reg_mode;
293 : 222275003 : rtx src;
294 : 222275003 : int regno = REGNO (reg);
295 : :
296 : 222275003 : if (new_class != NULL)
297 : 113882049 : *new_class = NO_REGS;
298 : 222275003 : if (regno < FIRST_PSEUDO_REGISTER)
299 : : {
300 : 27964587 : rtx final_reg = reg;
301 : 27964587 : rtx *final_loc = &final_reg;
302 : :
303 : 27964587 : lra_eliminate_reg_if_possible (final_loc);
304 : 27964587 : return TEST_HARD_REG_BIT (reg_class_contents[cl], REGNO (*final_loc));
305 : : }
306 : 194310416 : reg_mode = GET_MODE (reg);
307 : 194310416 : rclass = get_reg_class (regno);
308 : 194310416 : src = curr_insn_set != NULL ? SET_SRC (curr_insn_set) : NULL;
309 : 194310416 : 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 : 194310416 : || (!allow_all_reload_class_changes_p
316 : 15363864 : && INSN_UID (curr_insn) >= new_insn_uid_start
317 : 14828374 : && src != NULL
318 : 14828374 : && ((REG_P (src) || MEM_P (src))
319 : 1450187 : || (GET_CODE (src) == SUBREG
320 : 631924 : && (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 : 14010111 : return ((regno >= new_regno_start && rclass == ALL_REGS)
324 : 189199422 : || (rclass != NO_REGS && ira_class_subset_p[rclass][cl]
325 : 203789572 : && ! hard_reg_set_subset_p (reg_class_contents[cl],
326 : : lra_no_alloc_regs)));
327 : : else
328 : : {
329 : 19118801 : common_class = ira_reg_class_subset[rclass][cl];
330 : 19118801 : if (new_class != NULL)
331 : 5369458 : *new_class = common_class;
332 : 19118801 : 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 : 19118801 : && (new_class != NULL || common_class == rclass
336 : 1082452 : || !SMALL_REGISTER_CLASS_P (common_class)));
337 : : }
338 : : }
339 : :
340 : : /* Return true if REGNO satisfies a memory constraint. */
341 : : static bool
342 : 64476147 : 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 : 35971895 : 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 : 35971895 : 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 : 75846537 : address_eliminator::address_eliminator (struct address_info *ad)
385 : 75846537 : : m_ad (ad),
386 : 75846537 : m_base_loc (strip_subreg (ad->base_term)),
387 : 75846537 : m_base_reg (NULL_RTX),
388 : 75846537 : m_index_loc (strip_subreg (ad->index_term)),
389 : 75846537 : m_index_reg (NULL_RTX)
390 : : {
391 : 75846537 : if (m_base_loc != NULL)
392 : : {
393 : 63242772 : 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 : 63242772 : if (REG_P (m_base_reg))
399 : 63242772 : lra_eliminate_reg_if_possible (m_base_loc);
400 : 63242772 : if (m_ad->base_term2 != NULL)
401 : 0 : *m_ad->base_term2 = *m_ad->base_term;
402 : : }
403 : 75846537 : if (m_index_loc != NULL)
404 : : {
405 : 3683971 : m_index_reg = *m_index_loc;
406 : 3683971 : if (REG_P (m_index_reg))
407 : 3683971 : lra_eliminate_reg_if_possible (m_index_loc);
408 : : }
409 : 75846537 : }
410 : :
411 : 75846537 : address_eliminator::~address_eliminator ()
412 : : {
413 : 75846537 : if (m_base_loc && *m_base_loc != m_base_reg)
414 : : {
415 : 44772288 : *m_base_loc = m_base_reg;
416 : 44772288 : if (m_ad->base_term2 != NULL)
417 : 0 : *m_ad->base_term2 = *m_ad->base_term;
418 : : }
419 : 75846537 : if (m_index_loc && *m_index_loc != m_index_reg)
420 : 0 : *m_index_loc = m_index_reg;
421 : 75846537 : }
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 : 35949031 : valid_address_p (rtx op, struct address_info *ad,
429 : : enum constraint_num constraint)
430 : : {
431 : 35949031 : 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 : 35949031 : 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 : 35949031 : return valid_address_p (ad->mode, *ad->outer, ad->as);
443 : 35949031 : }
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 : 631600835 : extract_mem_from_operand (rtx op)
450 : : {
451 : 633334499 : for (rtx x = op;; x = XEXP (x, 0))
452 : : {
453 : 633334499 : if (MEM_P (x))
454 : : return x;
455 : 450221153 : if (GET_RTX_LENGTH (GET_CODE (x)) != 1
456 : 369382797 : || 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 : 37282766 : satisfies_memory_constraint_p (rtx op, enum constraint_num constraint)
466 : : {
467 : 37282766 : struct address_info ad;
468 : 37282766 : rtx mem = extract_mem_from_operand (op);
469 : 37282766 : if (!MEM_P (mem))
470 : : return false;
471 : :
472 : 36291023 : decompose_mem_address (&ad, mem);
473 : 36291023 : address_eliminator eliminator (&ad);
474 : 36291023 : return constraint_satisfied_p (op, constraint);
475 : 36291023 : }
476 : :
477 : : /* Return true if the eliminated form of address AD satisfies extra
478 : : address constraint CONSTRAINT. */
479 : : static bool
480 : 3606483 : satisfies_address_constraint_p (struct address_info *ad,
481 : : enum constraint_num constraint)
482 : : {
483 : 3606483 : address_eliminator eliminator (ad);
484 : 3606483 : return constraint_satisfied_p (*ad->outer, constraint);
485 : 3606483 : }
486 : :
487 : : /* Return true if the eliminated form of address OP satisfies extra
488 : : address constraint CONSTRAINT. */
489 : : static bool
490 : 1771181 : satisfies_address_constraint_p (rtx op, enum constraint_num constraint)
491 : : {
492 : 1771181 : struct address_info ad;
493 : :
494 : 1771181 : decompose_lea_address (&ad, &op);
495 : 1771181 : 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 : 1472101 : lra_init_equiv (void)
503 : : {
504 : 1472101 : ira_expand_reg_equiv ();
505 : 69977154 : for (int i = FIRST_PSEUDO_REGISTER; i < max_reg_num (); i++)
506 : : {
507 : 68505053 : rtx res;
508 : :
509 : 68505053 : if ((res = ira_reg_equiv[i].memory) != NULL_RTX)
510 : 3128068 : ira_reg_equiv[i].memory = copy_rtx (res);
511 : 68505053 : if ((res = ira_reg_equiv[i].invariant) != NULL_RTX)
512 : 893343 : ira_reg_equiv[i].invariant = copy_rtx (res);
513 : : }
514 : 1472101 : }
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 : 204406062 : update_equiv (int regno)
523 : : {
524 : 204406062 : rtx x;
525 : :
526 : 204406062 : if ((x = ira_reg_equiv[regno].memory) != NULL_RTX)
527 : 9501707 : ira_reg_equiv[regno].memory
528 : 9501707 : = simplify_replace_fn_rtx (x, NULL_RTX, loc_equivalence_callback,
529 : : NULL_RTX);
530 : 204406062 : if ((x = ira_reg_equiv[regno].invariant) != NULL_RTX)
531 : 2771305 : ira_reg_equiv[regno].invariant
532 : 2771305 : = simplify_replace_fn_rtx (x, NULL_RTX, loc_equivalence_callback,
533 : : NULL_RTX);
534 : 204406062 : }
535 : :
536 : : /* If we have decided to substitute X with another value, return that
537 : : value, otherwise return X. */
538 : : static rtx
539 : 442107514 : get_equiv (rtx x)
540 : : {
541 : 442107514 : int regno;
542 : 442107514 : rtx res;
543 : :
544 : 299225363 : if (! REG_P (x) || (regno = REGNO (x)) < FIRST_PSEUDO_REGISTER
545 : 198744259 : || regno >= ira_reg_equiv_len
546 : 198744259 : || ! ira_reg_equiv[regno].defined_p
547 : 26124564 : || ! ira_reg_equiv[regno].profitable_p
548 : 468186271 : || lra_get_regno_hard_regno (regno) >= 0)
549 : 437007357 : return x;
550 : 5100157 : if ((res = ira_reg_equiv[regno].memory) != NULL_RTX)
551 : : {
552 : 2280956 : if (targetm.cannot_substitute_mem_equiv_p (res))
553 : : return x;
554 : : return res;
555 : : }
556 : 2819201 : if ((res = ira_reg_equiv[regno].constant) != NULL_RTX)
557 : : return res;
558 : 1960846 : 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 : 248428116 : get_equiv_with_elimination (rtx x, rtx_insn *insn)
568 : : {
569 : 248428116 : rtx res = get_equiv (x);
570 : :
571 : 248428116 : if (x == res || CONSTANT_P (res))
572 : : return res;
573 : 1547132 : 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 : 107297615 : init_curr_operand_mode (void)
580 : : {
581 : 107297615 : int nop = curr_static_id->n_operands;
582 : 334273218 : for (int i = 0; i < nop; i++)
583 : : {
584 : 226975603 : machine_mode mode = GET_MODE (*curr_id->operand_loc[i]);
585 : 226975603 : 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 : 43981508 : if (curr_id->icode >= 0 && curr_static_id->operand[i].is_address)
590 : 115 : mode = Pmode;
591 : : else
592 : 43981393 : mode = curr_static_id->operand[i].mode;
593 : : }
594 : 226975603 : curr_operand_mode[i] = mode;
595 : : }
596 : 107297615 : }
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 : 107297615 : init_curr_insn_input_reloads (void)
625 : : {
626 : 107297615 : 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 : 3874601 : 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 : 3874601 : int i, regno;
670 : 3874601 : enum reg_class new_class;
671 : :
672 : 3874601 : 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 : 976019 : if (REG_P (original)
686 : 716463 : && (int) REGNO (original) >= new_regno_start
687 : 7207 : && (INSN_UID (curr_insn) >= new_insn_uid_start
688 : 250 : || ira_former_scratch_p (REGNO (original)))
689 : 983226 : && in_class_p (original, rclass, &new_class, true))
690 : : {
691 : 250 : unsigned int regno = REGNO (original);
692 : 250 : if (lra_dump_file != NULL)
693 : : {
694 : 0 : fprintf (lra_dump_file, " Reuse r%d for output ", regno);
695 : 0 : dump_value_slim (lra_dump_file, original, 1);
696 : : }
697 : 500 : if (new_class != lra_get_allocno_class (regno))
698 : 250 : lra_change_class (regno, new_class, ", change to", false);
699 : 250 : if (lra_dump_file != NULL)
700 : 0 : fprintf (lra_dump_file, "\n");
701 : 250 : *result_reg = original;
702 : 250 : return false;
703 : : }
704 : 975769 : *result_reg
705 : 975769 : = lra_create_new_reg_with_unique_value (mode, original, rclass,
706 : : exclude_start_hard_regs, title);
707 : 975769 : return true;
708 : : }
709 : :
710 : 2898582 : bool unique_p = early_clobber_p;
711 : : /* Prevent reuse value of expression with side effects,
712 : : e.g. volatile memory. */
713 : 2898582 : if (! side_effects_p (original))
714 : 3132785 : for (i = 0; i < curr_insn_input_reloads_num; i++)
715 : : {
716 : 242716 : if (! curr_insn_input_reloads[i].match_p
717 : 101896 : && ! curr_insn_input_reloads[i].early_clobber_p
718 : 101894 : && rtx_equal_p (curr_insn_input_reloads[i].input, original)
719 : 251242 : && in_class_p (curr_insn_input_reloads[i].reg, rclass, &new_class))
720 : : {
721 : 8513 : rtx reg = curr_insn_input_reloads[i].reg;
722 : 8513 : regno = REGNO (reg);
723 : : /* If input is equal to original and both are VOIDmode,
724 : : GET_MODE (reg) might be still different from mode.
725 : : Ensure we don't return *result_reg with wrong mode. */
726 : 8513 : if (GET_MODE (reg) != mode)
727 : : {
728 : 0 : if (in_subreg_p)
729 : 0 : continue;
730 : 0 : if (maybe_lt (GET_MODE_SIZE (GET_MODE (reg)),
731 : 0 : GET_MODE_SIZE (mode)))
732 : 0 : continue;
733 : 0 : reg = lowpart_subreg (mode, reg, GET_MODE (reg));
734 : 0 : if (reg == NULL_RTX || GET_CODE (reg) != SUBREG)
735 : 0 : continue;
736 : : }
737 : 8513 : *result_reg = reg;
738 : 8513 : if (lra_dump_file != NULL)
739 : : {
740 : 0 : fprintf (lra_dump_file, " Reuse r%d for reload ", regno);
741 : 0 : dump_value_slim (lra_dump_file, original, 1);
742 : : }
743 : 17026 : if (new_class != lra_get_allocno_class (regno))
744 : 4372 : lra_change_class (regno, new_class, ", change to", false);
745 : 8513 : if (lra_dump_file != NULL)
746 : 0 : fprintf (lra_dump_file, "\n");
747 : 8513 : return false;
748 : : }
749 : : /* If we have an input reload with a different mode, make sure it
750 : : will get a different hard reg. */
751 : 234203 : else if (REG_P (original)
752 : 184424 : && REG_P (curr_insn_input_reloads[i].input)
753 : 151665 : && REGNO (original) == REGNO (curr_insn_input_reloads[i].input)
754 : 234203 : && (GET_MODE (original)
755 : 1986 : != GET_MODE (curr_insn_input_reloads[i].input)))
756 : : unique_p = true;
757 : : }
758 : 5780138 : *result_reg = (unique_p
759 : 2890069 : ? lra_create_new_reg_with_unique_value
760 : 2890069 : : lra_create_new_reg) (mode, original, rclass,
761 : : exclude_start_hard_regs, title);
762 : 2890069 : lra_assert (curr_insn_input_reloads_num < LRA_MAX_INSN_RELOADS);
763 : 2890069 : curr_insn_input_reloads[curr_insn_input_reloads_num].input = original;
764 : 2890069 : curr_insn_input_reloads[curr_insn_input_reloads_num].match_p = false;
765 : 2890069 : curr_insn_input_reloads[curr_insn_input_reloads_num].early_clobber_p
766 : 2890069 : = early_clobber_p;
767 : 2890069 : curr_insn_input_reloads[curr_insn_input_reloads_num++].reg = *result_reg;
768 : 2890069 : return true;
769 : : }
770 : :
771 : :
772 : : /* The page contains major code to choose the current insn alternative
773 : : and generate reloads for it. */
774 : :
775 : : /* Return the offset from REGNO of the least significant register
776 : : in (reg:MODE REGNO).
777 : :
778 : : This function is used to tell whether two registers satisfy
779 : : a matching constraint. (reg:MODE1 REGNO1) matches (reg:MODE2 REGNO2) if:
780 : :
781 : : REGNO1 + lra_constraint_offset (REGNO1, MODE1)
782 : : == REGNO2 + lra_constraint_offset (REGNO2, MODE2) */
783 : : int
784 : 43827978 : lra_constraint_offset (int regno, machine_mode mode)
785 : : {
786 : 43827978 : lra_assert (regno < FIRST_PSEUDO_REGISTER);
787 : :
788 : 43827978 : scalar_int_mode int_mode;
789 : 43827978 : if (WORDS_BIG_ENDIAN
790 : : && is_a <scalar_int_mode> (mode, &int_mode)
791 : : && GET_MODE_SIZE (int_mode) > UNITS_PER_WORD)
792 : : return hard_regno_nregs (regno, mode) - 1;
793 : 43827978 : return 0;
794 : : }
795 : :
796 : : /* Like rtx_equal_p except that it allows a REG and a SUBREG to match
797 : : if they are the same hard reg, and has special hacks for
798 : : auto-increment and auto-decrement. This is specifically intended for
799 : : process_alt_operands to use in determining whether two operands
800 : : match. X is the operand whose number is the lower of the two.
801 : :
802 : : It is supposed that X is the output operand and Y is the input
803 : : operand. Y_HARD_REGNO is the final hard regno of register Y or
804 : : register in subreg Y as we know it now. Otherwise, it is a
805 : : negative value. */
806 : : static bool
807 : 58175529 : operands_match_p (rtx x, rtx y, int y_hard_regno)
808 : : {
809 : 58175529 : int i;
810 : 58175529 : RTX_CODE code = GET_CODE (x);
811 : 58175529 : const char *fmt;
812 : :
813 : 58175529 : if (x == y)
814 : : return true;
815 : 50540646 : if ((code == REG || (code == SUBREG && REG_P (SUBREG_REG (x))))
816 : 23912962 : && (REG_P (y) || (GET_CODE (y) == SUBREG && REG_P (SUBREG_REG (y)))))
817 : : {
818 : 23809612 : int j;
819 : :
820 : 23809612 : i = get_hard_regno (x);
821 : 23809612 : if (i < 0)
822 : 1213270 : goto slow;
823 : :
824 : 22596342 : if ((j = y_hard_regno) < 0)
825 : 682353 : goto slow;
826 : :
827 : 21913989 : i += lra_constraint_offset (i, GET_MODE (x));
828 : 21913989 : j += lra_constraint_offset (j, GET_MODE (y));
829 : :
830 : 21913989 : return i == j;
831 : : }
832 : :
833 : : /* If two operands must match, because they are really a single
834 : : operand of an assembler insn, then two post-increments are invalid
835 : : because the assembler insn would increment only once. On the
836 : : other hand, a post-increment matches ordinary indexing if the
837 : : post-increment is the output operand. */
838 : 26731034 : if (code == POST_DEC || code == POST_INC || code == POST_MODIFY)
839 : 0 : return operands_match_p (XEXP (x, 0), y, y_hard_regno);
840 : :
841 : : /* Two pre-increments are invalid because the assembler insn would
842 : : increment only once. On the other hand, a pre-increment matches
843 : : ordinary indexing if the pre-increment is the input operand. */
844 : 26731034 : if (GET_CODE (y) == PRE_DEC || GET_CODE (y) == PRE_INC
845 : 26731034 : || GET_CODE (y) == PRE_MODIFY)
846 : 0 : return operands_match_p (x, XEXP (y, 0), -1);
847 : :
848 : 26731034 : slow:
849 : :
850 : 28626657 : if (code == REG && REG_P (y))
851 : 1798836 : return REGNO (x) == REGNO (y);
852 : :
853 : 102704 : if (code == REG && GET_CODE (y) == SUBREG && REG_P (SUBREG_REG (y))
854 : 7010 : && x == SUBREG_REG (y))
855 : : return true;
856 : 26827821 : if (GET_CODE (y) == REG && code == SUBREG && REG_P (SUBREG_REG (x))
857 : 65217 : && SUBREG_REG (x) == y)
858 : : return true;
859 : :
860 : : /* Now we have disposed of all the cases in which different rtx
861 : : codes can match. */
862 : 26827661 : if (code != GET_CODE (y))
863 : : return false;
864 : :
865 : : /* (MULT:SI x y) and (MULT:HI x y) are NOT equivalent. */
866 : 1033716 : if (GET_MODE (x) != GET_MODE (y))
867 : : return false;
868 : :
869 : 1033014 : switch (code)
870 : : {
871 : : CASE_CONST_UNIQUE:
872 : : return false;
873 : :
874 : : case CONST_VECTOR:
875 : : if (!same_vector_encodings_p (x, y))
876 : : return false;
877 : : break;
878 : :
879 : 0 : case LABEL_REF:
880 : 0 : return label_ref_label (x) == label_ref_label (y);
881 : 22 : case SYMBOL_REF:
882 : 22 : return XSTR (x, 0) == XSTR (y, 0);
883 : :
884 : : default:
885 : : break;
886 : : }
887 : :
888 : : /* Compare the elements. If any pair of corresponding elements fail
889 : : to match, return false for the whole things. */
890 : :
891 : 1015134 : fmt = GET_RTX_FORMAT (code);
892 : 2950589 : for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
893 : : {
894 : 2001595 : int val, j;
895 : 2001595 : switch (fmt[i])
896 : : {
897 : 0 : case 'w':
898 : 0 : if (XWINT (x, i) != XWINT (y, i))
899 : : return false;
900 : : break;
901 : :
902 : 478 : case 'i':
903 : 478 : if (XINT (x, i) != XINT (y, i))
904 : : return false;
905 : : break;
906 : :
907 : 0 : case 'L':
908 : 0 : if (XLOC (x, i) != XLOC (y, i))
909 : : return false;
910 : : break;
911 : :
912 : 24472 : case 'p':
913 : 24472 : if (maybe_ne (SUBREG_BYTE (x), SUBREG_BYTE (y)))
914 : : return false;
915 : : break;
916 : :
917 : 1462930 : case 'e':
918 : 1462930 : val = operands_match_p (XEXP (x, i), XEXP (y, i), -1);
919 : 1462930 : if (val == 0)
920 : : return false;
921 : : break;
922 : :
923 : : case '0':
924 : : break;
925 : :
926 : 478 : case 'E':
927 : 478 : if (XVECLEN (x, i) != XVECLEN (y, i))
928 : : return false;
929 : 956 : for (j = XVECLEN (x, i) - 1; j >= 0; --j)
930 : : {
931 : 478 : val = operands_match_p (XVECEXP (x, i, j), XVECEXP (y, i, j), -1);
932 : 478 : if (val == 0)
933 : : return false;
934 : : }
935 : : break;
936 : :
937 : : /* It is believed that rtx's at this level will never
938 : : contain anything but integers and other rtx's, except for
939 : : within LABEL_REFs and SYMBOL_REFs. */
940 : 0 : default:
941 : 0 : gcc_unreachable ();
942 : : }
943 : : }
944 : : return true;
945 : : }
946 : :
947 : : /* True if X is a constant that can be forced into the constant pool.
948 : : MODE is the mode of the operand, or VOIDmode if not known. */
949 : : #define CONST_POOL_OK_P(MODE, X) \
950 : : ((MODE) != VOIDmode \
951 : : && CONSTANT_P (X) \
952 : : && GET_CODE (X) != HIGH \
953 : : && GET_MODE_SIZE (MODE).is_constant () \
954 : : && !targetm.cannot_force_const_mem (MODE, X))
955 : :
956 : : /* If REG is a reload pseudo, try to make its class satisfying CL. */
957 : : static void
958 : 3463404 : narrow_reload_pseudo_class (rtx reg, enum reg_class cl)
959 : : {
960 : 3463404 : enum reg_class rclass;
961 : :
962 : : /* Do not make more accurate class from reloads generated. They are
963 : : mostly moves with a lot of constraints. Making more accurate
964 : : class may results in very narrow class and impossibility of find
965 : : registers for several reloads of one insn. */
966 : 3463404 : if (INSN_UID (curr_insn) >= new_insn_uid_start)
967 : 3463373 : return;
968 : 3463292 : if (GET_CODE (reg) == SUBREG)
969 : 168571 : reg = SUBREG_REG (reg);
970 : 3463292 : if (! REG_P (reg) || (int) REGNO (reg) < new_regno_start)
971 : : return;
972 : 31 : if (in_class_p (reg, cl, &rclass) && rclass != cl)
973 : 12 : lra_change_class (REGNO (reg), rclass, " Change to", true);
974 : : }
975 : :
976 : : /* Searches X for any reference to a reg with the same value as REGNO,
977 : : returning the rtx of the reference found if any. Otherwise,
978 : : returns NULL_RTX. */
979 : : static rtx
980 : 522726 : regno_val_use_in (unsigned int regno, rtx x)
981 : : {
982 : 522726 : const char *fmt;
983 : 522726 : int i, j;
984 : 522726 : rtx tem;
985 : :
986 : 522726 : if (REG_P (x) && lra_reg_info[REGNO (x)].val == lra_reg_info[regno].val)
987 : : return x;
988 : :
989 : 522334 : fmt = GET_RTX_FORMAT (GET_CODE (x));
990 : 1051083 : for (i = GET_RTX_LENGTH (GET_CODE (x)) - 1; i >= 0; i--)
991 : : {
992 : 528749 : if (fmt[i] == 'e')
993 : : {
994 : 7622 : if ((tem = regno_val_use_in (regno, XEXP (x, i))))
995 : : return tem;
996 : : }
997 : 521127 : else if (fmt[i] == 'E')
998 : 0 : for (j = XVECLEN (x, i) - 1; j >= 0; j--)
999 : 0 : if ((tem = regno_val_use_in (regno , XVECEXP (x, i, j))))
1000 : : return tem;
1001 : : }
1002 : :
1003 : : return NULL_RTX;
1004 : : }
1005 : :
1006 : : /* Return true if all current insn non-output operands except INS (it
1007 : : has a negaitve end marker) do not use pseudos with the same value
1008 : : as REGNO. */
1009 : : static bool
1010 : 2 : check_conflict_input_operands (int regno, signed char *ins)
1011 : : {
1012 : 2 : int in;
1013 : 2 : int n_operands = curr_static_id->n_operands;
1014 : :
1015 : 8 : for (int nop = 0; nop < n_operands; nop++)
1016 : 7 : if (! curr_static_id->operand[nop].is_operator
1017 : 7 : && curr_static_id->operand[nop].type != OP_OUT)
1018 : : {
1019 : 5 : for (int i = 0; (in = ins[i]) >= 0; i++)
1020 : 4 : if (in == nop)
1021 : : break;
1022 : 3 : if (in < 0
1023 : 3 : && regno_val_use_in (regno, *curr_id->operand_loc[nop]) != NULL_RTX)
1024 : : return false;
1025 : : }
1026 : : return true;
1027 : : }
1028 : :
1029 : : /* Generate reloads for matching OUT and INS (array of input operand numbers
1030 : : with end marker -1) with reg class GOAL_CLASS and EXCLUDE_START_HARD_REGS,
1031 : : considering output operands OUTS (similar array to INS) needing to be in
1032 : : different registers. Add input and output reloads correspondingly to the
1033 : : lists *BEFORE and *AFTER. OUT might be negative. In this case we generate
1034 : : input reloads for matched input operands INS. EARLY_CLOBBER_P is a flag
1035 : : that the output operand is early clobbered for chosen alternative. */
1036 : : static void
1037 : 1731702 : match_reload (signed char out, signed char *ins, signed char *outs,
1038 : : enum reg_class goal_class, HARD_REG_SET *exclude_start_hard_regs,
1039 : : rtx_insn **before, rtx_insn **after, bool early_clobber_p)
1040 : : {
1041 : 1731702 : bool out_conflict;
1042 : 1731702 : int i, in;
1043 : 1731702 : rtx new_in_reg, new_out_reg, reg;
1044 : 1731702 : machine_mode inmode, outmode;
1045 : 1731702 : rtx in_rtx = *curr_id->operand_loc[ins[0]];
1046 : 1731702 : rtx out_rtx = out < 0 ? in_rtx : *curr_id->operand_loc[out];
1047 : :
1048 : 1731702 : inmode = curr_operand_mode[ins[0]];
1049 : 1731702 : outmode = out < 0 ? inmode : curr_operand_mode[out];
1050 : 1731702 : push_to_sequence (*before);
1051 : 1731702 : if (inmode != outmode)
1052 : : {
1053 : : /* process_alt_operands has already checked that the mode sizes
1054 : : are ordered. */
1055 : 129553 : if (partial_subreg_p (outmode, inmode))
1056 : : {
1057 : 1666 : bool asm_p = asm_noperands (PATTERN (curr_insn)) >= 0;
1058 : 1666 : int hr;
1059 : 1666 : HARD_REG_SET temp_hard_reg_set;
1060 : :
1061 : 19 : if (asm_p && (hr = get_hard_regno (out_rtx)) >= 0
1062 : 1669 : && hard_regno_nregs (hr, inmode) > 1)
1063 : : {
1064 : : /* See gcc.c-torture/execute/20030222-1.c.
1065 : : Consider the code for 32-bit (e.g. BE) target:
1066 : : int i, v; long x; x = v; asm ("" : "=r" (i) : "0" (x));
1067 : : We generate the following RTL with reload insns:
1068 : : 1. subreg:si(x:di, 0) = 0;
1069 : : 2. subreg:si(x:di, 4) = v:si;
1070 : : 3. t:di = x:di, dead x;
1071 : : 4. asm ("" : "=r" (subreg:si(t:di,4)) : "0" (t:di))
1072 : : 5. i:si = subreg:si(t:di,4);
1073 : : If we assign hard reg of x to t, dead code elimination
1074 : : will remove insn #2 and we will use unitialized hard reg.
1075 : : So exclude the hard reg of x for t. We could ignore this
1076 : : problem for non-empty asm using all x value but it is hard to
1077 : : check that the asm are expanded into insn realy using x
1078 : : and setting r. */
1079 : 0 : CLEAR_HARD_REG_SET (temp_hard_reg_set);
1080 : 0 : if (exclude_start_hard_regs != NULL)
1081 : 0 : temp_hard_reg_set = *exclude_start_hard_regs;
1082 : 0 : SET_HARD_REG_BIT (temp_hard_reg_set, hr);
1083 : 0 : exclude_start_hard_regs = &temp_hard_reg_set;
1084 : : }
1085 : 3332 : reg = new_in_reg
1086 : 1666 : = lra_create_new_reg_with_unique_value (inmode, in_rtx, goal_class,
1087 : : exclude_start_hard_regs,
1088 : : "");
1089 : 1666 : new_out_reg = gen_lowpart_SUBREG (outmode, reg);
1090 : 1666 : LRA_SUBREG_P (new_out_reg) = 1;
1091 : : /* If the input reg is dying here, we can use the same hard
1092 : : register for REG and IN_RTX. We do it only for original
1093 : : pseudos as reload pseudos can die although original
1094 : : pseudos still live where reload pseudos dies. */
1095 : 1467 : if (REG_P (in_rtx) && (int) REGNO (in_rtx) < lra_new_regno_start
1096 : 1429 : && find_regno_note (curr_insn, REG_DEAD, REGNO (in_rtx))
1097 : 2671 : && (!early_clobber_p
1098 : 2 : || check_conflict_input_operands(REGNO (in_rtx), ins)))
1099 : 1004 : lra_assign_reg_val (REGNO (in_rtx), REGNO (reg));
1100 : : }
1101 : : else
1102 : : {
1103 : 255774 : reg = new_out_reg
1104 : 127887 : = lra_create_new_reg_with_unique_value (outmode, out_rtx,
1105 : : goal_class,
1106 : : exclude_start_hard_regs,
1107 : : "");
1108 : 127887 : new_in_reg = gen_lowpart_SUBREG (inmode, reg);
1109 : : /* NEW_IN_REG is non-paradoxical subreg. We don't want
1110 : : NEW_OUT_REG living above. We add clobber clause for
1111 : : this. This is just a temporary clobber. We can remove
1112 : : it at the end of LRA work. */
1113 : 127887 : rtx_insn *clobber = emit_clobber (new_out_reg);
1114 : 127887 : LRA_TEMP_CLOBBER_P (PATTERN (clobber)) = 1;
1115 : 127887 : LRA_SUBREG_P (new_in_reg) = 1;
1116 : 127887 : if (GET_CODE (in_rtx) == SUBREG)
1117 : : {
1118 : 1786 : rtx subreg_reg = SUBREG_REG (in_rtx);
1119 : :
1120 : : /* If SUBREG_REG is dying here and sub-registers IN_RTX
1121 : : and NEW_IN_REG are similar, we can use the same hard
1122 : : register for REG and SUBREG_REG. */
1123 : 1786 : if (REG_P (subreg_reg)
1124 : 1786 : && (int) REGNO (subreg_reg) < lra_new_regno_start
1125 : 1786 : && GET_MODE (subreg_reg) == outmode
1126 : 1135 : && known_eq (SUBREG_BYTE (in_rtx), SUBREG_BYTE (new_in_reg))
1127 : 1135 : && find_regno_note (curr_insn, REG_DEAD, REGNO (subreg_reg))
1128 : 1970 : && (! early_clobber_p
1129 : 0 : || check_conflict_input_operands (REGNO (subreg_reg),
1130 : : ins)))
1131 : 184 : lra_assign_reg_val (REGNO (subreg_reg), REGNO (reg));
1132 : : }
1133 : : }
1134 : : }
1135 : : else
1136 : : {
1137 : : /* Pseudos have values -- see comments for lra_reg_info.
1138 : : Different pseudos with the same value do not conflict even if
1139 : : they live in the same place. When we create a pseudo we
1140 : : assign value of original pseudo (if any) from which we
1141 : : created the new pseudo. If we create the pseudo from the
1142 : : input pseudo, the new pseudo will have no conflict with the
1143 : : input pseudo which is wrong when the input pseudo lives after
1144 : : the insn and as the new pseudo value is changed by the insn
1145 : : output. Therefore we create the new pseudo from the output
1146 : : except the case when we have single matched dying input
1147 : : pseudo.
1148 : :
1149 : : We cannot reuse the current output register because we might
1150 : : have a situation like "a <- a op b", where the constraints
1151 : : force the second input operand ("b") to match the output
1152 : : operand ("a"). "b" must then be copied into a new register
1153 : : so that it doesn't clobber the current value of "a".
1154 : :
1155 : : We cannot use the same value if the output pseudo is
1156 : : early clobbered or the input pseudo is mentioned in the
1157 : : output, e.g. as an address part in memory, because
1158 : : output reload will actually extend the pseudo liveness.
1159 : : We don't care about eliminable hard regs here as we are
1160 : : interesting only in pseudos. */
1161 : :
1162 : : /* Matching input's register value is the same as one of the other
1163 : : output operand. Output operands in a parallel insn must be in
1164 : : different registers. */
1165 : 1602149 : out_conflict = false;
1166 : 1602149 : if (REG_P (in_rtx))
1167 : : {
1168 : 2727402 : for (i = 0; outs[i] >= 0; i++)
1169 : : {
1170 : 1411485 : rtx other_out_rtx = *curr_id->operand_loc[outs[i]];
1171 : 95331 : if (outs[i] != out && REG_P (other_out_rtx)
1172 : 1506622 : && (regno_val_use_in (REGNO (in_rtx), other_out_rtx)
1173 : : != NULL_RTX))
1174 : : {
1175 : : out_conflict = true;
1176 : : break;
1177 : : }
1178 : : }
1179 : : }
1180 : :
1181 : 1602149 : new_in_reg = new_out_reg
1182 : 1570042 : = (! early_clobber_p && ins[1] < 0 && REG_P (in_rtx)
1183 : 1284909 : && (int) REGNO (in_rtx) < lra_new_regno_start
1184 : 1284612 : && find_regno_note (curr_insn, REG_DEAD, REGNO (in_rtx))
1185 : : && (! early_clobber_p
1186 : : || check_conflict_input_operands (REGNO (in_rtx), ins))
1187 : 419966 : && (out < 0
1188 : 419966 : || regno_val_use_in (REGNO (in_rtx), out_rtx) == NULL_RTX)
1189 : 419906 : && !out_conflict
1190 : 2022026 : ? lra_create_new_reg (inmode, in_rtx, goal_class,
1191 : : exclude_start_hard_regs, "")
1192 : 1182272 : : lra_create_new_reg_with_unique_value (outmode, out_rtx, goal_class,
1193 : : exclude_start_hard_regs,
1194 : : ""));
1195 : : }
1196 : : /* In operand can be got from transformations before processing insn
1197 : : constraints. One example of such transformations is subreg
1198 : : reloading (see function simplify_operand_subreg). The new
1199 : : pseudos created by the transformations might have inaccurate
1200 : : class (ALL_REGS) and we should make their classes more
1201 : : accurate. */
1202 : 1731702 : narrow_reload_pseudo_class (in_rtx, goal_class);
1203 : 1731702 : lra_emit_move (copy_rtx (new_in_reg), in_rtx);
1204 : 1731702 : *before = end_sequence ();
1205 : : /* Add the new pseudo to consider values of subsequent input reload
1206 : : pseudos. */
1207 : 1731702 : lra_assert (curr_insn_input_reloads_num < LRA_MAX_INSN_RELOADS);
1208 : 1731702 : curr_insn_input_reloads[curr_insn_input_reloads_num].input = in_rtx;
1209 : 1731702 : curr_insn_input_reloads[curr_insn_input_reloads_num].match_p = true;
1210 : 1731702 : curr_insn_input_reloads[curr_insn_input_reloads_num].early_clobber_p = false;
1211 : 1731702 : curr_insn_input_reloads[curr_insn_input_reloads_num++].reg = new_in_reg;
1212 : 3463405 : for (i = 0; (in = ins[i]) >= 0; i++)
1213 : 1731703 : if (GET_MODE (*curr_id->operand_loc[in]) == VOIDmode
1214 : 1705268 : || GET_MODE (new_in_reg) == GET_MODE (*curr_id->operand_loc[in]))
1215 : 1731702 : *curr_id->operand_loc[in] = new_in_reg;
1216 : : else
1217 : : {
1218 : 1 : lra_assert
1219 : : (GET_MODE (new_out_reg) == GET_MODE (*curr_id->operand_loc[in]));
1220 : 1 : *curr_id->operand_loc[in] = new_out_reg;
1221 : : }
1222 : 1731702 : lra_update_dups (curr_id, ins);
1223 : 1731702 : if (out < 0)
1224 : : return;
1225 : : /* See a comment for the input operand above. */
1226 : 1731702 : narrow_reload_pseudo_class (out_rtx, goal_class);
1227 : 1731702 : if (find_reg_note (curr_insn, REG_UNUSED, out_rtx) == NULL_RTX)
1228 : : {
1229 : 1646868 : reg = SUBREG_P (out_rtx) ? SUBREG_REG (out_rtx) : out_rtx;
1230 : 1646868 : start_sequence ();
1231 : : /* If we had strict_low_part, use it also in reload to keep other
1232 : : parts unchanged but do it only for regs as strict_low_part
1233 : : has no sense for memory and probably there is no insn pattern
1234 : : to match the reload insn in memory case. */
1235 : 1646868 : if (out >= 0 && curr_static_id->operand[out].strict_low && REG_P (reg))
1236 : 0 : out_rtx = gen_rtx_STRICT_LOW_PART (VOIDmode, out_rtx);
1237 : 1646868 : lra_emit_move (out_rtx, copy_rtx (new_out_reg));
1238 : 1646868 : emit_insn (*after);
1239 : 1646868 : *after = end_sequence ();
1240 : : }
1241 : 1731702 : *curr_id->operand_loc[out] = new_out_reg;
1242 : 1731702 : lra_update_dup (curr_id, out);
1243 : : }
1244 : :
1245 : : /* Return register class which is union of all reg classes in insn
1246 : : constraint alternative string starting with P. */
1247 : : static enum reg_class
1248 : 0 : reg_class_from_constraints (const char *p)
1249 : : {
1250 : 0 : int c, len;
1251 : 0 : enum reg_class op_class = NO_REGS;
1252 : :
1253 : 0 : do
1254 : 0 : switch ((c = *p, len = CONSTRAINT_LEN (c, p)), c)
1255 : : {
1256 : : case '#':
1257 : : case ',':
1258 : : return op_class;
1259 : :
1260 : 0 : case 'g':
1261 : 0 : op_class = reg_class_subunion[op_class][GENERAL_REGS];
1262 : 0 : break;
1263 : :
1264 : 0 : default:
1265 : 0 : enum constraint_num cn = lookup_constraint (p);
1266 : 0 : enum reg_class cl = reg_class_for_constraint (cn);
1267 : 0 : if (cl == NO_REGS)
1268 : : {
1269 : 0 : if (insn_extra_address_constraint (cn))
1270 : 0 : op_class
1271 : 0 : = (reg_class_subunion
1272 : 0 : [op_class][base_reg_class (VOIDmode, ADDR_SPACE_GENERIC,
1273 : 0 : ADDRESS, SCRATCH)]);
1274 : : break;
1275 : : }
1276 : :
1277 : 0 : op_class = reg_class_subunion[op_class][cl];
1278 : 0 : break;
1279 : : }
1280 : 0 : while ((p += len), c);
1281 : : return op_class;
1282 : : }
1283 : :
1284 : : /* If OP is a register, return the class of the register as per
1285 : : get_reg_class, otherwise return NO_REGS. */
1286 : : static inline enum reg_class
1287 : 165076915 : get_op_class (rtx op)
1288 : : {
1289 : 137192924 : return REG_P (op) ? get_reg_class (REGNO (op)) : NO_REGS;
1290 : : }
1291 : :
1292 : : /* Return generated insn mem_pseudo:=val if TO_P or val:=mem_pseudo
1293 : : otherwise. If modes of MEM_PSEUDO and VAL are different, use
1294 : : SUBREG for VAL to make them equal. */
1295 : : static rtx_insn *
1296 : 1273155 : emit_spill_move (bool to_p, rtx mem_pseudo, rtx val)
1297 : : {
1298 : 1273155 : if (GET_MODE (mem_pseudo) != GET_MODE (val))
1299 : : {
1300 : : /* Usually size of mem_pseudo is greater than val size but in
1301 : : rare cases it can be less as it can be defined by target
1302 : : dependent macro HARD_REGNO_CALLER_SAVE_MODE. */
1303 : 3412 : if (! MEM_P (val))
1304 : : {
1305 : 3412 : val = gen_lowpart_SUBREG (GET_MODE (mem_pseudo),
1306 : : GET_CODE (val) == SUBREG
1307 : : ? SUBREG_REG (val) : val);
1308 : 3412 : LRA_SUBREG_P (val) = 1;
1309 : : }
1310 : : else
1311 : : {
1312 : 0 : mem_pseudo = gen_lowpart_SUBREG (GET_MODE (val), mem_pseudo);
1313 : 0 : LRA_SUBREG_P (mem_pseudo) = 1;
1314 : : }
1315 : : }
1316 : 1273155 : return to_p ? gen_move_insn (mem_pseudo, val)
1317 : 643222 : : gen_move_insn (val, mem_pseudo);
1318 : : }
1319 : :
1320 : : /* Process a special case insn (register move), return true if we
1321 : : don't need to process it anymore. INSN should be a single set
1322 : : insn. Set up that RTL was changed through CHANGE_P and that hook
1323 : : TARGET_SECONDARY_MEMORY_NEEDED says to use secondary memory through
1324 : : SEC_MEM_P. */
1325 : : static bool
1326 : 76446725 : check_and_process_move (bool *change_p, bool *sec_mem_p ATTRIBUTE_UNUSED)
1327 : : {
1328 : 76446725 : int sregno, dregno;
1329 : 76446725 : rtx dest, src, dreg, sreg, new_reg, scratch_reg;
1330 : 76446725 : rtx_insn *before;
1331 : 76446725 : enum reg_class dclass, sclass, secondary_class;
1332 : 76446725 : secondary_reload_info sri;
1333 : :
1334 : 76446725 : lra_assert (curr_insn_set != NULL_RTX);
1335 : 76446725 : dreg = dest = SET_DEST (curr_insn_set);
1336 : 76446725 : sreg = src = SET_SRC (curr_insn_set);
1337 : 76446725 : if (GET_CODE (dest) == SUBREG)
1338 : 1156913 : dreg = SUBREG_REG (dest);
1339 : 76446725 : if (GET_CODE (src) == SUBREG)
1340 : 1218677 : sreg = SUBREG_REG (src);
1341 : 76446725 : if (! (REG_P (dreg) || MEM_P (dreg)) || ! (REG_P (sreg) || MEM_P (sreg)))
1342 : : return false;
1343 : 35795794 : sclass = dclass = NO_REGS;
1344 : 35795794 : if (REG_P (dreg))
1345 : 23133751 : dclass = get_reg_class (REGNO (dreg));
1346 : 23133751 : gcc_assert (dclass < LIM_REG_CLASSES && dclass >= NO_REGS);
1347 : 35795794 : if (dclass == ALL_REGS)
1348 : : /* ALL_REGS is used for new pseudos created by transformations
1349 : : like reload of SUBREG_REG (see function
1350 : : simplify_operand_subreg). We don't know their class yet. We
1351 : : should figure out the class from processing the insn
1352 : : constraints not in this fast path function. Even if ALL_REGS
1353 : : were a right class for the pseudo, secondary_... hooks usually
1354 : : are not define for ALL_REGS. */
1355 : : return false;
1356 : 35793674 : if (REG_P (sreg))
1357 : 19837524 : sclass = get_reg_class (REGNO (sreg));
1358 : 19837524 : gcc_assert (sclass < LIM_REG_CLASSES && sclass >= NO_REGS);
1359 : 35793674 : if (sclass == ALL_REGS)
1360 : : /* See comments above. */
1361 : : return false;
1362 : 35793674 : if (sclass == NO_REGS && dclass == NO_REGS)
1363 : : return false;
1364 : 34332419 : if (targetm.secondary_memory_needed (GET_MODE (src), sclass, dclass)
1365 : 34332419 : && ((sclass != NO_REGS && dclass != NO_REGS)
1366 : 0 : || (GET_MODE (src)
1367 : 0 : != targetm.secondary_memory_needed_mode (GET_MODE (src)))))
1368 : : {
1369 : 13905 : *sec_mem_p = true;
1370 : 13905 : return false;
1371 : : }
1372 : 34318514 : if (! REG_P (dreg) || ! REG_P (sreg))
1373 : : return false;
1374 : 7684056 : sri.prev_sri = NULL;
1375 : 7684056 : sri.icode = CODE_FOR_nothing;
1376 : 7684056 : sri.extra_cost = 0;
1377 : 7684056 : secondary_class = NO_REGS;
1378 : : /* Set up hard register for a reload pseudo for hook
1379 : : secondary_reload because some targets just ignore unassigned
1380 : : pseudos in the hook. */
1381 : 7684056 : if (dclass != NO_REGS && lra_get_regno_hard_regno (REGNO (dreg)) < 0)
1382 : : {
1383 : 2901699 : dregno = REGNO (dreg);
1384 : 2901699 : reg_renumber[dregno] = ira_class_hard_regs[dclass][0];
1385 : : }
1386 : : else
1387 : : dregno = -1;
1388 : 7684056 : if (sclass != NO_REGS && lra_get_regno_hard_regno (REGNO (sreg)) < 0)
1389 : : {
1390 : 1269375 : sregno = REGNO (sreg);
1391 : 1269375 : reg_renumber[sregno] = ira_class_hard_regs[sclass][0];
1392 : : }
1393 : : else
1394 : : sregno = -1;
1395 : 7684056 : if (sclass != NO_REGS)
1396 : 3850767 : secondary_class
1397 : 7701534 : = (enum reg_class) targetm.secondary_reload (false, dest,
1398 : : (reg_class_t) sclass,
1399 : 3850767 : GET_MODE (src), &sri);
1400 : 3850767 : if (sclass == NO_REGS
1401 : 3850767 : || ((secondary_class != NO_REGS || sri.icode != CODE_FOR_nothing)
1402 : 1375 : && dclass != NO_REGS))
1403 : : {
1404 : 3833289 : enum reg_class old_sclass = secondary_class;
1405 : 3833289 : secondary_reload_info old_sri = sri;
1406 : :
1407 : 3833289 : sri.prev_sri = NULL;
1408 : 3833289 : sri.icode = CODE_FOR_nothing;
1409 : 3833289 : sri.extra_cost = 0;
1410 : 3833289 : secondary_class
1411 : 7666578 : = (enum reg_class) targetm.secondary_reload (true, src,
1412 : : (reg_class_t) dclass,
1413 : 3833289 : GET_MODE (src), &sri);
1414 : : /* Check the target hook consistency. */
1415 : 3833289 : lra_assert
1416 : : ((secondary_class == NO_REGS && sri.icode == CODE_FOR_nothing)
1417 : : || (old_sclass == NO_REGS && old_sri.icode == CODE_FOR_nothing)
1418 : : || (secondary_class == old_sclass && sri.icode == old_sri.icode));
1419 : : }
1420 : 7684056 : if (sregno >= 0)
1421 : 1269375 : reg_renumber [sregno] = -1;
1422 : 7684056 : if (dregno >= 0)
1423 : 2901699 : reg_renumber [dregno] = -1;
1424 : 7684056 : if (secondary_class == NO_REGS && sri.icode == CODE_FOR_nothing)
1425 : : return false;
1426 : 1376 : *change_p = true;
1427 : 1376 : new_reg = NULL_RTX;
1428 : 0 : if (secondary_class != NO_REGS)
1429 : 1376 : new_reg = lra_create_new_reg_with_unique_value (GET_MODE (src), NULL_RTX,
1430 : : secondary_class, NULL,
1431 : : "secondary");
1432 : 1376 : start_sequence ();
1433 : 1376 : if (sri.icode == CODE_FOR_nothing)
1434 : 1376 : lra_emit_move (new_reg, src);
1435 : : else
1436 : : {
1437 : 0 : enum reg_class scratch_class;
1438 : :
1439 : 0 : scratch_class = (reg_class_from_constraints
1440 : 0 : (insn_data[sri.icode].operand[2].constraint));
1441 : 0 : scratch_reg = (lra_create_new_reg_with_unique_value
1442 : 0 : (insn_data[sri.icode].operand[2].mode, NULL_RTX,
1443 : : scratch_class, NULL, "scratch"));
1444 : 0 : emit_insn (GEN_FCN (sri.icode) (new_reg != NULL_RTX ? new_reg : dest,
1445 : : src, scratch_reg));
1446 : : }
1447 : 1376 : before = end_sequence ();
1448 : 1376 : lra_process_new_insns (curr_insn, before, NULL, "Inserting the move");
1449 : 1376 : if (new_reg != NULL_RTX)
1450 : 1376 : SET_SRC (curr_insn_set) = new_reg;
1451 : : else
1452 : : {
1453 : 0 : if (lra_dump_file != NULL)
1454 : : {
1455 : 0 : fprintf (lra_dump_file, "Deleting move %u\n", INSN_UID (curr_insn));
1456 : 0 : dump_insn_slim (lra_dump_file, curr_insn);
1457 : : }
1458 : 0 : lra_set_insn_deleted (curr_insn);
1459 : 0 : return true;
1460 : : }
1461 : 1376 : return false;
1462 : : }
1463 : :
1464 : : /* The following data describe the result of process_alt_operands.
1465 : : The data are used in curr_insn_transform to generate reloads. */
1466 : :
1467 : : /* The chosen reg classes which should be used for the corresponding
1468 : : operands. */
1469 : : static enum reg_class goal_alt[MAX_RECOG_OPERANDS];
1470 : : /* Hard registers which cannot be a start hard register for the corresponding
1471 : : operands. */
1472 : : static HARD_REG_SET goal_alt_exclude_start_hard_regs[MAX_RECOG_OPERANDS];
1473 : : /* True if the operand should be the same as another operand and that
1474 : : other operand does not need a reload. */
1475 : : static bool goal_alt_match_win[MAX_RECOG_OPERANDS];
1476 : : /* True if the operand does not need a reload. */
1477 : : static bool goal_alt_win[MAX_RECOG_OPERANDS];
1478 : : /* True if the operand can be offsetable memory. */
1479 : : static bool goal_alt_offmemok[MAX_RECOG_OPERANDS];
1480 : : /* The number of an operand to which given operand can be matched to. */
1481 : : static int goal_alt_matches[MAX_RECOG_OPERANDS];
1482 : : /* The number of elements in the following array. */
1483 : : static int goal_alt_dont_inherit_ops_num;
1484 : : /* Numbers of operands whose reload pseudos should not be inherited. */
1485 : : static int goal_alt_dont_inherit_ops[MAX_RECOG_OPERANDS];
1486 : : /* True if we should try only this alternative for the next constraint sub-pass
1487 : : to speed up the sub-pass. */
1488 : : static bool goal_reuse_alt_p;
1489 : : /* True if the insn commutative operands should be swapped. */
1490 : : static bool goal_alt_swapped;
1491 : : /* The chosen insn alternative. */
1492 : : static int goal_alt_number;
1493 : : /* True if output reload of the stack pointer should be generated. */
1494 : : static bool goal_alt_out_sp_reload_p;
1495 : :
1496 : : /* True if the corresponding operand is the result of an equivalence
1497 : : substitution. */
1498 : : static bool equiv_substition_p[MAX_RECOG_OPERANDS];
1499 : :
1500 : : /* The following five variables are used to choose the best insn
1501 : : alternative. They reflect final characteristics of the best
1502 : : alternative. */
1503 : :
1504 : : /* Number of necessary reloads and overall cost reflecting the
1505 : : previous value and other unpleasantness of the best alternative. */
1506 : : static int best_losers, best_overall;
1507 : : /* Overall number hard registers used for reloads. For example, on
1508 : : some targets we need 2 general registers to reload DFmode and only
1509 : : one floating point register. */
1510 : : static int best_reload_nregs;
1511 : : /* Overall number reflecting distances of previous reloading the same
1512 : : value. The distances are counted from the current BB start. It is
1513 : : used to improve inheritance chances. */
1514 : : static int best_reload_sum;
1515 : :
1516 : : /* True if the current insn should have no correspondingly input or
1517 : : output reloads. */
1518 : : static bool no_input_reloads_p, no_output_reloads_p;
1519 : :
1520 : : /* True if we swapped the commutative operands in the current
1521 : : insn. */
1522 : : static int curr_swapped;
1523 : :
1524 : : /* if CHECK_ONLY_P is false, arrange for address element *LOC to be a
1525 : : register of class CL. Add any input reloads to list BEFORE. AFTER
1526 : : is nonnull if *LOC is an automodified value; handle that case by
1527 : : adding the required output reloads to list AFTER. Return true if
1528 : : the RTL was changed.
1529 : :
1530 : : if CHECK_ONLY_P is true, check that the *LOC is a correct address
1531 : : register. Return false if the address register is correct. */
1532 : : static bool
1533 : 35509032 : process_addr_reg (rtx *loc, bool check_only_p, rtx_insn **before, rtx_insn **after,
1534 : : enum reg_class cl)
1535 : : {
1536 : 35509032 : int regno;
1537 : 35509032 : enum reg_class rclass, new_class;
1538 : 35509032 : rtx reg;
1539 : 35509032 : rtx new_reg;
1540 : 35509032 : machine_mode mode;
1541 : 35509032 : bool subreg_p, before_p = false;
1542 : :
1543 : 35509032 : subreg_p = GET_CODE (*loc) == SUBREG;
1544 : 35509032 : if (subreg_p)
1545 : : {
1546 : 17138 : reg = SUBREG_REG (*loc);
1547 : 17138 : mode = GET_MODE (reg);
1548 : :
1549 : : /* For mode with size bigger than ptr_mode, there unlikely to be "mov"
1550 : : between two registers with different classes, but there normally will
1551 : : be "mov" which transfers element of vector register into the general
1552 : : register, and this normally will be a subreg which should be reloaded
1553 : : as a whole. This is particularly likely to be triggered when
1554 : : -fno-split-wide-types specified. */
1555 : 17138 : if (!REG_P (reg)
1556 : 17138 : || in_class_p (reg, cl, &new_class)
1557 : 19590 : || known_le (GET_MODE_SIZE (mode), GET_MODE_SIZE (ptr_mode)))
1558 : 17138 : loc = &SUBREG_REG (*loc);
1559 : : }
1560 : :
1561 : 35509032 : reg = *loc;
1562 : 35509032 : mode = GET_MODE (reg);
1563 : 35509032 : if (! REG_P (reg))
1564 : : {
1565 : 0 : if (check_only_p)
1566 : : return true;
1567 : : /* Always reload memory in an address even if the target supports
1568 : : such addresses. */
1569 : 0 : new_reg = lra_create_new_reg_with_unique_value (mode, reg, cl, NULL,
1570 : : "address");
1571 : 0 : before_p = true;
1572 : : }
1573 : : else
1574 : : {
1575 : 35509032 : regno = REGNO (reg);
1576 : 35509032 : rclass = get_reg_class (regno);
1577 : 35509032 : if (! check_only_p
1578 : 35509032 : && (*loc = get_equiv_with_elimination (reg, curr_insn)) != reg)
1579 : : {
1580 : 111721 : if (lra_dump_file != NULL)
1581 : : {
1582 : 0 : fprintf (lra_dump_file,
1583 : : "Changing pseudo %d in address of insn %u on equiv ",
1584 : 0 : REGNO (reg), INSN_UID (curr_insn));
1585 : 0 : dump_value_slim (lra_dump_file, *loc, 1);
1586 : 0 : fprintf (lra_dump_file, "\n");
1587 : : }
1588 : 111721 : *loc = copy_rtx (*loc);
1589 : : }
1590 : 35509032 : if (*loc != reg || ! in_class_p (reg, cl, &new_class))
1591 : : {
1592 : 484191 : if (check_only_p)
1593 : : return true;
1594 : 484191 : reg = *loc;
1595 : 484191 : if (get_reload_reg (after == NULL ? OP_IN : OP_INOUT,
1596 : : mode, reg, cl, NULL,
1597 : : subreg_p, false, "address", &new_reg))
1598 : : before_p = true;
1599 : : }
1600 : 35024841 : else if (new_class != NO_REGS && rclass != new_class)
1601 : : {
1602 : 473321 : if (check_only_p)
1603 : : return true;
1604 : 473321 : lra_change_class (regno, new_class, " Change to", true);
1605 : 473321 : return false;
1606 : : }
1607 : : else
1608 : : return false;
1609 : : }
1610 : 0 : if (before_p)
1611 : : {
1612 : 476957 : push_to_sequence (*before);
1613 : 476957 : lra_emit_move (new_reg, reg);
1614 : 476957 : *before = end_sequence ();
1615 : : }
1616 : 484191 : *loc = new_reg;
1617 : 484191 : if (after != NULL)
1618 : : {
1619 : 0 : start_sequence ();
1620 : 0 : lra_emit_move (before_p ? copy_rtx (reg) : reg, new_reg);
1621 : 0 : emit_insn (*after);
1622 : 0 : *after = end_sequence ();
1623 : : }
1624 : : return true;
1625 : : }
1626 : :
1627 : : /* Insert move insn in simplify_operand_subreg. BEFORE returns
1628 : : the insn to be inserted before curr insn. AFTER returns the
1629 : : the insn to be inserted after curr insn. ORIGREG and NEWREG
1630 : : are the original reg and new reg for reload. */
1631 : : static void
1632 : 459 : insert_move_for_subreg (rtx_insn **before, rtx_insn **after, rtx origreg,
1633 : : rtx newreg)
1634 : : {
1635 : 459 : if (before)
1636 : : {
1637 : 459 : push_to_sequence (*before);
1638 : 459 : lra_emit_move (newreg, origreg);
1639 : 459 : *before = end_sequence ();
1640 : : }
1641 : 459 : if (after)
1642 : : {
1643 : 0 : start_sequence ();
1644 : 0 : lra_emit_move (origreg, newreg);
1645 : 0 : emit_insn (*after);
1646 : 0 : *after = end_sequence ();
1647 : : }
1648 : 459 : }
1649 : :
1650 : : static bool valid_address_p (machine_mode mode, rtx addr, addr_space_t as);
1651 : : static bool process_address (int, bool, rtx_insn **, rtx_insn **);
1652 : :
1653 : : /* Make reloads for subreg in operand NOP with internal subreg mode
1654 : : REG_MODE, add new reloads for further processing. Return true if
1655 : : any change was done. */
1656 : : static bool
1657 : 177388940 : simplify_operand_subreg (int nop, machine_mode reg_mode)
1658 : : {
1659 : 177388940 : int hard_regno, inner_hard_regno;
1660 : 177388940 : rtx_insn *before, *after;
1661 : 177388940 : machine_mode mode, innermode;
1662 : 177388940 : rtx reg, new_reg;
1663 : 177388940 : rtx operand = *curr_id->operand_loc[nop];
1664 : 177388940 : enum reg_class regclass;
1665 : 177388940 : enum op_type type;
1666 : :
1667 : 177388940 : before = after = NULL;
1668 : :
1669 : 177388940 : if (GET_CODE (operand) != SUBREG)
1670 : : return false;
1671 : :
1672 : 3657784 : mode = GET_MODE (operand);
1673 : 3657784 : reg = SUBREG_REG (operand);
1674 : 3657784 : innermode = GET_MODE (reg);
1675 : 3657784 : type = curr_static_id->operand[nop].type;
1676 : 3657784 : if (MEM_P (reg))
1677 : : {
1678 : 11432 : const bool addr_was_valid
1679 : 11432 : = valid_address_p (innermode, XEXP (reg, 0), MEM_ADDR_SPACE (reg));
1680 : 11432 : alter_subreg (curr_id->operand_loc[nop], false);
1681 : 11432 : rtx subst = *curr_id->operand_loc[nop];
1682 : 11432 : lra_assert (MEM_P (subst));
1683 : 11432 : const bool addr_is_valid = valid_address_p (GET_MODE (subst),
1684 : : XEXP (subst, 0),
1685 : 11432 : MEM_ADDR_SPACE (subst));
1686 : 11432 : if (!addr_was_valid
1687 : 11432 : || addr_is_valid
1688 : 11432 : || ((get_constraint_type (lookup_constraint
1689 : 0 : (curr_static_id->operand[nop].constraint))
1690 : : != CT_SPECIAL_MEMORY)
1691 : : /* We still can reload address and if the address is
1692 : : valid, we can remove subreg without reloading its
1693 : : inner memory. */
1694 : 0 : && valid_address_p (GET_MODE (subst),
1695 : 0 : regno_reg_rtx
1696 : : [ira_class_hard_regs
1697 : 0 : [base_reg_class (GET_MODE (subst),
1698 : 0 : MEM_ADDR_SPACE (subst),
1699 : 0 : ADDRESS, SCRATCH)][0]],
1700 : 0 : MEM_ADDR_SPACE (subst))))
1701 : : {
1702 : : /* If we change the address for a paradoxical subreg of memory, the
1703 : : new address might violate the necessary alignment or the access
1704 : : might be slow; take this into consideration. We need not worry
1705 : : about accesses beyond allocated memory for paradoxical memory
1706 : : subregs as we don't substitute such equiv memory (see processing
1707 : : equivalences in function lra_constraints) and because for spilled
1708 : : pseudos we allocate stack memory enough for the biggest
1709 : : corresponding paradoxical subreg.
1710 : :
1711 : : However, do not blindly simplify a (subreg (mem ...)) for
1712 : : WORD_REGISTER_OPERATIONS targets as this may lead to loading junk
1713 : : data into a register when the inner is narrower than outer or
1714 : : missing important data from memory when the inner is wider than
1715 : : outer. This rule only applies to modes that are no wider than
1716 : : a word.
1717 : :
1718 : : If valid memory becomes invalid after subreg elimination
1719 : : and address might be different we still have to reload
1720 : : memory.
1721 : : */
1722 : 11432 : if ((! addr_was_valid
1723 : : || addr_is_valid
1724 : 0 : || known_eq (GET_MODE_SIZE (mode), GET_MODE_SIZE (innermode)))
1725 : 11432 : && !(maybe_ne (GET_MODE_PRECISION (mode),
1726 : 11432 : GET_MODE_PRECISION (innermode))
1727 : 14035 : && known_le (GET_MODE_SIZE (mode), UNITS_PER_WORD)
1728 : 20235 : && known_le (GET_MODE_SIZE (innermode), UNITS_PER_WORD)
1729 : : && WORD_REGISTER_OPERATIONS)
1730 : 24021 : && (!(MEM_ALIGN (subst) < GET_MODE_ALIGNMENT (mode)
1731 : 1157 : && targetm.slow_unaligned_access (mode, MEM_ALIGN (subst)))
1732 : 0 : || (MEM_ALIGN (reg) < GET_MODE_ALIGNMENT (innermode)
1733 : 0 : && targetm.slow_unaligned_access (innermode,
1734 : 0 : MEM_ALIGN (reg)))))
1735 : 11432 : return true;
1736 : :
1737 : 0 : *curr_id->operand_loc[nop] = operand;
1738 : :
1739 : : /* But if the address was not valid, we cannot reload the MEM without
1740 : : reloading the address first. */
1741 : 0 : if (!addr_was_valid)
1742 : 0 : process_address (nop, false, &before, &after);
1743 : :
1744 : : /* INNERMODE is fast, MODE slow. Reload the mem in INNERMODE. */
1745 : 0 : enum reg_class rclass
1746 : 0 : = (enum reg_class) targetm.preferred_reload_class (reg, ALL_REGS);
1747 : 0 : if (get_reload_reg (curr_static_id->operand[nop].type, innermode,
1748 : : reg, rclass, NULL,
1749 : : true, false, "slow/invalid mem", &new_reg))
1750 : : {
1751 : 0 : bool insert_before, insert_after;
1752 : 0 : bitmap_set_bit (&lra_subreg_reload_pseudos, REGNO (new_reg));
1753 : :
1754 : 0 : insert_before = (type != OP_OUT
1755 : 0 : || partial_subreg_p (mode, innermode));
1756 : 0 : insert_after = type != OP_IN;
1757 : 0 : insert_move_for_subreg (insert_before ? &before : NULL,
1758 : : insert_after ? &after : NULL,
1759 : : reg, new_reg);
1760 : : }
1761 : 0 : SUBREG_REG (operand) = new_reg;
1762 : :
1763 : : /* Convert to MODE. */
1764 : 0 : reg = operand;
1765 : 0 : rclass
1766 : 0 : = (enum reg_class) targetm.preferred_reload_class (reg, ALL_REGS);
1767 : 0 : if (get_reload_reg (curr_static_id->operand[nop].type, mode, reg,
1768 : : rclass, NULL,
1769 : : true, false, "slow/invalid mem", &new_reg))
1770 : : {
1771 : 0 : bool insert_before, insert_after;
1772 : 0 : bitmap_set_bit (&lra_subreg_reload_pseudos, REGNO (new_reg));
1773 : :
1774 : 0 : insert_before = type != OP_OUT;
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 : *curr_id->operand_loc[nop] = new_reg;
1781 : 0 : lra_process_new_insns (curr_insn, before, after,
1782 : : "Inserting slow/invalid mem reload");
1783 : 0 : return true;
1784 : : }
1785 : :
1786 : : /* If the address was valid and became invalid, prefer to reload
1787 : : the memory. Typical case is when the index scale should
1788 : : correspond the memory. */
1789 : 0 : *curr_id->operand_loc[nop] = operand;
1790 : : /* Do not return false here as the MEM_P (reg) will be processed
1791 : : later in this function. */
1792 : : }
1793 : 3646352 : else if (REG_P (reg) && REGNO (reg) < FIRST_PSEUDO_REGISTER)
1794 : : {
1795 : 66 : alter_subreg (curr_id->operand_loc[nop], false);
1796 : 66 : return true;
1797 : : }
1798 : 3646286 : else if (CONSTANT_P (reg))
1799 : : {
1800 : : /* Try to simplify subreg of constant. It is usually result of
1801 : : equivalence substitution. */
1802 : 44578 : if (innermode == VOIDmode
1803 : 44578 : && (innermode = original_subreg_reg_mode[nop]) == VOIDmode)
1804 : 0 : innermode = curr_static_id->operand[nop].mode;
1805 : 44578 : if ((new_reg = simplify_subreg (mode, reg, innermode,
1806 : 44578 : SUBREG_BYTE (operand))) != NULL_RTX)
1807 : : {
1808 : 44160 : *curr_id->operand_loc[nop] = new_reg;
1809 : 44160 : return true;
1810 : : }
1811 : : }
1812 : : /* Put constant into memory when we have mixed modes. It generates
1813 : : a better code in most cases as it does not need a secondary
1814 : : reload memory. It also prevents LRA looping when LRA is using
1815 : : secondary reload memory again and again. */
1816 : 836 : if (CONSTANT_P (reg) && CONST_POOL_OK_P (reg_mode, reg)
1817 : 3602544 : && SCALAR_INT_MODE_P (reg_mode) != SCALAR_INT_MODE_P (mode))
1818 : : {
1819 : 8 : SUBREG_REG (operand) = force_const_mem (reg_mode, reg);
1820 : 8 : alter_subreg (curr_id->operand_loc[nop], false);
1821 : 8 : return true;
1822 : : }
1823 : 3602118 : auto fp_subreg_can_be_simplified_after_reload_p = [] (machine_mode innermode,
1824 : : poly_uint64 offset,
1825 : : machine_mode mode) {
1826 : 0 : reload_completed = 1;
1827 : 0 : bool res = simplify_subreg_regno (FRAME_POINTER_REGNUM,
1828 : : innermode,
1829 : 0 : offset, mode) >= 0;
1830 : 0 : reload_completed = 0;
1831 : 0 : return res;
1832 : : };
1833 : : /* Force a reload of the SUBREG_REG if this is a constant or PLUS or
1834 : : if there may be a problem accessing OPERAND in the outer
1835 : : mode. */
1836 : 3602118 : if ((REG_P (reg)
1837 : 3601659 : && REGNO (reg) >= FIRST_PSEUDO_REGISTER
1838 : 3601659 : && (hard_regno = lra_get_regno_hard_regno (REGNO (reg))) >= 0
1839 : : /* Don't reload paradoxical subregs because we could be looping
1840 : : having repeatedly final regno out of hard regs range. */
1841 : 3043478 : && (hard_regno_nregs (hard_regno, innermode)
1842 : 3043478 : >= hard_regno_nregs (hard_regno, mode))
1843 : 3038380 : && simplify_subreg_regno (hard_regno, innermode,
1844 : 3038380 : SUBREG_BYTE (operand), mode) < 0
1845 : : /* Exclude reloading of frame pointer in subreg if frame pointer can not
1846 : : be simplified here only because the reload is not finished yet. */
1847 : 814 : && (hard_regno != FRAME_POINTER_REGNUM
1848 : 0 : || !fp_subreg_can_be_simplified_after_reload_p (innermode,
1849 : 0 : SUBREG_BYTE (operand),
1850 : : mode))
1851 : : /* Don't reload subreg for matching reload. It is actually
1852 : : valid subreg in LRA. */
1853 : 814 : && ! LRA_SUBREG_P (operand))
1854 : 7203777 : || CONSTANT_P (reg) || GET_CODE (reg) == PLUS || MEM_P (reg))
1855 : : {
1856 : 459 : enum reg_class rclass;
1857 : :
1858 : 459 : if (REG_P (reg))
1859 : : /* There is a big probability that we will get the same class
1860 : : for the new pseudo and we will get the same insn which
1861 : : means infinite looping. So spill the new pseudo. */
1862 : : rclass = NO_REGS;
1863 : : else
1864 : : /* The class will be defined later in curr_insn_transform. */
1865 : 459 : rclass
1866 : 459 : = (enum reg_class) targetm.preferred_reload_class (reg, ALL_REGS);
1867 : :
1868 : 459 : if (get_reload_reg (curr_static_id->operand[nop].type, reg_mode, reg,
1869 : : rclass, NULL,
1870 : : true, false, "subreg reg", &new_reg))
1871 : : {
1872 : 459 : bool insert_before, insert_after;
1873 : 459 : bitmap_set_bit (&lra_subreg_reload_pseudos, REGNO (new_reg));
1874 : :
1875 : 918 : insert_before = (type != OP_OUT
1876 : 459 : || read_modify_subreg_p (operand));
1877 : 459 : insert_after = (type != OP_IN);
1878 : 918 : insert_move_for_subreg (insert_before ? &before : NULL,
1879 : : insert_after ? &after : NULL,
1880 : : reg, new_reg);
1881 : : }
1882 : 459 : SUBREG_REG (operand) = new_reg;
1883 : 459 : lra_process_new_insns (curr_insn, before, after,
1884 : : "Inserting subreg reload");
1885 : 459 : return true;
1886 : : }
1887 : : /* Force a reload for a paradoxical subreg. For paradoxical subreg,
1888 : : IRA allocates hardreg to the inner pseudo reg according to its mode
1889 : : instead of the outermode, so the size of the hardreg may not be enough
1890 : : to contain the outermode operand, in that case we may need to insert
1891 : : reload for the reg. For the following two types of paradoxical subreg,
1892 : : we need to insert reload:
1893 : : 1. If the op_type is OP_IN, and the hardreg could not be paired with
1894 : : other hardreg to contain the outermode operand
1895 : : (checked by in_hard_reg_set_p), we need to insert the reload.
1896 : : 2. If the op_type is OP_OUT or OP_INOUT.
1897 : :
1898 : : Here is a paradoxical subreg example showing how the reload is generated:
1899 : :
1900 : : (insn 5 4 7 2 (set (reg:TI 106 [ __comp ])
1901 : : (subreg:TI (reg:DI 107 [ __comp ]) 0)) {*movti_internal_rex64}
1902 : :
1903 : : In IRA, reg107 is allocated to a DImode hardreg. We use x86-64 as example
1904 : : here, if reg107 is assigned to hardreg R15, because R15 is the last
1905 : : hardreg, compiler cannot find another hardreg to pair with R15 to
1906 : : contain TImode data. So we insert a TImode reload reg180 for it.
1907 : : After reload is inserted:
1908 : :
1909 : : (insn 283 0 0 (set (subreg:DI (reg:TI 180 [orig:107 __comp ] [107]) 0)
1910 : : (reg:DI 107 [ __comp ])) -1
1911 : : (insn 5 4 7 2 (set (reg:TI 106 [ __comp ])
1912 : : (subreg:TI (reg:TI 180 [orig:107 __comp ] [107]) 0)) {*movti_internal_rex64}
1913 : :
1914 : : Two reload hard registers will be allocated to reg180 to save TImode data
1915 : : in LRA_assign.
1916 : :
1917 : : For LRA pseudos this should normally be handled by the biggest_mode
1918 : : mechanism. However, it's possible for new uses of an LRA pseudo
1919 : : to be introduced after we've allocated it, such as when undoing
1920 : : inheritance, and the allocated register might not then be appropriate
1921 : : for the new uses. */
1922 : 3601659 : else if (REG_P (reg)
1923 : 3601659 : && REGNO (reg) >= FIRST_PSEUDO_REGISTER
1924 : 3601659 : && paradoxical_subreg_p (operand)
1925 : 1050137 : && (inner_hard_regno = lra_get_regno_hard_regno (REGNO (reg))) >= 0
1926 : 3601659 : && ((hard_regno
1927 : 4561045 : = simplify_subreg_regno (inner_hard_regno, innermode,
1928 : 959386 : SUBREG_BYTE (operand), mode)) < 0
1929 : 959386 : || ((hard_regno_nregs (inner_hard_regno, innermode)
1930 : 959386 : < hard_regno_nregs (hard_regno, mode))
1931 : 10196 : && (regclass = lra_get_allocno_class (REGNO (reg)))
1932 : 5098 : && (type != OP_IN
1933 : 5098 : || !in_hard_reg_set_p (reg_class_contents[regclass],
1934 : : mode, hard_regno)
1935 : 5098 : || overlaps_hard_reg_set_p (lra_no_alloc_regs,
1936 : : mode, hard_regno)))))
1937 : : {
1938 : : /* The class will be defined later in curr_insn_transform. */
1939 : 0 : enum reg_class rclass
1940 : 0 : = (enum reg_class) targetm.preferred_reload_class (reg, ALL_REGS);
1941 : :
1942 : 0 : if (get_reload_reg (curr_static_id->operand[nop].type, mode, reg,
1943 : : rclass, NULL,
1944 : : true, false, "paradoxical subreg", &new_reg))
1945 : : {
1946 : 0 : rtx subreg;
1947 : 0 : bool insert_before, insert_after;
1948 : :
1949 : 0 : PUT_MODE (new_reg, mode);
1950 : 0 : subreg = gen_lowpart_SUBREG (innermode, new_reg);
1951 : 0 : bitmap_set_bit (&lra_subreg_reload_pseudos, REGNO (new_reg));
1952 : :
1953 : 0 : insert_before = (type != OP_OUT);
1954 : 0 : insert_after = (type != OP_IN);
1955 : 0 : insert_move_for_subreg (insert_before ? &before : NULL,
1956 : : insert_after ? &after : NULL,
1957 : : reg, subreg);
1958 : : }
1959 : 0 : SUBREG_REG (operand) = new_reg;
1960 : 0 : lra_process_new_insns (curr_insn, before, after,
1961 : : "Inserting paradoxical subreg reload");
1962 : 0 : return true;
1963 : : }
1964 : : return false;
1965 : : }
1966 : :
1967 : : /* Return TRUE if X refers for a hard register from SET. */
1968 : : static bool
1969 : 409214 : uses_hard_regs_p (rtx x, HARD_REG_SET set)
1970 : : {
1971 : 409214 : int i, j, x_hard_regno;
1972 : 409214 : machine_mode mode;
1973 : 409214 : const char *fmt;
1974 : 409214 : enum rtx_code code;
1975 : :
1976 : 409214 : if (x == NULL_RTX)
1977 : : return false;
1978 : 409214 : code = GET_CODE (x);
1979 : 409214 : mode = GET_MODE (x);
1980 : :
1981 : 409214 : if (code == SUBREG)
1982 : : {
1983 : : /* For all SUBREGs we want to check whether the full multi-register
1984 : : overlaps the set. For normal SUBREGs this means 'get_hard_regno' of
1985 : : the inner register, for paradoxical SUBREGs this means the
1986 : : 'get_hard_regno' of the full SUBREG and for complete SUBREGs either is
1987 : : fine. Use the wider mode for all cases. */
1988 : 2779 : rtx subreg = SUBREG_REG (x);
1989 : 2779 : mode = wider_subreg_mode (x);
1990 : 2779 : if (mode == GET_MODE (subreg))
1991 : : {
1992 : 1747 : x = subreg;
1993 : 1747 : code = GET_CODE (x);
1994 : : }
1995 : : }
1996 : :
1997 : 409214 : if (REG_P (x) || SUBREG_P (x))
1998 : : {
1999 : 264478 : x_hard_regno = get_hard_regno (x);
2000 : 264478 : return (x_hard_regno >= 0
2001 : 264478 : && overlaps_hard_reg_set_p (set, mode, x_hard_regno));
2002 : : }
2003 : 144736 : fmt = GET_RTX_FORMAT (code);
2004 : 374903 : for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
2005 : : {
2006 : 232079 : if (fmt[i] == 'e')
2007 : : {
2008 : 113203 : if (uses_hard_regs_p (XEXP (x, i), set))
2009 : : return true;
2010 : : }
2011 : 118876 : else if (fmt[i] == 'E')
2012 : : {
2013 : 4402 : for (j = XVECLEN (x, i) - 1; j >= 0; j--)
2014 : 3982 : if (uses_hard_regs_p (XVECEXP (x, i, j), set))
2015 : : return true;
2016 : : }
2017 : : }
2018 : : return false;
2019 : : }
2020 : :
2021 : : /* Return true if OP is a spilled pseudo. */
2022 : : static inline bool
2023 : 81681386 : spilled_pseudo_p (rtx op)
2024 : : {
2025 : 81681386 : return (REG_P (op)
2026 : 81681386 : && REGNO (op) >= FIRST_PSEUDO_REGISTER && in_mem_p (REGNO (op)));
2027 : : }
2028 : :
2029 : : /* Return true if X is a general constant. */
2030 : : static inline bool
2031 : 7953043 : general_constant_p (rtx x)
2032 : : {
2033 : 7953043 : return CONSTANT_P (x) && (! flag_pic || LEGITIMATE_PIC_OPERAND_P (x));
2034 : : }
2035 : :
2036 : : static bool
2037 : 25434043 : reg_in_class_p (rtx reg, enum reg_class cl)
2038 : : {
2039 : 25434043 : if (cl == NO_REGS)
2040 : 1122496 : return get_reg_class (REGNO (reg)) == NO_REGS;
2041 : 24311547 : return in_class_p (reg, cl, NULL);
2042 : : }
2043 : :
2044 : : /* Return true if SET of RCLASS contains no hard regs which can be
2045 : : used in MODE. */
2046 : : static bool
2047 : 3868726 : prohibited_class_reg_set_mode_p (enum reg_class rclass,
2048 : : HARD_REG_SET &set,
2049 : : machine_mode mode)
2050 : : {
2051 : 3868726 : HARD_REG_SET temp;
2052 : :
2053 : 7737452 : lra_assert (hard_reg_set_subset_p (reg_class_contents[rclass], set));
2054 : 3868726 : temp = set & ~lra_no_alloc_regs;
2055 : 3868726 : return (hard_reg_set_subset_p
2056 : 3868726 : (temp, ira_prohibited_class_mode_regs[rclass][mode]));
2057 : : }
2058 : :
2059 : :
2060 : : /* Used to check validity info about small class input operands. It
2061 : : should be incremented at start of processing an insn
2062 : : alternative. */
2063 : : static unsigned int curr_small_class_check = 0;
2064 : :
2065 : : /* Update number of used inputs of class OP_CLASS for operand NOP
2066 : : of alternative NALT. Return true if we have more such class operands
2067 : : than the number of available regs. */
2068 : : static bool
2069 : 399548468 : update_and_check_small_class_inputs (int nop, int nalt,
2070 : : enum reg_class op_class)
2071 : : {
2072 : 399548468 : static unsigned int small_class_check[LIM_REG_CLASSES];
2073 : 399548468 : static int small_class_input_nums[LIM_REG_CLASSES];
2074 : :
2075 : 396654677 : if (SMALL_REGISTER_CLASS_P (op_class)
2076 : : /* We are interesting in classes became small because of fixing
2077 : : some hard regs, e.g. by an user through GCC options. */
2078 : 3001986 : && hard_reg_set_intersect_p (reg_class_contents[op_class],
2079 : 3001986 : ira_no_alloc_regs)
2080 : 399548507 : && (curr_static_id->operand[nop].type != OP_OUT
2081 : 33 : || TEST_BIT (curr_static_id->operand[nop].early_clobber_alts, nalt)))
2082 : : {
2083 : 6 : if (small_class_check[op_class] == curr_small_class_check)
2084 : 0 : small_class_input_nums[op_class]++;
2085 : : else
2086 : : {
2087 : 6 : small_class_check[op_class] = curr_small_class_check;
2088 : 6 : small_class_input_nums[op_class] = 1;
2089 : : }
2090 : 6 : if (small_class_input_nums[op_class] > ira_class_hard_regs_num[op_class])
2091 : : return true;
2092 : : }
2093 : : return false;
2094 : : }
2095 : :
2096 : : /* Print operand constraints for alternative ALT_NUMBER of the current
2097 : : insn. */
2098 : : static void
2099 : 4604 : print_curr_insn_alt (int alt_number)
2100 : : {
2101 : 15963 : for (int i = 0; i < curr_static_id->n_operands; i++)
2102 : : {
2103 : 11359 : const char *p = (curr_static_id->operand_alternative
2104 : 11359 : [alt_number * curr_static_id->n_operands + i].constraint);
2105 : 11359 : if (*p == '\0')
2106 : 216 : continue;
2107 : 11143 : fprintf (lra_dump_file, " (%d) ", i);
2108 : 39570 : for (; *p != '\0' && *p != ',' && *p != '#'; p++)
2109 : 17284 : fputc (*p, lra_dump_file);
2110 : : }
2111 : 4604 : }
2112 : :
2113 : : /* Major function to choose the current insn alternative and what
2114 : : operands should be reloaded and how. If ONLY_ALTERNATIVE is not
2115 : : negative we should consider only this alternative. Return false if
2116 : : we cannot choose the alternative or find how to reload the
2117 : : operands. */
2118 : : static bool
2119 : 90792942 : process_alt_operands (int only_alternative)
2120 : : {
2121 : 90792942 : bool ok_p = false;
2122 : 90792942 : int nop, overall, nalt;
2123 : 90792942 : int n_alternatives = curr_static_id->n_alternatives;
2124 : 90792942 : int n_operands = curr_static_id->n_operands;
2125 : : /* LOSERS counts the operands that don't fit this alternative and
2126 : : would require loading. */
2127 : 90792942 : int losers;
2128 : 90792942 : int addr_losers;
2129 : : /* REJECT is a count of how undesirable this alternative says it is
2130 : : if any reloading is required. If the alternative matches exactly
2131 : : then REJECT is ignored, but otherwise it gets this much counted
2132 : : against it in addition to the reloading needed. */
2133 : 90792942 : int reject;
2134 : : /* This is defined by '!' or '?' alternative constraint and added to
2135 : : reject. But in some cases it can be ignored. */
2136 : 90792942 : int static_reject;
2137 : 90792942 : int op_reject;
2138 : : /* The number of elements in the following array. */
2139 : 90792942 : int early_clobbered_regs_num;
2140 : : /* Numbers of operands which are early clobber registers. */
2141 : 90792942 : int early_clobbered_nops[MAX_RECOG_OPERANDS];
2142 : 90792942 : enum reg_class curr_alt[MAX_RECOG_OPERANDS];
2143 : 90792942 : enum reg_class all_this_alternative;
2144 : 90792942 : int all_used_nregs, all_reload_nregs;
2145 : 90792942 : HARD_REG_SET curr_alt_set[MAX_RECOG_OPERANDS];
2146 : 90792942 : HARD_REG_SET curr_alt_exclude_start_hard_regs[MAX_RECOG_OPERANDS];
2147 : 90792942 : bool curr_alt_match_win[MAX_RECOG_OPERANDS];
2148 : 90792942 : bool curr_alt_win[MAX_RECOG_OPERANDS];
2149 : 90792942 : bool curr_alt_offmemok[MAX_RECOG_OPERANDS];
2150 : 90792942 : int curr_alt_matches[MAX_RECOG_OPERANDS];
2151 : : /* The number of elements in the following array. */
2152 : 90792942 : int curr_alt_dont_inherit_ops_num;
2153 : : /* Numbers of operands whose reload pseudos should not be inherited. */
2154 : 90792942 : int curr_alt_dont_inherit_ops[MAX_RECOG_OPERANDS];
2155 : 90792942 : bool curr_reuse_alt_p;
2156 : : /* True if output stack pointer reload should be generated for the current
2157 : : alternative. */
2158 : 90792942 : bool curr_alt_out_sp_reload_p;
2159 : 90792942 : bool curr_alt_class_change_p;
2160 : 90792942 : rtx op;
2161 : : /* The register when the operand is a subreg of register, otherwise the
2162 : : operand itself. */
2163 : 90792942 : rtx no_subreg_reg_operand[MAX_RECOG_OPERANDS];
2164 : : /* The register if the operand is a register or subreg of register,
2165 : : otherwise NULL. */
2166 : 90792942 : rtx operand_reg[MAX_RECOG_OPERANDS];
2167 : 90792942 : int hard_regno[MAX_RECOG_OPERANDS];
2168 : 90792942 : machine_mode biggest_mode[MAX_RECOG_OPERANDS];
2169 : 90792942 : int reload_nregs, reload_sum;
2170 : 90792942 : bool costly_p;
2171 : 90792942 : enum reg_class cl;
2172 : 90792942 : const HARD_REG_SET *cl_filter;
2173 : 90792942 : HARD_REG_SET hard_reg_constraint;
2174 : :
2175 : : /* Calculate some data common for all alternatives to speed up the
2176 : : function. */
2177 : 301664601 : for (nop = 0; nop < n_operands; nop++)
2178 : : {
2179 : 210871659 : rtx reg;
2180 : :
2181 : 210871659 : op = no_subreg_reg_operand[nop] = *curr_id->operand_loc[nop];
2182 : : /* The real hard regno of the operand after the allocation. */
2183 : 210871659 : hard_regno[nop] = get_hard_regno (op);
2184 : :
2185 : 210871659 : operand_reg[nop] = reg = op;
2186 : 210871659 : biggest_mode[nop] = GET_MODE (op);
2187 : 210871659 : if (GET_CODE (op) == SUBREG)
2188 : : {
2189 : 4148725 : biggest_mode[nop] = wider_subreg_mode (op);
2190 : 4148725 : operand_reg[nop] = reg = SUBREG_REG (op);
2191 : : }
2192 : 210871659 : if (! REG_P (reg))
2193 : 89200762 : operand_reg[nop] = NULL_RTX;
2194 : 121670897 : else if (REGNO (reg) >= FIRST_PSEUDO_REGISTER
2195 : 142778271 : || ((int) REGNO (reg)
2196 : 21107374 : == lra_get_elimination_hard_regno (REGNO (reg))))
2197 : 118670853 : no_subreg_reg_operand[nop] = reg;
2198 : : else
2199 : 3000044 : operand_reg[nop] = no_subreg_reg_operand[nop]
2200 : : /* Just use natural mode for elimination result. It should
2201 : : be enough for extra constraints hooks. */
2202 : 3000044 : = regno_reg_rtx[hard_regno[nop]];
2203 : : }
2204 : :
2205 : : /* The constraints are made of several alternatives. Each operand's
2206 : : constraint looks like foo,bar,... with commas separating the
2207 : : alternatives. The first alternatives for all operands go
2208 : : together, the second alternatives go together, etc.
2209 : :
2210 : : First loop over alternatives. */
2211 : 90792942 : alternative_mask preferred = curr_id->preferred_alternatives;
2212 : 90792942 : if (only_alternative >= 0)
2213 : 1023019 : preferred &= ALTERNATIVE_BIT (only_alternative);
2214 : :
2215 : 374443057 : for (nalt = 0; nalt < n_alternatives; nalt++)
2216 : : {
2217 : : /* Loop over operands for one constraint alternative. */
2218 : 360564267 : if (!TEST_BIT (preferred, nalt))
2219 : 99491339 : continue;
2220 : :
2221 : 261072928 : if (lra_dump_file != NULL)
2222 : : {
2223 : 3408 : fprintf (lra_dump_file, " Considering alt=%d of insn %d: ",
2224 : 3408 : nalt, INSN_UID (curr_insn));
2225 : 3408 : print_curr_insn_alt (nalt);
2226 : 3408 : fprintf (lra_dump_file, "\n");
2227 : : }
2228 : :
2229 : 261072928 : bool matching_early_clobber[MAX_RECOG_OPERANDS];
2230 : 261072928 : curr_small_class_check++;
2231 : 261072928 : overall = losers = addr_losers = 0;
2232 : 261072928 : static_reject = reject = reload_nregs = reload_sum = 0;
2233 : 865101779 : for (nop = 0; nop < n_operands; nop++)
2234 : : {
2235 : 604028851 : int inc = (curr_static_id
2236 : 604028851 : ->operand_alternative[nalt * n_operands + nop].reject);
2237 : 604028851 : if (lra_dump_file != NULL && inc != 0)
2238 : 53 : fprintf (lra_dump_file,
2239 : : " Staticly defined alt reject+=%d\n", inc);
2240 : 604028851 : static_reject += inc;
2241 : 604028851 : matching_early_clobber[nop] = 0;
2242 : : }
2243 : : reject += static_reject;
2244 : : early_clobbered_regs_num = 0;
2245 : : curr_alt_out_sp_reload_p = false;
2246 : : curr_reuse_alt_p = true;
2247 : : curr_alt_class_change_p = false;
2248 : : all_this_alternative = NO_REGS;
2249 : : all_used_nregs = all_reload_nregs = 0;
2250 : 675236414 : for (nop = 0; nop < n_operands; nop++)
2251 : : {
2252 : 538279493 : const char *p;
2253 : 538279493 : char *end;
2254 : 538279493 : int len, c, m, i, opalt_num, this_alternative_matches;
2255 : 538279493 : bool win, did_match, offmemok, early_clobber_p;
2256 : : /* false => this operand can be reloaded somehow for this
2257 : : alternative. */
2258 : 538279493 : bool badop;
2259 : : /* true => this operand can be reloaded if the alternative
2260 : : allows regs. */
2261 : 538279493 : bool winreg;
2262 : : /* True if a constant forced into memory would be OK for
2263 : : this operand. */
2264 : 538279493 : bool constmemok;
2265 : 538279493 : enum reg_class this_alternative, this_costly_alternative;
2266 : 538279493 : HARD_REG_SET this_alternative_set, this_costly_alternative_set;
2267 : 538279493 : HARD_REG_SET this_alternative_exclude_start_hard_regs;
2268 : 538279493 : bool this_alternative_match_win, this_alternative_win;
2269 : 538279493 : bool this_alternative_offmemok;
2270 : 538279493 : bool scratch_p;
2271 : 538279493 : machine_mode mode;
2272 : 538279493 : enum constraint_num cn;
2273 : 538279493 : bool class_change_p = false;
2274 : :
2275 : 538279493 : opalt_num = nalt * n_operands + nop;
2276 : 538279493 : if (curr_static_id->operand_alternative[opalt_num].anything_ok)
2277 : : {
2278 : : /* Fast track for no constraints at all. */
2279 : 14615018 : curr_alt[nop] = NO_REGS;
2280 : 14615018 : CLEAR_HARD_REG_SET (curr_alt_set[nop]);
2281 : 14615018 : curr_alt_win[nop] = true;
2282 : 14615018 : curr_alt_match_win[nop] = false;
2283 : 14615018 : curr_alt_offmemok[nop] = false;
2284 : 14615018 : curr_alt_matches[nop] = -1;
2285 : 14615018 : continue;
2286 : : }
2287 : :
2288 : 523664475 : op = no_subreg_reg_operand[nop];
2289 : 523664475 : mode = curr_operand_mode[nop];
2290 : :
2291 : 523664475 : win = did_match = winreg = offmemok = constmemok = false;
2292 : 523664475 : badop = true;
2293 : :
2294 : 523664475 : early_clobber_p = false;
2295 : 523664475 : p = curr_static_id->operand_alternative[opalt_num].constraint;
2296 : :
2297 : 523664475 : this_costly_alternative = this_alternative = NO_REGS;
2298 : : /* We update set of possible hard regs besides its class
2299 : : because reg class might be inaccurate. For example,
2300 : : union of LO_REGS (l), HI_REGS(h), and STACK_REG(k) in ARM
2301 : : is translated in HI_REGS because classes are merged by
2302 : : pairs and there is no accurate intermediate class. */
2303 : 2094657900 : CLEAR_HARD_REG_SET (this_alternative_set);
2304 : 1570993425 : CLEAR_HARD_REG_SET (this_costly_alternative_set);
2305 : 523664475 : CLEAR_HARD_REG_SET (this_alternative_exclude_start_hard_regs);
2306 : 523664475 : this_alternative_win = false;
2307 : 523664475 : this_alternative_match_win = false;
2308 : 523664475 : this_alternative_offmemok = false;
2309 : 523664475 : this_alternative_matches = -1;
2310 : :
2311 : : /* An empty constraint should be excluded by the fast
2312 : : track. */
2313 : 523664475 : lra_assert (*p != 0 && *p != ',');
2314 : :
2315 : : op_reject = 0;
2316 : : /* Scan this alternative's specs for this operand; set WIN
2317 : : if the operand fits any letter in this alternative.
2318 : : Otherwise, clear BADOP if this operand could fit some
2319 : : letter after reloads, or set WINREG if this operand could
2320 : : fit after reloads provided the constraint allows some
2321 : : registers. */
2322 : : costly_p = false;
2323 : 1329564526 : do
2324 : : {
2325 : 1329564526 : switch ((c = *p, len = CONSTRAINT_LEN (c, p)), c)
2326 : : {
2327 : : case '\0':
2328 : : len = 0;
2329 : : break;
2330 : 500485823 : case ',':
2331 : 500485823 : c = '\0';
2332 : 500485823 : break;
2333 : :
2334 : 176793 : case '&':
2335 : 176793 : early_clobber_p = true;
2336 : 176793 : break;
2337 : :
2338 : 23149 : case '$':
2339 : 23149 : op_reject += LRA_MAX_REJECT;
2340 : 23149 : break;
2341 : 0 : case '^':
2342 : 0 : op_reject += LRA_LOSER_COST_FACTOR;
2343 : 0 : break;
2344 : :
2345 : 0 : case '#':
2346 : : /* Ignore rest of this alternative. */
2347 : 0 : c = '\0';
2348 : 0 : break;
2349 : :
2350 : 56712122 : case '0': case '1': case '2': case '3': case '4':
2351 : 56712122 : case '5': case '6': case '7': case '8': case '9':
2352 : 56712122 : {
2353 : 56712122 : int m_hregno;
2354 : 56712122 : bool match_p;
2355 : :
2356 : 56712122 : m = strtoul (p, &end, 10);
2357 : 56712122 : p = end;
2358 : 56712122 : len = 0;
2359 : 56712122 : lra_assert (nop > m);
2360 : :
2361 : : /* Reject matches if we don't know which operand is
2362 : : bigger. This situation would arguably be a bug in
2363 : : an .md pattern, but could also occur in a user asm. */
2364 : 170136366 : if (!ordered_p (GET_MODE_SIZE (biggest_mode[m]),
2365 : 56712122 : GET_MODE_SIZE (biggest_mode[nop])))
2366 : : break;
2367 : :
2368 : : /* Don't match wrong asm insn operands for proper
2369 : : diagnostic later. */
2370 : 56712122 : if (INSN_CODE (curr_insn) < 0
2371 : 31976 : && (curr_operand_mode[m] == BLKmode
2372 : 31975 : || curr_operand_mode[nop] == BLKmode)
2373 : 1 : && curr_operand_mode[m] != curr_operand_mode[nop])
2374 : : break;
2375 : :
2376 : 56712121 : m_hregno = get_hard_regno (*curr_id->operand_loc[m]);
2377 : : /* We are supposed to match a previous operand.
2378 : : If we do, we win if that one did. If we do
2379 : : not, count both of the operands as losers.
2380 : : (This is too conservative, since most of the
2381 : : time only a single reload insn will be needed
2382 : : to make the two operands win. As a result,
2383 : : this alternative may be rejected when it is
2384 : : actually desirable.) */
2385 : 56712121 : match_p = false;
2386 : 56712121 : if (operands_match_p (*curr_id->operand_loc[nop],
2387 : 56712121 : *curr_id->operand_loc[m], m_hregno))
2388 : : {
2389 : : /* We should reject matching of an early
2390 : : clobber operand if the matching operand is
2391 : : not dying in the insn. */
2392 : 14867681 : if (!TEST_BIT (curr_static_id->operand[m]
2393 : : .early_clobber_alts, nalt)
2394 : 19485 : || operand_reg[nop] == NULL_RTX
2395 : 14887166 : || (find_regno_note (curr_insn, REG_DEAD,
2396 : : REGNO (op))
2397 : 4976 : || REGNO (op) == REGNO (operand_reg[m])))
2398 : 14867681 : match_p = true;
2399 : : }
2400 : 14867681 : if (match_p)
2401 : : {
2402 : : /* If we are matching a non-offsettable
2403 : : address where an offsettable address was
2404 : : expected, then we must reject this
2405 : : combination, because we can't reload
2406 : : it. */
2407 : 14867681 : if (curr_alt_offmemok[m]
2408 : 1367 : && MEM_P (*curr_id->operand_loc[m])
2409 : 0 : && curr_alt[m] == NO_REGS && ! curr_alt_win[m])
2410 : 0 : continue;
2411 : : }
2412 : : else
2413 : : {
2414 : : /* If the operands do not match and one
2415 : : operand is INOUT, we can not match them.
2416 : : Try other possibilities, e.g. other
2417 : : alternatives or commutative operand
2418 : : exchange. */
2419 : 41844440 : if (curr_static_id->operand[nop].type == OP_INOUT
2420 : 41844440 : || curr_static_id->operand[m].type == OP_INOUT)
2421 : : break;
2422 : : /* Operands don't match. For asm if the operands
2423 : : are different user defined explicit hard
2424 : : registers, then we cannot make them match
2425 : : when one is early clobber operand. */
2426 : 41843909 : if ((REG_P (*curr_id->operand_loc[nop])
2427 : 26265280 : || SUBREG_P (*curr_id->operand_loc[nop]))
2428 : 16205223 : && (REG_P (*curr_id->operand_loc[m])
2429 : 207637 : || SUBREG_P (*curr_id->operand_loc[m]))
2430 : 16103415 : && INSN_CODE (curr_insn) < 0)
2431 : : {
2432 : 536 : rtx nop_reg = *curr_id->operand_loc[nop];
2433 : 536 : if (SUBREG_P (nop_reg))
2434 : 0 : nop_reg = SUBREG_REG (nop_reg);
2435 : 536 : rtx m_reg = *curr_id->operand_loc[m];
2436 : 536 : if (SUBREG_P (m_reg))
2437 : 0 : m_reg = SUBREG_REG (m_reg);
2438 : :
2439 : 536 : if (REG_P (nop_reg)
2440 : 536 : && HARD_REGISTER_P (nop_reg)
2441 : 0 : && REG_USERVAR_P (nop_reg)
2442 : 0 : && REG_P (m_reg)
2443 : 0 : && HARD_REGISTER_P (m_reg)
2444 : 536 : && REG_USERVAR_P (m_reg))
2445 : : {
2446 : : int i;
2447 : :
2448 : 0 : for (i = 0; i < early_clobbered_regs_num; i++)
2449 : 0 : if (m == early_clobbered_nops[i])
2450 : : break;
2451 : 0 : if (i < early_clobbered_regs_num
2452 : 0 : || early_clobber_p)
2453 : : break;
2454 : : }
2455 : : }
2456 : : /* Both operands must allow a reload register,
2457 : : otherwise we cannot make them match. */
2458 : 41843909 : if (curr_alt[m] == NO_REGS)
2459 : : break;
2460 : : /* Retroactively mark the operand we had to
2461 : : match as a loser, if it wasn't already and
2462 : : it wasn't matched to a register constraint
2463 : : (e.g it might be matched by memory). */
2464 : 41819841 : if (curr_alt_win[m]
2465 : 40973116 : && (operand_reg[m] == NULL_RTX
2466 : 40469676 : || hard_regno[m] < 0))
2467 : : {
2468 : 1273635 : if (lra_dump_file != NULL)
2469 : 9 : fprintf
2470 : 9 : (lra_dump_file,
2471 : : " %d Matched operand reload: "
2472 : : "losers++\n", m);
2473 : 1273635 : losers++;
2474 : 1273635 : reload_nregs
2475 : 1273635 : += (ira_reg_class_max_nregs[curr_alt[m]]
2476 : 1273635 : [GET_MODE (*curr_id->operand_loc[m])]);
2477 : : }
2478 : :
2479 : : /* Prefer matching earlyclobber alternative as
2480 : : it results in less hard regs required for
2481 : : the insn than a non-matching earlyclobber
2482 : : alternative. */
2483 : 41819841 : if (TEST_BIT (curr_static_id->operand[m]
2484 : : .early_clobber_alts, nalt))
2485 : : {
2486 : 18510 : if (lra_dump_file != NULL)
2487 : 0 : fprintf
2488 : 0 : (lra_dump_file,
2489 : : " %d Matching earlyclobber alt:"
2490 : : " reject--\n",
2491 : : nop);
2492 : 18510 : if (!matching_early_clobber[m])
2493 : : {
2494 : 18510 : reject--;
2495 : 18510 : matching_early_clobber[m] = 1;
2496 : : }
2497 : : }
2498 : : /* Otherwise we prefer no matching
2499 : : alternatives because it gives more freedom
2500 : : in RA. */
2501 : 41801331 : else if (operand_reg[nop] == NULL_RTX
2502 : 41801331 : || (find_regno_note (curr_insn, REG_DEAD,
2503 : 16178490 : REGNO (operand_reg[nop]))
2504 : : == NULL_RTX))
2505 : : {
2506 : 36866168 : if (lra_dump_file != NULL)
2507 : 908 : fprintf
2508 : 908 : (lra_dump_file,
2509 : : " %d Matching alt: reject+=2\n",
2510 : : nop);
2511 : 36866168 : reject += 2;
2512 : : }
2513 : : }
2514 : : /* If we have to reload this operand and some
2515 : : previous operand also had to match the same
2516 : : thing as this operand, we don't know how to do
2517 : : that. */
2518 : 56687522 : if (!match_p || !curr_alt_win[m])
2519 : : {
2520 : 87828808 : for (i = 0; i < nop; i++)
2521 : 45902601 : if (curr_alt_matches[i] == m)
2522 : : break;
2523 : 41926208 : if (i < nop)
2524 : : break;
2525 : : }
2526 : : else
2527 : : did_match = true;
2528 : :
2529 : 56687521 : this_alternative_matches = m;
2530 : : /* This can be fixed with reloads if the operand
2531 : : we are supposed to match can be fixed with
2532 : : reloads. */
2533 : 56687521 : badop = false;
2534 : 56687521 : this_alternative = curr_alt[m];
2535 : 56687521 : this_alternative_set = curr_alt_set[m];
2536 : 56687521 : this_alternative_exclude_start_hard_regs
2537 : 56687521 : = curr_alt_exclude_start_hard_regs[m];
2538 : 56687521 : winreg = this_alternative != NO_REGS;
2539 : 56687521 : break;
2540 : : }
2541 : :
2542 : 11856851 : case 'g':
2543 : 11856851 : if (MEM_P (op)
2544 : 7953043 : || general_constant_p (op)
2545 : 16456272 : || spilled_pseudo_p (op))
2546 : : win = true;
2547 : 11856851 : cl = GENERAL_REGS;
2548 : 11856851 : cl_filter = nullptr;
2549 : 11856851 : goto reg;
2550 : :
2551 : 2403 : case '{':
2552 : 2403 : {
2553 : 2403 : int regno = decode_hard_reg_constraint (p);
2554 : 2403 : gcc_assert (regno >= 0);
2555 : 2403 : cl = NO_REGS;
2556 : 2403 : int nregs = hard_regno_nregs (regno, mode);
2557 : 4806 : for (int i = 0; i < nregs; ++i)
2558 : 2403 : cl = reg_class_superunion[cl][REGNO_REG_CLASS (regno + i)];
2559 : 2403 : CLEAR_HARD_REG_SET (hard_reg_constraint);
2560 : 2403 : SET_HARD_REG_BIT (hard_reg_constraint, regno);
2561 : 2403 : cl_filter = &hard_reg_constraint;
2562 : 2403 : goto reg;
2563 : : }
2564 : :
2565 : 737128733 : default:
2566 : 737128733 : cn = lookup_constraint (p);
2567 : 737128733 : switch (get_constraint_type (cn))
2568 : : {
2569 : 488701149 : case CT_REGISTER:
2570 : 488701149 : cl = reg_class_for_constraint (cn);
2571 : 359355362 : if (cl != NO_REGS)
2572 : : {
2573 : 349642232 : cl_filter = get_register_filter (cn);
2574 : 349642232 : goto reg;
2575 : : }
2576 : : break;
2577 : :
2578 : 2071061 : case CT_CONST_INT:
2579 : 2071061 : if (CONST_INT_P (op)
2580 : 2071061 : && insn_const_int_ok_for_constraint (INTVAL (op), cn))
2581 : : win = true;
2582 : : break;
2583 : :
2584 : 112030150 : case CT_MEMORY:
2585 : 112030150 : case CT_RELAXED_MEMORY:
2586 : 112030150 : if (MEM_P (op)
2587 : 112030150 : && satisfies_memory_constraint_p (op, cn))
2588 : : win = true;
2589 : 76053856 : else if (spilled_pseudo_p (op))
2590 : 45541391 : win = true;
2591 : :
2592 : : /* If we didn't already win, we can reload constants
2593 : : via force_const_mem or put the pseudo value into
2594 : : memory, or make other memory by reloading the
2595 : : address like for 'o'. */
2596 : 117216376 : if (CONST_POOL_OK_P (mode, op)
2597 : 106843764 : || MEM_P (op) || REG_P (op)
2598 : : /* We can restore the equiv insn by a
2599 : : reload. */
2600 : 112649779 : || equiv_substition_p[nop])
2601 : 111994367 : badop = false;
2602 : : constmemok = true;
2603 : : offmemok = true;
2604 : : break;
2605 : :
2606 : 1771200 : case CT_ADDRESS:
2607 : : /* An asm operand with an address constraint
2608 : : that doesn't satisfy address_operand has
2609 : : is_address cleared, so that we don't try to
2610 : : make a non-address fit. */
2611 : 1771200 : if (!curr_static_id->operand[nop].is_address)
2612 : : break;
2613 : : /* If we didn't already win, we can reload the address
2614 : : into a base register. */
2615 : 1771181 : if (satisfies_address_constraint_p (op, cn))
2616 : 1771181 : win = true;
2617 : 1771181 : cl = base_reg_class (VOIDmode, ADDR_SPACE_GENERIC,
2618 : : ADDRESS, SCRATCH);
2619 : 1771181 : cl_filter = nullptr;
2620 : 1771181 : badop = false;
2621 : 1771181 : goto reg;
2622 : :
2623 : 131349841 : case CT_FIXED_FORM:
2624 : 131349841 : if (constraint_satisfied_p (op, cn))
2625 : 1329564526 : win = true;
2626 : : break;
2627 : :
2628 : 1205332 : case CT_SPECIAL_MEMORY:
2629 : 1205332 : if (satisfies_memory_constraint_p (op, cn))
2630 : : win = true;
2631 : 1028109 : else if (spilled_pseudo_p (op))
2632 : : {
2633 : 1329564526 : curr_reuse_alt_p = false;
2634 : 1329564526 : win = true;
2635 : : }
2636 : : break;
2637 : : }
2638 : : break;
2639 : :
2640 : 363272667 : reg:
2641 : 363272667 : if (mode == BLKmode)
2642 : : break;
2643 : 363272649 : this_alternative = reg_class_subunion[this_alternative][cl];
2644 : 363272649 : if (hard_reg_set_subset_p (this_alternative_set,
2645 : 363272649 : reg_class_contents[cl]))
2646 : 363269006 : this_alternative_exclude_start_hard_regs
2647 : 363269006 : = ira_exclude_class_mode_regs[cl][mode];
2648 : 3643 : else if (!hard_reg_set_subset_p (reg_class_contents[cl],
2649 : : this_alternative_set))
2650 : 3642 : this_alternative_exclude_start_hard_regs
2651 : 1089821589 : |= ira_exclude_class_mode_regs[cl][mode];
2652 : 363272649 : this_alternative_set |= reg_class_contents[cl];
2653 : 363272649 : if (cl_filter)
2654 : 4806 : this_alternative_exclude_start_hard_regs |= ~*cl_filter;
2655 : 363272649 : if (costly_p)
2656 : : {
2657 : 21775999 : this_costly_alternative
2658 : 21775999 : = reg_class_subunion[this_costly_alternative][cl];
2659 : 21775999 : this_costly_alternative_set |= reg_class_contents[cl];
2660 : : }
2661 : 363272649 : winreg = true;
2662 : 363272649 : if (REG_P (op))
2663 : : {
2664 : 231227826 : tree decl;
2665 : 231227826 : if (hard_regno[nop] >= 0
2666 : 194878538 : && in_hard_reg_set_p (this_alternative_set,
2667 : : mode, hard_regno[nop])
2668 : 176043915 : && (!cl_filter
2669 : 1268 : || TEST_HARD_REG_BIT (*cl_filter,
2670 : : hard_regno[nop]))
2671 : 407271735 : && ((REG_ATTRS (op) && (decl = REG_EXPR (op)) != NULL
2672 : 98272394 : && VAR_P (decl) && DECL_HARD_REGISTER (decl))
2673 : 176040652 : || !(TEST_HARD_REG_BIT
2674 : 176040652 : (this_alternative_exclude_start_hard_regs,
2675 : : hard_regno[nop]))))
2676 : : win = true;
2677 : 55183921 : else if (hard_regno[nop] < 0)
2678 : : {
2679 : 36349288 : if (in_class_p (op, this_alternative, NULL))
2680 : : win = true;
2681 : 27324970 : else if (in_class_p (op, this_alternative, NULL, true))
2682 : : {
2683 : 1329564526 : class_change_p = true;
2684 : 1329564526 : win = true;
2685 : : }
2686 : : }
2687 : : }
2688 : : break;
2689 : : }
2690 : 1329564526 : if (c != ' ' && c != '\t')
2691 : 1329564526 : costly_p = c == '*';
2692 : : }
2693 : 1329564526 : while ((p += len), c);
2694 : :
2695 : 1047328950 : scratch_p = (operand_reg[nop] != NULL_RTX
2696 : 523664475 : && ira_former_scratch_p (REGNO (operand_reg[nop])));
2697 : : /* Record which operands fit this alternative. */
2698 : 523664475 : if (win)
2699 : : {
2700 : 281596988 : if (early_clobber_p
2701 : 281453991 : || curr_static_id->operand[nop].type != OP_OUT)
2702 : : {
2703 : 123110279 : if (winreg)
2704 : 101644232 : all_used_nregs
2705 : 101644232 : += ira_reg_class_min_nregs[this_alternative][mode];
2706 : 123110279 : all_this_alternative
2707 : 123110279 : = (reg_class_subunion
2708 : 123110279 : [all_this_alternative][this_alternative]);
2709 : : }
2710 : 281596988 : this_alternative_win = true;
2711 : 281596988 : if (class_change_p)
2712 : : {
2713 : 296249 : curr_alt_class_change_p = true;
2714 : 296249 : if (lra_dump_file != NULL)
2715 : 8 : fprintf (lra_dump_file,
2716 : : " %d Narrowing class: reject+=3\n",
2717 : : nop);
2718 : 296249 : reject += 3;
2719 : : }
2720 : 281596988 : if (operand_reg[nop] != NULL_RTX)
2721 : : {
2722 : 196362665 : if (hard_regno[nop] >= 0)
2723 : : {
2724 : 175988088 : if (in_hard_reg_set_p (this_costly_alternative_set,
2725 : : mode, hard_regno[nop]))
2726 : : {
2727 : 783322 : if (lra_dump_file != NULL)
2728 : 21 : fprintf (lra_dump_file,
2729 : : " %d Costly set: reject++\n",
2730 : : nop);
2731 : 783322 : reject++;
2732 : : }
2733 : : }
2734 : : else
2735 : : {
2736 : : /* Prefer won reg to spilled pseudo under other
2737 : : equal conditions for possibe inheritance. */
2738 : 20374577 : if (! scratch_p)
2739 : : {
2740 : 20370011 : if (lra_dump_file != NULL)
2741 : 56 : fprintf
2742 : 56 : (lra_dump_file,
2743 : : " %d Non pseudo reload: reject++\n",
2744 : : nop);
2745 : 20370011 : reject++;
2746 : : }
2747 : 20374577 : if (in_class_p (operand_reg[nop],
2748 : : this_costly_alternative, NULL, true))
2749 : : {
2750 : 133926 : if (lra_dump_file != NULL)
2751 : 0 : fprintf
2752 : 0 : (lra_dump_file,
2753 : : " %d Non pseudo costly reload:"
2754 : : " reject++\n",
2755 : : nop);
2756 : 133926 : reject++;
2757 : : }
2758 : : }
2759 : : /* We simulate the behavior of old reload here.
2760 : : Although scratches need hard registers and it
2761 : : might result in spilling other pseudos, no reload
2762 : : insns are generated for the scratches. So it
2763 : : might cost something but probably less than old
2764 : : reload pass believes. */
2765 : 196362665 : if (scratch_p)
2766 : : {
2767 : 122062 : if (lra_dump_file != NULL)
2768 : 6 : fprintf (lra_dump_file,
2769 : : " %d Scratch win: reject+=2\n",
2770 : : nop);
2771 : 122062 : reject += 2;
2772 : : }
2773 : : }
2774 : : }
2775 : 242067487 : else if (did_match)
2776 : : this_alternative_match_win = true;
2777 : : else
2778 : : {
2779 : 227306173 : int const_to_mem = 0;
2780 : 227306173 : bool no_regs_p;
2781 : :
2782 : 227306173 : reject += op_reject;
2783 : : /* Mark output reload of the stack pointer. */
2784 : 227306173 : if (op == stack_pointer_rtx
2785 : 57432 : && curr_static_id->operand[nop].type != OP_IN)
2786 : 227306173 : curr_alt_out_sp_reload_p = true;
2787 : :
2788 : : /* If this alternative asks for a specific reg class, see if there
2789 : : is at least one allocatable register in that class. */
2790 : 227306173 : no_regs_p
2791 : 396494764 : = (this_alternative == NO_REGS
2792 : 227306173 : || (hard_reg_set_subset_p
2793 : 338377204 : (reg_class_contents[this_alternative],
2794 : : lra_no_alloc_regs)));
2795 : :
2796 : : /* For asms, verify that the class for this alternative is possible
2797 : : for the mode that is specified. */
2798 : 169188591 : if (!no_regs_p && INSN_CODE (curr_insn) < 0)
2799 : : {
2800 : : int i;
2801 : 69789 : for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
2802 : 69787 : if (targetm.hard_regno_mode_ok (i, mode)
2803 : 69787 : && in_hard_reg_set_p (reg_class_contents[this_alternative],
2804 : : mode, i))
2805 : : break;
2806 : 20995 : if (i == FIRST_PSEUDO_REGISTER)
2807 : 227306173 : winreg = false;
2808 : : }
2809 : :
2810 : : /* If this operand accepts a register, and if the
2811 : : register class has at least one allocatable register,
2812 : : then this operand can be reloaded. */
2813 : 227306173 : if (winreg && !no_regs_p)
2814 : : badop = false;
2815 : :
2816 : 58117584 : if (badop)
2817 : : {
2818 : 48385079 : if (lra_dump_file != NULL)
2819 : 606 : fprintf (lra_dump_file,
2820 : : " Bad operand -- refuse\n");
2821 : 124116007 : goto fail;
2822 : : }
2823 : :
2824 : 178921094 : if (this_alternative != NO_REGS)
2825 : : {
2826 : 169188590 : HARD_REG_SET available_regs
2827 : 169188590 : = (reg_class_contents[this_alternative]
2828 : 169188590 : & ~((ira_prohibited_class_mode_regs
2829 : 169188590 : [this_alternative][mode])
2830 : 169188590 : | lra_no_alloc_regs));
2831 : 338377180 : if (!hard_reg_set_empty_p (available_regs))
2832 : : {
2833 : 169187178 : if (early_clobber_p
2834 : 169153382 : || curr_static_id->operand[nop].type != OP_OUT)
2835 : : {
2836 : 88579260 : all_reload_nregs
2837 : 88579260 : += ira_reg_class_min_nregs[this_alternative][mode];
2838 : 88579260 : all_this_alternative
2839 : 88579260 : = (reg_class_subunion
2840 : 88579260 : [all_this_alternative][this_alternative]);
2841 : : }
2842 : : }
2843 : : else
2844 : : {
2845 : : /* There are no hard regs holding a value of given
2846 : : mode. */
2847 : 1412 : if (offmemok)
2848 : : {
2849 : 180 : this_alternative = NO_REGS;
2850 : 180 : if (lra_dump_file != NULL)
2851 : 0 : fprintf (lra_dump_file,
2852 : : " %d Using memory because of"
2853 : : " a bad mode: reject+=2\n",
2854 : : nop);
2855 : 180 : reject += 2;
2856 : : }
2857 : : else
2858 : : {
2859 : 1232 : if (lra_dump_file != NULL)
2860 : 0 : fprintf (lra_dump_file,
2861 : : " Wrong mode -- refuse\n");
2862 : 1232 : goto fail;
2863 : : }
2864 : : }
2865 : : }
2866 : :
2867 : : /* If not assigned pseudo has a class which a subset of
2868 : : required reg class, it is a less costly alternative
2869 : : as the pseudo still can get a hard reg of necessary
2870 : : class. */
2871 : 169187358 : if (! no_regs_p && REG_P (op) && hard_regno[nop] < 0
2872 : 21864610 : && (cl = get_reg_class (REGNO (op))) != NO_REGS
2873 : 182050449 : && ira_class_subset_p[this_alternative][cl])
2874 : : {
2875 : 1059 : if (lra_dump_file != NULL)
2876 : 0 : fprintf
2877 : 0 : (lra_dump_file,
2878 : : " %d Super set class reg: reject-=3\n", nop);
2879 : 1059 : reject -= 3;
2880 : : }
2881 : :
2882 : 178919862 : this_alternative_offmemok = offmemok;
2883 : 178919862 : if (this_costly_alternative != NO_REGS)
2884 : : {
2885 : 19551905 : if (lra_dump_file != NULL)
2886 : 25 : fprintf (lra_dump_file,
2887 : : " %d Costly loser: reject++\n", nop);
2888 : 19551905 : reject++;
2889 : : }
2890 : : /* If the operand is dying, has a matching constraint,
2891 : : and satisfies constraints of the matched operand
2892 : : which failed to satisfy the own constraints, most probably
2893 : : the reload for this operand will be gone. */
2894 : 178919862 : if (this_alternative_matches >= 0
2895 : 41908892 : && !curr_alt_win[this_alternative_matches]
2896 : 952608 : && REG_P (op)
2897 : 693561 : && find_regno_note (curr_insn, REG_DEAD, REGNO (op))
2898 : 179629032 : && (hard_regno[nop] >= 0
2899 : 370871 : ? in_hard_reg_set_p (this_alternative_set,
2900 : : mode, hard_regno[nop])
2901 : 32572 : : in_class_p (op, this_alternative, NULL)))
2902 : : {
2903 : 226112 : if (lra_dump_file != NULL)
2904 : 1 : fprintf
2905 : 1 : (lra_dump_file,
2906 : : " %d Dying matched operand reload: reject++\n",
2907 : : nop);
2908 : 226112 : reject++;
2909 : : }
2910 : : else
2911 : : {
2912 : : /* Strict_low_part requires to reload the register
2913 : : not the sub-register. In this case we should
2914 : : check that a final reload hard reg can hold the
2915 : : value mode. */
2916 : 178693750 : if (curr_static_id->operand[nop].strict_low
2917 : 108 : && REG_P (op)
2918 : 101 : && hard_regno[nop] < 0
2919 : 76 : && GET_CODE (*curr_id->operand_loc[nop]) == SUBREG
2920 : 76 : && ira_class_hard_regs_num[this_alternative] > 0
2921 : 178693826 : && (!targetm.hard_regno_mode_ok
2922 : 76 : (ira_class_hard_regs[this_alternative][0],
2923 : 76 : GET_MODE (*curr_id->operand_loc[nop]))))
2924 : : {
2925 : 0 : if (lra_dump_file != NULL)
2926 : 0 : fprintf
2927 : 0 : (lra_dump_file,
2928 : : " Strict low subreg reload -- refuse\n");
2929 : 0 : goto fail;
2930 : : }
2931 : 178693750 : if (lra_dump_file != NULL)
2932 : 2171 : fprintf
2933 : 2171 : (lra_dump_file,
2934 : : " %d Operand reload: losers++\n", nop);
2935 : 178693750 : losers++;
2936 : : }
2937 : 178919862 : if (operand_reg[nop] != NULL_RTX
2938 : : /* Output operands and matched input operands are
2939 : : not inherited. The following conditions do not
2940 : : exactly describe the previous statement but they
2941 : : are pretty close. */
2942 : 64603018 : && curr_static_id->operand[nop].type != OP_OUT
2943 : 28104638 : && (this_alternative_matches < 0
2944 : 16265854 : || curr_static_id->operand[nop].type != OP_IN))
2945 : : {
2946 : 11838784 : int last_reload = (lra_reg_info[ORIGINAL_REGNO
2947 : 11838784 : (operand_reg[nop])]
2948 : 11838784 : .last_reload);
2949 : :
2950 : : /* The value of reload_sum has sense only if we
2951 : : process insns in their order. It happens only on
2952 : : the first constraints sub-pass when we do most of
2953 : : reload work. */
2954 : 11838784 : if (lra_constraint_iter == 1 && last_reload > bb_reload_num)
2955 : 2545359 : reload_sum += last_reload - bb_reload_num;
2956 : : }
2957 : : /* If this is a constant that is reloaded into the
2958 : : desired class by copying it to memory first, count
2959 : : that as another reload. This is consistent with
2960 : : other code and is required to avoid choosing another
2961 : : alternative when the constant is moved into memory.
2962 : : Note that the test here is precisely the same as in
2963 : : the code below that calls force_const_mem. */
2964 : 229908292 : if (CONST_POOL_OK_P (mode, op)
2965 : 229908359 : && ((targetm.preferred_reload_class
2966 : 50988497 : (op, this_alternative) == NO_REGS)
2967 : 49390373 : || no_input_reloads_p))
2968 : : {
2969 : 1598124 : const_to_mem = 1;
2970 : 1598124 : if (! no_regs_p)
2971 : : {
2972 : 708549 : if (lra_dump_file != NULL)
2973 : 0 : fprintf
2974 : 0 : (lra_dump_file,
2975 : : " %d Constant reload through memory: "
2976 : : "losers++\n", nop);
2977 : 708549 : losers++;
2978 : : }
2979 : : }
2980 : :
2981 : : /* Alternative loses if it requires a type of reload not
2982 : : permitted for this insn. We can always reload
2983 : : objects with a REG_UNUSED note. */
2984 : 178919862 : if ((curr_static_id->operand[nop].type != OP_IN
2985 : 87002488 : && no_output_reloads_p
2986 : 0 : && ! find_reg_note (curr_insn, REG_UNUSED, op))
2987 : 178919862 : || (curr_static_id->operand[nop].type != OP_OUT
2988 : 91917576 : && no_input_reloads_p && ! const_to_mem)
2989 : 357839724 : || (this_alternative_matches >= 0
2990 : 41908892 : && (no_input_reloads_p
2991 : 41908892 : || (no_output_reloads_p
2992 : 0 : && (curr_static_id->operand
2993 : 0 : [this_alternative_matches].type != OP_IN)
2994 : 0 : && ! find_reg_note (curr_insn, REG_UNUSED,
2995 : : no_subreg_reg_operand
2996 : 0 : [this_alternative_matches])))))
2997 : : {
2998 : 0 : if (lra_dump_file != NULL)
2999 : 0 : fprintf
3000 : 0 : (lra_dump_file,
3001 : : " No input/output reload -- refuse\n");
3002 : 0 : goto fail;
3003 : : }
3004 : :
3005 : : /* Alternative loses if it required class pseudo cannot
3006 : : hold value of required mode. Such insns can be
3007 : : described by insn definitions with mode iterators. */
3008 : 178919862 : if (GET_MODE (*curr_id->operand_loc[nop]) != VOIDmode
3009 : 129322491 : && ! hard_reg_set_empty_p (this_alternative_set)
3010 : : /* It is common practice for constraints to use a
3011 : : class which does not have actually enough regs to
3012 : : hold the value (e.g. x86 AREG for mode requiring
3013 : : more one general reg). Therefore we have 2
3014 : : conditions to check that the reload pseudo cannot
3015 : : hold the mode value. */
3016 : 120380990 : && (!targetm.hard_regno_mode_ok
3017 : 120380990 : (ira_class_hard_regs[this_alternative][0],
3018 : : GET_MODE (*curr_id->operand_loc[nop])))
3019 : : /* The above condition is not enough as the first
3020 : : reg in ira_class_hard_regs can be not aligned for
3021 : : multi-words mode values. */
3022 : 178919862 : && (prohibited_class_reg_set_mode_p
3023 : 0 : (this_alternative, this_alternative_set,
3024 : 0 : GET_MODE (*curr_id->operand_loc[nop]))))
3025 : : {
3026 : 0 : if (lra_dump_file != NULL)
3027 : 0 : fprintf (lra_dump_file,
3028 : : " reload pseudo for op %d "
3029 : : "cannot hold the mode value -- refuse\n",
3030 : : nop);
3031 : 0 : goto fail;
3032 : : }
3033 : :
3034 : : /* Check strong discouragement of reload of non-constant
3035 : : into class THIS_ALTERNATIVE. */
3036 : 127931365 : if (! CONSTANT_P (op) && ! no_regs_p
3037 : 298008298 : && (targetm.preferred_reload_class
3038 : 119088436 : (op, this_alternative) == NO_REGS
3039 : 110334155 : || (curr_static_id->operand[nop].type == OP_OUT
3040 : 76071945 : && (targetm.preferred_output_reload_class
3041 : 76071945 : (op, this_alternative) == NO_REGS))))
3042 : : {
3043 : 13398747 : if (offmemok && REG_P (op))
3044 : : {
3045 : 801684 : if (lra_dump_file != NULL)
3046 : 0 : fprintf
3047 : 0 : (lra_dump_file,
3048 : : " %d Spill pseudo into memory: reject+=3\n",
3049 : : nop);
3050 : 801684 : reject += 3;
3051 : : }
3052 : : else
3053 : : {
3054 : 12597063 : if (lra_dump_file != NULL)
3055 : 0 : fprintf
3056 : 0 : (lra_dump_file,
3057 : : " %d Non-prefered reload: reject+=%d\n",
3058 : : nop, LRA_MAX_REJECT);
3059 : 12597063 : reject += LRA_MAX_REJECT;
3060 : : }
3061 : : }
3062 : :
3063 : 178919862 : if (! (MEM_P (op) && offmemok)
3064 : 178919790 : && ! (const_to_mem && constmemok))
3065 : : {
3066 : : /* We prefer to reload pseudos over reloading other
3067 : : things, since such reloads may be able to be
3068 : : eliminated later. So bump REJECT in other cases.
3069 : : Don't do this in the case where we are forcing a
3070 : : constant into memory and it will then win since
3071 : : we don't want to have a different alternative
3072 : : match then. */
3073 : 177914230 : if (! (REG_P (op) && REGNO (op) >= FIRST_PSEUDO_REGISTER))
3074 : : {
3075 : 127076760 : if (lra_dump_file != NULL)
3076 : 1648 : fprintf
3077 : 1648 : (lra_dump_file,
3078 : : " %d Non-pseudo reload: reject+=2\n",
3079 : : nop);
3080 : 127076760 : reject += 2;
3081 : : }
3082 : :
3083 : 177914230 : if (! no_regs_p)
3084 : 169071345 : reload_nregs
3085 : 169071345 : += ira_reg_class_max_nregs[this_alternative][mode];
3086 : :
3087 : 177914230 : if (SMALL_REGISTER_CLASS_P (this_alternative))
3088 : : {
3089 : 896263 : if (lra_dump_file != NULL)
3090 : 45 : fprintf
3091 : 45 : (lra_dump_file,
3092 : : " %d Small class reload: reject+=%d\n",
3093 : : nop, LRA_LOSER_COST_FACTOR / 2);
3094 : 896263 : reject += LRA_LOSER_COST_FACTOR / 2;
3095 : : }
3096 : : }
3097 : :
3098 : : /* We are trying to spill pseudo into memory. It is
3099 : : usually more costly than moving to a hard register
3100 : : although it might takes the same number of
3101 : : reloads.
3102 : :
3103 : : Non-pseudo spill may happen also. Suppose a target allows both
3104 : : register and memory in the operand constraint alternatives,
3105 : : then it's typical that an eliminable register has a substition
3106 : : of "base + offset" which can either be reloaded by a simple
3107 : : "new_reg <= base + offset" which will match the register
3108 : : constraint, or a similar reg addition followed by further spill
3109 : : to and reload from memory which will match the memory
3110 : : constraint, but this memory spill will be much more costly
3111 : : usually.
3112 : :
3113 : : Code below increases the reject for both pseudo and non-pseudo
3114 : : spill. */
3115 : 178919862 : if (no_regs_p
3116 : 9732504 : && !(MEM_P (op) && offmemok)
3117 : 9732460 : && !(REG_P (op) && hard_regno[nop] < 0))
3118 : : {
3119 : 8601138 : if (lra_dump_file != NULL)
3120 : 13 : fprintf
3121 : 20 : (lra_dump_file,
3122 : : " %d Spill %spseudo into memory: reject+=3\n",
3123 : : nop, REG_P (op) ? "" : "Non-");
3124 : 8601138 : reject += 3;
3125 : 8601138 : if (VECTOR_MODE_P (mode))
3126 : : {
3127 : : /* Spilling vectors into memory is usually more
3128 : : costly as they contain big values. */
3129 : 358571 : if (lra_dump_file != NULL)
3130 : 0 : fprintf
3131 : 0 : (lra_dump_file,
3132 : : " %d Spill vector pseudo: reject+=2\n",
3133 : : nop);
3134 : 358571 : reject += 2;
3135 : : }
3136 : : }
3137 : :
3138 : : /* When we use an operand requiring memory in given
3139 : : alternative, the insn should write *and* read the
3140 : : value to/from memory it is costly in comparison with
3141 : : an insn alternative which does not use memory
3142 : : (e.g. register or immediate operand). We exclude
3143 : : memory operand for such case as we can satisfy the
3144 : : memory constraints by reloading address. */
3145 : 9732504 : if (no_regs_p && offmemok && !MEM_P (op))
3146 : : {
3147 : 9732350 : if (lra_dump_file != NULL)
3148 : 27 : fprintf
3149 : 27 : (lra_dump_file,
3150 : : " Using memory insn operand %d: reject+=3\n",
3151 : : nop);
3152 : 9732350 : reject += 3;
3153 : : }
3154 : :
3155 : : /* If reload requires moving value through secondary
3156 : : memory, it will need one more insn at least. */
3157 : 178919862 : if (this_alternative != NO_REGS
3158 : 169187178 : && REG_P (op) && (cl = get_reg_class (REGNO (op))) != NO_REGS
3159 : 215951527 : && ((curr_static_id->operand[nop].type != OP_OUT
3160 : 20647364 : && targetm.secondary_memory_needed (mode, cl,
3161 : : this_alternative))
3162 : 33756080 : || (curr_static_id->operand[nop].type != OP_IN
3163 : 16384418 : && (targetm.secondary_memory_needed
3164 : 16384418 : (mode, this_alternative, cl)))))
3165 : : {
3166 : 11175178 : if (lra_dump_file != NULL)
3167 : 16 : fprintf
3168 : 16 : (lra_dump_file,
3169 : : " %d Secondary memory reload needed: "
3170 : : "losers++\n", nop);
3171 : 11175178 : losers++;
3172 : : }
3173 : :
3174 : 178919862 : if (MEM_P (op) && offmemok)
3175 : 72 : addr_losers++;
3176 : : else
3177 : : {
3178 : : /* Input reloads can be inherited more often than
3179 : : output reloads can be removed, so penalize output
3180 : : reloads. */
3181 : 178919790 : if (!REG_P (op) || curr_static_id->operand[nop].type != OP_IN)
3182 : : {
3183 : 150815347 : if (lra_dump_file != NULL)
3184 : 1722 : fprintf
3185 : 1722 : (lra_dump_file,
3186 : : " %d Non input pseudo reload: reject++\n",
3187 : : nop);
3188 : 150815347 : reject++;
3189 : : }
3190 : :
3191 : 178919790 : if (curr_static_id->operand[nop].type == OP_INOUT)
3192 : : {
3193 : 202 : if (lra_dump_file != NULL)
3194 : 0 : fprintf
3195 : 0 : (lra_dump_file,
3196 : : " %d Input/Output reload: reject+=%d\n",
3197 : : nop, LRA_LOSER_COST_FACTOR);
3198 : 202 : reject += LRA_LOSER_COST_FACTOR;
3199 : : }
3200 : : }
3201 : : }
3202 : :
3203 : 475278164 : if (early_clobber_p && ! scratch_p)
3204 : : {
3205 : 164709 : if (lra_dump_file != NULL)
3206 : 4 : fprintf (lra_dump_file,
3207 : : " %d Early clobber: reject++\n", nop);
3208 : 164709 : reject++;
3209 : : }
3210 : : /* ??? We check early clobbers after processing all operands
3211 : : (see loop below) and there we update the costs more.
3212 : : Should we update the cost (may be approximately) here
3213 : : because of early clobber register reloads or it is a rare
3214 : : or non-important thing to be worth to do it. */
3215 : 950556328 : overall = (losers * LRA_LOSER_COST_FACTOR + reject
3216 : 475278164 : - (addr_losers == losers ? static_reject : 0));
3217 : 475278164 : if ((best_losers == 0 || losers != 0) && best_overall < overall)
3218 : : {
3219 : 75729696 : if (lra_dump_file != NULL)
3220 : 1036 : fprintf (lra_dump_file,
3221 : : " overall=%d,losers=%d -- refuse\n",
3222 : : overall, losers);
3223 : 75729696 : goto fail;
3224 : : }
3225 : :
3226 : 399548468 : if (update_and_check_small_class_inputs (nop, nalt,
3227 : : this_alternative))
3228 : : {
3229 : 0 : if (lra_dump_file != NULL)
3230 : 0 : fprintf (lra_dump_file,
3231 : : " not enough small class regs -- refuse\n");
3232 : 0 : goto fail;
3233 : : }
3234 : 399548468 : curr_alt[nop] = this_alternative;
3235 : 399548468 : curr_alt_set[nop] = this_alternative_set;
3236 : 399548468 : curr_alt_exclude_start_hard_regs[nop]
3237 : 399548468 : = this_alternative_exclude_start_hard_regs;
3238 : 399548468 : curr_alt_win[nop] = this_alternative_win;
3239 : 399548468 : curr_alt_match_win[nop] = this_alternative_match_win;
3240 : 399548468 : curr_alt_offmemok[nop] = this_alternative_offmemok;
3241 : 399548468 : curr_alt_matches[nop] = this_alternative_matches;
3242 : :
3243 : 399548468 : if (this_alternative_matches >= 0
3244 : 399548468 : && !did_match && !this_alternative_win)
3245 : 13383922 : curr_alt_win[this_alternative_matches] = false;
3246 : :
3247 : 399548468 : if (early_clobber_p && operand_reg[nop] != NULL_RTX)
3248 : 169035 : early_clobbered_nops[early_clobbered_regs_num++] = nop;
3249 : : }
3250 : :
3251 : 133075028 : if (curr_insn_set != NULL_RTX && n_operands == 2
3252 : : /* Prevent processing non-move insns. */
3253 : 104196835 : && (GET_CODE (SET_SRC (curr_insn_set)) == SUBREG
3254 : 102387415 : || SET_SRC (curr_insn_set) == no_subreg_reg_operand[1])
3255 : 230111571 : && ((! curr_alt_win[0] && ! curr_alt_win[1]
3256 : 6349675 : && REG_P (no_subreg_reg_operand[0])
3257 : 3166344 : && REG_P (no_subreg_reg_operand[1])
3258 : 1254502 : && (reg_in_class_p (no_subreg_reg_operand[0], curr_alt[1])
3259 : 1042426 : || reg_in_class_p (no_subreg_reg_operand[1], curr_alt[0])))
3260 : 92618568 : || (! curr_alt_win[0] && curr_alt_win[1]
3261 : 27601321 : && REG_P (no_subreg_reg_operand[1])
3262 : : /* Check that we reload memory not the memory
3263 : : address. */
3264 : 15732510 : && ! (curr_alt_offmemok[0]
3265 : 387243 : && MEM_P (no_subreg_reg_operand[0]))
3266 : 15732510 : && reg_in_class_p (no_subreg_reg_operand[1], curr_alt[0]))
3267 : 78292832 : || (curr_alt_win[0] && ! curr_alt_win[1]
3268 : 9887596 : && REG_P (no_subreg_reg_operand[0])
3269 : : /* Check that we reload memory not the memory
3270 : : address. */
3271 : 7404607 : && ! (curr_alt_offmemok[1]
3272 : 1041446 : && MEM_P (no_subreg_reg_operand[1]))
3273 : 7404605 : && reg_in_class_p (no_subreg_reg_operand[0], curr_alt[1])
3274 : 6497003 : && (! CONST_POOL_OK_P (curr_operand_mode[1],
3275 : : no_subreg_reg_operand[1])
3276 : 2404218 : || (targetm.preferred_reload_class
3277 : 2404218 : (no_subreg_reg_operand[1],
3278 : : (enum reg_class) curr_alt[1]) != NO_REGS))
3279 : : /* If it is a result of recent elimination in move
3280 : : insn we can transform it into an add still by
3281 : : using this alternative. */
3282 : 6452944 : && GET_CODE (no_subreg_reg_operand[1]) != PLUS
3283 : : /* Likewise if the source has been replaced with an
3284 : : equivalent value. This only happens once -- the reload
3285 : : will use the equivalent value instead of the register it
3286 : : replaces -- so there should be no danger of cycling. */
3287 : 5929415 : && !equiv_substition_p[1])))
3288 : : {
3289 : : /* We have a move insn and a new reload insn will be similar
3290 : : to the current insn. We should avoid such situation as
3291 : : it results in LRA cycling. */
3292 : 20762669 : if (lra_dump_file != NULL)
3293 : 239 : fprintf (lra_dump_file,
3294 : : " Cycle danger: overall += LRA_MAX_REJECT\n");
3295 : 20762669 : overall += LRA_MAX_REJECT;
3296 : : }
3297 : 136956921 : if (all_this_alternative != NO_REGS
3298 : 117199993 : && !SMALL_REGISTER_CLASS_P (all_this_alternative)
3299 : 116323783 : && all_used_nregs != 0 && all_reload_nregs != 0
3300 : 136956921 : && (all_used_nregs + all_reload_nregs + 1
3301 : 4004624 : >= ira_class_hard_regs_num[all_this_alternative]))
3302 : : {
3303 : 265 : if (lra_dump_file != NULL)
3304 : 0 : fprintf
3305 : 0 : (lra_dump_file,
3306 : : " Register starvation: overall += LRA_MAX_REJECT"
3307 : : "(class=%s,avail=%d,used=%d,reload=%d)\n",
3308 : : reg_class_names[all_this_alternative],
3309 : : ira_class_hard_regs_num[all_this_alternative],
3310 : : all_used_nregs, all_reload_nregs);
3311 : 265 : overall += LRA_MAX_REJECT;
3312 : : }
3313 : 137122454 : ok_p = true;
3314 : : curr_alt_dont_inherit_ops_num = 0;
3315 : 137122454 : for (nop = 0; nop < early_clobbered_regs_num; nop++)
3316 : : {
3317 : 165534 : int i, j, clobbered_hard_regno, first_conflict_j, last_conflict_j;
3318 : 165534 : HARD_REG_SET temp_set;
3319 : :
3320 : 165534 : i = early_clobbered_nops[nop];
3321 : 165534 : if ((! curr_alt_win[i] && ! curr_alt_match_win[i])
3322 : 124427 : || hard_regno[i] < 0)
3323 : 164899 : continue;
3324 : 122620 : lra_assert (operand_reg[i] != NULL_RTX);
3325 : : clobbered_hard_regno = hard_regno[i];
3326 : 122620 : CLEAR_HARD_REG_SET (temp_set);
3327 : 122620 : add_to_hard_reg_set (&temp_set, GET_MODE (*curr_id->operand_loc[i]),
3328 : : clobbered_hard_regno);
3329 : 122620 : first_conflict_j = last_conflict_j = -1;
3330 : 618662 : for (j = 0; j < n_operands; j++)
3331 : 496043 : if (j == i
3332 : : /* We don't want process insides of match_operator and
3333 : : match_parallel because otherwise we would process
3334 : : their operands once again generating a wrong
3335 : : code. */
3336 : 373423 : || curr_static_id->operand[j].is_operator)
3337 : 124761 : continue;
3338 : 371282 : else if ((curr_alt_matches[j] == i && curr_alt_match_win[j])
3339 : 352098 : || (curr_alt_matches[i] == j && curr_alt_match_win[i]))
3340 : 19184 : continue;
3341 : : /* If we don't reload j-th operand, check conflicts. */
3342 : 120274 : else if ((curr_alt_win[j] || curr_alt_match_win[j])
3343 : 412303 : && uses_hard_regs_p (*curr_id->operand_loc[j], temp_set))
3344 : : {
3345 : 1020 : if (first_conflict_j < 0)
3346 : 635 : first_conflict_j = j;
3347 : 1020 : last_conflict_j = j;
3348 : : /* Both the earlyclobber operand and conflicting operand
3349 : : cannot both be user defined hard registers for asm.
3350 : : Let curr_insn_transform diagnose it. */
3351 : 1020 : if (HARD_REGISTER_P (operand_reg[i])
3352 : 1 : && REG_USERVAR_P (operand_reg[i])
3353 : 1 : && operand_reg[j] != NULL_RTX
3354 : 1 : && HARD_REGISTER_P (operand_reg[j])
3355 : 1 : && REG_USERVAR_P (operand_reg[j])
3356 : 1021 : && INSN_CODE (curr_insn) < 0)
3357 : 1 : return false;
3358 : : }
3359 : 122619 : if (last_conflict_j < 0)
3360 : 121985 : continue;
3361 : :
3362 : : /* If an earlyclobber operand conflicts with another non-matching
3363 : : operand (ie, they have been assigned the same hard register),
3364 : : then it is better to reload the other operand, as there may
3365 : : exist yet another operand with a matching constraint associated
3366 : : with the earlyclobber operand. However, if one of the operands
3367 : : is an explicit use of a hard register, then we must reload the
3368 : : other non-hard register operand. */
3369 : 634 : if (HARD_REGISTER_P (operand_reg[i])
3370 : 634 : || (first_conflict_j == last_conflict_j
3371 : 249 : && operand_reg[last_conflict_j] != NULL_RTX
3372 : 60 : && !curr_alt_match_win[last_conflict_j]
3373 : 60 : && !HARD_REGISTER_P (operand_reg[last_conflict_j])))
3374 : : {
3375 : 60 : curr_alt_win[last_conflict_j] = false;
3376 : 60 : curr_alt_dont_inherit_ops[curr_alt_dont_inherit_ops_num++]
3377 : 60 : = last_conflict_j;
3378 : 60 : losers++;
3379 : 60 : if (lra_dump_file != NULL)
3380 : 0 : fprintf
3381 : 0 : (lra_dump_file,
3382 : : " %d Conflict early clobber reload: losers++\n",
3383 : : i);
3384 : : }
3385 : : else
3386 : : {
3387 : : /* We need to reload early clobbered register and the
3388 : : matched registers. */
3389 : 2864 : for (j = 0; j < n_operands; j++)
3390 : 2290 : if (curr_alt_matches[j] == i)
3391 : : {
3392 : 2 : curr_alt_match_win[j] = false;
3393 : 2 : losers++;
3394 : 2 : if (lra_dump_file != NULL)
3395 : 0 : fprintf
3396 : 0 : (lra_dump_file,
3397 : : " %d Matching conflict early clobber "
3398 : : "reloads: losers++\n",
3399 : : j);
3400 : 2 : overall += LRA_LOSER_COST_FACTOR;
3401 : : }
3402 : 574 : if (! curr_alt_match_win[i])
3403 : 574 : curr_alt_dont_inherit_ops[curr_alt_dont_inherit_ops_num++] = i;
3404 : : else
3405 : : {
3406 : : /* Remember pseudos used for match reloads are never
3407 : : inherited. */
3408 : 0 : lra_assert (curr_alt_matches[i] >= 0);
3409 : 0 : curr_alt_win[curr_alt_matches[i]] = false;
3410 : : }
3411 : 574 : curr_alt_win[i] = curr_alt_match_win[i] = false;
3412 : 574 : losers++;
3413 : 574 : if (lra_dump_file != NULL)
3414 : 0 : fprintf
3415 : 0 : (lra_dump_file,
3416 : : " %d Matched conflict early clobber reloads: "
3417 : : "losers++\n",
3418 : : i);
3419 : : }
3420 : : /* Early clobber was already reflected in REJECT. */
3421 : 634 : if (!matching_early_clobber[i])
3422 : : {
3423 : 634 : lra_assert (reject > 0);
3424 : 634 : reject--;
3425 : 634 : matching_early_clobber[i] = 1;
3426 : : }
3427 : 634 : overall += LRA_LOSER_COST_FACTOR - 1;
3428 : : }
3429 : 136956920 : if (lra_dump_file != NULL)
3430 : 1766 : fprintf (lra_dump_file, " overall=%d,losers=%d,rld_nregs=%d\n",
3431 : : overall, losers, reload_nregs);
3432 : :
3433 : : /* If this alternative can be made to work by reloading, and it
3434 : : needs less reloading than the others checked so far, record
3435 : : it as the chosen goal for reloading. */
3436 : 136956920 : if ((best_losers != 0 && losers == 0)
3437 : 61023532 : || (((best_losers == 0 && losers == 0)
3438 : 60030647 : || (best_losers != 0 && losers != 0))
3439 : 61023532 : && (best_overall > overall
3440 : 16117918 : || (best_overall == overall
3441 : : /* If the cost of the reloads is the same,
3442 : : prefer alternative which requires minimal
3443 : : number of reload regs. */
3444 : 11946232 : && (reload_nregs < best_reload_nregs
3445 : 11842595 : || (reload_nregs == best_reload_nregs
3446 : 11798757 : && (best_reload_sum < reload_sum
3447 : 11778581 : || (best_reload_sum == reload_sum
3448 : 11754584 : && nalt < goal_alt_number))))))))
3449 : : {
3450 : 393322707 : for (nop = 0; nop < n_operands; nop++)
3451 : : {
3452 : 272120665 : goal_alt_win[nop] = curr_alt_win[nop];
3453 : 272120665 : goal_alt_match_win[nop] = curr_alt_match_win[nop];
3454 : 272120665 : goal_alt_matches[nop] = curr_alt_matches[nop];
3455 : 272120665 : goal_alt[nop] = curr_alt[nop];
3456 : 272120665 : goal_alt_exclude_start_hard_regs[nop]
3457 : 272120665 : = curr_alt_exclude_start_hard_regs[nop];
3458 : 272120665 : goal_alt_offmemok[nop] = curr_alt_offmemok[nop];
3459 : : }
3460 : 121202042 : goal_alt_dont_inherit_ops_num = curr_alt_dont_inherit_ops_num;
3461 : 121202042 : goal_reuse_alt_p = curr_reuse_alt_p;
3462 : 121202662 : for (nop = 0; nop < curr_alt_dont_inherit_ops_num; nop++)
3463 : 620 : goal_alt_dont_inherit_ops[nop] = curr_alt_dont_inherit_ops[nop];
3464 : 121202042 : goal_alt_swapped = curr_swapped;
3465 : 121202042 : goal_alt_out_sp_reload_p = curr_alt_out_sp_reload_p;
3466 : 121202042 : best_overall = overall;
3467 : 121202042 : best_losers = losers;
3468 : 121202042 : best_reload_nregs = reload_nregs;
3469 : 121202042 : best_reload_sum = reload_sum;
3470 : 121202042 : goal_alt_number = nalt;
3471 : : }
3472 : 136956920 : if (losers == 0 && !curr_alt_class_change_p)
3473 : : /* Everything is satisfied. Do not process alternatives
3474 : : anymore. */
3475 : : break;
3476 : 60042769 : fail:
3477 : 184158776 : ;
3478 : : }
3479 : : return ok_p;
3480 : : }
3481 : :
3482 : : /* Make reload base reg from address AD. */
3483 : : static rtx
3484 : 0 : base_to_reg (struct address_info *ad)
3485 : : {
3486 : 0 : enum reg_class cl;
3487 : 0 : int code = -1;
3488 : 0 : rtx new_inner = NULL_RTX;
3489 : 0 : rtx new_reg = NULL_RTX;
3490 : 0 : rtx_insn *insn;
3491 : 0 : rtx_insn *last_insn = get_last_insn();
3492 : :
3493 : 0 : lra_assert (ad->disp == ad->disp_term);
3494 : 0 : cl = base_reg_class (ad->mode, ad->as, ad->base_outer_code,
3495 : : get_index_code (ad));
3496 : 0 : new_reg = lra_create_new_reg (GET_MODE (*ad->base), NULL_RTX, cl, NULL,
3497 : : "base");
3498 : 0 : new_inner = simplify_gen_binary (PLUS, GET_MODE (new_reg), new_reg,
3499 : 0 : ad->disp_term == NULL
3500 : : ? const0_rtx
3501 : : : *ad->disp_term);
3502 : 0 : if (!valid_address_p (ad->mode, new_inner, ad->as))
3503 : : return NULL_RTX;
3504 : 0 : insn = emit_insn (gen_rtx_SET (new_reg, *ad->base));
3505 : 0 : code = recog_memoized (insn);
3506 : 0 : if (code < 0)
3507 : : {
3508 : 0 : delete_insns_since (last_insn);
3509 : 0 : return NULL_RTX;
3510 : : }
3511 : :
3512 : : return new_inner;
3513 : : }
3514 : :
3515 : : /* Make reload base reg + DISP from address AD. Return the new pseudo. */
3516 : : static rtx
3517 : 39 : base_plus_disp_to_reg (struct address_info *ad, rtx disp)
3518 : : {
3519 : 39 : enum reg_class cl;
3520 : 39 : rtx new_reg;
3521 : :
3522 : 39 : lra_assert (ad->base == ad->base_term);
3523 : 39 : cl = base_reg_class (ad->mode, ad->as, ad->base_outer_code,
3524 : : get_index_code (ad));
3525 : 39 : new_reg = lra_create_new_reg (GET_MODE (*ad->base_term), NULL_RTX, cl, NULL,
3526 : : "base + disp");
3527 : 39 : lra_emit_add (new_reg, *ad->base_term, disp);
3528 : 39 : return new_reg;
3529 : : }
3530 : :
3531 : : /* Make reload of index part of address AD. Return the new
3532 : : pseudo. */
3533 : : static rtx
3534 : 0 : index_part_to_reg (struct address_info *ad, enum reg_class index_class)
3535 : : {
3536 : 0 : rtx new_reg;
3537 : :
3538 : 0 : new_reg = lra_create_new_reg (GET_MODE (*ad->index), NULL_RTX,
3539 : : index_class, NULL, "index term");
3540 : 0 : expand_mult (GET_MODE (*ad->index), *ad->index_term,
3541 : : GEN_INT (get_index_scale (ad)), new_reg, 1);
3542 : 0 : return new_reg;
3543 : : }
3544 : :
3545 : : /* Return true if we can add a displacement to address AD, even if that
3546 : : makes the address invalid. The fix-up code requires any new address
3547 : : to be the sum of the BASE_TERM, INDEX and DISP_TERM fields. */
3548 : : static bool
3549 : 18193 : can_add_disp_p (struct address_info *ad)
3550 : : {
3551 : 18193 : return (!ad->autoinc_p
3552 : 18193 : && ad->segment == NULL
3553 : 18193 : && ad->base == ad->base_term
3554 : 36386 : && ad->disp == ad->disp_term);
3555 : : }
3556 : :
3557 : : /* Make equiv substitution in address AD. Return true if a substitution
3558 : : was made. */
3559 : : static bool
3560 : 39859178 : equiv_address_substitution (struct address_info *ad)
3561 : : {
3562 : 39859178 : rtx base_reg, new_base_reg, index_reg, new_index_reg, *base_term, *index_term;
3563 : 39859178 : poly_int64 disp;
3564 : 39859178 : HOST_WIDE_INT scale;
3565 : 39859178 : bool change_p;
3566 : :
3567 : 39859178 : base_term = strip_subreg (ad->base_term);
3568 : 10723 : if (base_term == NULL)
3569 : : base_reg = new_base_reg = NULL_RTX;
3570 : : else
3571 : : {
3572 : 33629193 : base_reg = *base_term;
3573 : 33629193 : new_base_reg = get_equiv_with_elimination (base_reg, curr_insn);
3574 : : }
3575 : 39859178 : index_term = strip_subreg (ad->index_term);
3576 : 6001 : if (index_term == NULL)
3577 : : index_reg = new_index_reg = NULL_RTX;
3578 : : else
3579 : : {
3580 : 1872697 : index_reg = *index_term;
3581 : 1872697 : new_index_reg = get_equiv_with_elimination (index_reg, curr_insn);
3582 : : }
3583 : 39859178 : if (base_reg == new_base_reg && index_reg == new_index_reg)
3584 : : return false;
3585 : 135112 : disp = 0;
3586 : 135112 : change_p = false;
3587 : 135112 : if (lra_dump_file != NULL)
3588 : : {
3589 : 0 : fprintf (lra_dump_file, "Changing address in insn %d ",
3590 : 0 : INSN_UID (curr_insn));
3591 : 0 : dump_value_slim (lra_dump_file, *ad->outer, 1);
3592 : : }
3593 : 135112 : if (base_reg != new_base_reg)
3594 : : {
3595 : 134625 : poly_int64 offset;
3596 : 134625 : if (REG_P (new_base_reg))
3597 : : {
3598 : 5394 : *base_term = new_base_reg;
3599 : 5394 : change_p = true;
3600 : : }
3601 : 129231 : else if (GET_CODE (new_base_reg) == PLUS
3602 : 18193 : && REG_P (XEXP (new_base_reg, 0))
3603 : 18193 : && poly_int_rtx_p (XEXP (new_base_reg, 1), &offset)
3604 : 147424 : && can_add_disp_p (ad))
3605 : : {
3606 : : disp += offset;
3607 : 18193 : *base_term = XEXP (new_base_reg, 0);
3608 : 18193 : change_p = true;
3609 : : }
3610 : 134625 : if (ad->base_term2 != NULL)
3611 : 0 : *ad->base_term2 = *ad->base_term;
3612 : : }
3613 : 135112 : if (index_reg != new_index_reg)
3614 : : {
3615 : 683 : poly_int64 offset;
3616 : 683 : if (REG_P (new_index_reg))
3617 : : {
3618 : 0 : *index_term = new_index_reg;
3619 : 0 : change_p = true;
3620 : : }
3621 : 683 : else if (GET_CODE (new_index_reg) == PLUS
3622 : 0 : && REG_P (XEXP (new_index_reg, 0))
3623 : 0 : && poly_int_rtx_p (XEXP (new_index_reg, 1), &offset)
3624 : 0 : && can_add_disp_p (ad)
3625 : 683 : && (scale = get_index_scale (ad)))
3626 : : {
3627 : 0 : disp += offset * scale;
3628 : 0 : *index_term = XEXP (new_index_reg, 0);
3629 : 0 : change_p = true;
3630 : : }
3631 : : }
3632 : 135112 : if (maybe_ne (disp, 0))
3633 : : {
3634 : 18193 : if (ad->disp != NULL)
3635 : 5657 : *ad->disp = plus_constant (GET_MODE (*ad->inner), *ad->disp, disp);
3636 : : else
3637 : : {
3638 : 12536 : *ad->inner = plus_constant (GET_MODE (*ad->inner), *ad->inner, disp);
3639 : 12536 : update_address (ad);
3640 : : }
3641 : : change_p = true;
3642 : : }
3643 : 135112 : if (lra_dump_file != NULL)
3644 : : {
3645 : 0 : if (! change_p)
3646 : 0 : fprintf (lra_dump_file, " -- no change\n");
3647 : : else
3648 : : {
3649 : 0 : fprintf (lra_dump_file, " on equiv ");
3650 : 0 : dump_value_slim (lra_dump_file, *ad->outer, 1);
3651 : 0 : fprintf (lra_dump_file, "\n");
3652 : : }
3653 : : }
3654 : : return change_p;
3655 : : }
3656 : :
3657 : : /* Skip all modifiers and whitespaces in constraint STR and return the
3658 : : result. */
3659 : : static const char *
3660 : 516795467 : skip_constraint_modifiers (const char *str)
3661 : : {
3662 : 728283909 : for (;;str++)
3663 : 622539688 : switch (*str)
3664 : : {
3665 : 105744221 : case '+': case '&' : case '=': case '*': case ' ': case '\t':
3666 : 105744221 : case '$': case '^' : case '%': case '?': case '!':
3667 : 105744221 : break;
3668 : 516795467 : default: return str;
3669 : : }
3670 : : }
3671 : :
3672 : : /* Takes a string of 0 or more comma-separated constraints. When more
3673 : : than one constraint is present, evaluate whether they all correspond
3674 : : to a single, repeated constraint (e.g. "r,r") or whether we have
3675 : : more than one distinct constraints (e.g. "r,m"). */
3676 : : static bool
3677 : 164399242 : constraint_unique (const char *cstr)
3678 : : {
3679 : 164399242 : enum constraint_num ca, cb;
3680 : 164399242 : ca = CONSTRAINT__UNKNOWN;
3681 : 324926552 : for (;;)
3682 : : {
3683 : 324926552 : cstr = skip_constraint_modifiers (cstr);
3684 : 324926552 : if (*cstr == '\0' || *cstr == ',')
3685 : : cb = CONSTRAINT_X;
3686 : : else
3687 : : {
3688 : 324926552 : cb = lookup_constraint (cstr);
3689 : 324926552 : if (cb == CONSTRAINT__UNKNOWN)
3690 : : return false;
3691 : 312673869 : cstr += CONSTRAINT_LEN (cstr[0], cstr);
3692 : : }
3693 : : /* Handle the first iteration of the loop. */
3694 : 312673869 : if (ca == CONSTRAINT__UNKNOWN)
3695 : : ca = cb;
3696 : : /* Handle the general case of comparing ca with subsequent
3697 : : constraints. */
3698 : 160395309 : else if (ca != cb)
3699 : : return false;
3700 : 168108882 : if (*cstr == '\0')
3701 : : return true;
3702 : 160527310 : if (*cstr == ',')
3703 : 88616046 : cstr += 1;
3704 : : }
3705 : : }
3706 : :
3707 : : /* Major function to make reloads for an address in operand NOP or
3708 : : check its correctness (If CHECK_ONLY_P is true). The supported
3709 : : cases are:
3710 : :
3711 : : 1) an address that existed before LRA started, at which point it
3712 : : must have been valid. These addresses are subject to elimination
3713 : : and may have become invalid due to the elimination offset being out
3714 : : of range.
3715 : :
3716 : : 2) an address created by forcing a constant to memory
3717 : : (force_const_to_mem). The initial form of these addresses might
3718 : : not be valid, and it is this function's job to make them valid.
3719 : :
3720 : : 3) a frame address formed from a register and a (possibly zero)
3721 : : constant offset. As above, these addresses might not be valid and
3722 : : this function must make them so.
3723 : :
3724 : : Add reloads to the lists *BEFORE and *AFTER. We might need to add
3725 : : reloads to *AFTER because of inc/dec, {pre, post} modify in the
3726 : : address. Return true for any RTL change.
3727 : :
3728 : : The function is a helper function which does not produce all
3729 : : transformations (when CHECK_ONLY_P is false) which can be
3730 : : necessary. It does just basic steps. To do all necessary
3731 : : transformations use function process_address. */
3732 : : static bool
3733 : 178075943 : process_address_1 (int nop, bool check_only_p,
3734 : : rtx_insn **before, rtx_insn **after)
3735 : : {
3736 : 178075943 : struct address_info ad;
3737 : 178075943 : rtx new_reg;
3738 : 178075943 : HOST_WIDE_INT scale;
3739 : 178075943 : rtx op = *curr_id->operand_loc[nop];
3740 : 178075943 : rtx mem = extract_mem_from_operand (op);
3741 : 178075943 : const char *constraint;
3742 : 178075943 : enum constraint_num cn;
3743 : 178075943 : bool change_p = false;
3744 : :
3745 : 178075943 : if (MEM_P (mem)
3746 : 38030872 : && GET_MODE (mem) == BLKmode
3747 : 25301 : && GET_CODE (XEXP (mem, 0)) == SCRATCH)
3748 : : return false;
3749 : :
3750 : 178075943 : constraint
3751 : 178075943 : = skip_constraint_modifiers (curr_static_id->operand[nop].constraint);
3752 : 178075943 : if (IN_RANGE (constraint[0], '0', '9'))
3753 : : {
3754 : 13792972 : char *end;
3755 : 13792972 : unsigned long dup = strtoul (constraint, &end, 10);
3756 : 13792972 : constraint
3757 : 13792972 : = skip_constraint_modifiers (curr_static_id->operand[dup].constraint);
3758 : : }
3759 : 189917324 : cn = lookup_constraint (*constraint == '\0' ? "X" : constraint);
3760 : : /* If we have several alternatives or/and several constraints in an
3761 : : alternative and we can not say at this stage what constraint will be used,
3762 : : use unknown constraint. The exception is an address constraint. If
3763 : : operand has one address constraint, probably all others constraints are
3764 : : address ones. */
3765 : 166234562 : if (constraint[0] != '\0' && get_constraint_type (cn) != CT_ADDRESS
3766 : 342475185 : && !constraint_unique (constraint))
3767 : : cn = CONSTRAINT__UNKNOWN;
3768 : 21258273 : if (insn_extra_address_constraint (cn)
3769 : : /* When we find an asm operand with an address constraint that
3770 : : doesn't satisfy address_operand to begin with, we clear
3771 : : is_address, so that we don't try to make a non-address fit.
3772 : : If the asm statement got this far, it's because other
3773 : : constraints are available, and we'll use them, disregarding
3774 : : the unsatisfiable address ones. */
3775 : 21258273 : && curr_static_id->operand[nop].is_address)
3776 : 1835301 : decompose_lea_address (&ad, curr_id->operand_loc[nop]);
3777 : : /* Do not attempt to decompose arbitrary addresses generated by combine
3778 : : for asm operands with loose constraints, e.g 'X'.
3779 : : Need to extract memory from op for special memory constraint,
3780 : : i.e. bcst_mem_operand in i386 backend. */
3781 : 176240642 : else if (MEM_P (mem)
3782 : 176240897 : && !(INSN_CODE (curr_insn) < 0
3783 : 18727 : && get_constraint_type (cn) == CT_FIXED_FORM
3784 : 255 : && constraint_satisfied_p (op, cn)))
3785 : 38030617 : decompose_mem_address (&ad, mem);
3786 : 138210025 : else if (GET_CODE (op) == SUBREG
3787 : 3601814 : && MEM_P (SUBREG_REG (op)))
3788 : 0 : decompose_mem_address (&ad, SUBREG_REG (op));
3789 : : else
3790 : : return false;
3791 : : /* If INDEX_REG_CLASS is assigned to base_term already and isn't to
3792 : : index_term, swap them so to avoid assigning INDEX_REG_CLASS to both
3793 : : when INDEX_REG_CLASS is a single register class. */
3794 : 39865918 : enum reg_class index_cl = index_reg_class (curr_insn);
3795 : 39865918 : if (ad.base_term != NULL
3796 : 33635867 : && ad.index_term != NULL
3797 : 1499006 : && ira_class_hard_regs_num[index_cl] == 1
3798 : 0 : && REG_P (*ad.base_term)
3799 : 0 : && REG_P (*ad.index_term)
3800 : 0 : && in_class_p (*ad.base_term, index_cl, NULL)
3801 : 39865918 : && ! in_class_p (*ad.index_term, index_cl, NULL))
3802 : : {
3803 : 0 : std::swap (ad.base, ad.index);
3804 : 0 : std::swap (ad.base_term, ad.index_term);
3805 : : }
3806 : 39865918 : if (! check_only_p)
3807 : 39859178 : change_p = equiv_address_substitution (&ad);
3808 : 39865918 : if (ad.base_term != NULL
3809 : 73501785 : && (process_addr_reg
3810 : 67271734 : (ad.base_term, check_only_p, before,
3811 : 33635867 : (ad.autoinc_p
3812 : 4154962 : && !(REG_P (*ad.base_term)
3813 : 2077481 : && find_regno_note (curr_insn, REG_DEAD,
3814 : : REGNO (*ad.base_term)) != NULL_RTX)
3815 : : ? after : NULL),
3816 : 33635867 : base_reg_class (ad.mode, ad.as, ad.base_outer_code,
3817 : : get_index_code (&ad), curr_insn))))
3818 : : {
3819 : 443740 : change_p = true;
3820 : 443740 : if (ad.base_term2 != NULL)
3821 : 0 : *ad.base_term2 = *ad.base_term;
3822 : : }
3823 : 39865918 : if (ad.index_term != NULL
3824 : 39865918 : && process_addr_reg (ad.index_term, check_only_p,
3825 : : before, NULL, index_cl))
3826 : : change_p = true;
3827 : :
3828 : : /* Target hooks sometimes don't treat extra-constraint addresses as
3829 : : legitimate address_operands, so handle them specially. */
3830 : 39865918 : if (insn_extra_address_constraint (cn)
3831 : 39865918 : && satisfies_address_constraint_p (&ad, cn))
3832 : : return change_p;
3833 : :
3834 : 38030624 : if (check_only_p)
3835 : : return change_p;
3836 : :
3837 : : /* There are three cases where the shape of *AD.INNER may now be invalid:
3838 : :
3839 : : 1) the original address was valid, but either elimination or
3840 : : equiv_address_substitution was applied and that made
3841 : : the address invalid.
3842 : :
3843 : : 2) the address is an invalid symbolic address created by
3844 : : force_const_to_mem.
3845 : :
3846 : : 3) the address is a frame address with an invalid offset.
3847 : :
3848 : : 4) the address is a frame address with an invalid base.
3849 : :
3850 : : All these cases involve a non-autoinc address, so there is no
3851 : : point revalidating other types. */
3852 : 38024481 : if (ad.autoinc_p || valid_address_p (op, &ad, cn))
3853 : 38024036 : return change_p;
3854 : :
3855 : : /* Any index existed before LRA started, so we can assume that the
3856 : : presence and shape of the index is valid. */
3857 : 445 : push_to_sequence (*before);
3858 : 445 : lra_assert (ad.disp == ad.disp_term);
3859 : 445 : if (ad.base == NULL)
3860 : : {
3861 : 353 : if (ad.index == NULL)
3862 : : {
3863 : 353 : rtx_insn *insn;
3864 : 353 : rtx_insn *last = get_last_insn ();
3865 : 353 : int code = -1;
3866 : 353 : enum reg_class cl = base_reg_class (ad.mode, ad.as,
3867 : : SCRATCH, SCRATCH,
3868 : : curr_insn);
3869 : 353 : rtx addr = *ad.inner;
3870 : :
3871 : 697 : new_reg = lra_create_new_reg (Pmode, NULL_RTX, cl, NULL, "addr");
3872 : 353 : if (HAVE_lo_sum)
3873 : : {
3874 : : /* addr => lo_sum (new_base, addr), case (2) above. */
3875 : : insn = emit_insn (gen_rtx_SET
3876 : : (new_reg,
3877 : : gen_rtx_HIGH (Pmode, copy_rtx (addr))));
3878 : : code = recog_memoized (insn);
3879 : : if (code >= 0)
3880 : : {
3881 : : *ad.inner = gen_rtx_LO_SUM (Pmode, new_reg, addr);
3882 : : if (!valid_address_p (op, &ad, cn))
3883 : : {
3884 : : /* Try to put lo_sum into register. */
3885 : : insn = emit_insn (gen_rtx_SET
3886 : : (new_reg,
3887 : : gen_rtx_LO_SUM (Pmode, new_reg, addr)));
3888 : : code = recog_memoized (insn);
3889 : : if (code >= 0)
3890 : : {
3891 : : *ad.inner = new_reg;
3892 : : if (!valid_address_p (op, &ad, cn))
3893 : : {
3894 : : *ad.inner = addr;
3895 : : code = -1;
3896 : : }
3897 : : }
3898 : :
3899 : : }
3900 : : }
3901 : : if (code < 0)
3902 : : delete_insns_since (last);
3903 : : }
3904 : :
3905 : 353 : if (code < 0)
3906 : : {
3907 : : /* addr => new_base, case (2) above. */
3908 : 353 : lra_emit_move (new_reg, addr);
3909 : :
3910 : 706 : for (insn = last == NULL_RTX ? get_insns () : NEXT_INSN (last);
3911 : 706 : insn != NULL_RTX;
3912 : 353 : insn = NEXT_INSN (insn))
3913 : 353 : if (recog_memoized (insn) < 0)
3914 : : break;
3915 : 353 : if (insn != NULL_RTX)
3916 : : {
3917 : : /* Do nothing if we cannot generate right insns.
3918 : : This is analogous to reload pass behavior. */
3919 : 0 : delete_insns_since (last);
3920 : 0 : end_sequence ();
3921 : 0 : return false;
3922 : : }
3923 : 353 : *ad.inner = new_reg;
3924 : : }
3925 : : }
3926 : : else
3927 : : {
3928 : : /* index * scale + disp => new base + index * scale,
3929 : : case (1) above. */
3930 : 0 : enum reg_class cl = base_reg_class (ad.mode, ad.as, PLUS,
3931 : 0 : GET_CODE (*ad.index),
3932 : : curr_insn);
3933 : :
3934 : 0 : lra_assert (index_cl != NO_REGS);
3935 : 0 : new_reg = lra_create_new_reg (Pmode, NULL_RTX, cl, NULL, "disp");
3936 : 0 : lra_emit_move (new_reg, *ad.disp);
3937 : 0 : *ad.inner = simplify_gen_binary (PLUS, GET_MODE (new_reg),
3938 : 0 : new_reg, *ad.index);
3939 : : }
3940 : : }
3941 : 92 : else if (ad.index == NULL)
3942 : : {
3943 : 53 : int regno;
3944 : 53 : enum reg_class cl;
3945 : 53 : rtx set;
3946 : 53 : rtx_insn *insns, *last_insn;
3947 : :
3948 : 53 : cl = base_reg_class (ad.mode, ad.as, ad.base_outer_code,
3949 : : get_index_code (&ad), curr_insn);
3950 : :
3951 : 53 : if (REG_P (*ad.base_term)
3952 : 53 : && ira_class_subset_p[get_reg_class (REGNO (*ad.base_term))][cl])
3953 : : /* It seems base reg is already in the base reg class and changing it
3954 : : does not make a progress. So reload the whole inner address. */
3955 : 53 : goto reload_inner_addr;
3956 : :
3957 : : /* Try to reload base into register only if the base is invalid
3958 : : for the address but with valid offset, case (4) above. */
3959 : 0 : start_sequence ();
3960 : 0 : new_reg = base_to_reg (&ad);
3961 : :
3962 : : /* base + disp => new base, cases (1) and (3) above. */
3963 : : /* Another option would be to reload the displacement into an
3964 : : index register. However, postreload has code to optimize
3965 : : address reloads that have the same base and different
3966 : : displacements, so reloading into an index register would
3967 : : not necessarily be a win. */
3968 : 0 : if (new_reg == NULL_RTX)
3969 : : {
3970 : : /* See if the target can split the displacement into a
3971 : : legitimate new displacement from a local anchor. */
3972 : 0 : gcc_assert (ad.disp == ad.disp_term);
3973 : 0 : poly_int64 orig_offset;
3974 : 0 : rtx offset1, offset2;
3975 : 0 : if (poly_int_rtx_p (*ad.disp, &orig_offset)
3976 : 0 : && targetm.legitimize_address_displacement (&offset1, &offset2,
3977 : : orig_offset,
3978 : : ad.mode))
3979 : : {
3980 : 0 : new_reg = base_plus_disp_to_reg (&ad, offset1);
3981 : 0 : new_reg = gen_rtx_PLUS (GET_MODE (new_reg), new_reg, offset2);
3982 : : }
3983 : : else
3984 : 0 : new_reg = base_plus_disp_to_reg (&ad, *ad.disp);
3985 : : }
3986 : 0 : insns = get_insns ();
3987 : 0 : last_insn = get_last_insn ();
3988 : : /* If we generated at least two insns, try last insn source as
3989 : : an address. If we succeed, we generate one less insn. */
3990 : 0 : if (REG_P (new_reg)
3991 : 0 : && last_insn != insns
3992 : 0 : && (set = single_set (last_insn)) != NULL_RTX
3993 : 0 : && GET_CODE (SET_SRC (set)) == PLUS
3994 : 0 : && REG_P (XEXP (SET_SRC (set), 0))
3995 : 0 : && CONSTANT_P (XEXP (SET_SRC (set), 1)))
3996 : : {
3997 : 0 : *ad.inner = SET_SRC (set);
3998 : 0 : if (valid_address_p (op, &ad, cn))
3999 : : {
4000 : 0 : *ad.base_term = XEXP (SET_SRC (set), 0);
4001 : 0 : *ad.disp_term = XEXP (SET_SRC (set), 1);
4002 : 0 : regno = REGNO (*ad.base_term);
4003 : 0 : if (regno >= FIRST_PSEUDO_REGISTER
4004 : 0 : && cl != lra_get_allocno_class (regno))
4005 : 0 : lra_change_class (regno, cl, " Change to", true);
4006 : 0 : new_reg = SET_SRC (set);
4007 : 0 : delete_insns_since (PREV_INSN (last_insn));
4008 : : }
4009 : : }
4010 : 0 : end_sequence ();
4011 : 0 : emit_insn (insns);
4012 : 0 : *ad.inner = new_reg;
4013 : : }
4014 : 39 : else if (ad.disp_term != NULL)
4015 : : {
4016 : : /* base + scale * index + disp => new base + scale * index,
4017 : : case (1) above. */
4018 : 39 : gcc_assert (ad.disp == ad.disp_term);
4019 : 39 : new_reg = base_plus_disp_to_reg (&ad, *ad.disp);
4020 : 39 : *ad.inner = simplify_gen_binary (PLUS, GET_MODE (new_reg),
4021 : 39 : new_reg, *ad.index);
4022 : : }
4023 : 0 : else if ((scale = get_index_scale (&ad)) == 1)
4024 : : {
4025 : : /* The last transformation to one reg will be made in
4026 : : curr_insn_transform function. */
4027 : 0 : end_sequence ();
4028 : 0 : return false;
4029 : : }
4030 : 0 : else if (scale != 0)
4031 : : {
4032 : : /* base + scale * index => base + new_reg,
4033 : : case (1) above.
4034 : : Index part of address may become invalid. For example, we
4035 : : changed pseudo on the equivalent memory and a subreg of the
4036 : : pseudo onto the memory of different mode for which the scale is
4037 : : prohibitted. */
4038 : 0 : new_reg = index_part_to_reg (&ad, index_cl);
4039 : 0 : *ad.inner = simplify_gen_binary (PLUS, GET_MODE (new_reg),
4040 : 0 : *ad.base_term, new_reg);
4041 : : }
4042 : : else
4043 : : {
4044 : 53 : enum reg_class cl;
4045 : 53 : rtx addr;
4046 : 0 : reload_inner_addr:
4047 : 53 : cl = base_reg_class (ad.mode, ad.as, SCRATCH, SCRATCH, curr_insn);
4048 : 53 : addr = *ad.inner;
4049 : 53 : new_reg = lra_create_new_reg (Pmode, NULL_RTX, cl, NULL, "addr");
4050 : : /* addr => new_base. */
4051 : 53 : lra_emit_move (new_reg, addr);
4052 : 53 : *ad.inner = new_reg;
4053 : : }
4054 : 445 : *before = end_sequence ();
4055 : 445 : return true;
4056 : : }
4057 : :
4058 : : /* If CHECK_ONLY_P is false, do address reloads until it is necessary.
4059 : : Use process_address_1 as a helper function. Return true for any
4060 : : RTL changes.
4061 : :
4062 : : If CHECK_ONLY_P is true, just check address correctness. Return
4063 : : false if the address correct. */
4064 : : static bool
4065 : 177584832 : process_address (int nop, bool check_only_p,
4066 : : rtx_insn **before, rtx_insn **after)
4067 : : {
4068 : 177584832 : bool res = false;
4069 : : /* Use enough iterations to process all address parts: */
4070 : 178075943 : for (int i = 0; i < 10; i++)
4071 : : {
4072 : 178075943 : if (!process_address_1 (nop, check_only_p, before, after))
4073 : : {
4074 : : return res;
4075 : : }
4076 : : else
4077 : : {
4078 : 491111 : if (check_only_p)
4079 : : return true;
4080 : 491111 : res = true;
4081 : : }
4082 : : }
4083 : 0 : fatal_insn ("unable to reload address in ", curr_insn);
4084 : : }
4085 : :
4086 : : /* Override the generic address_reload_context in order to
4087 : : control the creation of reload pseudos. */
4088 : : class lra_autoinc_reload_context : public address_reload_context
4089 : : {
4090 : : machine_mode mode;
4091 : : enum reg_class rclass;
4092 : :
4093 : : public:
4094 : 0 : lra_autoinc_reload_context (machine_mode mode, enum reg_class new_rclass)
4095 : 0 : : mode (mode), rclass (new_rclass) {}
4096 : :
4097 : 0 : rtx get_reload_reg () const override final
4098 : : {
4099 : 0 : return lra_create_new_reg (mode, NULL_RTX, rclass, NULL, "INC/DEC result");
4100 : : }
4101 : : };
4102 : :
4103 : : /* Emit insns to reload VALUE into a new register. VALUE is an
4104 : : auto-increment or auto-decrement RTX whose operand is a register or
4105 : : memory location; so reloading involves incrementing that location.
4106 : :
4107 : : INC_AMOUNT is the number to increment or decrement by (always
4108 : : positive and ignored for POST_MODIFY/PRE_MODIFY).
4109 : :
4110 : : Return a pseudo containing the result. */
4111 : : static rtx
4112 : 0 : emit_inc (enum reg_class new_rclass, rtx value, poly_int64 inc_amount)
4113 : : {
4114 : 0 : lra_autoinc_reload_context context (GET_MODE (value), new_rclass);
4115 : 0 : return context.emit_autoinc (value, inc_amount);
4116 : : }
4117 : :
4118 : : /* Return true if the current move insn does not need processing as we
4119 : : already know that it satisfies its constraints. */
4120 : : static bool
4121 : 101945012 : simple_move_p (void)
4122 : : {
4123 : 101945012 : rtx dest, src;
4124 : 101945012 : enum reg_class dclass, sclass;
4125 : :
4126 : 101945012 : lra_assert (curr_insn_set != NULL_RTX);
4127 : 101945012 : dest = SET_DEST (curr_insn_set);
4128 : 101945012 : src = SET_SRC (curr_insn_set);
4129 : :
4130 : : /* If the instruction has multiple sets we need to process it even if it
4131 : : is single_set. This can happen if one or more of the SETs are dead.
4132 : : See PR73650. */
4133 : 101945012 : if (multiple_sets (curr_insn))
4134 : : return false;
4135 : :
4136 : 101759071 : return ((dclass = get_op_class (dest)) != NO_REGS
4137 : 21394838 : && (sclass = get_op_class (src)) != NO_REGS
4138 : : /* The backend guarantees that register moves of cost 2
4139 : : never need reloads. */
4140 : 90847216 : && targetm.register_move_cost (GET_MODE (src), sclass, dclass) == 2);
4141 : : }
4142 : :
4143 : : /* Swap operands NOP and NOP + 1. */
4144 : : static inline void
4145 : 21611072 : swap_operands (int nop)
4146 : : {
4147 : 21611072 : std::swap (curr_operand_mode[nop], curr_operand_mode[nop + 1]);
4148 : 21611072 : std::swap (original_subreg_reg_mode[nop], original_subreg_reg_mode[nop + 1]);
4149 : 21611072 : std::swap (*curr_id->operand_loc[nop], *curr_id->operand_loc[nop + 1]);
4150 : 21611072 : std::swap (equiv_substition_p[nop], equiv_substition_p[nop + 1]);
4151 : : /* Swap the duplicates too. */
4152 : 21611072 : lra_update_dup (curr_id, nop);
4153 : 21611072 : lra_update_dup (curr_id, nop + 1);
4154 : 21611072 : }
4155 : :
4156 : : /* Return TRUE if X is a (subreg of) reg and there are no hard regs of X class
4157 : : which can contain value of MODE. */
4158 : 32 : static bool invalid_mode_reg_p (enum machine_mode mode, rtx x)
4159 : : {
4160 : 32 : if (SUBREG_P (x))
4161 : 1 : x = SUBREG_REG (x);
4162 : 32 : if (! REG_P (x))
4163 : : return false;
4164 : 32 : enum reg_class rclass = get_reg_class (REGNO (x));
4165 : 32 : return (!hard_reg_set_empty_p (reg_class_contents[rclass])
4166 : 32 : && hard_reg_set_subset_p
4167 : 32 : (reg_class_contents[rclass],
4168 : 32 : ira_prohibited_class_mode_regs[rclass][mode]));
4169 : : }
4170 : :
4171 : : /* Return TRUE if regno is referenced in more than one non-debug insn. */
4172 : : static bool
4173 : 2950844 : multiple_insn_refs_p (int regno)
4174 : : {
4175 : 2950844 : unsigned int uid;
4176 : 2950844 : bitmap_iterator bi;
4177 : 2950844 : int nrefs = 0;
4178 : 7039323 : EXECUTE_IF_SET_IN_BITMAP (&lra_reg_info[regno].insn_bitmap, 0, uid, bi)
4179 : : {
4180 : 7033702 : if (!NONDEBUG_INSN_P (lra_insn_recog_data[uid]->insn))
4181 : 1137635 : continue;
4182 : 5896067 : if (nrefs == 1)
4183 : : return true;
4184 : 2950844 : nrefs++;
4185 : : }
4186 : : return false;
4187 : : }
4188 : :
4189 : : /* Main entry point of the constraint code: search the body of the
4190 : : current insn to choose the best alternative. It is mimicking insn
4191 : : alternative cost calculation model of former reload pass. That is
4192 : : because machine descriptions were written to use this model. This
4193 : : model can be changed in future. Make commutative operand exchange
4194 : : if it is chosen.
4195 : :
4196 : : if CHECK_ONLY_P is false, do RTL changes to satisfy the
4197 : : constraints. Return true if any change happened during function
4198 : : call.
4199 : :
4200 : : If CHECK_ONLY_P is true then don't do any transformation. Just
4201 : : check that the insn satisfies all constraints. If the insn does
4202 : : not satisfy any constraint, return true. */
4203 : : static bool
4204 : 107316690 : curr_insn_transform (bool check_only_p)
4205 : : {
4206 : 107316690 : int i, j, k;
4207 : 107316690 : int n_operands;
4208 : 107316690 : int n_alternatives;
4209 : 107316690 : int n_outputs;
4210 : 107316690 : int commutative;
4211 : 107316690 : signed char goal_alt_matched[MAX_RECOG_OPERANDS][MAX_RECOG_OPERANDS];
4212 : 107316690 : signed char match_inputs[MAX_RECOG_OPERANDS + 1];
4213 : 107316690 : signed char outputs[MAX_RECOG_OPERANDS + 1];
4214 : 107316690 : rtx_insn *before, *after;
4215 : 107316690 : bool alt_p = false;
4216 : : /* Flag that the insn has been changed through a transformation. */
4217 : 107316690 : bool change_p;
4218 : 107316690 : bool sec_mem_p;
4219 : 107316690 : bool use_sec_mem_p;
4220 : 107316690 : int max_regno_before;
4221 : 107316690 : int reused_alternative_num;
4222 : :
4223 : 107316690 : curr_insn_set = single_set (curr_insn);
4224 : 107316690 : if (curr_insn_set != NULL_RTX && simple_move_p ())
4225 : : {
4226 : : /* We assume that the corresponding insn alternative has no
4227 : : earlier clobbers. If it is not the case, don't define move
4228 : : cost equal to 2 for the corresponding register classes. */
4229 : 16436905 : lra_set_used_insn_alternative (curr_insn, LRA_NON_CLOBBERED_ALT);
4230 : 16436905 : return false;
4231 : : }
4232 : :
4233 : 90879785 : no_input_reloads_p = no_output_reloads_p = false;
4234 : 90879785 : goal_alt_number = -1;
4235 : 90879785 : change_p = sec_mem_p = false;
4236 : :
4237 : : /* CALL_INSNs are not allowed to have any output reloads. */
4238 : 90879785 : if (CALL_P (curr_insn))
4239 : 5984966 : no_output_reloads_p = true;
4240 : :
4241 : 90879785 : n_operands = curr_static_id->n_operands;
4242 : 90879785 : n_alternatives = curr_static_id->n_alternatives;
4243 : :
4244 : : /* Just return "no reloads" if insn has no operands with
4245 : : constraints. */
4246 : 90879785 : if (n_operands == 0 || n_alternatives == 0)
4247 : : return false;
4248 : :
4249 : 80287656 : max_regno_before = max_reg_num ();
4250 : :
4251 : 339431160 : for (i = 0; i < n_operands; i++)
4252 : : {
4253 : 178855848 : goal_alt_matched[i][0] = -1;
4254 : 178855848 : goal_alt_matches[i] = -1;
4255 : : }
4256 : :
4257 : 80287656 : commutative = curr_static_id->commutative;
4258 : :
4259 : : /* Now see what we need for pseudos that didn't get hard regs or got
4260 : : the wrong kind of hard reg. For this, we must consider all the
4261 : : operands together against the register constraints. */
4262 : :
4263 : 80287656 : best_losers = best_overall = INT_MAX;
4264 : 80287656 : best_reload_sum = 0;
4265 : :
4266 : 80287656 : curr_swapped = false;
4267 : 80287656 : goal_alt_swapped = false;
4268 : :
4269 : 80287656 : if (! check_only_p)
4270 : : /* Make equivalence substitution and memory subreg elimination
4271 : : before address processing because an address legitimacy can
4272 : : depend on memory mode. */
4273 : 259076360 : for (i = 0; i < n_operands; i++)
4274 : : {
4275 : 178807513 : rtx op, subst, old;
4276 : 178807513 : bool op_change_p = false;
4277 : :
4278 : 178807513 : if (curr_static_id->operand[i].is_operator)
4279 : 1418573 : continue;
4280 : :
4281 : 177388940 : old = op = *curr_id->operand_loc[i];
4282 : 177388940 : if (GET_CODE (old) == SUBREG)
4283 : 3657784 : old = SUBREG_REG (old);
4284 : 177388940 : subst = get_equiv_with_elimination (old, curr_insn);
4285 : 177388940 : original_subreg_reg_mode[i] = VOIDmode;
4286 : 177388940 : equiv_substition_p[i] = false;
4287 : 177388940 : if (subst != old)
4288 : : {
4289 : 1569875 : equiv_substition_p[i] = true;
4290 : 1569875 : subst = copy_rtx (subst);
4291 : 1569875 : lra_assert (REG_P (old));
4292 : 1569875 : if (GET_CODE (op) != SUBREG)
4293 : 1514271 : *curr_id->operand_loc[i] = subst;
4294 : : else
4295 : : {
4296 : 55604 : SUBREG_REG (op) = subst;
4297 : 55604 : if (GET_MODE (subst) == VOIDmode)
4298 : 82 : original_subreg_reg_mode[i] = GET_MODE (old);
4299 : : }
4300 : 1569875 : if (lra_dump_file != NULL)
4301 : : {
4302 : 3 : fprintf (lra_dump_file,
4303 : : "Changing pseudo %d in operand %i of insn %u on equiv ",
4304 : 3 : REGNO (old), i, INSN_UID (curr_insn));
4305 : 3 : dump_value_slim (lra_dump_file, subst, 1);
4306 : 3 : fprintf (lra_dump_file, "\n");
4307 : : }
4308 : 1569875 : op_change_p = change_p = true;
4309 : : }
4310 : 177388940 : if (simplify_operand_subreg (i, GET_MODE (old)) || op_change_p)
4311 : : {
4312 : 1570396 : change_p = true;
4313 : 1570396 : lra_update_dup (curr_id, i);
4314 : : }
4315 : : }
4316 : :
4317 : : /* Reload address registers and displacements. We do it before
4318 : : finding an alternative because of memory constraints. */
4319 : 80287656 : before = after = NULL;
4320 : 259143504 : for (i = 0; i < n_operands; i++)
4321 : 178855848 : if (! curr_static_id->operand[i].is_operator
4322 : 178855848 : && process_address (i, check_only_p, &before, &after))
4323 : : {
4324 : 491108 : if (check_only_p)
4325 : : return true;
4326 : 491108 : change_p = true;
4327 : 491108 : lra_update_dup (curr_id, i);
4328 : : }
4329 : :
4330 : 80287656 : if (change_p)
4331 : : /* If we've changed the instruction then any alternative that
4332 : : we chose previously may no longer be valid. */
4333 : 2014489 : lra_set_used_insn_alternative (curr_insn, LRA_UNKNOWN_ALT);
4334 : :
4335 : 80268847 : if (! check_only_p && curr_insn_set != NULL_RTX
4336 : 156734381 : && check_and_process_move (&change_p, &sec_mem_p))
4337 : 0 : return change_p;
4338 : :
4339 : 80287656 : try_swapped:
4340 : :
4341 : 90792942 : reused_alternative_num = check_only_p ? LRA_UNKNOWN_ALT : curr_id->used_insn_alternative;
4342 : 90792942 : if (lra_dump_file != NULL && reused_alternative_num >= 0)
4343 : 0 : fprintf (lra_dump_file, "Reusing alternative %d for insn #%u\n",
4344 : 0 : reused_alternative_num, INSN_UID (curr_insn));
4345 : :
4346 : 90792942 : if (process_alt_operands (reused_alternative_num))
4347 : 82058392 : alt_p = true;
4348 : :
4349 : 90792942 : if (check_only_p)
4350 : 31738 : return ! alt_p || best_losers != 0;
4351 : :
4352 : : /* If insn is commutative (it's safe to exchange a certain pair of
4353 : : operands) then we need to try each alternative twice, the second
4354 : : time matching those two operands as if we had exchanged them. To
4355 : : do this, really exchange them in operands.
4356 : :
4357 : : If we have just tried the alternatives the second time, return
4358 : : operands to normal and drop through. */
4359 : :
4360 : 90774133 : if (reused_alternative_num < 0 && commutative >= 0)
4361 : : {
4362 : 21010572 : curr_swapped = !curr_swapped;
4363 : 21010572 : if (curr_swapped)
4364 : : {
4365 : 10505286 : swap_operands (commutative);
4366 : 10505286 : goto try_swapped;
4367 : : }
4368 : : else
4369 : 10505286 : swap_operands (commutative);
4370 : : }
4371 : :
4372 : 80268847 : if (! alt_p && ! sec_mem_p)
4373 : : {
4374 : : /* No alternative works with reloads?? */
4375 : 6 : if (INSN_CODE (curr_insn) >= 0)
4376 : 0 : fatal_insn ("unable to generate reloads for:", curr_insn);
4377 : 6 : error_for_asm (curr_insn,
4378 : : "inconsistent operand constraints in an %<asm%>");
4379 : 6 : lra_asm_error_p = true;
4380 : 6 : if (! JUMP_P (curr_insn))
4381 : : {
4382 : : /* Avoid further trouble with this insn. Don't generate use
4383 : : pattern here as we could use the insn SP offset. */
4384 : 6 : lra_set_insn_deleted (curr_insn);
4385 : : }
4386 : : else
4387 : : {
4388 : 0 : lra_invalidate_insn_data (curr_insn);
4389 : 0 : ira_nullify_asm_goto (curr_insn);
4390 : 0 : lra_update_insn_regno_info (curr_insn);
4391 : : }
4392 : 6 : return true;
4393 : : }
4394 : :
4395 : : /* If the best alternative is with operands 1 and 2 swapped, swap
4396 : : them. Update the operand numbers of any reloads already
4397 : : pushed. */
4398 : :
4399 : 80268841 : if (goal_alt_swapped)
4400 : : {
4401 : 596040 : if (lra_dump_file != NULL)
4402 : 18 : fprintf (lra_dump_file, " Commutative operand exchange in insn %u\n",
4403 : 18 : INSN_UID (curr_insn));
4404 : :
4405 : : /* Swap the duplicates too. */
4406 : 596040 : swap_operands (commutative);
4407 : 596040 : change_p = true;
4408 : : }
4409 : :
4410 : : /* Some targets' TARGET_SECONDARY_MEMORY_NEEDED (e.g. x86) are defined
4411 : : too conservatively. So we use the secondary memory only if there
4412 : : is no any alternative without reloads. */
4413 : 80268841 : use_sec_mem_p = false;
4414 : 80268841 : if (! alt_p)
4415 : : use_sec_mem_p = true;
4416 : 80268841 : else if (sec_mem_p)
4417 : : {
4418 : 16507 : for (i = 0; i < n_operands; i++)
4419 : 15907 : if (! goal_alt_win[i] && ! goal_alt_match_win[i])
4420 : : break;
4421 : 13905 : use_sec_mem_p = i < n_operands;
4422 : : }
4423 : :
4424 : 13905 : if (use_sec_mem_p)
4425 : : {
4426 : 13305 : int in = -1, out = -1;
4427 : 13305 : rtx new_reg, src, dest, rld;
4428 : 13305 : machine_mode sec_mode, rld_mode;
4429 : :
4430 : 13305 : lra_assert (curr_insn_set != NULL_RTX && sec_mem_p);
4431 : 13305 : dest = SET_DEST (curr_insn_set);
4432 : 13305 : src = SET_SRC (curr_insn_set);
4433 : 39915 : for (i = 0; i < n_operands; i++)
4434 : 26610 : if (*curr_id->operand_loc[i] == dest)
4435 : : out = i;
4436 : 13305 : else if (*curr_id->operand_loc[i] == src)
4437 : 13305 : in = i;
4438 : 13305 : for (i = 0; i < curr_static_id->n_dups; i++)
4439 : 0 : if (out < 0 && *curr_id->dup_loc[i] == dest)
4440 : 0 : out = curr_static_id->dup_num[i];
4441 : 0 : else if (in < 0 && *curr_id->dup_loc[i] == src)
4442 : 0 : in = curr_static_id->dup_num[i];
4443 : 13305 : lra_assert (out >= 0 && in >= 0
4444 : : && curr_static_id->operand[out].type == OP_OUT
4445 : : && curr_static_id->operand[in].type == OP_IN);
4446 : 13305 : rld = partial_subreg_p (GET_MODE (src), GET_MODE (dest)) ? src : dest;
4447 : 13305 : rld_mode = GET_MODE (rld);
4448 : 13305 : sec_mode = targetm.secondary_memory_needed_mode (rld_mode);
4449 : 13305 : if (rld_mode != sec_mode
4450 : 13305 : && (invalid_mode_reg_p (sec_mode, dest)
4451 : 16 : || invalid_mode_reg_p (sec_mode, src)))
4452 : : sec_mode = rld_mode;
4453 : 13305 : new_reg = lra_create_new_reg (sec_mode, NULL_RTX, NO_REGS, NULL,
4454 : : "secondary");
4455 : : /* If the mode is changed, it should be wider. */
4456 : 13305 : lra_assert (!partial_subreg_p (sec_mode, rld_mode));
4457 : 13305 : if (sec_mode != rld_mode)
4458 : : {
4459 : : /* If the target says specifically to use another mode for
4460 : : secondary memory moves we cannot reuse the original
4461 : : insn. */
4462 : 16 : after = emit_spill_move (false, new_reg, dest);
4463 : 16 : lra_process_new_insns (curr_insn, NULL, after,
4464 : : "Inserting the sec. move");
4465 : : /* We may have non null BEFORE here (e.g. after address
4466 : : processing. */
4467 : 16 : push_to_sequence (before);
4468 : 16 : before = emit_spill_move (true, new_reg, src);
4469 : 16 : emit_insn (before);
4470 : 16 : before = end_sequence ();
4471 : 16 : lra_process_new_insns (curr_insn, before, NULL, "Changing on");
4472 : 16 : lra_set_insn_deleted (curr_insn);
4473 : : }
4474 : 13289 : else if (dest == rld)
4475 : : {
4476 : 13289 : *curr_id->operand_loc[out] = new_reg;
4477 : 13289 : lra_update_dup (curr_id, out);
4478 : 13289 : after = emit_spill_move (false, new_reg, dest);
4479 : 13289 : lra_process_new_insns (curr_insn, NULL, after,
4480 : : "Inserting the sec. move");
4481 : : }
4482 : : else
4483 : : {
4484 : 0 : *curr_id->operand_loc[in] = new_reg;
4485 : 0 : lra_update_dup (curr_id, in);
4486 : : /* See comments above. */
4487 : 0 : push_to_sequence (before);
4488 : 0 : before = emit_spill_move (true, new_reg, src);
4489 : 0 : emit_insn (before);
4490 : 0 : before = end_sequence ();
4491 : 0 : lra_process_new_insns (curr_insn, before, NULL,
4492 : : "Inserting the sec. move");
4493 : : }
4494 : 13305 : lra_update_insn_regno_info (curr_insn);
4495 : 13305 : return true;
4496 : : }
4497 : :
4498 : 80255536 : lra_assert (goal_alt_number >= 0);
4499 : 160417041 : lra_set_used_insn_alternative (curr_insn, goal_reuse_alt_p
4500 : : ? goal_alt_number : LRA_UNKNOWN_ALT);
4501 : :
4502 : 80255536 : if (lra_dump_file != NULL)
4503 : : {
4504 : 1196 : const char *p;
4505 : :
4506 : 1196 : fprintf (lra_dump_file, " Choosing alt %d in insn %u:",
4507 : 1196 : goal_alt_number, INSN_UID (curr_insn));
4508 : 1196 : print_curr_insn_alt (goal_alt_number);
4509 : 1196 : if (INSN_CODE (curr_insn) >= 0
4510 : 1196 : && (p = get_insn_name (INSN_CODE (curr_insn))) != NULL)
4511 : 1189 : fprintf (lra_dump_file, " {%s}", p);
4512 : 1196 : if (maybe_ne (curr_id->sp_offset, 0))
4513 : : {
4514 : 0 : fprintf (lra_dump_file, " (sp_off=");
4515 : 0 : print_dec (curr_id->sp_offset, lra_dump_file);
4516 : 0 : fprintf (lra_dump_file, ")");
4517 : : }
4518 : 1196 : fprintf (lra_dump_file, "\n");
4519 : : }
4520 : :
4521 : : /* Right now, for any pair of operands I and J that are required to
4522 : : match, with J < I, goal_alt_matches[I] is J. Add I to
4523 : : goal_alt_matched[J]. */
4524 : :
4525 : 259036425 : for (i = 0; i < n_operands; i++)
4526 : 178780889 : if ((j = goal_alt_matches[i]) >= 0)
4527 : : {
4528 : 10543959 : for (k = 0; goal_alt_matched[j][k] >= 0; k++)
4529 : : ;
4530 : : /* We allow matching one output operand and several input
4531 : : operands. */
4532 : 10543958 : lra_assert (k == 0
4533 : : || (curr_static_id->operand[j].type == OP_OUT
4534 : : && curr_static_id->operand[i].type == OP_IN
4535 : : && (curr_static_id->operand
4536 : : [goal_alt_matched[j][0]].type == OP_IN)));
4537 : 10543958 : goal_alt_matched[j][k] = i;
4538 : 10543958 : goal_alt_matched[j][k + 1] = -1;
4539 : : }
4540 : :
4541 : 259036425 : for (i = 0; i < n_operands; i++)
4542 : 178780889 : goal_alt_win[i] |= goal_alt_match_win[i];
4543 : :
4544 : : /* Any constants that aren't allowed and can't be reloaded into
4545 : : registers are here changed into memory references. */
4546 : 259036425 : for (i = 0; i < n_operands; i++)
4547 : 178780889 : if (goal_alt_win[i])
4548 : : {
4549 : 172624591 : int regno;
4550 : 172624591 : enum reg_class new_class;
4551 : 172624591 : rtx reg = *curr_id->operand_loc[i];
4552 : :
4553 : 172624591 : if (GET_CODE (reg) == SUBREG)
4554 : 3348705 : reg = SUBREG_REG (reg);
4555 : :
4556 : 172624591 : if (REG_P (reg) && (regno = REGNO (reg)) >= FIRST_PSEUDO_REGISTER)
4557 : : {
4558 : 78451836 : bool ok_p = in_class_p (reg, goal_alt[i], &new_class, true);
4559 : :
4560 : 78451836 : if (new_class != NO_REGS && get_reg_class (regno) != new_class)
4561 : : {
4562 : 3571382 : lra_assert (ok_p);
4563 : 3571382 : lra_change_class (regno, new_class, " Change to", true);
4564 : : }
4565 : : }
4566 : : }
4567 : : else
4568 : : {
4569 : 6156298 : const char *constraint;
4570 : 6156298 : char c;
4571 : 6156298 : rtx op = *curr_id->operand_loc[i];
4572 : 6156298 : rtx subreg = NULL_RTX;
4573 : 6156298 : machine_mode mode = curr_operand_mode[i];
4574 : :
4575 : 6156298 : if (GET_CODE (op) == SUBREG)
4576 : : {
4577 : 243443 : subreg = op;
4578 : 243443 : op = SUBREG_REG (op);
4579 : 243443 : mode = GET_MODE (op);
4580 : : }
4581 : :
4582 : 6372683 : if (CONST_POOL_OK_P (mode, op)
4583 : 6372683 : && ((targetm.preferred_reload_class
4584 : 216385 : (op, (enum reg_class) goal_alt[i]) == NO_REGS)
4585 : 68318 : || no_input_reloads_p))
4586 : : {
4587 : 148067 : rtx tem = force_const_mem (mode, op);
4588 : :
4589 : 148067 : change_p = true;
4590 : 148067 : if (subreg != NULL_RTX)
4591 : 0 : tem = gen_rtx_SUBREG (mode, tem, SUBREG_BYTE (subreg));
4592 : :
4593 : 148067 : *curr_id->operand_loc[i] = tem;
4594 : 148067 : lra_update_dup (curr_id, i);
4595 : 148067 : process_address (i, false, &before, &after);
4596 : :
4597 : : /* If the alternative accepts constant pool refs directly
4598 : : there will be no reload needed at all. */
4599 : 148067 : if (subreg != NULL_RTX)
4600 : 0 : continue;
4601 : : /* Skip alternatives before the one requested. */
4602 : 148067 : constraint = (curr_static_id->operand_alternative
4603 : 148067 : [goal_alt_number * n_operands + i].constraint);
4604 : 148067 : for (;
4605 : 251305 : (c = *constraint) && c != ',' && c != '#';
4606 : 103238 : constraint += CONSTRAINT_LEN (c, constraint))
4607 : : {
4608 : 204306 : enum constraint_num cn = lookup_constraint (constraint);
4609 : 204306 : if ((insn_extra_memory_constraint (cn)
4610 : 103403 : || insn_extra_special_memory_constraint (cn)
4611 : : || insn_extra_relaxed_memory_constraint (cn))
4612 : 204471 : && satisfies_memory_constraint_p (tem, cn))
4613 : : break;
4614 : : }
4615 : 148067 : if (c == '\0' || c == ',' || c == '#')
4616 : 46999 : continue;
4617 : :
4618 : 101068 : goal_alt_win[i] = true;
4619 : : }
4620 : : }
4621 : :
4622 : : n_outputs = 0;
4623 : 259036425 : for (i = 0; i < n_operands; i++)
4624 : 178780889 : if (curr_static_id->operand[i].type == OP_OUT)
4625 : 69743369 : outputs[n_outputs++] = i;
4626 : 80255536 : outputs[n_outputs] = -1;
4627 : 259036425 : for (i = 0; i < n_operands; i++)
4628 : : {
4629 : 178780889 : int regno;
4630 : 178780889 : bool optional_p = false;
4631 : 178780889 : rtx old, new_reg;
4632 : 178780889 : rtx op = *curr_id->operand_loc[i];
4633 : :
4634 : 178780889 : if (goal_alt_win[i])
4635 : : {
4636 : 172725659 : if (goal_alt[i] == NO_REGS
4637 : 46986771 : && REG_P (op)
4638 : 5424899 : && (regno = REGNO (op)) >= FIRST_PSEUDO_REGISTER
4639 : : /* We assigned a hard register to the pseudo in the past but now
4640 : : decided to spill it for the insn. If the pseudo is used only
4641 : : in this insn, it is better to spill it here as we free hard
4642 : : registers for other pseudos referenced in the insn. The most
4643 : : common case of this is a scratch register which will be
4644 : : transformed to scratch back at the end of LRA. */
4645 : 175676503 : && !multiple_insn_refs_p (regno))
4646 : : {
4647 : 11242 : if (lra_get_allocno_class (regno) != NO_REGS)
4648 : 5339 : lra_change_class (regno, NO_REGS, " Change to", true);
4649 : 5621 : reg_renumber[regno] = -1;
4650 : : }
4651 : : /* We can do an optional reload. If the pseudo got a hard
4652 : : reg, we might improve the code through inheritance. If
4653 : : it does not get a hard register we coalesce memory/memory
4654 : : moves later. Ignore move insns to avoid cycling. */
4655 : 172725659 : if (! lra_simple_p
4656 : 172180981 : && lra_undo_inheritance_iter < LRA_MAX_INHERITANCE_PASSES
4657 : 159388615 : && goal_alt[i] != NO_REGS && REG_P (op)
4658 : 79269830 : && (regno = REGNO (op)) >= FIRST_PSEUDO_REGISTER
4659 : 66371193 : && regno < new_regno_start
4660 : 61556497 : && ! ira_former_scratch_p (regno)
4661 : 61498782 : && reg_renumber[regno] < 0
4662 : : /* Check that the optional reload pseudo will be able to
4663 : : hold given mode value. */
4664 : 3868658 : && ! (prohibited_class_reg_set_mode_p
4665 : 3868658 : (goal_alt[i], reg_class_contents[goal_alt[i]],
4666 : 3868658 : PSEUDO_REGNO_MODE (regno)))
4667 : 176594307 : && (curr_insn_set == NULL_RTX
4668 : 3861456 : || !((REG_P (SET_SRC (curr_insn_set))
4669 : : || MEM_P (SET_SRC (curr_insn_set))
4670 : : || GET_CODE (SET_SRC (curr_insn_set)) == SUBREG)
4671 : 3198886 : && (REG_P (SET_DEST (curr_insn_set))
4672 : : || MEM_P (SET_DEST (curr_insn_set))
4673 : : || GET_CODE (SET_DEST (curr_insn_set)) == SUBREG))))
4674 : : optional_p = true;
4675 : 172055861 : else if (goal_alt_matched[i][0] != -1
4676 : 8826508 : && curr_static_id->operand[i].type == OP_OUT
4677 : 8825386 : && (curr_static_id->operand_alternative
4678 : 8825386 : [goal_alt_number * n_operands + i].earlyclobber)
4679 : 19778 : && REG_P (op))
4680 : : {
4681 : 25197 : for (j = 0; goal_alt_matched[i][j] != -1; j++)
4682 : : {
4683 : 19725 : rtx op2 = *curr_id->operand_loc[goal_alt_matched[i][j]];
4684 : :
4685 : 19725 : if (REG_P (op2) && REGNO (op) != REGNO (op2))
4686 : : break;
4687 : : }
4688 : 19725 : if (goal_alt_matched[i][j] != -1)
4689 : : {
4690 : : /* Generate reloads for different output and matched
4691 : : input registers. This is the easiest way to avoid
4692 : : creation of non-existing register conflicts in
4693 : : lra-lives.cc. */
4694 : 14253 : match_reload (i, goal_alt_matched[i], outputs, goal_alt[i],
4695 : : &goal_alt_exclude_start_hard_regs[i], &before,
4696 : : &after, true);
4697 : : }
4698 : 173673489 : continue;
4699 : 19725 : }
4700 : : else
4701 : : {
4702 : 172036136 : enum reg_class rclass, common_class;
4703 : :
4704 : 90206910 : if (REG_P (op) && goal_alt[i] != NO_REGS
4705 : 84782011 : && (regno = REGNO (op)) >= new_regno_start
4706 : 4826003 : && (rclass = get_reg_class (regno)) == ALL_REGS
4707 : 0 : && ((common_class = ira_reg_class_subset[rclass][goal_alt[i]])
4708 : : != NO_REGS)
4709 : 0 : && common_class != ALL_REGS
4710 : 172036136 : && enough_allocatable_hard_regs_p (common_class,
4711 : 0 : GET_MODE (op)))
4712 : : /* Refine reload pseudo class from chosen alternative
4713 : : constraint. */
4714 : 0 : lra_change_class (regno, common_class, " Change to", true);
4715 : 172036136 : continue;
4716 : 172036136 : }
4717 : : }
4718 : :
4719 : : /* Operands that match previous ones have already been handled. */
4720 : 6725028 : if (goal_alt_matches[i] >= 0)
4721 : 1617628 : continue;
4722 : :
4723 : : /* We should not have an operand with a non-offsettable address
4724 : : appearing where an offsettable address will do. It also may
4725 : : be a case when the address should be special in other words
4726 : : not a general one (e.g. it needs no index reg). */
4727 : 5107400 : if (goal_alt_matched[i][0] == -1 && goal_alt_offmemok[i] && MEM_P (op))
4728 : : {
4729 : 72 : enum reg_class rclass;
4730 : 72 : rtx *loc = &XEXP (op, 0);
4731 : 72 : enum rtx_code code = GET_CODE (*loc);
4732 : :
4733 : 72 : push_to_sequence (before);
4734 : 72 : rclass = base_reg_class (GET_MODE (op), MEM_ADDR_SPACE (op),
4735 : : MEM, SCRATCH, curr_insn);
4736 : 72 : if (GET_RTX_CLASS (code) == RTX_AUTOINC)
4737 : 0 : new_reg = emit_inc (rclass, *loc,
4738 : : /* This value does not matter for MODIFY. */
4739 : 0 : GET_MODE_SIZE (GET_MODE (op)));
4740 : 86 : else if (get_reload_reg (OP_IN, Pmode, *loc, rclass,
4741 : : NULL, false, false,
4742 : : "offsetable address", &new_reg))
4743 : : {
4744 : 72 : rtx addr = *loc;
4745 : 72 : enum rtx_code code = GET_CODE (addr);
4746 : 72 : bool align_p = false;
4747 : :
4748 : 72 : if (code == AND && CONST_INT_P (XEXP (addr, 1)))
4749 : : {
4750 : : /* (and ... (const_int -X)) is used to align to X bytes. */
4751 : 0 : align_p = true;
4752 : 0 : addr = XEXP (*loc, 0);
4753 : : }
4754 : : else
4755 : 72 : addr = canonicalize_reload_addr (addr);
4756 : :
4757 : 72 : lra_emit_move (new_reg, addr);
4758 : 72 : if (align_p)
4759 : 0 : emit_move_insn (new_reg, gen_rtx_AND (GET_MODE (new_reg), new_reg, XEXP (*loc, 1)));
4760 : : }
4761 : 72 : before = end_sequence ();
4762 : 72 : *loc = new_reg;
4763 : 72 : lra_update_dup (curr_id, i);
4764 : 72 : }
4765 : 5107328 : else if (goal_alt_matched[i][0] == -1)
4766 : : {
4767 : 3389879 : machine_mode mode;
4768 : 3389879 : rtx reg, *loc;
4769 : 3389879 : int hard_regno;
4770 : 3389879 : enum op_type type = curr_static_id->operand[i].type;
4771 : :
4772 : 3389879 : loc = curr_id->operand_loc[i];
4773 : 3389879 : mode = curr_operand_mode[i];
4774 : 3389879 : if (GET_CODE (*loc) == SUBREG)
4775 : : {
4776 : 74872 : reg = SUBREG_REG (*loc);
4777 : 74872 : poly_int64 byte = SUBREG_BYTE (*loc);
4778 : 74872 : if (REG_P (reg)
4779 : : /* Strict_low_part requires reloading the register and not
4780 : : just the subreg. Likewise for a strict subreg no wider
4781 : : than a word for WORD_REGISTER_OPERATIONS targets. */
4782 : 74872 : && (curr_static_id->operand[i].strict_low
4783 : 74804 : || (!paradoxical_subreg_p (mode, GET_MODE (reg))
4784 : 72227 : && (hard_regno
4785 : 72227 : = get_try_hard_regno (REGNO (reg))) >= 0
4786 : 70695 : && (simplify_subreg_regno
4787 : 145567 : (hard_regno,
4788 : 70695 : GET_MODE (reg), byte, mode) < 0)
4789 : 0 : && (goal_alt[i] == NO_REGS
4790 : 0 : || (simplify_subreg_regno
4791 : 74872 : (ira_class_hard_regs[goal_alt[i]][0],
4792 : 0 : GET_MODE (reg), byte, mode) >= 0)))
4793 : 74804 : || (partial_subreg_p (mode, GET_MODE (reg))
4794 : 74804 : && known_le (GET_MODE_SIZE (GET_MODE (reg)),
4795 : : UNITS_PER_WORD)
4796 : : && WORD_REGISTER_OPERATIONS))
4797 : : /* Avoid the situation when there are no available hard regs
4798 : : for the pseudo mode but there are ones for the subreg
4799 : : mode: */
4800 : 74940 : && !(goal_alt[i] != NO_REGS
4801 : 68 : && REGNO (reg) >= FIRST_PSEUDO_REGISTER
4802 : 68 : && (prohibited_class_reg_set_mode_p
4803 : 68 : (goal_alt[i], reg_class_contents[goal_alt[i]],
4804 : 68 : GET_MODE (reg)))
4805 : : && !(prohibited_class_reg_set_mode_p
4806 : 0 : (goal_alt[i], reg_class_contents[goal_alt[i]],
4807 : : mode))))
4808 : : {
4809 : : /* An OP_INOUT is required when reloading a subreg of a
4810 : : mode wider than a word to ensure that data beyond the
4811 : : word being reloaded is preserved. Also automatically
4812 : : ensure that strict_low_part reloads are made into
4813 : : OP_INOUT which should already be true from the backend
4814 : : constraints. */
4815 : 68 : if (type == OP_OUT
4816 : 68 : && (curr_static_id->operand[i].strict_low
4817 : 0 : || read_modify_subreg_p (*loc)))
4818 : : type = OP_INOUT;
4819 : 68 : loc = &SUBREG_REG (*loc);
4820 : 68 : mode = GET_MODE (*loc);
4821 : : }
4822 : : }
4823 : 3389879 : old = *loc;
4824 : 3389879 : if (get_reload_reg (type, mode, old, goal_alt[i],
4825 : : &goal_alt_exclude_start_hard_regs[i],
4826 : 3389879 : loc != curr_id->operand_loc[i],
4827 : 3389879 : curr_static_id->operand_alternative
4828 : 3389879 : [goal_alt_number * n_operands + i].earlyclobber,
4829 : : "", &new_reg)
4830 : 3389879 : && type != OP_OUT)
4831 : : {
4832 : 2412581 : push_to_sequence (before);
4833 : 2412581 : lra_emit_move (new_reg, old);
4834 : 2412581 : before = end_sequence ();
4835 : : }
4836 : 3389879 : *loc = new_reg;
4837 : 3389879 : if (type != OP_IN
4838 : 976188 : && find_reg_note (curr_insn, REG_UNUSED, old) == NULL_RTX
4839 : : /* OLD can be an equivalent constant here. */
4840 : 4341518 : && !CONSTANT_P (old))
4841 : : {
4842 : 951639 : start_sequence ();
4843 : 951639 : lra_emit_move (type == OP_INOUT ? copy_rtx (old) : old, new_reg);
4844 : 951639 : emit_insn (after);
4845 : 951639 : after = end_sequence ();
4846 : 951639 : *loc = new_reg;
4847 : : }
4848 : 3389879 : for (j = 0; j < goal_alt_dont_inherit_ops_num; j++)
4849 : 582 : if (goal_alt_dont_inherit_ops[j] == i)
4850 : : {
4851 : 582 : lra_set_regno_unique_value (REGNO (new_reg));
4852 : 582 : break;
4853 : : }
4854 : 3389879 : lra_update_dup (curr_id, i);
4855 : : }
4856 : 1717449 : else if (curr_static_id->operand[i].type == OP_IN
4857 : 1717449 : && (curr_static_id->operand[goal_alt_matched[i][0]].type
4858 : : == OP_OUT
4859 : 0 : || (curr_static_id->operand[goal_alt_matched[i][0]].type
4860 : : == OP_INOUT
4861 : 0 : && (operands_match_p
4862 : 0 : (*curr_id->operand_loc[i],
4863 : 0 : *curr_id->operand_loc[goal_alt_matched[i][0]],
4864 : : -1)))))
4865 : : {
4866 : : /* generate reloads for input and matched outputs. */
4867 : 17006 : match_inputs[0] = i;
4868 : 17006 : match_inputs[1] = -1;
4869 : 17006 : match_reload (goal_alt_matched[i][0], match_inputs, outputs,
4870 : : goal_alt[i], &goal_alt_exclude_start_hard_regs[i],
4871 : : &before, &after,
4872 : 17006 : curr_static_id->operand_alternative
4873 : 17006 : [goal_alt_number * n_operands + goal_alt_matched[i][0]]
4874 : 17006 : .earlyclobber);
4875 : : }
4876 : 1700443 : else if ((curr_static_id->operand[i].type == OP_OUT
4877 : 0 : || (curr_static_id->operand[i].type == OP_INOUT
4878 : 0 : && (operands_match_p
4879 : 0 : (*curr_id->operand_loc[i],
4880 : 0 : *curr_id->operand_loc[goal_alt_matched[i][0]],
4881 : : -1))))
4882 : 1700443 : && (curr_static_id->operand[goal_alt_matched[i][0]].type
4883 : : == OP_IN))
4884 : : /* Generate reloads for output and matched inputs. */
4885 : 1700443 : match_reload (i, goal_alt_matched[i], outputs, goal_alt[i],
4886 : : &goal_alt_exclude_start_hard_regs[i], &before, &after,
4887 : 1700443 : curr_static_id->operand_alternative
4888 : 1700443 : [goal_alt_number * n_operands + i].earlyclobber);
4889 : 0 : else if (curr_static_id->operand[i].type == OP_IN
4890 : 0 : && (curr_static_id->operand[goal_alt_matched[i][0]].type
4891 : : == OP_IN))
4892 : : {
4893 : : /* Generate reloads for matched inputs. */
4894 : 0 : match_inputs[0] = i;
4895 : 0 : for (j = 0; (k = goal_alt_matched[i][j]) >= 0; j++)
4896 : 0 : match_inputs[j + 1] = k;
4897 : 0 : match_inputs[j + 1] = -1;
4898 : 0 : match_reload (-1, match_inputs, outputs, goal_alt[i],
4899 : : &goal_alt_exclude_start_hard_regs[i],
4900 : : &before, &after, false);
4901 : : }
4902 : : else
4903 : : /* We must generate code in any case when function
4904 : : process_alt_operands decides that it is possible. */
4905 : 0 : gcc_unreachable ();
4906 : :
4907 : 5107400 : if (optional_p)
4908 : : {
4909 : 669798 : rtx reg = op;
4910 : :
4911 : 669798 : lra_assert (REG_P (reg));
4912 : 669798 : regno = REGNO (reg);
4913 : 669798 : op = *curr_id->operand_loc[i]; /* Substitution. */
4914 : 669798 : if (GET_CODE (op) == SUBREG)
4915 : 0 : op = SUBREG_REG (op);
4916 : 669798 : gcc_assert (REG_P (op) && (int) REGNO (op) >= new_regno_start);
4917 : 669798 : bitmap_set_bit (&lra_optional_reload_pseudos, REGNO (op));
4918 : 669798 : lra_reg_info[REGNO (op)].restore_rtx = reg;
4919 : 669798 : if (lra_dump_file != NULL)
4920 : 3 : fprintf (lra_dump_file,
4921 : : " Making reload reg %d for reg %d optional\n",
4922 : : REGNO (op), regno);
4923 : : }
4924 : : }
4925 : 75882111 : if (before != NULL_RTX || after != NULL_RTX
4926 : 155322217 : || max_regno_before != max_reg_num ())
4927 : 5213862 : change_p = true;
4928 : 80255536 : if (change_p)
4929 : : {
4930 : 6146327 : lra_update_operator_dups (curr_id);
4931 : : /* Something changes -- process the insn. */
4932 : 6146327 : lra_update_insn_regno_info (curr_insn);
4933 : 6146327 : if (asm_noperands (PATTERN (curr_insn)) >= 0
4934 : 6146327 : && ++curr_id->asm_reloads_num >= FIRST_PSEUDO_REGISTER)
4935 : : /* Most probably there are no enough registers to satisfy asm insn: */
4936 : : {
4937 : 24 : lra_asm_insn_error (curr_insn);
4938 : 24 : return change_p;
4939 : : }
4940 : : }
4941 : 80255512 : if (goal_alt_out_sp_reload_p)
4942 : : {
4943 : : /* We have an output stack pointer reload -- update sp offset: */
4944 : 0 : rtx set;
4945 : 0 : bool done_p = false;
4946 : 0 : poly_int64 sp_offset = curr_id->sp_offset;
4947 : 0 : for (rtx_insn *insn = after; insn != NULL_RTX; insn = NEXT_INSN (insn))
4948 : 0 : if ((set = single_set (insn)) != NULL_RTX
4949 : 0 : && SET_DEST (set) == stack_pointer_rtx)
4950 : : {
4951 : 0 : lra_assert (!done_p);
4952 : 0 : done_p = true;
4953 : 0 : curr_id->sp_offset = 0;
4954 : 0 : lra_insn_recog_data_t id = lra_get_insn_recog_data (insn);
4955 : 0 : id->sp_offset = sp_offset;
4956 : 0 : if (lra_dump_file != NULL)
4957 : 0 : fprintf (lra_dump_file,
4958 : : " Moving sp offset from insn %u to %u\n",
4959 : 0 : INSN_UID (curr_insn), INSN_UID (insn));
4960 : : }
4961 : 0 : lra_assert (done_p);
4962 : : }
4963 : 80255512 : int const_regno = -1;
4964 : 80255512 : rtx set;
4965 : 80255512 : rtx_insn *prev, *const_insn = NULL;
4966 : 4373415 : if (before != NULL_RTX && (prev = PREV_INSN (curr_insn)) != NULL_RTX
4967 : 84628927 : && (set = single_set (prev)) != NULL_RTX && CONSTANT_P (SET_SRC (set)))
4968 : : {
4969 : 344220 : rtx reg = SET_DEST (set);
4970 : 344220 : if (GET_CODE (reg) == SUBREG)
4971 : 8931 : reg = SUBREG_REG (reg);
4972 : : /* Consider only reload insns as we don't want to change the order
4973 : : created by previous optimizations. */
4974 : 255635 : if (REG_P (reg) && (int) REGNO (reg) >= lra_new_regno_start
4975 : 344992 : && bitmap_bit_p (&lra_reg_info[REGNO (reg)].insn_bitmap,
4976 : 772 : INSN_UID (curr_insn)))
4977 : : {
4978 : 297 : const_regno = REGNO (reg);
4979 : 297 : const_insn = prev;
4980 : : }
4981 : : }
4982 : 80255512 : lra_process_new_insns (curr_insn, before, after, "Inserting insn reload");
4983 : 80255512 : if (const_regno >= 0) {
4984 : 594 : bool move_p = true;
4985 : 594 : for (rtx_insn *insn = before; insn != curr_insn; insn = NEXT_INSN (insn))
4986 : 297 : if (bitmap_bit_p (&lra_reg_info[const_regno].insn_bitmap,
4987 : 297 : INSN_UID (insn)))
4988 : : {
4989 : : move_p = false;
4990 : : break;
4991 : : }
4992 : 297 : if (move_p)
4993 : : {
4994 : 297 : reorder_insns_nobb (const_insn, const_insn, PREV_INSN (curr_insn));
4995 : 297 : if (lra_dump_file != NULL)
4996 : : {
4997 : 0 : dump_insn_slim (lra_dump_file, const_insn);
4998 : 0 : fprintf (lra_dump_file,
4999 : : " to decrease reg pressure, it is moved before:\n");
5000 : 0 : dump_insn_slim (lra_dump_file, curr_insn);
5001 : : }
5002 : : }
5003 : : }
5004 : : return change_p;
5005 : : }
5006 : :
5007 : : /* Return true if INSN satisfies all constraints. In other words, no
5008 : : reload insns are needed. */
5009 : : bool
5010 : 3472 : lra_constrain_insn (rtx_insn *insn)
5011 : : {
5012 : 3472 : int saved_new_regno_start = new_regno_start;
5013 : 3472 : int saved_new_insn_uid_start = new_insn_uid_start;
5014 : 3472 : bool change_p;
5015 : :
5016 : 3472 : curr_insn = insn;
5017 : 3472 : curr_id = lra_get_insn_recog_data (curr_insn);
5018 : 3472 : curr_static_id = curr_id->insn_static_data;
5019 : 3472 : new_insn_uid_start = get_max_uid ();
5020 : 3472 : new_regno_start = max_reg_num ();
5021 : 3472 : change_p = curr_insn_transform (true);
5022 : 3472 : new_regno_start = saved_new_regno_start;
5023 : 3472 : new_insn_uid_start = saved_new_insn_uid_start;
5024 : 3472 : return ! change_p;
5025 : : }
5026 : :
5027 : : /* Return true if X is in LIST. */
5028 : : static bool
5029 : 1369880 : in_list_p (rtx x, rtx list)
5030 : : {
5031 : 2339769 : for (; list != NULL_RTX; list = XEXP (list, 1))
5032 : 1290491 : if (XEXP (list, 0) == x)
5033 : : return true;
5034 : : return false;
5035 : : }
5036 : :
5037 : : /* Return true if X contains an allocatable hard register (if
5038 : : HARD_REG_P) or a (spilled if SPILLED_P) pseudo. */
5039 : : static bool
5040 : 7701909 : contains_reg_p (rtx x, bool hard_reg_p, bool spilled_p)
5041 : : {
5042 : 7701909 : int i, j;
5043 : 7701909 : const char *fmt;
5044 : 7701909 : enum rtx_code code;
5045 : :
5046 : 7701909 : code = GET_CODE (x);
5047 : 7701909 : if (REG_P (x))
5048 : : {
5049 : 1575170 : int regno = REGNO (x);
5050 : 1575170 : HARD_REG_SET alloc_regs;
5051 : :
5052 : 1575170 : if (hard_reg_p)
5053 : : {
5054 : 497338 : if (regno >= FIRST_PSEUDO_REGISTER)
5055 : 147623 : regno = lra_get_regno_hard_regno (regno);
5056 : 497338 : if (regno < 0)
5057 : : return false;
5058 : 497338 : alloc_regs = ~lra_no_alloc_regs;
5059 : 497338 : return overlaps_hard_reg_set_p (alloc_regs, GET_MODE (x), regno);
5060 : : }
5061 : : else
5062 : : {
5063 : 1077832 : if (regno < FIRST_PSEUDO_REGISTER)
5064 : : return false;
5065 : 347885 : if (! spilled_p)
5066 : : return true;
5067 : 183824 : return lra_get_regno_hard_regno (regno) < 0;
5068 : : }
5069 : : }
5070 : 6126739 : fmt = GET_RTX_FORMAT (code);
5071 : 15118912 : for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
5072 : : {
5073 : 9601625 : if (fmt[i] == 'e')
5074 : : {
5075 : 4275309 : if (contains_reg_p (XEXP (x, i), hard_reg_p, spilled_p))
5076 : : return true;
5077 : : }
5078 : 5326316 : else if (fmt[i] == 'E')
5079 : : {
5080 : 1316022 : for (j = XVECLEN (x, i) - 1; j >= 0; j--)
5081 : 1206434 : if (contains_reg_p (XVECEXP (x, i, j), hard_reg_p, spilled_p))
5082 : : return true;
5083 : : }
5084 : : }
5085 : : return false;
5086 : : }
5087 : :
5088 : : /* Process all regs in location *LOC and change them on equivalent
5089 : : substitution. Return true if any change was done. */
5090 : : static bool
5091 : 3098 : loc_equivalence_change_p (rtx *loc)
5092 : : {
5093 : 3098 : rtx subst, reg, x = *loc;
5094 : 3098 : bool result = false;
5095 : 3098 : enum rtx_code code = GET_CODE (x);
5096 : 3098 : const char *fmt;
5097 : 3098 : int i, j;
5098 : :
5099 : 3098 : if (code == SUBREG)
5100 : : {
5101 : 10 : reg = SUBREG_REG (x);
5102 : 10 : if ((subst = get_equiv_with_elimination (reg, curr_insn)) != reg
5103 : 10 : && GET_MODE (subst) == VOIDmode)
5104 : : {
5105 : : /* We cannot reload debug location. Simplify subreg here
5106 : : while we know the inner mode. */
5107 : 0 : *loc = simplify_gen_subreg (GET_MODE (x), subst,
5108 : 0 : GET_MODE (reg), SUBREG_BYTE (x));
5109 : 0 : return true;
5110 : : }
5111 : : }
5112 : 3098 : if (code == REG && (subst = get_equiv_with_elimination (x, curr_insn)) != x)
5113 : : {
5114 : 8 : *loc = subst;
5115 : 8 : return true;
5116 : : }
5117 : :
5118 : : /* Scan all the operand sub-expressions. */
5119 : 3090 : fmt = GET_RTX_FORMAT (code);
5120 : 7490 : for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
5121 : : {
5122 : 4400 : if (fmt[i] == 'e')
5123 : 2426 : result = loc_equivalence_change_p (&XEXP (x, i)) || result;
5124 : 1974 : else if (fmt[i] == 'E')
5125 : 135 : for (j = XVECLEN (x, i) - 1; j >= 0; j--)
5126 : 100 : result
5127 : 110 : = loc_equivalence_change_p (&XVECEXP (x, i, j)) || result;
5128 : : }
5129 : : return result;
5130 : : }
5131 : :
5132 : : /* Similar to loc_equivalence_change_p, but for use as
5133 : : simplify_replace_fn_rtx callback. DATA is insn for which the
5134 : : elimination is done. If it null we don't do the elimination. */
5135 : : static rtx
5136 : 43395488 : loc_equivalence_callback (rtx loc, const_rtx, void *data)
5137 : : {
5138 : 43395488 : if (!REG_P (loc))
5139 : : return NULL_RTX;
5140 : :
5141 : 11187372 : rtx subst = (data == NULL
5142 : 11187372 : ? get_equiv (loc) : get_equiv_with_elimination (loc, (rtx_insn *) data));
5143 : 11187372 : if (subst != loc)
5144 : : return subst;
5145 : :
5146 : : return NULL_RTX;
5147 : : }
5148 : :
5149 : : /* Maximum number of generated reload insns per an insn. It is for
5150 : : preventing this pass cycling in a bug case. */
5151 : : #define MAX_RELOAD_INSNS_NUMBER LRA_MAX_INSN_RELOADS
5152 : :
5153 : : /* The current iteration number of this LRA pass. */
5154 : : int lra_constraint_iter;
5155 : :
5156 : : /* True if we should during assignment sub-pass check assignment
5157 : : correctness for all pseudos and spill some of them to correct
5158 : : conflicts. It can be necessary when we substitute equiv which
5159 : : needs checking register allocation correctness because the
5160 : : equivalent value contains allocatable hard registers, or when we
5161 : : restore multi-register pseudo, or when we change the insn code and
5162 : : its operand became INOUT operand when it was IN one before. */
5163 : : bool check_and_force_assignment_correctness_p;
5164 : :
5165 : : /* Return true if REGNO is referenced in more than one block. */
5166 : : static bool
5167 : 157750 : multi_block_pseudo_p (int regno)
5168 : : {
5169 : 157750 : basic_block bb = NULL;
5170 : 157750 : unsigned int uid;
5171 : 157750 : bitmap_iterator bi;
5172 : :
5173 : 157750 : if (regno < FIRST_PSEUDO_REGISTER)
5174 : : return false;
5175 : :
5176 : 482827 : EXECUTE_IF_SET_IN_BITMAP (&lra_reg_info[regno].insn_bitmap, 0, uid, bi)
5177 : 329838 : if (bb == NULL)
5178 : 157750 : bb = BLOCK_FOR_INSN (lra_insn_recog_data[uid]->insn);
5179 : 172088 : else if (BLOCK_FOR_INSN (lra_insn_recog_data[uid]->insn) != bb)
5180 : : return true;
5181 : : return false;
5182 : : }
5183 : :
5184 : : /* Return true if LIST contains a deleted insn. */
5185 : : static bool
5186 : 741677 : contains_deleted_insn_p (rtx_insn_list *list)
5187 : : {
5188 : 1418864 : for (; list != NULL_RTX; list = list->next ())
5189 : 677187 : if (NOTE_P (list->insn ())
5190 : 677187 : && NOTE_KIND (list->insn ()) == NOTE_INSN_DELETED)
5191 : : return true;
5192 : : return false;
5193 : : }
5194 : :
5195 : : /* Return true if X contains a pseudo dying in INSN. */
5196 : : static bool
5197 : 2339035 : dead_pseudo_p (rtx x, rtx_insn *insn)
5198 : : {
5199 : 2339035 : int i, j;
5200 : 2339035 : const char *fmt;
5201 : 2339035 : enum rtx_code code;
5202 : :
5203 : 2339035 : if (REG_P (x))
5204 : 524048 : return (insn != NULL_RTX
5205 : 524048 : && find_regno_note (insn, REG_DEAD, REGNO (x)) != NULL_RTX);
5206 : 1814987 : code = GET_CODE (x);
5207 : 1814987 : fmt = GET_RTX_FORMAT (code);
5208 : 4637852 : for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
5209 : : {
5210 : 2828140 : if (fmt[i] == 'e')
5211 : : {
5212 : 1393610 : if (dead_pseudo_p (XEXP (x, i), insn))
5213 : : return true;
5214 : : }
5215 : 1434530 : else if (fmt[i] == 'E')
5216 : : {
5217 : 294418 : for (j = XVECLEN (x, i) - 1; j >= 0; j--)
5218 : 269651 : if (dead_pseudo_p (XVECEXP (x, i, j), insn))
5219 : : return true;
5220 : : }
5221 : : }
5222 : : return false;
5223 : : }
5224 : :
5225 : : /* Return true if INSN contains a dying pseudo in INSN right hand
5226 : : side. */
5227 : : static bool
5228 : 675774 : insn_rhs_dead_pseudo_p (rtx_insn *insn)
5229 : : {
5230 : 675774 : rtx set = single_set (insn);
5231 : :
5232 : 675774 : gcc_assert (set != NULL);
5233 : 675774 : return dead_pseudo_p (SET_SRC (set), insn);
5234 : : }
5235 : :
5236 : : /* Return true if any init insn of REGNO contains a dying pseudo in
5237 : : insn right hand side. */
5238 : : static bool
5239 : 740264 : init_insn_rhs_dead_pseudo_p (int regno)
5240 : : {
5241 : 740264 : rtx_insn_list *insns = ira_reg_equiv[regno].init_insns;
5242 : :
5243 : 740264 : if (insns == NULL)
5244 : : return false;
5245 : 1346180 : for (; insns != NULL_RTX; insns = insns->next ())
5246 : 675774 : if (insn_rhs_dead_pseudo_p (insns->insn ()))
5247 : : return true;
5248 : : return false;
5249 : : }
5250 : :
5251 : : /* Return TRUE if REGNO has a reverse equivalence. The equivalence is
5252 : : reverse only if we have one init insn with given REGNO as a
5253 : : source. */
5254 : : static bool
5255 : 741677 : reverse_equiv_p (int regno)
5256 : : {
5257 : 741677 : rtx_insn_list *insns = ira_reg_equiv[regno].init_insns;
5258 : 741677 : rtx set;
5259 : :
5260 : 741677 : if (insns == NULL)
5261 : : return false;
5262 : 677187 : if (! INSN_P (insns->insn ())
5263 : 1354374 : || insns->next () != NULL)
5264 : : return false;
5265 : 677187 : if ((set = single_set (insns->insn ())) == NULL_RTX)
5266 : : return false;
5267 : 677187 : return REG_P (SET_SRC (set)) && (int) REGNO (SET_SRC (set)) == regno;
5268 : : }
5269 : :
5270 : : /* Return TRUE if REGNO was reloaded in an equivalence init insn. We
5271 : : call this function only for non-reverse equivalence. */
5272 : : static bool
5273 : 734896 : contains_reloaded_insn_p (int regno)
5274 : : {
5275 : 734896 : rtx set;
5276 : 734896 : rtx_insn_list *list = ira_reg_equiv[regno].init_insns;
5277 : :
5278 : 1405302 : for (; list != NULL; list = list->next ())
5279 : 670406 : if ((set = single_set (list->insn ())) == NULL_RTX
5280 : 670406 : || ! REG_P (SET_DEST (set))
5281 : 1340812 : || (int) REGNO (SET_DEST (set)) != regno)
5282 : : return true;
5283 : : return false;
5284 : : }
5285 : :
5286 : : /* Try combine secondary memory reload insn FROM for insn TO into TO insn.
5287 : : FROM should be a load insn (usually a secondary memory reload insn). Return
5288 : : TRUE in case of success. */
5289 : : static bool
5290 : 7369366 : combine_reload_insn (rtx_insn *from, rtx_insn *to)
5291 : : {
5292 : 7369366 : bool ok_p;
5293 : 7369366 : rtx_insn *saved_insn;
5294 : 7369366 : rtx set, from_reg, to_reg, op;
5295 : 7369366 : enum reg_class to_class, from_class;
5296 : 7369366 : int n, nop;
5297 : 7369366 : signed char changed_nops[MAX_RECOG_OPERANDS + 1];
5298 : :
5299 : : /* Check conditions for second memory reload and original insn: */
5300 : 7369366 : if ((targetm.secondary_memory_needed
5301 : : == hook_bool_mode_reg_class_t_reg_class_t_false)
5302 : 7369366 : || NEXT_INSN (from) != to
5303 : 4381323 : || !NONDEBUG_INSN_P (to)
5304 : 11750689 : || CALL_P (to))
5305 : : return false;
5306 : :
5307 : 4375872 : lra_insn_recog_data_t id = lra_get_insn_recog_data (to);
5308 : 4375872 : struct lra_static_insn_data *static_id = id->insn_static_data;
5309 : :
5310 : 4375872 : if (id->used_insn_alternative == LRA_UNKNOWN_ALT
5311 : 4375872 : || (set = single_set (from)) == NULL_RTX)
5312 : 31089 : return false;
5313 : 4344783 : from_reg = SET_DEST (set);
5314 : 4344783 : to_reg = SET_SRC (set);
5315 : : /* Ignore optional reloads: */
5316 : 4260961 : if (! REG_P (from_reg) || ! REG_P (to_reg)
5317 : 7229524 : || bitmap_bit_p (&lra_optional_reload_pseudos, REGNO (from_reg)))
5318 : 2026844 : return false;
5319 : 2317939 : to_class = lra_get_allocno_class (REGNO (to_reg));
5320 : 2317939 : from_class = lra_get_allocno_class (REGNO (from_reg));
5321 : : /* Check that reload insn is a load: */
5322 : 2317939 : if (to_class != NO_REGS || from_class == NO_REGS)
5323 : : return false;
5324 : 47709 : for (n = nop = 0; nop < static_id->n_operands; nop++)
5325 : : {
5326 : 34307 : if (static_id->operand[nop].type != OP_IN)
5327 : 12392 : continue;
5328 : 21915 : op = *id->operand_loc[nop];
5329 : 21915 : if (!REG_P (op) || REGNO (op) != REGNO (from_reg))
5330 : 8690 : continue;
5331 : 13225 : *id->operand_loc[nop] = to_reg;
5332 : 13225 : changed_nops[n++] = nop;
5333 : : }
5334 : 13402 : changed_nops[n] = -1;
5335 : 13402 : lra_update_dups (id, changed_nops);
5336 : 13402 : lra_update_insn_regno_info (to);
5337 : 13402 : ok_p = recog_memoized (to) >= 0;
5338 : 13402 : if (ok_p)
5339 : : {
5340 : : /* Check that combined insn does not need any reloads: */
5341 : 13373 : saved_insn = curr_insn;
5342 : 13373 : curr_insn = to;
5343 : 13373 : curr_id = lra_get_insn_recog_data (curr_insn);
5344 : 13373 : curr_static_id = curr_id->insn_static_data;
5345 : 13373 : for (bool swapped_p = false;;)
5346 : : {
5347 : 15603 : ok_p = !curr_insn_transform (true);
5348 : 15603 : if (ok_p || curr_static_id->commutative < 0)
5349 : : break;
5350 : 4460 : swap_operands (curr_static_id->commutative);
5351 : 4460 : if (lra_dump_file != NULL)
5352 : : {
5353 : 0 : fprintf (lra_dump_file,
5354 : : " Swapping %scombined insn operands:\n",
5355 : : swapped_p ? "back " : "");
5356 : 0 : dump_insn_slim (lra_dump_file, to);
5357 : : }
5358 : 4460 : if (swapped_p)
5359 : : break;
5360 : : swapped_p = true;
5361 : : }
5362 : 13373 : curr_insn = saved_insn;
5363 : 13373 : curr_id = lra_get_insn_recog_data (curr_insn);
5364 : 13373 : curr_static_id = curr_id->insn_static_data;
5365 : : }
5366 : 13402 : if (ok_p)
5367 : : {
5368 : 3441 : id->used_insn_alternative = -1;
5369 : 3441 : lra_push_insn_and_update_insn_regno_info (to);
5370 : 3441 : if (lra_dump_file != NULL)
5371 : : {
5372 : 0 : fprintf (lra_dump_file, " Use combined insn:\n");
5373 : 0 : dump_insn_slim (lra_dump_file, to);
5374 : : }
5375 : 3441 : return true;
5376 : : }
5377 : 9961 : if (lra_dump_file != NULL)
5378 : : {
5379 : 0 : fprintf (lra_dump_file, " Failed combined insn:\n");
5380 : 0 : dump_insn_slim (lra_dump_file, to);
5381 : : }
5382 : 20193 : for (int i = 0; i < n; i++)
5383 : : {
5384 : 10232 : nop = changed_nops[i];
5385 : 10232 : *id->operand_loc[nop] = from_reg;
5386 : : }
5387 : 9961 : lra_update_dups (id, changed_nops);
5388 : 9961 : lra_update_insn_regno_info (to);
5389 : 9961 : if (lra_dump_file != NULL)
5390 : : {
5391 : 0 : fprintf (lra_dump_file, " Restoring insn after failed combining:\n");
5392 : 0 : dump_insn_slim (lra_dump_file, to);
5393 : : }
5394 : : return false;
5395 : : }
5396 : :
5397 : : /* Entry function of LRA constraint pass. Return true if the
5398 : : constraint pass did change the code. */
5399 : : bool
5400 : 3212397 : lra_constraints (bool first_p)
5401 : : {
5402 : 3212397 : bool changed_p;
5403 : 3212397 : int i, hard_regno, new_insns_num;
5404 : 3212397 : unsigned int min_len, new_min_len, uid;
5405 : 3212397 : rtx set, x, reg, nosubreg_dest;
5406 : 3212397 : rtx_insn *original_insn;
5407 : 3212397 : basic_block last_bb;
5408 : 3212397 : bitmap_iterator bi;
5409 : :
5410 : 3212397 : lra_constraint_iter++;
5411 : 3212397 : if (lra_dump_file != NULL)
5412 : 194 : fprintf (lra_dump_file, "\n********** Local #%d: **********\n\n",
5413 : : lra_constraint_iter);
5414 : 3212397 : changed_p = false;
5415 : 3212397 : if (pic_offset_table_rtx
5416 : 3212397 : && REGNO (pic_offset_table_rtx) >= FIRST_PSEUDO_REGISTER)
5417 : 103178 : check_and_force_assignment_correctness_p = true;
5418 : 3109219 : else if (first_p)
5419 : : /* On the first iteration we should check IRA assignment
5420 : : correctness. In rare cases, the assignments can be wrong as
5421 : : early clobbers operands are ignored in IRA or usages of
5422 : : paradoxical sub-registers are not taken into account by
5423 : : IRA. */
5424 : 1432149 : check_and_force_assignment_correctness_p = true;
5425 : 3212397 : new_insn_uid_start = get_max_uid ();
5426 : 3212397 : new_regno_start = first_p ? lra_constraint_new_regno_start : max_reg_num ();
5427 : : /* Mark used hard regs for target stack size calulations. */
5428 : 207618459 : for (i = FIRST_PSEUDO_REGISTER; i < new_regno_start; i++)
5429 : 204406062 : if (lra_reg_info[i].nrefs != 0
5430 : 302235486 : && (hard_regno = lra_get_regno_hard_regno (i)) >= 0)
5431 : : {
5432 : 93917159 : int j, nregs;
5433 : :
5434 : 93917159 : nregs = hard_regno_nregs (hard_regno, lra_reg_info[i].biggest_mode);
5435 : 190933599 : for (j = 0; j < nregs; j++)
5436 : 97016440 : df_set_regs_ever_live (hard_regno + j, true);
5437 : : }
5438 : : /* Do elimination before the equivalence processing as we can spill
5439 : : some pseudos during elimination. */
5440 : 3212397 : lra_eliminate (false, first_p);
5441 : 3212397 : auto_bitmap equiv_insn_bitmap (®_obstack);
5442 : :
5443 : : /* Register elimination can create new pseudos via the addptr pattern,
5444 : : so make sure the equivalency tables are resized appropriately. */
5445 : 3212397 : ira_expand_reg_equiv ();
5446 : 207618459 : for (i = FIRST_PSEUDO_REGISTER; i < new_regno_start; i++)
5447 : 204406062 : if (lra_reg_info[i].nrefs != 0)
5448 : : {
5449 : 97829424 : ira_reg_equiv[i].profitable_p = true;
5450 : 97829424 : reg = regno_reg_rtx[i];
5451 : 97829424 : if (lra_get_regno_hard_regno (i) < 0 && (x = get_equiv (reg)) != reg)
5452 : : {
5453 : 752749 : bool pseudo_p = contains_reg_p (x, false, false);
5454 : :
5455 : : /* After RTL transformation, we cannot guarantee that
5456 : : pseudo in the substitution was not reloaded which might
5457 : : make equivalence invalid. For example, in reverse
5458 : : equiv of p0
5459 : :
5460 : : p0 <- ...
5461 : : ...
5462 : : equiv_mem <- p0
5463 : :
5464 : : the memory address register was reloaded before the 2nd
5465 : : insn. */
5466 : 752749 : if ((! first_p && pseudo_p)
5467 : : /* We don't use DF for compilation speed sake. So it
5468 : : is problematic to update live info when we use an
5469 : : equivalence containing pseudos in more than one
5470 : : BB. */
5471 : 746438 : || (pseudo_p && multi_block_pseudo_p (i))
5472 : : /* If an init insn was deleted for some reason, cancel
5473 : : the equiv. We could update the equiv insns after
5474 : : transformations including an equiv insn deletion
5475 : : but it is not worthy as such cases are extremely
5476 : : rare. */
5477 : 741677 : || contains_deleted_insn_p (ira_reg_equiv[i].init_insns)
5478 : : /* If it is not a reverse equivalence, we check that a
5479 : : pseudo in rhs of the init insn is not dying in the
5480 : : insn. Otherwise, the live info at the beginning of
5481 : : the corresponding BB might be wrong after we
5482 : : removed the insn. When the equiv can be a
5483 : : constant, the right hand side of the init insn can
5484 : : be a pseudo. */
5485 : 741677 : || (! reverse_equiv_p (i)
5486 : 740264 : && (init_insn_rhs_dead_pseudo_p (i)
5487 : : /* If we reloaded the pseudo in an equivalence
5488 : : init insn, we cannot remove the equiv init
5489 : : insns and the init insns might write into
5490 : : const memory in this case. */
5491 : 734896 : || contains_reloaded_insn_p (i)))
5492 : : /* Prevent access beyond equivalent memory for
5493 : : paradoxical subregs. */
5494 : 736309 : || (MEM_P (x)
5495 : 1182549 : && maybe_gt (GET_MODE_SIZE (lra_reg_info[i].biggest_mode),
5496 : : GET_MODE_SIZE (GET_MODE (x))))
5497 : 1488348 : || (pic_offset_table_rtx
5498 : 51569 : && ((CONST_POOL_OK_P (PSEUDO_REGNO_MODE (i), x)
5499 : 7320 : && (targetm.preferred_reload_class
5500 : 3660 : (x, lra_get_allocno_class (i)) == NO_REGS))
5501 : 50006 : || contains_symbol_ref_p (x))))
5502 : 19532 : ira_reg_equiv[i].defined_p
5503 : 19532 : = ira_reg_equiv[i].caller_save_p = false;
5504 : 752749 : if (contains_reg_p (x, false, true))
5505 : 9662 : ira_reg_equiv[i].profitable_p = false;
5506 : 752749 : if (get_equiv (reg) != reg)
5507 : 728010 : bitmap_ior_into (equiv_insn_bitmap, &lra_reg_info[i].insn_bitmap);
5508 : : }
5509 : : }
5510 : 207618459 : for (i = FIRST_PSEUDO_REGISTER; i < new_regno_start; i++)
5511 : 204406062 : update_equiv (i);
5512 : : /* We should add all insns containing pseudos which should be
5513 : : substituted by their equivalences. */
5514 : 5620265 : EXECUTE_IF_SET_IN_BITMAP (equiv_insn_bitmap, 0, uid, bi)
5515 : 2407868 : lra_push_insn_by_uid (uid);
5516 : 3212397 : min_len = lra_insn_stack_length ();
5517 : 3212397 : new_insns_num = 0;
5518 : 3212397 : last_bb = NULL;
5519 : 3212397 : changed_p = false;
5520 : 3212397 : original_insn = NULL;
5521 : 167758628 : while ((new_min_len = lra_insn_stack_length ()) != 0)
5522 : : {
5523 : 161333834 : curr_insn = lra_pop_insn ();
5524 : 161333834 : --new_min_len;
5525 : 161333834 : curr_bb = BLOCK_FOR_INSN (curr_insn);
5526 : 161333834 : if (curr_bb != last_bb)
5527 : : {
5528 : 20895337 : last_bb = curr_bb;
5529 : 20895337 : bb_reload_num = lra_curr_reload_num;
5530 : : }
5531 : 161333834 : if (min_len > new_min_len)
5532 : : {
5533 : : min_len = new_min_len;
5534 : : new_insns_num = 0;
5535 : : original_insn = curr_insn;
5536 : : }
5537 : 7369366 : else if (combine_reload_insn (curr_insn, original_insn))
5538 : : {
5539 : 3441 : continue;
5540 : : }
5541 : 7365925 : if (new_insns_num > MAX_RELOAD_INSNS_NUMBER)
5542 : 0 : internal_error
5543 : 0 : ("maximum number of generated reload insns per insn achieved (%d)",
5544 : : MAX_RELOAD_INSNS_NUMBER);
5545 : 161330393 : new_insns_num++;
5546 : 161330393 : if (DEBUG_INSN_P (curr_insn))
5547 : : {
5548 : : /* We need to check equivalence in debug insn and change
5549 : : pseudo to the equivalent value if necessary. */
5550 : 52243762 : curr_id = lra_get_insn_recog_data (curr_insn);
5551 : 52243762 : if (bitmap_bit_p (equiv_insn_bitmap, INSN_UID (curr_insn)))
5552 : : {
5553 : 30512 : rtx old = *curr_id->operand_loc[0];
5554 : 30512 : *curr_id->operand_loc[0]
5555 : 30512 : = simplify_replace_fn_rtx (old, NULL_RTX,
5556 : : loc_equivalence_callback, curr_insn);
5557 : 30512 : if (old != *curr_id->operand_loc[0])
5558 : : {
5559 : : /* If we substitute pseudo by shared equivalence, we can fail
5560 : : to update LRA reg info and this can result in many
5561 : : unexpected consequences. So keep rtl unshared: */
5562 : 30512 : *curr_id->operand_loc[0]
5563 : 30512 : = copy_rtx (*curr_id->operand_loc[0]);
5564 : 30512 : lra_update_insn_regno_info (curr_insn);
5565 : 30512 : changed_p = true;
5566 : : }
5567 : : }
5568 : : }
5569 : 109086631 : else if (INSN_P (curr_insn))
5570 : : {
5571 : 108012283 : if ((set = single_set (curr_insn)) != NULL_RTX)
5572 : : {
5573 : 102640967 : nosubreg_dest = SET_DEST (set);
5574 : : /* The equivalence pseudo could be set up as SUBREG in a
5575 : : case when it is a call restore insn in a mode
5576 : : different from the pseudo mode. */
5577 : 102640967 : if (GET_CODE (nosubreg_dest) == SUBREG)
5578 : 1158651 : nosubreg_dest = SUBREG_REG (nosubreg_dest);
5579 : 103355635 : if ((REG_P (nosubreg_dest)
5580 : 75905770 : && (x = get_equiv (nosubreg_dest)) != nosubreg_dest
5581 : : /* Remove insns which set up a pseudo whose value
5582 : : cannot be changed. Such insns might be not in
5583 : : init_insns because we don't update equiv data
5584 : : during insn transformations.
5585 : :
5586 : : As an example, let suppose that a pseudo got
5587 : : hard register and on the 1st pass was not
5588 : : changed to equivalent constant. We generate an
5589 : : additional insn setting up the pseudo because of
5590 : : secondary memory movement. Then the pseudo is
5591 : : spilled and we use the equiv constant. In this
5592 : : case we should remove the additional insn and
5593 : : this insn is not init_insns list. */
5594 : 732778 : && (! MEM_P (x) || MEM_READONLY_P (x)
5595 : : /* Check that this is actually an insn setting
5596 : : up the equivalence. */
5597 : 338712 : || in_list_p (curr_insn,
5598 : 338712 : ira_reg_equiv
5599 : 338712 : [REGNO (nosubreg_dest)].init_insns)))
5600 : 177833402 : || (((x = get_equiv (SET_SRC (set))) != SET_SRC (set))
5601 : 2062336 : && in_list_p (curr_insn,
5602 : 1031168 : ira_reg_equiv
5603 : 1031168 : [REGNO (SET_SRC (set))].init_insns)
5604 : : /* This is a reverse equivalence to memory (see ira.cc)
5605 : : in store insn. We can reload all the destination and
5606 : : have an output reload which is a store to memory. If
5607 : : we just remove the insn, we will have the output
5608 : : reload storing an undefined value to the memory.
5609 : : Check that we did not reload the memory to prevent a
5610 : : wrong code generation. We could implement using the
5611 : : equivalence still in such case but doing this is not
5612 : : worth the efforts as such case is very rare. */
5613 : 1333 : && MEM_P (nosubreg_dest)))
5614 : : {
5615 : : /* This is equiv init insn of pseudo which did not get a
5616 : : hard register -- remove the insn. */
5617 : 714668 : if (lra_dump_file != NULL)
5618 : : {
5619 : 9 : fprintf (lra_dump_file,
5620 : : " Removing equiv init insn %i (freq=%d)\n",
5621 : 3 : INSN_UID (curr_insn),
5622 : 6 : REG_FREQ_FROM_BB (BLOCK_FOR_INSN (curr_insn)));
5623 : 3 : dump_insn_slim (lra_dump_file, curr_insn);
5624 : : }
5625 : 714668 : if (contains_reg_p (x, true, false))
5626 : 147623 : check_and_force_assignment_correctness_p = true;
5627 : 714668 : lra_set_insn_deleted (curr_insn);
5628 : 714668 : continue;
5629 : : }
5630 : : }
5631 : 107297615 : curr_id = lra_get_insn_recog_data (curr_insn);
5632 : 107297615 : curr_static_id = curr_id->insn_static_data;
5633 : 107297615 : init_curr_insn_input_reloads ();
5634 : 107297615 : init_curr_operand_mode ();
5635 : 107297615 : if (curr_insn_transform (false))
5636 : : changed_p = true;
5637 : : /* Check non-transformed insns too for equiv change as USE
5638 : : or CLOBBER don't need reloads but can contain pseudos
5639 : : being changed on their equivalences. */
5640 : 101137977 : else if (bitmap_bit_p (equiv_insn_bitmap, INSN_UID (curr_insn))
5641 : 101137977 : && loc_equivalence_change_p (&PATTERN (curr_insn)))
5642 : : {
5643 : 8 : lra_update_insn_regno_info (curr_insn);
5644 : 8 : changed_p = true;
5645 : : }
5646 : : }
5647 : : }
5648 : :
5649 : : /* If we used a new hard regno, changed_p should be true because the
5650 : : hard reg is assigned to a new pseudo. */
5651 : 3212397 : if (flag_checking && !changed_p)
5652 : : {
5653 : 133064690 : for (i = FIRST_PSEUDO_REGISTER; i < new_regno_start; i++)
5654 : 130469150 : if (lra_reg_info[i].nrefs != 0
5655 : 191080495 : && (hard_regno = lra_get_regno_hard_regno (i)) >= 0)
5656 : : {
5657 : 59186626 : int j, nregs = hard_regno_nregs (hard_regno,
5658 : 59186626 : PSEUDO_REGNO_MODE (i));
5659 : :
5660 : 120419763 : for (j = 0; j < nregs; j++)
5661 : 61233137 : lra_assert (df_regs_ever_live_p (hard_regno + j));
5662 : : }
5663 : : }
5664 : 2595580 : if (changed_p)
5665 : 616820 : lra_dump_insns_if_possible ("changed func after local");
5666 : 3212397 : return changed_p;
5667 : 3212397 : }
5668 : :
5669 : : static void initiate_invariants (void);
5670 : : static void finish_invariants (void);
5671 : :
5672 : : /* Initiate the LRA constraint pass. It is done once per
5673 : : function. */
5674 : : void
5675 : 1472101 : lra_constraints_init (void)
5676 : : {
5677 : 1472101 : initiate_invariants ();
5678 : 1472101 : }
5679 : :
5680 : : /* Finalize the LRA constraint pass. It is done once per
5681 : : function. */
5682 : : void
5683 : 1472101 : lra_constraints_finish (void)
5684 : : {
5685 : 1472101 : finish_invariants ();
5686 : 1472101 : }
5687 : :
5688 : :
5689 : :
5690 : : /* Structure describes invariants for ineheritance. */
5691 : : struct lra_invariant
5692 : : {
5693 : : /* The order number of the invariant. */
5694 : : int num;
5695 : : /* The invariant RTX. */
5696 : : rtx invariant_rtx;
5697 : : /* The origin insn of the invariant. */
5698 : : rtx_insn *insn;
5699 : : };
5700 : :
5701 : : typedef lra_invariant invariant_t;
5702 : : typedef invariant_t *invariant_ptr_t;
5703 : : typedef const invariant_t *const_invariant_ptr_t;
5704 : :
5705 : : /* Pointer to the inheritance invariants. */
5706 : : static vec<invariant_ptr_t> invariants;
5707 : :
5708 : : /* Allocation pool for the invariants. */
5709 : : static object_allocator<lra_invariant> *invariants_pool;
5710 : :
5711 : : /* Hash table for the invariants. */
5712 : : static htab_t invariant_table;
5713 : :
5714 : : /* Hash function for INVARIANT. */
5715 : : static hashval_t
5716 : 177180 : invariant_hash (const void *invariant)
5717 : : {
5718 : 177180 : rtx inv = ((const_invariant_ptr_t) invariant)->invariant_rtx;
5719 : 177180 : return lra_rtx_hash (inv);
5720 : : }
5721 : :
5722 : : /* Equal function for invariants INVARIANT1 and INVARIANT2. */
5723 : : static int
5724 : 56836 : invariant_eq_p (const void *invariant1, const void *invariant2)
5725 : : {
5726 : 56836 : rtx inv1 = ((const_invariant_ptr_t) invariant1)->invariant_rtx;
5727 : 56836 : rtx inv2 = ((const_invariant_ptr_t) invariant2)->invariant_rtx;
5728 : :
5729 : 56836 : return rtx_equal_p (inv1, inv2);
5730 : : }
5731 : :
5732 : : /* Insert INVARIANT_RTX into the table if it is not there yet. Return
5733 : : invariant which is in the table. */
5734 : : static invariant_ptr_t
5735 : 176988 : insert_invariant (rtx invariant_rtx)
5736 : : {
5737 : 176988 : void **entry_ptr;
5738 : 176988 : invariant_t invariant;
5739 : 176988 : invariant_ptr_t invariant_ptr;
5740 : :
5741 : 176988 : invariant.invariant_rtx = invariant_rtx;
5742 : 176988 : entry_ptr = htab_find_slot (invariant_table, &invariant, INSERT);
5743 : 176988 : if (*entry_ptr == NULL)
5744 : : {
5745 : 154375 : invariant_ptr = invariants_pool->allocate ();
5746 : 154375 : invariant_ptr->invariant_rtx = invariant_rtx;
5747 : 154375 : invariant_ptr->insn = NULL;
5748 : 154375 : invariants.safe_push (invariant_ptr);
5749 : 154375 : *entry_ptr = (void *) invariant_ptr;
5750 : : }
5751 : 176988 : return (invariant_ptr_t) *entry_ptr;
5752 : : }
5753 : :
5754 : : /* Initiate the invariant table. */
5755 : : static void
5756 : 1472101 : initiate_invariants (void)
5757 : : {
5758 : 1472101 : invariants.create (100);
5759 : 1472101 : invariants_pool
5760 : 1472101 : = new object_allocator<lra_invariant> ("Inheritance invariants");
5761 : 1472101 : invariant_table = htab_create (100, invariant_hash, invariant_eq_p, NULL);
5762 : 1472101 : }
5763 : :
5764 : : /* Finish the invariant table. */
5765 : : static void
5766 : 1472101 : finish_invariants (void)
5767 : : {
5768 : 1472101 : htab_delete (invariant_table);
5769 : 2944202 : delete invariants_pool;
5770 : 1472101 : invariants.release ();
5771 : 1472101 : }
5772 : :
5773 : : /* Make the invariant table empty. */
5774 : : static void
5775 : 12810047 : clear_invariants (void)
5776 : : {
5777 : 12810047 : htab_empty (invariant_table);
5778 : 12810047 : invariants_pool->release ();
5779 : 12810047 : invariants.truncate (0);
5780 : 12810047 : }
5781 : :
5782 : :
5783 : :
5784 : : /* This page contains code to do inheritance/split
5785 : : transformations. */
5786 : :
5787 : : /* Number of reloads passed so far in current EBB. */
5788 : : static int reloads_num;
5789 : :
5790 : : /* Number of calls passed so far in current EBB. */
5791 : : static int calls_num;
5792 : :
5793 : : /* Index ID is the CALLS_NUM associated the last call we saw with
5794 : : ABI identifier ID. */
5795 : : static int last_call_for_abi[NUM_ABI_IDS];
5796 : :
5797 : : /* Which registers have been fully or partially clobbered by a call
5798 : : since they were last used. */
5799 : : static HARD_REG_SET full_and_partial_call_clobbers;
5800 : :
5801 : : /* Current reload pseudo check for validity of elements in
5802 : : USAGE_INSNS. */
5803 : : static int curr_usage_insns_check;
5804 : :
5805 : : /* Info about last usage of registers in EBB to do inheritance/split
5806 : : transformation. Inheritance transformation is done from a spilled
5807 : : pseudo and split transformations from a hard register or a pseudo
5808 : : assigned to a hard register. */
5809 : : struct usage_insns
5810 : : {
5811 : : /* If the value is equal to CURR_USAGE_INSNS_CHECK, then the member
5812 : : value INSNS is valid. The insns is chain of optional debug insns
5813 : : and a finishing non-debug insn using the corresponding reg. The
5814 : : value is also used to mark the registers which are set up in the
5815 : : current insn. The negated insn uid is used for this. */
5816 : : int check;
5817 : : /* Value of global reloads_num at the last insn in INSNS. */
5818 : : int reloads_num;
5819 : : /* Value of global reloads_nums at the last insn in INSNS. */
5820 : : int calls_num;
5821 : : /* It can be true only for splitting. And it means that the restore
5822 : : insn should be put after insn given by the following member. */
5823 : : bool after_p;
5824 : : /* Next insns in the current EBB which use the original reg and the
5825 : : original reg value is not changed between the current insn and
5826 : : the next insns. In order words, e.g. for inheritance, if we need
5827 : : to use the original reg value again in the next insns we can try
5828 : : to use the value in a hard register from a reload insn of the
5829 : : current insn. */
5830 : : rtx insns;
5831 : : };
5832 : :
5833 : : /* Map: regno -> corresponding pseudo usage insns. */
5834 : : static struct usage_insns *usage_insns;
5835 : :
5836 : : static void
5837 : 247636002 : setup_next_usage_insn (int regno, rtx insn, int reloads_num, bool after_p)
5838 : : {
5839 : 247636002 : usage_insns[regno].check = curr_usage_insns_check;
5840 : 247636002 : usage_insns[regno].insns = insn;
5841 : 247636002 : usage_insns[regno].reloads_num = reloads_num;
5842 : 247636002 : usage_insns[regno].calls_num = calls_num;
5843 : 247636002 : usage_insns[regno].after_p = after_p;
5844 : 247636002 : if (regno >= FIRST_PSEUDO_REGISTER && reg_renumber[regno] >= 0)
5845 : 112290125 : remove_from_hard_reg_set (&full_and_partial_call_clobbers,
5846 : 112290125 : PSEUDO_REGNO_MODE (regno),
5847 : : reg_renumber[regno]);
5848 : 247636002 : }
5849 : :
5850 : : /* The function is used to form list REGNO usages which consists of
5851 : : optional debug insns finished by a non-debug insn using REGNO.
5852 : : RELOADS_NUM is current number of reload insns processed so far. */
5853 : : static void
5854 : 139206564 : add_next_usage_insn (int regno, rtx_insn *insn, int reloads_num)
5855 : : {
5856 : 139206564 : rtx next_usage_insns;
5857 : :
5858 : 139206564 : if (usage_insns[regno].check == curr_usage_insns_check
5859 : 71700475 : && (next_usage_insns = usage_insns[regno].insns) != NULL_RTX
5860 : 210907039 : && DEBUG_INSN_P (insn))
5861 : : {
5862 : : /* Check that we did not add the debug insn yet. */
5863 : 13572660 : if (next_usage_insns != insn
5864 : 13572660 : && (GET_CODE (next_usage_insns) != INSN_LIST
5865 : 5765554 : || XEXP (next_usage_insns, 0) != insn))
5866 : 13572646 : usage_insns[regno].insns = gen_rtx_INSN_LIST (VOIDmode, insn,
5867 : : next_usage_insns);
5868 : : }
5869 : 125633904 : else if (NONDEBUG_INSN_P (insn))
5870 : 125132859 : setup_next_usage_insn (regno, insn, reloads_num, false);
5871 : : else
5872 : 501045 : usage_insns[regno].check = 0;
5873 : 139206564 : }
5874 : :
5875 : : /* Return first non-debug insn in list USAGE_INSNS. */
5876 : : static rtx_insn *
5877 : 1175599 : skip_usage_debug_insns (rtx usage_insns)
5878 : : {
5879 : 1175599 : rtx insn;
5880 : :
5881 : : /* Skip debug insns. */
5882 : 1175599 : for (insn = usage_insns;
5883 : 1451121 : insn != NULL_RTX && GET_CODE (insn) == INSN_LIST;
5884 : 275522 : insn = XEXP (insn, 1))
5885 : : ;
5886 : 1175599 : return safe_as_a <rtx_insn *> (insn);
5887 : : }
5888 : :
5889 : : /* Return true if we need secondary memory moves for insn in
5890 : : USAGE_INSNS after inserting inherited pseudo of class INHER_CL
5891 : : into the insn. */
5892 : : static bool
5893 : 1175606 : check_secondary_memory_needed_p (enum reg_class inher_cl ATTRIBUTE_UNUSED,
5894 : : rtx usage_insns ATTRIBUTE_UNUSED)
5895 : : {
5896 : 1175606 : rtx_insn *insn;
5897 : 1175606 : rtx set, dest;
5898 : 1175606 : enum reg_class cl;
5899 : :
5900 : 1175606 : if (inher_cl == ALL_REGS
5901 : 1175606 : || (insn = skip_usage_debug_insns (usage_insns)) == NULL_RTX)
5902 : : return false;
5903 : 1175599 : lra_assert (INSN_P (insn));
5904 : 1175599 : if ((set = single_set (insn)) == NULL_RTX || ! REG_P (SET_DEST (set)))
5905 : : return false;
5906 : 1137873 : dest = SET_DEST (set);
5907 : 1137873 : if (! REG_P (dest))
5908 : : return false;
5909 : 1137873 : lra_assert (inher_cl != NO_REGS);
5910 : 1137873 : cl = get_reg_class (REGNO (dest));
5911 : 1137873 : return (cl != NO_REGS && cl != ALL_REGS
5912 : 1137873 : && targetm.secondary_memory_needed (GET_MODE (dest), inher_cl, cl));
5913 : : }
5914 : :
5915 : : /* Registers involved in inheritance/split in the current EBB
5916 : : (inheritance/split pseudos and original registers). */
5917 : : static bitmap_head check_only_regs;
5918 : :
5919 : : /* Reload pseudos cannot be involded in invariant inheritance in the
5920 : : current EBB. */
5921 : : static bitmap_head invalid_invariant_regs;
5922 : :
5923 : : /* Do inheritance transformations for insn INSN, which defines (if
5924 : : DEF_P) or uses ORIGINAL_REGNO. NEXT_USAGE_INSNS specifies which
5925 : : instruction in the EBB next uses ORIGINAL_REGNO; it has the same
5926 : : form as the "insns" field of usage_insns. Return true if we
5927 : : succeed in such transformation.
5928 : :
5929 : : The transformations look like:
5930 : :
5931 : : p <- ... i <- ...
5932 : : ... p <- i (new insn)
5933 : : ... =>
5934 : : <- ... p ... <- ... i ...
5935 : : or
5936 : : ... i <- p (new insn)
5937 : : <- ... p ... <- ... i ...
5938 : : ... =>
5939 : : <- ... p ... <- ... i ...
5940 : : where p is a spilled original pseudo and i is a new inheritance pseudo.
5941 : :
5942 : :
5943 : : The inheritance pseudo has the smallest class of two classes CL and
5944 : : class of ORIGINAL REGNO. */
5945 : : static bool
5946 : 1271909 : inherit_reload_reg (bool def_p, int original_regno,
5947 : : enum reg_class cl, rtx_insn *insn, rtx next_usage_insns)
5948 : : {
5949 : 1271909 : if (optimize_function_for_size_p (cfun))
5950 : : return false;
5951 : :
5952 : 1240747 : enum reg_class rclass = lra_get_allocno_class (original_regno);
5953 : 1240747 : rtx original_reg = regno_reg_rtx[original_regno];
5954 : 1240747 : rtx new_reg, usage_insn;
5955 : 1240747 : rtx_insn *new_insns;
5956 : :
5957 : 1240747 : lra_assert (! usage_insns[original_regno].after_p);
5958 : 1240747 : if (lra_dump_file != NULL)
5959 : 2 : fprintf (lra_dump_file,
5960 : : " <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n");
5961 : 1240747 : if (! ira_reg_classes_intersect_p[cl][rclass])
5962 : : {
5963 : 65141 : if (lra_dump_file != NULL)
5964 : : {
5965 : 0 : fprintf (lra_dump_file,
5966 : : " Rejecting inheritance for %d "
5967 : : "because of disjoint classes %s and %s\n",
5968 : : original_regno, reg_class_names[cl],
5969 : : reg_class_names[rclass]);
5970 : 0 : fprintf (lra_dump_file,
5971 : : " >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n");
5972 : : }
5973 : 65141 : return false;
5974 : : }
5975 : 1175606 : if ((ira_class_subset_p[cl][rclass] && cl != rclass)
5976 : : /* We don't use a subset of two classes because it can be
5977 : : NO_REGS. This transformation is still profitable in most
5978 : : cases even if the classes are not intersected as register
5979 : : move is probably cheaper than a memory load. */
5980 : 434072 : || ira_class_hard_regs_num[cl] < ira_class_hard_regs_num[rclass])
5981 : : {
5982 : 741534 : if (lra_dump_file != NULL)
5983 : 2 : fprintf (lra_dump_file, " Use smallest class of %s and %s\n",
5984 : : reg_class_names[cl], reg_class_names[rclass]);
5985 : :
5986 : : rclass = cl;
5987 : : }
5988 : 1175606 : if (check_secondary_memory_needed_p (rclass, next_usage_insns))
5989 : : {
5990 : : /* Reject inheritance resulting in secondary memory moves.
5991 : : Otherwise, there is a danger in LRA cycling. Also such
5992 : : transformation will be unprofitable. */
5993 : 13239 : if (lra_dump_file != NULL)
5994 : : {
5995 : 0 : rtx_insn *insn = skip_usage_debug_insns (next_usage_insns);
5996 : 0 : rtx set = single_set (insn);
5997 : :
5998 : 0 : lra_assert (set != NULL_RTX);
5999 : :
6000 : 0 : rtx dest = SET_DEST (set);
6001 : :
6002 : 0 : lra_assert (REG_P (dest));
6003 : 0 : fprintf (lra_dump_file,
6004 : : " Rejecting inheritance for insn %d(%s)<-%d(%s) "
6005 : : "as secondary mem is needed\n",
6006 : 0 : REGNO (dest), reg_class_names[get_reg_class (REGNO (dest))],
6007 : 0 : original_regno, reg_class_names[rclass]);
6008 : 0 : fprintf (lra_dump_file,
6009 : : " >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n");
6010 : : }
6011 : 13239 : return false;
6012 : : }
6013 : 1162367 : if (ira_reg_class_min_nregs[rclass][GET_MODE (original_reg)]
6014 : 1162367 : != ira_reg_class_max_nregs[rclass][GET_MODE (original_reg)])
6015 : : {
6016 : 29 : if (lra_dump_file != NULL)
6017 : : {
6018 : 0 : fprintf (lra_dump_file,
6019 : : " Rejecting inheritance for %d "
6020 : : "because of requiring non-uniform class %s\n",
6021 : : original_regno, reg_class_names[rclass]);
6022 : 0 : fprintf (lra_dump_file,
6023 : : " >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n");
6024 : : }
6025 : 29 : return false;
6026 : : }
6027 : 1162338 : new_reg = lra_create_new_reg (GET_MODE (original_reg), original_reg,
6028 : : rclass, NULL, "inheritance");
6029 : 1162338 : start_sequence ();
6030 : 1162338 : if (def_p)
6031 : 542733 : lra_emit_move (original_reg, new_reg);
6032 : : else
6033 : 619605 : lra_emit_move (new_reg, original_reg);
6034 : 1162338 : new_insns = end_sequence ();
6035 : 1162338 : if (NEXT_INSN (new_insns) != NULL_RTX)
6036 : : {
6037 : 0 : if (lra_dump_file != NULL)
6038 : : {
6039 : 0 : fprintf (lra_dump_file,
6040 : : " Rejecting inheritance %d->%d "
6041 : : "as it results in 2 or more insns:\n",
6042 : : original_regno, REGNO (new_reg));
6043 : 0 : dump_rtl_slim (lra_dump_file, new_insns, NULL, -1, 0);
6044 : 0 : fprintf (lra_dump_file,
6045 : : " >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n");
6046 : : }
6047 : 0 : return false;
6048 : : }
6049 : 1162338 : lra_substitute_pseudo_within_insn (insn, original_regno, new_reg, false);
6050 : 1162338 : lra_update_insn_regno_info (insn);
6051 : 1162338 : if (! def_p)
6052 : : /* We now have a new usage insn for original regno. */
6053 : 619605 : setup_next_usage_insn (original_regno, new_insns, reloads_num, false);
6054 : 1162338 : if (lra_dump_file != NULL)
6055 : 2 : fprintf (lra_dump_file, " Original reg change %d->%d (bb%d):\n",
6056 : 2 : original_regno, REGNO (new_reg), BLOCK_FOR_INSN (insn)->index);
6057 : 1162338 : lra_reg_info[REGNO (new_reg)].restore_rtx = regno_reg_rtx[original_regno];
6058 : 1162338 : bitmap_set_bit (&check_only_regs, REGNO (new_reg));
6059 : 1162338 : bitmap_set_bit (&check_only_regs, original_regno);
6060 : 1162338 : bitmap_set_bit (&lra_inheritance_pseudos, REGNO (new_reg));
6061 : 1162338 : if (def_p)
6062 : 542733 : lra_process_new_insns (insn, NULL, new_insns,
6063 : : "Add original<-inheritance");
6064 : : else
6065 : 619605 : lra_process_new_insns (insn, new_insns, NULL,
6066 : : "Add inheritance<-original");
6067 : 2597923 : while (next_usage_insns != NULL_RTX)
6068 : : {
6069 : 1435585 : if (GET_CODE (next_usage_insns) != INSN_LIST)
6070 : : {
6071 : 1162338 : usage_insn = next_usage_insns;
6072 : 1162338 : lra_assert (NONDEBUG_INSN_P (usage_insn));
6073 : : next_usage_insns = NULL;
6074 : : }
6075 : : else
6076 : : {
6077 : 273247 : usage_insn = XEXP (next_usage_insns, 0);
6078 : 273247 : lra_assert (DEBUG_INSN_P (usage_insn));
6079 : 273247 : next_usage_insns = XEXP (next_usage_insns, 1);
6080 : : }
6081 : 1435585 : lra_substitute_pseudo (&usage_insn, original_regno, new_reg, false,
6082 : 1435585 : DEBUG_INSN_P (usage_insn));
6083 : 1435585 : lra_update_insn_regno_info (as_a <rtx_insn *> (usage_insn));
6084 : 1435585 : if (lra_dump_file != NULL)
6085 : : {
6086 : 2 : basic_block bb = BLOCK_FOR_INSN (usage_insn);
6087 : 2 : fprintf (lra_dump_file,
6088 : : " Inheritance reuse change %d->%d (bb%d):\n",
6089 : : original_regno, REGNO (new_reg),
6090 : : bb ? bb->index : -1);
6091 : 2 : dump_insn_slim (lra_dump_file, as_a <rtx_insn *> (usage_insn));
6092 : : }
6093 : : }
6094 : 1162338 : if (lra_dump_file != NULL)
6095 : 2 : fprintf (lra_dump_file,
6096 : : " >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n");
6097 : : return true;
6098 : : }
6099 : :
6100 : : /* Return true if we need a caller save/restore for pseudo REGNO which
6101 : : was assigned to a hard register. */
6102 : : static inline bool
6103 : 114918820 : need_for_call_save_p (int regno)
6104 : : {
6105 : 114918820 : lra_assert (regno >= FIRST_PSEUDO_REGISTER && reg_renumber[regno] >= 0);
6106 : 114918820 : if (usage_insns[regno].calls_num < calls_num)
6107 : : {
6108 : : unsigned int abis = 0;
6109 : 117450489 : for (unsigned int i = 0; i < NUM_ABI_IDS; ++i)
6110 : 108415836 : if (last_call_for_abi[i] > usage_insns[regno].calls_num)
6111 : 9034653 : abis |= 1 << i;
6112 : 9034653 : gcc_assert (abis);
6113 : 9034653 : if (call_clobbered_in_region_p (abis, full_and_partial_call_clobbers,
6114 : 9034653 : PSEUDO_REGNO_MODE (regno),
6115 : : reg_renumber[regno]))
6116 : : return true;
6117 : : }
6118 : : return false;
6119 : : }
6120 : :
6121 : : /* Global registers occurring in the current EBB. */
6122 : : static bitmap_head ebb_global_regs;
6123 : :
6124 : : /* Return true if we need a split for hard register REGNO or pseudo
6125 : : REGNO which was assigned to a hard register.
6126 : : POTENTIAL_RELOAD_HARD_REGS contains hard registers which might be
6127 : : used for reloads since the EBB end. It is an approximation of the
6128 : : used hard registers in the split range. The exact value would
6129 : : require expensive calculations. If we were aggressive with
6130 : : splitting because of the approximation, the split pseudo will save
6131 : : the same hard register assignment and will be removed in the undo
6132 : : pass. We still need the approximation because too aggressive
6133 : : splitting would result in too inaccurate cost calculation in the
6134 : : assignment pass because of too many generated moves which will be
6135 : : probably removed in the undo pass. */
6136 : : static inline bool
6137 : 242690052 : need_for_split_p (HARD_REG_SET potential_reload_hard_regs, int regno)
6138 : : {
6139 : 242690052 : int hard_regno = regno < FIRST_PSEUDO_REGISTER ? regno : reg_renumber[regno];
6140 : :
6141 : 242690052 : lra_assert (hard_regno >= 0);
6142 : 242690052 : return ((TEST_HARD_REG_BIT (potential_reload_hard_regs, hard_regno)
6143 : : /* Don't split eliminable hard registers, otherwise we can
6144 : : split hard registers like hard frame pointer, which
6145 : : lives on BB start/end according to DF-infrastructure,
6146 : : when there is a pseudo assigned to the register and
6147 : : living in the same BB. */
6148 : 662693 : && (regno >= FIRST_PSEUDO_REGISTER
6149 : 43848 : || ! TEST_HARD_REG_BIT (eliminable_regset, hard_regno))
6150 : 633191 : && ! TEST_HARD_REG_BIT (lra_no_alloc_regs, hard_regno)
6151 : : /* Don't split call clobbered hard regs living through
6152 : : calls, otherwise we might have a check problem in the
6153 : : assign sub-pass as in the most cases (exception is a
6154 : : situation when check_and_force_assignment_correctness_p value is
6155 : : true) the assign pass assumes that all pseudos living
6156 : : through calls are assigned to call saved hard regs. */
6157 : 619937 : && (regno >= FIRST_PSEUDO_REGISTER
6158 : 1092 : || !TEST_HARD_REG_BIT (full_and_partial_call_clobbers, regno))
6159 : : /* We need at least 2 reloads to make pseudo splitting
6160 : : profitable. We should provide hard regno splitting in
6161 : : any case to solve 1st insn scheduling problem when
6162 : : moving hard register definition up might result in
6163 : : impossibility to find hard register for reload pseudo of
6164 : : small register class. */
6165 : 1239788 : && (usage_insns[regno].reloads_num
6166 : 1238739 : + (regno < FIRST_PSEUDO_REGISTER ? 0 : 3) < reloads_num)
6167 : 2600 : && (regno < FIRST_PSEUDO_REGISTER
6168 : : /* For short living pseudos, spilling + inheritance can
6169 : : be considered a substitution for splitting.
6170 : : Therefore we do not splitting for local pseudos. It
6171 : : decreases also aggressiveness of splitting. The
6172 : : minimal number of references is chosen taking into
6173 : : account that for 2 references splitting has no sense
6174 : : as we can just spill the pseudo. */
6175 : : || (regno >= FIRST_PSEUDO_REGISTER
6176 : 2553 : && lra_reg_info[regno].nrefs > 3
6177 : 2202 : && bitmap_bit_p (&ebb_global_regs, regno))))
6178 : 243351587 : || (regno >= FIRST_PSEUDO_REGISTER && need_for_call_save_p (regno)));
6179 : : }
6180 : :
6181 : : /* Return class for the split pseudo created from original pseudo with
6182 : : ALLOCNO_CLASS and MODE which got a hard register HARD_REGNO. We
6183 : : choose subclass of ALLOCNO_CLASS which contains HARD_REGNO and
6184 : : results in no secondary memory movements. */
6185 : : static enum reg_class
6186 : 1316 : choose_split_class (enum reg_class allocno_class,
6187 : : int hard_regno ATTRIBUTE_UNUSED,
6188 : : machine_mode mode ATTRIBUTE_UNUSED)
6189 : : {
6190 : 1316 : int i;
6191 : 1316 : enum reg_class cl, best_cl = NO_REGS;
6192 : 1316 : enum reg_class hard_reg_class ATTRIBUTE_UNUSED
6193 : : = REGNO_REG_CLASS (hard_regno);
6194 : :
6195 : 1316 : if (! targetm.secondary_memory_needed (mode, allocno_class, allocno_class)
6196 : 1316 : && TEST_HARD_REG_BIT (reg_class_contents[allocno_class], hard_regno))
6197 : : return allocno_class;
6198 : 0 : for (i = 0;
6199 : 0 : (cl = reg_class_subclasses[allocno_class][i]) != LIM_REG_CLASSES;
6200 : : i++)
6201 : 0 : if (! targetm.secondary_memory_needed (mode, cl, hard_reg_class)
6202 : 0 : && ! targetm.secondary_memory_needed (mode, hard_reg_class, cl)
6203 : 0 : && TEST_HARD_REG_BIT (reg_class_contents[cl], hard_regno)
6204 : 0 : && (best_cl == NO_REGS
6205 : 0 : || ira_class_hard_regs_num[best_cl] < ira_class_hard_regs_num[cl]))
6206 : : best_cl = cl;
6207 : : return best_cl;
6208 : : }
6209 : :
6210 : : /* Copy any equivalence information from ORIGINAL_REGNO to NEW_REGNO. It only
6211 : : makes sense to call this function if NEW_REGNO is always equal to
6212 : : ORIGINAL_REGNO. Set up defined_p flag when caller_save_p flag is set up and
6213 : : CALL_SAVE_P is true. */
6214 : :
6215 : : static void
6216 : 628021 : lra_copy_reg_equiv (unsigned int new_regno, unsigned int original_regno,
6217 : : bool call_save_p)
6218 : : {
6219 : 628021 : if (!ira_reg_equiv[original_regno].defined_p
6220 : 564558 : && !(call_save_p && ira_reg_equiv[original_regno].caller_save_p))
6221 : : return;
6222 : :
6223 : 63636 : ira_expand_reg_equiv ();
6224 : 63636 : ira_reg_equiv[new_regno].defined_p = true;
6225 : 63636 : if (ira_reg_equiv[original_regno].memory)
6226 : 29613 : ira_reg_equiv[new_regno].memory
6227 : 29613 : = copy_rtx (ira_reg_equiv[original_regno].memory);
6228 : 63636 : if (ira_reg_equiv[original_regno].constant)
6229 : 26810 : ira_reg_equiv[new_regno].constant
6230 : 26810 : = copy_rtx (ira_reg_equiv[original_regno].constant);
6231 : 63636 : if (ira_reg_equiv[original_regno].invariant)
6232 : 7213 : ira_reg_equiv[new_regno].invariant
6233 : 7213 : = copy_rtx (ira_reg_equiv[original_regno].invariant);
6234 : : }
6235 : :
6236 : : /* Do split transformations for insn INSN, which defines or uses
6237 : : ORIGINAL_REGNO. NEXT_USAGE_INSNS specifies which instruction in
6238 : : the EBB next uses ORIGINAL_REGNO; it has the same form as the
6239 : : "insns" field of usage_insns. If TO is not NULL, we don't use
6240 : : usage_insns, we put restore insns after TO insn. It is a case when
6241 : : we call it from lra_split_hard_reg_for, outside the inheritance
6242 : : pass.
6243 : :
6244 : : The transformations look like:
6245 : :
6246 : : p <- ... p <- ...
6247 : : ... s <- p (new insn -- save)
6248 : : ... =>
6249 : : ... p <- s (new insn -- restore)
6250 : : <- ... p ... <- ... p ...
6251 : : or
6252 : : <- ... p ... <- ... p ...
6253 : : ... s <- p (new insn -- save)
6254 : : ... =>
6255 : : ... p <- s (new insn -- restore)
6256 : : <- ... p ... <- ... p ...
6257 : :
6258 : : where p is an original pseudo got a hard register or a hard
6259 : : register and s is a new split pseudo. The save is put before INSN
6260 : : if BEFORE_P is true. Return true if we succeed in such
6261 : : transformation. */
6262 : : static bool
6263 : 629917 : split_reg (bool before_p, int original_regno, rtx_insn *insn,
6264 : : rtx next_usage_insns, rtx_insn *to)
6265 : : {
6266 : 629917 : enum reg_class rclass;
6267 : 629917 : rtx original_reg;
6268 : 629917 : int hard_regno, nregs;
6269 : 629917 : rtx new_reg, usage_insn;
6270 : 629917 : rtx_insn *restore, *save;
6271 : 629917 : bool after_p;
6272 : 629917 : bool call_save_p;
6273 : 629917 : machine_mode mode;
6274 : :
6275 : 629917 : if (original_regno < FIRST_PSEUDO_REGISTER)
6276 : : {
6277 : 206 : rclass = ira_allocno_class_translate[REGNO_REG_CLASS (original_regno)];
6278 : 206 : hard_regno = original_regno;
6279 : 206 : call_save_p = false;
6280 : 206 : nregs = 1;
6281 : 206 : mode = lra_reg_info[hard_regno].biggest_mode;
6282 : 206 : machine_mode reg_rtx_mode = GET_MODE (regno_reg_rtx[hard_regno]);
6283 : : /* A reg can have a biggest_mode of VOIDmode if it was only ever seen as
6284 : : part of a multi-word register. In that case, just use the reg_rtx
6285 : : mode. Do the same also if the biggest mode was larger than a register
6286 : : or we can not compare the modes. Otherwise, limit the size to that of
6287 : : the biggest access in the function or to the natural mode at least. */
6288 : 206 : if (mode == VOIDmode
6289 : 206 : || !ordered_p (GET_MODE_PRECISION (mode),
6290 : 206 : GET_MODE_PRECISION (reg_rtx_mode))
6291 : 206 : || paradoxical_subreg_p (mode, reg_rtx_mode)
6292 : 411 : || maybe_gt (GET_MODE_PRECISION (reg_rtx_mode), GET_MODE_PRECISION (mode)))
6293 : : {
6294 : 629917 : original_reg = regno_reg_rtx[hard_regno];
6295 : 629917 : mode = reg_rtx_mode;
6296 : : }
6297 : : else
6298 : 189 : original_reg = gen_rtx_REG (mode, hard_regno);
6299 : : }
6300 : : else
6301 : : {
6302 : 629711 : mode = PSEUDO_REGNO_MODE (original_regno);
6303 : 629711 : hard_regno = reg_renumber[original_regno];
6304 : 629711 : nregs = hard_regno_nregs (hard_regno, mode);
6305 : 629711 : rclass = lra_get_allocno_class (original_regno);
6306 : 629711 : original_reg = regno_reg_rtx[original_regno];
6307 : 629711 : call_save_p = need_for_call_save_p (original_regno);
6308 : : }
6309 : 629917 : lra_assert (hard_regno >= 0);
6310 : 629917 : if (lra_dump_file != NULL)
6311 : 0 : fprintf (lra_dump_file,
6312 : : " ((((((((((((((((((((((((((((((((((((((((((((((((\n");
6313 : :
6314 : 629917 : if (call_save_p)
6315 : : {
6316 : 628601 : mode = HARD_REGNO_CALLER_SAVE_MODE (hard_regno,
6317 : : hard_regno_nregs (hard_regno, mode),
6318 : : mode);
6319 : 628601 : new_reg = lra_create_new_reg (mode, NULL_RTX, NO_REGS, NULL, "save");
6320 : : }
6321 : : else
6322 : : {
6323 : 1316 : rclass = choose_split_class (rclass, hard_regno, mode);
6324 : 1316 : if (rclass == NO_REGS)
6325 : : {
6326 : 0 : if (lra_dump_file != NULL)
6327 : : {
6328 : 0 : fprintf (lra_dump_file,
6329 : : " Rejecting split of %d(%s): "
6330 : : "no good reg class for %d(%s)\n",
6331 : : original_regno,
6332 : 0 : reg_class_names[lra_get_allocno_class (original_regno)],
6333 : : hard_regno,
6334 : 0 : reg_class_names[REGNO_REG_CLASS (hard_regno)]);
6335 : 0 : fprintf
6336 : 0 : (lra_dump_file,
6337 : : " ))))))))))))))))))))))))))))))))))))))))))))))))\n");
6338 : : }
6339 : 0 : return false;
6340 : : }
6341 : : /* Split_if_necessary can split hard registers used as part of a
6342 : : multi-register mode but splits each register individually. The
6343 : : mode used for each independent register may not be supported
6344 : : so reject the split. Splitting the wider mode should theoretically
6345 : : be possible but is not implemented. */
6346 : 1316 : if (!targetm.hard_regno_mode_ok (hard_regno, mode))
6347 : : {
6348 : 0 : if (lra_dump_file != NULL)
6349 : : {
6350 : 0 : fprintf (lra_dump_file,
6351 : : " Rejecting split of %d(%s): unsuitable mode %s\n",
6352 : : original_regno,
6353 : 0 : reg_class_names[lra_get_allocno_class (original_regno)],
6354 : 0 : GET_MODE_NAME (mode));
6355 : 0 : fprintf
6356 : 0 : (lra_dump_file,
6357 : : " ))))))))))))))))))))))))))))))))))))))))))))))))\n");
6358 : : }
6359 : 0 : return false;
6360 : : }
6361 : 1316 : new_reg = lra_create_new_reg (mode, original_reg, rclass, NULL, "split");
6362 : 1316 : reg_renumber[REGNO (new_reg)] = hard_regno;
6363 : : }
6364 : 629917 : int new_regno = REGNO (new_reg);
6365 : 629917 : save = emit_spill_move (true, new_reg, original_reg);
6366 : 629917 : if (NEXT_INSN (save) != NULL_RTX && !call_save_p)
6367 : : {
6368 : 0 : if (lra_dump_file != NULL)
6369 : : {
6370 : 0 : fprintf
6371 : 0 : (lra_dump_file,
6372 : : " Rejecting split %d->%d resulting in > 2 save insns:\n",
6373 : : original_regno, new_regno);
6374 : 0 : dump_rtl_slim (lra_dump_file, save, NULL, -1, 0);
6375 : 0 : fprintf (lra_dump_file,
6376 : : " ))))))))))))))))))))))))))))))))))))))))))))))))\n");
6377 : : }
6378 : 0 : return false;
6379 : : }
6380 : 629917 : restore = emit_spill_move (false, new_reg, original_reg);
6381 : 629917 : if (NEXT_INSN (restore) != NULL_RTX && !call_save_p)
6382 : : {
6383 : 0 : if (lra_dump_file != NULL)
6384 : : {
6385 : 0 : fprintf (lra_dump_file,
6386 : : " Rejecting split %d->%d "
6387 : : "resulting in > 2 restore insns:\n",
6388 : : original_regno, new_regno);
6389 : 0 : dump_rtl_slim (lra_dump_file, restore, NULL, -1, 0);
6390 : 0 : fprintf (lra_dump_file,
6391 : : " ))))))))))))))))))))))))))))))))))))))))))))))))\n");
6392 : : }
6393 : 0 : return false;
6394 : : }
6395 : : /* Transfer equivalence information to the spill register, so that
6396 : : if we fail to allocate the spill register, we have the option of
6397 : : rematerializing the original value instead of spilling to the stack. */
6398 : 629917 : if (!HARD_REGISTER_NUM_P (original_regno)
6399 : 629711 : && mode == PSEUDO_REGNO_MODE (original_regno))
6400 : 628021 : lra_copy_reg_equiv (new_regno, original_regno, call_save_p);
6401 : 629917 : lra_reg_info[new_regno].restore_rtx = regno_reg_rtx[original_regno];
6402 : 629917 : bitmap_set_bit (&lra_split_regs, new_regno);
6403 : 629917 : if (to != NULL)
6404 : : {
6405 : 159 : lra_assert (next_usage_insns == NULL);
6406 : 159 : usage_insn = to;
6407 : 159 : after_p = true;
6408 : : }
6409 : : else
6410 : : {
6411 : : /* We need check_only_regs only inside the inheritance pass. */
6412 : 629758 : bitmap_set_bit (&check_only_regs, new_regno);
6413 : 629758 : bitmap_set_bit (&check_only_regs, original_regno);
6414 : 629758 : after_p = usage_insns[original_regno].after_p;
6415 : 714641 : for (;;)
6416 : : {
6417 : 714641 : if (GET_CODE (next_usage_insns) != INSN_LIST)
6418 : : {
6419 : 629758 : usage_insn = next_usage_insns;
6420 : 629758 : break;
6421 : : }
6422 : 84883 : usage_insn = XEXP (next_usage_insns, 0);
6423 : 84883 : lra_assert (DEBUG_INSN_P (usage_insn));
6424 : 84883 : next_usage_insns = XEXP (next_usage_insns, 1);
6425 : 84883 : lra_substitute_pseudo (&usage_insn, original_regno, new_reg, false,
6426 : : true);
6427 : 84883 : lra_update_insn_regno_info (as_a <rtx_insn *> (usage_insn));
6428 : 84883 : if (lra_dump_file != NULL)
6429 : : {
6430 : 0 : fprintf (lra_dump_file, " Split reuse change %d->%d:\n",
6431 : : original_regno, new_regno);
6432 : 0 : dump_insn_slim (lra_dump_file, as_a <rtx_insn *> (usage_insn));
6433 : : }
6434 : : }
6435 : : }
6436 : 629917 : lra_assert (NOTE_P (usage_insn) || NONDEBUG_INSN_P (usage_insn));
6437 : 629917 : lra_assert (usage_insn != insn || (after_p && before_p));
6438 : 1070732 : lra_process_new_insns (as_a <rtx_insn *> (usage_insn),
6439 : : after_p ? NULL : restore,
6440 : : after_p ? restore : NULL,
6441 : : call_save_p ? "Add reg<-save" : "Add reg<-split");
6442 : 629917 : if (call_save_p
6443 : 628601 : && first_call_insn != NULL
6444 : 1258518 : && BLOCK_FOR_INSN (first_call_insn) != BLOCK_FOR_INSN (insn))
6445 : : /* PR116028: If original_regno is a pseudo that has been assigned a
6446 : : callee-saved hard register, then emit the spill insn before the call
6447 : : insn 'first_call_insn' instead of adjacent to 'insn'. If 'insn'
6448 : : and 'first_call_insn' belong to the same EBB but to two separate
6449 : : BBs, and if 'insn' is present in the entry BB, then generating the
6450 : : spill insn in the entry BB can prevent shrink wrap from happening.
6451 : : This is because the spill insn references the stack pointer and
6452 : : hence the prolog gets generated in the entry BB itself. It is
6453 : : also more efficient to generate the spill before
6454 : : 'first_call_insn' as the spill now occurs only in the path
6455 : : containing the call. */
6456 : 23033 : lra_process_new_insns (first_call_insn, save, NULL, "Add save<-reg");
6457 : : else
6458 : 1214444 : lra_process_new_insns (insn, before_p ? save : NULL,
6459 : : before_p ? NULL : save,
6460 : : call_save_p ? "Add save<-reg" : "Add split<-reg");
6461 : 629917 : if (nregs > 1 || original_regno < FIRST_PSEUDO_REGISTER)
6462 : : /* If we are trying to split multi-register. We should check
6463 : : conflicts on the next assignment sub-pass. IRA can allocate on
6464 : : sub-register levels, LRA do this on pseudos level right now and
6465 : : this discrepancy may create allocation conflicts after
6466 : : splitting.
6467 : :
6468 : : If we are trying to split hard register we should also check conflicts
6469 : : as such splitting can create artificial conflict of the hard register
6470 : : with another pseudo because of simplified conflict calculation in
6471 : : LRA. */
6472 : 10044 : check_and_force_assignment_correctness_p = true;
6473 : 629917 : if (lra_dump_file != NULL)
6474 : 0 : fprintf (lra_dump_file,
6475 : : " ))))))))))))))))))))))))))))))))))))))))))))))))\n");
6476 : : return true;
6477 : : }
6478 : :
6479 : : /* Split a hard reg for reload pseudo REGNO having RCLASS and living
6480 : : in the range [FROM, TO]. Return true if did a split. Otherwise,
6481 : : return false. */
6482 : : bool
6483 : 1635 : spill_hard_reg_in_range (int regno, enum reg_class rclass, rtx_insn *from, rtx_insn *to)
6484 : : {
6485 : 1635 : int i, hard_regno;
6486 : 1635 : int rclass_size;
6487 : 1635 : rtx_insn *insn;
6488 : 1635 : unsigned int uid;
6489 : 1635 : bitmap_iterator bi;
6490 : 1635 : HARD_REG_SET ignore;
6491 : :
6492 : 1635 : lra_assert (from != NULL && to != NULL);
6493 : 1635 : ignore = lra_no_alloc_regs;
6494 : 4766 : EXECUTE_IF_SET_IN_BITMAP (&lra_reg_info[regno].insn_bitmap, 0, uid, bi)
6495 : : {
6496 : 3131 : lra_insn_recog_data_t id = lra_insn_recog_data[uid];
6497 : 3131 : struct lra_static_insn_data *static_id = id->insn_static_data;
6498 : 3131 : struct lra_insn_reg *reg;
6499 : :
6500 : 10417 : for (reg = id->regs; reg != NULL; reg = reg->next)
6501 : 7286 : if (reg->regno < FIRST_PSEUDO_REGISTER)
6502 : 707 : SET_HARD_REG_BIT (ignore, reg->regno);
6503 : 4850 : for (reg = static_id->hard_regs; reg != NULL; reg = reg->next)
6504 : 1719 : SET_HARD_REG_BIT (ignore, reg->regno);
6505 : : }
6506 : 1635 : rclass_size = ira_class_hard_regs_num[rclass];
6507 : 4705 : for (i = 0; i < rclass_size; i++)
6508 : : {
6509 : 3229 : hard_regno = ira_class_hard_regs[rclass][i];
6510 : 3229 : if (! TEST_HARD_REG_BIT (lra_reg_info[regno].conflict_hard_regs, hard_regno)
6511 : 3229 : || TEST_HARD_REG_BIT (ignore, hard_regno))
6512 : 3064 : continue;
6513 : 476 : for (insn = from; insn != NEXT_INSN (to); insn = NEXT_INSN (insn))
6514 : : {
6515 : 317 : struct lra_static_insn_data *static_id;
6516 : 317 : struct lra_insn_reg *reg;
6517 : :
6518 : 317 : if (!INSN_P (insn))
6519 : 0 : continue;
6520 : 317 : if (bitmap_bit_p (&lra_reg_info[hard_regno].insn_bitmap,
6521 : 317 : INSN_UID (insn)))
6522 : : break;
6523 : 311 : static_id = lra_get_insn_recog_data (insn)->insn_static_data;
6524 : 365 : for (reg = static_id->hard_regs; reg != NULL; reg = reg->next)
6525 : 54 : if (reg->regno == hard_regno)
6526 : : break;
6527 : : if (reg != NULL)
6528 : : break;
6529 : : }
6530 : 165 : if (insn != NEXT_INSN (to))
6531 : 6 : continue;
6532 : 159 : if (split_reg (true, hard_regno, from, NULL, to))
6533 : : return true;
6534 : : }
6535 : : return false;
6536 : : }
6537 : :
6538 : : /* Recognize that we need a split transformation for insn INSN, which
6539 : : defines or uses REGNO in its insn biggest MODE (we use it only if
6540 : : REGNO is a hard register). POTENTIAL_RELOAD_HARD_REGS contains
6541 : : hard registers which might be used for reloads since the EBB end.
6542 : : Put the save before INSN if BEFORE_P is true. MAX_UID is maximla
6543 : : uid before starting INSN processing. Return true if we succeed in
6544 : : such transformation. */
6545 : : static bool
6546 : 200118031 : split_if_necessary (int regno, machine_mode mode,
6547 : : HARD_REG_SET potential_reload_hard_regs,
6548 : : bool before_p, rtx_insn *insn, int max_uid)
6549 : : {
6550 : 200118031 : bool res = false;
6551 : 200118031 : int i, nregs = 1;
6552 : 200118031 : rtx next_usage_insns;
6553 : :
6554 : 200118031 : if (regno < FIRST_PSEUDO_REGISTER)
6555 : 92998626 : nregs = hard_regno_nregs (regno, mode);
6556 : 400599313 : for (i = 0; i < nregs; i++)
6557 : 200481282 : if (usage_insns[regno + i].check == curr_usage_insns_check
6558 : 133314835 : && (next_usage_insns = usage_insns[regno + i].insns) != NULL_RTX
6559 : : /* To avoid processing the register twice or more. */
6560 : 133314835 : && ((GET_CODE (next_usage_insns) != INSN_LIST
6561 : 128931531 : && INSN_UID (next_usage_insns) < max_uid)
6562 : 4383304 : || (GET_CODE (next_usage_insns) == INSN_LIST
6563 : 4383304 : && (INSN_UID (XEXP (next_usage_insns, 0)) < max_uid)))
6564 : 133314835 : && need_for_split_p (potential_reload_hard_regs, regno + i)
6565 : 200754620 : && split_reg (before_p, regno + i, insn, next_usage_insns, NULL))
6566 : : res = true;
6567 : 200118031 : return res;
6568 : : }
6569 : :
6570 : : /* Return TRUE if rtx X is considered as an invariant for
6571 : : inheritance. */
6572 : : static bool
6573 : 11868875 : invariant_p (const_rtx x)
6574 : : {
6575 : 11868875 : machine_mode mode;
6576 : 11868875 : const char *fmt;
6577 : 11868875 : enum rtx_code code;
6578 : 11868875 : int i, j;
6579 : :
6580 : 11868875 : if (side_effects_p (x))
6581 : : return false;
6582 : :
6583 : 11859188 : code = GET_CODE (x);
6584 : 11859188 : mode = GET_MODE (x);
6585 : 11859188 : if (code == SUBREG)
6586 : : {
6587 : 474693 : x = SUBREG_REG (x);
6588 : 474693 : code = GET_CODE (x);
6589 : 474693 : mode = wider_subreg_mode (mode, GET_MODE (x));
6590 : : }
6591 : :
6592 : 11859188 : if (MEM_P (x))
6593 : : return false;
6594 : :
6595 : 10088982 : if (REG_P (x))
6596 : : {
6597 : 3601498 : int i, nregs, regno = REGNO (x);
6598 : :
6599 : 3601498 : if (regno >= FIRST_PSEUDO_REGISTER || regno == STACK_POINTER_REGNUM
6600 : 984528 : || TEST_HARD_REG_BIT (eliminable_regset, regno)
6601 : 3621586 : || GET_MODE_CLASS (GET_MODE (x)) == MODE_CC)
6602 : : return false;
6603 : 2 : nregs = hard_regno_nregs (regno, mode);
6604 : 2 : for (i = 0; i < nregs; i++)
6605 : 2 : if (! fixed_regs[regno + i]
6606 : : /* A hard register may be clobbered in the current insn
6607 : : but we can ignore this case because if the hard
6608 : : register is used it should be set somewhere after the
6609 : : clobber. */
6610 : 2 : || bitmap_bit_p (&invalid_invariant_regs, regno + i))
6611 : 2 : return false;
6612 : : }
6613 : 6487484 : fmt = GET_RTX_FORMAT (code);
6614 : 11415549 : for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
6615 : : {
6616 : 8635561 : if (fmt[i] == 'e')
6617 : : {
6618 : 5694568 : if (! invariant_p (XEXP (x, i)))
6619 : : return false;
6620 : : }
6621 : 2940993 : else if (fmt[i] == 'E')
6622 : : {
6623 : 625545 : for (j = XVECLEN (x, i) - 1; j >= 0; j--)
6624 : 518710 : if (! invariant_p (XVECEXP (x, i, j)))
6625 : : return false;
6626 : : }
6627 : : }
6628 : : return true;
6629 : : }
6630 : :
6631 : : /* We have 'dest_reg <- invariant'. Let us try to make an invariant
6632 : : inheritance transformation (using dest_reg instead invariant in a
6633 : : subsequent insn). */
6634 : : static bool
6635 : 176988 : process_invariant_for_inheritance (rtx dst_reg, rtx invariant_rtx)
6636 : : {
6637 : 176988 : invariant_ptr_t invariant_ptr;
6638 : 176988 : rtx_insn *insn, *new_insns;
6639 : 176988 : rtx insn_set, insn_reg, new_reg;
6640 : 176988 : int insn_regno;
6641 : 176988 : bool succ_p = false;
6642 : 176988 : int dst_regno = REGNO (dst_reg);
6643 : 176988 : machine_mode dst_mode = GET_MODE (dst_reg);
6644 : 176988 : enum reg_class cl = lra_get_allocno_class (dst_regno), insn_reg_cl;
6645 : :
6646 : 176988 : invariant_ptr = insert_invariant (invariant_rtx);
6647 : 176988 : if ((insn = invariant_ptr->insn) != NULL_RTX)
6648 : : {
6649 : : /* We have a subsequent insn using the invariant. */
6650 : 22613 : insn_set = single_set (insn);
6651 : 22613 : lra_assert (insn_set != NULL);
6652 : 22613 : insn_reg = SET_DEST (insn_set);
6653 : 22613 : lra_assert (REG_P (insn_reg));
6654 : 22613 : insn_regno = REGNO (insn_reg);
6655 : 22613 : insn_reg_cl = lra_get_allocno_class (insn_regno);
6656 : :
6657 : 22613 : if (dst_mode == GET_MODE (insn_reg)
6658 : : /* We should consider only result move reg insns which are
6659 : : cheap. */
6660 : 22541 : && targetm.register_move_cost (dst_mode, cl, insn_reg_cl) == 2
6661 : 44569 : && targetm.register_move_cost (dst_mode, cl, cl) == 2)
6662 : : {
6663 : 21956 : if (lra_dump_file != NULL)
6664 : 0 : fprintf (lra_dump_file,
6665 : : " [[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[\n");
6666 : 21956 : new_reg = lra_create_new_reg (dst_mode, dst_reg, cl, NULL,
6667 : : "invariant inheritance");
6668 : 21956 : bitmap_set_bit (&lra_inheritance_pseudos, REGNO (new_reg));
6669 : 21956 : bitmap_set_bit (&check_only_regs, REGNO (new_reg));
6670 : 21956 : lra_reg_info[REGNO (new_reg)].restore_rtx = PATTERN (insn);
6671 : 21956 : start_sequence ();
6672 : 21956 : lra_emit_move (new_reg, dst_reg);
6673 : 21956 : new_insns = end_sequence ();
6674 : 21956 : lra_process_new_insns (curr_insn, NULL, new_insns,
6675 : : "Add invariant inheritance<-original");
6676 : 21956 : start_sequence ();
6677 : 21956 : lra_emit_move (SET_DEST (insn_set), new_reg);
6678 : 21956 : new_insns = end_sequence ();
6679 : 21956 : lra_process_new_insns (insn, NULL, new_insns,
6680 : : "Changing reload<-inheritance");
6681 : 21956 : lra_set_insn_deleted (insn);
6682 : 21956 : succ_p = true;
6683 : 21956 : if (lra_dump_file != NULL)
6684 : : {
6685 : 0 : fprintf (lra_dump_file,
6686 : : " Invariant inheritance reuse change %d (bb%d):\n",
6687 : 0 : REGNO (new_reg), BLOCK_FOR_INSN (insn)->index);
6688 : 0 : dump_insn_slim (lra_dump_file, insn);
6689 : 0 : fprintf (lra_dump_file,
6690 : : " ]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]\n");
6691 : : }
6692 : : }
6693 : : }
6694 : 176988 : invariant_ptr->insn = curr_insn;
6695 : 176988 : return succ_p;
6696 : : }
6697 : :
6698 : : /* Check only registers living at the current program point in the
6699 : : current EBB. */
6700 : : static bitmap_head live_regs;
6701 : :
6702 : : /* Update live info in EBB given by its HEAD and TAIL insns after
6703 : : inheritance/split transformation. The function removes dead moves
6704 : : too. */
6705 : : static void
6706 : 745156 : update_ebb_live_info (rtx_insn *head, rtx_insn *tail)
6707 : : {
6708 : 745156 : unsigned int j;
6709 : 745156 : int i, regno;
6710 : 745156 : bool live_p;
6711 : 745156 : rtx_insn *prev_insn;
6712 : 745156 : rtx set;
6713 : 745156 : bool remove_p;
6714 : 745156 : basic_block last_bb, prev_bb, curr_bb;
6715 : 745156 : bitmap_iterator bi;
6716 : 745156 : struct lra_insn_reg *reg;
6717 : 745156 : edge e;
6718 : 745156 : edge_iterator ei;
6719 : :
6720 : 745156 : last_bb = BLOCK_FOR_INSN (tail);
6721 : 745156 : prev_bb = NULL;
6722 : 745156 : for (curr_insn = tail;
6723 : 36357208 : curr_insn != PREV_INSN (head);
6724 : 35612052 : curr_insn = prev_insn)
6725 : : {
6726 : 35612052 : prev_insn = PREV_INSN (curr_insn);
6727 : : /* We need to process empty blocks too. They contain
6728 : : NOTE_INSN_BASIC_BLOCK referring for the basic block. */
6729 : 35612052 : if (NOTE_P (curr_insn) && NOTE_KIND (curr_insn) != NOTE_INSN_BASIC_BLOCK)
6730 : 1415303 : continue;
6731 : 34196749 : curr_bb = BLOCK_FOR_INSN (curr_insn);
6732 : 34196749 : if (curr_bb != prev_bb)
6733 : : {
6734 : 1496461 : if (prev_bb != NULL)
6735 : : {
6736 : : /* Update df_get_live_in (prev_bb): */
6737 : 54442112 : EXECUTE_IF_SET_IN_BITMAP (&check_only_regs, 0, j, bi)
6738 : 53690807 : if (bitmap_bit_p (&live_regs, j))
6739 : 1611266 : bitmap_set_bit (df_get_live_in (prev_bb), j);
6740 : : else
6741 : 52079541 : bitmap_clear_bit (df_get_live_in (prev_bb), j);
6742 : : }
6743 : 1496461 : if (curr_bb != last_bb)
6744 : : {
6745 : : /* Update df_get_live_out (curr_bb): */
6746 : 54442112 : EXECUTE_IF_SET_IN_BITMAP (&check_only_regs, 0, j, bi)
6747 : : {
6748 : 53690807 : live_p = bitmap_bit_p (&live_regs, j);
6749 : 53690807 : if (! live_p)
6750 : 156145594 : FOR_EACH_EDGE (e, ei, curr_bb->succs)
6751 : 104120005 : if (bitmap_bit_p (df_get_live_in (e->dest), j))
6752 : : {
6753 : : live_p = true;
6754 : : break;
6755 : : }
6756 : 52079541 : if (live_p)
6757 : 1665218 : bitmap_set_bit (df_get_live_out (curr_bb), j);
6758 : : else
6759 : 52025589 : bitmap_clear_bit (df_get_live_out (curr_bb), j);
6760 : : }
6761 : : }
6762 : 1496461 : prev_bb = curr_bb;
6763 : 1496461 : bitmap_and (&live_regs, &check_only_regs, df_get_live_out (curr_bb));
6764 : : }
6765 : 34196749 : if (! NONDEBUG_INSN_P (curr_insn))
6766 : 11939902 : continue;
6767 : 22256847 : curr_id = lra_get_insn_recog_data (curr_insn);
6768 : 22256847 : curr_static_id = curr_id->insn_static_data;
6769 : 22256847 : remove_p = false;
6770 : 22256847 : if ((set = single_set (curr_insn)) != NULL_RTX
6771 : 21575713 : && REG_P (SET_DEST (set))
6772 : 17224155 : && (regno = REGNO (SET_DEST (set))) >= FIRST_PSEUDO_REGISTER
6773 : 12795603 : && SET_DEST (set) != pic_offset_table_rtx
6774 : 12788670 : && bitmap_bit_p (&check_only_regs, regno)
6775 : 25440205 : && ! bitmap_bit_p (&live_regs, regno))
6776 : : remove_p = true;
6777 : : /* See which defined values die here. */
6778 : 61135839 : for (reg = curr_id->regs; reg != NULL; reg = reg->next)
6779 : 38878992 : if (reg->type == OP_OUT && ! reg->subreg_p)
6780 : 15339188 : bitmap_clear_bit (&live_regs, reg->regno);
6781 : 26478088 : for (reg = curr_static_id->hard_regs; reg != NULL; reg = reg->next)
6782 : 4221241 : if (reg->type == OP_OUT && ! reg->subreg_p)
6783 : 3195869 : bitmap_clear_bit (&live_regs, reg->regno);
6784 : 22256847 : if (curr_id->arg_hard_regs != NULL)
6785 : : /* Make clobbered argument hard registers die. */
6786 : 3363214 : for (i = 0; (regno = curr_id->arg_hard_regs[i]) >= 0; i++)
6787 : 2424448 : if (regno >= FIRST_PSEUDO_REGISTER)
6788 : 189780 : bitmap_clear_bit (&live_regs, regno - FIRST_PSEUDO_REGISTER);
6789 : : /* Mark each used value as live. */
6790 : 61135839 : for (reg = curr_id->regs; reg != NULL; reg = reg->next)
6791 : 38878992 : if (reg->type != OP_OUT
6792 : 38878992 : && bitmap_bit_p (&check_only_regs, reg->regno))
6793 : 4475519 : bitmap_set_bit (&live_regs, reg->regno);
6794 : 26478088 : for (reg = curr_static_id->hard_regs; reg != NULL; reg = reg->next)
6795 : 4221241 : if (reg->type != OP_OUT
6796 : 4221241 : && bitmap_bit_p (&check_only_regs, reg->regno))
6797 : 0 : bitmap_set_bit (&live_regs, reg->regno);
6798 : 22256847 : if (curr_id->arg_hard_regs != NULL)
6799 : : /* Make used argument hard registers live. */
6800 : 3363214 : for (i = 0; (regno = curr_id->arg_hard_regs[i]) >= 0; i++)
6801 : 2424448 : if (regno < FIRST_PSEUDO_REGISTER
6802 : 2424448 : && bitmap_bit_p (&check_only_regs, regno))
6803 : 0 : bitmap_set_bit (&live_regs, regno);
6804 : : /* It is quite important to remove dead move insns because it
6805 : : means removing dead store. We don't need to process them for
6806 : : constraints. */
6807 : 22256847 : if (remove_p)
6808 : : {
6809 : 299653 : if (lra_dump_file != NULL)
6810 : : {
6811 : 2 : fprintf (lra_dump_file, " Removing dead insn:\n ");
6812 : 2 : dump_insn_slim (lra_dump_file, curr_insn);
6813 : : }
6814 : 299653 : lra_set_insn_deleted (curr_insn);
6815 : : }
6816 : : }
6817 : 745156 : }
6818 : :
6819 : : /* The structure describes info to do an inheritance for the current
6820 : : insn. We need to collect such info first before doing the
6821 : : transformations because the transformations change the insn
6822 : : internal representation. */
6823 : : struct to_inherit
6824 : : {
6825 : : /* Original regno. */
6826 : : int regno;
6827 : : /* Subsequent insns which can inherit original reg value. */
6828 : : rtx insns;
6829 : : };
6830 : :
6831 : : /* Array containing all info for doing inheritance from the current
6832 : : insn. */
6833 : : static struct to_inherit to_inherit[LRA_MAX_INSN_RELOADS];
6834 : :
6835 : : /* Number elements in the previous array. */
6836 : : static int to_inherit_num;
6837 : :
6838 : : /* Add inheritance info REGNO and INSNS. Their meaning is described in
6839 : : structure to_inherit. */
6840 : : static void
6841 : 310047 : add_to_inherit (int regno, rtx insns)
6842 : : {
6843 : 310047 : int i;
6844 : :
6845 : 310133 : for (i = 0; i < to_inherit_num; i++)
6846 : 86 : if (to_inherit[i].regno == regno)
6847 : : return;
6848 : 310047 : lra_assert (to_inherit_num < LRA_MAX_INSN_RELOADS);
6849 : 310047 : to_inherit[to_inherit_num].regno = regno;
6850 : 310047 : to_inherit[to_inherit_num++].insns = insns;
6851 : : }
6852 : :
6853 : : /* Return the last non-debug insn in basic block BB, or the block begin
6854 : : note if none. */
6855 : : static rtx_insn *
6856 : 30371606 : get_last_insertion_point (basic_block bb)
6857 : : {
6858 : 30371606 : rtx_insn *insn;
6859 : :
6860 : 32466104 : FOR_BB_INSNS_REVERSE (bb, insn)
6861 : 32466104 : if (NONDEBUG_INSN_P (insn) || NOTE_INSN_BASIC_BLOCK_P (insn))
6862 : 30371606 : return insn;
6863 : 0 : gcc_unreachable ();
6864 : : }
6865 : :
6866 : : /* Set up RES by registers living on edges FROM except the edge (FROM,
6867 : : TO) or by registers set up in a jump insn in BB FROM. */
6868 : : static void
6869 : 11707785 : get_live_on_other_edges (basic_block from, basic_block to, bitmap res)
6870 : : {
6871 : 11707785 : rtx_insn *last;
6872 : 11707785 : struct lra_insn_reg *reg;
6873 : 11707785 : edge e;
6874 : 11707785 : edge_iterator ei;
6875 : :
6876 : 11707785 : lra_assert (to != NULL);
6877 : 11707785 : bitmap_clear (res);
6878 : 34871397 : FOR_EACH_EDGE (e, ei, from->succs)
6879 : 23163612 : if (e->dest != to)
6880 : 11455827 : bitmap_ior_into (res, df_get_live_in (e->dest));
6881 : 11707785 : last = get_last_insertion_point (from);
6882 : 11707785 : if (! JUMP_P (last))
6883 : 1954657 : return;
6884 : 9753128 : curr_id = lra_get_insn_recog_data (last);
6885 : 19506094 : for (reg = curr_id->regs; reg != NULL; reg = reg->next)
6886 : 9752966 : if (reg->type != OP_IN)
6887 : 74 : bitmap_set_bit (res, reg->regno);
6888 : : }
6889 : :
6890 : : /* Used as a temporary results of some bitmap calculations. */
6891 : : static bitmap_head temp_bitmap;
6892 : :
6893 : : /* We split for reloads of small class of hard regs. The following
6894 : : defines how many hard regs the class should have to be qualified as
6895 : : small. The code is mostly oriented to x86/x86-64 architecture
6896 : : where some insns need to use only specific register or pair of
6897 : : registers and these register can live in RTL explicitly, e.g. for
6898 : : parameter passing. */
6899 : : static const int max_small_class_regs_num = 2;
6900 : :
6901 : : /* Do inheritance/split transformations in EBB starting with HEAD and
6902 : : finishing on TAIL. We process EBB insns in the reverse order.
6903 : : Return true if we did any inheritance/split transformation in the
6904 : : EBB.
6905 : :
6906 : : We should avoid excessive splitting which results in worse code
6907 : : because of inaccurate cost calculations for spilling new split
6908 : : pseudos in such case. To achieve this we do splitting only if
6909 : : register pressure is high in given basic block and there are reload
6910 : : pseudos requiring hard registers. We could do more register
6911 : : pressure calculations at any given program point to avoid necessary
6912 : : splitting even more but it is to expensive and the current approach
6913 : : works well enough. */
6914 : : static bool
6915 : 12810047 : inherit_in_ebb (rtx_insn *head, rtx_insn *tail)
6916 : : {
6917 : 12810047 : int i, src_regno, dst_regno, nregs;
6918 : 12810047 : bool change_p, succ_p, update_reloads_num_p;
6919 : 12810047 : rtx_insn *prev_insn, *last_insn;
6920 : 12810047 : rtx next_usage_insns, curr_set;
6921 : 12810047 : enum reg_class cl;
6922 : 12810047 : struct lra_insn_reg *reg;
6923 : 12810047 : basic_block last_processed_bb, curr_bb = NULL;
6924 : 12810047 : HARD_REG_SET potential_reload_hard_regs, live_hard_regs;
6925 : 12810047 : bitmap to_process;
6926 : 12810047 : unsigned int j;
6927 : 12810047 : bitmap_iterator bi;
6928 : 12810047 : bool head_p, after_p;
6929 : :
6930 : 12810047 : change_p = false;
6931 : 12810047 : curr_usage_insns_check++;
6932 : 12810047 : clear_invariants ();
6933 : 12810047 : reloads_num = calls_num = 0;
6934 : 166530611 : for (unsigned int i = 0; i < NUM_ABI_IDS; ++i)
6935 : 153720564 : last_call_for_abi[i] = 0;
6936 : 12810047 : CLEAR_HARD_REG_SET (full_and_partial_call_clobbers);
6937 : 12810047 : bitmap_clear (&check_only_regs);
6938 : 12810047 : bitmap_clear (&invalid_invariant_regs);
6939 : 12810047 : last_processed_bb = NULL;
6940 : 12810047 : CLEAR_HARD_REG_SET (potential_reload_hard_regs);
6941 : 12810047 : live_hard_regs = eliminable_regset | lra_no_alloc_regs;
6942 : : /* We don't process new insns generated in the loop. */
6943 : 237848215 : for (curr_insn = tail; curr_insn != PREV_INSN (head); curr_insn = prev_insn)
6944 : : {
6945 : 225038168 : prev_insn = PREV_INSN (curr_insn);
6946 : 225038168 : if (BLOCK_FOR_INSN (curr_insn) != NULL)
6947 : 225037931 : curr_bb = BLOCK_FOR_INSN (curr_insn);
6948 : 225038168 : if (last_processed_bb != curr_bb)
6949 : : {
6950 : : /* We are at the end of BB. Add qualified living
6951 : : pseudos for potential splitting. */
6952 : 18663821 : to_process = df_get_live_out (curr_bb);
6953 : 18663821 : if (last_processed_bb != NULL)
6954 : : {
6955 : : /* We are somewhere in the middle of EBB. */
6956 : 5853774 : get_live_on_other_edges (curr_bb, last_processed_bb,
6957 : : &temp_bitmap);
6958 : 5853774 : to_process = &temp_bitmap;
6959 : : }
6960 : 18663821 : last_processed_bb = curr_bb;
6961 : 18663821 : last_insn = get_last_insertion_point (curr_bb);
6962 : 37327642 : after_p = (! JUMP_P (last_insn)
6963 : 18663821 : && (! CALL_P (last_insn)
6964 : 2306774 : || (find_reg_note (last_insn,
6965 : : REG_NORETURN, NULL_RTX) == NULL_RTX
6966 : 1385305 : && ! SIBLING_CALL_P (last_insn))));
6967 : 18663821 : CLEAR_HARD_REG_SET (potential_reload_hard_regs);
6968 : 202271329 : EXECUTE_IF_SET_IN_BITMAP (to_process, 0, j, bi)
6969 : : {
6970 : 183607514 : if ((int) j >= lra_constraint_new_regno_start)
6971 : : break;
6972 : 183607508 : if (j < FIRST_PSEUDO_REGISTER || reg_renumber[j] >= 0)
6973 : : {
6974 : 119665679 : if (j < FIRST_PSEUDO_REGISTER)
6975 : 70097517 : SET_HARD_REG_BIT (live_hard_regs, j);
6976 : : else
6977 : 49568162 : add_to_hard_reg_set (&live_hard_regs,
6978 : 49568162 : PSEUDO_REGNO_MODE (j),
6979 : 49568162 : reg_renumber[j]);
6980 : 119665679 : setup_next_usage_insn (j, last_insn, reloads_num, after_p);
6981 : : }
6982 : : }
6983 : : }
6984 : 225038168 : src_regno = dst_regno = -1;
6985 : 225038168 : curr_set = single_set (curr_insn);
6986 : 225038168 : if (curr_set != NULL_RTX && REG_P (SET_DEST (curr_set)))
6987 : 84920526 : dst_regno = REGNO (SET_DEST (curr_set));
6988 : 114970832 : if (curr_set != NULL_RTX && REG_P (SET_SRC (curr_set)))
6989 : 39843544 : src_regno = REGNO (SET_SRC (curr_set));
6990 : 225038168 : update_reloads_num_p = true;
6991 : 225038168 : if (src_regno < lra_constraint_new_regno_start
6992 : 218530550 : && src_regno >= FIRST_PSEUDO_REGISTER
6993 : 28125145 : && reg_renumber[src_regno] < 0
6994 : 3759968 : && dst_regno >= lra_constraint_new_regno_start
6995 : 227693098 : && (cl = lra_get_allocno_class (dst_regno)) != NO_REGS)
6996 : : {
6997 : : /* 'reload_pseudo <- original_pseudo'. */
6998 : 2654930 : if (ira_class_hard_regs_num[cl] <= max_small_class_regs_num)
6999 : 21570 : reloads_num++;
7000 : 2654930 : update_reloads_num_p = false;
7001 : 2654930 : succ_p = false;
7002 : 2654930 : if (usage_insns[src_regno].check == curr_usage_insns_check
7003 : 2654930 : && (next_usage_insns = usage_insns[src_regno].insns) != NULL_RTX)
7004 : 483716 : succ_p = inherit_reload_reg (false, src_regno, cl,
7005 : : curr_insn, next_usage_insns);
7006 : 483716 : if (succ_p)
7007 : : change_p = true;
7008 : : else
7009 : 2194810 : setup_next_usage_insn (src_regno, curr_insn, reloads_num, false);
7010 : 5309860 : if (hard_reg_set_subset_p (reg_class_contents[cl], live_hard_regs))
7011 : 632860656 : potential_reload_hard_regs |= reg_class_contents[cl];
7012 : : }
7013 : 222383238 : else if (src_regno < 0
7014 : 185194624 : && dst_regno >= lra_constraint_new_regno_start
7015 : 5655597 : && invariant_p (SET_SRC (curr_set))
7016 : 274206 : && (cl = lra_get_allocno_class (dst_regno)) != NO_REGS
7017 : 273664 : && ! bitmap_bit_p (&invalid_invariant_regs, dst_regno)
7018 : 222621097 : && ! bitmap_bit_p (&invalid_invariant_regs,
7019 : 237859 : ORIGINAL_REGNO(regno_reg_rtx[dst_regno])))
7020 : : {
7021 : : /* 'reload_pseudo <- invariant'. */
7022 : 176988 : if (ira_class_hard_regs_num[cl] <= max_small_class_regs_num)
7023 : 7464 : reloads_num++;
7024 : 176988 : update_reloads_num_p = false;
7025 : 176988 : if (process_invariant_for_inheritance (SET_DEST (curr_set), SET_SRC (curr_set)))
7026 : 21956 : change_p = true;
7027 : 353976 : if (hard_reg_set_subset_p (reg_class_contents[cl], live_hard_regs))
7028 : 632860656 : potential_reload_hard_regs |= reg_class_contents[cl];
7029 : : }
7030 : 222206250 : else if (src_regno >= lra_constraint_new_regno_start
7031 : 6507618 : && dst_regno < lra_constraint_new_regno_start
7032 : 5672217 : && dst_regno >= FIRST_PSEUDO_REGISTER
7033 : 3792807 : && reg_renumber[dst_regno] < 0
7034 : 1477570 : && (cl = lra_get_allocno_class (src_regno)) != NO_REGS
7035 : 1477570 : && usage_insns[dst_regno].check == curr_usage_insns_check
7036 : 222206250 : && (next_usage_insns
7037 : 478146 : = usage_insns[dst_regno].insns) != NULL_RTX)
7038 : : {
7039 : 478146 : if (ira_class_hard_regs_num[cl] <= max_small_class_regs_num)
7040 : 7914 : reloads_num++;
7041 : 478146 : update_reloads_num_p = false;
7042 : : /* 'original_pseudo <- reload_pseudo'. */
7043 : 478146 : if (! JUMP_P (curr_insn)
7044 : 478146 : && inherit_reload_reg (true, dst_regno, cl,
7045 : : curr_insn, next_usage_insns))
7046 : : change_p = true;
7047 : : /* Invalidate. */
7048 : 478146 : usage_insns[dst_regno].check = 0;
7049 : 956292 : if (hard_reg_set_subset_p (reg_class_contents[cl], live_hard_regs))
7050 : 632860656 : potential_reload_hard_regs |= reg_class_contents[cl];
7051 : : }
7052 : 221728104 : else if (INSN_P (curr_insn))
7053 : : {
7054 : 186023006 : int iter;
7055 : 186023006 : int max_uid = get_max_uid ();
7056 : :
7057 : 186023006 : curr_id = lra_get_insn_recog_data (curr_insn);
7058 : 186023006 : curr_static_id = curr_id->insn_static_data;
7059 : 186023006 : to_inherit_num = 0;
7060 : : /* Process insn definitions. */
7061 : 558069018 : for (iter = 0; iter < 2; iter++)
7062 : 372046012 : for (reg = iter == 0 ? curr_id->regs : curr_static_id->hard_regs;
7063 : 599982868 : reg != NULL;
7064 : 227936856 : reg = reg->next)
7065 : 227936856 : if (reg->type != OP_IN
7066 : 227936856 : && (dst_regno = reg->regno) < lra_constraint_new_regno_start)
7067 : : {
7068 : 46691254 : if (dst_regno >= FIRST_PSEUDO_REGISTER && reg->type == OP_OUT
7069 : 44552686 : && reg_renumber[dst_regno] < 0 && ! reg->subreg_p
7070 : 1878324 : && usage_insns[dst_regno].check == curr_usage_insns_check
7071 : 91987312 : && (next_usage_insns
7072 : 127513 : = usage_insns[dst_regno].insns) != NULL_RTX)
7073 : : {
7074 : 127513 : struct lra_insn_reg *r;
7075 : :
7076 : 380368 : for (r = curr_id->regs; r != NULL; r = r->next)
7077 : 252855 : if (r->type != OP_OUT && r->regno == dst_regno)
7078 : : break;
7079 : : /* Don't do inheritance if the pseudo is also
7080 : : used in the insn. */
7081 : 127513 : if (r == NULL)
7082 : : /* We cannot do inheritance right now
7083 : : because the current insn reg info (chain
7084 : : regs) can change after that. */
7085 : 127513 : add_to_inherit (dst_regno, next_usage_insns);
7086 : : }
7087 : : /* We cannot process one reg twice here because of
7088 : : usage_insns invalidation. */
7089 : 91987312 : if ((dst_regno < FIRST_PSEUDO_REGISTER
7090 : 46691254 : || reg_renumber[dst_regno] >= 0)
7091 : 89972818 : && ! reg->subreg_p && reg->type != OP_IN)
7092 : : {
7093 : 89693582 : HARD_REG_SET s;
7094 : :
7095 : 89693582 : if (split_if_necessary (dst_regno, reg->biggest_mode,
7096 : : potential_reload_hard_regs,
7097 : : false, curr_insn, max_uid))
7098 : 59524 : change_p = true;
7099 : 89693582 : CLEAR_HARD_REG_SET (s);
7100 : 89693582 : if (dst_regno < FIRST_PSEUDO_REGISTER)
7101 : 45296058 : add_to_hard_reg_set (&s, reg->biggest_mode, dst_regno);
7102 : : else
7103 : 44397524 : add_to_hard_reg_set (&s, PSEUDO_REGNO_MODE (dst_regno),
7104 : 44397524 : reg_renumber[dst_regno]);
7105 : 89693582 : live_hard_regs &= ~s;
7106 : 179387164 : potential_reload_hard_regs &= ~s;
7107 : : }
7108 : : /* We should invalidate potential inheritance or
7109 : : splitting for the current insn usages to the next
7110 : : usage insns (see code below) as the output pseudo
7111 : : prevents this. */
7112 : 91987312 : if ((dst_regno >= FIRST_PSEUDO_REGISTER
7113 : 46691254 : && reg_renumber[dst_regno] < 0)
7114 : 89972818 : || (reg->type == OP_OUT && ! reg->subreg_p
7115 : 81981496 : && (dst_regno < FIRST_PSEUDO_REGISTER
7116 : 42267593 : || reg_renumber[dst_regno] >= 0)))
7117 : : {
7118 : : /* Invalidate and mark definitions. */
7119 : 44282087 : if (dst_regno >= FIRST_PSEUDO_REGISTER)
7120 : 44282087 : usage_insns[dst_regno].check = -(int) INSN_UID (curr_insn);
7121 : : else
7122 : : {
7123 : 39713903 : nregs = hard_regno_nregs (dst_regno,
7124 : 39713903 : reg->biggest_mode);
7125 : 79694252 : for (i = 0; i < nregs; i++)
7126 : 79960698 : usage_insns[dst_regno + i].check
7127 : 39980349 : = -(int) INSN_UID (curr_insn);
7128 : : }
7129 : : }
7130 : : }
7131 : : /* Process clobbered call regs. */
7132 : 186023006 : if (curr_id->arg_hard_regs != NULL)
7133 : 19885645 : for (i = 0; (dst_regno = curr_id->arg_hard_regs[i]) >= 0; i++)
7134 : 14224084 : if (dst_regno >= FIRST_PSEUDO_REGISTER)
7135 : 1611174 : usage_insns[dst_regno - FIRST_PSEUDO_REGISTER].check
7136 : 805587 : = -(int) INSN_UID (curr_insn);
7137 : 186023006 : if (! JUMP_P (curr_insn))
7138 : 174413198 : for (i = 0; i < to_inherit_num; i++)
7139 : 127513 : if (inherit_reload_reg (true, to_inherit[i].regno,
7140 : : ALL_REGS, curr_insn,
7141 : : to_inherit[i].insns))
7142 : 102123 : change_p = true;
7143 : 186023006 : if (CALL_P (curr_insn))
7144 : : {
7145 : 7271582 : rtx cheap, pat, dest;
7146 : 7271582 : rtx_insn *restore;
7147 : 7271582 : int regno, hard_regno;
7148 : :
7149 : 7271582 : calls_num++;
7150 : 7271582 : function_abi callee_abi = insn_callee_abi (curr_insn);
7151 : 7271582 : last_call_for_abi[callee_abi.id ()] = calls_num;
7152 : 7271582 : full_and_partial_call_clobbers
7153 : 7271582 : |= callee_abi.full_and_partial_reg_clobbers ();
7154 : 7271582 : first_call_insn = curr_insn;
7155 : 7271582 : if ((cheap = find_reg_note (curr_insn,
7156 : : REG_RETURNED, NULL_RTX)) != NULL_RTX
7157 : 36342 : && ((cheap = XEXP (cheap, 0)), true)
7158 : 36342 : && (regno = REGNO (cheap)) >= FIRST_PSEUDO_REGISTER
7159 : 36342 : && (hard_regno = reg_renumber[regno]) >= 0
7160 : 27352 : && usage_insns[regno].check == curr_usage_insns_check
7161 : : /* If there are pending saves/restores, the
7162 : : optimization is not worth. */
7163 : 22743 : && usage_insns[regno].calls_num == calls_num - 1
7164 : 7292539 : && callee_abi.clobbers_reg_p (GET_MODE (cheap), hard_regno))
7165 : : {
7166 : : /* Restore the pseudo from the call result as
7167 : : REG_RETURNED note says that the pseudo value is
7168 : : in the call result and the pseudo is an argument
7169 : : of the call. */
7170 : 8788 : pat = PATTERN (curr_insn);
7171 : 8788 : if (GET_CODE (pat) == PARALLEL)
7172 : 0 : pat = XVECEXP (pat, 0, 0);
7173 : 8788 : dest = SET_DEST (pat);
7174 : : /* For multiple return values dest is PARALLEL.
7175 : : Currently we handle only single return value case. */
7176 : 8788 : if (REG_P (dest))
7177 : : {
7178 : 8788 : start_sequence ();
7179 : 8788 : emit_move_insn (cheap, copy_rtx (dest));
7180 : 8788 : restore = end_sequence ();
7181 : 8788 : lra_process_new_insns (curr_insn, NULL, restore,
7182 : : "Inserting call parameter restore");
7183 : : /* We don't need to save/restore of the pseudo from
7184 : : this call. */
7185 : 8788 : usage_insns[regno].calls_num = calls_num;
7186 : 8788 : remove_from_hard_reg_set
7187 : 8788 : (&full_and_partial_call_clobbers,
7188 : 8788 : GET_MODE (cheap), hard_regno);
7189 : 8788 : bitmap_set_bit (&check_only_regs, regno);
7190 : : }
7191 : : }
7192 : : }
7193 : 186023006 : to_inherit_num = 0;
7194 : : /* Process insn usages. */
7195 : 558069018 : for (iter = 0; iter < 2; iter++)
7196 : 372046012 : for (reg = iter == 0 ? curr_id->regs : curr_static_id->hard_regs;
7197 : 599982868 : reg != NULL;
7198 : 227936856 : reg = reg->next)
7199 : 227936856 : if ((reg->type != OP_OUT
7200 : 90845905 : || (reg->type == OP_OUT && reg->subreg_p))
7201 : 228484438 : && (src_regno = reg->regno) < lra_constraint_new_regno_start)
7202 : : {
7203 : 126009154 : if (src_regno >= FIRST_PSEUDO_REGISTER
7204 : 73584047 : && reg_renumber[src_regno] < 0 && reg->type == OP_IN)
7205 : : {
7206 : 2452534 : if (usage_insns[src_regno].check == curr_usage_insns_check
7207 : 761349 : && (next_usage_insns
7208 : 761349 : = usage_insns[src_regno].insns) != NULL_RTX
7209 : 3213883 : && NONDEBUG_INSN_P (curr_insn))
7210 : 182534 : add_to_inherit (src_regno, next_usage_insns);
7211 : 4540000 : else if (usage_insns[src_regno].check
7212 : 2270000 : != -(int) INSN_UID (curr_insn))
7213 : : /* Add usages but only if the reg is not set up
7214 : : in the same insn. */
7215 : 2270000 : add_next_usage_insn (src_regno, curr_insn, reloads_num);
7216 : : }
7217 : 71131513 : else if (src_regno < FIRST_PSEUDO_REGISTER
7218 : 71131513 : || reg_renumber[src_regno] >= 0)
7219 : : {
7220 : 123420450 : bool before_p;
7221 : 123420450 : rtx_insn *use_insn = curr_insn;
7222 : 123420450 : rtx_insn *prev_insn = PREV_INSN (curr_insn);
7223 : :
7224 : 246840900 : before_p = (JUMP_P (curr_insn)
7225 : 123420450 : || (CALL_P (curr_insn) && reg->type == OP_IN));
7226 : 123420450 : if (NONDEBUG_INSN_P (curr_insn)
7227 : 110424554 : && (! JUMP_P (curr_insn) || reg->type == OP_IN)
7228 : 233844899 : && split_if_necessary (src_regno, reg->biggest_mode,
7229 : : potential_reload_hard_regs,
7230 : : before_p, curr_insn, max_uid))
7231 : : {
7232 : 213814 : if (reg->subreg_p)
7233 : 3184 : check_and_force_assignment_correctness_p = true;
7234 : 213814 : change_p = true;
7235 : : /* Invalidate. */
7236 : 213814 : usage_insns[src_regno].check = 0;
7237 : 213814 : if (before_p && PREV_INSN (curr_insn) != prev_insn)
7238 : : use_insn = PREV_INSN (curr_insn);
7239 : : }
7240 : 123420450 : if (NONDEBUG_INSN_P (curr_insn))
7241 : : {
7242 : 110424554 : if (src_regno < FIRST_PSEUDO_REGISTER)
7243 : 47702591 : add_to_hard_reg_set (&live_hard_regs,
7244 : 47702591 : reg->biggest_mode, src_regno);
7245 : : else
7246 : 62721963 : add_to_hard_reg_set (&live_hard_regs,
7247 : 62721963 : PSEUDO_REGNO_MODE (src_regno),
7248 : 62721963 : reg_renumber[src_regno]);
7249 : : }
7250 : 123420450 : if (src_regno >= FIRST_PSEUDO_REGISTER)
7251 : 70995343 : add_next_usage_insn (src_regno, use_insn, reloads_num);
7252 : : else
7253 : : {
7254 : 104947831 : for (i = 0; i < hard_regno_nregs (src_regno, reg->biggest_mode); i++)
7255 : 52522724 : add_next_usage_insn (src_regno + i, use_insn, reloads_num);
7256 : : }
7257 : : }
7258 : : }
7259 : : /* Process used call regs. */
7260 : 186023006 : if (curr_id->arg_hard_regs != NULL)
7261 : 19885645 : for (i = 0; (src_regno = curr_id->arg_hard_regs[i]) >= 0; i++)
7262 : 14224084 : if (src_regno < FIRST_PSEUDO_REGISTER)
7263 : : {
7264 : 13418497 : SET_HARD_REG_BIT (live_hard_regs, src_regno);
7265 : 13418497 : add_next_usage_insn (src_regno, curr_insn, reloads_num);
7266 : : }
7267 : 186205540 : for (i = 0; i < to_inherit_num; i++)
7268 : : {
7269 : 182534 : src_regno = to_inherit[i].regno;
7270 : 182534 : if (inherit_reload_reg (false, src_regno, ALL_REGS,
7271 : : curr_insn, to_inherit[i].insns))
7272 : : change_p = true;
7273 : : else
7274 : 23049 : setup_next_usage_insn (src_regno, curr_insn, reloads_num, false);
7275 : : }
7276 : : }
7277 : 186094384 : if (update_reloads_num_p
7278 : 221728104 : && NONDEBUG_INSN_P (curr_insn) && curr_set != NULL_RTX)
7279 : : {
7280 : 111660768 : int regno = -1;
7281 : 111660768 : if ((REG_P (SET_DEST (curr_set))
7282 : 81610462 : && (regno = REGNO (SET_DEST (curr_set))) >= lra_constraint_new_regno_start
7283 : 8314867 : && reg_renumber[regno] < 0
7284 : 5296852 : && (cl = lra_get_allocno_class (regno)) != NO_REGS)
7285 : 188256898 : || (REG_P (SET_SRC (curr_set))
7286 : 35447140 : && (regno = REGNO (SET_SRC (curr_set))) >= lra_constraint_new_regno_start
7287 : 6099020 : && reg_renumber[regno] < 0
7288 : 3567229 : && (cl = lra_get_allocno_class (regno)) != NO_REGS))
7289 : : {
7290 : 8313665 : if (ira_class_hard_regs_num[cl] <= max_small_class_regs_num)
7291 : 208146 : reloads_num++;
7292 : 16627330 : if (hard_reg_set_subset_p (reg_class_contents[cl], live_hard_regs))
7293 : 225038168 : potential_reload_hard_regs |= reg_class_contents[cl];
7294 : : }
7295 : : }
7296 : 225038168 : if (NONDEBUG_INSN_P (curr_insn))
7297 : : {
7298 : 121293951 : int regno;
7299 : :
7300 : : /* Invalidate invariants with changed regs. */
7301 : 121293951 : curr_id = lra_get_insn_recog_data (curr_insn);
7302 : 309756448 : for (reg = curr_id->regs; reg != NULL; reg = reg->next)
7303 : 188462497 : if (reg->type != OP_IN)
7304 : : {
7305 : 81453618 : bitmap_set_bit (&invalid_invariant_regs, reg->regno);
7306 : 162907236 : bitmap_set_bit (&invalid_invariant_regs,
7307 : 81453618 : ORIGINAL_REGNO (regno_reg_rtx[reg->regno]));
7308 : : }
7309 : 121293951 : curr_static_id = curr_id->insn_static_data;
7310 : 153013667 : for (reg = curr_static_id->hard_regs; reg != NULL; reg = reg->next)
7311 : 31719716 : if (reg->type != OP_IN)
7312 : 22711474 : bitmap_set_bit (&invalid_invariant_regs, reg->regno);
7313 : 121293951 : if (curr_id->arg_hard_regs != NULL)
7314 : 19885645 : for (i = 0; (regno = curr_id->arg_hard_regs[i]) >= 0; i++)
7315 : 14224084 : if (regno >= FIRST_PSEUDO_REGISTER)
7316 : 805587 : bitmap_set_bit (&invalid_invariant_regs,
7317 : : regno - FIRST_PSEUDO_REGISTER);
7318 : : }
7319 : : /* We reached the start of the current basic block. */
7320 : 225038160 : if (prev_insn == NULL_RTX || prev_insn == PREV_INSN (head)
7321 : 437266289 : || BLOCK_FOR_INSN (prev_insn) != curr_bb)
7322 : : {
7323 : : /* We reached the beginning of the current block -- do
7324 : : rest of spliting in the current BB. */
7325 : 18664058 : to_process = df_get_live_in (curr_bb);
7326 : 18664058 : if (BLOCK_FOR_INSN (head) != curr_bb)
7327 : : {
7328 : : /* We are somewhere in the middle of EBB. */
7329 : 5854011 : get_live_on_other_edges (EDGE_PRED (curr_bb, 0)->src,
7330 : : curr_bb, &temp_bitmap);
7331 : 5854011 : to_process = &temp_bitmap;
7332 : : }
7333 : 18664058 : head_p = true;
7334 : 194939297 : EXECUTE_IF_SET_IN_BITMAP (to_process, 0, j, bi)
7335 : : {
7336 : 176275247 : if ((int) j >= lra_constraint_new_regno_start)
7337 : : break;
7338 : 112177319 : if (((int) j < FIRST_PSEUDO_REGISTER || reg_renumber[j] >= 0)
7339 : 111288865 : && usage_insns[j].check == curr_usage_insns_check
7340 : 285650456 : && (next_usage_insns = usage_insns[j].insns) != NULL_RTX)
7341 : : {
7342 : 109375217 : if (need_for_split_p (potential_reload_hard_regs, j))
7343 : : {
7344 : 356420 : if (lra_dump_file != NULL && head_p)
7345 : : {
7346 : 0 : fprintf (lra_dump_file,
7347 : : " ----------------------------------\n");
7348 : 0 : head_p = false;
7349 : : }
7350 : 356420 : if (split_reg (false, j, bb_note (curr_bb),
7351 : : next_usage_insns, NULL))
7352 : 356420 : change_p = true;
7353 : : }
7354 : 109375217 : usage_insns[j].check = 0;
7355 : : }
7356 : : }
7357 : : }
7358 : : }
7359 : 12810047 : first_call_insn = NULL;
7360 : 12810047 : return change_p;
7361 : : }
7362 : :
7363 : : /* This value affects EBB forming. If probability of edge from EBB to
7364 : : a BB is not greater than the following value, we don't add the BB
7365 : : to EBB. */
7366 : : #define EBB_PROBABILITY_CUTOFF \
7367 : : ((REG_BR_PROB_BASE * param_lra_inheritance_ebb_probability_cutoff) / 100)
7368 : :
7369 : : /* Current number of inheritance/split iteration. */
7370 : : int lra_inheritance_iter;
7371 : :
7372 : : /* Entry function for inheritance/split pass. */
7373 : : void
7374 : 1540003 : lra_inheritance (void)
7375 : : {
7376 : 1540003 : int i;
7377 : 1540003 : basic_block bb, start_bb;
7378 : 1540003 : edge e;
7379 : :
7380 : 1540003 : lra_inheritance_iter++;
7381 : 1540003 : if (lra_inheritance_iter > LRA_MAX_INHERITANCE_PASSES)
7382 : : return;
7383 : 1537010 : timevar_push (TV_LRA_INHERITANCE);
7384 : 1537010 : if (lra_dump_file != NULL)
7385 : 97 : fprintf (lra_dump_file, "\n********** Inheritance #%d: **********\n\n",
7386 : : lra_inheritance_iter);
7387 : 1537010 : curr_usage_insns_check = 0;
7388 : 1537010 : usage_insns = XNEWVEC (struct usage_insns, lra_constraint_new_regno_start);
7389 : 228809795 : for (i = 0; i < lra_constraint_new_regno_start; i++)
7390 : 227272785 : usage_insns[i].check = 0;
7391 : 1537010 : bitmap_initialize (&check_only_regs, ®_obstack);
7392 : 1537010 : bitmap_initialize (&invalid_invariant_regs, ®_obstack);
7393 : 1537010 : bitmap_initialize (&live_regs, ®_obstack);
7394 : 1537010 : bitmap_initialize (&temp_bitmap, ®_obstack);
7395 : 1537010 : bitmap_initialize (&ebb_global_regs, ®_obstack);
7396 : 14347057 : FOR_EACH_BB_FN (bb, cfun)
7397 : : {
7398 : 12810047 : start_bb = bb;
7399 : 12810047 : if (lra_dump_file != NULL)
7400 : 347 : fprintf (lra_dump_file, "EBB");
7401 : : /* Form a EBB starting with BB. */
7402 : 12810047 : bitmap_clear (&ebb_global_regs);
7403 : 12810047 : bitmap_ior_into (&ebb_global_regs, df_get_live_in (bb));
7404 : 18663821 : for (;;)
7405 : : {
7406 : 18663821 : if (lra_dump_file != NULL)
7407 : 487 : fprintf (lra_dump_file, " %d", bb->index);
7408 : 18663821 : if (bb->next_bb == EXIT_BLOCK_PTR_FOR_FN (cfun)
7409 : 17126811 : || LABEL_P (BB_HEAD (bb->next_bb)))
7410 : : break;
7411 : 8299789 : e = find_fallthru_edge (bb->succs);
7412 : 8299789 : if (! e)
7413 : : break;
7414 : 8299789 : if (e->probability.initialized_p ()
7415 : 8299789 : && e->probability.to_reg_br_prob_base () < EBB_PROBABILITY_CUTOFF)
7416 : : break;
7417 : : bb = bb->next_bb;
7418 : : }
7419 : 12810047 : bitmap_ior_into (&ebb_global_regs, df_get_live_out (bb));
7420 : 12810047 : if (lra_dump_file != NULL)
7421 : 347 : fprintf (lra_dump_file, "\n");
7422 : 12810047 : if (inherit_in_ebb (BB_HEAD (start_bb), BB_END (bb)))
7423 : : /* Remember that the EBB head and tail can change in
7424 : : inherit_in_ebb. */
7425 : 745156 : update_ebb_live_info (BB_HEAD (start_bb), BB_END (bb));
7426 : : }
7427 : 1537010 : bitmap_release (&ebb_global_regs);
7428 : 1537010 : bitmap_release (&temp_bitmap);
7429 : 1537010 : bitmap_release (&live_regs);
7430 : 1537010 : bitmap_release (&invalid_invariant_regs);
7431 : 1537010 : bitmap_release (&check_only_regs);
7432 : 1537010 : free (usage_insns);
7433 : 1537010 : lra_dump_insns_if_possible ("func after inheritance");
7434 : 1537010 : timevar_pop (TV_LRA_INHERITANCE);
7435 : : }
7436 : :
7437 : :
7438 : :
7439 : : /* This page contains code to undo failed inheritance/split
7440 : : transformations. */
7441 : :
7442 : : /* Current number of iteration undoing inheritance/split. */
7443 : : int lra_undo_inheritance_iter;
7444 : :
7445 : : /* Fix BB live info LIVE after removing pseudos created on pass doing
7446 : : inheritance/split which are REMOVED_PSEUDOS. */
7447 : : static void
7448 : 37327642 : fix_bb_live_info (bitmap live, bitmap removed_pseudos)
7449 : : {
7450 : 37327642 : unsigned int regno;
7451 : 37327642 : bitmap_iterator bi;
7452 : :
7453 : 255638642 : EXECUTE_IF_SET_IN_BITMAP (removed_pseudos, 0, regno, bi)
7454 : 218311000 : if (bitmap_clear_bit (live, regno)
7455 : 218311000 : && REG_P (lra_reg_info[regno].restore_rtx))
7456 : 1210168 : bitmap_set_bit (live, REGNO (lra_reg_info[regno].restore_rtx));
7457 : 37327642 : }
7458 : :
7459 : : /* Return regno of the (subreg of) REG. Otherwise, return a negative
7460 : : number. */
7461 : : static int
7462 : 67988003 : get_regno (rtx reg)
7463 : : {
7464 : 1121038 : if (GET_CODE (reg) == SUBREG)
7465 : 1053998 : reg = SUBREG_REG (reg);
7466 : 67988003 : if (REG_P (reg))
7467 : 43935192 : return REGNO (reg);
7468 : : return -1;
7469 : : }
7470 : :
7471 : : /* Delete a move INSN with destination reg DREGNO and a previous
7472 : : clobber insn with the same regno. The inheritance/split code can
7473 : : generate moves with preceding clobber and when we delete such moves
7474 : : we should delete the clobber insn too to keep the correct life
7475 : : info. */
7476 : : static void
7477 : 758882 : delete_move_and_clobber (rtx_insn *insn, int dregno)
7478 : : {
7479 : 758882 : rtx_insn *prev_insn = PREV_INSN (insn);
7480 : :
7481 : 758882 : lra_set_insn_deleted (insn);
7482 : 758882 : lra_assert (dregno >= 0);
7483 : 758882 : if (prev_insn != NULL && NONDEBUG_INSN_P (prev_insn)
7484 : 322409 : && GET_CODE (PATTERN (prev_insn)) == CLOBBER
7485 : 759198 : && dregno == get_regno (XEXP (PATTERN (prev_insn), 0)))
7486 : 0 : lra_set_insn_deleted (prev_insn);
7487 : 758882 : }
7488 : :
7489 : : /* Remove inheritance/split pseudos which are in REMOVE_PSEUDOS and
7490 : : return true if we did any change. The undo transformations for
7491 : : inheritance looks like
7492 : : i <- i2
7493 : : p <- i => p <- i2
7494 : : or removing
7495 : : p <- i, i <- p, and i <- i3
7496 : : where p is original pseudo from which inheritance pseudo i was
7497 : : created, i and i3 are removed inheritance pseudos, i2 is another
7498 : : not removed inheritance pseudo. All split pseudos or other
7499 : : occurrences of removed inheritance pseudos are changed on the
7500 : : corresponding original pseudos.
7501 : :
7502 : : The function also schedules insns changed and created during
7503 : : inheritance/split pass for processing by the subsequent constraint
7504 : : pass. */
7505 : : static bool
7506 : 1537010 : remove_inheritance_pseudos (bitmap remove_pseudos)
7507 : : {
7508 : 1537010 : basic_block bb;
7509 : 1537010 : int regno, sregno, prev_sregno, dregno;
7510 : 1537010 : rtx restore_rtx;
7511 : 1537010 : rtx set, prev_set;
7512 : 1537010 : rtx_insn *prev_insn;
7513 : 1537010 : bool change_p, done_p;
7514 : :
7515 : 1537010 : change_p = ! bitmap_empty_p (remove_pseudos);
7516 : : /* We cannot finish the function right away if CHANGE_P is true
7517 : : because we need to marks insns affected by previous
7518 : : inheritance/split pass for processing by the subsequent
7519 : : constraint pass. */
7520 : 20200831 : FOR_EACH_BB_FN (bb, cfun)
7521 : : {
7522 : 18663821 : fix_bb_live_info (df_get_live_in (bb), remove_pseudos);
7523 : 18663821 : fix_bb_live_info (df_get_live_out (bb), remove_pseudos);
7524 : 246176306 : FOR_BB_INSNS_REVERSE (bb, curr_insn)
7525 : : {
7526 : 227512485 : if (! INSN_P (curr_insn))
7527 : 36053095 : continue;
7528 : 191459390 : done_p = false;
7529 : 191459390 : sregno = dregno = -1;
7530 : 45878047 : if (change_p && NONDEBUG_INSN_P (curr_insn)
7531 : 223560192 : && (set = single_set (curr_insn)) != NULL_RTX)
7532 : : {
7533 : 31085813 : dregno = get_regno (SET_DEST (set));
7534 : 62171626 : sregno = get_regno (SET_SRC (set));
7535 : : }
7536 : :
7537 : 191459390 : if (sregno >= 0 && dregno >= 0)
7538 : : {
7539 : 10905337 : if (bitmap_bit_p (remove_pseudos, dregno)
7540 : 10905337 : && ! REG_P (lra_reg_info[dregno].restore_rtx))
7541 : : {
7542 : : /* invariant inheritance pseudo <- original pseudo */
7543 : 6872 : if (lra_dump_file != NULL)
7544 : : {
7545 : 0 : fprintf (lra_dump_file, " Removing invariant inheritance:\n");
7546 : 0 : dump_insn_slim (lra_dump_file, curr_insn);
7547 : 0 : fprintf (lra_dump_file, "\n");
7548 : : }
7549 : 6872 : delete_move_and_clobber (curr_insn, dregno);
7550 : 6872 : done_p = true;
7551 : : }
7552 : 10898465 : else if (bitmap_bit_p (remove_pseudos, sregno)
7553 : 10898465 : && ! REG_P (lra_reg_info[sregno].restore_rtx))
7554 : : {
7555 : : /* reload pseudo <- invariant inheritance pseudo */
7556 : 6872 : start_sequence ();
7557 : : /* We cannot just change the source. It might be
7558 : : an insn different from the move. */
7559 : 6872 : emit_insn (lra_reg_info[sregno].restore_rtx);
7560 : 6872 : rtx_insn *new_insns = end_sequence ();
7561 : 6872 : lra_assert (single_set (new_insns) != NULL
7562 : : && SET_DEST (set) == SET_DEST (single_set (new_insns)));
7563 : 6872 : lra_process_new_insns (curr_insn, NULL, new_insns,
7564 : : "Changing reload<-invariant inheritance");
7565 : 6872 : delete_move_and_clobber (curr_insn, dregno);
7566 : 6872 : done_p = true;
7567 : : }
7568 : 10891593 : else if ((bitmap_bit_p (remove_pseudos, sregno)
7569 : 1209390 : && (get_regno (lra_reg_info[sregno].restore_rtx) == dregno
7570 : 570410 : || (bitmap_bit_p (remove_pseudos, dregno)
7571 : 187558 : && get_regno (lra_reg_info[sregno].restore_rtx) >= 0
7572 : 187558 : && (get_regno (lra_reg_info[sregno].restore_rtx)
7573 : 187558 : == get_regno (lra_reg_info[dregno].restore_rtx)))))
7574 : 11368224 : || (bitmap_bit_p (remove_pseudos, dregno)
7575 : 648674 : && get_regno (lra_reg_info[dregno].restore_rtx) == sregno))
7576 : : /* One of the following cases:
7577 : : original <- removed inheritance pseudo
7578 : : removed inherit pseudo <- another removed inherit pseudo
7579 : : removed inherit pseudo <- original pseudo
7580 : : Or
7581 : : removed_split_pseudo <- original_reg
7582 : : original_reg <- removed_split_pseudo */
7583 : : {
7584 : 176847 : if (lra_dump_file != NULL)
7585 : : {
7586 : 0 : fprintf (lra_dump_file, " Removing %s:\n",
7587 : 0 : bitmap_bit_p (&lra_split_regs, sregno)
7588 : 0 : || bitmap_bit_p (&lra_split_regs, dregno)
7589 : : ? "split" : "inheritance");
7590 : 0 : dump_insn_slim (lra_dump_file, curr_insn);
7591 : : }
7592 : 176847 : delete_move_and_clobber (curr_insn, dregno);
7593 : 176847 : done_p = true;
7594 : : }
7595 : 10714746 : else if (bitmap_bit_p (remove_pseudos, sregno)
7596 : 10714746 : && bitmap_bit_p (&lra_inheritance_pseudos, sregno))
7597 : : {
7598 : : /* Search the following pattern:
7599 : : inherit_or_split_pseudo1 <- inherit_or_split_pseudo2
7600 : : original_pseudo <- inherit_or_split_pseudo1
7601 : : where the 2nd insn is the current insn and
7602 : : inherit_or_split_pseudo2 is not removed. If it is found,
7603 : : change the current insn onto:
7604 : : original_pseudo <- inherit_or_split_pseudo2. */
7605 : 721122 : for (prev_insn = PREV_INSN (curr_insn);
7606 : 721122 : prev_insn != NULL_RTX && ! NONDEBUG_INSN_P (prev_insn);
7607 : 244491 : prev_insn = PREV_INSN (prev_insn))
7608 : : ;
7609 : 476631 : if (prev_insn != NULL_RTX && BLOCK_FOR_INSN (prev_insn) == bb
7610 : 463399 : && (prev_set = single_set (prev_insn)) != NULL_RTX
7611 : : /* There should be no subregs in insn we are
7612 : : searching because only the original reg might
7613 : : be in subreg when we changed the mode of
7614 : : load/store for splitting. */
7615 : 457651 : && REG_P (SET_DEST (prev_set))
7616 : 354791 : && REG_P (SET_SRC (prev_set))
7617 : 272621 : && (int) REGNO (SET_DEST (prev_set)) == sregno
7618 : 185333 : && ((prev_sregno = REGNO (SET_SRC (prev_set)))
7619 : : >= FIRST_PSEUDO_REGISTER)
7620 : 185333 : && (lra_reg_info[prev_sregno].restore_rtx == NULL_RTX
7621 : 143665 : ||
7622 : : /* As we consider chain of inheritance or
7623 : : splitting described in above comment we should
7624 : : check that sregno and prev_sregno were
7625 : : inheritance/split pseudos created from the
7626 : : same original regno. */
7627 : 287330 : (get_regno (lra_reg_info[sregno].restore_rtx) >= 0
7628 : 287330 : && (get_regno (lra_reg_info[sregno].restore_rtx)
7629 : 287330 : == get_regno (lra_reg_info[prev_sregno].restore_rtx))))
7630 : 661964 : && ! bitmap_bit_p (remove_pseudos, prev_sregno))
7631 : : {
7632 : 103090 : int restore_regno = get_regno (lra_reg_info[sregno].restore_rtx);
7633 : 103090 : if (restore_regno < 0)
7634 : 0 : restore_regno = prev_sregno;
7635 : 103090 : lra_assert (GET_MODE (SET_SRC (prev_set))
7636 : : == GET_MODE (regno_reg_rtx[restore_regno]));
7637 : : /* Although we have a single set, the insn can
7638 : : contain more one sregno register occurrence
7639 : : as a source. Change all occurrences. */
7640 : 103090 : lra_substitute_pseudo_within_insn (curr_insn, sregno,
7641 : : regno_reg_rtx[restore_regno],
7642 : : false);
7643 : : /* As we are finishing with processing the insn
7644 : : here, check the destination too as it might
7645 : : inheritance pseudo for another pseudo. */
7646 : 103090 : if (bitmap_bit_p (remove_pseudos, dregno)
7647 : 0 : && bitmap_bit_p (&lra_inheritance_pseudos, dregno)
7648 : 103090 : && (restore_rtx
7649 : 0 : = lra_reg_info[dregno].restore_rtx) != NULL_RTX)
7650 : : {
7651 : 0 : if (GET_CODE (SET_DEST (set)) == SUBREG)
7652 : 0 : SUBREG_REG (SET_DEST (set)) = restore_rtx;
7653 : : else
7654 : 0 : SET_DEST (set) = restore_rtx;
7655 : : }
7656 : 103090 : lra_push_insn_and_update_insn_regno_info (curr_insn);
7657 : 103090 : lra_set_used_insn_alternative_by_uid
7658 : 103090 : (INSN_UID (curr_insn), LRA_UNKNOWN_ALT);
7659 : 103090 : done_p = true;
7660 : 103090 : if (lra_dump_file != NULL)
7661 : : {
7662 : 0 : fprintf (lra_dump_file, " Change reload insn:\n");
7663 : 0 : dump_insn_slim (lra_dump_file, curr_insn);
7664 : : }
7665 : : }
7666 : : }
7667 : : }
7668 : 190591 : if (! done_p)
7669 : : {
7670 : 191165709 : struct lra_insn_reg *reg;
7671 : 191165709 : bool restored_regs_p = false;
7672 : 191165709 : bool kept_regs_p = false;
7673 : :
7674 : 191165709 : curr_id = lra_get_insn_recog_data (curr_insn);
7675 : 397532184 : for (reg = curr_id->regs; reg != NULL; reg = reg->next)
7676 : : {
7677 : 206366475 : regno = reg->regno;
7678 : 206366475 : restore_rtx = lra_reg_info[regno].restore_rtx;
7679 : 206366475 : if (restore_rtx != NULL_RTX)
7680 : : {
7681 : 5882006 : if (change_p && bitmap_bit_p (remove_pseudos, regno))
7682 : : {
7683 : 826516 : lra_substitute_pseudo_within_insn
7684 : 826516 : (curr_insn, regno, restore_rtx, false);
7685 : 826516 : restored_regs_p = true;
7686 : : }
7687 : : else
7688 : : kept_regs_p = true;
7689 : : }
7690 : : }
7691 : 191165709 : if (NONDEBUG_INSN_P (curr_insn) && kept_regs_p)
7692 : : {
7693 : : /* The instruction has changed since the previous
7694 : : constraints pass. */
7695 : 4452128 : lra_push_insn_and_update_insn_regno_info (curr_insn);
7696 : 4452128 : lra_set_used_insn_alternative_by_uid
7697 : 4452128 : (INSN_UID (curr_insn), LRA_UNKNOWN_ALT);
7698 : : }
7699 : 186713581 : else if (restored_regs_p)
7700 : : /* The instruction has been restored to the form that
7701 : : it had during the previous constraints pass. */
7702 : 661478 : lra_update_insn_regno_info (curr_insn);
7703 : 5113606 : if (restored_regs_p && lra_dump_file != NULL)
7704 : : {
7705 : 0 : fprintf (lra_dump_file, " Insn after restoring regs:\n");
7706 : 0 : dump_insn_slim (lra_dump_file, curr_insn);
7707 : : }
7708 : : }
7709 : : }
7710 : : }
7711 : 1537010 : return change_p;
7712 : : }
7713 : :
7714 : : /* If optional reload pseudos failed to get a hard register or was not
7715 : : inherited, it is better to remove optional reloads. We do this
7716 : : transformation after undoing inheritance to figure out necessity to
7717 : : remove optional reloads easier. Return true if we do any
7718 : : change. */
7719 : : static bool
7720 : 1537010 : undo_optional_reloads (void)
7721 : : {
7722 : 1537010 : bool change_p, keep_p;
7723 : 1537010 : unsigned int regno, uid;
7724 : 1537010 : bitmap_iterator bi, bi2;
7725 : 1537010 : rtx_insn *insn;
7726 : 1537010 : rtx set, src, dest;
7727 : 1537010 : auto_bitmap removed_optional_reload_pseudos (®_obstack);
7728 : :
7729 : 1537010 : bitmap_copy (removed_optional_reload_pseudos, &lra_optional_reload_pseudos);
7730 : 2576861 : EXECUTE_IF_SET_IN_BITMAP (&lra_optional_reload_pseudos, 0, regno, bi)
7731 : : {
7732 : 1039851 : keep_p = false;
7733 : : /* Keep optional reloads from previous subpasses. */
7734 : 1039851 : if (lra_reg_info[regno].restore_rtx == NULL_RTX
7735 : : /* If the original pseudo changed its allocation, just
7736 : : removing the optional pseudo is dangerous as the original
7737 : : pseudo will have longer live range. */
7738 : 1039851 : || reg_renumber[REGNO (lra_reg_info[regno].restore_rtx)] >= 0)
7739 : : keep_p = true;
7740 : 639592 : else if (reg_renumber[regno] >= 0)
7741 : 1826748 : EXECUTE_IF_SET_IN_BITMAP (&lra_reg_info[regno].insn_bitmap, 0, uid, bi2)
7742 : : {
7743 : 1331324 : insn = lra_insn_recog_data[uid]->insn;
7744 : 1331324 : if ((set = single_set (insn)) == NULL_RTX)
7745 : 6658 : continue;
7746 : 1324666 : src = SET_SRC (set);
7747 : 1324666 : dest = SET_DEST (set);
7748 : 1324666 : if ((! REG_P (src) && ! SUBREG_P (src))
7749 : 709301 : || (! REG_P (dest) && ! SUBREG_P (dest)))
7750 : 615392 : continue;
7751 : 709274 : if (get_regno (dest) == (int) regno
7752 : : /* Ignore insn for optional reloads itself. */
7753 : 1190334 : && (get_regno (lra_reg_info[regno].restore_rtx)
7754 : 595167 : != get_regno (src))
7755 : : /* Check only inheritance on last inheritance pass. */
7756 : 126626 : && get_regno (src) >= new_regno_start
7757 : : /* Check that the optional reload was inherited. */
7758 : 835900 : && bitmap_bit_p (&lra_inheritance_pseudos, get_regno (src)))
7759 : : {
7760 : : keep_p = true;
7761 : : break;
7762 : : }
7763 : : }
7764 : 1022309 : if (keep_p)
7765 : : {
7766 : 526885 : bitmap_clear_bit (removed_optional_reload_pseudos, regno);
7767 : 526885 : if (lra_dump_file != NULL)
7768 : 3 : fprintf (lra_dump_file, "Keep optional reload reg %d\n", regno);
7769 : : }
7770 : : }
7771 : 1537010 : change_p = ! bitmap_empty_p (removed_optional_reload_pseudos);
7772 : 1537010 : auto_bitmap insn_bitmap (®_obstack);
7773 : 2049976 : EXECUTE_IF_SET_IN_BITMAP (removed_optional_reload_pseudos, 0, regno, bi)
7774 : : {
7775 : 512966 : if (lra_dump_file != NULL)
7776 : 2 : fprintf (lra_dump_file, "Remove optional reload reg %d\n", regno);
7777 : 512966 : bitmap_copy (insn_bitmap, &lra_reg_info[regno].insn_bitmap);
7778 : 1628346 : EXECUTE_IF_SET_IN_BITMAP (insn_bitmap, 0, uid, bi2)
7779 : : {
7780 : : /* We may have already removed a clobber. */
7781 : 1115380 : if (!lra_insn_recog_data[uid])
7782 : 0 : continue;
7783 : 1115380 : insn = lra_insn_recog_data[uid]->insn;
7784 : 1115380 : if ((set = single_set (insn)) != NULL_RTX)
7785 : : {
7786 : 1109439 : src = SET_SRC (set);
7787 : 1109439 : dest = SET_DEST (set);
7788 : 507009 : if ((REG_P (src) || SUBREG_P (src))
7789 : 602442 : && (REG_P (dest) || SUBREG_P (dest))
7790 : 1711853 : && ((get_regno (src) == (int) regno
7791 : 235716 : && (get_regno (lra_reg_info[regno].restore_rtx)
7792 : 117858 : == get_regno (dest)))
7793 : 518624 : || (get_regno (dest) == (int) regno
7794 : 484556 : && (get_regno (lra_reg_info[regno].restore_rtx)
7795 : 484556 : == get_regno (src)))))
7796 : : {
7797 : 568291 : if (lra_dump_file != NULL)
7798 : : {
7799 : 0 : fprintf (lra_dump_file, " Deleting move %u\n",
7800 : 0 : INSN_UID (insn));
7801 : 0 : dump_insn_slim (lra_dump_file, insn);
7802 : : }
7803 : 1136582 : delete_move_and_clobber (insn, get_regno (dest));
7804 : 568291 : continue;
7805 : : }
7806 : : /* We should not worry about generation memory-memory
7807 : : moves here as if the corresponding inheritance did
7808 : : not work (inheritance pseudo did not get a hard reg),
7809 : : we remove the inheritance pseudo and the optional
7810 : : reload. */
7811 : : }
7812 : 547089 : if (GET_CODE (PATTERN (insn)) == CLOBBER
7813 : 0 : && REG_P (SET_DEST (insn))
7814 : 547089 : && get_regno (SET_DEST (insn)) == (int) regno)
7815 : : /* Refuse to remap clobbers to preexisting pseudos. */
7816 : 0 : gcc_unreachable ();
7817 : 547089 : lra_substitute_pseudo_within_insn
7818 : 547089 : (insn, regno, lra_reg_info[regno].restore_rtx, false);
7819 : 547089 : lra_update_insn_regno_info (insn);
7820 : 547089 : if (lra_dump_file != NULL)
7821 : : {
7822 : 4 : fprintf (lra_dump_file,
7823 : : " Restoring original insn:\n");
7824 : 4 : dump_insn_slim (lra_dump_file, insn);
7825 : : }
7826 : : }
7827 : : }
7828 : : /* Clear restore_regnos. */
7829 : 2576861 : EXECUTE_IF_SET_IN_BITMAP (&lra_optional_reload_pseudos, 0, regno, bi)
7830 : 1039851 : lra_reg_info[regno].restore_rtx = NULL_RTX;
7831 : 1537010 : return change_p;
7832 : 1537010 : }
7833 : :
7834 : : /* Entry function for undoing inheritance/split transformation. Return true
7835 : : if we did any RTL change in this pass. */
7836 : : bool
7837 : 1540003 : lra_undo_inheritance (void)
7838 : : {
7839 : 1540003 : unsigned int regno;
7840 : 1540003 : int hard_regno;
7841 : 1540003 : int n_all_inherit, n_inherit, n_all_split, n_split;
7842 : 1540003 : rtx restore_rtx;
7843 : 1540003 : bitmap_iterator bi;
7844 : 1540003 : bool change_p;
7845 : :
7846 : 1540003 : lra_undo_inheritance_iter++;
7847 : 1540003 : if (lra_undo_inheritance_iter > LRA_MAX_INHERITANCE_PASSES)
7848 : : return false;
7849 : 1537010 : if (lra_dump_file != NULL)
7850 : 97 : fprintf (lra_dump_file,
7851 : : "\n********** Undoing inheritance #%d: **********\n\n",
7852 : : lra_undo_inheritance_iter);
7853 : 1537010 : auto_bitmap remove_pseudos (®_obstack);
7854 : 1537010 : n_inherit = n_all_inherit = 0;
7855 : 3421884 : EXECUTE_IF_SET_IN_BITMAP (&lra_inheritance_pseudos, 0, regno, bi)
7856 : 1884874 : if (lra_reg_info[regno].restore_rtx != NULL_RTX)
7857 : : {
7858 : 1184294 : n_all_inherit++;
7859 : 1184294 : if (reg_renumber[regno] < 0
7860 : : /* If the original pseudo changed its allocation, just
7861 : : removing inheritance is dangerous as for changing
7862 : : allocation we used shorter live-ranges. */
7863 : 1184294 : && (! REG_P (lra_reg_info[regno].restore_rtx)
7864 : 419244 : || reg_renumber[REGNO (lra_reg_info[regno].restore_rtx)] < 0))
7865 : 426116 : bitmap_set_bit (remove_pseudos, regno);
7866 : : else
7867 : 758178 : n_inherit++;
7868 : : }
7869 : 1537010 : if (lra_dump_file != NULL && n_all_inherit != 0)
7870 : 2 : fprintf (lra_dump_file, "Inherit %d out of %d (%.2f%%)\n",
7871 : : n_inherit, n_all_inherit,
7872 : 2 : (double) n_inherit / n_all_inherit * 100);
7873 : 1537010 : n_split = n_all_split = 0;
7874 : 2463296 : EXECUTE_IF_SET_IN_BITMAP (&lra_split_regs, 0, regno, bi)
7875 : 926286 : if ((restore_rtx = lra_reg_info[regno].restore_rtx) != NULL_RTX)
7876 : : {
7877 : 629793 : int restore_regno = REGNO (restore_rtx);
7878 : :
7879 : 629793 : n_all_split++;
7880 : 1259504 : hard_regno = (restore_regno >= FIRST_PSEUDO_REGISTER
7881 : 629793 : ? reg_renumber[restore_regno] : restore_regno);
7882 : 629793 : if (hard_regno < 0 || reg_renumber[regno] == hard_regno)
7883 : 2165 : bitmap_set_bit (remove_pseudos, regno);
7884 : : else
7885 : : {
7886 : 627628 : n_split++;
7887 : 627628 : if (lra_dump_file != NULL)
7888 : 0 : fprintf (lra_dump_file, " Keep split r%d (orig=r%d)\n",
7889 : : regno, restore_regno);
7890 : : }
7891 : : }
7892 : 1537010 : if (lra_dump_file != NULL && n_all_split != 0)
7893 : 0 : fprintf (lra_dump_file, "Split %d out of %d (%.2f%%)\n",
7894 : : n_split, n_all_split,
7895 : 0 : (double) n_split / n_all_split * 100);
7896 : 1537010 : change_p = remove_inheritance_pseudos (remove_pseudos);
7897 : : /* Clear restore_regnos. */
7898 : 3421884 : EXECUTE_IF_SET_IN_BITMAP (&lra_inheritance_pseudos, 0, regno, bi)
7899 : 1884874 : lra_reg_info[regno].restore_rtx = NULL_RTX;
7900 : 2463296 : EXECUTE_IF_SET_IN_BITMAP (&lra_split_regs, 0, regno, bi)
7901 : 926286 : lra_reg_info[regno].restore_rtx = NULL_RTX;
7902 : 1537010 : change_p = undo_optional_reloads () || change_p;
7903 : : if (change_p)
7904 : 113131 : lra_dump_insns_if_possible ("changed func after undoing inheritance");
7905 : 1537010 : return change_p;
7906 : 1537010 : }
|