annotate gcc/lra-eliminations.c @ 111:04ced10e8804

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