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

gcc 7
author kono
date Fri, 27 Oct 2017 22:46:09 +0900
parents
children 84e7813d76e9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 /* Change pseudos by memory.
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 /* This file contains code for a pass to change spilled pseudos into
kono
parents:
diff changeset
23 memory.
kono
parents:
diff changeset
24
kono
parents:
diff changeset
25 The pass creates necessary stack slots and assigns spilled pseudos
kono
parents:
diff changeset
26 to the stack slots in following way:
kono
parents:
diff changeset
27
kono
parents:
diff changeset
28 for all spilled pseudos P most frequently used first do
kono
parents:
diff changeset
29 for all stack slots S do
kono
parents:
diff changeset
30 if P doesn't conflict with pseudos assigned to S then
kono
parents:
diff changeset
31 assign S to P and goto to the next pseudo process
kono
parents:
diff changeset
32 end
kono
parents:
diff changeset
33 end
kono
parents:
diff changeset
34 create new stack slot S and assign P to S
kono
parents:
diff changeset
35 end
kono
parents:
diff changeset
36
kono
parents:
diff changeset
37 The actual algorithm is bit more complicated because of different
kono
parents:
diff changeset
38 pseudo sizes.
kono
parents:
diff changeset
39
kono
parents:
diff changeset
40 After that the code changes spilled pseudos (except ones created
kono
parents:
diff changeset
41 from scratches) by corresponding stack slot memory in RTL.
kono
parents:
diff changeset
42
kono
parents:
diff changeset
43 If at least one stack slot was created, we need to run more passes
kono
parents:
diff changeset
44 because we have new addresses which should be checked and because
kono
parents:
diff changeset
45 the old address displacements might change and address constraints
kono
parents:
diff changeset
46 (or insn memory constraints) might not be satisfied any more.
kono
parents:
diff changeset
47
kono
parents:
diff changeset
48 For some targets, the pass can spill some pseudos into hard
kono
parents:
diff changeset
49 registers of different class (usually into vector registers)
kono
parents:
diff changeset
50 instead of spilling them into memory if it is possible and
kono
parents:
diff changeset
51 profitable. Spilling GENERAL_REGS pseudo into SSE registers for
kono
parents:
diff changeset
52 Intel Corei7 is an example of such optimization. And this is
kono
parents:
diff changeset
53 actually recommended by Intel optimization guide.
kono
parents:
diff changeset
54
kono
parents:
diff changeset
55 The file also contains code for final change of pseudos on hard
kono
parents:
diff changeset
56 regs correspondingly assigned to them. */
kono
parents:
diff changeset
57
kono
parents:
diff changeset
58 #include "config.h"
kono
parents:
diff changeset
59 #include "system.h"
kono
parents:
diff changeset
60 #include "coretypes.h"
kono
parents:
diff changeset
61 #include "backend.h"
kono
parents:
diff changeset
62 #include "target.h"
kono
parents:
diff changeset
63 #include "rtl.h"
kono
parents:
diff changeset
64 #include "df.h"
kono
parents:
diff changeset
65 #include "insn-config.h"
kono
parents:
diff changeset
66 #include "regs.h"
kono
parents:
diff changeset
67 #include "memmodel.h"
kono
parents:
diff changeset
68 #include "ira.h"
kono
parents:
diff changeset
69 #include "recog.h"
kono
parents:
diff changeset
70 #include "output.h"
kono
parents:
diff changeset
71 #include "cfgrtl.h"
kono
parents:
diff changeset
72 #include "lra.h"
kono
parents:
diff changeset
73 #include "lra-int.h"
kono
parents:
diff changeset
74
kono
parents:
diff changeset
75
kono
parents:
diff changeset
76 /* Max regno at the start of the pass. */
kono
parents:
diff changeset
77 static int regs_num;
kono
parents:
diff changeset
78
kono
parents:
diff changeset
79 /* Map spilled regno -> hard regno used instead of memory for
kono
parents:
diff changeset
80 spilling. */
kono
parents:
diff changeset
81 static rtx *spill_hard_reg;
kono
parents:
diff changeset
82
kono
parents:
diff changeset
83 /* The structure describes stack slot of a spilled pseudo. */
kono
parents:
diff changeset
84 struct pseudo_slot
kono
parents:
diff changeset
85 {
kono
parents:
diff changeset
86 /* Number (0, 1, ...) of the stack slot to which given pseudo
kono
parents:
diff changeset
87 belongs. */
kono
parents:
diff changeset
88 int slot_num;
kono
parents:
diff changeset
89 /* First or next slot with the same slot number. */
kono
parents:
diff changeset
90 struct pseudo_slot *next, *first;
kono
parents:
diff changeset
91 /* Memory representing the spilled pseudo. */
kono
parents:
diff changeset
92 rtx mem;
kono
parents:
diff changeset
93 };
kono
parents:
diff changeset
94
kono
parents:
diff changeset
95 /* The stack slots for each spilled pseudo. Indexed by regnos. */
kono
parents:
diff changeset
96 static struct pseudo_slot *pseudo_slots;
kono
parents:
diff changeset
97
kono
parents:
diff changeset
98 /* The structure describes a register or a stack slot which can be
kono
parents:
diff changeset
99 used for several spilled pseudos. */
kono
parents:
diff changeset
100 struct slot
kono
parents:
diff changeset
101 {
kono
parents:
diff changeset
102 /* First pseudo with given stack slot. */
kono
parents:
diff changeset
103 int regno;
kono
parents:
diff changeset
104 /* Hard reg into which the slot pseudos are spilled. The value is
kono
parents:
diff changeset
105 negative for pseudos spilled into memory. */
kono
parents:
diff changeset
106 int hard_regno;
kono
parents:
diff changeset
107 /* Maximum alignment required by all users of the slot. */
kono
parents:
diff changeset
108 unsigned int align;
kono
parents:
diff changeset
109 /* Maximum size required by all users of the slot. */
kono
parents:
diff changeset
110 HOST_WIDE_INT size;
kono
parents:
diff changeset
111 /* Memory representing the all stack slot. It can be different from
kono
parents:
diff changeset
112 memory representing a pseudo belonging to give stack slot because
kono
parents:
diff changeset
113 pseudo can be placed in a part of the corresponding stack slot.
kono
parents:
diff changeset
114 The value is NULL for pseudos spilled into a hard reg. */
kono
parents:
diff changeset
115 rtx mem;
kono
parents:
diff changeset
116 /* Combined live ranges of all pseudos belonging to given slot. It
kono
parents:
diff changeset
117 is used to figure out that a new spilled pseudo can use given
kono
parents:
diff changeset
118 stack slot. */
kono
parents:
diff changeset
119 lra_live_range_t live_ranges;
kono
parents:
diff changeset
120 };
kono
parents:
diff changeset
121
kono
parents:
diff changeset
122 /* Array containing info about the stack slots. The array element is
kono
parents:
diff changeset
123 indexed by the stack slot number in the range [0..slots_num). */
kono
parents:
diff changeset
124 static struct slot *slots;
kono
parents:
diff changeset
125 /* The number of the stack slots currently existing. */
kono
parents:
diff changeset
126 static int slots_num;
kono
parents:
diff changeset
127
kono
parents:
diff changeset
128 /* Set up memory of the spilled pseudo I. The function can allocate
kono
parents:
diff changeset
129 the corresponding stack slot if it is not done yet. */
kono
parents:
diff changeset
130 static void
kono
parents:
diff changeset
131 assign_mem_slot (int i)
kono
parents:
diff changeset
132 {
kono
parents:
diff changeset
133 rtx x = NULL_RTX;
kono
parents:
diff changeset
134 machine_mode mode = GET_MODE (regno_reg_rtx[i]);
kono
parents:
diff changeset
135 HOST_WIDE_INT inherent_size = PSEUDO_REGNO_BYTES (i);
kono
parents:
diff changeset
136 machine_mode wider_mode
kono
parents:
diff changeset
137 = wider_subreg_mode (mode, lra_reg_info[i].biggest_mode);
kono
parents:
diff changeset
138 HOST_WIDE_INT total_size = GET_MODE_SIZE (wider_mode);
kono
parents:
diff changeset
139 HOST_WIDE_INT adjust = 0;
kono
parents:
diff changeset
140
kono
parents:
diff changeset
141 lra_assert (regno_reg_rtx[i] != NULL_RTX && REG_P (regno_reg_rtx[i])
kono
parents:
diff changeset
142 && lra_reg_info[i].nrefs != 0 && reg_renumber[i] < 0);
kono
parents:
diff changeset
143
kono
parents:
diff changeset
144 unsigned int slot_num = pseudo_slots[i].slot_num;
kono
parents:
diff changeset
145 x = slots[slot_num].mem;
kono
parents:
diff changeset
146 if (!x)
kono
parents:
diff changeset
147 {
kono
parents:
diff changeset
148 x = assign_stack_local (BLKmode, slots[slot_num].size,
kono
parents:
diff changeset
149 slots[slot_num].align);
kono
parents:
diff changeset
150 slots[slot_num].mem = x;
kono
parents:
diff changeset
151 }
kono
parents:
diff changeset
152
kono
parents:
diff changeset
153 /* On a big endian machine, the "address" of the slot is the address
kono
parents:
diff changeset
154 of the low part that fits its inherent mode. */
kono
parents:
diff changeset
155 adjust += subreg_size_lowpart_offset (inherent_size, total_size);
kono
parents:
diff changeset
156 x = adjust_address_nv (x, GET_MODE (regno_reg_rtx[i]), adjust);
kono
parents:
diff changeset
157
kono
parents:
diff changeset
158 /* Set all of the memory attributes as appropriate for a spill. */
kono
parents:
diff changeset
159 set_mem_attrs_for_spill (x);
kono
parents:
diff changeset
160 pseudo_slots[i].mem = x;
kono
parents:
diff changeset
161 }
kono
parents:
diff changeset
162
kono
parents:
diff changeset
163 /* Sort pseudos according their usage frequencies. */
kono
parents:
diff changeset
164 static int
kono
parents:
diff changeset
165 regno_freq_compare (const void *v1p, const void *v2p)
kono
parents:
diff changeset
166 {
kono
parents:
diff changeset
167 const int regno1 = *(const int *) v1p;
kono
parents:
diff changeset
168 const int regno2 = *(const int *) v2p;
kono
parents:
diff changeset
169 int diff;
kono
parents:
diff changeset
170
kono
parents:
diff changeset
171 if ((diff = lra_reg_info[regno2].freq - lra_reg_info[regno1].freq) != 0)
kono
parents:
diff changeset
172 return diff;
kono
parents:
diff changeset
173 return regno1 - regno2;
kono
parents:
diff changeset
174 }
kono
parents:
diff changeset
175
kono
parents:
diff changeset
176 /* Sort pseudos according to their slots, putting the slots in the order
kono
parents:
diff changeset
177 that they should be allocated. Slots with lower numbers have the highest
kono
parents:
diff changeset
178 priority and should get the smallest displacement from the stack or
kono
parents:
diff changeset
179 frame pointer (whichever is being used).
kono
parents:
diff changeset
180
kono
parents:
diff changeset
181 The first allocated slot is always closest to the frame pointer,
kono
parents:
diff changeset
182 so prefer lower slot numbers when frame_pointer_needed. If the stack
kono
parents:
diff changeset
183 and frame grow in the same direction, then the first allocated slot is
kono
parents:
diff changeset
184 always closest to the initial stack pointer and furthest away from the
kono
parents:
diff changeset
185 final stack pointer, so allocate higher numbers first when using the
kono
parents:
diff changeset
186 stack pointer in that case. The reverse is true if the stack and
kono
parents:
diff changeset
187 frame grow in opposite directions. */
kono
parents:
diff changeset
188 static int
kono
parents:
diff changeset
189 pseudo_reg_slot_compare (const void *v1p, const void *v2p)
kono
parents:
diff changeset
190 {
kono
parents:
diff changeset
191 const int regno1 = *(const int *) v1p;
kono
parents:
diff changeset
192 const int regno2 = *(const int *) v2p;
kono
parents:
diff changeset
193 int diff, slot_num1, slot_num2;
kono
parents:
diff changeset
194 int total_size1, total_size2;
kono
parents:
diff changeset
195
kono
parents:
diff changeset
196 slot_num1 = pseudo_slots[regno1].slot_num;
kono
parents:
diff changeset
197 slot_num2 = pseudo_slots[regno2].slot_num;
kono
parents:
diff changeset
198 if ((diff = slot_num1 - slot_num2) != 0)
kono
parents:
diff changeset
199 return (frame_pointer_needed
kono
parents:
diff changeset
200 || (!FRAME_GROWS_DOWNWARD) == STACK_GROWS_DOWNWARD ? diff : -diff);
kono
parents:
diff changeset
201 total_size1 = GET_MODE_SIZE (lra_reg_info[regno1].biggest_mode);
kono
parents:
diff changeset
202 total_size2 = GET_MODE_SIZE (lra_reg_info[regno2].biggest_mode);
kono
parents:
diff changeset
203 if ((diff = total_size2 - total_size1) != 0)
kono
parents:
diff changeset
204 return diff;
kono
parents:
diff changeset
205 return regno1 - regno2;
kono
parents:
diff changeset
206 }
kono
parents:
diff changeset
207
kono
parents:
diff changeset
208 /* Assign spill hard registers to N pseudos in PSEUDO_REGNOS which is
kono
parents:
diff changeset
209 sorted in order of highest frequency first. Put the pseudos which
kono
parents:
diff changeset
210 did not get a spill hard register at the beginning of array
kono
parents:
diff changeset
211 PSEUDO_REGNOS. Return the number of such pseudos. */
kono
parents:
diff changeset
212 static int
kono
parents:
diff changeset
213 assign_spill_hard_regs (int *pseudo_regnos, int n)
kono
parents:
diff changeset
214 {
kono
parents:
diff changeset
215 int i, k, p, regno, res, spill_class_size, hard_regno, nr;
kono
parents:
diff changeset
216 enum reg_class rclass, spill_class;
kono
parents:
diff changeset
217 machine_mode mode;
kono
parents:
diff changeset
218 lra_live_range_t r;
kono
parents:
diff changeset
219 rtx_insn *insn;
kono
parents:
diff changeset
220 rtx set;
kono
parents:
diff changeset
221 basic_block bb;
kono
parents:
diff changeset
222 HARD_REG_SET conflict_hard_regs;
kono
parents:
diff changeset
223 bitmap setjump_crosses = regstat_get_setjmp_crosses ();
kono
parents:
diff changeset
224 /* Hard registers which can not be used for any purpose at given
kono
parents:
diff changeset
225 program point because they are unallocatable or already allocated
kono
parents:
diff changeset
226 for other pseudos. */
kono
parents:
diff changeset
227 HARD_REG_SET *reserved_hard_regs;
kono
parents:
diff changeset
228
kono
parents:
diff changeset
229 if (! lra_reg_spill_p)
kono
parents:
diff changeset
230 return n;
kono
parents:
diff changeset
231 /* Set up reserved hard regs for every program point. */
kono
parents:
diff changeset
232 reserved_hard_regs = XNEWVEC (HARD_REG_SET, lra_live_max_point);
kono
parents:
diff changeset
233 for (p = 0; p < lra_live_max_point; p++)
kono
parents:
diff changeset
234 COPY_HARD_REG_SET (reserved_hard_regs[p], lra_no_alloc_regs);
kono
parents:
diff changeset
235 for (i = FIRST_PSEUDO_REGISTER; i < regs_num; i++)
kono
parents:
diff changeset
236 if (lra_reg_info[i].nrefs != 0
kono
parents:
diff changeset
237 && (hard_regno = lra_get_regno_hard_regno (i)) >= 0)
kono
parents:
diff changeset
238 for (r = lra_reg_info[i].live_ranges; r != NULL; r = r->next)
kono
parents:
diff changeset
239 for (p = r->start; p <= r->finish; p++)
kono
parents:
diff changeset
240 add_to_hard_reg_set (&reserved_hard_regs[p],
kono
parents:
diff changeset
241 lra_reg_info[i].biggest_mode, hard_regno);
kono
parents:
diff changeset
242 auto_bitmap ok_insn_bitmap (&reg_obstack);
kono
parents:
diff changeset
243 FOR_EACH_BB_FN (bb, cfun)
kono
parents:
diff changeset
244 FOR_BB_INSNS (bb, insn)
kono
parents:
diff changeset
245 if (DEBUG_INSN_P (insn)
kono
parents:
diff changeset
246 || ((set = single_set (insn)) != NULL_RTX
kono
parents:
diff changeset
247 && REG_P (SET_SRC (set)) && REG_P (SET_DEST (set))))
kono
parents:
diff changeset
248 bitmap_set_bit (ok_insn_bitmap, INSN_UID (insn));
kono
parents:
diff changeset
249 for (res = i = 0; i < n; i++)
kono
parents:
diff changeset
250 {
kono
parents:
diff changeset
251 regno = pseudo_regnos[i];
kono
parents:
diff changeset
252 rclass = lra_get_allocno_class (regno);
kono
parents:
diff changeset
253 if (bitmap_bit_p (setjump_crosses, regno)
kono
parents:
diff changeset
254 || (spill_class
kono
parents:
diff changeset
255 = ((enum reg_class)
kono
parents:
diff changeset
256 targetm.spill_class ((reg_class_t) rclass,
kono
parents:
diff changeset
257 PSEUDO_REGNO_MODE (regno)))) == NO_REGS
kono
parents:
diff changeset
258 || bitmap_intersect_compl_p (&lra_reg_info[regno].insn_bitmap,
kono
parents:
diff changeset
259 ok_insn_bitmap))
kono
parents:
diff changeset
260 {
kono
parents:
diff changeset
261 pseudo_regnos[res++] = regno;
kono
parents:
diff changeset
262 continue;
kono
parents:
diff changeset
263 }
kono
parents:
diff changeset
264 lra_assert (spill_class != NO_REGS);
kono
parents:
diff changeset
265 COPY_HARD_REG_SET (conflict_hard_regs,
kono
parents:
diff changeset
266 lra_reg_info[regno].conflict_hard_regs);
kono
parents:
diff changeset
267 for (r = lra_reg_info[regno].live_ranges; r != NULL; r = r->next)
kono
parents:
diff changeset
268 for (p = r->start; p <= r->finish; p++)
kono
parents:
diff changeset
269 IOR_HARD_REG_SET (conflict_hard_regs, reserved_hard_regs[p]);
kono
parents:
diff changeset
270 spill_class_size = ira_class_hard_regs_num[spill_class];
kono
parents:
diff changeset
271 mode = lra_reg_info[regno].biggest_mode;
kono
parents:
diff changeset
272 for (k = 0; k < spill_class_size; k++)
kono
parents:
diff changeset
273 {
kono
parents:
diff changeset
274 hard_regno = ira_class_hard_regs[spill_class][k];
kono
parents:
diff changeset
275 if (! overlaps_hard_reg_set_p (conflict_hard_regs, mode, hard_regno))
kono
parents:
diff changeset
276 break;
kono
parents:
diff changeset
277 }
kono
parents:
diff changeset
278 if (k >= spill_class_size)
kono
parents:
diff changeset
279 {
kono
parents:
diff changeset
280 /* There is no available regs -- assign memory later. */
kono
parents:
diff changeset
281 pseudo_regnos[res++] = regno;
kono
parents:
diff changeset
282 continue;
kono
parents:
diff changeset
283 }
kono
parents:
diff changeset
284 if (lra_dump_file != NULL)
kono
parents:
diff changeset
285 fprintf (lra_dump_file, " Spill r%d into hr%d\n", regno, hard_regno);
kono
parents:
diff changeset
286 /* Update reserved_hard_regs. */
kono
parents:
diff changeset
287 for (r = lra_reg_info[regno].live_ranges; r != NULL; r = r->next)
kono
parents:
diff changeset
288 for (p = r->start; p <= r->finish; p++)
kono
parents:
diff changeset
289 add_to_hard_reg_set (&reserved_hard_regs[p],
kono
parents:
diff changeset
290 lra_reg_info[regno].biggest_mode, hard_regno);
kono
parents:
diff changeset
291 spill_hard_reg[regno]
kono
parents:
diff changeset
292 = gen_raw_REG (PSEUDO_REGNO_MODE (regno), hard_regno);
kono
parents:
diff changeset
293 for (nr = 0;
kono
parents:
diff changeset
294 nr < hard_regno_nregs (hard_regno,
kono
parents:
diff changeset
295 lra_reg_info[regno].biggest_mode);
kono
parents:
diff changeset
296 nr++)
kono
parents:
diff changeset
297 /* Just loop. */
kono
parents:
diff changeset
298 df_set_regs_ever_live (hard_regno + nr, true);
kono
parents:
diff changeset
299 }
kono
parents:
diff changeset
300 free (reserved_hard_regs);
kono
parents:
diff changeset
301 return res;
kono
parents:
diff changeset
302 }
kono
parents:
diff changeset
303
kono
parents:
diff changeset
304 /* Add pseudo REGNO to slot SLOT_NUM. */
kono
parents:
diff changeset
305 static void
kono
parents:
diff changeset
306 add_pseudo_to_slot (int regno, int slot_num)
kono
parents:
diff changeset
307 {
kono
parents:
diff changeset
308 struct pseudo_slot *first;
kono
parents:
diff changeset
309
kono
parents:
diff changeset
310 /* Each pseudo has an inherent size which comes from its own mode,
kono
parents:
diff changeset
311 and a total size which provides room for paradoxical subregs.
kono
parents:
diff changeset
312 We need to make sure the size and alignment of the slot are
kono
parents:
diff changeset
313 sufficient for both. */
kono
parents:
diff changeset
314 machine_mode mode = wider_subreg_mode (PSEUDO_REGNO_MODE (regno),
kono
parents:
diff changeset
315 lra_reg_info[regno].biggest_mode);
kono
parents:
diff changeset
316 unsigned int align = spill_slot_alignment (mode);
kono
parents:
diff changeset
317 slots[slot_num].align = MAX (slots[slot_num].align, align);
kono
parents:
diff changeset
318 slots[slot_num].size = MAX (slots[slot_num].size, GET_MODE_SIZE (mode));
kono
parents:
diff changeset
319
kono
parents:
diff changeset
320 if (slots[slot_num].regno < 0)
kono
parents:
diff changeset
321 {
kono
parents:
diff changeset
322 /* It is the first pseudo in the slot. */
kono
parents:
diff changeset
323 slots[slot_num].regno = regno;
kono
parents:
diff changeset
324 pseudo_slots[regno].first = &pseudo_slots[regno];
kono
parents:
diff changeset
325 pseudo_slots[regno].next = NULL;
kono
parents:
diff changeset
326 }
kono
parents:
diff changeset
327 else
kono
parents:
diff changeset
328 {
kono
parents:
diff changeset
329 first = pseudo_slots[regno].first = &pseudo_slots[slots[slot_num].regno];
kono
parents:
diff changeset
330 pseudo_slots[regno].next = first->next;
kono
parents:
diff changeset
331 first->next = &pseudo_slots[regno];
kono
parents:
diff changeset
332 }
kono
parents:
diff changeset
333 pseudo_slots[regno].mem = NULL_RTX;
kono
parents:
diff changeset
334 pseudo_slots[regno].slot_num = slot_num;
kono
parents:
diff changeset
335 slots[slot_num].live_ranges
kono
parents:
diff changeset
336 = lra_merge_live_ranges (slots[slot_num].live_ranges,
kono
parents:
diff changeset
337 lra_copy_live_range_list
kono
parents:
diff changeset
338 (lra_reg_info[regno].live_ranges));
kono
parents:
diff changeset
339 }
kono
parents:
diff changeset
340
kono
parents:
diff changeset
341 /* Assign stack slot numbers to pseudos in array PSEUDO_REGNOS of
kono
parents:
diff changeset
342 length N. Sort pseudos in PSEUDO_REGNOS for subsequent assigning
kono
parents:
diff changeset
343 memory stack slots. */
kono
parents:
diff changeset
344 static void
kono
parents:
diff changeset
345 assign_stack_slot_num_and_sort_pseudos (int *pseudo_regnos, int n)
kono
parents:
diff changeset
346 {
kono
parents:
diff changeset
347 int i, j, regno;
kono
parents:
diff changeset
348
kono
parents:
diff changeset
349 slots_num = 0;
kono
parents:
diff changeset
350 /* Assign stack slot numbers to spilled pseudos, use smaller numbers
kono
parents:
diff changeset
351 for most frequently used pseudos. */
kono
parents:
diff changeset
352 for (i = 0; i < n; i++)
kono
parents:
diff changeset
353 {
kono
parents:
diff changeset
354 regno = pseudo_regnos[i];
kono
parents:
diff changeset
355 if (! flag_ira_share_spill_slots)
kono
parents:
diff changeset
356 j = slots_num;
kono
parents:
diff changeset
357 else
kono
parents:
diff changeset
358 {
kono
parents:
diff changeset
359 for (j = 0; j < slots_num; j++)
kono
parents:
diff changeset
360 if (slots[j].hard_regno < 0
kono
parents:
diff changeset
361 && ! (lra_intersected_live_ranges_p
kono
parents:
diff changeset
362 (slots[j].live_ranges,
kono
parents:
diff changeset
363 lra_reg_info[regno].live_ranges)))
kono
parents:
diff changeset
364 break;
kono
parents:
diff changeset
365 }
kono
parents:
diff changeset
366 if (j >= slots_num)
kono
parents:
diff changeset
367 {
kono
parents:
diff changeset
368 /* New slot. */
kono
parents:
diff changeset
369 slots[j].live_ranges = NULL;
kono
parents:
diff changeset
370 slots[j].size = 0;
kono
parents:
diff changeset
371 slots[j].align = BITS_PER_UNIT;
kono
parents:
diff changeset
372 slots[j].regno = slots[j].hard_regno = -1;
kono
parents:
diff changeset
373 slots[j].mem = NULL_RTX;
kono
parents:
diff changeset
374 slots_num++;
kono
parents:
diff changeset
375 }
kono
parents:
diff changeset
376 add_pseudo_to_slot (regno, j);
kono
parents:
diff changeset
377 }
kono
parents:
diff changeset
378 /* Sort regnos according to their slot numbers. */
kono
parents:
diff changeset
379 qsort (pseudo_regnos, n, sizeof (int), pseudo_reg_slot_compare);
kono
parents:
diff changeset
380 }
kono
parents:
diff changeset
381
kono
parents:
diff changeset
382 /* Recursively process LOC in INSN and change spilled pseudos to the
kono
parents:
diff changeset
383 corresponding memory or spilled hard reg. Ignore spilled pseudos
kono
parents:
diff changeset
384 created from the scratches. Return true if the pseudo nrefs equal
kono
parents:
diff changeset
385 to 0 (don't change the pseudo in this case). Otherwise return false. */
kono
parents:
diff changeset
386 static bool
kono
parents:
diff changeset
387 remove_pseudos (rtx *loc, rtx_insn *insn)
kono
parents:
diff changeset
388 {
kono
parents:
diff changeset
389 int i;
kono
parents:
diff changeset
390 rtx hard_reg;
kono
parents:
diff changeset
391 const char *fmt;
kono
parents:
diff changeset
392 enum rtx_code code;
kono
parents:
diff changeset
393 bool res = false;
kono
parents:
diff changeset
394
kono
parents:
diff changeset
395 if (*loc == NULL_RTX)
kono
parents:
diff changeset
396 return res;
kono
parents:
diff changeset
397 code = GET_CODE (*loc);
kono
parents:
diff changeset
398 if (code == REG && (i = REGNO (*loc)) >= FIRST_PSEUDO_REGISTER
kono
parents:
diff changeset
399 && lra_get_regno_hard_regno (i) < 0
kono
parents:
diff changeset
400 /* We do not want to assign memory for former scratches because
kono
parents:
diff changeset
401 it might result in an address reload for some targets. In
kono
parents:
diff changeset
402 any case we transform such pseudos not getting hard registers
kono
parents:
diff changeset
403 into scratches back. */
kono
parents:
diff changeset
404 && ! lra_former_scratch_p (i))
kono
parents:
diff changeset
405 {
kono
parents:
diff changeset
406 if (lra_reg_info[i].nrefs == 0
kono
parents:
diff changeset
407 && pseudo_slots[i].mem == NULL && spill_hard_reg[i] == NULL)
kono
parents:
diff changeset
408 return true;
kono
parents:
diff changeset
409 if ((hard_reg = spill_hard_reg[i]) != NULL_RTX)
kono
parents:
diff changeset
410 *loc = copy_rtx (hard_reg);
kono
parents:
diff changeset
411 else
kono
parents:
diff changeset
412 {
kono
parents:
diff changeset
413 rtx x = lra_eliminate_regs_1 (insn, pseudo_slots[i].mem,
kono
parents:
diff changeset
414 GET_MODE (pseudo_slots[i].mem),
kono
parents:
diff changeset
415 false, false, 0, true);
kono
parents:
diff changeset
416 *loc = x != pseudo_slots[i].mem ? x : copy_rtx (x);
kono
parents:
diff changeset
417 }
kono
parents:
diff changeset
418 return res;
kono
parents:
diff changeset
419 }
kono
parents:
diff changeset
420
kono
parents:
diff changeset
421 fmt = GET_RTX_FORMAT (code);
kono
parents:
diff changeset
422 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
kono
parents:
diff changeset
423 {
kono
parents:
diff changeset
424 if (fmt[i] == 'e')
kono
parents:
diff changeset
425 res = remove_pseudos (&XEXP (*loc, i), insn) || res;
kono
parents:
diff changeset
426 else if (fmt[i] == 'E')
kono
parents:
diff changeset
427 {
kono
parents:
diff changeset
428 int j;
kono
parents:
diff changeset
429
kono
parents:
diff changeset
430 for (j = XVECLEN (*loc, i) - 1; j >= 0; j--)
kono
parents:
diff changeset
431 res = remove_pseudos (&XVECEXP (*loc, i, j), insn) || res;
kono
parents:
diff changeset
432 }
kono
parents:
diff changeset
433 }
kono
parents:
diff changeset
434 return res;
kono
parents:
diff changeset
435 }
kono
parents:
diff changeset
436
kono
parents:
diff changeset
437 /* Convert spilled pseudos into their stack slots or spill hard regs,
kono
parents:
diff changeset
438 put insns to process on the constraint stack (that is all insns in
kono
parents:
diff changeset
439 which pseudos were changed to memory or spill hard regs). */
kono
parents:
diff changeset
440 static void
kono
parents:
diff changeset
441 spill_pseudos (void)
kono
parents:
diff changeset
442 {
kono
parents:
diff changeset
443 basic_block bb;
kono
parents:
diff changeset
444 rtx_insn *insn, *curr;
kono
parents:
diff changeset
445 int i;
kono
parents:
diff changeset
446
kono
parents:
diff changeset
447 auto_bitmap spilled_pseudos (&reg_obstack);
kono
parents:
diff changeset
448 auto_bitmap changed_insns (&reg_obstack);
kono
parents:
diff changeset
449 for (i = FIRST_PSEUDO_REGISTER; i < regs_num; i++)
kono
parents:
diff changeset
450 {
kono
parents:
diff changeset
451 if (lra_reg_info[i].nrefs != 0 && lra_get_regno_hard_regno (i) < 0
kono
parents:
diff changeset
452 && ! lra_former_scratch_p (i))
kono
parents:
diff changeset
453 {
kono
parents:
diff changeset
454 bitmap_set_bit (spilled_pseudos, i);
kono
parents:
diff changeset
455 bitmap_ior_into (changed_insns, &lra_reg_info[i].insn_bitmap);
kono
parents:
diff changeset
456 }
kono
parents:
diff changeset
457 }
kono
parents:
diff changeset
458 FOR_EACH_BB_FN (bb, cfun)
kono
parents:
diff changeset
459 {
kono
parents:
diff changeset
460 FOR_BB_INSNS_SAFE (bb, insn, curr)
kono
parents:
diff changeset
461 {
kono
parents:
diff changeset
462 bool removed_pseudo_p = false;
kono
parents:
diff changeset
463
kono
parents:
diff changeset
464 if (bitmap_bit_p (changed_insns, INSN_UID (insn)))
kono
parents:
diff changeset
465 {
kono
parents:
diff changeset
466 rtx *link_loc, link;
kono
parents:
diff changeset
467
kono
parents:
diff changeset
468 removed_pseudo_p = remove_pseudos (&PATTERN (insn), insn);
kono
parents:
diff changeset
469 if (CALL_P (insn)
kono
parents:
diff changeset
470 && remove_pseudos (&CALL_INSN_FUNCTION_USAGE (insn), insn))
kono
parents:
diff changeset
471 removed_pseudo_p = true;
kono
parents:
diff changeset
472 for (link_loc = &REG_NOTES (insn);
kono
parents:
diff changeset
473 (link = *link_loc) != NULL_RTX;
kono
parents:
diff changeset
474 link_loc = &XEXP (link, 1))
kono
parents:
diff changeset
475 {
kono
parents:
diff changeset
476 switch (REG_NOTE_KIND (link))
kono
parents:
diff changeset
477 {
kono
parents:
diff changeset
478 case REG_FRAME_RELATED_EXPR:
kono
parents:
diff changeset
479 case REG_CFA_DEF_CFA:
kono
parents:
diff changeset
480 case REG_CFA_ADJUST_CFA:
kono
parents:
diff changeset
481 case REG_CFA_OFFSET:
kono
parents:
diff changeset
482 case REG_CFA_REGISTER:
kono
parents:
diff changeset
483 case REG_CFA_EXPRESSION:
kono
parents:
diff changeset
484 case REG_CFA_RESTORE:
kono
parents:
diff changeset
485 case REG_CFA_SET_VDRAP:
kono
parents:
diff changeset
486 if (remove_pseudos (&XEXP (link, 0), insn))
kono
parents:
diff changeset
487 removed_pseudo_p = true;
kono
parents:
diff changeset
488 break;
kono
parents:
diff changeset
489 default:
kono
parents:
diff changeset
490 break;
kono
parents:
diff changeset
491 }
kono
parents:
diff changeset
492 }
kono
parents:
diff changeset
493 if (lra_dump_file != NULL)
kono
parents:
diff changeset
494 fprintf (lra_dump_file,
kono
parents:
diff changeset
495 "Changing spilled pseudos to memory in insn #%u\n",
kono
parents:
diff changeset
496 INSN_UID (insn));
kono
parents:
diff changeset
497 lra_push_insn (insn);
kono
parents:
diff changeset
498 if (lra_reg_spill_p || targetm.different_addr_displacement_p ())
kono
parents:
diff changeset
499 lra_set_used_insn_alternative (insn, -1);
kono
parents:
diff changeset
500 }
kono
parents:
diff changeset
501 else if (CALL_P (insn)
kono
parents:
diff changeset
502 /* Presence of any pseudo in CALL_INSN_FUNCTION_USAGE
kono
parents:
diff changeset
503 does not affect value of insn_bitmap of the
kono
parents:
diff changeset
504 corresponding lra_reg_info. That is because we
kono
parents:
diff changeset
505 don't need to reload pseudos in
kono
parents:
diff changeset
506 CALL_INSN_FUNCTION_USAGEs. So if we process only
kono
parents:
diff changeset
507 insns in the insn_bitmap of given pseudo here, we
kono
parents:
diff changeset
508 can miss the pseudo in some
kono
parents:
diff changeset
509 CALL_INSN_FUNCTION_USAGEs. */
kono
parents:
diff changeset
510 && remove_pseudos (&CALL_INSN_FUNCTION_USAGE (insn), insn))
kono
parents:
diff changeset
511 removed_pseudo_p = true;
kono
parents:
diff changeset
512 if (removed_pseudo_p)
kono
parents:
diff changeset
513 {
kono
parents:
diff changeset
514 lra_assert (DEBUG_INSN_P (insn));
kono
parents:
diff changeset
515 lra_invalidate_insn_data (insn);
kono
parents:
diff changeset
516 INSN_VAR_LOCATION_LOC (insn) = gen_rtx_UNKNOWN_VAR_LOC ();
kono
parents:
diff changeset
517 if (lra_dump_file != NULL)
kono
parents:
diff changeset
518 fprintf (lra_dump_file,
kono
parents:
diff changeset
519 "Debug insn #%u is reset because it referenced "
kono
parents:
diff changeset
520 "removed pseudo\n", INSN_UID (insn));
kono
parents:
diff changeset
521 }
kono
parents:
diff changeset
522 bitmap_and_compl_into (df_get_live_in (bb), spilled_pseudos);
kono
parents:
diff changeset
523 bitmap_and_compl_into (df_get_live_out (bb), spilled_pseudos);
kono
parents:
diff changeset
524 }
kono
parents:
diff changeset
525 }
kono
parents:
diff changeset
526 }
kono
parents:
diff changeset
527
kono
parents:
diff changeset
528 /* Return true if we need to change some pseudos into memory. */
kono
parents:
diff changeset
529 bool
kono
parents:
diff changeset
530 lra_need_for_spills_p (void)
kono
parents:
diff changeset
531 {
kono
parents:
diff changeset
532 int i; max_regno = max_reg_num ();
kono
parents:
diff changeset
533
kono
parents:
diff changeset
534 for (i = FIRST_PSEUDO_REGISTER; i < max_regno; i++)
kono
parents:
diff changeset
535 if (lra_reg_info[i].nrefs != 0 && lra_get_regno_hard_regno (i) < 0
kono
parents:
diff changeset
536 && ! lra_former_scratch_p (i))
kono
parents:
diff changeset
537 return true;
kono
parents:
diff changeset
538 return false;
kono
parents:
diff changeset
539 }
kono
parents:
diff changeset
540
kono
parents:
diff changeset
541 /* Change spilled pseudos into memory or spill hard regs. Put changed
kono
parents:
diff changeset
542 insns on the constraint stack (these insns will be considered on
kono
parents:
diff changeset
543 the next constraint pass). The changed insns are all insns in
kono
parents:
diff changeset
544 which pseudos were changed. */
kono
parents:
diff changeset
545 void
kono
parents:
diff changeset
546 lra_spill (void)
kono
parents:
diff changeset
547 {
kono
parents:
diff changeset
548 int i, n, curr_regno;
kono
parents:
diff changeset
549 int *pseudo_regnos;
kono
parents:
diff changeset
550
kono
parents:
diff changeset
551 regs_num = max_reg_num ();
kono
parents:
diff changeset
552 spill_hard_reg = XNEWVEC (rtx, regs_num);
kono
parents:
diff changeset
553 pseudo_regnos = XNEWVEC (int, regs_num);
kono
parents:
diff changeset
554 for (n = 0, i = FIRST_PSEUDO_REGISTER; i < regs_num; i++)
kono
parents:
diff changeset
555 if (lra_reg_info[i].nrefs != 0 && lra_get_regno_hard_regno (i) < 0
kono
parents:
diff changeset
556 /* We do not want to assign memory for former scratches. */
kono
parents:
diff changeset
557 && ! lra_former_scratch_p (i))
kono
parents:
diff changeset
558 pseudo_regnos[n++] = i;
kono
parents:
diff changeset
559 lra_assert (n > 0);
kono
parents:
diff changeset
560 pseudo_slots = XNEWVEC (struct pseudo_slot, regs_num);
kono
parents:
diff changeset
561 for (i = FIRST_PSEUDO_REGISTER; i < regs_num; i++)
kono
parents:
diff changeset
562 {
kono
parents:
diff changeset
563 spill_hard_reg[i] = NULL_RTX;
kono
parents:
diff changeset
564 pseudo_slots[i].mem = NULL_RTX;
kono
parents:
diff changeset
565 }
kono
parents:
diff changeset
566 slots = XNEWVEC (struct slot, regs_num);
kono
parents:
diff changeset
567 /* Sort regnos according their usage frequencies. */
kono
parents:
diff changeset
568 qsort (pseudo_regnos, n, sizeof (int), regno_freq_compare);
kono
parents:
diff changeset
569 n = assign_spill_hard_regs (pseudo_regnos, n);
kono
parents:
diff changeset
570 assign_stack_slot_num_and_sort_pseudos (pseudo_regnos, n);
kono
parents:
diff changeset
571 for (i = 0; i < n; i++)
kono
parents:
diff changeset
572 if (pseudo_slots[pseudo_regnos[i]].mem == NULL_RTX)
kono
parents:
diff changeset
573 assign_mem_slot (pseudo_regnos[i]);
kono
parents:
diff changeset
574 if (n > 0 && crtl->stack_alignment_needed)
kono
parents:
diff changeset
575 /* If we have a stack frame, we must align it now. The stack size
kono
parents:
diff changeset
576 may be a part of the offset computation for register
kono
parents:
diff changeset
577 elimination. */
kono
parents:
diff changeset
578 assign_stack_local (BLKmode, 0, crtl->stack_alignment_needed);
kono
parents:
diff changeset
579 if (lra_dump_file != NULL)
kono
parents:
diff changeset
580 {
kono
parents:
diff changeset
581 for (i = 0; i < slots_num; i++)
kono
parents:
diff changeset
582 {
kono
parents:
diff changeset
583 fprintf (lra_dump_file, " Slot %d regnos (width = %d):", i,
kono
parents:
diff changeset
584 GET_MODE_SIZE (GET_MODE (slots[i].mem)));
kono
parents:
diff changeset
585 for (curr_regno = slots[i].regno;;
kono
parents:
diff changeset
586 curr_regno = pseudo_slots[curr_regno].next - pseudo_slots)
kono
parents:
diff changeset
587 {
kono
parents:
diff changeset
588 fprintf (lra_dump_file, " %d", curr_regno);
kono
parents:
diff changeset
589 if (pseudo_slots[curr_regno].next == NULL)
kono
parents:
diff changeset
590 break;
kono
parents:
diff changeset
591 }
kono
parents:
diff changeset
592 fprintf (lra_dump_file, "\n");
kono
parents:
diff changeset
593 }
kono
parents:
diff changeset
594 }
kono
parents:
diff changeset
595 spill_pseudos ();
kono
parents:
diff changeset
596 free (slots);
kono
parents:
diff changeset
597 free (pseudo_slots);
kono
parents:
diff changeset
598 free (pseudo_regnos);
kono
parents:
diff changeset
599 free (spill_hard_reg);
kono
parents:
diff changeset
600 }
kono
parents:
diff changeset
601
kono
parents:
diff changeset
602 /* Apply alter_subreg for subregs of regs in *LOC. Use FINAL_P for
kono
parents:
diff changeset
603 alter_subreg calls. Return true if any subreg of reg is
kono
parents:
diff changeset
604 processed. */
kono
parents:
diff changeset
605 static bool
kono
parents:
diff changeset
606 alter_subregs (rtx *loc, bool final_p)
kono
parents:
diff changeset
607 {
kono
parents:
diff changeset
608 int i;
kono
parents:
diff changeset
609 rtx x = *loc;
kono
parents:
diff changeset
610 bool res;
kono
parents:
diff changeset
611 const char *fmt;
kono
parents:
diff changeset
612 enum rtx_code code;
kono
parents:
diff changeset
613
kono
parents:
diff changeset
614 if (x == NULL_RTX)
kono
parents:
diff changeset
615 return false;
kono
parents:
diff changeset
616 code = GET_CODE (x);
kono
parents:
diff changeset
617 if (code == SUBREG && REG_P (SUBREG_REG (x)))
kono
parents:
diff changeset
618 {
kono
parents:
diff changeset
619 lra_assert (REGNO (SUBREG_REG (x)) < FIRST_PSEUDO_REGISTER);
kono
parents:
diff changeset
620 alter_subreg (loc, final_p);
kono
parents:
diff changeset
621 return true;
kono
parents:
diff changeset
622 }
kono
parents:
diff changeset
623 fmt = GET_RTX_FORMAT (code);
kono
parents:
diff changeset
624 res = false;
kono
parents:
diff changeset
625 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
kono
parents:
diff changeset
626 {
kono
parents:
diff changeset
627 if (fmt[i] == 'e')
kono
parents:
diff changeset
628 {
kono
parents:
diff changeset
629 if (alter_subregs (&XEXP (x, i), final_p))
kono
parents:
diff changeset
630 res = true;
kono
parents:
diff changeset
631 }
kono
parents:
diff changeset
632 else if (fmt[i] == 'E')
kono
parents:
diff changeset
633 {
kono
parents:
diff changeset
634 int j;
kono
parents:
diff changeset
635
kono
parents:
diff changeset
636 for (j = XVECLEN (x, i) - 1; j >= 0; j--)
kono
parents:
diff changeset
637 if (alter_subregs (&XVECEXP (x, i, j), final_p))
kono
parents:
diff changeset
638 res = true;
kono
parents:
diff changeset
639 }
kono
parents:
diff changeset
640 }
kono
parents:
diff changeset
641 return res;
kono
parents:
diff changeset
642 }
kono
parents:
diff changeset
643
kono
parents:
diff changeset
644 /* Return true if REGNO is used for return in the current
kono
parents:
diff changeset
645 function. */
kono
parents:
diff changeset
646 static bool
kono
parents:
diff changeset
647 return_regno_p (unsigned int regno)
kono
parents:
diff changeset
648 {
kono
parents:
diff changeset
649 rtx outgoing = crtl->return_rtx;
kono
parents:
diff changeset
650
kono
parents:
diff changeset
651 if (! outgoing)
kono
parents:
diff changeset
652 return false;
kono
parents:
diff changeset
653
kono
parents:
diff changeset
654 if (REG_P (outgoing))
kono
parents:
diff changeset
655 return REGNO (outgoing) == regno;
kono
parents:
diff changeset
656 else if (GET_CODE (outgoing) == PARALLEL)
kono
parents:
diff changeset
657 {
kono
parents:
diff changeset
658 int i;
kono
parents:
diff changeset
659
kono
parents:
diff changeset
660 for (i = 0; i < XVECLEN (outgoing, 0); i++)
kono
parents:
diff changeset
661 {
kono
parents:
diff changeset
662 rtx x = XEXP (XVECEXP (outgoing, 0, i), 0);
kono
parents:
diff changeset
663
kono
parents:
diff changeset
664 if (REG_P (x) && REGNO (x) == regno)
kono
parents:
diff changeset
665 return true;
kono
parents:
diff changeset
666 }
kono
parents:
diff changeset
667 }
kono
parents:
diff changeset
668 return false;
kono
parents:
diff changeset
669 }
kono
parents:
diff changeset
670
kono
parents:
diff changeset
671 /* Return true if REGNO is in one of subsequent USE after INSN in the
kono
parents:
diff changeset
672 same BB. */
kono
parents:
diff changeset
673 static bool
kono
parents:
diff changeset
674 regno_in_use_p (rtx_insn *insn, unsigned int regno)
kono
parents:
diff changeset
675 {
kono
parents:
diff changeset
676 static lra_insn_recog_data_t id;
kono
parents:
diff changeset
677 static struct lra_static_insn_data *static_id;
kono
parents:
diff changeset
678 struct lra_insn_reg *reg;
kono
parents:
diff changeset
679 int i, arg_regno;
kono
parents:
diff changeset
680 basic_block bb = BLOCK_FOR_INSN (insn);
kono
parents:
diff changeset
681
kono
parents:
diff changeset
682 while ((insn = next_nondebug_insn (insn)) != NULL_RTX)
kono
parents:
diff changeset
683 {
kono
parents:
diff changeset
684 if (BARRIER_P (insn) || bb != BLOCK_FOR_INSN (insn))
kono
parents:
diff changeset
685 return false;
kono
parents:
diff changeset
686 if (! INSN_P (insn))
kono
parents:
diff changeset
687 continue;
kono
parents:
diff changeset
688 if (GET_CODE (PATTERN (insn)) == USE
kono
parents:
diff changeset
689 && REG_P (XEXP (PATTERN (insn), 0))
kono
parents:
diff changeset
690 && regno == REGNO (XEXP (PATTERN (insn), 0)))
kono
parents:
diff changeset
691 return true;
kono
parents:
diff changeset
692 /* Check that the regno is not modified. */
kono
parents:
diff changeset
693 id = lra_get_insn_recog_data (insn);
kono
parents:
diff changeset
694 for (reg = id->regs; reg != NULL; reg = reg->next)
kono
parents:
diff changeset
695 if (reg->type != OP_IN && reg->regno == (int) regno)
kono
parents:
diff changeset
696 return false;
kono
parents:
diff changeset
697 static_id = id->insn_static_data;
kono
parents:
diff changeset
698 for (reg = static_id->hard_regs; reg != NULL; reg = reg->next)
kono
parents:
diff changeset
699 if (reg->type != OP_IN && reg->regno == (int) regno)
kono
parents:
diff changeset
700 return false;
kono
parents:
diff changeset
701 if (id->arg_hard_regs != NULL)
kono
parents:
diff changeset
702 for (i = 0; (arg_regno = id->arg_hard_regs[i]) >= 0; i++)
kono
parents:
diff changeset
703 if ((int) regno == (arg_regno >= FIRST_PSEUDO_REGISTER
kono
parents:
diff changeset
704 ? arg_regno : arg_regno - FIRST_PSEUDO_REGISTER))
kono
parents:
diff changeset
705 return false;
kono
parents:
diff changeset
706 }
kono
parents:
diff changeset
707 return false;
kono
parents:
diff changeset
708 }
kono
parents:
diff changeset
709
kono
parents:
diff changeset
710 /* Final change of pseudos got hard registers into the corresponding
kono
parents:
diff changeset
711 hard registers and removing temporary clobbers. */
kono
parents:
diff changeset
712 void
kono
parents:
diff changeset
713 lra_final_code_change (void)
kono
parents:
diff changeset
714 {
kono
parents:
diff changeset
715 int i, hard_regno;
kono
parents:
diff changeset
716 basic_block bb;
kono
parents:
diff changeset
717 rtx_insn *insn, *curr;
kono
parents:
diff changeset
718 int max_regno = max_reg_num ();
kono
parents:
diff changeset
719
kono
parents:
diff changeset
720 for (i = FIRST_PSEUDO_REGISTER; i < max_regno; i++)
kono
parents:
diff changeset
721 if (lra_reg_info[i].nrefs != 0
kono
parents:
diff changeset
722 && (hard_regno = lra_get_regno_hard_regno (i)) >= 0)
kono
parents:
diff changeset
723 SET_REGNO (regno_reg_rtx[i], hard_regno);
kono
parents:
diff changeset
724 FOR_EACH_BB_FN (bb, cfun)
kono
parents:
diff changeset
725 FOR_BB_INSNS_SAFE (bb, insn, curr)
kono
parents:
diff changeset
726 if (INSN_P (insn))
kono
parents:
diff changeset
727 {
kono
parents:
diff changeset
728 rtx pat = PATTERN (insn);
kono
parents:
diff changeset
729
kono
parents:
diff changeset
730 if (GET_CODE (pat) == CLOBBER && LRA_TEMP_CLOBBER_P (pat))
kono
parents:
diff changeset
731 {
kono
parents:
diff changeset
732 /* Remove clobbers temporarily created in LRA. We don't
kono
parents:
diff changeset
733 need them anymore and don't want to waste compiler
kono
parents:
diff changeset
734 time processing them in a few subsequent passes. */
kono
parents:
diff changeset
735 lra_invalidate_insn_data (insn);
kono
parents:
diff changeset
736 delete_insn (insn);
kono
parents:
diff changeset
737 continue;
kono
parents:
diff changeset
738 }
kono
parents:
diff changeset
739
kono
parents:
diff changeset
740 /* IRA can generate move insns involving pseudos. It is
kono
parents:
diff changeset
741 better remove them earlier to speed up compiler a bit.
kono
parents:
diff changeset
742 It is also better to do it here as they might not pass
kono
parents:
diff changeset
743 final RTL check in LRA, (e.g. insn moving a control
kono
parents:
diff changeset
744 register into itself). So remove an useless move insn
kono
parents:
diff changeset
745 unless next insn is USE marking the return reg (we should
kono
parents:
diff changeset
746 save this as some subsequent optimizations assume that
kono
parents:
diff changeset
747 such original insns are saved). */
kono
parents:
diff changeset
748 if (NONJUMP_INSN_P (insn) && GET_CODE (pat) == SET
kono
parents:
diff changeset
749 && REG_P (SET_SRC (pat)) && REG_P (SET_DEST (pat))
kono
parents:
diff changeset
750 && REGNO (SET_SRC (pat)) == REGNO (SET_DEST (pat))
kono
parents:
diff changeset
751 && (! return_regno_p (REGNO (SET_SRC (pat)))
kono
parents:
diff changeset
752 || ! regno_in_use_p (insn, REGNO (SET_SRC (pat)))))
kono
parents:
diff changeset
753 {
kono
parents:
diff changeset
754 lra_invalidate_insn_data (insn);
kono
parents:
diff changeset
755 delete_insn (insn);
kono
parents:
diff changeset
756 continue;
kono
parents:
diff changeset
757 }
kono
parents:
diff changeset
758
kono
parents:
diff changeset
759 lra_insn_recog_data_t id = lra_get_insn_recog_data (insn);
kono
parents:
diff changeset
760 struct lra_insn_reg *reg;
kono
parents:
diff changeset
761
kono
parents:
diff changeset
762 for (reg = id->regs; reg != NULL; reg = reg->next)
kono
parents:
diff changeset
763 if (reg->regno >= FIRST_PSEUDO_REGISTER
kono
parents:
diff changeset
764 && lra_reg_info [reg->regno].nrefs == 0)
kono
parents:
diff changeset
765 break;
kono
parents:
diff changeset
766
kono
parents:
diff changeset
767 if (reg != NULL)
kono
parents:
diff changeset
768 {
kono
parents:
diff changeset
769 /* Pseudos still can be in debug insns in some very rare
kono
parents:
diff changeset
770 and complicated cases, e.g. the pseudo was removed by
kono
parents:
diff changeset
771 inheritance and the debug insn is not EBBs where the
kono
parents:
diff changeset
772 inheritance happened. It is difficult and time
kono
parents:
diff changeset
773 consuming to find what hard register corresponds the
kono
parents:
diff changeset
774 pseudo -- so just remove the debug insn. Another
kono
parents:
diff changeset
775 solution could be assigning hard reg/memory but it
kono
parents:
diff changeset
776 would be a misleading info. It is better not to have
kono
parents:
diff changeset
777 info than have it wrong. */
kono
parents:
diff changeset
778 lra_assert (DEBUG_INSN_P (insn));
kono
parents:
diff changeset
779 lra_invalidate_insn_data (insn);
kono
parents:
diff changeset
780 delete_insn (insn);
kono
parents:
diff changeset
781 continue;
kono
parents:
diff changeset
782 }
kono
parents:
diff changeset
783
kono
parents:
diff changeset
784 struct lra_static_insn_data *static_id = id->insn_static_data;
kono
parents:
diff changeset
785 bool insn_change_p = false;
kono
parents:
diff changeset
786
kono
parents:
diff changeset
787 for (i = id->insn_static_data->n_operands - 1; i >= 0; i--)
kono
parents:
diff changeset
788 if ((DEBUG_INSN_P (insn) || ! static_id->operand[i].is_operator)
kono
parents:
diff changeset
789 && alter_subregs (id->operand_loc[i], ! DEBUG_INSN_P (insn)))
kono
parents:
diff changeset
790 {
kono
parents:
diff changeset
791 lra_update_dup (id, i);
kono
parents:
diff changeset
792 insn_change_p = true;
kono
parents:
diff changeset
793 }
kono
parents:
diff changeset
794 if (insn_change_p)
kono
parents:
diff changeset
795 lra_update_operator_dups (id);
kono
parents:
diff changeset
796 }
kono
parents:
diff changeset
797 }