Introduce gimple_omp_continue
[official-gcc.git] / gcc / lra-eliminations.c
blob8109af84ae0fe45ffb2e817775c48040cf427f33
1 /* Code for RTL register eliminations.
2 Copyright (C) 2010-2014 Free Software Foundation, Inc.
3 Contributed by Vladimir Makarov <vmakarov@redhat.com>.
5 This file is part of GCC.
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.
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.
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/>. */
21 /* Eliminable registers (like a soft argument or frame pointer) are
22 widely used in RTL. These eliminable registers should be replaced
23 by real hard registers (like the stack pointer or hard frame
24 pointer) plus some offset. The offsets usually change whenever the
25 stack is expanded. We know the final offsets only at the very end
26 of LRA.
28 Within LRA, we usually keep the RTL in such a state that the
29 eliminable registers can be replaced by just the corresponding hard
30 register (without any offset). To achieve this we should add the
31 initial elimination offset at the beginning of LRA and update the
32 offsets whenever the stack is expanded. We need to do this before
33 every constraint pass because the choice of offset often affects
34 whether a particular address or memory constraint is satisfied.
36 We keep RTL code at most time in such state that the virtual
37 registers can be changed by just the corresponding hard registers
38 (with zero offsets) and we have the right RTL code. To achieve this
39 we should add initial offset at the beginning of LRA work and update
40 offsets after each stack expanding. But actually we update virtual
41 registers to the same virtual registers + corresponding offsets
42 before every constraint pass because it affects constraint
43 satisfaction (e.g. an address displacement became too big for some
44 target).
46 The final change of eliminable registers to the corresponding hard
47 registers are done at the very end of LRA when there were no change
48 in offsets anymore:
50 fp + 42 => sp + 42
54 #include "config.h"
55 #include "system.h"
56 #include "coretypes.h"
57 #include "tm.h"
58 #include "hard-reg-set.h"
59 #include "rtl.h"
60 #include "tm_p.h"
61 #include "regs.h"
62 #include "insn-config.h"
63 #include "insn-codes.h"
64 #include "recog.h"
65 #include "output.h"
66 #include "addresses.h"
67 #include "target.h"
68 #include "function.h"
69 #include "expr.h"
70 #include "basic-block.h"
71 #include "except.h"
72 #include "optabs.h"
73 #include "df.h"
74 #include "ira.h"
75 #include "rtl-error.h"
76 #include "lra-int.h"
78 /* This structure is used to record information about hard register
79 eliminations. */
80 struct lra_elim_table
82 /* Hard register number to be eliminated. */
83 int from;
84 /* Hard register number used as replacement. */
85 int to;
86 /* Difference between values of the two hard registers above on
87 previous iteration. */
88 HOST_WIDE_INT previous_offset;
89 /* Difference between the values on the current iteration. */
90 HOST_WIDE_INT offset;
91 /* Nonzero if this elimination can be done. */
92 bool can_eliminate;
93 /* CAN_ELIMINATE since the last check. */
94 bool prev_can_eliminate;
95 /* REG rtx for the register to be eliminated. We cannot simply
96 compare the number since we might then spuriously replace a hard
97 register corresponding to a pseudo assigned to the reg to be
98 eliminated. */
99 rtx from_rtx;
100 /* REG rtx for the replacement. */
101 rtx to_rtx;
104 /* The elimination table. Each array entry describes one possible way
105 of eliminating a register in favor of another. If there is more
106 than one way of eliminating a particular register, the most
107 preferred should be specified first. */
108 static struct lra_elim_table *reg_eliminate = 0;
110 /* This is an intermediate structure to initialize the table. It has
111 exactly the members provided by ELIMINABLE_REGS. */
112 static const struct elim_table_1
114 const int from;
115 const int to;
116 } reg_eliminate_1[] =
118 /* If a set of eliminable hard registers was specified, define the
119 table from it. Otherwise, default to the normal case of the frame
120 pointer being replaced by the stack pointer. */
122 #ifdef ELIMINABLE_REGS
123 ELIMINABLE_REGS;
124 #else
125 {{ FRAME_POINTER_REGNUM, STACK_POINTER_REGNUM}};
126 #endif
128 #define NUM_ELIMINABLE_REGS ARRAY_SIZE (reg_eliminate_1)
130 /* Print info about elimination table to file F. */
131 static void
132 print_elim_table (FILE *f)
134 struct lra_elim_table *ep;
136 for (ep = reg_eliminate; ep < &reg_eliminate[NUM_ELIMINABLE_REGS]; ep++)
137 fprintf (f, "%s eliminate %d to %d (offset=" HOST_WIDE_INT_PRINT_DEC
138 ", prev_offset=" HOST_WIDE_INT_PRINT_DEC ")\n",
139 ep->can_eliminate ? "Can" : "Can't",
140 ep->from, ep->to, ep->offset, ep->previous_offset);
143 /* Print info about elimination table to stderr. */
144 void
145 lra_debug_elim_table (void)
147 print_elim_table (stderr);
150 /* Setup possibility of elimination in elimination table element EP to
151 VALUE. Setup FRAME_POINTER_NEEDED if elimination from frame
152 pointer to stack pointer is not possible anymore. */
153 static void
154 setup_can_eliminate (struct lra_elim_table *ep, bool value)
156 ep->can_eliminate = ep->prev_can_eliminate = value;
157 if (! value
158 && ep->from == FRAME_POINTER_REGNUM && ep->to == STACK_POINTER_REGNUM)
159 frame_pointer_needed = 1;
162 /* Map: eliminable "from" register -> its current elimination,
163 or NULL if none. The elimination table may contain more than
164 one elimination for the same hard register, but this map specifies
165 the one that we are currently using. */
166 static struct lra_elim_table *elimination_map[FIRST_PSEUDO_REGISTER];
168 /* When an eliminable hard register becomes not eliminable, we use the
169 following special structure to restore original offsets for the
170 register. */
171 static struct lra_elim_table self_elim_table;
173 /* Offsets should be used to restore original offsets for eliminable
174 hard register which just became not eliminable. Zero,
175 otherwise. */
176 static HOST_WIDE_INT self_elim_offsets[FIRST_PSEUDO_REGISTER];
178 /* Map: hard regno -> RTL presentation. RTL presentations of all
179 potentially eliminable hard registers are stored in the map. */
180 static rtx eliminable_reg_rtx[FIRST_PSEUDO_REGISTER];
182 /* Set up ELIMINATION_MAP of the currently used eliminations. */
183 static void
184 setup_elimination_map (void)
186 int i;
187 struct lra_elim_table *ep;
189 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
190 elimination_map[i] = NULL;
191 for (ep = reg_eliminate; ep < &reg_eliminate[NUM_ELIMINABLE_REGS]; ep++)
192 if (ep->can_eliminate && elimination_map[ep->from] == NULL)
193 elimination_map[ep->from] = ep;
198 /* Compute the sum of X and Y, making canonicalizations assumed in an
199 address, namely: sum constant integers, surround the sum of two
200 constants with a CONST, put the constant as the second operand, and
201 group the constant on the outermost sum.
203 This routine assumes both inputs are already in canonical form. */
204 static rtx
205 form_sum (rtx x, rtx y)
207 rtx tem;
208 enum machine_mode mode = GET_MODE (x);
210 if (mode == VOIDmode)
211 mode = GET_MODE (y);
213 if (mode == VOIDmode)
214 mode = Pmode;
216 if (CONST_INT_P (x))
217 return plus_constant (mode, y, INTVAL (x));
218 else if (CONST_INT_P (y))
219 return plus_constant (mode, x, INTVAL (y));
220 else if (CONSTANT_P (x))
221 tem = x, x = y, y = tem;
223 if (GET_CODE (x) == PLUS && CONSTANT_P (XEXP (x, 1)))
224 return form_sum (XEXP (x, 0), form_sum (XEXP (x, 1), y));
226 /* Note that if the operands of Y are specified in the opposite
227 order in the recursive calls below, infinite recursion will
228 occur. */
229 if (GET_CODE (y) == PLUS && CONSTANT_P (XEXP (y, 1)))
230 return form_sum (form_sum (x, XEXP (y, 0)), XEXP (y, 1));
232 /* If both constant, encapsulate sum. Otherwise, just form sum. A
233 constant will have been placed second. */
234 if (CONSTANT_P (x) && CONSTANT_P (y))
236 if (GET_CODE (x) == CONST)
237 x = XEXP (x, 0);
238 if (GET_CODE (y) == CONST)
239 y = XEXP (y, 0);
241 return gen_rtx_CONST (VOIDmode, gen_rtx_PLUS (mode, x, y));
244 return gen_rtx_PLUS (mode, x, y);
247 /* Return the current substitution hard register of the elimination of
248 HARD_REGNO. If HARD_REGNO is not eliminable, return itself. */
250 lra_get_elimination_hard_regno (int hard_regno)
252 struct lra_elim_table *ep;
254 if (hard_regno < 0 || hard_regno >= FIRST_PSEUDO_REGISTER)
255 return hard_regno;
256 if ((ep = elimination_map[hard_regno]) == NULL)
257 return hard_regno;
258 return ep->to;
261 /* Return elimination which will be used for hard reg REG, NULL
262 otherwise. */
263 static struct lra_elim_table *
264 get_elimination (rtx reg)
266 int hard_regno;
267 struct lra_elim_table *ep;
268 HOST_WIDE_INT offset;
270 lra_assert (REG_P (reg));
271 if ((hard_regno = REGNO (reg)) < 0 || hard_regno >= FIRST_PSEUDO_REGISTER)
272 return NULL;
273 if ((ep = elimination_map[hard_regno]) != NULL)
274 return ep->from_rtx != reg ? NULL : ep;
275 if ((offset = self_elim_offsets[hard_regno]) == 0)
276 return NULL;
277 /* This is an iteration to restore offsets just after HARD_REGNO
278 stopped to be eliminable. */
279 self_elim_table.from = self_elim_table.to = hard_regno;
280 self_elim_table.from_rtx
281 = self_elim_table.to_rtx
282 = eliminable_reg_rtx[hard_regno];
283 lra_assert (self_elim_table.from_rtx != NULL);
284 self_elim_table.offset = offset;
285 return &self_elim_table;
288 /* Scan X and replace any eliminable registers (such as fp) with a
289 replacement (such as sp) if SUBST_P, plus an offset. The offset is
290 a change in the offset between the eliminable register and its
291 substitution if UPDATE_P, or the full offset if FULL_P, or
292 otherwise zero. If FULL_P, we also use the SP offsets for
293 elimination to SP.
295 MEM_MODE is the mode of an enclosing MEM. We need this to know how
296 much to adjust a register for, e.g., PRE_DEC. Also, if we are
297 inside a MEM, we are allowed to replace a sum of a hard register
298 and the constant zero with the hard register, which we cannot do
299 outside a MEM. In addition, we need to record the fact that a
300 hard register is referenced outside a MEM.
302 If we make full substitution to SP for non-null INSN, add the insn
303 sp offset. */
305 lra_eliminate_regs_1 (rtx_insn *insn, rtx x, enum machine_mode mem_mode,
306 bool subst_p, bool update_p, bool full_p)
308 enum rtx_code code = GET_CODE (x);
309 struct lra_elim_table *ep;
310 rtx new_rtx;
311 int i, j;
312 const char *fmt;
313 int copied = 0;
315 gcc_assert (!update_p || !full_p);
316 if (! current_function_decl)
317 return x;
319 switch (code)
321 CASE_CONST_ANY:
322 case CONST:
323 case SYMBOL_REF:
324 case CODE_LABEL:
325 case PC:
326 case CC0:
327 case ASM_INPUT:
328 case ADDR_VEC:
329 case ADDR_DIFF_VEC:
330 case RETURN:
331 return x;
333 case REG:
334 /* First handle the case where we encounter a bare hard register
335 that is eliminable. Replace it with a PLUS. */
336 if ((ep = get_elimination (x)) != NULL)
338 rtx to = subst_p ? ep->to_rtx : ep->from_rtx;
340 if (update_p)
341 return plus_constant (Pmode, to, ep->offset - ep->previous_offset);
342 else if (full_p)
343 return plus_constant (Pmode, to,
344 ep->offset
345 - (insn != NULL_RTX
346 && ep->to_rtx == stack_pointer_rtx
347 ? lra_get_insn_recog_data (insn)->sp_offset
348 : 0));
349 else
350 return to;
352 return x;
354 case PLUS:
355 /* If this is the sum of an eliminable register and a constant, rework
356 the sum. */
357 if (REG_P (XEXP (x, 0)) && CONSTANT_P (XEXP (x, 1)))
359 if ((ep = get_elimination (XEXP (x, 0))) != NULL)
361 HOST_WIDE_INT offset;
362 rtx to = subst_p ? ep->to_rtx : ep->from_rtx;
364 if (! update_p && ! full_p)
365 return gen_rtx_PLUS (Pmode, to, XEXP (x, 1));
367 offset = (update_p
368 ? ep->offset - ep->previous_offset : ep->offset);
369 if (full_p && insn != NULL_RTX && ep->to_rtx == stack_pointer_rtx)
370 offset -= lra_get_insn_recog_data (insn)->sp_offset;
371 if (CONST_INT_P (XEXP (x, 1))
372 && INTVAL (XEXP (x, 1)) == -offset)
373 return to;
374 else
375 return gen_rtx_PLUS (Pmode, to,
376 plus_constant (Pmode,
377 XEXP (x, 1), offset));
380 /* If the hard register is not eliminable, we are done since
381 the other operand is a constant. */
382 return x;
385 /* If this is part of an address, we want to bring any constant
386 to the outermost PLUS. We will do this by doing hard
387 register replacement in our operands and seeing if a constant
388 shows up in one of them.
390 Note that there is no risk of modifying the structure of the
391 insn, since we only get called for its operands, thus we are
392 either modifying the address inside a MEM, or something like
393 an address operand of a load-address insn. */
396 rtx new0 = lra_eliminate_regs_1 (insn, XEXP (x, 0), mem_mode,
397 subst_p, update_p, full_p);
398 rtx new1 = lra_eliminate_regs_1 (insn, XEXP (x, 1), mem_mode,
399 subst_p, update_p, full_p);
401 if (new0 != XEXP (x, 0) || new1 != XEXP (x, 1))
402 return form_sum (new0, new1);
404 return x;
406 case MULT:
407 /* If this is the product of an eliminable hard register and a
408 constant, apply the distribute law and move the constant out
409 so that we have (plus (mult ..) ..). This is needed in order
410 to keep load-address insns valid. This case is pathological.
411 We ignore the possibility of overflow here. */
412 if (REG_P (XEXP (x, 0)) && CONST_INT_P (XEXP (x, 1))
413 && (ep = get_elimination (XEXP (x, 0))) != NULL)
415 rtx to = subst_p ? ep->to_rtx : ep->from_rtx;
417 if (update_p)
418 return
419 plus_constant (Pmode,
420 gen_rtx_MULT (Pmode, to, XEXP (x, 1)),
421 (ep->offset - ep->previous_offset)
422 * INTVAL (XEXP (x, 1)));
423 else if (full_p)
425 HOST_WIDE_INT offset = ep->offset;
427 if (insn != NULL_RTX && ep->to_rtx == stack_pointer_rtx)
428 offset -= lra_get_insn_recog_data (insn)->sp_offset;
429 return
430 plus_constant (Pmode,
431 gen_rtx_MULT (Pmode, to, XEXP (x, 1)),
432 offset * INTVAL (XEXP (x, 1)));
434 else
435 return gen_rtx_MULT (Pmode, to, XEXP (x, 1));
438 /* ... fall through ... */
440 case CALL:
441 case COMPARE:
442 /* See comments before PLUS about handling MINUS. */
443 case MINUS:
444 case DIV: case UDIV:
445 case MOD: case UMOD:
446 case AND: case IOR: case XOR:
447 case ROTATERT: case ROTATE:
448 case ASHIFTRT: case LSHIFTRT: case ASHIFT:
449 case NE: case EQ:
450 case GE: case GT: case GEU: case GTU:
451 case LE: case LT: case LEU: case LTU:
453 rtx new0 = lra_eliminate_regs_1 (insn, XEXP (x, 0), mem_mode,
454 subst_p, update_p, full_p);
455 rtx new1 = XEXP (x, 1)
456 ? lra_eliminate_regs_1 (insn, XEXP (x, 1), mem_mode,
457 subst_p, update_p, full_p) : 0;
459 if (new0 != XEXP (x, 0) || new1 != XEXP (x, 1))
460 return gen_rtx_fmt_ee (code, GET_MODE (x), new0, new1);
462 return x;
464 case EXPR_LIST:
465 /* If we have something in XEXP (x, 0), the usual case,
466 eliminate it. */
467 if (XEXP (x, 0))
469 new_rtx = lra_eliminate_regs_1 (insn, XEXP (x, 0), mem_mode,
470 subst_p, update_p, full_p);
471 if (new_rtx != XEXP (x, 0))
473 /* If this is a REG_DEAD note, it is not valid anymore.
474 Using the eliminated version could result in creating a
475 REG_DEAD note for the stack or frame pointer. */
476 if (REG_NOTE_KIND (x) == REG_DEAD)
477 return (XEXP (x, 1)
478 ? lra_eliminate_regs_1 (insn, XEXP (x, 1), mem_mode,
479 subst_p, update_p, full_p)
480 : NULL_RTX);
482 x = alloc_reg_note (REG_NOTE_KIND (x), new_rtx, XEXP (x, 1));
486 /* ... fall through ... */
488 case INSN_LIST:
489 case INT_LIST:
490 /* Now do eliminations in the rest of the chain. If this was
491 an EXPR_LIST, this might result in allocating more memory than is
492 strictly needed, but it simplifies the code. */
493 if (XEXP (x, 1))
495 new_rtx = lra_eliminate_regs_1 (insn, XEXP (x, 1), mem_mode,
496 subst_p, update_p, full_p);
497 if (new_rtx != XEXP (x, 1))
498 return
499 gen_rtx_fmt_ee (GET_CODE (x), GET_MODE (x),
500 XEXP (x, 0), new_rtx);
502 return x;
504 case PRE_INC:
505 case POST_INC:
506 case PRE_DEC:
507 case POST_DEC:
508 /* We do not support elimination of a register that is modified.
509 elimination_effects has already make sure that this does not
510 happen. */
511 return x;
513 case PRE_MODIFY:
514 case POST_MODIFY:
515 /* We do not support elimination of a hard register that is
516 modified. LRA has already make sure that this does not
517 happen. The only remaining case we need to consider here is
518 that the increment value may be an eliminable register. */
519 if (GET_CODE (XEXP (x, 1)) == PLUS
520 && XEXP (XEXP (x, 1), 0) == XEXP (x, 0))
522 rtx new_rtx = lra_eliminate_regs_1 (insn, XEXP (XEXP (x, 1), 1),
523 mem_mode,
524 subst_p, update_p, full_p);
526 if (new_rtx != XEXP (XEXP (x, 1), 1))
527 return gen_rtx_fmt_ee (code, GET_MODE (x), XEXP (x, 0),
528 gen_rtx_PLUS (GET_MODE (x),
529 XEXP (x, 0), new_rtx));
531 return x;
533 case STRICT_LOW_PART:
534 case NEG: case NOT:
535 case SIGN_EXTEND: case ZERO_EXTEND:
536 case TRUNCATE: case FLOAT_EXTEND: case FLOAT_TRUNCATE:
537 case FLOAT: case FIX:
538 case UNSIGNED_FIX: case UNSIGNED_FLOAT:
539 case ABS:
540 case SQRT:
541 case FFS:
542 case CLZ:
543 case CTZ:
544 case POPCOUNT:
545 case PARITY:
546 case BSWAP:
547 new_rtx = lra_eliminate_regs_1 (insn, XEXP (x, 0), mem_mode,
548 subst_p, update_p, full_p);
549 if (new_rtx != XEXP (x, 0))
550 return gen_rtx_fmt_e (code, GET_MODE (x), new_rtx);
551 return x;
553 case SUBREG:
554 new_rtx = lra_eliminate_regs_1 (insn, SUBREG_REG (x), mem_mode,
555 subst_p, update_p, full_p);
557 if (new_rtx != SUBREG_REG (x))
559 int x_size = GET_MODE_SIZE (GET_MODE (x));
560 int new_size = GET_MODE_SIZE (GET_MODE (new_rtx));
562 if (MEM_P (new_rtx) && x_size <= new_size)
564 SUBREG_REG (x) = new_rtx;
565 alter_subreg (&x, false);
566 return x;
568 else if (! subst_p)
570 /* LRA can transform subregs itself. So don't call
571 simplify_gen_subreg until LRA transformations are
572 finished. Function simplify_gen_subreg can do
573 non-trivial transformations (like truncation) which
574 might make LRA work to fail. */
575 SUBREG_REG (x) = new_rtx;
576 return x;
578 else
579 return simplify_gen_subreg (GET_MODE (x), new_rtx,
580 GET_MODE (new_rtx), SUBREG_BYTE (x));
583 return x;
585 case MEM:
586 /* Our only special processing is to pass the mode of the MEM to our
587 recursive call and copy the flags. While we are here, handle this
588 case more efficiently. */
589 return
590 replace_equiv_address_nv
592 lra_eliminate_regs_1 (insn, XEXP (x, 0), GET_MODE (x),
593 subst_p, update_p, full_p));
595 case USE:
596 /* Handle insn_list USE that a call to a pure function may generate. */
597 new_rtx = lra_eliminate_regs_1 (insn, XEXP (x, 0), VOIDmode,
598 subst_p, update_p, full_p);
599 if (new_rtx != XEXP (x, 0))
600 return gen_rtx_USE (GET_MODE (x), new_rtx);
601 return x;
603 case CLOBBER:
604 case SET:
605 gcc_unreachable ();
607 default:
608 break;
611 /* Process each of our operands recursively. If any have changed, make a
612 copy of the rtx. */
613 fmt = GET_RTX_FORMAT (code);
614 for (i = 0; i < GET_RTX_LENGTH (code); i++, fmt++)
616 if (*fmt == 'e')
618 new_rtx = lra_eliminate_regs_1 (insn, XEXP (x, i), mem_mode,
619 subst_p, update_p, full_p);
620 if (new_rtx != XEXP (x, i) && ! copied)
622 x = shallow_copy_rtx (x);
623 copied = 1;
625 XEXP (x, i) = new_rtx;
627 else if (*fmt == 'E')
629 int copied_vec = 0;
630 for (j = 0; j < XVECLEN (x, i); j++)
632 new_rtx = lra_eliminate_regs_1 (insn, XVECEXP (x, i, j), mem_mode,
633 subst_p, update_p, full_p);
634 if (new_rtx != XVECEXP (x, i, j) && ! copied_vec)
636 rtvec new_v = gen_rtvec_v (XVECLEN (x, i),
637 XVEC (x, i)->elem);
638 if (! copied)
640 x = shallow_copy_rtx (x);
641 copied = 1;
643 XVEC (x, i) = new_v;
644 copied_vec = 1;
646 XVECEXP (x, i, j) = new_rtx;
651 return x;
654 /* This function is used externally in subsequent passes of GCC. It
655 always does a full elimination of X. */
657 lra_eliminate_regs (rtx x, enum machine_mode mem_mode,
658 rtx insn ATTRIBUTE_UNUSED)
660 return lra_eliminate_regs_1 (NULL, x, mem_mode, true, false, true);
663 /* Stack pointer offset before the current insn relative to one at the
664 func start. RTL insns can change SP explicitly. We keep the
665 changes from one insn to another through this variable. */
666 static HOST_WIDE_INT curr_sp_change;
668 /* Scan rtx X for references to elimination source or target registers
669 in contexts that would prevent the elimination from happening.
670 Update the table of eliminables to reflect the changed state.
671 MEM_MODE is the mode of an enclosing MEM rtx, or VOIDmode if not
672 within a MEM. */
673 static void
674 mark_not_eliminable (rtx x, enum machine_mode mem_mode)
676 enum rtx_code code = GET_CODE (x);
677 struct lra_elim_table *ep;
678 int i, j;
679 const char *fmt;
681 switch (code)
683 case PRE_INC:
684 case POST_INC:
685 case PRE_DEC:
686 case POST_DEC:
687 case POST_MODIFY:
688 case PRE_MODIFY:
689 if (XEXP (x, 0) == stack_pointer_rtx
690 && ((code != PRE_MODIFY && code != POST_MODIFY)
691 || (GET_CODE (XEXP (x, 1)) == PLUS
692 && XEXP (x, 0) == XEXP (XEXP (x, 1), 0)
693 && CONST_INT_P (XEXP (XEXP (x, 1), 1)))))
695 int size = GET_MODE_SIZE (mem_mode);
697 #ifdef PUSH_ROUNDING
698 /* If more bytes than MEM_MODE are pushed, account for
699 them. */
700 size = PUSH_ROUNDING (size);
701 #endif
702 if (code == PRE_DEC || code == POST_DEC)
703 curr_sp_change -= size;
704 else if (code == PRE_INC || code == POST_INC)
705 curr_sp_change += size;
706 else if (code == PRE_MODIFY || code == POST_MODIFY)
707 curr_sp_change += INTVAL (XEXP (XEXP (x, 1), 1));
709 else if (REG_P (XEXP (x, 0))
710 && REGNO (XEXP (x, 0)) >= FIRST_PSEUDO_REGISTER)
712 /* If we modify the source of an elimination rule, disable
713 it. Do the same if it is the destination and not the
714 hard frame register. */
715 for (ep = reg_eliminate;
716 ep < &reg_eliminate[NUM_ELIMINABLE_REGS];
717 ep++)
718 if (ep->from_rtx == XEXP (x, 0)
719 || (ep->to_rtx == XEXP (x, 0)
720 && ep->to_rtx != hard_frame_pointer_rtx))
721 setup_can_eliminate (ep, false);
723 return;
725 case USE:
726 if (REG_P (XEXP (x, 0)) && REGNO (XEXP (x, 0)) < FIRST_PSEUDO_REGISTER)
727 /* If using a hard register that is the source of an eliminate
728 we still think can be performed, note it cannot be
729 performed since we don't know how this hard register is
730 used. */
731 for (ep = reg_eliminate;
732 ep < &reg_eliminate[NUM_ELIMINABLE_REGS];
733 ep++)
734 if (ep->from_rtx == XEXP (x, 0)
735 && ep->to_rtx != hard_frame_pointer_rtx)
736 setup_can_eliminate (ep, false);
737 return;
739 case CLOBBER:
740 if (REG_P (XEXP (x, 0)) && REGNO (XEXP (x, 0)) < FIRST_PSEUDO_REGISTER)
741 /* If clobbering a hard register that is the replacement
742 register for an elimination we still think can be
743 performed, note that it cannot be performed. Otherwise, we
744 need not be concerned about it. */
745 for (ep = reg_eliminate;
746 ep < &reg_eliminate[NUM_ELIMINABLE_REGS];
747 ep++)
748 if (ep->to_rtx == XEXP (x, 0)
749 && ep->to_rtx != hard_frame_pointer_rtx)
750 setup_can_eliminate (ep, false);
751 return;
753 case SET:
754 if (SET_DEST (x) == stack_pointer_rtx
755 && GET_CODE (SET_SRC (x)) == PLUS
756 && XEXP (SET_SRC (x), 0) == SET_DEST (x)
757 && CONST_INT_P (XEXP (SET_SRC (x), 1)))
759 curr_sp_change += INTVAL (XEXP (SET_SRC (x), 1));
760 return;
762 if (! REG_P (SET_DEST (x))
763 || REGNO (SET_DEST (x)) >= FIRST_PSEUDO_REGISTER)
764 mark_not_eliminable (SET_DEST (x), mem_mode);
765 else
767 /* See if this is setting the replacement hard register for
768 an elimination.
770 If DEST is the hard frame pointer, we do nothing because
771 we assume that all assignments to the frame pointer are
772 for non-local gotos and are being done at a time when
773 they are valid and do not disturb anything else. Some
774 machines want to eliminate a fake argument pointer (or
775 even a fake frame pointer) with either the real frame
776 pointer or the stack pointer. Assignments to the hard
777 frame pointer must not prevent this elimination. */
778 for (ep = reg_eliminate;
779 ep < &reg_eliminate[NUM_ELIMINABLE_REGS];
780 ep++)
781 if (ep->to_rtx == SET_DEST (x)
782 && SET_DEST (x) != hard_frame_pointer_rtx)
783 setup_can_eliminate (ep, false);
786 mark_not_eliminable (SET_SRC (x), mem_mode);
787 return;
789 case MEM:
790 /* Our only special processing is to pass the mode of the MEM to
791 our recursive call. */
792 mark_not_eliminable (XEXP (x, 0), GET_MODE (x));
793 return;
795 default:
796 break;
799 fmt = GET_RTX_FORMAT (code);
800 for (i = 0; i < GET_RTX_LENGTH (code); i++, fmt++)
802 if (*fmt == 'e')
803 mark_not_eliminable (XEXP (x, i), mem_mode);
804 else if (*fmt == 'E')
805 for (j = 0; j < XVECLEN (x, i); j++)
806 mark_not_eliminable (XVECEXP (x, i, j), mem_mode);
812 #ifdef HARD_FRAME_POINTER_REGNUM
814 /* Find offset equivalence note for reg WHAT in INSN and return the
815 found elmination offset. If the note is not found, return NULL.
816 Remove the found note. */
817 static rtx
818 remove_reg_equal_offset_note (rtx insn, rtx what)
820 rtx link, *link_loc;
822 for (link_loc = &REG_NOTES (insn);
823 (link = *link_loc) != NULL_RTX;
824 link_loc = &XEXP (link, 1))
825 if (REG_NOTE_KIND (link) == REG_EQUAL
826 && GET_CODE (XEXP (link, 0)) == PLUS
827 && XEXP (XEXP (link, 0), 0) == what
828 && CONST_INT_P (XEXP (XEXP (link, 0), 1)))
830 *link_loc = XEXP (link, 1);
831 return XEXP (XEXP (link, 0), 1);
833 return NULL_RTX;
836 #endif
838 /* Scan INSN and eliminate all eliminable hard registers in it.
840 If REPLACE_P is true, do the replacement destructively. Also
841 delete the insn as dead it if it is setting an eliminable register.
843 If REPLACE_P is false, just update the offsets while keeping the
844 base register the same. If FIRST_P, use the sp offset for
845 elimination to sp. Attach the note about used elimination for
846 insns setting frame pointer to update elimination easy (without
847 parsing already generated elimination insns to find offset
848 previously used) in future. */
850 static void
851 eliminate_regs_in_insn (rtx_insn *insn, bool replace_p, bool first_p)
853 int icode = recog_memoized (insn);
854 rtx old_set = single_set (insn);
855 bool validate_p;
856 int i;
857 rtx substed_operand[MAX_RECOG_OPERANDS];
858 rtx orig_operand[MAX_RECOG_OPERANDS];
859 struct lra_elim_table *ep;
860 rtx plus_src, plus_cst_src;
861 lra_insn_recog_data_t id;
862 struct lra_static_insn_data *static_id;
864 if (icode < 0 && asm_noperands (PATTERN (insn)) < 0 && ! DEBUG_INSN_P (insn))
866 lra_assert (GET_CODE (PATTERN (insn)) == USE
867 || GET_CODE (PATTERN (insn)) == CLOBBER
868 || GET_CODE (PATTERN (insn)) == ASM_INPUT);
869 return;
872 /* Check for setting an eliminable register. */
873 if (old_set != 0 && REG_P (SET_DEST (old_set))
874 && (ep = get_elimination (SET_DEST (old_set))) != NULL)
876 for (ep = reg_eliminate; ep < &reg_eliminate[NUM_ELIMINABLE_REGS]; ep++)
877 if (ep->from_rtx == SET_DEST (old_set) && ep->can_eliminate)
879 bool delete_p = replace_p;
881 #ifdef HARD_FRAME_POINTER_REGNUM
882 if (ep->from == FRAME_POINTER_REGNUM
883 && ep->to == HARD_FRAME_POINTER_REGNUM)
884 /* If this is setting the frame pointer register to the
885 hardware frame pointer register and this is an
886 elimination that will be done (tested above), this
887 insn is really adjusting the frame pointer downward
888 to compensate for the adjustment done before a
889 nonlocal goto. */
891 rtx src = SET_SRC (old_set);
892 rtx off = remove_reg_equal_offset_note (insn, ep->to_rtx);
894 if (off != NULL_RTX
895 || src == ep->to_rtx
896 || (GET_CODE (src) == PLUS
897 && XEXP (src, 0) == ep->to_rtx
898 && CONST_INT_P (XEXP (src, 1))))
900 HOST_WIDE_INT offset;
902 if (replace_p)
904 SET_DEST (old_set) = ep->to_rtx;
905 lra_update_insn_recog_data (insn);
906 return;
908 offset = (off != NULL_RTX ? INTVAL (off)
909 : src == ep->to_rtx ? 0 : INTVAL (XEXP (src, 1)));
910 offset -= (ep->offset - ep->previous_offset);
911 src = plus_constant (Pmode, ep->to_rtx, offset);
913 /* First see if this insn remains valid when we
914 make the change. If not, keep the INSN_CODE
915 the same and let the constraint pass fit it
916 up. */
917 validate_change (insn, &SET_SRC (old_set), src, 1);
918 validate_change (insn, &SET_DEST (old_set),
919 ep->from_rtx, 1);
920 if (! apply_change_group ())
922 SET_SRC (old_set) = src;
923 SET_DEST (old_set) = ep->from_rtx;
925 lra_update_insn_recog_data (insn);
926 /* Add offset note for future updates. */
927 add_reg_note (insn, REG_EQUAL, src);
928 return;
931 #endif
933 /* This insn isn't serving a useful purpose. We delete it
934 when REPLACE is set. */
935 if (delete_p)
936 lra_delete_dead_insn (insn);
937 return;
941 /* We allow one special case which happens to work on all machines we
942 currently support: a single set with the source or a REG_EQUAL
943 note being a PLUS of an eliminable register and a constant. */
944 plus_src = plus_cst_src = 0;
945 if (old_set && REG_P (SET_DEST (old_set)))
947 if (GET_CODE (SET_SRC (old_set)) == PLUS)
948 plus_src = SET_SRC (old_set);
949 /* First see if the source is of the form (plus (...) CST). */
950 if (plus_src
951 && CONST_INT_P (XEXP (plus_src, 1)))
952 plus_cst_src = plus_src;
953 /* Check that the first operand of the PLUS is a hard reg or
954 the lowpart subreg of one. */
955 if (plus_cst_src)
957 rtx reg = XEXP (plus_cst_src, 0);
959 if (GET_CODE (reg) == SUBREG && subreg_lowpart_p (reg))
960 reg = SUBREG_REG (reg);
962 if (!REG_P (reg) || REGNO (reg) >= FIRST_PSEUDO_REGISTER)
963 plus_cst_src = 0;
966 if (plus_cst_src)
968 rtx reg = XEXP (plus_cst_src, 0);
969 HOST_WIDE_INT offset = INTVAL (XEXP (plus_cst_src, 1));
971 if (GET_CODE (reg) == SUBREG)
972 reg = SUBREG_REG (reg);
974 if (REG_P (reg) && (ep = get_elimination (reg)) != NULL)
976 rtx to_rtx = replace_p ? ep->to_rtx : ep->from_rtx;
978 if (! replace_p)
980 offset += (ep->offset - ep->previous_offset);
981 if (first_p && ep->to_rtx == stack_pointer_rtx)
982 offset -= lra_get_insn_recog_data (insn)->sp_offset;
983 offset = trunc_int_for_mode (offset, GET_MODE (plus_cst_src));
986 if (GET_CODE (XEXP (plus_cst_src, 0)) == SUBREG)
987 to_rtx = gen_lowpart (GET_MODE (XEXP (plus_cst_src, 0)), to_rtx);
988 /* If we have a nonzero offset, and the source is already a
989 simple REG, the following transformation would increase
990 the cost of the insn by replacing a simple REG with (plus
991 (reg sp) CST). So try only when we already had a PLUS
992 before. */
993 if (offset == 0 || plus_src)
995 rtx new_src = plus_constant (GET_MODE (to_rtx), to_rtx, offset);
997 old_set = single_set (insn);
999 /* First see if this insn remains valid when we make the
1000 change. If not, try to replace the whole pattern
1001 with a simple set (this may help if the original insn
1002 was a PARALLEL that was only recognized as single_set
1003 due to REG_UNUSED notes). If this isn't valid
1004 either, keep the INSN_CODE the same and let the
1005 constraint pass fix it up. */
1006 if (! validate_change (insn, &SET_SRC (old_set), new_src, 0))
1008 rtx new_pat = gen_rtx_SET (VOIDmode,
1009 SET_DEST (old_set), new_src);
1011 if (! validate_change (insn, &PATTERN (insn), new_pat, 0))
1012 SET_SRC (old_set) = new_src;
1014 lra_update_insn_recog_data (insn);
1015 /* This can't have an effect on elimination offsets, so skip
1016 right to the end. */
1017 return;
1022 /* Eliminate all eliminable registers occurring in operands that
1023 can be handled by the constraint pass. */
1024 id = lra_get_insn_recog_data (insn);
1025 static_id = id->insn_static_data;
1026 validate_p = false;
1027 for (i = 0; i < static_id->n_operands; i++)
1029 orig_operand[i] = *id->operand_loc[i];
1030 substed_operand[i] = *id->operand_loc[i];
1032 /* For an asm statement, every operand is eliminable. */
1033 if (icode < 0 || insn_data[icode].operand[i].eliminable)
1035 /* Check for setting a hard register that we know about. */
1036 if (static_id->operand[i].type != OP_IN
1037 && REG_P (orig_operand[i]))
1039 /* If we are assigning to a hard register that can be
1040 eliminated, it must be as part of a PARALLEL, since
1041 the code above handles single SETs. This reg can not
1042 be longer eliminated -- it is forced by
1043 mark_not_eliminable. */
1044 for (ep = reg_eliminate;
1045 ep < &reg_eliminate[NUM_ELIMINABLE_REGS];
1046 ep++)
1047 lra_assert (ep->from_rtx != orig_operand[i]
1048 || ! ep->can_eliminate);
1051 /* Companion to the above plus substitution, we can allow
1052 invariants as the source of a plain move. */
1053 substed_operand[i]
1054 = lra_eliminate_regs_1 (insn, *id->operand_loc[i], VOIDmode,
1055 replace_p, ! replace_p && ! first_p,
1056 first_p);
1057 if (substed_operand[i] != orig_operand[i])
1058 validate_p = true;
1062 if (! validate_p)
1063 return;
1065 /* Substitute the operands; the new values are in the substed_operand
1066 array. */
1067 for (i = 0; i < static_id->n_operands; i++)
1068 *id->operand_loc[i] = substed_operand[i];
1069 for (i = 0; i < static_id->n_dups; i++)
1070 *id->dup_loc[i] = substed_operand[(int) static_id->dup_num[i]];
1072 /* If we had a move insn but now we don't, re-recognize it.
1073 This will cause spurious re-recognition if the old move had a
1074 PARALLEL since the new one still will, but we can't call
1075 single_set without having put new body into the insn and the
1076 re-recognition won't hurt in this rare case. */
1077 id = lra_update_insn_recog_data (insn);
1078 static_id = id->insn_static_data;
1081 /* Spill pseudos which are assigned to hard registers in SET. Add
1082 affected insns for processing in the subsequent constraint
1083 pass. */
1084 static void
1085 spill_pseudos (HARD_REG_SET set)
1087 int i;
1088 bitmap_head to_process;
1089 rtx_insn *insn;
1091 if (hard_reg_set_empty_p (set))
1092 return;
1093 if (lra_dump_file != NULL)
1095 fprintf (lra_dump_file, " Spilling non-eliminable hard regs:");
1096 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
1097 if (TEST_HARD_REG_BIT (set, i))
1098 fprintf (lra_dump_file, " %d", i);
1099 fprintf (lra_dump_file, "\n");
1101 bitmap_initialize (&to_process, &reg_obstack);
1102 for (i = FIRST_PSEUDO_REGISTER; i < max_reg_num (); i++)
1103 if (lra_reg_info[i].nrefs != 0 && reg_renumber[i] >= 0
1104 && overlaps_hard_reg_set_p (set,
1105 PSEUDO_REGNO_MODE (i), reg_renumber[i]))
1107 if (lra_dump_file != NULL)
1108 fprintf (lra_dump_file, " Spilling r%d(%d)\n",
1109 i, reg_renumber[i]);
1110 reg_renumber[i] = -1;
1111 bitmap_ior_into (&to_process, &lra_reg_info[i].insn_bitmap);
1113 IOR_HARD_REG_SET (lra_no_alloc_regs, set);
1114 for (insn = get_insns (); insn != NULL_RTX; insn = NEXT_INSN (insn))
1115 if (bitmap_bit_p (&to_process, INSN_UID (insn)))
1117 lra_push_insn (insn);
1118 lra_set_used_insn_alternative (insn, -1);
1120 bitmap_clear (&to_process);
1123 /* Update all offsets and possibility for elimination on eliminable
1124 registers. Spill pseudos assigned to registers which are
1125 uneliminable, update LRA_NO_ALLOC_REGS and ELIMINABLE_REG_SET. Add
1126 insns to INSNS_WITH_CHANGED_OFFSETS containing eliminable hard
1127 registers whose offsets should be changed. Return true if any
1128 elimination offset changed. */
1129 static bool
1130 update_reg_eliminate (bitmap insns_with_changed_offsets)
1132 bool prev, result;
1133 struct lra_elim_table *ep, *ep1;
1134 HARD_REG_SET temp_hard_reg_set;
1136 /* Clear self elimination offsets. */
1137 for (ep = reg_eliminate; ep < &reg_eliminate[NUM_ELIMINABLE_REGS]; ep++)
1138 self_elim_offsets[ep->from] = 0;
1139 for (ep = reg_eliminate; ep < &reg_eliminate[NUM_ELIMINABLE_REGS]; ep++)
1141 /* If it is a currently used elimination: update the previous
1142 offset. */
1143 if (elimination_map[ep->from] == ep)
1144 ep->previous_offset = ep->offset;
1146 prev = ep->prev_can_eliminate;
1147 setup_can_eliminate (ep, targetm.can_eliminate (ep->from, ep->to));
1148 if (ep->can_eliminate && ! prev)
1150 /* It is possible that not eliminable register becomes
1151 eliminable because we took other reasons into account to
1152 set up eliminable regs in the initial set up. Just
1153 ignore new eliminable registers. */
1154 setup_can_eliminate (ep, false);
1155 continue;
1157 if (ep->can_eliminate != prev && elimination_map[ep->from] == ep)
1159 /* We cannot use this elimination anymore -- find another
1160 one. */
1161 if (lra_dump_file != NULL)
1162 fprintf (lra_dump_file,
1163 " Elimination %d to %d is not possible anymore\n",
1164 ep->from, ep->to);
1165 /* If after processing RTL we decides that SP can be used as
1166 a result of elimination, it can not be changed. */
1167 gcc_assert (ep->to_rtx != stack_pointer_rtx);
1168 /* Mark that is not eliminable anymore. */
1169 elimination_map[ep->from] = NULL;
1170 for (ep1 = ep + 1; ep1 < &reg_eliminate[NUM_ELIMINABLE_REGS]; ep1++)
1171 if (ep1->can_eliminate && ep1->from == ep->from)
1172 break;
1173 if (ep1 < &reg_eliminate[NUM_ELIMINABLE_REGS])
1175 if (lra_dump_file != NULL)
1176 fprintf (lra_dump_file, " Using elimination %d to %d now\n",
1177 ep1->from, ep1->to);
1178 lra_assert (ep1->previous_offset == 0);
1179 ep1->previous_offset = ep->offset;
1181 else
1183 /* There is no elimination anymore just use the hard
1184 register `from' itself. Setup self elimination
1185 offset to restore the original offset values. */
1186 if (lra_dump_file != NULL)
1187 fprintf (lra_dump_file, " %d is not eliminable at all\n",
1188 ep->from);
1189 self_elim_offsets[ep->from] = -ep->offset;
1190 if (ep->offset != 0)
1191 bitmap_ior_into (insns_with_changed_offsets,
1192 &lra_reg_info[ep->from].insn_bitmap);
1196 #ifdef ELIMINABLE_REGS
1197 INITIAL_ELIMINATION_OFFSET (ep->from, ep->to, ep->offset);
1198 #else
1199 INITIAL_FRAME_POINTER_OFFSET (ep->offset);
1200 #endif
1202 setup_elimination_map ();
1203 result = false;
1204 CLEAR_HARD_REG_SET (temp_hard_reg_set);
1205 for (ep = reg_eliminate; ep < &reg_eliminate[NUM_ELIMINABLE_REGS]; ep++)
1206 if (elimination_map[ep->from] == NULL)
1207 SET_HARD_REG_BIT (temp_hard_reg_set, ep->from);
1208 else if (elimination_map[ep->from] == ep)
1210 /* Prevent the hard register into which we eliminate from
1211 the usage for pseudos. */
1212 if (ep->from != ep->to)
1213 SET_HARD_REG_BIT (temp_hard_reg_set, ep->to);
1214 if (ep->previous_offset != ep->offset)
1216 bitmap_ior_into (insns_with_changed_offsets,
1217 &lra_reg_info[ep->from].insn_bitmap);
1219 /* Update offset when the eliminate offset have been
1220 changed. */
1221 lra_update_reg_val_offset (lra_reg_info[ep->from].val,
1222 ep->offset - ep->previous_offset);
1223 result = true;
1226 IOR_HARD_REG_SET (lra_no_alloc_regs, temp_hard_reg_set);
1227 AND_COMPL_HARD_REG_SET (eliminable_regset, temp_hard_reg_set);
1228 spill_pseudos (temp_hard_reg_set);
1229 return result;
1232 /* Initialize the table of hard registers to eliminate.
1233 Pre-condition: global flag frame_pointer_needed has been set before
1234 calling this function. */
1235 static void
1236 init_elim_table (void)
1238 struct lra_elim_table *ep;
1239 #ifdef ELIMINABLE_REGS
1240 bool value_p;
1241 const struct elim_table_1 *ep1;
1242 #endif
1244 if (!reg_eliminate)
1245 reg_eliminate = XCNEWVEC (struct lra_elim_table, NUM_ELIMINABLE_REGS);
1247 memset (self_elim_offsets, 0, sizeof (self_elim_offsets));
1248 /* Initiate member values which will be never changed. */
1249 self_elim_table.can_eliminate = self_elim_table.prev_can_eliminate = true;
1250 self_elim_table.previous_offset = 0;
1251 #ifdef ELIMINABLE_REGS
1252 for (ep = reg_eliminate, ep1 = reg_eliminate_1;
1253 ep < &reg_eliminate[NUM_ELIMINABLE_REGS]; ep++, ep1++)
1255 ep->offset = ep->previous_offset = 0;
1256 ep->from = ep1->from;
1257 ep->to = ep1->to;
1258 value_p = (targetm.can_eliminate (ep->from, ep->to)
1259 && ! (ep->to == STACK_POINTER_REGNUM
1260 && frame_pointer_needed
1261 && (! SUPPORTS_STACK_ALIGNMENT
1262 || ! stack_realign_fp)));
1263 setup_can_eliminate (ep, value_p);
1265 #else
1266 reg_eliminate[0].offset = reg_eliminate[0].previous_offset = 0;
1267 reg_eliminate[0].from = reg_eliminate_1[0].from;
1268 reg_eliminate[0].to = reg_eliminate_1[0].to;
1269 setup_can_eliminate (&reg_eliminate[0], ! frame_pointer_needed);
1270 #endif
1272 /* Build the FROM and TO REG rtx's. Note that code in gen_rtx_REG
1273 will cause, e.g., gen_rtx_REG (Pmode, STACK_POINTER_REGNUM) to
1274 equal stack_pointer_rtx. We depend on this. Threfore we switch
1275 off that we are in LRA temporarily. */
1276 lra_in_progress = 0;
1277 for (ep = reg_eliminate; ep < &reg_eliminate[NUM_ELIMINABLE_REGS]; ep++)
1279 ep->from_rtx = gen_rtx_REG (Pmode, ep->from);
1280 ep->to_rtx = gen_rtx_REG (Pmode, ep->to);
1281 eliminable_reg_rtx[ep->from] = ep->from_rtx;
1283 lra_in_progress = 1;
1286 /* Function for initialization of elimination once per function. It
1287 sets up sp offset for each insn. */
1288 static void
1289 init_elimination (void)
1291 bool stop_to_sp_elimination_p;
1292 basic_block bb;
1293 rtx_insn *insn;
1294 struct lra_elim_table *ep;
1296 init_elim_table ();
1297 FOR_EACH_BB_FN (bb, cfun)
1299 curr_sp_change = 0;
1300 stop_to_sp_elimination_p = false;
1301 FOR_BB_INSNS (bb, insn)
1302 if (INSN_P (insn))
1304 lra_get_insn_recog_data (insn)->sp_offset = curr_sp_change;
1305 if (NONDEBUG_INSN_P (insn))
1307 mark_not_eliminable (PATTERN (insn), VOIDmode);
1308 if (curr_sp_change != 0
1309 && find_reg_note (insn, REG_LABEL_OPERAND, NULL_RTX))
1310 stop_to_sp_elimination_p = true;
1313 if (! frame_pointer_needed
1314 && (curr_sp_change != 0 || stop_to_sp_elimination_p)
1315 && bb->succs && bb->succs->length () != 0)
1316 for (ep = reg_eliminate; ep < &reg_eliminate[NUM_ELIMINABLE_REGS]; ep++)
1317 if (ep->to == STACK_POINTER_REGNUM)
1318 setup_can_eliminate (ep, false);
1320 setup_elimination_map ();
1323 /* Eliminate hard reg given by its location LOC. */
1324 void
1325 lra_eliminate_reg_if_possible (rtx *loc)
1327 int regno;
1328 struct lra_elim_table *ep;
1330 lra_assert (REG_P (*loc));
1331 if ((regno = REGNO (*loc)) >= FIRST_PSEUDO_REGISTER
1332 || ! TEST_HARD_REG_BIT (lra_no_alloc_regs, regno))
1333 return;
1334 if ((ep = get_elimination (*loc)) != NULL)
1335 *loc = ep->to_rtx;
1338 /* Do (final if FINAL_P or first if FIRST_P) elimination in INSN. Add
1339 the insn for subsequent processing in the constraint pass, update
1340 the insn info. */
1341 static void
1342 process_insn_for_elimination (rtx_insn *insn, bool final_p, bool first_p)
1344 eliminate_regs_in_insn (insn, final_p, first_p);
1345 if (! final_p)
1347 /* Check that insn changed its code. This is a case when a move
1348 insn becomes an add insn and we do not want to process the
1349 insn as a move anymore. */
1350 int icode = recog (PATTERN (insn), insn, 0);
1352 if (icode >= 0 && icode != INSN_CODE (insn))
1354 INSN_CODE (insn) = icode;
1355 lra_update_insn_recog_data (insn);
1357 lra_update_insn_regno_info (insn);
1358 lra_push_insn (insn);
1359 lra_set_used_insn_alternative (insn, -1);
1363 /* Entry function to do final elimination if FINAL_P or to update
1364 elimination register offsets (FIRST_P if we are doing it the first
1365 time). */
1366 void
1367 lra_eliminate (bool final_p, bool first_p)
1369 unsigned int uid;
1370 bitmap_head insns_with_changed_offsets;
1371 bitmap_iterator bi;
1372 struct lra_elim_table *ep;
1374 gcc_assert (! final_p || ! first_p);
1376 timevar_push (TV_LRA_ELIMINATE);
1378 if (first_p)
1379 init_elimination ();
1381 bitmap_initialize (&insns_with_changed_offsets, &reg_obstack);
1382 if (final_p)
1384 #ifdef ENABLE_CHECKING
1385 update_reg_eliminate (&insns_with_changed_offsets);
1386 if (! bitmap_empty_p (&insns_with_changed_offsets))
1387 gcc_unreachable ();
1388 #endif
1389 /* We change eliminable hard registers in insns so we should do
1390 this for all insns containing any eliminable hard
1391 register. */
1392 for (ep = reg_eliminate; ep < &reg_eliminate[NUM_ELIMINABLE_REGS]; ep++)
1393 if (elimination_map[ep->from] != NULL)
1394 bitmap_ior_into (&insns_with_changed_offsets,
1395 &lra_reg_info[ep->from].insn_bitmap);
1397 else if (! update_reg_eliminate (&insns_with_changed_offsets))
1398 goto lra_eliminate_done;
1399 if (lra_dump_file != NULL)
1401 fprintf (lra_dump_file, "New elimination table:\n");
1402 print_elim_table (lra_dump_file);
1404 EXECUTE_IF_SET_IN_BITMAP (&insns_with_changed_offsets, 0, uid, bi)
1405 /* A dead insn can be deleted in process_insn_for_elimination. */
1406 if (lra_insn_recog_data[uid] != NULL)
1407 process_insn_for_elimination (lra_insn_recog_data[uid]->insn,
1408 final_p, first_p);
1409 bitmap_clear (&insns_with_changed_offsets);
1411 lra_eliminate_done:
1412 timevar_pop (TV_LRA_ELIMINATE);