]>
Commit | Line | Data |
---|---|---|
55a2c322 | 1 | /* Assign reload pseudos. |
d1e082c2 | 2 | Copyright (C) 2010-2013 Free Software Foundation, Inc. |
55a2c322 VM |
3 | Contributed by Vladimir Makarov <vmakarov@redhat.com>. |
4 | ||
5 | This file is part of GCC. | |
6 | ||
7 | GCC is free software; you can redistribute it and/or modify it under | |
8 | the terms of the GNU General Public License as published by the Free | |
9 | Software Foundation; either version 3, or (at your option) any later | |
10 | version. | |
11 | ||
12 | GCC is distributed in the hope that it will be useful, but WITHOUT ANY | |
13 | WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
14 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
15 | for more details. | |
16 | ||
17 | You should have received a copy of the GNU General Public License | |
18 | along with GCC; see the file COPYING3. If not see | |
19 | <http://www.gnu.org/licenses/>. */ | |
20 | ||
21 | ||
22 | /* This file's main objective is to assign hard registers to reload | |
23 | pseudos. It also tries to allocate hard registers to other | |
24 | pseudos, but at a lower priority than the reload pseudos. The pass | |
25 | does not transform the RTL. | |
26 | ||
27 | We must allocate a hard register to every reload pseudo. We try to | |
28 | increase the chances of finding a viable allocation by assigning | |
29 | the pseudos in order of fewest available hard registers first. If | |
30 | we still fail to find a hard register, we spill other (non-reload) | |
31 | pseudos in order to make room. | |
32 | ||
33 | find_hard_regno_for finds hard registers for allocation without | |
34 | spilling. spill_for does the same with spilling. Both functions | |
35 | use a cost model to determine the most profitable choice of hard | |
36 | and spill registers. | |
37 | ||
38 | Once we have finished allocating reload pseudos, we also try to | |
39 | assign registers to other (non-reload) pseudos. This is useful if | |
40 | hard registers were freed up by the spilling just described. | |
41 | ||
42 | We try to assign hard registers by collecting pseudos into threads. | |
43 | These threads contain reload and inheritance pseudos that are | |
44 | connected by copies (move insns). Doing this improves the chances | |
45 | of pseudos in the thread getting the same hard register and, as a | |
46 | result, of allowing some move insns to be deleted. | |
47 | ||
48 | When we assign a hard register to a pseudo, we decrease the cost of | |
49 | using the same hard register for pseudos that are connected by | |
50 | copies. | |
51 | ||
52 | If two hard registers have the same frequency-derived cost, we | |
53 | prefer hard registers with higher priorities. The mapping of | |
54 | registers to priorities is controlled by the register_priority | |
55 | target hook. For example, x86-64 has a few register priorities: | |
56 | hard registers with and without REX prefixes have different | |
57 | priorities. This permits us to generate smaller code as insns | |
58 | without REX prefixes are shorter. | |
59 | ||
60 | If a few hard registers are still equally good for the assignment, | |
61 | we choose the least used hard register. It is called leveling and | |
62 | may be profitable for some targets. | |
63 | ||
64 | Only insns with changed allocation pseudos are processed on the | |
65 | next constraint pass. | |
66 | ||
67 | The pseudo live-ranges are used to find conflicting pseudos. | |
68 | ||
69 | For understanding the code, it is important to keep in mind that | |
70 | inheritance, split, and reload pseudos created since last | |
71 | constraint pass have regno >= lra_constraint_new_regno_start. | |
72 | Inheritance and split pseudos created on any pass are in the | |
73 | corresponding bitmaps. Inheritance and split pseudos since the | |
74 | last constraint pass have also the corresponding non-negative | |
75 | restore_regno. */ | |
76 | ||
77 | #include "config.h" | |
78 | #include "system.h" | |
79 | #include "coretypes.h" | |
80 | #include "tm.h" | |
81 | #include "hard-reg-set.h" | |
82 | #include "rtl.h" | |
ce940020 | 83 | #include "rtl-error.h" |
55a2c322 VM |
84 | #include "tm_p.h" |
85 | #include "target.h" | |
86 | #include "insn-config.h" | |
87 | #include "recog.h" | |
88 | #include "output.h" | |
89 | #include "regs.h" | |
90 | #include "function.h" | |
91 | #include "expr.h" | |
92 | #include "basic-block.h" | |
93 | #include "except.h" | |
94 | #include "df.h" | |
95 | #include "ira.h" | |
96 | #include "sparseset.h" | |
97 | #include "lra-int.h" | |
98 | ||
99 | /* Array containing corresponding values of function | |
100 | lra_get_allocno_class. It is used to speed up the code. */ | |
101 | static enum reg_class *regno_allocno_class_array; | |
102 | ||
103 | /* Information about the thread to which a pseudo belongs. Threads are | |
104 | a set of connected reload and inheritance pseudos with the same set of | |
105 | available hard registers. Lone registers belong to their own threads. */ | |
106 | struct regno_assign_info | |
107 | { | |
108 | /* First/next pseudo of the same thread. */ | |
109 | int first, next; | |
110 | /* Frequency of the thread (execution frequency of only reload | |
111 | pseudos in the thread when the thread contains a reload pseudo). | |
112 | Defined only for the first thread pseudo. */ | |
113 | int freq; | |
114 | }; | |
115 | ||
116 | /* Map regno to the corresponding regno assignment info. */ | |
117 | static struct regno_assign_info *regno_assign_info; | |
118 | ||
119 | /* Process a pseudo copy with execution frequency COPY_FREQ connecting | |
120 | REGNO1 and REGNO2 to form threads. */ | |
121 | static void | |
122 | process_copy_to_form_thread (int regno1, int regno2, int copy_freq) | |
123 | { | |
124 | int last, regno1_first, regno2_first; | |
125 | ||
126 | lra_assert (regno1 >= lra_constraint_new_regno_start | |
127 | && regno2 >= lra_constraint_new_regno_start); | |
128 | regno1_first = regno_assign_info[regno1].first; | |
129 | regno2_first = regno_assign_info[regno2].first; | |
130 | if (regno1_first != regno2_first) | |
131 | { | |
132 | for (last = regno2_first; | |
133 | regno_assign_info[last].next >= 0; | |
134 | last = regno_assign_info[last].next) | |
135 | regno_assign_info[last].first = regno1_first; | |
136 | regno_assign_info[last].first = regno1_first; | |
137 | regno_assign_info[last].next = regno_assign_info[regno1_first].next; | |
138 | regno_assign_info[regno1_first].next = regno2_first; | |
139 | regno_assign_info[regno1_first].freq | |
140 | += regno_assign_info[regno2_first].freq; | |
141 | } | |
142 | regno_assign_info[regno1_first].freq -= 2 * copy_freq; | |
143 | lra_assert (regno_assign_info[regno1_first].freq >= 0); | |
144 | } | |
145 | ||
146 | /* Initialize REGNO_ASSIGN_INFO and form threads. */ | |
147 | static void | |
148 | init_regno_assign_info (void) | |
149 | { | |
150 | int i, regno1, regno2, max_regno = max_reg_num (); | |
151 | lra_copy_t cp; | |
f4eafc30 | 152 | |
55a2c322 VM |
153 | regno_assign_info = XNEWVEC (struct regno_assign_info, max_regno); |
154 | for (i = FIRST_PSEUDO_REGISTER; i < max_regno; i++) | |
155 | { | |
156 | regno_assign_info[i].first = i; | |
157 | regno_assign_info[i].next = -1; | |
158 | regno_assign_info[i].freq = lra_reg_info[i].freq; | |
159 | } | |
160 | /* Form the threads. */ | |
161 | for (i = 0; (cp = lra_get_copy (i)) != NULL; i++) | |
162 | if ((regno1 = cp->regno1) >= lra_constraint_new_regno_start | |
163 | && (regno2 = cp->regno2) >= lra_constraint_new_regno_start | |
164 | && reg_renumber[regno1] < 0 && lra_reg_info[regno1].nrefs != 0 | |
165 | && reg_renumber[regno2] < 0 && lra_reg_info[regno2].nrefs != 0 | |
166 | && (ira_class_hard_regs_num[regno_allocno_class_array[regno1]] | |
167 | == ira_class_hard_regs_num[regno_allocno_class_array[regno2]])) | |
168 | process_copy_to_form_thread (regno1, regno2, cp->freq); | |
169 | } | |
170 | ||
171 | /* Free REGNO_ASSIGN_INFO. */ | |
172 | static void | |
173 | finish_regno_assign_info (void) | |
174 | { | |
175 | free (regno_assign_info); | |
176 | } | |
177 | ||
178 | /* The function is used to sort *reload* and *inheritance* pseudos to | |
179 | try to assign them hard registers. We put pseudos from the same | |
180 | thread always nearby. */ | |
181 | static int | |
182 | reload_pseudo_compare_func (const void *v1p, const void *v2p) | |
183 | { | |
184 | int r1 = *(const int *) v1p, r2 = *(const int *) v2p; | |
185 | enum reg_class cl1 = regno_allocno_class_array[r1]; | |
186 | enum reg_class cl2 = regno_allocno_class_array[r2]; | |
187 | int diff; | |
f4eafc30 | 188 | |
55a2c322 VM |
189 | lra_assert (r1 >= lra_constraint_new_regno_start |
190 | && r2 >= lra_constraint_new_regno_start); | |
f4eafc30 | 191 | |
55a2c322 VM |
192 | /* Prefer to assign reload registers with smaller classes first to |
193 | guarantee assignment to all reload registers. */ | |
194 | if ((diff = (ira_class_hard_regs_num[cl1] | |
195 | - ira_class_hard_regs_num[cl2])) != 0) | |
196 | return diff; | |
197 | if ((diff = (regno_assign_info[regno_assign_info[r2].first].freq | |
198 | - regno_assign_info[regno_assign_info[r1].first].freq)) != 0) | |
199 | return diff; | |
47918951 VM |
200 | /* Allocate bigger pseudos first to avoid register file |
201 | fragmentation. */ | |
202 | if ((diff | |
203 | = (ira_reg_class_max_nregs[cl2][lra_reg_info[r2].biggest_mode] | |
204 | - ira_reg_class_max_nregs[cl1][lra_reg_info[r1].biggest_mode])) != 0) | |
205 | return diff; | |
55a2c322 VM |
206 | /* Put pseudos from the thread nearby. */ |
207 | if ((diff = regno_assign_info[r1].first - regno_assign_info[r2].first) != 0) | |
208 | return diff; | |
209 | /* If regs are equally good, sort by their numbers, so that the | |
210 | results of qsort leave nothing to chance. */ | |
211 | return r1 - r2; | |
212 | } | |
213 | ||
214 | /* The function is used to sort *non-reload* pseudos to try to assign | |
215 | them hard registers. The order calculation is simpler than in the | |
216 | previous function and based on the pseudo frequency usage. */ | |
217 | static int | |
218 | pseudo_compare_func (const void *v1p, const void *v2p) | |
219 | { | |
220 | int r1 = *(const int *) v1p, r2 = *(const int *) v2p; | |
221 | int diff; | |
222 | ||
223 | /* Prefer to assign more frequently used registers first. */ | |
224 | if ((diff = lra_reg_info[r2].freq - lra_reg_info[r1].freq) != 0) | |
225 | return diff; | |
f4eafc30 | 226 | |
55a2c322 VM |
227 | /* If regs are equally good, sort by their numbers, so that the |
228 | results of qsort leave nothing to chance. */ | |
229 | return r1 - r2; | |
230 | } | |
231 | ||
232 | /* Arrays of size LRA_LIVE_MAX_POINT mapping a program point to the | |
233 | pseudo live ranges with given start point. We insert only live | |
234 | ranges of pseudos interesting for assignment purposes. They are | |
235 | reload pseudos and pseudos assigned to hard registers. */ | |
236 | static lra_live_range_t *start_point_ranges; | |
237 | ||
238 | /* Used as a flag that a live range is not inserted in the start point | |
239 | chain. */ | |
240 | static struct lra_live_range not_in_chain_mark; | |
241 | ||
242 | /* Create and set up START_POINT_RANGES. */ | |
243 | static void | |
244 | create_live_range_start_chains (void) | |
245 | { | |
246 | int i, max_regno; | |
247 | lra_live_range_t r; | |
248 | ||
249 | start_point_ranges = XCNEWVEC (lra_live_range_t, lra_live_max_point); | |
250 | max_regno = max_reg_num (); | |
251 | for (i = FIRST_PSEUDO_REGISTER; i < max_regno; i++) | |
252 | if (i >= lra_constraint_new_regno_start || reg_renumber[i] >= 0) | |
253 | { | |
254 | for (r = lra_reg_info[i].live_ranges; r != NULL; r = r->next) | |
255 | { | |
256 | r->start_next = start_point_ranges[r->start]; | |
257 | start_point_ranges[r->start] = r; | |
258 | } | |
259 | } | |
260 | else | |
261 | { | |
262 | for (r = lra_reg_info[i].live_ranges; r != NULL; r = r->next) | |
263 | r->start_next = ¬_in_chain_mark; | |
264 | } | |
265 | } | |
266 | ||
267 | /* Insert live ranges of pseudo REGNO into start chains if they are | |
268 | not there yet. */ | |
269 | static void | |
270 | insert_in_live_range_start_chain (int regno) | |
271 | { | |
272 | lra_live_range_t r = lra_reg_info[regno].live_ranges; | |
273 | ||
274 | if (r->start_next != ¬_in_chain_mark) | |
275 | return; | |
276 | for (; r != NULL; r = r->next) | |
277 | { | |
278 | r->start_next = start_point_ranges[r->start]; | |
279 | start_point_ranges[r->start] = r; | |
280 | } | |
281 | } | |
282 | ||
283 | /* Free START_POINT_RANGES. */ | |
284 | static void | |
285 | finish_live_range_start_chains (void) | |
286 | { | |
287 | gcc_assert (start_point_ranges != NULL); | |
288 | free (start_point_ranges); | |
289 | start_point_ranges = NULL; | |
290 | } | |
291 | ||
292 | /* Map: program point -> bitmap of all pseudos living at the point and | |
293 | assigned to hard registers. */ | |
294 | static bitmap_head *live_hard_reg_pseudos; | |
295 | static bitmap_obstack live_hard_reg_pseudos_bitmap_obstack; | |
296 | ||
297 | /* reg_renumber corresponding to pseudos marked in | |
298 | live_hard_reg_pseudos. reg_renumber might be not matched to | |
299 | live_hard_reg_pseudos but live_pseudos_reg_renumber always reflects | |
300 | live_hard_reg_pseudos. */ | |
301 | static int *live_pseudos_reg_renumber; | |
302 | ||
303 | /* Sparseset used to calculate living hard reg pseudos for some program | |
304 | point range. */ | |
305 | static sparseset live_range_hard_reg_pseudos; | |
306 | ||
307 | /* Sparseset used to calculate living reload/inheritance pseudos for | |
308 | some program point range. */ | |
309 | static sparseset live_range_reload_inheritance_pseudos; | |
310 | ||
311 | /* Allocate and initialize the data about living pseudos at program | |
312 | points. */ | |
313 | static void | |
314 | init_lives (void) | |
315 | { | |
316 | int i, max_regno = max_reg_num (); | |
317 | ||
318 | live_range_hard_reg_pseudos = sparseset_alloc (max_regno); | |
319 | live_range_reload_inheritance_pseudos = sparseset_alloc (max_regno); | |
320 | live_hard_reg_pseudos = XNEWVEC (bitmap_head, lra_live_max_point); | |
321 | bitmap_obstack_initialize (&live_hard_reg_pseudos_bitmap_obstack); | |
322 | for (i = 0; i < lra_live_max_point; i++) | |
323 | bitmap_initialize (&live_hard_reg_pseudos[i], | |
324 | &live_hard_reg_pseudos_bitmap_obstack); | |
325 | live_pseudos_reg_renumber = XNEWVEC (int, max_regno); | |
326 | for (i = 0; i < max_regno; i++) | |
327 | live_pseudos_reg_renumber[i] = -1; | |
328 | } | |
329 | ||
330 | /* Free the data about living pseudos at program points. */ | |
331 | static void | |
332 | finish_lives (void) | |
333 | { | |
334 | sparseset_free (live_range_hard_reg_pseudos); | |
335 | sparseset_free (live_range_reload_inheritance_pseudos); | |
336 | free (live_hard_reg_pseudos); | |
337 | bitmap_obstack_release (&live_hard_reg_pseudos_bitmap_obstack); | |
338 | free (live_pseudos_reg_renumber); | |
339 | } | |
340 | ||
341 | /* Update the LIVE_HARD_REG_PSEUDOS and LIVE_PSEUDOS_REG_RENUMBER | |
342 | entries for pseudo REGNO. Assume that the register has been | |
343 | spilled if FREE_P, otherwise assume that it has been assigned | |
344 | reg_renumber[REGNO] (if >= 0). We also insert the pseudo live | |
345 | ranges in the start chains when it is assumed to be assigned to a | |
346 | hard register because we use the chains of pseudos assigned to hard | |
347 | registers during allocation. */ | |
348 | static void | |
349 | update_lives (int regno, bool free_p) | |
350 | { | |
351 | int p; | |
352 | lra_live_range_t r; | |
353 | ||
354 | if (reg_renumber[regno] < 0) | |
355 | return; | |
356 | live_pseudos_reg_renumber[regno] = free_p ? -1 : reg_renumber[regno]; | |
357 | for (r = lra_reg_info[regno].live_ranges; r != NULL; r = r->next) | |
358 | { | |
359 | for (p = r->start; p <= r->finish; p++) | |
360 | if (free_p) | |
361 | bitmap_clear_bit (&live_hard_reg_pseudos[p], regno); | |
362 | else | |
363 | { | |
364 | bitmap_set_bit (&live_hard_reg_pseudos[p], regno); | |
365 | insert_in_live_range_start_chain (regno); | |
366 | } | |
367 | } | |
368 | } | |
369 | ||
370 | /* Sparseset used to calculate reload pseudos conflicting with a given | |
371 | pseudo when we are trying to find a hard register for the given | |
372 | pseudo. */ | |
373 | static sparseset conflict_reload_and_inheritance_pseudos; | |
374 | ||
375 | /* Map: program point -> bitmap of all reload and inheritance pseudos | |
376 | living at the point. */ | |
377 | static bitmap_head *live_reload_and_inheritance_pseudos; | |
378 | static bitmap_obstack live_reload_and_inheritance_pseudos_bitmap_obstack; | |
379 | ||
380 | /* Allocate and initialize data about living reload pseudos at any | |
381 | given program point. */ | |
382 | static void | |
383 | init_live_reload_and_inheritance_pseudos (void) | |
384 | { | |
385 | int i, p, max_regno = max_reg_num (); | |
386 | lra_live_range_t r; | |
f4eafc30 | 387 | |
55a2c322 VM |
388 | conflict_reload_and_inheritance_pseudos = sparseset_alloc (max_regno); |
389 | live_reload_and_inheritance_pseudos = XNEWVEC (bitmap_head, lra_live_max_point); | |
390 | bitmap_obstack_initialize (&live_reload_and_inheritance_pseudos_bitmap_obstack); | |
391 | for (p = 0; p < lra_live_max_point; p++) | |
392 | bitmap_initialize (&live_reload_and_inheritance_pseudos[p], | |
393 | &live_reload_and_inheritance_pseudos_bitmap_obstack); | |
394 | for (i = lra_constraint_new_regno_start; i < max_regno; i++) | |
395 | { | |
396 | for (r = lra_reg_info[i].live_ranges; r != NULL; r = r->next) | |
397 | for (p = r->start; p <= r->finish; p++) | |
398 | bitmap_set_bit (&live_reload_and_inheritance_pseudos[p], i); | |
399 | } | |
400 | } | |
401 | ||
402 | /* Finalize data about living reload pseudos at any given program | |
403 | point. */ | |
404 | static void | |
405 | finish_live_reload_and_inheritance_pseudos (void) | |
406 | { | |
407 | sparseset_free (conflict_reload_and_inheritance_pseudos); | |
408 | free (live_reload_and_inheritance_pseudos); | |
409 | bitmap_obstack_release (&live_reload_and_inheritance_pseudos_bitmap_obstack); | |
410 | } | |
411 | ||
412 | /* The value used to check that cost of given hard reg is really | |
413 | defined currently. */ | |
414 | static int curr_hard_regno_costs_check = 0; | |
415 | /* Array used to check that cost of the corresponding hard reg (the | |
416 | array element index) is really defined currently. */ | |
417 | static int hard_regno_costs_check[FIRST_PSEUDO_REGISTER]; | |
418 | /* The current costs of allocation of hard regs. Defined only if the | |
419 | value of the corresponding element of the previous array is equal to | |
420 | CURR_HARD_REGNO_COSTS_CHECK. */ | |
421 | static int hard_regno_costs[FIRST_PSEUDO_REGISTER]; | |
422 | ||
423 | /* Adjust cost of HARD_REGNO by INCR. Reset the cost first if it is | |
424 | not defined yet. */ | |
425 | static inline void | |
426 | adjust_hard_regno_cost (int hard_regno, int incr) | |
427 | { | |
428 | if (hard_regno_costs_check[hard_regno] != curr_hard_regno_costs_check) | |
429 | hard_regno_costs[hard_regno] = 0; | |
430 | hard_regno_costs_check[hard_regno] = curr_hard_regno_costs_check; | |
431 | hard_regno_costs[hard_regno] += incr; | |
432 | } | |
433 | ||
434 | /* Try to find a free hard register for pseudo REGNO. Return the | |
435 | hard register on success and set *COST to the cost of using | |
436 | that register. (If several registers have equal cost, the one with | |
437 | the highest priority wins.) Return -1 on failure. | |
438 | ||
439 | If TRY_ONLY_HARD_REGNO >= 0, consider only that hard register, | |
440 | otherwise consider all hard registers in REGNO's class. */ | |
441 | static int | |
442 | find_hard_regno_for (int regno, int *cost, int try_only_hard_regno) | |
443 | { | |
444 | HARD_REG_SET conflict_set; | |
445 | int best_cost = INT_MAX, best_priority = INT_MIN, best_usage = INT_MAX; | |
446 | lra_live_range_t r; | |
447 | int p, i, j, rclass_size, best_hard_regno, priority, hard_regno; | |
448 | int hr, conflict_hr, nregs; | |
449 | enum machine_mode biggest_mode; | |
450 | unsigned int k, conflict_regno; | |
d70a81dd | 451 | int offset, val, biggest_nregs, nregs_diff; |
55a2c322 VM |
452 | enum reg_class rclass; |
453 | bitmap_iterator bi; | |
454 | bool *rclass_intersect_p; | |
455 | HARD_REG_SET impossible_start_hard_regs; | |
456 | ||
457 | COPY_HARD_REG_SET (conflict_set, lra_no_alloc_regs); | |
458 | rclass = regno_allocno_class_array[regno]; | |
459 | rclass_intersect_p = ira_reg_classes_intersect_p[rclass]; | |
460 | curr_hard_regno_costs_check++; | |
461 | sparseset_clear (conflict_reload_and_inheritance_pseudos); | |
462 | sparseset_clear (live_range_hard_reg_pseudos); | |
463 | IOR_HARD_REG_SET (conflict_set, lra_reg_info[regno].conflict_hard_regs); | |
464 | biggest_mode = lra_reg_info[regno].biggest_mode; | |
465 | for (r = lra_reg_info[regno].live_ranges; r != NULL; r = r->next) | |
466 | { | |
467 | EXECUTE_IF_SET_IN_BITMAP (&live_hard_reg_pseudos[r->start], 0, k, bi) | |
468 | if (rclass_intersect_p[regno_allocno_class_array[k]]) | |
469 | sparseset_set_bit (live_range_hard_reg_pseudos, k); | |
470 | EXECUTE_IF_SET_IN_BITMAP (&live_reload_and_inheritance_pseudos[r->start], | |
471 | 0, k, bi) | |
472 | if (lra_reg_info[k].preferred_hard_regno1 >= 0 | |
473 | && live_pseudos_reg_renumber[k] < 0 | |
474 | && rclass_intersect_p[regno_allocno_class_array[k]]) | |
475 | sparseset_set_bit (conflict_reload_and_inheritance_pseudos, k); | |
476 | for (p = r->start + 1; p <= r->finish; p++) | |
477 | { | |
478 | lra_live_range_t r2; | |
f4eafc30 | 479 | |
55a2c322 VM |
480 | for (r2 = start_point_ranges[p]; |
481 | r2 != NULL; | |
482 | r2 = r2->start_next) | |
483 | { | |
484 | if (r2->regno >= lra_constraint_new_regno_start | |
485 | && lra_reg_info[r2->regno].preferred_hard_regno1 >= 0 | |
486 | && live_pseudos_reg_renumber[r2->regno] < 0 | |
487 | && rclass_intersect_p[regno_allocno_class_array[r2->regno]]) | |
488 | sparseset_set_bit (conflict_reload_and_inheritance_pseudos, | |
489 | r2->regno); | |
490 | if (live_pseudos_reg_renumber[r2->regno] >= 0 | |
491 | && rclass_intersect_p[regno_allocno_class_array[r2->regno]]) | |
492 | sparseset_set_bit (live_range_hard_reg_pseudos, r2->regno); | |
493 | } | |
494 | } | |
495 | } | |
496 | if ((hard_regno = lra_reg_info[regno].preferred_hard_regno1) >= 0) | |
497 | { | |
498 | adjust_hard_regno_cost | |
499 | (hard_regno, -lra_reg_info[regno].preferred_hard_regno_profit1); | |
500 | if ((hard_regno = lra_reg_info[regno].preferred_hard_regno2) >= 0) | |
501 | adjust_hard_regno_cost | |
502 | (hard_regno, -lra_reg_info[regno].preferred_hard_regno_profit2); | |
503 | } | |
504 | #ifdef STACK_REGS | |
505 | if (lra_reg_info[regno].no_stack_p) | |
506 | for (i = FIRST_STACK_REG; i <= LAST_STACK_REG; i++) | |
507 | SET_HARD_REG_BIT (conflict_set, i); | |
508 | #endif | |
509 | sparseset_clear_bit (conflict_reload_and_inheritance_pseudos, regno); | |
510 | val = lra_reg_info[regno].val; | |
d70a81dd | 511 | offset = lra_reg_info[regno].offset; |
55a2c322 VM |
512 | CLEAR_HARD_REG_SET (impossible_start_hard_regs); |
513 | EXECUTE_IF_SET_IN_SPARSESET (live_range_hard_reg_pseudos, conflict_regno) | |
d70a81dd | 514 | if (lra_reg_val_equal_p (conflict_regno, val, offset)) |
55a2c322 VM |
515 | { |
516 | conflict_hr = live_pseudos_reg_renumber[conflict_regno]; | |
517 | nregs = (hard_regno_nregs[conflict_hr] | |
518 | [lra_reg_info[conflict_regno].biggest_mode]); | |
519 | /* Remember about multi-register pseudos. For example, 2 hard | |
520 | register pseudos can start on the same hard register but can | |
f4eafc30 | 521 | not start on HR and HR+1/HR-1. */ |
55a2c322 VM |
522 | for (hr = conflict_hr + 1; |
523 | hr < FIRST_PSEUDO_REGISTER && hr < conflict_hr + nregs; | |
524 | hr++) | |
525 | SET_HARD_REG_BIT (impossible_start_hard_regs, hr); | |
526 | for (hr = conflict_hr - 1; | |
527 | hr >= 0 && hr + hard_regno_nregs[hr][biggest_mode] > conflict_hr; | |
528 | hr--) | |
529 | SET_HARD_REG_BIT (impossible_start_hard_regs, hr); | |
530 | } | |
531 | else | |
532 | { | |
533 | add_to_hard_reg_set (&conflict_set, | |
534 | lra_reg_info[conflict_regno].biggest_mode, | |
535 | live_pseudos_reg_renumber[conflict_regno]); | |
536 | if (hard_reg_set_subset_p (reg_class_contents[rclass], | |
537 | conflict_set)) | |
538 | return -1; | |
539 | } | |
540 | EXECUTE_IF_SET_IN_SPARSESET (conflict_reload_and_inheritance_pseudos, | |
541 | conflict_regno) | |
d70a81dd | 542 | if (!lra_reg_val_equal_p (conflict_regno, val, offset)) |
55a2c322 VM |
543 | { |
544 | lra_assert (live_pseudos_reg_renumber[conflict_regno] < 0); | |
545 | if ((hard_regno | |
546 | = lra_reg_info[conflict_regno].preferred_hard_regno1) >= 0) | |
547 | { | |
548 | adjust_hard_regno_cost | |
549 | (hard_regno, | |
550 | lra_reg_info[conflict_regno].preferred_hard_regno_profit1); | |
551 | if ((hard_regno | |
552 | = lra_reg_info[conflict_regno].preferred_hard_regno2) >= 0) | |
553 | adjust_hard_regno_cost | |
554 | (hard_regno, | |
555 | lra_reg_info[conflict_regno].preferred_hard_regno_profit2); | |
556 | } | |
557 | } | |
558 | /* Make sure that all registers in a multi-word pseudo belong to the | |
559 | required class. */ | |
560 | IOR_COMPL_HARD_REG_SET (conflict_set, reg_class_contents[rclass]); | |
561 | lra_assert (rclass != NO_REGS); | |
562 | rclass_size = ira_class_hard_regs_num[rclass]; | |
563 | best_hard_regno = -1; | |
564 | hard_regno = ira_class_hard_regs[rclass][0]; | |
565 | biggest_nregs = hard_regno_nregs[hard_regno][biggest_mode]; | |
566 | nregs_diff = (biggest_nregs | |
567 | - hard_regno_nregs[hard_regno][PSEUDO_REGNO_MODE (regno)]); | |
568 | for (i = 0; i < rclass_size; i++) | |
569 | { | |
570 | if (try_only_hard_regno >= 0) | |
571 | hard_regno = try_only_hard_regno; | |
572 | else | |
573 | hard_regno = ira_class_hard_regs[rclass][i]; | |
574 | if (! overlaps_hard_reg_set_p (conflict_set, | |
575 | PSEUDO_REGNO_MODE (regno), hard_regno) | |
576 | /* We can not use prohibited_class_mode_regs because it is | |
577 | not defined for all classes. */ | |
578 | && HARD_REGNO_MODE_OK (hard_regno, PSEUDO_REGNO_MODE (regno)) | |
579 | && ! TEST_HARD_REG_BIT (impossible_start_hard_regs, hard_regno) | |
580 | && (nregs_diff == 0 | |
a1b46e46 JR |
581 | || (WORDS_BIG_ENDIAN |
582 | ? (hard_regno - nregs_diff >= 0 | |
583 | && TEST_HARD_REG_BIT (reg_class_contents[rclass], | |
584 | hard_regno - nregs_diff)) | |
585 | : TEST_HARD_REG_BIT (reg_class_contents[rclass], | |
586 | hard_regno + nregs_diff)))) | |
55a2c322 VM |
587 | { |
588 | if (hard_regno_costs_check[hard_regno] | |
589 | != curr_hard_regno_costs_check) | |
590 | { | |
591 | hard_regno_costs_check[hard_regno] = curr_hard_regno_costs_check; | |
592 | hard_regno_costs[hard_regno] = 0; | |
593 | } | |
594 | for (j = 0; | |
595 | j < hard_regno_nregs[hard_regno][PSEUDO_REGNO_MODE (regno)]; | |
596 | j++) | |
597 | if (! TEST_HARD_REG_BIT (call_used_reg_set, hard_regno + j) | |
598 | && ! df_regs_ever_live_p (hard_regno + j)) | |
599 | /* It needs save restore. */ | |
600 | hard_regno_costs[hard_regno] | |
1f873f0e | 601 | += 2 * ENTRY_BLOCK_PTR->next_bb->frequency + 1; |
55a2c322 VM |
602 | priority = targetm.register_priority (hard_regno); |
603 | if (best_hard_regno < 0 || hard_regno_costs[hard_regno] < best_cost | |
604 | || (hard_regno_costs[hard_regno] == best_cost | |
605 | && (priority > best_priority | |
3b9ceb4b | 606 | || (targetm.register_usage_leveling_p () |
55a2c322 VM |
607 | && priority == best_priority |
608 | && best_usage > lra_hard_reg_usage[hard_regno])))) | |
609 | { | |
610 | best_hard_regno = hard_regno; | |
611 | best_cost = hard_regno_costs[hard_regno]; | |
612 | best_priority = priority; | |
613 | best_usage = lra_hard_reg_usage[hard_regno]; | |
614 | } | |
615 | } | |
616 | if (try_only_hard_regno >= 0) | |
617 | break; | |
618 | } | |
619 | if (best_hard_regno >= 0) | |
620 | *cost = best_cost - lra_reg_info[regno].freq; | |
621 | return best_hard_regno; | |
622 | } | |
623 | ||
624 | /* Current value used for checking elements in | |
625 | update_hard_regno_preference_check. */ | |
626 | static int curr_update_hard_regno_preference_check; | |
627 | /* If an element value is equal to the above variable value, then the | |
628 | corresponding regno has been processed for preference | |
629 | propagation. */ | |
630 | static int *update_hard_regno_preference_check; | |
631 | ||
632 | /* Update the preference for using HARD_REGNO for pseudos that are | |
633 | connected directly or indirectly with REGNO. Apply divisor DIV | |
634 | to any preference adjustments. | |
635 | ||
636 | The more indirectly a pseudo is connected, the smaller its effect | |
637 | should be. We therefore increase DIV on each "hop". */ | |
638 | static void | |
639 | update_hard_regno_preference (int regno, int hard_regno, int div) | |
640 | { | |
641 | int another_regno, cost; | |
642 | lra_copy_t cp, next_cp; | |
643 | ||
644 | /* Search depth 5 seems to be enough. */ | |
645 | if (div > (1 << 5)) | |
646 | return; | |
647 | for (cp = lra_reg_info[regno].copies; cp != NULL; cp = next_cp) | |
648 | { | |
649 | if (cp->regno1 == regno) | |
650 | { | |
651 | next_cp = cp->regno1_next; | |
652 | another_regno = cp->regno2; | |
653 | } | |
654 | else if (cp->regno2 == regno) | |
655 | { | |
656 | next_cp = cp->regno2_next; | |
657 | another_regno = cp->regno1; | |
658 | } | |
659 | else | |
660 | gcc_unreachable (); | |
661 | if (reg_renumber[another_regno] < 0 | |
662 | && (update_hard_regno_preference_check[another_regno] | |
663 | != curr_update_hard_regno_preference_check)) | |
664 | { | |
665 | update_hard_regno_preference_check[another_regno] | |
666 | = curr_update_hard_regno_preference_check; | |
667 | cost = cp->freq < div ? 1 : cp->freq / div; | |
668 | lra_setup_reload_pseudo_preferenced_hard_reg | |
669 | (another_regno, hard_regno, cost); | |
670 | update_hard_regno_preference (another_regno, hard_regno, div * 2); | |
671 | } | |
672 | } | |
673 | } | |
674 | ||
675 | /* Update REG_RENUMBER and other pseudo preferences by assignment of | |
676 | HARD_REGNO to pseudo REGNO and print about it if PRINT_P. */ | |
677 | void | |
678 | lra_setup_reg_renumber (int regno, int hard_regno, bool print_p) | |
679 | { | |
680 | int i, hr; | |
681 | ||
682 | /* We can not just reassign hard register. */ | |
683 | lra_assert (hard_regno < 0 || reg_renumber[regno] < 0); | |
684 | if ((hr = hard_regno) < 0) | |
685 | hr = reg_renumber[regno]; | |
686 | reg_renumber[regno] = hard_regno; | |
687 | lra_assert (hr >= 0); | |
688 | for (i = 0; i < hard_regno_nregs[hr][PSEUDO_REGNO_MODE (regno)]; i++) | |
689 | if (hard_regno < 0) | |
690 | lra_hard_reg_usage[hr + i] -= lra_reg_info[regno].freq; | |
691 | else | |
692 | lra_hard_reg_usage[hr + i] += lra_reg_info[regno].freq; | |
693 | if (print_p && lra_dump_file != NULL) | |
694 | fprintf (lra_dump_file, " Assign %d to %sr%d (freq=%d)\n", | |
695 | reg_renumber[regno], | |
696 | regno < lra_constraint_new_regno_start | |
697 | ? "" | |
698 | : bitmap_bit_p (&lra_inheritance_pseudos, regno) ? "inheritance " | |
699 | : bitmap_bit_p (&lra_split_regs, regno) ? "split " | |
700 | : bitmap_bit_p (&lra_optional_reload_pseudos, regno) | |
701 | ? "optional reload ": "reload ", | |
702 | regno, lra_reg_info[regno].freq); | |
703 | if (hard_regno >= 0) | |
704 | { | |
705 | curr_update_hard_regno_preference_check++; | |
706 | update_hard_regno_preference (regno, hard_regno, 1); | |
707 | } | |
708 | } | |
709 | ||
710 | /* Pseudos which occur in insns containing a particular pseudo. */ | |
711 | static bitmap_head insn_conflict_pseudos; | |
712 | ||
713 | /* Bitmaps used to contain spill pseudos for given pseudo hard regno | |
714 | and best spill pseudos for given pseudo (and best hard regno). */ | |
715 | static bitmap_head spill_pseudos_bitmap, best_spill_pseudos_bitmap; | |
716 | ||
717 | /* Current pseudo check for validity of elements in | |
718 | TRY_HARD_REG_PSEUDOS. */ | |
719 | static int curr_pseudo_check; | |
720 | /* Array used for validity of elements in TRY_HARD_REG_PSEUDOS. */ | |
721 | static int try_hard_reg_pseudos_check[FIRST_PSEUDO_REGISTER]; | |
722 | /* Pseudos who hold given hard register at the considered points. */ | |
723 | static bitmap_head try_hard_reg_pseudos[FIRST_PSEUDO_REGISTER]; | |
724 | ||
725 | /* Set up try_hard_reg_pseudos for given program point P and class | |
726 | RCLASS. Those are pseudos living at P and assigned to a hard | |
727 | register of RCLASS. In other words, those are pseudos which can be | |
728 | spilled to assign a hard register of RCLASS to a pseudo living at | |
729 | P. */ | |
730 | static void | |
731 | setup_try_hard_regno_pseudos (int p, enum reg_class rclass) | |
732 | { | |
733 | int i, hard_regno; | |
734 | enum machine_mode mode; | |
735 | unsigned int spill_regno; | |
736 | bitmap_iterator bi; | |
737 | ||
738 | /* Find what pseudos could be spilled. */ | |
739 | EXECUTE_IF_SET_IN_BITMAP (&live_hard_reg_pseudos[p], 0, spill_regno, bi) | |
740 | { | |
741 | mode = PSEUDO_REGNO_MODE (spill_regno); | |
742 | hard_regno = live_pseudos_reg_renumber[spill_regno]; | |
743 | if (overlaps_hard_reg_set_p (reg_class_contents[rclass], | |
744 | mode, hard_regno)) | |
745 | { | |
746 | for (i = hard_regno_nregs[hard_regno][mode] - 1; i >= 0; i--) | |
747 | { | |
748 | if (try_hard_reg_pseudos_check[hard_regno + i] | |
749 | != curr_pseudo_check) | |
750 | { | |
751 | try_hard_reg_pseudos_check[hard_regno + i] | |
752 | = curr_pseudo_check; | |
753 | bitmap_clear (&try_hard_reg_pseudos[hard_regno + i]); | |
754 | } | |
755 | bitmap_set_bit (&try_hard_reg_pseudos[hard_regno + i], | |
756 | spill_regno); | |
757 | } | |
758 | } | |
759 | } | |
760 | } | |
761 | ||
762 | /* Assign temporarily HARD_REGNO to pseudo REGNO. Temporary | |
763 | assignment means that we might undo the data change. */ | |
764 | static void | |
765 | assign_temporarily (int regno, int hard_regno) | |
766 | { | |
767 | int p; | |
768 | lra_live_range_t r; | |
769 | ||
770 | for (r = lra_reg_info[regno].live_ranges; r != NULL; r = r->next) | |
771 | { | |
772 | for (p = r->start; p <= r->finish; p++) | |
773 | if (hard_regno < 0) | |
774 | bitmap_clear_bit (&live_hard_reg_pseudos[p], regno); | |
775 | else | |
776 | { | |
777 | bitmap_set_bit (&live_hard_reg_pseudos[p], regno); | |
778 | insert_in_live_range_start_chain (regno); | |
779 | } | |
780 | } | |
781 | live_pseudos_reg_renumber[regno] = hard_regno; | |
782 | } | |
783 | ||
784 | /* Array used for sorting reload pseudos for subsequent allocation | |
785 | after spilling some pseudo. */ | |
786 | static int *sorted_reload_pseudos; | |
787 | ||
788 | /* Spill some pseudos for a reload pseudo REGNO and return hard | |
789 | register which should be used for pseudo after spilling. The | |
790 | function adds spilled pseudos to SPILLED_PSEUDO_BITMAP. When we | |
791 | choose hard register (and pseudos occupying the hard registers and | |
792 | to be spilled), we take into account not only how REGNO will | |
793 | benefit from the spills but also how other reload pseudos not yet | |
794 | assigned to hard registers benefit from the spills too. In very | |
795 | rare cases, the function can fail and return -1. */ | |
796 | static int | |
797 | spill_for (int regno, bitmap spilled_pseudo_bitmap) | |
798 | { | |
799 | int i, j, n, p, hard_regno, best_hard_regno, cost, best_cost, rclass_size; | |
800 | int reload_hard_regno, reload_cost; | |
295d875c | 801 | enum machine_mode mode; |
55a2c322 | 802 | enum reg_class rclass; |
55a2c322 VM |
803 | unsigned int spill_regno, reload_regno, uid; |
804 | int insn_pseudos_num, best_insn_pseudos_num; | |
805 | lra_live_range_t r; | |
806 | bitmap_iterator bi; | |
807 | ||
808 | rclass = regno_allocno_class_array[regno]; | |
809 | lra_assert (reg_renumber[regno] < 0 && rclass != NO_REGS); | |
810 | bitmap_clear (&insn_conflict_pseudos); | |
811 | bitmap_clear (&best_spill_pseudos_bitmap); | |
812 | EXECUTE_IF_SET_IN_BITMAP (&lra_reg_info[regno].insn_bitmap, 0, uid, bi) | |
813 | { | |
814 | struct lra_insn_reg *ir; | |
f4eafc30 | 815 | |
55a2c322 VM |
816 | for (ir = lra_get_insn_regs (uid); ir != NULL; ir = ir->next) |
817 | if (ir->regno >= FIRST_PSEUDO_REGISTER) | |
818 | bitmap_set_bit (&insn_conflict_pseudos, ir->regno); | |
819 | } | |
820 | best_hard_regno = -1; | |
821 | best_cost = INT_MAX; | |
822 | best_insn_pseudos_num = INT_MAX; | |
823 | rclass_size = ira_class_hard_regs_num[rclass]; | |
824 | mode = PSEUDO_REGNO_MODE (regno); | |
825 | /* Invalidate try_hard_reg_pseudos elements. */ | |
826 | curr_pseudo_check++; | |
827 | for (r = lra_reg_info[regno].live_ranges; r != NULL; r = r->next) | |
828 | for (p = r->start; p <= r->finish; p++) | |
829 | setup_try_hard_regno_pseudos (p, rclass); | |
830 | for (i = 0; i < rclass_size; i++) | |
831 | { | |
832 | hard_regno = ira_class_hard_regs[rclass][i]; | |
833 | bitmap_clear (&spill_pseudos_bitmap); | |
834 | for (j = hard_regno_nregs[hard_regno][mode] - 1; j >= 0; j--) | |
835 | { | |
836 | if (try_hard_reg_pseudos_check[hard_regno + j] != curr_pseudo_check) | |
837 | continue; | |
838 | lra_assert (!bitmap_empty_p (&try_hard_reg_pseudos[hard_regno + j])); | |
839 | bitmap_ior_into (&spill_pseudos_bitmap, | |
840 | &try_hard_reg_pseudos[hard_regno + j]); | |
841 | } | |
842 | /* Spill pseudos. */ | |
55a2c322 VM |
843 | EXECUTE_IF_SET_IN_BITMAP (&spill_pseudos_bitmap, 0, spill_regno, bi) |
844 | if ((int) spill_regno >= lra_constraint_new_regno_start | |
845 | && ! bitmap_bit_p (&lra_inheritance_pseudos, spill_regno) | |
846 | && ! bitmap_bit_p (&lra_split_regs, spill_regno) | |
847 | && ! bitmap_bit_p (&lra_optional_reload_pseudos, spill_regno)) | |
848 | goto fail; | |
849 | insn_pseudos_num = 0; | |
850 | if (lra_dump_file != NULL) | |
851 | fprintf (lra_dump_file, " Trying %d:", hard_regno); | |
852 | sparseset_clear (live_range_reload_inheritance_pseudos); | |
853 | EXECUTE_IF_SET_IN_BITMAP (&spill_pseudos_bitmap, 0, spill_regno, bi) | |
854 | { | |
855 | if (bitmap_bit_p (&insn_conflict_pseudos, spill_regno)) | |
856 | insn_pseudos_num++; | |
55a2c322 VM |
857 | for (r = lra_reg_info[spill_regno].live_ranges; |
858 | r != NULL; | |
859 | r = r->next) | |
860 | { | |
861 | for (p = r->start; p <= r->finish; p++) | |
862 | { | |
863 | lra_live_range_t r2; | |
f4eafc30 | 864 | |
55a2c322 VM |
865 | for (r2 = start_point_ranges[p]; |
866 | r2 != NULL; | |
867 | r2 = r2->start_next) | |
868 | if (r2->regno >= lra_constraint_new_regno_start) | |
869 | sparseset_set_bit (live_range_reload_inheritance_pseudos, | |
870 | r2->regno); | |
871 | } | |
872 | } | |
873 | } | |
295d875c VM |
874 | n = 0; |
875 | EXECUTE_IF_SET_IN_SPARSESET (live_range_reload_inheritance_pseudos, | |
876 | reload_regno) | |
877 | if ((int) reload_regno != regno | |
878 | && (ira_reg_classes_intersect_p | |
879 | [rclass][regno_allocno_class_array[reload_regno]]) | |
880 | && live_pseudos_reg_renumber[reload_regno] < 0 | |
881 | && find_hard_regno_for (reload_regno, &cost, -1) < 0) | |
882 | sorted_reload_pseudos[n++] = reload_regno; | |
883 | EXECUTE_IF_SET_IN_BITMAP (&spill_pseudos_bitmap, 0, spill_regno, bi) | |
884 | { | |
885 | update_lives (spill_regno, true); | |
886 | if (lra_dump_file != NULL) | |
887 | fprintf (lra_dump_file, " spill %d(freq=%d)", | |
888 | spill_regno, lra_reg_info[spill_regno].freq); | |
889 | } | |
55a2c322 VM |
890 | hard_regno = find_hard_regno_for (regno, &cost, -1); |
891 | if (hard_regno >= 0) | |
892 | { | |
893 | assign_temporarily (regno, hard_regno); | |
55a2c322 VM |
894 | qsort (sorted_reload_pseudos, n, sizeof (int), |
895 | reload_pseudo_compare_func); | |
896 | for (j = 0; j < n; j++) | |
897 | { | |
898 | reload_regno = sorted_reload_pseudos[j]; | |
899 | lra_assert (live_pseudos_reg_renumber[reload_regno] < 0); | |
900 | if ((reload_hard_regno | |
901 | = find_hard_regno_for (reload_regno, | |
295d875c | 902 | &reload_cost, -1)) >= 0) |
55a2c322 VM |
903 | { |
904 | if (lra_dump_file != NULL) | |
905 | fprintf (lra_dump_file, " assign %d(cost=%d)", | |
906 | reload_regno, reload_cost); | |
907 | assign_temporarily (reload_regno, reload_hard_regno); | |
908 | cost += reload_cost; | |
909 | } | |
910 | } | |
911 | EXECUTE_IF_SET_IN_BITMAP (&spill_pseudos_bitmap, 0, spill_regno, bi) | |
912 | { | |
913 | rtx x; | |
f4eafc30 | 914 | |
55a2c322 VM |
915 | cost += lra_reg_info[spill_regno].freq; |
916 | if (ira_reg_equiv[spill_regno].memory != NULL | |
917 | || ira_reg_equiv[spill_regno].constant != NULL) | |
918 | for (x = ira_reg_equiv[spill_regno].init_insns; | |
919 | x != NULL; | |
920 | x = XEXP (x, 1)) | |
921 | cost -= REG_FREQ_FROM_BB (BLOCK_FOR_INSN (XEXP (x, 0))); | |
922 | } | |
923 | if (best_insn_pseudos_num > insn_pseudos_num | |
924 | || (best_insn_pseudos_num == insn_pseudos_num | |
925 | && best_cost > cost)) | |
926 | { | |
927 | best_insn_pseudos_num = insn_pseudos_num; | |
928 | best_cost = cost; | |
929 | best_hard_regno = hard_regno; | |
930 | bitmap_copy (&best_spill_pseudos_bitmap, &spill_pseudos_bitmap); | |
931 | if (lra_dump_file != NULL) | |
932 | fprintf (lra_dump_file, " Now best %d(cost=%d)\n", | |
933 | hard_regno, cost); | |
934 | } | |
935 | assign_temporarily (regno, -1); | |
936 | for (j = 0; j < n; j++) | |
937 | { | |
938 | reload_regno = sorted_reload_pseudos[j]; | |
939 | if (live_pseudos_reg_renumber[reload_regno] >= 0) | |
940 | assign_temporarily (reload_regno, -1); | |
941 | } | |
942 | } | |
943 | if (lra_dump_file != NULL) | |
944 | fprintf (lra_dump_file, "\n"); | |
945 | /* Restore the live hard reg pseudo info for spilled pseudos. */ | |
946 | EXECUTE_IF_SET_IN_BITMAP (&spill_pseudos_bitmap, 0, spill_regno, bi) | |
947 | update_lives (spill_regno, false); | |
948 | fail: | |
949 | ; | |
950 | } | |
951 | /* Spill: */ | |
952 | EXECUTE_IF_SET_IN_BITMAP (&best_spill_pseudos_bitmap, 0, spill_regno, bi) | |
953 | { | |
954 | if (lra_dump_file != NULL) | |
955 | fprintf (lra_dump_file, " Spill %sr%d(hr=%d, freq=%d) for r%d\n", | |
956 | ((int) spill_regno < lra_constraint_new_regno_start | |
957 | ? "" | |
958 | : bitmap_bit_p (&lra_inheritance_pseudos, spill_regno) | |
959 | ? "inheritance " | |
960 | : bitmap_bit_p (&lra_split_regs, spill_regno) | |
961 | ? "split " | |
962 | : bitmap_bit_p (&lra_optional_reload_pseudos, spill_regno) | |
963 | ? "optional reload " : "reload "), | |
964 | spill_regno, reg_renumber[spill_regno], | |
965 | lra_reg_info[spill_regno].freq, regno); | |
966 | update_lives (spill_regno, true); | |
967 | lra_setup_reg_renumber (spill_regno, -1, false); | |
968 | } | |
969 | bitmap_ior_into (spilled_pseudo_bitmap, &best_spill_pseudos_bitmap); | |
970 | return best_hard_regno; | |
971 | } | |
972 | ||
973 | /* Assign HARD_REGNO to REGNO. */ | |
974 | static void | |
975 | assign_hard_regno (int hard_regno, int regno) | |
976 | { | |
977 | int i; | |
978 | ||
979 | lra_assert (hard_regno >= 0); | |
980 | lra_setup_reg_renumber (regno, hard_regno, true); | |
981 | update_lives (regno, false); | |
982 | for (i = 0; | |
983 | i < hard_regno_nregs[hard_regno][lra_reg_info[regno].biggest_mode]; | |
984 | i++) | |
985 | df_set_regs_ever_live (hard_regno + i, true); | |
986 | } | |
987 | ||
988 | /* Array used for sorting different pseudos. */ | |
989 | static int *sorted_pseudos; | |
990 | ||
991 | /* The constraints pass is allowed to create equivalences between | |
992 | pseudos that make the current allocation "incorrect" (in the sense | |
993 | that pseudos are assigned to hard registers from their own conflict | |
994 | sets). The global variable lra_risky_transformations_p says | |
995 | whether this might have happened. | |
996 | ||
997 | Process pseudos assigned to hard registers (less frequently used | |
998 | first), spill if a conflict is found, and mark the spilled pseudos | |
999 | in SPILLED_PSEUDO_BITMAP. Set up LIVE_HARD_REG_PSEUDOS from | |
1000 | pseudos, assigned to hard registers. */ | |
1001 | static void | |
1002 | setup_live_pseudos_and_spill_after_risky_transforms (bitmap | |
1003 | spilled_pseudo_bitmap) | |
1004 | { | |
1005 | int p, i, j, n, regno, hard_regno; | |
1006 | unsigned int k, conflict_regno; | |
d70a81dd | 1007 | int val, offset; |
55a2c322 VM |
1008 | HARD_REG_SET conflict_set; |
1009 | enum machine_mode mode; | |
1010 | lra_live_range_t r; | |
1011 | bitmap_iterator bi; | |
1012 | int max_regno = max_reg_num (); | |
1013 | ||
1014 | if (! lra_risky_transformations_p) | |
1015 | { | |
1016 | for (i = FIRST_PSEUDO_REGISTER; i < max_regno; i++) | |
1017 | if (reg_renumber[i] >= 0 && lra_reg_info[i].nrefs > 0) | |
1018 | update_lives (i, false); | |
1019 | return; | |
1020 | } | |
1021 | for (n = 0, i = FIRST_PSEUDO_REGISTER; i < max_regno; i++) | |
1022 | if (reg_renumber[i] >= 0 && lra_reg_info[i].nrefs > 0) | |
1023 | sorted_pseudos[n++] = i; | |
1024 | qsort (sorted_pseudos, n, sizeof (int), pseudo_compare_func); | |
1025 | for (i = n - 1; i >= 0; i--) | |
1026 | { | |
1027 | regno = sorted_pseudos[i]; | |
1028 | hard_regno = reg_renumber[regno]; | |
1029 | lra_assert (hard_regno >= 0); | |
1030 | mode = lra_reg_info[regno].biggest_mode; | |
1031 | sparseset_clear (live_range_hard_reg_pseudos); | |
1032 | for (r = lra_reg_info[regno].live_ranges; r != NULL; r = r->next) | |
1033 | { | |
1034 | EXECUTE_IF_SET_IN_BITMAP (&live_hard_reg_pseudos[r->start], 0, k, bi) | |
1035 | sparseset_set_bit (live_range_hard_reg_pseudos, k); | |
1036 | for (p = r->start + 1; p <= r->finish; p++) | |
1037 | { | |
1038 | lra_live_range_t r2; | |
f4eafc30 | 1039 | |
55a2c322 VM |
1040 | for (r2 = start_point_ranges[p]; |
1041 | r2 != NULL; | |
1042 | r2 = r2->start_next) | |
1043 | if (live_pseudos_reg_renumber[r2->regno] >= 0) | |
1044 | sparseset_set_bit (live_range_hard_reg_pseudos, r2->regno); | |
1045 | } | |
1046 | } | |
1047 | COPY_HARD_REG_SET (conflict_set, lra_no_alloc_regs); | |
1048 | IOR_HARD_REG_SET (conflict_set, lra_reg_info[regno].conflict_hard_regs); | |
1049 | val = lra_reg_info[regno].val; | |
d70a81dd | 1050 | offset = lra_reg_info[regno].offset; |
55a2c322 | 1051 | EXECUTE_IF_SET_IN_SPARSESET (live_range_hard_reg_pseudos, conflict_regno) |
d70a81dd | 1052 | if (!lra_reg_val_equal_p (conflict_regno, val, offset) |
55a2c322 VM |
1053 | /* If it is multi-register pseudos they should start on |
1054 | the same hard register. */ | |
1055 | || hard_regno != reg_renumber[conflict_regno]) | |
1056 | add_to_hard_reg_set (&conflict_set, | |
1057 | lra_reg_info[conflict_regno].biggest_mode, | |
1058 | reg_renumber[conflict_regno]); | |
1059 | if (! overlaps_hard_reg_set_p (conflict_set, mode, hard_regno)) | |
1060 | { | |
1061 | update_lives (regno, false); | |
1062 | continue; | |
1063 | } | |
1064 | bitmap_set_bit (spilled_pseudo_bitmap, regno); | |
1065 | for (j = 0; | |
1066 | j < hard_regno_nregs[hard_regno][PSEUDO_REGNO_MODE (regno)]; | |
1067 | j++) | |
1068 | lra_hard_reg_usage[hard_regno + j] -= lra_reg_info[regno].freq; | |
1069 | reg_renumber[regno] = -1; | |
1070 | if (lra_dump_file != NULL) | |
1071 | fprintf (lra_dump_file, " Spill r%d after risky transformations\n", | |
1072 | regno); | |
1073 | } | |
1074 | } | |
1075 | ||
1076 | /* Improve allocation by assigning the same hard regno of inheritance | |
1077 | pseudos to the connected pseudos. We need this because inheritance | |
1078 | pseudos are allocated after reload pseudos in the thread and when | |
1079 | we assign a hard register to a reload pseudo we don't know yet that | |
1080 | the connected inheritance pseudos can get the same hard register. | |
1081 | Add pseudos with changed allocation to bitmap CHANGED_PSEUDOS. */ | |
1082 | static void | |
1083 | improve_inheritance (bitmap changed_pseudos) | |
1084 | { | |
1085 | unsigned int k; | |
1086 | int regno, another_regno, hard_regno, another_hard_regno, cost, i, n; | |
1087 | lra_copy_t cp, next_cp; | |
1088 | bitmap_iterator bi; | |
1089 | ||
8e3a4869 VM |
1090 | if (lra_inheritance_iter > LRA_MAX_INHERITANCE_PASSES) |
1091 | return; | |
55a2c322 VM |
1092 | n = 0; |
1093 | EXECUTE_IF_SET_IN_BITMAP (&lra_inheritance_pseudos, 0, k, bi) | |
1094 | if (reg_renumber[k] >= 0 && lra_reg_info[k].nrefs != 0) | |
1095 | sorted_pseudos[n++] = k; | |
1096 | qsort (sorted_pseudos, n, sizeof (int), pseudo_compare_func); | |
1097 | for (i = 0; i < n; i++) | |
1098 | { | |
1099 | regno = sorted_pseudos[i]; | |
1100 | hard_regno = reg_renumber[regno]; | |
1101 | lra_assert (hard_regno >= 0); | |
1102 | for (cp = lra_reg_info[regno].copies; cp != NULL; cp = next_cp) | |
1103 | { | |
1104 | if (cp->regno1 == regno) | |
1105 | { | |
1106 | next_cp = cp->regno1_next; | |
1107 | another_regno = cp->regno2; | |
1108 | } | |
1109 | else if (cp->regno2 == regno) | |
1110 | { | |
1111 | next_cp = cp->regno2_next; | |
1112 | another_regno = cp->regno1; | |
1113 | } | |
1114 | else | |
1115 | gcc_unreachable (); | |
1116 | /* Don't change reload pseudo allocation. It might have | |
1117 | this allocation for a purpose and changing it can result | |
1118 | in LRA cycling. */ | |
1119 | if ((another_regno < lra_constraint_new_regno_start | |
1120 | || bitmap_bit_p (&lra_inheritance_pseudos, another_regno)) | |
1121 | && (another_hard_regno = reg_renumber[another_regno]) >= 0 | |
1122 | && another_hard_regno != hard_regno) | |
1123 | { | |
1124 | if (lra_dump_file != NULL) | |
1125 | fprintf | |
1126 | (lra_dump_file, | |
1127 | " Improving inheritance for %d(%d) and %d(%d)...\n", | |
1128 | regno, hard_regno, another_regno, another_hard_regno); | |
1129 | update_lives (another_regno, true); | |
1130 | lra_setup_reg_renumber (another_regno, -1, false); | |
1131 | if (hard_regno | |
1132 | == find_hard_regno_for (another_regno, &cost, hard_regno)) | |
1133 | assign_hard_regno (hard_regno, another_regno); | |
1134 | else | |
1135 | assign_hard_regno (another_hard_regno, another_regno); | |
1136 | bitmap_set_bit (changed_pseudos, another_regno); | |
1137 | } | |
1138 | } | |
1139 | } | |
1140 | } | |
1141 | ||
1142 | ||
1143 | /* Bitmap finally containing all pseudos spilled on this assignment | |
1144 | pass. */ | |
1145 | static bitmap_head all_spilled_pseudos; | |
1146 | /* All pseudos whose allocation was changed. */ | |
1147 | static bitmap_head changed_pseudo_bitmap; | |
1148 | ||
1149 | /* Assign hard registers to reload pseudos and other pseudos. */ | |
1150 | static void | |
1151 | assign_by_spills (void) | |
1152 | { | |
1153 | int i, n, nfails, iter, regno, hard_regno, cost, restore_regno; | |
1154 | rtx insn; | |
1155 | basic_block bb; | |
1156 | bitmap_head changed_insns, do_not_assign_nonreload_pseudos; | |
1157 | bitmap_head non_reload_pseudos; | |
1158 | unsigned int u; | |
1159 | bitmap_iterator bi; | |
992ca0f0 | 1160 | bool reload_p; |
55a2c322 VM |
1161 | int max_regno = max_reg_num (); |
1162 | ||
1163 | for (n = 0, i = lra_constraint_new_regno_start; i < max_regno; i++) | |
1164 | if (reg_renumber[i] < 0 && lra_reg_info[i].nrefs != 0 | |
1165 | && regno_allocno_class_array[i] != NO_REGS) | |
1166 | sorted_pseudos[n++] = i; | |
1167 | bitmap_initialize (&insn_conflict_pseudos, ®_obstack); | |
1168 | bitmap_initialize (&spill_pseudos_bitmap, ®_obstack); | |
1169 | bitmap_initialize (&best_spill_pseudos_bitmap, ®_obstack); | |
1170 | update_hard_regno_preference_check = XCNEWVEC (int, max_regno); | |
1171 | curr_update_hard_regno_preference_check = 0; | |
1172 | memset (try_hard_reg_pseudos_check, 0, sizeof (try_hard_reg_pseudos_check)); | |
1173 | for (i = 0; i < FIRST_PSEUDO_REGISTER; i++) | |
1174 | bitmap_initialize (&try_hard_reg_pseudos[i], ®_obstack); | |
1175 | curr_pseudo_check = 0; | |
1176 | bitmap_initialize (&changed_insns, ®_obstack); | |
1177 | bitmap_initialize (&non_reload_pseudos, ®_obstack); | |
1178 | bitmap_ior (&non_reload_pseudos, &lra_inheritance_pseudos, &lra_split_regs); | |
1179 | bitmap_ior_into (&non_reload_pseudos, &lra_optional_reload_pseudos); | |
1180 | for (iter = 0; iter <= 1; iter++) | |
1181 | { | |
1182 | qsort (sorted_pseudos, n, sizeof (int), reload_pseudo_compare_func); | |
1183 | nfails = 0; | |
1184 | for (i = 0; i < n; i++) | |
1185 | { | |
1186 | regno = sorted_pseudos[i]; | |
1187 | if (lra_dump_file != NULL) | |
1188 | fprintf (lra_dump_file, " Assigning to %d " | |
1189 | "(cl=%s, orig=%d, freq=%d, tfirst=%d, tfreq=%d)...\n", | |
1190 | regno, reg_class_names[regno_allocno_class_array[regno]], | |
1191 | ORIGINAL_REGNO (regno_reg_rtx[regno]), | |
1192 | lra_reg_info[regno].freq, regno_assign_info[regno].first, | |
1193 | regno_assign_info[regno_assign_info[regno].first].freq); | |
1194 | hard_regno = find_hard_regno_for (regno, &cost, -1); | |
992ca0f0 VM |
1195 | reload_p = ! bitmap_bit_p (&non_reload_pseudos, regno); |
1196 | if (hard_regno < 0 && reload_p) | |
55a2c322 VM |
1197 | hard_regno = spill_for (regno, &all_spilled_pseudos); |
1198 | if (hard_regno < 0) | |
1199 | { | |
992ca0f0 | 1200 | if (reload_p) |
55a2c322 VM |
1201 | sorted_pseudos[nfails++] = regno; |
1202 | } | |
1203 | else | |
1204 | { | |
1205 | /* This register might have been spilled by the previous | |
1206 | pass. Indicate that it is no longer spilled. */ | |
1207 | bitmap_clear_bit (&all_spilled_pseudos, regno); | |
1208 | assign_hard_regno (hard_regno, regno); | |
992ca0f0 VM |
1209 | if (! reload_p) |
1210 | /* As non-reload pseudo assignment is changed we | |
1211 | should reconsider insns referring for the | |
1212 | pseudo. */ | |
1213 | bitmap_set_bit (&changed_pseudo_bitmap, regno); | |
55a2c322 VM |
1214 | } |
1215 | } | |
1216 | if (nfails == 0) | |
1217 | break; | |
ce940020 VM |
1218 | if (iter > 0) |
1219 | { | |
1220 | /* We did not assign hard regs to reload pseudos after two | |
1221 | iteration. It means something is wrong with asm insn | |
1222 | constraints. Report it. */ | |
1223 | bool asm_p = false; | |
1224 | bitmap_head failed_reload_insns; | |
1225 | ||
1226 | bitmap_initialize (&failed_reload_insns, ®_obstack); | |
1227 | for (i = 0; i < nfails; i++) | |
c656b86b VM |
1228 | { |
1229 | regno = sorted_pseudos[i]; | |
1230 | bitmap_ior_into (&failed_reload_insns, | |
1231 | &lra_reg_info[regno].insn_bitmap); | |
1232 | /* Assign an arbitrary hard register of regno class to | |
1233 | avoid further trouble with the asm insns. */ | |
1234 | bitmap_clear_bit (&all_spilled_pseudos, regno); | |
1235 | assign_hard_regno | |
1236 | (ira_class_hard_regs[regno_allocno_class_array[regno]][0], | |
1237 | regno); | |
1238 | } | |
ce940020 VM |
1239 | EXECUTE_IF_SET_IN_BITMAP (&failed_reload_insns, 0, u, bi) |
1240 | { | |
1241 | insn = lra_insn_recog_data[u]->insn; | |
1242 | if (asm_noperands (PATTERN (insn)) >= 0) | |
1243 | { | |
1244 | asm_p = true; | |
1245 | error_for_asm (insn, | |
1246 | "%<asm%> operand has impossible constraints"); | |
e86c0101 SB |
1247 | /* Avoid further trouble with this insn. |
1248 | For asm goto, instead of fixing up all the edges | |
1249 | just clear the template and clear input operands | |
1250 | (asm goto doesn't have any output operands). */ | |
1251 | if (JUMP_P (insn)) | |
1252 | { | |
1253 | rtx asm_op = extract_asm_operands (PATTERN (insn)); | |
1254 | ASM_OPERANDS_TEMPLATE (asm_op) = ggc_strdup (""); | |
1255 | ASM_OPERANDS_INPUT_VEC (asm_op) = rtvec_alloc (0); | |
1256 | ASM_OPERANDS_INPUT_CONSTRAINT_VEC (asm_op) = rtvec_alloc (0); | |
1257 | lra_update_insn_regno_info (insn); | |
1258 | } | |
1259 | else | |
1260 | { | |
1261 | PATTERN (insn) = gen_rtx_USE (VOIDmode, const0_rtx); | |
1262 | lra_set_insn_deleted (insn); | |
1263 | } | |
ce940020 VM |
1264 | } |
1265 | } | |
1266 | lra_assert (asm_p); | |
1267 | break; | |
1268 | } | |
55a2c322 VM |
1269 | /* This is a very rare event. We can not assign a hard |
1270 | register to reload pseudo because the hard register was | |
1271 | assigned to another reload pseudo on a previous | |
1272 | assignment pass. For x86 example, on the 1st pass we | |
1273 | assigned CX (although another hard register could be used | |
1274 | for this) to reload pseudo in an insn, on the 2nd pass we | |
1275 | need CX (and only this) hard register for a new reload | |
1276 | pseudo in the same insn. */ | |
1277 | if (lra_dump_file != NULL) | |
1278 | fprintf (lra_dump_file, " 2nd iter for reload pseudo assignments:\n"); | |
1279 | for (i = 0; i < nfails; i++) | |
1280 | { | |
1281 | if (lra_dump_file != NULL) | |
1282 | fprintf (lra_dump_file, " Reload r%d assignment failure\n", | |
1283 | sorted_pseudos[i]); | |
1284 | bitmap_ior_into (&changed_insns, | |
1285 | &lra_reg_info[sorted_pseudos[i]].insn_bitmap); | |
1286 | } | |
e86c0101 SB |
1287 | |
1288 | /* FIXME: Look up the changed insns in the cached LRA insn data using | |
1289 | an EXECUTE_IF_SET_IN_BITMAP over changed_insns. */ | |
55a2c322 VM |
1290 | FOR_EACH_BB (bb) |
1291 | FOR_BB_INSNS (bb, insn) | |
1292 | if (bitmap_bit_p (&changed_insns, INSN_UID (insn))) | |
1293 | { | |
1294 | lra_insn_recog_data_t data; | |
1295 | struct lra_insn_reg *r; | |
f4eafc30 | 1296 | |
55a2c322 VM |
1297 | data = lra_get_insn_recog_data (insn); |
1298 | for (r = data->regs; r != NULL; r = r->next) | |
1299 | { | |
1300 | regno = r->regno; | |
1301 | /* A reload pseudo did not get a hard register on the | |
1302 | first iteration because of the conflict with | |
1303 | another reload pseudos in the same insn. So we | |
1304 | consider only reload pseudos assigned to hard | |
1305 | registers. We shall exclude inheritance pseudos as | |
1306 | they can occur in original insns (not reload ones). | |
1307 | We can omit the check for split pseudos because | |
1308 | they occur only in move insns containing non-reload | |
1309 | pseudos. */ | |
1310 | if (regno < lra_constraint_new_regno_start | |
1311 | || bitmap_bit_p (&lra_inheritance_pseudos, regno) | |
1312 | || reg_renumber[regno] < 0) | |
1313 | continue; | |
1314 | sorted_pseudos[nfails++] = regno; | |
1315 | if (lra_dump_file != NULL) | |
1316 | fprintf (lra_dump_file, | |
1317 | " Spill reload r%d(hr=%d, freq=%d)\n", | |
1318 | regno, reg_renumber[regno], | |
1319 | lra_reg_info[regno].freq); | |
1320 | update_lives (regno, true); | |
1321 | lra_setup_reg_renumber (regno, -1, false); | |
1322 | } | |
1323 | } | |
1324 | n = nfails; | |
1325 | } | |
1326 | improve_inheritance (&changed_pseudo_bitmap); | |
1327 | bitmap_clear (&non_reload_pseudos); | |
1328 | bitmap_clear (&changed_insns); | |
1329 | if (! lra_simple_p) | |
1330 | { | |
1331 | /* We should not assign to original pseudos of inheritance | |
1332 | pseudos or split pseudos if any its inheritance pseudo did | |
1333 | not get hard register or any its split pseudo was not split | |
1334 | because undo inheritance/split pass will extend live range of | |
1335 | such inheritance or split pseudos. */ | |
1336 | bitmap_initialize (&do_not_assign_nonreload_pseudos, ®_obstack); | |
1337 | EXECUTE_IF_SET_IN_BITMAP (&lra_inheritance_pseudos, 0, u, bi) | |
1338 | if ((restore_regno = lra_reg_info[u].restore_regno) >= 0 | |
1339 | && reg_renumber[u] < 0 | |
1340 | && bitmap_bit_p (&lra_inheritance_pseudos, u)) | |
1341 | bitmap_set_bit (&do_not_assign_nonreload_pseudos, restore_regno); | |
1342 | EXECUTE_IF_SET_IN_BITMAP (&lra_split_regs, 0, u, bi) | |
1343 | if ((restore_regno = lra_reg_info[u].restore_regno) >= 0 | |
1344 | && reg_renumber[u] >= 0) | |
1345 | bitmap_set_bit (&do_not_assign_nonreload_pseudos, restore_regno); | |
1346 | for (n = 0, i = FIRST_PSEUDO_REGISTER; i < max_regno; i++) | |
1347 | if (((i < lra_constraint_new_regno_start | |
1348 | && ! bitmap_bit_p (&do_not_assign_nonreload_pseudos, i)) | |
1349 | || (bitmap_bit_p (&lra_inheritance_pseudos, i) | |
1350 | && lra_reg_info[i].restore_regno >= 0) | |
1351 | || (bitmap_bit_p (&lra_split_regs, i) | |
1352 | && lra_reg_info[i].restore_regno >= 0) | |
1353 | || bitmap_bit_p (&lra_optional_reload_pseudos, i)) | |
1354 | && reg_renumber[i] < 0 && lra_reg_info[i].nrefs != 0 | |
1355 | && regno_allocno_class_array[i] != NO_REGS) | |
1356 | sorted_pseudos[n++] = i; | |
1357 | bitmap_clear (&do_not_assign_nonreload_pseudos); | |
1358 | if (n != 0 && lra_dump_file != NULL) | |
1359 | fprintf (lra_dump_file, " Reassigning non-reload pseudos\n"); | |
1360 | qsort (sorted_pseudos, n, sizeof (int), pseudo_compare_func); | |
1361 | for (i = 0; i < n; i++) | |
1362 | { | |
1363 | regno = sorted_pseudos[i]; | |
1364 | hard_regno = find_hard_regno_for (regno, &cost, -1); | |
1365 | if (hard_regno >= 0) | |
1366 | { | |
1367 | assign_hard_regno (hard_regno, regno); | |
992ca0f0 VM |
1368 | /* We change allocation for non-reload pseudo on this |
1369 | iteration -- mark the pseudo for invalidation of used | |
1370 | alternatives of insns containing the pseudo. */ | |
55a2c322 VM |
1371 | bitmap_set_bit (&changed_pseudo_bitmap, regno); |
1372 | } | |
1373 | } | |
1374 | } | |
1375 | free (update_hard_regno_preference_check); | |
1376 | bitmap_clear (&best_spill_pseudos_bitmap); | |
1377 | bitmap_clear (&spill_pseudos_bitmap); | |
1378 | bitmap_clear (&insn_conflict_pseudos); | |
1379 | } | |
1380 | ||
1381 | ||
1382 | /* Entry function to assign hard registers to new reload pseudos | |
1383 | starting with LRA_CONSTRAINT_NEW_REGNO_START (by possible spilling | |
1384 | of old pseudos) and possibly to the old pseudos. The function adds | |
1385 | what insns to process for the next constraint pass. Those are all | |
1386 | insns who contains non-reload and non-inheritance pseudos with | |
1387 | changed allocation. | |
1388 | ||
1389 | Return true if we did not spill any non-reload and non-inheritance | |
1390 | pseudos. */ | |
1391 | bool | |
1392 | lra_assign (void) | |
1393 | { | |
1394 | int i; | |
1395 | unsigned int u; | |
1396 | bitmap_iterator bi; | |
1397 | bitmap_head insns_to_process; | |
1398 | bool no_spills_p; | |
1399 | int max_regno = max_reg_num (); | |
1400 | ||
1401 | timevar_push (TV_LRA_ASSIGN); | |
1402 | init_lives (); | |
1403 | sorted_pseudos = XNEWVEC (int, max_regno); | |
1404 | sorted_reload_pseudos = XNEWVEC (int, max_regno); | |
1405 | regno_allocno_class_array = XNEWVEC (enum reg_class, max_regno); | |
1406 | for (i = FIRST_PSEUDO_REGISTER; i < max_regno; i++) | |
1407 | regno_allocno_class_array[i] = lra_get_allocno_class (i); | |
1408 | init_regno_assign_info (); | |
1409 | bitmap_initialize (&all_spilled_pseudos, ®_obstack); | |
1410 | create_live_range_start_chains (); | |
1411 | setup_live_pseudos_and_spill_after_risky_transforms (&all_spilled_pseudos); | |
1412 | #ifdef ENABLE_CHECKING | |
1413 | for (i = FIRST_PSEUDO_REGISTER; i < max_regno; i++) | |
1414 | if (lra_reg_info[i].nrefs != 0 && reg_renumber[i] >= 0 | |
1415 | && lra_reg_info[i].call_p | |
1416 | && overlaps_hard_reg_set_p (call_used_reg_set, | |
1417 | PSEUDO_REGNO_MODE (i), reg_renumber[i])) | |
1418 | gcc_unreachable (); | |
1419 | #endif | |
1420 | /* Setup insns to process on the next constraint pass. */ | |
1421 | bitmap_initialize (&changed_pseudo_bitmap, ®_obstack); | |
1422 | init_live_reload_and_inheritance_pseudos (); | |
1423 | assign_by_spills (); | |
1424 | finish_live_reload_and_inheritance_pseudos (); | |
1425 | bitmap_ior_into (&changed_pseudo_bitmap, &all_spilled_pseudos); | |
1426 | no_spills_p = true; | |
1427 | EXECUTE_IF_SET_IN_BITMAP (&all_spilled_pseudos, 0, u, bi) | |
1428 | /* We ignore spilled pseudos created on last inheritance pass | |
1429 | because they will be removed. */ | |
1430 | if (lra_reg_info[u].restore_regno < 0) | |
1431 | { | |
1432 | no_spills_p = false; | |
1433 | break; | |
1434 | } | |
1435 | finish_live_range_start_chains (); | |
1436 | bitmap_clear (&all_spilled_pseudos); | |
1437 | bitmap_initialize (&insns_to_process, ®_obstack); | |
1438 | EXECUTE_IF_SET_IN_BITMAP (&changed_pseudo_bitmap, 0, u, bi) | |
1439 | bitmap_ior_into (&insns_to_process, &lra_reg_info[u].insn_bitmap); | |
1440 | bitmap_clear (&changed_pseudo_bitmap); | |
1441 | EXECUTE_IF_SET_IN_BITMAP (&insns_to_process, 0, u, bi) | |
1442 | { | |
1443 | lra_push_insn_by_uid (u); | |
1444 | /* Invalidate alternatives for insn should be processed. */ | |
1445 | lra_set_used_insn_alternative_by_uid (u, -1); | |
1446 | } | |
1447 | bitmap_clear (&insns_to_process); | |
1448 | finish_regno_assign_info (); | |
1449 | free (regno_allocno_class_array); | |
1450 | free (sorted_pseudos); | |
1451 | free (sorted_reload_pseudos); | |
1452 | finish_lives (); | |
1453 | timevar_pop (TV_LRA_ASSIGN); | |
1454 | return no_spills_p; | |
1455 | } |