annotate gcc/lra.c @ 16: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
16
kono
parents:
diff changeset
1 /* LRA (local register allocator) driver and LRA utilities.
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
kono
parents:
diff changeset
22 /* The Local Register Allocator (LRA) is a replacement of former
kono
parents:
diff changeset
23 reload pass. It is focused to simplify code solving the reload
kono
parents:
diff changeset
24 pass tasks, to make the code maintenance easier, and to implement new
kono
parents:
diff changeset
25 perspective optimizations.
kono
parents:
diff changeset
26
kono
parents:
diff changeset
27 The major LRA design solutions are:
kono
parents:
diff changeset
28 o division small manageable, separated sub-tasks
kono
parents:
diff changeset
29 o reflection of all transformations and decisions in RTL as more
kono
parents:
diff changeset
30 as possible
kono
parents:
diff changeset
31 o insn constraints as a primary source of the info (minimizing
kono
parents:
diff changeset
32 number of target-depended macros/hooks)
kono
parents:
diff changeset
33
kono
parents:
diff changeset
34 In brief LRA works by iterative insn process with the final goal is
kono
parents:
diff changeset
35 to satisfy all insn and address constraints:
kono
parents:
diff changeset
36 o New reload insns (in brief reloads) and reload pseudos might be
kono
parents:
diff changeset
37 generated;
kono
parents:
diff changeset
38 o Some pseudos might be spilled to assign hard registers to
kono
parents:
diff changeset
39 new reload pseudos;
kono
parents:
diff changeset
40 o Recalculating spilled pseudo values (rematerialization);
kono
parents:
diff changeset
41 o Changing spilled pseudos to stack memory or their equivalences;
kono
parents:
diff changeset
42 o Allocation stack memory changes the address displacement and
kono
parents:
diff changeset
43 new iteration is needed.
kono
parents:
diff changeset
44
kono
parents:
diff changeset
45 Here is block diagram of LRA passes:
kono
parents:
diff changeset
46
kono
parents:
diff changeset
47 ------------------------
kono
parents:
diff changeset
48 --------------- | Undo inheritance for | ---------------
kono
parents:
diff changeset
49 | Memory-memory | | spilled pseudos, | | New (and old) |
kono
parents:
diff changeset
50 | move coalesce |<---| splits for pseudos got |<-- | pseudos |
kono
parents:
diff changeset
51 --------------- | the same hard regs, | | assignment |
kono
parents:
diff changeset
52 Start | | and optional reloads | ---------------
kono
parents:
diff changeset
53 | | ------------------------ ^
kono
parents:
diff changeset
54 V | ---------------- |
kono
parents:
diff changeset
55 ----------- V | Update virtual | |
kono
parents:
diff changeset
56 | Remove |----> ------------>| register | |
kono
parents:
diff changeset
57 | scratches | ^ | displacements | |
kono
parents:
diff changeset
58 ----------- | ---------------- |
kono
parents:
diff changeset
59 | | |
kono
parents:
diff changeset
60 | V New |
kono
parents:
diff changeset
61 | ------------ pseudos -------------------
kono
parents:
diff changeset
62 | |Constraints:| or insns | Inheritance/split |
kono
parents:
diff changeset
63 | | RTL |--------->| transformations |
kono
parents:
diff changeset
64 | | transfor- | | in EBB scope |
kono
parents:
diff changeset
65 | substi- | mations | -------------------
kono
parents:
diff changeset
66 | tutions ------------
kono
parents:
diff changeset
67 | | No change
kono
parents:
diff changeset
68 ---------------- V
kono
parents:
diff changeset
69 | Spilled pseudo | -------------------
kono
parents:
diff changeset
70 | to memory |<----| Rematerialization |
kono
parents:
diff changeset
71 | substitution | -------------------
kono
parents:
diff changeset
72 ----------------
kono
parents:
diff changeset
73 | No susbtitions
kono
parents:
diff changeset
74 V
kono
parents:
diff changeset
75 -------------------------
kono
parents:
diff changeset
76 | Hard regs substitution, |
kono
parents:
diff changeset
77 | devirtalization, and |------> Finish
kono
parents:
diff changeset
78 | restoring scratches got |
kono
parents:
diff changeset
79 | memory |
kono
parents:
diff changeset
80 -------------------------
kono
parents:
diff changeset
81
kono
parents:
diff changeset
82 To speed up the process:
kono
parents:
diff changeset
83 o We process only insns affected by changes on previous
kono
parents:
diff changeset
84 iterations;
kono
parents:
diff changeset
85 o We don't use DFA-infrastructure because it results in much slower
kono
parents:
diff changeset
86 compiler speed than a special IR described below does;
kono
parents:
diff changeset
87 o We use a special insn representation for quick access to insn
kono
parents:
diff changeset
88 info which is always *synchronized* with the current RTL;
kono
parents:
diff changeset
89 o Insn IR is minimized by memory. It is divided on three parts:
kono
parents:
diff changeset
90 o one specific for each insn in RTL (only operand locations);
kono
parents:
diff changeset
91 o one common for all insns in RTL with the same insn code
kono
parents:
diff changeset
92 (different operand attributes from machine descriptions);
kono
parents:
diff changeset
93 o one oriented for maintenance of live info (list of pseudos).
kono
parents:
diff changeset
94 o Pseudo data:
kono
parents:
diff changeset
95 o all insns where the pseudo is referenced;
kono
parents:
diff changeset
96 o live info (conflicting hard regs, live ranges, # of
kono
parents:
diff changeset
97 references etc);
kono
parents:
diff changeset
98 o data used for assigning (preferred hard regs, costs etc).
kono
parents:
diff changeset
99
kono
parents:
diff changeset
100 This file contains LRA driver, LRA utility functions and data, and
kono
parents:
diff changeset
101 code for dealing with scratches. */
kono
parents:
diff changeset
102
kono
parents:
diff changeset
103 #include "config.h"
kono
parents:
diff changeset
104 #include "system.h"
kono
parents:
diff changeset
105 #include "coretypes.h"
kono
parents:
diff changeset
106 #include "backend.h"
kono
parents:
diff changeset
107 #include "target.h"
kono
parents:
diff changeset
108 #include "rtl.h"
kono
parents:
diff changeset
109 #include "tree.h"
kono
parents:
diff changeset
110 #include "predict.h"
kono
parents:
diff changeset
111 #include "df.h"
kono
parents:
diff changeset
112 #include "memmodel.h"
kono
parents:
diff changeset
113 #include "tm_p.h"
kono
parents:
diff changeset
114 #include "optabs.h"
kono
parents:
diff changeset
115 #include "regs.h"
kono
parents:
diff changeset
116 #include "ira.h"
kono
parents:
diff changeset
117 #include "recog.h"
kono
parents:
diff changeset
118 #include "expr.h"
kono
parents:
diff changeset
119 #include "cfgrtl.h"
kono
parents:
diff changeset
120 #include "cfgbuild.h"
kono
parents:
diff changeset
121 #include "lra.h"
kono
parents:
diff changeset
122 #include "lra-int.h"
kono
parents:
diff changeset
123 #include "print-rtl.h"
kono
parents:
diff changeset
124
kono
parents:
diff changeset
125 /* Dump bitmap SET with TITLE and BB INDEX. */
kono
parents:
diff changeset
126 void
kono
parents:
diff changeset
127 lra_dump_bitmap_with_title (const char *title, bitmap set, int index)
kono
parents:
diff changeset
128 {
kono
parents:
diff changeset
129 unsigned int i;
kono
parents:
diff changeset
130 int count;
kono
parents:
diff changeset
131 bitmap_iterator bi;
kono
parents:
diff changeset
132 static const int max_nums_on_line = 10;
kono
parents:
diff changeset
133
kono
parents:
diff changeset
134 if (bitmap_empty_p (set))
kono
parents:
diff changeset
135 return;
kono
parents:
diff changeset
136 fprintf (lra_dump_file, " %s %d:", title, index);
kono
parents:
diff changeset
137 fprintf (lra_dump_file, "\n");
kono
parents:
diff changeset
138 count = max_nums_on_line + 1;
kono
parents:
diff changeset
139 EXECUTE_IF_SET_IN_BITMAP (set, 0, i, bi)
kono
parents:
diff changeset
140 {
kono
parents:
diff changeset
141 if (count > max_nums_on_line)
kono
parents:
diff changeset
142 {
kono
parents:
diff changeset
143 fprintf (lra_dump_file, "\n ");
kono
parents:
diff changeset
144 count = 0;
kono
parents:
diff changeset
145 }
kono
parents:
diff changeset
146 fprintf (lra_dump_file, " %4u", i);
kono
parents:
diff changeset
147 count++;
kono
parents:
diff changeset
148 }
kono
parents:
diff changeset
149 fprintf (lra_dump_file, "\n");
kono
parents:
diff changeset
150 }
kono
parents:
diff changeset
151
kono
parents:
diff changeset
152 /* Hard registers currently not available for allocation. It can
kono
parents:
diff changeset
153 changed after some hard registers become not eliminable. */
kono
parents:
diff changeset
154 HARD_REG_SET lra_no_alloc_regs;
kono
parents:
diff changeset
155
kono
parents:
diff changeset
156 static int get_new_reg_value (void);
kono
parents:
diff changeset
157 static void expand_reg_info (void);
kono
parents:
diff changeset
158 static void invalidate_insn_recog_data (int);
kono
parents:
diff changeset
159 static int get_insn_freq (rtx_insn *);
kono
parents:
diff changeset
160 static void invalidate_insn_data_regno_info (lra_insn_recog_data_t,
kono
parents:
diff changeset
161 rtx_insn *, int);
kono
parents:
diff changeset
162
kono
parents:
diff changeset
163 /* Expand all regno related info needed for LRA. */
kono
parents:
diff changeset
164 static void
kono
parents:
diff changeset
165 expand_reg_data (int old)
kono
parents:
diff changeset
166 {
kono
parents:
diff changeset
167 resize_reg_info ();
kono
parents:
diff changeset
168 expand_reg_info ();
kono
parents:
diff changeset
169 ira_expand_reg_equiv ();
kono
parents:
diff changeset
170 for (int i = (int) max_reg_num () - 1; i >= old; i--)
kono
parents:
diff changeset
171 lra_change_class (i, ALL_REGS, " Set", true);
kono
parents:
diff changeset
172 }
kono
parents:
diff changeset
173
kono
parents:
diff changeset
174 /* Create and return a new reg of ORIGINAL mode. If ORIGINAL is NULL
kono
parents:
diff changeset
175 or of VOIDmode, use MD_MODE for the new reg. Initialize its
kono
parents:
diff changeset
176 register class to RCLASS. Print message about assigning class
kono
parents:
diff changeset
177 RCLASS containing new register name TITLE unless it is NULL. Use
kono
parents:
diff changeset
178 attributes of ORIGINAL if it is a register. The created register
kono
parents:
diff changeset
179 will have unique held value. */
kono
parents:
diff changeset
180 rtx
kono
parents:
diff changeset
181 lra_create_new_reg_with_unique_value (machine_mode md_mode, rtx original,
kono
parents:
diff changeset
182 enum reg_class rclass, const char *title)
kono
parents:
diff changeset
183 {
kono
parents:
diff changeset
184 machine_mode mode;
kono
parents:
diff changeset
185 rtx new_reg;
kono
parents:
diff changeset
186
kono
parents:
diff changeset
187 if (original == NULL_RTX || (mode = GET_MODE (original)) == VOIDmode)
kono
parents:
diff changeset
188 mode = md_mode;
kono
parents:
diff changeset
189 lra_assert (mode != VOIDmode);
kono
parents:
diff changeset
190 new_reg = gen_reg_rtx (mode);
kono
parents:
diff changeset
191 if (original == NULL_RTX || ! REG_P (original))
kono
parents:
diff changeset
192 {
kono
parents:
diff changeset
193 if (lra_dump_file != NULL)
kono
parents:
diff changeset
194 fprintf (lra_dump_file, " Creating newreg=%i", REGNO (new_reg));
kono
parents:
diff changeset
195 }
kono
parents:
diff changeset
196 else
kono
parents:
diff changeset
197 {
kono
parents:
diff changeset
198 if (ORIGINAL_REGNO (original) >= FIRST_PSEUDO_REGISTER)
kono
parents:
diff changeset
199 ORIGINAL_REGNO (new_reg) = ORIGINAL_REGNO (original);
kono
parents:
diff changeset
200 REG_USERVAR_P (new_reg) = REG_USERVAR_P (original);
kono
parents:
diff changeset
201 REG_POINTER (new_reg) = REG_POINTER (original);
kono
parents:
diff changeset
202 REG_ATTRS (new_reg) = REG_ATTRS (original);
kono
parents:
diff changeset
203 if (lra_dump_file != NULL)
kono
parents:
diff changeset
204 fprintf (lra_dump_file, " Creating newreg=%i from oldreg=%i",
kono
parents:
diff changeset
205 REGNO (new_reg), REGNO (original));
kono
parents:
diff changeset
206 }
kono
parents:
diff changeset
207 if (lra_dump_file != NULL)
kono
parents:
diff changeset
208 {
kono
parents:
diff changeset
209 if (title != NULL)
kono
parents:
diff changeset
210 fprintf (lra_dump_file, ", assigning class %s to%s%s r%d",
kono
parents:
diff changeset
211 reg_class_names[rclass], *title == '\0' ? "" : " ",
kono
parents:
diff changeset
212 title, REGNO (new_reg));
kono
parents:
diff changeset
213 fprintf (lra_dump_file, "\n");
kono
parents:
diff changeset
214 }
kono
parents:
diff changeset
215 expand_reg_data (max_reg_num ());
kono
parents:
diff changeset
216 setup_reg_classes (REGNO (new_reg), rclass, NO_REGS, rclass);
kono
parents:
diff changeset
217 return new_reg;
kono
parents:
diff changeset
218 }
kono
parents:
diff changeset
219
kono
parents:
diff changeset
220 /* Analogous to the previous function but also inherits value of
kono
parents:
diff changeset
221 ORIGINAL. */
kono
parents:
diff changeset
222 rtx
kono
parents:
diff changeset
223 lra_create_new_reg (machine_mode md_mode, rtx original,
kono
parents:
diff changeset
224 enum reg_class rclass, const char *title)
kono
parents:
diff changeset
225 {
kono
parents:
diff changeset
226 rtx new_reg;
kono
parents:
diff changeset
227
kono
parents:
diff changeset
228 new_reg
kono
parents:
diff changeset
229 = lra_create_new_reg_with_unique_value (md_mode, original, rclass, title);
kono
parents:
diff changeset
230 if (original != NULL_RTX && REG_P (original))
kono
parents:
diff changeset
231 lra_assign_reg_val (REGNO (original), REGNO (new_reg));
kono
parents:
diff changeset
232 return new_reg;
kono
parents:
diff changeset
233 }
kono
parents:
diff changeset
234
kono
parents:
diff changeset
235 /* Set up for REGNO unique hold value. */
kono
parents:
diff changeset
236 void
kono
parents:
diff changeset
237 lra_set_regno_unique_value (int regno)
kono
parents:
diff changeset
238 {
kono
parents:
diff changeset
239 lra_reg_info[regno].val = get_new_reg_value ();
kono
parents:
diff changeset
240 }
kono
parents:
diff changeset
241
kono
parents:
diff changeset
242 /* Invalidate INSN related info used by LRA. The info should never be
kono
parents:
diff changeset
243 used after that. */
kono
parents:
diff changeset
244 void
kono
parents:
diff changeset
245 lra_invalidate_insn_data (rtx_insn *insn)
kono
parents:
diff changeset
246 {
kono
parents:
diff changeset
247 lra_invalidate_insn_regno_info (insn);
kono
parents:
diff changeset
248 invalidate_insn_recog_data (INSN_UID (insn));
kono
parents:
diff changeset
249 }
kono
parents:
diff changeset
250
kono
parents:
diff changeset
251 /* Mark INSN deleted and invalidate the insn related info used by
kono
parents:
diff changeset
252 LRA. */
kono
parents:
diff changeset
253 void
kono
parents:
diff changeset
254 lra_set_insn_deleted (rtx_insn *insn)
kono
parents:
diff changeset
255 {
kono
parents:
diff changeset
256 lra_invalidate_insn_data (insn);
kono
parents:
diff changeset
257 SET_INSN_DELETED (insn);
kono
parents:
diff changeset
258 }
kono
parents:
diff changeset
259
kono
parents:
diff changeset
260 /* Delete an unneeded INSN and any previous insns who sole purpose is
kono
parents:
diff changeset
261 loading data that is dead in INSN. */
kono
parents:
diff changeset
262 void
kono
parents:
diff changeset
263 lra_delete_dead_insn (rtx_insn *insn)
kono
parents:
diff changeset
264 {
kono
parents:
diff changeset
265 rtx_insn *prev = prev_real_insn (insn);
kono
parents:
diff changeset
266 rtx prev_dest;
kono
parents:
diff changeset
267
kono
parents:
diff changeset
268 /* If the previous insn sets a register that dies in our insn,
kono
parents:
diff changeset
269 delete it too. */
kono
parents:
diff changeset
270 if (prev && GET_CODE (PATTERN (prev)) == SET
kono
parents:
diff changeset
271 && (prev_dest = SET_DEST (PATTERN (prev)), REG_P (prev_dest))
kono
parents:
diff changeset
272 && reg_mentioned_p (prev_dest, PATTERN (insn))
kono
parents:
diff changeset
273 && find_regno_note (insn, REG_DEAD, REGNO (prev_dest))
kono
parents:
diff changeset
274 && ! side_effects_p (SET_SRC (PATTERN (prev))))
kono
parents:
diff changeset
275 lra_delete_dead_insn (prev);
kono
parents:
diff changeset
276
kono
parents:
diff changeset
277 lra_set_insn_deleted (insn);
kono
parents:
diff changeset
278 }
kono
parents:
diff changeset
279
kono
parents:
diff changeset
280 /* Emit insn x = y + z. Return NULL if we failed to do it.
kono
parents:
diff changeset
281 Otherwise, return the insn. We don't use gen_add3_insn as it might
kono
parents:
diff changeset
282 clobber CC. */
kono
parents:
diff changeset
283 static rtx_insn *
kono
parents:
diff changeset
284 emit_add3_insn (rtx x, rtx y, rtx z)
kono
parents:
diff changeset
285 {
kono
parents:
diff changeset
286 rtx_insn *last;
kono
parents:
diff changeset
287
kono
parents:
diff changeset
288 last = get_last_insn ();
kono
parents:
diff changeset
289
kono
parents:
diff changeset
290 if (have_addptr3_insn (x, y, z))
kono
parents:
diff changeset
291 {
kono
parents:
diff changeset
292 rtx_insn *insn = gen_addptr3_insn (x, y, z);
kono
parents:
diff changeset
293
kono
parents:
diff changeset
294 /* If the target provides an "addptr" pattern it hopefully does
kono
parents:
diff changeset
295 for a reason. So falling back to the normal add would be
kono
parents:
diff changeset
296 a bug. */
kono
parents:
diff changeset
297 lra_assert (insn != NULL_RTX);
kono
parents:
diff changeset
298 emit_insn (insn);
kono
parents:
diff changeset
299 return insn;
kono
parents:
diff changeset
300 }
kono
parents:
diff changeset
301
kono
parents:
diff changeset
302 rtx_insn *insn = emit_insn (gen_rtx_SET (x, gen_rtx_PLUS (GET_MODE (y),
kono
parents:
diff changeset
303 y, z)));
kono
parents:
diff changeset
304 if (recog_memoized (insn) < 0)
kono
parents:
diff changeset
305 {
kono
parents:
diff changeset
306 delete_insns_since (last);
kono
parents:
diff changeset
307 insn = NULL;
kono
parents:
diff changeset
308 }
kono
parents:
diff changeset
309 return insn;
kono
parents:
diff changeset
310 }
kono
parents:
diff changeset
311
kono
parents:
diff changeset
312 /* Emit insn x = x + y. Return the insn. We use gen_add2_insn as the
kono
parents:
diff changeset
313 last resort. */
kono
parents:
diff changeset
314 static rtx_insn *
kono
parents:
diff changeset
315 emit_add2_insn (rtx x, rtx y)
kono
parents:
diff changeset
316 {
kono
parents:
diff changeset
317 rtx_insn *insn = emit_add3_insn (x, x, y);
kono
parents:
diff changeset
318 if (insn == NULL_RTX)
kono
parents:
diff changeset
319 {
kono
parents:
diff changeset
320 insn = gen_add2_insn (x, y);
kono
parents:
diff changeset
321 if (insn != NULL_RTX)
kono
parents:
diff changeset
322 emit_insn (insn);
kono
parents:
diff changeset
323 }
kono
parents:
diff changeset
324 return insn;
kono
parents:
diff changeset
325 }
kono
parents:
diff changeset
326
kono
parents:
diff changeset
327 /* Target checks operands through operand predicates to recognize an
kono
parents:
diff changeset
328 insn. We should have a special precaution to generate add insns
kono
parents:
diff changeset
329 which are frequent results of elimination.
kono
parents:
diff changeset
330
kono
parents:
diff changeset
331 Emit insns for x = y + z. X can be used to store intermediate
kono
parents:
diff changeset
332 values and should be not in Y and Z when we use X to store an
kono
parents:
diff changeset
333 intermediate value. Y + Z should form [base] [+ index[ * scale]] [
kono
parents:
diff changeset
334 + disp] where base and index are registers, disp and scale are
kono
parents:
diff changeset
335 constants. Y should contain base if it is present, Z should
kono
parents:
diff changeset
336 contain disp if any. index[*scale] can be part of Y or Z. */
kono
parents:
diff changeset
337 void
kono
parents:
diff changeset
338 lra_emit_add (rtx x, rtx y, rtx z)
kono
parents:
diff changeset
339 {
kono
parents:
diff changeset
340 int old;
kono
parents:
diff changeset
341 rtx_insn *last;
kono
parents:
diff changeset
342 rtx a1, a2, base, index, disp, scale, index_scale;
kono
parents:
diff changeset
343 bool ok_p;
kono
parents:
diff changeset
344
kono
parents:
diff changeset
345 rtx_insn *add3_insn = emit_add3_insn (x, y, z);
kono
parents:
diff changeset
346 old = max_reg_num ();
kono
parents:
diff changeset
347 if (add3_insn != NULL)
kono
parents:
diff changeset
348 ;
kono
parents:
diff changeset
349 else
kono
parents:
diff changeset
350 {
kono
parents:
diff changeset
351 disp = a2 = NULL_RTX;
kono
parents:
diff changeset
352 if (GET_CODE (y) == PLUS)
kono
parents:
diff changeset
353 {
kono
parents:
diff changeset
354 a1 = XEXP (y, 0);
kono
parents:
diff changeset
355 a2 = XEXP (y, 1);
kono
parents:
diff changeset
356 disp = z;
kono
parents:
diff changeset
357 }
kono
parents:
diff changeset
358 else
kono
parents:
diff changeset
359 {
kono
parents:
diff changeset
360 a1 = y;
kono
parents:
diff changeset
361 if (CONSTANT_P (z))
kono
parents:
diff changeset
362 disp = z;
kono
parents:
diff changeset
363 else
kono
parents:
diff changeset
364 a2 = z;
kono
parents:
diff changeset
365 }
kono
parents:
diff changeset
366 index_scale = scale = NULL_RTX;
kono
parents:
diff changeset
367 if (GET_CODE (a1) == MULT)
kono
parents:
diff changeset
368 {
kono
parents:
diff changeset
369 index_scale = a1;
kono
parents:
diff changeset
370 index = XEXP (a1, 0);
kono
parents:
diff changeset
371 scale = XEXP (a1, 1);
kono
parents:
diff changeset
372 base = a2;
kono
parents:
diff changeset
373 }
kono
parents:
diff changeset
374 else if (a2 != NULL_RTX && GET_CODE (a2) == MULT)
kono
parents:
diff changeset
375 {
kono
parents:
diff changeset
376 index_scale = a2;
kono
parents:
diff changeset
377 index = XEXP (a2, 0);
kono
parents:
diff changeset
378 scale = XEXP (a2, 1);
kono
parents:
diff changeset
379 base = a1;
kono
parents:
diff changeset
380 }
kono
parents:
diff changeset
381 else
kono
parents:
diff changeset
382 {
kono
parents:
diff changeset
383 base = a1;
kono
parents:
diff changeset
384 index = a2;
kono
parents:
diff changeset
385 }
kono
parents:
diff changeset
386 if ((base != NULL_RTX && ! (REG_P (base) || GET_CODE (base) == SUBREG))
kono
parents:
diff changeset
387 || (index != NULL_RTX
kono
parents:
diff changeset
388 && ! (REG_P (index) || GET_CODE (index) == SUBREG))
kono
parents:
diff changeset
389 || (disp != NULL_RTX && ! CONSTANT_P (disp))
kono
parents:
diff changeset
390 || (scale != NULL_RTX && ! CONSTANT_P (scale)))
kono
parents:
diff changeset
391 {
kono
parents:
diff changeset
392 /* Probably we have no 3 op add. Last chance is to use 2-op
kono
parents:
diff changeset
393 add insn. To succeed, don't move Z to X as an address
kono
parents:
diff changeset
394 segment always comes in Y. Otherwise, we might fail when
kono
parents:
diff changeset
395 adding the address segment to register. */
kono
parents:
diff changeset
396 lra_assert (x != y && x != z);
kono
parents:
diff changeset
397 emit_move_insn (x, y);
kono
parents:
diff changeset
398 rtx_insn *insn = emit_add2_insn (x, z);
kono
parents:
diff changeset
399 lra_assert (insn != NULL_RTX);
kono
parents:
diff changeset
400 }
kono
parents:
diff changeset
401 else
kono
parents:
diff changeset
402 {
kono
parents:
diff changeset
403 if (index_scale == NULL_RTX)
kono
parents:
diff changeset
404 index_scale = index;
kono
parents:
diff changeset
405 if (disp == NULL_RTX)
kono
parents:
diff changeset
406 {
kono
parents:
diff changeset
407 /* Generate x = index_scale; x = x + base. */
kono
parents:
diff changeset
408 lra_assert (index_scale != NULL_RTX && base != NULL_RTX);
kono
parents:
diff changeset
409 emit_move_insn (x, index_scale);
kono
parents:
diff changeset
410 rtx_insn *insn = emit_add2_insn (x, base);
kono
parents:
diff changeset
411 lra_assert (insn != NULL_RTX);
kono
parents:
diff changeset
412 }
kono
parents:
diff changeset
413 else if (scale == NULL_RTX)
kono
parents:
diff changeset
414 {
kono
parents:
diff changeset
415 /* Try x = base + disp. */
kono
parents:
diff changeset
416 lra_assert (base != NULL_RTX);
kono
parents:
diff changeset
417 last = get_last_insn ();
kono
parents:
diff changeset
418 rtx_insn *move_insn =
kono
parents:
diff changeset
419 emit_move_insn (x, gen_rtx_PLUS (GET_MODE (base), base, disp));
kono
parents:
diff changeset
420 if (recog_memoized (move_insn) < 0)
kono
parents:
diff changeset
421 {
kono
parents:
diff changeset
422 delete_insns_since (last);
kono
parents:
diff changeset
423 /* Generate x = disp; x = x + base. */
kono
parents:
diff changeset
424 emit_move_insn (x, disp);
kono
parents:
diff changeset
425 rtx_insn *add2_insn = emit_add2_insn (x, base);
kono
parents:
diff changeset
426 lra_assert (add2_insn != NULL_RTX);
kono
parents:
diff changeset
427 }
kono
parents:
diff changeset
428 /* Generate x = x + index. */
kono
parents:
diff changeset
429 if (index != NULL_RTX)
kono
parents:
diff changeset
430 {
kono
parents:
diff changeset
431 rtx_insn *insn = emit_add2_insn (x, index);
kono
parents:
diff changeset
432 lra_assert (insn != NULL_RTX);
kono
parents:
diff changeset
433 }
kono
parents:
diff changeset
434 }
kono
parents:
diff changeset
435 else
kono
parents:
diff changeset
436 {
kono
parents:
diff changeset
437 /* Try x = index_scale; x = x + disp; x = x + base. */
kono
parents:
diff changeset
438 last = get_last_insn ();
kono
parents:
diff changeset
439 rtx_insn *move_insn = emit_move_insn (x, index_scale);
kono
parents:
diff changeset
440 ok_p = false;
kono
parents:
diff changeset
441 if (recog_memoized (move_insn) >= 0)
kono
parents:
diff changeset
442 {
kono
parents:
diff changeset
443 rtx_insn *insn = emit_add2_insn (x, disp);
kono
parents:
diff changeset
444 if (insn != NULL_RTX)
kono
parents:
diff changeset
445 {
kono
parents:
diff changeset
446 if (base == NULL_RTX)
kono
parents:
diff changeset
447 ok_p = true;
kono
parents:
diff changeset
448 else
kono
parents:
diff changeset
449 {
kono
parents:
diff changeset
450 insn = emit_add2_insn (x, base);
kono
parents:
diff changeset
451 if (insn != NULL_RTX)
kono
parents:
diff changeset
452 ok_p = true;
kono
parents:
diff changeset
453 }
kono
parents:
diff changeset
454 }
kono
parents:
diff changeset
455 }
kono
parents:
diff changeset
456 if (! ok_p)
kono
parents:
diff changeset
457 {
kono
parents:
diff changeset
458 rtx_insn *insn;
kono
parents:
diff changeset
459
kono
parents:
diff changeset
460 delete_insns_since (last);
kono
parents:
diff changeset
461 /* Generate x = disp; x = x + base; x = x + index_scale. */
kono
parents:
diff changeset
462 emit_move_insn (x, disp);
kono
parents:
diff changeset
463 if (base != NULL_RTX)
kono
parents:
diff changeset
464 {
kono
parents:
diff changeset
465 insn = emit_add2_insn (x, base);
kono
parents:
diff changeset
466 lra_assert (insn != NULL_RTX);
kono
parents:
diff changeset
467 }
kono
parents:
diff changeset
468 insn = emit_add2_insn (x, index_scale);
kono
parents:
diff changeset
469 lra_assert (insn != NULL_RTX);
kono
parents:
diff changeset
470 }
kono
parents:
diff changeset
471 }
kono
parents:
diff changeset
472 }
kono
parents:
diff changeset
473 }
kono
parents:
diff changeset
474 /* Functions emit_... can create pseudos -- so expand the pseudo
kono
parents:
diff changeset
475 data. */
kono
parents:
diff changeset
476 if (old != max_reg_num ())
kono
parents:
diff changeset
477 expand_reg_data (old);
kono
parents:
diff changeset
478 }
kono
parents:
diff changeset
479
kono
parents:
diff changeset
480 /* The number of emitted reload insns so far. */
kono
parents:
diff changeset
481 int lra_curr_reload_num;
kono
parents:
diff changeset
482
kono
parents:
diff changeset
483 /* Emit x := y, processing special case when y = u + v or y = u + v *
kono
parents:
diff changeset
484 scale + w through emit_add (Y can be an address which is base +
kono
parents:
diff changeset
485 index reg * scale + displacement in general case). X may be used
kono
parents:
diff changeset
486 as intermediate result therefore it should be not in Y. */
kono
parents:
diff changeset
487 void
kono
parents:
diff changeset
488 lra_emit_move (rtx x, rtx y)
kono
parents:
diff changeset
489 {
kono
parents:
diff changeset
490 int old;
kono
parents:
diff changeset
491
kono
parents:
diff changeset
492 if (GET_CODE (y) != PLUS)
kono
parents:
diff changeset
493 {
kono
parents:
diff changeset
494 if (rtx_equal_p (x, y))
kono
parents:
diff changeset
495 return;
kono
parents:
diff changeset
496 old = max_reg_num ();
kono
parents:
diff changeset
497 emit_move_insn (x, y);
kono
parents:
diff changeset
498 if (REG_P (x))
kono
parents:
diff changeset
499 lra_reg_info[ORIGINAL_REGNO (x)].last_reload = ++lra_curr_reload_num;
kono
parents:
diff changeset
500 /* Function emit_move can create pseudos -- so expand the pseudo
kono
parents:
diff changeset
501 data. */
kono
parents:
diff changeset
502 if (old != max_reg_num ())
kono
parents:
diff changeset
503 expand_reg_data (old);
kono
parents:
diff changeset
504 return;
kono
parents:
diff changeset
505 }
kono
parents:
diff changeset
506 lra_emit_add (x, XEXP (y, 0), XEXP (y, 1));
kono
parents:
diff changeset
507 }
kono
parents:
diff changeset
508
kono
parents:
diff changeset
509 /* Update insn operands which are duplication of operands whose
kono
parents:
diff changeset
510 numbers are in array of NOPS (with end marker -1). The insn is
kono
parents:
diff changeset
511 represented by its LRA internal representation ID. */
kono
parents:
diff changeset
512 void
kono
parents:
diff changeset
513 lra_update_dups (lra_insn_recog_data_t id, signed char *nops)
kono
parents:
diff changeset
514 {
kono
parents:
diff changeset
515 int i, j, nop;
kono
parents:
diff changeset
516 struct lra_static_insn_data *static_id = id->insn_static_data;
kono
parents:
diff changeset
517
kono
parents:
diff changeset
518 for (i = 0; i < static_id->n_dups; i++)
kono
parents:
diff changeset
519 for (j = 0; (nop = nops[j]) >= 0; j++)
kono
parents:
diff changeset
520 if (static_id->dup_num[i] == nop)
kono
parents:
diff changeset
521 *id->dup_loc[i] = *id->operand_loc[nop];
kono
parents:
diff changeset
522 }
kono
parents:
diff changeset
523
kono
parents:
diff changeset
524
kono
parents:
diff changeset
525
kono
parents:
diff changeset
526 /* This page contains code dealing with info about registers in the
kono
parents:
diff changeset
527 insns. */
kono
parents:
diff changeset
528
kono
parents:
diff changeset
529 /* Pools for insn reg info. */
kono
parents:
diff changeset
530 object_allocator<lra_insn_reg> lra_insn_reg_pool ("insn regs");
kono
parents:
diff changeset
531
kono
parents:
diff changeset
532 /* Create LRA insn related info about a reference to REGNO in INSN
kono
parents:
diff changeset
533 with TYPE (in/out/inout), biggest reference mode MODE, flag that it
kono
parents:
diff changeset
534 is reference through subreg (SUBREG_P), flag that is early
kono
parents:
diff changeset
535 clobbered in the insn (EARLY_CLOBBER), and reference to the next
kono
parents:
diff changeset
536 insn reg info (NEXT). If REGNO can be early clobbered,
kono
parents:
diff changeset
537 alternatives in which it can be early clobbered are given by
kono
parents:
diff changeset
538 EARLY_CLOBBER_ALTS. */
kono
parents:
diff changeset
539 static struct lra_insn_reg *
kono
parents:
diff changeset
540 new_insn_reg (rtx_insn *insn, int regno, enum op_type type,
kono
parents:
diff changeset
541 machine_mode mode,
kono
parents:
diff changeset
542 bool subreg_p, bool early_clobber,
kono
parents:
diff changeset
543 alternative_mask early_clobber_alts,
kono
parents:
diff changeset
544 struct lra_insn_reg *next)
kono
parents:
diff changeset
545 {
kono
parents:
diff changeset
546 lra_insn_reg *ir = lra_insn_reg_pool.allocate ();
kono
parents:
diff changeset
547 ir->type = type;
kono
parents:
diff changeset
548 ir->biggest_mode = mode;
kono
parents:
diff changeset
549 if (NONDEBUG_INSN_P (insn)
kono
parents:
diff changeset
550 && partial_subreg_p (lra_reg_info[regno].biggest_mode, mode))
kono
parents:
diff changeset
551 lra_reg_info[regno].biggest_mode = mode;
kono
parents:
diff changeset
552 ir->subreg_p = subreg_p;
kono
parents:
diff changeset
553 ir->early_clobber = early_clobber;
kono
parents:
diff changeset
554 ir->early_clobber_alts = early_clobber_alts;
kono
parents:
diff changeset
555 ir->regno = regno;
kono
parents:
diff changeset
556 ir->next = next;
kono
parents:
diff changeset
557 return ir;
kono
parents:
diff changeset
558 }
kono
parents:
diff changeset
559
kono
parents:
diff changeset
560 /* Free insn reg info list IR. */
kono
parents:
diff changeset
561 static void
kono
parents:
diff changeset
562 free_insn_regs (struct lra_insn_reg *ir)
kono
parents:
diff changeset
563 {
kono
parents:
diff changeset
564 struct lra_insn_reg *next_ir;
kono
parents:
diff changeset
565
kono
parents:
diff changeset
566 for (; ir != NULL; ir = next_ir)
kono
parents:
diff changeset
567 {
kono
parents:
diff changeset
568 next_ir = ir->next;
kono
parents:
diff changeset
569 lra_insn_reg_pool.remove (ir);
kono
parents:
diff changeset
570 }
kono
parents:
diff changeset
571 }
kono
parents:
diff changeset
572
kono
parents:
diff changeset
573 /* Finish pool for insn reg info. */
kono
parents:
diff changeset
574 static void
kono
parents:
diff changeset
575 finish_insn_regs (void)
kono
parents:
diff changeset
576 {
kono
parents:
diff changeset
577 lra_insn_reg_pool.release ();
kono
parents:
diff changeset
578 }
kono
parents:
diff changeset
579
kono
parents:
diff changeset
580
kono
parents:
diff changeset
581
kono
parents:
diff changeset
582 /* This page contains code dealing LRA insn info (or in other words
kono
parents:
diff changeset
583 LRA internal insn representation). */
kono
parents:
diff changeset
584
kono
parents:
diff changeset
585 /* Map INSN_CODE -> the static insn data. This info is valid during
kono
parents:
diff changeset
586 all translation unit. */
kono
parents:
diff changeset
587 struct lra_static_insn_data *insn_code_data[NUM_INSN_CODES];
kono
parents:
diff changeset
588
kono
parents:
diff changeset
589 /* Debug insns are represented as a special insn with one input
kono
parents:
diff changeset
590 operand which is RTL expression in var_location. */
kono
parents:
diff changeset
591
kono
parents:
diff changeset
592 /* The following data are used as static insn operand data for all
kono
parents:
diff changeset
593 debug insns. If structure lra_operand_data is changed, the
kono
parents:
diff changeset
594 initializer should be changed too. */
kono
parents:
diff changeset
595 static struct lra_operand_data debug_operand_data =
kono
parents:
diff changeset
596 {
kono
parents:
diff changeset
597 NULL, /* alternative */
kono
parents:
diff changeset
598 0, /* early_clobber_alts */
kono
parents:
diff changeset
599 E_VOIDmode, /* We are not interesting in the operand mode. */
kono
parents:
diff changeset
600 OP_IN,
kono
parents:
diff changeset
601 0, 0, 0, 0
kono
parents:
diff changeset
602 };
kono
parents:
diff changeset
603
kono
parents:
diff changeset
604 /* The following data are used as static insn data for all debug
kono
parents:
diff changeset
605 insns. If structure lra_static_insn_data is changed, the
kono
parents:
diff changeset
606 initializer should be changed too. */
kono
parents:
diff changeset
607 static struct lra_static_insn_data debug_insn_static_data =
kono
parents:
diff changeset
608 {
kono
parents:
diff changeset
609 &debug_operand_data,
kono
parents:
diff changeset
610 0, /* Duplication operands #. */
kono
parents:
diff changeset
611 -1, /* Commutative operand #. */
kono
parents:
diff changeset
612 1, /* Operands #. There is only one operand which is debug RTL
kono
parents:
diff changeset
613 expression. */
kono
parents:
diff changeset
614 0, /* Duplications #. */
kono
parents:
diff changeset
615 0, /* Alternatives #. We are not interesting in alternatives
kono
parents:
diff changeset
616 because we does not proceed debug_insns for reloads. */
kono
parents:
diff changeset
617 NULL, /* Hard registers referenced in machine description. */
kono
parents:
diff changeset
618 NULL /* Descriptions of operands in alternatives. */
kono
parents:
diff changeset
619 };
kono
parents:
diff changeset
620
kono
parents:
diff changeset
621 /* Called once per compiler work to initialize some LRA data related
kono
parents:
diff changeset
622 to insns. */
kono
parents:
diff changeset
623 static void
kono
parents:
diff changeset
624 init_insn_code_data_once (void)
kono
parents:
diff changeset
625 {
kono
parents:
diff changeset
626 memset (insn_code_data, 0, sizeof (insn_code_data));
kono
parents:
diff changeset
627 }
kono
parents:
diff changeset
628
kono
parents:
diff changeset
629 /* Called once per compiler work to finalize some LRA data related to
kono
parents:
diff changeset
630 insns. */
kono
parents:
diff changeset
631 static void
kono
parents:
diff changeset
632 finish_insn_code_data_once (void)
kono
parents:
diff changeset
633 {
kono
parents:
diff changeset
634 for (unsigned int i = 0; i < NUM_INSN_CODES; i++)
kono
parents:
diff changeset
635 {
kono
parents:
diff changeset
636 if (insn_code_data[i] != NULL)
kono
parents:
diff changeset
637 free (insn_code_data[i]);
kono
parents:
diff changeset
638 }
kono
parents:
diff changeset
639 }
kono
parents:
diff changeset
640
kono
parents:
diff changeset
641 /* Return static insn data, allocate and setup if necessary. Although
kono
parents:
diff changeset
642 dup_num is static data (it depends only on icode), to set it up we
kono
parents:
diff changeset
643 need to extract insn first. So recog_data should be valid for
kono
parents:
diff changeset
644 normal insn (ICODE >= 0) before the call. */
kono
parents:
diff changeset
645 static struct lra_static_insn_data *
kono
parents:
diff changeset
646 get_static_insn_data (int icode, int nop, int ndup, int nalt)
kono
parents:
diff changeset
647 {
kono
parents:
diff changeset
648 struct lra_static_insn_data *data;
kono
parents:
diff changeset
649 size_t n_bytes;
kono
parents:
diff changeset
650
kono
parents:
diff changeset
651 lra_assert (icode < (int) NUM_INSN_CODES);
kono
parents:
diff changeset
652 if (icode >= 0 && (data = insn_code_data[icode]) != NULL)
kono
parents:
diff changeset
653 return data;
kono
parents:
diff changeset
654 lra_assert (nop >= 0 && ndup >= 0 && nalt >= 0);
kono
parents:
diff changeset
655 n_bytes = sizeof (struct lra_static_insn_data)
kono
parents:
diff changeset
656 + sizeof (struct lra_operand_data) * nop
kono
parents:
diff changeset
657 + sizeof (int) * ndup;
kono
parents:
diff changeset
658 data = XNEWVAR (struct lra_static_insn_data, n_bytes);
kono
parents:
diff changeset
659 data->operand_alternative = NULL;
kono
parents:
diff changeset
660 data->n_operands = nop;
kono
parents:
diff changeset
661 data->n_dups = ndup;
kono
parents:
diff changeset
662 data->n_alternatives = nalt;
kono
parents:
diff changeset
663 data->operand = ((struct lra_operand_data *)
kono
parents:
diff changeset
664 ((char *) data + sizeof (struct lra_static_insn_data)));
kono
parents:
diff changeset
665 data->dup_num = ((int *) ((char *) data->operand
kono
parents:
diff changeset
666 + sizeof (struct lra_operand_data) * nop));
kono
parents:
diff changeset
667 if (icode >= 0)
kono
parents:
diff changeset
668 {
kono
parents:
diff changeset
669 int i;
kono
parents:
diff changeset
670
kono
parents:
diff changeset
671 insn_code_data[icode] = data;
kono
parents:
diff changeset
672 for (i = 0; i < nop; i++)
kono
parents:
diff changeset
673 {
kono
parents:
diff changeset
674 data->operand[i].constraint
kono
parents:
diff changeset
675 = insn_data[icode].operand[i].constraint;
kono
parents:
diff changeset
676 data->operand[i].mode = insn_data[icode].operand[i].mode;
kono
parents:
diff changeset
677 data->operand[i].strict_low = insn_data[icode].operand[i].strict_low;
kono
parents:
diff changeset
678 data->operand[i].is_operator
kono
parents:
diff changeset
679 = insn_data[icode].operand[i].is_operator;
kono
parents:
diff changeset
680 data->operand[i].type
kono
parents:
diff changeset
681 = (data->operand[i].constraint[0] == '=' ? OP_OUT
kono
parents:
diff changeset
682 : data->operand[i].constraint[0] == '+' ? OP_INOUT
kono
parents:
diff changeset
683 : OP_IN);
kono
parents:
diff changeset
684 data->operand[i].is_address = false;
kono
parents:
diff changeset
685 }
kono
parents:
diff changeset
686 for (i = 0; i < ndup; i++)
kono
parents:
diff changeset
687 data->dup_num[i] = recog_data.dup_num[i];
kono
parents:
diff changeset
688 }
kono
parents:
diff changeset
689 return data;
kono
parents:
diff changeset
690 }
kono
parents:
diff changeset
691
kono
parents:
diff changeset
692 /* The current length of the following array. */
kono
parents:
diff changeset
693 int lra_insn_recog_data_len;
kono
parents:
diff changeset
694
kono
parents:
diff changeset
695 /* Map INSN_UID -> the insn recog data (NULL if unknown). */
kono
parents:
diff changeset
696 lra_insn_recog_data_t *lra_insn_recog_data;
kono
parents:
diff changeset
697
kono
parents:
diff changeset
698 /* Initialize LRA data about insns. */
kono
parents:
diff changeset
699 static void
kono
parents:
diff changeset
700 init_insn_recog_data (void)
kono
parents:
diff changeset
701 {
kono
parents:
diff changeset
702 lra_insn_recog_data_len = 0;
kono
parents:
diff changeset
703 lra_insn_recog_data = NULL;
kono
parents:
diff changeset
704 }
kono
parents:
diff changeset
705
kono
parents:
diff changeset
706 /* Expand, if necessary, LRA data about insns. */
kono
parents:
diff changeset
707 static void
kono
parents:
diff changeset
708 check_and_expand_insn_recog_data (int index)
kono
parents:
diff changeset
709 {
kono
parents:
diff changeset
710 int i, old;
kono
parents:
diff changeset
711
kono
parents:
diff changeset
712 if (lra_insn_recog_data_len > index)
kono
parents:
diff changeset
713 return;
kono
parents:
diff changeset
714 old = lra_insn_recog_data_len;
kono
parents:
diff changeset
715 lra_insn_recog_data_len = index * 3 / 2 + 1;
kono
parents:
diff changeset
716 lra_insn_recog_data = XRESIZEVEC (lra_insn_recog_data_t,
kono
parents:
diff changeset
717 lra_insn_recog_data,
kono
parents:
diff changeset
718 lra_insn_recog_data_len);
kono
parents:
diff changeset
719 for (i = old; i < lra_insn_recog_data_len; i++)
kono
parents:
diff changeset
720 lra_insn_recog_data[i] = NULL;
kono
parents:
diff changeset
721 }
kono
parents:
diff changeset
722
kono
parents:
diff changeset
723 /* Finish LRA DATA about insn. */
kono
parents:
diff changeset
724 static void
kono
parents:
diff changeset
725 free_insn_recog_data (lra_insn_recog_data_t data)
kono
parents:
diff changeset
726 {
kono
parents:
diff changeset
727 if (data->operand_loc != NULL)
kono
parents:
diff changeset
728 free (data->operand_loc);
kono
parents:
diff changeset
729 if (data->dup_loc != NULL)
kono
parents:
diff changeset
730 free (data->dup_loc);
kono
parents:
diff changeset
731 if (data->arg_hard_regs != NULL)
kono
parents:
diff changeset
732 free (data->arg_hard_regs);
kono
parents:
diff changeset
733 if (data->icode < 0 && NONDEBUG_INSN_P (data->insn))
kono
parents:
diff changeset
734 {
kono
parents:
diff changeset
735 if (data->insn_static_data->operand_alternative != NULL)
kono
parents:
diff changeset
736 free (const_cast <operand_alternative *>
kono
parents:
diff changeset
737 (data->insn_static_data->operand_alternative));
kono
parents:
diff changeset
738 free_insn_regs (data->insn_static_data->hard_regs);
kono
parents:
diff changeset
739 free (data->insn_static_data);
kono
parents:
diff changeset
740 }
kono
parents:
diff changeset
741 free_insn_regs (data->regs);
kono
parents:
diff changeset
742 data->regs = NULL;
kono
parents:
diff changeset
743 free (data);
kono
parents:
diff changeset
744 }
kono
parents:
diff changeset
745
kono
parents:
diff changeset
746 /* Pools for copies. */
kono
parents:
diff changeset
747 static object_allocator<lra_copy> lra_copy_pool ("lra copies");
kono
parents:
diff changeset
748
kono
parents:
diff changeset
749 /* Finish LRA data about all insns. */
kono
parents:
diff changeset
750 static void
kono
parents:
diff changeset
751 finish_insn_recog_data (void)
kono
parents:
diff changeset
752 {
kono
parents:
diff changeset
753 int i;
kono
parents:
diff changeset
754 lra_insn_recog_data_t data;
kono
parents:
diff changeset
755
kono
parents:
diff changeset
756 for (i = 0; i < lra_insn_recog_data_len; i++)
kono
parents:
diff changeset
757 if ((data = lra_insn_recog_data[i]) != NULL)
kono
parents:
diff changeset
758 free_insn_recog_data (data);
kono
parents:
diff changeset
759 finish_insn_regs ();
kono
parents:
diff changeset
760 lra_copy_pool.release ();
kono
parents:
diff changeset
761 lra_insn_reg_pool.release ();
kono
parents:
diff changeset
762 free (lra_insn_recog_data);
kono
parents:
diff changeset
763 }
kono
parents:
diff changeset
764
kono
parents:
diff changeset
765 /* Setup info about operands in alternatives of LRA DATA of insn. */
kono
parents:
diff changeset
766 static void
kono
parents:
diff changeset
767 setup_operand_alternative (lra_insn_recog_data_t data,
kono
parents:
diff changeset
768 const operand_alternative *op_alt)
kono
parents:
diff changeset
769 {
kono
parents:
diff changeset
770 int i, j, nop, nalt;
kono
parents:
diff changeset
771 int icode = data->icode;
kono
parents:
diff changeset
772 struct lra_static_insn_data *static_data = data->insn_static_data;
kono
parents:
diff changeset
773
kono
parents:
diff changeset
774 static_data->commutative = -1;
kono
parents:
diff changeset
775 nop = static_data->n_operands;
kono
parents:
diff changeset
776 nalt = static_data->n_alternatives;
kono
parents:
diff changeset
777 static_data->operand_alternative = op_alt;
kono
parents:
diff changeset
778 for (i = 0; i < nop; i++)
kono
parents:
diff changeset
779 {
kono
parents:
diff changeset
780 static_data->operand[i].early_clobber_alts = 0;
kono
parents:
diff changeset
781 static_data->operand[i].early_clobber = false;
kono
parents:
diff changeset
782 static_data->operand[i].is_address = false;
kono
parents:
diff changeset
783 if (static_data->operand[i].constraint[0] == '%')
kono
parents:
diff changeset
784 {
kono
parents:
diff changeset
785 /* We currently only support one commutative pair of operands. */
kono
parents:
diff changeset
786 if (static_data->commutative < 0)
kono
parents:
diff changeset
787 static_data->commutative = i;
kono
parents:
diff changeset
788 else
kono
parents:
diff changeset
789 lra_assert (icode < 0); /* Asm */
kono
parents:
diff changeset
790 /* The last operand should not be marked commutative. */
kono
parents:
diff changeset
791 lra_assert (i != nop - 1);
kono
parents:
diff changeset
792 }
kono
parents:
diff changeset
793 }
kono
parents:
diff changeset
794 for (j = 0; j < nalt; j++)
kono
parents:
diff changeset
795 for (i = 0; i < nop; i++, op_alt++)
kono
parents:
diff changeset
796 {
kono
parents:
diff changeset
797 static_data->operand[i].early_clobber |= op_alt->earlyclobber;
kono
parents:
diff changeset
798 if (op_alt->earlyclobber)
kono
parents:
diff changeset
799 static_data->operand[i].early_clobber_alts |= (alternative_mask) 1 << j;
kono
parents:
diff changeset
800 static_data->operand[i].is_address |= op_alt->is_address;
kono
parents:
diff changeset
801 }
kono
parents:
diff changeset
802 }
kono
parents:
diff changeset
803
kono
parents:
diff changeset
804 /* Recursively process X and collect info about registers, which are
kono
parents:
diff changeset
805 not the insn operands, in X with TYPE (in/out/inout) and flag that
kono
parents:
diff changeset
806 it is early clobbered in the insn (EARLY_CLOBBER) and add the info
kono
parents:
diff changeset
807 to LIST. X is a part of insn given by DATA. Return the result
kono
parents:
diff changeset
808 list. */
kono
parents:
diff changeset
809 static struct lra_insn_reg *
kono
parents:
diff changeset
810 collect_non_operand_hard_regs (rtx *x, lra_insn_recog_data_t data,
kono
parents:
diff changeset
811 struct lra_insn_reg *list,
kono
parents:
diff changeset
812 enum op_type type, bool early_clobber)
kono
parents:
diff changeset
813 {
kono
parents:
diff changeset
814 int i, j, regno, last;
kono
parents:
diff changeset
815 bool subreg_p;
kono
parents:
diff changeset
816 machine_mode mode;
kono
parents:
diff changeset
817 struct lra_insn_reg *curr;
kono
parents:
diff changeset
818 rtx op = *x;
kono
parents:
diff changeset
819 enum rtx_code code = GET_CODE (op);
kono
parents:
diff changeset
820 const char *fmt = GET_RTX_FORMAT (code);
kono
parents:
diff changeset
821
kono
parents:
diff changeset
822 for (i = 0; i < data->insn_static_data->n_operands; i++)
kono
parents:
diff changeset
823 if (! data->insn_static_data->operand[i].is_operator
kono
parents:
diff changeset
824 && x == data->operand_loc[i])
kono
parents:
diff changeset
825 /* It is an operand loc. Stop here. */
kono
parents:
diff changeset
826 return list;
kono
parents:
diff changeset
827 for (i = 0; i < data->insn_static_data->n_dups; i++)
kono
parents:
diff changeset
828 if (x == data->dup_loc[i])
kono
parents:
diff changeset
829 /* It is a dup loc. Stop here. */
kono
parents:
diff changeset
830 return list;
kono
parents:
diff changeset
831 mode = GET_MODE (op);
kono
parents:
diff changeset
832 subreg_p = false;
kono
parents:
diff changeset
833 if (code == SUBREG)
kono
parents:
diff changeset
834 {
kono
parents:
diff changeset
835 mode = wider_subreg_mode (op);
kono
parents:
diff changeset
836 if (read_modify_subreg_p (op))
kono
parents:
diff changeset
837 subreg_p = true;
kono
parents:
diff changeset
838 op = SUBREG_REG (op);
kono
parents:
diff changeset
839 code = GET_CODE (op);
kono
parents:
diff changeset
840 }
kono
parents:
diff changeset
841 if (REG_P (op))
kono
parents:
diff changeset
842 {
kono
parents:
diff changeset
843 if ((regno = REGNO (op)) >= FIRST_PSEUDO_REGISTER)
kono
parents:
diff changeset
844 return list;
kono
parents:
diff changeset
845 /* Process all regs even unallocatable ones as we need info
kono
parents:
diff changeset
846 about all regs for rematerialization pass. */
kono
parents:
diff changeset
847 for (last = end_hard_regno (mode, regno); regno < last; regno++)
kono
parents:
diff changeset
848 {
kono
parents:
diff changeset
849 for (curr = list; curr != NULL; curr = curr->next)
kono
parents:
diff changeset
850 if (curr->regno == regno && curr->subreg_p == subreg_p
kono
parents:
diff changeset
851 && curr->biggest_mode == mode)
kono
parents:
diff changeset
852 {
kono
parents:
diff changeset
853 if (curr->type != type)
kono
parents:
diff changeset
854 curr->type = OP_INOUT;
kono
parents:
diff changeset
855 if (early_clobber)
kono
parents:
diff changeset
856 {
kono
parents:
diff changeset
857 curr->early_clobber = true;
kono
parents:
diff changeset
858 curr->early_clobber_alts = ALL_ALTERNATIVES;
kono
parents:
diff changeset
859 }
kono
parents:
diff changeset
860 break;
kono
parents:
diff changeset
861 }
kono
parents:
diff changeset
862 if (curr == NULL)
kono
parents:
diff changeset
863 {
kono
parents:
diff changeset
864 /* This is a new hard regno or the info can not be
kono
parents:
diff changeset
865 integrated into the found structure. */
kono
parents:
diff changeset
866 #ifdef STACK_REGS
kono
parents:
diff changeset
867 early_clobber
kono
parents:
diff changeset
868 = (early_clobber
kono
parents:
diff changeset
869 /* This clobber is to inform popping floating
kono
parents:
diff changeset
870 point stack only. */
kono
parents:
diff changeset
871 && ! (FIRST_STACK_REG <= regno
kono
parents:
diff changeset
872 && regno <= LAST_STACK_REG));
kono
parents:
diff changeset
873 #endif
kono
parents:
diff changeset
874 list = new_insn_reg (data->insn, regno, type, mode, subreg_p,
kono
parents:
diff changeset
875 early_clobber,
kono
parents:
diff changeset
876 early_clobber ? ALL_ALTERNATIVES : 0, list);
kono
parents:
diff changeset
877 }
kono
parents:
diff changeset
878 }
kono
parents:
diff changeset
879 return list;
kono
parents:
diff changeset
880 }
kono
parents:
diff changeset
881 switch (code)
kono
parents:
diff changeset
882 {
kono
parents:
diff changeset
883 case SET:
kono
parents:
diff changeset
884 list = collect_non_operand_hard_regs (&SET_DEST (op), data,
kono
parents:
diff changeset
885 list, OP_OUT, false);
kono
parents:
diff changeset
886 list = collect_non_operand_hard_regs (&SET_SRC (op), data,
kono
parents:
diff changeset
887 list, OP_IN, false);
kono
parents:
diff changeset
888 break;
kono
parents:
diff changeset
889 case CLOBBER:
kono
parents:
diff changeset
890 /* We treat clobber of non-operand hard registers as early
kono
parents:
diff changeset
891 clobber (the behavior is expected from asm). */
kono
parents:
diff changeset
892 list = collect_non_operand_hard_regs (&XEXP (op, 0), data,
kono
parents:
diff changeset
893 list, OP_OUT, true);
kono
parents:
diff changeset
894 break;
kono
parents:
diff changeset
895 case PRE_INC: case PRE_DEC: case POST_INC: case POST_DEC:
kono
parents:
diff changeset
896 list = collect_non_operand_hard_regs (&XEXP (op, 0), data,
kono
parents:
diff changeset
897 list, OP_INOUT, false);
kono
parents:
diff changeset
898 break;
kono
parents:
diff changeset
899 case PRE_MODIFY: case POST_MODIFY:
kono
parents:
diff changeset
900 list = collect_non_operand_hard_regs (&XEXP (op, 0), data,
kono
parents:
diff changeset
901 list, OP_INOUT, false);
kono
parents:
diff changeset
902 list = collect_non_operand_hard_regs (&XEXP (op, 1), data,
kono
parents:
diff changeset
903 list, OP_IN, false);
kono
parents:
diff changeset
904 break;
kono
parents:
diff changeset
905 default:
kono
parents:
diff changeset
906 fmt = GET_RTX_FORMAT (code);
kono
parents:
diff changeset
907 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
kono
parents:
diff changeset
908 {
kono
parents:
diff changeset
909 if (fmt[i] == 'e')
kono
parents:
diff changeset
910 list = collect_non_operand_hard_regs (&XEXP (op, i), data,
kono
parents:
diff changeset
911 list, OP_IN, false);
kono
parents:
diff changeset
912 else if (fmt[i] == 'E')
kono
parents:
diff changeset
913 for (j = XVECLEN (op, i) - 1; j >= 0; j--)
kono
parents:
diff changeset
914 list = collect_non_operand_hard_regs (&XVECEXP (op, i, j), data,
kono
parents:
diff changeset
915 list, OP_IN, false);
kono
parents:
diff changeset
916 }
kono
parents:
diff changeset
917 }
kono
parents:
diff changeset
918 return list;
kono
parents:
diff changeset
919 }
kono
parents:
diff changeset
920
kono
parents:
diff changeset
921 /* Set up and return info about INSN. Set up the info if it is not set up
kono
parents:
diff changeset
922 yet. */
kono
parents:
diff changeset
923 lra_insn_recog_data_t
kono
parents:
diff changeset
924 lra_set_insn_recog_data (rtx_insn *insn)
kono
parents:
diff changeset
925 {
kono
parents:
diff changeset
926 lra_insn_recog_data_t data;
kono
parents:
diff changeset
927 int i, n, icode;
kono
parents:
diff changeset
928 rtx **locs;
kono
parents:
diff changeset
929 unsigned int uid = INSN_UID (insn);
kono
parents:
diff changeset
930 struct lra_static_insn_data *insn_static_data;
kono
parents:
diff changeset
931
kono
parents:
diff changeset
932 check_and_expand_insn_recog_data (uid);
kono
parents:
diff changeset
933 if (DEBUG_INSN_P (insn))
kono
parents:
diff changeset
934 icode = -1;
kono
parents:
diff changeset
935 else
kono
parents:
diff changeset
936 {
kono
parents:
diff changeset
937 icode = INSN_CODE (insn);
kono
parents:
diff changeset
938 if (icode < 0)
kono
parents:
diff changeset
939 /* It might be a new simple insn which is not recognized yet. */
kono
parents:
diff changeset
940 INSN_CODE (insn) = icode = recog_memoized (insn);
kono
parents:
diff changeset
941 }
kono
parents:
diff changeset
942 data = XNEW (struct lra_insn_recog_data);
kono
parents:
diff changeset
943 lra_insn_recog_data[uid] = data;
kono
parents:
diff changeset
944 data->insn = insn;
kono
parents:
diff changeset
945 data->used_insn_alternative = -1;
kono
parents:
diff changeset
946 data->icode = icode;
kono
parents:
diff changeset
947 data->regs = NULL;
kono
parents:
diff changeset
948 if (DEBUG_INSN_P (insn))
kono
parents:
diff changeset
949 {
kono
parents:
diff changeset
950 data->insn_static_data = &debug_insn_static_data;
kono
parents:
diff changeset
951 data->dup_loc = NULL;
kono
parents:
diff changeset
952 data->arg_hard_regs = NULL;
kono
parents:
diff changeset
953 data->preferred_alternatives = ALL_ALTERNATIVES;
kono
parents:
diff changeset
954 data->operand_loc = XNEWVEC (rtx *, 1);
kono
parents:
diff changeset
955 data->operand_loc[0] = &INSN_VAR_LOCATION_LOC (insn);
kono
parents:
diff changeset
956 return data;
kono
parents:
diff changeset
957 }
kono
parents:
diff changeset
958 if (icode < 0)
kono
parents:
diff changeset
959 {
kono
parents:
diff changeset
960 int nop, nalt;
kono
parents:
diff changeset
961 machine_mode operand_mode[MAX_RECOG_OPERANDS];
kono
parents:
diff changeset
962 const char *constraints[MAX_RECOG_OPERANDS];
kono
parents:
diff changeset
963
kono
parents:
diff changeset
964 nop = asm_noperands (PATTERN (insn));
kono
parents:
diff changeset
965 data->operand_loc = data->dup_loc = NULL;
kono
parents:
diff changeset
966 nalt = 1;
kono
parents:
diff changeset
967 if (nop < 0)
kono
parents:
diff changeset
968 {
kono
parents:
diff changeset
969 /* It is a special insn like USE or CLOBBER. We should
kono
parents:
diff changeset
970 recognize any regular insn otherwise LRA can do nothing
kono
parents:
diff changeset
971 with this insn. */
kono
parents:
diff changeset
972 gcc_assert (GET_CODE (PATTERN (insn)) == USE
kono
parents:
diff changeset
973 || GET_CODE (PATTERN (insn)) == CLOBBER
kono
parents:
diff changeset
974 || GET_CODE (PATTERN (insn)) == ASM_INPUT);
kono
parents:
diff changeset
975 data->insn_static_data = insn_static_data
kono
parents:
diff changeset
976 = get_static_insn_data (-1, 0, 0, nalt);
kono
parents:
diff changeset
977 }
kono
parents:
diff changeset
978 else
kono
parents:
diff changeset
979 {
kono
parents:
diff changeset
980 /* expand_asm_operands makes sure there aren't too many
kono
parents:
diff changeset
981 operands. */
kono
parents:
diff changeset
982 lra_assert (nop <= MAX_RECOG_OPERANDS);
kono
parents:
diff changeset
983 if (nop != 0)
kono
parents:
diff changeset
984 data->operand_loc = XNEWVEC (rtx *, nop);
kono
parents:
diff changeset
985 /* Now get the operand values and constraints out of the
kono
parents:
diff changeset
986 insn. */
kono
parents:
diff changeset
987 decode_asm_operands (PATTERN (insn), NULL,
kono
parents:
diff changeset
988 data->operand_loc,
kono
parents:
diff changeset
989 constraints, operand_mode, NULL);
kono
parents:
diff changeset
990 if (nop > 0)
kono
parents:
diff changeset
991 {
kono
parents:
diff changeset
992 const char *p = recog_data.constraints[0];
kono
parents:
diff changeset
993
kono
parents:
diff changeset
994 for (p = constraints[0]; *p; p++)
kono
parents:
diff changeset
995 nalt += *p == ',';
kono
parents:
diff changeset
996 }
kono
parents:
diff changeset
997 data->insn_static_data = insn_static_data
kono
parents:
diff changeset
998 = get_static_insn_data (-1, nop, 0, nalt);
kono
parents:
diff changeset
999 for (i = 0; i < nop; i++)
kono
parents:
diff changeset
1000 {
kono
parents:
diff changeset
1001 insn_static_data->operand[i].mode = operand_mode[i];
kono
parents:
diff changeset
1002 insn_static_data->operand[i].constraint = constraints[i];
kono
parents:
diff changeset
1003 insn_static_data->operand[i].strict_low = false;
kono
parents:
diff changeset
1004 insn_static_data->operand[i].is_operator = false;
kono
parents:
diff changeset
1005 insn_static_data->operand[i].is_address = false;
kono
parents:
diff changeset
1006 }
kono
parents:
diff changeset
1007 }
kono
parents:
diff changeset
1008 for (i = 0; i < insn_static_data->n_operands; i++)
kono
parents:
diff changeset
1009 insn_static_data->operand[i].type
kono
parents:
diff changeset
1010 = (insn_static_data->operand[i].constraint[0] == '=' ? OP_OUT
kono
parents:
diff changeset
1011 : insn_static_data->operand[i].constraint[0] == '+' ? OP_INOUT
kono
parents:
diff changeset
1012 : OP_IN);
kono
parents:
diff changeset
1013 data->preferred_alternatives = ALL_ALTERNATIVES;
kono
parents:
diff changeset
1014 if (nop > 0)
kono
parents:
diff changeset
1015 {
kono
parents:
diff changeset
1016 operand_alternative *op_alt = XCNEWVEC (operand_alternative,
kono
parents:
diff changeset
1017 nalt * nop);
kono
parents:
diff changeset
1018 preprocess_constraints (nop, nalt, constraints, op_alt);
kono
parents:
diff changeset
1019 setup_operand_alternative (data, op_alt);
kono
parents:
diff changeset
1020 }
kono
parents:
diff changeset
1021 }
kono
parents:
diff changeset
1022 else
kono
parents:
diff changeset
1023 {
kono
parents:
diff changeset
1024 insn_extract (insn);
kono
parents:
diff changeset
1025 data->insn_static_data = insn_static_data
kono
parents:
diff changeset
1026 = get_static_insn_data (icode, insn_data[icode].n_operands,
kono
parents:
diff changeset
1027 insn_data[icode].n_dups,
kono
parents:
diff changeset
1028 insn_data[icode].n_alternatives);
kono
parents:
diff changeset
1029 n = insn_static_data->n_operands;
kono
parents:
diff changeset
1030 if (n == 0)
kono
parents:
diff changeset
1031 locs = NULL;
kono
parents:
diff changeset
1032 else
kono
parents:
diff changeset
1033 {
kono
parents:
diff changeset
1034 locs = XNEWVEC (rtx *, n);
kono
parents:
diff changeset
1035 memcpy (locs, recog_data.operand_loc, n * sizeof (rtx *));
kono
parents:
diff changeset
1036 }
kono
parents:
diff changeset
1037 data->operand_loc = locs;
kono
parents:
diff changeset
1038 n = insn_static_data->n_dups;
kono
parents:
diff changeset
1039 if (n == 0)
kono
parents:
diff changeset
1040 locs = NULL;
kono
parents:
diff changeset
1041 else
kono
parents:
diff changeset
1042 {
kono
parents:
diff changeset
1043 locs = XNEWVEC (rtx *, n);
kono
parents:
diff changeset
1044 memcpy (locs, recog_data.dup_loc, n * sizeof (rtx *));
kono
parents:
diff changeset
1045 }
kono
parents:
diff changeset
1046 data->dup_loc = locs;
kono
parents:
diff changeset
1047 data->preferred_alternatives = get_preferred_alternatives (insn);
kono
parents:
diff changeset
1048 const operand_alternative *op_alt = preprocess_insn_constraints (icode);
kono
parents:
diff changeset
1049 if (!insn_static_data->operand_alternative)
kono
parents:
diff changeset
1050 setup_operand_alternative (data, op_alt);
kono
parents:
diff changeset
1051 else if (op_alt != insn_static_data->operand_alternative)
kono
parents:
diff changeset
1052 insn_static_data->operand_alternative = op_alt;
kono
parents:
diff changeset
1053 }
kono
parents:
diff changeset
1054 if (GET_CODE (PATTERN (insn)) == CLOBBER || GET_CODE (PATTERN (insn)) == USE)
kono
parents:
diff changeset
1055 insn_static_data->hard_regs = NULL;
kono
parents:
diff changeset
1056 else
kono
parents:
diff changeset
1057 insn_static_data->hard_regs
kono
parents:
diff changeset
1058 = collect_non_operand_hard_regs (&PATTERN (insn), data,
kono
parents:
diff changeset
1059 NULL, OP_IN, false);
kono
parents:
diff changeset
1060 data->arg_hard_regs = NULL;
kono
parents:
diff changeset
1061 if (CALL_P (insn))
kono
parents:
diff changeset
1062 {
kono
parents:
diff changeset
1063 bool use_p;
kono
parents:
diff changeset
1064 rtx link;
kono
parents:
diff changeset
1065 int n_hard_regs, regno, arg_hard_regs[FIRST_PSEUDO_REGISTER];
kono
parents:
diff changeset
1066
kono
parents:
diff changeset
1067 n_hard_regs = 0;
kono
parents:
diff changeset
1068 /* Finding implicit hard register usage. We believe it will be
kono
parents:
diff changeset
1069 not changed whatever transformations are used. Call insns
kono
parents:
diff changeset
1070 are such example. */
kono
parents:
diff changeset
1071 for (link = CALL_INSN_FUNCTION_USAGE (insn);
kono
parents:
diff changeset
1072 link != NULL_RTX;
kono
parents:
diff changeset
1073 link = XEXP (link, 1))
kono
parents:
diff changeset
1074 if (((use_p = GET_CODE (XEXP (link, 0)) == USE)
kono
parents:
diff changeset
1075 || GET_CODE (XEXP (link, 0)) == CLOBBER)
kono
parents:
diff changeset
1076 && REG_P (XEXP (XEXP (link, 0), 0)))
kono
parents:
diff changeset
1077 {
kono
parents:
diff changeset
1078 regno = REGNO (XEXP (XEXP (link, 0), 0));
kono
parents:
diff changeset
1079 lra_assert (regno < FIRST_PSEUDO_REGISTER);
kono
parents:
diff changeset
1080 /* It is an argument register. */
kono
parents:
diff changeset
1081 for (i = REG_NREGS (XEXP (XEXP (link, 0), 0)) - 1; i >= 0; i--)
kono
parents:
diff changeset
1082 arg_hard_regs[n_hard_regs++]
kono
parents:
diff changeset
1083 = regno + i + (use_p ? 0 : FIRST_PSEUDO_REGISTER);
kono
parents:
diff changeset
1084 }
kono
parents:
diff changeset
1085 if (n_hard_regs != 0)
kono
parents:
diff changeset
1086 {
kono
parents:
diff changeset
1087 arg_hard_regs[n_hard_regs++] = -1;
kono
parents:
diff changeset
1088 data->arg_hard_regs = XNEWVEC (int, n_hard_regs);
kono
parents:
diff changeset
1089 memcpy (data->arg_hard_regs, arg_hard_regs,
kono
parents:
diff changeset
1090 sizeof (int) * n_hard_regs);
kono
parents:
diff changeset
1091 }
kono
parents:
diff changeset
1092 }
kono
parents:
diff changeset
1093 /* Some output operand can be recognized only from the context not
kono
parents:
diff changeset
1094 from the constraints which are empty in this case. Call insn may
kono
parents:
diff changeset
1095 contain a hard register in set destination with empty constraint
kono
parents:
diff changeset
1096 and extract_insn treats them as an input. */
kono
parents:
diff changeset
1097 for (i = 0; i < insn_static_data->n_operands; i++)
kono
parents:
diff changeset
1098 {
kono
parents:
diff changeset
1099 int j;
kono
parents:
diff changeset
1100 rtx pat, set;
kono
parents:
diff changeset
1101 struct lra_operand_data *operand = &insn_static_data->operand[i];
kono
parents:
diff changeset
1102
kono
parents:
diff changeset
1103 /* ??? Should we treat 'X' the same way. It looks to me that
kono
parents:
diff changeset
1104 'X' means anything and empty constraint means we do not
kono
parents:
diff changeset
1105 care. */
kono
parents:
diff changeset
1106 if (operand->type != OP_IN || *operand->constraint != '\0'
kono
parents:
diff changeset
1107 || operand->is_operator)
kono
parents:
diff changeset
1108 continue;
kono
parents:
diff changeset
1109 pat = PATTERN (insn);
kono
parents:
diff changeset
1110 if (GET_CODE (pat) == SET)
kono
parents:
diff changeset
1111 {
kono
parents:
diff changeset
1112 if (data->operand_loc[i] != &SET_DEST (pat))
kono
parents:
diff changeset
1113 continue;
kono
parents:
diff changeset
1114 }
kono
parents:
diff changeset
1115 else if (GET_CODE (pat) == PARALLEL)
kono
parents:
diff changeset
1116 {
kono
parents:
diff changeset
1117 for (j = XVECLEN (pat, 0) - 1; j >= 0; j--)
kono
parents:
diff changeset
1118 {
kono
parents:
diff changeset
1119 set = XVECEXP (PATTERN (insn), 0, j);
kono
parents:
diff changeset
1120 if (GET_CODE (set) == SET
kono
parents:
diff changeset
1121 && &SET_DEST (set) == data->operand_loc[i])
kono
parents:
diff changeset
1122 break;
kono
parents:
diff changeset
1123 }
kono
parents:
diff changeset
1124 if (j < 0)
kono
parents:
diff changeset
1125 continue;
kono
parents:
diff changeset
1126 }
kono
parents:
diff changeset
1127 else
kono
parents:
diff changeset
1128 continue;
kono
parents:
diff changeset
1129 operand->type = OP_OUT;
kono
parents:
diff changeset
1130 }
kono
parents:
diff changeset
1131 return data;
kono
parents:
diff changeset
1132 }
kono
parents:
diff changeset
1133
kono
parents:
diff changeset
1134 /* Return info about insn give by UID. The info should be already set
kono
parents:
diff changeset
1135 up. */
kono
parents:
diff changeset
1136 static lra_insn_recog_data_t
kono
parents:
diff changeset
1137 get_insn_recog_data_by_uid (int uid)
kono
parents:
diff changeset
1138 {
kono
parents:
diff changeset
1139 lra_insn_recog_data_t data;
kono
parents:
diff changeset
1140
kono
parents:
diff changeset
1141 data = lra_insn_recog_data[uid];
kono
parents:
diff changeset
1142 lra_assert (data != NULL);
kono
parents:
diff changeset
1143 return data;
kono
parents:
diff changeset
1144 }
kono
parents:
diff changeset
1145
kono
parents:
diff changeset
1146 /* Invalidate all info about insn given by its UID. */
kono
parents:
diff changeset
1147 static void
kono
parents:
diff changeset
1148 invalidate_insn_recog_data (int uid)
kono
parents:
diff changeset
1149 {
kono
parents:
diff changeset
1150 lra_insn_recog_data_t data;
kono
parents:
diff changeset
1151
kono
parents:
diff changeset
1152 data = lra_insn_recog_data[uid];
kono
parents:
diff changeset
1153 lra_assert (data != NULL);
kono
parents:
diff changeset
1154 free_insn_recog_data (data);
kono
parents:
diff changeset
1155 lra_insn_recog_data[uid] = NULL;
kono
parents:
diff changeset
1156 }
kono
parents:
diff changeset
1157
kono
parents:
diff changeset
1158 /* Update all the insn info about INSN. It is usually called when
kono
parents:
diff changeset
1159 something in the insn was changed. Return the updated info. */
kono
parents:
diff changeset
1160 lra_insn_recog_data_t
kono
parents:
diff changeset
1161 lra_update_insn_recog_data (rtx_insn *insn)
kono
parents:
diff changeset
1162 {
kono
parents:
diff changeset
1163 lra_insn_recog_data_t data;
kono
parents:
diff changeset
1164 int n;
kono
parents:
diff changeset
1165 unsigned int uid = INSN_UID (insn);
kono
parents:
diff changeset
1166 struct lra_static_insn_data *insn_static_data;
kono
parents:
diff changeset
1167 HOST_WIDE_INT sp_offset = 0;
kono
parents:
diff changeset
1168
kono
parents:
diff changeset
1169 check_and_expand_insn_recog_data (uid);
kono
parents:
diff changeset
1170 if ((data = lra_insn_recog_data[uid]) != NULL
kono
parents:
diff changeset
1171 && data->icode != INSN_CODE (insn))
kono
parents:
diff changeset
1172 {
kono
parents:
diff changeset
1173 sp_offset = data->sp_offset;
kono
parents:
diff changeset
1174 invalidate_insn_data_regno_info (data, insn, get_insn_freq (insn));
kono
parents:
diff changeset
1175 invalidate_insn_recog_data (uid);
kono
parents:
diff changeset
1176 data = NULL;
kono
parents:
diff changeset
1177 }
kono
parents:
diff changeset
1178 if (data == NULL)
kono
parents:
diff changeset
1179 {
kono
parents:
diff changeset
1180 data = lra_get_insn_recog_data (insn);
kono
parents:
diff changeset
1181 /* Initiate or restore SP offset. */
kono
parents:
diff changeset
1182 data->sp_offset = sp_offset;
kono
parents:
diff changeset
1183 return data;
kono
parents:
diff changeset
1184 }
kono
parents:
diff changeset
1185 insn_static_data = data->insn_static_data;
kono
parents:
diff changeset
1186 data->used_insn_alternative = -1;
kono
parents:
diff changeset
1187 if (DEBUG_INSN_P (insn))
kono
parents:
diff changeset
1188 return data;
kono
parents:
diff changeset
1189 if (data->icode < 0)
kono
parents:
diff changeset
1190 {
kono
parents:
diff changeset
1191 int nop;
kono
parents:
diff changeset
1192 machine_mode operand_mode[MAX_RECOG_OPERANDS];
kono
parents:
diff changeset
1193 const char *constraints[MAX_RECOG_OPERANDS];
kono
parents:
diff changeset
1194
kono
parents:
diff changeset
1195 nop = asm_noperands (PATTERN (insn));
kono
parents:
diff changeset
1196 if (nop >= 0)
kono
parents:
diff changeset
1197 {
kono
parents:
diff changeset
1198 lra_assert (nop == data->insn_static_data->n_operands);
kono
parents:
diff changeset
1199 /* Now get the operand values and constraints out of the
kono
parents:
diff changeset
1200 insn. */
kono
parents:
diff changeset
1201 decode_asm_operands (PATTERN (insn), NULL,
kono
parents:
diff changeset
1202 data->operand_loc,
kono
parents:
diff changeset
1203 constraints, operand_mode, NULL);
kono
parents:
diff changeset
1204
kono
parents:
diff changeset
1205 if (flag_checking)
kono
parents:
diff changeset
1206 for (int i = 0; i < nop; i++)
kono
parents:
diff changeset
1207 lra_assert
kono
parents:
diff changeset
1208 (insn_static_data->operand[i].mode == operand_mode[i]
kono
parents:
diff changeset
1209 && insn_static_data->operand[i].constraint == constraints[i]
kono
parents:
diff changeset
1210 && ! insn_static_data->operand[i].is_operator);
kono
parents:
diff changeset
1211 }
kono
parents:
diff changeset
1212
kono
parents:
diff changeset
1213 if (flag_checking)
kono
parents:
diff changeset
1214 for (int i = 0; i < insn_static_data->n_operands; i++)
kono
parents:
diff changeset
1215 lra_assert
kono
parents:
diff changeset
1216 (insn_static_data->operand[i].type
kono
parents:
diff changeset
1217 == (insn_static_data->operand[i].constraint[0] == '=' ? OP_OUT
kono
parents:
diff changeset
1218 : insn_static_data->operand[i].constraint[0] == '+' ? OP_INOUT
kono
parents:
diff changeset
1219 : OP_IN));
kono
parents:
diff changeset
1220 }
kono
parents:
diff changeset
1221 else
kono
parents:
diff changeset
1222 {
kono
parents:
diff changeset
1223 insn_extract (insn);
kono
parents:
diff changeset
1224 n = insn_static_data->n_operands;
kono
parents:
diff changeset
1225 if (n != 0)
kono
parents:
diff changeset
1226 memcpy (data->operand_loc, recog_data.operand_loc, n * sizeof (rtx *));
kono
parents:
diff changeset
1227 n = insn_static_data->n_dups;
kono
parents:
diff changeset
1228 if (n != 0)
kono
parents:
diff changeset
1229 memcpy (data->dup_loc, recog_data.dup_loc, n * sizeof (rtx *));
kono
parents:
diff changeset
1230 lra_assert (check_bool_attrs (insn));
kono
parents:
diff changeset
1231 }
kono
parents:
diff changeset
1232 return data;
kono
parents:
diff changeset
1233 }
kono
parents:
diff changeset
1234
kono
parents:
diff changeset
1235 /* Set up that INSN is using alternative ALT now. */
kono
parents:
diff changeset
1236 void
kono
parents:
diff changeset
1237 lra_set_used_insn_alternative (rtx_insn *insn, int alt)
kono
parents:
diff changeset
1238 {
kono
parents:
diff changeset
1239 lra_insn_recog_data_t data;
kono
parents:
diff changeset
1240
kono
parents:
diff changeset
1241 data = lra_get_insn_recog_data (insn);
kono
parents:
diff changeset
1242 data->used_insn_alternative = alt;
kono
parents:
diff changeset
1243 }
kono
parents:
diff changeset
1244
kono
parents:
diff changeset
1245 /* Set up that insn with UID is using alternative ALT now. The insn
kono
parents:
diff changeset
1246 info should be already set up. */
kono
parents:
diff changeset
1247 void
kono
parents:
diff changeset
1248 lra_set_used_insn_alternative_by_uid (int uid, int alt)
kono
parents:
diff changeset
1249 {
kono
parents:
diff changeset
1250 lra_insn_recog_data_t data;
kono
parents:
diff changeset
1251
kono
parents:
diff changeset
1252 check_and_expand_insn_recog_data (uid);
kono
parents:
diff changeset
1253 data = lra_insn_recog_data[uid];
kono
parents:
diff changeset
1254 lra_assert (data != NULL);
kono
parents:
diff changeset
1255 data->used_insn_alternative = alt;
kono
parents:
diff changeset
1256 }
kono
parents:
diff changeset
1257
kono
parents:
diff changeset
1258
kono
parents:
diff changeset
1259
kono
parents:
diff changeset
1260 /* This page contains code dealing with common register info and
kono
parents:
diff changeset
1261 pseudo copies. */
kono
parents:
diff changeset
1262
kono
parents:
diff changeset
1263 /* The size of the following array. */
kono
parents:
diff changeset
1264 static int reg_info_size;
kono
parents:
diff changeset
1265 /* Common info about each register. */
kono
parents:
diff changeset
1266 struct lra_reg *lra_reg_info;
kono
parents:
diff changeset
1267
kono
parents:
diff changeset
1268 /* Last register value. */
kono
parents:
diff changeset
1269 static int last_reg_value;
kono
parents:
diff changeset
1270
kono
parents:
diff changeset
1271 /* Return new register value. */
kono
parents:
diff changeset
1272 static int
kono
parents:
diff changeset
1273 get_new_reg_value (void)
kono
parents:
diff changeset
1274 {
kono
parents:
diff changeset
1275 return ++last_reg_value;
kono
parents:
diff changeset
1276 }
kono
parents:
diff changeset
1277
kono
parents:
diff changeset
1278 /* Vec referring to pseudo copies. */
kono
parents:
diff changeset
1279 static vec<lra_copy_t> copy_vec;
kono
parents:
diff changeset
1280
kono
parents:
diff changeset
1281 /* Initialize I-th element of lra_reg_info. */
kono
parents:
diff changeset
1282 static inline void
kono
parents:
diff changeset
1283 initialize_lra_reg_info_element (int i)
kono
parents:
diff changeset
1284 {
kono
parents:
diff changeset
1285 bitmap_initialize (&lra_reg_info[i].insn_bitmap, &reg_obstack);
kono
parents:
diff changeset
1286 #ifdef STACK_REGS
kono
parents:
diff changeset
1287 lra_reg_info[i].no_stack_p = false;
kono
parents:
diff changeset
1288 #endif
kono
parents:
diff changeset
1289 CLEAR_HARD_REG_SET (lra_reg_info[i].conflict_hard_regs);
kono
parents:
diff changeset
1290 CLEAR_HARD_REG_SET (lra_reg_info[i].actual_call_used_reg_set);
kono
parents:
diff changeset
1291 lra_reg_info[i].preferred_hard_regno1 = -1;
kono
parents:
diff changeset
1292 lra_reg_info[i].preferred_hard_regno2 = -1;
kono
parents:
diff changeset
1293 lra_reg_info[i].preferred_hard_regno_profit1 = 0;
kono
parents:
diff changeset
1294 lra_reg_info[i].preferred_hard_regno_profit2 = 0;
kono
parents:
diff changeset
1295 lra_reg_info[i].biggest_mode = VOIDmode;
kono
parents:
diff changeset
1296 lra_reg_info[i].live_ranges = NULL;
kono
parents:
diff changeset
1297 lra_reg_info[i].nrefs = lra_reg_info[i].freq = 0;
kono
parents:
diff changeset
1298 lra_reg_info[i].last_reload = 0;
kono
parents:
diff changeset
1299 lra_reg_info[i].restore_rtx = NULL_RTX;
kono
parents:
diff changeset
1300 lra_reg_info[i].val = get_new_reg_value ();
kono
parents:
diff changeset
1301 lra_reg_info[i].offset = 0;
kono
parents:
diff changeset
1302 lra_reg_info[i].copies = NULL;
kono
parents:
diff changeset
1303 }
kono
parents:
diff changeset
1304
kono
parents:
diff changeset
1305 /* Initialize common reg info and copies. */
kono
parents:
diff changeset
1306 static void
kono
parents:
diff changeset
1307 init_reg_info (void)
kono
parents:
diff changeset
1308 {
kono
parents:
diff changeset
1309 int i;
kono
parents:
diff changeset
1310
kono
parents:
diff changeset
1311 last_reg_value = 0;
kono
parents:
diff changeset
1312 reg_info_size = max_reg_num () * 3 / 2 + 1;
kono
parents:
diff changeset
1313 lra_reg_info = XNEWVEC (struct lra_reg, reg_info_size);
kono
parents:
diff changeset
1314 for (i = 0; i < reg_info_size; i++)
kono
parents:
diff changeset
1315 initialize_lra_reg_info_element (i);
kono
parents:
diff changeset
1316 copy_vec.truncate (0);
kono
parents:
diff changeset
1317 }
kono
parents:
diff changeset
1318
kono
parents:
diff changeset
1319
kono
parents:
diff changeset
1320 /* Finish common reg info and copies. */
kono
parents:
diff changeset
1321 static void
kono
parents:
diff changeset
1322 finish_reg_info (void)
kono
parents:
diff changeset
1323 {
kono
parents:
diff changeset
1324 int i;
kono
parents:
diff changeset
1325
kono
parents:
diff changeset
1326 for (i = 0; i < reg_info_size; i++)
kono
parents:
diff changeset
1327 bitmap_clear (&lra_reg_info[i].insn_bitmap);
kono
parents:
diff changeset
1328 free (lra_reg_info);
kono
parents:
diff changeset
1329 reg_info_size = 0;
kono
parents:
diff changeset
1330 }
kono
parents:
diff changeset
1331
kono
parents:
diff changeset
1332 /* Expand common reg info if it is necessary. */
kono
parents:
diff changeset
1333 static void
kono
parents:
diff changeset
1334 expand_reg_info (void)
kono
parents:
diff changeset
1335 {
kono
parents:
diff changeset
1336 int i, old = reg_info_size;
kono
parents:
diff changeset
1337
kono
parents:
diff changeset
1338 if (reg_info_size > max_reg_num ())
kono
parents:
diff changeset
1339 return;
kono
parents:
diff changeset
1340 reg_info_size = max_reg_num () * 3 / 2 + 1;
kono
parents:
diff changeset
1341 lra_reg_info = XRESIZEVEC (struct lra_reg, lra_reg_info, reg_info_size);
kono
parents:
diff changeset
1342 for (i = old; i < reg_info_size; i++)
kono
parents:
diff changeset
1343 initialize_lra_reg_info_element (i);
kono
parents:
diff changeset
1344 }
kono
parents:
diff changeset
1345
kono
parents:
diff changeset
1346 /* Free all copies. */
kono
parents:
diff changeset
1347 void
kono
parents:
diff changeset
1348 lra_free_copies (void)
kono
parents:
diff changeset
1349 {
kono
parents:
diff changeset
1350 lra_copy_t cp;
kono
parents:
diff changeset
1351
kono
parents:
diff changeset
1352 while (copy_vec.length () != 0)
kono
parents:
diff changeset
1353 {
kono
parents:
diff changeset
1354 cp = copy_vec.pop ();
kono
parents:
diff changeset
1355 lra_reg_info[cp->regno1].copies = lra_reg_info[cp->regno2].copies = NULL;
kono
parents:
diff changeset
1356 lra_copy_pool.remove (cp);
kono
parents:
diff changeset
1357 }
kono
parents:
diff changeset
1358 }
kono
parents:
diff changeset
1359
kono
parents:
diff changeset
1360 /* Create copy of two pseudos REGNO1 and REGNO2. The copy execution
kono
parents:
diff changeset
1361 frequency is FREQ. */
kono
parents:
diff changeset
1362 void
kono
parents:
diff changeset
1363 lra_create_copy (int regno1, int regno2, int freq)
kono
parents:
diff changeset
1364 {
kono
parents:
diff changeset
1365 bool regno1_dest_p;
kono
parents:
diff changeset
1366 lra_copy_t cp;
kono
parents:
diff changeset
1367
kono
parents:
diff changeset
1368 lra_assert (regno1 != regno2);
kono
parents:
diff changeset
1369 regno1_dest_p = true;
kono
parents:
diff changeset
1370 if (regno1 > regno2)
kono
parents:
diff changeset
1371 {
kono
parents:
diff changeset
1372 std::swap (regno1, regno2);
kono
parents:
diff changeset
1373 regno1_dest_p = false;
kono
parents:
diff changeset
1374 }
kono
parents:
diff changeset
1375 cp = lra_copy_pool.allocate ();
kono
parents:
diff changeset
1376 copy_vec.safe_push (cp);
kono
parents:
diff changeset
1377 cp->regno1_dest_p = regno1_dest_p;
kono
parents:
diff changeset
1378 cp->freq = freq;
kono
parents:
diff changeset
1379 cp->regno1 = regno1;
kono
parents:
diff changeset
1380 cp->regno2 = regno2;
kono
parents:
diff changeset
1381 cp->regno1_next = lra_reg_info[regno1].copies;
kono
parents:
diff changeset
1382 lra_reg_info[regno1].copies = cp;
kono
parents:
diff changeset
1383 cp->regno2_next = lra_reg_info[regno2].copies;
kono
parents:
diff changeset
1384 lra_reg_info[regno2].copies = cp;
kono
parents:
diff changeset
1385 if (lra_dump_file != NULL)
kono
parents:
diff changeset
1386 fprintf (lra_dump_file, " Creating copy r%d%sr%d@%d\n",
kono
parents:
diff changeset
1387 regno1, regno1_dest_p ? "<-" : "->", regno2, freq);
kono
parents:
diff changeset
1388 }
kono
parents:
diff changeset
1389
kono
parents:
diff changeset
1390 /* Return N-th (0, 1, ...) copy. If there is no copy, return
kono
parents:
diff changeset
1391 NULL. */
kono
parents:
diff changeset
1392 lra_copy_t
kono
parents:
diff changeset
1393 lra_get_copy (int n)
kono
parents:
diff changeset
1394 {
kono
parents:
diff changeset
1395 if (n >= (int) copy_vec.length ())
kono
parents:
diff changeset
1396 return NULL;
kono
parents:
diff changeset
1397 return copy_vec[n];
kono
parents:
diff changeset
1398 }
kono
parents:
diff changeset
1399
kono
parents:
diff changeset
1400
kono
parents:
diff changeset
1401
kono
parents:
diff changeset
1402 /* This page contains code dealing with info about registers in
kono
parents:
diff changeset
1403 insns. */
kono
parents:
diff changeset
1404
kono
parents:
diff changeset
1405 /* Process X of insn UID recursively and add info (operand type is
kono
parents:
diff changeset
1406 given by TYPE, flag of that it is early clobber is EARLY_CLOBBER)
kono
parents:
diff changeset
1407 about registers in X to the insn DATA. If X can be early clobbered,
kono
parents:
diff changeset
1408 alternatives in which it can be early clobbered are given by
kono
parents:
diff changeset
1409 EARLY_CLOBBER_ALTS. */
kono
parents:
diff changeset
1410 static void
kono
parents:
diff changeset
1411 add_regs_to_insn_regno_info (lra_insn_recog_data_t data, rtx x, int uid,
kono
parents:
diff changeset
1412 enum op_type type, bool early_clobber,
kono
parents:
diff changeset
1413 alternative_mask early_clobber_alts)
kono
parents:
diff changeset
1414 {
kono
parents:
diff changeset
1415 int i, j, regno;
kono
parents:
diff changeset
1416 bool subreg_p;
kono
parents:
diff changeset
1417 machine_mode mode;
kono
parents:
diff changeset
1418 const char *fmt;
kono
parents:
diff changeset
1419 enum rtx_code code;
kono
parents:
diff changeset
1420 struct lra_insn_reg *curr;
kono
parents:
diff changeset
1421
kono
parents:
diff changeset
1422 code = GET_CODE (x);
kono
parents:
diff changeset
1423 mode = GET_MODE (x);
kono
parents:
diff changeset
1424 subreg_p = false;
kono
parents:
diff changeset
1425 if (GET_CODE (x) == SUBREG)
kono
parents:
diff changeset
1426 {
kono
parents:
diff changeset
1427 mode = wider_subreg_mode (x);
kono
parents:
diff changeset
1428 if (read_modify_subreg_p (x))
kono
parents:
diff changeset
1429 subreg_p = true;
kono
parents:
diff changeset
1430 x = SUBREG_REG (x);
kono
parents:
diff changeset
1431 code = GET_CODE (x);
kono
parents:
diff changeset
1432 }
kono
parents:
diff changeset
1433 if (REG_P (x))
kono
parents:
diff changeset
1434 {
kono
parents:
diff changeset
1435 regno = REGNO (x);
kono
parents:
diff changeset
1436 /* Process all regs even unallocatable ones as we need info about
kono
parents:
diff changeset
1437 all regs for rematerialization pass. */
kono
parents:
diff changeset
1438 expand_reg_info ();
kono
parents:
diff changeset
1439 if (bitmap_set_bit (&lra_reg_info[regno].insn_bitmap, uid))
kono
parents:
diff changeset
1440 {
kono
parents:
diff changeset
1441 data->regs = new_insn_reg (data->insn, regno, type, mode, subreg_p,
kono
parents:
diff changeset
1442 early_clobber, early_clobber_alts,
kono
parents:
diff changeset
1443 data->regs);
kono
parents:
diff changeset
1444 return;
kono
parents:
diff changeset
1445 }
kono
parents:
diff changeset
1446 else
kono
parents:
diff changeset
1447 {
kono
parents:
diff changeset
1448 for (curr = data->regs; curr != NULL; curr = curr->next)
kono
parents:
diff changeset
1449 if (curr->regno == regno)
kono
parents:
diff changeset
1450 {
kono
parents:
diff changeset
1451 if (curr->subreg_p != subreg_p || curr->biggest_mode != mode)
kono
parents:
diff changeset
1452 /* The info can not be integrated into the found
kono
parents:
diff changeset
1453 structure. */
kono
parents:
diff changeset
1454 data->regs = new_insn_reg (data->insn, regno, type, mode,
kono
parents:
diff changeset
1455 subreg_p, early_clobber,
kono
parents:
diff changeset
1456 early_clobber_alts, data->regs);
kono
parents:
diff changeset
1457 else
kono
parents:
diff changeset
1458 {
kono
parents:
diff changeset
1459 if (curr->type != type)
kono
parents:
diff changeset
1460 curr->type = OP_INOUT;
kono
parents:
diff changeset
1461 if (curr->early_clobber != early_clobber)
kono
parents:
diff changeset
1462 curr->early_clobber = true;
kono
parents:
diff changeset
1463 curr->early_clobber_alts |= early_clobber_alts;
kono
parents:
diff changeset
1464 }
kono
parents:
diff changeset
1465 return;
kono
parents:
diff changeset
1466 }
kono
parents:
diff changeset
1467 gcc_unreachable ();
kono
parents:
diff changeset
1468 }
kono
parents:
diff changeset
1469 }
kono
parents:
diff changeset
1470
kono
parents:
diff changeset
1471 switch (code)
kono
parents:
diff changeset
1472 {
kono
parents:
diff changeset
1473 case SET:
kono
parents:
diff changeset
1474 add_regs_to_insn_regno_info (data, SET_DEST (x), uid, OP_OUT, false, 0);
kono
parents:
diff changeset
1475 add_regs_to_insn_regno_info (data, SET_SRC (x), uid, OP_IN, false, 0);
kono
parents:
diff changeset
1476 break;
kono
parents:
diff changeset
1477 case CLOBBER:
kono
parents:
diff changeset
1478 /* We treat clobber of non-operand hard registers as early
kono
parents:
diff changeset
1479 clobber (the behavior is expected from asm). */
kono
parents:
diff changeset
1480 add_regs_to_insn_regno_info (data, XEXP (x, 0), uid, OP_OUT, true, ALL_ALTERNATIVES);
kono
parents:
diff changeset
1481 break;
kono
parents:
diff changeset
1482 case PRE_INC: case PRE_DEC: case POST_INC: case POST_DEC:
kono
parents:
diff changeset
1483 add_regs_to_insn_regno_info (data, XEXP (x, 0), uid, OP_INOUT, false, 0);
kono
parents:
diff changeset
1484 break;
kono
parents:
diff changeset
1485 case PRE_MODIFY: case POST_MODIFY:
kono
parents:
diff changeset
1486 add_regs_to_insn_regno_info (data, XEXP (x, 0), uid, OP_INOUT, false, 0);
kono
parents:
diff changeset
1487 add_regs_to_insn_regno_info (data, XEXP (x, 1), uid, OP_IN, false, 0);
kono
parents:
diff changeset
1488 break;
kono
parents:
diff changeset
1489 default:
kono
parents:
diff changeset
1490 if ((code != PARALLEL && code != EXPR_LIST) || type != OP_OUT)
kono
parents:
diff changeset
1491 /* Some targets place small structures in registers for return
kono
parents:
diff changeset
1492 values of functions, and those registers are wrapped in
kono
parents:
diff changeset
1493 PARALLEL that we may see as the destination of a SET. Here
kono
parents:
diff changeset
1494 is an example:
kono
parents:
diff changeset
1495
kono
parents:
diff changeset
1496 (call_insn 13 12 14 2 (set (parallel:BLK [
kono
parents:
diff changeset
1497 (expr_list:REG_DEP_TRUE (reg:DI 0 ax)
kono
parents:
diff changeset
1498 (const_int 0 [0]))
kono
parents:
diff changeset
1499 (expr_list:REG_DEP_TRUE (reg:DI 1 dx)
kono
parents:
diff changeset
1500 (const_int 8 [0x8]))
kono
parents:
diff changeset
1501 ])
kono
parents:
diff changeset
1502 (call (mem:QI (symbol_ref:DI (... */
kono
parents:
diff changeset
1503 type = OP_IN;
kono
parents:
diff changeset
1504 fmt = GET_RTX_FORMAT (code);
kono
parents:
diff changeset
1505 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
kono
parents:
diff changeset
1506 {
kono
parents:
diff changeset
1507 if (fmt[i] == 'e')
kono
parents:
diff changeset
1508 add_regs_to_insn_regno_info (data, XEXP (x, i), uid, type, false, 0);
kono
parents:
diff changeset
1509 else if (fmt[i] == 'E')
kono
parents:
diff changeset
1510 {
kono
parents:
diff changeset
1511 for (j = XVECLEN (x, i) - 1; j >= 0; j--)
kono
parents:
diff changeset
1512 add_regs_to_insn_regno_info (data, XVECEXP (x, i, j), uid,
kono
parents:
diff changeset
1513 type, false, 0);
kono
parents:
diff changeset
1514 }
kono
parents:
diff changeset
1515 }
kono
parents:
diff changeset
1516 }
kono
parents:
diff changeset
1517 }
kono
parents:
diff changeset
1518
kono
parents:
diff changeset
1519 /* Return execution frequency of INSN. */
kono
parents:
diff changeset
1520 static int
kono
parents:
diff changeset
1521 get_insn_freq (rtx_insn *insn)
kono
parents:
diff changeset
1522 {
kono
parents:
diff changeset
1523 basic_block bb = BLOCK_FOR_INSN (insn);
kono
parents:
diff changeset
1524
kono
parents:
diff changeset
1525 gcc_checking_assert (bb != NULL);
kono
parents:
diff changeset
1526 return REG_FREQ_FROM_BB (bb);
kono
parents:
diff changeset
1527 }
kono
parents:
diff changeset
1528
kono
parents:
diff changeset
1529 /* Invalidate all reg info of INSN with DATA and execution frequency
kono
parents:
diff changeset
1530 FREQ. Update common info about the invalidated registers. */
kono
parents:
diff changeset
1531 static void
kono
parents:
diff changeset
1532 invalidate_insn_data_regno_info (lra_insn_recog_data_t data, rtx_insn *insn,
kono
parents:
diff changeset
1533 int freq)
kono
parents:
diff changeset
1534 {
kono
parents:
diff changeset
1535 int uid;
kono
parents:
diff changeset
1536 bool debug_p;
kono
parents:
diff changeset
1537 unsigned int i;
kono
parents:
diff changeset
1538 struct lra_insn_reg *ir, *next_ir;
kono
parents:
diff changeset
1539
kono
parents:
diff changeset
1540 uid = INSN_UID (insn);
kono
parents:
diff changeset
1541 debug_p = DEBUG_INSN_P (insn);
kono
parents:
diff changeset
1542 for (ir = data->regs; ir != NULL; ir = next_ir)
kono
parents:
diff changeset
1543 {
kono
parents:
diff changeset
1544 i = ir->regno;
kono
parents:
diff changeset
1545 next_ir = ir->next;
kono
parents:
diff changeset
1546 lra_insn_reg_pool.remove (ir);
kono
parents:
diff changeset
1547 bitmap_clear_bit (&lra_reg_info[i].insn_bitmap, uid);
kono
parents:
diff changeset
1548 if (i >= FIRST_PSEUDO_REGISTER && ! debug_p)
kono
parents:
diff changeset
1549 {
kono
parents:
diff changeset
1550 lra_reg_info[i].nrefs--;
kono
parents:
diff changeset
1551 lra_reg_info[i].freq -= freq;
kono
parents:
diff changeset
1552 lra_assert (lra_reg_info[i].nrefs >= 0 && lra_reg_info[i].freq >= 0);
kono
parents:
diff changeset
1553 }
kono
parents:
diff changeset
1554 }
kono
parents:
diff changeset
1555 data->regs = NULL;
kono
parents:
diff changeset
1556 }
kono
parents:
diff changeset
1557
kono
parents:
diff changeset
1558 /* Invalidate all reg info of INSN. Update common info about the
kono
parents:
diff changeset
1559 invalidated registers. */
kono
parents:
diff changeset
1560 void
kono
parents:
diff changeset
1561 lra_invalidate_insn_regno_info (rtx_insn *insn)
kono
parents:
diff changeset
1562 {
kono
parents:
diff changeset
1563 invalidate_insn_data_regno_info (lra_get_insn_recog_data (insn), insn,
kono
parents:
diff changeset
1564 get_insn_freq (insn));
kono
parents:
diff changeset
1565 }
kono
parents:
diff changeset
1566
kono
parents:
diff changeset
1567 /* Update common reg info from reg info of insn given by its DATA and
kono
parents:
diff changeset
1568 execution frequency FREQ. */
kono
parents:
diff changeset
1569 static void
kono
parents:
diff changeset
1570 setup_insn_reg_info (lra_insn_recog_data_t data, int freq)
kono
parents:
diff changeset
1571 {
kono
parents:
diff changeset
1572 unsigned int i;
kono
parents:
diff changeset
1573 struct lra_insn_reg *ir;
kono
parents:
diff changeset
1574
kono
parents:
diff changeset
1575 for (ir = data->regs; ir != NULL; ir = ir->next)
kono
parents:
diff changeset
1576 if ((i = ir->regno) >= FIRST_PSEUDO_REGISTER)
kono
parents:
diff changeset
1577 {
kono
parents:
diff changeset
1578 lra_reg_info[i].nrefs++;
kono
parents:
diff changeset
1579 lra_reg_info[i].freq += freq;
kono
parents:
diff changeset
1580 }
kono
parents:
diff changeset
1581 }
kono
parents:
diff changeset
1582
kono
parents:
diff changeset
1583 /* Set up insn reg info of INSN. Update common reg info from reg info
kono
parents:
diff changeset
1584 of INSN. */
kono
parents:
diff changeset
1585 void
kono
parents:
diff changeset
1586 lra_update_insn_regno_info (rtx_insn *insn)
kono
parents:
diff changeset
1587 {
kono
parents:
diff changeset
1588 int i, uid, freq;
kono
parents:
diff changeset
1589 lra_insn_recog_data_t data;
kono
parents:
diff changeset
1590 struct lra_static_insn_data *static_data;
kono
parents:
diff changeset
1591 enum rtx_code code;
kono
parents:
diff changeset
1592 rtx link;
kono
parents:
diff changeset
1593
kono
parents:
diff changeset
1594 if (! INSN_P (insn))
kono
parents:
diff changeset
1595 return;
kono
parents:
diff changeset
1596 data = lra_get_insn_recog_data (insn);
kono
parents:
diff changeset
1597 static_data = data->insn_static_data;
kono
parents:
diff changeset
1598 freq = get_insn_freq (insn);
kono
parents:
diff changeset
1599 invalidate_insn_data_regno_info (data, insn, freq);
kono
parents:
diff changeset
1600 uid = INSN_UID (insn);
kono
parents:
diff changeset
1601 for (i = static_data->n_operands - 1; i >= 0; i--)
kono
parents:
diff changeset
1602 add_regs_to_insn_regno_info (data, *data->operand_loc[i], uid,
kono
parents:
diff changeset
1603 static_data->operand[i].type,
kono
parents:
diff changeset
1604 static_data->operand[i].early_clobber,
kono
parents:
diff changeset
1605 static_data->operand[i].early_clobber_alts);
kono
parents:
diff changeset
1606 if ((code = GET_CODE (PATTERN (insn))) == CLOBBER || code == USE)
kono
parents:
diff changeset
1607 add_regs_to_insn_regno_info (data, XEXP (PATTERN (insn), 0), uid,
kono
parents:
diff changeset
1608 code == USE ? OP_IN : OP_OUT, false, 0);
kono
parents:
diff changeset
1609 if (CALL_P (insn))
kono
parents:
diff changeset
1610 /* On some targets call insns can refer to pseudos in memory in
kono
parents:
diff changeset
1611 CALL_INSN_FUNCTION_USAGE list. Process them in order to
kono
parents:
diff changeset
1612 consider their occurrences in calls for different
kono
parents:
diff changeset
1613 transformations (e.g. inheritance) with given pseudos. */
kono
parents:
diff changeset
1614 for (link = CALL_INSN_FUNCTION_USAGE (insn);
kono
parents:
diff changeset
1615 link != NULL_RTX;
kono
parents:
diff changeset
1616 link = XEXP (link, 1))
kono
parents:
diff changeset
1617 if (((code = GET_CODE (XEXP (link, 0))) == USE || code == CLOBBER)
kono
parents:
diff changeset
1618 && MEM_P (XEXP (XEXP (link, 0), 0)))
kono
parents:
diff changeset
1619 add_regs_to_insn_regno_info (data, XEXP (XEXP (link, 0), 0), uid,
kono
parents:
diff changeset
1620 code == USE ? OP_IN : OP_OUT, false, 0);
kono
parents:
diff changeset
1621 if (NONDEBUG_INSN_P (insn))
kono
parents:
diff changeset
1622 setup_insn_reg_info (data, freq);
kono
parents:
diff changeset
1623 }
kono
parents:
diff changeset
1624
kono
parents:
diff changeset
1625 /* Return reg info of insn given by it UID. */
kono
parents:
diff changeset
1626 struct lra_insn_reg *
kono
parents:
diff changeset
1627 lra_get_insn_regs (int uid)
kono
parents:
diff changeset
1628 {
kono
parents:
diff changeset
1629 lra_insn_recog_data_t data;
kono
parents:
diff changeset
1630
kono
parents:
diff changeset
1631 data = get_insn_recog_data_by_uid (uid);
kono
parents:
diff changeset
1632 return data->regs;
kono
parents:
diff changeset
1633 }
kono
parents:
diff changeset
1634
kono
parents:
diff changeset
1635
kono
parents:
diff changeset
1636
kono
parents:
diff changeset
1637 /* Recursive hash function for RTL X. */
kono
parents:
diff changeset
1638 hashval_t
kono
parents:
diff changeset
1639 lra_rtx_hash (rtx x)
kono
parents:
diff changeset
1640 {
kono
parents:
diff changeset
1641 int i, j;
kono
parents:
diff changeset
1642 enum rtx_code code;
kono
parents:
diff changeset
1643 const char *fmt;
kono
parents:
diff changeset
1644 hashval_t val = 0;
kono
parents:
diff changeset
1645
kono
parents:
diff changeset
1646 if (x == 0)
kono
parents:
diff changeset
1647 return val;
kono
parents:
diff changeset
1648
kono
parents:
diff changeset
1649 code = GET_CODE (x);
kono
parents:
diff changeset
1650 val += (int) code + 4095;
kono
parents:
diff changeset
1651
kono
parents:
diff changeset
1652 /* Some RTL can be compared nonrecursively. */
kono
parents:
diff changeset
1653 switch (code)
kono
parents:
diff changeset
1654 {
kono
parents:
diff changeset
1655 case REG:
kono
parents:
diff changeset
1656 return val + REGNO (x);
kono
parents:
diff changeset
1657
kono
parents:
diff changeset
1658 case LABEL_REF:
kono
parents:
diff changeset
1659 return iterative_hash_object (XEXP (x, 0), val);
kono
parents:
diff changeset
1660
kono
parents:
diff changeset
1661 case SYMBOL_REF:
kono
parents:
diff changeset
1662 return iterative_hash_object (XSTR (x, 0), val);
kono
parents:
diff changeset
1663
kono
parents:
diff changeset
1664 case SCRATCH:
kono
parents:
diff changeset
1665 case CONST_DOUBLE:
kono
parents:
diff changeset
1666 case CONST_INT:
kono
parents:
diff changeset
1667 case CONST_VECTOR:
kono
parents:
diff changeset
1668 return val;
kono
parents:
diff changeset
1669
kono
parents:
diff changeset
1670 default:
kono
parents:
diff changeset
1671 break;
kono
parents:
diff changeset
1672 }
kono
parents:
diff changeset
1673
kono
parents:
diff changeset
1674 /* Hash the elements. */
kono
parents:
diff changeset
1675 fmt = GET_RTX_FORMAT (code);
kono
parents:
diff changeset
1676 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
kono
parents:
diff changeset
1677 {
kono
parents:
diff changeset
1678 switch (fmt[i])
kono
parents:
diff changeset
1679 {
kono
parents:
diff changeset
1680 case 'w':
kono
parents:
diff changeset
1681 val += XWINT (x, i);
kono
parents:
diff changeset
1682 break;
kono
parents:
diff changeset
1683
kono
parents:
diff changeset
1684 case 'n':
kono
parents:
diff changeset
1685 case 'i':
kono
parents:
diff changeset
1686 val += XINT (x, i);
kono
parents:
diff changeset
1687 break;
kono
parents:
diff changeset
1688
kono
parents:
diff changeset
1689 case 'V':
kono
parents:
diff changeset
1690 case 'E':
kono
parents:
diff changeset
1691 val += XVECLEN (x, i);
kono
parents:
diff changeset
1692
kono
parents:
diff changeset
1693 for (j = 0; j < XVECLEN (x, i); j++)
kono
parents:
diff changeset
1694 val += lra_rtx_hash (XVECEXP (x, i, j));
kono
parents:
diff changeset
1695 break;
kono
parents:
diff changeset
1696
kono
parents:
diff changeset
1697 case 'e':
kono
parents:
diff changeset
1698 val += lra_rtx_hash (XEXP (x, i));
kono
parents:
diff changeset
1699 break;
kono
parents:
diff changeset
1700
kono
parents:
diff changeset
1701 case 'S':
kono
parents:
diff changeset
1702 case 's':
kono
parents:
diff changeset
1703 val += htab_hash_string (XSTR (x, i));
kono
parents:
diff changeset
1704 break;
kono
parents:
diff changeset
1705
kono
parents:
diff changeset
1706 case 'u':
kono
parents:
diff changeset
1707 case '0':
kono
parents:
diff changeset
1708 case 't':
kono
parents:
diff changeset
1709 break;
kono
parents:
diff changeset
1710
kono
parents:
diff changeset
1711 /* It is believed that rtx's at this level will never
kono
parents:
diff changeset
1712 contain anything but integers and other rtx's, except for
kono
parents:
diff changeset
1713 within LABEL_REFs and SYMBOL_REFs. */
kono
parents:
diff changeset
1714 default:
kono
parents:
diff changeset
1715 abort ();
kono
parents:
diff changeset
1716 }
kono
parents:
diff changeset
1717 }
kono
parents:
diff changeset
1718 return val;
kono
parents:
diff changeset
1719 }
kono
parents:
diff changeset
1720
kono
parents:
diff changeset
1721
kono
parents:
diff changeset
1722
kono
parents:
diff changeset
1723 /* This page contains code dealing with stack of the insns which
kono
parents:
diff changeset
1724 should be processed by the next constraint pass. */
kono
parents:
diff changeset
1725
kono
parents:
diff changeset
1726 /* Bitmap used to put an insn on the stack only in one exemplar. */
kono
parents:
diff changeset
1727 static sbitmap lra_constraint_insn_stack_bitmap;
kono
parents:
diff changeset
1728
kono
parents:
diff changeset
1729 /* The stack itself. */
kono
parents:
diff changeset
1730 vec<rtx_insn *> lra_constraint_insn_stack;
kono
parents:
diff changeset
1731
kono
parents:
diff changeset
1732 /* Put INSN on the stack. If ALWAYS_UPDATE is true, always update the reg
kono
parents:
diff changeset
1733 info for INSN, otherwise only update it if INSN is not already on the
kono
parents:
diff changeset
1734 stack. */
kono
parents:
diff changeset
1735 static inline void
kono
parents:
diff changeset
1736 lra_push_insn_1 (rtx_insn *insn, bool always_update)
kono
parents:
diff changeset
1737 {
kono
parents:
diff changeset
1738 unsigned int uid = INSN_UID (insn);
kono
parents:
diff changeset
1739 if (always_update)
kono
parents:
diff changeset
1740 lra_update_insn_regno_info (insn);
kono
parents:
diff changeset
1741 if (uid >= SBITMAP_SIZE (lra_constraint_insn_stack_bitmap))
kono
parents:
diff changeset
1742 lra_constraint_insn_stack_bitmap =
kono
parents:
diff changeset
1743 sbitmap_resize (lra_constraint_insn_stack_bitmap, 3 * uid / 2, 0);
kono
parents:
diff changeset
1744 if (bitmap_bit_p (lra_constraint_insn_stack_bitmap, uid))
kono
parents:
diff changeset
1745 return;
kono
parents:
diff changeset
1746 bitmap_set_bit (lra_constraint_insn_stack_bitmap, uid);
kono
parents:
diff changeset
1747 if (! always_update)
kono
parents:
diff changeset
1748 lra_update_insn_regno_info (insn);
kono
parents:
diff changeset
1749 lra_constraint_insn_stack.safe_push (insn);
kono
parents:
diff changeset
1750 }
kono
parents:
diff changeset
1751
kono
parents:
diff changeset
1752 /* Put INSN on the stack. */
kono
parents:
diff changeset
1753 void
kono
parents:
diff changeset
1754 lra_push_insn (rtx_insn *insn)
kono
parents:
diff changeset
1755 {
kono
parents:
diff changeset
1756 lra_push_insn_1 (insn, false);
kono
parents:
diff changeset
1757 }
kono
parents:
diff changeset
1758
kono
parents:
diff changeset
1759 /* Put INSN on the stack and update its reg info. */
kono
parents:
diff changeset
1760 void
kono
parents:
diff changeset
1761 lra_push_insn_and_update_insn_regno_info (rtx_insn *insn)
kono
parents:
diff changeset
1762 {
kono
parents:
diff changeset
1763 lra_push_insn_1 (insn, true);
kono
parents:
diff changeset
1764 }
kono
parents:
diff changeset
1765
kono
parents:
diff changeset
1766 /* Put insn with UID on the stack. */
kono
parents:
diff changeset
1767 void
kono
parents:
diff changeset
1768 lra_push_insn_by_uid (unsigned int uid)
kono
parents:
diff changeset
1769 {
kono
parents:
diff changeset
1770 lra_push_insn (lra_insn_recog_data[uid]->insn);
kono
parents:
diff changeset
1771 }
kono
parents:
diff changeset
1772
kono
parents:
diff changeset
1773 /* Take the last-inserted insns off the stack and return it. */
kono
parents:
diff changeset
1774 rtx_insn *
kono
parents:
diff changeset
1775 lra_pop_insn (void)
kono
parents:
diff changeset
1776 {
kono
parents:
diff changeset
1777 rtx_insn *insn = lra_constraint_insn_stack.pop ();
kono
parents:
diff changeset
1778 bitmap_clear_bit (lra_constraint_insn_stack_bitmap, INSN_UID (insn));
kono
parents:
diff changeset
1779 return insn;
kono
parents:
diff changeset
1780 }
kono
parents:
diff changeset
1781
kono
parents:
diff changeset
1782 /* Return the current size of the insn stack. */
kono
parents:
diff changeset
1783 unsigned int
kono
parents:
diff changeset
1784 lra_insn_stack_length (void)
kono
parents:
diff changeset
1785 {
kono
parents:
diff changeset
1786 return lra_constraint_insn_stack.length ();
kono
parents:
diff changeset
1787 }
kono
parents:
diff changeset
1788
kono
parents:
diff changeset
1789 /* Push insns FROM to TO (excluding it) going in reverse order. */
kono
parents:
diff changeset
1790 static void
kono
parents:
diff changeset
1791 push_insns (rtx_insn *from, rtx_insn *to)
kono
parents:
diff changeset
1792 {
kono
parents:
diff changeset
1793 rtx_insn *insn;
kono
parents:
diff changeset
1794
kono
parents:
diff changeset
1795 if (from == NULL_RTX)
kono
parents:
diff changeset
1796 return;
kono
parents:
diff changeset
1797 for (insn = from; insn != to; insn = PREV_INSN (insn))
kono
parents:
diff changeset
1798 if (INSN_P (insn))
kono
parents:
diff changeset
1799 lra_push_insn (insn);
kono
parents:
diff changeset
1800 }
kono
parents:
diff changeset
1801
kono
parents:
diff changeset
1802 /* Set up sp offset for insn in range [FROM, LAST]. The offset is
kono
parents:
diff changeset
1803 taken from the next BB insn after LAST or zero if there in such
kono
parents:
diff changeset
1804 insn. */
kono
parents:
diff changeset
1805 static void
kono
parents:
diff changeset
1806 setup_sp_offset (rtx_insn *from, rtx_insn *last)
kono
parents:
diff changeset
1807 {
kono
parents:
diff changeset
1808 rtx_insn *before = next_nonnote_insn_bb (last);
kono
parents:
diff changeset
1809 HOST_WIDE_INT offset = (before == NULL_RTX || ! INSN_P (before)
kono
parents:
diff changeset
1810 ? 0 : lra_get_insn_recog_data (before)->sp_offset);
kono
parents:
diff changeset
1811
kono
parents:
diff changeset
1812 for (rtx_insn *insn = from; insn != NEXT_INSN (last); insn = NEXT_INSN (insn))
kono
parents:
diff changeset
1813 lra_get_insn_recog_data (insn)->sp_offset = offset;
kono
parents:
diff changeset
1814 }
kono
parents:
diff changeset
1815
kono
parents:
diff changeset
1816 /* Emit insns BEFORE before INSN and insns AFTER after INSN. Put the
kono
parents:
diff changeset
1817 insns onto the stack. Print about emitting the insns with
kono
parents:
diff changeset
1818 TITLE. */
kono
parents:
diff changeset
1819 void
kono
parents:
diff changeset
1820 lra_process_new_insns (rtx_insn *insn, rtx_insn *before, rtx_insn *after,
kono
parents:
diff changeset
1821 const char *title)
kono
parents:
diff changeset
1822 {
kono
parents:
diff changeset
1823 rtx_insn *last;
kono
parents:
diff changeset
1824
kono
parents:
diff changeset
1825 if (before == NULL_RTX && after == NULL_RTX)
kono
parents:
diff changeset
1826 return;
kono
parents:
diff changeset
1827 if (lra_dump_file != NULL)
kono
parents:
diff changeset
1828 {
kono
parents:
diff changeset
1829 dump_insn_slim (lra_dump_file, insn);
kono
parents:
diff changeset
1830 if (before != NULL_RTX)
kono
parents:
diff changeset
1831 {
kono
parents:
diff changeset
1832 fprintf (lra_dump_file," %s before:\n", title);
kono
parents:
diff changeset
1833 dump_rtl_slim (lra_dump_file, before, NULL, -1, 0);
kono
parents:
diff changeset
1834 }
kono
parents:
diff changeset
1835 if (after != NULL_RTX)
kono
parents:
diff changeset
1836 {
kono
parents:
diff changeset
1837 fprintf (lra_dump_file, " %s after:\n", title);
kono
parents:
diff changeset
1838 dump_rtl_slim (lra_dump_file, after, NULL, -1, 0);
kono
parents:
diff changeset
1839 }
kono
parents:
diff changeset
1840 fprintf (lra_dump_file, "\n");
kono
parents:
diff changeset
1841 }
kono
parents:
diff changeset
1842 if (before != NULL_RTX)
kono
parents:
diff changeset
1843 {
kono
parents:
diff changeset
1844 if (cfun->can_throw_non_call_exceptions)
kono
parents:
diff changeset
1845 copy_reg_eh_region_note_forward (insn, before, NULL);
kono
parents:
diff changeset
1846 emit_insn_before (before, insn);
kono
parents:
diff changeset
1847 push_insns (PREV_INSN (insn), PREV_INSN (before));
kono
parents:
diff changeset
1848 setup_sp_offset (before, PREV_INSN (insn));
kono
parents:
diff changeset
1849 }
kono
parents:
diff changeset
1850 if (after != NULL_RTX)
kono
parents:
diff changeset
1851 {
kono
parents:
diff changeset
1852 if (cfun->can_throw_non_call_exceptions)
kono
parents:
diff changeset
1853 copy_reg_eh_region_note_forward (insn, after, NULL);
kono
parents:
diff changeset
1854 for (last = after; NEXT_INSN (last) != NULL_RTX; last = NEXT_INSN (last))
kono
parents:
diff changeset
1855 ;
kono
parents:
diff changeset
1856 emit_insn_after (after, insn);
kono
parents:
diff changeset
1857 push_insns (last, insn);
kono
parents:
diff changeset
1858 setup_sp_offset (after, last);
kono
parents:
diff changeset
1859 }
kono
parents:
diff changeset
1860 if (cfun->can_throw_non_call_exceptions)
kono
parents:
diff changeset
1861 {
kono
parents:
diff changeset
1862 rtx note = find_reg_note (insn, REG_EH_REGION, NULL_RTX);
kono
parents:
diff changeset
1863 if (note && !insn_could_throw_p (insn))
kono
parents:
diff changeset
1864 remove_note (insn, note);
kono
parents:
diff changeset
1865 }
kono
parents:
diff changeset
1866 }
kono
parents:
diff changeset
1867
kono
parents:
diff changeset
1868
kono
parents:
diff changeset
1869 /* Replace all references to register OLD_REGNO in *LOC with pseudo
kono
parents:
diff changeset
1870 register NEW_REG. Try to simplify subreg of constant if SUBREG_P.
kono
parents:
diff changeset
1871 Return true if any change was made. */
kono
parents:
diff changeset
1872 bool
kono
parents:
diff changeset
1873 lra_substitute_pseudo (rtx *loc, int old_regno, rtx new_reg, bool subreg_p)
kono
parents:
diff changeset
1874 {
kono
parents:
diff changeset
1875 rtx x = *loc;
kono
parents:
diff changeset
1876 bool result = false;
kono
parents:
diff changeset
1877 enum rtx_code code;
kono
parents:
diff changeset
1878 const char *fmt;
kono
parents:
diff changeset
1879 int i, j;
kono
parents:
diff changeset
1880
kono
parents:
diff changeset
1881 if (x == NULL_RTX)
kono
parents:
diff changeset
1882 return false;
kono
parents:
diff changeset
1883
kono
parents:
diff changeset
1884 code = GET_CODE (x);
kono
parents:
diff changeset
1885 if (code == SUBREG && subreg_p)
kono
parents:
diff changeset
1886 {
kono
parents:
diff changeset
1887 rtx subst, inner = SUBREG_REG (x);
kono
parents:
diff changeset
1888 /* Transform subreg of constant while we still have inner mode
kono
parents:
diff changeset
1889 of the subreg. The subreg internal should not be an insn
kono
parents:
diff changeset
1890 operand. */
kono
parents:
diff changeset
1891 if (REG_P (inner) && (int) REGNO (inner) == old_regno
kono
parents:
diff changeset
1892 && CONSTANT_P (new_reg)
kono
parents:
diff changeset
1893 && (subst = simplify_subreg (GET_MODE (x), new_reg, GET_MODE (inner),
kono
parents:
diff changeset
1894 SUBREG_BYTE (x))) != NULL_RTX)
kono
parents:
diff changeset
1895 {
kono
parents:
diff changeset
1896 *loc = subst;
kono
parents:
diff changeset
1897 return true;
kono
parents:
diff changeset
1898 }
kono
parents:
diff changeset
1899
kono
parents:
diff changeset
1900 }
kono
parents:
diff changeset
1901 else if (code == REG && (int) REGNO (x) == old_regno)
kono
parents:
diff changeset
1902 {
kono
parents:
diff changeset
1903 machine_mode mode = GET_MODE (x);
kono
parents:
diff changeset
1904 machine_mode inner_mode = GET_MODE (new_reg);
kono
parents:
diff changeset
1905
kono
parents:
diff changeset
1906 if (mode != inner_mode
kono
parents:
diff changeset
1907 && ! (CONST_INT_P (new_reg) && SCALAR_INT_MODE_P (mode)))
kono
parents:
diff changeset
1908 {
kono
parents:
diff changeset
1909 if (!partial_subreg_p (mode, inner_mode)
kono
parents:
diff changeset
1910 || ! SCALAR_INT_MODE_P (inner_mode))
kono
parents:
diff changeset
1911 new_reg = gen_rtx_SUBREG (mode, new_reg, 0);
kono
parents:
diff changeset
1912 else
kono
parents:
diff changeset
1913 new_reg = gen_lowpart_SUBREG (mode, new_reg);
kono
parents:
diff changeset
1914 }
kono
parents:
diff changeset
1915 *loc = new_reg;
kono
parents:
diff changeset
1916 return true;
kono
parents:
diff changeset
1917 }
kono
parents:
diff changeset
1918
kono
parents:
diff changeset
1919 /* Scan all the operand sub-expressions. */
kono
parents:
diff changeset
1920 fmt = GET_RTX_FORMAT (code);
kono
parents:
diff changeset
1921 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
kono
parents:
diff changeset
1922 {
kono
parents:
diff changeset
1923 if (fmt[i] == 'e')
kono
parents:
diff changeset
1924 {
kono
parents:
diff changeset
1925 if (lra_substitute_pseudo (&XEXP (x, i), old_regno,
kono
parents:
diff changeset
1926 new_reg, subreg_p))
kono
parents:
diff changeset
1927 result = true;
kono
parents:
diff changeset
1928 }
kono
parents:
diff changeset
1929 else if (fmt[i] == 'E')
kono
parents:
diff changeset
1930 {
kono
parents:
diff changeset
1931 for (j = XVECLEN (x, i) - 1; j >= 0; j--)
kono
parents:
diff changeset
1932 if (lra_substitute_pseudo (&XVECEXP (x, i, j), old_regno,
kono
parents:
diff changeset
1933 new_reg, subreg_p))
kono
parents:
diff changeset
1934 result = true;
kono
parents:
diff changeset
1935 }
kono
parents:
diff changeset
1936 }
kono
parents:
diff changeset
1937 return result;
kono
parents:
diff changeset
1938 }
kono
parents:
diff changeset
1939
kono
parents:
diff changeset
1940 /* Call lra_substitute_pseudo within an insn. Try to simplify subreg
kono
parents:
diff changeset
1941 of constant if SUBREG_P. This won't update the insn ptr, just the
kono
parents:
diff changeset
1942 contents of the insn. */
kono
parents:
diff changeset
1943 bool
kono
parents:
diff changeset
1944 lra_substitute_pseudo_within_insn (rtx_insn *insn, int old_regno,
kono
parents:
diff changeset
1945 rtx new_reg, bool subreg_p)
kono
parents:
diff changeset
1946 {
kono
parents:
diff changeset
1947 rtx loc = insn;
kono
parents:
diff changeset
1948 return lra_substitute_pseudo (&loc, old_regno, new_reg, subreg_p);
kono
parents:
diff changeset
1949 }
kono
parents:
diff changeset
1950
kono
parents:
diff changeset
1951
kono
parents:
diff changeset
1952
kono
parents:
diff changeset
1953 /* This page contains code dealing with scratches (changing them onto
kono
parents:
diff changeset
1954 pseudos and restoring them from the pseudos).
kono
parents:
diff changeset
1955
kono
parents:
diff changeset
1956 We change scratches into pseudos at the beginning of LRA to
kono
parents:
diff changeset
1957 simplify dealing with them (conflicts, hard register assignments).
kono
parents:
diff changeset
1958
kono
parents:
diff changeset
1959 If the pseudo denoting scratch was spilled it means that we do need
kono
parents:
diff changeset
1960 a hard register for it. Such pseudos are transformed back to
kono
parents:
diff changeset
1961 scratches at the end of LRA. */
kono
parents:
diff changeset
1962
kono
parents:
diff changeset
1963 /* Description of location of a former scratch operand. */
kono
parents:
diff changeset
1964 struct sloc
kono
parents:
diff changeset
1965 {
kono
parents:
diff changeset
1966 rtx_insn *insn; /* Insn where the scratch was. */
kono
parents:
diff changeset
1967 int nop; /* Number of the operand which was a scratch. */
kono
parents:
diff changeset
1968 };
kono
parents:
diff changeset
1969
kono
parents:
diff changeset
1970 typedef struct sloc *sloc_t;
kono
parents:
diff changeset
1971
kono
parents:
diff changeset
1972 /* Locations of the former scratches. */
kono
parents:
diff changeset
1973 static vec<sloc_t> scratches;
kono
parents:
diff changeset
1974
kono
parents:
diff changeset
1975 /* Bitmap of scratch regnos. */
kono
parents:
diff changeset
1976 static bitmap_head scratch_bitmap;
kono
parents:
diff changeset
1977
kono
parents:
diff changeset
1978 /* Bitmap of scratch operands. */
kono
parents:
diff changeset
1979 static bitmap_head scratch_operand_bitmap;
kono
parents:
diff changeset
1980
kono
parents:
diff changeset
1981 /* Return true if pseudo REGNO is made of SCRATCH. */
kono
parents:
diff changeset
1982 bool
kono
parents:
diff changeset
1983 lra_former_scratch_p (int regno)
kono
parents:
diff changeset
1984 {
kono
parents:
diff changeset
1985 return bitmap_bit_p (&scratch_bitmap, regno);
kono
parents:
diff changeset
1986 }
kono
parents:
diff changeset
1987
kono
parents:
diff changeset
1988 /* Return true if the operand NOP of INSN is a former scratch. */
kono
parents:
diff changeset
1989 bool
kono
parents:
diff changeset
1990 lra_former_scratch_operand_p (rtx_insn *insn, int nop)
kono
parents:
diff changeset
1991 {
kono
parents:
diff changeset
1992 return bitmap_bit_p (&scratch_operand_bitmap,
kono
parents:
diff changeset
1993 INSN_UID (insn) * MAX_RECOG_OPERANDS + nop) != 0;
kono
parents:
diff changeset
1994 }
kono
parents:
diff changeset
1995
kono
parents:
diff changeset
1996 /* Register operand NOP in INSN as a former scratch. It will be
kono
parents:
diff changeset
1997 changed to scratch back, if it is necessary, at the LRA end. */
kono
parents:
diff changeset
1998 void
kono
parents:
diff changeset
1999 lra_register_new_scratch_op (rtx_insn *insn, int nop)
kono
parents:
diff changeset
2000 {
kono
parents:
diff changeset
2001 lra_insn_recog_data_t id = lra_get_insn_recog_data (insn);
kono
parents:
diff changeset
2002 rtx op = *id->operand_loc[nop];
kono
parents:
diff changeset
2003 sloc_t loc = XNEW (struct sloc);
kono
parents:
diff changeset
2004 lra_assert (REG_P (op));
kono
parents:
diff changeset
2005 loc->insn = insn;
kono
parents:
diff changeset
2006 loc->nop = nop;
kono
parents:
diff changeset
2007 scratches.safe_push (loc);
kono
parents:
diff changeset
2008 bitmap_set_bit (&scratch_bitmap, REGNO (op));
kono
parents:
diff changeset
2009 bitmap_set_bit (&scratch_operand_bitmap,
kono
parents:
diff changeset
2010 INSN_UID (insn) * MAX_RECOG_OPERANDS + nop);
kono
parents:
diff changeset
2011 add_reg_note (insn, REG_UNUSED, op);
kono
parents:
diff changeset
2012 }
kono
parents:
diff changeset
2013
kono
parents:
diff changeset
2014 /* Change scratches onto pseudos and save their location. */
kono
parents:
diff changeset
2015 static void
kono
parents:
diff changeset
2016 remove_scratches (void)
kono
parents:
diff changeset
2017 {
kono
parents:
diff changeset
2018 int i;
kono
parents:
diff changeset
2019 bool insn_changed_p;
kono
parents:
diff changeset
2020 basic_block bb;
kono
parents:
diff changeset
2021 rtx_insn *insn;
kono
parents:
diff c