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"
76 #include "statistics.h"
77 #include "double-int.h"
79 #include "fixed-value.h"
93 #include "dominance.h"
95 #include "basic-block.h"
100 #include "rtl-error.h"
103 /* This structure is used to record information about hard register
105 struct lra_elim_table
107 /* Hard register number to be eliminated. */
109 /* Hard register number used as replacement. */
111 /* Difference between values of the two hard registers above on
112 previous iteration. */
113 HOST_WIDE_INT previous_offset
;
114 /* Difference between the values on the current iteration. */
115 HOST_WIDE_INT offset
;
116 /* Nonzero if this elimination can be done. */
118 /* CAN_ELIMINATE since the last check. */
119 bool prev_can_eliminate
;
120 /* REG rtx for the register to be eliminated. We cannot simply
121 compare the number since we might then spuriously replace a hard
122 register corresponding to a pseudo assigned to the reg to be
125 /* REG rtx for the replacement. */
129 /* The elimination table. Each array entry describes one possible way
130 of eliminating a register in favor of another. If there is more
131 than one way of eliminating a particular register, the most
132 preferred should be specified first. */
133 static struct lra_elim_table
*reg_eliminate
= 0;
135 /* This is an intermediate structure to initialize the table. It has
136 exactly the members provided by ELIMINABLE_REGS. */
137 static const struct elim_table_1
141 } reg_eliminate_1
[] =
143 /* If a set of eliminable hard registers was specified, define the
144 table from it. Otherwise, default to the normal case of the frame
145 pointer being replaced by the stack pointer. */
147 #ifdef ELIMINABLE_REGS
150 {{ FRAME_POINTER_REGNUM
, STACK_POINTER_REGNUM
}};
153 #define NUM_ELIMINABLE_REGS ARRAY_SIZE (reg_eliminate_1)
155 /* Print info about elimination table to file F. */
157 print_elim_table (FILE *f
)
159 struct lra_elim_table
*ep
;
161 for (ep
= reg_eliminate
; ep
< ®_eliminate
[NUM_ELIMINABLE_REGS
]; ep
++)
162 fprintf (f
, "%s eliminate %d to %d (offset=" HOST_WIDE_INT_PRINT_DEC
163 ", prev_offset=" HOST_WIDE_INT_PRINT_DEC
")\n",
164 ep
->can_eliminate
? "Can" : "Can't",
165 ep
->from
, ep
->to
, ep
->offset
, ep
->previous_offset
);
168 /* Print info about elimination table to stderr. */
170 lra_debug_elim_table (void)
172 print_elim_table (stderr
);
175 /* Setup possibility of elimination in elimination table element EP to
176 VALUE. Setup FRAME_POINTER_NEEDED if elimination from frame
177 pointer to stack pointer is not possible anymore. */
179 setup_can_eliminate (struct lra_elim_table
*ep
, bool value
)
181 ep
->can_eliminate
= ep
->prev_can_eliminate
= value
;
183 && ep
->from
== FRAME_POINTER_REGNUM
&& ep
->to
== STACK_POINTER_REGNUM
)
184 frame_pointer_needed
= 1;
187 /* Map: eliminable "from" register -> its current elimination,
188 or NULL if none. The elimination table may contain more than
189 one elimination for the same hard register, but this map specifies
190 the one that we are currently using. */
191 static struct lra_elim_table
*elimination_map
[FIRST_PSEUDO_REGISTER
];
193 /* When an eliminable hard register becomes not eliminable, we use the
194 following special structure to restore original offsets for the
196 static struct lra_elim_table self_elim_table
;
198 /* Offsets should be used to restore original offsets for eliminable
199 hard register which just became not eliminable. Zero,
201 static HOST_WIDE_INT self_elim_offsets
[FIRST_PSEUDO_REGISTER
];
203 /* Map: hard regno -> RTL presentation. RTL presentations of all
204 potentially eliminable hard registers are stored in the map. */
205 static rtx eliminable_reg_rtx
[FIRST_PSEUDO_REGISTER
];
207 /* Set up ELIMINATION_MAP of the currently used eliminations. */
209 setup_elimination_map (void)
212 struct lra_elim_table
*ep
;
214 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
215 elimination_map
[i
] = NULL
;
216 for (ep
= reg_eliminate
; ep
< ®_eliminate
[NUM_ELIMINABLE_REGS
]; ep
++)
217 if (ep
->can_eliminate
&& elimination_map
[ep
->from
] == NULL
)
218 elimination_map
[ep
->from
] = ep
;
223 /* Compute the sum of X and Y, making canonicalizations assumed in an
224 address, namely: sum constant integers, surround the sum of two
225 constants with a CONST, put the constant as the second operand, and
226 group the constant on the outermost sum.
228 This routine assumes both inputs are already in canonical form. */
230 form_sum (rtx x
, rtx y
)
233 machine_mode mode
= GET_MODE (x
);
235 if (mode
== VOIDmode
)
238 if (mode
== VOIDmode
)
242 return plus_constant (mode
, y
, INTVAL (x
));
243 else if (CONST_INT_P (y
))
244 return plus_constant (mode
, x
, INTVAL (y
));
245 else if (CONSTANT_P (x
))
246 tem
= x
, x
= y
, y
= tem
;
248 if (GET_CODE (x
) == PLUS
&& CONSTANT_P (XEXP (x
, 1)))
249 return form_sum (XEXP (x
, 0), form_sum (XEXP (x
, 1), y
));
251 /* Note that if the operands of Y are specified in the opposite
252 order in the recursive calls below, infinite recursion will
254 if (GET_CODE (y
) == PLUS
&& CONSTANT_P (XEXP (y
, 1)))
255 return form_sum (form_sum (x
, XEXP (y
, 0)), XEXP (y
, 1));
257 /* If both constant, encapsulate sum. Otherwise, just form sum. A
258 constant will have been placed second. */
259 if (CONSTANT_P (x
) && CONSTANT_P (y
))
261 if (GET_CODE (x
) == CONST
)
263 if (GET_CODE (y
) == CONST
)
266 return gen_rtx_CONST (VOIDmode
, gen_rtx_PLUS (mode
, x
, y
));
269 return gen_rtx_PLUS (mode
, x
, y
);
272 /* Return the current substitution hard register of the elimination of
273 HARD_REGNO. If HARD_REGNO is not eliminable, return itself. */
275 lra_get_elimination_hard_regno (int hard_regno
)
277 struct lra_elim_table
*ep
;
279 if (hard_regno
< 0 || hard_regno
>= FIRST_PSEUDO_REGISTER
)
281 if ((ep
= elimination_map
[hard_regno
]) == NULL
)
286 /* Return elimination which will be used for hard reg REG, NULL
288 static struct lra_elim_table
*
289 get_elimination (rtx reg
)
292 struct lra_elim_table
*ep
;
293 HOST_WIDE_INT offset
;
295 lra_assert (REG_P (reg
));
296 if ((hard_regno
= REGNO (reg
)) < 0 || hard_regno
>= FIRST_PSEUDO_REGISTER
)
298 if ((ep
= elimination_map
[hard_regno
]) != NULL
)
299 return ep
->from_rtx
!= reg
? NULL
: ep
;
300 if ((offset
= self_elim_offsets
[hard_regno
]) == 0)
302 /* This is an iteration to restore offsets just after HARD_REGNO
303 stopped to be eliminable. */
304 self_elim_table
.from
= self_elim_table
.to
= hard_regno
;
305 self_elim_table
.from_rtx
306 = self_elim_table
.to_rtx
307 = eliminable_reg_rtx
[hard_regno
];
308 lra_assert (self_elim_table
.from_rtx
!= NULL
);
309 self_elim_table
.offset
= offset
;
310 return &self_elim_table
;
313 /* Scan X and replace any eliminable registers (such as fp) with a
314 replacement (such as sp) if SUBST_P, plus an offset. The offset is
315 a change in the offset between the eliminable register and its
316 substitution if UPDATE_P, or the full offset if FULL_P, or
317 otherwise zero. If FULL_P, we also use the SP offsets for
318 elimination to SP. If UPDATE_P, use UPDATE_SP_OFFSET for updating
319 offsets of register elimnable to SP.
321 MEM_MODE is the mode of an enclosing MEM. We need this to know how
322 much to adjust a register for, e.g., PRE_DEC. Also, if we are
323 inside a MEM, we are allowed to replace a sum of a hard register
324 and the constant zero with the hard register, which we cannot do
325 outside a MEM. In addition, we need to record the fact that a
326 hard register is referenced outside a MEM.
328 If we make full substitution to SP for non-null INSN, add the insn
331 lra_eliminate_regs_1 (rtx_insn
*insn
, rtx x
, machine_mode mem_mode
,
332 bool subst_p
, bool update_p
,
333 HOST_WIDE_INT update_sp_offset
, bool full_p
)
335 enum rtx_code code
= GET_CODE (x
);
336 struct lra_elim_table
*ep
;
342 gcc_assert (!update_p
|| !full_p
);
343 if (! current_function_decl
)
361 /* First handle the case where we encounter a bare hard register
362 that is eliminable. Replace it with a PLUS. */
363 if ((ep
= get_elimination (x
)) != NULL
)
365 rtx to
= subst_p
? ep
->to_rtx
: ep
->from_rtx
;
368 return plus_constant (Pmode
, to
,
369 ep
->offset
- ep
->previous_offset
370 + (ep
->to_rtx
== stack_pointer_rtx
371 ? update_sp_offset
: 0));
373 return plus_constant (Pmode
, to
,
376 && ep
->to_rtx
== stack_pointer_rtx
377 ? lra_get_insn_recog_data (insn
)->sp_offset
385 /* If this is the sum of an eliminable register and a constant, rework
387 if (REG_P (XEXP (x
, 0)) && CONSTANT_P (XEXP (x
, 1)))
389 if ((ep
= get_elimination (XEXP (x
, 0))) != NULL
)
391 HOST_WIDE_INT offset
;
392 rtx to
= subst_p
? ep
->to_rtx
: ep
->from_rtx
;
394 if (! update_p
&& ! full_p
)
395 return gen_rtx_PLUS (Pmode
, to
, XEXP (x
, 1));
398 ? ep
->offset
- ep
->previous_offset
399 + (ep
->to_rtx
== stack_pointer_rtx
400 ? update_sp_offset
: 0)
402 if (full_p
&& insn
!= NULL_RTX
&& ep
->to_rtx
== stack_pointer_rtx
)
403 offset
-= lra_get_insn_recog_data (insn
)->sp_offset
;
404 if (CONST_INT_P (XEXP (x
, 1))
405 && INTVAL (XEXP (x
, 1)) == -offset
)
408 return gen_rtx_PLUS (Pmode
, to
,
409 plus_constant (Pmode
,
410 XEXP (x
, 1), offset
));
413 /* If the hard register is not eliminable, we are done since
414 the other operand is a constant. */
418 /* If this is part of an address, we want to bring any constant
419 to the outermost PLUS. We will do this by doing hard
420 register replacement in our operands and seeing if a constant
421 shows up in one of them.
423 Note that there is no risk of modifying the structure of the
424 insn, since we only get called for its operands, thus we are
425 either modifying the address inside a MEM, or something like
426 an address operand of a load-address insn. */
429 rtx new0
= lra_eliminate_regs_1 (insn
, XEXP (x
, 0), mem_mode
,
431 update_sp_offset
, full_p
);
432 rtx new1
= lra_eliminate_regs_1 (insn
, XEXP (x
, 1), mem_mode
,
434 update_sp_offset
, full_p
);
436 if (new0
!= XEXP (x
, 0) || new1
!= XEXP (x
, 1))
437 return form_sum (new0
, new1
);
442 /* If this is the product of an eliminable hard register and a
443 constant, apply the distribute law and move the constant out
444 so that we have (plus (mult ..) ..). This is needed in order
445 to keep load-address insns valid. This case is pathological.
446 We ignore the possibility of overflow here. */
447 if (REG_P (XEXP (x
, 0)) && CONST_INT_P (XEXP (x
, 1))
448 && (ep
= get_elimination (XEXP (x
, 0))) != NULL
)
450 rtx to
= subst_p
? ep
->to_rtx
: ep
->from_rtx
;
453 return plus_constant (Pmode
,
454 gen_rtx_MULT (Pmode
, to
, XEXP (x
, 1)),
455 (ep
->offset
- ep
->previous_offset
456 + (ep
->to_rtx
== stack_pointer_rtx
457 ? update_sp_offset
: 0))
458 * INTVAL (XEXP (x
, 1)));
461 HOST_WIDE_INT offset
= ep
->offset
;
463 if (insn
!= NULL_RTX
&& ep
->to_rtx
== stack_pointer_rtx
)
464 offset
-= lra_get_insn_recog_data (insn
)->sp_offset
;
466 plus_constant (Pmode
,
467 gen_rtx_MULT (Pmode
, to
, XEXP (x
, 1)),
468 offset
* INTVAL (XEXP (x
, 1)));
471 return gen_rtx_MULT (Pmode
, to
, XEXP (x
, 1));
474 /* ... fall through ... */
478 /* See comments before PLUS about handling MINUS. */
482 case AND
: case IOR
: case XOR
:
483 case ROTATERT
: case ROTATE
:
484 case ASHIFTRT
: case LSHIFTRT
: case ASHIFT
:
486 case GE
: case GT
: case GEU
: case GTU
:
487 case LE
: case LT
: case LEU
: case LTU
:
489 rtx new0
= lra_eliminate_regs_1 (insn
, XEXP (x
, 0), mem_mode
,
491 update_sp_offset
, full_p
);
492 rtx new1
= XEXP (x
, 1)
493 ? lra_eliminate_regs_1 (insn
, XEXP (x
, 1), mem_mode
,
495 update_sp_offset
, full_p
) : 0;
497 if (new0
!= XEXP (x
, 0) || new1
!= XEXP (x
, 1))
498 return gen_rtx_fmt_ee (code
, GET_MODE (x
), new0
, new1
);
503 /* If we have something in XEXP (x, 0), the usual case,
507 new_rtx
= lra_eliminate_regs_1 (insn
, XEXP (x
, 0), mem_mode
,
509 update_sp_offset
, full_p
);
510 if (new_rtx
!= XEXP (x
, 0))
512 /* If this is a REG_DEAD note, it is not valid anymore.
513 Using the eliminated version could result in creating a
514 REG_DEAD note for the stack or frame pointer. */
515 if (REG_NOTE_KIND (x
) == REG_DEAD
)
517 ? lra_eliminate_regs_1 (insn
, XEXP (x
, 1), mem_mode
,
519 update_sp_offset
, full_p
)
522 x
= alloc_reg_note (REG_NOTE_KIND (x
), new_rtx
, XEXP (x
, 1));
526 /* ... fall through ... */
530 /* Now do eliminations in the rest of the chain. If this was
531 an EXPR_LIST, this might result in allocating more memory than is
532 strictly needed, but it simplifies the code. */
535 new_rtx
= lra_eliminate_regs_1 (insn
, XEXP (x
, 1), mem_mode
,
537 update_sp_offset
, full_p
);
538 if (new_rtx
!= XEXP (x
, 1))
540 gen_rtx_fmt_ee (GET_CODE (x
), GET_MODE (x
),
541 XEXP (x
, 0), new_rtx
);
549 /* We do not support elimination of a register that is modified.
550 elimination_effects has already make sure that this does not
556 /* We do not support elimination of a hard register that is
557 modified. LRA has already make sure that this does not
558 happen. The only remaining case we need to consider here is
559 that the increment value may be an eliminable register. */
560 if (GET_CODE (XEXP (x
, 1)) == PLUS
561 && XEXP (XEXP (x
, 1), 0) == XEXP (x
, 0))
563 rtx new_rtx
= lra_eliminate_regs_1 (insn
, XEXP (XEXP (x
, 1), 1),
564 mem_mode
, subst_p
, update_p
,
565 update_sp_offset
, full_p
);
567 if (new_rtx
!= XEXP (XEXP (x
, 1), 1))
568 return gen_rtx_fmt_ee (code
, GET_MODE (x
), XEXP (x
, 0),
569 gen_rtx_PLUS (GET_MODE (x
),
570 XEXP (x
, 0), new_rtx
));
574 case STRICT_LOW_PART
:
576 case SIGN_EXTEND
: case ZERO_EXTEND
:
577 case TRUNCATE
: case FLOAT_EXTEND
: case FLOAT_TRUNCATE
:
578 case FLOAT
: case FIX
:
579 case UNSIGNED_FIX
: case UNSIGNED_FLOAT
:
588 new_rtx
= lra_eliminate_regs_1 (insn
, XEXP (x
, 0), mem_mode
,
590 update_sp_offset
, full_p
);
591 if (new_rtx
!= XEXP (x
, 0))
592 return gen_rtx_fmt_e (code
, GET_MODE (x
), new_rtx
);
596 new_rtx
= lra_eliminate_regs_1 (insn
, SUBREG_REG (x
), mem_mode
,
598 update_sp_offset
, full_p
);
600 if (new_rtx
!= SUBREG_REG (x
))
602 int x_size
= GET_MODE_SIZE (GET_MODE (x
));
603 int new_size
= GET_MODE_SIZE (GET_MODE (new_rtx
));
605 if (MEM_P (new_rtx
) && x_size
<= new_size
)
607 SUBREG_REG (x
) = new_rtx
;
608 alter_subreg (&x
, false);
613 /* LRA can transform subregs itself. So don't call
614 simplify_gen_subreg until LRA transformations are
615 finished. Function simplify_gen_subreg can do
616 non-trivial transformations (like truncation) which
617 might make LRA work to fail. */
618 SUBREG_REG (x
) = new_rtx
;
622 return simplify_gen_subreg (GET_MODE (x
), new_rtx
,
623 GET_MODE (new_rtx
), SUBREG_BYTE (x
));
629 /* Our only special processing is to pass the mode of the MEM to our
630 recursive call and copy the flags. While we are here, handle this
631 case more efficiently. */
633 replace_equiv_address_nv
635 lra_eliminate_regs_1 (insn
, XEXP (x
, 0), GET_MODE (x
),
636 subst_p
, update_p
, update_sp_offset
, full_p
));
639 /* Handle insn_list USE that a call to a pure function may generate. */
640 new_rtx
= lra_eliminate_regs_1 (insn
, XEXP (x
, 0), VOIDmode
,
641 subst_p
, update_p
, update_sp_offset
, full_p
);
642 if (new_rtx
!= XEXP (x
, 0))
643 return gen_rtx_USE (GET_MODE (x
), new_rtx
);
654 /* Process each of our operands recursively. If any have changed, make a
656 fmt
= GET_RTX_FORMAT (code
);
657 for (i
= 0; i
< GET_RTX_LENGTH (code
); i
++, fmt
++)
661 new_rtx
= lra_eliminate_regs_1 (insn
, XEXP (x
, i
), mem_mode
,
663 update_sp_offset
, full_p
);
664 if (new_rtx
!= XEXP (x
, i
) && ! copied
)
666 x
= shallow_copy_rtx (x
);
669 XEXP (x
, i
) = new_rtx
;
671 else if (*fmt
== 'E')
674 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
676 new_rtx
= lra_eliminate_regs_1 (insn
, XVECEXP (x
, i
, j
), mem_mode
,
678 update_sp_offset
, full_p
);
679 if (new_rtx
!= XVECEXP (x
, i
, j
) && ! copied_vec
)
681 rtvec new_v
= gen_rtvec_v (XVECLEN (x
, i
),
685 x
= shallow_copy_rtx (x
);
691 XVECEXP (x
, i
, j
) = new_rtx
;
699 /* This function is used externally in subsequent passes of GCC. It
700 always does a full elimination of X. */
702 lra_eliminate_regs (rtx x
, machine_mode mem_mode
,
703 rtx insn ATTRIBUTE_UNUSED
)
705 return lra_eliminate_regs_1 (NULL
, x
, mem_mode
, true, false, 0, true);
708 /* Stack pointer offset before the current insn relative to one at the
709 func start. RTL insns can change SP explicitly. We keep the
710 changes from one insn to another through this variable. */
711 static HOST_WIDE_INT curr_sp_change
;
713 /* Scan rtx X for references to elimination source or target registers
714 in contexts that would prevent the elimination from happening.
715 Update the table of eliminables to reflect the changed state.
716 MEM_MODE is the mode of an enclosing MEM rtx, or VOIDmode if not
719 mark_not_eliminable (rtx x
, machine_mode mem_mode
)
721 enum rtx_code code
= GET_CODE (x
);
722 struct lra_elim_table
*ep
;
734 if (XEXP (x
, 0) == stack_pointer_rtx
735 && ((code
!= PRE_MODIFY
&& code
!= POST_MODIFY
)
736 || (GET_CODE (XEXP (x
, 1)) == PLUS
737 && XEXP (x
, 0) == XEXP (XEXP (x
, 1), 0)
738 && CONST_INT_P (XEXP (XEXP (x
, 1), 1)))))
740 int size
= GET_MODE_SIZE (mem_mode
);
743 /* If more bytes than MEM_MODE are pushed, account for
745 size
= PUSH_ROUNDING (size
);
747 if (code
== PRE_DEC
|| code
== POST_DEC
)
748 curr_sp_change
-= size
;
749 else if (code
== PRE_INC
|| code
== POST_INC
)
750 curr_sp_change
+= size
;
751 else if (code
== PRE_MODIFY
|| code
== POST_MODIFY
)
752 curr_sp_change
+= INTVAL (XEXP (XEXP (x
, 1), 1));
754 else if (REG_P (XEXP (x
, 0))
755 && REGNO (XEXP (x
, 0)) >= FIRST_PSEUDO_REGISTER
)
757 /* If we modify the source of an elimination rule, disable
758 it. Do the same if it is the destination and not the
759 hard frame register. */
760 for (ep
= reg_eliminate
;
761 ep
< ®_eliminate
[NUM_ELIMINABLE_REGS
];
763 if (ep
->from_rtx
== XEXP (x
, 0)
764 || (ep
->to_rtx
== XEXP (x
, 0)
765 && ep
->to_rtx
!= hard_frame_pointer_rtx
))
766 setup_can_eliminate (ep
, false);
771 if (REG_P (XEXP (x
, 0)) && REGNO (XEXP (x
, 0)) < FIRST_PSEUDO_REGISTER
)
772 /* If using a hard register that is the source of an eliminate
773 we still think can be performed, note it cannot be
774 performed since we don't know how this hard register is
776 for (ep
= reg_eliminate
;
777 ep
< ®_eliminate
[NUM_ELIMINABLE_REGS
];
779 if (ep
->from_rtx
== XEXP (x
, 0)
780 && ep
->to_rtx
!= hard_frame_pointer_rtx
)
781 setup_can_eliminate (ep
, false);
785 if (REG_P (XEXP (x
, 0)) && REGNO (XEXP (x
, 0)) < FIRST_PSEUDO_REGISTER
)
786 /* If clobbering a hard register that is the replacement
787 register for an elimination we still think can be
788 performed, note that it cannot be performed. Otherwise, we
789 need not be concerned about it. */
790 for (ep
= reg_eliminate
;
791 ep
< ®_eliminate
[NUM_ELIMINABLE_REGS
];
793 if (ep
->to_rtx
== XEXP (x
, 0)
794 && ep
->to_rtx
!= hard_frame_pointer_rtx
)
795 setup_can_eliminate (ep
, false);
799 if (SET_DEST (x
) == stack_pointer_rtx
800 && GET_CODE (SET_SRC (x
)) == PLUS
801 && XEXP (SET_SRC (x
), 0) == SET_DEST (x
)
802 && CONST_INT_P (XEXP (SET_SRC (x
), 1)))
804 curr_sp_change
+= INTVAL (XEXP (SET_SRC (x
), 1));
807 if (! REG_P (SET_DEST (x
))
808 || REGNO (SET_DEST (x
)) >= FIRST_PSEUDO_REGISTER
)
809 mark_not_eliminable (SET_DEST (x
), mem_mode
);
812 /* See if this is setting the replacement hard register for
815 If DEST is the hard frame pointer, we do nothing because
816 we assume that all assignments to the frame pointer are
817 for non-local gotos and are being done at a time when
818 they are valid and do not disturb anything else. Some
819 machines want to eliminate a fake argument pointer (or
820 even a fake frame pointer) with either the real frame
821 pointer or the stack pointer. Assignments to the hard
822 frame pointer must not prevent this elimination. */
823 for (ep
= reg_eliminate
;
824 ep
< ®_eliminate
[NUM_ELIMINABLE_REGS
];
826 if (ep
->to_rtx
== SET_DEST (x
)
827 && SET_DEST (x
) != hard_frame_pointer_rtx
)
828 setup_can_eliminate (ep
, false);
831 mark_not_eliminable (SET_SRC (x
), mem_mode
);
835 /* Our only special processing is to pass the mode of the MEM to
836 our recursive call. */
837 mark_not_eliminable (XEXP (x
, 0), GET_MODE (x
));
844 fmt
= GET_RTX_FORMAT (code
);
845 for (i
= 0; i
< GET_RTX_LENGTH (code
); i
++, fmt
++)
848 mark_not_eliminable (XEXP (x
, i
), mem_mode
);
849 else if (*fmt
== 'E')
850 for (j
= 0; j
< XVECLEN (x
, i
); j
++)
851 mark_not_eliminable (XVECEXP (x
, i
, j
), mem_mode
);
857 #ifdef HARD_FRAME_POINTER_REGNUM
859 /* Find offset equivalence note for reg WHAT in INSN and return the
860 found elmination offset. If the note is not found, return NULL.
861 Remove the found note. */
863 remove_reg_equal_offset_note (rtx insn
, rtx what
)
867 for (link_loc
= ®_NOTES (insn
);
868 (link
= *link_loc
) != NULL_RTX
;
869 link_loc
= &XEXP (link
, 1))
870 if (REG_NOTE_KIND (link
) == REG_EQUAL
871 && GET_CODE (XEXP (link
, 0)) == PLUS
872 && XEXP (XEXP (link
, 0), 0) == what
873 && CONST_INT_P (XEXP (XEXP (link
, 0), 1)))
875 *link_loc
= XEXP (link
, 1);
876 return XEXP (XEXP (link
, 0), 1);
883 /* Scan INSN and eliminate all eliminable hard registers in it.
885 If REPLACE_P is true, do the replacement destructively. Also
886 delete the insn as dead it if it is setting an eliminable register.
888 If REPLACE_P is false, just update the offsets while keeping the
889 base register the same. If FIRST_P, use the sp offset for
890 elimination to sp. Otherwise, use UPDATE_SP_OFFSET for this.
891 Attach the note about used elimination for insns setting frame
892 pointer to update elimination easy (without parsing already
893 generated elimination insns to find offset previously used) in
897 eliminate_regs_in_insn (rtx_insn
*insn
, bool replace_p
, bool first_p
,
898 HOST_WIDE_INT update_sp_offset
)
900 int icode
= recog_memoized (insn
);
901 rtx old_set
= single_set (insn
);
904 rtx substed_operand
[MAX_RECOG_OPERANDS
];
905 rtx orig_operand
[MAX_RECOG_OPERANDS
];
906 struct lra_elim_table
*ep
;
907 rtx plus_src
, plus_cst_src
;
908 lra_insn_recog_data_t id
;
909 struct lra_static_insn_data
*static_id
;
911 if (icode
< 0 && asm_noperands (PATTERN (insn
)) < 0 && ! DEBUG_INSN_P (insn
))
913 lra_assert (GET_CODE (PATTERN (insn
)) == USE
914 || GET_CODE (PATTERN (insn
)) == CLOBBER
915 || GET_CODE (PATTERN (insn
)) == ASM_INPUT
);
919 /* Check for setting an eliminable register. */
920 if (old_set
!= 0 && REG_P (SET_DEST (old_set
))
921 && (ep
= get_elimination (SET_DEST (old_set
))) != NULL
)
923 for (ep
= reg_eliminate
; ep
< ®_eliminate
[NUM_ELIMINABLE_REGS
]; ep
++)
924 if (ep
->from_rtx
== SET_DEST (old_set
) && ep
->can_eliminate
)
926 bool delete_p
= replace_p
;
928 #ifdef HARD_FRAME_POINTER_REGNUM
929 if (ep
->from
== FRAME_POINTER_REGNUM
930 && ep
->to
== HARD_FRAME_POINTER_REGNUM
)
931 /* If this is setting the frame pointer register to the
932 hardware frame pointer register and this is an
933 elimination that will be done (tested above), this
934 insn is really adjusting the frame pointer downward
935 to compensate for the adjustment done before a
938 rtx src
= SET_SRC (old_set
);
939 rtx off
= remove_reg_equal_offset_note (insn
, ep
->to_rtx
);
943 || (GET_CODE (src
) == PLUS
944 && XEXP (src
, 0) == ep
->to_rtx
945 && CONST_INT_P (XEXP (src
, 1))))
947 HOST_WIDE_INT offset
;
951 SET_DEST (old_set
) = ep
->to_rtx
;
952 lra_update_insn_recog_data (insn
);
955 offset
= (off
!= NULL_RTX
? INTVAL (off
)
956 : src
== ep
->to_rtx
? 0 : INTVAL (XEXP (src
, 1)));
957 offset
-= (ep
->offset
- ep
->previous_offset
);
958 src
= plus_constant (Pmode
, ep
->to_rtx
, offset
);
960 /* First see if this insn remains valid when we
961 make the change. If not, keep the INSN_CODE
962 the same and let the constraint pass fit it
964 validate_change (insn
, &SET_SRC (old_set
), src
, 1);
965 validate_change (insn
, &SET_DEST (old_set
),
967 if (! apply_change_group ())
969 SET_SRC (old_set
) = src
;
970 SET_DEST (old_set
) = ep
->from_rtx
;
972 lra_update_insn_recog_data (insn
);
973 /* Add offset note for future updates. */
974 add_reg_note (insn
, REG_EQUAL
, src
);
980 /* This insn isn't serving a useful purpose. We delete it
981 when REPLACE is set. */
983 lra_delete_dead_insn (insn
);
988 /* We allow one special case which happens to work on all machines we
989 currently support: a single set with the source or a REG_EQUAL
990 note being a PLUS of an eliminable register and a constant. */
991 plus_src
= plus_cst_src
= 0;
992 if (old_set
&& REG_P (SET_DEST (old_set
)))
994 if (GET_CODE (SET_SRC (old_set
)) == PLUS
)
995 plus_src
= SET_SRC (old_set
);
996 /* First see if the source is of the form (plus (...) CST). */
998 && CONST_INT_P (XEXP (plus_src
, 1)))
999 plus_cst_src
= plus_src
;
1000 /* Check that the first operand of the PLUS is a hard reg or
1001 the lowpart subreg of one. */
1004 rtx reg
= XEXP (plus_cst_src
, 0);
1006 if (GET_CODE (reg
) == SUBREG
&& subreg_lowpart_p (reg
))
1007 reg
= SUBREG_REG (reg
);
1009 if (!REG_P (reg
) || REGNO (reg
) >= FIRST_PSEUDO_REGISTER
)
1015 rtx reg
= XEXP (plus_cst_src
, 0);
1016 HOST_WIDE_INT offset
= INTVAL (XEXP (plus_cst_src
, 1));
1018 if (GET_CODE (reg
) == SUBREG
)
1019 reg
= SUBREG_REG (reg
);
1021 if (REG_P (reg
) && (ep
= get_elimination (reg
)) != NULL
)
1023 rtx to_rtx
= replace_p
? ep
->to_rtx
: ep
->from_rtx
;
1027 offset
+= (ep
->offset
- ep
->previous_offset
);
1028 if (ep
->to_rtx
== stack_pointer_rtx
)
1031 offset
-= lra_get_insn_recog_data (insn
)->sp_offset
;
1033 offset
+= update_sp_offset
;
1035 offset
= trunc_int_for_mode (offset
, GET_MODE (plus_cst_src
));
1038 if (GET_CODE (XEXP (plus_cst_src
, 0)) == SUBREG
)
1039 to_rtx
= gen_lowpart (GET_MODE (XEXP (plus_cst_src
, 0)), to_rtx
);
1040 /* If we have a nonzero offset, and the source is already a
1041 simple REG, the following transformation would increase
1042 the cost of the insn by replacing a simple REG with (plus
1043 (reg sp) CST). So try only when we already had a PLUS
1045 if (offset
== 0 || plus_src
)
1047 rtx new_src
= plus_constant (GET_MODE (to_rtx
), to_rtx
, offset
);
1049 old_set
= single_set (insn
);
1051 /* First see if this insn remains valid when we make the
1052 change. If not, try to replace the whole pattern
1053 with a simple set (this may help if the original insn
1054 was a PARALLEL that was only recognized as single_set
1055 due to REG_UNUSED notes). If this isn't valid
1056 either, keep the INSN_CODE the same and let the
1057 constraint pass fix it up. */
1058 if (! validate_change (insn
, &SET_SRC (old_set
), new_src
, 0))
1060 rtx new_pat
= gen_rtx_SET (VOIDmode
,
1061 SET_DEST (old_set
), new_src
);
1063 if (! validate_change (insn
, &PATTERN (insn
), new_pat
, 0))
1064 SET_SRC (old_set
) = new_src
;
1066 lra_update_insn_recog_data (insn
);
1067 /* This can't have an effect on elimination offsets, so skip
1068 right to the end. */
1074 /* Eliminate all eliminable registers occurring in operands that
1075 can be handled by the constraint pass. */
1076 id
= lra_get_insn_recog_data (insn
);
1077 static_id
= id
->insn_static_data
;
1079 for (i
= 0; i
< static_id
->n_operands
; i
++)
1081 orig_operand
[i
] = *id
->operand_loc
[i
];
1082 substed_operand
[i
] = *id
->operand_loc
[i
];
1084 /* For an asm statement, every operand is eliminable. */
1085 if (icode
< 0 || insn_data
[icode
].operand
[i
].eliminable
)
1087 /* Check for setting a hard register that we know about. */
1088 if (static_id
->operand
[i
].type
!= OP_IN
1089 && REG_P (orig_operand
[i
]))
1091 /* If we are assigning to a hard register that can be
1092 eliminated, it must be as part of a PARALLEL, since
1093 the code above handles single SETs. This reg can not
1094 be longer eliminated -- it is forced by
1095 mark_not_eliminable. */
1096 for (ep
= reg_eliminate
;
1097 ep
< ®_eliminate
[NUM_ELIMINABLE_REGS
];
1099 lra_assert (ep
->from_rtx
!= orig_operand
[i
]
1100 || ! ep
->can_eliminate
);
1103 /* Companion to the above plus substitution, we can allow
1104 invariants as the source of a plain move. */
1106 = lra_eliminate_regs_1 (insn
, *id
->operand_loc
[i
], VOIDmode
,
1107 replace_p
, ! replace_p
&& ! first_p
,
1108 update_sp_offset
, first_p
);
1109 if (substed_operand
[i
] != orig_operand
[i
])
1117 /* Substitute the operands; the new values are in the substed_operand
1119 for (i
= 0; i
< static_id
->n_operands
; i
++)
1120 *id
->operand_loc
[i
] = substed_operand
[i
];
1121 for (i
= 0; i
< static_id
->n_dups
; i
++)
1122 *id
->dup_loc
[i
] = substed_operand
[(int) static_id
->dup_num
[i
]];
1124 /* If we had a move insn but now we don't, re-recognize it.
1125 This will cause spurious re-recognition if the old move had a
1126 PARALLEL since the new one still will, but we can't call
1127 single_set without having put new body into the insn and the
1128 re-recognition won't hurt in this rare case. */
1129 id
= lra_update_insn_recog_data (insn
);
1130 static_id
= id
->insn_static_data
;
1133 /* Spill pseudos which are assigned to hard registers in SET. Add
1134 affected insns for processing in the subsequent constraint
1137 spill_pseudos (HARD_REG_SET set
)
1140 bitmap_head to_process
;
1143 if (hard_reg_set_empty_p (set
))
1145 if (lra_dump_file
!= NULL
)
1147 fprintf (lra_dump_file
, " Spilling non-eliminable hard regs:");
1148 for (i
= 0; i
< FIRST_PSEUDO_REGISTER
; i
++)
1149 if (TEST_HARD_REG_BIT (set
, i
))
1150 fprintf (lra_dump_file
, " %d", i
);
1151 fprintf (lra_dump_file
, "\n");
1153 bitmap_initialize (&to_process
, ®_obstack
);
1154 for (i
= FIRST_PSEUDO_REGISTER
; i
< max_reg_num (); i
++)
1155 if (lra_reg_info
[i
].nrefs
!= 0 && reg_renumber
[i
] >= 0
1156 && overlaps_hard_reg_set_p (set
,
1157 PSEUDO_REGNO_MODE (i
), reg_renumber
[i
]))
1159 if (lra_dump_file
!= NULL
)
1160 fprintf (lra_dump_file
, " Spilling r%d(%d)\n",
1161 i
, reg_renumber
[i
]);
1162 reg_renumber
[i
] = -1;
1163 bitmap_ior_into (&to_process
, &lra_reg_info
[i
].insn_bitmap
);
1165 IOR_HARD_REG_SET (lra_no_alloc_regs
, set
);
1166 for (insn
= get_insns (); insn
!= NULL_RTX
; insn
= NEXT_INSN (insn
))
1167 if (bitmap_bit_p (&to_process
, INSN_UID (insn
)))
1169 lra_push_insn (insn
);
1170 lra_set_used_insn_alternative (insn
, -1);
1172 bitmap_clear (&to_process
);
1175 /* Update all offsets and possibility for elimination on eliminable
1176 registers. Spill pseudos assigned to registers which are
1177 uneliminable, update LRA_NO_ALLOC_REGS and ELIMINABLE_REG_SET. Add
1178 insns to INSNS_WITH_CHANGED_OFFSETS containing eliminable hard
1179 registers whose offsets should be changed. Return true if any
1180 elimination offset changed. */
1182 update_reg_eliminate (bitmap insns_with_changed_offsets
)
1185 struct lra_elim_table
*ep
, *ep1
;
1186 HARD_REG_SET temp_hard_reg_set
;
1188 /* Clear self elimination offsets. */
1189 for (ep
= reg_eliminate
; ep
< ®_eliminate
[NUM_ELIMINABLE_REGS
]; ep
++)
1190 self_elim_offsets
[ep
->from
] = 0;
1191 for (ep
= reg_eliminate
; ep
< ®_eliminate
[NUM_ELIMINABLE_REGS
]; ep
++)
1193 /* If it is a currently used elimination: update the previous
1195 if (elimination_map
[ep
->from
] == ep
)
1196 ep
->previous_offset
= ep
->offset
;
1198 prev
= ep
->prev_can_eliminate
;
1199 setup_can_eliminate (ep
, targetm
.can_eliminate (ep
->from
, ep
->to
));
1200 if (ep
->can_eliminate
&& ! prev
)
1202 /* It is possible that not eliminable register becomes
1203 eliminable because we took other reasons into account to
1204 set up eliminable regs in the initial set up. Just
1205 ignore new eliminable registers. */
1206 setup_can_eliminate (ep
, false);
1209 if (ep
->can_eliminate
!= prev
&& elimination_map
[ep
->from
] == ep
)
1211 /* We cannot use this elimination anymore -- find another
1213 if (lra_dump_file
!= NULL
)
1214 fprintf (lra_dump_file
,
1215 " Elimination %d to %d is not possible anymore\n",
1217 /* If after processing RTL we decides that SP can be used as
1218 a result of elimination, it can not be changed. */
1219 gcc_assert ((ep
->to_rtx
!= stack_pointer_rtx
)
1220 || (ep
->from
< FIRST_PSEUDO_REGISTER
1221 && fixed_regs
[ep
->from
]));
1222 /* Mark that is not eliminable anymore. */
1223 elimination_map
[ep
->from
] = NULL
;
1224 for (ep1
= ep
+ 1; ep1
< ®_eliminate
[NUM_ELIMINABLE_REGS
]; ep1
++)
1225 if (ep1
->can_eliminate
&& ep1
->from
== ep
->from
)
1227 if (ep1
< ®_eliminate
[NUM_ELIMINABLE_REGS
])
1229 if (lra_dump_file
!= NULL
)
1230 fprintf (lra_dump_file
, " Using elimination %d to %d now\n",
1231 ep1
->from
, ep1
->to
);
1232 lra_assert (ep1
->previous_offset
== 0);
1233 ep1
->previous_offset
= ep
->offset
;
1237 /* There is no elimination anymore just use the hard
1238 register `from' itself. Setup self elimination
1239 offset to restore the original offset values. */
1240 if (lra_dump_file
!= NULL
)
1241 fprintf (lra_dump_file
, " %d is not eliminable at all\n",
1243 self_elim_offsets
[ep
->from
] = -ep
->offset
;
1244 if (ep
->offset
!= 0)
1245 bitmap_ior_into (insns_with_changed_offsets
,
1246 &lra_reg_info
[ep
->from
].insn_bitmap
);
1250 #ifdef ELIMINABLE_REGS
1251 INITIAL_ELIMINATION_OFFSET (ep
->from
, ep
->to
, ep
->offset
);
1253 INITIAL_FRAME_POINTER_OFFSET (ep
->offset
);
1256 setup_elimination_map ();
1258 CLEAR_HARD_REG_SET (temp_hard_reg_set
);
1259 for (ep
= reg_eliminate
; ep
< ®_eliminate
[NUM_ELIMINABLE_REGS
]; ep
++)
1260 if (elimination_map
[ep
->from
] == NULL
)
1261 SET_HARD_REG_BIT (temp_hard_reg_set
, ep
->from
);
1262 else if (elimination_map
[ep
->from
] == ep
)
1264 /* Prevent the hard register into which we eliminate from
1265 the usage for pseudos. */
1266 if (ep
->from
!= ep
->to
)
1267 SET_HARD_REG_BIT (temp_hard_reg_set
, ep
->to
);
1268 if (ep
->previous_offset
!= ep
->offset
)
1270 bitmap_ior_into (insns_with_changed_offsets
,
1271 &lra_reg_info
[ep
->from
].insn_bitmap
);
1273 /* Update offset when the eliminate offset have been
1275 lra_update_reg_val_offset (lra_reg_info
[ep
->from
].val
,
1276 ep
->offset
- ep
->previous_offset
);
1280 IOR_HARD_REG_SET (lra_no_alloc_regs
, temp_hard_reg_set
);
1281 AND_COMPL_HARD_REG_SET (eliminable_regset
, temp_hard_reg_set
);
1282 spill_pseudos (temp_hard_reg_set
);
1286 /* Initialize the table of hard registers to eliminate.
1287 Pre-condition: global flag frame_pointer_needed has been set before
1288 calling this function. */
1290 init_elim_table (void)
1292 struct lra_elim_table
*ep
;
1293 #ifdef ELIMINABLE_REGS
1295 const struct elim_table_1
*ep1
;
1299 reg_eliminate
= XCNEWVEC (struct lra_elim_table
, NUM_ELIMINABLE_REGS
);
1301 memset (self_elim_offsets
, 0, sizeof (self_elim_offsets
));
1302 /* Initiate member values which will be never changed. */
1303 self_elim_table
.can_eliminate
= self_elim_table
.prev_can_eliminate
= true;
1304 self_elim_table
.previous_offset
= 0;
1305 #ifdef ELIMINABLE_REGS
1306 for (ep
= reg_eliminate
, ep1
= reg_eliminate_1
;
1307 ep
< ®_eliminate
[NUM_ELIMINABLE_REGS
]; ep
++, ep1
++)
1309 ep
->offset
= ep
->previous_offset
= 0;
1310 ep
->from
= ep1
->from
;
1312 value_p
= (targetm
.can_eliminate (ep
->from
, ep
->to
)
1313 && ! (ep
->to
== STACK_POINTER_REGNUM
1314 && frame_pointer_needed
1315 && (! SUPPORTS_STACK_ALIGNMENT
1316 || ! stack_realign_fp
)));
1317 setup_can_eliminate (ep
, value_p
);
1320 reg_eliminate
[0].offset
= reg_eliminate
[0].previous_offset
= 0;
1321 reg_eliminate
[0].from
= reg_eliminate_1
[0].from
;
1322 reg_eliminate
[0].to
= reg_eliminate_1
[0].to
;
1323 setup_can_eliminate (®_eliminate
[0], ! frame_pointer_needed
);
1326 /* Build the FROM and TO REG rtx's. Note that code in gen_rtx_REG
1327 will cause, e.g., gen_rtx_REG (Pmode, STACK_POINTER_REGNUM) to
1328 equal stack_pointer_rtx. We depend on this. Threfore we switch
1329 off that we are in LRA temporarily. */
1330 lra_in_progress
= 0;
1331 for (ep
= reg_eliminate
; ep
< ®_eliminate
[NUM_ELIMINABLE_REGS
]; ep
++)
1333 ep
->from_rtx
= gen_rtx_REG (Pmode
, ep
->from
);
1334 ep
->to_rtx
= gen_rtx_REG (Pmode
, ep
->to
);
1335 eliminable_reg_rtx
[ep
->from
] = ep
->from_rtx
;
1337 lra_in_progress
= 1;
1340 /* Function for initialization of elimination once per function. It
1341 sets up sp offset for each insn. */
1343 init_elimination (void)
1345 bool stop_to_sp_elimination_p
;
1348 struct lra_elim_table
*ep
;
1351 FOR_EACH_BB_FN (bb
, cfun
)
1354 stop_to_sp_elimination_p
= false;
1355 FOR_BB_INSNS (bb
, insn
)
1358 lra_get_insn_recog_data (insn
)->sp_offset
= curr_sp_change
;
1359 if (NONDEBUG_INSN_P (insn
))
1361 mark_not_eliminable (PATTERN (insn
), VOIDmode
);
1362 if (curr_sp_change
!= 0
1363 && find_reg_note (insn
, REG_LABEL_OPERAND
, NULL_RTX
))
1364 stop_to_sp_elimination_p
= true;
1367 if (! frame_pointer_needed
1368 && (curr_sp_change
!= 0 || stop_to_sp_elimination_p
)
1369 && bb
->succs
&& bb
->succs
->length () != 0)
1370 for (ep
= reg_eliminate
; ep
< ®_eliminate
[NUM_ELIMINABLE_REGS
]; ep
++)
1371 if (ep
->to
== STACK_POINTER_REGNUM
)
1372 setup_can_eliminate (ep
, false);
1374 setup_elimination_map ();
1377 /* Eliminate hard reg given by its location LOC. */
1379 lra_eliminate_reg_if_possible (rtx
*loc
)
1382 struct lra_elim_table
*ep
;
1384 lra_assert (REG_P (*loc
));
1385 if ((regno
= REGNO (*loc
)) >= FIRST_PSEUDO_REGISTER
1386 || ! TEST_HARD_REG_BIT (lra_no_alloc_regs
, regno
))
1388 if ((ep
= get_elimination (*loc
)) != NULL
)
1392 /* Do (final if FINAL_P or first if FIRST_P) elimination in INSN. Add
1393 the insn for subsequent processing in the constraint pass, update
1396 process_insn_for_elimination (rtx_insn
*insn
, bool final_p
, bool first_p
)
1398 eliminate_regs_in_insn (insn
, final_p
, first_p
, 0);
1401 /* Check that insn changed its code. This is a case when a move
1402 insn becomes an add insn and we do not want to process the
1403 insn as a move anymore. */
1404 int icode
= recog (PATTERN (insn
), insn
, 0);
1406 if (icode
>= 0 && icode
!= INSN_CODE (insn
))
1408 INSN_CODE (insn
) = icode
;
1409 lra_update_insn_recog_data (insn
);
1411 lra_update_insn_regno_info (insn
);
1412 lra_push_insn (insn
);
1413 lra_set_used_insn_alternative (insn
, -1);
1417 /* Entry function to do final elimination if FINAL_P or to update
1418 elimination register offsets (FIRST_P if we are doing it the first
1421 lra_eliminate (bool final_p
, bool first_p
)
1424 bitmap_head insns_with_changed_offsets
;
1426 struct lra_elim_table
*ep
;
1428 gcc_assert (! final_p
|| ! first_p
);
1430 timevar_push (TV_LRA_ELIMINATE
);
1433 init_elimination ();
1435 bitmap_initialize (&insns_with_changed_offsets
, ®_obstack
);
1438 #ifdef ENABLE_CHECKING
1439 update_reg_eliminate (&insns_with_changed_offsets
);
1440 if (! bitmap_empty_p (&insns_with_changed_offsets
))
1443 /* We change eliminable hard registers in insns so we should do
1444 this for all insns containing any eliminable hard
1446 for (ep
= reg_eliminate
; ep
< ®_eliminate
[NUM_ELIMINABLE_REGS
]; ep
++)
1447 if (elimination_map
[ep
->from
] != NULL
)
1448 bitmap_ior_into (&insns_with_changed_offsets
,
1449 &lra_reg_info
[ep
->from
].insn_bitmap
);
1451 else if (! update_reg_eliminate (&insns_with_changed_offsets
))
1452 goto lra_eliminate_done
;
1453 if (lra_dump_file
!= NULL
)
1455 fprintf (lra_dump_file
, "New elimination table:\n");
1456 print_elim_table (lra_dump_file
);
1458 EXECUTE_IF_SET_IN_BITMAP (&insns_with_changed_offsets
, 0, uid
, bi
)
1459 /* A dead insn can be deleted in process_insn_for_elimination. */
1460 if (lra_insn_recog_data
[uid
] != NULL
)
1461 process_insn_for_elimination (lra_insn_recog_data
[uid
]->insn
,
1463 bitmap_clear (&insns_with_changed_offsets
);
1466 timevar_pop (TV_LRA_ELIMINATE
);