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