1 /* Code for RTL register eliminations.
2 Copyright (C) 2010-2015 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
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
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
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
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
56 #include "coretypes.h"
68 #include "rtl-error.h"
71 /* This structure is used to record information about hard register
75 /* Hard register number to be eliminated. */
77 /* Hard register number used as replacement. */
79 /* Difference between values of the two hard registers above on
80 previous iteration. */
81 HOST_WIDE_INT previous_offset
;
82 /* Difference between the values on the current iteration. */
84 /* Nonzero if this elimination can be done. */
86 /* CAN_ELIMINATE since the last check. */
87 bool prev_can_eliminate
;
88 /* REG rtx for the register to be eliminated. We cannot simply
89 compare the number since we might then spuriously replace a hard
90 register corresponding to a pseudo assigned to the reg to be
93 /* REG rtx for the replacement. */
97 /* The elimination table. Each array entry describes one possible way
98 of eliminating a register in favor of another. If there is more
99 than one way of eliminating a particular register, the most
100 preferred should be specified first. */
101 static struct lra_elim_table
*reg_eliminate
= 0;
103 /* This is an intermediate structure to initialize the table. It has
104 exactly the members provided by ELIMINABLE_REGS. */
105 static const struct elim_table_1
109 } reg_eliminate_1
[] =
111 /* If a set of eliminable hard registers was specified, define the
112 table from it. Otherwise, default to the normal case of the frame
113 pointer being replaced by the stack pointer. */
115 #ifdef ELIMINABLE_REGS
118 {{ FRAME_POINTER_REGNUM
, STACK_POINTER_REGNUM
}};
121 #define NUM_ELIMINABLE_REGS ARRAY_SIZE (reg_eliminate_1)
123 /* Print info about elimination table to file F. */
125 print_elim_table (FILE *f
)
127 struct lra_elim_table
*ep
;
129 for (ep
= reg_eliminate
; ep
< ®_eliminate
[NUM_ELIMINABLE_REGS
]; ep
++)
130 fprintf (f
, "%s eliminate %d to %d (offset=" HOST_WIDE_INT_PRINT_DEC
131 ", prev_offset=" HOST_WIDE_INT_PRINT_DEC
")\n",
132 ep
->can_eliminate
? "Can" : "Can't",
133 ep
->from
, ep
->to
, ep
->offset
, ep
->previous_offset
);
136 /* Print info about elimination table to stderr. */
138 lra_debug_elim_table (void)
140 print_elim_table (stderr
);
143 /* Setup possibility of elimination in elimination table element EP to
144 VALUE. Setup FRAME_POINTER_NEEDED if elimination from frame
145 pointer to stack pointer is not possible anymore. */
147 setup_can_eliminate (struct lra_elim_table
*ep
, bool value
)
149 ep
->can_eliminate
= ep
->prev_can_eliminate
= value
;
151 && ep
->from
== FRAME_POINTER_REGNUM
&& ep
->to
== STACK_POINTER_REGNUM
)
152 frame_pointer_needed
= 1;
153 if (!frame_pointer_needed
)
154 REGNO_POINTER_ALIGN (HARD_FRAME_POINTER_REGNUM
) = 0;
157 /* Map: eliminable "from" register -> its current elimination,
158 or NULL if none. The elimination table may contain more than
159 one elimination for the same hard register, but this map specifies
160 the one that we are currently using. */
161 static struct lra_elim_table
*elimination_map
[FIRST_PSEUDO_REGISTER
];
163 /* When an eliminable hard register becomes not eliminable, we use the
164 following special structure to restore original offsets for the
166 static struct lra_elim_table self_elim_table
;
168 /* Offsets should be used to restore original offsets for eliminable
169 hard register which just became not eliminable. Zero,
171 static HOST_WIDE_INT self_elim_offsets
[FIRST_PSEUDO_REGISTER
];
173 /* Map: hard regno -> RTL presentation. RTL presentations of all
174 potentially eliminable hard registers are stored in the map. */
175 static rtx eliminable_reg_rtx
[FIRST_PSEUDO_REGISTER
];
177 /* Set up ELIMINATION_MAP of the currently used eliminations. */
179 setup_elimination_map (void)
182 struct lra_elim_table
*ep
;
184 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
185 elimination_map
[i
] = NULL
;
186 for (ep
= reg_eliminate
; ep
< ®_eliminate
[NUM_ELIMINABLE_REGS
]; ep
++)
187 if (ep
->can_eliminate
&& elimination_map
[ep
->from
] == NULL
)
188 elimination_map
[ep
->from
] = ep
;
193 /* Compute the sum of X and Y, making canonicalizations assumed in an
194 address, namely: sum constant integers, surround the sum of two
195 constants with a CONST, put the constant as the second operand, and
196 group the constant on the outermost sum.
198 This routine assumes both inputs are already in canonical form. */
200 form_sum (rtx x
, rtx y
)
202 machine_mode mode
= GET_MODE (x
);
204 if (mode
== VOIDmode
)
207 if (mode
== VOIDmode
)
211 return plus_constant (mode
, y
, INTVAL (x
));
212 else if (CONST_INT_P (y
))
213 return plus_constant (mode
, x
, INTVAL (y
));
214 else if (CONSTANT_P (x
))
217 if (GET_CODE (x
) == PLUS
&& CONSTANT_P (XEXP (x
, 1)))
218 return form_sum (XEXP (x
, 0), form_sum (XEXP (x
, 1), y
));
220 /* Note that if the operands of Y are specified in the opposite
221 order in the recursive calls below, infinite recursion will
223 if (GET_CODE (y
) == PLUS
&& CONSTANT_P (XEXP (y
, 1)))
224 return form_sum (form_sum (x
, XEXP (y
, 0)), XEXP (y
, 1));
226 /* If both constant, encapsulate sum. Otherwise, just form sum. A
227 constant will have been placed second. */
228 if (CONSTANT_P (x
) && CONSTANT_P (y
))
230 if (GET_CODE (x
) == CONST
)
232 if (GET_CODE (y
) == CONST
)
235 return gen_rtx_CONST (VOIDmode
, gen_rtx_PLUS (mode
, x
, y
));
238 return gen_rtx_PLUS (mode
, x
, y
);
241 /* Return the current substitution hard register of the elimination of
242 HARD_REGNO. If HARD_REGNO is not eliminable, return itself. */
244 lra_get_elimination_hard_regno (int hard_regno
)
246 struct lra_elim_table
*ep
;
248 if (hard_regno
< 0 || hard_regno
>= FIRST_PSEUDO_REGISTER
)
250 if ((ep
= elimination_map
[hard_regno
]) == NULL
)
255 /* Return elimination which will be used for hard reg REG, NULL
257 static struct lra_elim_table
*
258 get_elimination (rtx reg
)
261 struct lra_elim_table
*ep
;
262 HOST_WIDE_INT offset
;
264 lra_assert (REG_P (reg
));
265 if ((hard_regno
= REGNO (reg
)) < 0 || hard_regno
>= FIRST_PSEUDO_REGISTER
)
267 if ((ep
= elimination_map
[hard_regno
]) != NULL
)
268 return ep
->from_rtx
!= reg
? NULL
: ep
;
269 if ((offset
= self_elim_offsets
[hard_regno
]) == 0)
271 /* This is an iteration to restore offsets just after HARD_REGNO
272 stopped to be eliminable. */
273 self_elim_table
.from
= self_elim_table
.to
= hard_regno
;
274 self_elim_table
.from_rtx
275 = self_elim_table
.to_rtx
276 = eliminable_reg_rtx
[hard_regno
];
277 lra_assert (self_elim_table
.from_rtx
!= NULL
);
278 self_elim_table
.offset
= offset
;
279 return &self_elim_table
;
282 /* Scan X and replace any eliminable registers (such as fp) with a
283 replacement (such as sp) if SUBST_P, plus an offset. The offset is
284 a change in the offset between the eliminable register and its
285 substitution if UPDATE_P, or the full offset if FULL_P, or
286 otherwise zero. If FULL_P, we also use the SP offsets for
287 elimination to SP. If UPDATE_P, use UPDATE_SP_OFFSET for updating
288 offsets of register elimnable to SP. If UPDATE_SP_OFFSET is
289 non-zero, don't use difference of the offset and the previous
292 MEM_MODE is the mode of an enclosing MEM. We need this to know how
293 much to adjust a register for, e.g., PRE_DEC. Also, if we are
294 inside a MEM, we are allowed to replace a sum of a hard register
295 and the constant zero with the hard register, which we cannot do
296 outside a MEM. In addition, we need to record the fact that a
297 hard register is referenced outside a MEM.
299 If we make full substitution to SP for non-null INSN, add the insn
302 lra_eliminate_regs_1 (rtx_insn
*insn
, rtx x
, machine_mode mem_mode
,
303 bool subst_p
, bool update_p
,
304 HOST_WIDE_INT update_sp_offset
, bool full_p
)
306 enum rtx_code code
= GET_CODE (x
);
307 struct lra_elim_table
*ep
;
313 lra_assert (!update_p
|| !full_p
);
314 lra_assert (update_sp_offset
== 0 || (!subst_p
&& update_p
&& !full_p
));
315 if (! current_function_decl
)
333 /* First handle the case where we encounter a bare hard register
334 that is eliminable. Replace it with a PLUS. */
335 if ((ep
= get_elimination (x
)) != NULL
)
337 rtx to
= subst_p
? ep
->to_rtx
: ep
->from_rtx
;
339 if (update_sp_offset
!= 0)
341 if (ep
->to_rtx
== stack_pointer_rtx
)
342 return plus_constant (Pmode
, to
, update_sp_offset
);
346 return plus_constant (Pmode
, to
, ep
->offset
- ep
->previous_offset
);
348 return plus_constant (Pmode
, to
,
351 && ep
->to_rtx
== stack_pointer_rtx
352 ? lra_get_insn_recog_data (insn
)->sp_offset
360 /* If this is the sum of an eliminable register and a constant, rework
362 if (REG_P (XEXP (x
, 0)) && CONSTANT_P (XEXP (x
, 1)))
364 if ((ep
= get_elimination (XEXP (x
, 0))) != NULL
)
366 HOST_WIDE_INT offset
;
367 rtx to
= subst_p
? ep
->to_rtx
: ep
->from_rtx
;
369 if (! update_p
&& ! full_p
)
370 return gen_rtx_PLUS (Pmode
, to
, XEXP (x
, 1));
372 if (update_sp_offset
!= 0)
373 offset
= ep
->to_rtx
== stack_pointer_rtx
? update_sp_offset
: 0;
376 ? ep
->offset
- ep
->previous_offset
: ep
->offset
);
377 if (full_p
&& insn
!= NULL_RTX
&& ep
->to_rtx
== stack_pointer_rtx
)
378 offset
-= lra_get_insn_recog_data (insn
)->sp_offset
;
379 if (CONST_INT_P (XEXP (x
, 1)) && INTVAL (XEXP (x
, 1)) == -offset
)
382 return gen_rtx_PLUS (Pmode
, to
,
383 plus_constant (Pmode
,
384 XEXP (x
, 1), offset
));
387 /* If the hard register is not eliminable, we are done since
388 the other operand is a constant. */
392 /* If this is part of an address, we want to bring any constant
393 to the outermost PLUS. We will do this by doing hard
394 register replacement in our operands and seeing if a constant
395 shows up in one of them.
397 Note that there is no risk of modifying the structure of the
398 insn, since we only get called for its operands, thus we are
399 either modifying the address inside a MEM, or something like
400 an address operand of a load-address insn. */
403 rtx new0
= lra_eliminate_regs_1 (insn
, XEXP (x
, 0), mem_mode
,
405 update_sp_offset
, full_p
);
406 rtx new1
= lra_eliminate_regs_1 (insn
, XEXP (x
, 1), mem_mode
,
408 update_sp_offset
, full_p
);
410 if (new0
!= XEXP (x
, 0) || new1
!= XEXP (x
, 1))
411 return form_sum (new0
, new1
);
416 /* If this is the product of an eliminable hard register and a
417 constant, apply the distribute law and move the constant out
418 so that we have (plus (mult ..) ..). This is needed in order
419 to keep load-address insns valid. This case is pathological.
420 We ignore the possibility of overflow here. */
421 if (REG_P (XEXP (x
, 0)) && CONST_INT_P (XEXP (x
, 1))
422 && (ep
= get_elimination (XEXP (x
, 0))) != NULL
)
424 rtx to
= subst_p
? ep
->to_rtx
: ep
->from_rtx
;
426 if (update_sp_offset
!= 0)
428 if (ep
->to_rtx
== stack_pointer_rtx
)
429 return plus_constant (Pmode
,
430 gen_rtx_MULT (Pmode
, to
, XEXP (x
, 1)),
431 update_sp_offset
* INTVAL (XEXP (x
, 1)));
432 return gen_rtx_MULT (Pmode
, to
, XEXP (x
, 1));
435 return plus_constant (Pmode
,
436 gen_rtx_MULT (Pmode
, to
, XEXP (x
, 1)),
437 (ep
->offset
- ep
->previous_offset
)
438 * INTVAL (XEXP (x
, 1)));
441 HOST_WIDE_INT offset
= ep
->offset
;
443 if (insn
!= NULL_RTX
&& ep
->to_rtx
== stack_pointer_rtx
)
444 offset
-= lra_get_insn_recog_data (insn
)->sp_offset
;
446 plus_constant (Pmode
,
447 gen_rtx_MULT (Pmode
, to
, XEXP (x
, 1)),
448 offset
* INTVAL (XEXP (x
, 1)));
451 return gen_rtx_MULT (Pmode
, to
, XEXP (x
, 1));
454 /* ... fall through ... */
458 /* See comments before PLUS about handling MINUS. */
462 case AND
: case IOR
: case XOR
:
463 case ROTATERT
: case ROTATE
:
464 case ASHIFTRT
: case LSHIFTRT
: case ASHIFT
:
466 case GE
: case GT
: case GEU
: case GTU
:
467 case LE
: case LT
: case LEU
: case LTU
:
469 rtx new0
= lra_eliminate_regs_1 (insn
, XEXP (x
, 0), mem_mode
,
471 update_sp_offset
, full_p
);
472 rtx new1
= XEXP (x
, 1)
473 ? lra_eliminate_regs_1 (insn
, XEXP (x
, 1), mem_mode
,
475 update_sp_offset
, full_p
) : 0;
477 if (new0
!= XEXP (x
, 0) || new1
!= XEXP (x
, 1))
478 return gen_rtx_fmt_ee (code
, GET_MODE (x
), new0
, new1
);
483 /* If we have something in XEXP (x, 0), the usual case,
487 new_rtx
= lra_eliminate_regs_1 (insn
, XEXP (x
, 0), mem_mode
,
489 update_sp_offset
, full_p
);
490 if (new_rtx
!= XEXP (x
, 0))
492 /* If this is a REG_DEAD note, it is not valid anymore.
493 Using the eliminated version could result in creating a
494 REG_DEAD note for the stack or frame pointer. */
495 if (REG_NOTE_KIND (x
) == REG_DEAD
)
497 ? lra_eliminate_regs_1 (insn
, XEXP (x
, 1), mem_mode
,
499 update_sp_offset
, full_p
)
502 x
= alloc_reg_note (REG_NOTE_KIND (x
), new_rtx
, XEXP (x
, 1));
506 /* ... fall through ... */
510 /* Now do eliminations in the rest of the chain. If this was
511 an EXPR_LIST, this might result in allocating more memory than is
512 strictly needed, but it simplifies the code. */
515 new_rtx
= lra_eliminate_regs_1 (insn
, XEXP (x
, 1), mem_mode
,
517 update_sp_offset
, full_p
);
518 if (new_rtx
!= XEXP (x
, 1))
520 gen_rtx_fmt_ee (GET_CODE (x
), GET_MODE (x
),
521 XEXP (x
, 0), new_rtx
);
529 /* We do not support elimination of a register that is modified.
530 elimination_effects has already make sure that this does not
536 /* We do not support elimination of a hard register that is
537 modified. LRA has already make sure that this does not
538 happen. The only remaining case we need to consider here is
539 that the increment value may be an eliminable register. */
540 if (GET_CODE (XEXP (x
, 1)) == PLUS
541 && XEXP (XEXP (x
, 1), 0) == XEXP (x
, 0))
543 rtx new_rtx
= lra_eliminate_regs_1 (insn
, XEXP (XEXP (x
, 1), 1),
544 mem_mode
, subst_p
, update_p
,
545 update_sp_offset
, full_p
);
547 if (new_rtx
!= XEXP (XEXP (x
, 1), 1))
548 return gen_rtx_fmt_ee (code
, GET_MODE (x
), XEXP (x
, 0),
549 gen_rtx_PLUS (GET_MODE (x
),
550 XEXP (x
, 0), new_rtx
));
554 case STRICT_LOW_PART
:
556 case SIGN_EXTEND
: case ZERO_EXTEND
:
557 case TRUNCATE
: case FLOAT_EXTEND
: case FLOAT_TRUNCATE
:
558 case FLOAT
: case FIX
:
559 case UNSIGNED_FIX
: case UNSIGNED_FLOAT
:
568 new_rtx
= lra_eliminate_regs_1 (insn
, XEXP (x
, 0), mem_mode
,
570 update_sp_offset
, full_p
);
571 if (new_rtx
!= XEXP (x
, 0))
572 return gen_rtx_fmt_e (code
, GET_MODE (x
), new_rtx
);
576 new_rtx
= lra_eliminate_regs_1 (insn
, SUBREG_REG (x
), mem_mode
,
578 update_sp_offset
, full_p
);
580 if (new_rtx
!= SUBREG_REG (x
))
582 int x_size
= GET_MODE_SIZE (GET_MODE (x
));
583 int new_size
= GET_MODE_SIZE (GET_MODE (new_rtx
));
585 if (MEM_P (new_rtx
) && x_size
<= new_size
)
587 SUBREG_REG (x
) = new_rtx
;
588 alter_subreg (&x
, false);
593 /* LRA can transform subregs itself. So don't call
594 simplify_gen_subreg until LRA transformations are
595 finished. Function simplify_gen_subreg can do
596 non-trivial transformations (like truncation) which
597 might make LRA work to fail. */
598 SUBREG_REG (x
) = new_rtx
;
602 return simplify_gen_subreg (GET_MODE (x
), new_rtx
,
603 GET_MODE (new_rtx
), SUBREG_BYTE (x
));
609 /* Our only special processing is to pass the mode of the MEM to our
610 recursive call and copy the flags. While we are here, handle this
611 case more efficiently. */
613 replace_equiv_address_nv
615 lra_eliminate_regs_1 (insn
, XEXP (x
, 0), GET_MODE (x
),
616 subst_p
, update_p
, update_sp_offset
, full_p
));
619 /* Handle insn_list USE that a call to a pure function may generate. */
620 new_rtx
= lra_eliminate_regs_1 (insn
, XEXP (x
, 0), VOIDmode
,
621 subst_p
, update_p
, update_sp_offset
, full_p
);
622 if (new_rtx
!= XEXP (x
, 0))
623 return gen_rtx_USE (GET_MODE (x
), new_rtx
);
634 /* Process each of our operands recursively. If any have changed, make a
636 fmt
= GET_RTX_FORMAT (code
);
637 for (i
= 0; i
< GET_RTX_LENGTH (code
); i
++, fmt
++)
641 new_rtx
= lra_eliminate_regs_1 (insn
, XEXP (x
, i
), mem_mode
,
643 update_sp_offset
, full_p
);
644 if (new_rtx
!= XEXP (x
, i
) && ! copied
)
646 x
= shallow_copy_rtx (x
);
649 XEXP (x
, i
) = new_rtx
;
651 else if (*fmt
== 'E')
654 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
656 new_rtx
= lra_eliminate_regs_1 (insn
, XVECEXP (x
, i
, j
), mem_mode
,
658 update_sp_offset
, full_p
);
659 if (new_rtx
!= XVECEXP (x
, i
, j
) && ! copied_vec
)
661 rtvec new_v
= gen_rtvec_v (XVECLEN (x
, i
),
665 x
= shallow_copy_rtx (x
);
671 XVECEXP (x
, i
, j
) = new_rtx
;
679 /* This function is used externally in subsequent passes of GCC. It
680 always does a full elimination of X. */
682 lra_eliminate_regs (rtx x
, machine_mode mem_mode
,
683 rtx insn ATTRIBUTE_UNUSED
)
685 return lra_eliminate_regs_1 (NULL
, x
, mem_mode
, true, false, 0, true);
688 /* Stack pointer offset before the current insn relative to one at the
689 func start. RTL insns can change SP explicitly. We keep the
690 changes from one insn to another through this variable. */
691 static HOST_WIDE_INT curr_sp_change
;
693 /* Scan rtx X for references to elimination source or target registers
694 in contexts that would prevent the elimination from happening.
695 Update the table of eliminables to reflect the changed state.
696 MEM_MODE is the mode of an enclosing MEM rtx, or VOIDmode if not
699 mark_not_eliminable (rtx x
, machine_mode mem_mode
)
701 enum rtx_code code
= GET_CODE (x
);
702 struct lra_elim_table
*ep
;
714 if (XEXP (x
, 0) == stack_pointer_rtx
715 && ((code
!= PRE_MODIFY
&& code
!= POST_MODIFY
)
716 || (GET_CODE (XEXP (x
, 1)) == PLUS
717 && XEXP (x
, 0) == XEXP (XEXP (x
, 1), 0)
718 && CONST_INT_P (XEXP (XEXP (x
, 1), 1)))))
720 int size
= GET_MODE_SIZE (mem_mode
);
723 /* If more bytes than MEM_MODE are pushed, account for
725 size
= PUSH_ROUNDING (size
);
727 if (code
== PRE_DEC
|| code
== POST_DEC
)
728 curr_sp_change
-= size
;
729 else if (code
== PRE_INC
|| code
== POST_INC
)
730 curr_sp_change
+= size
;
731 else if (code
== PRE_MODIFY
|| code
== POST_MODIFY
)
732 curr_sp_change
+= INTVAL (XEXP (XEXP (x
, 1), 1));
734 else if (REG_P (XEXP (x
, 0))
735 && REGNO (XEXP (x
, 0)) >= FIRST_PSEUDO_REGISTER
)
737 /* If we modify the source of an elimination rule, disable
738 it. Do the same if it is the destination and not the
739 hard frame register. */
740 for (ep
= reg_eliminate
;
741 ep
< ®_eliminate
[NUM_ELIMINABLE_REGS
];
743 if (ep
->from_rtx
== XEXP (x
, 0)
744 || (ep
->to_rtx
== XEXP (x
, 0)
745 && ep
->to_rtx
!= hard_frame_pointer_rtx
))
746 setup_can_eliminate (ep
, false);
751 if (REG_P (XEXP (x
, 0)) && REGNO (XEXP (x
, 0)) < FIRST_PSEUDO_REGISTER
)
752 /* If using a hard register that is the source of an eliminate
753 we still think can be performed, note it cannot be
754 performed since we don't know how this hard register is
756 for (ep
= reg_eliminate
;
757 ep
< ®_eliminate
[NUM_ELIMINABLE_REGS
];
759 if (ep
->from_rtx
== XEXP (x
, 0)
760 && ep
->to_rtx
!= hard_frame_pointer_rtx
)
761 setup_can_eliminate (ep
, false);
765 if (REG_P (XEXP (x
, 0)) && REGNO (XEXP (x
, 0)) < FIRST_PSEUDO_REGISTER
)
766 /* If clobbering a hard register that is the replacement
767 register for an elimination we still think can be
768 performed, note that it cannot be performed. Otherwise, we
769 need not be concerned about it. */
770 for (ep
= reg_eliminate
;
771 ep
< ®_eliminate
[NUM_ELIMINABLE_REGS
];
773 if (ep
->to_rtx
== XEXP (x
, 0)
774 && ep
->to_rtx
!= hard_frame_pointer_rtx
)
775 setup_can_eliminate (ep
, false);
779 if (SET_DEST (x
) == stack_pointer_rtx
780 && GET_CODE (SET_SRC (x
)) == PLUS
781 && XEXP (SET_SRC (x
), 0) == SET_DEST (x
)
782 && CONST_INT_P (XEXP (SET_SRC (x
), 1)))
784 curr_sp_change
+= INTVAL (XEXP (SET_SRC (x
), 1));
787 if (! REG_P (SET_DEST (x
))
788 || REGNO (SET_DEST (x
)) >= FIRST_PSEUDO_REGISTER
)
789 mark_not_eliminable (SET_DEST (x
), mem_mode
);
792 /* See if this is setting the replacement hard register for
795 If DEST is the hard frame pointer, we do nothing because
796 we assume that all assignments to the frame pointer are
797 for non-local gotos and are being done at a time when
798 they are valid and do not disturb anything else. Some
799 machines want to eliminate a fake argument pointer (or
800 even a fake frame pointer) with either the real frame
801 pointer or the stack pointer. Assignments to the hard
802 frame pointer must not prevent this elimination. */
803 for (ep
= reg_eliminate
;
804 ep
< ®_eliminate
[NUM_ELIMINABLE_REGS
];
806 if (ep
->to_rtx
== SET_DEST (x
)
807 && SET_DEST (x
) != hard_frame_pointer_rtx
)
808 setup_can_eliminate (ep
, false);
811 mark_not_eliminable (SET_SRC (x
), mem_mode
);
815 /* Our only special processing is to pass the mode of the MEM to
816 our recursive call. */
817 mark_not_eliminable (XEXP (x
, 0), GET_MODE (x
));
824 fmt
= GET_RTX_FORMAT (code
);
825 for (i
= 0; i
< GET_RTX_LENGTH (code
); i
++, fmt
++)
828 mark_not_eliminable (XEXP (x
, i
), mem_mode
);
829 else if (*fmt
== 'E')
830 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
831 mark_not_eliminable (XVECEXP (x
, i
, j
), mem_mode
);
837 #ifdef HARD_FRAME_POINTER_REGNUM
839 /* Find offset equivalence note for reg WHAT in INSN and return the
840 found elmination offset. If the note is not found, return NULL.
841 Remove the found note. */
843 remove_reg_equal_offset_note (rtx_insn
*insn
, rtx what
)
847 for (link_loc
= ®_NOTES (insn
);
848 (link
= *link_loc
) != NULL_RTX
;
849 link_loc
= &XEXP (link
, 1))
850 if (REG_NOTE_KIND (link
) == REG_EQUAL
851 && GET_CODE (XEXP (link
, 0)) == PLUS
852 && XEXP (XEXP (link
, 0), 0) == what
853 && CONST_INT_P (XEXP (XEXP (link
, 0), 1)))
855 *link_loc
= XEXP (link
, 1);
856 return XEXP (XEXP (link
, 0), 1);
863 /* Scan INSN and eliminate all eliminable hard registers in it.
865 If REPLACE_P is true, do the replacement destructively. Also
866 delete the insn as dead it if it is setting an eliminable register.
868 If REPLACE_P is false, just update the offsets while keeping the
869 base register the same. If FIRST_P, use the sp offset for
870 elimination to sp. Otherwise, use UPDATE_SP_OFFSET for this. If
871 UPDATE_SP_OFFSET is non-zero, don't use difference of the offset
872 and the previous offset. Attach the note about used elimination
873 for insns setting frame pointer to update elimination easy (without
874 parsing already generated elimination insns to find offset
875 previously used) in future. */
878 eliminate_regs_in_insn (rtx_insn
*insn
, bool replace_p
, bool first_p
,
879 HOST_WIDE_INT update_sp_offset
)
881 int icode
= recog_memoized (insn
);
882 rtx old_set
= single_set (insn
);
885 rtx substed_operand
[MAX_RECOG_OPERANDS
];
886 rtx orig_operand
[MAX_RECOG_OPERANDS
];
887 struct lra_elim_table
*ep
;
888 rtx plus_src
, plus_cst_src
;
889 lra_insn_recog_data_t id
;
890 struct lra_static_insn_data
*static_id
;
892 if (icode
< 0 && asm_noperands (PATTERN (insn
)) < 0 && ! DEBUG_INSN_P (insn
))
894 lra_assert (GET_CODE (PATTERN (insn
)) == USE
895 || GET_CODE (PATTERN (insn
)) == CLOBBER
896 || GET_CODE (PATTERN (insn
)) == ASM_INPUT
);
900 /* Check for setting an eliminable register. */
901 if (old_set
!= 0 && REG_P (SET_DEST (old_set
))
902 && (ep
= get_elimination (SET_DEST (old_set
))) != NULL
)
904 for (ep
= reg_eliminate
; ep
< ®_eliminate
[NUM_ELIMINABLE_REGS
]; ep
++)
905 if (ep
->from_rtx
== SET_DEST (old_set
) && ep
->can_eliminate
)
907 bool delete_p
= replace_p
;
909 #ifdef HARD_FRAME_POINTER_REGNUM
910 if (ep
->from
== FRAME_POINTER_REGNUM
911 && ep
->to
== HARD_FRAME_POINTER_REGNUM
)
912 /* If this is setting the frame pointer register to the
913 hardware frame pointer register and this is an
914 elimination that will be done (tested above), this
915 insn is really adjusting the frame pointer downward
916 to compensate for the adjustment done before a
919 rtx src
= SET_SRC (old_set
);
920 rtx off
= remove_reg_equal_offset_note (insn
, ep
->to_rtx
);
922 /* We should never process such insn with non-zero
924 lra_assert (update_sp_offset
== 0);
928 || (GET_CODE (src
) == PLUS
929 && XEXP (src
, 0) == ep
->to_rtx
930 && CONST_INT_P (XEXP (src
, 1))))
932 HOST_WIDE_INT offset
;
936 SET_DEST (old_set
) = ep
->to_rtx
;
937 lra_update_insn_recog_data (insn
);
940 offset
= (off
!= NULL_RTX
? INTVAL (off
)
941 : src
== ep
->to_rtx
? 0 : INTVAL (XEXP (src
, 1)));
942 offset
-= (ep
->offset
- ep
->previous_offset
);
943 src
= plus_constant (Pmode
, ep
->to_rtx
, offset
);
945 /* First see if this insn remains valid when we
946 make the change. If not, keep the INSN_CODE
947 the same and let the constraint pass fit it
949 validate_change (insn
, &SET_SRC (old_set
), src
, 1);
950 validate_change (insn
, &SET_DEST (old_set
),
952 if (! apply_change_group ())
954 SET_SRC (old_set
) = src
;
955 SET_DEST (old_set
) = ep
->from_rtx
;
957 lra_update_insn_recog_data (insn
);
958 /* Add offset note for future updates. */
959 add_reg_note (insn
, REG_EQUAL
, src
);
965 /* This insn isn't serving a useful purpose. We delete it
966 when REPLACE is set. */
968 lra_delete_dead_insn (insn
);
973 /* We allow one special case which happens to work on all machines we
974 currently support: a single set with the source or a REG_EQUAL
975 note being a PLUS of an eliminable register and a constant. */
976 plus_src
= plus_cst_src
= 0;
977 if (old_set
&& REG_P (SET_DEST (old_set
)))
979 if (GET_CODE (SET_SRC (old_set
)) == PLUS
)
980 plus_src
= SET_SRC (old_set
);
981 /* First see if the source is of the form (plus (...) CST). */
983 && CONST_INT_P (XEXP (plus_src
, 1)))
984 plus_cst_src
= plus_src
;
985 /* Check that the first operand of the PLUS is a hard reg or
986 the lowpart subreg of one. */
989 rtx reg
= XEXP (plus_cst_src
, 0);
991 if (GET_CODE (reg
) == SUBREG
&& subreg_lowpart_p (reg
))
992 reg
= SUBREG_REG (reg
);
994 if (!REG_P (reg
) || REGNO (reg
) >= FIRST_PSEUDO_REGISTER
)
1000 rtx reg
= XEXP (plus_cst_src
, 0);
1001 HOST_WIDE_INT offset
= INTVAL (XEXP (plus_cst_src
, 1));
1003 if (GET_CODE (reg
) == SUBREG
)
1004 reg
= SUBREG_REG (reg
);
1006 if (REG_P (reg
) && (ep
= get_elimination (reg
)) != NULL
)
1008 rtx to_rtx
= replace_p
? ep
->to_rtx
: ep
->from_rtx
;
1012 if (update_sp_offset
== 0)
1013 offset
+= (ep
->offset
- ep
->previous_offset
);
1014 if (ep
->to_rtx
== stack_pointer_rtx
)
1017 offset
-= lra_get_insn_recog_data (insn
)->sp_offset
;
1019 offset
+= update_sp_offset
;
1021 offset
= trunc_int_for_mode (offset
, GET_MODE (plus_cst_src
));
1024 if (GET_CODE (XEXP (plus_cst_src
, 0)) == SUBREG
)
1025 to_rtx
= gen_lowpart (GET_MODE (XEXP (plus_cst_src
, 0)), to_rtx
);
1026 /* If we have a nonzero offset, and the source is already a
1027 simple REG, the following transformation would increase
1028 the cost of the insn by replacing a simple REG with (plus
1029 (reg sp) CST). So try only when we already had a PLUS
1031 if (offset
== 0 || plus_src
)
1033 rtx new_src
= plus_constant (GET_MODE (to_rtx
), to_rtx
, offset
);
1035 old_set
= single_set (insn
);
1037 /* First see if this insn remains valid when we make the
1038 change. If not, try to replace the whole pattern
1039 with a simple set (this may help if the original insn
1040 was a PARALLEL that was only recognized as single_set
1041 due to REG_UNUSED notes). If this isn't valid
1042 either, keep the INSN_CODE the same and let the
1043 constraint pass fix it up. */
1044 if (! validate_change (insn
, &SET_SRC (old_set
), new_src
, 0))
1046 rtx new_pat
= gen_rtx_SET (SET_DEST (old_set
), new_src
);
1048 if (! validate_change (insn
, &PATTERN (insn
), new_pat
, 0))
1049 SET_SRC (old_set
) = new_src
;
1051 lra_update_insn_recog_data (insn
);
1052 /* This can't have an effect on elimination offsets, so skip
1053 right to the end. */
1059 /* Eliminate all eliminable registers occurring in operands that
1060 can be handled by the constraint pass. */
1061 id
= lra_get_insn_recog_data (insn
);
1062 static_id
= id
->insn_static_data
;
1064 for (i
= 0; i
< static_id
->n_operands
; i
++)
1066 orig_operand
[i
] = *id
->operand_loc
[i
];
1067 substed_operand
[i
] = *id
->operand_loc
[i
];
1069 /* For an asm statement, every operand is eliminable. */
1070 if (icode
< 0 || insn_data
[icode
].operand
[i
].eliminable
)
1072 /* Check for setting a hard register that we know about. */
1073 if (static_id
->operand
[i
].type
!= OP_IN
1074 && REG_P (orig_operand
[i
]))
1076 /* If we are assigning to a hard register that can be
1077 eliminated, it must be as part of a PARALLEL, since
1078 the code above handles single SETs. This reg can not
1079 be longer eliminated -- it is forced by
1080 mark_not_eliminable. */
1081 for (ep
= reg_eliminate
;
1082 ep
< ®_eliminate
[NUM_ELIMINABLE_REGS
];
1084 lra_assert (ep
->from_rtx
!= orig_operand
[i
]
1085 || ! ep
->can_eliminate
);
1088 /* Companion to the above plus substitution, we can allow
1089 invariants as the source of a plain move. */
1091 = lra_eliminate_regs_1 (insn
, *id
->operand_loc
[i
], VOIDmode
,
1092 replace_p
, ! replace_p
&& ! first_p
,
1093 update_sp_offset
, first_p
);
1094 if (substed_operand
[i
] != orig_operand
[i
])
1102 /* Substitute the operands; the new values are in the substed_operand
1104 for (i
= 0; i
< static_id
->n_operands
; i
++)
1105 *id
->operand_loc
[i
] = substed_operand
[i
];
1106 for (i
= 0; i
< static_id
->n_dups
; i
++)
1107 *id
->dup_loc
[i
] = substed_operand
[(int) static_id
->dup_num
[i
]];
1109 /* If we had a move insn but now we don't, re-recognize it.
1110 This will cause spurious re-recognition if the old move had a
1111 PARALLEL since the new one still will, but we can't call
1112 single_set without having put new body into the insn and the
1113 re-recognition won't hurt in this rare case. */
1114 id
= lra_update_insn_recog_data (insn
);
1115 static_id
= id
->insn_static_data
;
1118 /* Spill pseudos which are assigned to hard registers in SET. Add
1119 affected insns for processing in the subsequent constraint
1122 spill_pseudos (HARD_REG_SET set
)
1125 bitmap_head to_process
;
1128 if (hard_reg_set_empty_p (set
))
1130 if (lra_dump_file
!= NULL
)
1132 fprintf (lra_dump_file
, " Spilling non-eliminable hard regs:");
1133 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
1134 if (TEST_HARD_REG_BIT (set
, i
))
1135 fprintf (lra_dump_file
, " %d", i
);
1136 fprintf (lra_dump_file
, "\n");
1138 bitmap_initialize (&to_process
, ®_obstack
);
1139 for (i
= FIRST_PSEUDO_REGISTER
; i
< max_reg_num (); i
++)
1140 if (lra_reg_info
[i
].nrefs
!= 0 && reg_renumber
[i
] >= 0
1141 && overlaps_hard_reg_set_p (set
,
1142 PSEUDO_REGNO_MODE (i
), reg_renumber
[i
]))
1144 if (lra_dump_file
!= NULL
)
1145 fprintf (lra_dump_file
, " Spilling r%d(%d)\n",
1146 i
, reg_renumber
[i
]);
1147 reg_renumber
[i
] = -1;
1148 bitmap_ior_into (&to_process
, &lra_reg_info
[i
].insn_bitmap
);
1150 IOR_HARD_REG_SET (lra_no_alloc_regs
, set
);
1151 for (insn
= get_insns (); insn
!= NULL_RTX
; insn
= NEXT_INSN (insn
))
1152 if (bitmap_bit_p (&to_process
, INSN_UID (insn
)))
1154 lra_push_insn (insn
);
1155 lra_set_used_insn_alternative (insn
, -1);
1157 bitmap_clear (&to_process
);
1160 /* Update all offsets and possibility for elimination on eliminable
1161 registers. Spill pseudos assigned to registers which are
1162 uneliminable, update LRA_NO_ALLOC_REGS and ELIMINABLE_REG_SET. Add
1163 insns to INSNS_WITH_CHANGED_OFFSETS containing eliminable hard
1164 registers whose offsets should be changed. Return true if any
1165 elimination offset changed. */
1167 update_reg_eliminate (bitmap insns_with_changed_offsets
)
1170 struct lra_elim_table
*ep
, *ep1
;
1171 HARD_REG_SET temp_hard_reg_set
;
1173 /* Clear self elimination offsets. */
1174 for (ep
= reg_eliminate
; ep
< ®_eliminate
[NUM_ELIMINABLE_REGS
]; ep
++)
1175 self_elim_offsets
[ep
->from
] = 0;
1176 for (ep
= reg_eliminate
; ep
< ®_eliminate
[NUM_ELIMINABLE_REGS
]; ep
++)
1178 /* If it is a currently used elimination: update the previous
1180 if (elimination_map
[ep
->from
] == ep
)
1181 ep
->previous_offset
= ep
->offset
;
1183 prev
= ep
->prev_can_eliminate
;
1184 setup_can_eliminate (ep
, targetm
.can_eliminate (ep
->from
, ep
->to
));
1185 if (ep
->can_eliminate
&& ! prev
)
1187 /* It is possible that not eliminable register becomes
1188 eliminable because we took other reasons into account to
1189 set up eliminable regs in the initial set up. Just
1190 ignore new eliminable registers. */
1191 setup_can_eliminate (ep
, false);
1194 if (ep
->can_eliminate
!= prev
&& elimination_map
[ep
->from
] == ep
)
1196 /* We cannot use this elimination anymore -- find another
1198 if (lra_dump_file
!= NULL
)
1199 fprintf (lra_dump_file
,
1200 " Elimination %d to %d is not possible anymore\n",
1202 /* If after processing RTL we decides that SP can be used as
1203 a result of elimination, it can not be changed. */
1204 gcc_assert ((ep
->to_rtx
!= stack_pointer_rtx
)
1205 || (ep
->from
< FIRST_PSEUDO_REGISTER
1206 && fixed_regs
[ep
->from
]));
1207 /* Mark that is not eliminable anymore. */
1208 elimination_map
[ep
->from
] = NULL
;
1209 for (ep1
= ep
+ 1; ep1
< ®_eliminate
[NUM_ELIMINABLE_REGS
]; ep1
++)
1210 if (ep1
->can_eliminate
&& ep1
->from
== ep
->from
)
1212 if (ep1
< ®_eliminate
[NUM_ELIMINABLE_REGS
])
1214 if (lra_dump_file
!= NULL
)
1215 fprintf (lra_dump_file
, " Using elimination %d to %d now\n",
1216 ep1
->from
, ep1
->to
);
1217 lra_assert (ep1
->previous_offset
== 0);
1218 ep1
->previous_offset
= ep
->offset
;
1222 /* There is no elimination anymore just use the hard
1223 register `from' itself. Setup self elimination
1224 offset to restore the original offset values. */
1225 if (lra_dump_file
!= NULL
)
1226 fprintf (lra_dump_file
, " %d is not eliminable at all\n",
1228 self_elim_offsets
[ep
->from
] = -ep
->offset
;
1229 if (ep
->offset
!= 0)
1230 bitmap_ior_into (insns_with_changed_offsets
,
1231 &lra_reg_info
[ep
->from
].insn_bitmap
);
1235 #ifdef ELIMINABLE_REGS
1236 INITIAL_ELIMINATION_OFFSET (ep
->from
, ep
->to
, ep
->offset
);
1238 INITIAL_FRAME_POINTER_OFFSET (ep
->offset
);
1241 setup_elimination_map ();
1243 CLEAR_HARD_REG_SET (temp_hard_reg_set
);
1244 for (ep
= reg_eliminate
; ep
< ®_eliminate
[NUM_ELIMINABLE_REGS
]; ep
++)
1245 if (elimination_map
[ep
->from
] == NULL
)
1246 SET_HARD_REG_BIT (temp_hard_reg_set
, ep
->from
);
1247 else if (elimination_map
[ep
->from
] == ep
)
1249 /* Prevent the hard register into which we eliminate from
1250 the usage for pseudos. */
1251 if (ep
->from
!= ep
->to
)
1252 SET_HARD_REG_BIT (temp_hard_reg_set
, ep
->to
);
1253 if (ep
->previous_offset
!= ep
->offset
)
1255 bitmap_ior_into (insns_with_changed_offsets
,
1256 &lra_reg_info
[ep
->from
].insn_bitmap
);
1258 /* Update offset when the eliminate offset have been
1260 lra_update_reg_val_offset (lra_reg_info
[ep
->from
].val
,
1261 ep
->offset
- ep
->previous_offset
);
1265 IOR_HARD_REG_SET (lra_no_alloc_regs
, temp_hard_reg_set
);
1266 AND_COMPL_HARD_REG_SET (eliminable_regset
, temp_hard_reg_set
);
1267 spill_pseudos (temp_hard_reg_set
);
1271 /* Initialize the table of hard registers to eliminate.
1272 Pre-condition: global flag frame_pointer_needed has been set before
1273 calling this function. */
1275 init_elim_table (void)
1277 struct lra_elim_table
*ep
;
1278 #ifdef ELIMINABLE_REGS
1280 const struct elim_table_1
*ep1
;
1284 reg_eliminate
= XCNEWVEC (struct lra_elim_table
, NUM_ELIMINABLE_REGS
);
1286 memset (self_elim_offsets
, 0, sizeof (self_elim_offsets
));
1287 /* Initiate member values which will be never changed. */
1288 self_elim_table
.can_eliminate
= self_elim_table
.prev_can_eliminate
= true;
1289 self_elim_table
.previous_offset
= 0;
1290 #ifdef ELIMINABLE_REGS
1291 for (ep
= reg_eliminate
, ep1
= reg_eliminate_1
;
1292 ep
< ®_eliminate
[NUM_ELIMINABLE_REGS
]; ep
++, ep1
++)
1294 ep
->offset
= ep
->previous_offset
= 0;
1295 ep
->from
= ep1
->from
;
1297 value_p
= (targetm
.can_eliminate (ep
->from
, ep
->to
)
1298 && ! (ep
->to
== STACK_POINTER_REGNUM
1299 && frame_pointer_needed
1300 && (! SUPPORTS_STACK_ALIGNMENT
1301 || ! stack_realign_fp
)));
1302 setup_can_eliminate (ep
, value_p
);
1305 reg_eliminate
[0].offset
= reg_eliminate
[0].previous_offset
= 0;
1306 reg_eliminate
[0].from
= reg_eliminate_1
[0].from
;
1307 reg_eliminate
[0].to
= reg_eliminate_1
[0].to
;
1308 setup_can_eliminate (®_eliminate
[0], ! frame_pointer_needed
);
1311 /* Build the FROM and TO REG rtx's. Note that code in gen_rtx_REG
1312 will cause, e.g., gen_rtx_REG (Pmode, STACK_POINTER_REGNUM) to
1313 equal stack_pointer_rtx. We depend on this. Threfore we switch
1314 off that we are in LRA temporarily. */
1315 lra_in_progress
= 0;
1316 for (ep
= reg_eliminate
; ep
< ®_eliminate
[NUM_ELIMINABLE_REGS
]; ep
++)
1318 ep
->from_rtx
= gen_rtx_REG (Pmode
, ep
->from
);
1319 ep
->to_rtx
= gen_rtx_REG (Pmode
, ep
->to
);
1320 eliminable_reg_rtx
[ep
->from
] = ep
->from_rtx
;
1322 lra_in_progress
= 1;
1325 /* Function for initialization of elimination once per function. It
1326 sets up sp offset for each insn. */
1328 init_elimination (void)
1330 bool stop_to_sp_elimination_p
;
1333 struct lra_elim_table
*ep
;
1336 FOR_EACH_BB_FN (bb
, cfun
)
1339 stop_to_sp_elimination_p
= false;
1340 FOR_BB_INSNS (bb
, insn
)
1343 lra_get_insn_recog_data (insn
)->sp_offset
= curr_sp_change
;
1344 if (NONDEBUG_INSN_P (insn
))
1346 mark_not_eliminable (PATTERN (insn
), VOIDmode
);
1347 if (curr_sp_change
!= 0
1348 && find_reg_note (insn
, REG_LABEL_OPERAND
, NULL_RTX
))
1349 stop_to_sp_elimination_p
= true;
1352 if (! frame_pointer_needed
1353 && (curr_sp_change
!= 0 || stop_to_sp_elimination_p
)
1354 && bb
->succs
&& bb
->succs
->length () != 0)
1355 for (ep
= reg_eliminate
; ep
< ®_eliminate
[NUM_ELIMINABLE_REGS
]; ep
++)
1356 if (ep
->to
== STACK_POINTER_REGNUM
)
1357 setup_can_eliminate (ep
, false);
1359 setup_elimination_map ();
1362 /* Eliminate hard reg given by its location LOC. */
1364 lra_eliminate_reg_if_possible (rtx
*loc
)
1367 struct lra_elim_table
*ep
;
1369 lra_assert (REG_P (*loc
));
1370 if ((regno
= REGNO (*loc
)) >= FIRST_PSEUDO_REGISTER
1371 || ! TEST_HARD_REG_BIT (lra_no_alloc_regs
, regno
))
1373 if ((ep
= get_elimination (*loc
)) != NULL
)
1377 /* Do (final if FINAL_P or first if FIRST_P) elimination in INSN. Add
1378 the insn for subsequent processing in the constraint pass, update
1381 process_insn_for_elimination (rtx_insn
*insn
, bool final_p
, bool first_p
)
1383 eliminate_regs_in_insn (insn
, final_p
, first_p
, 0);
1386 /* Check that insn changed its code. This is a case when a move
1387 insn becomes an add insn and we do not want to process the
1388 insn as a move anymore. */
1389 int icode
= recog (PATTERN (insn
), insn
, 0);
1391 if (icode
>= 0 && icode
!= INSN_CODE (insn
))
1393 INSN_CODE (insn
) = icode
;
1394 lra_update_insn_recog_data (insn
);
1396 lra_update_insn_regno_info (insn
);
1397 lra_push_insn (insn
);
1398 lra_set_used_insn_alternative (insn
, -1);
1402 /* Entry function to do final elimination if FINAL_P or to update
1403 elimination register offsets (FIRST_P if we are doing it the first
1406 lra_eliminate (bool final_p
, bool first_p
)
1409 bitmap_head insns_with_changed_offsets
;
1411 struct lra_elim_table
*ep
;
1413 gcc_assert (! final_p
|| ! first_p
);
1415 timevar_push (TV_LRA_ELIMINATE
);
1418 init_elimination ();
1420 bitmap_initialize (&insns_with_changed_offsets
, ®_obstack
);
1425 update_reg_eliminate (&insns_with_changed_offsets
);
1426 gcc_assert (bitmap_empty_p (&insns_with_changed_offsets
));
1428 /* We change eliminable hard registers in insns so we should do
1429 this for all insns containing any eliminable hard
1431 for (ep
= reg_eliminate
; ep
< ®_eliminate
[NUM_ELIMINABLE_REGS
]; ep
++)
1432 if (elimination_map
[ep
->from
] != NULL
)
1433 bitmap_ior_into (&insns_with_changed_offsets
,
1434 &lra_reg_info
[ep
->from
].insn_bitmap
);
1436 else if (! update_reg_eliminate (&insns_with_changed_offsets
))
1437 goto lra_eliminate_done
;
1438 if (lra_dump_file
!= NULL
)
1440 fprintf (lra_dump_file
, "New elimination table:\n");
1441 print_elim_table (lra_dump_file
);
1443 EXECUTE_IF_SET_IN_BITMAP (&insns_with_changed_offsets
, 0, uid
, bi
)
1444 /* A dead insn can be deleted in process_insn_for_elimination. */
1445 if (lra_insn_recog_data
[uid
] != NULL
)
1446 process_insn_for_elimination (lra_insn_recog_data
[uid
]->insn
,
1448 bitmap_clear (&insns_with_changed_offsets
);
1451 timevar_pop (TV_LRA_ELIMINATE
);