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"
58 #include "hard-reg-set.h"
62 #include "insn-config.h"
63 #include "insn-codes.h"
66 #include "addresses.h"
77 #include "dominance.h"
79 #include "basic-block.h"
84 #include "rtl-error.h"
87 /* This structure is used to record information about hard register
91 /* Hard register number to be eliminated. */
93 /* Hard register number used as replacement. */
95 /* Difference between values of the two hard registers above on
96 previous iteration. */
97 HOST_WIDE_INT previous_offset
;
98 /* Difference between the values on the current iteration. */
100 /* Nonzero if this elimination can be done. */
102 /* CAN_ELIMINATE since the last check. */
103 bool prev_can_eliminate
;
104 /* REG rtx for the register to be eliminated. We cannot simply
105 compare the number since we might then spuriously replace a hard
106 register corresponding to a pseudo assigned to the reg to be
109 /* REG rtx for the replacement. */
113 /* The elimination table. Each array entry describes one possible way
114 of eliminating a register in favor of another. If there is more
115 than one way of eliminating a particular register, the most
116 preferred should be specified first. */
117 static struct lra_elim_table
*reg_eliminate
= 0;
119 /* This is an intermediate structure to initialize the table. It has
120 exactly the members provided by ELIMINABLE_REGS. */
121 static const struct elim_table_1
125 } reg_eliminate_1
[] =
127 /* If a set of eliminable hard registers was specified, define the
128 table from it. Otherwise, default to the normal case of the frame
129 pointer being replaced by the stack pointer. */
131 #ifdef ELIMINABLE_REGS
134 {{ FRAME_POINTER_REGNUM
, STACK_POINTER_REGNUM
}};
137 #define NUM_ELIMINABLE_REGS ARRAY_SIZE (reg_eliminate_1)
139 /* Print info about elimination table to file F. */
141 print_elim_table (FILE *f
)
143 struct lra_elim_table
*ep
;
145 for (ep
= reg_eliminate
; ep
< ®_eliminate
[NUM_ELIMINABLE_REGS
]; ep
++)
146 fprintf (f
, "%s eliminate %d to %d (offset=" HOST_WIDE_INT_PRINT_DEC
147 ", prev_offset=" HOST_WIDE_INT_PRINT_DEC
")\n",
148 ep
->can_eliminate
? "Can" : "Can't",
149 ep
->from
, ep
->to
, ep
->offset
, ep
->previous_offset
);
152 /* Print info about elimination table to stderr. */
154 lra_debug_elim_table (void)
156 print_elim_table (stderr
);
159 /* Setup possibility of elimination in elimination table element EP to
160 VALUE. Setup FRAME_POINTER_NEEDED if elimination from frame
161 pointer to stack pointer is not possible anymore. */
163 setup_can_eliminate (struct lra_elim_table
*ep
, bool value
)
165 ep
->can_eliminate
= ep
->prev_can_eliminate
= value
;
167 && ep
->from
== FRAME_POINTER_REGNUM
&& ep
->to
== STACK_POINTER_REGNUM
)
168 frame_pointer_needed
= 1;
171 /* Map: eliminable "from" register -> its current elimination,
172 or NULL if none. The elimination table may contain more than
173 one elimination for the same hard register, but this map specifies
174 the one that we are currently using. */
175 static struct lra_elim_table
*elimination_map
[FIRST_PSEUDO_REGISTER
];
177 /* When an eliminable hard register becomes not eliminable, we use the
178 following special structure to restore original offsets for the
180 static struct lra_elim_table self_elim_table
;
182 /* Offsets should be used to restore original offsets for eliminable
183 hard register which just became not eliminable. Zero,
185 static HOST_WIDE_INT self_elim_offsets
[FIRST_PSEUDO_REGISTER
];
187 /* Map: hard regno -> RTL presentation. RTL presentations of all
188 potentially eliminable hard registers are stored in the map. */
189 static rtx eliminable_reg_rtx
[FIRST_PSEUDO_REGISTER
];
191 /* Set up ELIMINATION_MAP of the currently used eliminations. */
193 setup_elimination_map (void)
196 struct lra_elim_table
*ep
;
198 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
199 elimination_map
[i
] = NULL
;
200 for (ep
= reg_eliminate
; ep
< ®_eliminate
[NUM_ELIMINABLE_REGS
]; ep
++)
201 if (ep
->can_eliminate
&& elimination_map
[ep
->from
] == NULL
)
202 elimination_map
[ep
->from
] = ep
;
207 /* Compute the sum of X and Y, making canonicalizations assumed in an
208 address, namely: sum constant integers, surround the sum of two
209 constants with a CONST, put the constant as the second operand, and
210 group the constant on the outermost sum.
212 This routine assumes both inputs are already in canonical form. */
214 form_sum (rtx x
, rtx y
)
217 machine_mode mode
= GET_MODE (x
);
219 if (mode
== VOIDmode
)
222 if (mode
== VOIDmode
)
226 return plus_constant (mode
, y
, INTVAL (x
));
227 else if (CONST_INT_P (y
))
228 return plus_constant (mode
, x
, INTVAL (y
));
229 else if (CONSTANT_P (x
))
230 tem
= x
, x
= y
, y
= tem
;
232 if (GET_CODE (x
) == PLUS
&& CONSTANT_P (XEXP (x
, 1)))
233 return form_sum (XEXP (x
, 0), form_sum (XEXP (x
, 1), y
));
235 /* Note that if the operands of Y are specified in the opposite
236 order in the recursive calls below, infinite recursion will
238 if (GET_CODE (y
) == PLUS
&& CONSTANT_P (XEXP (y
, 1)))
239 return form_sum (form_sum (x
, XEXP (y
, 0)), XEXP (y
, 1));
241 /* If both constant, encapsulate sum. Otherwise, just form sum. A
242 constant will have been placed second. */
243 if (CONSTANT_P (x
) && CONSTANT_P (y
))
245 if (GET_CODE (x
) == CONST
)
247 if (GET_CODE (y
) == CONST
)
250 return gen_rtx_CONST (VOIDmode
, gen_rtx_PLUS (mode
, x
, y
));
253 return gen_rtx_PLUS (mode
, x
, y
);
256 /* Return the current substitution hard register of the elimination of
257 HARD_REGNO. If HARD_REGNO is not eliminable, return itself. */
259 lra_get_elimination_hard_regno (int hard_regno
)
261 struct lra_elim_table
*ep
;
263 if (hard_regno
< 0 || hard_regno
>= FIRST_PSEUDO_REGISTER
)
265 if ((ep
= elimination_map
[hard_regno
]) == NULL
)
270 /* Return elimination which will be used for hard reg REG, NULL
272 static struct lra_elim_table
*
273 get_elimination (rtx reg
)
276 struct lra_elim_table
*ep
;
277 HOST_WIDE_INT offset
;
279 lra_assert (REG_P (reg
));
280 if ((hard_regno
= REGNO (reg
)) < 0 || hard_regno
>= FIRST_PSEUDO_REGISTER
)
282 if ((ep
= elimination_map
[hard_regno
]) != NULL
)
283 return ep
->from_rtx
!= reg
? NULL
: ep
;
284 if ((offset
= self_elim_offsets
[hard_regno
]) == 0)
286 /* This is an iteration to restore offsets just after HARD_REGNO
287 stopped to be eliminable. */
288 self_elim_table
.from
= self_elim_table
.to
= hard_regno
;
289 self_elim_table
.from_rtx
290 = self_elim_table
.to_rtx
291 = eliminable_reg_rtx
[hard_regno
];
292 lra_assert (self_elim_table
.from_rtx
!= NULL
);
293 self_elim_table
.offset
= offset
;
294 return &self_elim_table
;
297 /* Scan X and replace any eliminable registers (such as fp) with a
298 replacement (such as sp) if SUBST_P, plus an offset. The offset is
299 a change in the offset between the eliminable register and its
300 substitution if UPDATE_P, or the full offset if FULL_P, or
301 otherwise zero. If FULL_P, we also use the SP offsets for
302 elimination to SP. If UPDATE_P, use UPDATE_SP_OFFSET for updating
303 offsets of register elimnable to SP.
305 MEM_MODE is the mode of an enclosing MEM. We need this to know how
306 much to adjust a register for, e.g., PRE_DEC. Also, if we are
307 inside a MEM, we are allowed to replace a sum of a hard register
308 and the constant zero with the hard register, which we cannot do
309 outside a MEM. In addition, we need to record the fact that a
310 hard register is referenced outside a MEM.
312 If we make full substitution to SP for non-null INSN, add the insn
315 lra_eliminate_regs_1 (rtx_insn
*insn
, rtx x
, machine_mode mem_mode
,
316 bool subst_p
, bool update_p
,
317 HOST_WIDE_INT update_sp_offset
, bool full_p
)
319 enum rtx_code code
= GET_CODE (x
);
320 struct lra_elim_table
*ep
;
326 gcc_assert (!update_p
|| !full_p
);
327 if (! current_function_decl
)
345 /* First handle the case where we encounter a bare hard register
346 that is eliminable. Replace it with a PLUS. */
347 if ((ep
= get_elimination (x
)) != NULL
)
349 rtx to
= subst_p
? ep
->to_rtx
: ep
->from_rtx
;
352 return plus_constant (Pmode
, to
,
353 ep
->offset
- ep
->previous_offset
354 + (ep
->to_rtx
== stack_pointer_rtx
355 ? update_sp_offset
: 0));
357 return plus_constant (Pmode
, to
,
360 && ep
->to_rtx
== stack_pointer_rtx
361 ? lra_get_insn_recog_data (insn
)->sp_offset
369 /* If this is the sum of an eliminable register and a constant, rework
371 if (REG_P (XEXP (x
, 0)) && CONSTANT_P (XEXP (x
, 1)))
373 if ((ep
= get_elimination (XEXP (x
, 0))) != NULL
)
375 HOST_WIDE_INT offset
;
376 rtx to
= subst_p
? ep
->to_rtx
: ep
->from_rtx
;
378 if (! update_p
&& ! full_p
)
379 return gen_rtx_PLUS (Pmode
, to
, XEXP (x
, 1));
382 ? ep
->offset
- ep
->previous_offset
383 + (ep
->to_rtx
== stack_pointer_rtx
384 ? update_sp_offset
: 0)
386 if (full_p
&& insn
!= NULL_RTX
&& ep
->to_rtx
== stack_pointer_rtx
)
387 offset
-= lra_get_insn_recog_data (insn
)->sp_offset
;
388 if (CONST_INT_P (XEXP (x
, 1))
389 && INTVAL (XEXP (x
, 1)) == -offset
)
392 return gen_rtx_PLUS (Pmode
, to
,
393 plus_constant (Pmode
,
394 XEXP (x
, 1), offset
));
397 /* If the hard register is not eliminable, we are done since
398 the other operand is a constant. */
402 /* If this is part of an address, we want to bring any constant
403 to the outermost PLUS. We will do this by doing hard
404 register replacement in our operands and seeing if a constant
405 shows up in one of them.
407 Note that there is no risk of modifying the structure of the
408 insn, since we only get called for its operands, thus we are
409 either modifying the address inside a MEM, or something like
410 an address operand of a load-address insn. */
413 rtx new0
= lra_eliminate_regs_1 (insn
, XEXP (x
, 0), mem_mode
,
415 update_sp_offset
, full_p
);
416 rtx new1
= lra_eliminate_regs_1 (insn
, XEXP (x
, 1), mem_mode
,
418 update_sp_offset
, full_p
);
420 if (new0
!= XEXP (x
, 0) || new1
!= XEXP (x
, 1))
421 return form_sum (new0
, new1
);
426 /* If this is the product of an eliminable hard register and a
427 constant, apply the distribute law and move the constant out
428 so that we have (plus (mult ..) ..). This is needed in order
429 to keep load-address insns valid. This case is pathological.
430 We ignore the possibility of overflow here. */
431 if (REG_P (XEXP (x
, 0)) && CONST_INT_P (XEXP (x
, 1))
432 && (ep
= get_elimination (XEXP (x
, 0))) != NULL
)
434 rtx to
= subst_p
? ep
->to_rtx
: ep
->from_rtx
;
437 return plus_constant (Pmode
,
438 gen_rtx_MULT (Pmode
, to
, XEXP (x
, 1)),
439 (ep
->offset
- ep
->previous_offset
440 + (ep
->to_rtx
== stack_pointer_rtx
441 ? update_sp_offset
: 0))
442 * INTVAL (XEXP (x
, 1)));
445 HOST_WIDE_INT offset
= ep
->offset
;
447 if (insn
!= NULL_RTX
&& ep
->to_rtx
== stack_pointer_rtx
)
448 offset
-= lra_get_insn_recog_data (insn
)->sp_offset
;
450 plus_constant (Pmode
,
451 gen_rtx_MULT (Pmode
, to
, XEXP (x
, 1)),
452 offset
* INTVAL (XEXP (x
, 1)));
455 return gen_rtx_MULT (Pmode
, to
, XEXP (x
, 1));
458 /* ... fall through ... */
462 /* See comments before PLUS about handling MINUS. */
466 case AND
: case IOR
: case XOR
:
467 case ROTATERT
: case ROTATE
:
468 case ASHIFTRT
: case LSHIFTRT
: case ASHIFT
:
470 case GE
: case GT
: case GEU
: case GTU
:
471 case LE
: case LT
: case LEU
: case LTU
:
473 rtx new0
= lra_eliminate_regs_1 (insn
, XEXP (x
, 0), mem_mode
,
475 update_sp_offset
, full_p
);
476 rtx new1
= XEXP (x
, 1)
477 ? lra_eliminate_regs_1 (insn
, XEXP (x
, 1), mem_mode
,
479 update_sp_offset
, full_p
) : 0;
481 if (new0
!= XEXP (x
, 0) || new1
!= XEXP (x
, 1))
482 return gen_rtx_fmt_ee (code
, GET_MODE (x
), new0
, new1
);
487 /* If we have something in XEXP (x, 0), the usual case,
491 new_rtx
= lra_eliminate_regs_1 (insn
, XEXP (x
, 0), mem_mode
,
493 update_sp_offset
, full_p
);
494 if (new_rtx
!= XEXP (x
, 0))
496 /* If this is a REG_DEAD note, it is not valid anymore.
497 Using the eliminated version could result in creating a
498 REG_DEAD note for the stack or frame pointer. */
499 if (REG_NOTE_KIND (x
) == REG_DEAD
)
501 ? lra_eliminate_regs_1 (insn
, XEXP (x
, 1), mem_mode
,
503 update_sp_offset
, full_p
)
506 x
= alloc_reg_note (REG_NOTE_KIND (x
), new_rtx
, XEXP (x
, 1));
510 /* ... fall through ... */
514 /* Now do eliminations in the rest of the chain. If this was
515 an EXPR_LIST, this might result in allocating more memory than is
516 strictly needed, but it simplifies the code. */
519 new_rtx
= lra_eliminate_regs_1 (insn
, XEXP (x
, 1), mem_mode
,
521 update_sp_offset
, full_p
);
522 if (new_rtx
!= XEXP (x
, 1))
524 gen_rtx_fmt_ee (GET_CODE (x
), GET_MODE (x
),
525 XEXP (x
, 0), new_rtx
);
533 /* We do not support elimination of a register that is modified.
534 elimination_effects has already make sure that this does not
540 /* We do not support elimination of a hard register that is
541 modified. LRA has already make sure that this does not
542 happen. The only remaining case we need to consider here is
543 that the increment value may be an eliminable register. */
544 if (GET_CODE (XEXP (x
, 1)) == PLUS
545 && XEXP (XEXP (x
, 1), 0) == XEXP (x
, 0))
547 rtx new_rtx
= lra_eliminate_regs_1 (insn
, XEXP (XEXP (x
, 1), 1),
548 mem_mode
, subst_p
, update_p
,
549 update_sp_offset
, full_p
);
551 if (new_rtx
!= XEXP (XEXP (x
, 1), 1))
552 return gen_rtx_fmt_ee (code
, GET_MODE (x
), XEXP (x
, 0),
553 gen_rtx_PLUS (GET_MODE (x
),
554 XEXP (x
, 0), new_rtx
));
558 case STRICT_LOW_PART
:
560 case SIGN_EXTEND
: case ZERO_EXTEND
:
561 case TRUNCATE
: case FLOAT_EXTEND
: case FLOAT_TRUNCATE
:
562 case FLOAT
: case FIX
:
563 case UNSIGNED_FIX
: case UNSIGNED_FLOAT
:
572 new_rtx
= lra_eliminate_regs_1 (insn
, XEXP (x
, 0), mem_mode
,
574 update_sp_offset
, full_p
);
575 if (new_rtx
!= XEXP (x
, 0))
576 return gen_rtx_fmt_e (code
, GET_MODE (x
), new_rtx
);
580 new_rtx
= lra_eliminate_regs_1 (insn
, SUBREG_REG (x
), mem_mode
,
582 update_sp_offset
, full_p
);
584 if (new_rtx
!= SUBREG_REG (x
))
586 int x_size
= GET_MODE_SIZE (GET_MODE (x
));
587 int new_size
= GET_MODE_SIZE (GET_MODE (new_rtx
));
589 if (MEM_P (new_rtx
) && x_size
<= new_size
)
591 SUBREG_REG (x
) = new_rtx
;
592 alter_subreg (&x
, false);
597 /* LRA can transform subregs itself. So don't call
598 simplify_gen_subreg until LRA transformations are
599 finished. Function simplify_gen_subreg can do
600 non-trivial transformations (like truncation) which
601 might make LRA work to fail. */
602 SUBREG_REG (x
) = new_rtx
;
606 return simplify_gen_subreg (GET_MODE (x
), new_rtx
,
607 GET_MODE (new_rtx
), SUBREG_BYTE (x
));
613 /* Our only special processing is to pass the mode of the MEM to our
614 recursive call and copy the flags. While we are here, handle this
615 case more efficiently. */
617 replace_equiv_address_nv
619 lra_eliminate_regs_1 (insn
, XEXP (x
, 0), GET_MODE (x
),
620 subst_p
, update_p
, update_sp_offset
, full_p
));
623 /* Handle insn_list USE that a call to a pure function may generate. */
624 new_rtx
= lra_eliminate_regs_1 (insn
, XEXP (x
, 0), VOIDmode
,
625 subst_p
, update_p
, update_sp_offset
, full_p
);
626 if (new_rtx
!= XEXP (x
, 0))
627 return gen_rtx_USE (GET_MODE (x
), new_rtx
);
638 /* Process each of our operands recursively. If any have changed, make a
640 fmt
= GET_RTX_FORMAT (code
);
641 for (i
= 0; i
< GET_RTX_LENGTH (code
); i
++, fmt
++)
645 new_rtx
= lra_eliminate_regs_1 (insn
, XEXP (x
, i
), mem_mode
,
647 update_sp_offset
, full_p
);
648 if (new_rtx
!= XEXP (x
, i
) && ! copied
)
650 x
= shallow_copy_rtx (x
);
653 XEXP (x
, i
) = new_rtx
;
655 else if (*fmt
== 'E')
658 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
660 new_rtx
= lra_eliminate_regs_1 (insn
, XVECEXP (x
, i
, j
), mem_mode
,
662 update_sp_offset
, full_p
);
663 if (new_rtx
!= XVECEXP (x
, i
, j
) && ! copied_vec
)
665 rtvec new_v
= gen_rtvec_v (XVECLEN (x
, i
),
669 x
= shallow_copy_rtx (x
);
675 XVECEXP (x
, i
, j
) = new_rtx
;
683 /* This function is used externally in subsequent passes of GCC. It
684 always does a full elimination of X. */
686 lra_eliminate_regs (rtx x
, machine_mode mem_mode
,
687 rtx insn ATTRIBUTE_UNUSED
)
689 return lra_eliminate_regs_1 (NULL
, x
, mem_mode
, true, false, 0, true);
692 /* Stack pointer offset before the current insn relative to one at the
693 func start. RTL insns can change SP explicitly. We keep the
694 changes from one insn to another through this variable. */
695 static HOST_WIDE_INT curr_sp_change
;
697 /* Scan rtx X for references to elimination source or target registers
698 in contexts that would prevent the elimination from happening.
699 Update the table of eliminables to reflect the changed state.
700 MEM_MODE is the mode of an enclosing MEM rtx, or VOIDmode if not
703 mark_not_eliminable (rtx x
, machine_mode mem_mode
)
705 enum rtx_code code
= GET_CODE (x
);
706 struct lra_elim_table
*ep
;
718 if (XEXP (x
, 0) == stack_pointer_rtx
719 && ((code
!= PRE_MODIFY
&& code
!= POST_MODIFY
)
720 || (GET_CODE (XEXP (x
, 1)) == PLUS
721 && XEXP (x
, 0) == XEXP (XEXP (x
, 1), 0)
722 && CONST_INT_P (XEXP (XEXP (x
, 1), 1)))))
724 int size
= GET_MODE_SIZE (mem_mode
);
727 /* If more bytes than MEM_MODE are pushed, account for
729 size
= PUSH_ROUNDING (size
);
731 if (code
== PRE_DEC
|| code
== POST_DEC
)
732 curr_sp_change
-= size
;
733 else if (code
== PRE_INC
|| code
== POST_INC
)
734 curr_sp_change
+= size
;
735 else if (code
== PRE_MODIFY
|| code
== POST_MODIFY
)
736 curr_sp_change
+= INTVAL (XEXP (XEXP (x
, 1), 1));
738 else if (REG_P (XEXP (x
, 0))
739 && REGNO (XEXP (x
, 0)) >= FIRST_PSEUDO_REGISTER
)
741 /* If we modify the source of an elimination rule, disable
742 it. Do the same if it is the destination and not the
743 hard frame register. */
744 for (ep
= reg_eliminate
;
745 ep
< ®_eliminate
[NUM_ELIMINABLE_REGS
];
747 if (ep
->from_rtx
== XEXP (x
, 0)
748 || (ep
->to_rtx
== XEXP (x
, 0)
749 && ep
->to_rtx
!= hard_frame_pointer_rtx
))
750 setup_can_eliminate (ep
, false);
755 if (REG_P (XEXP (x
, 0)) && REGNO (XEXP (x
, 0)) < FIRST_PSEUDO_REGISTER
)
756 /* If using a hard register that is the source of an eliminate
757 we still think can be performed, note it cannot be
758 performed since we don't know how this hard register is
760 for (ep
= reg_eliminate
;
761 ep
< ®_eliminate
[NUM_ELIMINABLE_REGS
];
763 if (ep
->from_rtx
== XEXP (x
, 0)
764 && ep
->to_rtx
!= hard_frame_pointer_rtx
)
765 setup_can_eliminate (ep
, false);
769 if (REG_P (XEXP (x
, 0)) && REGNO (XEXP (x
, 0)) < FIRST_PSEUDO_REGISTER
)
770 /* If clobbering a hard register that is the replacement
771 register for an elimination we still think can be
772 performed, note that it cannot be performed. Otherwise, we
773 need not be concerned about it. */
774 for (ep
= reg_eliminate
;
775 ep
< ®_eliminate
[NUM_ELIMINABLE_REGS
];
777 if (ep
->to_rtx
== XEXP (x
, 0)
778 && ep
->to_rtx
!= hard_frame_pointer_rtx
)
779 setup_can_eliminate (ep
, false);
783 if (SET_DEST (x
) == stack_pointer_rtx
784 && GET_CODE (SET_SRC (x
)) == PLUS
785 && XEXP (SET_SRC (x
), 0) == SET_DEST (x
)
786 && CONST_INT_P (XEXP (SET_SRC (x
), 1)))
788 curr_sp_change
+= INTVAL (XEXP (SET_SRC (x
), 1));
791 if (! REG_P (SET_DEST (x
))
792 || REGNO (SET_DEST (x
)) >= FIRST_PSEUDO_REGISTER
)
793 mark_not_eliminable (SET_DEST (x
), mem_mode
);
796 /* See if this is setting the replacement hard register for
799 If DEST is the hard frame pointer, we do nothing because
800 we assume that all assignments to the frame pointer are
801 for non-local gotos and are being done at a time when
802 they are valid and do not disturb anything else. Some
803 machines want to eliminate a fake argument pointer (or
804 even a fake frame pointer) with either the real frame
805 pointer or the stack pointer. Assignments to the hard
806 frame pointer must not prevent this elimination. */
807 for (ep
= reg_eliminate
;
808 ep
< ®_eliminate
[NUM_ELIMINABLE_REGS
];
810 if (ep
->to_rtx
== SET_DEST (x
)
811 && SET_DEST (x
) != hard_frame_pointer_rtx
)
812 setup_can_eliminate (ep
, false);
815 mark_not_eliminable (SET_SRC (x
), mem_mode
);
819 /* Our only special processing is to pass the mode of the MEM to
820 our recursive call. */
821 mark_not_eliminable (XEXP (x
, 0), GET_MODE (x
));
828 fmt
= GET_RTX_FORMAT (code
);
829 for (i
= 0; i
< GET_RTX_LENGTH (code
); i
++, fmt
++)
832 mark_not_eliminable (XEXP (x
, i
), mem_mode
);
833 else if (*fmt
== 'E')
834 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
835 mark_not_eliminable (XVECEXP (x
, i
, j
), mem_mode
);
841 #ifdef HARD_FRAME_POINTER_REGNUM
843 /* Find offset equivalence note for reg WHAT in INSN and return the
844 found elmination offset. If the note is not found, return NULL.
845 Remove the found note. */
847 remove_reg_equal_offset_note (rtx insn
, rtx what
)
851 for (link_loc
= ®_NOTES (insn
);
852 (link
= *link_loc
) != NULL_RTX
;
853 link_loc
= &XEXP (link
, 1))
854 if (REG_NOTE_KIND (link
) == REG_EQUAL
855 && GET_CODE (XEXP (link
, 0)) == PLUS
856 && XEXP (XEXP (link
, 0), 0) == what
857 && CONST_INT_P (XEXP (XEXP (link
, 0), 1)))
859 *link_loc
= XEXP (link
, 1);
860 return XEXP (XEXP (link
, 0), 1);
867 /* Scan INSN and eliminate all eliminable hard registers in it.
869 If REPLACE_P is true, do the replacement destructively. Also
870 delete the insn as dead it if it is setting an eliminable register.
872 If REPLACE_P is false, just update the offsets while keeping the
873 base register the same. If FIRST_P, use the sp offset for
874 elimination to sp. Otherwise, use UPDATE_SP_OFFSET for this.
875 Attach the note about used elimination for insns setting frame
876 pointer to update elimination easy (without parsing already
877 generated elimination insns to find offset previously used) in
881 eliminate_regs_in_insn (rtx_insn
*insn
, bool replace_p
, bool first_p
,
882 HOST_WIDE_INT update_sp_offset
)
884 int icode
= recog_memoized (insn
);
885 rtx old_set
= single_set (insn
);
888 rtx substed_operand
[MAX_RECOG_OPERANDS
];
889 rtx orig_operand
[MAX_RECOG_OPERANDS
];
890 struct lra_elim_table
*ep
;
891 rtx plus_src
, plus_cst_src
;
892 lra_insn_recog_data_t id
;
893 struct lra_static_insn_data
*static_id
;
895 if (icode
< 0 && asm_noperands (PATTERN (insn
)) < 0 && ! DEBUG_INSN_P (insn
))
897 lra_assert (GET_CODE (PATTERN (insn
)) == USE
898 || GET_CODE (PATTERN (insn
)) == CLOBBER
899 || GET_CODE (PATTERN (insn
)) == ASM_INPUT
);
903 /* Check for setting an eliminable register. */
904 if (old_set
!= 0 && REG_P (SET_DEST (old_set
))
905 && (ep
= get_elimination (SET_DEST (old_set
))) != NULL
)
907 for (ep
= reg_eliminate
; ep
< ®_eliminate
[NUM_ELIMINABLE_REGS
]; ep
++)
908 if (ep
->from_rtx
== SET_DEST (old_set
) && ep
->can_eliminate
)
910 bool delete_p
= replace_p
;
912 #ifdef HARD_FRAME_POINTER_REGNUM
913 if (ep
->from
== FRAME_POINTER_REGNUM
914 && ep
->to
== HARD_FRAME_POINTER_REGNUM
)
915 /* If this is setting the frame pointer register to the
916 hardware frame pointer register and this is an
917 elimination that will be done (tested above), this
918 insn is really adjusting the frame pointer downward
919 to compensate for the adjustment done before a
922 rtx src
= SET_SRC (old_set
);
923 rtx off
= remove_reg_equal_offset_note (insn
, ep
->to_rtx
);
927 || (GET_CODE (src
) == PLUS
928 && XEXP (src
, 0) == ep
->to_rtx
929 && CONST_INT_P (XEXP (src
, 1))))
931 HOST_WIDE_INT offset
;
935 SET_DEST (old_set
) = ep
->to_rtx
;
936 lra_update_insn_recog_data (insn
);
939 offset
= (off
!= NULL_RTX
? INTVAL (off
)
940 : src
== ep
->to_rtx
? 0 : INTVAL (XEXP (src
, 1)));
941 offset
-= (ep
->offset
- ep
->previous_offset
);
942 src
= plus_constant (Pmode
, ep
->to_rtx
, offset
);
944 /* First see if this insn remains valid when we
945 make the change. If not, keep the INSN_CODE
946 the same and let the constraint pass fit it
948 validate_change (insn
, &SET_SRC (old_set
), src
, 1);
949 validate_change (insn
, &SET_DEST (old_set
),
951 if (! apply_change_group ())
953 SET_SRC (old_set
) = src
;
954 SET_DEST (old_set
) = ep
->from_rtx
;
956 lra_update_insn_recog_data (insn
);
957 /* Add offset note for future updates. */
958 add_reg_note (insn
, REG_EQUAL
, src
);
964 /* This insn isn't serving a useful purpose. We delete it
965 when REPLACE is set. */
967 lra_delete_dead_insn (insn
);
972 /* We allow one special case which happens to work on all machines we
973 currently support: a single set with the source or a REG_EQUAL
974 note being a PLUS of an eliminable register and a constant. */
975 plus_src
= plus_cst_src
= 0;
976 if (old_set
&& REG_P (SET_DEST (old_set
)))
978 if (GET_CODE (SET_SRC (old_set
)) == PLUS
)
979 plus_src
= SET_SRC (old_set
);
980 /* First see if the source is of the form (plus (...) CST). */
982 && CONST_INT_P (XEXP (plus_src
, 1)))
983 plus_cst_src
= plus_src
;
984 /* Check that the first operand of the PLUS is a hard reg or
985 the lowpart subreg of one. */
988 rtx reg
= XEXP (plus_cst_src
, 0);
990 if (GET_CODE (reg
) == SUBREG
&& subreg_lowpart_p (reg
))
991 reg
= SUBREG_REG (reg
);
993 if (!REG_P (reg
) || REGNO (reg
) >= FIRST_PSEUDO_REGISTER
)
999 rtx reg
= XEXP (plus_cst_src
, 0);
1000 HOST_WIDE_INT offset
= INTVAL (XEXP (plus_cst_src
, 1));
1002 if (GET_CODE (reg
) == SUBREG
)
1003 reg
= SUBREG_REG (reg
);
1005 if (REG_P (reg
) && (ep
= get_elimination (reg
)) != NULL
)
1007 rtx to_rtx
= replace_p
? ep
->to_rtx
: ep
->from_rtx
;
1011 offset
+= (ep
->offset
- ep
->previous_offset
);
1012 if (ep
->to_rtx
== stack_pointer_rtx
)
1015 offset
-= lra_get_insn_recog_data (insn
)->sp_offset
;
1017 offset
+= update_sp_offset
;
1019 offset
= trunc_int_for_mode (offset
, GET_MODE (plus_cst_src
));
1022 if (GET_CODE (XEXP (plus_cst_src
, 0)) == SUBREG
)
1023 to_rtx
= gen_lowpart (GET_MODE (XEXP (plus_cst_src
, 0)), to_rtx
);
1024 /* If we have a nonzero offset, and the source is already a
1025 simple REG, the following transformation would increase
1026 the cost of the insn by replacing a simple REG with (plus
1027 (reg sp) CST). So try only when we already had a PLUS
1029 if (offset
== 0 || plus_src
)
1031 rtx new_src
= plus_constant (GET_MODE (to_rtx
), to_rtx
, offset
);
1033 old_set
= single_set (insn
);
1035 /* First see if this insn remains valid when we make the
1036 change. If not, try to replace the whole pattern
1037 with a simple set (this may help if the original insn
1038 was a PARALLEL that was only recognized as single_set
1039 due to REG_UNUSED notes). If this isn't valid
1040 either, keep the INSN_CODE the same and let the
1041 constraint pass fix it up. */
1042 if (! validate_change (insn
, &SET_SRC (old_set
), new_src
, 0))
1044 rtx new_pat
= gen_rtx_SET (VOIDmode
,
1045 SET_DEST (old_set
), new_src
);
1047 if (! validate_change (insn
, &PATTERN (insn
), new_pat
, 0))
1048 SET_SRC (old_set
) = new_src
;
1050 lra_update_insn_recog_data (insn
);
1051 /* This can't have an effect on elimination offsets, so skip
1052 right to the end. */
1058 /* Eliminate all eliminable registers occurring in operands that
1059 can be handled by the constraint pass. */
1060 id
= lra_get_insn_recog_data (insn
);
1061 static_id
= id
->insn_static_data
;
1063 for (i
= 0; i
< static_id
->n_operands
; i
++)
1065 orig_operand
[i
] = *id
->operand_loc
[i
];
1066 substed_operand
[i
] = *id
->operand_loc
[i
];
1068 /* For an asm statement, every operand is eliminable. */
1069 if (icode
< 0 || insn_data
[icode
].operand
[i
].eliminable
)
1071 /* Check for setting a hard register that we know about. */
1072 if (static_id
->operand
[i
].type
!= OP_IN
1073 && REG_P (orig_operand
[i
]))
1075 /* If we are assigning to a hard register that can be
1076 eliminated, it must be as part of a PARALLEL, since
1077 the code above handles single SETs. This reg can not
1078 be longer eliminated -- it is forced by
1079 mark_not_eliminable. */
1080 for (ep
= reg_eliminate
;
1081 ep
< ®_eliminate
[NUM_ELIMINABLE_REGS
];
1083 lra_assert (ep
->from_rtx
!= orig_operand
[i
]
1084 || ! ep
->can_eliminate
);
1087 /* Companion to the above plus substitution, we can allow
1088 invariants as the source of a plain move. */
1090 = lra_eliminate_regs_1 (insn
, *id
->operand_loc
[i
], VOIDmode
,
1091 replace_p
, ! replace_p
&& ! first_p
,
1092 update_sp_offset
, first_p
);
1093 if (substed_operand
[i
] != orig_operand
[i
])
1101 /* Substitute the operands; the new values are in the substed_operand
1103 for (i
= 0; i
< static_id
->n_operands
; i
++)
1104 *id
->operand_loc
[i
] = substed_operand
[i
];
1105 for (i
= 0; i
< static_id
->n_dups
; i
++)
1106 *id
->dup_loc
[i
] = substed_operand
[(int) static_id
->dup_num
[i
]];
1108 /* If we had a move insn but now we don't, re-recognize it.
1109 This will cause spurious re-recognition if the old move had a
1110 PARALLEL since the new one still will, but we can't call
1111 single_set without having put new body into the insn and the
1112 re-recognition won't hurt in this rare case. */
1113 id
= lra_update_insn_recog_data (insn
);
1114 static_id
= id
->insn_static_data
;
1117 /* Spill pseudos which are assigned to hard registers in SET. Add
1118 affected insns for processing in the subsequent constraint
1121 spill_pseudos (HARD_REG_SET set
)
1124 bitmap_head to_process
;
1127 if (hard_reg_set_empty_p (set
))
1129 if (lra_dump_file
!= NULL
)
1131 fprintf (lra_dump_file
, " Spilling non-eliminable hard regs:");
1132 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
1133 if (TEST_HARD_REG_BIT (set
, i
))
1134 fprintf (lra_dump_file
, " %d", i
);
1135 fprintf (lra_dump_file
, "\n");
1137 bitmap_initialize (&to_process
, ®_obstack
);
1138 for (i
= FIRST_PSEUDO_REGISTER
; i
< max_reg_num (); i
++)
1139 if (lra_reg_info
[i
].nrefs
!= 0 && reg_renumber
[i
] >= 0
1140 && overlaps_hard_reg_set_p (set
,
1141 PSEUDO_REGNO_MODE (i
), reg_renumber
[i
]))
1143 if (lra_dump_file
!= NULL
)
1144 fprintf (lra_dump_file
, " Spilling r%d(%d)\n",
1145 i
, reg_renumber
[i
]);
1146 reg_renumber
[i
] = -1;
1147 bitmap_ior_into (&to_process
, &lra_reg_info
[i
].insn_bitmap
);
1149 IOR_HARD_REG_SET (lra_no_alloc_regs
, set
);
1150 for (insn
= get_insns (); insn
!= NULL_RTX
; insn
= NEXT_INSN (insn
))
1151 if (bitmap_bit_p (&to_process
, INSN_UID (insn
)))
1153 lra_push_insn (insn
);
1154 lra_set_used_insn_alternative (insn
, -1);
1156 bitmap_clear (&to_process
);
1159 /* Update all offsets and possibility for elimination on eliminable
1160 registers. Spill pseudos assigned to registers which are
1161 uneliminable, update LRA_NO_ALLOC_REGS and ELIMINABLE_REG_SET. Add
1162 insns to INSNS_WITH_CHANGED_OFFSETS containing eliminable hard
1163 registers whose offsets should be changed. Return true if any
1164 elimination offset changed. */
1166 update_reg_eliminate (bitmap insns_with_changed_offsets
)
1169 struct lra_elim_table
*ep
, *ep1
;
1170 HARD_REG_SET temp_hard_reg_set
;
1172 /* Clear self elimination offsets. */
1173 for (ep
= reg_eliminate
; ep
< ®_eliminate
[NUM_ELIMINABLE_REGS
]; ep
++)
1174 self_elim_offsets
[ep
->from
] = 0;
1175 for (ep
= reg_eliminate
; ep
< ®_eliminate
[NUM_ELIMINABLE_REGS
]; ep
++)
1177 /* If it is a currently used elimination: update the previous
1179 if (elimination_map
[ep
->from
] == ep
)
1180 ep
->previous_offset
= ep
->offset
;
1182 prev
= ep
->prev_can_eliminate
;
1183 setup_can_eliminate (ep
, targetm
.can_eliminate (ep
->from
, ep
->to
));
1184 if (ep
->can_eliminate
&& ! prev
)
1186 /* It is possible that not eliminable register becomes
1187 eliminable because we took other reasons into account to
1188 set up eliminable regs in the initial set up. Just
1189 ignore new eliminable registers. */
1190 setup_can_eliminate (ep
, false);
1193 if (ep
->can_eliminate
!= prev
&& elimination_map
[ep
->from
] == ep
)
1195 /* We cannot use this elimination anymore -- find another
1197 if (lra_dump_file
!= NULL
)
1198 fprintf (lra_dump_file
,
1199 " Elimination %d to %d is not possible anymore\n",
1201 /* If after processing RTL we decides that SP can be used as
1202 a result of elimination, it can not be changed. */
1203 gcc_assert ((ep
->to_rtx
!= stack_pointer_rtx
)
1204 || (ep
->from
< FIRST_PSEUDO_REGISTER
1205 && fixed_regs
[ep
->from
]));
1206 /* Mark that is not eliminable anymore. */
1207 elimination_map
[ep
->from
] = NULL
;
1208 for (ep1
= ep
+ 1; ep1
< ®_eliminate
[NUM_ELIMINABLE_REGS
]; ep1
++)
1209 if (ep1
->can_eliminate
&& ep1
->from
== ep
->from
)
1211 if (ep1
< ®_eliminate
[NUM_ELIMINABLE_REGS
])
1213 if (lra_dump_file
!= NULL
)
1214 fprintf (lra_dump_file
, " Using elimination %d to %d now\n",
1215 ep1
->from
, ep1
->to
);
1216 lra_assert (ep1
->previous_offset
== 0);
1217 ep1
->previous_offset
= ep
->offset
;
1221 /* There is no elimination anymore just use the hard
1222 register `from' itself. Setup self elimination
1223 offset to restore the original offset values. */
1224 if (lra_dump_file
!= NULL
)
1225 fprintf (lra_dump_file
, " %d is not eliminable at all\n",
1227 self_elim_offsets
[ep
->from
] = -ep
->offset
;
1228 if (ep
->offset
!= 0)
1229 bitmap_ior_into (insns_with_changed_offsets
,
1230 &lra_reg_info
[ep
->from
].insn_bitmap
);
1234 #ifdef ELIMINABLE_REGS
1235 INITIAL_ELIMINATION_OFFSET (ep
->from
, ep
->to
, ep
->offset
);
1237 INITIAL_FRAME_POINTER_OFFSET (ep
->offset
);
1240 setup_elimination_map ();
1242 CLEAR_HARD_REG_SET (temp_hard_reg_set
);
1243 for (ep
= reg_eliminate
; ep
< ®_eliminate
[NUM_ELIMINABLE_REGS
]; ep
++)
1244 if (elimination_map
[ep
->from
] == NULL
)
1245 SET_HARD_REG_BIT (temp_hard_reg_set
, ep
->from
);
1246 else if (elimination_map
[ep
->from
] == ep
)
1248 /* Prevent the hard register into which we eliminate from
1249 the usage for pseudos. */
1250 if (ep
->from
!= ep
->to
)
1251 SET_HARD_REG_BIT (temp_hard_reg_set
, ep
->to
);
1252 if (ep
->previous_offset
!= ep
->offset
)
1254 bitmap_ior_into (insns_with_changed_offsets
,
1255 &lra_reg_info
[ep
->from
].insn_bitmap
);
1257 /* Update offset when the eliminate offset have been
1259 lra_update_reg_val_offset (lra_reg_info
[ep
->from
].val
,
1260 ep
->offset
- ep
->previous_offset
);
1264 IOR_HARD_REG_SET (lra_no_alloc_regs
, temp_hard_reg_set
);
1265 AND_COMPL_HARD_REG_SET (eliminable_regset
, temp_hard_reg_set
);
1266 spill_pseudos (temp_hard_reg_set
);
1270 /* Initialize the table of hard registers to eliminate.
1271 Pre-condition: global flag frame_pointer_needed has been set before
1272 calling this function. */
1274 init_elim_table (void)
1276 struct lra_elim_table
*ep
;
1277 #ifdef ELIMINABLE_REGS
1279 const struct elim_table_1
*ep1
;
1283 reg_eliminate
= XCNEWVEC (struct lra_elim_table
, NUM_ELIMINABLE_REGS
);
1285 memset (self_elim_offsets
, 0, sizeof (self_elim_offsets
));
1286 /* Initiate member values which will be never changed. */
1287 self_elim_table
.can_eliminate
= self_elim_table
.prev_can_eliminate
= true;
1288 self_elim_table
.previous_offset
= 0;
1289 #ifdef ELIMINABLE_REGS
1290 for (ep
= reg_eliminate
, ep1
= reg_eliminate_1
;
1291 ep
< ®_eliminate
[NUM_ELIMINABLE_REGS
]; ep
++, ep1
++)
1293 ep
->offset
= ep
->previous_offset
= 0;
1294 ep
->from
= ep1
->from
;
1296 value_p
= (targetm
.can_eliminate (ep
->from
, ep
->to
)
1297 && ! (ep
->to
== STACK_POINTER_REGNUM
1298 && frame_pointer_needed
1299 && (! SUPPORTS_STACK_ALIGNMENT
1300 || ! stack_realign_fp
)));
1301 setup_can_eliminate (ep
, value_p
);
1304 reg_eliminate
[0].offset
= reg_eliminate
[0].previous_offset
= 0;
1305 reg_eliminate
[0].from
= reg_eliminate_1
[0].from
;
1306 reg_eliminate
[0].to
= reg_eliminate_1
[0].to
;
1307 setup_can_eliminate (®_eliminate
[0], ! frame_pointer_needed
);
1310 /* Build the FROM and TO REG rtx's. Note that code in gen_rtx_REG
1311 will cause, e.g., gen_rtx_REG (Pmode, STACK_POINTER_REGNUM) to
1312 equal stack_pointer_rtx. We depend on this. Threfore we switch
1313 off that we are in LRA temporarily. */
1314 lra_in_progress
= 0;
1315 for (ep
= reg_eliminate
; ep
< ®_eliminate
[NUM_ELIMINABLE_REGS
]; ep
++)
1317 ep
->from_rtx
= gen_rtx_REG (Pmode
, ep
->from
);
1318 ep
->to_rtx
= gen_rtx_REG (Pmode
, ep
->to
);
1319 eliminable_reg_rtx
[ep
->from
] = ep
->from_rtx
;
1321 lra_in_progress
= 1;
1324 /* Function for initialization of elimination once per function. It
1325 sets up sp offset for each insn. */
1327 init_elimination (void)
1329 bool stop_to_sp_elimination_p
;
1332 struct lra_elim_table
*ep
;
1335 FOR_EACH_BB_FN (bb
, cfun
)
1338 stop_to_sp_elimination_p
= false;
1339 FOR_BB_INSNS (bb
, insn
)
1342 lra_get_insn_recog_data (insn
)->sp_offset
= curr_sp_change
;
1343 if (NONDEBUG_INSN_P (insn
))
1345 mark_not_eliminable (PATTERN (insn
), VOIDmode
);
1346 if (curr_sp_change
!= 0
1347 && find_reg_note (insn
, REG_LABEL_OPERAND
, NULL_RTX
))
1348 stop_to_sp_elimination_p
= true;
1351 if (! frame_pointer_needed
1352 && (curr_sp_change
!= 0 || stop_to_sp_elimination_p
)
1353 && bb
->succs
&& bb
->succs
->length () != 0)
1354 for (ep
= reg_eliminate
; ep
< ®_eliminate
[NUM_ELIMINABLE_REGS
]; ep
++)
1355 if (ep
->to
== STACK_POINTER_REGNUM
)
1356 setup_can_eliminate (ep
, false);
1358 setup_elimination_map ();
1361 /* Eliminate hard reg given by its location LOC. */
1363 lra_eliminate_reg_if_possible (rtx
*loc
)
1366 struct lra_elim_table
*ep
;
1368 lra_assert (REG_P (*loc
));
1369 if ((regno
= REGNO (*loc
)) >= FIRST_PSEUDO_REGISTER
1370 || ! TEST_HARD_REG_BIT (lra_no_alloc_regs
, regno
))
1372 if ((ep
= get_elimination (*loc
)) != NULL
)
1376 /* Do (final if FINAL_P or first if FIRST_P) elimination in INSN. Add
1377 the insn for subsequent processing in the constraint pass, update
1380 process_insn_for_elimination (rtx_insn
*insn
, bool final_p
, bool first_p
)
1382 eliminate_regs_in_insn (insn
, final_p
, first_p
, 0);
1385 /* Check that insn changed its code. This is a case when a move
1386 insn becomes an add insn and we do not want to process the
1387 insn as a move anymore. */
1388 int icode
= recog (PATTERN (insn
), insn
, 0);
1390 if (icode
>= 0 && icode
!= INSN_CODE (insn
))
1392 INSN_CODE (insn
) = icode
;
1393 lra_update_insn_recog_data (insn
);
1395 lra_update_insn_regno_info (insn
);
1396 lra_push_insn (insn
);
1397 lra_set_used_insn_alternative (insn
, -1);
1401 /* Entry function to do final elimination if FINAL_P or to update
1402 elimination register offsets (FIRST_P if we are doing it the first
1405 lra_eliminate (bool final_p
, bool first_p
)
1408 bitmap_head insns_with_changed_offsets
;
1410 struct lra_elim_table
*ep
;
1412 gcc_assert (! final_p
|| ! first_p
);
1414 timevar_push (TV_LRA_ELIMINATE
);
1417 init_elimination ();
1419 bitmap_initialize (&insns_with_changed_offsets
, ®_obstack
);
1422 #ifdef ENABLE_CHECKING
1423 update_reg_eliminate (&insns_with_changed_offsets
);
1424 if (! bitmap_empty_p (&insns_with_changed_offsets
))
1427 /* We change eliminable hard registers in insns so we should do
1428 this for all insns containing any eliminable hard
1430 for (ep
= reg_eliminate
; ep
< ®_eliminate
[NUM_ELIMINABLE_REGS
]; ep
++)
1431 if (elimination_map
[ep
->from
] != NULL
)
1432 bitmap_ior_into (&insns_with_changed_offsets
,
1433 &lra_reg_info
[ep
->from
].insn_bitmap
);
1435 else if (! update_reg_eliminate (&insns_with_changed_offsets
))
1436 goto lra_eliminate_done
;
1437 if (lra_dump_file
!= NULL
)
1439 fprintf (lra_dump_file
, "New elimination table:\n");
1440 print_elim_table (lra_dump_file
);
1442 EXECUTE_IF_SET_IN_BITMAP (&insns_with_changed_offsets
, 0, uid
, bi
)
1443 /* A dead insn can be deleted in process_insn_for_elimination. */
1444 if (lra_insn_recog_data
[uid
] != NULL
)
1445 process_insn_for_elimination (lra_insn_recog_data
[uid
]->insn
,
1447 bitmap_clear (&insns_with_changed_offsets
);
1450 timevar_pop (TV_LRA_ELIMINATE
);